diff options
Diffstat (limited to 'src')
788 files changed, 149421 insertions, 25968 deletions
diff --git a/src/com/jogamp/graph/curve/OutlineShape.java b/src/com/jogamp/graph/curve/OutlineShape.java deleted file mode 100755 index 827717aa5..000000000 --- a/src/com/jogamp/graph/curve/OutlineShape.java +++ /dev/null @@ -1,307 +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 com.jogamp.graph.curve;
-
-import java.util.ArrayList;
-import java.util.Collections;
-
-import com.jogamp.graph.geom.Outline;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.math.VectorUtil;
-
-import com.jogamp.graph.curve.tess.CDTriangulator2D;
-
-/** A Generic shape objects which is defined by a list of Outlines.
- * This Shape can be transformed to Triangulations.
- * The list of triangles generated are render-able by a Region object.
- * The triangulation produced by this Shape will define the
- * closed region defined by the outlines.
- *
- * One or more OutlineShape Object can be associated to a region
- * this is left as a high-level representation of the Objects. For
- * optimizations, flexibility requirements for future features.
- *
- * <br><br>
- * Example to creating an Outline Shape:
- * <pre>
- addVertex(...)
- addVertex(...)
- addVertex(...)
- addEnptyOutline()
- addVertex(...)
- addVertex(...)
- addVertex(...)
- * </pre>
- *
- * The above will create two outlines each with three vertices. By adding these two outlines to
- * the OutlineShape, we are stating that the combination of the two outlines represent the shape.
- * <br>
- *
- * To specify that the shape is curved at a region, the on-curve flag should be set to false
- * for the vertex that is in the middle of the curved region (if the curved region is defined by 3
- * vertices (quadratic curve).
- * <br>
- * In case the curved region is defined by 4 or more vertices the middle vertices should both have
- * the on-curve flag set to false.
- *
- * <br>Example: <br>
- * <pre>
- addVertex(0,0, true);
- addVertex(0,1, false);
- addVertex(1,1, false);
- addVertex(1,0, true);
- * </pre>
- *
- * The above snippet defines a cubic nurbs curve where (0,1 and 1,1)
- * do not belong to the final rendered shape.
- *
- * <i>Implementation Notes:</i><br>
- * <ul>
- * <li> The first vertex of any outline belonging to the shape should be on-curve</li>
- * <li> Intersections between off-curved parts of the outline is not handled</li>
- * </ul>
- *
- * @see Outline
- * @see Region
- */
-public class OutlineShape {
-
- public static final int QUADRATIC_NURBS = 10;
- private final Vertex.Factory<? extends Vertex> vertexFactory;
-
- /** The list of {@link Outline}s that are part of this
- * outline shape.
- */
- private ArrayList<Outline> outlines = new ArrayList<Outline>(3);
-
- /** Create a new Outline based Shape
- */
- public OutlineShape(Vertex.Factory<? extends Vertex> factory) {
- vertexFactory = factory;
- outlines.add(new Outline());
- }
-
- /** Returns the associated vertex factory of this outline shape
- * @return Vertex.Factory object
- */
- public final Vertex.Factory<? extends Vertex> vertexFactory() { return vertexFactory; }
-
- /** Add a new empty {@link Outline}
- * to the shape, this new outline will
- * be placed at the end of the outline list.
- *
- * After a call to this function all new vertices added
- * will belong to the new outline
- */
- public void addEmptyOutline(){
- outlines.add(new Outline());
- }
-
- /** Adds an {@link Outline} to the OutlineShape object
- * if last outline of the shape is empty, it will replace
- * that last Outline with the new one. If outline is empty,
- * it will do nothing.
- * @param outline an Outline object
- */
- public void addOutline(Outline outline){
- if(outline.isEmpty()){
- return;
- }
- if(getLastOutline().isEmpty()){
- outlines.remove(getLastOutline());
- }
- outlines.add(outline);
- }
-
- /** Adds a vertex to the last open outline in the
- * shape.
- * @param v the vertex to be added to the OutlineShape
- */
- public final void addVertex(Vertex v){
- getLastOutline().addVertex(v);
- }
-
- /** Add a 2D {@link Vertex} to the last outline by defining the coordniate attribute
- * of the vertex. The 2D vertex will be represented as Z=0.
- *
- * @param x the x coordinate
- * @param y the y coordniate
- * @param onCurve flag if this vertex is on the final curve or defines a curved region
- * of the shape around this vertex.
- */
- public final void addVertex(float x, float y, boolean onCurve) {
- getLastOutline().addVertex(vertexFactory, x, y, onCurve);
- }
-
- /** Add a 3D {@link Vertex} to the last outline by defining the coordniate attribute
- * of the vertex.
- * @param x the x coordinate
- * @param y the y coordniate
- * @param z the z coordniate
- * @param onCurve flag if this vertex is on the final curve or defines a curved region
- * of the shape around this vertex.
- */
- public final void addVertex(float x, float y, float z, boolean onCurve) {
- getLastOutline().addVertex(vertexFactory, x, y, z, onCurve);
- }
-
- /** Add a vertex to the last outline by passing a float array and specifying the
- * offset and length in which. The attributes of the vertex are located.
- * The attributes should be continuous (stride = 0).
- * Attributes which value are not set (when length less than 3)
- * are set implicitly to zero.
- * @param coordsBuffer the coordinate array where the vertex attributes are to be picked from
- * @param offset the offset in the buffer to the x coordinate
- * @param length the number of attributes to pick from the buffer (maximum 3)
- * @param onCurve flag if this vertex is on the final curve or defines a curved region
- * of the shape around this vertex.
- */
- public final void addVertex(float[] coordsBuffer, int offset, int length, boolean onCurve) {
- getLastOutline().addVertex(vertexFactory, coordsBuffer, offset, length, onCurve);
- }
-
- /** Closes the last outline in the shape
- * if last vertex is not equal to first vertex.
- * A new temp vertex is added at the end which
- * is equal to the first.
- */
- public void closeLastOutline(){
- getLastOutline().setClosed(true);
- }
-
- /** Get the last added outline to the list
- * of outlines that define the shape
- * @return the last outline
- */
- public final Outline getLastOutline(){
- return outlines.get(outlines.size()-1);
- }
- /** Make sure that the outlines represent
- * the specified destinationType, if not
- * transform outlines to destination type.
- * @param destinationType The curve type needed
- */
- public void transformOutlines(int destinationType){
- if(destinationType == QUADRATIC_NURBS){
- transformOutlinesQuadratic();
- }
- }
-
- private void transformOutlinesQuadratic(){
- ArrayList<Outline> newOutlines = new ArrayList<Outline>(3);
-
- /**loop over the outlines and make sure no
- * adj off-curve vertices
- */
- for(Outline outline:outlines){
- Outline newOutline = new Outline();
-
- ArrayList<Vertex> vertices = outline.getVertices();
- int size =vertices.size()-1;
- for(int i=0;i<size;i++){
- Vertex currentVertex = vertices.get(i);
- Vertex nextVertex = vertices.get((i+1)%size);
- if(!(currentVertex.isOnCurve()) && !(nextVertex.isOnCurve())) {
- newOutline.addVertex(currentVertex);
-
- float[] newCoords = VectorUtil.mid(currentVertex.getCoord(), nextVertex.getCoord());
- newOutline.addVertex(vertexFactory, newCoords, 0, 3, true);
- }
- else {
- newOutline.addVertex(currentVertex);
- }
- }
- newOutlines.add(newOutline);
- }
- outlines = newOutlines;
- }
-
- private void generateVertexIds(){
- int maxVertexId = 0;
- for(Outline outline:outlines){
- ArrayList<Vertex> vertices = outline.getVertices();
- for(Vertex vert:vertices){
- vert.setId(maxVertexId);
- maxVertexId++;
- }
- }
- }
-
- /** @return the list of vertices associated with the
- * {@code Outline} list of this object
- */
- public ArrayList<Vertex> getVertices(){
- ArrayList<Vertex> vertices = new ArrayList<Vertex>();
- for(Outline polyline:outlines){
- vertices.addAll(polyline.getVertices());
- }
- return vertices;
- }
-
- /** Triangulate the outline shape generating a list of triangles
- * @return an arraylist of triangles representing the filled region
- * which is produced by the combination of the outlines
- */
- public ArrayList<Triangle> triangulate(){
- return triangulate(0.5f);
- }
-
- /**Triangulate the {@link OutlineShape} generating a list of triangles
- * @param sharpness defines the curvature strength around the off-curve vertices.
- * defaults to 0.5f
- * @return an arraylist of triangles representing the filled region
- * which is produced by the combination of the outlines
- */
- public ArrayList<Triangle> triangulate(float sharpness){
- if(outlines.size() == 0){
- return null;
- }
- sortOutlines();
- generateVertexIds();
-
- CDTriangulator2D triangulator2d = new CDTriangulator2D(sharpness);
- for(int index = 0; index< outlines.size();index++){
- Outline outline = outlines.get(index);
- triangulator2d.addCurve(outline);
- }
-
- ArrayList<Triangle> triangles = triangulator2d.generateTriangulation();
- triangulator2d.reset();
-
- return triangles;
- }
-
- /** Sort the outlines from large
- * to small depending on the AABox
- */
- private void sortOutlines() {
- Collections.sort(outlines);
- Collections.reverse(outlines);
- }
-}
diff --git a/src/com/jogamp/graph/curve/Region.java b/src/com/jogamp/graph/curve/Region.java deleted file mode 100755 index 051cb1c38..000000000 --- a/src/com/jogamp/graph/curve/Region.java +++ /dev/null @@ -1,128 +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 com.jogamp.graph.curve;
-
-import java.util.ArrayList;
-
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.opengl.util.PMVMatrix;
-
-/** A Region is the OGL binding of one or more OutlineShapes
- * Defined by its vertices and generated triangles. The Region
- * defines the final shape of the OutlineShape(s), which shall produced a shaded
- * region on the screen.
- *
- * Implementations of the Region shall take care of the OGL
- * binding of the depending on its context, profile.
- *
- * @see RegionFactory, OutlineShape
- */
-public interface Region {
- /** The vertices index in an OGL object
- */
- public static int VERTEX_ATTR_IDX = 0;
-
- /** The Texture Coord index in an OGL object
- */
- public static int TEXCOORD_ATTR_IDX = 1;
-
- /** 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
- * it initialize the objects.
- */
- public void update();
-
- /** Renders the associated OGL objects specifying
- * current width/hight of window for multi pass rendering
- * of the region.
- * @param matrix current {@link PMVMatrix}.
- * @param vp_width current screen width
- * @param vp_height current screen height
- * @param width texture width for mp rendering
- *
- * @see update()
- */
- public void render(PMVMatrix matrix, int vp_width, int vp_height, int width);
-
- /** Adds a list of {@link Triangle} objects to the Region
- * These triangles are to be binded to OGL objects
- * on the next call to {@code update}
- * @param tris an arraylist of triangle objects
- *
- * @see update()
- */
- public void addTriangles(ArrayList<Triangle> tris);
-
- /** Get the current number of vertices associated
- * with this region. This number is not necessary equal to
- * the OGL binded number of vertices.
- * @return vertices count
- *
- * @see isDirty()
- */
- public int getNumVertices();
-
- /** Adds a list of {@link Vertex} objects to the Region
- * These vertices are to be binded to OGL objects
- * on the next call to {@code update}
- * @param verts an arraylist of vertex objects
- *
- * @see update()
- */
- public void addVertices(ArrayList<Vertex> verts);
-
- /** Check if this region is dirty. A region is marked dirty
- * when new Vertices, Triangles, and or Lines are added after a
- * call to update()
- * @return true if region is Dirty, false otherwise
- *
- * @see update();
- */
- public boolean isDirty();
-
- /** Delete and clean the associated OGL
- * objects
- */
- public void destroy();
-
- public boolean isFlipped();
-
- /** Set if the y coordinate of the region should be flipped
- * {@code y=-y} used mainly for fonts since they use opposite vertex
- * as origion
- * @param flipped flag if the coordinate is flipped defaults to false.
- */
- public void setFlipped(boolean flipped);
-}
diff --git a/src/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/com/jogamp/graph/curve/opengl/RegionRenderer.java deleted file mode 100644 index c1fec10b8..000000000 --- a/src/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.jogamp.graph.curve.opengl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -import javax.media.opengl.GL2ES2; - -import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.RegionFactory; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.Vertex; - -public abstract class RegionRenderer extends Renderer { - - /** Create a Hardware accelerated Curve Region Renderer - */ - public static RegionRenderer create(Vertex.Factory<? extends Vertex> factory, int type) { - return new jogamp.graph.curve.opengl.RegionRendererImpl01(factory, type); - } - - public RegionRenderer(Vertex.Factory<? extends Vertex> factory, int type) { - super(factory, type); - } - - /** Render an array of {@link OutlineShape}s combined in one region - * at the position provided the triangles of the - * shapes will be generated, if not yet generated - * @param outlineShapes array of OutlineShapes to Render. - * @param position the initial translation of the outlineShapes. - * @param texSize texture size for multipass render * - * @throws Exception if HwRegionRenderer not initialized - */ - public abstract void renderOutlineShapes(GL2ES2 gl, OutlineShape[] outlineShapes, float[] position, int texSize); - - /** Render an {@link OutlineShape} in 3D space at the position provided - * the triangles of the shapes will be generated, if not yet generated - * @param outlineShape the OutlineShape to Render. - * @param position the initial translation of the outlineShape. - * @param texSize texture size for multipass render - * @throws Exception if HwRegionRenderer not initialized - */ - public abstract void renderOutlineShape(GL2ES2 gl, OutlineShape outlineShape, float[] position, int texSize); - - protected HashMap<Integer, Region> regions = new HashMap<Integer, Region>(); - - public void flushCache() { - Iterator<Region> iterator = regions.values().iterator(); - while(iterator.hasNext()){ - Region region = iterator.next(); - region.destroy(); - } - regions.clear(); - } - - /** Create an ogl {@link Region} defining this {@link OutlineShape} - * @param sharpness parameter for Region generation - * @return the resulting Region. - */ - protected Region createRegion(GL2ES2 gl, OutlineShape outlineShape, float sharpness) { - Region region = RegionFactory.create(gl.getContext(), st, renderType); - - outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS); - - ArrayList<Triangle> triangles = (ArrayList<Triangle>) outlineShape.triangulate(sharpness); - ArrayList<Vertex> vertices = (ArrayList<Vertex>) outlineShape.getVertices(); - region.addVertices(vertices); - region.addTriangles(triangles); - - region.update(); - return region; - } - - /** Create an ogl {@link Region} defining the list of {@link OutlineShape}. - * Combining the Shapes into single buffers. - * @param sharpness parameter for Region generation - * @return the resulting Region inclusive the generated region - */ - protected Region createRegion(GL2ES2 gl, OutlineShape[] outlineShapes, float sharpness) { - Region region = RegionFactory.create(gl.getContext(), st, renderType); - - int numVertices = region.getNumVertices(); - - for(OutlineShape outlineShape:outlineShapes){ - outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS); - - ArrayList<Triangle> triangles = outlineShape.triangulate(sharpness); - region.addTriangles(triangles); - - ArrayList<Vertex> vertices = outlineShape.getVertices(); - for(Vertex vert:vertices){ - vert.setId(numVertices++); - } - region.addVertices(vertices); - } - - region.update(); - return region; - } - - protected static int getHashCode(OutlineShape outlineShape){ - return outlineShape.hashCode(); - } - - protected static int getHashCode(OutlineShape[] outlineShapes){ - int hashcode = 0; - for(OutlineShape outlineShape:outlineShapes){ - hashcode += getHashCode(outlineShape); - } - return hashcode; - } -}
\ No newline at end of file diff --git a/src/com/jogamp/graph/curve/opengl/Renderer.java b/src/com/jogamp/graph/curve/opengl/Renderer.java deleted file mode 100644 index 863928ed4..000000000 --- a/src/com/jogamp/graph/curve/opengl/Renderer.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.jogamp.graph.curve.opengl; - -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLUniformData; -import javax.media.opengl.fixedfunc.GLMatrixFunc; - -import jogamp.opengl.Debug; - -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.opengl.SVertex; -import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.glsl.ShaderState; - -public abstract class Renderer { - protected static final boolean DEBUG = Debug.debug("CurveRenderer"); - - protected abstract boolean initImpl(GL2ES2 gl); - - protected abstract void disposeImpl(GL2ES2 gl); - - /** - * Flushes all cached data - */ - public abstract void flushCache(); - - public abstract float getAlpha(); - - public abstract void setAlpha(GL2ES2 gl, float alpha_t); - - public abstract void setColor(GL2ES2 gl, float r, float g, float b); - - protected final Vertex.Factory<? extends Vertex> pointFactory; - protected ShaderState st = new ShaderState(); - protected PMVMatrix pmvMatrix = new PMVMatrix(); - protected GLUniformData mgl_PMVMatrix; - protected int renderType; - protected int vp_width = 0; - protected int vp_height = 0; - - private boolean vboSupported = false; - private boolean initialized = false; - - /** - * - * @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(); - } - - public Vertex.Factory<? extends Vertex> getFactory() { return pointFactory; } - - public final boolean isInitialized() { return initialized; } - - 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; } - - /** - * Initialize shaders and bindings for GPU based rendering. - * Leaves the renderer enabled, ie ShaderState on. - * - * @param gl the current GL state - * @return true if succeeded, false otherwise - */ - public boolean init(GL2ES2 gl) { - if(initialized){ - if(DEBUG) { - System.err.println("TextRenderer: Already initialized!"); - } - return true; - } - vboSupported = gl.isFunctionAvailable("glGenBuffers") && - gl.isFunctionAvailable("glBindBuffer") && - gl.isFunctionAvailable("glBufferData") && - gl.isFunctionAvailable("glDrawElements") && - gl.isFunctionAvailable("glVertexAttribPointer") && - gl.isFunctionAvailable("glDeleteBuffers"); - - if(DEBUG) { - System.err.println("TextRendererImpl01: VBO Supported = " + isVBOSupported()); - } - - initialized = initImpl(gl); - return initialized; - } - - public void dispose(GL2ES2 gl) { - if(!initialized){ - if(DEBUG) { - System.err.println("TextRenderer: Not initialized!"); - } - return; - } - disposeImpl(gl); - st.destroy(gl); - flushCache(); - initialized = false; - } - - public final ShaderState getShaderState() { return st; } - - public final PMVMatrix getMatrix() { return pmvMatrix; } - - public void rotate(GL2ES2 gl, float angle, float x, float y, float z) { - pmvMatrix.glRotatef(angle, x, y, z); - if(initialized && null != gl && st.inUse()) { - st.glUniform(gl, mgl_PMVMatrix); - } - } - - public void translate(GL2ES2 gl, float x, float y, float z) { - pmvMatrix.glTranslatef(x, y, z); - if(initialized && null != gl && st.inUse()) { - st.glUniform(gl, mgl_PMVMatrix); - } - } - - public void resetModelview(GL2ES2 gl) { - pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - pmvMatrix.glLoadIdentity(); - if(initialized && null != gl && st.inUse()) { - st.glUniform(gl, mgl_PMVMatrix); - } - } - - public void updateMatrix(GL2ES2 gl) { - if(initialized && null != gl && st.inUse()) { - st.glUniform(gl, mgl_PMVMatrix); - } - } - - public boolean reshapePerspective(GL2ES2 gl, float angle, int width, int height, float near, float far) { - this.vp_width = width; - this.vp_height = height; - float ratio = (float)width/(float)height; - pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); - pmvMatrix.gluPerspective(angle, ratio, near, far); - - if(initialized && null != gl) { - st.glUniform(gl, mgl_PMVMatrix); - } - - return true; - } - - public boolean reshapeOrtho(GL2ES2 gl, int width, int height, float near, float far) { - this.vp_width = width; - this.vp_height = height; - pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); - pmvMatrix.glOrthof(0, width, 0, height, near, far); - - if(initialized && null != gl) { - st.glUniform(gl, mgl_PMVMatrix); - } - - return true; - } - -}
\ No newline at end of file diff --git a/src/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/com/jogamp/graph/curve/opengl/TextRenderer.java deleted file mode 100644 index 2bb99d27c..000000000 --- a/src/com/jogamp/graph/curve/opengl/TextRenderer.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.jogamp.graph.curve.opengl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -import javax.media.opengl.GL2ES2; - -import jogamp.graph.curve.text.GlyphString; -import jogamp.graph.font.FontInt; -import jogamp.graph.geom.plane.AffineTransform; -import jogamp.graph.geom.plane.Path2D; - -import com.jogamp.graph.font.Font; -import com.jogamp.graph.geom.Vertex; - -public abstract class TextRenderer extends Renderer { - - /** - * Create a Hardware accelerated Text Renderer. - * @param factory optional Point.Factory for Vertex construction. Default is Vertex.Factory. - */ - public static TextRenderer create(Vertex.Factory<? extends Vertex> factory, int type) { - return new jogamp.graph.curve.opengl.TextRendererImpl01(factory, type); - } - - protected TextRenderer(Vertex.Factory<? extends Vertex> factory, int type) { - super(factory, type); - } - - /** Render the String in 3D space wrt to the font provided at the position provided - * the outlines will be generated, if not yet generated - * @param gl the current GL state - * @param font {@link Font} to be used - * @param str text to be rendered - * @param position the lower left corner of the string - * @param fontSize font size - * @param texSize texture size for multipass render - * @throws Exception if TextRenderer not initialized - */ - public abstract void renderString3D(GL2ES2 gl, Font font, - String str, float[] position, int fontSize, int texSize); - - /**Create the resulting {@link GlyphString} that represents - * the String wrt to the font. - * @param font {@link Font} to be used - * @param size font size - * @param str {@link String} to be created - * @param sharpness parameter for Region generation of the resulting GlyphString - * @return the resulting GlyphString inclusive the generated region - */ - protected GlyphString createString(GL2ES2 gl, Font font, int size, String str, float sharpness) { - AffineTransform affineTransform = new AffineTransform(pointFactory); - - Path2D[] paths = new Path2D[str.length()]; - ((FontInt)font).getOutline(str, size, affineTransform, paths); - - GlyphString glyphString = new GlyphString(pointFactory, font.getName(), str); - glyphString.createfromFontPath(paths, affineTransform); - glyphString.generateRegion(gl.getContext(), sharpness, st, renderType); - - return glyphString; - } - - public void flushCache() { - Iterator<GlyphString> iterator = stringCacheMap.values().iterator(); - while(iterator.hasNext()){ - GlyphString glyphString = iterator.next(); - glyphString.destroy(); - } - 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/com/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java deleted file mode 100644 index a2e4ca50f..000000000 --- a/src/com/jogamp/graph/curve/tess/CDTriangulator2D.java +++ /dev/null @@ -1,216 +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 com.jogamp.graph.curve.tess; - -import java.util.ArrayList; - -import jogamp.graph.curve.tess.GraphOutline; -import jogamp.graph.curve.tess.GraphVertex; -import jogamp.graph.curve.tess.Loop; - -import com.jogamp.graph.geom.Outline; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.math.VectorUtil; - -import jogamp.opengl.Debug; - -/** Constrained Delaunay Triangulation - * implementation of a list of Outlines that define a set of - * Closed Regions with optional n holes. - * - */ -public class CDTriangulator2D { - - protected static final boolean DEBUG = Debug.debug("Triangulation"); - - private float sharpness = 0.5f; - private ArrayList<Loop> loops; - private ArrayList<Vertex> vertices; - - private ArrayList<Triangle> triangles; - private int maxTriID = 0; - - - public CDTriangulator2D() { - this(0.5f); - } - - /** Constructor for a new Delaunay triangulator - * @param curveSharpness the curvature around - * the off-curve vertices - */ - public CDTriangulator2D(float curveSharpness) { - this.sharpness = curveSharpness; - reset(); - } - - /** Reset the triangulation to initial state - * Clearing cached data - */ - public void reset() { - maxTriID = 0; - vertices = new ArrayList<Vertex>(); - triangles = new ArrayList<Triangle>(3); - loops = new ArrayList<Loop>(); - } - - /** Add a curve to the list of profiles provided - * @param polyline a bounding {@link Outline} - */ - public void addCurve(Outline polyline){ - Loop loop = null; - - if(!loops.isEmpty()){ - loop = getContainerLoop(polyline); - } - - if(loop == null) { - GraphOutline outline = new GraphOutline(polyline); - GraphOutline innerPoly = extractBoundaryTriangles(outline, false); - vertices.addAll(polyline.getVertices()); - loop = new Loop(innerPoly, VectorUtil.CCW); - loops.add(loop); - } - else { - GraphOutline outline = new GraphOutline(polyline); - GraphOutline innerPoly = extractBoundaryTriangles(outline, true); - vertices.addAll(innerPoly.getPoints()); - loop.addConstraintCurve(innerPoly); - } - } - - /** Generate the triangulation of the provided - * List of {@link Outline}s - */ - public ArrayList<Triangle> generateTriangulation(){ - for(int i=0;i<loops.size();i++) { - Loop loop = loops.get(i); - int numTries = 0; - int size = loop.computeLoopSize(); - while(!loop.isSimplex()){ - Triangle tri = null; - if(numTries > size){ - tri = loop.cut(false); - } - else{ - tri = loop.cut(true); - } - numTries++; - - if(tri != null) { - numTries = 0; - size--; - tri.setId(maxTriID++); - triangles.add(tri); - if(DEBUG){ - System.err.println(tri); - } - } - if(numTries > size*2){ - if(DEBUG){ - System.err.println("Triangulation not complete!"); - } - break; - } - } - Triangle tri = loop.cut(true); - if(tri != null) - triangles.add(tri); - } - return triangles; - } - - private GraphOutline extractBoundaryTriangles(GraphOutline outline, boolean hole){ - GraphOutline innerOutline = new GraphOutline(); - ArrayList<GraphVertex> outVertices = outline.getGraphPoint(); - int size = outVertices.size(); - for(int i=0; i < size; i++) { - GraphVertex currentVertex = outVertices.get(i); - GraphVertex gv0 = outVertices.get((i+size-1)%size); - GraphVertex gv2 = outVertices.get((i+1)%size); - GraphVertex gv1 = currentVertex; - - if(!currentVertex.getPoint().isOnCurve()) { - Vertex v0 = gv0.getPoint().clone(); - Vertex v2 = gv2.getPoint().clone(); - Vertex v1 = gv1.getPoint().clone(); - - gv0.setBoundaryContained(true); - gv1.setBoundaryContained(true); - gv2.setBoundaryContained(true); - - Triangle t= null; - boolean holeLike = false; - if(VectorUtil.ccw(v0,v1,v2)){ - t = new Triangle(v0, v1, v2); - } - else { - holeLike = true; - t = new Triangle(v2, v1, v0); - } - t.setId(maxTriID++); - triangles.add(t); - if(DEBUG){ - System.err.println(t); - } - if(hole || holeLike) { - v0.setTexCoord(0, -0.1f); - v2.setTexCoord(1, -0.1f); - v1.setTexCoord(0.5f, -1*sharpness -0.1f); - innerOutline.addVertex(currentVertex); - } - else { - v0.setTexCoord(0, 0.1f); - v2.setTexCoord(1, 0.1f); - v1.setTexCoord(0.5f, sharpness+0.1f); - } - } - else { - if(!gv2.getPoint().isOnCurve() || !gv0.getPoint().isOnCurve()){ - currentVertex.setBoundaryContained(true); - } - innerOutline.addVertex(currentVertex); - } - } - return innerOutline; - } - - private Loop getContainerLoop(Outline polyline){ - ArrayList<Vertex> vertices = polyline.getVertices(); - for(Vertex vert: vertices){ - for (Loop loop:loops){ - if(loop.checkInside(vert)){ - return loop; - } - } - } - return null; - } -} diff --git a/src/com/jogamp/graph/font/FontFactory.java b/src/com/jogamp/graph/font/FontFactory.java deleted file mode 100644 index 1752a693c..000000000 --- a/src/com/jogamp/graph/font/FontFactory.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright 2011 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.graph.font; - -import java.security.AccessController; - -import com.jogamp.common.util.ReflectionUtil; - -import jogamp.graph.font.FontConstructor; -import jogamp.graph.font.JavaFontLoader; -import jogamp.graph.font.UbuntuFontLoader; -import jogamp.opengl.Debug; - -public class FontFactory { - /** Ubuntu is the default font family */ - public static final int UBUNTU = 0; - - /** Java fonts are optional */ - public static final int JAVA = 1; - - private static final FontConstructor fontConstr; - - static { - /** - * For example: - * "jogamp.graph.font.typecast.TypecastFontFactory" (default) - * "jogamp.graph.font.ttf.TTFFontImpl" - */ - String fontImplName = Debug.getProperty("FontImpl", true, AccessController.getContext()); - if(null == fontImplName) { - fontImplName = "jogamp.graph.font.typecast.TypecastFontConstructor"; - } - fontConstr = (FontConstructor) ReflectionUtil.createInstance(fontImplName, FontFactory.class.getClassLoader()); - } - - public static final FontConstructor getFontConstr() { return fontConstr; } - - public static final FontSet getDefault() { - return get(UBUNTU); - } - - public static final FontSet get(int font) { - switch (font) { - case JAVA: - return JavaFontLoader.get(); - default: - return UbuntuFontLoader.get(); - } - } - - public static final Font get(String path) { - return fontConstr.create(path); - } - -} diff --git a/src/com/jogamp/graph/font/FontSet.java b/src/com/jogamp/graph/font/FontSet.java deleted file mode 100644 index 0cee81124..000000000 --- a/src/com/jogamp/graph/font/FontSet.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright 2011 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.graph.font; - - -public interface FontSet { - - /** Font family REGULAR **/ - public static final int FAMILY_REGULAR = 0; - - /** Font family LIGHT **/ - public static final int FAMILY_LIGHT = 1; - - /** Font family MEDIUM **/ - public static final int FAMILY_MEDIUM = 2; - - /** Font family CONDENSED **/ - public static final int FAMILY_CONDENSED = 3; - - /** Font family MONO **/ - public static final int FAMILY_MONOSPACED = 4; - - /** SERIF style/family bit flag. Fallback to Sans Serif. */ - public static final int STYLE_SERIF = 1 << 1; - - /** BOLD style bit flag */ - public static final int STYLE_BOLD = 1 << 2; - - /** ITALIC style bit flag */ - public static final int STYLE_ITALIC = 1 << 3; - - Font getDefault(); - - Font get(int family, int stylebits); -} diff --git a/src/com/jogamp/graph/geom/AABBox.java b/src/com/jogamp/graph/geom/AABBox.java deleted file mode 100644 index 8cd06329e..000000000 --- a/src/com/jogamp/graph/geom/AABBox.java +++ /dev/null @@ -1,299 +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 com.jogamp.graph.geom; - -import com.jogamp.graph.math.VectorUtil; - -/** - * Axis Aligned Bounding Box. Defined by two 3D coordinates (low and high) - * The low being the the lower left corner of the box, and the high being the upper - * right corner of the box. - * - */ -public class AABBox { - private float[] low = {Float.MAX_VALUE,Float.MAX_VALUE,Float.MAX_VALUE}; - private float[] high = {-1*Float.MAX_VALUE,-1*Float.MAX_VALUE,-1*Float.MAX_VALUE}; - private float[] center = new float[3]; - - /** Create a Axis Aligned bounding box (AABBox) - * where the low and and high MAX float Values. - */ - public AABBox() {} - - /** Create an AABBox specifying the coordinates - * of the low and high - * @param lx min x-coordinate - * @param ly min y-coordnate - * @param lz min z-coordinate - * @param hx max x-coordinate - * @param hy max y-coordinate - * @param hz max z-coordinate - */ - public AABBox(float lx, float ly, float lz, - float hx, float hy, float hz) - { - setLow(lx, ly, lz); - setHigh(hx, hy, hz); - - computeCenter(); - } - - /** Create a AABBox defining the low and high - * @param low min xyz-coordinates - * @param high max xyz-coordinates - */ - public AABBox(float[] low, float[] high) - { - this.low = low; - this.high = high; - - computeCenter(); - } - - /** Get the max xyz-coordinates - * @return a float array containing the max xyz coordinates - */ - public float[] getHigh() - { - return high; - } - - private void setHigh(float hx, float hy, float hz) - { - this.high[0] = hx; - this.high[1] = hy; - this.high[2] = hz; - } - - /** Get the min xyz-coordinates - * @return a float array containing the min xyz coordinates - */ - public float[] getLow() - { - return low; - } - - private void setLow(float lx, float ly, float lz) - { - this.low[0] = lx; - this.low[1] = ly; - this.low[2] = lz; - } - - /** Resize the AABBox to encapsulate another AABox - * @param newBox AABBox to be encapsulated in - */ - public void resize(AABBox newBox) - { - float[] newLow = newBox.getLow(); - float[] newHigh = newBox.getHigh(); - - /** test low */ - if (newLow[0] < low[0]) - low[0] = newLow[0]; - if (newLow[1] < low[1]) - low[1] = newLow[1]; - if (newLow[2] < low[2]) - low[2] = newLow[2]; - - /** test high */ - if (newHigh[0] > high[0]) - high[0] = newHigh[0]; - if (newHigh[1] > high[1]) - high[1] = newHigh[1]; - if (newHigh[2] > high[2]) - high[2] = newHigh[2]; - - computeCenter(); - } - - private void computeCenter() - { - center[0] = (high[0] + low[0])/2; - center[1] = (high[1] + low[1])/2; - center[2] = (high[2] + low[2])/2; - } - - /** Resize the AABBox to encapsulate the passed - * xyz-coordinates. - * @param x x-axis coordinate value - * @param y y-axis coordinate value - * @param z z-axis coordinate value - */ - public void resize(float x, float y, float z) - { - /** test low */ - if (x < low[0]) - low[0] = x; - if (y < low[1]) - low[1] = y; - if (z < low[2]) - low[2] = z; - - /** test high */ - if (x > high[0]) - high[0] = x; - if (y > high[1]) - high[1] = y; - if (z > high[2]) - high[2] = z; - - computeCenter(); - } - - /** Check if the x & y coordinates are bounded/contained - * by this AABBox - * @param x x-axis coordinate value - * @param y y-axis coordinate value - * @return true if x belong to (low.x, high.x) and - * y belong to (low.y, high.y) - */ - public boolean contains(float x, float y){ - if(x<low[0] || x>high[0]){ - return false; - } - if(y<low[1]|| y>high[1]){ - return false; - } - return true; - } - - /** Check if the xyz coordinates are bounded/contained - * by this AABBox. - * @param x x-axis coordinate value - * @param y y-axis coordinate value - * @param z z-axis coordinate value - * @return true if x belong to (low.x, high.x) and - * y belong to (low.y, high.y) and z belong to (low.z, high.z) - */ - public boolean contains(float x, float y, float z){ - if(x<low[0] || x>high[0]){ - return false; - } - if(y<low[1]|| y>high[1]){ - return false; - } - if(z<low[2] || z>high[2]){ - return false; - } - return true; - } - - /** Check if there is a common region between this AABBox and the passed - * 2D region irrespective of z range - * @param x lower left x-coord - * @param y lower left y-coord - * @param w width - * @param h hight - * @return true if this AABBox might have a common region with this 2D region - */ - public boolean intersects(float x, float y, float w, float h) { - if (w <= 0 || h <= 0) { - return false; - } - - final float _w = getWidth(); - final float _h = getHeight(); - if (_w <= 0 || _h <= 0) { - return false; - } - - final float x0 = getMinX(); - final float y0 = getMinY(); - return (x + w > x0 && - y + h > y0 && - x < x0 + _w && - y < y0 + _h); - } - - - /** Get the size of the Box where the size is represented by the - * length of the vector between low and high. - * @return a float representing the size of the AABBox - */ - public float getSize(){ - return VectorUtil.computeLength(low, high); - } - - /**Get the Center of the AABBox - * @return the xyz-coordinates of the center of the AABBox - */ - public float[] getCenter() { - return center; - } - - /** Scale the AABBox by a constant - * @param size a constant float value - */ - public void scale(float size) { - float[] diffH = new float[3]; - diffH[0] = high[0] - center[0]; - diffH[1] = high[1] - center[1]; - diffH[2] = high[2] - center[2]; - - diffH = VectorUtil.scale(diffH, size); - - float[] diffL = new float[3]; - diffL[0] = low[0] - center[0]; - diffL[1] = low[1] - center[1]; - diffL[2] = low[2] - center[2]; - - diffL = VectorUtil.scale(diffL, size); - - high = VectorUtil.vectorAdd(center, diffH); - low = VectorUtil.vectorAdd(center, diffL); - } - - public float getMinX() { - return low[0]; - } - - public float getMinY() { - return low[1]; - } - - public float getWidth(){ - return high[0] - low[0]; - } - - public float getHeight() { - return high[1] - low[1]; - } - - public float getDepth() { - return high[2] - low[2]; - } - public AABBox clone(){ - return new AABBox(this.low, this.high); - } - - public String toString() { - return "[ "+low[0]+"/"+low[1]+"/"+low[1]+" .. "+high[0]+"/"+high[0]+"/"+high[0]+", ctr "+ - center[0]+"/"+center[1]+"/"+center[1]+" ]"; - } -} diff --git a/src/com/jogamp/graph/geom/Outline.java b/src/com/jogamp/graph/geom/Outline.java deleted file mode 100644 index a805adf6c..000000000 --- a/src/com/jogamp/graph/geom/Outline.java +++ /dev/null @@ -1,176 +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 com.jogamp.graph.geom; - -import java.util.ArrayList; - -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.math.VectorUtil; - - - -/** Define a single continuous stroke by control vertices. - * The vertices define the shape of the region defined by this - * outline. The Outline can contain a list of off-curve and on-curve - * vertices which define curved regions. - * - * Note: An outline should be closed to be rendered as a region. - * - * @see OutlineShape, Region - */ -public class Outline implements Comparable<Outline> { - - private ArrayList<Vertex> vertices = new ArrayList<Vertex>(3); - private boolean closed = false; - private AABBox box = new AABBox(); - - /**Create an outline defined by control vertices. - * An outline can contain off Curve vertices which define curved - * regions in the outline. - */ - public Outline(){ - - } - - /** Add a vertex to the outline. The {@link Vertex} is added at the - * end of the outline loop/strip. - * @param vertex Vertex to be added - */ - public final void addVertex(Vertex vertex) { - vertices.add(vertex); - box.resize(vertex.getX(), vertex.getY(), vertex.getZ()); - } - - /** Add a {@link Vertex} by specifying its 2D attributes to the outline. - * The {@link Vertex} is added at the - * end of the outline loop/strip. - * @param factory a {@link Factory} to get the required Vertex impl - * @param x the x coordinate - * @param y the y coordinate - * @param onCurve flag if this vertex is on the final curve or defines a curved region - * of the shape around this vertex. - */ - public final void addVertex(Vertex.Factory<? extends Vertex> factory, float x, float y, boolean onCurve) { - addVertex(factory, x, y, 0f, onCurve); - } - - /** Add a {@link Vertex} by specifying its 3D attributes to the outline. - * The {@link Vertex} is added at the - * end of the outline loop/strip. - * @param factory a {@link Factory} to get the required Vertex impl - * @param x the x coordinate - * @param y the y coordinate - * @param z the z coordinate - * @param onCurve flag if this vertex is on the final curve or defines a curved region - * of the shape around this vertex. - */ - public final void addVertex(Vertex.Factory<? extends Vertex> factory, float x, float y, float z, boolean onCurve) { - Vertex v = factory.create(x, y, z); - v.setOnCurve(onCurve); - addVertex(v); - } - - /** Add a vertex to the outline by passing a float array and specifying the - * offset and length in which. The attributes of the vertex are located. - * The attributes should be continuous (stride = 0). - * Attributes which value are not set (when length less than 3) - * are set implicitly to zero. - * @param factory a {@link Factory} to get the required Vertex impl - * @param coordsBuffer the coordinate array where the vertex attributes are to be picked from - * @param offset the offset in the buffer to the x coordinate - * @param length the number of attributes to pick from the buffer (maximum 3) - * @param onCurve flag if this vertex is on the final curve or defines a curved region - * of the shape around this vertex. - */ - public final void addVertex(Vertex.Factory<? extends Vertex> factory, float[] coordsBuffer, int offset, int length, boolean onCurve) { - Vertex v = factory.create(coordsBuffer, offset, length); - v.setOnCurve(onCurve); - addVertex(v); - } - - public Vertex getVertex(int index){ - return vertices.get(index); - } - - public boolean isEmpty(){ - return (vertices.size() == 0); - } - public Vertex getLastVertex(){ - if(isEmpty()){ - return null; - } - return vertices.get(vertices.size()-1); - } - - public ArrayList<Vertex> getVertices() { - return vertices; - } - public void setVertices(ArrayList<Vertex> vertices) { - this.vertices = vertices; - } - public AABBox getBox() { - return box; - } - public boolean isClosed() { - return closed; - } - - /** define if this outline is closed or not. - * if set to closed, checks if the last vertex is - * equal to the first vertex. If not Equal adds a - * vertex at the end to the list. - * @param closed - */ - public void setClosed(boolean closed) { - this.closed = closed; - if(closed){ - Vertex first = vertices.get(0); - Vertex last = getLastVertex(); - if(!VectorUtil.checkEquality(first.getCoord(), last.getCoord())){ - Vertex v = first.clone(); - vertices.add(v); - } - } - } - - /** Compare two outlines with Bounding Box area - * as criteria. - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - public int compareTo(Outline outline) { - float size = box.getSize(); - float newSize = outline.getBox().getSize(); - if(size < newSize){ - return -1; - } - else if(size > newSize){ - return 1; - } - return 0; - } -} diff --git a/src/com/jogamp/graph/geom/opengl/SVertex.java b/src/com/jogamp/graph/geom/opengl/SVertex.java deleted file mode 100644 index 681067e40..000000000 --- a/src/com/jogamp/graph/geom/opengl/SVertex.java +++ /dev/null @@ -1,178 +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 com.jogamp.graph.geom.opengl; - - -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.math.VectorUtil; - -/** A Simple Vertex Implementation. Where the coordinates, and other attributes are - * float based, and the coordinates and texture coordinates are saved in two float arrays. - * - */ -public class SVertex implements Vertex { - private int id = Integer.MAX_VALUE; - protected float[] coord = new float[3]; - protected boolean onCurve = true; - private float[] texCoord = new float[2]; - - static final Factory factory = new Factory(); - - public static Factory factory() { return factory; } - - public static class Factory implements Vertex.Factory<SVertex> { - @Override - public SVertex create() { - return new SVertex(); - } - - @Override - public SVertex create(float x, float y) { - return new SVertex(x, y); - } - - @Override - public SVertex create(float x, float y, float z) { - return new SVertex(x, y, z); - } - - @Override - public SVertex create(float[] coordsBuffer, int offset, int length) { - return new SVertex(coordsBuffer, offset, length); - } - } - - public SVertex() { - } - - public SVertex(float x, float y) { - setCoord(x, y); - } - public SVertex(float x, float y, float z) { - setCoord(x, y, z); - } - public SVertex(float[] coordsBuffer, int offset, int length) { - setCoord(coordsBuffer, offset, length); - } - - public void setCoord(float x, float y) { - this.coord[0] = x; - this.coord[1] = y; - this.coord[2] = 0f; - } - - public void setCoord(float x, float y, float z) { - this.coord[0] = x; - this.coord[1] = y; - this.coord[2] = z; - } - - public void setCoord(float[] coordsBuffer, int offset, int length) { - if(length > coordsBuffer.length - offset) { - throw new IndexOutOfBoundsException("coordsBuffer too small: "+coordsBuffer.length+" - "+offset+" < "+length); - } - if(length > 3) { - throw new IndexOutOfBoundsException("length too big: "+length+" > "+3); - } - int i=0; - while(i<length) { - this.coord[i++] = coordsBuffer[offset++]; - } - } - - public float[] getCoord() { - return coord; - } - - public void setX(float x) { - this.coord[0] = x; - } - - public void setY(float y) { - this.coord[1] = y; - } - - public void setZ(float z) { - this.coord[2] = z; - } - - public float getX() { - return this.coord[0]; - } - - public float getY() { - return this.coord[1]; - } - - public float getZ() { - return this.coord[2]; - } - - public boolean isOnCurve() { - return onCurve; - } - - public void setOnCurve(boolean onCurve) { - this.onCurve = onCurve; - } - - public int getId(){ - return id; - } - - public void setId(int id){ - this.id = id; - } - - public int compareTo(Vertex p) { - if(VectorUtil.checkEquality(coord, p.getCoord())) { - return 0; - } - return -1; - } - - public float[] getTexCoord() { - return texCoord; - } - - public void setTexCoord(float s, float t) { - this.texCoord[0] = s; - this.texCoord[1] = t; - } - - public SVertex clone(){ - SVertex v = new SVertex(this.coord, 0, 3); - v.setOnCurve(this.onCurve); - return v; - } - - public String toString() { - return "[ID: " + id + " X: " + coord[0] - + " Y: " + coord[1] + " Z: " + coord[2] + "]"; - } -} diff --git a/src/com/jogamp/graph/math/Quaternion.java b/src/com/jogamp/graph/math/Quaternion.java deleted file mode 100755 index b77a5fa08..000000000 --- a/src/com/jogamp/graph/math/Quaternion.java +++ /dev/null @@ -1,382 +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 com.jogamp.graph.math;
-
-import jogamp.graph.math.MathFloat;
-
-public class Quaternion {
- protected float x,y,z,w;
-
- public Quaternion(){
-
- }
-
- public Quaternion(float x, float y, float z, float w) {
- this.x = x;
- this.y = y;
- this.z = z;
- this.w = w;
- }
-
- /** Constructor to create a rotation based quaternion from two vectors
- * @param vector1
- * @param vector2
- */
- public Quaternion(float[] vector1, float[] vector2)
- {
- float theta = (float)MathFloat.acos(dot(vector1, vector2));
- float[] cross = cross(vector1,vector2);
- cross = normalizeVec(cross);
-
- this.x = (float)MathFloat.sin(theta/2)*cross[0];
- this.y = (float)MathFloat.sin(theta/2)*cross[1];
- this.z = (float)MathFloat.sin(theta/2)*cross[2];
- this.w = (float)MathFloat.cos(theta/2);
- this.normalize();
- }
-
- /** Transform the rotational quaternion to axis based rotation angles
- * @return new float[4] with ,theta,Rx,Ry,Rz
- */
- public float[] toAxis()
- {
- float[] vec = new float[4];
- float scale = (float)MathFloat.sqrt(x * x + y * y + z * z);
- vec[0] =(float) MathFloat.acos(w) * 2.0f;
- vec[1] = x / scale;
- vec[2] = y / scale;
- vec[3] = z / scale;
- return vec;
- }
-
- /** Normalize a vector
- * @param vector input vector
- * @return normalized vector
- */
- private float[] normalizeVec(float[] vector)
- {
- float[] newVector = new float[3];
-
- float d = MathFloat.sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]);
- if(d> 0.0f)
- {
- newVector[0] = vector[0]/d;
- newVector[1] = vector[1]/d;
- newVector[2] = vector[2]/d;
- }
- return newVector;
- }
- /** compute the dot product of two points
- * @param vec1 vector 1
- * @param vec2 vector 2
- * @return the dot product as float
- */
- private float dot(float[] vec1, float[] vec2)
- {
- return (vec1[0]*vec2[0] + vec1[1]*vec2[1] + vec1[2]*vec2[2]);
- }
- /** cross product vec1 x vec2
- * @param vec1 vector 1
- * @param vec2 vecttor 2
- * @return the resulting vector
- */
- private float[] cross(float[] vec1, float[] vec2)
- {
- float[] out = new float[3];
-
- out[0] = vec2[2]*vec1[1] - vec2[1]*vec1[2];
- out[1] = vec2[0]*vec1[2] - vec2[2]*vec1[0];
- out[2] = vec2[1]*vec1[0] - vec2[0]*vec1[1];
-
- return out;
- }
- public float getW() {
- return w;
- }
- public void setW(float w) {
- this.w = w;
- }
- public float getX() {
- return x;
- }
- public void setX(float x) {
- this.x = x;
- }
- public float getY() {
- return y;
- }
- public void setY(float y) {
- this.y = y;
- }
- public float getZ() {
- return z;
- }
- public void setZ(float z) {
- this.z = z;
- }
-
- /** Add a quaternion
- * @param q quaternion
- */
- public void add(Quaternion q)
- {
- x+=q.x;
- y+=q.y;
- z+=q.z;
- }
-
- /** Subtract a quaternion
- * @param q quaternion
- */
- public void subtract(Quaternion q)
- {
- x-=q.x;
- y-=q.y;
- z-=q.z;
- }
-
- /** Divide a quaternion by a constant
- * @param n a float to divide by
- */
- public void divide(float n)
- {
- x/=n;
- y/=n;
- z/=n;
- }
-
- /** Multiply this quaternion by
- * the param quaternion
- * @param q a quaternion to multiply with
- */
- public void mult(Quaternion q)
- {
- float w1 = w*q.w - (x*q.x + y*q.y + z*q.z);
-
- float x1 = w*q.z + q.w*z + y*q.z - z*q.y;
- float y1 = w*q.x + q.w*x + z*q.x - x*q.z;
- float z1 = w*q.y + q.w*y + x*q.y - y*q.x;
-
- w = w1;
- x = x1;
- y = y1;
- z = z1;
- }
-
- /** Multiply a quaternion by a constant
- * @param n a float constant
- */
- public void mult(float n)
- {
- x*=n;
- y*=n;
- z*=n;
- }
-
- /** Normalize a quaternion required if
- * to be used as a rotational quaternion
- */
- public void normalize()
- {
- float norme = (float)MathFloat.sqrt(w*w + x*x + y*y + z*z);
- if (norme == 0.0f)
- {
- w = 1.0f;
- x = y = z = 0.0f;
- }
- else
- {
- float recip = 1.0f/norme;
-
- w *= recip;
- x *= recip;
- y *= recip;
- z *= recip;
- }
- }
-
- /** Invert the quaternion If rotational,
- * will produce a the inverse rotation
- */
- public void inverse()
- {
- float norm = w*w + x*x + y*y + z*z;
-
- float recip = 1.0f/norm;
-
- w *= recip;
- x = -1*x*recip;
- y = -1*y*recip;
- z = -1*z*recip;
- }
-
- /** Transform this quaternion to a
- * 4x4 column matrix representing the rotation
- * @return new float[16] column matrix 4x4
- */
- public float[] toMatrix()
- {
- float[] matrix = new float[16];
- matrix[0] = 1.0f - 2*y*y - 2*z*z;
- matrix[1] = 2*x*y + 2*w*z;
- matrix[2] = 2*x*z - 2*w*y;
- matrix[3] = 0;
-
- matrix[4] = 2*x*y - 2*w*z;
- matrix[5] = 1.0f - 2*x*x - 2*z*z;
- matrix[6] = 2*y*z + 2*w*x;
- matrix[7] = 0;
-
- matrix[8] = 2*x*z + 2*w*y;
- matrix[9] = 2*y*z - 2*w*x;
- matrix[10] = 1.0f - 2*x*x - 2*y*y;
- matrix[11] = 0;
-
- matrix[12] = 0;
- matrix[13] = 0;
- matrix[14] = 0;
- matrix[15] = 1;
- return matrix;
- }
-
- /** Set this quaternion from a Sphereical interpolation
- * of two param quaternion, used mostly for rotational animation
- * @param a initial quaternion
- * @param b target quaternion
- * @param t float between 0 and 1 representing interp.
- */
- public void slerp(Quaternion a,Quaternion b, float t)
- {
- float omega, cosom, sinom, sclp, sclq;
- cosom = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w;
- if ((1.0f+cosom) > MathFloat.E) {
- if ((1.0f-cosom) > MathFloat.E) {
- omega = (float)MathFloat.acos(cosom);
- sinom = (float)MathFloat.sin(omega);
- sclp = (float)MathFloat.sin((1.0f-t)*omega) / sinom;
- sclq = (float)MathFloat.sin(t*omega) / sinom;
- }
- else {
- sclp = 1.0f - t;
- sclq = t;
- }
- x = sclp*a.x + sclq*b.x;
- y = sclp*a.y + sclq*b.y;
- z = sclp*a.z + sclq*b.z;
- w = sclp*a.w + sclq*b.w;
- }
- else {
- x =-a.y;
- y = a.x;
- z =-a.w;
- w = a.z;
- sclp = MathFloat.sin((1.0f-t) * MathFloat.PI * 0.5f);
- sclq = MathFloat.sin(t * MathFloat.PI * 0.5f);
- x = sclp*a.x + sclq*b.x;
- y = sclp*a.y + sclq*b.y;
- z = sclp*a.z + sclq*b.z;
- }
- }
-
- /** Check if this quaternion is empty, ie (0,0,0,1)
- * @return true if empty, false otherwise
- */
- public boolean isEmpty()
- {
- if (w==1 && x==0 && y==0 && z==0)
- return true;
- return false;
- }
-
- /** Check if this quaternion represents an identity
- * matrix, for rotation.
- * @return true if it is an identity rep., false otherwise
- */
- public boolean isIdentity()
- {
- if (w==0 && x==0 && y==0 && z==0)
- return true;
- return false;
- }
-
- /** compute the quaternion from a 3x3 column matrix
- * @param m 3x3 column matrix
- */
- public void setFromMatrix(float[] m) {
- float T= m[0] + m[4] + m[8] + 1;
- if (T>0){
- float S = 0.5f / (float)MathFloat.sqrt(T);
- w = 0.25f / S;
- x = ( m[5] - m[7]) * S;
- y = ( m[6] - m[2]) * S;
- z = ( m[1] - m[3] ) * S;
- }
- else{
- if ((m[0] > m[4])&(m[0] > m[8])) {
- float S = MathFloat.sqrt( 1.0f + m[0] - m[4] - m[8] ) * 2f; // S=4*qx
- w = (m[7] - m[5]) / S;
- x = 0.25f * S;
- y = (m[3] + m[1]) / S;
- z = (m[6] + m[2]) / S;
- }
- else if (m[4] > m[8]) {
- float S = MathFloat.sqrt( 1.0f + m[4] - m[0] - m[8] ) * 2f; // S=4*qy
- w = (m[6] - m[2]) / S;
- x = (m[3] + m[1]) / S;
- y = 0.25f * S;
- z = (m[7] + m[5]) / S;
- }
- else {
- float S = MathFloat.sqrt( 1.0f + m[8] - m[0] - m[4] ) * 2f; // S=4*qz
- w = (m[3] - m[1]) / S;
- x = (m[6] + m[2]) / S;
- y = (m[7] + m[5]) / S;
- z = 0.25f * S;
- }
- }
- }
-
- /** Check if the the 3x3 matrix (param) is in fact
- * an affine rotational matrix
- * @param m 3x3 column matrix
- * @return true if representing a rotational matrix, false otherwise
- */
- public boolean isRotationMatrix(float[] m) {
- double epsilon = 0.01; // margin to allow for rounding errors
- if (MathFloat.abs(m[0]*m[3] + m[3]*m[4] + m[6]*m[7]) > epsilon) return false;
- if (MathFloat.abs(m[0]*m[2] + m[3]*m[5] + m[6]*m[8]) > epsilon) return false;
- if (MathFloat.abs(m[1]*m[2] + m[4]*m[5] + m[7]*m[8]) > epsilon) return false;
- if (MathFloat.abs(m[0]*m[0] + m[3]*m[3] + m[6]*m[6] - 1) > epsilon) return false;
- if (MathFloat.abs(m[1]*m[1] + m[4]*m[4] + m[7]*m[7] - 1) > epsilon) return false;
- if (MathFloat.abs(m[2]*m[2] + m[5]*m[5] + m[8]*m[8] - 1) > epsilon) return false;
- return (MathFloat.abs(determinant(m)-1) < epsilon);
- }
- private float determinant(float[] m) {
- return m[0]*m[4]*m[8] + m[3]*m[7]*m[2] + m[6]*m[1]*m[5] - m[0]*m[7]*m[5] - m[3]*m[1]*m[8] - m[6]*m[4]*m[2];
- }
-}
diff --git a/src/com/jogamp/graph/math/VectorUtil.java b/src/com/jogamp/graph/math/VectorUtil.java deleted file mode 100755 index cca9a454f..000000000 --- a/src/com/jogamp/graph/math/VectorUtil.java +++ /dev/null @@ -1,295 +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 com.jogamp.graph.math;
-
-import java.util.ArrayList;
-
-import jogamp.graph.math.MathFloat;
-
-import com.jogamp.graph.geom.Vertex;
-
-public class VectorUtil {
-
- public static final int CW = -1;
- public static final int CCW = 1;
- public static final int COLLINEAR = 0;
-
- /** compute the dot product of two points
- * @param vec1 vector 1
- * @param vec2 vector 2
- * @return the dot product as float
- */
- public static float dot(float[] vec1, float[] vec2)
- {
- return (vec1[0]*vec2[0] + vec1[1]*vec2[1] + vec1[2]*vec2[2]);
- }
- /** Normalize a vector
- * @param vector input vector
- * @return normalized vector
- */
- public static float[] normalize(float[] vector)
- {
- float[] newVector = new float[3];
-
- float d = MathFloat.sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]);
- if(d> 0.0f)
- {
- newVector[0] = vector[0]/d;
- newVector[1] = vector[1]/d;
- newVector[2] = vector[2]/d;
- }
- return newVector;
- }
-
- /** Scales a vector by param
- * @param vector input vector
- * @param scale constant to scale by
- * @return scaled vector
- */
- public static float[] scale(float[] vector, float scale)
- {
- float[] newVector = new float[3];
-
- newVector[0] = vector[0]*scale;
- newVector[1] = vector[1]*scale;
- newVector[2] = vector[2]*scale;
- return newVector;
- }
-
- /** Adds to vectors
- * @param v1 vector 1
- * @param v2 vector 2
- * @return v1 + v2
- */
- public static float[] vectorAdd(float[] v1, float[] v2)
- {
- float[] newVector = new float[3];
-
- newVector[0] = v1[0] + v2[0];
- newVector[1] = v1[1] + v2[1];
- newVector[2] = v1[2] + v2[2];
- return newVector;
- }
-
- /** cross product vec1 x vec2
- * @param vec1 vector 1
- * @param vec2 vecttor 2
- * @return the resulting vector
- */
- public static float[] cross(float[] vec1, float[] vec2)
- {
- float[] out = new float[3];
-
- out[0] = vec2[2]*vec1[1] - vec2[1]*vec1[2];
- out[1] = vec2[0]*vec1[2] - vec2[2]*vec1[0];
- out[2] = vec2[1]*vec1[0] - vec2[0]*vec1[1];
-
- return out;
- }
-
- /** Column Matrix Vector multiplication
- * @param colMatrix column matrix (4x4)
- * @param vec vector(x,y,z)
- * @return result new float[3]
- */
- public static float[] colMatrixVectorMult(float[] colMatrix, float[] vec)
- {
- float[] out = new float[3];
-
- out[0] = vec[0]*colMatrix[0] + vec[1]*colMatrix[4] + vec[2]*colMatrix[8] + colMatrix[12];
- out[1] = vec[0]*colMatrix[1] + vec[1]*colMatrix[5] + vec[2]*colMatrix[9] + colMatrix[13];
- out[2] = vec[0]*colMatrix[2] + vec[1]*colMatrix[6] + vec[2]*colMatrix[10] + colMatrix[14];
-
- return out;
- }
-
- /** Matrix Vector multiplication
- * @param rawMatrix column matrix (4x4)
- * @param vec vector(x,y,z)
- * @return result new float[3]
- */
- public static float[] rowMatrixVectorMult(float[] rawMatrix, float[] vec)
- {
- float[] out = new float[3];
-
- out[0] = vec[0]*rawMatrix[0] + vec[1]*rawMatrix[1] + vec[2]*rawMatrix[2] + rawMatrix[3];
- out[1] = vec[0]*rawMatrix[4] + vec[1]*rawMatrix[5] + vec[2]*rawMatrix[6] + rawMatrix[7];
- out[2] = vec[0]*rawMatrix[8] + vec[1]*rawMatrix[9] + vec[2]*rawMatrix[10] + rawMatrix[11];
-
- return out;
- }
-
- /** Calculate the midpoint of two values
- * @param p1 first value
- * @param p2 second vale
- * @return midpoint
- */
- public static float mid(float p1, float p2)
- {
- return (p1+p2)/2.0f;
- }
- /** Calculate the midpoint of two points
- * @param p1 first point
- * @param p2 second point
- * @return midpoint
- */
- public static float[] mid(float[] p1, float[] p2)
- {
- float[] midPoint = new float[3];
- midPoint[0] = (p1[0] + p2[0])/2.0f;
- midPoint[1] = (p1[1] + p2[1])/2.0f;
- midPoint[2] = (p1[2] + p2[2])/2.0f;
-
- return midPoint;
- }
- /** Compute the norm of a vector
- * @param vec vector
- * @return vorm
- */
- public static float norm(float[] vec)
- {
- return MathFloat.sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]);
- }
- /** Compute distance between 2 points
- * @param p0 a ref point on the line
- * @param vec vector representing the direction of the line
- * @param point the point to compute the relative distance of
- * @return distance float
- */
- public static float computeLength(float[] p0, float[] point)
- {
- float[] w = new float[]{point[0]-p0[0],point[1]-p0[1],point[2]-p0[2]};
-
- float distance = MathFloat.sqrt(w[0]*w[0] + w[1]*w[1] + w[2]*w[2]);
-
- return distance;
- }
-
- /**Check equality of 2 vec3 vectors
- * @param v1 vertex 1
- * @param v2 vertex 2
- * @return
- */
- public static boolean checkEquality(float[] v1, float[] v2)
- {
- if(Float.compare(v1[0], v2[0]) == 0
- && Float.compare(v1[1] , v2[1]) == 0
- && Float.compare(v1[2], v2[2]) == 0 )
- return true;
- return false;
- }
-
- /** Compute the determinant of 3 vectors
- * @param a vector 1
- * @param b vector 2
- * @param c vector 3
- * @return the determinant value
- */
- public static float computeDeterminant(float[] a, float[] b, float[] c)
- {
- float area = a[0]*b[1]*c[2] + a[1]*b[2]*c[0] + a[2]*b[0]*c[1] - a[0]*b[2]*c[1] - a[1]*b[0]*c[2] - a[2]*b[1]*c[0];
- return area;
- }
-
- /** Check if three vertices are colliniear
- * @param v1 vertex 1
- * @param v2 vertex 2
- * @param v3 vertex 3
- * @return true if collinear, false otherwise
- */
- public static boolean checkCollinear(float[] v1, float[] v2, float[] v3)
- {
- return (computeDeterminant(v1, v2, v3) == VectorUtil.COLLINEAR);
- }
-
- /** Compute Vector
- * @param v1 vertex 1
- * @param v2 vertex2 2
- * @return Vector V1V2
- */
- public static float[] computeVector(float[] v1, float[] v2)
- {
- float[] vector = new float[3];
- vector[0] = v2[0] - v1[0];
- vector[1] = v2[1] - v1[1];
- vector[2] = v2[2] - v1[2];
- return vector;
- }
-
- /** Check if vertices in triangle circumcircle
- * @param a triangle vertex 1
- * @param b triangle vertex 2
- * @param c triangle vertex 3
- * @param d vertex in question
- * @return true if the vertex d is inside the circle defined by the
- * vertices a, b, c. from paper by Guibas and Stolfi (1985).
- */
- public static boolean inCircle(Vertex a, Vertex b, Vertex c, Vertex d){
- return (a.getX() * a.getX() + a.getY() * a.getY()) * triArea(b, c, d) -
- (b.getX() * b.getX() + b.getY() * b.getY()) * triArea(a, c, d) +
- (c.getX() * c.getX() + c.getY() * c.getY()) * triArea(a, b, d) -
- (d.getX() * d.getX() + d.getY() * d.getY()) * triArea(a, b, c) > 0;
- }
-
- /** Computes oriented area of a triangle
- * @param a first vertex
- * @param b second vertex
- * @param c third vertex
- * @return compute twice the area of the oriented triangle (a,b,c), the area
- * is positive if the triangle is oriented counterclockwise.
- */
- public static float triArea(Vertex a, Vertex b, Vertex c){
- return (b.getX() - a.getX()) * (c.getY() - a.getY()) - (b.getY() - a.getY())*(c.getX() - a.getX());
- }
-
- /** Check if points are in ccw order
- * @param a first vertex
- * @param b second vertex
- * @param c third vertex
- * @return true if the points a,b,c are in a ccw order
- */
- public static boolean ccw(Vertex a, Vertex b, Vertex c){
- return triArea(a,b,c) > 0;
- }
-
- /** Computes the area of a list of vertices to check if ccw
- * @param vertices
- * @return positve area if ccw else negative area value
- */
- public static float area(ArrayList<Vertex> vertices) {
- int n = vertices.size();
- float area = 0.0f;
- for (int p = n - 1, q = 0; q < n; p = q++)
- {
- float[] pCoord = vertices.get(p).getCoord();
- float[] qCoord = vertices.get(q).getCoord();
- area += pCoord[0] * qCoord[1] - qCoord[0] * pCoord[1];
- }
- return area;
- }
-}
diff --git a/src/com/jogamp/opengl/test/junit/graph/TestRegionRenderer01.java b/src/com/jogamp/opengl/test/junit/graph/TestRegionRenderer01.java deleted file mode 100644 index 9ad4eb41a..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/TestRegionRenderer01.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.jogamp.opengl.test.junit.graph;
-
-import java.io.IOException;
-
-import javax.media.nativewindow.NativeWindowFactory;
-import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLCapabilitiesImmutable;
-import javax.media.opengl.GLEventListener;
-import javax.media.opengl.GLException;
-import javax.media.opengl.GLProfile;
-
-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;
-
-
-public class TestRegionRenderer01 {
-
- public static void main(String args[]) throws IOException {
- String tstname = TestRegionRenderer01.class.getName();
- org.junit.runner.JUnitCore.main(tstname);
- }
-
- @BeforeClass
- public static void initClass() {
- GLProfile.initSingleton(true);
- NativeWindowFactory.initSingleton(true);
- }
-
- static void destroyWindow(GLWindow window) {
- if(null!=window) {
- window.destroy();
- }
- }
-
- static GLWindow createWindow(String title, GLCapabilitiesImmutable caps, int width, int height) {
- Assert.assertNotNull(caps);
-
- GLWindow window = GLWindow.create(caps);
- window.setSize(width, height);
- window.setPosition(10, 10);
- window.setTitle(title);
- Assert.assertNotNull(window);
- window.setVisible(true);
-
- return window;
- }
-
- @Test
- public void testRegionRendererR2T01() throws InterruptedException {
- GLProfile glp = GLProfile.getGL2ES2();
-
- GLCapabilities caps = new GLCapabilities(glp);
- //caps.setOnscreen(false);
- caps.setAlphaBits(4);
-
- GLWindow window = createWindow("shape-r2t1-msaa0", caps, 800,400);
-
- 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);
-
- listener.setTech(-20, 00, 0f, -300, 400);
- window.display();
-
- listener.setTech(-20, 00, 0f, -150, 800);
- window.display();
-
- listener.setTech(-20, 00, 0f, -50, 1000);
- window.display();
-
- destroyWindow(window);
- }
-
- @Test
- public void testRegionRendererMSAA01() throws InterruptedException {
- GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
- GLCapabilities caps = new GLCapabilities(glp);
- // caps.setOnscreen(false);
- caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(4);
-
- GLWindow window = createWindow("shape-r2t0-msaa1", caps, 800, 400);
-
- 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);
- window.display();
-
- listener.setTech(-20, 00, 0f, -150, 800);
- window.display();
-
- listener.setTech(-20, 00, 0f, -50, 1000);
- window.display();
-
- destroyWindow(window);
- }
-
- private class RegionGLListener implements GLEventListener {
- String winTitle;
- String name;
- GPURegionRendererListenerBase01 impl;
-
- public RegionGLListener(GPURegionRendererListenerBase01 impl, String title, String name) {
- this.impl = impl;
- this.winTitle = title;
- this.name = name;
- }
-
- public void setTech(float xt, float yt, float angle, int zoom, int fboSize){
- impl.setMatrix(xt, yt, angle, zoom, fboSize);
- }
-
- public void init(GLAutoDrawable drawable) {
- impl.init(drawable);
- }
-
- public void display(GLAutoDrawable drawable) {
- impl.display(drawable);
-
- try {
- impl.printScreen(drawable, "./", winTitle, name, false);
- } catch (GLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public void dispose(GLAutoDrawable drawable) {
- impl.dispose(drawable);
-
- }
-
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- impl.reshape(drawable, x, y, width, height);
-
- }
- }
-}
diff --git a/src/com/jogamp/opengl/test/junit/graph/TestTextRenderer01.java b/src/com/jogamp/opengl/test/junit/graph/TestTextRenderer01.java deleted file mode 100755 index c954c6aa7..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/TestTextRenderer01.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.jogamp.opengl.test.junit.graph;
-
-import java.io.IOException;
-
-import javax.media.nativewindow.NativeWindowFactory;
-import javax.media.opengl.GL;
-import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLCapabilitiesImmutable;
-import javax.media.opengl.GLException;
-import javax.media.opengl.GLProfile;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.jogamp.graph.curve.Region;
-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;
-
-
-public class TestTextRenderer01 {
-
- public static void main(String args[]) throws IOException {
- String tstname = TestTextRenderer01.class.getName();
- org.junit.runner.JUnitCore.main(tstname);
- }
-
- @BeforeClass
- public static void initClass() {
- GLProfile.initSingleton(true);
- NativeWindowFactory.initSingleton(true);
- }
-
- static void destroyWindow(GLWindow window) {
- if(null!=window) {
- window.destroy();
- }
- }
-
- static GLWindow createWindow(String title, GLCapabilitiesImmutable caps, int width, int height) {
- Assert.assertNotNull(caps);
-
- GLWindow window = GLWindow.create(caps);
- window.setSize(width, height);
- window.setPosition(10, 10);
- window.setTitle(title);
- Assert.assertNotNull(window);
- window.setVisible(true);
-
- return window;
- }
-
- @Test
- public void testTextRendererR2T01() throws InterruptedException {
- GLProfile glp = GLProfile.getGL2ES2();
-
- GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
-
- GLWindow window = createWindow("text-r2t1-msaa0", caps, 800,400);
- TextGLListener textGLListener = new TextGLListener(Region.TWO_PASS);
- textGLListener.attachInputListenerTo(window);
- window.addGLEventListener(textGLListener);
-
- textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0);
- textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
- window.display();
-
- textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
- window.display();
-
- textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
- window.display();
-
- textGLListener.setFontSet(FontFactory.JAVA, 0, 0);
- textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
- window.display();
-
- textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
- window.display();
-
- textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
- window.display();
-
- destroyWindow(window);
- }
-
- @Test
- public void testTextRendererMSAA01() throws InterruptedException {
- GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
- GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(4);
-
- GLWindow window = createWindow("text-r2t0-msaa1", caps, 800, 400);
- TextGLListener textGLListener = new TextGLListener(Region.SINGLE_PASS);
- textGLListener.attachInputListenerTo(window);
- window.addGLEventListener(textGLListener);
-
- textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0);
- textGLListener.setTech(-400, -30, 0f, -1000, 0);
- window.display();
-
- textGLListener.setTech(-400, -30, 0, -380, 0);
- window.display();
-
- textGLListener.setTech(-400, -20, 0, -80, 0);
- window.display();
-
- textGLListener.setFontSet(FontFactory.JAVA, 0, 0);
- textGLListener.setTech(-400, -30, 0f, -1000, 0);
- window.display();
-
- textGLListener.setTech(-400, -30, 0, -380, 0);
- window.display();
-
- textGLListener.setTech(-400, -20, 0, -80, 0);
- window.display();
-
- destroyWindow(window);
- }
-
- private class TextGLListener extends GPUTextRendererListenerBase01 {
- String winTitle;
-
- public TextGLListener(int type) {
- super(SVertex.factory(), type, false, false);
- }
-
- public void attachInputListenerTo(GLWindow window) {
- super.attachInputListenerTo(window);
- winTitle = window.getTitle();
- }
- public void setTech(float xt, float yt, float angle, int zoom, int fboSize){
- setMatrix(xt, yt, angle, zoom, fboSize);
- }
-
- public void init(GLAutoDrawable drawable) {
- GL2ES2 gl = drawable.getGL().getGL2ES2();
- super.init(drawable);
- gl.setSwapInterval(1);
- gl.glEnable(GL.GL_DEPTH_TEST);
-
- final TextRenderer textRenderer = (TextRenderer) getRenderer();
-
- textRenderer.init(gl);
- textRenderer.setAlpha(gl, 1.0f);
- textRenderer.setColor(gl, 0.0f, 0.0f, 0.0f);
- }
-
- public void display(GLAutoDrawable drawable) {
- super.display(drawable);
-
- try {
- printScreen(drawable, "./", winTitle, false);
- } catch (GLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-}
diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java deleted file mode 100644 index bf4bfab71..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java +++ /dev/null @@ -1,124 +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 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 deleted file mode 100644 index 56db37ebe..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java +++ /dev/null @@ -1,120 +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 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 deleted file mode 100755 index dbd5fe158..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java +++ /dev/null @@ -1,75 +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 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 deleted file mode 100644 index 7ffab59e3..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java +++ /dev/null @@ -1,75 +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 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/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java deleted file mode 100644 index 622178bf2..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java +++ /dev/null @@ -1,264 +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 com.jogamp.opengl.test.junit.graph.demos; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; - -import javax.media.opengl.GL; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLAnimatorControl; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.GLException; -import javax.media.opengl.GLPipelineFactory; -import javax.media.opengl.GLRunnable; - -import com.jogamp.graph.curve.opengl.Renderer; -import com.jogamp.newt.event.KeyEvent; -import com.jogamp.newt.event.KeyListener; -import com.jogamp.newt.opengl.GLWindow; - -/** - * - * Action Keys: - * - 1/2: zoom in/out - * - 6/7: 2nd pass texture size - * - 0/9: rotate - * - v: toggle v-sync - * - s: screenshot - */ -public abstract class GPURendererListenerBase01 implements GLEventListener { - private Screenshot screenshot; - private Renderer renderer; - private boolean debug; - private boolean trace; - - private KeyAction keyAction; - - private volatile GLAutoDrawable autoDrawable = null; - - private final float[] position = new float[] {0,0,0}; - - private float xTran = -10; - private float yTran = 10; - private float ang = 0f; - private float zoom = -70f; - private int texSize = 400; - - boolean updateMatrix = true; - boolean ignoreInput = false; - - public GPURendererListenerBase01(Renderer renderer, boolean debug, boolean trace) { - this.renderer = renderer; - this.debug = debug; - this.trace = trace; - this.screenshot = new Screenshot(); - } - - public final Renderer getRenderer() { return renderer; } - public final float getZoom() { return zoom; } - public final float getXTran() { return xTran; } - public final float getYTran() { return yTran; } - public final float getAngle() { return ang; } - public final int getTexSize() { return texSize; } - public final float[] getPosition() { return position; } - - public void setMatrix(float xtrans, float ytrans, float angle, int zoom, int fbosize) { - this.xTran = xtrans; - this.yTran = ytrans; - this.ang = angle; - this.zoom = zoom; - this.texSize = fbosize; - updateMatrix = true; - } - - public void init(GLAutoDrawable drawable) { - autoDrawable = drawable; - GL2ES2 gl = drawable.getGL().getGL2ES2(); - if(debug) { - gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, gl, null) ).getGL2ES2(); - } - if(trace) { - gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2(); - } - gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - } - - public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glViewport(xstart, ystart, width, height); - renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 7000.0f); - - dumpMatrix(); - } - - public void dispose(GLAutoDrawable drawable) { - autoDrawable = null; - GL2ES2 gl = drawable.getGL().getGL2ES2(); - screenshot.dispose(); - renderer.dispose(gl); - } - - public void zoom(int v){ - zoom += v; - updateMatrix = true; - dumpMatrix(); - } - - public void move(float x, float y){ - xTran += x; - yTran += y; - updateMatrix = true; - dumpMatrix(); - } - public void rotate(float delta){ - ang += delta; - ang %= 360.0f; - updateMatrix = true; - dumpMatrix(); - } - - void dumpMatrix() { - System.err.println("Matrix: " + xTran + "/" + yTran + " x"+zoom + " @"+ang); - } - - /** Attach the input listener to the window */ - public void attachInputListenerTo(GLWindow window) { - if ( null == keyAction ) { - keyAction = new KeyAction(); - window.addKeyListener(keyAction); - } - } - - public void detachFrom(GLWindow window) { - if ( null == keyAction ) { - return; - } - window.removeGLEventListener(this); - window.removeKeyListener(keyAction); - } - - public void printScreen(GLAutoDrawable drawable, String dir, String tech, String objName, boolean exportAlpha) throws GLException, IOException { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zoom), texSize, objName); - - String filename = dir + tech + sw +".tga"; - 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); - } - else if(arg0.getKeyCode() == KeyEvent.VK_2){ - zoom(-10); - } - else if(arg0.getKeyCode() == KeyEvent.VK_UP){ - move(0, -1); - } - else if(arg0.getKeyCode() == KeyEvent.VK_DOWN){ - move(0, 1); - } - else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){ - move(1, 0); - } - else if(arg0.getKeyCode() == KeyEvent.VK_RIGHT){ - move(-1, 0); - } - else if(arg0.getKeyCode() == KeyEvent.VK_6){ - texSize -= 10; - System.err.println("Tex Size: " + texSize); - } - else if(arg0.getKeyCode() == KeyEvent.VK_7){ - texSize += 10; - System.err.println("Tex Size: " + texSize); - } - else if(arg0.getKeyCode() == KeyEvent.VK_0){ - rotate(1); - } - else if(arg0.getKeyCode() == KeyEvent.VK_9){ - rotate(-1); - } - else if(arg0.getKeyCode() == KeyEvent.VK_V) { - if(null != autoDrawable) { - autoDrawable.invoke(false, new GLRunnable() { - public void run(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); - int i = gl.getSwapInterval(); - i = i==0 ? 1 : 0; - gl.setSwapInterval(i); - final GLAnimatorControl a = drawable.getAnimator(); - if( null != a ) { - a.resetCounter(); - } - System.err.println("Swap Interval: "+i); - } - }); - } - } - 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/GPUTextNewtDemo02.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java deleted file mode 100644 index 40c7d6ac4..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java +++ /dev/null @@ -1,76 +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 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; - -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), - * at javax.media.opengl.DebugGL4bc.checkGLGetError(DebugGL4bc.java:33961) - * at javax.media.opengl.DebugGL4bc.glFramebufferRenderbuffer(DebugGL4bc.java:33077) - * at jogamp.graph.curve.opengl.VBORegion2PGL3.initFBOTexture(VBORegion2PGL3.java:295) - */ - 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); - System.out.println("Requested: "+caps); - - GLWindow window = GLWindow.create(caps); - - window.setPosition(10, 10); - window.setSize(800, 400); - window.setTitle("GPU Text Newt Demo 02 - r2t1 msaa0"); - - 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(); - } -} diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java deleted file mode 100644 index 909f68b85..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java +++ /dev/null @@ -1,229 +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 com.jogamp.opengl.test.junit.graph.demos; - -import java.io.IOException; -import javax.media.opengl.GL; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLAnimatorControl; -import javax.media.opengl.GLAutoDrawable; -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; -import com.jogamp.newt.opengl.GLWindow; - -/** - * - * GPURendererListenerBase01 Keys: - * - 1/2: zoom in/out - * - 6/7: 2nd pass texture size - * - 0/9: rotate - * - v: toggle v-sync - * - s: screenshot - * - * Additional Keys: - * - 3/4: font +/- - * - 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; - Font font; - - boolean drawFontSet = true; - boolean drawFPS = true; - boolean updateFont = true; - int fontSize = 40; - final int fontSizeModulo = 100; - - 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(); - } - - public void display(GLAutoDrawable drawable) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Demo02 needs to have this set here as well .. hmm ? - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - final TextRenderer textRenderer = (TextRenderer) getRenderer(); - - if(drawFPS || drawFontSet || updateMatrix) { - final int width = drawable.getWidth(); - final int height = drawable.getHeight(); - final GLAnimatorControl animator = drawable.getAnimator(); - final boolean _drawFPS = drawFPS && null != animator && animator.getTotalFrames()>10; - - if(_drawFPS || drawFontSet) { - textRenderer.reshapeOrtho(null, width, height, 0.1f, 7000.0f); - } - if(_drawFPS) { - final float fps = ( animator.getTotalFrames() * 1000.0f ) / (float) animator.getDuration() ; - final String fpsS = String.valueOf(fps); - final int fpsSp = fpsS.indexOf('.'); - textRenderer.resetModelview(null); - textRenderer.translate(gl, 0, 0, -6000); - textRenderer.renderString3D(gl, font, fpsS.substring(0, fpsSp+2), getPosition(), fontSize, getTexSize()); - } - if(drawFontSet) { - textRenderer.resetModelview(null); - 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) { - textRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f); - } - - textRenderer.resetModelview(null); - textRenderer.translate(null, getXTran(), getYTran(), getZoom()); - textRenderer.rotate(gl, getAngle(), 0, 1, 0); - updateMatrix = false; - } - - 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) { - fontSize = Math.abs((fontSize + v) % fontSizeModulo) ; - updateFont = true; - dumpMatrix(true); - } - - public void nextFontSet() { - fontSet = ( fontSet == FontFactory.UBUNTU ) ? FontFactory.JAVA : FontFactory.UBUNTU ; - font = FontFactory.get(fontSet).getDefault(); - } - - public void setFontSet(int set, int family, int stylebits) { - fontSet = set; - 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) { - System.err.println("bbox: "+font.getStringBounds(text2, fontSize)); - } - } - - KeyAction keyAction = null; - - @Override - public void attachInputListenerTo(GLWindow window) { - if ( null == keyAction ) { - keyAction = new KeyAction(); - window.addKeyListener(keyAction); - super.attachInputListenerTo(window); - } - - } - - @Override - public void detachFrom(GLWindow window) { - super.detachFrom(window); - if ( null == keyAction ) { - return; - } - window.removeKeyListener(keyAction); - } - - public void printScreen(GLAutoDrawable drawable, String dir, String tech, boolean exportAlpha) throws GLException, IOException { - printScreen(drawable, dir, tech, font.getName(), exportAlpha); - } - - 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_H) { - drawFontSet = !drawFontSet; - System.err.println("Draw font set: "+drawFontSet); - } - else if(arg0.getKeyCode() == KeyEvent.VK_F){ - drawFPS = !drawFPS; - System.err.println("Draw FPS: "+drawFPS); - } - 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 keyReleased(KeyEvent arg0) {} - } -}
\ No newline at end of file diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java b/src/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java deleted file mode 100644 index 5975e096b..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java +++ /dev/null @@ -1,69 +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 com.jogamp.opengl.test.junit.graph.demos; - -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GL2GL3; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLCapabilitiesImmutable; - -public class MSAATool { - public static void dump(GLAutoDrawable drawable) { - float[] vf = new float[] { 0f }; - byte[] vb = new byte[] { 0 }; - int[] vi = new int[] { 0, 0 }; - - System.out.println("GL MSAA SETUP:"); - GL2ES2 gl = drawable.getGL().getGL2ES2(); - GLCapabilitiesImmutable caps = drawable.getChosenGLCapabilities(); - System.out.println(" Caps realised "+caps); - System.out.println(" Caps sample buffers "+caps.getSampleBuffers()+", samples "+caps.getNumSamples()); - - // default TRUE - System.out.println(" GL MULTISAMPLE "+gl.glIsEnabled(GL2ES2.GL_MULTISAMPLE)); - // sample buffers min 0, same as GLX_SAMPLE_BUFFERS_ARB or WGL_SAMPLE_BUFFERS_ARB - gl.glGetIntegerv(GL2GL3.GL_SAMPLE_BUFFERS, vi, 0); - // samples min 0 - gl.glGetIntegerv(GL2GL3.GL_SAMPLES, vi, 1); - System.out.println(" GL SAMPLE_BUFFERS "+vi[0]+", SAMPLES "+vi[1]); - - System.out.println("GL CSAA SETUP:"); - // default FALSE - System.out.println(" GL SAMPLE COVERAGE "+gl.glIsEnabled(GL2GL3.GL_SAMPLE_COVERAGE)); - // default FALSE - System.out.println(" GL SAMPLE_ALPHA_TO_COVERAGE "+gl.glIsEnabled(GL2GL3.GL_SAMPLE_ALPHA_TO_COVERAGE)); - // default FALSE - System.out.println(" GL SAMPLE_ALPHA_TO_ONE "+gl.glIsEnabled(GL2GL3.GL_SAMPLE_ALPHA_TO_ONE)); - // default FALSE, value 1, invert false - gl.glGetFloatv(GL2GL3.GL_SAMPLE_COVERAGE_VALUE, vf, 0); - gl.glGetBooleanv(GL2GL3.GL_SAMPLE_COVERAGE_INVERT, vb, 0); - System.out.println(" GL SAMPLE_COVERAGE "+gl.glIsEnabled(GL2GL3.GL_SAMPLE_COVERAGE) + - ": SAMPLE_COVERAGE_VALUE "+vf[0]+ - ", SAMPLE_COVERAGE_INVERT "+vb[0]); - } -} diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/Screenshot.java b/src/com/jogamp/opengl/test/junit/graph/demos/Screenshot.java deleted file mode 100644 index e0c304e49..000000000 --- a/src/com/jogamp/opengl/test/junit/graph/demos/Screenshot.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.jogamp.opengl.test.junit.graph.demos; - -import java.io.File; -import java.io.IOException; - -import javax.media.opengl.GL; -import javax.media.opengl.GLAutoDrawable; - -import com.jogamp.opengl.util.texture.TextureIO; - -public class Screenshot { - - ReadBufferUtil readBufferUtil = new ReadBufferUtil(); - - public void dispose() { - readBufferUtil.dispose(); - } - - public void surface2File(GLAutoDrawable drawable, String filename) { - GL gl = drawable.getGL(); - // FIXME glFinish() is an expensive paranoia sync, should not be necessary due to spec - gl.glFinish(); - readBufferUtil.fetchOffscreenTexture(drawable, gl); - gl.glFinish(); - try { - surface2File(filename); - } catch (IOException ex) { - throw new RuntimeException("can not write survace to file", ex); - } - } - - void surface2File(String filename) throws IOException { - File file = new File(filename); - TextureIO.write(readBufferUtil.getTextureData(), file); - System.err.println("Wrote: " + file.getAbsolutePath() + ", ..."); - readBufferUtil.rewindPixelBuffer(); - } - -} diff --git a/src/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogamp/graph/curve/opengl/RegionRendererImpl01.java deleted file mode 100755 index c1f293fff..000000000 --- a/src/jogamp/graph/curve/opengl/RegionRendererImpl01.java +++ /dev/null @@ -1,206 +0,0 @@ -/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package jogamp.graph.curve.opengl;
-
-import java.nio.FloatBuffer;
-import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLException;
-import javax.media.opengl.GLUniformData;
-import javax.media.opengl.fixedfunc.GLMatrixFunc;
-
-import com.jogamp.graph.curve.OutlineShape;
-import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.RegionRenderer;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.opengl.util.glsl.ShaderCode;
-import com.jogamp.opengl.util.glsl.ShaderProgram;
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-
-public class RegionRendererImpl01 extends RegionRenderer {
- /**Sharpness is equivalent to the value of t value of texture coord
- * on the off-curve vertex. The high value of sharpness will
- * result in high curvature.
- */
- private GLUniformData mgl_sharpness = new GLUniformData("p1y", 0.5f);
- GLUniformData mgl_alpha = new GLUniformData("g_alpha", 1.0f);
- private GLUniformData mgl_color = new GLUniformData("g_color", 3, FloatBuffer.allocate(3));
- private GLUniformData mgl_strength = new GLUniformData("a_strength", 3.0f);
-
- public RegionRendererImpl01(Vertex.Factory<? extends Vertex> factory, int type) {
- super(factory, type);
- }
-
- protected boolean initImpl(GL2ES2 gl) {
- boolean VBOsupported = gl.isFunctionAvailable("glGenBuffers") &&
- gl.isFunctionAvailable("glBindBuffer") &&
- gl.isFunctionAvailable("glBufferData") &&
- gl.isFunctionAvailable("glDrawElements") &&
- gl.isFunctionAvailable("glVertexAttribPointer") &&
- gl.isFunctionAvailable("glDeleteBuffers");
-
- if(DEBUG) {
- System.err.println("RegionRenderer: VBO Supported = " + VBOsupported);
- }
-
- if(!VBOsupported){
- return false;
- }
-
- gl.glEnable(GL2ES2.GL_BLEND);
- gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA);
-
- ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, RegionRendererImpl01.class,
- "shader", "shader/bin", "curverenderer01");
- ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, RegionRendererImpl01.class,
- "shader", "shader/bin", "curverenderer01");
-
- ShaderProgram sp = new ShaderProgram();
- sp.add(rsVp);
- sp.add(rsFp);
-
- if(!sp.link(gl, System.err)) {
- throw new GLException("RegionRenderer: Couldn't link program: "+sp);
- }
-
- st = new ShaderState();
- st.attachShaderProgram(gl, sp);
- gl.glBindAttribLocation(sp.id(), 0, "v_position");
- gl.glBindAttribLocation(sp.id(), 1, "texCoord");
-
- st.glUseProgram(gl, true);
-
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmvMatrix.glLoadIdentity();
-
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- resetModelview(null);
-
- mgl_PMVMatrix = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
- if(!st.glUniform(gl, mgl_PMVMatrix)) {
- if(DEBUG){
- System.err.println("Error setting PMVMatrix in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_sharpness)) {
- if(DEBUG){
- System.err.println("Error setting sharpness in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_alpha)) {
- if(DEBUG){
- System.err.println("Error setting global alpha in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_color)) {
- if(DEBUG){
- System.err.println("Error setting global color in shader: "+st);
- }
- return false;
- }
-
- if(!st.glUniform(gl, mgl_strength)) {
- System.err.println("Error setting antialias strength in shader: "+st);
- }
-
- if(DEBUG) {
- System.err.println("RegionRendererImpl01 initialized: " + Thread.currentThread()+" "+st);
- }
- return true;
- }
-
- @Override
- protected void disposeImpl(GL2ES2 gl) {
- }
-
-
- @Override
- public float getAlpha() {
- return mgl_alpha.floatValue();
- }
-
- @Override
- public void setAlpha(GL2ES2 gl, float alpha_t) {
- mgl_alpha.setData(alpha_t);
- if(null != gl && st.inUse()) {
- st.glUniform(gl, mgl_alpha);
- }
- }
-
- @Override
- public void setColor(GL2ES2 gl, float r, float g, float b){
- FloatBuffer fb = (FloatBuffer) mgl_color.getBuffer();
- fb.put(0, r);
- fb.put(1, r);
- fb.put(2, r);
- if(null != gl && st.inUse()) {
- st.glUniform(gl, mgl_color);
- }
- }
-
-
- @Override
- public void renderOutlineShape(GL2ES2 gl, OutlineShape outlineShape, float[] position, int texSize) {
- if(!isInitialized()){
- throw new GLException("RegionRendererImpl01: not initialized!");
- }
- int hashCode = getHashCode(outlineShape);
- Region region = regions.get(hashCode);
-
- if(null == region) {
- region = createRegion(gl, outlineShape, mgl_sharpness.floatValue());
- regions.put(hashCode, region);
- }
- region.render(pmvMatrix, vp_width, vp_height, texSize);
- }
-
- @Override
- public void renderOutlineShapes(GL2ES2 gl, OutlineShape[] outlineShapes, float[] position, int texSize) {
- if(!isInitialized()){
- throw new GLException("RegionRendererImpl01: not initialized!");
- }
-
- int hashCode = getHashCode(outlineShapes);
- Region region = regions.get(hashCode);
-
- if(null == region) {
- region = createRegion(gl, outlineShapes, mgl_sharpness.floatValue());
- regions.put(hashCode, region);
- }
- region.render(pmvMatrix, vp_width, vp_height, texSize);
- }
-}
diff --git a/src/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogamp/graph/curve/opengl/TextRendererImpl01.java deleted file mode 100644 index cebe7a19e..000000000 --- a/src/jogamp/graph/curve/opengl/TextRendererImpl01.java +++ /dev/null @@ -1,188 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import java.nio.FloatBuffer; - -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLException; -import javax.media.opengl.GLUniformData; -import javax.media.opengl.fixedfunc.GLMatrixFunc; - -import jogamp.graph.curve.text.GlyphString; - -import com.jogamp.graph.curve.opengl.TextRenderer; -import com.jogamp.graph.font.Font; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.opengl.util.glsl.ShaderCode; -import com.jogamp.opengl.util.glsl.ShaderProgram; - -public class TextRendererImpl01 extends TextRenderer { - /**Sharpness is equivalent to the value of t value of texture coord - * on the off-curve vertex. The high value of sharpness will - * result in high curvature. - */ - private GLUniformData mgl_sharpness = new GLUniformData("p1y", 0.5f); - GLUniformData mgl_alpha = new GLUniformData("g_alpha", 1.0f); - private GLUniformData mgl_color = new GLUniformData("g_color", 3, FloatBuffer.allocate(3)); - private GLUniformData mgl_strength = new GLUniformData("a_strength", 1.8f); - - public TextRendererImpl01(Vertex.Factory<? extends Vertex> factory, int type) { - super(factory, type); - } - - @Override - protected boolean initImpl(GL2ES2 gl){ - boolean VBOsupported = gl.isFunctionAvailable("glGenBuffers") && - gl.isFunctionAvailable("glBindBuffer") && - gl.isFunctionAvailable("glBufferData") && - gl.isFunctionAvailable("glDrawElements") && - gl.isFunctionAvailable("glVertexAttribPointer") && - gl.isFunctionAvailable("glDeleteBuffers"); - - if(DEBUG) { - System.err.println("TextRendererImpl01: VBO Supported = " + VBOsupported); - } - - if(!VBOsupported){ - return false; - } - - gl.glEnable(GL2ES2.GL_BLEND); - gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA); - - ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, TextRendererImpl01.class, - "shader", "shader/bin", "curverenderer01"); - ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, TextRendererImpl01.class, - "shader", "shader/bin", "curverenderer01"); - - ShaderProgram sp = new ShaderProgram(); - sp.add(rsVp); - sp.add(rsFp); - - if(!sp.link(gl, System.err)) { - throw new GLException("TextRendererImpl01: Couldn't link program: "+sp); - } - - st.attachShaderProgram(gl, sp); - gl.glBindAttribLocation(sp.id(), 0, "v_position"); - gl.glBindAttribLocation(sp.id(), 1, "texCoord"); - - st.glUseProgram(gl, true); - - pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); - pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - pmvMatrix.glLoadIdentity(); - - pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); - resetModelview(null); - - mgl_PMVMatrix = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); - if(!st.glUniform(gl, mgl_PMVMatrix)) { - if(DEBUG){ - System.err.println("Error setting PMVMatrix in shader: "+st); - } - return false; - } - - if(!st.glUniform(gl, mgl_sharpness)) { - if(DEBUG){ - System.err.println("Error setting sharpness in shader: "+st); - } - return false; - } - - if(!st.glUniform(gl, mgl_alpha)) { - if(DEBUG){ - System.err.println("Error setting global alpha in shader: "+st); - } - return false; - } - - if(!st.glUniform(gl, mgl_color)) { - if(DEBUG){ - System.err.println("Error setting global color in shader: "+st); - } - return false; - } - - if(!st.glUniform(gl, mgl_strength)) { - System.err.println("Error setting antialias strength in shader: "+st); - } - - if(DEBUG) { - System.err.println("TextRendererImpl01 initialized: " + Thread.currentThread()+" "+st); - } - return true; - } - - @Override - protected void disposeImpl(GL2ES2 gl) { - } - - @Override - public float getAlpha() { - return mgl_alpha.floatValue(); - } - - @Override - public void setAlpha(GL2ES2 gl, float alpha_t) { - mgl_alpha.setData(alpha_t); - if(null != gl && st.inUse()) { - st.glUniform(gl, mgl_alpha); - } - } - - @Override - public void setColor(GL2ES2 gl, float r, float g, float b){ - FloatBuffer fb = (FloatBuffer) mgl_color.getBuffer(); - fb.put(0, r); - fb.put(1, r); - fb.put(2, r); - if(null != gl && st.inUse()) { - st.glUniform(gl, mgl_color); - } - } - - @Override - public void renderString3D(GL2ES2 gl, Font font, String str, float[] position, int fontSize, int texSize) { - if(!isInitialized()){ - throw new GLException("TextRendererImpl01: not initialized!"); - } - GlyphString glyphString = getCachedGlyphString(font, str, fontSize); - if(null == glyphString) { - glyphString = createString(gl, font, fontSize, str, mgl_sharpness.floatValue()); - 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 deleted file mode 100644 index c7c370f6d..000000000 --- a/src/jogamp/graph/curve/opengl/VBORegion2PES2.java +++ /dev/null @@ -1,385 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; -import java.util.ArrayList; - -import javax.media.opengl.GL2ES2; -// FIXME: Subsume GL2GL3.GL_DRAW_FRAMEBUFFER -> GL2ES2.GL_DRAW_FRAMEBUFFER ! -import javax.media.opengl.GL2GL3; -import javax.media.opengl.GLContext; -import javax.media.opengl.GLUniformData; -import javax.media.opengl.fixedfunc.GLMatrixFunc; - -import com.jogamp.common.nio.Buffers; - -import com.jogamp.graph.geom.AABBox; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.Vertex; - -import com.jogamp.graph.curve.Region; -import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.glsl.ShaderState; - -public class VBORegion2PES2 implements Region{ - private int numVertices = 0; - private IntBuffer vboIds; - - private IntBuffer t_vboIds; - - private ArrayList<Triangle> triangles = new ArrayList<Triangle>(); - private ArrayList<Vertex> vertices = new ArrayList<Vertex>(); - private GLContext context; - - private int numBuffers = 3; - - private boolean flipped = false; - - private boolean dirty = false; - - private AABBox box = null; - private int[] texture = { 0 } ; - private int[] fbo = { 0 } ; - private int[] rbo_depth = { 0 } ; - private boolean texInitialized = false; - - 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; - } - - public void update(){ - box = new AABBox(); - - GL2ES2 gl = context.getGL().getGL2ES2(); - ShortBuffer indicies = Buffers.newDirectShortBuffer(triangles.size() * 3); - - 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]); - - indicies.put((short) t.getVertices()[0].getId()); - indicies.put((short) t.getVertices()[1].getId()); - indicies.put((short) t.getVertices()[2].getId()); - } - else{ - Vertex v1 = t.getVertices()[0]; - Vertex v2 = t.getVertices()[1]; - Vertex v3 = t.getVertices()[2]; - - indicies.put((short) v1.getId()); - indicies.put((short) v2.getId()); - indicies.put((short) v3.getId()); - } - } - indicies.rewind(); - - FloatBuffer verticesBuffer = Buffers.newDirectFloatBuffer(vertices.size() * 3); - for(Vertex v:vertices){ - verticesBuffer.put(v.getX()); - if(flipped){ - verticesBuffer.put(-1*v.getY()); - } - else{ - verticesBuffer.put(v.getY()); - } - verticesBuffer.put(v.getZ()); - if(flipped){ - box.resize(v.getX(), -1*v.getY(), v.getZ()); - } - else{ - box.resize(v.getX(), v.getY(), v.getZ()); - } - } - verticesBuffer.rewind(); - - FloatBuffer texCoordBuffer = Buffers.newDirectFloatBuffer(vertices.size() * 2); - for(Vertex v:vertices){ - float[] tex = v.getTexCoord(); - texCoordBuffer.put(tex[0]); - texCoordBuffer.put(tex[1]); - } - texCoordBuffer.rewind(); - - vboIds = IntBuffer.allocate(numBuffers); - gl.glGenBuffers(numBuffers, vboIds); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0)); // vertices - gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, numVertices * 3 * Buffers.SIZEOF_FLOAT, verticesBuffer, GL2ES2.GL_STATIC_DRAW); - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1)); //texture - gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, numVertices * 2 * Buffers.SIZEOF_FLOAT, texCoordBuffer, GL2ES2.GL_STATIC_DRAW); - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); - - gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2)); //triangles - gl.glBufferData(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, triangles.size()* 3 * Buffers.SIZEOF_SHORT, indicies, GL2ES2.GL_STATIC_DRAW); - gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 0); - - dirty = false; - } - - public void render(PMVMatrix matrix, int vp_width, int vp_height, int width){ - if(null == matrix || vp_width <=0 || vp_height <= 0 || width <= 0){ - renderRegion(); - } - else { - if(width != tex_width_c){ - texInitialized = false; - tex_width_c = width; - } - if(!texInitialized){ - initFBOTexture(matrix,vp_width, vp_height); - texInitialized = true; - } -// System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3)); - renderTexture(matrix, vp_width, vp_height); - } - } - - private void renderTexture(PMVMatrix matrix, int width, int hight){ - GL2ES2 gl = context.getGL().getGL2ES2(); - 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); - gl.glBindTexture(GL2ES2.GL_TEXTURE_2D, texture[0]); - - st.glUniform(gl, new GLUniformData("texture", texture[0])); - int loc = gl.glGetUniformLocation(st.shaderProgram().id(), "texture"); - gl.glUniform1i(loc, 0); - - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(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(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); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); - } - - private void setupBoundingBuffers(){ - GL2ES2 gl = context.getGL().getGL2ES2(); - - ShortBuffer indicies = Buffers.newDirectShortBuffer(6); - indicies.put((short) 0); indicies.put((short) 1); indicies.put((short) 3); - indicies.put((short) 1); indicies.put((short) 2); indicies.put((short) 3); - indicies.rewind(); - - FloatBuffer verticesBuffer = Buffers.newDirectFloatBuffer(4 * 3); - FloatBuffer texCoordBuffer = Buffers.newDirectFloatBuffer(4 * 2); - - verticesBuffer.put(box.getLow()[0]); - verticesBuffer.put(box.getLow()[1]); - verticesBuffer.put(box.getLow()[2]); - texCoordBuffer.put(5); - texCoordBuffer.put(5); - - verticesBuffer.put(box.getLow()[0]); - verticesBuffer.put(box.getHigh()[1]); - verticesBuffer.put(box.getLow()[2]); - - texCoordBuffer.put(5); - texCoordBuffer.put(6); - - verticesBuffer.put(box.getHigh()[0]); - verticesBuffer.put(box.getHigh()[1]); - verticesBuffer.put(box.getLow()[2]); - - texCoordBuffer.put(6); - texCoordBuffer.put(6); - - verticesBuffer.put(box.getHigh()[0]); - verticesBuffer.put(box.getLow()[1]); - verticesBuffer.put(box.getLow()[2]); - - texCoordBuffer.put(6); - texCoordBuffer.put(5); - - verticesBuffer.rewind(); - texCoordBuffer.rewind(); - - t_vboIds = IntBuffer.allocate(3); - gl.glGenBuffers(numBuffers, t_vboIds); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(0)); // vertices - gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, 4 * 3 * Buffers.SIZEOF_FLOAT, verticesBuffer, GL2ES2.GL_STATIC_DRAW); - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(1)); //texture - gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, 4 * 2 * Buffers.SIZEOF_FLOAT, texCoordBuffer, GL2ES2.GL_STATIC_DRAW); - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); - - gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, t_vboIds.get(2)); //triangles - gl.glBufferData(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 4 * 3 * Buffers.SIZEOF_SHORT, indicies, GL2ES2.GL_STATIC_DRAW); - gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 0); - } - - private void initFBOTexture(PMVMatrix m, int width, int hight){ - tex_height_c = (int)(tex_width_c*box.getHeight()/box.getWidth()); - // tex_height_c = tex_width_c; - System.out.println("FBO Size: "+tex_height_c+"x"+tex_width_c); - System.out.println("FBO Scale: " + m.glGetMatrixf().get(0) +" " + m.glGetMatrixf().get(5)); - GL2ES2 gl = context.getGL().getGL2ES2(); - - if(fbo[0] > 0) { - gl.glDeleteFramebuffers(1, fbo, 0); - fbo[0] = 0; - } - if(texture[0]>0) { - gl.glDeleteTextures(1, texture, 0); - texture[0] = 0; - } - - gl.glGenFramebuffers(1, fbo, 0); - gl.glGenTextures(1, texture, 0); - gl.glGenRenderbuffers(1,rbo_depth, 0); - System.out.println("FBO: fbo " + fbo[0] + ", tex " + texture[0] + ", depth " + rbo_depth[0]); - - gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, fbo[0]); - gl.glBindTexture(GL2ES2.GL_TEXTURE_2D, texture[0]); - gl.glTexImage2D(GL2ES2.GL_TEXTURE_2D, 0, GL2ES2.GL_RGBA, tex_width_c, - tex_height_c, 0, GL2ES2.GL_RGBA, GL2ES2.GL_UNSIGNED_BYTE, null); - - gl.glTexParameterf(GL2ES2.GL_TEXTURE_2D, GL2ES2.GL_TEXTURE_MIN_FILTER, GL2ES2.GL_LINEAR); - gl.glTexParameterf(GL2ES2.GL_TEXTURE_2D, GL2ES2.GL_TEXTURE_MAG_FILTER, GL2ES2.GL_LINEAR); - gl.glTexParameterf(GL2ES2.GL_TEXTURE_2D, GL2ES2.GL_TEXTURE_WRAP_S, GL2ES2.GL_CLAMP_TO_EDGE); - gl.glTexParameterf(GL2ES2.GL_TEXTURE_2D, GL2ES2.GL_TEXTURE_WRAP_T, GL2ES2.GL_CLAMP_TO_EDGE); - - gl.glFramebufferTexture2D(GL2GL3.GL_DRAW_FRAMEBUFFER, GL2ES2.GL_COLOR_ATTACHMENT0, - GL2ES2.GL_TEXTURE_2D, texture[0], 0); - - // Set up the depth buffer - gl.glBindRenderbuffer(GL2ES2.GL_RENDERBUFFER, rbo_depth[0]); - gl.glRenderbufferStorage(GL2ES2.GL_RENDERBUFFER, GL2ES2.GL_DEPTH_COMPONENT, tex_width_c, tex_height_c); - gl.glFramebufferRenderbuffer(GL2ES2.GL_FRAMEBUFFER, GL2ES2.GL_DEPTH_COMPONENT, GL2ES2.GL_RENDERBUFFER, rbo_depth[0]); - - int status = gl.glCheckFramebufferStatus(GL2ES2.GL_FRAMEBUFFER); - if(status != GL2ES2.GL_FRAMEBUFFER_COMPLETE){ - System.err.println("Cant Create R2T pass!"); - } - - //render texture - PMVMatrix tex_matrix = new PMVMatrix(); - gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, fbo[0]); - 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.glBindFramebuffer(GL2ES2.GL_FRAMEBUFFER, 0); - gl.glBindTexture(GL2ES2.GL_TEXTURE_2D, 0); - - setupBoundingBuffers(); - } - - private void renderRegion(){ - GL2ES2 gl = context.getGL().getGL2ES2(); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(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(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); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); - } - - 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() { - GL2ES2 gl = context.getGL().getGL2ES2(); - gl.glDeleteBuffers(numBuffers, vboIds); - gl.glDeleteFramebuffers(1, fbo, 0); - fbo[0] = 0; - gl.glDeleteTextures(1, texture, 0); - texture[0] = 0; - gl.glDeleteRenderbuffers(1, rbo_depth, 0); - rbo_depth[0] = 0; - } - - public boolean isFlipped() { - return flipped; - } - - public void setFlipped(boolean flipped) { - this.flipped = flipped; - } -} diff --git a/src/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogamp/graph/curve/opengl/VBORegionSPES2.java deleted file mode 100644 index 701549d46..000000000 --- a/src/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; -import java.util.ArrayList; - -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLContext; - -import com.jogamp.common.nio.Buffers; -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.opengl.util.PMVMatrix; - -public class VBORegionSPES2 implements Region{ - private int numVertices = 0; - private IntBuffer vboIds; - - private ArrayList<Triangle> triangles = new ArrayList<Triangle>(); - private ArrayList<Vertex> vertices = new ArrayList<Vertex>(); - - private GLContext context; - - private int numBuffers = 3; - - private boolean flipped = false; - private boolean dirty = false; - - public VBORegionSPES2(GLContext context){ - this.context =context; - } - - public void update(){ - GL2ES2 gl = context.getGL().getGL2ES2(); - ShortBuffer indicies = Buffers.newDirectShortBuffer(triangles.size() * 3); - - for(Triangle t:triangles){ - final Vertex[] t_vertices = t.getVertices(); - - if(t_vertices[0].getId() == Integer.MAX_VALUE){ - t_vertices[0].setId(numVertices++); - t_vertices[1].setId(numVertices++); - t_vertices[2].setId(numVertices++); - - vertices.add(t.getVertices()[0]); - vertices.add(t.getVertices()[1]); - vertices.add(t.getVertices()[2]); - - indicies.put((short) t.getVertices()[0].getId()); - indicies.put((short) t.getVertices()[1].getId()); - indicies.put((short) t.getVertices()[2].getId()); - } - else{ - Vertex v1 = t_vertices[0]; - Vertex v2 = t_vertices[1]; - Vertex v3 = t_vertices[2]; - - indicies.put((short) v1.getId()); - indicies.put((short) v2.getId()); - indicies.put((short) v3.getId()); - } - } - indicies.rewind(); - - FloatBuffer verticesBuffer = Buffers.newDirectFloatBuffer(vertices.size() * 3); - for(Vertex v:vertices){ - verticesBuffer.put(v.getX()); - if(flipped){ - verticesBuffer.put(-1*v.getY()); - } - else{ - verticesBuffer.put(v.getY()); - } - verticesBuffer.put(v.getZ()); - } - verticesBuffer.rewind(); - - FloatBuffer texCoordBuffer = Buffers.newDirectFloatBuffer(vertices.size() * 2); - for(Vertex v:vertices){ - float[] tex = v.getTexCoord(); - texCoordBuffer.put(tex[0]); - texCoordBuffer.put(tex[1]); - } - texCoordBuffer.rewind(); - - vboIds = IntBuffer.allocate(numBuffers); - gl.glGenBuffers(numBuffers, vboIds); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0)); // vertices - gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, numVertices * 3 * Buffers.SIZEOF_FLOAT, verticesBuffer, GL2ES2.GL_STATIC_DRAW); - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1)); //texture - gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, numVertices * 2 * Buffers.SIZEOF_FLOAT, texCoordBuffer, GL2ES2.GL_STATIC_DRAW); - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); - - gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2)); //triangles - gl.glBufferData(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, triangles.size()* 3 * Buffers.SIZEOF_SHORT, indicies, GL2ES2.GL_STATIC_DRAW); - gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 0); - - dirty = false; - } - - private void render() { - GL2ES2 gl = context.getGL().getGL2ES2(); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(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(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); - - gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); - } - - public void render(PMVMatrix matrix, int vp_width, int vp_height, int width){ - render(); - } - - 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() { - GL2ES2 gl = context.getGL().getGL2ES2(); - gl.glDeleteBuffers(numBuffers, vboIds); - } - - public boolean isFlipped() { - return flipped; - } - - public void setFlipped(boolean flipped) { - this.flipped = flipped; - } -} diff --git a/src/jogamp/graph/curve/opengl/shader/curverenderer01.fp b/src/jogamp/graph/curve/opengl/shader/curverenderer01.fp deleted file mode 100644 index 2b3a0ce1d..000000000 --- a/src/jogamp/graph/curve/opengl/shader/curverenderer01.fp +++ /dev/null @@ -1,99 +0,0 @@ -//#version 100 - -uniform float p1y; -uniform float g_alpha; -uniform vec3 g_color; -uniform float a_strength; - -varying vec2 v_texCoord; - -vec3 b_color = vec3(0.0, 0.0, 0.0); - -uniform sampler2D texture; -vec4 weights = vec4(0.075, 0.06, 0.045, 0.025); - -void main (void) -{ - vec2 rtex = vec2(abs(v_texCoord.x),abs(v_texCoord.y)); - vec3 c = g_color; - - float alpha = 0.0; - - if((v_texCoord.x == 0.0) && (v_texCoord.y == 0.0)){ - alpha = g_alpha; - } - else if((v_texCoord.x >= 5.0)){ - vec2 dfx = dFdx(v_texCoord); - vec2 dfy = dFdy(v_texCoord); - - vec2 size = 1.0/textureSize(texture,0); //version 130 - rtex -= 5.0; - vec4 t = texture2D(texture, rtex)* 0.18; - - t += texture2D(texture, rtex + size*(vec2(1, 0)))*weights.x; - t += texture2D(texture, rtex - size*(vec2(1, 0)))*weights.x; - t += texture2D(texture, rtex + size*(vec2(0, 1)))*weights.x; - t += texture2D(texture, rtex - size*(vec2(0, 1)))*weights.x; - - t += texture2D(texture, rtex + 2.0*size*(vec2(1, 0))) *weights.y; - t += texture2D(texture, rtex - 2.0*size*(vec2(1, 0)))*weights.y; - t += texture2D(texture, rtex + 2.0*size*(vec2(0, 1)))*weights.y; - t += texture2D(texture, rtex - 2.0*size*(vec2(0, 1)))*weights.y; - - t += texture2D(texture, rtex + 3.0*size*(vec2(1, 0))) *weights.z; - t += texture2D(texture, rtex - 3.0*size*(vec2(1, 0)))*weights.z; - t += texture2D(texture, rtex + 3.0*size*(vec2(0, 1)))*weights.z; - t += texture2D(texture, rtex - 3.0*size*(vec2(0, 1)))*weights.z; - - t += texture2D(texture, rtex + 4.0*size*(vec2(1, 0))) *weights.w; - t += texture2D(texture, rtex - 4.0*size*(vec2(1, 0)))*weights.w; - t += texture2D(texture, rtex + 4.0*size*(vec2(0, 1)))*weights.w; - t += texture2D(texture, rtex - 4.0*size*(vec2(0, 1)))*weights.w; - - if(t.w == 0.0){ - discard; - } - - c = t.xyz; - alpha = g_alpha* t.w; - } - /////////////////////////////////////////////////////////// - else if ((v_texCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)){ - vec2 dtx = dFdx(rtex); - vec2 dty = dFdy(rtex); - - rtex.y -= 0.1; - if(rtex.y < 0.0) { - if(v_texCoord.y < 0.0) - discard; - else{ - rtex.y = 0.0; - } - } - - vec2 f = vec2((dtx.y - 2.0*p1y*dtx.x + 4.0*p1y*rtex.x*dtx.x), (dty.y - 2.0*p1y*dty.x + 4.0*p1y*rtex.x*dty.x)); - - float position = rtex.y - ((2.0 * rtex.x * p1y) * (1.0 - rtex.x)); - float d = position/(length(f)); - - float a = (0.5 - d * sign(v_texCoord.y)); - - - if (a >= 1.0) { - alpha = g_alpha; - // c = vec3(1.0,1.0,1.0); - } - else if (a <= 0.0) { - alpha = 0.0;//discard; - // c = vec3(0.0,0.0,0.0); - - } - else { - alpha = g_alpha*a; - // c = vec3(a,a,a); - mix(b_color,g_color, a); - } - } - - gl_FragColor = vec4(c, alpha); -} diff --git a/src/jogamp/graph/curve/opengl/shader/curverenderer01.vp b/src/jogamp/graph/curve/opengl/shader/curverenderer01.vp deleted file mode 100644 index bc9ecb41e..000000000 --- a/src/jogamp/graph/curve/opengl/shader/curverenderer01.vp +++ /dev/null @@ -1,13 +0,0 @@ -//#version 100 - -uniform mat4 mgl_PMVMatrix[2]; -attribute vec4 v_position; -attribute vec2 texCoord; - -varying vec2 v_texCoord; - -void main(void) -{ - gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * v_position; - v_texCoord = texCoord.st; -}
\ No newline at end of file diff --git a/src/jogamp/graph/curve/tess/GraphVertex.java b/src/jogamp/graph/curve/tess/GraphVertex.java deleted file mode 100644 index b9f95a0e7..000000000 --- a/src/jogamp/graph/curve/tess/GraphVertex.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.tess; - -import java.util.ArrayList; - -import com.jogamp.graph.geom.Vertex; - -public class GraphVertex { - private Vertex point; - private ArrayList<HEdge> edges = null; - private boolean boundaryContained = false; - - public GraphVertex(Vertex point) { - this.point = point; - } - - public Vertex getPoint() { - return point; - } - - public float getX(){ - return point.getX(); - } - - public float getY(){ - return point.getY(); - } - - public float getZ(){ - return point.getZ(); - } - public float[] getCoord() { - return point.getCoord(); - } - - public void setPoint(Vertex point) { - this.point = point; - } - - public ArrayList<HEdge> getEdges() { - return edges; - } - - public void setEdges(ArrayList<HEdge> edges) { - this.edges = edges; - } - - public void addEdge(HEdge edge){ - if(edges == null){ - edges = new ArrayList<HEdge>(); - } - edges.add(edge); - } - public void removeEdge(HEdge edge){ - if(edges == null) - return; - edges.remove(edge); - if(edges.size() == 0){ - edges = null; - } - } - public HEdge findNextEdge(GraphVertex nextVert){ - for(HEdge e:edges){ - if(e.getNext().getGraphPoint() == nextVert){ - return e; - } - } - return null; - } - public HEdge findBoundEdge(){ - for(HEdge e:edges){ - if((e.getType() == HEdge.BOUNDARY) || (e.getType() == HEdge.HOLE)){ - return e; - } - } - return null; - } - public HEdge findPrevEdge(GraphVertex prevVert){ - for(HEdge e:edges){ - if(e.getPrev().getGraphPoint() == prevVert){ - return e; - } - } - return null; - } - - public boolean isBoundaryContained() { - return boundaryContained; - } - - public void setBoundaryContained(boolean boundaryContained) { - this.boundaryContained = boundaryContained; - } -} diff --git a/src/jogamp/graph/curve/tess/HEdge.java b/src/jogamp/graph/curve/tess/HEdge.java deleted file mode 100644 index d1bcc6e17..000000000 --- a/src/jogamp/graph/curve/tess/HEdge.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.tess; - -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Triangle; - - -public class HEdge { - public static int BOUNDARY = 3; - public static int INNER = 1; - public static int HOLE = 2; - - private GraphVertex vert; - private HEdge prev = null; - private HEdge next = null; - private HEdge sibling = null; - private int type = BOUNDARY; - private Triangle triangle = null; - - public HEdge(GraphVertex vert, int type) { - this.vert = vert; - this.type = type; - } - - public HEdge(GraphVertex vert, HEdge prev, HEdge next, HEdge sibling, int type) { - this.vert = vert; - this.prev = prev; - this.next = next; - this.sibling = sibling; - this.type = type; - } - - public HEdge(GraphVertex vert, HEdge prev, HEdge next, HEdge sibling, int type, Triangle triangle) { - this.vert = vert; - this.prev = prev; - this.next = next; - this.sibling = sibling; - this.type = type; - this.triangle = triangle; - } - - public GraphVertex getGraphPoint() { - return vert; - } - - public void setVert(GraphVertex vert) { - this.vert = vert; - } - - public HEdge getPrev() { - return prev; - } - - public void setPrev(HEdge prev) { - this.prev = prev; - } - - public HEdge getNext() { - return next; - } - - public void setNext(HEdge next) { - this.next = next; - } - - public HEdge getSibling() { - return sibling; - } - - public void setSibling(HEdge sibling) { - this.sibling = sibling; - } - - public int getType() { - return type; - } - - public void setType(int type) { - this.type = type; - } - - public Triangle getTriangle() { - return triangle; - } - - public void setTriangle(Triangle triangle) { - this.triangle = triangle; - } - - public static <T extends Vertex> void connect(HEdge first, HEdge next){ - first.setNext(next); - next.setPrev(first); - } - - public static <T extends Vertex> void makeSiblings(HEdge first, HEdge second){ - first.setSibling(second); - second.setSibling(first); - } - - public boolean vertexOnCurveVertex(){ - return vert.getPoint().isOnCurve(); - } - -} diff --git a/src/jogamp/graph/curve/tess/Loop.java b/src/jogamp/graph/curve/tess/Loop.java deleted file mode 100644 index fd7736a20..000000000 --- a/src/jogamp/graph/curve/tess/Loop.java +++ /dev/null @@ -1,373 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.tess; - -import java.util.ArrayList; - - -import com.jogamp.graph.geom.AABBox; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.math.VectorUtil; - -public class Loop { - private HEdge root = null; - private AABBox box = new AABBox(); - private GraphOutline initialOutline = null; - - public Loop(GraphOutline polyline, int direction){ - initialOutline = polyline; - this.root = initFromPolyline(initialOutline, direction); - } - - public HEdge getHEdge(){ - return root; - } - - public Triangle cut(boolean delaunay){ - if(isSimplex()){ - Triangle t = new Triangle(root.getGraphPoint().getPoint(), root.getNext().getGraphPoint().getPoint(), - root.getNext().getNext().getGraphPoint().getPoint()); - t.setVerticesBoundary(checkVerticesBoundary(root)); - return t; - } - HEdge prev = root.getPrev(); - HEdge next1 = root.getNext(); - - HEdge next2 = findClosestValidNeighbor(next1.getNext(), delaunay); - if(next2 == null){ - root = root.getNext(); - return null; - } - - GraphVertex v1 = root.getGraphPoint(); - GraphVertex v2 = next1.getGraphPoint(); - GraphVertex v3 = next2.getGraphPoint(); - - HEdge v3Edge = new HEdge(v3, HEdge.INNER); - - HEdge.connect(v3Edge, root); - HEdge.connect(next1, v3Edge); - - HEdge v3EdgeSib = v3Edge.getSibling(); - if(v3EdgeSib == null){ - v3EdgeSib = new HEdge(v3Edge.getNext().getGraphPoint(), HEdge.INNER); - HEdge.makeSiblings(v3Edge, v3EdgeSib); - } - - HEdge.connect(prev, v3EdgeSib); - HEdge.connect(v3EdgeSib, next2); - - Triangle t = createTriangle(v1.getPoint(), v2.getPoint(), v3.getPoint(), root); - this.root = next2; - return t; - } - - public boolean isSimplex(){ - return (root.getNext().getNext().getNext() == root); - } - - /**Create a connected list of half edges (loop) - * from the boundary profile - * @param direction requested winding of edges (CCW or CW) - */ - private HEdge initFromPolyline(GraphOutline outline, int direction){ - ArrayList<GraphVertex> vertices = outline.getGraphPoint(); - - if(vertices.size()<3) { - throw new IllegalArgumentException("outline's vertices < 3: " + vertices.size()); - } - boolean isCCW = VectorUtil.ccw(vertices.get(0).getPoint(), vertices.get(1).getPoint(), - vertices.get(2).getPoint()); - boolean invert = isCCW && (direction == VectorUtil.CW); - - HEdge firstEdge = null; - HEdge lastEdge = null; - int index =0; - int max = vertices.size(); - - int edgeType = HEdge.BOUNDARY; - if(invert){ - index = vertices.size() -1; - max = -1; - edgeType = HEdge.HOLE; - } - - while(index != max){ - GraphVertex v1 = vertices.get(index); - box.resize(v1.getX(), v1.getY(), v1.getZ()); - - HEdge edge = new HEdge(v1, edgeType); - - v1.addEdge(edge); - if(lastEdge != null){ - lastEdge.setNext(edge); - edge.setPrev(lastEdge); - } - else{ - firstEdge = edge; - } - - if(!invert){ - if(index == vertices.size()-1){ - edge.setNext(firstEdge); - firstEdge.setPrev(edge); - } - } - else if (index == 0){ - edge.setNext(firstEdge); - firstEdge.setPrev(edge); - } - - lastEdge = edge; - - if(!invert){ - index++; - } - else{ - index--; - } - } - return firstEdge; - } - - public void addConstraintCurve(GraphOutline polyline) { - // GraphOutline outline = new GraphOutline(polyline); - /**needed to generate vertex references.*/ - initFromPolyline(polyline, VectorUtil.CW); - - GraphVertex v3 = locateClosestVertex(polyline); - HEdge v3Edge = v3.findBoundEdge(); - HEdge v3EdgeP = v3Edge.getPrev(); - HEdge crossEdge = new HEdge(root.getGraphPoint(), HEdge.INNER); - - HEdge.connect(root.getPrev(), crossEdge); - HEdge.connect(crossEdge, v3Edge); - - HEdge crossEdgeSib = crossEdge.getSibling(); - if(crossEdgeSib == null) { - crossEdgeSib = new HEdge(crossEdge.getNext().getGraphPoint(), HEdge.INNER); - HEdge.makeSiblings(crossEdge, crossEdgeSib); - } - - HEdge.connect(v3EdgeP, crossEdgeSib); - HEdge.connect(crossEdgeSib, root); - } - - /** Locates the vertex and update the loops root - * to have (root + vertex) as closest pair - * @param polyline the control polyline - * to search for closestvertices - * @return the vertex that is closest to the newly set root Hedge. - */ - private GraphVertex locateClosestVertex(GraphOutline polyline) { - HEdge closestE = null; - GraphVertex closestV = null; - - float minDistance = Float.MAX_VALUE; - boolean inValid = false; - ArrayList<GraphVertex> initVertices = initialOutline.getGraphPoint(); - ArrayList<GraphVertex> vertices = polyline.getGraphPoint(); - - for(int i=0; i< initVertices.size()-1; i++){ - GraphVertex v = initVertices.get(i); - GraphVertex nextV = initVertices.get(i+1); - for(GraphVertex cand:vertices){ - float distance = VectorUtil.computeLength(v.getCoord(), cand.getCoord()); - if(distance < minDistance){ - for (GraphVertex vert:vertices){ - if(vert == v || vert == nextV || vert == cand) - continue; - inValid = VectorUtil.inCircle(v.getPoint(), nextV.getPoint(), - cand.getPoint(), vert.getPoint()); - if(inValid){ - break; - } - } - if(!inValid){ - closestV = cand; - minDistance = distance; - closestE = v.findBoundEdge(); - } - } - - } - } - - if(closestE != null){ - root = closestE; - } - - return closestV; - } - - private HEdge findClosestValidNeighbor(HEdge edge, boolean delaunay) { - HEdge next = root.getNext(); - - if(!VectorUtil.ccw(root.getGraphPoint().getPoint(), next.getGraphPoint().getPoint(), - edge.getGraphPoint().getPoint())){ - return null; - } - - HEdge candEdge = edge; - boolean inValid = false; - - if(delaunay){ - Vertex cand = candEdge.getGraphPoint().getPoint(); - HEdge e = candEdge.getNext(); - while (e != candEdge){ - if(e.getGraphPoint() == root.getGraphPoint() - || e.getGraphPoint() == next.getGraphPoint() - || e.getGraphPoint().getPoint() == cand){ - e = e.getNext(); - continue; - } - inValid = VectorUtil.inCircle(root.getGraphPoint().getPoint(), next.getGraphPoint().getPoint(), - cand, e.getGraphPoint().getPoint()); - if(inValid){ - break; - } - e = e.getNext(); - } - } - if(!inValid){ - return candEdge; - } - return null; - } - - /** Create a triangle from the param vertices only if - * the triangle is valid. IE not outside region. - * @param v1 vertex 1 - * @param v2 vertex 2 - * @param v3 vertex 3 - * @param root and edge of this triangle - * @return the triangle iff it satisfies, null otherwise - */ - private Triangle createTriangle(Vertex v1, Vertex v2, Vertex v3, HEdge rootT){ - Triangle t = new Triangle(v1, v2, v3); - t.setVerticesBoundary(checkVerticesBoundary(rootT)); - return t; - } - - private boolean[] checkVerticesBoundary(HEdge rootT) { - boolean[] boundary = new boolean[3]; - HEdge e1 = rootT; - HEdge e2 = rootT.getNext(); - HEdge e3 = rootT.getNext().getNext(); - - if(e1.getGraphPoint().isBoundaryContained()){ - boundary[0] = true; - } - if(e2.getGraphPoint().isBoundaryContained()){ - boundary[1] = true; - } - if(e3.getGraphPoint().isBoundaryContained()){ - boundary[2] = true; - } - return boundary; - } - - - /** Check if vertex inside the Loop - * @param vertex the Vertex - * @return true if the vertex is inside, false otherwise - */ - public boolean checkInside(Vertex vertex) { - if(!box.contains(vertex.getX(), vertex.getY(), vertex.getZ())){ - return false; - } - - float[] center = box.getCenter(); - - int hits = 0; - HEdge current = root; - HEdge next = root.getNext(); - while(next!= root){ - if(current.getType() == HEdge.INNER || next.getType() == HEdge.INNER){ - current = next; - next = current.getNext(); - continue; - } - Vertex vert1 = current.getGraphPoint().getPoint(); - Vertex vert2 = next.getGraphPoint().getPoint(); - - /** The ray is P0+s*D0, where P0 is the ray origin, D0 is a direction vector and s >= 0. - * The segment is P1+t*D1, where P1 and P1+D1 are the endpoints, and 0 <= t <= 1. - * perp(x,y) = (y,-x). - * if Dot(perp(D1),D0) is not zero, - * s = Dot(perp(D1),P1-P0)/Dot(perp(D1),D0) - * t = Dot(perp(D0),P1-P0)/Dot(perp(D1),D0) - */ - - float[] d0 = new float[]{center[0] - vertex.getX(), center[1]-vertex.getY(), - center[2]-vertex.getZ()}; - float[] d1 = {vert2.getX() - vert1.getX(), vert2.getY() - vert1.getY(), - vert2.getZ() - vert1.getZ()}; - - float[] prep_d1 = {d1[1],-1*d1[0], d1[2]}; - float[] prep_d0 = {d0[1],-1*d0[0], d0[2]}; - - float[] p0p1 = new float[]{vert1.getX() - vertex.getX(), vert1.getY() - vertex.getY(), - vert1.getZ() - vertex.getZ()}; - - float dotD1D0 = VectorUtil.dot(prep_d1, d0); - if(dotD1D0 == 0){ - /** ray parallel to segment */ - current = next; - next = current.getNext(); - continue; - } - - float s = VectorUtil.dot(prep_d1,p0p1)/dotD1D0; - float t = VectorUtil.dot(prep_d0,p0p1)/dotD1D0; - - if(s >= 0 && t >= 0 && t<= 1){ - hits++; - } - current = next; - next = current.getNext(); - } - - if(hits % 2 != 0){ - /** check if hit count is even */ - return true; - } - return false; - } - - public int computeLoopSize(){ - int size = 0; - HEdge e = root; - do{ - size++; - e = e.getNext(); - }while(e != root); - return size; - } -} diff --git a/src/jogamp/graph/curve/text/GlyphShape.java b/src/jogamp/graph/curve/text/GlyphShape.java deleted file mode 100644 index 36ba57244..000000000 --- a/src/jogamp/graph/curve/text/GlyphShape.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.text; - -import java.util.ArrayList; - -import jogamp.graph.geom.plane.PathIterator; - -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Triangle; - -import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.math.Quaternion; - -public class GlyphShape { - - private Quaternion quat= null; - private int numVertices = 0; - private OutlineShape shape = null; - - /** Create a new Glyph shape - * based on Parametric curve control polyline - */ - public GlyphShape(Vertex.Factory<? extends Vertex> factory){ - shape = new OutlineShape(factory); - } - - /** Create a GlyphShape from a font Path Iterator - * @param pathIterator the path iterator - * - * @see PathIterator - */ - public GlyphShape(Vertex.Factory<? extends Vertex> factory, PathIterator pathIterator){ - this(factory); - - if(null != pathIterator){ - while(!pathIterator.isDone()){ - float[] coords = new float[6]; - int segmentType = pathIterator.currentSegment(coords); - addOutlineVerticesFromGlyphVector(coords, segmentType); - - pathIterator.next(); - } - } - shape.transformOutlines(OutlineShape.QUADRATIC_NURBS); - } - - public final Vertex.Factory<? extends Vertex> vertexFactory() { return shape.vertexFactory(); } - - private void addVertexToLastOutline(Vertex vertex){ - shape.addVertex(vertex); - } - - private void addOutlineVerticesFromGlyphVector(float[] coords, int segmentType){ - if(segmentType == PathIterator.SEG_MOVETO){ - if(!shape.getLastOutline().isEmpty()){ - shape.addEmptyOutline(); - } - Vertex vert = vertexFactory().create(coords[0],coords[1]); - vert.setOnCurve(true); - addVertexToLastOutline(vert); - - numVertices++; - } - else if(segmentType == PathIterator.SEG_LINETO){ - Vertex vert1 = vertexFactory().create(coords[0],coords[1]); - vert1.setOnCurve(true); - addVertexToLastOutline(vert1); - - numVertices++; - } - else if(segmentType == PathIterator.SEG_QUADTO){ - Vertex vert1 = vertexFactory().create(coords[0],coords[1]); - vert1.setOnCurve(false); - addVertexToLastOutline(vert1); - - Vertex vert2 = vertexFactory().create(coords[2],coords[3]); - vert2.setOnCurve(true); - addVertexToLastOutline(vert2); - - numVertices+=2; - } - else if(segmentType == PathIterator.SEG_CUBICTO){ - Vertex vert1 = vertexFactory().create(coords[0],coords[1]); - vert1.setOnCurve(false); - addVertexToLastOutline(vert1); - - Vertex vert2 = vertexFactory().create(coords[2],coords[3]); - vert2.setOnCurve(false); - addVertexToLastOutline(vert2); - - Vertex vert3 = vertexFactory().create(coords[4],coords[5]); - vert3.setOnCurve(true); - addVertexToLastOutline(vert3); - - numVertices+=3; - } - else if(segmentType == PathIterator.SEG_CLOSE){ - shape.closeLastOutline(); - } - } - - public int getNumVertices() { - return numVertices; - } - - /** Get the rotational Quaternion attached to this Shape - * @return the Quaternion Object - */ - public Quaternion getQuat() { - return quat; - } - - /** Set the Quaternion that shall defien the rotation - * of this shape. - * @param quat - */ - public void setQuat(Quaternion quat) { - this.quat = quat; - } - - /** Triangluate the glyph shape - * @param sharpness sharpness of the curved regions default = 0.5 - * @return ArrayList of triangles which define this shape - */ - public ArrayList<Triangle> triangulate(float sharpness){ - return shape.triangulate(sharpness); - } - - /** Get the list of Vertices of this Object - * @return arrayList of Vertices - */ - public ArrayList<Vertex> getVertices(){ - return shape.getVertices(); - } -} diff --git a/src/jogamp/graph/curve/text/GlyphString.java b/src/jogamp/graph/curve/text/GlyphString.java deleted file mode 100644 index 808e3a415..000000000 --- a/src/jogamp/graph/curve/text/GlyphString.java +++ /dev/null @@ -1,163 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.text; - -import java.util.ArrayList; - -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.opengl.SVertex; - -import javax.media.opengl.GLContext; - -import jogamp.graph.geom.plane.AffineTransform; -import jogamp.graph.geom.plane.Path2D; -import jogamp.graph.geom.plane.PathIterator; - - -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.RegionFactory; -import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.glsl.ShaderState; - -public class GlyphString { - private final Vertex.Factory<? extends Vertex> pointFactory; - private ArrayList<GlyphShape> glyphs = new ArrayList<GlyphShape>(); - private String str = ""; - private String fontname = ""; - private Region region; - - private SVertex origin = new SVertex(); - - /** Create a new GlyphString object - * @param fontname the name of the font that this String is - * associated with - * @param str the string object - */ - public GlyphString(Vertex.Factory<? extends Vertex> factory, String fontname, String str){ - pointFactory = factory; - this.fontname = fontname; - this.str = str; - } - - public final Vertex.Factory<? extends Vertex> pointFactory() { return pointFactory; } - - public void addGlyphShape(GlyphShape glyph){ - glyphs.add(glyph); - } - public String getString(){ - return str; - } - - /** Creates the Curve based Glyphs from a Font - * @param paths a list of FontPath2D objects that define the outline - * @param affineTransform a global affine transformation applied to the paths. - */ - public void createfromFontPath(Path2D[] paths, AffineTransform affineTransform){ - final int numGlyps = paths.length; - for (int index=0;index<numGlyps;index++){ - if(paths[index] == null){ - continue; - } - PathIterator iterator = paths[index].iterator(affineTransform); - GlyphShape glyphShape = new GlyphShape(pointFactory, iterator); - - if(glyphShape.getNumVertices() < 3) { - continue; - } - addGlyphShape(glyphShape); - } - } - - private ArrayList<Triangle> initializeTriangles(float sharpness){ - ArrayList<Triangle> triangles = new ArrayList<Triangle>(); - for(GlyphShape glyph:glyphs){ - ArrayList<Triangle> tris = glyph.triangulate(sharpness); - triangles.addAll(tris); - } - return triangles; - } - - /** Generate a OGL Region to represent this Object. - * @param context the GLContext which the region is defined by. - * @param shaprness the curvature sharpness of the object. - * @param st shader state - */ - public void generateRegion(GLContext context, float shaprness, ShaderState st, int type){ - region = RegionFactory.create(context, st, type); - region.setFlipped(true); - - ArrayList<Triangle> tris = initializeTriangles(shaprness); - region.addTriangles(tris); - - int numVertices = region.getNumVertices(); - for(GlyphShape glyph:glyphs){ - ArrayList<Vertex> gVertices = glyph.getVertices(); - for(Vertex vert:gVertices){ - vert.setId(numVertices++); - } - region.addVertices(gVertices); - } - - /** initialize the region */ - region.update(); - } - - /** Generate a Hashcode for this object - * @return a string defining the hashcode - */ - public String getTextHashCode(){ - return "" + fontname.hashCode() + str.hashCode(); - } - - /** Render the Object based using the associated Region - * previously generated. - */ - public void renderString3D() { - region.render(null, 0, 0, 0); - } - /** Render the Object based using the associated Region - * previously generated. - */ - public void renderString3D(PMVMatrix matrix, int vp_width, int vp_height, int size) { - region.render(matrix, vp_width, vp_height, size); - } - - /** Get the Origion of this GlyphString - * @return - */ - public Vertex getOrigin() { - return origin; - } - - /** Destroy the associated OGL objects - */ - public void destroy(){ - region.destroy(); - } -} diff --git a/src/jogamp/graph/font/JavaFontLoader.java b/src/jogamp/graph/font/JavaFontLoader.java deleted file mode 100644 index 33505e797..000000000 --- a/src/jogamp/graph/font/JavaFontLoader.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.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; - -public class JavaFontLoader implements FontSet { - - final static FontSet fontLoader = new JavaFontLoader(); - - public static FontSet get() { - return fontLoader; - } - - final static String availableFontFileNames[] = - { - /* 00 */ "LucidaBrightRegular.ttf", - /* 01 */ "LucidaBrightItalic.ttf", - /* 02 */ "LucidaBrightDemiBold.ttf", - /* 03 */ "LucidaBrightDemiItalic.ttf", - /* 04 */ "LucidaSansRegular.ttf", - /* 05 */ "LucidaSansDemiBold.ttf", - /* 06 */ "LucidaTypewriterRegular.ttf", - /* 07 */ "LucidaTypewriterBold.ttf", - }; - - final String javaFontPath; - - private JavaFontLoader() { - 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 - } - - public Font get(int family, int style) { - Font font = (Font)fontMap.get( ( family << 8 ) | style ); - if (font != null) { - return font; - } - - // 1st process Sans Serif (2 fonts) - if( is(style, STYLE_SERIF) ) { - if( is(style, STYLE_BOLD) ) { - font = abspath(availableFontFileNames[5], family, style); - } else { - font = abspath(availableFontFileNames[4], family, style); - } - fontMap.put( ( family << 8 ) | style, font ); - return font; - } - - // Serif Fonts .. - switch (family) { - case FAMILY_LIGHT: - case FAMILY_MEDIUM: - case FAMILY_CONDENSED: - case FAMILY_REGULAR: - if( is(style, STYLE_BOLD) ) { - if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[3], family, style); - } else { - font = abspath(availableFontFileNames[2], family, style); - } - } else if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[1], family, style); - } else { - font = abspath(availableFontFileNames[0], family, style); - } - break; - - case FAMILY_MONOSPACED: - if( is(style, STYLE_BOLD) ) { - font = abspath(availableFontFileNames[7], family, style); - } else { - font = abspath(availableFontFileNames[6], family, style); - } - break; - } - - return font; - } - - 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 deleted file mode 100644 index e09ea85e5..000000000 --- a/src/jogamp/graph/font/UbuntuFontLoader.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.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; -import com.jogamp.opengl.util.Locator; - -public class UbuntuFontLoader implements FontSet { - - final static FontSet fontLoader = new UbuntuFontLoader(); - - public static FontSet get() { - return fontLoader; - } - - final static String availableFontFileNames[] = - { - /* 00 */ "Ubuntu-R.ttf", // regular - /* 01 */ "Ubuntu-RI.ttf", // regular italic - /* 02 */ "Ubuntu-B.ttf", // bold - /* 03 */ "Ubuntu-BI.ttf", // bold italic - /* 04 */ "Ubuntu-L.ttf", // light - /* 05 */ "Ubuntu-LI.ttf", // light italic - /* 06 */ "Ubuntu-M.ttf", // medium - /* 07 */ "Ubuntu-MI.ttf", // medium italic - - }; - - final static String relPath = "fonts/ubuntu/" ; - - 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 ) ; - } - - public Font getDefault() { - return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular - } - - public Font get(int family, int style) - { - Font font = (Font)fontMap.get( ( family << 8 ) | style ); - if (font != null) { - return font; - } - - switch (family) { - case FAMILY_MONOSPACED: - case FAMILY_CONDENSED: - case FAMILY_REGULAR: - if( is(style, STYLE_BOLD) ) { - if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[3], family, style); - } else { - font = abspath(availableFontFileNames[2], family, style); - } - } else if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[1], family, style); - } else { - font = abspath(availableFontFileNames[0], family, style); - } - break; - - case FAMILY_LIGHT: - if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[5], family, style); - } else { - font = abspath(availableFontFileNames[4], family, style); - } - break; - - case FAMILY_MEDIUM: - if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[6], family, style); - } else { - font = abspath(availableFontFileNames[7], family, style); - } - break; - } - - return font; - } - - 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/fonts/ubuntu/CONTRIBUTING.txt b/src/jogamp/graph/font/fonts/ubuntu/CONTRIBUTING.txt deleted file mode 100644 index 15bdc0c0b..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/CONTRIBUTING.txt +++ /dev/null @@ -1,21 +0,0 @@ -The Ubuntu Font Family is very long-term endeavour, and the first time -that a professionally-designed font has been funded specifically with -the intent of being an on-going community expanded project: - - http://font.ubuntu.com/ - -Development of the Ubuntu Font Family is undertaken on Launchpad: - - http://launchpad.net/ubuntu-font-family/ - -and this is where milestones, bug management and releases are handled. - -Contributions are welcomed. Your work will be used on millions of -computers every single day! Following the initial bootstrapping of -Latin, Cyrillic, Greek, Arabic and Hebrew expansion will be undertaken -by font designers from the font design and Ubuntu communities. - -To ensure that the Ubuntu Font Family can be re-licensed to future -widely-used libre font licences, copyright assignment is being required: - - https://launchpad.net/~uff-contributors diff --git a/src/jogamp/graph/font/fonts/ubuntu/FONTLOG.txt b/src/jogamp/graph/font/fonts/ubuntu/FONTLOG.txt deleted file mode 100644 index cf0e4c111..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/FONTLOG.txt +++ /dev/null @@ -1,211 +0,0 @@ -This is the FONTLOG file for the Ubuntu Font Family and attempts to follow -the recommendations at: http://scripts.sil.org/OFL-FAQ_web#43cecb44 - - -Overview - -The new Ubuntu Font Family was started to enable the personality of -Ubuntu to be seen and felt in every menu, button and dialog. -The typeface is sans-serif, uses OpenType features and is manually -hinted for clarity on desktop and mobile computing screens. - -The scope of the Ubuntu Font Family includes all the languages used by -the various Ubuntu users around the world in tune with Ubuntu's -philosophy which states that every user should be able to use their -software in the language of their choice. So the Ubuntu Font Family -project will be extended to cover many more written languages. - - -History - -The Ubuntu Font Family has been creating during 2010. As of December 2010 -coverage is provided for Latin, Cyrillic and Greek across Regular, Italic, -Bold and Bold-Italic. - - -ChangeLog - -2010-03-08 (Paul Sladen) Ubuntu Font Family version 0.71.2 - - * (Production) Adjust Medium WeightClass to 500 (Md, MdIt) (LP: #730912) - -2010-03-07 (Paul Sladen) Ubuntu Font Family version 0.71.1 - - * (Design) Add Capitalised version of glyphs and kern. (Lt, LtIt, - Md, MdIt) DM (LP: #677446) - * (Design) Re-space and tighen Regular and Italic by amount specified - by Mark Shuttleworth (minus 4 FUnits). (Rg, It) (LP: #677149) - * (Design) Design: Latin (U+0192) made straight more like l/c f with - tail (LP: #670768) - * (Design) (U+01B3) should have hook on right, as the lowercase - (U+01B4) (LP: #681026) - * (Design) Tail of Light Italic germandbls, longs and lowercase 'f' - to match Italic/BoldItalic (LP: #623925) - * (Production) Update <case> feature (Lt, LtIt, Md, MdIt). DM - (LP: #676538, #676539) - * (Production) Remove Bulgarian locl feature for Italics. (LP: #708578) - * (Production) Update Description information with new string: - "The Ubuntu Font Family are libre fonts funded by Canonical Ltd - on behalf of the Ubuntu project. The font design work and - technical implementation is being undertaken by Dalton Maag. The - typeface is sans-serif, uses OpenType features and is manually - hinted for clarity on desktop and mobile computing screens. The - scope of the Ubuntu Font Family includes all the languages used - by the various Ubuntu users around the world in tune with - Ubuntu's philosophy which states that every user should be able - to use their software in the language of their choice. The - project is ongoing, and we expect the family will be extended to - cover many written languages in the coming years." - (Rg, It, Bd, BdIt, Lt, LtIt, Md, MdIt) (LP: #690590) - * (Production) Pixel per em indicator added at U+F000 (Lt, LtIt, Md, - MdIt) (LP: #615787) - * (Production) Version number indicator added at U+EFFD (Lt, LtIt, Md, - MdIt) (LP: #640623) - * (Production) fstype bit set to 0 - Editable (Lt, LtIt, Md, MdIt) - (LP: #648406) - * (Production) Localisation of name table has been removed because - of problems with Mac OS/X interpretation of localisation. DM - (LP: #730785) - * (Hinting) Regular '?' dot non-circular (has incorrect control - value). (LP: #654336) - * (Hinting) Too much space after latin capital 'G' in 13pt - regular. Now reduced. (LP: #683437) - * (Hinting) Balance Indian Rupee at 18,19pt (LP: #662177) - * (Hinting) Make Regular '£' less ambiguous at 13-15 ppm (LP: #685562) - * (Hinting) Regular capital 'W' made symmetrical at 31 ppem (LP: #686168) - -2010-12-14 (Paul Sladen) Ubuntu Font Family version 0.70.1 - - Packaging, rebuilt from '2010-12-08 UbuntuFontsSourceFiles_070.zip': - * (Midstream) Fstype bit != 0 (LP: #648406) - * (Midstream) Add unit test to validate fstype bits (LP: #648406) - * (Midstream) Add unit test to validate licence - -2010-12-14 (Paul Sladen) Ubuntu Font Family version 0.70 - - Release notes 0.70: - * (Design) Add Capitalised version of glyphs and kern. (Rg, It, Bd, - BdIt) DM (LP: #676538, #677446) - * (Design) Give acute and grave a slight upright move to more match - the Hungarian double acute angle. (Rg, It, Bd, BdIt) (LP: #656647) - * (Design) Shift Bold Italic accent glyphs to be consistent with the - Italic. (BdIt only) DM (LP: #677449) - * (Design) Check spacing and kerning of dcaron, lcaron and - tcaron. (Rg, It, Bd, BdIt) (LP: #664722) - * (Design) Add positive kerning to () {} [] to open out the - combinations so they are less like a closed box. (Rg, It, Bd, - BdIt) (LP: #671228) - * (Design) Change design of acute.asc and check highest points (Bd - and BdIt only) DM - * (Production) Update <case> feature. DM (LP: #676538, #676539) - * (Production) Remove Romanian locl feature. (Rg, It, Bd, BdIt) - (LP: #635615) - * (Production) Update Copyright information with new - strings. "Copyright 2010 Canonical Ltd. Licensed under the Ubuntu - Font Licence 1.0" Trademark string "Ubuntu and Canonical are - registered trademarks of Canonical Ltd." (Rg, It, Bd, BdIt) DM - (LP: #677450) - * (Design) Check aligning of hyphen, math signs em, en, check braces - and other brackets. 16/11 (LP: #676465) - * (Production) Pixel per em indicator added at U+F000 (Rg, It, Bd, - BdIt) (LP: #615787) - * (Production) Version number indicator added at U+EFFD (Rg, It, Bd, - BdIt) (LP: #640623) - * (Production) fstype bit set to 0 - Editable (Rg, It, Bd, BdIt) - (LP: #648406) - -2010-10-05 (Paul Sladen) Ubuntu Font Family version 0.69 - - [Dalton Maag] - * Italic, - - Hinting on lowercase Italic l amended 19ppm (LP: #632451) - - Hinting on lowercase Italic u amended 12ppm (LP: #626376) - - * Regular, Italic, Bold, BoldItalic - - New Rupee Sign added @ U+20B9 (LP: #645987) - - Ubuntu Roundel added @ U+E0FF (LP: #651606) - - [Paul Sladen] - * All - - Removed "!ubu" GSUB.calt ligature for U+E0FF (LP: #651606) - - -Acknowledgements - -If you make modifications be sure to add your name (N), email (E), -web-address (if you have one) (W) and description (D). This list is in -alphabetical order. - -N: Amélie Bonet -W: http://ameliebonet.com/ -D: Type design with Dalton Maag, particularly Ubuntu Mono - -N: Ron Carpenter -N: Vincent Connare -N: Lukas Paltram -W: http://www.daltonmaag.com/ -D: Type design and engineering with Dalton Maag - -N: Dave Crossland -W: http://understandingfonts.com/ -D: Documentation and libre licensing guidance - -N: Iain Farrell -W: http://www.flickr.com/photos/iain -D: Ubuntu Font Family delivery for the Ubuntu UX team - -N: Shiraaz Gabru -W: http://www.daltonmaag.com/ -D: Ubuntu Font Family project management at Dalton Maag - -N: Marcus Haslam -W: http://design.canonical.com/author/marcus-haslam/ -D: Creative inspiration - -N: Ben Laenen -D: Inspiration behind the pixels-per-em (PPEM) readout debugging glyph at U+F000 - (for this font the concept was re-implemented from scratch by Dalton-Maag) - -N: Bruno Maag -W: http://www.daltonmaag.com/ -D: Stylistic direction of the Ubuntu Font Family, as head of Dalton Maag - -N: Ivanka Majic -W: http://www.ivankamajic.com/ -D: Guiding the UX team and Cyrillic feedback - -N: David Marshall -N: Malcolm Wooden -W: http://www.daltonmaag.com/ -D: Font Engineering and technical direction - -N: Rodrigo Rivas -D: Indian Rupee Sign glyph - -N: Mark Shuttleworth -W: http://www.markshuttleworth.com/ -D: Executive quality-control and funding - -N: Paul Sladen -W: http://www.paul.sladen.org/ -D: Bug triaging, packaging - -N: Nicolas Spalinger -W: http://planet.open-fonts.org -D: Continuous guidance on libre/open font licensing, best practises in source - tree layout, release and packaging (pkg-fonts Debian team) - -N: Kenneth Wimer -D: Initial PPA packaging - -* Canonical Ltd is the primary commercial sponsor of the Ubuntu and - Kubuntu operating systems -* Dalton Maag are a custom type foundry headed by Bruno Maag - -For further documentation, information on contributors, source code -downloads and those involved with the Ubuntu Font Family, visit: - - http://font.ubuntu.com/ diff --git a/src/jogamp/graph/font/fonts/ubuntu/LICENCE-FAQ.txt b/src/jogamp/graph/font/fonts/ubuntu/LICENCE-FAQ.txt deleted file mode 100644 index 776a25edf..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/LICENCE-FAQ.txt +++ /dev/null @@ -1,177 +0,0 @@ - Ubuntu Font Family Licensing FAQ - - Stylistic Foundations - - The Ubuntu Font Family is the first time that a libre typeface has been - designed professionally and explicitly with the intent of developing a - public and long-term community-based development process. - - When developing an open project, it is generally necessary to have firm - foundations: a font needs to maintain harmony within itself even across - many type designers and writing systems. For the [1]Ubuntu Font Family, - the process has been guided with the type foundry Dalton Maag setting - the project up with firm stylistic foundation covering several - left-to-right scripts: Latin, Greek and Cyrillic; and right-to-left - scripts: Arabic and Hebrew (due in 2011). - - With this starting point the community will, under the supervision of - [2]Canonical and [3]Dalton Maag, be able to build on the existing font - sources to expand their character coverage. Ultimately everybody will - be able to use the Ubuntu Font Family in their own written languages - across the whole of Unicode (and this will take some time!). - - Licensing - - The licence chosen by any free software project is one of the - foundational decisions that sets out how derivatives and contributions - can occur, and in turn what kind of community will form around the - project. - - Using a licence that is compatible with other popular licences is a - powerful constraint because of the [4]network effects: the freedom to - share improvements between projects allows free software to reach - high-quality over time. Licence-proliferation leads to many - incompatible licences, undermining the network effect, the freedom to - share and ultimately making the libre movement that Ubuntu is a part of - less effective. For all kinds of software, writing a new licence is not - to be taken lightly and is a choice that needs to be thoroughly - justified if this path is taken. - - Today it is not clear to Canonical what the best licence for a font - project like the Ubuntu Font Family is: one that starts life designed - by professionals and continues with the full range of community - development, from highly commercial work in new directions to curious - beginners' experimental contributions. The fast and steady pace of the - Ubuntu release cycle means that an interim libre licence has been - necessary to enable the consideration of the font family as part of - Ubuntu 10.10 operating system release. - - Before taking any decision on licensing, Canonical as sponsor and - backer of the project has reviewed the many existing licenses used for - libre/open fonts and engaged the stewards of the most popular licenses - in detailed discussions. The current interim licence is the first step - in progressing the state-of-the-art in licensing for libre/open font - development. - - The public discussion must now involve everyone in the (comparatively - new) area of the libre/open font community; including font users, - software freedom advocates, open source supporters and existing libre - font developers. Most importantly, the minds and wishes of professional - type designers considering entering the free software business - community must be taken on board. - - Conversations and discussion has taken place, privately, with - individuals from the following groups (generally speaking personally on - behalf of themselves, rather than their affiliations): - * [5]SIL International - * [6]Open Font Library - * [7]Software Freedom Law Center - * [8]Google Font API - - Document embedding - - One issue highlighted early on in the survey of existing font licences - is that of document embedding. Almost all font licences, both free and - unfree, permit embedding a font into a document to a certain degree. - Embedding a font with other works that make up a document creates a - "combined work" and copyleft would normally require the whole document - to be distributed under the terms of the font licence. As beautiful as - the font might be, such a licence makes a font too restrictive for - useful general purpose digital publishing. - - The situation is not entirely unique to fonts and is encountered also - with tools such as GNU Bison: a vanilla GNU GPL licence would require - anything generated with Bison to be made available under the terms of - the GPL as well. To avoid this, Bison is [9]published with an - additional permission to the GPL which allows the output of Bison to be - made available under any licence. - - The conflict between licensing of fonts and licensing of documents, is - addressed in two popular libre font licences, the SIL OFL and GNU GPL: - * [10]SIL Open Font Licence: When OFL fonts are embedded in a - document, the OFL's terms do not apply to that document. (See - [11]OFL-FAQ for details. - * [12]GPL Font Exception: The situation is resolved by granting an - additional permission to allow documents to not be covered by the - GPL. (The exception is being reviewed). - - The Ubuntu Font Family must also resolve this conflict, ensuring that - if the font is embedded and then extracted it is once again clearly - under the terms of its libre licence. - - Long-term licensing - - Those individuals involved, especially from Ubuntu and Canonical, are - interested in finding a long-term libre licence that finds broad favour - across the whole libre/open font community. The deliberation during the - past months has been on how to licence the Ubuntu Font Family in the - short-term, while knowingly encouraging everyone to pursue a long-term - goal. - * [13]Copyright assignment will be required so that the Ubuntu Font - Family's licensing can be progressively expanded to one (or more) - licences, as best practice continues to evolve within the - libre/open font community. - * Canonical will support and fund legal work on libre font licensing. - It is recognised that the cost and time commitments required are - likely to be significant. We invite other capable parties to join - in supporting this activity. - - The GPL version 3 (GPLv3) will be used for Ubuntu Font Family build - scripts and the CC-BY-SA for associated documentation and non-font - content: all items which do not end up embedded in general works and - documents. - -Ubuntu Font Licence - - For the short-term only, the initial licence is the [14]Ubuntu Font - License (UFL). This is loosely inspired from the work on the SIL - OFL 1.1, and seeks to clarify the issues that arose during discussions - and legal review, from the perspective of the backers, Canonical Ltd. - Those already using established licensing models such as the GPL, OFL - or Creative Commons licensing should have no worries about continuing - to use them. The Ubuntu Font Licence (UFL) and the SIL Open Font - Licence (SIL OFL) are not identical and should not be confused with - each other. Please read the terms precisely. The UFL is only intended - as an interim license, and the overriding aim is to support the - creation of a more suitable and generic libre font licence. As soon as - such a licence is developed, the Ubuntu Font Family will migrate to - it—made possible by copyright assignment in the interium. Between the - OFL 1.1, and the UFL 1.0, the following changes are made to produce the - Ubuntu Font Licence: - * Clarification: - - 1. Document embedding (see [15]embedding section above). - 2. Apply at point of distribution, instead of receipt - 3. Author vs. copyright holder disambiguation (type designers are - authors, with the copyright holder normally being the funder) - 4. Define "Propagate" (for internationalisation, similar to the GPLv3) - 5. Define "Substantially Changed" - 6. Trademarks are explicitly not transferred - 7. Refine renaming requirement - - Streamlining: - 8. Remove "not to be sold separately" clause - 9. Remove "Reserved Font Name(s)" declaration - - A visual demonstration of how these points were implemented can be - found in the accompanying coloured diff between SIL OFL 1.1 and the - Ubuntu Font Licence 1.0: [16]ofl-1.1-ufl-1.0.diff.html - -References - - 1. http://font.ubuntu.com/ - 2. http://www.canonical.com/ - 3. http://www.daltonmaag.com/ - 4. http://en.wikipedia.org/wiki/Network_effect - 5. http://scripts.sil.org/ - 6. http://openfontlibrary.org/ - 7. http://www.softwarefreedom.org/ - 8. http://code.google.com/webfonts - 9. http://www.gnu.org/licenses/gpl-faq.html#CanIUseGPLToolsForNF - 10. http://scripts.sil.org/OFL_web - 11. http://scripts.sil.org/OFL-FAQ_web - 12. http://www.gnu.org/licenses/gpl-faq.html#FontException - 13. https://launchpad.net/~uff-contributors - 14. http://font.ubuntu.com/ufl/ubuntu-font-licence-1.0.txt - 15. http://font.ubuntu.com/ufl/FAQ.html#embedding - 16. http://font.ubuntu.com/ufl/ofl-1.1-ufl-1.0.diff.html diff --git a/src/jogamp/graph/font/fonts/ubuntu/LICENCE.txt b/src/jogamp/graph/font/fonts/ubuntu/LICENCE.txt deleted file mode 100644 index ae78a8f94..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/LICENCE.txt +++ /dev/null @@ -1,96 +0,0 @@ -------------------------------- -UBUNTU FONT LICENCE Version 1.0 -------------------------------- - -PREAMBLE -This licence allows the licensed fonts to be used, studied, modified and -redistributed freely. The fonts, including any derivative works, can be -bundled, embedded, and redistributed provided the terms of this licence -are met. The fonts and derivatives, however, cannot be released under -any other licence. The requirement for fonts to remain under this -licence does not require any document created using the fonts or their -derivatives to be published under this licence, as long as the primary -purpose of the document is not to be a vehicle for the distribution of -the fonts. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this licence and clearly marked as such. This may -include source files, build scripts and documentation. - -"Original Version" refers to the collection of Font Software components -as received under this licence. - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to -a new environment. - -"Copyright Holder(s)" refers to all individuals and companies who have a -copyright ownership of the Font Software. - -"Substantially Changed" refers to Modified Versions which can be easily -identified as dissimilar to the Font Software by users of the Font -Software comparing the Original Version with the Modified Version. - -To "Propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification and with or without charging -a redistribution fee), making available to the public, and in some -countries other activities as well. - -PERMISSION & CONDITIONS -This licence does not grant any rights under trademark law and all such -rights are reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of the Font Software, to propagate the Font Software, subject to -the below conditions: - -1) Each copy of the Font Software must contain the above copyright -notice and this licence. These can be included either as stand-alone -text files, human-readable headers or in the appropriate machine- -readable metadata fields within text or binary files as long as those -fields can be easily viewed by the user. - -2) The font name complies with the following: -(a) The Original Version must retain its name, unmodified. -(b) Modified Versions which are Substantially Changed must be renamed to -avoid use of the name of the Original Version or similar names entirely. -(c) Modified Versions which are not Substantially Changed must be -renamed to both (i) retain the name of the Original Version and (ii) add -additional naming elements to distinguish the Modified Version from the -Original Version. The name of such Modified Versions must be the name of -the Original Version, with "derivative X" where X represents the name of -the new work, appended to that name. - -3) The name(s) of the Copyright Holder(s) and any contributor to the -Font Software shall not be used to promote, endorse or advertise any -Modified Version, except (i) as required by this licence, (ii) to -acknowledge the contribution(s) of the Copyright Holder(s) or (iii) with -their explicit written permission. - -4) The Font Software, modified or unmodified, in part or in whole, must -be distributed entirely under this licence, and must not be distributed -under any other licence. The requirement for fonts to remain under this -licence does not affect any document created using the Font Software, -except any version of the Font Software extracted from a document -created using the Font Software may only be distributed under this -licence. - -TERMINATION -This licence becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF -COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER -DEALINGS IN THE FONT SOFTWARE. diff --git a/src/jogamp/graph/font/fonts/ubuntu/README.txt b/src/jogamp/graph/font/fonts/ubuntu/README.txt deleted file mode 100644 index 292d4ade6..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/README.txt +++ /dev/null @@ -1,15 +0,0 @@ - ---------------------- - Ubuntu Font Family - ====================== - -The Ubuntu Font Family are a set of matching new libre/open fonts in -development during 2010--2011. The development is being funded by -Canonical Ltd on behalf the wider Free Software community and the -Ubuntu project. The technical font design work and implementation is -being undertaken by Dalton Maag. - -Both the final font Truetype/OpenType files and the design files used -to produce the font family are distributed under an open licence and -you are expressly encouraged to experiment, modify, share and improve. - - http://font.ubuntu.com/ diff --git a/src/jogamp/graph/font/fonts/ubuntu/TRADEMARKS.txt b/src/jogamp/graph/font/fonts/ubuntu/TRADEMARKS.txt deleted file mode 100644 index d34265bc8..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/TRADEMARKS.txt +++ /dev/null @@ -1,4 +0,0 @@ -Ubuntu and Canonical are registered trademarks of Canonical Ltd. - -The licence accompanying these works does not grant any rights -under trademark law and all such rights are reserved. diff --git a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-B.ttf b/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-B.ttf Binary files differdeleted file mode 100644 index 7639344e7..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-B.ttf +++ /dev/null diff --git a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-BI.ttf b/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-BI.ttf Binary files differdeleted file mode 100644 index 337b8a88b..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-BI.ttf +++ /dev/null diff --git a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-L.ttf b/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-L.ttf Binary files differdeleted file mode 100644 index c3b0fa46d..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-L.ttf +++ /dev/null diff --git a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-LI.ttf b/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-LI.ttf Binary files differdeleted file mode 100644 index d65e8eab3..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-LI.ttf +++ /dev/null diff --git a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-M.ttf b/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-M.ttf Binary files differdeleted file mode 100644 index 387ef03fc..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-M.ttf +++ /dev/null diff --git a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-MI.ttf b/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-MI.ttf Binary files differdeleted file mode 100644 index 5b92fcb5d..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-MI.ttf +++ /dev/null diff --git a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-R.ttf b/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-R.ttf Binary files differdeleted file mode 100644 index a46446440..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-R.ttf +++ /dev/null diff --git a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-RI.ttf b/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-RI.ttf Binary files differdeleted file mode 100644 index 0e0955918..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/Ubuntu-RI.ttf +++ /dev/null diff --git a/src/jogamp/graph/font/fonts/ubuntu/copyright.txt b/src/jogamp/graph/font/fonts/ubuntu/copyright.txt deleted file mode 100644 index 3a45d712e..000000000 --- a/src/jogamp/graph/font/fonts/ubuntu/copyright.txt +++ /dev/null @@ -1,5 +0,0 @@ -Copyright 2010 Canonical Ltd. - -This Font Software is licensed under the Ubuntu Font Licence, Version -1.0. https://launchpad.net/ubuntu-font-licence - diff --git a/src/jogamp/graph/font/typecast/TypecastFont.java b/src/jogamp/graph/font/typecast/TypecastFont.java deleted file mode 100644 index 0d018a314..000000000 --- a/src/jogamp/graph/font/typecast/TypecastFont.java +++ /dev/null @@ -1,268 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.font.typecast; - -import jogamp.graph.font.FontInt; -import jogamp.graph.geom.plane.AffineTransform; -import jogamp.graph.geom.plane.Path2D; -import net.java.dev.typecast.ot.OTFont; -import net.java.dev.typecast.ot.OTFontCollection; -import net.java.dev.typecast.ot.table.CmapFormat; -import net.java.dev.typecast.ot.table.CmapIndexEntry; -import net.java.dev.typecast.ot.table.CmapTable; -import net.java.dev.typecast.ot.table.HdmxTable; -import net.java.dev.typecast.ot.table.ID; - -import com.jogamp.common.util.IntObjectHashMap; -import com.jogamp.graph.geom.AABBox; - -class TypecastFont implements FontInt { - static final boolean DEBUG = false; - - final OTFontCollection fontset; - final OTFont font; - TypecastHMetrics metrics; - final CmapFormat cmapFormat; - int cmapentries; - - // FIXME: Add cache size to limit memory usage ?? - IntObjectHashMap char2Glyph; - - public TypecastFont(OTFontCollection fontset) { - this.fontset = fontset; - this.font = fontset.getFont(0); - - // FIXME: Generic attempt to find the best CmapTable, - // which is assumed to be the one with the most entries (stupid 'eh?) - CmapTable cmapTable = font.getCmapTable(); - CmapFormat[] _cmapFormatP = { null, null, null, null }; - int platform = -1; - int platformLength = -1; - int encoding = -1; - for(int i=0; i<cmapTable.getNumTables(); i++) { - CmapIndexEntry cmapIdxEntry = cmapTable.getCmapIndexEntry(i); - int pidx = cmapIdxEntry.getPlatformId(); - CmapFormat cf = cmapIdxEntry.getFormat(); - if(DEBUG) { - System.err.println("CmapFormat["+i+"]: platform " + pidx + - ", encoding "+cmapIdxEntry.getEncodingId() + ": "+cf); - } - if( _cmapFormatP[pidx] == null || - _cmapFormatP[pidx].getLength() < cf.getLength() ) { - _cmapFormatP[pidx] = cf; - if( cf.getLength() > platformLength ) { - platformLength = cf.getLength() ; - platform = pidx; - encoding = cmapIdxEntry.getEncodingId(); - } - } - } - if(0 <= platform) { - cmapFormat = _cmapFormatP[platform]; - if(DEBUG) { - System.err.println("Selected CmapFormat: platform " + platform + - ", encoding "+encoding + ": "+cmapFormat); - } - } else { - CmapFormat _cmapFormat = null; - /*if(null == _cmapFormat) { - platform = ID.platformMacintosh; - encoding = ID.encodingASCII; - _cmapFormat = cmapTable.getCmapFormat(platform, encoding); - } */ - if(null == _cmapFormat) { - // default unicode - platform = ID.platformMicrosoft; - encoding = ID.encodingUnicode; - _cmapFormat = cmapTable.getCmapFormat((short)platform, (short)encoding); - } - if(null == _cmapFormat) { - // maybe a symbol font ? - platform = ID.platformMicrosoft; - encoding = ID.encodingSymbol; - _cmapFormat = cmapTable.getCmapFormat((short)platform, (short)encoding); - } - if(null == _cmapFormat) { - throw new RuntimeException("Cannot find a suitable cmap table for font "+font); - } - cmapFormat = _cmapFormat; - if(DEBUG) { - System.err.println("Selected CmapFormat (2): platform " + platform + ", encoding "+encoding + ": "+cmapFormat); - } - } - - cmapentries = 0; - for (int i = 0; i < cmapFormat.getRangeCount(); ++i) { - CmapFormat.Range range = cmapFormat.getRange(i); - cmapentries += range.getEndCode() - range.getStartCode() + 1; // end included - } - if(DEBUG) { - System.err.println("num glyphs: "+font.getNumGlyphs()); - System.err.println("num cmap entries: "+cmapentries); - System.err.println("num cmap ranges: "+cmapFormat.getRangeCount()); - - for (int i = 0; i < cmapFormat.getRangeCount(); ++i) { - CmapFormat.Range range = cmapFormat.getRange(i); - for (int j = range.getStartCode(); j <= range.getEndCode(); ++j) { - final int code = cmapFormat.mapCharCode(j); - if(code < 15) { - System.err.println(" char: " + (int)j + " ( " + (char)j +" ) -> " + code); - } - } - } - } - char2Glyph = new IntObjectHashMap(cmapentries + cmapentries/4); - } - - public String getName() { - return fontset.getFileName(); - } - - public Metrics getMetrics() { - if (metrics == null) { - metrics = new TypecastHMetrics(this); - } - return metrics; - } - - public Glyph getGlyph(char symbol) { - TypecastGlyph result = (TypecastGlyph) char2Glyph.get(symbol); - if (null == result) { - // final short code = (short) char2Code.get(symbol); - short code = (short) cmapFormat.mapCharCode(symbol); - if(0 == code && 0 != symbol) { - // reserved special glyph IDs by convention - switch(symbol) { - case ' ': code = Glyph.ID_SPACE; break; - case '\n': code = Glyph.ID_CR; break; - default: code = Glyph.ID_UNKNOWN; - } - } - - net.java.dev.typecast.ot.OTGlyph glyph = font.getGlyph(code); - if(null == glyph) { - glyph = font.getGlyph(Glyph.ID_UNKNOWN); - } - if(null == glyph) { - throw new RuntimeException("Could not retrieve glyph for symbol: <"+symbol+"> "+(int)symbol+" -> glyph id "+code); - } - Path2D path = TypecastRenderer.buildPath(glyph); - result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), path); - if(DEBUG) { - System.err.println("New glyph: " + (int)symbol + " ( " + (char)symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + path); - } - final HdmxTable hdmx = font.getHdmxTable(); - if (null!= result && null != hdmx) { - /*if(DEBUG) { - System.err.println("hdmx "+hdmx); - }*/ - for (int i=0; i<hdmx.getNumberOfRecords(); i++) - { - final HdmxTable.DeviceRecord dr = hdmx.getRecord(i); - result.addAdvance(dr.getWidth(code), dr.getPixelSize()); - if(DEBUG) { - System.err.println("hdmx advance : pixelsize = "+dr.getWidth(code)+" : "+ dr.getPixelSize()); - } - } - } - char2Glyph.put(symbol, result); - } - return result; - } - - public void getOutline(String string, float pixelSize, AffineTransform transform, Path2D[] result) { - TypecastRenderer.getOutline(this, string, pixelSize, transform, result); - } - - public float getStringWidth(String string, float pixelSize) { - float width = 0; - final int len = string.length(); - for (int i=0; i< len; i++) - { - char character = string.charAt(i); - if (character == '\n') { - width = 0; - } else { - Glyph glyph = getGlyph(character); - width += glyph.getAdvance(pixelSize, false); - } - } - - return (int)(width + 0.5f); - } - - public float getStringHeight(String string, float pixelSize) { - int height = 0; - - for (int i=0; i<string.length(); i++) - { - char character = string.charAt(i); - if (character != ' ') - { - Glyph glyph = getGlyph(character); - AABBox bbox = glyph.getBBox(pixelSize); - height = (int)Math.ceil(Math.max(bbox.getHeight(), height)); - } - } - return height; - } - - public AABBox getStringBounds(CharSequence string, float pixelSize) { - if (string == null) { - return new AABBox(); - } - final Metrics metrics = getMetrics(); - final float lineGap = metrics.getLineGap(pixelSize); - final float ascent = metrics.getAscent(pixelSize); - final float descent = metrics.getDescent(pixelSize); - final float advanceY = lineGap - descent + ascent; - float totalHeight = 0; - float totalWidth = 0; - float curLineWidth = 0; - for (int i=0; i<string.length(); i++) { - char character = string.charAt(i); - if (character == '\n') { - totalWidth = Math.max(curLineWidth, totalWidth); - curLineWidth = 0; - totalHeight -= advanceY; - continue; - } - Glyph glyph = getGlyph(character); - curLineWidth += glyph.getAdvance(pixelSize, true); - } - if (curLineWidth > 0) { - totalHeight -= advanceY; - totalWidth = Math.max(curLineWidth, totalWidth); - } - return new AABBox(0, 0, 0, totalWidth, totalHeight,0); - } - - final public int getNumGlyphs() { - return font.getNumGlyphs(); - } -}
\ No newline at end of file diff --git a/src/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogamp/graph/font/typecast/TypecastGlyph.java deleted file mode 100644 index 88d865f9c..000000000 --- a/src/jogamp/graph/font/typecast/TypecastGlyph.java +++ /dev/null @@ -1,232 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.font.typecast; - -import java.util.HashMap; - -import jogamp.graph.font.FontInt; -import jogamp.graph.geom.plane.AffineTransform; -import jogamp.graph.geom.plane.Path2D; - -import com.jogamp.graph.font.Font; -import com.jogamp.graph.geom.AABBox; - -public class TypecastGlyph implements FontInt.Glyph { - public class Advance - { - final Font font; - final float advance; - HashMap<Float, Float> size2advance = new HashMap<Float, Float>(); - - public Advance(Font font, float advance) - { - this.font = font; - this.advance = advance; - } - - public void reset() { - size2advance.clear(); - } - - public float getScale(float pixelSize) - { - return this.font.getMetrics().getScale(pixelSize); - } - - public void add(float advance, float size) - { - size2advance.put(size, advance); - } - - public float get(float size, boolean useFrationalMetrics) - { - Float fo = size2advance.get(size); - if(null == fo) { - float value = (this.advance * getScale(size)); - if (useFrationalMetrics == false) { - //value = (float)Math.ceil(value); - // value = (int)value; - value = (int) ( value + 0.5f ) ; // TODO: check - } - size2advance.put(size, value); - return value; - } - return fo.floatValue(); - } - - public String toString() - { - return "\nAdvance:"+ - "\n advance: "+this.advance+ - "\n advances: \n"+size2advance; - } - } - - public class Metrics - { - AABBox bbox; - Advance advance; - - public Metrics(Font font, AABBox bbox, float advance) - { - this.bbox = bbox; - this.advance = new Advance(font, advance); - } - - public void reset() { - advance.reset(); - } - - public float getScale(float pixelSize) - { - return this.advance.getScale(pixelSize); - } - - public AABBox getBBox() - { - return this.bbox; - } - - public void addAdvance(float advance, float size) - { - this.advance.add(advance, size); - } - - public float getAdvance(float size, boolean useFrationalMetrics) - { - return this.advance.get(size, useFrationalMetrics); - } - - public String toString() - { - return "\nMetrics:"+ - "\n bbox: "+this.bbox+ - this.advance; - } - } - - public static final short INVALID_ID = (short)((1 << 16) - 1); - public static final short MAX_ID = (short)((1 << 16) - 2); - - private final Font font; - - char symbol; - short id; - int advance; - Metrics metrics; - - protected Path2D path; // in EM units - protected Path2D pathSized; - protected float numberSized; - - protected TypecastGlyph(Font font, char symbol) { - this.font = font; - this.symbol = symbol; - } - - protected TypecastGlyph(Font font, - char symbol, short id, AABBox bbox, int advance, Path2D path) { - this.font = font; - this.symbol = symbol; - this.advance = advance; - - init(id, bbox, advance); - - this.path = path; - this.pathSized = null; - this.numberSized = 0.0f; - } - - void init(short id, AABBox bbox, int advance) { - this.id = id; - this.advance = advance; - this.metrics = new Metrics(this.font, bbox, this.advance); - } - - public void reset(Path2D path) { - this.path = path; - this.metrics.reset(); - } - - public Font getFont() { - return this.font; - } - - public char getSymbol() { - return this.symbol; - } - - AABBox getBBoxUnsized() { - return this.metrics.getBBox(); - } - - public AABBox getBBox() { - return this.metrics.getBBox(); - } - - public Metrics getMetrics() { - return this.metrics; - } - - public short getID() { - return this.id; - } - - public float getScale(float pixelSize) { - return this.metrics.getScale(pixelSize); - } - - public AABBox getBBox(float pixelSize) { - final float size = getScale(pixelSize); - AABBox newBox = getBBox().clone(); - newBox.scale(size); - return newBox; - } - - protected void addAdvance(float advance, float size) { - this.metrics.addAdvance(advance, size); - } - - public float getAdvance(float pixelSize, boolean useFrationalMetrics) { - return this.metrics.getAdvance(pixelSize, useFrationalMetrics); - } - - public Path2D getPath() { - return this.path; - } - - public Path2D getPath(float pixelSize) { - final float size = getScale(pixelSize); - - if (this.numberSized != size) { - this.numberSized = size; - this.pathSized = AffineTransform.getScaleInstance(null, size, size).createTransformedShape(getPath()); - } - return this.pathSized; - } -} diff --git a/src/jogamp/graph/font/typecast/TypecastHMetrics.java b/src/jogamp/graph/font/typecast/TypecastHMetrics.java deleted file mode 100644 index cd8595498..000000000 --- a/src/jogamp/graph/font/typecast/TypecastHMetrics.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.font.typecast; - -import net.java.dev.typecast.ot.table.HeadTable; -import net.java.dev.typecast.ot.table.HheaTable; -import com.jogamp.graph.font.Font.Metrics; -import com.jogamp.graph.geom.AABBox; - -class TypecastHMetrics implements Metrics { - private final TypecastFont fontImpl; - - // HeadTable - private final HeadTable headTable; - private final float unitsPerEM_Inv; - private final AABBox bbox; - // HheaTable - private final HheaTable hheaTable; - // VheaTable (for horizontal fonts) - // private final VheaTable vheaTable; - - public TypecastHMetrics(TypecastFont fontImpl) { - this.fontImpl = fontImpl; - headTable = this.fontImpl.font.getHeadTable(); - hheaTable = this.fontImpl.font.getHheaTable(); - // vheaTable = this.fontImpl.font.getVheaTable(); - unitsPerEM_Inv = 1.0f / ( (float) headTable.getUnitsPerEm() ); - - int maxWidth = headTable.getXMax() - headTable.getXMin(); - int maxHeight = headTable.getYMax() - headTable.getYMin(); - float lowx= headTable.getXMin(); - float lowy = -(headTable.getYMin()+maxHeight); - float highx = lowx + maxWidth; - float highy = lowy + maxHeight; - bbox = new AABBox(lowx, lowy, 0, highx, highy, 0); // invert - } - - public final float getAscent(float pixelSize) { - return getScale(pixelSize) * -hheaTable.getAscender(); // invert - } - public final float getDescent(float pixelSize) { - return getScale(pixelSize) * -hheaTable.getDescender(); // invert - } - public final float getLineGap(float pixelSize) { - return getScale(pixelSize) * -hheaTable.getLineGap(); // invert - } - public final float getMaxExtend(float pixelSize) { - return getScale(pixelSize) * hheaTable.getXMaxExtent(); - } - public final float getScale(float pixelSize) { - return pixelSize * unitsPerEM_Inv; - } - public final AABBox getBBox(float pixelSize) { - AABBox res = new AABBox(bbox.getLow(), bbox.getHigh()); - res.scale(getScale(pixelSize)); - return res; - } -}
\ No newline at end of file diff --git a/src/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogamp/graph/font/typecast/TypecastRenderer.java deleted file mode 100644 index 410f5b73a..000000000 --- a/src/jogamp/graph/font/typecast/TypecastRenderer.java +++ /dev/null @@ -1,163 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.font.typecast; - -import jogamp.graph.geom.plane.AffineTransform; -import jogamp.graph.geom.plane.Path2D; - -import com.jogamp.graph.font.Font; -import net.java.dev.typecast.ot.Point; -import net.java.dev.typecast.ot.OTGlyph; - -/** - * Factory to build a {@link com.jogamp.graph.geom.Path2D Path2D} from - * {@link net.java.dev.typecast.ot.OTGlyph Glyph}s. - */ -public class TypecastRenderer { - - public static void getOutline(TypecastFont font, - String string, float pixelSize, AffineTransform transform, Path2D[] p) - { - if (string == null) { - return; - } - Font.Metrics metrics = font.getMetrics(); - float advanceTotal = 0; - float lineGap = metrics.getLineGap(pixelSize) ; - float ascent = metrics.getAscent(pixelSize) ; - float descent = metrics.getDescent(pixelSize) ; - if (transform == null) { - transform = new AffineTransform(); - } - AffineTransform t = new AffineTransform(); - - float advanceY = lineGap - descent + ascent; - float y = 0; - for (int i=0; i<string.length(); i++) - { - p[i] = new Path2D(); - p[i].reset(); - t.setTransform(transform); - char character = string.charAt(i); - if (character == '\n') { - y -= advanceY; - advanceTotal = 0; - continue; - } else if (character == ' ') { - advanceTotal += font.font.getHmtxTable().getAdvanceWidth(TypecastGlyph.ID_SPACE) * metrics.getScale(pixelSize); - continue; - } - TypecastGlyph glyph = (TypecastGlyph) font.getGlyph(character); - Path2D gp = glyph.getPath(); - float scale = metrics.getScale(pixelSize); - t.translate(advanceTotal, y); - t.scale(scale, scale); - p[i].append(gp.iterator(t), false); - advanceTotal += glyph.getAdvance(pixelSize, true); - } - } - - /** - * Build a {@link com.jogamp.graph.geom.Path2D Path2D} from a - * {@link net.java.dev.typecast.ot.OTGlyph Glyph}. This glyph path can then - * be transformed and rendered. - */ - public static Path2D buildPath(OTGlyph glyph) { - - if (glyph == null) { - return null; - } - - Path2D glyphPath = new Path2D(); - - // Iterate through all of the points in the glyph. Each time we find a - // contour end point, add the point range to the path. - int firstIndex = 0; - int count = 0; - for (int i = 0; i < glyph.getPointCount(); i++) { - count++; - if (glyph.getPoint(i).endOfContour) { - addContourToPath(glyphPath, glyph, firstIndex, count); - firstIndex = i + 1; - count = 0; - } - } - return glyphPath; - } - - private static void addContourToPath(Path2D gp, OTGlyph glyph, int startIndex, int count) { - int offset = 0; - while (offset < count) { - Point point = glyph.getPoint(startIndex + offset%count); - Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count); - Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count); - if(offset == 0) - { - gp.moveTo(point.x, -point.y); - } - - if (point.onCurve) { - if (point_plus1.onCurve) { - // s = new Line2D.Float(point.x, -point.y, point_plus1.x, -point_plus1.y); - gp.lineTo( point_plus1.x, -point_plus1.y ); - offset++; - } else { - if (point_plus2.onCurve) { - // s = new QuadCurve2D.Float( point.x, -point.y, point_plus1.x, -point_plus1.y, point_plus2.x, -point_plus2.y); - gp.quadTo(point_plus1.x, -point_plus1.y, point_plus2.x, -point_plus2.y); - offset+=2; - } else { - // s = new QuadCurve2D.Float(point.x,-point.y,point_plus1.x,-point_plus1.y, - // midValue(point_plus1.x, point_plus2.x), -midValue(point_plus1.y, point_plus2.y)); - gp.quadTo(point_plus1.x, -point_plus1.y, midValue(point_plus1.x, point_plus2.x), -midValue(point_plus1.y, point_plus2.y)); - offset+=2; - } - } - } else { - if (point_plus1.onCurve) { - // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), -midValue(point_minus1.y, point.y), - // point.x, -point.y, point_plus1.x, -point_plus1.y); - //gp.curve3(point_plus1.x, -point_plus1.y, point.x, -point.y); - gp.quadTo(point.x, -point.y, point_plus1.x, -point_plus1.y); - offset++; - - } else { - // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), -midValue(point_minus1.y, point.y), point.x, -point.y, - // midValue(point.x, point_plus1.x), -midValue(point.y, point_plus1.y)); - //gp.curve3(midValue(point.x, point_plus1.x), -midValue(point.y, point_plus1.y), point.x, -point.y); - gp.quadTo(point.x, -point.y, midValue(point.x, point_plus1.x), -midValue(point.y, point_plus1.y)); - offset++; - } - } - } - } - - private static int midValue(int a, int b) { - return a + (b - a)/2; - } -} diff --git a/src/jogamp/graph/geom/plane/AffineTransform.java b/src/jogamp/graph/geom/plane/AffineTransform.java deleted file mode 100644 index 2ba9f8d06..000000000 --- a/src/jogamp/graph/geom/plane/AffineTransform.java +++ /dev/null @@ -1,580 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - */ -package jogamp.graph.geom.plane; - -import java.io.IOException; -import java.io.Serializable; - -import jogamp.graph.math.MathFloat; -import org.apache.harmony.misc.HashCode; - -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Vertex.Factory; - -public class AffineTransform implements Cloneable, Serializable { - - private static final long serialVersionUID = 1330973210523860834L; - - static final String determinantIsZero = "Determinant is zero"; - - public static final int TYPE_IDENTITY = 0; - public static final int TYPE_TRANSLATION = 1; - public static final int TYPE_UNIFORM_SCALE = 2; - public static final int TYPE_GENERAL_SCALE = 4; - public static final int TYPE_QUADRANT_ROTATION = 8; - public static final int TYPE_GENERAL_ROTATION = 16; - public static final int TYPE_GENERAL_TRANSFORM = 32; - public static final int TYPE_FLIP = 64; - public static final int TYPE_MASK_SCALE = TYPE_UNIFORM_SCALE | TYPE_GENERAL_SCALE; - public static final int TYPE_MASK_ROTATION = TYPE_QUADRANT_ROTATION | TYPE_GENERAL_ROTATION; - - /** - * The <code>TYPE_UNKNOWN</code> is an initial type value - */ - static final int TYPE_UNKNOWN = -1; - - /** - * The min value equivalent to zero. If absolute value less then ZERO it considered as zero. - */ - static final float ZERO = (float) 1E-10; - - private final Vertex.Factory<? extends Vertex> pointFactory; - - /** - * The values of transformation matrix - */ - float m00; - float m10; - float m01; - float m11; - float m02; - float m12; - - /** - * The transformation <code>type</code> - */ - transient int type; - - public AffineTransform() { - pointFactory = null; - type = TYPE_IDENTITY; - m00 = m11 = 1.0f; - m10 = m01 = m02 = m12 = 0.0f; - } - - public AffineTransform(Factory<? extends Vertex> factory) { - pointFactory = factory; - type = TYPE_IDENTITY; - m00 = m11 = 1.0f; - m10 = m01 = m02 = m12 = 0.0f; - } - - public AffineTransform(AffineTransform t) { - this.pointFactory = t.pointFactory; - this.type = t.type; - this.m00 = t.m00; - this.m10 = t.m10; - this.m01 = t.m01; - this.m11 = t.m11; - this.m02 = t.m02; - this.m12 = t.m12; - } - - public AffineTransform(Vertex.Factory<? extends Vertex> factory, float m00, float m10, float m01, float m11, float m02, float m12) { - pointFactory = factory; - this.type = TYPE_UNKNOWN; - this.m00 = m00; - this.m10 = m10; - this.m01 = m01; - this.m11 = m11; - this.m02 = m02; - this.m12 = m12; - } - - public AffineTransform(Vertex.Factory<? extends Vertex> factory, float[] matrix) { - pointFactory = factory; - this.type = TYPE_UNKNOWN; - m00 = matrix[0]; - m10 = matrix[1]; - m01 = matrix[2]; - m11 = matrix[3]; - if (matrix.length > 4) { - m02 = matrix[4]; - m12 = matrix[5]; - } - } - - /* - * Method returns type of affine transformation. - * - * Transform matrix is - * m00 m01 m02 - * m10 m11 m12 - * - * According analytic geometry new basis vectors are (m00, m01) and (m10, m11), - * translation vector is (m02, m12). Original basis vectors are (1, 0) and (0, 1). - * Type transformations classification: - * TYPE_IDENTITY - new basis equals original one and zero translation - * TYPE_TRANSLATION - translation vector isn't zero - * TYPE_UNIFORM_SCALE - vectors length of new basis equals - * TYPE_GENERAL_SCALE - vectors length of new basis doesn't equal - * TYPE_FLIP - new basis vector orientation differ from original one - * TYPE_QUADRANT_ROTATION - new basis is rotated by 90, 180, 270, or 360 degrees - * TYPE_GENERAL_ROTATION - new basis is rotated by arbitrary angle - * TYPE_GENERAL_TRANSFORM - transformation can't be inversed - */ - public int getType() { - if (type != TYPE_UNKNOWN) { - return type; - } - - int type = 0; - - if (m00 * m01 + m10 * m11 != 0.0) { - type |= TYPE_GENERAL_TRANSFORM; - return type; - } - - if (m02 != 0.0 || m12 != 0.0) { - type |= TYPE_TRANSLATION; - } else - if (m00 == 1.0 && m11 == 1.0 && m01 == 0.0 && m10 == 0.0) { - type = TYPE_IDENTITY; - return type; - } - - if (m00 * m11 - m01 * m10 < 0.0) { - type |= TYPE_FLIP; - } - - float dx = m00 * m00 + m10 * m10; - float dy = m01 * m01 + m11 * m11; - if (dx != dy) { - type |= TYPE_GENERAL_SCALE; - } else - if (dx != 1.0) { - type |= TYPE_UNIFORM_SCALE; - } - - if ((m00 == 0.0 && m11 == 0.0) || - (m10 == 0.0 && m01 == 0.0 && (m00 < 0.0 || m11 < 0.0))) - { - type |= TYPE_QUADRANT_ROTATION; - } else - if (m01 != 0.0 || m10 != 0.0) { - type |= TYPE_GENERAL_ROTATION; - } - - return type; - } - - public float getScaleX() { - return m00; - } - - public float getScaleY() { - return m11; - } - - public float getShearX() { - return m01; - } - - public float getShearY() { - return m10; - } - - public float getTranslateX() { - return m02; - } - - public float getTranslateY() { - return m12; - } - - public boolean isIdentity() { - return getType() == TYPE_IDENTITY; - } - - public void getMatrix(float[] matrix) { - matrix[0] = m00; - matrix[1] = m10; - matrix[2] = m01; - matrix[3] = m11; - if (matrix.length > 4) { - matrix[4] = m02; - matrix[5] = m12; - } - } - - public float getDeterminant() { - return m00 * m11 - m01 * m10; - } - - public void setTransform(float m00, float m10, float m01, float m11, float m02, float m12) { - this.type = TYPE_UNKNOWN; - this.m00 = m00; - this.m10 = m10; - this.m01 = m01; - this.m11 = m11; - this.m02 = m02; - this.m12 = m12; - } - - public void setTransform(AffineTransform t) { - type = t.type; - setTransform(t.m00, t.m10, t.m01, t.m11, t.m02, t.m12); - } - - public void setToIdentity() { - type = TYPE_IDENTITY; - m00 = m11 = 1.0f; - m10 = m01 = m02 = m12 = 0.0f; - } - - public void setToTranslation(float mx, float my) { - m00 = m11 = 1.0f; - m01 = m10 = 0.0f; - m02 = mx; - m12 = my; - if (mx == 0.0f && my == 0.0f) { - type = TYPE_IDENTITY; - } else { - type = TYPE_TRANSLATION; - } - } - - public void setToScale(float scx, float scy) { - m00 = scx; - m11 = scy; - m10 = m01 = m02 = m12 = 0.0f; - if (scx != 1.0f || scy != 1.0f) { - type = TYPE_UNKNOWN; - } else { - type = TYPE_IDENTITY; - } - } - - public void setToShear(float shx, float shy) { - m00 = m11 = 1.0f; - m02 = m12 = 0.0f; - m01 = shx; - m10 = shy; - if (shx != 0.0f || shy != 0.0f) { - type = TYPE_UNKNOWN; - } else { - type = TYPE_IDENTITY; - } - } - - public void setToRotation(float angle) { - float sin = MathFloat.sin(angle); - float cos = MathFloat.cos(angle); - if (MathFloat.abs(cos) < ZERO) { - cos = 0.0f; - sin = sin > 0.0f ? 1.0f : -1.0f; - } else - if (MathFloat.abs(sin) < ZERO) { - sin = 0.0f; - cos = cos > 0.0f ? 1.0f : -1.0f; - } - m00 = m11 = cos; - m01 = -sin; - m10 = sin; - m02 = m12 = 0.0f; - type = TYPE_UNKNOWN; - } - - public void setToRotation(float angle, float px, float py) { - setToRotation(angle); - m02 = px * (1.0f - m00) + py * m10; - m12 = py * (1.0f - m00) - px * m10; - type = TYPE_UNKNOWN; - } - - public static <T extends Vertex> AffineTransform getTranslateInstance(Vertex.Factory<? extends Vertex> factory, float mx, float my) { - AffineTransform t = new AffineTransform(factory); - t.setToTranslation(mx, my); - return t; - } - - public static <T extends Vertex> AffineTransform getScaleInstance(Vertex.Factory<? extends Vertex> factory, float scx, float scY) { - AffineTransform t = new AffineTransform(factory); - t.setToScale(scx, scY); - return t; - } - - public static <T extends Vertex> AffineTransform getShearInstance(Vertex.Factory<? extends Vertex> factory, float shx, float shy) { - AffineTransform t = new AffineTransform(factory); - t.setToShear(shx, shy); - return t; - } - - public static <T extends Vertex> AffineTransform getRotateInstance(Vertex.Factory<? extends Vertex> factory, float angle) { - AffineTransform t = new AffineTransform(factory); - t.setToRotation(angle); - return t; - } - - public static <T extends Vertex> AffineTransform getRotateInstance(Vertex.Factory<? extends Vertex> factory, float angle, float x, float y) { - AffineTransform t = new AffineTransform(factory); - t.setToRotation(angle, x, y); - return t; - } - - public void translate(float mx, float my) { - concatenate(AffineTransform.getTranslateInstance(pointFactory, mx, my)); - } - - public void scale(float scx, float scy) { - concatenate(AffineTransform.getScaleInstance(pointFactory, scx, scy)); - } - - public void shear(float shx, float shy) { - concatenate(AffineTransform.getShearInstance(pointFactory, shx, shy)); - } - - public void rotate(float angle) { - concatenate(AffineTransform.getRotateInstance(pointFactory, angle)); - } - - public void rotate(float angle, float px, float py) { - concatenate(AffineTransform.getRotateInstance(pointFactory, angle, px, py)); - } - - /** - * Multiply matrix of two AffineTransform objects. - * The first argument's {@link Vertex.Factory} is being used. - * - * @param t1 - the AffineTransform object is a multiplicand - * @param t2 - the AffineTransform object is a multiplier - * @return an AffineTransform object that is a result of t1 multiplied by matrix t2. - */ - AffineTransform multiply(AffineTransform t1, AffineTransform t2) { - return new AffineTransform(t1.pointFactory, - t1.m00 * t2.m00 + t1.m10 * t2.m01, // m00 - t1.m00 * t2.m10 + t1.m10 * t2.m11, // m01 - t1.m01 * t2.m00 + t1.m11 * t2.m01, // m10 - t1.m01 * t2.m10 + t1.m11 * t2.m11, // m11 - t1.m02 * t2.m00 + t1.m12 * t2.m01 + t2.m02, // m02 - t1.m02 * t2.m10 + t1.m12 * t2.m11 + t2.m12);// m12 - } - - public void concatenate(AffineTransform t) { - setTransform(multiply(t, this)); - } - - public void preConcatenate(AffineTransform t) { - setTransform(multiply(this, t)); - } - - public AffineTransform createInverse() throws NoninvertibleTransformException { - float det = getDeterminant(); - if (MathFloat.abs(det) < ZERO) { - throw new NoninvertibleTransformException(determinantIsZero); - } - return new AffineTransform( - this.pointFactory, - m11 / det, // m00 - -m10 / det, // m10 - -m01 / det, // m01 - m00 / det, // m11 - (m01 * m12 - m11 * m02) / det, // m02 - (m10 * m02 - m00 * m12) / det // m12 - ); - } - - public Vertex transform(Vertex src, Vertex dst) { - if (dst == null) { - dst = pointFactory.create(); - } - - float x = src.getX(); - float y = src.getY(); - - dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); - return dst; - } - - public void transform(Vertex[] src, int srcOff, Vertex[] dst, int dstOff, int length) { - while (--length >= 0) { - Vertex srcPoint = src[srcOff++]; - float x = srcPoint.getX(); - float y = srcPoint.getY(); - Vertex dstPoint = dst[dstOff]; - if (dstPoint == null) { - throw new IllegalArgumentException("dst["+dstOff+"] is null"); - } - dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); - dst[dstOff++] = dstPoint; - } - } - - public void transform(float[] src, int srcOff, float[] dst, int dstOff, int length) { - int step = 2; - if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) { - srcOff = srcOff + length * 2 - 2; - dstOff = dstOff + length * 2 - 2; - step = -2; - } - while (--length >= 0) { - float x = src[srcOff + 0]; - float y = src[srcOff + 1]; - dst[dstOff + 0] = x * m00 + y * m01 + m02; - dst[dstOff + 1] = x * m10 + y * m11 + m12; - srcOff += step; - dstOff += step; - } - } - - public Vertex deltaTransform(Vertex src, Vertex dst) { - if (dst == null) { - dst = pointFactory.create(); - } - - float x = src.getX(); - float y = src.getY(); - - dst.setCoord(x * m00 + y * m01, x * m10 + y * m11); - return dst; - } - - public void deltaTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) { - while (--length >= 0) { - float x = src[srcOff++]; - float y = src[srcOff++]; - dst[dstOff++] = x * m00 + y * m01; - dst[dstOff++] = x * m10 + y * m11; - } - } - - public Vertex inverseTransform(Vertex src, Vertex dst) throws NoninvertibleTransformException { - float det = getDeterminant(); - if (MathFloat.abs(det) < ZERO) { - throw new NoninvertibleTransformException(determinantIsZero); - } - if (dst == null) { - dst = pointFactory.create(); - } - - float x = src.getX() - m02; - float y = src.getY() - m12; - - dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det); - return dst; - } - - public void inverseTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) - throws NoninvertibleTransformException - { - float det = getDeterminant(); - if (MathFloat.abs(det) < ZERO) { - throw new NoninvertibleTransformException(determinantIsZero); - } - - while (--length >= 0) { - float x = src[srcOff++] - m02; - float y = src[srcOff++] - m12; - dst[dstOff++] = (x * m11 - y * m01) / det; - dst[dstOff++] = (y * m00 - x * m10) / det; - } - } - - public Path2D createTransformedShape(Path2D src) { - if (src == null) { - return null; - } - if (src instanceof Path2D) { - return ((Path2D)src).createTransformedShape(this); - } - PathIterator path = src.iterator(this); - Path2D dst = new Path2D(path.getWindingRule()); - dst.append(path, false); - return dst; - } - - @Override - public String toString() { - return - getClass().getName() + - "[[" + m00 + ", " + m01 + ", " + m02 + "], [" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - + m10 + ", " + m11 + ", " + m12 + "]]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - - @Override - public int hashCode() { - HashCode hash = new HashCode(); - hash.append(m00); - hash.append(m01); - hash.append(m02); - hash.append(m10); - hash.append(m11); - hash.append(m12); - return hash.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof AffineTransform) { - AffineTransform t = (AffineTransform)obj; - return - m00 == t.m00 && m01 == t.m01 && - m02 == t.m02 && m10 == t.m10 && - m11 == t.m11 && m12 == t.m12; - } - return false; - } - - - /** - * Write AffineTrasform object to the output steam. - * @param stream - the output stream - * @throws IOException - if there are I/O errors while writing to the output strem - */ - private void writeObject(java.io.ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - } - - - /** - * Read AffineTransform object from the input stream - * @param stream - the input steam - * @throws IOException - if there are I/O errors while reading from the input strem - * @throws ClassNotFoundException - if class could not be found - */ - private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - type = TYPE_UNKNOWN; - } - -} - diff --git a/src/jogamp/graph/geom/plane/IllegalPathStateException.java b/src/jogamp/graph/geom/plane/IllegalPathStateException.java deleted file mode 100644 index 55211b3f9..000000000 --- a/src/jogamp/graph/geom/plane/IllegalPathStateException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - */ -package jogamp.graph.geom.plane; - -public class IllegalPathStateException extends RuntimeException { - - private static final long serialVersionUID = -5158084205220481094L; - - public IllegalPathStateException() { - } - - public IllegalPathStateException(String s) { - super(s); - } - -} - diff --git a/src/jogamp/graph/geom/plane/NoninvertibleTransformException.java b/src/jogamp/graph/geom/plane/NoninvertibleTransformException.java deleted file mode 100644 index 398a03fca..000000000 --- a/src/jogamp/graph/geom/plane/NoninvertibleTransformException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - */ -package jogamp.graph.geom.plane; - -public class NoninvertibleTransformException extends java.lang.Exception { - - private static final long serialVersionUID = 6137225240503990466L; - - public NoninvertibleTransformException(String s) { - super(s); - } - -} - diff --git a/src/jogamp/graph/geom/plane/Path2D.java b/src/jogamp/graph/geom/plane/Path2D.java deleted file mode 100644 index 431891361..000000000 --- a/src/jogamp/graph/geom/plane/Path2D.java +++ /dev/null @@ -1,428 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - */ -package jogamp.graph.geom.plane; - -import java.util.NoSuchElementException; - -import com.jogamp.graph.geom.AABBox; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.opengl.SVertex; - -import jogamp.graph.math.plane.Crossing; - -public final class Path2D implements Cloneable { - - public static final int WIND_EVEN_ODD = PathIterator.WIND_EVEN_ODD; - public static final int WIND_NON_ZERO = PathIterator.WIND_NON_ZERO; - - static final String invalidWindingRuleValue = "Invalid winding rule value"; - static final String iteratorOutOfBounds = "Iterator out of bounds"; - - /** - * The buffers size - */ - private static final int BUFFER_SIZE = 10; - - /** - * The buffers capacity - */ - private static final int BUFFER_CAPACITY = 10; - - /** - * The point's types buffer - */ - byte[] types; - - /** - * The points buffer - */ - float[] points; - - /** - * The point's type buffer size - */ - int typeSize; - - /** - * The points buffer size - */ - int pointSize; - - /** - * The path rule - */ - int rule; - - /** - * The space amount in points buffer for different segmenet's types - */ - static int pointShift[] = { - 2, // MOVETO - 2, // LINETO - 4, // QUADTO - 6, // CUBICTO - 0}; // CLOSE - - /* - * GeneralPath path iterator - */ - class Iterator implements PathIterator { - - /** - * The current cursor position in types buffer - */ - int typeIndex; - - /** - * The current cursor position in points buffer - */ - int pointIndex; - - /** - * The source GeneralPath object - */ - Path2D p; - - /** - * The path iterator transformation - */ - AffineTransform t; - - /** - * Constructs a new GeneralPath.Iterator for given general path - * @param path - the source GeneralPath object - */ - Iterator(Path2D path) { - this(path, null); - } - - /** - * Constructs a new GeneralPath.Iterator for given general path and transformation - * @param path - the source GeneralPath object - * @param at - the AffineTransform object to apply rectangle path - */ - Iterator(Path2D path, AffineTransform at) { - this.p = path; - this.t = at; - } - - public int getWindingRule() { - return p.getWindingRule(); - } - - public boolean isDone() { - return typeIndex >= p.typeSize; - } - - public void next() { - typeIndex++; - } - - public int currentSegment(float[] coords) { - if (isDone()) { - throw new NoSuchElementException(iteratorOutOfBounds); - } - int type = p.types[typeIndex]; - int count = Path2D.pointShift[type]; - System.arraycopy(p.points, pointIndex, coords, 0, count); - if (t != null) { - t.transform(coords, 0, coords, 0, count / 2); - } - pointIndex += count; - return type; - } - - } - - public Path2D() { - this(WIND_NON_ZERO, BUFFER_SIZE); - } - - public Path2D(int rule) { - this(rule, BUFFER_SIZE); - } - - public Path2D(int rule, int initialCapacity) { - setWindingRule(rule); - types = new byte[initialCapacity]; - points = new float[initialCapacity * 2]; - } - - public Path2D(Path2D path) { - this(WIND_NON_ZERO, BUFFER_SIZE); - PathIterator p = path.iterator(null); - setWindingRule(p.getWindingRule()); - append(p, false); - } - - public void setWindingRule(int rule) { - if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) { - throw new NoSuchElementException(invalidWindingRuleValue); - } - this.rule = rule; - } - - public int getWindingRule() { - return rule; - } - - /** - * Checks points and types buffer size to add pointCount points. If necessary realloc buffers to enlarge size. - * @param pointCount - the point count to be added in buffer - */ - void checkBuf(int pointCount, boolean checkMove) { - if (checkMove && typeSize == 0) { - throw new IllegalPathStateException("First segment should be SEG_MOVETO type"); - } - if (typeSize == types.length) { - byte tmp[] = new byte[typeSize + BUFFER_CAPACITY]; - System.arraycopy(types, 0, tmp, 0, typeSize); - types = tmp; - } - if (pointSize + pointCount > points.length) { - float tmp[] = new float[pointSize + Math.max(BUFFER_CAPACITY * 2, pointCount)]; - System.arraycopy(points, 0, tmp, 0, pointSize); - points = tmp; - } - } - - public void moveTo(float x, float y) { - if (typeSize > 0 && types[typeSize - 1] == PathIterator.SEG_MOVETO) { - points[pointSize - 2] = x; - points[pointSize - 1] = y; - } else { - checkBuf(2, false); - types[typeSize++] = PathIterator.SEG_MOVETO; - points[pointSize++] = x; - points[pointSize++] = y; - } - } - - public void lineTo(float x, float y) { - checkBuf(2, true); - types[typeSize++] = PathIterator.SEG_LINETO; - points[pointSize++] = x; - points[pointSize++] = y; - } - - public void quadTo(float x1, float y1, float x2, float y2) { - checkBuf(4, true); - types[typeSize++] = PathIterator.SEG_QUADTO; - points[pointSize++] = x1; - points[pointSize++] = y1; - points[pointSize++] = x2; - points[pointSize++] = y2; - } - - public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) { - checkBuf(6, true); - types[typeSize++] = PathIterator.SEG_CUBICTO; - points[pointSize++] = x1; - points[pointSize++] = y1; - points[pointSize++] = x2; - points[pointSize++] = y2; - points[pointSize++] = x3; - points[pointSize++] = y3; - } - - final public int size() { - return typeSize; - } - - final public boolean isClosed() { - return typeSize > 0 && types[typeSize - 1] == PathIterator.SEG_CLOSE ; - } - - public void closePath() { - if (!isClosed()) { - checkBuf(0, true); - types[typeSize++] = PathIterator.SEG_CLOSE; - } - } - - public String toString() { - return "[size "+size()+", closed "+isClosed()+"]"; - } - - public void append(Path2D path, boolean connect) { - PathIterator p = path.iterator(null); - append(p, connect); - } - - public void append(PathIterator path, boolean connect) { - while (!path.isDone()) { - float coords[] = new float[6]; - switch (path.currentSegment(coords)) { - case PathIterator.SEG_MOVETO: - if (!connect || typeSize == 0) { - moveTo(coords[0], coords[1]); - break; - } - if (types[typeSize - 1] != PathIterator.SEG_CLOSE && - points[pointSize - 2] == coords[0] && - points[pointSize - 1] == coords[1]) - { - break; - } - // NO BREAK; - case PathIterator.SEG_LINETO: - lineTo(coords[0], coords[1]); - break; - case PathIterator.SEG_QUADTO: - quadTo(coords[0], coords[1], coords[2], coords[3]); - break; - case PathIterator.SEG_CUBICTO: - curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); - break; - case PathIterator.SEG_CLOSE: - closePath(); - break; - } - path.next(); - connect = false; - } - } - - public SVertex getCurrentPoint() { - if (typeSize == 0) { - return null; - } - int j = pointSize - 2; - if (types[typeSize - 1] == PathIterator.SEG_CLOSE) { - - for (int i = typeSize - 2; i > 0; i--) { - int type = types[i]; - if (type == PathIterator.SEG_MOVETO) { - break; - } - j -= pointShift[type]; - } - } - return new SVertex(points[j], points[j + 1]); - } - - public void reset() { - typeSize = 0; - pointSize = 0; - } - - public void transform(AffineTransform t) { - t.transform(points, 0, points, 0, pointSize / 2); - } - - public Path2D createTransformedShape(AffineTransform t) { - Path2D p = (Path2D)clone(); - if (t != null) { - p.transform(t); - } - return p; - } - - public final synchronized AABBox getBounds2D() { - float rx1, ry1, rx2, ry2; - if (pointSize == 0) { - rx1 = ry1 = rx2 = ry2 = 0.0f; - } else { - int i = pointSize - 1; - ry1 = ry2 = points[i--]; - rx1 = rx2 = points[i--]; - while (i > 0) { - float y = points[i--]; - float x = points[i--]; - if (x < rx1) { - rx1 = x; - } else - if (x > rx2) { - rx2 = x; - } - if (y < ry1) { - ry1 = y; - } else - if (y > ry2) { - ry2 = y; - } - } - } - return new AABBox(rx1, ry1, 0f, rx2, ry2, 0f); - } - - /** - * Checks cross count according to path rule to define is it point inside shape or not. - * @param cross - the point cross count - * @return true if point is inside path, or false otherwise - */ - boolean isInside(int cross) { - if (rule == WIND_NON_ZERO) { - return Crossing.isInsideNonZero(cross); - } - return Crossing.isInsideEvenOdd(cross); - } - - public boolean contains(float px, float py) { - return isInside(Crossing.crossShape(this, px, py)); - } - - public boolean contains(float rx, float ry, float rw, float rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); - return cross != Crossing.CROSSING && isInside(cross); - } - - public boolean intersects(float rx, float ry, float rw, float rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); - return cross == Crossing.CROSSING || isInside(cross); - } - - public boolean contains(Vertex p) { - return contains(p.getX(), p.getY()); - } - - public boolean contains(AABBox r) { - return contains(r); - } - - public boolean intersects(AABBox r) { - return intersects(r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight()); - } - - public PathIterator iterator() { - return new Iterator(this); - } - - public PathIterator iterator(AffineTransform t) { - return new Iterator(this, t); - } - - /* public PathIterator getPathIterator(AffineTransform t, float flatness) { - return new FlatteningPathIterator(getPathIterator(t), flatness); - } */ - - @Override - public Object clone() { - try { - Path2D p = (Path2D) super.clone(); - p.types = types.clone(); - p.points = points.clone(); - return p; - } catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } -} - diff --git a/src/jogamp/graph/geom/plane/PathIterator.java b/src/jogamp/graph/geom/plane/PathIterator.java deleted file mode 100644 index 8868a8c58..000000000 --- a/src/jogamp/graph/geom/plane/PathIterator.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - */ -package jogamp.graph.geom.plane; - -public interface PathIterator { - - public static final int WIND_EVEN_ODD = 0; - public static final int WIND_NON_ZERO = 1; - - public static final int SEG_MOVETO = 0; - public static final int SEG_LINETO = 1; - public static final int SEG_QUADTO = 2; - public static final int SEG_CUBICTO = 3; - public static final int SEG_CLOSE = 4; - - public int getWindingRule(); - - public boolean isDone(); - - public void next(); - - public int currentSegment(float[] coords); - -} - diff --git a/src/jogamp/graph/math/plane/Crossing.java b/src/jogamp/graph/math/plane/Crossing.java deleted file mode 100644 index 8f8638632..000000000 --- a/src/jogamp/graph/math/plane/Crossing.java +++ /dev/null @@ -1,897 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Denis M. Kishenko - */ -package jogamp.graph.math.plane; - -import jogamp.graph.geom.plane.Path2D; -import jogamp.graph.geom.plane.PathIterator; -import jogamp.graph.math.MathFloat; - - -public class Crossing { - - /** - * Allowable tolerance for bounds comparison - */ - static final float DELTA = (float) 1E-5; - - /** - * If roots have distance less then <code>ROOT_DELTA</code> they are double - */ - static final float ROOT_DELTA = (float) 1E-10; - - /** - * Rectangle cross segment - */ - public static final int CROSSING = 255; - - /** - * Unknown crossing result - */ - static final int UNKNOWN = 254; - - /** - * Solves quadratic equation - * @param eqn - the coefficients of the equation - * @param res - the roots of the equation - * @return a number of roots - */ - public static int solveQuad(float eqn[], float res[]) { - float a = eqn[2]; - float b = eqn[1]; - float c = eqn[0]; - int rc = 0; - if (a == 0.0) { - if (b == 0.0) { - return -1; - } - res[rc++] = -c / b; - } else { - float d = b * b - 4.0f * a * c; - // d < 0.0 - if (d < 0.0) { - return 0; - } - d = MathFloat.sqrt(d); - res[rc++] = (- b + d) / (a * 2.0f); - // d != 0.0 - if (d != 0.0) { - res[rc++] = (- b - d) / (a * 2.0f); - } - } - return fixRoots(res, rc); - } - - /** - * Solves cubic equation - * @param eqn - the coefficients of the equation - * @param res - the roots of the equation - * @return a number of roots - */ - public static int solveCubic(float eqn[], float res[]) { - float d = eqn[3]; - if (d == 0) { - return solveQuad(eqn, res); - } - float a = eqn[2] / d; - float b = eqn[1] / d; - float c = eqn[0] / d; - int rc = 0; - - float Q = (a * a - 3.0f * b) / 9.0f; - float R = (2.0f * a * a * a - 9.0f * a * b + 27.0f * c) / 54.0f; - float Q3 = Q * Q * Q; - float R2 = R * R; - float n = - a / 3.0f; - - if (R2 < Q3) { - float t = MathFloat.acos(R / MathFloat.sqrt(Q3)) / 3.0f; - float p = 2.0f * MathFloat.PI / 3.0f; - float m = -2.0f * MathFloat.sqrt(Q); - res[rc++] = m * MathFloat.cos(t) + n; - res[rc++] = m * MathFloat.cos(t + p) + n; - res[rc++] = m * MathFloat.cos(t - p) + n; - } else { -// Debug.println("R2 >= Q3 (" + R2 + "/" + Q3 + ")"); - float A = MathFloat.pow(MathFloat.abs(R) + MathFloat.sqrt(R2 - Q3), 1.0f / 3.0f); - if (R > 0.0) { - A = -A; - } -// if (A == 0.0) { - if (-ROOT_DELTA < A && A < ROOT_DELTA) { - res[rc++] = n; - } else { - float B = Q / A; - res[rc++] = A + B + n; -// if (R2 == Q3) { - float delta = R2 - Q3; - if (-ROOT_DELTA < delta && delta < ROOT_DELTA) { - res[rc++] = - (A + B) / 2.0f + n; - } - } - - } - return fixRoots(res, rc); - } - - /** - * Excludes float roots. Roots are float if they lies enough close with each other. - * @param res - the roots - * @param rc - the roots count - * @return new roots count - */ - static int fixRoots(float res[], int rc) { - int tc = 0; - for(int i = 0; i < rc; i++) { - out: { - for(int j = i + 1; j < rc; j++) { - if (isZero(res[i] - res[j])) { - break out; - } - } - res[tc++] = res[i]; - } - } - return tc; - } - - /** - * QuadCurve class provides basic functionality to find curve crossing and calculating bounds - */ - public static class QuadCurve { - - float ax, ay, bx, by; - float Ax, Ay, Bx, By; - - public QuadCurve(float x1, float y1, float cx, float cy, float x2, float y2) { - ax = x2 - x1; - ay = y2 - y1; - bx = cx - x1; - by = cy - y1; - - Bx = bx + bx; // Bx = 2.0 * bx - Ax = ax - Bx; // Ax = ax - 2.0 * bx - - By = by + by; // By = 2.0 * by - Ay = ay - By; // Ay = ay - 2.0 * by - } - - int cross(float res[], int rc, float py1, float py2) { - int cross = 0; - - for (int i = 0; i < rc; i++) { - float t = res[i]; - - // CURVE-OUTSIDE - if (t < -DELTA || t > 1 + DELTA) { - continue; - } - // CURVE-START - if (t < DELTA) { - if (py1 < 0.0 && (bx != 0.0 ? bx : ax - bx) < 0.0) { - cross--; - } - continue; - } - // CURVE-END - if (t > 1 - DELTA) { - if (py1 < ay && (ax != bx ? ax - bx : bx) > 0.0) { - cross++; - } - continue; - } - // CURVE-INSIDE - float ry = t * (t * Ay + By); - // ry = t * t * Ay + t * By - if (ry > py2) { - float rxt = t * Ax + bx; - // rxt = 2.0 * t * Ax + Bx = 2.0 * t * Ax + 2.0 * bx - if (rxt > -DELTA && rxt < DELTA) { - continue; - } - cross += rxt > 0.0 ? 1 : -1; - } - } // for - - return cross; - } - - int solvePoint(float res[], float px) { - float eqn[] = {-px, Bx, Ax}; - return solveQuad(eqn, res); - } - - int solveExtrem(float res[]) { - int rc = 0; - if (Ax != 0.0) { - res[rc++] = - Bx / (Ax + Ax); - } - if (Ay != 0.0) { - res[rc++] = - By / (Ay + Ay); - } - return rc; - } - - int addBound(float bound[], int bc, float res[], int rc, float minX, float maxX, boolean changeId, int id) { - for(int i = 0; i < rc; i++) { - float t = res[i]; - if (t > -DELTA && t < 1 + DELTA) { - float rx = t * (t * Ax + Bx); - if (minX <= rx && rx <= maxX) { - bound[bc++] = t; - bound[bc++] = rx; - bound[bc++] = t * (t * Ay + By); - bound[bc++] = id; - if (changeId) { - id++; - } - } - } - } - return bc; - } - - } - - /** - * CubicCurve class provides basic functionality to find curve crossing and calculating bounds - */ - public static class CubicCurve { - - float ax, ay, bx, by, cx, cy; - float Ax, Ay, Bx, By, Cx, Cy; - float Ax3, Bx2; - - public CubicCurve(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2) { - ax = x2 - x1; - ay = y2 - y1; - bx = cx1 - x1; - by = cy1 - y1; - cx = cx2 - x1; - cy = cy2 - y1; - - Cx = bx + bx + bx; // Cx = 3.0 * bx - Bx = cx + cx + cx - Cx - Cx; // Bx = 3.0 * cx - 6.0 * bx - Ax = ax - Bx - Cx; // Ax = ax - 3.0 * cx + 3.0 * bx - - Cy = by + by + by; // Cy = 3.0 * by - By = cy + cy + cy - Cy - Cy; // By = 3.0 * cy - 6.0 * by - Ay = ay - By - Cy; // Ay = ay - 3.0 * cy + 3.0 * by - - Ax3 = Ax + Ax + Ax; - Bx2 = Bx + Bx; - } - - int cross(float res[], int rc, float py1, float py2) { - int cross = 0; - for (int i = 0; i < rc; i++) { - float t = res[i]; - - // CURVE-OUTSIDE - if (t < -DELTA || t > 1 + DELTA) { - continue; - } - // CURVE-START - if (t < DELTA) { - if (py1 < 0.0 && (bx != 0.0 ? bx : (cx != bx ? cx - bx : ax - cx)) < 0.0) { - cross--; - } - continue; - } - // CURVE-END - if (t > 1 - DELTA) { - if (py1 < ay && (ax != cx ? ax - cx : (cx != bx ? cx - bx : bx)) > 0.0) { - cross++; - } - continue; - } - // CURVE-INSIDE - float ry = t * (t * (t * Ay + By) + Cy); - // ry = t * t * t * Ay + t * t * By + t * Cy - if (ry > py2) { - float rxt = t * (t * Ax3 + Bx2) + Cx; - // rxt = 3.0 * t * t * Ax + 2.0 * t * Bx + Cx - if (rxt > -DELTA && rxt < DELTA) { - rxt = t * (Ax3 + Ax3) + Bx2; - // rxt = 6.0 * t * Ax + 2.0 * Bx - if (rxt < -DELTA || rxt > DELTA) { - // Inflection point - continue; - } - rxt = ax; - } - cross += rxt > 0.0 ? 1 : -1; - } - } //for - - return cross; - } - - int solvePoint(float res[], float px) { - float eqn[] = {-px, Cx, Bx, Ax}; - return solveCubic(eqn, res); - } - - int solveExtremX(float res[]) { - float eqn[] = {Cx, Bx2, Ax3}; - return solveQuad(eqn, res); - } - - int solveExtremY(float res[]) { - float eqn[] = {Cy, By + By, Ay + Ay + Ay}; - return solveQuad(eqn, res); - } - - int addBound(float bound[], int bc, float res[], int rc, float minX, float maxX, boolean changeId, int id) { - for(int i = 0; i < rc; i++) { - float t = res[i]; - if (t > -DELTA && t < 1 + DELTA) { - float rx = t * (t * (t * Ax + Bx) + Cx); - if (minX <= rx && rx <= maxX) { - bound[bc++] = t; - bound[bc++] = rx; - bound[bc++] = t * (t * (t * Ay + By) + Cy); - bound[bc++] = id; - if (changeId) { - id++; - } - } - } - } - return bc; - } - - } - - /** - * Returns how many times ray from point (x,y) cross line. - */ - public static int crossLine(float x1, float y1, float x2, float y2, float x, float y) { - - // LEFT/RIGHT/UP/EMPTY - if ((x < x1 && x < x2) || - (x > x1 && x > x2) || - (y > y1 && y > y2) || - (x1 == x2)) - { - return 0; - } - - // DOWN - if (y < y1 && y < y2) { - } else { - // INSIDE - if ((y2 - y1) * (x - x1) / (x2 - x1) <= y - y1) { - // INSIDE-UP - return 0; - } - } - - // START - if (x == x1) { - return x1 < x2 ? 0 : -1; - } - - // END - if (x == x2) { - return x1 < x2 ? 1 : 0; - } - - // INSIDE-DOWN - return x1 < x2 ? 1 : -1; - } - - /** - * Returns how many times ray from point (x,y) cross quard curve - */ - public static int crossQuad(float x1, float y1, float cx, float cy, float x2, float y2, float x, float y) { - - // LEFT/RIGHT/UP/EMPTY - if ((x < x1 && x < cx && x < x2) || - (x > x1 && x > cx && x > x2) || - (y > y1 && y > cy && y > y2) || - (x1 == cx && cx == x2)) - { - return 0; - } - - // DOWN - if (y < y1 && y < cy && y < y2 && x != x1 && x != x2) { - if (x1 < x2) { - return x1 < x && x < x2 ? 1 : 0; - } - return x2 < x && x < x1 ? -1 : 0; - } - - // INSIDE - QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2); - float px = x - x1; - float py = y - y1; - float res[] = new float[3]; - int rc = c.solvePoint(res, px); - - return c.cross(res, rc, py, py); - } - - /** - * Returns how many times ray from point (x,y) cross cubic curve - */ - public static int crossCubic(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, float x, float y) { - - // LEFT/RIGHT/UP/EMPTY - if ((x < x1 && x < cx1 && x < cx2 && x < x2) || - (x > x1 && x > cx1 && x > cx2 && x > x2) || - (y > y1 && y > cy1 && y > cy2 && y > y2) || - (x1 == cx1 && cx1 == cx2 && cx2 == x2)) - { - return 0; - } - - // DOWN - if (y < y1 && y < cy1 && y < cy2 && y < y2 && x != x1 && x != x2) { - if (x1 < x2) { - return x1 < x && x < x2 ? 1 : 0; - } - return x2 < x && x < x1 ? -1 : 0; - } - - // INSIDE - CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2); - float px = x - x1; - float py = y - y1; - float res[] = new float[3]; - int rc = c.solvePoint(res, px); - return c.cross(res, rc, py, py); - } - - /** - * Returns how many times ray from point (x,y) cross path - */ - public static int crossPath(PathIterator p, float x, float y) { - int cross = 0; - float mx, my, cx, cy; - mx = my = cx = cy = 0.0f; - float coords[] = new float[6]; - - while (!p.isDone()) { - switch (p.currentSegment(coords)) { - case PathIterator.SEG_MOVETO: - if (cx != mx || cy != my) { - cross += crossLine(cx, cy, mx, my, x, y); - } - mx = cx = coords[0]; - my = cy = coords[1]; - break; - case PathIterator.SEG_LINETO: - cross += crossLine(cx, cy, cx = coords[0], cy = coords[1], x, y); - break; - case PathIterator.SEG_QUADTO: - cross += crossQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], x, y); - break; - case PathIterator.SEG_CUBICTO: - cross += crossCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], x, y); - break; - case PathIterator.SEG_CLOSE: - if (cy != my || cx != mx) { - cross += crossLine(cx, cy, cx = mx, cy = my, x, y); - } - break; - } - - // checks if the point (x,y) is the vertex of shape with PathIterator p - if (x == cx && y == cy) { - cross = 0; - cy = my; - break; - } - p.next(); - } - if (cy != my) { - cross += crossLine(cx, cy, mx, my, x, y); - } - return cross; - } - - /** - * Returns how many times ray from point (x,y) cross shape - */ - public static int crossShape(Path2D s, float x, float y) { - if (!s.getBounds2D().contains(x, y)) { - return 0; - } - return crossPath(s.iterator(null), x, y); - } - - /** - * Returns true if value enough small - */ - public static boolean isZero(float val) { - return -DELTA < val && val < DELTA; - } - - /** - * Sort bound array - */ - static void sortBound(float bound[], int bc) { - for(int i = 0; i < bc - 4; i += 4) { - int k = i; - for(int j = i + 4; j < bc; j += 4) { - if (bound[k] > bound[j]) { - k = j; - } - } - if (k != i) { - float tmp = bound[i]; - bound[i] = bound[k]; - bound[k] = tmp; - tmp = bound[i + 1]; - bound[i + 1] = bound[k + 1]; - bound[k + 1] = tmp; - tmp = bound[i + 2]; - bound[i + 2] = bound[k + 2]; - bound[k + 2] = tmp; - tmp = bound[i + 3]; - bound[i + 3] = bound[k + 3]; - bound[k + 3] = tmp; - } - } - } - - /** - * Returns are bounds intersect or not intersect rectangle - */ - static int crossBound(float bound[], int bc, float py1, float py2) { - - // LEFT/RIGHT - if (bc == 0) { - return 0; - } - - // Check Y coordinate - int up = 0; - int down = 0; - for(int i = 2; i < bc; i += 4) { - if (bound[i] < py1) { - up++; - continue; - } - if (bound[i] > py2) { - down++; - continue; - } - return CROSSING; - } - - // UP - if (down == 0) { - return 0; - } - - if (up != 0) { - // bc >= 2 - sortBound(bound, bc); - boolean sign = bound[2] > py2; - for(int i = 6; i < bc; i += 4) { - boolean sign2 = bound[i] > py2; - if (sign != sign2 && bound[i + 1] != bound[i - 3]) { - return CROSSING; - } - sign = sign2; - } - } - return UNKNOWN; - } - - /** - * Returns how many times rectangle stripe cross line or the are intersect - */ - public static int intersectLine(float x1, float y1, float x2, float y2, float rx1, float ry1, float rx2, float ry2) { - - // LEFT/RIGHT/UP - if ((rx2 < x1 && rx2 < x2) || - (rx1 > x1 && rx1 > x2) || - (ry1 > y1 && ry1 > y2)) - { - return 0; - } - - // DOWN - if (ry2 < y1 && ry2 < y2) { - } else { - - // INSIDE - if (x1 == x2) { - return CROSSING; - } - - // Build bound - float bx1, bx2; - if (x1 < x2) { - bx1 = x1 < rx1 ? rx1 : x1; - bx2 = x2 < rx2 ? x2 : rx2; - } else { - bx1 = x2 < rx1 ? rx1 : x2; - bx2 = x1 < rx2 ? x1 : rx2; - } - float k = (y2 - y1) / (x2 - x1); - float by1 = k * (bx1 - x1) + y1; - float by2 = k * (bx2 - x1) + y1; - - // BOUND-UP - if (by1 < ry1 && by2 < ry1) { - return 0; - } - - // BOUND-DOWN - if (by1 > ry2 && by2 > ry2) { - } else { - return CROSSING; - } - } - - // EMPTY - if (x1 == x2) { - return 0; - } - - // CURVE-START - if (rx1 == x1) { - return x1 < x2 ? 0 : -1; - } - - // CURVE-END - if (rx1 == x2) { - return x1 < x2 ? 1 : 0; - } - - if (x1 < x2) { - return x1 < rx1 && rx1 < x2 ? 1 : 0; - } - return x2 < rx1 && rx1 < x1 ? -1 : 0; - - } - - /** - * Returns how many times rectangle stripe cross quad curve or the are intersect - */ - public static int intersectQuad(float x1, float y1, float cx, float cy, float x2, float y2, float rx1, float ry1, float rx2, float ry2) { - - // LEFT/RIGHT/UP ------------------------------------------------------ - if ((rx2 < x1 && rx2 < cx && rx2 < x2) || - (rx1 > x1 && rx1 > cx && rx1 > x2) || - (ry1 > y1 && ry1 > cy && ry1 > y2)) - { - return 0; - } - - // DOWN --------------------------------------------------------------- - if (ry2 < y1 && ry2 < cy && ry2 < y2 && rx1 != x1 && rx1 != x2) { - if (x1 < x2) { - return x1 < rx1 && rx1 < x2 ? 1 : 0; - } - return x2 < rx1 && rx1 < x1 ? -1 : 0; - } - - // INSIDE ------------------------------------------------------------- - QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2); - float px1 = rx1 - x1; - float py1 = ry1 - y1; - float px2 = rx2 - x1; - float py2 = ry2 - y1; - - float res1[] = new float[3]; - float res2[] = new float[3]; - int rc1 = c.solvePoint(res1, px1); - int rc2 = c.solvePoint(res2, px2); - - // INSIDE-LEFT/RIGHT - if (rc1 == 0 && rc2 == 0) { - return 0; - } - - // Build bound -------------------------------------------------------- - float minX = px1 - DELTA; - float maxX = px2 + DELTA; - float bound[] = new float[28]; - int bc = 0; - // Add roots - bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0); - bc = c.addBound(bound, bc, res2, rc2, minX, maxX, false, 1); - // Add extremal points` - rc2 = c.solveExtrem(res2); - bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2); - // Add start and end - if (rx1 < x1 && x1 < rx2) { - bound[bc++] = 0.0f; - bound[bc++] = 0.0f; - bound[bc++] = 0.0f; - bound[bc++] = 4; - } - if (rx1 < x2 && x2 < rx2) { - bound[bc++] = 1.0f; - bound[bc++] = c.ax; - bound[bc++] = c.ay; - bound[bc++] = 5; - } - // End build bound ---------------------------------------------------- - - int cross = crossBound(bound, bc, py1, py2); - if (cross != UNKNOWN) { - return cross; - } - return c.cross(res1, rc1, py1, py2); - } - - /** - * Returns how many times rectangle stripe cross cubic curve or the are intersect - */ - public static int intersectCubic(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, float rx1, float ry1, float rx2, float ry2) { - - // LEFT/RIGHT/UP - if ((rx2 < x1 && rx2 < cx1 && rx2 < cx2 && rx2 < x2) || - (rx1 > x1 && rx1 > cx1 && rx1 > cx2 && rx1 > x2) || - (ry1 > y1 && ry1 > cy1 && ry1 > cy2 && ry1 > y2)) - { - return 0; - } - - // DOWN - if (ry2 < y1 && ry2 < cy1 && ry2 < cy2 && ry2 < y2 && rx1 != x1 && rx1 != x2) { - if (x1 < x2) { - return x1 < rx1 && rx1 < x2 ? 1 : 0; - } - return x2 < rx1 && rx1 < x1 ? -1 : 0; - } - - // INSIDE - CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2); - float px1 = rx1 - x1; - float py1 = ry1 - y1; - float px2 = rx2 - x1; - float py2 = ry2 - y1; - - float res1[] = new float[3]; - float res2[] = new float[3]; - int rc1 = c.solvePoint(res1, px1); - int rc2 = c.solvePoint(res2, px2); - - // LEFT/RIGHT - if (rc1 == 0 && rc2 == 0) { - return 0; - } - - float minX = px1 - DELTA; - float maxX = px2 + DELTA; - - // Build bound -------------------------------------------------------- - float bound[] = new float[40]; - int bc = 0; - // Add roots - bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0); - bc = c.addBound(bound, bc, res2, rc2, minX, maxX, false, 1); - // Add extrimal points - rc2 = c.solveExtremX(res2); - bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 2); - rc2 = c.solveExtremY(res2); - bc = c.addBound(bound, bc, res2, rc2, minX, maxX, true, 4); - // Add start and end - if (rx1 < x1 && x1 < rx2) { - bound[bc++] = 0.0f; - bound[bc++] = 0.0f; - bound[bc++] = 0.0f; - bound[bc++] = 6; - } - if (rx1 < x2 && x2 < rx2) { - bound[bc++] = 1.0f; - bound[bc++] = c.ax; - bound[bc++] = c.ay; - bound[bc++] = 7; - } - // End build bound ---------------------------------------------------- - - int cross = crossBound(bound, bc, py1, py2); - if (cross != UNKNOWN) { - return cross; - } - return c.cross(res1, rc1, py1, py2); - } - - /** - * Returns how many times rectangle stripe cross path or the are intersect - */ - public static int intersectPath(PathIterator p, float x, float y, float w, float h) { - - int cross = 0; - int count; - float mx, my, cx, cy; - mx = my = cx = cy = 0.0f; - float coords[] = new float[6]; - - float rx1 = x; - float ry1 = y; - float rx2 = x + w; - float ry2 = y + h; - - while (!p.isDone()) { - count = 0; - switch (p.currentSegment(coords)) { - case PathIterator.SEG_MOVETO: - if (cx != mx || cy != my) { - count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2); - } - mx = cx = coords[0]; - my = cy = coords[1]; - break; - case PathIterator.SEG_LINETO: - count = intersectLine(cx, cy, cx = coords[0], cy = coords[1], rx1, ry1, rx2, ry2); - break; - case PathIterator.SEG_QUADTO: - count = intersectQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], rx1, ry1, rx2, ry2); - break; - case PathIterator.SEG_CUBICTO: - count = intersectCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], rx1, ry1, rx2, ry2); - break; - case PathIterator.SEG_CLOSE: - if (cy != my || cx != mx) { - count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2); - } - cx = mx; - cy = my; - break; - } - if (count == CROSSING) { - return CROSSING; - } - cross += count; - p.next(); - } - if (cy != my) { - count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2); - if (count == CROSSING) { - return CROSSING; - } - cross += count; - } - return cross; - } - - /** - * Returns how many times rectangle stripe cross shape or the are intersect - */ - public static int intersectShape(Path2D s, float x, float y, float w, float h) { - if (!s.getBounds2D().intersects(x, y, w, h)) { - return 0; - } - return intersectPath(s.iterator(null), x, y, w, h); - } - - /** - * Returns true if cross count correspond inside location for non zero path rule - */ - public static boolean isInsideNonZero(int cross) { - return cross != 0; - } - - /** - * Returns true if cross count correspond inside location for even-odd path rule - */ - public static boolean isInsideEvenOdd(int cross) { - return (cross & 1) != 0; - } -} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java new file mode 100644 index 000000000..2b51be164 --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; + +public class Audio { + private static Audio instance = null; + private Mixer mixer; + + public synchronized static Audio getInstance() { + if (instance == null) { + instance = new Audio(); + } + return instance; + } + + private Audio() { + mixer = Mixer.getMixer(); + } + + public Mixer getMixer() { + return mixer; + } + + public Track newTrack(File file) throws IOException + { + Track res = new Track(file); + mixer.add(res); + return res; + } + + public void shutdown() { + mixer.shutdown(); + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java new file mode 100644 index 000000000..60972873e --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java @@ -0,0 +1,362 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; +import java.nio.*; +import java.util.*; + +// Needed only for NIO workarounds on CVM +import java.lang.reflect.*; + +public class Mixer { + // This class is a singleton + private static Mixer mixer; + + private volatile boolean shutdown; + private volatile Object shutdownLock = new Object(); + private volatile boolean shutdownDone; + + // Windows Event object + private long event; + + private volatile ArrayList/*<Track>*/ tracks = new ArrayList(); + + private Vec3f leftSpeakerPosition = new Vec3f(-1, 0, 0); + private Vec3f rightSpeakerPosition = new Vec3f( 1, 0, 0); + + private float falloffFactor = 1.0f; + + static { + mixer = new Mixer(); + } + + private Mixer() { + event = CreateEvent(); + new FillerThread().start(); + MixerThread m = new MixerThread(); + m.setPriority(Thread.MAX_PRIORITY - 1); + m.start(); + } + + public static Mixer getMixer() { + return mixer; + } + + synchronized void add(Track track) { + ArrayList/*<Track>*/ newTracks = (ArrayList) tracks.clone(); + newTracks.add(track); + tracks = newTracks; + } + + synchronized void remove(Track track) { + ArrayList/*<Track>*/ newTracks = (ArrayList) tracks.clone(); + newTracks.remove(track); + tracks = newTracks; + } + + // NOTE: due to a bug on the APX device, we only have mono sounds, + // so we currently only pay attention to the position of the left + // speaker + public void setLeftSpeakerPosition(float x, float y, float z) { + leftSpeakerPosition.set(x, y, z); + } + + // NOTE: due to a bug on the APX device, we only have mono sounds, + // so we currently only pay attention to the position of the left + // speaker + public void setRightSpeakerPosition(float x, float y, float z) { + rightSpeakerPosition.set(x, y, z); + } + + /** This defines a scale factor of sorts -- the higher the number, + the larger an area the sound will affect. Default value is + 1.0f. Valid values are [1.0f, ...]. The formula for the gain + for each channel is +<PRE> + falloffFactor + ------------------- + falloffFactor + r^2 +</PRE> +*/ + public void setFalloffFactor(float factor) { + falloffFactor = factor; + } + + public void shutdown() { + synchronized(shutdownLock) { + shutdown = true; + SetEvent(event); + try { + shutdownLock.wait(); + } catch (InterruptedException e) { + } + } + } + + class FillerThread extends Thread { + FillerThread() { + super("Mixer Thread"); + } + + public void run() { + while (!shutdown) { + List/*<Track>*/ curTracks = tracks; + + for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { + Track track = (Track) iter.next(); + try { + track.fill(); + } catch (IOException e) { + e.printStackTrace(); + remove(track); + } + } + + try { + // Run ten times per second + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + class MixerThread extends Thread { + // Temporary mixing buffer + // Interleaved left and right channels + float[] mixingBuffer; + private Vec3f temp = new Vec3f(); + + MixerThread() { + super("Mixer Thread"); + if (!initializeWaveOut(event)) { + throw new InternalError("Error initializing waveout device"); + } + } + + public void run() { + while (!shutdown) { + // Get the next buffer + long mixerBuffer = getNextMixerBuffer(); + if (mixerBuffer != 0) { + ByteBuffer buf = getMixerBufferData(mixerBuffer); + + if (buf == null) { + // This is happening on CVM because + // JNI_NewDirectByteBuffer isn't implemented + // by default and isn't compatible with the + // JSR-239 NIO implementation (apparently) + buf = newDirectByteBuffer(getMixerBufferDataAddress(mixerBuffer), + getMixerBufferDataCapacity(mixerBuffer)); + } + + if (buf == null) { + throw new InternalError("Couldn't wrap the native address with a direct byte buffer"); + } + + // System.out.println("Mixing buffer"); + + // If we don't have enough samples in our mixing buffer, expand it + // FIXME: knowledge of native output rendering format + if ((mixingBuffer == null) || (mixingBuffer.length < (buf.capacity() / 2 /* bytes / sample */))) { + mixingBuffer = new float[buf.capacity() / 2]; + } else { + // Zap it + for (int i = 0; i < mixingBuffer.length; i++) { + mixingBuffer[i] = 0.0f; + } + } + + // This assertion should be in place if we have stereo + if ((mixingBuffer.length % 2) != 0) { + String msg = "FATAL ERROR: odd number of samples in the mixing buffer"; + System.out.println(msg); + throw new InternalError(msg); + } + + // Run down all of the registered tracks mixing them in + List/*<Track>*/ curTracks = tracks; + + for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { + Track track = (Track) iter.next(); + // Consider only playing tracks + if (track.isPlaying()) { + // First recompute its gain + Vec3f pos = track.getPosition(); + float leftGain = gain(pos, leftSpeakerPosition); + float rightGain = gain(pos, rightSpeakerPosition); + // Now mix it in + int i = 0; + while (i < mixingBuffer.length) { + if (track.hasNextSample()) { + float sample = track.nextSample(); + mixingBuffer[i++] = sample * leftGain; + mixingBuffer[i++] = sample * rightGain; + } else { + // This allows tracks to stall without being abruptly cancelled + if (track.done()) { + remove(track); + } + break; + } + } + } + } + + // Now that we have our data, send it down to the card + int outPos = 0; + for (int i = 0; i < mixingBuffer.length; i++) { + short val = (short) mixingBuffer[i]; + buf.put(outPos++, (byte) val); + buf.put(outPos++, (byte) (val >> 8)); + } + if (!prepareMixerBuffer(mixerBuffer)) { + throw new RuntimeException("Error preparing mixer buffer"); + } + if (!writeMixerBuffer(mixerBuffer)) { + throw new RuntimeException("Error writing mixer buffer to device"); + } + } else { + // System.out.println("No mixer buffer available"); + + // Wait for a buffer to become available + if (!WaitForSingleObject(event)) { + throw new RuntimeException("Error while waiting for event object"); + } + + /* + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + */ + } + } + + // Need to shut down + shutdownWaveOut(); + synchronized(shutdownLock) { + shutdownLock.notifyAll(); + } + } + + // This defines the 3D spatialization gain function. + // The function is defined as: + // falloffFactor + // ------------------- + // falloffFactor + r^2 + private float gain(Vec3f pos, Vec3f speakerPos) { + temp.sub(pos, speakerPos); + float dotp = temp.dot(temp); + return (falloffFactor / (falloffFactor + dotp)); + } + } + + // Initializes waveout device + private static native boolean initializeWaveOut(long eventObject); + // Shuts down waveout device + private static native void shutdownWaveOut(); + + // Gets the next (opaque) buffer of data to fill from the native + // code, or 0 if none was available yet (it should not happen that + // none is available the way the code is written). + private static native long getNextMixerBuffer(); + // Gets the next ByteBuffer to fill out of the mixer buffer. It + // requires interleaved left and right channel samples, 16 signed + // bits per sample, little endian. Implicit 44.1 kHz sample rate. + private static native ByteBuffer getMixerBufferData(long mixerBuffer); + // We need these to work around the lack of + // JNI_NewDirectByteBuffer in CVM + the JSR 239 NIO classes + private static native long getMixerBufferDataAddress(long mixerBuffer); + private static native int getMixerBufferDataCapacity(long mixerBuffer); + // Prepares this mixer buffer for writing to the device. + private static native boolean prepareMixerBuffer(long mixerBuffer); + // Writes this mixer buffer to the device. + private static native boolean writeMixerBuffer(long mixerBuffer); + + // Helpers to prevent mixer thread from busy waiting + private static native long CreateEvent(); + private static native boolean WaitForSingleObject(long event); + private static native void SetEvent(long event); + private static native void CloseHandle(long handle); + + // We need a reflective hack to wrap a direct ByteBuffer around + // the native memory because JNI_NewDirectByteBuffer doesn't work + // in CVM + JSR-239 NIO + private static Class directByteBufferClass; + private static Constructor directByteBufferConstructor; + private static Map createdBuffers = new HashMap(); // Map Long, ByteBuffer + + private static ByteBuffer newDirectByteBuffer(long address, long capacity) { + Long key = new Long(address); + ByteBuffer buf = (ByteBuffer) createdBuffers.get(key); + if (buf == null) { + buf = newDirectByteBufferImpl(address, capacity); + if (buf != null) { + createdBuffers.put(key, buf); + } + } + return buf; + } + private static ByteBuffer newDirectByteBufferImpl(long address, long capacity) { + if (directByteBufferClass == null) { + try { + directByteBufferClass = Class.forName("java.nio.DirectByteBuffer"); + byte[] tmp = new byte[0]; + directByteBufferConstructor = + directByteBufferClass.getDeclaredConstructor(new Class[] { Integer.TYPE, + tmp.getClass(), + Integer.TYPE }); + directByteBufferConstructor.setAccessible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (directByteBufferConstructor != null) { + try { + return (ByteBuffer) + directByteBufferConstructor.newInstance(new Object[] { + new Integer((int) capacity), + null, + new Integer((int) address) + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java new file mode 100644 index 000000000..c45430d23 --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; + +class SoundBuffer { + private byte[] data; + private boolean needsByteSwap; + private int numBytes; + private int bytesPerSample; + private int numSamples; + private boolean playing; + private boolean empty; + + // Note: needsByteSwap argument makes assumptions about the format + SoundBuffer(int size, int bytesPerSample, boolean needsByteSwap) { + this.bytesPerSample = bytesPerSample; + this.needsByteSwap = needsByteSwap; + data = new byte[size * bytesPerSample]; + empty = true; + } + + boolean playing() { + return playing; + } + + void playing(boolean playing) { + this.playing = playing; + } + + boolean empty() { + return empty; + } + + void empty(boolean empty) { + this.empty = empty; + } + + void fill(InputStream input) throws IOException { + synchronized(this) { + if (playing) { + throw new IllegalStateException("Can not fill a buffer that is playing"); + } + } + + empty(true); + int num = input.read(data); + if (num > 0) { + numBytes = num; + numSamples = numBytes / bytesPerSample; + empty(false); + if ((numBytes % bytesPerSample) != 0) { + System.out.println("WARNING: needed integral multiple of " + bytesPerSample + + " bytes, but read " + numBytes + " bytes"); + } + } else { + numBytes = 0; + } + } + + int numSamples() { + return numSamples; + } + + // This is called by the mixer and must be extremely fast + // FIXME: may want to reconsider use of floating point at this point + // FIXME: assumes all sounds are of the same format to avoid normalization + float getSample(int sample) { + int startByte = sample * bytesPerSample; + // FIXME: assumes no more than 4 bytes per sample + int res = 0; + if (needsByteSwap) { + for (int i = startByte + bytesPerSample - 1; i >= startByte; i--) { + res <<= 8; + res |= (data[i] & 0xff); + } + } else { + int endByte = startByte + bytesPerSample - 1; + for (int i = startByte; i <= endByte; i++) { + res <<= 8; + res |= (data[i] & 0xff); + } + } + // Sign extend + if (bytesPerSample == 2) { + res = (short) res; + } else if (bytesPerSample == 1) { + res = (byte) res; + } + + return (float) res; + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/TestSpatialization.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/TestSpatialization.java new file mode 100644 index 000000000..3d6de2b29 --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/TestSpatialization.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; +import javax.media.nativewindow.NativeSurface; +import javax.media.opengl.GLDrawableFactory; + +public class TestSpatialization { + public static void main(String[] args) { + if (args.length != 1) { + System.out.println("Usage: TestSpatialization [file name]"); + System.exit(1); + } + + try { + // FIXME: this is a hack to get the native library loaded + try { + GLDrawableFactory.getFactory(NativeSurface.class); + } catch (Exception e) {} + // Initialize the audio subsystem + Audio audio = Audio.getInstance(); + // Create a track + Track track = audio.newTrack(new File(args[0])); + track.setPosition(1, 0, 0); + // Run for ten seconds + long startTime = System.currentTimeMillis(); + long duration = 10000; + long curTime = 0; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + System.out.println("Playing..."); + track.setLooping(true); + track.play(); + while ((curTime = System.currentTimeMillis()) < startTime + duration) { + // Make one revolution every two seconds + float rads = (float) (((2 * Math.PI) * (((float) (curTime - startTime)) / 1000.0f)) / 2); + track.setPosition((float) Math.cos(rads), 0, (float) Math.sin(rads)); + // Would like to make it go in a circle, but since + // stereo doesn't work now, make it move along a line + // track.setPosition(-1.0f, 0, 2.0f * (float) Math.sin(rads)); + // Sleep a little between updates + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + } + System.out.println("Shutting down audio subsystem"); + audio.shutdown(); + System.out.println("Exiting."); + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java new file mode 100644 index 000000000..b57bf1dc6 --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; +import java.nio.*; + +public class Track { + // Default number of samples per buffer + private static final int BUFFER_SIZE = 32768; + // Number of bytes per sample (FIXME: dependence on audio format) + static final int BYTES_PER_SAMPLE = 2; + // Whether we need byte swapping (FIXME: dependence on audio format) + static final boolean NEEDS_BYTE_SWAP = true; + + // This is the buffer this track is currently playing from + private SoundBuffer activeBuffer; + // This is the sample position in the active buffer + private int samplePosition; + // This is the total number of samples in the file + private int totalSamples; + // This is the total number of samples we have read + private int samplesRead; + // This is the buffer that the background filler thread may be filling + private SoundBuffer fillingBuffer; + // If we're playing the file, this is its input stream + private InputStream input; + // Keep around the file name + private File file; + // Whether we're playing this sound + private boolean playing; + // Whether we're looping this sound + private boolean looping; + // The position of this sound; defaults to being at the origin + private volatile Vec3f position = new Vec3f(); + + Track(File file) throws IOException { + if (!file.getName().endsWith(".rawsound")) { + throw new IOException("Unsupported file format (currently supports only raw sounds)"); + } + + this.file = file; + openInput(); + + // Allocate the buffers + activeBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); + fillingBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); + + // Fill the first buffer immediately + fill(); + swapBuffers(); + } + + private void openInput() throws IOException { + input = new BufferedInputStream(new FileInputStream(file)); + totalSamples = (int) file.length() / BYTES_PER_SAMPLE; + } + + public File getFile() { + return file; + } + + public synchronized void play() { + if (input == null) { + try { + openInput(); + // Fill it immediately + fill(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + playing = true; + } + + public synchronized boolean isPlaying() { + return playing; + } + + public synchronized void setLooping(boolean looping) { + this.looping = looping; + } + + public synchronized boolean isLooping() { + return looping; + } + + public void setPosition(float x, float y, float z) { + position = new Vec3f(x, y, z); + } + + synchronized void fill() throws IOException { + if (input == null) { + return; + } + SoundBuffer curBuffer = fillingBuffer; + if (!curBuffer.empty()) { + return; + } + curBuffer.fill(input); + if (curBuffer.empty()) { + // End of file + InputStream tmp = null; + synchronized(this) { + tmp = input; + input = null; + } + tmp.close(); + + // If looping, re-open + if (isLooping()) { + openInput(); + // and fill + fill(); + } + } + } + + // These are only for use by the Mixer + private float leftGain; + private float rightGain; + + void setLeftGain(float leftGain) { + this.leftGain = leftGain; + } + + float getLeftGain() { + return leftGain; + } + + void setRightGain(float rightGain) { + this.rightGain = rightGain; + } + + float getRightGain() { + return rightGain; + } + + Vec3f getPosition() { + return position; + } + + // This is called by the mixer and must be extremely fast + // Note this assumes mono sounds (FIXME) + boolean hasNextSample() { + return (!activeBuffer.empty() && samplePosition < activeBuffer.numSamples()); + } + + // This is called by the mixer and must be extremely fast + float nextSample() { + float res = activeBuffer.getSample(samplePosition++); + ++samplesRead; + if (!hasNextSample()) { + swapBuffers(); + samplePosition = 0; + if (done()) { + playing = false; + } + } + return res; + } + + synchronized void swapBuffers() { + SoundBuffer tmp = activeBuffer; + activeBuffer = fillingBuffer; + fillingBuffer = tmp; + fillingBuffer.empty(true); + } + + // This provides a more robust termination condition + boolean done() { + return (samplesRead == totalSamples) && !looping; + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java new file mode 100644 index 000000000..1afdaf081 --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.audio.windows.waveout; + +/** 3-element single-precision vector */ + +class Vec3f { + public static final Vec3f X_AXIS = new Vec3f( 1, 0, 0); + public static final Vec3f Y_AXIS = new Vec3f( 0, 1, 0); + public static final Vec3f Z_AXIS = new Vec3f( 0, 0, 1); + public static final Vec3f NEG_X_AXIS = new Vec3f(-1, 0, 0); + public static final Vec3f NEG_Y_AXIS = new Vec3f( 0, -1, 0); + public static final Vec3f NEG_Z_AXIS = new Vec3f( 0, 0, -1); + + private float x; + private float y; + private float z; + + public Vec3f() {} + + public Vec3f(Vec3f arg) { + set(arg); + } + + public Vec3f(float x, float y, float z) { + set(x, y, z); + } + + public Vec3f copy() { + return new Vec3f(this); + } + + public void set(Vec3f arg) { + set(arg.x, arg.y, arg.z); + } + + public void set(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** Sets the ith component, 0 <= i < 3 */ + public void set(int i, float val) { + switch (i) { + case 0: x = val; break; + case 1: y = val; break; + case 2: z = val; break; + default: throw new IndexOutOfBoundsException(); + } + } + + /** Gets the ith component, 0 <= i < 3 */ + public float get(int i) { + switch (i) { + case 0: return x; + case 1: return y; + case 2: return z; + default: throw new IndexOutOfBoundsException(); + } + } + + public float x() { return x; } + public float y() { return y; } + public float z() { return z; } + + public void setX(float x) { this.x = x; } + public void setY(float y) { this.y = y; } + public void setZ(float z) { this.z = z; } + + public float dot(Vec3f arg) { + return x * arg.x + y * arg.y + z * arg.z; + } + + public float length() { + return (float) Math.sqrt(lengthSquared()); + } + + public float lengthSquared() { + return this.dot(this); + } + + public void normalize() { + float len = length(); + if (len == 0.0f) return; + scale(1.0f / len); + } + + /** Returns this * val; creates new vector */ + public Vec3f times(float val) { + Vec3f tmp = new Vec3f(this); + tmp.scale(val); + return tmp; + } + + /** this = this * val */ + public void scale(float val) { + x *= val; + y *= val; + z *= val; + } + + /** Returns this + arg; creates new vector */ + public Vec3f plus(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.add(this, arg); + return tmp; + } + + /** this = this + b */ + public void add(Vec3f b) { + add(this, b); + } + + /** this = a + b */ + public void add(Vec3f a, Vec3f b) { + x = a.x + b.x; + y = a.y + b.y; + z = a.z + b.z; + } + + /** Returns this + s * arg; creates new vector */ + public Vec3f addScaled(float s, Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.addScaled(this, s, arg); + return tmp; + } + + /** this = a + s * b */ + public void addScaled(Vec3f a, float s, Vec3f b) { + x = a.x + s * b.x; + y = a.y + s * b.y; + z = a.z + s * b.z; + } + + /** Returns this - arg; creates new vector */ + public Vec3f minus(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.sub(this, arg); + return tmp; + } + + /** this = this - b */ + public void sub(Vec3f b) { + sub(this, b); + } + + /** this = a - b */ + public void sub(Vec3f a, Vec3f b) { + x = a.x - b.x; + y = a.y - b.y; + z = a.z - b.z; + } + + /** Returns this cross arg; creates new vector */ + public Vec3f cross(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.cross(this, arg); + return tmp; + } + + /** this = a cross b. NOTE: "this" must be a different vector than + both a and b. */ + public void cross(Vec3f a, Vec3f b) { + x = a.y * b.z - a.z * b.y; + y = a.z * b.x - a.x * b.z; + z = a.x * b.y - a.y * b.x; + } + + /** Sets each component of this vector to the product of the + component with the corresponding component of the argument + vector. */ + public void componentMul(Vec3f arg) { + x *= arg.x; + y *= arg.y; + z *= arg.z; + } + + public String toString() { + return "(" + x + ", " + y + ", " + z + ")"; + } +} diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java new file mode 100644 index 000000000..d11504a64 --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java @@ -0,0 +1,1097 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.gluegen.opengl; + +import com.jogamp.gluegen.CodeGenUtils; +import com.jogamp.gluegen.JavaType; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.Method; +import java.nio.Buffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +public class BuildComposablePipeline { + + public static final int GEN_DEBUG = 1 << 0; // default + public static final int GEN_TRACE = 1 << 1; // default + public static final int GEN_CUSTOM = 1 << 2; + public static final int GEN_PROLOG_XOR_DOWNSTREAM = 1 << 3; + int mode; + private String outputDir; + private String outputPackage; + private String outputName; + private Class<?> classToComposeAround; + private Class<?> classPrologOpt; + private Class<?> classDownstream; + // Only desktop OpenGL has immediate mode glBegin / glEnd + private boolean hasImmediateMode; + // Desktop OpenGL and GLES1 have GL_STACK_OVERFLOW and GL_STACK_UNDERFLOW errors + private boolean hasStackOverflow; + + public static Class<?> getClass(String name) { + Class<?> clazz = null; + try { + clazz = Class.forName(name); + } catch (Exception e) { + throw new RuntimeException( + "Could not find class \"" + name + "\"", e); + } + return clazz; + } + + public static Method getMethod(Class<?> clazz, Method m) { + Method res = null; + try { + res = clazz.getMethod(m.getName(), m.getParameterTypes()); + } catch (Exception e) { + } + return res; + } + + public static void main(String[] args) { + String classToComposeAroundName = args[0]; + Class<?> classPrologOpt, classDownstream; + Class<?> classToComposeAround = getClass(classToComposeAroundName); + + String outputDir = args[1]; + String outputPackage, outputName; + int mode; + + if (args.length > 2) { + String outputClazzName = args[2]; + outputPackage = getPackageName(outputClazzName); + outputName = getBaseClassName(outputClazzName); + classPrologOpt = getClass(args[3]); + classDownstream = getClass(args[4]); + mode = GEN_CUSTOM; + if (args.length > 5) { + if (args[5].equals("prolog_xor_downstream")) { + mode |= GEN_PROLOG_XOR_DOWNSTREAM; + } + } + } else { + outputPackage = getPackageName(classToComposeAroundName); + outputName = null; // TBD .. + classPrologOpt = null; + classDownstream = classToComposeAround; + mode = GEN_DEBUG | GEN_TRACE; + } + + BuildComposablePipeline composer = + new BuildComposablePipeline(mode, outputDir, outputPackage, outputName, classToComposeAround, classPrologOpt, classDownstream); + + try { + composer.emit(); + } catch (IOException e) { + throw new RuntimeException( + "Error generating composable pipeline source files", e); + } + } + + protected BuildComposablePipeline(int mode, String outputDir, String outputPackage, String outputName, + Class<?> classToComposeAround, Class<?> classPrologOpt, Class<?> classDownstream) { + this.mode = mode; + this.outputDir = outputDir; + this.outputPackage = outputPackage; + this.outputName = outputName; + this.classToComposeAround = classToComposeAround; + this.classPrologOpt = classPrologOpt; + this.classDownstream = classDownstream; + + if (!classToComposeAround.isInterface()) { + throw new IllegalArgumentException( + classToComposeAround.getName() + " is not an interface class"); + } + + try { + hasImmediateMode = + (classToComposeAround.getMethod("glBegin", new Class<?>[]{Integer.TYPE}) != null); + } catch (Exception e) { + } + + try { + hasStackOverflow = + (classToComposeAround.getField("GL_STACK_OVERFLOW") != null); + } catch (Exception e) { + } + } + + /** + * Emit the java source code for the classes that comprise the composable + * pipeline. + */ + public void emit() throws IOException { + + List<Method> publicMethodsRaw = Arrays.asList(classToComposeAround.getMethods()); + + Set<PlainMethod> publicMethodsPlain = new HashSet<PlainMethod>(); + for (Iterator<Method> iter = publicMethodsRaw.iterator(); iter.hasNext();) { + Method method = iter.next(); + // Don't hook methods which aren't real GL methods, + // such as the synthetic "isGL2ES2" "getGL2ES2" + String name = method.getName(); + boolean runHooks = name.startsWith("gl"); + if (!name.startsWith("getGL") && !name.startsWith("isGL") && !name.equals("toString")) { + publicMethodsPlain.add(new PlainMethod(method, runHooks)); + } + } + + if (0 != (mode & GEN_DEBUG)) { + (new DebugPipeline(outputDir, outputPackage, classToComposeAround, classDownstream)).emit(publicMethodsPlain.iterator()); + } + if (0 != (mode & GEN_TRACE)) { + (new TracePipeline(outputDir, outputPackage, classToComposeAround, classDownstream)).emit(publicMethodsPlain.iterator()); + } + if (0 != (mode & GEN_CUSTOM)) { + (new CustomPipeline(mode, outputDir, outputPackage, outputName, classToComposeAround, classPrologOpt, classDownstream)).emit(publicMethodsPlain.iterator()); + } + } + + public static String getPackageName(String clazzName) { + int lastDot = clazzName.lastIndexOf('.'); + if (lastDot == -1) { + // no package, class is at root level + return null; + } + return clazzName.substring(0, lastDot); + } + + public static String getBaseClassName(String clazzName) { + int lastDot = clazzName.lastIndexOf('.'); + if (lastDot == -1) { + // no package, class is at root level + return clazzName; + } + return clazzName.substring(lastDot + 1); + } + + //------------------------------------------------------- + protected class PlainMethod { + + Method m; + boolean runHooks; + + PlainMethod(Method m, boolean runHooks) { + this.m = m; + this.runHooks = runHooks; + } + + public Method getWrappedMethod() { + return m; + } + + public boolean runHooks() { + return runHooks; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof PlainMethod) { + PlainMethod b = (PlainMethod) obj; + boolean res = + m.getName().equals(b.m.getName()) + && m.getModifiers() == b.m.getModifiers() + && m.getReturnType().equals(b.m.getReturnType()) + && Arrays.equals(m.getParameterTypes(), b.m.getParameterTypes()); + return res; + } + return false; + } + + @Override + public int hashCode() { + int hash = m.getName().hashCode() ^ m.getModifiers() ^ m.getReturnType().hashCode(); + Class<?>[] args = m.getParameterTypes(); + for (int i = 0; i < args.length; i++) { + hash ^= args[i].hashCode(); + } + return hash; + } + + @Override + public String toString() { + Class<?>[] args = m.getParameterTypes(); + StringBuilder argsString = new StringBuilder(); + argsString.append("("); + for (int i = 0; i < args.length; i++) { + if (i > 0) { + argsString.append(", "); + } + argsString.append(args[i].getName()); + } + argsString.append(")"); + return m.toString() + + "\n\tname: " + m.getName() + + "\n\tmods: " + m.getModifiers() + + "\n\tretu: " + m.getReturnType() + + "\n\targs[" + args.length + "]: " + argsString.toString(); + } + } + + /** + * Emits a Java source file that represents one element of the composable + * pipeline. + */ + protected abstract class PipelineEmitter { + + private File file; + protected String basePackage; + protected String baseName; // does not include package! + protected String downstreamPackage; + protected String downstreamName; // does not include package! + protected String prologPackageOpt = null; + protected String prologNameOpt = null; // does not include package! + protected String outputDir; + protected String outputPackage; + protected Class<?> baseInterfaceClass; + protected Class<?> prologClassOpt = null; + protected Class<?> downstreamClass; + + /** + * @param outputDir the directory into which the pipeline classes will be + * generated. + * @param baseInterfaceClassName the full class name (including package, + * e.g. "java.lang.String") of the interface that the pipeline wraps + * @exception IllegalArgumentException if classToComposeAround is not an + * interface. + */ + PipelineEmitter(String outputDir, String outputPackage, Class<?> baseInterfaceClass, Class<?> prologClassOpt, Class<?> downstreamClass) { + this.outputDir = outputDir; + this.outputPackage = outputPackage; + this.baseInterfaceClass = baseInterfaceClass; + this.prologClassOpt = prologClassOpt; + this.downstreamClass = downstreamClass; + + basePackage = getPackageName(baseInterfaceClass.getName()); + baseName = getBaseClassName(baseInterfaceClass.getName()); + downstreamPackage = getPackageName(downstreamClass.getName()); + downstreamName = getBaseClassName(downstreamClass.getName()); + if (null != prologClassOpt) { + prologPackageOpt = getPackageName(prologClassOpt.getName()); + prologNameOpt = getBaseClassName(prologClassOpt.getName()); + } + } + + public void emit(Iterator<PlainMethod> methodsToWrap) throws IOException { + String outputClassName = getOutputName(); + this.file = new File(outputDir + File.separatorChar + outputClassName + ".java"); + String parentDir = file.getParent(); + if (parentDir != null) { + File pDirFile = new File(parentDir); + pDirFile.mkdirs(); + } + + PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file))); + + List<Class<?>> baseInterfaces = Arrays.asList(baseInterfaceClass.getInterfaces()); + HashSet<Class<?>> clazzList = new HashSet<Class<?>>(); + clazzList.add(baseInterfaceClass); + clazzList.addAll(baseInterfaces); + int ifNamesNumber = clazzList.size(); + + // keep original order .. + clazzList.clear(); + String[] ifNames = new String[ifNamesNumber]; + { + int i = 0; + + for (Iterator<Class<?>> iter = baseInterfaces.iterator(); iter.hasNext();) { + Class<?> ifClass = iter.next(); + if (!clazzList.contains(ifClass)) { + ifNames[i++] = ifClass.getName(); + clazzList.add(ifClass); + } + } + + if (null != baseInterfaceClass && !clazzList.contains(baseInterfaceClass)) { + ifNames[i++] = baseInterfaceClass.getName(); + clazzList.add(baseInterfaceClass); + } + } + + clazzList.add(downstreamClass); + if (null != prologClassOpt) { + clazzList.add(prologClassOpt); + } + + ArrayList<String> imports = new ArrayList<String>(); + imports.add("java.io.*"); + imports.add("javax.media.opengl.*"); + imports.add("com.jogamp.gluegen.runtime.*"); + imports.add(Buffer.class.getPackage().getName()+".*"); + for (Class<?> clasS : clazzList) { + imports.add(clasS.getName()); + } + + CodeGenUtils.emitJavaHeaders(output, + outputPackage, + outputClassName, + true, + imports, + new String[]{"public"}, + ifNames, + null, + new CodeGenUtils.EmissionCallback() { + public void emit(PrintWriter w) { + emitClassDocComment(w); + } + }); + + preMethodEmissionHook(output); + + constructorHook(output); + + emitGLIsMethods(output); + emitGLGetMethods(output); + + while (methodsToWrap.hasNext()) { + PlainMethod pm = methodsToWrap.next(); + Method m = pm.getWrappedMethod(); + emitMethodDocComment(output, m); + emitSignature(output, m); + emitBody(output, m, pm.runHooks()); + } + + postMethodEmissionHook(output); + + output.println(); + output.print(" private " + downstreamName + " " + getDownstreamObjectName() + ";"); + + // end the class + output.println(); + output.print("} // end class "); + output.println(outputClassName); + + output.flush(); + output.close(); + + System.out.println("wrote to file: " + file); // JAU + } + + /** Get the name of the object through which API calls should be routed. */ + protected String getDownstreamObjectName() { + return "downstream" + downstreamName; + } + + /** Get the name of the object which shall be called as a prolog. */ + protected String getPrologObjectNameOpt() { + if (null != prologNameOpt) { + return "prolog" + prologNameOpt; + } + return null; + } + + protected void emitMethodDocComment(PrintWriter output, Method m) { + } + + protected void emitSignature(PrintWriter output, Method m) { + output.print(" public "); + output.print(' '); + output.print(JavaType.createForClass(m.getReturnType()).getName()); + output.print(' '); + output.print(m.getName()); + output.print('('); + output.print(getArgListAsString(m, true, true)); + output.println(")"); + } + + protected void emitBody(PrintWriter output, Method m, boolean runHooks) { + output.println(" {"); + output.print(" "); + Class<?> retType = m.getReturnType(); + + boolean callPreDownstreamHook = runHooks && hasPreDownstreamCallHook(m); + boolean callPostDownstreamHook = runHooks && hasPostDownstreamCallHook(m); + boolean callDownstream = (null != getMethod(downstreamClass, m)) + && !(0 != (GEN_PROLOG_XOR_DOWNSTREAM & getMode()) && callPreDownstreamHook); + boolean hasResult = (retType != Void.TYPE); + + if (!callDownstream) { + if (!emptyDownstreamAllowed()) { + throw new RuntimeException("Method " + m + " has no downstream (" + downstreamName + ")"); + } + } + + if (!callPreDownstreamHook && !callPostDownstreamHook && !callDownstream) { + if (!emptyMethodAllowed()) { + throw new RuntimeException("Method " + m + " is empty, no downstream (" + downstreamName + ") nor prolog (" + prologNameOpt + ")."); + } else { + output.print(" if(DEBUG) { System.out.println(\"WARNING: No prolog, no downstream, empty: \"+"); + printFunctionCallString(output, m); + output.println("); } "); + } + } + + if (callPreDownstreamHook) { + if (hasResult && !callDownstream) { + if (callPostDownstreamHook) { + output.print(" " + JavaType.createForClass(retType).getName()); + output.print(" _res = "); + } else { + output.print(" return "); + } + } + preDownstreamCallHook(output, m); + } + + if (callDownstream) { + if (hasResult) { + if (callPostDownstreamHook) { + output.print(" " + JavaType.createForClass(retType).getName()); + output.print(" _res = "); + } else { + output.print(" return "); + } + } + output.print(getDownstreamObjectName()); + output.print('.'); + output.print(m.getName()); + output.print('('); + output.print(getArgListAsString(m, false, true)); + output.println(");"); + } + + if (callPostDownstreamHook) { + postDownstreamCallHook(output, m); + } + + if (hasResult && callDownstream && callPostDownstreamHook) { + output.println(" return _res;"); + } + output.println(" }"); + + } + + protected String getArgListAsString(Method m, boolean includeArgTypes, boolean includeArgNames) { + StringBuilder buf = new StringBuilder(256); + if (!includeArgNames && !includeArgTypes) { + throw new IllegalArgumentException( + "Cannot generate arglist without both arg types and arg names"); + } + + Class<?>[] argTypes = m.getParameterTypes(); + for (int i = 0; i < argTypes.length; ++i) { + if (includeArgTypes) { + buf.append(JavaType.createForClass(argTypes[i]).getName()); + buf.append(' '); + } + + if (includeArgNames) { + buf.append("arg"); + buf.append(i); + } + if (i < argTypes.length - 1) { + buf.append(','); + } + } + + return buf.toString(); + } + + /** The name of the class around which this pipeline is being + * composed. E.g., if this pipeline was constructed with + * "java.util.Set" as the baseInterfaceClassName, then this method will + * return "Set". + */ + protected String getBaseInterfaceName() { + return baseName; + } + + /** Get the output name for this pipeline class. */ + protected abstract String getOutputName(); + + /** + * Called after the class headers have been generated, but before any + * method wrappers have been generated. + */ + protected void preMethodEmissionHook(PrintWriter output) { + output.println(" public static final boolean DEBUG = jogamp.opengl.Debug.debug(\"" + getOutputName() + "\");"); + } + + /** + * Emits the constructor for the pipeline; called after the preMethodEmissionHook. + */ + protected abstract void constructorHook(PrintWriter output); + + /** + * Called after the method wrappers have been generated, but before the + * closing parenthesis of the class is emitted. + */ + protected void postMethodEmissionHook(PrintWriter output) { + output.println(" public String toString() {"); + output.println(" StringBuffer sb = new StringBuffer();"); + output.println(" sb.append(\"" + getOutputName() + " [ implementing " + baseInterfaceClass.getName() + ",\\n\\t\");"); + if (null != prologClassOpt) { + output.println(" sb.append(\" prolog: \"+" + getPrologObjectNameOpt() + ".toString()+\",\\n\\t\");"); + } + output.println(" sb.append(\" downstream: \"+" + getDownstreamObjectName() + ".toString()+\"\\n\\t]\");"); + output.println(" return sb.toString();"); + output.println(" }"); + } + + /** + * Called before the pipeline routes the call to the downstream object. + */ + protected abstract void preDownstreamCallHook(PrintWriter output, Method m); + + protected abstract boolean hasPreDownstreamCallHook(Method m); + + /** + * Called after the pipeline has routed the call to the downstream object, + * but before the calling function exits or returns a value. + */ + protected abstract void postDownstreamCallHook(PrintWriter output, Method m); + + protected abstract boolean hasPostDownstreamCallHook(Method m); + + protected abstract int getMode(); + + protected abstract boolean emptyMethodAllowed(); + + protected abstract boolean emptyDownstreamAllowed(); + + /** Emit a Javadoc comment for this pipeline class. */ + protected abstract void emitClassDocComment(PrintWriter output); + + /** + * Emits one of the isGL* methods. + */ + protected void emitGLIsMethod(PrintWriter output, String type) { + output.println(" public boolean is" + type + "() {"); + Class<?> clazz = BuildComposablePipeline.getClass("javax.media.opengl." + type); + if (clazz.isAssignableFrom(baseInterfaceClass)) { + output.println(" return true;"); + } else { + output.println(" return false;"); + } + output.println(" }"); + } + + /** + * Emits all of the isGL* methods. + */ + protected void emitGLIsMethods(PrintWriter output) { + emitGLIsMethod(output, "GL"); + emitGLIsMethod(output, "GL4bc"); + emitGLIsMethod(output, "GL4"); + emitGLIsMethod(output, "GL3bc"); + emitGLIsMethod(output, "GL3"); + emitGLIsMethod(output, "GL2"); + emitGLIsMethod(output, "GLES1"); + emitGLIsMethod(output, "GLES2"); + emitGLIsMethod(output, "GL2ES1"); + emitGLIsMethod(output, "GL2ES2"); + emitGLIsMethod(output, "GL2GL3"); + output.println(" public boolean isGLES() {"); + output.println(" return isGLES2() || isGLES1();"); + output.println(" }"); + } + + /** + * Emits one of the getGL* methods. + */ + protected void emitGLGetMethod(PrintWriter output, String type) { + output.println(" public javax.media.opengl." + type + " get" + type + "() {"); + Class<?> clazz = BuildComposablePipeline.getClass("javax.media.opengl." + type); + if (clazz.isAssignableFrom(baseInterfaceClass)) { + output.println(" return this;"); + } else { + output.println(" throw new GLException(\"Not a " + type + " implementation\");"); + } + output.println(" }"); + } + + /** + * Emits all of the getGL* methods. + */ + protected void emitGLGetMethods(PrintWriter output) { + emitGLGetMethod(output, "GL"); + emitGLGetMethod(output, "GL4bc"); + emitGLGetMethod(output, "GL4"); + emitGLGetMethod(output, "GL3bc"); + emitGLGetMethod(output, "GL3"); + emitGLGetMethod(output, "GL2"); + emitGLGetMethod(output, "GLES1"); + emitGLGetMethod(output, "GLES2"); + emitGLGetMethod(output, "GL2ES1"); + emitGLGetMethod(output, "GL2ES2"); + emitGLGetMethod(output, "GL2GL3"); + output.println(" public GLProfile getGLProfile() {"); + output.println(" return " + getDownstreamObjectName() + ".getGLProfile();"); + output.println(" }"); + } + } // end class PipelineEmitter + + //------------------------------------------------------- + protected class CustomPipeline extends PipelineEmitter { + + String className; + int mode; + + CustomPipeline(int mode, String outputDir, String outputPackage, String outputName, Class<?> baseInterfaceClass, Class<?> prologClassOpt, Class<?> downstreamClass) { + super(outputDir, outputPackage, baseInterfaceClass, prologClassOpt, downstreamClass); + className = outputName; + this.mode = mode; + } + + protected String getOutputName() { + return className; + } + + protected int getMode() { + return mode; + } + + protected boolean emptyMethodAllowed() { + return true; + } + + protected boolean emptyDownstreamAllowed() { + return true; + } + + @Override + protected void preMethodEmissionHook(PrintWriter output) { + super.preMethodEmissionHook(output); + } + + protected void constructorHook(PrintWriter output) { + output.print(" public " + getOutputName() + "("); + output.print(downstreamName + " " + getDownstreamObjectName()); + if (null != prologNameOpt) { + output.println(", " + prologNameOpt + " " + getPrologObjectNameOpt() + ")"); + } else { + output.println(")"); + } + output.println(" {"); + output.println(" if (" + getDownstreamObjectName() + " == null) {"); + output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");"); + output.println(" }"); + output.print(" this." + getDownstreamObjectName()); + output.println(" = " + getDownstreamObjectName() + ";"); + if (null != prologNameOpt) { + output.print(" this." + getPrologObjectNameOpt()); + output.println(" = " + getPrologObjectNameOpt() + ";"); + } + output.println(" }"); + output.println(); + } + + @Override + protected void postMethodEmissionHook(PrintWriter output) { + super.postMethodEmissionHook(output); + if (null != prologNameOpt) { + output.print(" private " + prologNameOpt + " " + getPrologObjectNameOpt() + ";"); + } + } + + protected void emitClassDocComment(PrintWriter output) { + output.println("/**"); + output.println(" * Composable pipeline {@link " + outputPackage + "." + outputName + "}, implementing the interface"); + output.println(" * {@link " + baseInterfaceClass.getName() + "}"); + output.println(" * <p>"); + output.println(" * Each method follows the call graph <ul>"); + if (null != prologClassOpt) { + output.println(" * <li> call <em>prolog</em> {@link " + prologClassOpt.getName() + "} if available"); + } + output.println(" * <li> call <em>downstream</em> {@link " + downstreamClass.getName() + "} if available"); + if (null != prologClassOpt && 0 != (GEN_PROLOG_XOR_DOWNSTREAM & getMode())) { + output.println(" * <strong>and</strong> if no call to {@link " + prologClassOpt.getName() + "} is made"); + } + output.println(" * </ul><p>"); + output.println(" * "); + output.println(" * <ul>"); + output.println(" * <li> <em>Interface</em> {@link " + baseInterfaceClass.getName() + "}"); + if (null != prologClassOpt) { + output.println(" * <li> <em>Prolog</em> {@link " + prologClassOpt.getName() + "}"); + } + output.println(" * <li> <em>Downstream</em> {@link " + downstreamClass.getName() + "}"); + output.println(" * </ul><p>"); + output.println(" * Sample code which installs this pipeline: </P>"); + output.println(" * "); + output.println("<PRE>"); + if (null != prologNameOpt) { + output.println(" GL gl = drawable.setGL( new " + className + "( drawable.getGL().getGL2ES2(), new " + prologNameOpt + "( drawable.getGL().getGL2ES2() ) ) );"); + } else { + output.println(" GL gl = drawable.setGL( new " + className + "( drawable.getGL().getGL2ES2() ) );"); + } + output.println("</PRE>"); + output.println("*/"); + } + + protected boolean hasPreDownstreamCallHook(Method m) { + return null != getMethod(prologClassOpt, m); + } + + protected void preDownstreamCallHook(PrintWriter output, Method m) { + if (null != prologNameOpt) { + output.print(getPrologObjectNameOpt()); + output.print('.'); + output.print(m.getName()); + output.print('('); + output.print(getArgListAsString(m, false, true)); + output.println(");"); + } + } + + protected boolean hasPostDownstreamCallHook(Method m) { + return false; + } + + protected void postDownstreamCallHook(PrintWriter output, Method m) { + } + } // end class CustomPipeline + + protected class DebugPipeline extends PipelineEmitter { + + String className; + + DebugPipeline(String outputDir, String outputPackage, Class<?> baseInterfaceClass, Class<?> downstreamClass) { + super(outputDir, outputPackage, baseInterfaceClass, null, downstreamClass); + className = "Debug" + getBaseInterfaceName(); + } + + protected String getOutputName() { + return className; + } + + protected int getMode() { + return 0; + } + + protected boolean emptyMethodAllowed() { + return false; + } + + protected boolean emptyDownstreamAllowed() { + return false; + } + + @Override + protected void preMethodEmissionHook(PrintWriter output) { + super.preMethodEmissionHook(output); + } + + protected void constructorHook(PrintWriter output) { + output.print(" public " + getOutputName() + "("); + output.println(downstreamName + " " + getDownstreamObjectName() + ")"); + output.println(" {"); + output.println(" if (" + getDownstreamObjectName() + " == null) {"); + output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");"); + output.println(" }"); + output.print(" this." + getDownstreamObjectName()); + output.println(" = " + getDownstreamObjectName() + ";"); + if (null != prologNameOpt) { + output.print(" this." + getPrologObjectNameOpt()); + output.println(" = " + getPrologObjectNameOpt() + ";"); + } + output.println(" // Fetch GLContext object for better error checking (if possible)"); + output.println(" _context = " + getDownstreamObjectName() + ".getContext();"); + output.println(" }"); + output.println(); + } + + @Override + protected void postMethodEmissionHook(PrintWriter output) { + super.postMethodEmissionHook(output); + output.println(" private void checkGLGetError(String caller)"); + output.println(" {"); + if (hasImmediateMode) { + output.println(" if (insideBeginEndPair) {"); + output.println(" return;"); + output.println(" }"); + output.println(); + } + output.println(" // Debug code to make sure the pipeline is working; leave commented out unless testing this class"); + output.println(" //System.err.println(\"Checking for GL errors " + + "after call to \" + caller);"); + output.println(); + output.println(" int err = " + + getDownstreamObjectName() + + ".glGetError();"); + output.println(" if (err == GL_NO_ERROR) { return; }"); + output.println(); + output.println(" StringBuffer buf = new StringBuffer(Thread.currentThread()+"); + output.println(" \" glGetError() returned the following error codes after a call to \" + caller + \": \");"); + output.println(); + output.println(" // Loop repeatedly to allow for distributed GL implementations,"); + output.println(" // as detailed in the glGetError() specification"); + output.println(" int recursionDepth = 10;"); + output.println(" do {"); + output.println(" switch (err) {"); + output.println(" case GL_INVALID_ENUM: buf.append(\"GL_INVALID_ENUM \"); break;"); + output.println(" case GL_INVALID_VALUE: buf.append(\"GL_INVALID_VALUE \"); break;"); + output.println(" case GL_INVALID_OPERATION: buf.append(\"GL_INVALID_OPERATION \"); break;"); + if (hasStackOverflow) { + output.println(" case GL_STACK_OVERFLOW: buf.append(\"GL_STACK_OVERFLOW \"); break;"); + output.println(" case GL_STACK_UNDERFLOW: buf.append(\"GL_STACK_UNDERFLOW \"); break;"); + } + output.println(" case GL_OUT_OF_MEMORY: buf.append(\"GL_OUT_OF_MEMORY \"); break;"); + output.println(" case GL_NO_ERROR: throw new InternalError(\"Should not be treating GL_NO_ERROR as error\");"); + output.println(" default: buf.append(\"Unknown glGetError() return value: \");"); + output.println(" }"); + output.println(" buf.append(\"( \" + err + \" 0x\"+Integer.toHexString(err).toUpperCase() + \"), \");"); + output.println(" } while ((--recursionDepth >= 0) && (err = " + + getDownstreamObjectName() + + ".glGetError()) != GL_NO_ERROR);"); + output.println(" throw new GLException(buf.toString());"); + output.println(" }"); + if (hasImmediateMode) { + output.println(" /** True if the pipeline is inside a glBegin/glEnd pair.*/"); + output.println(" private boolean insideBeginEndPair = false;"); + output.println(); + } + output.println(" private void checkContext() {"); + output.println(" GLContext currentContext = GLContext.getCurrent();"); + output.println(" if (currentContext == null) {"); + output.println(" throw new GLException(\"No OpenGL context is current on this thread\");"); + output.println(" }"); + output.println(" if ((_context != null) && (_context != currentContext)) {"); + output.println(" throw new GLException(\"This GL object is being incorrectly used with a different GLContext than that which created it\");"); + output.println(" }"); + output.println(" }"); + output.println(" private GLContext _context;"); + } + + protected void emitClassDocComment(PrintWriter output) { + output.println("/** <P> Composable pipeline which wraps an underlying {@link GL} implementation,"); + output.println(" providing error checking after each OpenGL method call. If an error occurs,"); + output.println(" causes a {@link GLException} to be thrown at exactly the point of failure."); + output.println(" Sample code which installs this pipeline: </P>"); + output.println(); + output.println("<PRE>"); + output.println(" GL gl = drawable.setGL(new DebugGL(drawable.getGL()));"); + output.println("</PRE>"); + output.println("*/"); + } + + protected boolean hasPreDownstreamCallHook(Method m) { + return true; + } + + protected void preDownstreamCallHook(PrintWriter output, Method m) { + output.println(" checkContext();"); + } + + protected boolean hasPostDownstreamCallHook(Method m) { + return true; + } + + protected void postDownstreamCallHook(PrintWriter output, Method m) { + if (m.getName().equals("glBegin")) { + output.println(" insideBeginEndPair = true;"); + output.println(" // NOTE: can't check glGetError(); it's not allowed inside glBegin/glEnd pair"); + } else { + if (m.getName().equals("glEnd")) { + output.println(" insideBeginEndPair = false;"); + } + + output.println(" String txt = new String(\"" + m.getName() + "(\" +"); + Class<?>[] params = m.getParameterTypes(); + for (int i = 0; params != null && i < params.length; i++) { + if (params[i].equals(int.class)) { + output.println(" \"<" + params[i].getName() + "> 0x\"+Integer.toHexString(arg" + i + ").toUpperCase() +"); + } else { + output.println(" \"<" + params[i].getName() + ">\" +"); + } + if (i < params.length - 1) { + output.println(" \", \" +"); + } + } + output.println(" \")\");"); + // calls to glGetError() are only allowed outside of glBegin/glEnd pairs + output.println(" checkGLGetError( txt );"); + } + } + } // end class DebugPipeline + + //------------------------------------------------------- + protected class TracePipeline extends PipelineEmitter { + + String className; + + TracePipeline(String outputDir, String outputPackage, Class<?> baseInterfaceClass, Class<?> downstreamClass) { + super(outputDir, outputPackage, baseInterfaceClass, null, downstreamClass); + className = "Trace" + getBaseInterfaceName(); + } + + protected String getOutputName() { + return className; + } + + protected int getMode() { + return 0; + } + + protected boolean emptyMethodAllowed() { + return false; + } + + protected boolean emptyDownstreamAllowed() { + return false; + } + + @Override + protected void preMethodEmissionHook(PrintWriter output) { + super.preMethodEmissionHook(output); + } + + protected void constructorHook(PrintWriter output) { + output.print(" public " + getOutputName() + "("); + output.println(downstreamName + " " + getDownstreamObjectName() + ", PrintStream " + getOutputStreamName() + ")"); + output.println(" {"); + output.println(" if (" + getDownstreamObjectName() + " == null) {"); + output.println(" throw new IllegalArgumentException(\"null " + getDownstreamObjectName() + "\");"); + output.println(" }"); + output.print(" this." + getDownstreamObjectName()); + output.println(" = " + getDownstreamObjectName() + ";"); + output.print(" this." + getOutputStreamName()); + output.println(" = " + getOutputStreamName() + ";"); + output.println(" }"); + output.println(); + } + + @Override + protected void postMethodEmissionHook(PrintWriter output) { + super.postMethodEmissionHook(output); + output.println("private PrintStream " + getOutputStreamName() + ";"); + output.println("private int indent = 0;"); + output.println("protected String dumpArray(Object obj)"); + output.println("{"); + output.println(" if (obj == null) return \"[null]\";"); + output.println(" StringBuffer sb = new StringBuffer(\"[\");"); + output.println(" int len = java.lang.reflect.Array.getLength(obj);"); + output.println(" int count = Math.min(len,16);"); + output.println(" for ( int i =0; i < count; i++ ) {"); + output.println(" sb.append(java.lang.reflect.Array.get(obj,i));"); + output.println(" if (i < count-1)"); + output.println(" sb.append(',');"); + output.println(" }"); + output.println(" if ( len > 16 )"); + output.println(" sb.append(\"...\").append(len);"); + output.println(" sb.append(']');"); + output.println(" return sb.toString();"); + output.println("}"); + output.println("protected void print(String str)"); + output.println("{"); + output.println(" " + getOutputStreamName() + ".print(str);"); + output.println("}"); + output.println("protected void println(String str)"); + output.println("{"); + output.println(" " + getOutputStreamName() + ".println(str);"); + output.println("}"); + output.println("protected void printIndent()"); + output.println("{"); + output.println(" for( int i =0; i < indent; i++) {" + getOutputStreamName() + ".print(' ');}"); + output.println("}"); + } + + protected void emitClassDocComment(PrintWriter output) { + output.println("/** <P> Composable pipeline which wraps an underlying {@link GL} implementation,"); + output.println(" providing tracing information to a user-specified {@link java.io.PrintStream}"); + output.println(" before and after each OpenGL method call. Sample code which installs this pipeline: </P>"); + output.println(); + output.println("<PRE>"); + output.println(" GL gl = drawable.setGL(new TraceGL(drawable.getGL(), System.err));"); + output.println("</PRE>"); + output.println("*/"); + } + + protected boolean hasPreDownstreamCallHook(Method m) { + return true; + } + + protected void preDownstreamCallHook(PrintWriter output, Method m) { + if (m.getName().equals("glEnd") || m.getName().equals("glEndList")) { + output.println("indent-=2;"); + output.println(" printIndent();"); + } else { + output.println("printIndent();"); + } + + output.print(" print("); + printFunctionCallString(output, m); + output.println(");"); + } + + protected boolean hasPostDownstreamCallHook(Method m) { + return true; + } + + protected void postDownstreamCallHook(PrintWriter output, Method m) { + Class<?> ret = m.getReturnType(); + if (ret != Void.TYPE) { + output.println(" println(\" = \"+_res);"); + } else { + output.println(" println(\"\");"); + } + } + + private String getOutputStreamName() { + return "stream"; + } + } // end class TracePipeline + + public static final void printFunctionCallString(PrintWriter output, Method m) { + Class<?>[] params = m.getParameterTypes(); + output.print(" \"" + m.getName() + "(\""); + for (int i = 0; i < params.length; i++) { + if (params[i].isArray()) { + output.print("+\"<" + params[i].getName() + ">\""); + } else if (params[i].equals(int.class)) { + output.print("+\"<" + params[i].getName() + "> 0x\"+Integer.toHexString(arg" + i + ").toUpperCase()"); + } else { + output.print("+\"<" + params[i].getName() + "> \"+arg" + i); + } + if (i < params.length - 1) { + output.print("+\", \""); + } + } + output.print("+\")\""); + } +} diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/BuildStaticGLInfo.java b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildStaticGLInfo.java new file mode 100644 index 000000000..3131267cc --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildStaticGLInfo.java @@ -0,0 +1,361 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.gluegen.opengl; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + /** + * Builds the StaticGLInfo class from the OpenGL header files (i.e., gl.h + * and glext.h) whose paths were passed as arguments to {@link + * #main(String[])}. + * + * It relies upon the assumption that a function's membership is scoped by + * preprocessor blocks in the header files that match the following pattern: + * <br> + * + * <pre> + * + * #ifndef GL_XXXX + * GLAPI <returnType> <APIENTRY|GLAPIENTRY> glFuncName(<params>) + * #endif GL_XXXX + * + * </pre> + * + * For example, if it parses the following data: + * + * <pre> + * + * #ifndef GL_VERSION_1_3 + * GLAPI void APIENTRY glActiveTexture (GLenum); + * GLAPI void APIENTRY glMultiTexCoord1dv (GLenum, const GLdouble *); + * GLAPI void <APIENTRY|GLAPIENTRY> glFuncName(<params>) + * #endif GL_VERSION_1_3 + * + * #ifndef GL_ARB_texture_compression + * GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); + * GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); + * #endif + * + * </pre> + * + * It will associate + * <code> glActiveTexture </code> and + * <code> glMultiTexCoord1dv </code> + * with the symbol + * <code> GL_VERSION_1_3 </code>, + * and associate + * <code> glCompressedTexImage2DARB </code> and + * <code> glCompressedTexImage3DARB </code> + * with the symbol + * <code> GL_ARB_texture_compression </code>. + * */ +public class BuildStaticGLInfo { + + // Handles function pointer + protected static int funcIdentifierGroup = 10; + protected static Pattern funcPattern = + Pattern.compile("^(GLAPI|GL_API|GL_APICALL|EGLAPI|extern)?(\\s*)((unsigned|const)\\s+)?(\\w+)(\\s*\\*)?(\\s+)(GLAPIENTRY|GL_APIENTRY|APIENTRY|EGLAPIENTRY|WINAPI)?(\\s*)([ew]?gl\\w+)\\s?(\\(.*)"); + + protected static Pattern associationPattern = + Pattern.compile("\\#ifndef ([CEW]?GL[XU]?_[A-Za-z0-9_]+)(.*)"); + + protected static int defineIdentifierGroup = 1; + protected static Pattern definePattern = + Pattern.compile("\\#define ([CEW]?GL[XU]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)(.*)"); + + // Maps function / #define names to the names of the extensions they're declared in + protected Map<String, String> declarationToExtensionMap = new HashMap<String, String>(); + + // Maps extension names to Set of identifiers (both #defines and + // function names) this extension declares + protected Map<String, Set<String>> extensionToDeclarationMap = new HashMap<String, Set<String>>(); + protected boolean debug = false; + + /** + * The first argument is the package to which the StaticGLInfo class + * belongs, the second is the path to the directory in which that package's + * classes reside, and the remaining arguments are paths to the C header + * files that should be parsed + */ + public static void main(String[] args) throws IOException { + if (args.length > 0 && args[0].equals("-test")) { + BuildStaticGLInfo builder = new BuildStaticGLInfo(); + builder.setDebug(true); + String[] newArgs = new String[args.length - 1]; + System.arraycopy(args, 1, newArgs, 0, args.length - 1); + builder.parse(newArgs); + builder.dump(); + System.exit(0); + } + + String packageName = args[0]; + String packageDir = args[1]; + + String[] cHeaderFilePaths = new String[args.length - 2]; + System.arraycopy(args, 2, cHeaderFilePaths, 0, cHeaderFilePaths.length); + + BuildStaticGLInfo builder = new BuildStaticGLInfo(); + try { + builder.parse(cHeaderFilePaths); + + File file = new File(packageDir + File.separatorChar + "StaticGLInfo.java"); + String parentDir = file.getParent(); + if (parentDir != null) { + File pDirFile = new File(parentDir); + pDirFile.mkdirs(); + } + + PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file))); + builder.emitJavaCode(writer, packageName); + + writer.flush(); + writer.close(); + } catch (Exception e) { + StringBuilder buf = new StringBuilder("{ "); + for (int i = 0; i < cHeaderFilePaths.length; ++i) { + buf.append(cHeaderFilePaths[i]); + buf.append(" "); + } + buf.append('}'); + throw new RuntimeException( + "Error building StaticGLInfo.java from " + buf.toString(), e); + } + } + + public void setDebug(boolean v) { + debug = v; + } + + /** Parses the supplied C header files and adds the function + associations contained therein to the internal map. */ + public void parse(String[] cHeaderFilePaths) throws IOException { + for (int i = 0; i < cHeaderFilePaths.length; i++) { + parse(cHeaderFilePaths[i]); + } + } + + /** Parses the supplied C header file and adds the function + associations contained therein to the internal map. */ + public void parse(String cHeaderFilePath) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(cHeaderFilePath)); + String line, activeAssociation = null; + Matcher m = null; + while ((line = reader.readLine()) != null) { + int type = 0; // 1-define, 2-function + // see if we're inside a #ifndef GL_XXX block and matching a function + if (activeAssociation != null) { + String identifier = null; + if ((m = funcPattern.matcher(line)).matches()) { + identifier = m.group(funcIdentifierGroup).trim(); + type = 2; + } else if ((m = definePattern.matcher(line)).matches()) { + identifier = m.group(defineIdentifierGroup).trim(); + type = 1; + } else if (line.startsWith("#endif")) { + if (debug) { + System.err.println("END ASSOCIATION BLOCK: <" + activeAssociation + ">"); + } + activeAssociation = null; + } + if ((identifier != null) + && (activeAssociation != null) + && // Handles #ifndef GL_... #define GL_... + !identifier.equals(activeAssociation)) { + addAssociation(identifier, activeAssociation); + if (debug) { + System.err.println(" ADDING ASSOCIATION: <" + identifier + "> <" + activeAssociation + "> ; type " + type); + } + } + } else if ((m = associationPattern.matcher(line)).matches()) { + // found a new #ifndef GL_XXX block + activeAssociation = m.group(1).trim(); + + if (debug) { + System.err.println("BEGIN ASSOCIATION BLOCK: <" + activeAssociation + ">"); + } + } + } + reader.close(); + } + + public void dump() { + for (String name : extensionToDeclarationMap.keySet()) { + Set<String> decls = extensionToDeclarationMap.get(name); + System.out.println("<" + name + "> :"); + List<String> l = new ArrayList<String>(); + l.addAll(decls); + Collections.sort(l); + for (String str : l) { + System.out.println(" <" + str + ">"); + } + } + } + + public String getExtension(String identifier) { + return declarationToExtensionMap.get(identifier); + } + + public Set<String> getDeclarations(String extension) { + return extensionToDeclarationMap.get(extension); + } + + public Set<String> getExtensions() { + return extensionToDeclarationMap.keySet(); + } + + public void emitJavaCode(PrintWriter output, String packageName) { + output.println("package " + packageName + ";"); + output.println(); + output.println("import java.util.*;"); + output.println(); + output.println("public final class StaticGLInfo"); + output.println("{"); + + output.println(" // maps function names to the extension string or OpenGL"); + output.println(" // specification version string to which they correspond."); + output.println(" private static HashMap funcToAssocMap;"); + output.println(); + + output.println(" /**"); + output.println(" * Returns the OpenGL extension string or GL_VERSION string with which the"); + output.println(" * given function is associated. <P>"); + output.println(" *"); + output.println(" * If the"); + output.println(" * function is part of the OpenGL core, the returned value will be"); + output.println(" * GL_VERSION_XXX where XXX represents the OpenGL version of which the"); + output.println(" * function is a member (XXX will be of the form \"A\" or \"A_B\" or \"A_B_C\";"); + output.println(" * e.g., GL_VERSION_1_2_1 for OpenGL version 1.2.1)."); + output.println(" *"); + output.println(" * If the function is an extension function, the returned value will the"); + output.println(" * OpenGL extension string for the extension to which the function"); + output.println(" * corresponds. For example, if glLoadTransposeMatrixfARB is the argument,"); + output.println(" * GL_ARB_transpose_matrix will be the value returned."); + output.println(" * Please see http://oss.sgi.com/projects/ogl-sample/registry/index.html for"); + output.println(" * a list of extension names and the functions they expose."); + output.println(" *"); + output.println(" * If the function specified is not part of any known OpenGL core version or"); + output.println(" * extension, then NULL will be returned."); + output.println(" */"); + output.println(" public static String getFunctionAssociation(String glFunctionName)"); + output.println(" {"); + output.println(" String mappedName = null;"); + output.println(" int funcNamePermNum = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutationNumber(glFunctionName);"); + output.println(" for(int i = 0; null==mappedName && i < funcNamePermNum; i++) {"); + output.println(" String tmp = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutation(glFunctionName, i);"); + output.println(" try {"); + output.println(" mappedName = (String)funcToAssocMap.get(tmp);"); + output.println(" } catch (Exception e) { }"); + output.println(" }"); + output.println(" return mappedName;"); + output.println(" }"); + output.println(); + + output.println(" static"); + output.println(" {"); + + // Compute max capacity + int maxCapacity = 0; + for (String name : declarationToExtensionMap.keySet()) { + if (!name.startsWith("GL")) { + ++maxCapacity; + } + } + + output.println(" funcToAssocMap = new HashMap(" + maxCapacity + "); // approximate max capacity"); + output.println(" String group;"); + ArrayList<String> sets = new ArrayList<String>(extensionToDeclarationMap.keySet()); + Collections.sort(sets); + for (String groupName : sets) { + Set<String> funcs = extensionToDeclarationMap.get(groupName); + List<String> l = new ArrayList<String>(); + l.addAll(funcs); + Collections.sort(l); + Iterator<String> funcIter = l.iterator(); + boolean printedHeader = false; + while (funcIter.hasNext()) { + String funcName = funcIter.next(); + if (!funcName.startsWith("GL")) { + if (!printedHeader) { + output.println(); + output.println(" //----------------------------------------------------------------"); + output.println(" // " + groupName); + output.println(" //----------------------------------------------------------------"); + output.println(" group = \"" + groupName + "\";"); + printedHeader = true; + } + + output.println(" funcToAssocMap.put(\"" + funcName + "\", group);"); + } + } + } + output.println(" }"); + output.println("} // end class StaticGLInfo"); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + protected void addAssociation(String identifier, String association) { + declarationToExtensionMap.put(identifier, association); + Set<String> identifiers = extensionToDeclarationMap.get(association); + if (identifiers == null) { + identifiers = new HashSet<String>(); + extensionToDeclarationMap.put(association, identifiers); + } + identifiers.add(identifier); + } +} diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/GLConfiguration.java b/src/jogl/classes/com/jogamp/gluegen/opengl/GLConfiguration.java new file mode 100755 index 000000000..d03e1bd9c --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/GLConfiguration.java @@ -0,0 +1,306 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.gluegen.opengl; + +import com.jogamp.gluegen.GlueEmitterControls; +import com.jogamp.gluegen.MethodBinding; +import com.jogamp.gluegen.procaddress.ProcAddressConfiguration; +import com.jogamp.gluegen.runtime.opengl.GLExtensionNames; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.StringTokenizer; + +public class GLConfiguration extends ProcAddressConfiguration { + + // The following data members support ignoring an entire extension at a time + private List<String> glHeaders = new ArrayList<String>(); + private Set<String> ignoredExtensions = new HashSet<String>(); + private Set<String> extensionsRenamedIntoCore = new HashSet<String>(); + private BuildStaticGLInfo glInfo; + + // Maps function names to the kind of buffer object it deals with + private Map<String, GLEmitter.BufferObjectKind> bufferObjectKinds = new HashMap<String, GLEmitter.BufferObjectKind>(); + private GLEmitter emitter; + private Set<String> dropUniqVendorExtensions = new HashSet<String>(); + + // This directive is off by default but can help automatically + // indicate which extensions have been folded into the core OpenGL + // namespace, and if not, then why not + private boolean autoUnifyExtensions = false; + private boolean allowNonGLExtensions = false; + + public GLConfiguration(GLEmitter emitter) { + super(); + this.emitter = emitter; + try { + setProcAddressNameExpr("PFN $UPPERCASE({0}) PROC"); + } catch (NoSuchElementException e) { + throw new RuntimeException("Error configuring ProcAddressNameExpr", e); + } + } + + @Override + protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException { + if (cmd.equalsIgnoreCase("IgnoreExtension")) { + String sym = readString("IgnoreExtension", tok, filename, lineNo); + ignoredExtensions.add(sym); + } else if (cmd.equalsIgnoreCase("RenameExtensionIntoCore")) { + String sym = readString("RenameExtensionIntoCore", tok, filename, lineNo); + extensionsRenamedIntoCore.add(sym); + } else if (cmd.equalsIgnoreCase("AllowNonGLExtensions")) { + allowNonGLExtensions = readBoolean("AllowNonGLExtensions", tok, filename, lineNo).booleanValue(); + } else if (cmd.equalsIgnoreCase("AutoUnifyExtensions")) { + autoUnifyExtensions = readBoolean("AutoUnifyExtensions", tok, filename, lineNo).booleanValue(); + } else if (cmd.equalsIgnoreCase("GLHeader")) { + String sym = readString("GLHeader", tok, filename, lineNo); + glHeaders.add(sym); + } else if (cmd.equalsIgnoreCase("BufferObjectKind")) { + readBufferObjectKind(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("DropUniqVendorExtensions")) { + String sym = readString("DropUniqVendorExtensions", tok, filename, lineNo); + dropUniqVendorExtensions.add(sym); + } else { + super.dispatch(cmd, tok, file, filename, lineNo); + } + } + + protected void readBufferObjectKind(StringTokenizer tok, String filename, int lineNo) { + try { + String kindString = tok.nextToken(); + GLEmitter.BufferObjectKind kind = null; + String target = tok.nextToken(); + if (kindString.equalsIgnoreCase("UnpackPixel")) { + kind = GLEmitter.BufferObjectKind.UNPACK_PIXEL; + } else if (kindString.equalsIgnoreCase("PackPixel")) { + kind = GLEmitter.BufferObjectKind.PACK_PIXEL; + } else if (kindString.equalsIgnoreCase("Array")) { + kind = GLEmitter.BufferObjectKind.ARRAY; + } else if (kindString.equalsIgnoreCase("Element")) { + kind = GLEmitter.BufferObjectKind.ELEMENT; + } else { + throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo + + " in file \"" + filename + "\": illegal BufferObjectKind \"" + + kindString + "\", expected one of UnpackPixel, PackPixel, Array, or Element"); + } + + bufferObjectKinds.put(target, kind); + } catch (NoSuchElementException e) { + throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + + /** Overrides javaPrologueForMethod in superclass and + automatically generates prologue code for functions associated + with buffer objects. */ + @Override + public List<String> javaPrologueForMethod(MethodBinding binding, boolean forImplementingMethodCall, boolean eraseBufferAndArrayTypes) { + + List<String> res = super.javaPrologueForMethod(binding, forImplementingMethodCall, eraseBufferAndArrayTypes); + GLEmitter.BufferObjectKind kind = getBufferObjectKind(binding.getName()); + if (kind != null) { + // Need to generate appropriate prologue based on both buffer + // object kind and whether this variant of the MethodBinding + // is the one accepting a "long" as argument + // + // NOTE we MUST NOT mutate the array returned from the super + // call! + ArrayList<String> res2 = new ArrayList<String>(); + if (res != null) { + res2.addAll(res); + } + res = res2; + + String prologue = "check"; + + if (kind == GLEmitter.BufferObjectKind.UNPACK_PIXEL) { + prologue = prologue + "UnpackPBO"; + } else if (kind == GLEmitter.BufferObjectKind.PACK_PIXEL) { + prologue = prologue + "PackPBO"; + } else if (kind == GLEmitter.BufferObjectKind.ARRAY) { + prologue = prologue + "ArrayVBO"; + } else if (kind == GLEmitter.BufferObjectKind.ELEMENT) { + prologue = prologue + "ElementVBO"; + } else { + throw new RuntimeException("Unknown BufferObjectKind " + kind); + } + + if (emitter.isBufferObjectMethodBinding(binding)) { + prologue = prologue + "Enabled"; + } else { + prologue = prologue + "Disabled"; + } + + prologue = prologue + "(true);"; + + res.add(0, prologue); + + // Must also filter out bogus rangeCheck directives for VBO/PBO + // variants + if (emitter.isBufferObjectMethodBinding(binding)) { + for (Iterator<String> iter = res.iterator(); iter.hasNext();) { + String line = iter.next(); + if (line.indexOf("Buffers.rangeCheck") >= 0) { + iter.remove(); + } + } + } + } + + return res; + } + + @Override + public void dumpIgnores() { + System.err.println("GL Ignored extensions: "); + for (String str : ignoredExtensions) { + System.err.println("\t" + str); + } + super.dumpIgnores(); + } + + protected boolean shouldIgnoreExtension(String symbol, boolean criteria) { + if (criteria && glInfo != null) { + String extension = glInfo.getExtension(symbol); + if (extension != null + && ignoredExtensions.contains(extension)) { + return true; + } + boolean isGLEnum = GLExtensionNames.isGLEnumeration(symbol); + boolean isGLFunc = GLExtensionNames.isGLFunction(symbol); + if (isGLFunc || isGLEnum) { + if (GLExtensionNames.isExtensionVEN(symbol, isGLFunc)) { + String extSuffix = GLExtensionNames.getExtensionSuffix(symbol, isGLFunc); + if (getDropUniqVendorExtensions(extSuffix)) { + if (DEBUG_IGNORES) { + System.err.println("Ignore UniqVendorEXT: " + symbol + ", vendor " + extSuffix); + } + return true; + } + } + } + } + return false; + } + + @Override + public boolean shouldIgnoreInInterface(String symbol) { + return shouldIgnoreInInterface(symbol, true); + } + + public boolean shouldIgnoreInInterface(String symbol, boolean checkEXT) { + return shouldIgnoreExtension(symbol, checkEXT) || super.shouldIgnoreInInterface(symbol); + } + + @Override + public boolean shouldIgnoreInImpl(String symbol) { + return shouldIgnoreInImpl(symbol, true); + } + + public boolean shouldIgnoreInImpl(String symbol, boolean checkEXT) { + return shouldIgnoreExtension(symbol, checkEXT) || super.shouldIgnoreInImpl(symbol); + } + + /** Should we automatically ignore extensions that have already been + fully subsumed into the OpenGL core namespace, and if they have + not been, indicate which definition is not already in the core? */ + public boolean getAutoUnifyExtensions() { + return autoUnifyExtensions; + } + + /** If true, accept all non encapsulated defines and functions, + * as it is mandatory for GL declarations. */ + public boolean getAllowNonGLExtensions() { + return allowNonGLExtensions; + } + + /** shall the non unified (uniq) vendor extensions be dropped ? */ + public boolean getDropUniqVendorExtensions(String extName) { + return dropUniqVendorExtensions.contains(extName); + } + + /** Returns the kind of buffer object this function deals with, or + null if none. */ + GLEmitter.BufferObjectKind getBufferObjectKind(String name) { + return bufferObjectKinds.get(name); + } + + public boolean isBufferObjectFunction(String name) { + return (getBufferObjectKind(name) != null); + } + + /** Parses any GL headers specified in the configuration file for + the purpose of being able to ignore an extension at a time. */ + public void parseGLHeaders(GlueEmitterControls controls) throws IOException { + if (!glHeaders.isEmpty()) { + glInfo = new BuildStaticGLInfo(); + for (String file : glHeaders) { + String fullPath = controls.findHeaderFile(file); + if (fullPath == null) { + throw new IOException("Unable to locate header file \"" + file + "\""); + } + glInfo.parse(fullPath); + } + } + } + + /** Returns the information about the association between #defines, + function symbols and the OpenGL extensions they are defined + in. */ + public BuildStaticGLInfo getGLInfo() { + return glInfo; + } + + /** Returns the OpenGL extensions that should have all of their + constant definitions and functions renamed into the core + namespace; for example, glGenFramebuffersEXT to + glGenFramebuffers and GL_FRAMEBUFFER_EXT to GL_FRAMEBUFFER. */ + public Set<String> getExtensionsRenamedIntoCore() { + return extensionsRenamedIntoCore; + } +} diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java b/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java new file mode 100644 index 000000000..530e6fe76 --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java @@ -0,0 +1,473 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.gluegen.opengl; + +import com.jogamp.gluegen.ConstantDefinition; +import com.jogamp.gluegen.FunctionEmitter; +import com.jogamp.gluegen.GlueEmitterControls; +import com.jogamp.gluegen.JavaConfiguration; +import com.jogamp.gluegen.JavaEmitter; +import com.jogamp.gluegen.JavaMethodBindingEmitter; +import com.jogamp.gluegen.JavaType; +import com.jogamp.gluegen.MethodBinding; +import com.jogamp.gluegen.SymbolFilter; +import com.jogamp.gluegen.cgram.types.FunctionSymbol; +import com.jogamp.gluegen.procaddress.ProcAddressEmitter; +import com.jogamp.gluegen.procaddress.ProcAddressJavaMethodBindingEmitter; +import com.jogamp.gluegen.runtime.opengl.GLExtensionNames; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * A subclass of ProcAddressEmitter with special OpenGL-specific + * configuration abilities. + */ +public class GLEmitter extends ProcAddressEmitter { + + // Keeps track of which MethodBindings were created for handling + // Buffer Object variants. Used as a Set rather than a Map. + private Map<MethodBinding, MethodBinding> bufferObjectMethodBindings = new IdentityHashMap<MethodBinding, MethodBinding>(); + + enum BufferObjectKind { UNPACK_PIXEL, PACK_PIXEL, ARRAY, ELEMENT} + + @Override + public void beginEmission(GlueEmitterControls controls) throws IOException { + getGLConfig().parseGLHeaders(controls); + renameExtensionsIntoCore(); + if (getGLConfig().getAutoUnifyExtensions()) { + unifyExtensions(controls); + } + super.beginEmission(controls); + } + + protected void renameExtensionsIntoCore() { + // This method handles renaming of entire extensions into the + // OpenGL core namespace. For example, it is used to move certain + // OpenGL ES (OES) extensions into the core namespace which are + // already in the core namespace in desktop OpenGL. It builds upon + // renaming mechanisms that are built elsewhere. + + GLConfiguration config = getGLConfig(); + Set<String> extensionsRenamedIntoCore = config.getExtensionsRenamedIntoCore(); + BuildStaticGLInfo glInfo = config.getGLInfo(); + if (null == glInfo) { + if (extensionsRenamedIntoCore.size() > 0) { + throw new RuntimeException("ExtensionRenamedIntoCore (num: " + extensionsRenamedIntoCore.size() + "), but no GLHeader"); + } + return; + } + for (String extension : extensionsRenamedIntoCore) { + Set<String> declarations = glInfo.getDeclarations(extension); + if (declarations != null) { + for (Iterator<String> iterator = declarations.iterator(); iterator.hasNext();) { + String decl = iterator.next(); + boolean isGLFunction = GLExtensionNames.isGLFunction(decl); + boolean isGLEnumeration = false; + if (!isGLFunction) { + isGLEnumeration = GLExtensionNames.isGLEnumeration(decl); + } + if (isGLFunction || isGLEnumeration) { + String renamed = GLExtensionNames.normalize(decl, isGLFunction); + if (!renamed.equals(decl)) { + config.addJavaSymbolRename(decl, renamed); + } + } + } + } + } + } + + class ExtensionUnifier implements SymbolFilter { + + private List<ConstantDefinition> constants; + private List<FunctionSymbol> functions; + + public void filterSymbols(List<ConstantDefinition> constants, + List<FunctionSymbol> functions) { + this.constants = constants; + this.functions = functions; + doWork(); + } + + public List<ConstantDefinition> getConstants() { + return constants; + } + + public List<FunctionSymbol> getFunctions() { + return functions; + } + + private void doWork() { + BuildStaticGLInfo glInfo = getGLConfig().getGLInfo(); + if (glInfo == null) { + return; + } + // Try to retain a "good" ordering for these symbols + Map<String, ConstantDefinition> constantMap = new LinkedHashMap<String, ConstantDefinition>(); + for (ConstantDefinition def : constants) { + constantMap.put(def.getName(), def); + } + Map<String, FunctionSymbol> functionMap = new LinkedHashMap<String, FunctionSymbol>(); + for (FunctionSymbol sym : functions) { + functionMap.put(sym.getName(), sym); + } + + // Go through all of the declared extensions. + // For each extension, look at its #define and function symbols. + // If we find all of the extension's symbols in the core API under + // non-ARB (or whatever is the suffix) names, then remove this extension + // from the public API. If it turns out that we are running on hardware + // that doesn't support the core version of these APIs, the runtime + // will take care of looking up the extension version of these entry + // points. + Set<String> extensionNames = glInfo.getExtensions(); + + for (String extension : extensionNames) { + Set<String> declarations = glInfo.getDeclarations(extension); + boolean isExtension = true; + boolean shouldUnify = true; + String cause = null; + for (String decl : declarations) { + boolean isFunc = !decl.startsWith("GL_"); + if (!GLExtensionNames.isExtension(decl, isFunc)) { + isExtension = false; + break; + } + // See whether we're emitting glue code for this + // entry point or definition at all + if (isFunc) { + if (!functionMap.containsKey(decl)) { + isExtension = false; + break; + } + } else { + if (!constantMap.containsKey(decl)) { + isExtension = false; + break; + } + } + cause = decl; + String unifiedName = GLExtensionNames.normalize(decl, isFunc); + // NOTE that we look up the unified name in the + // BuildStaticGLInfo's notion of the APIs -- since + // we might not be emitting glue code for the + // headers that actually contain the core entry + // point. Think of the case where we are parsing the + // GLES2 gl2.h, which contains certain desktop + // OpenGL extensions that have been moved into the + // core, but later generating the implementing glue + // code (not the interface) for the desktop gl.h / + // glext.h. + shouldUnify = (glInfo.getExtension(unifiedName) != null); + // if (isFunc) { + // shouldUnify = functionMap.containsKey(unifiedName); + // } else { + // shouldUnify = constantMap.containsKey(unifiedName); + // } + if (!shouldUnify) { + break; + } + } + if (isExtension) { + if (shouldUnify) { + for (String decl : declarations) { + boolean isFunc = !decl.startsWith("GL_"); + if (isFunc) { + functionMap.remove(decl); + } else { + constantMap.remove(decl); + } + } + System.err.println("INFO: unified extension " + extension + " into core API"); + } else { + System.err.println("INFO: didn't unify extension " + extension + " into core API because of " + cause); + } + } + } + constants = new ArrayList<ConstantDefinition>(constantMap.values()); + functions = new ArrayList<FunctionSymbol>(functionMap.values()); + } + } + + private void unifyExtensions(GlueEmitterControls controls) { + controls.runSymbolFilter(new ExtensionUnifier()); + } + + @Override + protected JavaConfiguration createConfig() { + return new GLConfiguration(this); + } + + /** In order to implement Buffer Object variants of certain + functions we generate another MethodBinding which maps the void* + argument to a Java long. The generation of emitters then takes + place as usual. We do however need to keep track of the modified + MethodBinding object so that we can also modify the emitters + later to inform them that their argument has changed. We might + want to push this functionality down into the MethodBinding + (i.e., mutators for argument names). We also would need to + inform the CMethodBindingEmitter that it is overloaded in this + case (though we default to true currently). */ + @Override + protected List<MethodBinding> expandMethodBinding(MethodBinding binding) { + List<MethodBinding> bindings = super.expandMethodBinding(binding); + + if (!getGLConfig().isBufferObjectFunction(binding.getName())) { + return bindings; + } + + List<MethodBinding> newBindings = new ArrayList<MethodBinding>(bindings); + + // Need to expand each one of the generated bindings to take a + // Java long instead of a Buffer for each void* argument + + for (MethodBinding cur : bindings) { + + // Some of these routines (glBitmap) take strongly-typed + // primitive pointers as arguments which are expanded into + // non-void* arguments + // This test (rather than !signatureUsesNIO) is used to catch + // more unexpected situations + if (cur.signatureUsesJavaPrimitiveArrays()) { + continue; + } + + MethodBinding result = cur; + for (int i = 0; i < cur.getNumArguments(); i++) { + if (cur.getJavaArgumentType(i).isNIOBuffer()) { + result = result.replaceJavaArgumentType(i, JavaType.createForClass(Long.TYPE)); + } + } + + if (result == cur) { + throw new RuntimeException("Error: didn't find any void* arguments for BufferObject function " + + binding.getName()); + } + + newBindings.add(result); + // Now need to flag this MethodBinding so that we generate the + // correct flags in the emitters later + bufferObjectMethodBindings.put(result, result); + } + + return newBindings; + } + + @Override + protected boolean needsModifiedEmitters(FunctionSymbol sym) { + if ((!needsProcAddressWrapper(sym) && !needsBufferObjectVariant(sym)) + || getConfig().isUnimplemented(sym.getName())) { + return false; + } + + return true; + } + + public boolean isBufferObjectMethodBinding(MethodBinding binding) { + return bufferObjectMethodBindings.containsKey(binding); + } + + @Override + public void emitDefine(ConstantDefinition def, String optionalComment) throws Exception { + BuildStaticGLInfo glInfo = getGLConfig().getGLInfo(); + if (null == glInfo) { + throw new Exception("No GLInfo for: " + def); + } + String symbolRenamed = def.getName(); + StringBuilder newComment = new StringBuilder(); + newComment.append("Part of <code>"); + if (0 == addExtensionsOfSymbols2Buffer(newComment, ", ", symbolRenamed, def.getAliasedNames())) { + if (def.isEnum()) { + String enumName = def.getEnumName(); + if (null != enumName) { + newComment.append(enumName); + } else { + newComment.append("CORE ENUM"); + } + } else { + if (getGLConfig().getAllowNonGLExtensions()) { + newComment.append("CORE DEF"); + } else { + // Note: All GL defines must be contained within an extension marker ! + // #ifndef GL_EXT_lala + // #define GL_EXT_lala 1 + // ... + // #endif + if (JavaConfiguration.DEBUG_IGNORES) { + StringBuilder sb = new StringBuilder(); + JavaEmitter.addStrings2Buffer(sb, ", ", symbolRenamed, def.getAliasedNames()); + System.err.println("Dropping marker: " + sb.toString()); + } + return; + } + } + } + newComment.append("</code>"); + + if (null != optionalComment) { + newComment.append("<br>"); + newComment.append(optionalComment); + } + + super.emitDefine(def, newComment.toString()); + } + + public int addExtensionsOfSymbols2Buffer(StringBuilder buf, String sep, String first, Collection<String> col) { + BuildStaticGLInfo glInfo = getGLConfig().getGLInfo(); + if (null == glInfo) { + throw new RuntimeException("No GLInfo for: " + first); + } + int num = 0; + if (null == buf) { + buf = new StringBuilder(); + } + String extensionName; + + Iterator<String> iter = col.iterator(); + if (null != first) { + extensionName = glInfo.getExtension(first); + if (null != extensionName) { + buf.append(extensionName); + if (iter.hasNext()) { + buf.append(sep); + } + num++; + } + } + while (iter.hasNext()) { + extensionName = glInfo.getExtension(iter.next()); + if (null != extensionName) { + buf.append(extensionName); + if (iter.hasNext()) { + buf.append(sep); + } + num++; + } + } + return num; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + @Override + protected void generateModifiedEmitters(JavaMethodBindingEmitter baseJavaEmitter, List<FunctionEmitter> emitters) { + List<FunctionEmitter> superEmitters = new ArrayList<FunctionEmitter>(); + super.generateModifiedEmitters(baseJavaEmitter, superEmitters); + + // See whether this is one of the Buffer Object variants + boolean bufferObjectVariant = bufferObjectMethodBindings.containsKey(baseJavaEmitter.getBinding()); + + for (FunctionEmitter emitter : superEmitters) { + if (emitter instanceof ProcAddressJavaMethodBindingEmitter) { + emitter = new GLJavaMethodBindingEmitter((ProcAddressJavaMethodBindingEmitter) emitter, this, bufferObjectVariant); + } + emitters.add(emitter); + } + } + + protected boolean needsBufferObjectVariant(FunctionSymbol sym) { + return getGLConfig().isBufferObjectFunction(sym.getName()); + } + + protected GLConfiguration getGLConfig() { + return (GLConfiguration) getConfig(); + } + + @Override + protected void endProcAddressTable() throws Exception { + PrintWriter w = tableWriter; + + w.println(" /**"); + w.println(" * This is a convenience method to get (by name) the native function"); + w.println(" * pointer for a given function. It lets you avoid having to"); + w.println(" * manually compute the "" + PROCADDRESS_VAR_PREFIX + " + "); + w.println(" * <functionName>" member variable name and look it up via"); + w.println(" * reflection; it also will throw an exception if you try to get the"); + w.println(" * address of an unknown function, or one that is statically linked"); + w.println(" * and therefore does not have a function pointer in this table."); + w.println(" *"); + w.println(" * @throws RuntimeException if the function pointer was not found in"); + w.println(" * this table, either because the function was unknown or because"); + w.println(" * it was statically linked."); + w.println(" */"); + w.println(" public long getAddressFor(String functionNameUsr) {"); + w.println(" String functionNameBase = "+GLExtensionNames.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLExtensionNames.normalizeARB(functionNameUsr, true), true);"); + w.println(" String addressFieldNameBase = PROCADDRESS_VAR_PREFIX + functionNameBase;"); + w.println(" java.lang.reflect.Field addressField = null;"); + w.println(" int funcNamePermNum = "+GLExtensionNames.class.getName()+".getFuncNamePermutationNumber(functionNameBase);"); + w.println(" for(int i = 0; null==addressField && i < funcNamePermNum; i++) {"); + w.println(" String addressFieldName = "+GLExtensionNames.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);"); + w.println(" try {"); + w.println(" addressField = getClass().getField(addressFieldName);"); + w.println(" } catch (Exception e) { }"); + w.println(" }"); + w.println(); + w.println(" if(null==addressField) {"); + w.println(" // The user is calling a bogus function or one which is not"); + w.println(" // runtime linked"); + w.println(" throw new RuntimeException("); + w.println(" \"WARNING: Address field query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); + w.println(" \"\\\"; it's either statically linked or address field is not a known \" +"); + w.println(" \"function\");"); + w.println(" } "); + w.println(" try {"); + w.println(" return addressField.getLong(this);"); + w.println(" } catch (Exception e) {"); + w.println(" throw new RuntimeException("); + w.println(" \"WARNING: Address query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); + w.println(" \"\\\"; it's either statically linked or is not a known \" +"); + w.println(" \"function\", e);"); + w.println(" }"); + w.println(" }"); + + w.println("} // end of class " + tableClassName); + w.flush(); + w.close(); + } +} diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/GLJavaMethodBindingEmitter.java b/src/jogl/classes/com/jogamp/gluegen/opengl/GLJavaMethodBindingEmitter.java new file mode 100755 index 000000000..4d8c14985 --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/GLJavaMethodBindingEmitter.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.gluegen.opengl; + +import com.jogamp.gluegen.CommentEmitter; +import com.jogamp.gluegen.JavaEmitter; +import com.jogamp.gluegen.JavaMethodBindingEmitter; +import com.jogamp.gluegen.MethodBinding; +import com.jogamp.gluegen.cgram.types.Type; +import com.jogamp.gluegen.procaddress.ProcAddressJavaMethodBindingEmitter; +import java.io.PrintWriter; + +/** A specialization of the proc address emitter which knows how to +change argument names to take into account Vertex Buffer Object / +Pixel Buffer Object variants. */ +public class GLJavaMethodBindingEmitter extends ProcAddressJavaMethodBindingEmitter { + + protected boolean bufferObjectVariant; + protected GLEmitter glEmitter; + protected CommentEmitter glCommentEmitter = new GLCommentEmitter(); + + public GLJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap, boolean callThroughProcAddress, + String getProcAddressTableExpr, boolean changeNameAndArguments, boolean bufferObjectVariant, GLEmitter emitter) { + + super(methodToWrap, callThroughProcAddress, getProcAddressTableExpr, changeNameAndArguments, emitter); + this.bufferObjectVariant = bufferObjectVariant; + this.glEmitter = emitter; + setCommentEmitter(glCommentEmitter); + } + + public GLJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap, GLEmitter emitter, boolean bufferObjectVariant) { + super(methodToWrap); + this.bufferObjectVariant = bufferObjectVariant; + this.glEmitter = emitter; + setCommentEmitter(glCommentEmitter); + } + + public GLJavaMethodBindingEmitter(GLJavaMethodBindingEmitter methodToWrap) { + this(methodToWrap, methodToWrap.glEmitter, methodToWrap.bufferObjectVariant); + } + + @Override + protected String getArgumentName(int i) { + String name = super.getArgumentName(i); + + if (!bufferObjectVariant) { + return name; + } + + // Emitters for VBO/PBO-related routines change the outgoing + // argument name for the buffer + if (binding.getJavaArgumentType(i).isLong()) { + Type cType = binding.getCArgumentType(i); + Type targetType = cType.asPointer().getTargetType(); + if (cType.isPointer() && (targetType.isVoid() || targetType.isPrimitive())) { + return name + "_buffer_offset"; + } + } + + return name; + } + + protected class GLCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter { + + @Override + protected void emitBindingCSignature(MethodBinding binding, PrintWriter writer) { + + super.emitBindingCSignature(binding, writer); + + String symbolRenamed = binding.getName(); + StringBuilder newComment = new StringBuilder(); + + newComment.append("<br>Part of <code>"); + if (0 == glEmitter.addExtensionsOfSymbols2Buffer(newComment, ", ", symbolRenamed, binding.getAliasedNames())) { + if (glEmitter.getGLConfig().getAllowNonGLExtensions()) { + newComment.append("CORE FUNC"); + } else { + StringBuilder sb = new StringBuilder(); + JavaEmitter.addStrings2Buffer(sb, ", ", symbolRenamed, binding.getAliasedNames()); + RuntimeException ex = new RuntimeException("Couldn't find extension to: " + binding + " ; " + sb.toString()); + glEmitter.getGLConfig().getGLInfo().dump(); + // glEmitter.getGLConfig().dumpRenames(); + throw ex; + } + } + newComment.append("</code>"); + writer.print(newComment.toString()); + } + } +} diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/ant/StaticGLGenTask.java b/src/jogl/classes/com/jogamp/gluegen/opengl/ant/StaticGLGenTask.java new file mode 100644 index 000000000..e3e7cb970 --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/ant/StaticGLGenTask.java @@ -0,0 +1,303 @@ +package com.jogamp.gluegen.opengl.ant; + +/* + * Copyright (C) 2003 Rob Grzywinski ([email protected]) + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.LogStreamHandler; +import org.apache.tools.ant.types.CommandlineJava; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.PatternSet; +import org.apache.tools.ant.util.JavaEnvUtils; + +/** + * <p>An <a href="http://ant.apache.org">ANT</a> {@link org.apache.tools.ant.Task} + * for using {@link com.jogamp.gluegen.opengl.BuildStaticGLInfo}.</p> + * + * <p>Usage:</p> + * <pre> + <staticglgen package="[generated files package]" + headers="[file pattern of GL headers]" + outputdir="[directory to output the generated files]" /> + * </pre> + * + * @author Rob Grzywinski <a href="mailto:[email protected]">[email protected]</a> + */ +// FIXME: blow out javadoc +public class StaticGLGenTask extends Task +{ + /** + * <p>The {@link com.jogamp.gluegen.opengl.BuildStaticGLInfo} classname.</p> + */ + private static final String GL_GEN = "com.jogamp.gluegen.opengl.BuildStaticGLInfo"; + + // ========================================================================= + /** + * <p>The {@link org.apache.tools.ant.types.CommandlineJava} that is used + * to execute {@link com.jogamp.gluegen.opengl.BuildStaticGLInfo}.</p> + */ + private CommandlineJava glgenCommandline; + + // ========================================================================= + /** + * <p>The package name for the generated files.</p> + */ + private String packageName; + + /** + * <p>The output directory.</p> + */ + private String outputDirectory; + + /** + * <p>The {@link org.apache.tools.ant.types.FileSet} of GL headers.</p> + */ + private FileSet headerSet = new FileSet(); + + // ========================================================================= + /** + * <p>Create and add the VM and classname to {@link org.apache.tools.ant.types.CommandlineJava}.</p> + */ + public StaticGLGenTask() + { + // create the CommandlineJava that will be used to call BuildStaticGLInfo + glgenCommandline = new CommandlineJava(); + + // set the VM and classname in the commandline + glgenCommandline.setVm(JavaEnvUtils.getJreExecutable("java")); + glgenCommandline.setClassname(GL_GEN); + } + + // ========================================================================= + // ANT getters and setters + /** + * <p>Set the package name for the generated files. This is called by ANT.</p> + * + * @param packageName the name of the package for the generated files + */ + public void setPackage(String packageName) + { + log( ("Setting package name to: " + packageName), Project.MSG_VERBOSE); + this.packageName = packageName; + } + + /** + * <p>Set the output directory. This is called by ANT.</p> + * + * @param directory the output directory + */ + public void setOutputDir(String directory) + { + log( ("Setting output directory to: " + directory), + Project.MSG_VERBOSE); + this.outputDirectory = directory; + } + + /** + * <p>Add a header file to the list. This is called by ANT for a nested + * element.</p> + * + * @return {@link org.apache.tools.ant.types.PatternSet.NameEntry} + */ + public PatternSet.NameEntry createHeader() + { + return headerSet.createInclude(); + } + + /** + * <p>Add a header file to the list. This is called by ANT for a nested + * element.</p> + * + * @return {@link org.apache.tools.ant.types.PatternSet.NameEntry} + */ + public PatternSet.NameEntry createHeadersFile() + { + return headerSet.createIncludesFile(); + } + + /** + * <p>Set the set of header patterns. Patterns may be separated by a comma + * or a space. This is called by ANT.</p> + * + * @param headers the string containing the header patterns + */ + public void setHeaders(String headers) + { + headerSet.setIncludes(headers); + } + + /** + * <p>Add an optional classpath that defines the location of {@link com.jogamp.gluegen.opengl.BuildStaticGLInfo} + * and <code>BuildStaticGLInfo</code>'s dependencies.</p> + * + * @returns {@link org.apache.tools.ant.types.Path} + */ + public Path createClasspath() + { + return glgenCommandline.createClasspath(project).createPath(); + } + + // ========================================================================= + /** + * <p>Run the task. This involves validating the set attributes, creating + * the command line to be executed and finally executing the command.</p> + * + * @see org.apache.tools.ant.Task#execute() + */ + public void execute() + throws BuildException + { + // validate that all of the required attributes have been set + validateAttributes(); + + // TODO: add logic to determine if the generated file needs to be + // regenerated + + // add the attributes to the CommandlineJava + addAttributes(); + + log(glgenCommandline.describeCommand(), Project.MSG_VERBOSE); + + // execute the command and throw on error + final int error = execute(glgenCommandline.getCommandline()); + if(error == 1) + throw new BuildException( ("BuildStaticGLInfo returned: " + error), location); + } + + /** + * <p>Ensure that the user specified all required arguments.</p> + * + * @throws BuildException if there are required arguments that are not + * present or not valid + */ + private void validateAttributes() + throws BuildException + { + // validate that the package name is set + if(!isValid(packageName)) + throw new BuildException("Invalid package name: " + packageName); + + // validate that the output directory is set + // TODO: switch to file and ensure that it exists + if(!isValid(outputDirectory)) + throw new BuildException("Invalid output directory name: " + outputDirectory); + + // TODO: validate that there are headers set + } + + /** + * <p>Is the specified string valid? A valid string is non-<code>null</code> + * and has a non-zero length.</p> + * + * @param string the string to be tested for validity + * @return <code>true</code> if the string is valid. <code>false</code> + * otherwise. + */ + private boolean isValid(String string) + { + // check for null + if(string == null) + return false; + + // ensure that the string has a non-zero length + // NOTE: must trim() to remove leading and trailing whitespace + if(string.trim().length() < 1) + return false; + + // the string is valid + return true; + } + + /** + * <p>Add all of the attributes to the command line. They have already + * been validated.</p> + */ + private void addAttributes() + { + // add the package name + glgenCommandline.createArgument().setValue(packageName); + + // add the output directory name + glgenCommandline.createArgument().setValue(outputDirectory); + + // add the header -files- from the FileSet + headerSet.setDir(getProject().getBaseDir()); + DirectoryScanner directoryScanner = headerSet.getDirectoryScanner(getProject()); + String[] directoryFiles = directoryScanner.getIncludedFiles(); + for(int i=0; i<directoryFiles.length; i++) + { + glgenCommandline.createArgument().setValue(directoryFiles[i]); + } + } + + /** + * <p>Execute {@link com.jogamp.gluegen.opengl.BuildStaticGLInfo} in a + * forked JVM.</p> + * + * @throws BuildException + */ + private int execute(String[] command) + throws BuildException + { + // create the object that will perform the command execution + Execute execute = new Execute(new LogStreamHandler(this, Project.MSG_INFO, + Project.MSG_WARN), + null); + + // set the project and command line + execute.setAntRun(project); + execute.setCommandline(command); + execute.setWorkingDirectory( project.getBaseDir() ); + + // execute the command + try + { + return execute.execute(); + } catch(IOException ioe) + { + throw new BuildException(ioe, location); + } + } +} diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureEmitter.java b/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureEmitter.java new file mode 100755 index 000000000..e8cdcc4b4 --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureEmitter.java @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.gluegen.opengl.nativesig; + +import com.jogamp.gluegen.FunctionEmitter; +import com.jogamp.gluegen.JavaMethodBindingEmitter; +import com.jogamp.gluegen.JavaType; +import com.jogamp.gluegen.MethodBinding; +import com.jogamp.gluegen.cgram.types.FunctionSymbol; +import com.jogamp.gluegen.opengl.GLEmitter; +import com.jogamp.gluegen.opengl.GLJavaMethodBindingEmitter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * Emitter producing NativeSignature attributes. + */ +public class NativeSignatureEmitter extends GLEmitter { + + @Override + protected List<? extends FunctionEmitter> generateMethodBindingEmitters(Set<MethodBinding> methodBindingSet, FunctionSymbol sym) throws Exception { + + // Allow superclass to do most of the work for us + List<? extends FunctionEmitter> res = super.generateMethodBindingEmitters(methodBindingSet, sym); + + // Filter out all non-JavaMethodBindingEmitters + for (Iterator<? extends FunctionEmitter> iter = res.iterator(); iter.hasNext();) { + FunctionEmitter emitter = iter.next(); + if (!(emitter instanceof JavaMethodBindingEmitter)) { + iter.remove(); + } + } + + if (res.isEmpty()) { + return res; + } + + PrintWriter writer = (getConfig().allStatic() ? javaWriter() : javaImplWriter()); + + List<FunctionEmitter> processed = new ArrayList<FunctionEmitter>(); + + // First, filter out all emitters going to the "other" (public) writer + for (Iterator<? extends FunctionEmitter> iter = res.iterator(); iter.hasNext();) { + FunctionEmitter emitter = iter.next(); + if (emitter.getDefaultOutput() != writer) { + processed.add(emitter); + iter.remove(); + } + } + + // Now process all of the remaining emitters sorted by MethodBinding + while (!res.isEmpty()) { + List<JavaMethodBindingEmitter> emittersForBinding = new ArrayList<JavaMethodBindingEmitter>(); + JavaMethodBindingEmitter emitter = (JavaMethodBindingEmitter) res.remove(0); + emittersForBinding.add(emitter); + MethodBinding binding = emitter.getBinding(); + for (Iterator<? extends FunctionEmitter> iter = res.iterator(); iter.hasNext();) { + JavaMethodBindingEmitter emitter2 = (JavaMethodBindingEmitter) iter.next(); + if (emitter2.getBinding() == binding) { + emittersForBinding.add(emitter2); + iter.remove(); + } + } + generateNativeSignatureEmitters(binding, emittersForBinding); + processed.addAll(emittersForBinding); + } + + return processed; + } + + protected void generateNativeSignatureEmitters(MethodBinding binding, List<JavaMethodBindingEmitter> allEmitters) { + + if (allEmitters.isEmpty()) { + return; + } + + PrintWriter writer = (getConfig().allStatic() ? javaWriter() : javaImplWriter()); + + // Give ourselves the chance to interpose on the generation of all code to keep things simple + List<JavaMethodBindingEmitter> newEmitters = new ArrayList<JavaMethodBindingEmitter>(); + for (JavaMethodBindingEmitter javaEmitter : allEmitters) { + NativeSignatureJavaMethodBindingEmitter newEmitter = null; + if (javaEmitter instanceof GLJavaMethodBindingEmitter) { + newEmitter = new NativeSignatureJavaMethodBindingEmitter((GLJavaMethodBindingEmitter) javaEmitter); + } else { + newEmitter = new NativeSignatureJavaMethodBindingEmitter(javaEmitter, this); + } + newEmitters.add(newEmitter); + } + allEmitters.clear(); + allEmitters.addAll(newEmitters); + + // Detect whether we need to produce more or modify some of these emitters. + // Note that at this point we are assuming that generatePublicEmitters has + // been called with signatureOnly both true and false. + if (signatureContainsStrings(binding) && !haveEmitterWithBody(allEmitters)) { + // This basically handles glGetString but also any similar methods + NativeSignatureJavaMethodBindingEmitter javaEmitter = findEmitterWithWriter(allEmitters, writer); + + // First, we need to clone this emitter to produce the native + // entry point + NativeSignatureJavaMethodBindingEmitter emitter = new NativeSignatureJavaMethodBindingEmitter(javaEmitter); + emitter.removeModifier(JavaMethodBindingEmitter.PUBLIC); + emitter.addModifier(JavaMethodBindingEmitter.PRIVATE); + emitter.setForImplementingMethodCall(true); + // Note: this is chosen so we don't have to change the logic in + // emitReturnVariableSetupAndCall which decides which variant + // (direct / indirect) to call + emitter.setForDirectBufferImplementation(true); + allEmitters.add(emitter); + + // Now make the original emitter non-native and cause it to emit a body + javaEmitter.removeModifier(JavaMethodBindingEmitter.NATIVE); + javaEmitter.setEmitBody(true); + } + } + + protected boolean signatureContainsStrings(MethodBinding binding) { + for (int i = 0; i < binding.getNumArguments(); i++) { + JavaType type = binding.getJavaArgumentType(i); + if (type.isString() || type.isStringArray()) { + return true; + } + } + JavaType retType = binding.getJavaReturnType(); + if (retType.isString() || retType.isStringArray()) { + return true; + } + return false; + } + + protected boolean haveEmitterWithBody(List<JavaMethodBindingEmitter> allEmitters) { + for (JavaMethodBindingEmitter emitter : allEmitters) { + if (!emitter.signatureOnly()) { + return true; + } + } + return false; + } + + protected NativeSignatureJavaMethodBindingEmitter findEmitterWithWriter(List<JavaMethodBindingEmitter> allEmitters, PrintWriter writer) { + for (JavaMethodBindingEmitter jemitter : allEmitters) { + NativeSignatureJavaMethodBindingEmitter emitter = (NativeSignatureJavaMethodBindingEmitter)jemitter; + if (emitter.getDefaultOutput() == writer) { + return emitter; + } + } + throw new RuntimeException("Unexpectedly failed to find an emitter with the given writer"); + } +} diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureJavaMethodBindingEmitter.java b/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureJavaMethodBindingEmitter.java new file mode 100755 index 000000000..c0c66a4b3 --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureJavaMethodBindingEmitter.java @@ -0,0 +1,487 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.gluegen.opengl.nativesig; + +import com.jogamp.gluegen.JavaMethodBindingEmitter; +import com.jogamp.gluegen.JavaType; +import com.jogamp.gluegen.MethodBinding; +import com.jogamp.gluegen.cgram.types.Type; +import com.jogamp.gluegen.opengl.GLEmitter; +import com.jogamp.gluegen.opengl.GLJavaMethodBindingEmitter; +import com.jogamp.gluegen.procaddress.ProcAddressJavaMethodBindingEmitter; +import java.io.PrintWriter; + +public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBindingEmitter { + + public NativeSignatureJavaMethodBindingEmitter(GLJavaMethodBindingEmitter methodToWrap) { + super(methodToWrap); + } + + public NativeSignatureJavaMethodBindingEmitter(ProcAddressJavaMethodBindingEmitter methodToWrap, GLEmitter emitter, boolean bufferObjectVariant) { + super(methodToWrap, emitter, bufferObjectVariant); + } + + public NativeSignatureJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap, NativeSignatureEmitter emitter) { + super(methodToWrap, false, null, false, false, emitter); + } + + @Override + protected void emitSignature(PrintWriter writer) { + writer.print(getBaseIndentString()); + emitNativeSignatureAnnotation(writer); + super.emitSignature(writer); + } + + protected void emitNativeSignatureAnnotation(PrintWriter writer) { + if (hasModifier(JavaMethodBindingEmitter.NATIVE)) { + // Emit everything as a leaf for now + // FIXME: make this configurable + writer.print("@NativeSignature(\"l"); + MethodBinding binding = getBinding(); + if (callThroughProcAddress) { + writer.print("p"); + } + writer.print("("); + if (callThroughProcAddress) { + writer.print("P"); + } + for (int i = 0; i < binding.getNumArguments(); i++) { + emitNativeSignatureElement(writer, binding.getJavaArgumentType(i), binding.getCArgumentType(i), i); + } + writer.print(")"); + emitNativeSignatureElement(writer, binding.getJavaReturnType(), binding.getCReturnType(), -1); + writer.println("\")"); + } + } + + protected void emitNativeSignatureElement(PrintWriter writer, JavaType type, Type cType, int index) { + if (type.isVoid()) { + if (index > 0) { + throw new InternalError("Error parsing arguments -- void should not be seen aside from argument 0"); + } + return; + } + + if (type.isNIOBuffer()) { + writer.print("A"); + } else if (type.isPrimitiveArray()) { + writer.print("MO"); + } else if (type.isPrimitive()) { + Class clazz = type.getJavaClass(); + if (clazz == Byte.TYPE) { writer.print("B"); } + else if (clazz == Character.TYPE) { writer.print("C"); } + else if (clazz == Double.TYPE) { writer.print("D"); } + else if (clazz == Float.TYPE) { writer.print("F"); } + else if (clazz == Integer.TYPE) { writer.print("I"); } + else if (clazz == Long.TYPE) { + // See if this is intended to be a pointer at the C level + if (cType.isPointer()) { + writer.print("A"); + } else { + writer.print("J"); + } + } + else if (clazz == Short.TYPE) { writer.print("S"); } + else if (clazz == Boolean.TYPE) { writer.print("Z"); } + else throw new InternalError("Unhandled primitive type " + clazz); + } else if (type.isString()) { + writer.print("A"); + } else { + throw new RuntimeException("Type not yet handled: " + type); + } + } + + protected String getReturnTypeString(boolean skipArray) { + if (isForImplementingMethodCall()) { + JavaType returnType = getBinding().getJavaReturnType(); + if (returnType.isString() || returnType.isNIOByteBuffer()) { + // Treat these as addresses + return "long"; + } + } + return super.getReturnTypeString(skipArray); + } + + protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { + super.emitPreCallSetup(binding, writer); + for (int i = 0; i < binding.getNumArguments(); i++) { + JavaType type = binding.getJavaArgumentType(i); + if (type.isNIOBuffer() && !directNIOOnly) { + // Emit declarations for variables holding primitive arrays as type Object + // We don't know 100% sure we're going to use these at this point in the code, though + writer.println(" Object " + getNIOBufferArrayName(i) + " = (_direct ? null : Buffers.getArray(" + + getArgumentName(i) + "));"); + } else if (type.isString()) { + writer.println(" long " + binding.getArgumentName(i) + "_c_str = BuffersInternal.newCString(" + binding.getArgumentName(i) + ");"); + } + // FIXME: going to need more of these for Buffer[] and String[], at least + } + } + + protected String getNIOBufferArrayName(int argNumber) { + return "__buffer_array_" + argNumber; + } + + protected int emitArguments(PrintWriter writer) + { + boolean needComma = false; + int numEmitted = 0; + + if (callThroughProcAddress) { + if (changeNameAndArguments) { + writer.print("long procAddress"); + ++numEmitted; + needComma = true; + } + } + + if (forImplementingMethodCall && binding.hasContainingType()) { + if (needComma) { + writer.print(", "); + } + + // Always emit outgoing "this" argument + writer.print("long "); + writer.print(javaThisArgumentName()); + ++numEmitted; + needComma = true; + } + + for (int i = 0; i < binding.getNumArguments(); i++) { + JavaType type = binding.getJavaArgumentType(i); + if (type.isVoid()) { + // Make sure this is the only param to the method; if it isn't, + // there's something wrong with our parsing of the headers. + if (binding.getNumArguments() != 1) { + throw new InternalError( + "\"void\" argument type found in " + + "multi-argument function \"" + binding + "\""); + } + continue; + } + + if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) { + // Don't need to expose these at the Java level + continue; + } + + if (needComma) { + writer.print(", "); + } + + if (forImplementingMethodCall && + (forDirectBufferImplementation && type.isNIOBuffer() || + type.isString())) { + // Direct Buffers and Strings go out as longs + writer.print("long"); + // FIXME: will need more tests here to handle other constructs like String and direct Buffer arrays + } else { + writer.print(erasedTypeString(type, false)); + } + writer.print(" "); + writer.print(getArgumentName(i)); + + ++numEmitted; + needComma = true; + + // Add Buffer and array index offset arguments after each associated argument + if (forIndirectBufferAndArrayImplementation) { + if (type.isNIOBuffer()) { + writer.print(", int " + byteOffsetArgName(i)); + } else if (type.isNIOBufferArray()) { + writer.print(", int[] " + + byteOffsetArrayArgName(i)); + } + } + + // Add offset argument after each primitive array + if (type.isPrimitiveArray()) { + writer.print(", int " + offsetArgName(i)); + } + } + return numEmitted; + } + + protected void emitReturnVariableSetupAndCall(MethodBinding binding, PrintWriter writer) { + writer.print(" "); + JavaType returnType = binding.getJavaReturnType(); + boolean needsResultAssignment = false; + + if (!returnType.isVoid()) { + if (returnType.isCompoundTypeWrapper() || + returnType.isNIOByteBuffer()) { + writer.println("java.nio.ByteBuffer _res;"); + needsResultAssignment = true; + } else if (returnType.isArrayOfCompoundTypeWrappers()) { + writer.println("java.nio.ByteBuffer[] _res;"); + needsResultAssignment = true; + } else if (returnType.isString() || returnType.isNIOByteBuffer()) { + writer.print(returnType); + writer.println(" _res;"); + needsResultAssignment = true; + } else { + // Always assign to "_res" variable so we can clean up + // outgoing String arguments, for example + emitReturnType(writer); + writer.println(" _res;"); + needsResultAssignment = true; + } + } + + if (binding.signatureCanUseIndirectNIO() && !directNIOOnly) { + // Must generate two calls for this gated on whether the NIO + // buffers coming in are all direct or indirect + writer.println("if (_direct) {"); + writer.print (" "); + } + + if (needsResultAssignment) { + writer.print(" _res = "); + if (returnType.isString()) { + writer.print("BuffersInternal.newJavaString("); + } else if (returnType.isNIOByteBuffer()) { + writer.print("BuffersInternal.newDirectByteBuffer("); + } + } else { + writer.print(" "); + if (!returnType.isVoid()) { + writer.print("return "); + } + } + + if (binding.signatureUsesJavaPrimitiveArrays() && + !binding.signatureCanUseIndirectNIO()) { + // FIXME: what happens with a C function of the form + // void foo(int* arg0, void* arg1); + // ? + + // Only one call being made in this body, going to indirect + // buffer / array entry point + emitCall(binding, writer); + if (returnType.isString() || returnType.isNIOByteBuffer()) { + writer.print(")"); + } + writer.print(";"); + writer.println(); + } else { + emitCall(binding, writer); + if (returnType.isString() || returnType.isNIOByteBuffer()) { + writer.print(")"); + } + writer.print(";"); + } + + if (binding.signatureCanUseIndirectNIO() && !directNIOOnly) { + // Must generate two calls for this gated on whether the NIO + // buffers coming in are all direct or indirect + writer.println(); + writer.println(" } else {"); + writer.print (" "); + if (needsResultAssignment) { + writer.print(" _res = "); + } else { + writer.print(" "); + if (!returnType.isVoid()) { + writer.print("return "); + } + } + emitCall(binding, writer); + writer.print(";"); + writer.println(); + writer.println(" }"); + } else { + writer.println(); + } + emitPrologueOrEpilogue(epilogue, writer); + if (needsResultAssignment) { + emitCallResultReturn(binding, writer); + } + } + + protected int emitCallArguments(MethodBinding binding, PrintWriter writer, boolean direct) { + // Note that we override this completely because we both need to + // move the potential location of the outgoing proc address as + // well as change the way we pass out Buffers, arrays, Strings, etc. + + boolean needComma = false; + int numArgsEmitted = 0; + + if (callThroughProcAddress) { + writer.print("__addr_"); + needComma = true; + ++numArgsEmitted; + } + + if (binding.hasContainingType()) { + // Emit this pointer + assert(binding.getContainingType().isCompoundTypeWrapper()); + writer.print("BuffersInternal.getDirectBufferAddress("); + writer.print("getBuffer()"); + writer.print(")"); + needComma = true; + ++numArgsEmitted; + } + for (int i = 0; i < binding.getNumArguments(); i++) { + JavaType type = binding.getJavaArgumentType(i); + if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) { + // Don't need to expose these at the Java level + continue; + } + + if (type.isVoid()) { + // Make sure this is the only param to the method; if it isn't, + // there's something wrong with our parsing of the headers. + assert(binding.getNumArguments() == 1); + continue; + } + + if (needComma) { + writer.print(", "); + } + + if (type.isCompoundTypeWrapper()) { + writer.print("BuffersInternal.getDirectBufferAddress("); + writer.print("(("); + } + + if (type.isNIOBuffer()) { + if (!direct) { + writer.print(getNIOBufferArrayName(i)); + } else { + writer.print("BuffersInternal.getDirectBufferAddress("); + writer.print(getArgumentName(i)); + writer.print(")"); + } + } else { + writer.print(getArgumentName(i)); + } + + if (type.isCompoundTypeWrapper()) { + writer.print(" == null) ? null : "); + writer.print(getArgumentName(i)); + writer.print(".getBuffer())"); + writer.print(")"); + } + + if (type.isNIOBuffer()) { + if (direct) { + writer.print("+ Buffers.getDirectBufferByteOffset(" + getArgumentName(i) + ")"); + } else { + writer.print(", BuffersInternal.arrayBaseOffset(" + + getNIOBufferArrayName(i) + + ") + Buffers.getIndirectBufferByteOffset(" + getArgumentName(i) + ")"); + } + } else if (type.isNIOBufferArray()) { + writer.print(", " + byteOffsetArrayArgName(i)); + } + + // Add Array offset parameter for primitive arrays + if (type.isPrimitiveArray()) { + writer.print(", "); + writer.print("BuffersInternal.arrayBaseOffset(" + getArgumentName(i) + ") + "); + if(type.isFloatArray()) { + writer.print("Buffers.SIZEOF_FLOAT * "); + } else if(type.isDoubleArray()) { + writer.print("Buffers.SIZEOF_DOUBLE * "); + } else if(type.isByteArray()) { + writer.print("1 * "); + } else if(type.isLongArray()) { + writer.print("Buffers.SIZEOF_LONG * "); + } else if(type.isShortArray()) { + writer.print("Buffers.SIZEOF_SHORT * "); + } else if(type.isIntArray()) { + writer.print("Buffers.SIZEOF_INT * "); + } else { + throw new RuntimeException("Unsupported type for calculating array offset argument for " + + getArgumentName(i) + + "-- error occurred while processing Java glue code for " + getName()); + } + writer.print(offsetArgName(i)); + } + + if (type.isString()) { + writer.print("_c_str"); + } + + if (type.isCompoundTypeWrapper()) { + writer.print(")"); + } + + needComma = true; + ++numArgsEmitted; + } + return numArgsEmitted; + } + + protected void emitCallResultReturn(MethodBinding binding, PrintWriter writer) { + for (int i = 0; i < binding.getNumArguments(); i++) { + JavaType type = binding.getJavaArgumentType(i); + if (type.isString()) { + writer.println(";"); + writer.println(" BuffersInternal.freeCString(" + binding.getArgumentName(i) + "_c_str);"); + } + // FIXME: will need more of these cleanups for things like Buffer[] and String[] (see above) + } + + super.emitCallResultReturn(binding, writer); + } + + public String getName() { + String res = super.getName(); + if (forImplementingMethodCall && bufferObjectVariant) { + return res + "BufObj"; + } + return res; + } + + protected String getImplMethodName(boolean direct) { + String name = null; + if (direct) { + name = binding.getName() + "$0"; + } else { + name = binding.getName() + "$1"; + } + if (bufferObjectVariant) { + return name + "BufObj"; + } + return name; + } +} diff --git a/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLExtensionNames.java b/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLExtensionNames.java new file mode 100644 index 000000000..426333034 --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLExtensionNames.java @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + */ +package com.jogamp.gluegen.runtime.opengl; + +public class GLExtensionNames { + //GL_XYZ : GL_XYZ, GL_XYZ_GL2, GL_XYZ_ARB, GL_XYZ_OES, GL_XYZ_OML + //GL_XYZ : GL_XYZ, GL_GL2_XYZ, GL_ARB_XYZ, GL_OES_XYZ, GL_OML_XYZ + // + // Pass-1 Unify ARB extensions with the same value + // Pass-2 Unify vendor extensions, + // if exist as an ARB extension with the same value. + // Pass-3 Emit + + public static final String[] extensionsARB = { "ARB", "GL2", "OES", "KHR", "OML" }; + public static final String[] extensionsVEN = { "3DFX", + "AMD", + "ANGLE", + "ARM", + "APPLE", + "ATI", + "EXT", + "HI", + "HP", + "IBM", + "IMG", + "MESA", + "MESAX", + "NV", + "QCOM", + "SGI", + "SGIS", + "SGIX", + "SUN", + "VIV", + "WIN" + }; + + + public static final boolean isGLFunction(String str) { + return str.startsWith("gl") || /* str.startsWith("glu") || str.startsWith("glX") || */ + str.startsWith("egl") || str.startsWith("wgl") || str.startsWith("agl") || + str.startsWith("cgl") ; + } + + public static final boolean isGLEnumeration(String str) { + return str.startsWith("GL_") || str.startsWith("GLU_") || str.startsWith("GLX_") || + str.startsWith("EGL_") || str.startsWith("WGL_") || str.startsWith("AGL_") || + str.startsWith("CGL_") ; + } + + public static final int getExtensionIdx(String[] extensions, String str, boolean isGLFunc) { + if(isGLFunc) { + for(int i = extensions.length - 1 ; i>=0 ; i--) { + if( str.endsWith(extensions[i]) ) { + return i; + } + } + } else { + for(int i = extensions.length - 1 ; i>=0 ; i--) { + if( str.endsWith("_"+extensions[i]) ) { + return i; + } + } + } + return -1; + } + + public static final boolean isExtension(String[] extensions, String str, boolean isGLFunc) { + return getExtensionIdx(extensions, str, isGLFunc)>=0; + } + + public static final String getExtensionSuffix(String str, boolean isGLFunc) { + int idx = getExtensionIdx(extensionsARB, str, isGLFunc); + if(idx>=0) { + return extensionsARB[idx]; + } + idx = getExtensionIdx(extensionsVEN, str, isGLFunc); + if(idx>=0) { + return extensionsVEN[idx]; + } + return null; + } + + public static final String normalize(String[] extensions, String str, boolean isGLFunc) { + boolean touched = false; + for(int i = extensions.length - 1 ; !touched && i>=0 ; i--) { + if(isGLFunc) { + if(str.endsWith(extensions[i])) { + // functions + str = str.substring(0, str.length()-extensions[i].length()); + touched=true; + } + } else { + if(str.endsWith("_"+extensions[i])) { + // enums + str = str.substring(0, str.length()-1-extensions[i].length()); + touched=true; + } + } + } + return str; + } + public static final String normalizeARB(String str, boolean isGLFunc) { + return normalize(extensionsARB, str, isGLFunc); + } + public static final boolean isExtensionARB(String str, boolean isGLFunc) { + return isExtension(extensionsARB, str, isGLFunc); + } + public static final String normalizeVEN(String str, boolean isGLFunc) { + return normalize(extensionsVEN, str, isGLFunc); + } + public static final boolean isExtensionVEN(String str, boolean isGLFunc) { + return isExtension(extensionsVEN, str, isGLFunc); + } + public static final String normalize(String str, boolean isGLFunc) { + if (isExtensionARB(str, isGLFunc)) { + return normalizeARB(str, isGLFunc); + } + if (isExtensionVEN(str, isGLFunc)) { + return normalizeVEN(str, isGLFunc); + } + return str; + } + public static final boolean isExtension(String str, boolean isGLFunc) { + return isExtension(extensionsARB, str, isGLFunc) || + isExtension(extensionsVEN, str, isGLFunc); + } + + public static final int getFuncNamePermutationNumber(String name) { + if(isExtensionARB(name, true) || isExtensionVEN(name, true)) { + // no name permutation, if it's already a known extension + return 1; + } + return 1 + extensionsARB.length + extensionsVEN.length; + } + + public static final String getFuncNamePermutation(String name, int i) { + // identity + if(i==0) { + return name; + } + if(0>i || i>=(1+extensionsARB.length + extensionsVEN.length)) { + throw new RuntimeException("Index out of range [0.."+(1+extensionsARB.length+extensionsVEN.length-1)+"]: "+i); + } + // ARB + i-=1; + if(i<extensionsARB.length) { + return name+extensionsARB[i]; + } + // VEN + i-=extensionsARB.length; + return name+extensionsVEN[i]; + } +} + diff --git a/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLProcAddressResolver.java b/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLProcAddressResolver.java new file mode 100644 index 000000000..fe9efebc7 --- /dev/null +++ b/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLProcAddressResolver.java @@ -0,0 +1,62 @@ +/** + * 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. + */ + +/* + * Created on Saturday, April 24 2010 16:44 + */ +package com.jogamp.gluegen.runtime.opengl; + +import com.jogamp.common.os.DynamicLookupHelper; +import com.jogamp.gluegen.runtime.FunctionAddressResolver; + +/** + * @author Sven Gothel + * @author Michael Bien + */ +public class GLProcAddressResolver implements FunctionAddressResolver { + + public static final boolean DEBUG = false; + + public long resolve(String name, DynamicLookupHelper lookup) { + + long newProcAddress = 0; + int permutations = GLExtensionNames.getFuncNamePermutationNumber(name); + + for (int i = 0; 0 == newProcAddress && i < permutations; i++) { + String funcName = GLExtensionNames.getFuncNamePermutation(name, i); + try { + newProcAddress = lookup.dynamicLookupFunction(funcName); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } + } + } + return newProcAddress; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/JoglVersion.java b/src/jogl/classes/com/jogamp/opengl/JoglVersion.java new file mode 100644 index 000000000..34108bce6 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/JoglVersion.java @@ -0,0 +1,116 @@ +/** + * 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; + +import com.jogamp.common.GlueGenVersion; +import javax.media.opengl.*; +import com.jogamp.common.os.Platform; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.common.util.JogampVersion; +import com.jogamp.nativewindow.NativeWindowVersion; +import java.util.jar.Manifest; +import javax.media.nativewindow.AbstractGraphicsDevice; + +public class JoglVersion extends JogampVersion { + + protected static volatile JoglVersion jogampCommonVersionInfo; + + protected JoglVersion(String packageName, Manifest mf) { + super(packageName, mf); + } + + public static JoglVersion getInstance() { + if(null == jogampCommonVersionInfo) { // volatile: ok + synchronized(JoglVersion.class) { + if( null == jogampCommonVersionInfo ) { + final String packageName = "javax.media.opengl"; + final Manifest mf = VersionUtil.getManifest(JoglVersion.class.getClassLoader(), packageName); + jogampCommonVersionInfo = new JoglVersion(packageName, mf); + } + } + } + return jogampCommonVersionInfo; + } + + public StringBuilder toString(GL gl, StringBuilder sb) { + sb = super.toString(sb).append(Platform.getNewline()); + getGLInfo(gl, sb); + return sb; + } + + public String toString(GL gl) { + return toString(gl, null).toString(); + } + + public static StringBuilder getGLInfo(GL gl, StringBuilder sb) { + AbstractGraphicsDevice device = gl.getContext().getGLDrawable().getNativeSurface() + .getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); + if(null==sb) { + sb = new StringBuilder(); + } + GLContext ctx = gl.getContext(); + + sb.append(VersionUtil.SEPERATOR).append(Platform.getNewline()); + sb.append(device.getClass().getSimpleName()).append("[type ") + .append(device.getType()).append(", connection ").append(device.getConnection()).append("]: ") + .append(GLProfile.glAvailabilityToString(device)); + sb.append(Platform.getNewline()); + sb.append("Swap Interval ").append(gl.getSwapInterval()); + sb.append(Platform.getNewline()); + sb.append("GL Profile ").append(gl.getGLProfile()); + sb.append(Platform.getNewline()); + sb.append("CTX VERSION ").append(gl.getContext().getGLVersion()); + sb.append(Platform.getNewline()); + sb.append("GL ").append(gl); + sb.append(Platform.getNewline()); + sb.append("GL_VENDOR ").append(gl.glGetString(gl.GL_VENDOR)); + sb.append(Platform.getNewline()); + sb.append("GL_VERSION ").append(gl.glGetString(gl.GL_VERSION)); + sb.append(Platform.getNewline()); + sb.append("GL_EXTENSIONS "); + sb.append(Platform.getNewline()); + sb.append(" ").append(ctx.getGLExtensionsString()); + sb.append(Platform.getNewline()); + sb.append("GLX_EXTENSIONS "); + sb.append(Platform.getNewline()); + sb.append(" ").append(ctx.getPlatformExtensionsString()); + sb.append(Platform.getNewline()); + sb.append(VersionUtil.SEPERATOR); + + return sb; + } + + public static void main(String args[]) { + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(GlueGenVersion.getInstance()); + System.err.println(NativeWindowVersion.getInstance()); + System.err.println(JoglVersion.getInstance()); + } +} + diff --git a/src/jogl/classes/com/jogamp/opengl/cg/CgDynamicLibraryBundleInfo.java b/src/jogl/classes/com/jogamp/opengl/cg/CgDynamicLibraryBundleInfo.java new file mode 100644 index 000000000..5655d1a7a --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/cg/CgDynamicLibraryBundleInfo.java @@ -0,0 +1,80 @@ +/** + * 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.cg; + +import com.jogamp.common.os.DynamicLibraryBundleInfo; +import java.util.*; + +public class CgDynamicLibraryBundleInfo implements DynamicLibraryBundleInfo { + private static List/*<String>*/ glueLibNames; + static { + glueLibNames = new ArrayList(); + // glueLibNames.addAll(getGlueLibNamesPreload()); + glueLibNames.add("jogl_cg"); + } + + public static final int getCgGlueLibIndex() { + return glueLibNames.size()-1; + } + + protected CgDynamicLibraryBundleInfo() { + super(); + } + + /** Make Cg symbols available to CgGL */ + public boolean shallLinkGlobal() { return true; } + + /** default **/ + public boolean shallLookupGlobal() { return false; } + + /** Tool has none **/ + public final List getToolGetProcAddressFuncNameList() { + return null; + } + + /** Tool has none **/ + public final long toolDynamicLookupFunction(long toolGetProcAddressHandle, String funcName) { + return 0; + } + + public List/*<List<String>>*/ getToolLibNames() { + List/*<List>*/ libNamesList = new ArrayList(); + + libNamesList.add("Cg"); + libNamesList.add("CgGL"); + + return libNamesList; + } + + public final List/*<String>*/ getGlueLibNames() { + return glueLibNames; + } +} + + diff --git a/src/jogl/classes/com/jogamp/opengl/cg/CgException.java b/src/jogl/classes/com/jogamp/opengl/cg/CgException.java new file mode 100644 index 000000000..8bfd9e23e --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/cg/CgException.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.cg; + +/** + * A generic exception for errors that occur throughout the NVidia Cg + * binding, as a substitute for {@link RuntimeException}. + */ +public class CgException extends RuntimeException { + /** Constructs a CgException object. */ + public CgException() { + super(); + } + + /** Constructs a CgException object with the specified detail message. */ + public CgException(String message) { + super(message); + } + + /** Constructs a CgException object with the specified detail message and + root cause. */ + public CgException(String message, Throwable cause) { + super(message, cause); + } + + /** Constructs a CgException object with the specified root cause. */ + public CgException(Throwable cause) { + super(cause); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java b/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java new file mode 100644 index 000000000..9c77a0508 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.opengl.util; + +import java.awt.Component; +import java.awt.EventQueue; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.swing.JComponent; +import javax.swing.RepaintManager; +import javax.swing.SwingUtilities; + +import javax.media.opengl.GLAutoDrawable; + +/** Abstraction to factor out AWT dependencies from the Animator's + implementation in a way that still allows the FPSAnimator to pick + up this behavior if desired. */ + +class AWTAnimatorImpl implements AnimatorBase.AnimatorImpl { + // For efficient rendering of Swing components, in particular when + // they overlap one another + private List lightweights = new ArrayList(); + private Map repaintManagers = new IdentityHashMap(); + private Map dirtyRegions = new IdentityHashMap(); + + public void display(ArrayList drawables, + boolean ignoreExceptions, + boolean printExceptions) { + for (int i=0; i<drawables.size(); i++) { + GLAutoDrawable drawable = (GLAutoDrawable) drawables.get(i); + if (drawable instanceof JComponent) { + // Lightweight components need a more efficient drawing + // scheme than simply forcing repainting of each one in + // turn since drawing one can force another one to be + // drawn in turn + lightweights.add(drawable); + } else { + try { + drawable.display(); + } catch (RuntimeException e) { + if (ignoreExceptions) { + if (printExceptions) { + e.printStackTrace(); + } + } else { + throw(e); + } + } + } + } + + if (lightweights.size() > 0) { + try { + SwingUtilities.invokeAndWait(drawWithRepaintManagerRunnable); + } catch (Exception e) { + e.printStackTrace(); + } + lightweights.clear(); + } + } + + // Uses RepaintManager APIs to implement more efficient redrawing of + // the Swing widgets we're animating + private Runnable drawWithRepaintManagerRunnable = new Runnable() { + public void run() { + for (Iterator iter = lightweights.iterator(); iter.hasNext(); ) { + JComponent comp = (JComponent) iter.next(); + RepaintManager rm = RepaintManager.currentManager(comp); + rm.markCompletelyDirty(comp); + repaintManagers.put(rm, rm); + + // RepaintManagers don't currently optimize the case of + // overlapping sibling components. If we have two + // JInternalFrames in a JDesktopPane, the redraw of the + // bottom one will cause the top one to be redrawn as + // well. The top one will then be redrawn separately. In + // order to optimize this case we need to compute the union + // of all of the dirty regions on a particular JComponent if + // optimized drawing isn't enabled for it. + + // Walk up the hierarchy trying to find a non-optimizable + // ancestor + Rectangle visible = comp.getVisibleRect(); + int x = visible.x; + int y = visible.y; + while (comp != null) { + x += comp.getX(); + y += comp.getY(); + Component c = comp.getParent(); + if ((c == null) || (!(c instanceof JComponent))) { + comp = null; + } else { + comp = (JComponent) c; + if (!comp.isOptimizedDrawingEnabled()) { + rm = RepaintManager.currentManager(comp); + repaintManagers.put(rm, rm); + // Need to dirty this region + Rectangle dirty = (Rectangle) dirtyRegions.get(comp); + if (dirty == null) { + dirty = new Rectangle(x, y, visible.width, visible.height); + dirtyRegions.put(comp, dirty); + } else { + // Compute union with already dirty region + // Note we could compute multiple non-overlapping + // regions: might want to do that in the future + // (prob. need more complex algorithm -- dynamic + // programming?) + dirty.add(new Rectangle(x, y, visible.width, visible.height)); + } + } + } + } + } + + // Dirty any needed regions on non-optimizable components + for (Iterator iter = dirtyRegions.keySet().iterator(); iter.hasNext(); ) { + JComponent comp = (JComponent) iter.next(); + Rectangle rect = (Rectangle) dirtyRegions.get(comp); + RepaintManager rm = RepaintManager.currentManager(comp); + rm.addDirtyRegion(comp, rect.x, rect.y, rect.width, rect.height); + } + + // Draw all dirty regions + for (Iterator iter = repaintManagers.keySet().iterator(); iter.hasNext(); ) { + ((RepaintManager) iter.next()).paintDirtyRegions(); + } + dirtyRegions.clear(); + repaintManagers.clear(); + } + }; + + public boolean skipWaitForCompletion(Thread thread) { + return ((Thread.currentThread() == thread) || EventQueue.isDispatchThread()); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java new file mode 100644 index 000000000..4fbd0e478 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util; + +import javax.media.opengl.GLAutoDrawable; + + +/** <P> An Animator can be attached to one or more {@link + GLAutoDrawable}s to drive their display() methods in a loop. </P> + + <P> The Animator class creates a background thread in which the + calls to <code>display()</code> are performed. After each drawable + has been redrawn, a brief pause is performed to avoid swamping the + CPU, unless {@link #setRunAsFastAsPossible} has been called. </P> + + * <p> + * The Animator execution thread does not run as a daemon thread, + * so it is able to keep an application from terminating.<br> + * Call {@link #stop() } to terminate the animation and it's execution thread. + * </p> +*/ + +public class Animator extends AnimatorBase { + + protected ThreadGroup threadGroup; + private Runnable runnable; + private boolean runAsFastAsPossible; + protected boolean isAnimating; + protected boolean pauseIssued; + protected volatile boolean stopIssued; + + public Animator() { + super(); + if(DEBUG) { + System.err.println("Animator created"); + } + } + + public Animator(ThreadGroup tg) { + super(); + threadGroup = tg; + + if(DEBUG) { + System.err.println("Animator created, ThreadGroup: "+threadGroup); + } + } + + /** Creates a new Animator for a particular drawable. */ + public Animator(GLAutoDrawable drawable) { + super(); + add(drawable); + } + + /** Creates a new Animator for a particular drawable. */ + public Animator(ThreadGroup tg, GLAutoDrawable drawable) { + this(tg); + add(drawable); + } + + protected String getBaseName(String prefix) { + return prefix + "Animator" ; + } + + /** + * Sets a flag in this Animator indicating that it is to run as + * fast as possible. By default there is a brief pause in the + * animation loop which prevents the CPU from getting swamped. + * This method may not have an effect on subclasses. + */ + public final void setRunAsFastAsPossible(boolean runFast) { + stateSync.lock(); + try { + runAsFastAsPossible = runFast; + } finally { + stateSync.unlock(); + } + } + + private void setIsAnimatingSynced(boolean v) { + stateSync.lock(); + try { + isAnimating = v; + } finally { + stateSync.unlock(); + } + } + + class MainLoop implements Runnable { + public String toString() { + return "[started "+isStartedImpl()+", animating "+isAnimatingImpl()+", paused "+isPausedImpl()+", frames "+getTotalFrames()+", drawable "+drawables.size()+"]"; + } + + public void run() { + try { + synchronized (Animator.this) { + if(DEBUG) { + System.err.println("Animator start:" + Thread.currentThread() + ": " + toString()); + } + + startTime = System.currentTimeMillis(); + curTime = startTime; + totalFrames = 0; + + animThread = Thread.currentThread(); + setIsAnimatingSynced(false); // barrier + Animator.this.notifyAll(); + } + + while (!stopIssued) { + synchronized (Animator.this) { + // Don't consume CPU unless there is work to be done and not paused + while (!stopIssued && (pauseIssued || drawablesEmpty)) { + boolean wasPaused = pauseIssued; + if (DEBUG) { + System.err.println("Animator pause:" + Thread.currentThread() + ": " + toString()); + } + setIsAnimatingSynced(false); // barrier + Animator.this.notifyAll(); + try { + Animator.this.wait(); + } catch (InterruptedException e) { + } + + if (wasPaused) { + // resume from pause -> reset counter + startTime = System.currentTimeMillis(); + curTime = startTime; + totalFrames = 0; + if (DEBUG) { + System.err.println("Animator resume:" + Thread.currentThread() + ": " + toString()); + } + } + } + if (!stopIssued && !isAnimating) { + // resume from pause or drawablesEmpty, + // implies !pauseIssued and !drawablesEmpty + setIsAnimatingSynced(true); + Animator.this.notifyAll(); + } + } // sync Animator.this + if (!stopIssued) { + display(); + } + if (!stopIssued && !runAsFastAsPossible) { + // Avoid swamping the CPU + Thread.yield(); + } + } + } finally { + synchronized (Animator.this) { + if(DEBUG) { + System.err.println("Animator stop " + Thread.currentThread() + ": " + toString()); + } + stopIssued = false; + pauseIssued = false; + animThread = null; + setIsAnimatingSynced(false); // barrier + Animator.this.notifyAll(); + } + } + } + } + + private final boolean isStartedImpl() { + return animThread != null ; + } + public final boolean isStarted() { + stateSync.lock(); + try { + return animThread != null ; + } finally { + stateSync.unlock(); + } + } + + private final boolean isAnimatingImpl() { + return animThread != null && isAnimating ; + } + public final boolean isAnimating() { + stateSync.lock(); + try { + return animThread != null && isAnimating ; + } finally { + stateSync.unlock(); + } + } + + private final boolean isPausedImpl() { + return animThread != null && pauseIssued ; + } + public final boolean isPaused() { + stateSync.lock(); + try { + return animThread != null && pauseIssued ; + } finally { + stateSync.unlock(); + } + } + + interface Condition { + /** + * @return true if branching (cont waiting, action), otherwise false + */ + boolean result(); + } + + private synchronized void finishLifecycleAction(Condition condition) { + // It's hard to tell whether the thread which changes the lifecycle has + // dependencies on the Animator's internal thread. Currently we + // use a couple of heuristics to determine whether we should do + // the blocking wait(). + boolean doWait = !impl.skipWaitForCompletion(animThread); + if (doWait) { + while (condition.result()) { + try { + wait(); + } catch (InterruptedException ie) { } + } + } + if(DEBUG) { + System.err.println("finishLifecycleAction(" + condition.getClass().getName() + "): finished - waited " + doWait + + ", started: " + isStartedImpl() +", animating: " + isAnimatingImpl() + + ", paused: " + isPausedImpl() + ", drawables " + drawables.size()); + } + } + + public synchronized boolean start() { + if ( isStartedImpl() ) { + return false; + } + if (runnable == null) { + runnable = new MainLoop(); + } + resetCounter(); + String threadName = Thread.currentThread().getName()+"-"+baseName; + Thread thread; + if(null==threadGroup) { + thread = new Thread(runnable, threadName); + } else { + thread = new Thread(threadGroup, runnable, threadName); + } + thread.start(); + finishLifecycleAction(waitForStartedCondition); + return true; + } + + private class WaitForStartedCondition implements Condition { + public boolean result() { + return !isStartedImpl() || (!drawablesEmpty && !isAnimating) ; + } + } + Condition waitForStartedCondition = new WaitForStartedCondition(); + + public synchronized boolean stop() { + if ( !isStartedImpl() ) { + return false; + } + stopIssued = true; + notifyAll(); + finishLifecycleAction(waitForStoppedCondition); + return true; + } + private class WaitForStoppedCondition implements Condition { + public boolean result() { + return isStartedImpl(); + } + } + Condition waitForStoppedCondition = new WaitForStoppedCondition(); + + public synchronized boolean pause() { + if ( !isStartedImpl() || pauseIssued ) { + return false; + } + stateSync.lock(); + try { + pauseIssued = true; + } finally { + stateSync.unlock(); + } + notifyAll(); + finishLifecycleAction(waitForPausedCondition); + return true; + } + private class WaitForPausedCondition implements Condition { + public boolean result() { + // end waiting if stopped as well + return isAnimating && isStartedImpl(); + } + } + Condition waitForPausedCondition = new WaitForPausedCondition(); + + public synchronized boolean resume() { + if ( !isStartedImpl() || !pauseIssued ) { + return false; + } + stateSync.lock(); + try { + pauseIssued = false; + } finally { + stateSync.unlock(); + } + notifyAll(); + finishLifecycleAction(waitForResumeCondition); + return true; + } + private class WaitForResumeCondition implements Condition { + public boolean result() { + // end waiting if stopped as well + return !drawablesEmpty && !isAnimating && isStartedImpl(); + } + } + Condition waitForResumeCondition = new WaitForResumeCondition(); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java new file mode 100644 index 000000000..01c2ea664 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java @@ -0,0 +1,194 @@ +/** + * 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.util; + +import com.jogamp.common.util.locks.RecursiveLock; +import jogamp.opengl.Debug; +import java.util.ArrayList; +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLProfile; + +/** + * Base implementation of GLAnimatorControl<br> + * <p> + * The change synchronization is done via synchronized blocks on the AnimatorBase instance.<br> + * Status get / set activity is synced with a RecursiveLock, used as a memory barrier.<br> + * This is suitable, since all change requests are allowed to be expensive + * as they are not expected to be called at every frame. + * </p> + */ +public abstract class AnimatorBase implements GLAnimatorControl { + protected static final boolean DEBUG = Debug.debug("Animator"); + + private static int animatorCount = 0; + + public interface AnimatorImpl { + void display(ArrayList drawables, boolean ignoreExceptions, boolean printExceptions); + boolean skipWaitForCompletion(Thread thread); + } + + protected ArrayList/*<GLAutoDrawable>*/ drawables = new ArrayList(); + protected boolean drawablesEmpty; + protected AnimatorImpl impl; + protected String baseName; + protected Thread animThread; + protected boolean ignoreExceptions; + protected boolean printExceptions; + protected long startTime; + protected long curTime; + protected int totalFrames; + protected RecursiveLock stateSync = new RecursiveLock(); + + /** Creates a new, empty Animator. */ + public AnimatorBase() { + if(GLProfile.isAWTAvailable()) { + try { + impl = (AnimatorImpl) Class.forName("com.jogamp.opengl.util.AWTAnimatorImpl").newInstance(); + baseName = "AWTAnimator"; + } catch (Exception e) { e.printStackTrace(); } + } + if(null==impl) { + impl = new DefaultAnimatorImpl(); + baseName = "Animator"; + } + synchronized (Animator.class) { + animatorCount++; + baseName = baseName.concat("-"+animatorCount); + drawablesEmpty = true; + } + resetCounter(); + } + + protected abstract String getBaseName(String prefix); + + public synchronized void add(GLAutoDrawable drawable) { + if(DEBUG) { + System.err.println("Animator add: "+drawable.hashCode()+" - "+Thread.currentThread()); + } + boolean paused = pause(); + drawables.add(drawable); + drawablesEmpty = drawables.size() == 0; + drawable.setAnimator(this); + if(paused) { + resume(); + } + if(!impl.skipWaitForCompletion(animThread)) { + while(isStarted() && !isPaused() && !isAnimating()) { + try { + wait(); + } catch (InterruptedException ie) { } + } + } + notifyAll(); + } + + public synchronized void remove(GLAutoDrawable drawable) { + if(DEBUG) { + System.err.println("Animator remove: "+drawable.hashCode()+" - "+Thread.currentThread() + ": "+toString()); + } + + boolean paused = pause(); + drawables.remove(drawable); + drawablesEmpty = drawables.size() == 0; + drawable.setAnimator(null); + if(paused) { + resume(); + } + if(!impl.skipWaitForCompletion(animThread)) { + while(isStarted() && drawablesEmpty && isAnimating()) { + try { + wait(); + } catch (InterruptedException ie) { } + } + } + notifyAll(); + } + + /** Called every frame to cause redrawing of all of the + GLAutoDrawables this Animator manages. Subclasses should call + this to get the most optimized painting behavior for the set of + components this Animator manages, in particular when multiple + lightweight widgets are continually being redrawn. */ + protected void display() { + impl.display(drawables, ignoreExceptions, printExceptions); + curTime = System.currentTimeMillis(); + totalFrames++; + } + + public long getCurrentTime() { + return curTime; + } + + public long getDuration() { + return curTime - startTime; + } + + public long getStartTime() { + return startTime; + } + + public int getTotalFrames() { + return totalFrames; + } + + public final Thread getThread() { + stateSync.lock(); + try { + return animThread; + } finally { + stateSync.unlock(); + } + } + + public synchronized void resetCounter() { + startTime = System.currentTimeMillis(); // overwrite startTime to real init one + curTime = startTime; + totalFrames = 0; + } + + /** Sets a flag causing this Animator to ignore exceptions produced + while redrawing the drawables. By default this flag is set to + false, causing any exception thrown to halt the Animator. */ + public void setIgnoreExceptions(boolean ignoreExceptions) { + this.ignoreExceptions = ignoreExceptions; + } + + /** Sets a flag indicating that when exceptions are being ignored by + this Animator (see {@link #setIgnoreExceptions}), to print the + exceptions' stack traces for diagnostic information. Defaults to + false. */ + public void setPrintExceptions(boolean printExceptions) { + this.printExceptions = printExceptions; + } + + public String toString() { + return getClass().getName()+"[started "+isStarted()+", animating "+isAnimating()+", paused "+isPaused()+", frames "+getTotalFrames()+", drawable "+drawables.size()+"]"; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/DefaultAnimatorImpl.java b/src/jogl/classes/com/jogamp/opengl/util/DefaultAnimatorImpl.java new file mode 100644 index 000000000..d3f9cdeeb --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/DefaultAnimatorImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.opengl.util; + +import java.util.ArrayList; +import javax.media.opengl.GLAutoDrawable; + +/** Abstraction to factor out AWT dependencies from the Animator's + implementation in a way that still allows the FPSAnimator to pick + up this behavior if desired. */ + +class DefaultAnimatorImpl implements AnimatorBase.AnimatorImpl { + public void display(ArrayList drawables, + boolean ignoreExceptions, + boolean printExceptions) { + for (int i=0; i<drawables.size(); i++) { + GLAutoDrawable drawable = (GLAutoDrawable) drawables.get(i); + try { + drawable.display(); + } catch (RuntimeException e) { + if (ignoreExceptions) { + if (printExceptions) { + e.printStackTrace(); + } + } else { + throw(e); + } + } + } + } + + public boolean skipWaitForCompletion(Thread thread) { + return (Thread.currentThread() == thread); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/FBObject.java b/src/jogl/classes/com/jogamp/opengl/util/FBObject.java new file mode 100644 index 000000000..4920ed5f5 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/FBObject.java @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.opengl.util; + +import javax.media.opengl.*; + +public class FBObject { + private int width, height, attr; + private int fb, fbo_tex, depth_rb, stencil_rb, vStatus; + private int texInternalFormat, texDataFormat, texDataType; + + public static final int ATTR_DEPTH = 1 << 0; + public static final int ATTR_STENCIL = 1 << 1; + + public FBObject(int width, int height, int attributes) { + this.width = width; + this.height = height; + this.attr = attributes; + } + + + public boolean validateStatus(GL gl) { + vStatus = getStatus(gl, fb); + switch(vStatus) { + case GL.GL_FRAMEBUFFER_COMPLETE: + return true; + case GL.GL_FRAMEBUFFER_UNSUPPORTED: + case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: + case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: + case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS: + //case GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: + //case GL2.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: + //case GL2.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT: + case 0: + default: + return false; + } + } + + public static int getStatus(GL gl, int fb) { + if(!gl.glIsFramebuffer(fb)) { + return -1; + } + return gl.glCheckFramebufferStatus(gl.GL_FRAMEBUFFER); + //return gl.glCheckFramebufferStatus(fb); + } + + public String getStatusString() { + return getStatusString(vStatus); + } + + public static String getStatusString(int fbStatus) { + switch(fbStatus) { + case -1: + return "NOT A FBO"; + case GL.GL_FRAMEBUFFER_COMPLETE: + return "OK"; + case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + return("GL FBO: incomplete,incomplete attachment\n"); + case GL.GL_FRAMEBUFFER_UNSUPPORTED: + return("GL FBO: Unsupported framebuffer format"); + case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: + return("GL FBO: incomplete,missing attachment"); + case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: + return("GL FBO: incomplete,attached images must have same dimensions"); + case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS: + return("GL FBO: incomplete,attached images must have same format"); + /* + case GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: + return("GL FBO: incomplete,missing draw buffer"); + case GL2.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: + return("GL FBO: incomplete,missing read buffer"); + case GL2.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT: + return("GL FBO: incomplete, duplicate attachment"); + */ + case 0: + return("GL FBO: incomplete, implementation fault"); + default: + return("GL FBO: incomplete, implementation ERROR"); + } + } + + public void init(GL gl) { + int textureInternalFormat, textureDataFormat, textureDataType; + + if(gl.isGL2()) { + textureInternalFormat=GL.GL_RGBA8; + textureDataFormat=GL2.GL_BGRA; + textureDataType=GL2.GL_UNSIGNED_INT_8_8_8_8_REV; + } else if(gl.isGLES()) { + textureInternalFormat=GL.GL_RGBA; + textureDataFormat=GL.GL_RGBA; + textureDataType=GL.GL_UNSIGNED_BYTE; + } else { + textureInternalFormat=GL.GL_RGB; + textureDataFormat=GL.GL_RGB; + textureDataType=GL.GL_UNSIGNED_BYTE; + } + init(gl, textureInternalFormat, textureDataFormat, textureDataType); + } + + public void init(GL gl, int textureInternalFormat, int textureDataFormat, int textureDataType) { + texInternalFormat=textureInternalFormat; + texDataFormat=textureDataFormat; + texDataType=textureDataType; + + // generate fbo .. + int name[] = new int[1]; + + gl.glGenFramebuffers(1, name, 0); + fb = name[0]; + System.out.println("fb: "+fb); + + gl.glGenTextures(1, name, 0); + fbo_tex = name[0]; + System.out.println("fbo_tex: "+fbo_tex); + + if(0!=(attr&ATTR_DEPTH)) { + gl.glGenRenderbuffers(1, name, 0); + depth_rb = name[0]; + System.out.println("depth_rb: "+depth_rb); + } else { + depth_rb = 0; + } + if(0!=(attr&ATTR_STENCIL)) { + gl.glGenRenderbuffers(1, name, 0); + stencil_rb = name[0]; + System.out.println("stencil_rb: "+stencil_rb); + } else { + stencil_rb = 0; + } + + // bind fbo .. + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb); + + gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex); + gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, texInternalFormat, width, height, 0, + texDataFormat, texDataType, null); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + //gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP); + //gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP); + + + // Set up the color buffer for use as a renderable texture: + gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, + GL.GL_COLOR_ATTACHMENT0, + GL.GL_TEXTURE_2D, fbo_tex, 0); + + if(depth_rb!=0) { + // Initialize the depth buffer: + gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, depth_rb); + gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, + GL.GL_DEPTH_COMPONENT16, width, height); + // Set up the depth buffer attachment: + gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, + GL.GL_DEPTH_ATTACHMENT, + GL.GL_RENDERBUFFER, depth_rb); + } + + if(stencil_rb!=0) { + // Initialize the stencil buffer: + gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, stencil_rb); + gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, + GL.GL_STENCIL_INDEX8, width, height); + gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, + GL.GL_STENCIL_ATTACHMENT, + GL.GL_RENDERBUFFER, stencil_rb); + } + + // Check the FBO for completeness + if(validateStatus(gl)) { + System.out.println("Framebuffer " + fb + " is complete"); + } else { + System.out.println("Framebuffer " + fb + " is incomplete: status = 0x" + Integer.toHexString(vStatus) + + " : " + getStatusString()); + } + + unbind(gl); + } + + public void destroy(GL gl) { + unbind(gl); + + int name[] = new int[1]; + + if(0!=stencil_rb) { + name[0] = stencil_rb; + gl.glDeleteRenderbuffers(1, name, 0); + stencil_rb = 0; + } + if(0!=depth_rb) { + name[0] = depth_rb; + gl.glDeleteRenderbuffers(1, name, 0); + depth_rb=0; + } + if(0!=fbo_tex) { + name[0] = fbo_tex; + gl.glDeleteTextures(1, name, 0); + fbo_tex = 0; + } + if(0!=fb) { + name[0] = fb; + gl.glDeleteFramebuffers(1, name, 0); + fb = 0; + } + } + + public void bind(GL gl) { + gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex); + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb); + } + + public void unbind(GL gl) { + gl.glBindTexture(GL.GL_TEXTURE_2D, 0); + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); + } + + public void use(GL gl) { + gl.glBindTexture(GL.GL_TEXTURE_2D, 0); + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); + gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex); // to use it .. + } + + public int getFBName() { + return fb; + } + public int getTextureName() { + return fbo_tex; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java new file mode 100644 index 000000000..fc364b67a --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.opengl.util; + +import java.util.*; +import javax.media.opengl.*; + +/** An Animator subclass which attempts to achieve a target +frames-per-second rate to avoid using all CPU time. The target FPS +is only an estimate and is not guaranteed. */ +public class FPSAnimator extends AnimatorBase { + private Timer timer = null; + private TimerTask task = null; + private int fps; + private boolean scheduleAtFixedRate; + private volatile boolean shouldRun; + + protected String getBaseName(String prefix) { + return "FPS" + prefix + "Animator" ; + } + + /** Creates an FPSAnimator with a given target frames-per-second + value. Equivalent to <code>FPSAnimator(null, fps)</code>. */ + public FPSAnimator(int fps) { + this(null, fps); + } + + /** Creates an FPSAnimator with a given target frames-per-second + value and a flag indicating whether to use fixed-rate + scheduling. Equivalent to <code>FPSAnimator(null, fps, + scheduleAtFixedRate)</code>. */ + public FPSAnimator(int fps, boolean scheduleAtFixedRate) { + this(null, fps, scheduleAtFixedRate); + } + + /** Creates an FPSAnimator with a given target frames-per-second + value and an initial drawable to animate. Equivalent to + <code>FPSAnimator(null, fps, false)</code>. */ + public FPSAnimator(GLAutoDrawable drawable, int fps) { + this(drawable, fps, false); + } + + /** Creates an FPSAnimator with a given target frames-per-second + value, an initial drawable to animate, and a flag indicating + whether to use fixed-rate scheduling. */ + public FPSAnimator(GLAutoDrawable drawable, int fps, boolean scheduleAtFixedRate) { + this.fps = fps; + if (drawable != null) { + add(drawable); + } + this.scheduleAtFixedRate = scheduleAtFixedRate; + } + + public final boolean isStarted() { + stateSync.lock(); + try { + return (timer != null); + } finally { + stateSync.unlock(); + } + } + + public final boolean isAnimating() { + stateSync.lock(); + try { + return (timer != null) && (task != null); + } finally { + stateSync.unlock(); + } + } + + public final boolean isPaused() { + stateSync.lock(); + try { + return (timer != null) && (task == null); + } finally { + stateSync.unlock(); + } + } + + private void startTask() { + if(null != task) { + return; + } + long delay = (long) (1000.0f / (float) fps); + task = new TimerTask() { + public void run() { + if(FPSAnimator.this.shouldRun) { + FPSAnimator.this.animThread = Thread.currentThread(); + // display impl. uses synchronized block on the animator instance + display(); + } + } + }; + + resetCounter(); + shouldRun = true; + + if (scheduleAtFixedRate) { + timer.scheduleAtFixedRate(task, 0, delay); + } else { + timer.schedule(task, 0, delay); + } + } + + public synchronized boolean start() { + if (timer != null) { + return false; + } + stateSync.lock(); + try { + timer = new Timer(); + startTask(); + } finally { + stateSync.unlock(); + } + return true; + } + + /** Stops this FPSAnimator. Due to the implementation of the + FPSAnimator it is not guaranteed that the FPSAnimator will be + completely stopped by the time this method returns. */ + public synchronized boolean stop() { + if (timer == null) { + return false; + } + stateSync.lock(); + try { + shouldRun = false; + if(null != task) { + task.cancel(); + task = null; + } + if(null != timer) { + timer.cancel(); + timer = null; + } + animThread = null; + try { + Thread.sleep(20); // ~ 1/60 hz wait, since we can't ctrl stopped threads + } catch (InterruptedException e) { } + } finally { + stateSync.unlock(); + } + return true; + } + + public synchronized boolean pause() { + if (timer == null) { + return false; + } + stateSync.lock(); + try { + shouldRun = false; + if(null != task) { + task.cancel(); + task = null; + } + animThread = null; + try { + Thread.sleep(20); // ~ 1/60 hz wait, since we can't ctrl stopped threads + } catch (InterruptedException e) { } + } finally { + stateSync.unlock(); + } + return true; + } + + public synchronized boolean resume() { + if (timer == null) { + return false; + } + stateSync.lock(); + try { + startTask(); + } finally { + stateSync.unlock(); + } + return true; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/FileUtil.java b/src/jogl/classes/com/jogamp/opengl/util/FileUtil.java new file mode 100644 index 000000000..6ad0da825 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/FileUtil.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util; + +import java.io.*; + +/** Utilities for dealing with files. */ + +public class FileUtil { + private FileUtil() {} + + /** + * Returns the lowercase suffix of the given file name (the text + * after the last '.' in the file name). Returns null if the file + * name has no suffix. Only operates on the given file name; + * performs no I/O operations. + * + * @param file name of the file + * @return lowercase suffix of the file name + * @throws NullPointerException if file is null + */ + + public static String getFileSuffix(File file) { + return getFileSuffix(file.getName()); + } + + /** + * Returns the lowercase suffix of the given file name (the text + * after the last '.' in the file name). Returns null if the file + * name has no suffix. Only operates on the given file name; + * performs no I/O operations. + * + * @param filename name of the file + * @return lowercase suffix of the file name + * @throws NullPointerException if filename is null + */ + public static String getFileSuffix(String filename) { + int lastDot = filename.lastIndexOf('.'); + if (lastDot < 0) { + return null; + } + return toLowerCase(filename.substring(lastDot + 1)); + } + + private static String toLowerCase(String arg) { + if (arg == null) { + return null; + } + + return arg.toLowerCase(); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/FixedPoint.java b/src/jogl/classes/com/jogamp/opengl/util/FixedPoint.java new file mode 100644 index 000000000..6412db5ef --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/FixedPoint.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.opengl.util; + +public class FixedPoint { + public static final int toFixed(int value) { + if (value < -32768) value = -32768; + if (value > 32767) value = 32767; + return value * 65536; + } + + public static final int toFixed(float value) { + if (value < -32768) value = -32768; + if (value > 32767) value = 32767; + return (int)(value * 65536.0f); + } + + public static final float toFloat(int value) { + return (float)value/65536.0f; + } + + public static final int mult(int x1, int x2) { + return (int) ( ((long)x1*(long)x2)/65536 ); + } + + public static final int div(int x1, int x2) { + return (int) ( (((long)x1)<<16)/x2 ); + } +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java new file mode 100644 index 000000000..4586d1df5 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java @@ -0,0 +1,354 @@ + +package com.jogamp.opengl.util; + +import com.jogamp.common.nio.Buffers; +import java.security.*; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.glsl.*; + +import jogamp.opengl.SystemUtil; + +import java.nio.*; + +public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayDataEditable { + + /** + * The OpenGL ES emulation on the PC probably has a buggy VBO implementation, + * where we have to 'refresh' the VertexPointer or VertexAttribArray after each + * BindBuffer ! + * + * This should not be necessary on proper native implementations. + */ + public static final boolean hasVBOBug = AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return SystemUtil.getenv("JOGL_VBO_BUG"); + } + }) != null; + + /** + * @param index The GL array index + * @param name The optional custom name for the GL array index, maybe null. + * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'. + * This name might be used as the shader attribute name. + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Wheather the data shall be normalized + * + * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) + */ + public static GLArrayDataClient createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized, + int initialSize) + throws GLException + { + gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); + GLArrayDataClient adc = new GLArrayDataClient(); + GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc); + adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, 0, 0); + return adc; + } + + public static GLArrayDataClient createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized, + int stride, Buffer buffer) + throws GLException + { + gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); + GLArrayDataClient adc = new GLArrayDataClient(); + GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc); + adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler, 0, 0); + return adc; + } + + public static GLArrayDataClient createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, + int initialSize) + throws GLException + { + if(!gl.hasGLSL()) { + throw new GLException("GLArrayDataClient.GLSL not supported: "+gl); + } + gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true); + + GLArrayDataClient adc = new GLArrayDataClient(); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); + adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, 0, 0); + return adc; + } + + public static GLArrayDataClient createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, + int stride, Buffer buffer) + throws GLException + { + if(!gl.hasGLSL()) { + throw new GLException("GLArrayDataClient.GLSL not supported: "+gl); + } + gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true); + + GLArrayDataClient adc = new GLArrayDataClient(); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); + adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler, 0, 0); + return adc; + } + + // + // Data read access + // + + public final boolean isBufferWritten() { return bufferWritten; } + + public final boolean sealed() { return sealed; } + + public int getBufferUsage() { return -1; } + + // + // Data and GL state modification .. + // + + public final void setBufferWritten(boolean written) { bufferWritten=written; } + + public void destroy(GL gl) { + reset(gl); + buffer=null; + } + + public void reset(GL gl) { + enableBuffer(gl, false); + reset(); + } + + public void seal(GL gl, boolean seal) + { + seal(seal); + if(sealedGL==seal) return; + sealedGL = seal; + if(seal) { + init_vbo(gl); + + enableBuffer(gl, true); + } else { + enableBuffer(gl, false); + } + } + + public void enableBuffer(GL gl, boolean enable) { + if(enableBufferAlways && enable) { + bufferEnabled = false; + } + if( bufferEnabled != enable && components>0 ) { + if(enable) { + checkSeal(true); + if(null!=buffer) { + buffer.rewind(); + } + } + glArrayHandler.enableBuffer(gl, enable); + bufferEnabled = enable; + } + } + + public void setEnableAlways(boolean always) { + enableBufferAlways = always; + } + + // + // Data modification .. + // + + public void reset() { + if(buffer!=null) { + buffer.clear(); + } + this.sealed=false; + this.bufferEnabled=false; + this.bufferWritten=false; + } + + public void seal(boolean seal) + { + if(sealed==seal) return; + sealed = seal; + if(seal) { + bufferWritten=false; + if (null!=buffer) { + buffer.flip(); + } + } else { + if (null!=buffer) { + buffer.position(buffer.limit()); + buffer.limit(buffer.capacity()); + } + } + } + + + public void rewind() { + if(buffer!=null) { + buffer.rewind(); + } + } + + public void padding(int done) { + if ( buffer==null || sealed ) return; + while(done<strideL) { + Buffers.putb(buffer, (byte)0); + done++; + } + } + + /** + * Generic buffer relative put method. + * + * This class buffer Class must match the arguments buffer class. + * The arguments remaining elements must be a multiple of this arrays element stride. + */ + public void put(Buffer v) { + if ( buffer==null || sealed ) return; + if(0!=(v.remaining() % strideL)) { + throw new GLException("Buffer length ("+v.remaining()+") is not a multiple of component-stride:\n\t"+this); + } + growBufferIfNecessary(v.remaining()); + Buffers.put(buffer, v); + } + + public void putb(byte v) { + if ( buffer==null || sealed ) return; + growBufferIfNecessary(1); + Buffers.putb(buffer, v); + } + + public void puts(short v) { + if ( buffer==null || sealed ) return; + growBufferIfNecessary(1); + Buffers.puts(buffer, v); + } + + public void puti(int v) { + if ( buffer==null || sealed ) return; + growBufferIfNecessary(1); + Buffers.puti(buffer, v); + } + + public void putx(int v) { + puti(v); + } + + public void putf(float v) { + if ( buffer==null || sealed ) return; + growBufferIfNecessary(1); + Buffers.putf(buffer, v); + } + + public String toString() { + return "GLArrayDataClient["+name+ + ", index "+index+ + ", location "+location+ + ", isVertexAttribute "+isVertexAttribute+ + ", dataType "+dataType+ + ", bufferClazz "+clazz+ + ", elements "+getElementNumber()+ + ", components "+components+ + ", stride "+stride+"u "+strideB+"b "+strideL+"c"+ + ", initialSize "+initialSize+ + ", sealed "+sealed+ + ", bufferEnabled "+bufferEnabled+ + ", bufferWritten "+bufferWritten+ + ", buffer "+buffer+ + "]"; + } + + // non public matters + + protected final boolean growBufferIfNecessary(int spare) { + if(buffer==null || buffer.remaining()<spare) { + growBuffer(initialSize); + return true; + } + return false; + } + + protected final void growBuffer(int additional) { + if(sealed || 0==additional || 0==components) return; + + // add the stride delta + additional += (additional/components)*(strideL-components); + + if(components>0) { + int osize = (buffer!=null)?buffer.capacity():0; + if(clazz==ByteBuffer.class) { + ByteBuffer newBBuffer = Buffers.newDirectByteBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newBBuffer.put((ByteBuffer)buffer); + } + buffer = newBBuffer; + } else if(clazz==ShortBuffer.class) { + ShortBuffer newSBuffer = Buffers.newDirectShortBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newSBuffer.put((ShortBuffer)buffer); + } + buffer = newSBuffer; + } else if(clazz==IntBuffer.class) { + IntBuffer newIBuffer = Buffers.newDirectIntBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newIBuffer.put((IntBuffer)buffer); + } + buffer = newIBuffer; + } else if(clazz==FloatBuffer.class) { + FloatBuffer newFBuffer = Buffers.newDirectFloatBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newFBuffer.put((FloatBuffer)buffer); + } + buffer = newFBuffer; + } else { + throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this); + } + } + } + + protected final void checkSeal(boolean test) throws GLException { + if(sealed!=test) { + if(test) { + throw new GLException("Not Sealed yet, seal first:\n\t"+this); + } else { + throw new GLException("Already Sealed, can't modify VBO:\n\t"+this); + } + } + } + + protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data, + int initialSize, boolean isVertexAttribute, GLArrayHandler handler, + int vboName, long bufferOffset) + throws GLException + { + super.init(name, index, comps, dataType, normalized, stride, data, isVertexAttribute, + vboName, bufferOffset); + + this.initialSize = initialSize; + this.glArrayHandler = handler; + this.sealed=false; + this.sealedGL=false; + this.bufferEnabled=false; + this.enableBufferAlways=false; + this.bufferWritten=false; + if(null==buffer) { + growBuffer(initialSize); + } + } + + protected void init_vbo(GL gl) {} + + protected GLArrayDataClient() { } + + protected boolean sealed, sealedGL; + protected boolean bufferEnabled; + protected boolean bufferWritten; + protected boolean enableBufferAlways; + + protected int initialSize; + + protected GLArrayHandler glArrayHandler; +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java new file mode 100644 index 000000000..0f8ed27be --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java @@ -0,0 +1,110 @@ + +package com.jogamp.opengl.util; + +import javax.media.opengl.*; + +import java.nio.*; + +/** + * + * The total number of bytes hold by the referenced buffer is: + * getComponentSize()* getComponentNumber() * getElementNumber() + * + */ +public interface GLArrayDataEditable extends GLArrayData { + + public boolean sealed(); + + /** + * The VBO buffer usage, if it's an VBO, otherwise -1 + */ + public int getBufferUsage(); + + /** + * Is the buffer written to the GPU ? + */ + public boolean isBufferWritten(); + + /** + * Marks the buffer written to the GPU + */ + public void setBufferWritten(boolean written); + + // + // Data and GL state modification .. + // + + public void destroy(GL gl); + + public void reset(GL gl); + + /** + * If seal is true, it + * disable write operations to the buffer. + * Calls flip, ie limit:=position and position:=0. + * Also enables the buffer for OpenGL, and passes the data. + * + * If seal is false, it + * enable write operations continuing + * at the buffer position, where you left off at seal(true), + * ie position:=limit and limit:=capacity. + * Also disables the buffer for OpenGL. + * + * @see #seal(boolean) + */ + public void seal(GL gl, boolean seal); + + /** + * Enables/disables the buffer, which implies + * the client state, binding the VBO + * and transfering the data if not done yet. + * + * The above will only be executed, + * if the buffer is disabled, + * or 'setEnableAlways' was called with 'true'. + * + * @see #setEnableAlways(boolean) + */ + public void enableBuffer(GL gl, boolean enable); + + /** + * Affects the behavior of 'enableBuffer'. + * + * The default is 'false' + * + * This is usefull when you mix up + * GLArrayData usage with conventional GL array calls. + * + * @see #enableBuffer(GL, boolean) + */ + public void setEnableAlways(boolean always); + + // + // Data modification .. + // + + public void reset(); + + /** + * If seal is true, it + * disable write operations to the buffer. + * Calls flip, ie limit:=position and position:=0. + * + * If seal is false, it + * enable write operations continuing + * at the buffer position, where you left off at seal(true), + * ie position:=limit and limit:=capacity. + * + */ + public void seal(boolean seal); + + public void rewind(); + public void padding(int done); + public void put(Buffer v); + public void putb(byte v); + public void puts(short v); + public void puti(int v); + public void putx(int v); + public void putf(float v); +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java new file mode 100644 index 000000000..c061e212a --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java @@ -0,0 +1,209 @@ + +package com.jogamp.opengl.util; + +import javax.media.opengl.*; +import java.nio.*; + +import com.jogamp.opengl.util.glsl.*; + +public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataEditable { + + // + // lifetime matters + // + + /** + * Create a VBOBuffer object, using a predefined fixed function array index + * and starting with a given Buffer object incl it's stride + * + * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected. + * On profile ES2 the fixed function emulation will transform these calls to + * EnableVertexAttribArray and VertexAttribPointer calls, + * and a predefined vertex attribute variable name will be choosen. + * + * @param index The GL array index + * @param name The optional custom name for the GL array index, maybe null. + * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'. + * This name might be used as the shader attribute name. + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Wheather the data shall be normalized + * + * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) + */ + public static GLArrayDataServer createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized, + int stride, Buffer buffer, int vboBufferUsage) + throws GLException + { + gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); + + GLArrayDataServer ads = new GLArrayDataServer(); + GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads); + ads.init(gl, name, index, comps, dataType, normalized, stride, buffer, buffer.limit(), false, glArrayHandler, + 0, 0, vboBufferUsage); + return ads; + } + + /** + * Create a VBOBuffer object, using a predefined fixed function array index + * and starting with a new created Buffer object with initialSize size + * + * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected. + * On profile ES2 the fixed function emulation will transform these calls to + * EnableVertexAttribArray and VertexAttribPointer calls, + * and a predefined vertex attribute variable name will be choosen. + * + * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) + */ + public static GLArrayDataServer createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized, + int initialSize, int vboBufferUsage) + throws GLException + { + gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); + + GLArrayDataServer ads = new GLArrayDataServer(); + GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads); + ads.init(gl, name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, + 0, 0, vboBufferUsage); + return ads; + } + + /** + * Create a VBOBuffer object, using a custom GLSL array attribute name + * and starting with a new created Buffer object with initialSize size + * + * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) + */ + public static GLArrayDataServer createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, + int initialSize, int vboBufferUsage) + throws GLException + { + if(!gl.hasGLSL()) { + throw new GLException("GLArrayDataServer.GLSL not supported: "+gl); + } + gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true); + + GLArrayDataServer ads = new GLArrayDataServer(); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads); + ads.init(gl, name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, + 0, 0, vboBufferUsage); + return ads; + } + + /** + * Create a VBOBuffer object, using a custom GLSL array attribute name + * and starting with a given Buffer object incl it's stride + * + * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) + */ + public static GLArrayDataServer createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, + int stride, Buffer buffer, int vboBufferUsage) + throws GLException + { + if(!gl.hasGLSL()) { + throw new GLException("GLArrayDataServer.GLSL not supported: "+gl); + } + gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true); + + GLArrayDataServer ads = new GLArrayDataServer(); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads); + ads.init(gl, name, -1, comps, dataType, normalized, stride, buffer, buffer.limit(), true, glArrayHandler, + 0, 0, vboBufferUsage); + return ads; + } + + // + // Data matters GLArrayData + // + + public int getBufferUsage() { return vboBufferUsage; } + + // + // Data and GL state modification .. + // + + public void destroy(GL gl) { + super.destroy(gl); + if(vboName!=0) { + int[] tmp = new int[1]; + tmp[0] = vboName; + gl.glDeleteBuffers(1, tmp, 0); + vboName = 0; + } + } + + // + // data matters + // + + /** + * Convenient way do disable the VBO behavior and + * switch to client side data one + * Only possible if buffer is defined. + */ + public void setVBOUsage(boolean vboUsage) { + checkSeal(false); + super.setVBOUsage(vboUsage); + } + + public String toString() { + return "GLArrayDataServer["+name+ + ", index "+index+ + ", location "+location+ + ", isVertexAttribute "+isVertexAttribute+ + ", dataType "+dataType+ + ", bufferClazz "+clazz+ + ", elements "+getElementNumber()+ + ", components "+components+ + ", stride "+stride+"u "+strideB+"b "+strideL+"c"+ + ", initialSize "+initialSize+ + ", vboBufferUsage "+vboBufferUsage+ + ", vboUsage "+vboUsage+ + ", vboName "+vboName+ + ", sealed "+sealed+ + ", bufferEnabled "+bufferEnabled+ + ", bufferWritten "+bufferWritten+ + ", buffer "+buffer+ + ", offset "+bufferOffset+ + "]"; + } + + // + // non public matters .. + // + + protected void init(GL gl, String name, int index, int comps, int dataType, boolean normalized, + int stride, Buffer data, int initialSize, boolean isVertexAttribute, + GLArrayHandler glArrayHandler, + int vboName, long bufferOffset, int vboBufferUsage) + throws GLException + { + super.init(name, index, comps, dataType, normalized, stride, data, initialSize, isVertexAttribute, glArrayHandler, + vboName, bufferOffset); + + vboUsage=true; + + if( ! (gl.isGL2ES2() && vboBufferUsage==GL2ES2.GL_STREAM_DRAW) ) { + switch(vboBufferUsage) { + case -1: // nop + case GL.GL_STATIC_DRAW: + case GL.GL_DYNAMIC_DRAW: + break; + default: + throw new GLException("invalid vboBufferUsage: "+vboBufferUsage+":\n\t"+this); + } + } + this.vboBufferUsage=vboBufferUsage; + } + + protected void init_vbo(GL gl) { + if(vboUsage && vboName==0) { + int[] tmp = new int[1]; + gl.glGenBuffers(1, tmp, 0); + vboName = tmp[0]; + } + } + + protected int vboBufferUsage; +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java new file mode 100644 index 000000000..88a8603f9 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java @@ -0,0 +1,215 @@ + +package com.jogamp.opengl.util; + +import javax.media.opengl.*; + +import jogamp.opengl.util.glsl.fixedfunc.*; + +import java.nio.*; + +public class GLArrayDataWrapper implements GLArrayData { + + public static GLArrayDataWrapper createFixed(GL gl, int index, int comps, int dataType, boolean normalized, + int stride, Buffer buffer, + int vboName, long bufferOffset) + throws GLException + { + gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); + GLArrayDataWrapper adc = new GLArrayDataWrapper(); + adc.init(null, index, comps, dataType, normalized, stride, buffer, false, + vboName, bufferOffset); + return adc; + } + + public static GLArrayDataWrapper createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, + int stride, Buffer buffer, + int vboName, long bufferOffset) + throws GLException + { + if(!gl.hasGLSL()) { + throw new GLException("GLArrayDataWrapper.GLSL not supported: "+gl); + } + gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true); + + GLArrayDataWrapper adc = new GLArrayDataWrapper(); + adc.init(name, -1, comps, dataType, normalized, stride, buffer, true, + vboName, bufferOffset); + return adc; + } + + // + // Data read access + // + + public final boolean isVertexAttribute() { return isVertexAttribute; } + + public final int getIndex() { return index; } + + public final int getLocation() { return location; } + + public final void setLocation(int v) { location = v; } + + public final String getName() { return name; } + + public final long getOffset() { return vboUsage?bufferOffset:-1; } + + public final int getVBOName() { return vboUsage?vboName:-1; } + + public final boolean isVBO() { return vboUsage; } + + public final Buffer getBuffer() { return buffer; } + + public final int getComponentNumber() { return components; } + + public final int getComponentType() { return dataType; } + + public final int getComponentSize() { + if(clazz==ByteBuffer.class) { + return GLBuffers.SIZEOF_BYTE; + } + if(clazz==ShortBuffer.class) { + return GLBuffers.SIZEOF_SHORT; + } + if(clazz==IntBuffer.class) { + return GLBuffers.SIZEOF_INT; + } + if(clazz==FloatBuffer.class) { + return GLBuffers.SIZEOF_FLOAT; + } + throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this); + } + + public final int getElementNumber() { + if(null==buffer) return 0; + return ( buffer.position()==0 ) ? ( buffer.limit() / components ) : ( buffer.position() / components ) ; + } + + public final boolean getNormalized() { return normalized; } + + public final int getStride() { return stride; } + + public final Class getBufferClass() { return clazz; } + + public void destroy(GL gl) { + this.buffer = null; + this.components = 0; + this.stride=0; + this.strideB=0; + this.strideL=0; + this.vboName=0; + this.vboUsage=false; + this.bufferOffset=0; + } + + public String toString() { + return "GLArrayDataWrapper["+name+ + ", index "+index+ + ", location "+location+ + ", isVertexAttribute "+isVertexAttribute+ + ", dataType "+dataType+ + ", bufferClazz "+clazz+ + ", elements "+getElementNumber()+ + ", components "+components+ + ", stride "+stride+"u "+strideB+"b "+strideL+"c"+ + ", buffer "+buffer+ + ", offset "+bufferOffset+ + ", vboUsage "+vboUsage+ + ", vboName "+vboName+ + "]"; + } + + public static final Class getBufferClass(int dataType) { + switch(dataType) { + case GL.GL_BYTE: + case GL.GL_UNSIGNED_BYTE: + return ByteBuffer.class; + case GL.GL_SHORT: + case GL.GL_UNSIGNED_SHORT: + return ShortBuffer.class; + case GL2ES1.GL_FIXED: + return IntBuffer.class; + case GL.GL_FLOAT: + return FloatBuffer.class; + default: + throw new GLException("Given OpenGL data type not supported: "+dataType); + } + } + + public void setName(String newName) { + location = -1; + name = newName; + } + + public void setVBOUsage(boolean vboUsage) { + this.vboUsage=vboUsage; + } + + public void setVBOName(int vboName) { + this.vboName=vboName; + setVBOUsage(vboName>0); + } + + protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data, + boolean isVertexAttribute, + int vboName, long bufferOffset) + throws GLException + { + this.isVertexAttribute = isVertexAttribute; + this.index = index; + this.location = -1; + // We can't have any dependence on the FixedFuncUtil class here for build bootstrapping reasons + this.name = (null==name)?FixedFuncPipeline.getPredefinedArrayIndexName(index):name; + if(null==this.name) { + throw new GLException("Not a valid GL array index: "+index); + } + this.dataType = dataType; + this.clazz = getBufferClass(dataType); + switch(dataType) { + case GL.GL_BYTE: + case GL.GL_UNSIGNED_BYTE: + case GL.GL_SHORT: + case GL.GL_UNSIGNED_SHORT: + case GL2ES1.GL_FIXED: + this.normalized = normalized; + break; + default: + this.normalized = false; + } + + int bpc = getComponentSize(); + if(0<stride && stride<comps*bpc) { + throw new GLException("stride ("+stride+") lower than component bytes, "+comps+" * "+bpc); + } + if(0<stride && stride%bpc!=0) { + throw new GLException("stride ("+stride+") not a multiple of bpc "+bpc); + } + this.buffer = data; + this.components = comps; + this.stride=stride; + this.strideB=(0==stride)?comps*bpc:stride; + this.strideL=(0==stride)?comps:strideB/bpc; + this.vboName=vboName; + this.vboUsage=vboName>0; + this.bufferOffset=bufferOffset; + } + + protected GLArrayDataWrapper() { } + + protected int index; + protected int location; + protected String name; + protected int components; + protected int dataType; + protected boolean normalized; + protected int stride; // user given stride + protected int strideB; // stride in bytes + protected int strideL; // stride in logical components + protected Class clazz; + protected Buffer buffer; + protected boolean isVertexAttribute; + + protected long bufferOffset; + protected int vboName; + protected boolean vboUsage; +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java new file mode 100644 index 000000000..bfabb5b01 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java @@ -0,0 +1,11 @@ + +package com.jogamp.opengl.util; + +import javax.media.opengl.*; + +public interface GLArrayHandler { + + public void enableBuffer(GL gl, boolean enable); + +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java b/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java new file mode 100644 index 000000000..efe3a7675 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.opengl.util; + +import com.jogamp.common.nio.Buffers; +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.GL2ES2; + +import java.nio.*; + +/** + * Utility routines for dealing with direct buffers. + * @author Kenneth Russel + * @author Michael Bien + */ +public class GLBuffers extends Buffers { + + public static final int sizeOfGLType(int glType) { + switch (glType) { + case GL.GL_UNSIGNED_BYTE: + return SIZEOF_BYTE; + case GL.GL_BYTE: + return SIZEOF_BYTE; + case GL.GL_UNSIGNED_SHORT: + return SIZEOF_SHORT; + case GL.GL_SHORT: + return SIZEOF_SHORT; + case GL.GL_FLOAT: + return SIZEOF_FLOAT; + case GL.GL_FIXED: + return SIZEOF_INT; + case GL2ES2.GL_INT: + return SIZEOF_INT; + case GL2ES2.GL_UNSIGNED_INT: + return SIZEOF_INT; + case GL2.GL_DOUBLE: + return SIZEOF_DOUBLE; + } + return -1; + } + + public static final Buffer newDirectGLBuffer(int glType, int numElements) { + switch (glType) { + case GL.GL_UNSIGNED_BYTE: + case GL.GL_BYTE: + return newDirectByteBuffer(numElements); + case GL.GL_UNSIGNED_SHORT: + case GL.GL_SHORT: + return newDirectShortBuffer(numElements); + case GL.GL_FLOAT: + return newDirectFloatBuffer(numElements); + case GL.GL_FIXED: + case GL2ES2.GL_INT: + case GL2ES2.GL_UNSIGNED_INT: + return newDirectIntBuffer(numElements); + case GL2.GL_DOUBLE: + return newDirectDoubleBuffer(numElements); + } + return null; + } + + public static final Buffer sliceGLBuffer(ByteBuffer parent, int bytePos, int byteLen, int glType) { + if (parent == null || byteLen == 0) { + return null; + } + parent.position(bytePos); + parent.limit(bytePos + byteLen); + + switch (glType) { + case GL.GL_UNSIGNED_BYTE: + case GL.GL_BYTE: + return parent.slice(); + case GL.GL_UNSIGNED_SHORT: + case GL.GL_SHORT: + return parent.asShortBuffer(); + case GL.GL_FLOAT: + return parent.asFloatBuffer(); + case GL.GL_FIXED: + case GL2ES2.GL_INT: + case GL2ES2.GL_UNSIGNED_INT: + return parent.asIntBuffer(); + case GL2.GL_DOUBLE: + return parent.asDoubleBuffer(); + } + return null; + } + + //---------------------------------------------------------------------- + // Conversion routines + // + public final static float[] getFloatArray(double[] source) { + int i = source.length; + float[] dest = new float[i--]; + while (i >= 0) { + dest[i] = (float) source[i]; + i--; + } + return dest; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java new file mode 100644 index 000000000..f0f5ea896 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java @@ -0,0 +1,65 @@ + +package com.jogamp.opengl.util; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; +import com.jogamp.opengl.util.*; +import java.nio.*; + +public class GLFixedArrayHandler implements GLArrayHandler { + private GLArrayDataEditable ad; + + public GLFixedArrayHandler(GLArrayDataEditable ad) { + this.ad = ad; + } + + protected final void passArrayPointer(GLPointerFunc gl) { + switch(ad.getIndex()) { + case GLPointerFunc.GL_VERTEX_ARRAY: + gl.glVertexPointer(ad); + break; + case GLPointerFunc.GL_NORMAL_ARRAY: + gl.glNormalPointer(ad); + break; + case GLPointerFunc.GL_COLOR_ARRAY: + gl.glColorPointer(ad); + break; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + gl.glTexCoordPointer(ad); + break; + default: + throw new GLException("invalid glArrayIndex: "+ad.getIndex()+":\n\t"+ad); + } + } + + public void enableBuffer(GL gl, boolean enable) { + GLPointerFunc glp = gl.getGL2ES1(); + if(enable) { + glp.glEnableClientState(ad.getIndex()); + + Buffer buffer = ad.getBuffer(); + + if(ad.isVBO()) { + // always bind and refresh the VBO mgr, + // in case more than one gl*Pointer objects are in use + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); + if(!ad.isBufferWritten()) { + if(null!=buffer) { + gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); + } + ad.setBufferWritten(true); + } + passArrayPointer(glp); + } else if(null!=buffer) { + passArrayPointer(glp); + ad.setBufferWritten(true); + } + } else { + if(ad.isVBO()) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } + glp.glDisableClientState(ad.getIndex()); + } + } +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/Gamma.java b/src/jogl/classes/com/jogamp/opengl/util/Gamma.java new file mode 100644 index 000000000..c649d1c6a --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/Gamma.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util; + +import javax.media.opengl.*; +import jogamp.opengl.*; + +/** Provides control over the primary display's gamma, brightness and + contrast controls via the hardware gamma ramp tables. Not + supported on all platforms or graphics hardware. <P> + + Thanks to the LWJGL project for illustrating how to access gamma + control on the various platforms. +*/ + +public class Gamma { + private Gamma() {} + + /** + * Sets the gamma, brightness, and contrast of the current main + * display. This functionality is not available on all platforms and + * graphics hardware. Returns true if the settings were successfully + * changed, false if not. This method may return false for some + * values of the incoming arguments even on hardware which does + * support the underlying functionality. <P> + * + * If this method returns true, the display settings will + * automatically be reset to their original values upon JVM exit + * (assuming the JVM does not crash); if the user wishes to change + * the display settings back to normal ahead of time, use {@link + * #resetDisplayGamma resetDisplayGamma}(). It is recommended to + * call {@link #resetDisplayGamma resetDisplayGamma} before calling + * e.g. <code>System.exit()</code> from the application rather than + * rely on the shutdown hook functionality due to inevitable race + * conditions and unspecified behavior during JVM teardown. <P> + * + * This method may be called multiple times during the application's + * execution, but calling {@link #resetDisplayGamma + * resetDisplayGamma} will only reset the settings to the values + * before the first call to this method. <P> + * + * @param gamma The gamma value, typically > 1.0 (default values + * vary, but typically roughly 1.0) + * @param brightness The brightness value between -1.0 and 1.0, + * inclusive (default values vary, but typically 0) + * @param contrast The contrast, greater than 0.0 (default values + * vary, but typically 1) + * @return true if gamma settings were successfully changed, false + * if not + * @throws IllegalArgumentException if any of the parameters were + * out-of-bounds + */ + public static boolean setDisplayGamma(GL gl, float gamma, float brightness, float contrast) throws IllegalArgumentException { + return GLDrawableFactoryImpl.getFactoryImpl(gl.getContext().getGLDrawable().getGLProfile()).setDisplayGamma(gamma, brightness, contrast); + } + + /** + * Resets the gamma, brightness and contrast values for the primary + * display to their original values before {@link #setDisplayGamma + * setDisplayGamma} was called the first time. {@link + * #setDisplayGamma setDisplayGamma} must be called before calling + * this method or an unspecified exception will be thrown. While it + * is not explicitly required that this method be called before + * exiting, calling it is recommended because of the inevitable + * unspecified behavior during JVM teardown. + */ + public static void resetDisplayGamma(GL gl) { + GLDrawableFactoryImpl.getFactoryImpl(gl.getContext().getGLDrawable().getGLProfile()).resetDisplayGamma(); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java new file mode 100644 index 000000000..d9fce6e6a --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java @@ -0,0 +1,974 @@ + +package com.jogamp.opengl.util; + +import com.jogamp.common.util.*; +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; +import java.nio.*; +import java.util.Iterator; +import java.util.ArrayList; + +public class ImmModeSink { + + public static final boolean DEBUG_BEGIN_END = false; + public static final boolean DEBUG_DRAW = false; + + // public static final int GL_QUADS = 0x0007; // Needs data manipulation + public static final int GL_QUAD_STRIP = 0x0008; + public static final int GL_POLYGON = 0x0009; + + /** + * Uses a GL2ES1, or ES2 fixed function emulation immediate mode sink + */ + public static ImmModeSink createFixed(GL gl, int glBufferUsage, int initialSize, + int vComps, int vDataType, + int cComps, int cDataType, + int nComps, int nDataType, + int tComps, int tDataType) { + return new ImmModeSink(gl, glBufferUsage, initialSize, + vComps, vDataType, cComps, cDataType, nComps, nDataType, tComps, tDataType, false); + } + + /** + * Uses a GL2ES2 GLSL shader immediate mode sink. + * To issue the draw() command, + * a ShaderState must be current, using ShaderState.glUseProgram(). + * + * @see #draw(GL, boolean) + * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean) + * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrent() + */ + public static ImmModeSink createGLSL(GL gl, int glBufferUsage, int initialSize, + int vComps, int vDataType, + int cComps, int cDataType, + int nComps, int nDataType, + int tComps, int tDataType) { + return new ImmModeSink(gl, glBufferUsage, initialSize, + vComps, vDataType, cComps, cDataType, nComps, nDataType, tComps, tDataType, true); + } + + public static boolean usesVBO() { return vboUsage; } + + public static void setVBOUsage(boolean v) { vboUsage = v; } + + public void destroy(GL gl) { + destroyList(gl); + + vboSet.destroy(gl); + } + + public void reset() { + reset(null); + } + + public void reset(GL gl) { + destroyList(gl); + vboSet.reset(gl); + } + + public String toString() { + StringBuffer sb = new StringBuffer("ImmModeSink["); + sb.append(",\n\tVBO list: "+vboSetList.size()+" ["); + for(Iterator i=vboSetList.iterator(); i.hasNext() ; ) { + sb.append("\n\t"); + sb.append( (VBOSet)i.next() ); + } + if(vboSetList.size()>0) { + sb.append("\n\t],\nVBO current: NOP]"); + } else { + sb.append("\n\t],\nVBO current: \n"); + sb.append(vboSet); + sb.append("\n]"); + } + return sb.toString(); + } + + public void draw(GL gl, boolean disableBufferAfterDraw) { + if(DEBUG_DRAW) { + Exception e = new Exception("Info: ImmModeSink.draw(disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); + e.printStackTrace(); + } + int n=0; + for(Iterator i=vboSetList.iterator(); i.hasNext() ; n++) { + ((VBOSet)i.next()).draw(gl, null, disableBufferAfterDraw, n); + } + } + + public void draw(GL gl, Buffer indices, boolean disableBufferAfterDraw) { + if(DEBUG_DRAW) { + Exception e = new Exception("Info: ImmModeSink.draw(disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); + e.printStackTrace(); + } + int n=0; + for(Iterator i=vboSetList.iterator(); i.hasNext() ; n++) { + ((VBOSet)i.next()).draw(gl, indices, disableBufferAfterDraw, n); + } + } + + public void glBegin(int mode) { + if(DEBUG_BEGIN_END) { + Exception e = new Exception("Info: ImmModeSink.glBegin("+vboSet.mode+"):\n\t"+this); + e.printStackTrace(); + } + vboSet.modeOrig = mode; + switch(mode) { + // Needs data manipulation .. + //case GL_QUADS: + // mode=GL.GL_LINES; + // break; + case GL_QUAD_STRIP: + mode=GL.GL_TRIANGLE_STRIP; + break; + case GL_POLYGON: + mode=GL.GL_LINES; + break; + } + vboSet.mode = mode; + vboSet.checkSeal(false); + } + + public final void glEnd(GL gl) { + glEnd(gl, null, true); + } + + public void glEnd(GL gl, boolean immediateDraw) { + glEnd(gl, null, immediateDraw); + } + + public final void glEnd(GL gl, Buffer indices) { + glEnd(gl, indices, true); + } + + private void glEnd(GL gl, Buffer indices, boolean immediateDraw) { + if(DEBUG_BEGIN_END) { + Exception e = new Exception("Info: ImmModeSink START glEnd(immediate: "+immediateDraw+"):\n\t"+this); + e.printStackTrace(); + } + if(immediateDraw) { + vboSet.seal(gl, true); + vboSet.draw(gl, indices, true, -1); + reset(gl); + } else { + vboSet.seal(gl, true); + vboSet.enableBuffer(gl, false); + vboSetList.add(vboSet); + vboSet = vboSet.regenerate(); + } + } + + public void glVertexv(Buffer v) { + vboSet.glVertexv(v); + } + public void glNormalv(Buffer v) { + vboSet.glNormalv(v); + } + public void glColorv(Buffer v) { + vboSet.glColorv(v); + } + public void glTexCoordv(Buffer v) { + vboSet.glTexCoordv(v); + } + + public final void glVertex2f(float x, float y) { + vboSet.glVertex2f(x,y); + } + + public final void glVertex3f(float x, float y, float z) { + vboSet.glVertex3f(x,y,z); + } + + public final void glNormal3f(float x, float y, float z) { + vboSet.glNormal3f(x,y,z); + } + + public final void glColor3f(float x, float y, float z) { + vboSet.glColor3f(x,y,z); + } + + public final void glColor4f(float x, float y, float z, float a) { + vboSet.glColor4f(x,y,z, a); + } + + public final void glTexCoord2f(float x, float y) { + vboSet.glTexCoord2f(x,y); + } + + public final void glTexCoord3f(float x, float y, float z) { + vboSet.glTexCoord3f(x,y,z); + } + + public final void glVertex2s(short x, short y) { + vboSet.glVertex2s(x,y); + } + + public final void glVertex3s(short x, short y, short z) { + vboSet.glVertex3s(x,y,z); + } + + public final void glNormal3s(short x, short y, short z) { + vboSet.glNormal3s(x,y,z); + } + + public final void glColor3s(short x, short y, short z) { + vboSet.glColor3s(x,y,z); + } + + public final void glColor4s(short x, short y, short z, short a) { + vboSet.glColor4s(x,y,z,a); + } + + public final void glTexCoord2s(short x, short y) { + vboSet.glTexCoord2s(x,y); + } + + public final void glTexCoord3s(short x, short y, short z) { + vboSet.glTexCoord3s(x,y,z); + } + + public final void glVertex2b(byte x, byte y) { + vboSet.glVertex2b(x,y); + } + + public final void glVertex3b(byte x, byte y, byte z) { + vboSet.glVertex3b(x,y,z); + } + + public final void glNormal3b(byte x, byte y, byte z) { + vboSet.glNormal3b(x,y,z); + } + + public final void glColor3b(byte x, byte y, byte z) { + vboSet.glColor3b(x,y,z); + } + + public final void glColor4b(byte x, byte y, byte z, byte a) { + vboSet.glColor4b(x,y,z,a); + } + + public final void glTexCoord2b(byte x, byte y) { + vboSet.glTexCoord2b(x,y); + } + + public final void glTexCoord3b(byte x, byte y, byte z) { + vboSet.glTexCoord3b(x,y,z); + } + + protected ImmModeSink(GL gl, int glBufferUsage, int initialSize, + int vComps, int vDataType, + int cComps, int cDataType, + int nComps, int nDataType, + int tComps, int tDataType, boolean useGLSL) { + if(useGLSL && !gl.hasGLSL()) { + throw new GLException("ImmModeSink GLSL usage not supported: "+gl); + } + vboSet = new VBOSet(gl, glBufferUsage, initialSize, + vComps, vDataType, cComps, cDataType, nComps, nDataType, tComps, tDataType, useGLSL); + this.vboSetList = new ArrayList(); + } + + private void destroyList(GL gl) { + for(Iterator i=vboSetList.iterator(); i.hasNext() ; ) { + ((VBOSet)i.next()).destroy(gl); + } + vboSetList.clear(); + } + + private VBOSet vboSet; + private ArrayList vboSetList; + private static boolean vboUsage = true; + + protected static class VBOSet { + protected VBOSet (GL gl, int glBufferUsage, int initialSize, + int vComps, int vDataType, + int cComps, int cDataType, + int nComps, int nDataType, + int tComps, int tDataType, boolean useGLSL) { + this.gl=gl; + this.glBufferUsage=glBufferUsage; + this.initialSize=initialSize; + this.vDataType=vDataType; + this.vComps=vComps; + this.cDataType=cDataType; + this.cComps=cComps; + this.nDataType=nDataType; + this.nComps=nComps; + this.tDataType=tDataType; + this.tComps=tComps; + this.useGLSL=useGLSL; + + allocateBuffer(initialSize); + rewind(); + + this.sealed=false; + this.sealedGL=false; + this.mode = -1; + this.modeOrig = -1; + this.bufferEnabled=false; + this.bufferWritten=false; + } + + protected final VBOSet regenerate() { + return new VBOSet(gl, glBufferUsage, initialSize, + vComps, vDataType, cComps, cDataType, nComps, nDataType, tComps, tDataType, useGLSL); + } + + protected void checkSeal(boolean test) throws GLException { + if(mode<0) { + throw new GLException("No mode set yet, call glBegin(mode) first:\n\t"+this); + } + if(sealed!=test) { + if(test) { + throw new GLException("Not Sealed yet, call glEnd() first:\n\t"+this); + } else { + throw new GLException("Already Sealed, can't modify VBO after glEnd():\n\t"+this); + } + } + } + + protected void draw(GL gl, Buffer indices, boolean disableBufferAfterDraw, int i) + { + if(DEBUG_DRAW) { + Exception e = new Exception("Info: ImmModeSink.draw["+i+"](disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); + e.printStackTrace(); + } + enableBuffer(gl, true); + + if (buffer!=null) { + GL2ES1 glf = gl.getGL2ES1(); + + if(null==indices) { + glf.glDrawArrays(mode, 0, count); + } else { + Class clazz = indices.getClass(); + int type=-1; + if(ReflectionUtil.instanceOf(clazz, ByteBuffer.class.getName())) { + type = GL.GL_UNSIGNED_BYTE; + } else if(ReflectionUtil.instanceOf(clazz, ShortBuffer.class.getName())) { + type = GL.GL_UNSIGNED_SHORT; + } + if(0>type) { + throw new GLException("Given Buffer Class not supported: "+clazz+", should be ubyte or ushort:\n\t"+this); + } + glf.glDrawElements(mode, indices.remaining(), type, indices); + // GL2: gl.glDrawRangeElements(mode, 0, indices.remaining()-1, indices.remaining(), type, indices); + } + } + + if(disableBufferAfterDraw) { + enableBuffer(gl, false); + } + } + + public void glVertexv(Buffer v) { + checkSeal(false); + GLBuffers.put(vertexArray, v); + } + public void glNormalv(Buffer v) { + checkSeal(false); + GLBuffers.put(normalArray, v); + } + public void glColorv(Buffer v) { + checkSeal(false); + GLBuffers.put(colorArray, v); + } + public void glTexCoordv(Buffer v) { + checkSeal(false); + GLBuffers.put(textCoordArray, v); + } + + public void glVertex2b(byte x, byte y) { + checkSeal(false); + growBufferIfNecessary(VERTEX, 2); + if(vComps>0) + GLBuffers.putb(vertexArray, x); + if(vComps>1) + GLBuffers.putb(vertexArray, y); + padding(VERTEX, vComps-2); + } + public void glVertex3b(byte x, byte y, byte z) { + checkSeal(false); + growBufferIfNecessary(VERTEX, 3); + if(vComps>0) + GLBuffers.putb(vertexArray, x); + if(vComps>1) + GLBuffers.putb(vertexArray, y); + if(vComps>2) + GLBuffers.putb(vertexArray, z); + padding(VERTEX, vComps-3); + } + public void glVertex2s(short x, short y) { + checkSeal(false); + growBufferIfNecessary(VERTEX, 2); + if(vComps>0) + GLBuffers.puts(vertexArray, x); + if(vComps>1) + GLBuffers.puts(vertexArray, y); + padding(VERTEX, vComps-2); + } + public void glVertex3s(short x, short y, short z) { + checkSeal(false); + growBufferIfNecessary(VERTEX, 3); + if(vComps>0) + GLBuffers.puts(vertexArray, x); + if(vComps>1) + GLBuffers.puts(vertexArray, y); + if(vComps>2) + GLBuffers.puts(vertexArray, z); + padding(VERTEX, vComps-3); + } + public void glVertex2f(float x, float y) { + checkSeal(false); + growBufferIfNecessary(VERTEX, 2); + if(vComps>0) + GLBuffers.putf(vertexArray, x); + if(vComps>1) + GLBuffers.putf(vertexArray, y); + padding(VERTEX, vComps-2); + } + public void glVertex3f(float x, float y, float z) { + checkSeal(false); + growBufferIfNecessary(VERTEX, 3); + if(vComps>0) + GLBuffers.putf(vertexArray, x); + if(vComps>1) + GLBuffers.putf(vertexArray, y); + if(vComps>2) + GLBuffers.putf(vertexArray, z); + padding(VERTEX, vComps-3); + } + + public void glNormal3b(byte x, byte y, byte z) { + checkSeal(false); + growBufferIfNecessary(NORMAL, 3); + if(nComps>0) + GLBuffers.putb(normalArray, x); + if(nComps>1) + GLBuffers.putb(normalArray, y); + if(nComps>2) + GLBuffers.putb(normalArray, z); + padding(NORMAL, nComps-3); + } + public void glNormal3s(short x, short y, short z) { + checkSeal(false); + growBufferIfNecessary(NORMAL, 3); + if(nComps>0) + GLBuffers.puts(normalArray, x); + if(nComps>1) + GLBuffers.puts(normalArray, y); + if(nComps>2) + GLBuffers.puts(normalArray, z); + padding(NORMAL, nComps-3); + } + public void glNormal3f(float x, float y, float z) { + checkSeal(false); + growBufferIfNecessary(NORMAL, 3); + if(nComps>0) + GLBuffers.putf(normalArray, x); + if(nComps>1) + GLBuffers.putf(normalArray, y); + if(nComps>2) + GLBuffers.putf(normalArray, z); + padding(NORMAL, nComps-3); + } + + public void glColor3b(byte r, byte g, byte b) { + checkSeal(false); + growBufferIfNecessary(COLOR, 3); + if(cComps>0) + GLBuffers.putb(colorArray, r); + if(cComps>1) + GLBuffers.putb(colorArray, g); + if(cComps>2) + GLBuffers.putb(colorArray, b); + padding(COLOR, cComps-3); + } + public void glColor4b(byte r, byte g, byte b, byte a) { + checkSeal(false); + growBufferIfNecessary(COLOR, 4); + if(cComps>0) + GLBuffers.putb(colorArray, r); + if(cComps>1) + GLBuffers.putb(colorArray, g); + if(cComps>2) + GLBuffers.putb(colorArray, b); + if(cComps>3) + GLBuffers.putb(colorArray, a); + padding(COLOR, cComps-4); + } + public void glColor3s(short r, short g, short b) { + checkSeal(false); + growBufferIfNecessary(COLOR, 3); + if(cComps>0) + GLBuffers.puts(colorArray, r); + if(cComps>1) + GLBuffers.puts(colorArray, g); + if(cComps>2) + GLBuffers.puts(colorArray, b); + padding(COLOR, cComps-3); + } + public void glColor4s(short r, short g, short b, short a) { + checkSeal(false); + growBufferIfNecessary(COLOR, 4); + if(cComps>0) + GLBuffers.puts(colorArray, r); + if(cComps>1) + GLBuffers.puts(colorArray, g); + if(cComps>2) + GLBuffers.puts(colorArray, b); + if(cComps>3) + GLBuffers.puts(colorArray, a); + padding(COLOR, cComps-4); + } + public void glColor3f(float r, float g, float b) { + checkSeal(false); + growBufferIfNecessary(COLOR, 3); + if(cComps>0) + GLBuffers.putf(colorArray, r); + if(cComps>1) + GLBuffers.putf(colorArray, g); + if(cComps>2) + GLBuffers.putf(colorArray, b); + padding(COLOR, cComps-3); + } + public void glColor4f(float r, float g, float b, float a) { + checkSeal(false); + growBufferIfNecessary(COLOR, 4); + if(cComps>0) + GLBuffers.putf(colorArray, r); + if(cComps>1) + GLBuffers.putf(colorArray, g); + if(cComps>2) + GLBuffers.putf(colorArray, b); + if(cComps>3) + GLBuffers.putf(colorArray, a); + padding(COLOR, cComps-4); + } + + public void glTexCoord2b(byte x, byte y) { + checkSeal(false); + growBufferIfNecessary(TEXTCOORD, 2); + if(tComps>0) + GLBuffers.putb(textCoordArray, x); + if(tComps>1) + GLBuffers.putb(textCoordArray, y); + padding(TEXTCOORD, tComps-2); + } + public void glTexCoord3b(byte x, byte y, byte z) { + checkSeal(false); + growBufferIfNecessary(TEXTCOORD, 3); + if(tComps>0) + GLBuffers.putb(textCoordArray, x); + if(tComps>1) + GLBuffers.putb(textCoordArray, y); + if(tComps>2) + GLBuffers.putb(textCoordArray, z); + padding(TEXTCOORD, tComps-3); + } + public void glTexCoord2s(short x, short y) { + checkSeal(false); + growBufferIfNecessary(TEXTCOORD, 2); + if(tComps>0) + GLBuffers.puts(textCoordArray, x); + if(tComps>1) + GLBuffers.puts(textCoordArray, y); + padding(TEXTCOORD, tComps-2); + } + public void glTexCoord3s(short x, short y, short z) { + checkSeal(false); + growBufferIfNecessary(TEXTCOORD, 3); + if(tComps>0) + GLBuffers.puts(textCoordArray, x); + if(tComps>1) + GLBuffers.puts(textCoordArray, y); + if(tComps>2) + GLBuffers.puts(textCoordArray, z); + padding(TEXTCOORD, tComps-3); + } + public void glTexCoord2f(float x, float y) { + checkSeal(false); + growBufferIfNecessary(TEXTCOORD, 2); + if(tComps>0) + GLBuffers.putf(textCoordArray, x); + if(tComps>1) + GLBuffers.putf(textCoordArray, y); + padding(TEXTCOORD, tComps-2); + } + public void glTexCoord3f(float x, float y, float z) { + checkSeal(false); + growBufferIfNecessary(TEXTCOORD, 3); + if(tComps>0) + GLBuffers.putf(textCoordArray, x); + if(tComps>1) + GLBuffers.putf(textCoordArray, y); + if(tComps>2) + GLBuffers.putf(textCoordArray, z); + padding(TEXTCOORD, tComps-3); + } + + public void rewind() { + if(null!=vertexArray) { + vertexArray.rewind(); + } + if(null!=colorArray) { + colorArray.rewind(); + } + if(null!=normalArray) { + normalArray.rewind(); + } + if(null!=textCoordArray) { + textCoordArray.rewind(); + } + } + + public void destroy(GL gl) { + reset(gl); + + vertexArray=null; colorArray=null; normalArray=null; textCoordArray=null; + vArrayData=null; cArrayData=null; nArrayData=null; tArrayData=null; + buffer=null; + bSize=0; count=0; + } + + public void reset(GL gl) { + enableBuffer(gl, false); + reset(); + } + + public void reset() { + if(buffer!=null) { + buffer.clear(); + } + rewind(); + + this.mode = -1; + this.modeOrig = -1; + this.sealed=false; + this.bufferEnabled=false; + this.bufferWritten=false; + } + + public void seal(GL glObj, boolean seal) + { + seal(seal); + if(sealedGL==seal) return; + sealedGL = seal; + GL gl = glObj.getGL(); + if(seal) { + if(vboUsage && vboName==0) { + int[] tmp = new int[1]; + gl.glGenBuffers(1, tmp, 0); + vboName = tmp[0]; + } + if(null!=vArrayData) + vArrayData.setVBOName(vboName); + if(null!=cArrayData) + cArrayData.setVBOName(vboName); + if(null!=nArrayData) + nArrayData.setVBOName(vboName); + if(null!=tArrayData) + tArrayData.setVBOName(vboName); + enableBuffer(gl, true); + } else { + enableBuffer(gl, false); + } + } + + public void seal(boolean seal) + { + if(sealed==seal) return; + sealed = seal; + if(seal) { + bufferWritten=false; + } + } + + public void enableBuffer(GL gl, boolean enable) { + /* if(enableBufferAlways && enable) { + bufferEnabled = false; + } */ + if( bufferEnabled != enable && count>0 ) { + if(enable) { + checkSeal(true); + } + if(useGLSL) { + enableBufferGLSL(gl, enable); + } else { + enableBufferFixed(gl, enable); + } + bufferEnabled = enable; + } + } + + public void enableBufferFixed(GL gl, boolean enable) { + GL2ES1 glf = gl.getGL2ES1(); + + if(enable) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName); + + if(!bufferWritten) { + gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit(), buffer, GL.GL_STATIC_DRAW); + bufferWritten=true; + } + + if(vComps>0) { + glf.glEnableClientState(glf.GL_VERTEX_ARRAY); + glf.glVertexPointer(vArrayData); + } + if(cComps>0) { + glf.glEnableClientState(glf.GL_COLOR_ARRAY); + glf.glColorPointer(cArrayData); + } + if(nComps>0) { + glf.glEnableClientState(glf.GL_NORMAL_ARRAY); + glf.glNormalPointer(nArrayData); + } + if(tComps>0) { + glf.glEnableClientState(glf.GL_TEXTURE_COORD_ARRAY); + glf.glTexCoordPointer(tArrayData); + } + + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } else { + if(vComps>0) { + glf.glDisableClientState(glf.GL_VERTEX_ARRAY); + } + if(cComps>0) { + glf.glDisableClientState(glf.GL_COLOR_ARRAY); + } + if(nComps>0) { + glf.glDisableClientState(glf.GL_NORMAL_ARRAY); + } + if(tComps>0) { + glf.glDisableClientState(glf.GL_TEXTURE_COORD_ARRAY); + } + } + } + + public void enableBufferGLSL(GL gl, boolean enable) { + GL2ES2 glsl = gl.getGL2ES2(); + com.jogamp.opengl.util.glsl.ShaderState st = com.jogamp.opengl.util.glsl.ShaderState.getCurrent(); + if(null==st) { + throw new GLException("No ShaderState current"); + } + + if(enable) { + glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName); + + if(!bufferWritten) { + glsl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit(), buffer, GL.GL_STATIC_DRAW); + bufferWritten=true; + } + + if(vComps>0) { + st.glEnableVertexAttribArray(glsl, vArrayData.getName()); + st.glVertexAttribPointer(glsl, vArrayData); + } + if(cComps>0) { + st.glEnableVertexAttribArray(glsl, cArrayData.getName()); + st.glVertexAttribPointer(glsl, cArrayData); + } + if(nComps>0) { + st.glEnableVertexAttribArray(glsl, nArrayData.getName()); + st.glVertexAttribPointer(glsl, nArrayData); + } + if(tComps>0) { + st.glEnableVertexAttribArray(glsl, tArrayData.getName()); + st.glVertexAttribPointer(glsl, tArrayData); + } + + glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } else { + if(vComps>0) { + st.glDisableVertexAttribArray(glsl, vArrayData.getName()); + } + if(cComps>0) { + st.glDisableVertexAttribArray(glsl, cArrayData.getName()); + } + if(nComps>0) { + st.glDisableVertexAttribArray(glsl, nArrayData.getName()); + } + if(tComps>0) { + st.glDisableVertexAttribArray(glsl, tArrayData.getName()); + } + } + } + + public String toString() { + return "VBOSet[mode "+mode+ + ", modeOrig "+modeOrig+ + ", sealed "+sealed+ + ", bufferEnabled "+bufferEnabled+ + ", bufferWritten "+bufferWritten+ + ",\n\t"+vArrayData+ + ",\n\t"+cArrayData+ + ",\n\t"+nArrayData+ + ",\n\t"+tArrayData+ + "]"; + } + + // non public matters + + protected void allocateBuffer(int elements) { + int vWidth = vComps * GLBuffers.sizeOfGLType(vDataType); + int cWidth = cComps * GLBuffers.sizeOfGLType(cDataType); + int nWidth = nComps * GLBuffers.sizeOfGLType(nDataType); + int tWidth = tComps * GLBuffers.sizeOfGLType(tDataType); + + count = elements; + bSize = count * ( vWidth + cWidth + nWidth + tWidth ) ; + + buffer = GLBuffers.newDirectByteBuffer(bSize); + + int pos = 0; + int size= count * vWidth ; + if(size>0) { + vertexArray = GLBuffers.sliceGLBuffer(buffer, pos, size, vDataType); + } else { + vertexArray = null; + } + vOffset = pos; + pos+=size; + + size= count * cWidth ; + if(size>0) { + colorArray = GLBuffers.sliceGLBuffer(buffer, pos, size, cDataType); + } else { + colorArray = null; + } + cOffset = pos; + pos+=size; + + size= count * nWidth ; + if(size>0) { + normalArray = GLBuffers.sliceGLBuffer(buffer, pos, size, nDataType); + } else { + normalArray = null; + } + nOffset = pos; + pos+=size; + + size= count * tWidth ; + if(size>0) { + textCoordArray = GLBuffers.sliceGLBuffer(buffer, pos, size, tDataType); + } else { + textCoordArray = null; + } + tOffset = pos; + pos+=size; + + buffer.position(pos); + buffer.flip(); + + if(vComps>0) { + vArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, vComps, vDataType, false, + 0, vertexArray, 0, vOffset); + } else { + vArrayData = null; + } + if(cComps>0) { + cArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_COLOR_ARRAY, cComps, cDataType, false, + 0, colorArray, 0, cOffset); + } else { + cArrayData = null; + } + if(nComps>0) { + nArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_NORMAL_ARRAY, nComps, nDataType, false, + 0, normalArray, 0, nOffset); + } else { + nArrayData = null; + } + if(tComps>0) { + tArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false, + 0, textCoordArray, 0, tOffset); + } else { + tArrayData = null; + } + + } + + protected final boolean growBufferIfNecessary(int type, int spare) { + if(buffer==null || count < spare) { + growBuffer(type, initialSize); + return true; + } + return false; + } + + protected final void growBuffer(int type, int additional) { + if(sealed || 0==additional) return; + + // save olde values .. + Buffer _vertexArray=vertexArray, _colorArray=colorArray, _normalArray=normalArray, _textCoordArray=textCoordArray; + ByteBuffer _buffer = buffer; + + allocateBuffer(count+additional); + + if(null!=_vertexArray) { + _vertexArray.flip(); + GLBuffers.put(vertexArray, _vertexArray); + } + if(null!=_colorArray) { + _colorArray.flip(); + GLBuffers.put(colorArray, _colorArray); + } + if(null!=_normalArray) { + _normalArray.flip(); + GLBuffers.put(normalArray, _normalArray); + } + if(null!=_textCoordArray) { + _textCoordArray.flip(); + GLBuffers.put(textCoordArray, _textCoordArray); + } + } + + protected void padding(int type, int fill) { + if ( sealed ) return; + + Buffer dest = null; + + switch (type) { + case VERTEX: + dest = vertexArray; + break; + case COLOR: + dest = colorArray; + break; + case NORMAL: + dest = normalArray; + break; + case TEXTCOORD: + dest = textCoordArray; + break; + } + + if ( null==dest ) return; + + while((fill--)>0) { + GLBuffers.putb(dest, (byte)0); + } + } + + protected int mode, modeOrig; + protected int glBufferUsage, initialSize; + + protected ByteBuffer buffer; + protected int bSize, count, vboName; + + public static final int VERTEX = 0; + public static final int COLOR = 1; + public static final int NORMAL = 2; + public static final int TEXTCOORD = 3; + + protected int vOffset, cOffset, nOffset, tOffset; + protected int vComps, cComps, nComps, tComps; + protected int vDataType, cDataType, nDataType, tDataType; + protected Buffer vertexArray, colorArray, normalArray, textCoordArray; + protected GLArrayDataWrapper vArrayData, cArrayData, nArrayData, tArrayData; + + protected boolean sealed, sealedGL, useGLSL; + protected boolean bufferEnabled, bufferWritten; + protected GL gl; + } + +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/Locator.java b/src/jogl/classes/com/jogamp/opengl/util/Locator.java new file mode 100644 index 000000000..8dbd7cd93 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/Locator.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.opengl.util; + +import java.io.*; +import java.net.*; + +/** Utilities for dealing with resources. */ + +public class Locator { + private Locator() {} + + /** + * Locates the resource using 'getResource(String path, ClassLoader cl)', + * with this context ClassLoader and the path as is, + * as well with the context's package name path plus the path. + * + * @see #getResource(String, ClassLoader) + */ + public static URL getResource(Class context, String path) { + ClassLoader contextCL = (null!=context)?context.getClassLoader():null; + URL url = getResource(path, contextCL); + if (url == null && null!=context) { + // Try again by scoping the path within the class's package + String className = context.getName().replace('.', '/'); + int lastSlash = className.lastIndexOf('/'); + if (lastSlash >= 0) { + String tmpPath = className.substring(0, lastSlash + 1) + path; + url = getResource(tmpPath, contextCL); + } + } + return url; + } + + /** + * Locates the resource using the ClassLoader's facility, + * the absolute URL and absolute file. + * + * @see ClassLoader#getResource(String) + * @see ClassLoader#getSystemResource(String) + * @see URL#URL(String) + * @see File#File(String) + */ + public static URL getResource(String path, ClassLoader cl) { + URL url = null; + if (cl != null) { + url = cl.getResource(path); + } else { + url = ClassLoader.getSystemResource(path); + } + if(!urlExists(url)) { + url = null; + try { + url = new URL(path); + } catch (MalformedURLException e) { } + } + if(!urlExists(url)) { + url = null; + try { + File file = new File(path); + if(file.exists()) { + url = file.toURL(); + } + } catch (MalformedURLException e) {} + } + return url; + } + + /** + * Generates a path for the 'relativeFile' relative to the 'absoluteFileLocation' + */ + public static String getRelativeOf(String absoluteFileLocation, String relativeFile) { + File file = new File(absoluteFileLocation); + file = file.getParentFile(); + while (file != null && relativeFile.startsWith("../")) { + file = file.getParentFile(); + relativeFile = relativeFile.substring(3); + } + if (file != null) { + String res = new File(file, relativeFile).getPath(); + // Handle things on Windows + return res.replace('\\', '/'); + } else { + return relativeFile; + } + } + + /** + * Returns true, if the url exists, + * trying to open a connection. + */ + public static boolean urlExists(URL url) { + boolean v = false; + if(null!=url) { + try { + URLConnection uc = url.openConnection(); + v = true; + } catch (IOException ioe) { } + } + return v; + } + +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java new file mode 100644 index 000000000..0e1b7926e --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java @@ -0,0 +1,686 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.opengl.util; + +import com.jogamp.common.nio.Buffers; +import jogamp.opengl.ProjectFloat; + +import java.nio.*; +import java.util.ArrayList; +import java.util.List; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.GLMatrixFunc; + +public class PMVMatrix implements GLMatrixFunc { + + public PMVMatrix() { + projectFloat = new ProjectFloat(); + + matrixIdent = Buffers.newDirectFloatBuffer(1*16); + projectFloat.gluMakeIdentityf(matrixIdent); + matrixIdent.rewind(); + + // T Texture + // P Projection + // Mv ModelView + // Mvi Modelview-Inverse + // Mvit Modelview-Inverse-Transpose + // Pmv P * Mv + matrixTPMvMvitPmv = Buffers.newDirectFloatBuffer(6*16); // grouping T + P + Mv + Mvi + Mvit + Pmv + matrixPMvMvitPmv = slice(matrixTPMvMvitPmv, 1*16, 5*16); // grouping P + Mv + Mvi + Mvit + Pmv + matrixT = slice(matrixTPMvMvitPmv, 0*16, 1*16); // T + matrixPMvMvit = slice(matrixTPMvMvitPmv, 1*16, 4*16); // grouping P + Mv + Mvi + Mvit + matrixPMvMvi = slice(matrixTPMvMvitPmv, 1*16, 3*16); // grouping P + Mv + Mvi + matrixPMv = slice(matrixTPMvMvitPmv, 1*16, 2*16); // grouping P + Mv + matrixP = slice(matrixTPMvMvitPmv, 1*16, 1*16); // P + matrixMv = slice(matrixTPMvMvitPmv, 2*16, 1*16); // Mv + matrixMvi = slice(matrixTPMvMvitPmv, 3*16, 1*16); // Mvi + matrixMvit = slice(matrixTPMvMvitPmv, 4*16, 1*16); // Mvit + matrixPmv = slice(matrixTPMvMvitPmv, 5*16, 1*16); // Pmv + matrixTPMvMvitPmv.rewind(); + + matrixMvit3 = Buffers.newDirectFloatBuffer(3*3); + + localBuf = Buffers.newDirectFloatBuffer(6*16); + + matrixMult=slice(localBuf, 0*16, 16); + + matrixTrans=slice(localBuf, 1*16, 16); + projectFloat.gluMakeIdentityf(matrixTrans); + + matrixRot=slice(localBuf, 2*16, 16); + projectFloat.gluMakeIdentityf(matrixRot); + + matrixScale=slice(localBuf, 3*16, 16); + projectFloat.gluMakeIdentityf(matrixScale); + + matrixOrtho=slice(localBuf, 4*16, 16); + projectFloat.gluMakeIdentityf(matrixOrtho); + + matrixFrustum=slice(localBuf, 5*16, 16); + projectFloat.gluMakeZero(matrixFrustum); + + vec3f=new float[3]; + + matrixPStack = new ArrayList(); + matrixMvStack= new ArrayList(); + + // default values and mode + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glMatrixMode(GL.GL_TEXTURE); + glLoadIdentity(); + setDirty(); + } + + public void destroy() { + if(null!=projectFloat) { + projectFloat.destroy(); projectFloat=null; + } + + if(null!=matrixIdent) { + matrixIdent.clear(); matrixIdent=null; + } + if(null!=matrixTPMvMvitPmv) { + matrixTPMvMvitPmv.clear(); matrixTPMvMvitPmv=null; + } + if(null!=matrixMvit3) { + matrixMvit3.clear(); matrixMvit3=null; + } + if(null!=localBuf) { + localBuf.clear(); localBuf=null; + } + + if(null!=matrixPStack) { + matrixPStack.clear(); matrixPStack=null; + } + vec3f=null; + if(null!=matrixMvStack) { + matrixMvStack.clear(); matrixMvStack=null; + } + if(null!=matrixPStack) { + matrixPStack.clear(); matrixPStack=null; + } + if(null!=matrixTStack) { + matrixTStack.clear(); matrixTStack=null; + } + + matrixTPMvMvitPmv=null; matrixPMvMvit=null; matrixPMvMvitPmv=null; matrixPMvMvi=null; matrixPMv=null; + matrixP=null; matrixT=null; matrixMv=null; matrixMvi=null; matrixMvit=null; matrixPmv=null; + matrixMult=null; matrixTrans=null; matrixRot=null; matrixScale=null; matrixOrtho=null; matrixFrustum=null; + } + + private static FloatBuffer slice(FloatBuffer buf, int pos, int len) { + buf.position(pos); + buf.limit(pos + len); + return buf.slice(); + } + + public static final boolean isMatrixModeName(final int matrixModeName) { + switch(matrixModeName) { + case GL_MODELVIEW_MATRIX: + case GL_PROJECTION_MATRIX: + case GL_TEXTURE_MATRIX: + return true; + } + return false; + } + + public static final int matrixModeName2MatrixGetName(final int matrixModeName) { + switch(matrixModeName) { + case GL_MODELVIEW: + return GL_MODELVIEW_MATRIX; + case GL_PROJECTION: + return GL_PROJECTION_MATRIX; + case GL.GL_TEXTURE: + return GL_TEXTURE_MATRIX; + default: + throw new GLException("unsupported matrixName: "+matrixModeName); + } + } + + public static final boolean isMatrixGetName(final int matrixGetName) { + switch(matrixGetName) { + case GL_MATRIX_MODE: + case GL_MODELVIEW_MATRIX: + case GL_PROJECTION_MATRIX: + case GL_TEXTURE_MATRIX: + return true; + } + return false; + } + + public static final int matrixGetName2MatrixModeName(final int matrixGetName) { + switch(matrixGetName) { + case GL_MODELVIEW_MATRIX: + return GL_MODELVIEW; + case GL_PROJECTION_MATRIX: + return GL_PROJECTION; + case GL_TEXTURE_MATRIX: + return GL.GL_TEXTURE; + default: + throw new GLException("unsupported matrixGetName: "+matrixGetName); + } + } + + public void setDirty() { + modified = DIRTY_MODELVIEW | DIRTY_PROJECTION | DIRTY_TEXTURE ; + matrixMode = GL_MODELVIEW; + } + + public int getDirtyBits() { + return modified; + } + + public boolean isDirty(final int matrixName) { + boolean res; + switch(matrixName) { + case GL_MODELVIEW: + res = (modified&DIRTY_MODELVIEW)!=0 ; + break; + case GL_PROJECTION: + res = (modified&DIRTY_PROJECTION)!=0 ; + break; + case GL.GL_TEXTURE: + res = (modified&DIRTY_TEXTURE)!=0 ; + break; + default: + throw new GLException("unsupported matrixName: "+matrixName); + } + return res; + } + + public boolean isDirty() { + return modified!=0; + } + + public boolean update() { + // if(0==modified) return false; + + // int res = modified; + int res = DIRTY_MODELVIEW | DIRTY_PROJECTION ; + if( (res&DIRTY_MODELVIEW)!=0 ) { + setMviMvit(); + } + if( (res&DIRTY_MODELVIEW)!=0 || (res&DIRTY_PROJECTION)!=0 ) { + glMultMatrixf(matrixP, matrixMv, matrixPmv); + } + modified=0; + return res!=0; + } + + public final int glGetMatrixMode() { + return matrixMode; + } + + public final FloatBuffer glGetTMatrixf() { + return matrixT; + } + + public final FloatBuffer glGetPMatrixf() { + return matrixP; + } + + public final FloatBuffer glGetMvMatrixf() { + return matrixMv; + } + + public final FloatBuffer glGetPMvMvitPmvMatrixf() { + return matrixPMvMvitPmv; + } + + public final FloatBuffer glGetPMvMvitMatrixf() { + return matrixPMvMvit; + } + + public final FloatBuffer glGetPMvMviMatrixf() { + return matrixPMvMvi; + } + + public final FloatBuffer glGetPMvMatrixf() { + return matrixPMv; + } + + public final FloatBuffer glGetMviMatrixf() { + return matrixMvi; + } + + public final FloatBuffer glGetPmvMatrixf() { + return matrixPmv; + } + + public final FloatBuffer glGetNormalMatrixf() { + return matrixMvit3; + } + + /* + * @return the current matrix + */ + public final FloatBuffer glGetMatrixf() { + return glGetMatrixf(matrixMode); + } + + /** + * @param matrixName GL_MODELVIEW, GL_PROJECTION or GL.GL_TEXTURE + * @return the given matrix + */ + public final FloatBuffer glGetMatrixf(final int matrixName) { + if(matrixName==GL_MODELVIEW) { + return matrixMv; + } else if(matrixName==GL_PROJECTION) { + return matrixP; + } else if(matrixName==GL.GL_TEXTURE) { + return matrixT; + } else { + throw new GLException("unsupported matrixName: "+matrixName); + } + } + + public final void gluPerspective(final float fovy, final float aspect, final float zNear, final float zFar) { + float top=(float)Math.tan(fovy*((float)Math.PI)/360.0f)*zNear; + float bottom=-1.0f*top; + float left=aspect*bottom; + float right=aspect*top; + glFrustumf(left, right, bottom, top, zNear, zFar); + } + + public static final void glMultMatrixf(final FloatBuffer a, final FloatBuffer b, FloatBuffer p) { + for (int i = 0; i < 4; i++) { + final float ai0=a.get(i+0*4), ai1=a.get(i+1*4), ai2=a.get(i+2*4), ai3=a.get(i+3*4); + p.put(i+0*4 , ai0 * b.get(0+0*4) + ai1 * b.get(1+0*4) + ai2 * b.get(2+0*4) + ai3 * b.get(3+0*4) ); + p.put(i+1*4 , ai0 * b.get(0+1*4) + ai1 * b.get(1+1*4) + ai2 * b.get(2+1*4) + ai3 * b.get(3+1*4) ); + p.put(i+2*4 , ai0 * b.get(0+2*4) + ai1 * b.get(1+2*4) + ai2 * b.get(2+2*4) + ai3 * b.get(3+2*4) ); + p.put(i+3*4 , ai0 * b.get(0+3*4) + ai1 * b.get(1+3*4) + ai2 * b.get(2+3*4) + ai3 * b.get(3+3*4) ); + } + } + public static final void glMultMatrixf(final FloatBuffer a, final float[] b, int b_off, FloatBuffer p) { + for (int i = 0; i < 4; i++) { + final float ai0=a.get(i+0*4), ai1=a.get(i+1*4), ai2=a.get(i+2*4), ai3=a.get(i+3*4); + p.put(i+0*4 , ai0 * b[b_off+0+0*4] + ai1 * b[b_off+1+0*4] + ai2 * b[b_off+2+0*4] + ai3 * b[b_off+3+0*4] ); + p.put(i+1*4 , ai0 * b[b_off+0+1*4] + ai1 * b[b_off+1+1*4] + ai2 * b[b_off+2+1*4] + ai3 * b[b_off+3+1*4] ); + p.put(i+2*4 , ai0 * b[b_off+0+2*4] + ai1 * b[b_off+1+2*4] + ai2 * b[b_off+2+2*4] + ai3 * b[b_off+3+2*4] ); + p.put(i+3*4 , ai0 * b[b_off+0+3*4] + ai1 * b[b_off+1+3*4] + ai2 * b[b_off+2+3*4] + ai3 * b[b_off+3+3*4] ); + } + } + + // + // MatrixIf + // + + public void glMatrixMode(final int matrixName) { + switch(matrixName) { + case GL_MODELVIEW: + case GL_PROJECTION: + case GL.GL_TEXTURE: + break; + default: + throw new GLException("unsupported matrixName: "+matrixName); + } + matrixMode = matrixName; + } + + public void glGetFloatv(int matrixGetName, FloatBuffer params) { + int pos = params.position(); + if(matrixGetName==GL_MATRIX_MODE) { + params.put((float)matrixMode); + } else { + FloatBuffer matrix = glGetMatrixf(matrixGetName2MatrixModeName(matrixGetName)); + params.put(matrix); + matrix.rewind(); + } + params.position(pos); + } + public void glGetFloatv(int matrixGetName, float[] params, int params_offset) { + if(matrixGetName==GL_MATRIX_MODE) { + params[params_offset]=(float)matrixMode; + } else { + FloatBuffer matrix = glGetMatrixf(matrixGetName2MatrixModeName(matrixGetName)); + matrix.get(params, params_offset, 16); + matrix.rewind(); + } + } + public void glGetIntegerv(int pname, IntBuffer params) { + int pos = params.position(); + if(pname==GL_MATRIX_MODE) { + params.put(matrixMode); + } else { + throw new GLException("unsupported pname: "+pname); + } + params.position(pos); + } + public void glGetIntegerv(int pname, int[] params, int params_offset) { + if(pname==GL_MATRIX_MODE) { + params[params_offset]=matrixMode; + } else { + throw new GLException("unsupported pname: "+pname); + } + } + + public final void glLoadMatrixf(final float[] values, final int offset) { + int len = values.length-offset; + if(matrixMode==GL_MODELVIEW) { + matrixMv.clear(); + matrixMv.put(values, offset, len); + matrixMv.rewind(); + modified |= DIRTY_MODELVIEW ; + } else if(matrixMode==GL_PROJECTION) { + matrixP.clear(); + matrixP.put(values, offset, len); + matrixP.rewind(); + modified |= DIRTY_PROJECTION ; + } else if(matrixMode==GL.GL_TEXTURE) { + matrixT.clear(); + matrixT.put(values, offset, len); + matrixT.rewind(); + modified |= DIRTY_TEXTURE ; + } + } + + public final void glLoadMatrixf(java.nio.FloatBuffer m) { + int spos = m.position(); + if(matrixMode==GL_MODELVIEW) { + matrixMv.clear(); + matrixMv.put(m); + matrixMv.rewind(); + modified |= DIRTY_MODELVIEW ; + } else if(matrixMode==GL_PROJECTION) { + matrixP.clear(); + matrixP.put(m); + matrixP.rewind(); + modified |= DIRTY_PROJECTION ; + } else if(matrixMode==GL.GL_TEXTURE) { + matrixT.clear(); + matrixT.put(m); + matrixT.rewind(); + modified |= DIRTY_TEXTURE ; + } + m.position(spos); + } + + public final void glPopMatrix() { + float[] stackEntry=null; + if(matrixMode==GL_MODELVIEW) { + stackEntry = (float[])matrixMvStack.remove(0); + } else if(matrixMode==GL_PROJECTION) { + stackEntry = (float[])matrixPStack.remove(0); + } else if(matrixMode==GL.GL_TEXTURE) { + stackEntry = (float[])matrixTStack.remove(0); + } + glLoadMatrixf(stackEntry, 0); + } + + public final void glPushMatrix() { + float[] stackEntry = new float[1*16]; + if(matrixMode==GL_MODELVIEW) { + matrixMv.get(stackEntry); + matrixMv.rewind(); + matrixMvStack.add(0, stackEntry); + } else if(matrixMode==GL_PROJECTION) { + matrixP.get(stackEntry); + matrixP.rewind(); + matrixPStack.add(0, stackEntry); + } else if(matrixMode==GL.GL_TEXTURE) { + matrixT.get(stackEntry); + matrixT.rewind(); + matrixTStack.add(0, stackEntry); + } + } + + public final void glLoadIdentity() { + if(matrixMode==GL_MODELVIEW) { + matrixMv.clear(); + matrixMv.put(matrixIdent); + matrixMv.rewind(); + matrixIdent.rewind(); + modified |= DIRTY_MODELVIEW ; + } else if(matrixMode==GL_PROJECTION) { + matrixP.clear(); + matrixP.put(matrixIdent); + matrixP.rewind(); + matrixIdent.rewind(); + modified |= DIRTY_PROJECTION ; + } else if(matrixMode==GL.GL_TEXTURE) { + matrixT.clear(); + matrixT.put(matrixIdent); + matrixT.rewind(); + matrixIdent.rewind(); + modified |= DIRTY_TEXTURE ; + } + } + + public final void glMultMatrixf(final FloatBuffer m) { + if(matrixMode==GL_MODELVIEW) { + glMultMatrixf(matrixMv, m, matrixMult); + matrixMv.clear(); + matrixMv.put(matrixMult); + matrixMv.rewind(); + modified |= DIRTY_MODELVIEW ; + } else if(matrixMode==GL_PROJECTION) { + glMultMatrixf(matrixP, m, matrixMult); + matrixP.clear(); + matrixP.put(matrixMult); + matrixP.rewind(); + modified |= DIRTY_PROJECTION ; + } else if(matrixMode==GL.GL_TEXTURE) { + glMultMatrixf(matrixT, m, matrixMult); + matrixT.clear(); + matrixT.put(matrixMult); + matrixT.rewind(); + modified |= DIRTY_TEXTURE ; + } + matrixMult.rewind(); + } + + public void glMultMatrixf(float[] m, int m_offset) { + if(matrixMode==GL_MODELVIEW) { + glMultMatrixf(matrixMv, m, m_offset, matrixMult); + matrixMv.clear(); + matrixMv.put(matrixMult); + matrixMv.rewind(); + modified |= DIRTY_MODELVIEW ; + } else if(matrixMode==GL_PROJECTION) { + glMultMatrixf(matrixP, m, m_offset, matrixMult); + matrixP.clear(); + matrixP.put(matrixMult); + matrixP.rewind(); + modified |= DIRTY_PROJECTION ; + } else if(matrixMode==GL.GL_TEXTURE) { + glMultMatrixf(matrixT, m, m_offset, matrixMult); + matrixT.clear(); + matrixT.put(matrixMult); + matrixT.rewind(); + modified |= DIRTY_TEXTURE ; + } + matrixMult.rewind(); + } + + public final void glTranslatef(final float x, final float y, final float z) { + // Translation matrix: + // 1 0 0 x + // 0 1 0 y + // 0 0 1 z + // 0 0 0 1 + matrixTrans.put(0+4*3, x); + matrixTrans.put(1+4*3, y); + matrixTrans.put(2+4*3, z); + glMultMatrixf(matrixTrans); + } + + public final void glRotatef(final float angdeg, float x, float y, float z) { + float angrad = angdeg * (float) Math.PI / 180; + float c = (float)Math.cos(angrad); + float ic= 1.0f - c; + float s = (float)Math.sin(angrad); + + vec3f[0]=x; vec3f[1]=y; vec3f[2]=z; + projectFloat.normalize(vec3f); + x = vec3f[0]; y = vec3f[1]; z = vec3f[2]; + + // Rotation matrix: + // xx(1−c)+c xy(1−c)+zs xz(1−c)-ys 0 + // xy(1−c)-zs yy(1−c)+c yz(1−c)+xs 0 + // xz(1−c)+ys yz(1−c)-xs zz(1−c)+c 0 + // 0 0 0 1 + float xy = x*y; + float xz = x*z; + float xs = x*s; + float ys = y*s; + float yz = y*z; + float zs = z*s; + matrixRot.put(0*4+0, x*x*ic+c); + matrixRot.put(0*4+1, xy*ic+zs); + matrixRot.put(0*4+2, xz*ic-ys); + + matrixRot.put(1*4+0, xy*ic-zs); + matrixRot.put(1*4+1, y*y*ic+c); + matrixRot.put(1*4+2, yz*ic+xs); + + matrixRot.put(2*4+0, xz*ic+ys); + matrixRot.put(2*4+1, yz*ic-xs); + matrixRot.put(2*4+2, z*z*ic+c); + + glMultMatrixf(matrixRot); + } + + public final void glScalef(final float x, final float y, final float z) { + // Scale matrix: + // x 0 0 0 + // 0 y 0 0 + // 0 0 z 0 + // 0 0 0 1 + matrixScale.put(0+4*0, x); + matrixScale.put(1+4*1, y); + matrixScale.put(2+4*2, z); + + glMultMatrixf(matrixScale); + } + + public final void glOrthof(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { + // Ortho matrix: + // 2/dx 0 0 tx + // 0 2/dy 0 ty + // 0 0 2/dz tz + // 0 0 0 1 + float dx=right-left; + float dy=top-bottom; + float dz=zFar-zNear; + float tx=-1.0f*(right+left)/dx; + float ty=-1.0f*(top+bottom)/dy; + float tz=-1.0f*(zFar+zNear)/dz; + + matrixOrtho.put(0+4*0, 2.0f/dx); + matrixOrtho.put(1+4*1, 2.0f/dy); + matrixOrtho.put(2+4*2, -2.0f/dz); + matrixOrtho.put(0+4*3, tx); + matrixOrtho.put(1+4*3, ty); + matrixOrtho.put(2+4*3, tz); + + glMultMatrixf(matrixOrtho); + } + + public final void glFrustumf(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { + if(zNear<=0.0f||zFar<0.0f) { + throw new GLException("GL_INVALID_VALUE: zNear and zFar must be positive, and zNear>0"); + } + if(left==right || top==bottom) { + throw new GLException("GL_INVALID_VALUE: top,bottom and left,right must not be equal"); + } + // Frustum matrix: + // 2*zNear/dx 0 A 0 + // 0 2*zNear/dy B 0 + // 0 0 C D + // 0 0 −1 0 + float zNear2 = 2.0f*zNear; + float dx=right-left; + float dy=top-bottom; + float dz=zFar-zNear; + float A=(right+left)/dx; + float B=(top+bottom)/dy; + float C=-1.0f*(zFar+zNear)/dz; + float D=-2.0f*(zFar*zNear)/dz; + + matrixFrustum.put(0+4*0, zNear2/dx); + matrixFrustum.put(1+4*1, zNear2/dy); + matrixFrustum.put(2+4*2, C); + + matrixFrustum.put(0+4*2, A); + matrixFrustum.put(1+4*2, B); + + matrixFrustum.put(2+4*3, D); + matrixFrustum.put(3+4*2, -1.0f); + + glMultMatrixf(matrixFrustum); + } + + // + // private + // + + private final void setMviMvit() { + if(!projectFloat.gluInvertMatrixf(matrixMv, matrixMvi)) { + throw new GLException("Invalid source Mv matrix, can't compute inverse"); + } + + // transpose matrix + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + matrixMvit.put(j+i*4, matrixMvi.get(i+j*4)); + } + } + + // fetch 3x3 + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + matrixMvit3.put(i+j*3, matrixMvit.get(i+j*4)); + } + } + } + + protected FloatBuffer matrixIdent; + protected FloatBuffer matrixTPMvMvitPmv, matrixPMvMvit, matrixPMvMvitPmv, matrixPMvMvi, matrixPMv, matrixP, matrixT, matrixMv, matrixMvi, matrixMvit, matrixPmv; + protected FloatBuffer matrixMvit3; + protected FloatBuffer localBuf, matrixMult, matrixTrans, matrixRot, matrixScale, matrixOrtho, matrixFrustum; + protected float[] vec3f; + protected List/*FloatBuffer*/ matrixTStack, matrixPStack, matrixMvStack; + protected int matrixMode = GL_MODELVIEW; + protected int modified = 0; + protected ProjectFloat projectFloat; + + public static final int DIRTY_MODELVIEW = 1 << 0; + public static final int DIRTY_PROJECTION = 1 << 1; + public static final int DIRTY_TEXTURE = 1 << 2; +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/StreamUtil.java b/src/jogl/classes/com/jogamp/opengl/util/StreamUtil.java new file mode 100644 index 000000000..4cf8cb1f0 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/StreamUtil.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util; + +import java.io.*; +import java.nio.*; + +/** Utilities for dealing with streams. */ + +public class StreamUtil { + private StreamUtil() {} + + public static byte[] readAll2Array(InputStream stream) throws IOException { + BytesRead bytesRead = readAllImpl(stream); + byte[] data = bytesRead.data; + if (bytesRead.payloadLen != data.length) { + data = new byte[bytesRead.payloadLen]; + System.arraycopy(bytesRead.data, 0, data, 0, bytesRead.payloadLen); + } + return data; + } + + public static ByteBuffer readAll2Buffer(InputStream stream) throws IOException { + BytesRead bytesRead = readAllImpl(stream); + return GLBuffers.newDirectByteBuffer(bytesRead.data, 0, bytesRead.payloadLen); + } + + private static BytesRead readAllImpl(InputStream stream) throws IOException { + // FIXME: Shall we do this here ? + if( !(stream instanceof BufferedInputStream) ) { + stream = new BufferedInputStream(stream); + } + int avail = stream.available(); + byte[] data = new byte[avail]; + int numRead = 0; + int pos = 0; + do { + if (pos + avail > data.length) { + byte[] newData = new byte[pos + avail]; + System.arraycopy(data, 0, newData, 0, pos); + data = newData; + } + numRead = stream.read(data, pos, avail); + if (numRead >= 0) { + pos += numRead; + } + avail = stream.available(); + } while (avail > 0 && numRead >= 0); + + return new BytesRead(pos, data); + } + + private static class BytesRead { + BytesRead(int payloadLen, byte[] data) { + this.payloadLen=payloadLen; + this.data=data; + } + int payloadLen; + byte[] data; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/TGAWriter.java b/src/jogl/classes/com/jogamp/opengl/util/TGAWriter.java new file mode 100644 index 000000000..b949f0e39 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/TGAWriter.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.jogamp.opengl.util; + +import java.io.*; +import java.nio.*; +import java.nio.channels.*; + +/** + * Utility class which helps take fast screenshots of OpenGL rendering + * results into Targa-format files. Used by the {@link com.jogamp.opengl.util.awt.Screenshot} + * class; can also be used in conjunction with the {@link com.jogamp.opengl.util.gl2.TileRenderer} class. + */ +public class TGAWriter { + + private static final int TARGA_HEADER_SIZE = 18; + + private FileChannel ch; + private ByteBuffer buf; + + /** Constructor for the TGAWriter. */ + public TGAWriter() { + } + + /** + * Opens the specified Targa file for writing, overwriting any + * existing file, and sets up the header of the file expecting the + * data to be filled in before closing it. + * + * @param file the file to write containing the screenshot + * @param width the width of the current drawable + * @param height the height of the current drawable + * @param alpha whether the alpha channel should be saved. If true, + * requires GL_EXT_abgr extension to be present. + * + * @throws IOException if an I/O error occurred while writing the + * file + */ + public void open(File file, + int width, + int height, + boolean alpha) throws IOException { + RandomAccessFile out = new RandomAccessFile(file, "rw"); + ch = out.getChannel(); + int pixelSize = (alpha ? 32 : 24); + int numChannels = (alpha ? 4 : 3); + + int fileLength = TARGA_HEADER_SIZE + width * height * numChannels; + out.setLength(fileLength); + MappedByteBuffer image = ch.map(FileChannel.MapMode.READ_WRITE, 0, fileLength); + + // write the TARGA header + image.put(0, (byte) 0).put(1, (byte) 0); + image.put(2, (byte) 2); // uncompressed type + image.put(12, (byte) (width & 0xFF)); // width + image.put(13, (byte) (width >> 8)); // width + image.put(14, (byte) (height & 0xFF)); // height + image.put(15, (byte) (height >> 8)); // height + image.put(16, (byte) pixelSize); // pixel size + + // go to image data position + image.position(TARGA_HEADER_SIZE); + // jogl needs a sliced buffer + buf = image.slice(); + } + + /** + * Returns the ByteBuffer corresponding to the data for the image. + * This must be filled in with data in either BGR or BGRA format + * depending on whether an alpha channel was specified during + * open(). + */ + public ByteBuffer getImageData() { + return buf; + } + + public void close() throws IOException { + // close the file channel + ch.close(); + buf = null; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/ImageUtil.java b/src/jogl/classes/com/jogamp/opengl/util/awt/ImageUtil.java new file mode 100644 index 000000000..a3139b16a --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/ImageUtil.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.awt; + +import java.awt.*; +import java.awt.image.*; + +/** Utilities for dealing with images. */ + +public class ImageUtil { + private ImageUtil() {} + + /** Flips the supplied BufferedImage vertically. This is often a + necessary conversion step to display a Java2D image correctly + with OpenGL and vice versa. */ + public static void flipImageVertically(BufferedImage image) { + WritableRaster raster = image.getRaster(); + Object scanline1 = null; + Object scanline2 = null; + + for (int i = 0; i < image.getHeight() / 2; i++) { + scanline1 = raster.getDataElements(0, i, image.getWidth(), 1, scanline1); + scanline2 = raster.getDataElements(0, image.getHeight() - i - 1, image.getWidth(), 1, scanline2); + raster.setDataElements(0, i, image.getWidth(), 1, scanline2); + raster.setDataElements(0, image.getHeight() - i - 1, image.getWidth(), 1, scanline1); + } + } + + /** + * Creates a <code>BufferedImage</code> with a pixel format compatible with the graphics + * environment. The returned image can thus benefit from hardware accelerated operations + * in Java2D API. + * + * @param width The width of the image to be created + * @param height The height of the image to be created + * + * @return A instance of <code>BufferedImage</code> with a type compatible with the graphics card. + */ + public static BufferedImage createCompatibleImage(int width, int height) { + GraphicsConfiguration configuration = + GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration(); + return configuration.createCompatibleImage(width, height); + } + + /** + * Creates a thumbnail from an image. A thumbnail is a scaled down version of the original picture. + * This method will retain the width to height ratio of the original picture and return a new + * instance of <code>BufferedImage</code>. The original picture is not modified. + * + * @param image The original image to sample down + * @param thumbWidth The width of the thumbnail to be created + * + * @throws IllegalArgumentException If thumbWidth is greater than image.getWidth() + * + * @return A thumbnail with the requested width or the original picture if thumbWidth = image.getWidth() + */ + public static BufferedImage createThumbnail(BufferedImage image, int thumbWidth) { + // Thanks to Romain Guy for this utility + if (thumbWidth > image.getWidth()) { + throw new IllegalArgumentException("Thumbnail width must be greater than image width"); + } + + if (thumbWidth == image.getWidth()) { + return image; + } + + float ratio = (float) image.getWidth() / (float) image.getHeight(); + int width = image.getWidth(); + BufferedImage thumb = image; + + do { + width /= 2; + if (width < thumbWidth) { + width = thumbWidth; + } + + BufferedImage temp = createCompatibleImage(width, (int) (width / ratio)); + Graphics2D g2 = temp.createGraphics(); + g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2.drawImage(thumb, 0, 0, temp.getWidth(), temp.getHeight(), null); + g2.dispose(); + thumb = temp; + } while (width != thumbWidth); + + return thumb; + } + +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/Overlay.java b/src/jogl/classes/com/jogamp/opengl/util/awt/Overlay.java new file mode 100644 index 000000000..1275c9391 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/Overlay.java @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.awt; + +import java.awt.Graphics2D; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.texture.*; + +/** Provides a Java 2D overlay on top of an arbitrary GLDrawable, + making it easier to do things like draw text and images on top of + an OpenGL scene while still maintaining reasonably good + efficiency. */ + +public class Overlay { + private GLDrawable drawable; + private TextureRenderer renderer; + private boolean contentsLost; + + /** Creates a new Java 2D overlay on top of the specified + GLDrawable. */ + public Overlay(GLDrawable drawable) { + this.drawable = drawable; + } + + /** Creates a {@link java.awt.Graphics2D Graphics2D} instance for + rendering into the overlay. The returned object should be + disposed of using the normal {@link java.awt.Graphics#dispose() + Graphics.dispose()} method once it is no longer being used. + + @return a new {@link java.awt.Graphics2D Graphics2D} object for + rendering into the backing store of this renderer + */ + public Graphics2D createGraphics() { + // Validate the size of the renderer against the current size of + // the drawable + validateRenderer(); + return renderer.createGraphics(); + } + + /** Indicates whether the Java 2D contents of the overlay were lost + since the last time {@link #createGraphics} was called. This + method should be called immediately after calling {@link + #createGraphics} to see whether the entire contents of the + overlay need to be redrawn or just the region the application is + interested in updating. + + @return whether the contents of the overlay were lost since the + last render + */ + public boolean contentsLost() { + return contentsLost; + } + + /** Marks the given region of the overlay as dirty. This region, and + any previously set dirty regions, will be automatically + synchronized with the underlying Texture during the next {@link + #draw draw} or {@link #drawAll drawAll} operation, at which + point the dirty region will be cleared. It is not necessary for + an OpenGL context to be current when this method is called. + + @param x the x coordinate (in Java 2D coordinates -- relative to + upper left) of the region to update + @param y the y coordinate (in Java 2D coordinates -- relative to + upper left) of the region to update + @param width the width of the region to update + @param height the height of the region to update + + @throws GLException If an OpenGL context is not current when this method is called */ + public void markDirty(int x, int y, int width, int height) { + renderer.markDirty(x, y, width, height); + } + + /** Draws the entire contents of the overlay on top of the OpenGL + drawable. This is a convenience method which encapsulates all + portions of the rendering process; if this method is used, + {@link #beginRendering}, {@link #endRendering}, etc. should not + be used. This method should be called while the OpenGL context + for the drawable is current, and after your OpenGL scene has + been rendered. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void drawAll() throws GLException { + beginRendering(); + draw(0, 0, drawable.getWidth(), drawable.getHeight()); + endRendering(); + } + + /** Begins the OpenGL rendering process for the overlay. This is + separated out so advanced applications can render independent + pieces of the overlay to different portions of the drawable. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void beginRendering() throws GLException { + renderer.beginOrthoRendering(drawable.getWidth(), drawable.getHeight()); + } + + /** Ends the OpenGL rendering process for the overlay. This is + separated out so advanced applications can render independent + pieces of the overlay to different portions of the drawable. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void endRendering() throws GLException { + renderer.endOrthoRendering(); + } + + /** Draws the specified sub-rectangle of the overlay on top of the + OpenGL drawable. {@link #beginRendering} and {@link + #endRendering} must be used in conjunction with this method to + achieve proper rendering results. This method should be called + while the OpenGL context for the drawable is current, and after + your OpenGL scene has been rendered. + + @param x the lower-left x coordinate (relative to the lower left + of the overlay) of the rectangle to draw + @param y the lower-left y coordinate (relative to the lower left + of the overlay) of the rectangle to draw + @param width the width of the rectangle to draw + @param height the height of the rectangle to draw + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void draw(int x, int y, int width, int height) throws GLException { + draw(x, y, x, y, width, height); + } + + /** Draws the specified sub-rectangle of the overlay at the + specified x and y coordinate on top of the OpenGL drawable. + {@link #beginRendering} and {@link #endRendering} must be used + in conjunction with this method to achieve proper rendering + results. This method should be called while the OpenGL context + for the drawable is current, and after your OpenGL scene has + been rendered. + + @param screenx the on-screen x coordinate at which to draw the rectangle + @param screeny the on-screen y coordinate (relative to lower left) at + which to draw the rectangle + @param overlayx the x coordinate of the pixel in the overlay of + the lower left portion of the rectangle to draw + @param overlayy the y coordinate of the pixel in the overlay + (relative to lower left) of the lower left portion of the + rectangle to draw + @param width the width of the rectangle to draw + @param height the height of the rectangle to draw + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void draw(int screenx, int screeny, + int overlayx, int overlayy, + int width, int height) throws GLException { + renderer.drawOrthoRect(screenx, screeny, + overlayx, overlayy, + width, height); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void validateRenderer() { + if (renderer == null) { + renderer = new TextureRenderer(drawable.getWidth(), + drawable.getHeight(), + true); + contentsLost = true; + } else if (renderer.getWidth() != drawable.getWidth() || + renderer.getHeight() != drawable.getHeight()) { + renderer.setSize(drawable.getWidth(), drawable.getHeight()); + contentsLost = true; + } else { + contentsLost = false; + } + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java b/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java new file mode 100644 index 000000000..7019d720f --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java @@ -0,0 +1,432 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.jogamp.opengl.util.awt; + +import java.awt.image.*; +import java.io.*; +import java.nio.*; +import java.nio.channels.*; +import javax.imageio.*; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import javax.media.opengl.glu.gl2.*; + +import com.jogamp.opengl.util.*; + +/** Utilities for taking screenshots of OpenGL applications. */ + +public class Screenshot { + private Screenshot() {} + + /** + * Takes a fast screenshot of the current OpenGL drawable to a Targa + * file. Requires the OpenGL context for the desired drawable to be + * current. Takes the screenshot from the last assigned read buffer, + * or the OpenGL default read buffer if none has been specified by + * the user (GL_FRONT for single-buffered configurations and GL_BACK + * for double-buffered configurations). This is the fastest + * mechanism for taking a screenshot of an application. Contributed + * by Carsten Weisse of Bytonic Software (http://bytonic.de/). <p> + * + * No alpha channel is written with this variant. + * + * @param file the file to write containing the screenshot + * @param width the width of the current drawable + * @param height the height of the current drawable + * + * @throws GLException if an OpenGL context was not current or + * another OpenGL-related error occurred + * @throws IOException if an I/O error occurred while writing the + * file + */ + public static void writeToTargaFile(File file, + int width, + int height) throws GLException, IOException { + writeToTargaFile(file, width, height, false); + } + + /** + * Takes a fast screenshot of the current OpenGL drawable to a Targa + * file. Requires the OpenGL context for the desired drawable to be + * current. Takes the screenshot from the last assigned read buffer, + * or the OpenGL default read buffer if none has been specified by + * the user (GL_FRONT for single-buffered configurations and GL_BACK + * for double-buffered configurations). This is the fastest + * mechanism for taking a screenshot of an application. Contributed + * by Carsten Weisse of Bytonic Software (http://bytonic.de/). + * + * @param file the file to write containing the screenshot + * @param width the width of the current drawable + * @param height the height of the current drawable + * @param alpha whether the alpha channel should be saved. If true, + * requires GL_EXT_abgr extension to be present. + * + * @throws GLException if an OpenGL context was not current or + * another OpenGL-related error occurred + * @throws IOException if an I/O error occurred while writing the + * file + */ + public static void writeToTargaFile(File file, + int width, + int height, + boolean alpha) throws GLException, IOException { + writeToTargaFile(file, 0, 0, width, height, alpha); + } + + /** + * Takes a fast screenshot of the current OpenGL drawable to a Targa + * file. Requires the OpenGL context for the desired drawable to be + * current. Takes the screenshot from the last assigned read buffer, + * or the OpenGL default read buffer if none has been specified by + * the user (GL_FRONT for single-buffered configurations and GL_BACK + * for double-buffered configurations). This is the fastest + * mechanism for taking a screenshot of an application. Contributed + * by Carsten Weisse of Bytonic Software (http://bytonic.de/). + * + * @param file the file to write containing the screenshot + * @param x the starting x coordinate of the screenshot, measured from the lower-left + * @param y the starting y coordinate of the screenshot, measured from the lower-left + * @param width the width of the desired screenshot area + * @param height the height of the desired screenshot area + * @param alpha whether the alpha channel should be saved. If true, + * requires GL_EXT_abgr extension to be present. + * + * @throws GLException if an OpenGL context was not current or + * another OpenGL-related error occurred + * @throws IOException if an I/O error occurred while writing the + * file + */ + public static void writeToTargaFile(File file, + int x, + int y, + int width, + int height, + boolean alpha) throws GLException, IOException { + if (alpha) { + checkExtABGR(); + } + + TGAWriter writer = new TGAWriter(); + writer.open(file, width, height, alpha); + ByteBuffer bgr = writer.getImageData(); + + GL2 gl = GLUgl2.getCurrentGL2(); + + // Set up pixel storage modes + PixelStorageModes psm = new PixelStorageModes(); + psm.save(gl); + + int readbackType = (alpha ? GL2.GL_ABGR_EXT : GL2.GL_BGR); + + // read the BGR values into the image buffer + gl.glReadPixels(x, y, width, height, readbackType, + GL2.GL_UNSIGNED_BYTE, bgr); + + // Restore pixel storage modes + psm.restore(gl); + + // close the file + writer.close(); + } + + /** + * Takes a screenshot of the current OpenGL drawable to a + * BufferedImage. Requires the OpenGL context for the desired + * drawable to be current. Takes the screenshot from the last + * assigned read buffer, or the OpenGL default read buffer if none + * has been specified by the user (GL_FRONT for single-buffered + * configurations and GL_BACK for double-buffered configurations). + * Note that the scanlines of the resulting image are flipped + * vertically in order to correctly match the OpenGL contents, which + * takes time and is therefore not as fast as the Targa screenshot + * function. <P> + * + * No alpha channel is read back with this variant. + * + * @param width the width of the current drawable + * @param height the height of the current drawable + * + * @throws GLException if an OpenGL context was not current or + * another OpenGL-related error occurred + */ + public static BufferedImage readToBufferedImage(int width, + int height) throws GLException { + return readToBufferedImage(width, height, false); + } + + /** + * Takes a screenshot of the current OpenGL drawable to a + * BufferedImage. Requires the OpenGL context for the desired + * drawable to be current. Takes the screenshot from the last + * assigned read buffer, or the OpenGL default read buffer if none + * has been specified by the user (GL_FRONT for single-buffered + * configurations and GL_BACK for double-buffered configurations). + * Note that the scanlines of the resulting image are flipped + * vertically in order to correctly match the OpenGL contents, which + * takes time and is therefore not as fast as the Targa screenshot + * function. + * + * @param width the width of the current drawable + * @param height the height of the current drawable + * @param alpha whether the alpha channel should be read back. If + * true, requires GL_EXT_abgr extension to be present. + * + * @throws GLException if an OpenGL context was not current or + * another OpenGL-related error occurred + */ + public static BufferedImage readToBufferedImage(int width, + int height, + boolean alpha) throws GLException { + return readToBufferedImage(0, 0, width, height, alpha); + } + + /** + * Takes a screenshot of the current OpenGL drawable to a + * BufferedImage. Requires the OpenGL context for the desired + * drawable to be current. Takes the screenshot from the last + * assigned read buffer, or the OpenGL default read buffer if none + * has been specified by the user (GL_FRONT for single-buffered + * configurations and GL_BACK for double-buffered configurations). + * Note that the scanlines of the resulting image are flipped + * vertically in order to correctly match the OpenGL contents, which + * takes time and is therefore not as fast as the Targa screenshot + * function. + * + * @param x the starting x coordinate of the screenshot, measured from the lower-left + * @param y the starting y coordinate of the screenshot, measured from the lower-left + * @param width the width of the desired screenshot area + * @param height the height of the desired screenshot area + * @param alpha whether the alpha channel should be read back. If + * true, requires GL_EXT_abgr extension to be present. + * + * @throws GLException if an OpenGL context was not current or + * another OpenGL-related error occurred + */ + public static BufferedImage readToBufferedImage(int x, + int y, + int width, + int height, + boolean alpha) throws GLException { + int bufImgType = (alpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR); + int readbackType = (alpha ? GL2.GL_ABGR_EXT : GL2.GL_BGR); + + if (alpha) { + checkExtABGR(); + } + + // Allocate necessary storage + BufferedImage image = new BufferedImage(width, height, bufImgType); + + GL2 gl = GLUgl2.getCurrentGL2(); + + // Set up pixel storage modes + PixelStorageModes psm = new PixelStorageModes(); + psm.save(gl); + + // read the BGR values into the image + gl.glReadPixels(x, y, width, height, readbackType, + GL2.GL_UNSIGNED_BYTE, + ByteBuffer.wrap(((DataBufferByte) image.getRaster().getDataBuffer()).getData())); + + // Restore pixel storage modes + psm.restore(gl); + + // Must flip BufferedImage vertically for correct results + ImageUtil.flipImageVertically(image); + return image; + } + + /** + * Takes a screenshot of the current OpenGL drawable to the + * specified file on disk using the ImageIO package. Requires the + * OpenGL context for the desired drawable to be current. Takes the + * screenshot from the last assigned read buffer, or the OpenGL + * default read buffer if none has been specified by the user + * (GL_FRONT for single-buffered configurations and GL_BACK for + * double-buffered configurations). This is not the fastest + * mechanism for taking a screenshot but may be more convenient than + * others for getting images for consumption by other packages. The + * file format is inferred from the suffix of the given file. <P> + * + * No alpha channel is saved with this variant. + * + * @param file the file to write containing the screenshot + * @param width the width of the current drawable + * @param height the height of the current drawable + * + * @throws GLException if an OpenGL context was not current or + * another OpenGL-related error occurred + * + * @throws IOException if an I/O error occurred or if the file could + * not be written to disk due to the requested file format being + * unsupported by ImageIO + */ + public static void writeToFile(File file, + int width, + int height) throws IOException, GLException { + writeToFile(file, width, height, false); + } + + /** + * Takes a screenshot of the current OpenGL drawable to the + * specified file on disk using the ImageIO package. Requires the + * OpenGL context for the desired drawable to be current. Takes the + * screenshot from the last assigned read buffer, or the OpenGL + * default read buffer if none has been specified by the user + * (GL_FRONT for single-buffered configurations and GL_BACK for + * double-buffered configurations). This is not the fastest + * mechanism for taking a screenshot but may be more convenient than + * others for getting images for consumption by other packages. The + * file format is inferred from the suffix of the given file. <P> + * + * Note that some file formats, in particular JPEG, can not handle + * an alpha channel properly. If the "alpha" argument is specified + * as true for such a file format it will be silently ignored. + * + * @param file the file to write containing the screenshot + * @param width the width of the current drawable + * @param height the height of the current drawable + * @param alpha whether an alpha channel should be saved. If true, + * requires GL_EXT_abgr extension to be present. + * + * @throws GLException if an OpenGL context was not current or + * another OpenGL-related error occurred + * + * @throws IOException if an I/O error occurred or if the file could + * not be written to disk due to the requested file format being + * unsupported by ImageIO + */ + public static void writeToFile(File file, + int width, + int height, + boolean alpha) throws IOException, GLException { + writeToFile(file, 0, 0, width, height, alpha); + } + + /** + * Takes a screenshot of the current OpenGL drawable to the + * specified file on disk using the ImageIO package. Requires the + * OpenGL context for the desired drawable to be current. Takes the + * screenshot from the last assigned read buffer, or the OpenGL + * default read buffer if none has been specified by the user + * (GL_FRONT for single-buffered configurations and GL_BACK for + * double-buffered configurations). This is not the fastest + * mechanism for taking a screenshot but may be more convenient than + * others for getting images for consumption by other packages. The + * file format is inferred from the suffix of the given file. <P> + * + * Note that some file formats, in particular JPEG, can not handle + * an alpha channel properly. If the "alpha" argument is specified + * as true for such a file format it will be silently ignored. + * + * @param file the file to write containing the screenshot + * @param x the starting x coordinate of the screenshot, measured from the lower-left + * @param y the starting y coordinate of the screenshot, measured from the lower-left + * @param width the width of the current drawable + * @param height the height of the current drawable + * @param alpha whether an alpha channel should be saved. If true, + * requires GL_EXT_abgr extension to be present. + * + * @throws GLException if an OpenGL context was not current or + * another OpenGL-related error occurred + * + * @throws IOException if an I/O error occurred or if the file could + * not be written to disk due to the requested file format being + * unsupported by ImageIO + */ + public static void writeToFile(File file, + int x, + int y, + int width, + int height, + boolean alpha) throws IOException, GLException { + String fileSuffix = FileUtil.getFileSuffix(file); + if (alpha && (fileSuffix.equals("jpg") || fileSuffix.equals("jpeg"))) { + // JPEGs can't deal properly with alpha channels + alpha = false; + } + + BufferedImage image = readToBufferedImage(x, y, width, height, alpha); + if (!ImageIO.write(image, fileSuffix, file)) { + throw new IOException("Unsupported file format " + fileSuffix); + } + } + + private static int glGetInteger(GL2 gl, int pname, int[] tmp) { + gl.glGetIntegerv(pname, tmp, 0); + return tmp[0]; + } + + private static void checkExtABGR() { + GL2 gl = GLUgl2.getCurrentGL2(); + if (!gl.isExtensionAvailable("GL_EXT_abgr")) { + throw new IllegalArgumentException("Saving alpha channel requires GL_EXT_abgr"); + } + } + + static class PixelStorageModes { + int packAlignment; + int packRowLength; + int packSkipRows; + int packSkipPixels; + int packSwapBytes; + int[] tmp = new int[1]; + + void save(GL2 gl) { + packAlignment = glGetInteger(gl, GL2.GL_PACK_ALIGNMENT, tmp); + packRowLength = glGetInteger(gl, GL2.GL_PACK_ROW_LENGTH, tmp); + packSkipRows = glGetInteger(gl, GL2.GL_PACK_SKIP_ROWS, tmp); + packSkipPixels = glGetInteger(gl, GL2.GL_PACK_SKIP_PIXELS, tmp); + packSwapBytes = glGetInteger(gl, GL2.GL_PACK_SWAP_BYTES, tmp); + + gl.glPixelStorei(GL2.GL_PACK_ALIGNMENT, 1); + gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, 0); + gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, 0); + gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, 0); + gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, 0); + } + + void restore(GL2 gl) { + gl.glPixelStorei(GL2.GL_PACK_ALIGNMENT, packAlignment); + gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, packRowLength); + gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, packSkipRows); + gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, packSkipPixels); + gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, packSwapBytes); + } + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java new file mode 100644 index 000000000..86882176a --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java @@ -0,0 +1,1984 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.opengl.util.awt; + +import com.jogamp.common.nio.Buffers; +import jogamp.opengl.Debug; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.packrect.*; +import com.jogamp.opengl.util.texture.*; + +import java.awt.AlphaComposite; +import java.awt.Color; + +// For debugging purposes +import java.awt.EventQueue; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Point; +import java.awt.RenderingHints; +import java.awt.event.*; +import java.awt.font.*; +import java.awt.geom.*; + +import java.nio.*; + +import java.text.*; + +import java.util.*; + +import java.security.*; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import javax.media.opengl.awt.*; + + +/** Renders bitmapped Java 2D text into an OpenGL window with high + performance, full Unicode support, and a simple API. Performs + appropriate caching of text rendering results in an OpenGL texture + internally to avoid repeated font rasterization. The caching is + completely automatic, does not require any user intervention, and + has no visible controls in the public API. <P> + + Using the {@link TextRenderer TextRenderer} is simple. Add a + "<code>TextRenderer renderer;</code>" field to your {@link + javax.media.opengl.GLEventListener GLEventListener}. In your {@link + javax.media.opengl.GLEventListener#init init} method, add: + + <PRE> + renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36)); + </PRE> + + <P> In the {@link javax.media.opengl.GLEventListener#display display} method of your + {@link javax.media.opengl.GLEventListener GLEventListener}, add: + <PRE> + renderer.beginRendering(drawable.getWidth(), drawable.getHeight()); + // optionally set the color + renderer.setColor(1.0f, 0.2f, 0.2f, 0.8f); + renderer.draw("Text to draw", xPosition, yPosition); + // ... more draw commands, color changes, etc. + renderer.endRendering(); + </PRE> + + Unless you are sharing textures and display lists between OpenGL + contexts, you do not need to call the {@link #dispose dispose} + method of the TextRenderer; the OpenGL resources it uses + internally will be cleaned up automatically when the OpenGL + context is destroyed. <P> + + <b>Note</b> that the TextRenderer may cause the vertex and texture + coordinate array buffer bindings to change, or to be unbound. This + is important to note if you are using Vertex Buffer Objects (VBOs) + in your application. <P> + + Internally, the renderer uses a rectangle packing algorithm to + pack both glyphs and full Strings' rendering results (which are + variable size) onto a larger OpenGL texture. The internal backing + store is maintained using a {@link + com.jogamp.opengl.util.awt.TextureRenderer TextureRenderer}. A least + recently used (LRU) algorithm is used to discard previously + rendered strings; the specific algorithm is undefined, but is + currently implemented by flushing unused Strings' rendering + results every few hundred rendering cycles, where a rendering + cycle is defined as a pair of calls to {@link #beginRendering + beginRendering} / {@link #endRendering endRendering}. + + @author John Burkey + @author Kenneth Russell +*/ +public class TextRenderer { + private static final boolean DEBUG = Debug.isPropertyDefined("jogl.debug.TextRenderer", true, AccessController.getContext()); + + // These are occasionally useful for more in-depth debugging + private static final boolean DISABLE_GLYPH_CACHE = false; + private static final boolean DRAW_BBOXES = false; + + static final int kSize = 256; + + // Every certain number of render cycles, flush the strings which + // haven't been used recently + private static final int CYCLES_PER_FLUSH = 100; + + // The amount of vertical dead space on the backing store before we + // force a compaction + private static final float MAX_VERTICAL_FRAGMENTATION = 0.7f; + static final int kQuadsPerBuffer = 100; + static final int kCoordsPerVertVerts = 3; + static final int kCoordsPerVertTex = 2; + static final int kVertsPerQuad = 4; + static final int kTotalBufferSizeVerts = kQuadsPerBuffer * kVertsPerQuad; + static final int kTotalBufferSizeCoordsVerts = kQuadsPerBuffer * kVertsPerQuad * kCoordsPerVertVerts; + static final int kTotalBufferSizeCoordsTex = kQuadsPerBuffer * kVertsPerQuad * kCoordsPerVertTex; + static final int kTotalBufferSizeBytesVerts = kTotalBufferSizeCoordsVerts * 4; + static final int kTotalBufferSizeBytesTex = kTotalBufferSizeCoordsTex * 4; + static final int kSizeInBytes_OneVertices_VertexData = kCoordsPerVertVerts * 4; + static final int kSizeInBytes_OneVertices_TexData = kCoordsPerVertTex * 4; + private Font font; + private boolean antialiased; + private boolean useFractionalMetrics; + + // Whether we're attempting to use automatic mipmap generation support + private boolean mipmap; + private RectanglePacker packer; + private boolean haveMaxSize; + private RenderDelegate renderDelegate; + private TextureRenderer cachedBackingStore; + private Graphics2D cachedGraphics; + private FontRenderContext cachedFontRenderContext; + private Map /*<String,Rect>*/ stringLocations = new HashMap /*<String,Rect>*/(); + private GlyphProducer mGlyphProducer; + + private int numRenderCycles; + + // Need to keep track of whether we're in a beginRendering() / + // endRendering() cycle so we can re-enter the exact same state if + // we have to reallocate the backing store + private boolean inBeginEndPair; + private boolean isOrthoMode; + private int beginRenderingWidth; + private int beginRenderingHeight; + private boolean beginRenderingDepthTestDisabled; + + // For resetting the color after disposal of the old backing store + private boolean haveCachedColor; + private float cachedR; + private float cachedG; + private float cachedB; + private float cachedA; + private Color cachedColor; + private boolean needToResetColor; + + // For debugging only + private Frame dbgFrame; + + // Debugging purposes only + private boolean debugged; + Pipelined_QuadRenderer mPipelinedQuadRenderer; + + //emzic: added boolean flag + private boolean useVertexArrays = true; + + //emzic: added boolean flag + private boolean isExtensionAvailable_GL_VERSION_1_5; + private boolean checkFor_isExtensionAvailable_GL_VERSION_1_5; + + // Whether GL_LINEAR filtering is enabled for the backing store + private boolean smoothing = true; + + /** Creates a new TextRenderer with the given font, using no + antialiasing or fractional metrics, and the default + RenderDelegate. Equivalent to <code>TextRenderer(font, false, + false)</code>. + + @param font the font to render with + */ + public TextRenderer(Font font) { + this(font, false, false, null, false); + } + + /** Creates a new TextRenderer with the given font, using no + antialiasing or fractional metrics, and the default + RenderDelegate. If <CODE>mipmap</CODE> is true, attempts to use + OpenGL's automatic mipmap generation for better smoothing when + rendering the TextureRenderer's contents at a distance. + Equivalent to <code>TextRenderer(font, false, false)</code>. + + @param font the font to render with + @param mipmap whether to attempt use of automatic mipmap generation + */ + public TextRenderer(Font font, boolean mipmap) { + this(font, false, false, null, mipmap); + } + + /** Creates a new TextRenderer with the given Font, specified font + properties, and default RenderDelegate. The + <code>antialiased</code> and <code>useFractionalMetrics</code> + flags provide control over the same properties at the Java 2D + level. No mipmap support is requested. Equivalent to + <code>TextRenderer(font, antialiased, useFractionalMetrics, + null)</code>. + + @param font the font to render with + @param antialiased whether to use antialiased fonts + @param useFractionalMetrics whether to use fractional font + metrics at the Java 2D level + */ + public TextRenderer(Font font, boolean antialiased, + boolean useFractionalMetrics) { + this(font, antialiased, useFractionalMetrics, null, false); + } + + /** Creates a new TextRenderer with the given Font, specified font + properties, and given RenderDelegate. The + <code>antialiased</code> and <code>useFractionalMetrics</code> + flags provide control over the same properties at the Java 2D + level. The <code>renderDelegate</code> provides more control + over the text rendered. No mipmap support is requested. + + @param font the font to render with + @param antialiased whether to use antialiased fonts + @param useFractionalMetrics whether to use fractional font + metrics at the Java 2D level + @param renderDelegate the render delegate to use to draw the + text's bitmap, or null to use the default one + */ + public TextRenderer(Font font, boolean antialiased, + boolean useFractionalMetrics, RenderDelegate renderDelegate) { + this(font, antialiased, useFractionalMetrics, renderDelegate, false); + } + + /** Creates a new TextRenderer with the given Font, specified font + properties, and given RenderDelegate. The + <code>antialiased</code> and <code>useFractionalMetrics</code> + flags provide control over the same properties at the Java 2D + level. The <code>renderDelegate</code> provides more control + over the text rendered. If <CODE>mipmap</CODE> is true, attempts + to use OpenGL's automatic mipmap generation for better smoothing + when rendering the TextureRenderer's contents at a distance. + + @param font the font to render with + @param antialiased whether to use antialiased fonts + @param useFractionalMetrics whether to use fractional font + metrics at the Java 2D level + @param renderDelegate the render delegate to use to draw the + text's bitmap, or null to use the default one + @param mipmap whether to attempt use of automatic mipmap generation + */ + public TextRenderer(Font font, boolean antialiased, + boolean useFractionalMetrics, RenderDelegate renderDelegate, + boolean mipmap) { + this.font = font; + this.antialiased = antialiased; + this.useFractionalMetrics = useFractionalMetrics; + this.mipmap = mipmap; + + // FIXME: consider adjusting the size based on font size + // (it will already automatically resize if necessary) + packer = new RectanglePacker(new Manager(), kSize, kSize); + + if (renderDelegate == null) { + renderDelegate = new DefaultRenderDelegate(); + } + + this.renderDelegate = renderDelegate; + + mGlyphProducer = new GlyphProducer(font.getNumGlyphs()); + } + + /** Returns the bounding rectangle of the given String, assuming it + was rendered at the origin. See {@link #getBounds(CharSequence) + getBounds(CharSequence)}. */ + public Rectangle2D getBounds(String str) { + return getBounds((CharSequence) str); + } + + /** Returns the bounding rectangle of the given CharSequence, + assuming it was rendered at the origin. The coordinate system of + the returned rectangle is Java 2D's, with increasing Y + coordinates in the downward direction. The relative coordinate + (0, 0) in the returned rectangle corresponds to the baseline of + the leftmost character of the rendered string, in similar + fashion to the results returned by, for example, {@link + java.awt.font.GlyphVector#getVisualBounds}. Most applications + will use only the width and height of the returned Rectangle for + the purposes of centering or justifying the String. It is not + specified which Java 2D bounds ({@link + java.awt.font.GlyphVector#getVisualBounds getVisualBounds}, + {@link java.awt.font.GlyphVector#getPixelBounds getPixelBounds}, + etc.) the returned bounds correspond to, although every effort + is made to ensure an accurate bound. */ + public Rectangle2D getBounds(CharSequence str) { + // FIXME: this should be more optimized and use the glyph cache + Rect r = null; + + if ((r = (Rect) stringLocations.get(str)) != null) { + TextData data = (TextData) r.getUserData(); + + // Reconstitute the Java 2D results based on the cached values + return new Rectangle2D.Double(-data.origin().x, -data.origin().y, + r.w(), r.h()); + } + + // Must return a Rectangle compatible with the layout algorithm -- + // must be idempotent + return normalize(renderDelegate.getBounds(str, font, + getFontRenderContext())); + } + + /** Returns the Font this renderer is using. */ + public Font getFont() { + return font; + } + + /** Returns a FontRenderContext which can be used for external + text-related size computations. This object should be considered + transient and may become invalidated between {@link + #beginRendering beginRendering} / {@link #endRendering + endRendering} pairs. */ + public FontRenderContext getFontRenderContext() { + if (cachedFontRenderContext == null) { + cachedFontRenderContext = getGraphics2D().getFontRenderContext(); + } + + return cachedFontRenderContext; + } + + /** Begins rendering with this {@link TextRenderer TextRenderer} + into the current OpenGL drawable, pushing the projection and + modelview matrices and some state bits and setting up a + two-dimensional orthographic projection with (0, 0) as the + lower-left coordinate and (width, height) as the upper-right + coordinate. Binds and enables the internal OpenGL texture + object, sets the texture environment mode to GL_MODULATE, and + changes the current color to the last color set with this + TextRenderer via {@link #setColor setColor}. This method + disables the depth test and is equivalent to + beginRendering(width, height, true). + + @param width the width of the current on-screen OpenGL drawable + @param height the height of the current on-screen OpenGL drawable + @throws javax.media.opengl.GLException If an OpenGL context is not current when this method is called + */ + public void beginRendering(int width, int height) throws GLException { + beginRendering(width, height, true); + } + + /** Begins rendering with this {@link TextRenderer TextRenderer} + into the current OpenGL drawable, pushing the projection and + modelview matrices and some state bits and setting up a + two-dimensional orthographic projection with (0, 0) as the + lower-left coordinate and (width, height) as the upper-right + coordinate. Binds and enables the internal OpenGL texture + object, sets the texture environment mode to GL_MODULATE, and + changes the current color to the last color set with this + TextRenderer via {@link #setColor setColor}. Disables the depth + test if the disableDepthTest argument is true. + + @param width the width of the current on-screen OpenGL drawable + @param height the height of the current on-screen OpenGL drawable + @param disableDepthTest whether to disable the depth test + @throws GLException If an OpenGL context is not current when this method is called + */ + public void beginRendering(int width, int height, boolean disableDepthTest) + throws GLException { + beginRendering(true, width, height, disableDepthTest); + } + + /** Begins rendering of 2D text in 3D with this {@link TextRenderer + TextRenderer} into the current OpenGL drawable. Assumes the end + user is responsible for setting up the modelview and projection + matrices, and will render text using the {@link #draw3D draw3D} + method. This method pushes some OpenGL state bits, binds and + enables the internal OpenGL texture object, sets the texture + environment mode to GL_MODULATE, and changes the current color + to the last color set with this TextRenderer via {@link + #setColor setColor}. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void begin3DRendering() throws GLException { + beginRendering(false, 0, 0, false); + } + + /** Changes the current color of this TextRenderer to the supplied + one. The default color is opaque white. + + @param color the new color to use for rendering text + @throws GLException If an OpenGL context is not current when this method is called + */ + public void setColor(Color color) throws GLException { + boolean noNeedForFlush = (haveCachedColor && (cachedColor != null) && + color.equals(cachedColor)); + + if (!noNeedForFlush) { + flushGlyphPipeline(); + } + + getBackingStore().setColor(color); + haveCachedColor = true; + cachedColor = color; + } + + /** Changes the current color of this TextRenderer to the supplied + one, where each component ranges from 0.0f - 1.0f. The alpha + component, if used, does not need to be premultiplied into the + color channels as described in the documentation for {@link + com.jogamp.opengl.util.texture.Texture Texture}, although + premultiplied colors are used internally. The default color is + opaque white. + + @param r the red component of the new color + @param g the green component of the new color + @param b the blue component of the new color + @param a the alpha component of the new color, 0.0f = completely + transparent, 1.0f = completely opaque + @throws GLException If an OpenGL context is not current when this method is called + */ + public void setColor(float r, float g, float b, float a) + throws GLException { + boolean noNeedForFlush = (haveCachedColor && (cachedColor == null) && + (r == cachedR) && (g == cachedG) && (b == cachedB) && + (a == cachedA)); + + if (!noNeedForFlush) { + flushGlyphPipeline(); + } + + getBackingStore().setColor(r, g, b, a); + haveCachedColor = true; + cachedR = r; + cachedG = g; + cachedB = b; + cachedA = a; + cachedColor = null; + } + + /** Draws the supplied CharSequence at the desired location using + the renderer's current color. The baseline of the leftmost + character is at position (x, y) specified in OpenGL coordinates, + where the origin is at the lower-left of the drawable and the Y + coordinate increases in the upward direction. + + @param str the string to draw + @param x the x coordinate at which to draw + @param y the y coordinate at which to draw + @throws GLException If an OpenGL context is not current when this method is called + */ + public void draw(CharSequence str, int x, int y) throws GLException { + draw3D(str, x, y, 0, 1); + } + + /** Draws the supplied String at the desired location using the + renderer's current color. See {@link #draw(CharSequence, int, + int) draw(CharSequence, int, int)}. */ + public void draw(String str, int x, int y) throws GLException { + draw3D(str, x, y, 0, 1); + } + + /** Draws the supplied CharSequence at the desired 3D location using + the renderer's current color. The baseline of the leftmost + character is placed at position (x, y, z) in the current + coordinate system. + + @param str the string to draw + @param x the x coordinate at which to draw + @param y the y coordinate at which to draw + @param z the z coordinate at which to draw + @param scaleFactor a uniform scale factor applied to the width and height of the drawn rectangle + @throws GLException If an OpenGL context is not current when this method is called + */ + public void draw3D(CharSequence str, float x, float y, float z, + float scaleFactor) { + internal_draw3D(str, x, y, z, scaleFactor); + } + + /** Draws the supplied String at the desired 3D location using the + renderer's current color. See {@link #draw3D(CharSequence, + float, float, float, float) draw3D(CharSequence, float, float, + float, float)}. */ + public void draw3D(String str, float x, float y, float z, float scaleFactor) { + internal_draw3D(str, x, y, z, scaleFactor); + } + + /** Returns the pixel width of the given character. */ + public float getCharWidth(char inChar) { + return mGlyphProducer.getGlyphPixelWidth(inChar); + } + + /** Causes the TextRenderer to flush any internal caches it may be + maintaining and draw its rendering results to the screen. This + should be called after each call to draw() if you are setting + OpenGL state such as the modelview matrix between calls to + draw(). */ + public void flush() { + flushGlyphPipeline(); + } + + /** Ends a render cycle with this {@link TextRenderer TextRenderer}. + Restores the projection and modelview matrices as well as + several OpenGL state bits. Should be paired with {@link + #beginRendering beginRendering}. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void endRendering() throws GLException { + endRendering(true); + } + + /** Ends a 3D render cycle with this {@link TextRenderer TextRenderer}. + Restores several OpenGL state bits. Should be paired with {@link + #begin3DRendering begin3DRendering}. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void end3DRendering() throws GLException { + endRendering(false); + } + + /** Disposes of all resources this TextRenderer is using. It is not + valid to use the TextRenderer after this method is called. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void dispose() throws GLException { + packer.dispose(); + packer = null; + cachedBackingStore = null; + cachedGraphics = null; + cachedFontRenderContext = null; + + if (dbgFrame != null) { + dbgFrame.dispose(); + } + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private static Rectangle2D preNormalize(Rectangle2D src) { + // Need to round to integer coordinates + // Also give ourselves a little slop around the reported + // bounds of glyphs because it looks like neither the visual + // nor the pixel bounds works perfectly well + int minX = (int) Math.floor(src.getMinX()) - 1; + int minY = (int) Math.floor(src.getMinY()) - 1; + int maxX = (int) Math.ceil(src.getMaxX()) + 1; + int maxY = (int) Math.ceil(src.getMaxY()) + 1; + return new Rectangle2D.Double(minX, minY, maxX - minX, maxY - minY); + } + + + private Rectangle2D normalize(Rectangle2D src) { + // Give ourselves a boundary around each entity on the backing + // store in order to prevent bleeding of nearby Strings due to + // the fact that we use linear filtering + + // NOTE that this boundary is quite heuristic and is related + // to how far away in 3D we may view the text -- + // heuristically, 1.5% of the font's height + int boundary = (int) Math.max(1, 0.015 * font.getSize()); + + return new Rectangle2D.Double((int) Math.floor(src.getMinX() - boundary), + (int) Math.floor(src.getMinY() - boundary), + (int) Math.ceil(src.getWidth() + 2 * boundary), + (int) Math.ceil(src.getHeight()) + 2 * boundary); + } + + private TextureRenderer getBackingStore() { + TextureRenderer renderer = (TextureRenderer) packer.getBackingStore(); + + if (renderer != cachedBackingStore) { + // Backing store changed since last time; discard any cached Graphics2D + if (cachedGraphics != null) { + cachedGraphics.dispose(); + cachedGraphics = null; + cachedFontRenderContext = null; + } + + cachedBackingStore = renderer; + } + + return cachedBackingStore; + } + + private Graphics2D getGraphics2D() { + TextureRenderer renderer = getBackingStore(); + + if (cachedGraphics == null) { + cachedGraphics = renderer.createGraphics(); + + // Set up composite, font and rendering hints + cachedGraphics.setComposite(AlphaComposite.Src); + cachedGraphics.setColor(Color.WHITE); + cachedGraphics.setFont(font); + cachedGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + (antialiased ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON + : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)); + cachedGraphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, + (useFractionalMetrics + ? RenderingHints.VALUE_FRACTIONALMETRICS_ON + : RenderingHints.VALUE_FRACTIONALMETRICS_OFF)); + } + + return cachedGraphics; + } + + private void beginRendering(boolean ortho, int width, int height, + boolean disableDepthTestForOrtho) { + GL2 gl = GLContext.getCurrentGL().getGL2(); + + if (DEBUG && !debugged) { + debug(gl); + } + + inBeginEndPair = true; + isOrthoMode = ortho; + beginRenderingWidth = width; + beginRenderingHeight = height; + beginRenderingDepthTestDisabled = disableDepthTestForOrtho; + + if (ortho) { + getBackingStore().beginOrthoRendering(width, height, + disableDepthTestForOrtho); + } else { + getBackingStore().begin3DRendering(); + } + + // Push client attrib bits used by the pipelined quad renderer + gl.glPushClientAttrib((int) GL2.GL_ALL_CLIENT_ATTRIB_BITS); + + if (!haveMaxSize) { + // Query OpenGL for the maximum texture size and set it in the + // RectanglePacker to keep it from expanding too large + int[] sz = new int[1]; + gl.glGetIntegerv(GL2.GL_MAX_TEXTURE_SIZE, sz, 0); + packer.setMaxSize(sz[0], sz[0]); + haveMaxSize = true; + } + + if (needToResetColor && haveCachedColor) { + if (cachedColor == null) { + getBackingStore().setColor(cachedR, cachedG, cachedB, cachedA); + } else { + getBackingStore().setColor(cachedColor); + } + + needToResetColor = false; + } + + // Disable future attempts to use mipmapping if TextureRenderer + // doesn't support it + if (mipmap && !getBackingStore().isUsingAutoMipmapGeneration()) { + if (DEBUG) { + System.err.println("Disabled mipmapping in TextRenderer"); + } + + mipmap = false; + } + } + + /** + * emzic: here the call to glBindBuffer crashes on certain graphicscard/driver combinations + * this is why the ugly try-catch block has been added, which falls back to the old textrenderer + * + * @param ortho + * @throws GLException + */ + private void endRendering(boolean ortho) throws GLException { + flushGlyphPipeline(); + + inBeginEndPair = false; + + GL2 gl = GLContext.getCurrentGL().getGL2(); + + // Pop client attrib bits used by the pipelined quad renderer + gl.glPopClientAttrib(); + + // The OpenGL spec is unclear about whether this changes the + // buffer bindings, so preemptively zero out the GL_ARRAY_BUFFER + // binding + if (getUseVertexArrays() && is15Available(gl)) { + try { + gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0); + } catch (Exception e) { + isExtensionAvailable_GL_VERSION_1_5 = false; + } + } + + if (ortho) { + getBackingStore().endOrthoRendering(); + } else { + getBackingStore().end3DRendering(); + } + + if (++numRenderCycles >= CYCLES_PER_FLUSH) { + numRenderCycles = 0; + + if (DEBUG) { + System.err.println("Clearing unused entries in endRendering()"); + } + + clearUnusedEntries(); + } + } + + private void clearUnusedEntries() { + final java.util.List deadRects = new ArrayList /*<Rect>*/(); + + // Iterate through the contents of the backing store, removing + // text strings that haven't been used recently + packer.visit(new RectVisitor() { + public void visit(Rect rect) { + TextData data = (TextData) rect.getUserData(); + + if (data.used()) { + data.clearUsed(); + } else { + deadRects.add(rect); + } + } + }); + + for (Iterator iter = deadRects.iterator(); iter.hasNext();) { + Rect r = (Rect) iter.next(); + packer.remove(r); + stringLocations.remove(((TextData) r.getUserData()).string()); + + int unicodeToClearFromCache = ((TextData) r.getUserData()).unicodeID; + + if (unicodeToClearFromCache > 0) { + mGlyphProducer.clearCacheEntry(unicodeToClearFromCache); + } + + // if (DEBUG) { + // Graphics2D g = getGraphics2D(); + // g.setComposite(AlphaComposite.Clear); + // g.fillRect(r.x(), r.y(), r.w(), r.h()); + // g.setComposite(AlphaComposite.Src); + // } + } + + // If we removed dead rectangles this cycle, try to do a compaction + float frag = packer.verticalFragmentationRatio(); + + if (!deadRects.isEmpty() && (frag > MAX_VERTICAL_FRAGMENTATION)) { + if (DEBUG) { + System.err.println( + "Compacting TextRenderer backing store due to vertical fragmentation " + + frag); + } + + packer.compact(); + } + + if (DEBUG) { + getBackingStore().markDirty(0, 0, getBackingStore().getWidth(), + getBackingStore().getHeight()); + } + } + + private void internal_draw3D(CharSequence str, float x, float y, float z, + float scaleFactor) { + List/*<Glyph>*/ glyphs = mGlyphProducer.getGlyphs(str); + for (Iterator iter = glyphs.iterator(); iter.hasNext(); ) { + Glyph glyph = (Glyph) iter.next(); + float advance = glyph.draw3D(x, y, z, scaleFactor); + x += advance * scaleFactor; + } + } + + private void flushGlyphPipeline() { + if (mPipelinedQuadRenderer != null) { + mPipelinedQuadRenderer.draw(); + } + } + + private void draw3D_ROBUST(CharSequence str, float x, float y, float z, + float scaleFactor) { + String curStr; + if (str instanceof String) { + curStr = (String) str; + } else { + curStr = str.toString(); + } + + // Look up the string on the backing store + Rect rect = (Rect) stringLocations.get(curStr); + + if (rect == null) { + // Rasterize this string and place it on the backing store + Graphics2D g = getGraphics2D(); + Rectangle2D origBBox = preNormalize(renderDelegate.getBounds(curStr, font, getFontRenderContext())); + Rectangle2D bbox = normalize(origBBox); + Point origin = new Point((int) -bbox.getMinX(), + (int) -bbox.getMinY()); + rect = new Rect(0, 0, (int) bbox.getWidth(), + (int) bbox.getHeight(), + new TextData(curStr, origin, origBBox, -1)); + + packer.add(rect); + stringLocations.put(curStr, rect); + + // Re-fetch the Graphics2D in case the addition of the rectangle + // caused the old backing store to be thrown away + g = getGraphics2D(); + + // OK, should now have an (x, y) for this rectangle; rasterize + // the String + int strx = rect.x() + origin.x; + int stry = rect.y() + origin.y; + + // Clear out the area we're going to draw into + g.setComposite(AlphaComposite.Clear); + g.fillRect(rect.x(), rect.y(), rect.w(), rect.h()); + g.setComposite(AlphaComposite.Src); + + // Draw the string + renderDelegate.draw(g, curStr, strx, stry); + + if (DRAW_BBOXES) { + TextData data = (TextData) rect.getUserData(); + // Draw a bounding box on the backing store + g.drawRect(strx - data.origOriginX(), + stry - data.origOriginY(), + (int) data.origRect().getWidth(), + (int) data.origRect().getHeight()); + g.drawRect(strx - data.origin().x, + stry - data.origin().y, + rect.w(), + rect.h()); + } + + // Mark this region of the TextureRenderer as dirty + getBackingStore().markDirty(rect.x(), rect.y(), rect.w(), + rect.h()); + } + + // OK, now draw the portion of the backing store to the screen + TextureRenderer renderer = getBackingStore(); + + // NOTE that the rectangles managed by the packer have their + // origin at the upper-left but the TextureRenderer's origin is + // at its lower left!!! + TextData data = (TextData) rect.getUserData(); + data.markUsed(); + + Rectangle2D origRect = data.origRect(); + + // Align the leftmost point of the baseline to the (x, y, z) coordinate requested + renderer.draw3DRect(x - (scaleFactor * data.origOriginX()), + y - (scaleFactor * ((float) origRect.getHeight() - data.origOriginY())), z, + rect.x() + (data.origin().x - data.origOriginX()), + renderer.getHeight() - rect.y() - (int) origRect.getHeight() - + (data.origin().y - data.origOriginY()), + (int) origRect.getWidth(), (int) origRect.getHeight(), scaleFactor); + } + + //---------------------------------------------------------------------- + // Debugging functionality + // + private void debug(GL gl) { + dbgFrame = new Frame("TextRenderer Debug Output"); + + GLCanvas dbgCanvas = new GLCanvas(new GLCapabilities(gl.getGLProfile()), null, + GLContext.getCurrent(), null); + dbgCanvas.addGLEventListener(new DebugListener(gl, dbgFrame)); + dbgFrame.add(dbgCanvas); + + final FPSAnimator anim = new FPSAnimator(dbgCanvas, 10); + dbgFrame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + // Run this on another thread than the AWT event queue to + // make sure the call to Animator.stop() completes before + // exiting + new Thread(new Runnable() { + public void run() { + anim.stop(); + } + }).start(); + } + }); + dbgFrame.setSize(kSize, kSize); + dbgFrame.setVisible(true); + anim.start(); + debugged = true; + } + + /** Class supporting more full control over the process of rendering + the bitmapped text. Allows customization of whether the backing + store text bitmap is full-color or intensity only, the size of + each individual rendered text rectangle, and the contents of + each individual rendered text string. The default implementation + of this interface uses an intensity-only texture, a + closely-cropped rectangle around the text, and renders text + using the color white, which is modulated by the set color + during the rendering process. */ + public static interface RenderDelegate { + /** Indicates whether the backing store of this TextRenderer + should be intensity-only (the default) or full-color. */ + public boolean intensityOnly(); + + /** Computes the bounds of the given String relative to the + origin. */ + public Rectangle2D getBounds(String str, Font font, + FontRenderContext frc); + + /** Computes the bounds of the given character sequence relative + to the origin. */ + public Rectangle2D getBounds(CharSequence str, Font font, + FontRenderContext frc); + + /** Computes the bounds of the given GlyphVector, already + assumed to have been created for a particular Font, + relative to the origin. */ + public Rectangle2D getBounds(GlyphVector gv, FontRenderContext frc); + + /** Render the passed character sequence at the designated + location using the supplied Graphics2D instance. The + surrounding region will already have been cleared to the RGB + color (0, 0, 0) with zero alpha. The initial drawing context + of the passed Graphics2D will be set to use + AlphaComposite.Src, the color white, the Font specified in the + TextRenderer's constructor, and the rendering hints specified + in the TextRenderer constructor. Changes made by the end user + may be visible in successive calls to this method, but are not + guaranteed to be preserved. Implementors of this method + should reset the Graphics2D's state to that desired each time + this method is called, in particular those states which are + not the defaults. */ + public void draw(Graphics2D graphics, String str, int x, int y); + + /** Render the passed GlyphVector at the designated location using + the supplied Graphics2D instance. The surrounding region will + already have been cleared to the RGB color (0, 0, 0) with zero + alpha. The initial drawing context of the passed Graphics2D + will be set to use AlphaComposite.Src, the color white, the + Font specified in the TextRenderer's constructor, and the + rendering hints specified in the TextRenderer constructor. + Changes made by the end user may be visible in successive + calls to this method, but are not guaranteed to be preserved. + Implementors of this method should reset the Graphics2D's + state to that desired each time this method is called, in + particular those states which are not the defaults. */ + public void drawGlyphVector(Graphics2D graphics, GlyphVector str, + int x, int y); + } + + private static class CharSequenceIterator implements CharacterIterator { + CharSequence mSequence; + int mLength; + int mCurrentIndex; + + CharSequenceIterator() { + } + + CharSequenceIterator(CharSequence sequence) { + initFromCharSequence(sequence); + } + + public void initFromCharSequence(CharSequence sequence) { + mSequence = sequence; + mLength = mSequence.length(); + mCurrentIndex = 0; + } + + public char last() { + mCurrentIndex = Math.max(0, mLength - 1); + + return current(); + } + + public char current() { + if ((mLength == 0) || (mCurrentIndex >= mLength)) { + return CharacterIterator.DONE; + } + + return mSequence.charAt(mCurrentIndex); + } + + public char next() { + mCurrentIndex++; + + return current(); + } + + public char previous() { + mCurrentIndex = Math.max(mCurrentIndex - 1, 0); + + return current(); + } + + public char setIndex(int position) { + mCurrentIndex = position; + + return current(); + } + + public int getBeginIndex() { + return 0; + } + + public int getEndIndex() { + return mLength; + } + + public int getIndex() { + return mCurrentIndex; + } + + public Object clone() { + CharSequenceIterator iter = new CharSequenceIterator(mSequence); + iter.mCurrentIndex = mCurrentIndex; + + return iter; + } + + public char first() { + if (mLength == 0) { + return CharacterIterator.DONE; + } + + mCurrentIndex = 0; + + return current(); + } + } + + // Data associated with each rectangle of text + static class TextData { + // Back-pointer to String this TextData describes, if it + // represents a String rather than a single glyph + private String str; + + // If this TextData represents a single glyph, this is its + // unicode ID + int unicodeID; + + // The following must be defined and used VERY precisely. This is + // the offset from the upper-left corner of this rectangle (Java + // 2D coordinate system) at which the string must be rasterized in + // order to fit within the rectangle -- the leftmost point of the + // baseline. + private Point origin; + + // This represents the pre-normalized rectangle, which fits + // within the rectangle on the backing store. We keep a + // one-pixel border around entries on the backing store to + // prevent bleeding of adjacent letters when using GL_LINEAR + // filtering for rendering. The origin of this rectangle is + // equivalent to the origin above. + private Rectangle2D origRect; + + private boolean used; // Whether this text was used recently + + TextData(String str, Point origin, Rectangle2D origRect, int unicodeID) { + this.str = str; + this.origin = origin; + this.origRect = origRect; + this.unicodeID = unicodeID; + } + + String string() { + return str; + } + + Point origin() { + return origin; + } + + // The following three methods are used to locate the glyph + // within the expanded rectangle coming from normalize() + int origOriginX() { + return (int) -origRect.getMinX(); + } + + int origOriginY() { + return (int) -origRect.getMinY(); + } + + Rectangle2D origRect() { + return origRect; + } + + boolean used() { + return used; + } + + void markUsed() { + used = true; + } + + void clearUsed() { + used = false; + } + } + + class Manager implements BackingStoreManager { + private Graphics2D g; + + public Object allocateBackingStore(int w, int h) { + // FIXME: should consider checking Font's attributes to see + // whether we're likely to need to support a full RGBA backing + // store (i.e., non-default Paint, foreground color, etc.), but + // for now, let's just be more efficient + TextureRenderer renderer; + + if (renderDelegate.intensityOnly()) { + renderer = TextureRenderer.createAlphaOnlyRenderer(w, h, mipmap); + } else { + renderer = new TextureRenderer(w, h, true, mipmap); + } + renderer.setSmoothing(smoothing); + + if (DEBUG) { + System.err.println(" TextRenderer allocating backing store " + + w + " x " + h); + } + + return renderer; + } + + public void deleteBackingStore(Object backingStore) { + ((TextureRenderer) backingStore).dispose(); + } + + public boolean preExpand(Rect cause, int attemptNumber) { + // Only try this one time; clear out potentially obsolete entries + // NOTE: this heuristic and the fact that it clears the used bit + // of all entries seems to cause cycling of entries in some + // situations, where the backing store becomes small compared to + // the amount of text on the screen (see the TextFlow demo) and + // the entries continually cycle in and out of the backing + // store, decreasing performance. If we added a little age + // information to the entries, and only cleared out entries + // above a certain age, this behavior would be eliminated. + // However, it seems the system usually stabilizes itself, so + // for now we'll just keep things simple. Note that if we don't + // clear the used bit here, the backing store tends to increase + // very quickly to its maximum size, at least with the TextFlow + // demo when the text is being continually re-laid out. + if (attemptNumber == 0) { + if (DEBUG) { + System.err.println( + "Clearing unused entries in preExpand(): attempt number " + + attemptNumber); + } + + if (inBeginEndPair) { + // Draw any outstanding glyphs + flush(); + } + + clearUnusedEntries(); + + return true; + } + + return false; + } + + public boolean additionFailed(Rect cause, int attemptNumber) { + // Heavy hammer -- might consider doing something different + packer.clear(); + stringLocations.clear(); + mGlyphProducer.clearAllCacheEntries(); + + if (DEBUG) { + System.err.println( + " *** Cleared all text because addition failed ***"); + } + + if (attemptNumber == 0) { + return true; + } + + return false; + } + + public boolean canCompact() { + return true; + } + + public void beginMovement(Object oldBackingStore, Object newBackingStore) { + // Exit the begin / end pair if necessary + if (inBeginEndPair) { + // Draw any outstanding glyphs + flush(); + + GL2 gl = GLContext.getCurrentGL().getGL2(); + + // Pop client attrib bits used by the pipelined quad renderer + gl.glPopClientAttrib(); + + // The OpenGL spec is unclear about whether this changes the + // buffer bindings, so preemptively zero out the GL_ARRAY_BUFFER + // binding + if (getUseVertexArrays() && is15Available(gl)) { + try { + gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0); + } catch (Exception e) { + isExtensionAvailable_GL_VERSION_1_5 = false; + } + } + + if (isOrthoMode) { + ((TextureRenderer) oldBackingStore).endOrthoRendering(); + } else { + ((TextureRenderer) oldBackingStore).end3DRendering(); + } + } + + TextureRenderer newRenderer = (TextureRenderer) newBackingStore; + g = newRenderer.createGraphics(); + } + + public void move(Object oldBackingStore, Rect oldLocation, + Object newBackingStore, Rect newLocation) { + TextureRenderer oldRenderer = (TextureRenderer) oldBackingStore; + TextureRenderer newRenderer = (TextureRenderer) newBackingStore; + + if (oldRenderer == newRenderer) { + // Movement on the same backing store -- easy case + g.copyArea(oldLocation.x(), oldLocation.y(), oldLocation.w(), + oldLocation.h(), newLocation.x() - oldLocation.x(), + newLocation.y() - oldLocation.y()); + } else { + // Need to draw from the old renderer's image into the new one + Image img = oldRenderer.getImage(); + g.drawImage(img, newLocation.x(), newLocation.y(), + newLocation.x() + newLocation.w(), + newLocation.y() + newLocation.h(), oldLocation.x(), + oldLocation.y(), oldLocation.x() + oldLocation.w(), + oldLocation.y() + oldLocation.h(), null); + } + } + + public void endMovement(Object oldBackingStore, Object newBackingStore) { + g.dispose(); + + // Sync the whole surface + TextureRenderer newRenderer = (TextureRenderer) newBackingStore; + newRenderer.markDirty(0, 0, newRenderer.getWidth(), + newRenderer.getHeight()); + + // Re-enter the begin / end pair if necessary + if (inBeginEndPair) { + if (isOrthoMode) { + ((TextureRenderer) newBackingStore).beginOrthoRendering(beginRenderingWidth, + beginRenderingHeight, beginRenderingDepthTestDisabled); + } else { + ((TextureRenderer) newBackingStore).begin3DRendering(); + } + + // Push client attrib bits used by the pipelined quad renderer + GL2 gl = GLContext.getCurrentGL().getGL2(); + gl.glPushClientAttrib((int) GL2.GL_ALL_CLIENT_ATTRIB_BITS); + + if (haveCachedColor) { + if (cachedColor == null) { + ((TextureRenderer) newBackingStore).setColor(cachedR, + cachedG, cachedB, cachedA); + } else { + ((TextureRenderer) newBackingStore).setColor(cachedColor); + } + } + } else { + needToResetColor = true; + } + } + } + + public static class DefaultRenderDelegate implements RenderDelegate { + public boolean intensityOnly() { + return true; + } + + public Rectangle2D getBounds(CharSequence str, Font font, + FontRenderContext frc) { + return getBounds(font.createGlyphVector(frc, + new CharSequenceIterator(str)), + frc); + } + + public Rectangle2D getBounds(String str, Font font, + FontRenderContext frc) { + return getBounds(font.createGlyphVector(frc, str), frc); + } + + public Rectangle2D getBounds(GlyphVector gv, FontRenderContext frc) { + return gv.getVisualBounds(); + } + + public void drawGlyphVector(Graphics2D graphics, GlyphVector str, + int x, int y) { + graphics.drawGlyphVector(str, x, y); + } + + public void draw(Graphics2D graphics, String str, int x, int y) { + graphics.drawString(str, x, y); + } + } + + //---------------------------------------------------------------------- + // Glyph-by-glyph rendering support + // + + // A temporary to prevent excessive garbage creation + private char[] singleUnicode = new char[1]; + + /** A Glyph represents either a single unicode glyph or a + substring of characters to be drawn. The reason for the dual + behavior is so that we can take in a sequence of unicode + characters and partition them into runs of individual glyphs, + but if we encounter complex text and/or unicode sequences we + don't understand, we can render them using the + string-by-string method. <P> + + Glyphs need to be able to re-upload themselves to the backing + store on demand as we go along in the render sequence. + */ + + class Glyph { + // If this Glyph represents an individual unicode glyph, this + // is its unicode ID. If it represents a String, this is -1. + private int unicodeID; + // If the above field isn't -1, then these fields are used. + // The glyph code in the font + private int glyphCode; + // The GlyphProducer which created us + private GlyphProducer producer; + // The advance of this glyph + private float advance; + // The GlyphVector for this single character; this is passed + // in during construction but cleared during the upload + // process + private GlyphVector singleUnicodeGlyphVector; + // The rectangle of this glyph on the backing store, or null + // if it has been cleared due to space pressure + private Rect glyphRectForTextureMapping; + // If this Glyph represents a String, this is the sequence of + // characters + private String str; + // Whether we need a valid advance when rendering this string + // (i.e., whether it has other single glyphs coming after it) + private boolean needAdvance; + + // Creates a Glyph representing an individual Unicode character + public Glyph(int unicodeID, + int glyphCode, + float advance, + GlyphVector singleUnicodeGlyphVector, + GlyphProducer producer) { + this.unicodeID = unicodeID; + this.glyphCode = glyphCode; + this.advance = advance; + this.singleUnicodeGlyphVector = singleUnicodeGlyphVector; + this.producer = producer; + } + + // Creates a Glyph representing a sequence of characters, with + // an indication of whether additional single glyphs are being + // rendered after it + public Glyph(String str, boolean needAdvance) { + this.str = str; + this.needAdvance = needAdvance; + } + + /** Returns this glyph's unicode ID */ + public int getUnicodeID() { + return unicodeID; + } + + /** Returns this glyph's (font-specific) glyph code */ + public int getGlyphCode() { + return glyphCode; + } + + /** Returns the advance for this glyph */ + public float getAdvance() { + return advance; + } + + /** Draws this glyph and returns the (x) advance for this glyph */ + public float draw3D(float inX, float inY, float z, float scaleFactor) { + if (str != null) { + draw3D_ROBUST(str, inX, inY, z, scaleFactor); + if (!needAdvance) { + return 0; + } + // Compute and return the advance for this string + GlyphVector gv = font.createGlyphVector(getFontRenderContext(), str); + float totalAdvance = 0; + for (int i = 0; i < gv.getNumGlyphs(); i++) { + totalAdvance += gv.getGlyphMetrics(i).getAdvance(); + } + return totalAdvance; + } + + // This is the code path taken for individual glyphs + if (glyphRectForTextureMapping == null) { + upload(); + } + + try { + if (mPipelinedQuadRenderer == null) { + mPipelinedQuadRenderer = new Pipelined_QuadRenderer(); + } + + TextureRenderer renderer = getBackingStore(); + // Handles case where NPOT texture is used for backing store + TextureCoords wholeImageTexCoords = renderer.getTexture().getImageTexCoords(); + float xScale = wholeImageTexCoords.right(); + float yScale = wholeImageTexCoords.bottom(); + + Rect rect = glyphRectForTextureMapping; + TextData data = (TextData) rect.getUserData(); + data.markUsed(); + + Rectangle2D origRect = data.origRect(); + + float x = inX - (scaleFactor * data.origOriginX()); + float y = inY - (scaleFactor * ((float) origRect.getHeight() - data.origOriginY())); + + int texturex = rect.x() + (data.origin().x - data.origOriginX()); + int texturey = renderer.getHeight() - rect.y() - (int) origRect.getHeight() - + (data.origin().y - data.origOriginY()); + int width = (int) origRect.getWidth(); + int height = (int) origRect.getHeight(); + + float tx1 = xScale * (float) texturex / (float) renderer.getWidth(); + float ty1 = yScale * (1.0f - + ((float) texturey / (float) renderer.getHeight())); + float tx2 = xScale * (float) (texturex + width) / (float) renderer.getWidth(); + float ty2 = yScale * (1.0f - + ((float) (texturey + height) / (float) renderer.getHeight())); + + mPipelinedQuadRenderer.glTexCoord2f(tx1, ty1); + mPipelinedQuadRenderer.glVertex3f(x, y, z); + mPipelinedQuadRenderer.glTexCoord2f(tx2, ty1); + mPipelinedQuadRenderer.glVertex3f(x + (width * scaleFactor), y, + z); + mPipelinedQuadRenderer.glTexCoord2f(tx2, ty2); + mPipelinedQuadRenderer.glVertex3f(x + (width * scaleFactor), + y + (height * scaleFactor), z); + mPipelinedQuadRenderer.glTexCoord2f(tx1, ty2); + mPipelinedQuadRenderer.glVertex3f(x, + y + (height * scaleFactor), z); + } catch (Exception e) { + e.printStackTrace(); + } + return advance; + } + + /** Notifies this glyph that it's been cleared out of the cache */ + public void clear() { + glyphRectForTextureMapping = null; + } + + private void upload() { + GlyphVector gv = getGlyphVector(); + Rectangle2D origBBox = preNormalize(renderDelegate.getBounds(gv, getFontRenderContext())); + Rectangle2D bbox = normalize(origBBox); + Point origin = new Point((int) -bbox.getMinX(), + (int) -bbox.getMinY()); + Rect rect = new Rect(0, 0, (int) bbox.getWidth(), + (int) bbox.getHeight(), + new TextData(null, origin, origBBox, unicodeID)); + packer.add(rect); + glyphRectForTextureMapping = rect; + Graphics2D g = getGraphics2D(); + // OK, should now have an (x, y) for this rectangle; rasterize + // the glyph + int strx = rect.x() + origin.x; + int stry = rect.y() + origin.y; + + // Clear out the area we're going to draw into + g.setComposite(AlphaComposite.Clear); + g.fillRect(rect.x(), rect.y(), rect.w(), rect.h()); + g.setComposite(AlphaComposite.Src); + + // Draw the string + renderDelegate.drawGlyphVector(g, gv, strx, stry); + + if (DRAW_BBOXES) { + TextData data = (TextData) rect.getUserData(); + // Draw a bounding box on the backing store + g.drawRect(strx - data.origOriginX(), + stry - data.origOriginY(), + (int) data.origRect().getWidth(), + (int) data.origRect().getHeight()); + g.drawRect(strx - data.origin().x, + stry - data.origin().y, + rect.w(), + rect.h()); + } + + // Mark this region of the TextureRenderer as dirty + getBackingStore().markDirty(rect.x(), rect.y(), rect.w(), + rect.h()); + // Re-register ourselves with our producer + producer.register(this); + } + + private GlyphVector getGlyphVector() { + GlyphVector gv = singleUnicodeGlyphVector; + if (gv != null) { + singleUnicodeGlyphVector = null; // Don't need this anymore + return gv; + } + singleUnicode[0] = (char) unicodeID; + return font.createGlyphVector(getFontRenderContext(), singleUnicode); + } + } + + class GlyphProducer { + final int undefined = -2; + FontRenderContext fontRenderContext; + List/*<Glyph>*/ glyphsOutput = new ArrayList/*<Glyph>*/(); + HashMap/*<String, GlyphVector>*/fullGlyphVectorCache = new HashMap/*<String, GlyphVector>*/(); + HashMap/*<Character, GlyphMetrics>*/glyphMetricsCache = new HashMap/*<Character, GlyphMetrics>*/(); + // The mapping from unicode character to font-specific glyph ID + int[] unicodes2Glyphs; + // The mapping from glyph ID to Glyph + Glyph[] glyphCache; + // We re-use this for each incoming string + CharSequenceIterator iter = new CharSequenceIterator(); + + GlyphProducer(int fontLengthInGlyphs) { + unicodes2Glyphs = new int[512]; + glyphCache = new Glyph[fontLengthInGlyphs]; + clearAllCacheEntries(); + } + + public List/*<Glyph>*/ getGlyphs(CharSequence inString) { + glyphsOutput.clear(); + GlyphVector fullRunGlyphVector; + fullRunGlyphVector = (GlyphVector) fullGlyphVectorCache.get(inString.toString()); + if (fullRunGlyphVector == null) { + iter.initFromCharSequence(inString); + fullRunGlyphVector = font.createGlyphVector(getFontRenderContext(), iter); + fullGlyphVectorCache.put(inString.toString(), fullRunGlyphVector); + } + boolean complex = (fullRunGlyphVector.getLayoutFlags() != 0); + if (complex || DISABLE_GLYPH_CACHE) { + // Punt to the robust version of the renderer + glyphsOutput.add(new Glyph(inString.toString(), false)); + return glyphsOutput; + } + + int lengthInGlyphs = fullRunGlyphVector.getNumGlyphs(); + int i = 0; + while (i < lengthInGlyphs) { + Character letter = CharacterCache.valueOf(inString.charAt(i)); + GlyphMetrics metrics = (GlyphMetrics) glyphMetricsCache.get(letter); + if (metrics == null) { + metrics = fullRunGlyphVector.getGlyphMetrics(i); + glyphMetricsCache.put(letter, metrics); + } + Glyph glyph = getGlyph(inString, metrics, i); + if (glyph != null) { + glyphsOutput.add(glyph); + i++; + } else { + // Assemble a run of characters that don't fit in + // the cache + StringBuffer buf = new StringBuffer(); + while (i < lengthInGlyphs && + getGlyph(inString, fullRunGlyphVector.getGlyphMetrics(i), i) == null) { + buf.append(inString.charAt(i++)); + } + glyphsOutput.add(new Glyph(buf.toString(), + // Any more glyphs after this run? + i < lengthInGlyphs)); + } + } + return glyphsOutput; + } + + public void clearCacheEntry(int unicodeID) { + int glyphID = unicodes2Glyphs[unicodeID]; + if (glyphID != undefined) { + Glyph glyph = glyphCache[glyphID]; + if (glyph != null) { + glyph.clear(); + } + glyphCache[glyphID] = null; + } + unicodes2Glyphs[unicodeID] = undefined; + } + + public void clearAllCacheEntries() { + for (int i = 0; i < unicodes2Glyphs.length; i++) { + clearCacheEntry(i); + } + } + + public void register(Glyph glyph) { + unicodes2Glyphs[glyph.getUnicodeID()] = glyph.getGlyphCode(); + glyphCache[glyph.getGlyphCode()] = glyph; + } + + public float getGlyphPixelWidth(char unicodeID) { + Glyph glyph = getGlyph(unicodeID); + if (glyph != null) { + return glyph.getAdvance(); + } + + // Have to do this the hard / uncached way + singleUnicode[0] = unicodeID; + GlyphVector gv = font.createGlyphVector(fontRenderContext, + singleUnicode); + return gv.getGlyphMetrics(0).getAdvance(); + } + + // Returns a glyph object for this single glyph. Returns null + // if the unicode or glyph ID would be out of bounds of the + // glyph cache. + private Glyph getGlyph(CharSequence inString, + GlyphMetrics glyphMetrics, + int index) { + char unicodeID = inString.charAt(index); + + if (unicodeID >= unicodes2Glyphs.length) { + return null; + } + + int glyphID = unicodes2Glyphs[unicodeID]; + if (glyphID != undefined) { + return glyphCache[glyphID]; + } + + // Must fabricate the glyph + singleUnicode[0] = unicodeID; + GlyphVector gv = font.createGlyphVector(getFontRenderContext(), singleUnicode); + return getGlyph(unicodeID, gv, glyphMetrics); + } + + // It's unclear whether this variant might produce less + // optimal results than if we can see the entire GlyphVector + // for the incoming string + private Glyph getGlyph(int unicodeID) { + if (unicodeID >= unicodes2Glyphs.length) { + return null; + } + + int glyphID = unicodes2Glyphs[unicodeID]; + if (glyphID != undefined) { + return glyphCache[glyphID]; + } + singleUnicode[0] = (char) unicodeID; + GlyphVector gv = font.createGlyphVector(getFontRenderContext(), singleUnicode); + return getGlyph(unicodeID, gv, gv.getGlyphMetrics(0)); + } + + private Glyph getGlyph(int unicodeID, + GlyphVector singleUnicodeGlyphVector, + GlyphMetrics metrics) { + int glyphCode = singleUnicodeGlyphVector.getGlyphCode(0); + // Have seen huge glyph codes (65536) coming out of some fonts in some Unicode situations + if (glyphCode >= glyphCache.length) { + return null; + } + Glyph glyph = new Glyph(unicodeID, + glyphCode, + metrics.getAdvance(), + singleUnicodeGlyphVector, + this); + register(glyph); + return glyph; + } + } + + private static class CharacterCache { + private CharacterCache() { + } + + static final Character cache[] = new Character[127 + 1]; + + static { + for (int i = 0; i < cache.length; i++) { + cache[i] = new Character((char) i); + } + } + + public static Character valueOf(char c) { + if (c <= 127) { // must cache + return CharacterCache.cache[c]; + } + return new Character(c); + } + } + + class Pipelined_QuadRenderer { + int mOutstandingGlyphsVerticesPipeline = 0; + FloatBuffer mTexCoords; + FloatBuffer mVertCoords; + boolean usingVBOs; + int mVBO_For_ResuableTileVertices; + int mVBO_For_ResuableTileTexCoords; + + Pipelined_QuadRenderer() { + GL2 gl = GLContext.getCurrentGL().getGL2(); + mVertCoords = Buffers.newDirectFloatBuffer(kTotalBufferSizeCoordsVerts); + mTexCoords = Buffers.newDirectFloatBuffer(kTotalBufferSizeCoordsTex); + + usingVBOs = getUseVertexArrays() && is15Available(gl); + + if (usingVBOs) { + try { + int[] vbos = new int[2]; + gl.glGenBuffers(2, IntBuffer.wrap(vbos)); + + mVBO_For_ResuableTileVertices = vbos[0]; + mVBO_For_ResuableTileTexCoords = vbos[1]; + + gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, + mVBO_For_ResuableTileVertices); + gl.glBufferData(GL2.GL_ARRAY_BUFFER, kTotalBufferSizeBytesVerts, + null, GL2.GL_STREAM_DRAW); // stream draw because this is a single quad use pipeline + + gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, + mVBO_For_ResuableTileTexCoords); + gl.glBufferData(GL2.GL_ARRAY_BUFFER, kTotalBufferSizeBytesTex, + null, GL2.GL_STREAM_DRAW); // stream draw because this is a single quad use pipeline + } catch (Exception e) { + isExtensionAvailable_GL_VERSION_1_5 = false; + usingVBOs = false; + } + } + } + + public void glTexCoord2f(float v, float v1) { + mTexCoords.put(v); + mTexCoords.put(v1); + } + + public void glVertex3f(float inX, float inY, float inZ) { + mVertCoords.put(inX); + mVertCoords.put(inY); + mVertCoords.put(inZ); + + mOutstandingGlyphsVerticesPipeline++; + + if (mOutstandingGlyphsVerticesPipeline >= kTotalBufferSizeVerts) { + this.draw(); + } + } + + private void draw() { + if (useVertexArrays) { + drawVertexArrays(); + } else { + drawIMMEDIATE(); + } + } + + private void drawVertexArrays() { + if (mOutstandingGlyphsVerticesPipeline > 0) { + GL2 gl = GLContext.getCurrentGL().getGL2(); + + TextureRenderer renderer = getBackingStore(); + Texture texture = renderer.getTexture(); // triggers texture uploads. Maybe this should be more obvious? + + mVertCoords.rewind(); + mTexCoords.rewind(); + + gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); + + if (usingVBOs) { + gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, + mVBO_For_ResuableTileVertices); + gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, + mOutstandingGlyphsVerticesPipeline * kSizeInBytes_OneVertices_VertexData, + mVertCoords); // upload only the new stuff + gl.glVertexPointer(3, GL2.GL_FLOAT, 0, 0); + } else { + gl.glVertexPointer(3, GL2.GL_FLOAT, 0, mVertCoords); + } + + gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + + if (usingVBOs) { + gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, + mVBO_For_ResuableTileTexCoords); + gl.glBufferSubData(GL2.GL_ARRAY_BUFFER, 0, + mOutstandingGlyphsVerticesPipeline * kSizeInBytes_OneVertices_TexData, + mTexCoords); // upload only the new stuff + gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, 0); + } else { + gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, mTexCoords); + } + + gl.glDrawArrays(GL2.GL_QUADS, 0, + mOutstandingGlyphsVerticesPipeline); + + mVertCoords.rewind(); + mTexCoords.rewind(); + mOutstandingGlyphsVerticesPipeline = 0; + } + } + + private void drawIMMEDIATE() { + if (mOutstandingGlyphsVerticesPipeline > 0) { + TextureRenderer renderer = getBackingStore(); + Texture texture = renderer.getTexture(); // triggers texture uploads. Maybe this should be more obvious? + + GL2 gl = GLContext.getCurrentGL().getGL2(); + gl.glBegin(GL2.GL_QUADS); + + try { + int numberOfQuads = mOutstandingGlyphsVerticesPipeline / 4; + mVertCoords.rewind(); + mTexCoords.rewind(); + + for (int i = 0; i < numberOfQuads; i++) { + gl.glTexCoord2f(mTexCoords.get(), mTexCoords.get()); + gl.glVertex3f(mVertCoords.get(), mVertCoords.get(), + mVertCoords.get()); + + gl.glTexCoord2f(mTexCoords.get(), mTexCoords.get()); + gl.glVertex3f(mVertCoords.get(), mVertCoords.get(), + mVertCoords.get()); + + gl.glTexCoord2f(mTexCoords.get(), mTexCoords.get()); + gl.glVertex3f(mVertCoords.get(), mVertCoords.get(), + mVertCoords.get()); + + gl.glTexCoord2f(mTexCoords.get(), mTexCoords.get()); + gl.glVertex3f(mVertCoords.get(), mVertCoords.get(), + mVertCoords.get()); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + gl.glEnd(); + mVertCoords.rewind(); + mTexCoords.rewind(); + mOutstandingGlyphsVerticesPipeline = 0; + } + } + } + } + + class DebugListener implements GLEventListener { + private GLU glu; + private Frame frame; + + DebugListener(GL gl, Frame frame) { + this.glu = GLU.createGLU(gl); + this.frame = frame; + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = GLContext.getCurrentGL().getGL2(); + gl.glClear(GL2.GL_DEPTH_BUFFER_BIT | GL2.GL_COLOR_BUFFER_BIT); + + if (packer == null) { + return; + } + + TextureRenderer rend = getBackingStore(); + final int w = rend.getWidth(); + final int h = rend.getHeight(); + rend.beginOrthoRendering(w, h); + rend.drawOrthoRect(0, 0); + rend.endOrthoRendering(); + + if ((frame.getWidth() != w) || (frame.getHeight() != h)) { + EventQueue.invokeLater(new Runnable() { + public void run() { + frame.setSize(w, h); + } + }); + } + } + + public void dispose(GLAutoDrawable drawable) { + glu.destroy(); + glu=null; + frame=null; + } + + // Unused methods + public void init(GLAutoDrawable drawable) { + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, + int height) { + } + + public void displayChanged(GLAutoDrawable drawable, + boolean modeChanged, boolean deviceChanged) { + } + } + + /** + * Sets whether vertex arrays are being used internally for + * rendering, or whether text is rendered using the OpenGL + * immediate mode commands. This is provided as a concession for + * certain graphics cards which have poor vertex array + * performance. Defaults to true. + */ + public void setUseVertexArrays(boolean useVertexArrays) { + this.useVertexArrays = useVertexArrays; + } + + /** + * Indicates whether vertex arrays are being used internally for + * rendering, or whether text is rendered using the OpenGL + * immediate mode commands. Defaults to true. + */ + public final boolean getUseVertexArrays() { + return useVertexArrays; + } + + /** + * Sets whether smoothing (i.e., GL_LINEAR filtering) is enabled + * in the backing TextureRenderer of this TextRenderer. A few + * graphics cards do not behave well when this is enabled, + * resulting in fuzzy text. Defaults to true. + */ + public void setSmoothing(boolean smoothing) { + this.smoothing = smoothing; + getBackingStore().setSmoothing(smoothing); + } + + /** + * Indicates whether smoothing is enabled in the backing + * TextureRenderer of this TextRenderer. A few graphics cards do + * not behave well when this is enabled, resulting in fuzzy text. + * Defaults to true. + */ + public boolean getSmoothing() { + return smoothing; + } + + private final boolean is15Available(GL gl) { + if (!checkFor_isExtensionAvailable_GL_VERSION_1_5) { + isExtensionAvailable_GL_VERSION_1_5 = gl.isExtensionAvailable("GL_VERSION_1_5"); + checkFor_isExtensionAvailable_GL_VERSION_1_5 = true; + } + return isExtensionAvailable_GL_VERSION_1_5; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java new file mode 100644 index 000000000..86dca59f4 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java @@ -0,0 +1,698 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.awt; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.image.*; + +import javax.media.opengl.*; +import javax.media.opengl.glu.gl2.*; +import com.jogamp.opengl.util.texture.*; +import com.jogamp.opengl.util.texture.awt.*; + +/** Provides the ability to render into an OpenGL {@link + com.jogamp.opengl.util.texture.Texture Texture} using the Java 2D + APIs. This renderer class uses an internal Java 2D image (of + unspecified type) for its backing store and flushes portions of + that image to an OpenGL texture on demand. The resulting OpenGL + texture can then be mapped on to a polygon for display. */ + +public class TextureRenderer { + // For now, we supply only a BufferedImage back-end for this + // renderer. In theory we could use the Java 2D/JOGL bridge to fully + // accelerate the rendering paths, but there are restrictions on + // what work can be done where; for example, Graphics2D-related work + // must not be done on the Queue Flusher Thread, but JOGL's + // OpenGL-related work must be. This implies that the user's code + // would need to be split up into multiple callbacks run from the + // appropriate threads, which would be somewhat unfortunate. + + // Whether we have an alpha channel in the (RGB/A) backing store + private boolean alpha; + + // Whether we're using only a GL_INTENSITY backing store + private boolean intensity; + + // Whether we're attempting to use automatic mipmap generation support + private boolean mipmap; + + // Whether smoothing is enabled for the OpenGL texture (switching + // between GL_LINEAR and GL_NEAREST filtering) + private boolean smoothing = true; + private boolean smoothingChanged; + + // The backing store itself + private BufferedImage image; + + private Texture texture; + private AWTTextureData textureData; + private boolean mustReallocateTexture; + private Rectangle dirtyRegion; + + private GLUgl2 glu = new GLUgl2(); + + // Current color + private float r = 1.0f; + private float g = 1.0f; + private float b = 1.0f; + private float a = 1.0f; + + /** Creates a new renderer with backing store of the specified width + and height. If <CODE>alpha</CODE> is true, allocates an alpha + channel in the backing store image. No mipmap support is + requested. + + @param width the width of the texture to render into + @param height the height of the texture to render into + @param alpha whether to allocate an alpha channel for the texture + */ + public TextureRenderer(int width, int height, boolean alpha) { + this(width, height, alpha, false); + } + + /** Creates a new renderer with backing store of the specified width + and height. If <CODE>alpha</CODE> is true, allocates an alpha channel in the + backing store image. If <CODE>mipmap</CODE> is true, attempts to use OpenGL's + automatic mipmap generation for better smoothing when rendering + the TextureRenderer's contents at a distance. + + @param width the width of the texture to render into + @param height the height of the texture to render into + @param alpha whether to allocate an alpha channel for the texture + @param mipmap whether to attempt use of automatic mipmap generation + */ + public TextureRenderer(int width, int height, boolean alpha, boolean mipmap) { + this(width, height, alpha, false, mipmap); + } + + // Internal constructor to avoid confusion since alpha only makes + // sense when intensity is not set + private TextureRenderer(int width, int height, boolean alpha, boolean intensity, boolean mipmap) { + this.alpha = alpha; + this.intensity = intensity; + this.mipmap = mipmap; + init(width, height); + } + + /** Creates a new renderer with a special kind of backing store + which acts only as an alpha channel. No mipmap support is + requested. Internally, this associates a GL_INTENSITY OpenGL + texture with the backing store. */ + public static TextureRenderer createAlphaOnlyRenderer(int width, int height) { + return createAlphaOnlyRenderer(width, height, false); + } + + /** Creates a new renderer with a special kind of backing store + which acts only as an alpha channel. If <CODE>mipmap</CODE> is + true, attempts to use OpenGL's automatic mipmap generation for + better smoothing when rendering the TextureRenderer's contents + at a distance. Internally, this associates a GL_INTENSITY OpenGL + texture with the backing store. */ + public static TextureRenderer createAlphaOnlyRenderer(int width, int height, boolean mipmap) { + return new TextureRenderer(width, height, false, true, mipmap); + } + + /** Returns the width of the backing store of this renderer. + + @return the width of the backing store of this renderer + */ + public int getWidth() { + return image.getWidth(); + } + + /** Returns the height of the backing store of this renderer. + + @return the height of the backing store of this renderer + */ + public int getHeight() { + return image.getHeight(); + } + + /** Returns the size of the backing store of this renderer in a + newly-allocated {@link java.awt.Dimension Dimension} object. + + @return the size of the backing store of this renderer + */ + public Dimension getSize() { + return getSize(null); + } + + /** Returns the size of the backing store of this renderer. Uses the + {@link java.awt.Dimension Dimension} object if one is supplied, + or allocates a new one if null is passed. + + @param d a {@link java.awt.Dimension Dimension} object in which + to store the results, or null to allocate a new one + + @return the size of the backing store of this renderer + */ + public Dimension getSize(Dimension d) { + if (d == null) + d = new Dimension(); + d.setSize(image.getWidth(), image.getHeight()); + return d; + } + + /** Sets the size of the backing store of this renderer. This may + cause the OpenGL texture object associated with this renderer to + be invalidated; it is not recommended to cache this texture + object outside this class but to instead call {@link #getTexture + getTexture} when it is needed. + + @param width the new width of the backing store of this renderer + @param height the new height of the backing store of this renderer + @throws GLException If an OpenGL context is not current when this method is called + */ + public void setSize(int width, int height) throws GLException { + init(width, height); + } + + /** Sets the size of the backing store of this renderer. This may + cause the OpenGL texture object associated with this renderer to + be invalidated. + + @param d the new size of the backing store of this renderer + @throws GLException If an OpenGL context is not current when this method is called + */ + public void setSize(Dimension d) throws GLException { + setSize(d.width, d.height); + } + + /** Sets whether smoothing is enabled for the OpenGL texture; if so, + uses GL_LINEAR interpolation for the minification and + magnification filters. Defaults to true. Changes to this setting + will not take effect until the next call to {@link + #beginOrthoRendering beginOrthoRendering}. + + @param smoothing whether smoothing is enabled for the OpenGL texture + */ + public void setSmoothing(boolean smoothing) { + this.smoothing = smoothing; + smoothingChanged = true; + } + + /** Returns whether smoothing is enabled for the OpenGL texture; see + {@link #setSmoothing setSmoothing}. Defaults to true. + + @return whether smoothing is enabled for the OpenGL texture + */ + public boolean getSmoothing() { + return smoothing; + } + + /** Creates a {@link java.awt.Graphics2D Graphics2D} instance for + rendering to the backing store of this renderer. The returned + object should be disposed of using the normal {@link + java.awt.Graphics#dispose() Graphics.dispose()} method once it + is no longer being used. + + @return a new {@link java.awt.Graphics2D Graphics2D} object for + rendering into the backing store of this renderer + */ + public Graphics2D createGraphics() { + return image.createGraphics(); + } + + /** Returns the underlying Java 2D {@link java.awt.Image Image} + being rendered into. */ + public Image getImage() { + return image; + } + + /** Marks the given region of the TextureRenderer as dirty. This + region, and any previously set dirty regions, will be + automatically synchronized with the underlying Texture during + the next {@link #getTexture getTexture} operation, at which + point the dirty region will be cleared. It is not necessary for + an OpenGL context to be current when this method is called. + + @param x the x coordinate (in Java 2D coordinates -- relative to + upper left) of the region to update + @param y the y coordinate (in Java 2D coordinates -- relative to + upper left) of the region to update + @param width the width of the region to update + @param height the height of the region to update + */ + public void markDirty(int x, int y, int width, int height) { + Rectangle curRegion = new Rectangle(x, y, width, height); + if (dirtyRegion == null) { + dirtyRegion = curRegion; + } else { + dirtyRegion.add(curRegion); + } + } + + /** Returns the underlying OpenGL Texture object associated with + this renderer, synchronizing any dirty regions of the + TextureRenderer with the underlying OpenGL texture. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public Texture getTexture() throws GLException { + if (dirtyRegion != null) { + sync(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height); + dirtyRegion = null; + } + + ensureTexture(); + return texture; + } + + /** Disposes all resources associated with this renderer. It is not + valid to use this renderer after calling this method. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void dispose() throws GLException { + if (texture != null) { + texture.dispose(); + texture = null; + } + if (image != null) { + image.flush(); + image = null; + } + } + + /** Convenience method which assists in rendering portions of the + OpenGL texture to the screen, if the application intends to draw + them as a flat overlay on to the screen. Pushes OpenGL state + bits (GL_ENABLE_BIT, GL_DEPTH_BUFFER_BIT and GL_TRANSFORM_BIT); + disables the depth test, back-face culling, and lighting; + enables the texture in this renderer; and sets up the viewing + matrices for orthographic rendering where the coordinates go + from (0, 0) at the lower left to (width, height) at the upper + right. Equivalent to beginOrthoRendering(width, height, true). + {@link #endOrthoRendering} must be used in conjunction with this + method to restore all OpenGL states. + + @param width the width of the current on-screen OpenGL drawable + @param height the height of the current on-screen OpenGL drawable + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void beginOrthoRendering(int width, int height) throws GLException { + beginOrthoRendering(width, height, true); + } + + /** Convenience method which assists in rendering portions of the + OpenGL texture to the screen, if the application intends to draw + them as a flat overlay on to the screen. Pushes OpenGL state + bits (GL_ENABLE_BIT, GL_DEPTH_BUFFER_BIT and GL_TRANSFORM_BIT); + disables the depth test (if the "disableDepthTest" argument is + true), back-face culling, and lighting; enables the texture in + this renderer; and sets up the viewing matrices for orthographic + rendering where the coordinates go from (0, 0) at the lower left + to (width, height) at the upper right. {@link + #endOrthoRendering} must be used in conjunction with this method + to restore all OpenGL states. + + @param width the width of the current on-screen OpenGL drawable + @param height the height of the current on-screen OpenGL drawable + @param disableDepthTest whether the depth test should be disabled + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void beginOrthoRendering(int width, int height, boolean disableDepthTest) throws GLException { + beginRendering(true, width, height, disableDepthTest); + } + + /** Convenience method which assists in rendering portions of the + OpenGL texture to the screen as 2D quads in 3D space. Pushes + OpenGL state (GL_ENABLE_BIT); disables lighting; and enables the + texture in this renderer. Unlike {@link #beginOrthoRendering + beginOrthoRendering}, does not modify the depth test, back-face + culling, lighting, or the modelview or projection matrices. The + user is responsible for setting up the view matrices for correct + results of {@link #draw3DRect draw3DRect}. {@link + #end3DRendering} must be used in conjunction with this method to + restore all OpenGL states. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void begin3DRendering() throws GLException { + beginRendering(false, 0, 0, false); + } + + /** Changes the color of the polygons, and therefore the drawn + images, this TextureRenderer produces. Use of this method is + optional. The TextureRenderer uses the GL_MODULATE texture + environment mode, which causes the portions of the rendered + texture to be multiplied by the color of the rendered + polygons. The polygon color can be varied to achieve effects + like tinting of the overall output or fading in and out by + changing the alpha of the color. <P> + + Each component ranges from 0.0f - 1.0f. The alpha component, if + used, does not need to be premultiplied into the color channels + as described in the documentation for {@link + com.jogamp.opengl.util.texture.Texture Texture}, although + premultiplied colors are used internally. The default color is + opaque white. + + @param r the red component of the new color + @param g the green component of the new color + @param b the blue component of the new color + @param a the alpha component of the new color, 0.0f = completely + transparent, 1.0f = completely opaque + @throws GLException If an OpenGL context is not current when this method is called + */ + public void setColor(float r, float g, float b, float a) throws GLException { + GL2 gl = GLContext.getCurrentGL().getGL2(); + this.r = r * a; + this.g = g * a; + this.b = b * a; + this.a = a; + + gl.glColor4f(this.r, this.g, this.b, this.a); + } + + private float[] compArray; + /** Changes the current color of this TextureRenderer to the + supplied one. The default color is opaque white. See {@link + #setColor(float,float,float,float) setColor} for more details. + + @param color the new color to use for rendering + @throws GLException If an OpenGL context is not current when this method is called + */ + public void setColor(Color color) throws GLException { + // Get color's RGBA components as floats in the range [0,1]. + if (compArray == null) { + compArray = new float[4]; + } + color.getRGBComponents(compArray); + setColor(compArray[0], compArray[1], compArray[2], compArray[3]); + } + + /** Draws an orthographically projected rectangle containing all of + the underlying texture to the specified location on the + screen. All (x, y) coordinates are specified relative to the + lower left corner of either the texture image or the current + OpenGL drawable. This method is equivalent to + <code>drawOrthoRect(screenx, screeny, 0, 0, getWidth(), + getHeight());</code>. + + @param screenx the on-screen x coordinate at which to draw the rectangle + @param screeny the on-screen y coordinate (relative to lower left) at + which to draw the rectangle + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void drawOrthoRect(int screenx, int screeny) throws GLException { + drawOrthoRect(screenx, screeny, 0, 0, getWidth(), getHeight()); + } + + /** Draws an orthographically projected rectangle of the underlying + texture to the specified location on the screen. All (x, y) + coordinates are specified relative to the lower left corner of + either the texture image or the current OpenGL drawable. + + @param screenx the on-screen x coordinate at which to draw the rectangle + @param screeny the on-screen y coordinate (relative to lower left) at + which to draw the rectangle + @param texturex the x coordinate of the pixel in the texture of + the lower left portion of the rectangle to draw + @param texturey the y coordinate of the pixel in the texture + (relative to lower left) of the lower left portion of the + rectangle to draw + @param width the width of the rectangle to draw + @param height the height of the rectangle to draw + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void drawOrthoRect(int screenx, int screeny, + int texturex, int texturey, + int width, int height) throws GLException { + draw3DRect(screenx, screeny, 0, texturex, texturey, width, height, 1); + } + + /** Draws a rectangle of the underlying texture to the specified 3D + location. In the current coordinate system, the lower left + corner of the rectangle is placed at (x, y, z), and the upper + right corner is placed at (x + width * scaleFactor, y + height * + scaleFactor, z). The lower left corner of the sub-rectangle of + the texture is (texturex, texturey) and the upper right corner + is (texturex + width, texturey + height). For back-face culling + purposes, the rectangle is drawn with counterclockwise + orientation of the vertices when viewed from the front. + + @param x the x coordinate at which to draw the rectangle + @param y the y coordinate at which to draw the rectangle + @param z the z coordinate at which to draw the rectangle + @param texturex the x coordinate of the pixel in the texture of + the lower left portion of the rectangle to draw + @param texturey the y coordinate of the pixel in the texture + (relative to lower left) of the lower left portion of the + rectangle to draw + @param width the width in texels of the rectangle to draw + @param height the height in texels of the rectangle to draw + @param scaleFactor the scale factor to apply (multiplicatively) + to the size of the drawn rectangle + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void draw3DRect(float x, float y, float z, + int texturex, int texturey, + int width, int height, + float scaleFactor) throws GLException { + GL2 gl = GLContext.getCurrentGL().getGL2(); + Texture texture = getTexture(); + TextureCoords coords = texture.getSubImageTexCoords(texturex, texturey, + texturex + width, + texturey + height); + gl.glBegin(GL2.GL_QUADS); + gl.glTexCoord2f(coords.left(), coords.bottom()); + gl.glVertex3f(x, y, z); + gl.glTexCoord2f(coords.right(), coords.bottom()); + gl.glVertex3f(x + width * scaleFactor, y, z); + gl.glTexCoord2f(coords.right(), coords.top()); + gl.glVertex3f(x + width * scaleFactor, y + height * scaleFactor, z); + gl.glTexCoord2f(coords.left(), coords.top()); + gl.glVertex3f(x, y + height * scaleFactor, z); + gl.glEnd(); + } + + /** Convenience method which assists in rendering portions of the + OpenGL texture to the screen, if the application intends to draw + them as a flat overlay on to the screen. Must be used if {@link + #beginOrthoRendering} is used to set up the rendering stage for + this overlay. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void endOrthoRendering() throws GLException { + endRendering(true); + } + + /** Convenience method which assists in rendering portions of the + OpenGL texture to the screen as 2D quads in 3D space. Must be + used if {@link #begin3DRendering} is used to set up the + rendering stage for this overlay. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void end3DRendering() throws GLException { + endRendering(false); + } + + /** Indicates whether automatic mipmap generation is in use for this + TextureRenderer. The result of this method may change from true + to false if it is discovered during allocation of the + TextureRenderer's backing store that automatic mipmap generation + is not supported at the OpenGL level. */ + public boolean isUsingAutoMipmapGeneration() { + return mipmap; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void beginRendering(boolean ortho, int width, int height, boolean disableDepthTestForOrtho) { + GL2 gl = GLContext.getCurrentGL().getGL2(); + int attribBits = + GL2.GL_ENABLE_BIT | GL2.GL_TEXTURE_BIT | GL2.GL_COLOR_BUFFER_BIT | + (ortho ? (GL2.GL_DEPTH_BUFFER_BIT | GL2.GL_TRANSFORM_BIT) : 0); + gl.glPushAttrib(attribBits); + gl.glDisable(GL2.GL_LIGHTING); + if (ortho) { + if (disableDepthTestForOrtho) { + gl.glDisable(GL2.GL_DEPTH_TEST); + } + gl.glDisable(GL2.GL_CULL_FACE); + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glPushMatrix(); + gl.glLoadIdentity(); + glu.gluOrtho2D(0, width, 0, height); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glPushMatrix(); + gl.glLoadIdentity(); + gl.glMatrixMode(GL2.GL_TEXTURE); + gl.glPushMatrix(); + gl.glLoadIdentity(); + } + gl.glEnable(GL2.GL_BLEND); + gl.glBlendFunc(GL2.GL_ONE, GL2.GL_ONE_MINUS_SRC_ALPHA); + Texture texture = getTexture(); + texture.enable(); + texture.bind(); + gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE); + // Change polygon color to last saved + gl.glColor4f(r, g, b, a); + if (smoothingChanged) { + smoothingChanged = false; + if (smoothing) { + texture.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); + if (mipmap) { + texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR); + } else { + texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR); + } + } else { + texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); + texture.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); + } + } + } + + private void endRendering(boolean ortho) { + GL2 gl = GLContext.getCurrentGL().getGL2(); + Texture texture = getTexture(); + texture.disable(); + if (ortho) { + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glPopMatrix(); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glPopMatrix(); + gl.glMatrixMode(GL2.GL_TEXTURE); + gl.glPopMatrix(); + } + gl.glPopAttrib(); + } + + private void init(int width, int height) { + GL2 gl = GLContext.getCurrentGL().getGL2(); + // Discard previous BufferedImage if any + if (image != null) { + image.flush(); + image = null; + } + + // Infer the internal format if not an intensity texture + int internalFormat = (intensity ? GL2.GL_INTENSITY : 0); + int imageType = + (intensity ? BufferedImage.TYPE_BYTE_GRAY : + (alpha ? BufferedImage.TYPE_INT_ARGB_PRE : BufferedImage.TYPE_INT_RGB)); + image = new BufferedImage(width, height, imageType); + // Always realllocate the TextureData associated with this + // BufferedImage; it's just a reference to the contents but we + // need it in order to update sub-regions of the underlying + // texture + textureData = new AWTTextureData(gl.getGLProfile(), internalFormat, 0, mipmap, image); + // For now, always reallocate the underlying OpenGL texture when + // the backing store size changes + mustReallocateTexture = true; + } + + /** Synchronizes the specified region of the backing store down to + the underlying OpenGL texture. If {@link #markDirty markDirty} + is used instead to indicate the regions that are out of sync, + this method does not need to be called. + + @param x the x coordinate (in Java 2D coordinates -- relative to + upper left) of the region to update + @param y the y coordinate (in Java 2D coordinates -- relative to + upper left) of the region to update + @param width the width of the region to update + @param height the height of the region to update + + @throws GLException If an OpenGL context is not current when this method is called + */ + private void sync(int x, int y, int width, int height) throws GLException { + // Force allocation if necessary + boolean canSkipUpdate = ensureTexture(); + + if (!canSkipUpdate) { + // Update specified region. + // NOTE that because BufferedImage-based TextureDatas now don't + // do anything to their contents, the coordinate systems for + // OpenGL and Java 2D actually line up correctly for + // updateSubImage calls, so we don't need to do any argument + // conversion here (i.e., flipping the Y coordinate). + texture.updateSubImage(textureData, 0, x, y, x, y, width, height); + } + } + + // Returns true if the texture was newly allocated, false if not + private boolean ensureTexture() { + if (mustReallocateTexture) { + if (texture != null) { + texture.dispose(); + texture = null; + } + mustReallocateTexture = false; + } + + if (texture == null) { + texture = TextureIO.newTexture(textureData); + if (mipmap && !texture.isUsingAutoMipmapGeneration()) { + // Only try this once + texture.dispose(); + mipmap = false; + textureData.setMipmap(false); + texture = TextureIO.newTexture(textureData); + } + + if (!smoothing) { + // The TextureIO classes default to GL_LINEAR filtering + texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); + texture.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); + } + return true; + } + + return false; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/BitmapCharRec.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/BitmapCharRec.java new file mode 100644 index 000000000..34685e1b2 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/BitmapCharRec.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +/* Copyright (c) Mark J. Kilgard, 1994, 1998. */ + +/* This program is freely distributable without licensing fees + and is provided without guarantee or warrantee expressed or + implied. This program is -not- in the public domain. */ + +class BitmapCharRec { + public int width; + public int height; + public float xorig; + public float yorig; + public float advance; + public byte[] bitmap; + + public BitmapCharRec(int width, + int height, + float xorig, + float yorig, + float advance, + byte[] bitmap) { + this.width = width; + this.height = height; + this.xorig = xorig; + this.yorig = yorig; + this.advance = advance; + this.bitmap = bitmap; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/BitmapFontRec.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/BitmapFontRec.java new file mode 100644 index 000000000..18f7d3b28 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/BitmapFontRec.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +/* Copyright (c) Mark J. Kilgard, 1994, 1998. */ + +/* This program is freely distributable without licensing fees + and is provided without guarantee or warrantee expressed or + implied. This program is -not- in the public domain. */ + +class BitmapFontRec { + public String name; + public int num_chars; + public int first; + public BitmapCharRec[] ch; + + public BitmapFontRec(String name, + int num_chars, + int first, + BitmapCharRec[] ch) { + this.name = name; + this.num_chars = num_chars; + this.first = first; + this.ch = ch; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/CoordRec.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/CoordRec.java new file mode 100644 index 000000000..9ad95ec03 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/CoordRec.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +/* Copyright (c) Mark J. Kilgard, 1994, 1998. */ + +/* This program is freely distributable without licensing fees + and is provided without guarantee or warrantee expressed or + implied. This program is -not- in the public domain. */ + +class CoordRec { + public float x; + public float y; + + public CoordRec(float x, float y) { + this.x = x; + this.y = y; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUT.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUT.java new file mode 100644 index 000000000..8befc13ba --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUT.java @@ -0,0 +1,1342 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import javax.media.opengl.glu.gl2.*; + +/** Subset of the routines provided by the GLUT interface. Note the + signatures of many of the methods are necessarily different than + the corresponding C version. A GLUT object must only be used from + one particular thread at a time. <P> + + Copyright (c) Mark J. Kilgard, 1994, 1997. <P> + + (c) Copyright 1993, Silicon Graphics, Inc. <P> + + ALL RIGHTS RESERVED <P> + + Permission to use, copy, modify, and distribute this software + for any purpose and without fee is hereby granted, provided + that the above copyright notice appear in all copies and that + both the copyright notice and this permission notice appear in + supporting documentation, and that the name of Silicon + Graphics, Inc. not be used in advertising or publicity + pertaining to distribution of the software without specific, + written prior permission. <P> + + THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU + "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR + OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO + EVENT SHALL SILICON GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE + ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR + CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER, + INCLUDING WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE, + SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD PARTIES, WHETHER OR + NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF THE POSSIBILITY + OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE OR + PERFORMANCE OF THIS SOFTWARE. <P> + + US Government Users Restricted Rights <P> + + Use, duplication, or disclosure by the Government is subject to + restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + (c)(1)(ii) of the Rights in Technical Data and Computer + Software clause at DFARS 252.227-7013 and/or in similar or + successor clauses in the FAR or the DOD or NASA FAR + Supplement. Unpublished-- rights reserved under the copyright + laws of the United States. Contractor/manufacturer is Silicon + Graphics, Inc., 2011 N. Shoreline Blvd., Mountain View, CA + 94039-7311. <P> + + OpenGL(TM) is a trademark of Silicon Graphics, Inc. <P> +*/ + +public class GLUT { + public static final int STROKE_ROMAN = 0; + public static final int STROKE_MONO_ROMAN = 1; + public static final int BITMAP_9_BY_15 = 2; + public static final int BITMAP_8_BY_13 = 3; + public static final int BITMAP_TIMES_ROMAN_10 = 4; + public static final int BITMAP_TIMES_ROMAN_24 = 5; + public static final int BITMAP_HELVETICA_10 = 6; + public static final int BITMAP_HELVETICA_12 = 7; + public static final int BITMAP_HELVETICA_18 = 8; + + private GLUgl2 glu = new GLUgl2(); + + //---------------------------------------------------------------------- + // Shapes + // + + public void glutWireSphere(double radius, int slices, int stacks) { + quadObjInit(glu); + glu.gluQuadricDrawStyle(quadObj, GLU.GLU_LINE); + glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + glu.gluSphere(quadObj, radius, slices, stacks); + } + + public void glutSolidSphere(double radius, int slices, int stacks) { + quadObjInit(glu); + glu.gluQuadricDrawStyle(quadObj, GLU.GLU_FILL); + glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + glu.gluSphere(quadObj, radius, slices, stacks); + } + + public void glutWireCone(double base, double height, + int slices, int stacks) { + quadObjInit(glu); + glu.gluQuadricDrawStyle(quadObj, GLU.GLU_LINE); + glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + glu.gluCylinder(quadObj, base, 0.0, height, slices, stacks); + } + + public void glutSolidCone(double base, double height, + int slices, int stacks) { + quadObjInit(glu); + glu.gluQuadricDrawStyle(quadObj, GLU.GLU_FILL); + glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + glu.gluCylinder(quadObj, base, 0.0, height, slices, stacks); + } + + public void glutWireCylinder(double radius, double height, int slices, int stacks) { + quadObjInit(glu); + glu.gluQuadricDrawStyle(quadObj, GLU.GLU_LINE); + glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + glu.gluCylinder(quadObj, radius, radius, height, slices, stacks); + } + + public void glutSolidCylinder(double radius, double height, int slices, int stacks) { + GL2 gl = GLUgl2.getCurrentGL2(); + + // Prepare table of points for drawing end caps + double [] x = new double[slices]; + double [] y = new double[slices]; + double angleDelta = Math.PI * 2 / slices; + double angle = 0; + for (int i = 0 ; i < slices ; i ++) { + angle = i * angleDelta; + x[i] = Math.cos(angle) * radius; + y[i] = Math.sin(angle) * radius; + } + + // Draw bottom cap + gl.glBegin(GL2.GL_TRIANGLE_FAN); + gl.glNormal3d(0,0,-1); + gl.glVertex3d(0,0,0); + for (int i = 0 ; i < slices ; i ++) { + gl.glVertex3d(x[i], y[i], 0); + } + gl.glVertex3d(x[0], y[0], 0); + gl.glEnd(); + + // Draw top cap + gl.glBegin(GL2.GL_TRIANGLE_FAN); + gl.glNormal3d(0,0,1); + gl.glVertex3d(0,0,height); + for (int i = 0 ; i < slices ; i ++) { + gl.glVertex3d(x[i], y[i], height); + } + gl.glVertex3d(x[0], y[0], height); + gl.glEnd(); + + // Draw walls + quadObjInit(glu); + glu.gluQuadricDrawStyle(quadObj, GLU.GLU_FILL); + glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH); + /* If we ever changed/used the texture or orientation state + of quadObj, we'd need to change it to the defaults here + with gluQuadricTexture and/or gluQuadricOrientation. */ + glu.gluCylinder(quadObj, radius, radius, height, slices, stacks); + } + + public void glutWireCube(float size) { + drawBox(GLUgl2.getCurrentGL2(), size, GL2.GL_LINE_LOOP); + } + + public void glutSolidCube(float size) { + drawBox(GLUgl2.getCurrentGL2(), size, GL2.GL_QUADS); + } + + public void glutWireTorus(double innerRadius, double outerRadius, + int nsides, int rings) { + GL2 gl = GLUgl2.getCurrentGL2(); + gl.glPushAttrib(GL2.GL_POLYGON_BIT); + gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); + doughnut(gl, innerRadius, outerRadius, nsides, rings); + gl.glPopAttrib(); + } + + public void glutSolidTorus(double innerRadius, double outerRadius, + int nsides, int rings) { + doughnut(GLUgl2.getCurrentGL2(), innerRadius, outerRadius, nsides, rings); + } + + public void glutWireDodecahedron() { + dodecahedron(GLUgl2.getCurrentGL2(), GL2.GL_LINE_LOOP); + } + + public void glutSolidDodecahedron() { + dodecahedron(GLUgl2.getCurrentGL2(), GL2.GL_TRIANGLE_FAN); + } + + public void glutWireOctahedron() { + octahedron(GLUgl2.getCurrentGL2(), GL2.GL_LINE_LOOP); + } + + public void glutSolidOctahedron() { + octahedron(GLUgl2.getCurrentGL2(), GL2.GL_TRIANGLES); + } + + public void glutWireIcosahedron() { + icosahedron(GLUgl2.getCurrentGL2(), GL2.GL_LINE_LOOP); + } + + public void glutSolidIcosahedron() { + icosahedron(GLUgl2.getCurrentGL2(), GL2.GL_TRIANGLES); + } + + public void glutWireTetrahedron() { + tetrahedron(GLUgl2.getCurrentGL2(), GL2.GL_LINE_LOOP); + } + + public void glutSolidTetrahedron() { + tetrahedron(GLUgl2.getCurrentGL2(), GL2.GL_TRIANGLES); + } + +/** + * Renders the teapot as a solid shape of the specified size. The teapot is + * created in a way that replicates the C GLUT implementation. + * + * @param scale + * the factor by which to scale the teapot + */ + public void glutSolidTeapot(double scale) { + glutSolidTeapot(scale, true); + } + + /** + * Renders the teapot as a solid shape of the specified size. The teapot can + * either be created in a way that is backward-compatible with the standard + * C glut library (i.e. broken), or in a more pleasing way (i.e. with + * surfaces whose front-faces point outwards and standing on the z=0 plane, + * instead of the y=-1 plane). Both surface normals and texture coordinates + * for the teapot are generated. The teapot is generated with OpenGL + * evaluators. + * + * @param scale + * the factor by which to scale the teapot + * @param cStyle + * whether to create the teapot in exactly the same way as in the C + * implementation of GLUT + */ + public void glutSolidTeapot(double scale, boolean cStyle) { + teapot(GLUgl2.getCurrentGL2(), 14, scale, GL2.GL_FILL, cStyle); + } + + /** + * Renders the teapot as a wireframe shape of the specified size. The teapot + * is created in a way that replicates the C GLUT implementation. + * + * @param scale + * the factor by which to scale the teapot + */ + public void glutWireTeapot(double scale) { + glutWireTeapot(scale, true); + } + + /** + * Renders the teapot as a wireframe shape of the specified size. The teapot + * can either be created in a way that is backward-compatible with the + * standard C glut library (i.e. broken), or in a more pleasing way (i.e. + * with surfaces whose front-faces point outwards and standing on the z=0 + * plane, instead of the y=-1 plane). Both surface normals and texture + * coordinates for the teapot are generated. The teapot is generated with + * OpenGL evaluators. + * + * @param scale + * the factor by which to scale the teapot + * @param cStyle + * whether to create the teapot in exactly the same way as in the C + * implementation of GLUT + */ + public void glutWireTeapot(double scale, boolean cStyle) { + teapot(GLUgl2.getCurrentGL2(), 10, scale, GL2.GL_LINE, cStyle); + } + + //---------------------------------------------------------------------- + // Fonts + // + + public void glutBitmapCharacter(int font, char character) { + GL2 gl = GLUgl2.getCurrentGL2(); + int[] swapbytes = new int[1]; + int[] lsbfirst = new int[1]; + int[] rowlength = new int[1]; + int[] skiprows = new int[1]; + int[] skippixels = new int[1]; + int[] alignment = new int[1]; + beginBitmap(gl, + swapbytes, + lsbfirst, + rowlength, + skiprows, + skippixels, + alignment); + bitmapCharacterImpl(gl, font, character); + endBitmap(gl, + swapbytes, + lsbfirst, + rowlength, + skiprows, + skippixels, + alignment); + } + + public void glutBitmapString (int font, String string) { + GL2 gl = GLUgl2.getCurrentGL2(); + int[] swapbytes = new int[1]; + int[] lsbfirst = new int[1]; + int[] rowlength = new int[1]; + int[] skiprows = new int[1]; + int[] skippixels = new int[1]; + int[] alignment = new int[1]; + beginBitmap(gl, + swapbytes, + lsbfirst, + rowlength, + skiprows, + skippixels, + alignment); + int len = string.length(); + for (int i = 0; i < len; i++) { + bitmapCharacterImpl(gl, font, string.charAt(i)); + } + endBitmap(gl, + swapbytes, + lsbfirst, + rowlength, + skiprows, + skippixels, + alignment); + } + + public int glutBitmapWidth (int font, char character) { + BitmapFontRec fontinfo = getBitmapFont(font); + int c = character & 0xFFFF; + if (c < fontinfo.first || c >= fontinfo.first + fontinfo.num_chars) + return 0; + BitmapCharRec ch = fontinfo.ch[c - fontinfo.first]; + if (ch != null) + return (int) ch.advance; + else + return 0; + } + + public void glutStrokeCharacter(int font, char character) { + GL2 gl = GLUgl2.getCurrentGL2(); + StrokeFontRec fontinfo = getStrokeFont(font); + int c = character & 0xFFFF; + if (c < 0 || c >= fontinfo.num_chars) + return; + StrokeCharRec ch = fontinfo.ch[c]; + if (ch != null) { + for (int i = 0; i < ch.num_strokes; i++) { + StrokeRec stroke = ch.stroke[i]; + gl.glBegin(GL2.GL_LINE_STRIP); + for (int j = 0; j < stroke.num_coords; j++) { + CoordRec coord = stroke.coord[j]; + gl.glVertex2f(coord.x, coord.y); + } + gl.glEnd(); + } + gl.glTranslatef(ch.right, 0.0f, 0.0f); + } + } + + public void glutStrokeString(int font, String string) { + GL2 gl = GLUgl2.getCurrentGL2(); + StrokeFontRec fontinfo = getStrokeFont(font); + int len = string.length(); + for (int pos = 0; pos < len; pos++) { + int c = string.charAt(pos) & 0xFFFF; + if (c < 0 || c >= fontinfo.num_chars) + continue; + StrokeCharRec ch = fontinfo.ch[c]; + if (ch != null) { + for (int i = 0; i < ch.num_strokes; i++) { + StrokeRec stroke = ch.stroke[i]; + gl.glBegin(GL2.GL_LINE_STRIP); + for (int j = 0; j < stroke.num_coords; j++) { + CoordRec coord = stroke.coord[j]; + gl.glVertex2f(coord.x, coord.y); + } + gl.glEnd(); + } + gl.glTranslatef(ch.right, 0.0f, 0.0f); + } + } + } + + public int glutStrokeWidth (int font, char character) { + return (int) glutStrokeWidthf(font, character); + } + + public float glutStrokeWidthf (int font, char character) { + StrokeFontRec fontinfo = getStrokeFont(font); + int c = character & 0xFFFF; + if (c < 0 || c >= fontinfo.num_chars) + return 0; + StrokeCharRec ch = fontinfo.ch[c]; + if (ch != null) + return ch.right; + else + return 0; + } + + public int glutBitmapLength (int font, String string) { + BitmapFontRec fontinfo = getBitmapFont(font); + int length = 0; + int len = string.length(); + for (int pos = 0; pos < len; pos++) { + int c = string.charAt(pos) & 0xFFFF; + if (c >= fontinfo.first && c < fontinfo.first + fontinfo.num_chars) { + BitmapCharRec ch = fontinfo.ch[c - fontinfo.first]; + if (ch != null) + length += ch.advance; + } + } + return length; + } + + public int glutStrokeLength (int font, String string) { + return (int) glutStrokeLengthf(font, string); + } + + public float glutStrokeLengthf (int font, String string) { + StrokeFontRec fontinfo = getStrokeFont(font); + float length = 0; + int len = string.length(); + for (int i = 0; i < len; i++) { + char c = string.charAt(i); + if (c >= 0 && c < fontinfo.num_chars) { + StrokeCharRec ch = fontinfo.ch[c]; + if (ch != null) + length += ch.right; + } + } + return length; + } + + /** + This function draws a wireframe dodecahedron whose + facets are rhombic and + whose vertices are at unit radius. + No facet lies normal to any coordinate axes. + The polyhedron is centered at the origin. + */ + public void glutWireRhombicDodecahedron() { + GL2 gl = GLUgl2.getCurrentGL2(); + for( int i = 0; i < 12; i++ ) { + gl.glBegin( GL2.GL_LINE_LOOP ); + gl.glNormal3dv( rdod_n[ i ],0 ); + gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 0 ] ],0 ); + gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 1 ] ],0 ); + gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 2 ] ],0 ); + gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 3 ] ],0 ); + gl.glEnd( ); + } + } + + /** + This function draws a solid-shaded dodecahedron + whose facets are rhombic and + whose vertices are at unit radius. + No facet lies normal to any coordinate axes. + The polyhedron is centered at the origin. + */ + public void glutSolidRhombicDodecahedron() { + GL2 gl = GLUgl2.getCurrentGL2(); + gl.glBegin( GL2.GL_QUADS ); + for( int i = 0; i < 12; i++ ) { + gl.glNormal3dv( rdod_n[ i ],0 ); + gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 0 ] ],0 ); + gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 1 ] ],0 ); + gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 2 ] ],0 ); + gl.glVertex3dv( rdod_r[ rdod_v[ i ][ 3 ] ],0 ); + } + gl.glEnd( ); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + //---------------------------------------------------------------------- + // Shape implementation + // + + private GLUquadric quadObj; + private void quadObjInit(GLUgl2 glu) { + if (quadObj == null) { + quadObj = glu.gluNewQuadric(); + } + if (quadObj == null) { + throw new GLException("Out of memory"); + } + } + + private static void doughnut(GL2 gl, double r, double R, int nsides, int rings) { + int i, j; + float theta, phi, theta1; + float cosTheta, sinTheta; + float cosTheta1, sinTheta1; + float ringDelta, sideDelta; + + ringDelta = (float) (2.0 * Math.PI / rings); + sideDelta = (float) (2.0 * Math.PI / nsides); + + theta = 0.0f; + cosTheta = 1.0f; + sinTheta = 0.0f; + for (i = rings - 1; i >= 0; i--) { + theta1 = theta + ringDelta; + cosTheta1 = (float) Math.cos(theta1); + sinTheta1 = (float) Math.sin(theta1); + gl.glBegin(GL2.GL_QUAD_STRIP); + phi = 0.0f; + for (j = nsides; j >= 0; j--) { + float cosPhi, sinPhi, dist; + + phi += sideDelta; + cosPhi = (float) Math.cos(phi); + sinPhi = (float) Math.sin(phi); + dist = (float) (R + r * cosPhi); + + gl.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); + gl.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, (float) r * sinPhi); + gl.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); + gl.glVertex3f(cosTheta * dist, -sinTheta * dist, (float) r * sinPhi); + } + gl.glEnd(); + theta = theta1; + cosTheta = cosTheta1; + sinTheta = sinTheta1; + } + } + + private static float[][] boxVertices; + private static final float[][] boxNormals = { + {-1.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {1.0f, 0.0f, 0.0f}, + {0.0f, -1.0f, 0.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, -1.0f} + }; + private static final int[][] boxFaces = { + {0, 1, 2, 3}, + {3, 2, 6, 7}, + {7, 6, 5, 4}, + {4, 5, 1, 0}, + {5, 6, 2, 1}, + {7, 4, 0, 3} + }; + private void drawBox(GL2 gl, float size, int type) { + if (boxVertices == null) { + float[][] v = new float[8][]; + for (int i = 0; i < 8; i++) { + v[i] = new float[3]; + } + v[0][0] = v[1][0] = v[2][0] = v[3][0] = -0.5f; + v[4][0] = v[5][0] = v[6][0] = v[7][0] = 0.5f; + v[0][1] = v[1][1] = v[4][1] = v[5][1] = -0.5f; + v[2][1] = v[3][1] = v[6][1] = v[7][1] = 0.5f; + v[0][2] = v[3][2] = v[4][2] = v[7][2] = -0.5f; + v[1][2] = v[2][2] = v[5][2] = v[6][2] = 0.5f; + boxVertices = v; + } + float[][] v = boxVertices; + float[][] n = boxNormals; + int[][] faces = boxFaces; + for (int i = 5; i >= 0; i--) { + gl.glBegin(type); + gl.glNormal3fv(n[i], 0); + float[] vt = v[faces[i][0]]; + gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); + vt = v[faces[i][1]]; + gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); + vt = v[faces[i][2]]; + gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); + vt = v[faces[i][3]]; + gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); + gl.glEnd(); + } + } + + private float[][] dodec; + + private void initDodecahedron() { + dodec = new float[20][]; + for (int i = 0; i < dodec.length; i++) { + dodec[i] = new float[3]; + } + + float alpha, beta; + + alpha = (float) Math.sqrt(2.0f / (3.0f + Math.sqrt(5.0))); + beta = 1.0f + (float) Math.sqrt(6.0 / (3.0 + Math.sqrt(5.0)) - + 2.0 + 2.0 * Math.sqrt(2.0 / (3.0 + Math.sqrt(5.0)))); + dodec[0][0] = -alpha; dodec[0][1] = 0; dodec[0][2] = beta; + dodec[1][0] = alpha; dodec[1][1] = 0; dodec[1][2] = beta; + dodec[2][0] = -1; dodec[2][1] = -1; dodec[2][2] = -1; + dodec[3][0] = -1; dodec[3][1] = -1; dodec[3][2] = 1; + dodec[4][0] = -1; dodec[4][1] = 1; dodec[4][2] = -1; + dodec[5][0] = -1; dodec[5][1] = 1; dodec[5][2] = 1; + dodec[6][0] = 1; dodec[6][1] = -1; dodec[6][2] = -1; + dodec[7][0] = 1; dodec[7][1] = -1; dodec[7][2] = 1; + dodec[8][0] = 1; dodec[8][1] = 1; dodec[8][2] = -1; + dodec[9][0] = 1; dodec[9][1] = 1; dodec[9][2] = 1; + dodec[10][0] = beta; dodec[10][1] = alpha; dodec[10][2] = 0; + dodec[11][0] = beta; dodec[11][1] = -alpha; dodec[11][2] = 0; + dodec[12][0] = -beta; dodec[12][1] = alpha; dodec[12][2] = 0; + dodec[13][0] = -beta; dodec[13][1] = -alpha; dodec[13][2] = 0; + dodec[14][0] = -alpha; dodec[14][1] = 0; dodec[14][2] = -beta; + dodec[15][0] = alpha; dodec[15][1] = 0; dodec[15][2] = -beta; + dodec[16][0] = 0; dodec[16][1] = beta; dodec[16][2] = alpha; + dodec[17][0] = 0; dodec[17][1] = beta; dodec[17][2] = -alpha; + dodec[18][0] = 0; dodec[18][1] = -beta; dodec[18][2] = alpha; + dodec[19][0] = 0; dodec[19][1] = -beta; dodec[19][2] = -alpha; + } + + private static void diff3(float[] a, float[] b, float[] c) { + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + c[2] = a[2] - b[2]; + } + + private static void crossprod(float[] v1, float[] v2, float[] prod) { + float[] p = new float[3]; /* in case prod == v1 or v2 */ + + p[0] = v1[1] * v2[2] - v2[1] * v1[2]; + p[1] = v1[2] * v2[0] - v2[2] * v1[0]; + p[2] = v1[0] * v2[1] - v2[0] * v1[1]; + prod[0] = p[0]; + prod[1] = p[1]; + prod[2] = p[2]; + } + + private static void normalize(float[] v) { + float d; + + d = (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + if (d == 0.0) { + v[0] = d = 1.0f; + } + d = 1 / d; + v[0] *= d; + v[1] *= d; + v[2] *= d; + } + + private void pentagon(GL2 gl, int a, int b, int c, int d, int e, int shadeType) { + float[] n0 = new float[3]; + float[] d1 = new float[3]; + float[] d2 = new float[3]; + + diff3(dodec[a], dodec[b], d1); + diff3(dodec[b], dodec[c], d2); + crossprod(d1, d2, n0); + normalize(n0); + + gl.glBegin(shadeType); + gl.glNormal3fv(n0, 0); + gl.glVertex3fv(dodec[a], 0); + gl.glVertex3fv(dodec[b], 0); + gl.glVertex3fv(dodec[c], 0); + gl.glVertex3fv(dodec[d], 0); + gl.glVertex3fv(dodec[e], 0); + gl.glEnd(); + } + + private void dodecahedron(GL2 gl, int type) { + if (dodec == null) { + initDodecahedron(); + } + pentagon(gl, 0, 1, 9, 16, 5, type); + pentagon(gl, 1, 0, 3, 18, 7, type); + pentagon(gl, 1, 7, 11, 10, 9, type); + pentagon(gl, 11, 7, 18, 19, 6, type); + pentagon(gl, 8, 17, 16, 9, 10, type); + pentagon(gl, 2, 14, 15, 6, 19, type); + pentagon(gl, 2, 13, 12, 4, 14, type); + pentagon(gl, 2, 19, 18, 3, 13, type); + pentagon(gl, 3, 0, 5, 12, 13, type); + pentagon(gl, 6, 15, 8, 10, 11, type); + pentagon(gl, 4, 17, 8, 15, 14, type); + pentagon(gl, 4, 12, 5, 16, 17, type); + } + + private static void recorditem(GL2 gl, float[] n1, float[] n2, float[] n3, int shadeType) { + float[] q0 = new float[3]; + float[] q1 = new float[3]; + + diff3(n1, n2, q0); + diff3(n2, n3, q1); + crossprod(q0, q1, q1); + normalize(q1); + + gl.glBegin(shadeType); + gl.glNormal3fv(q1, 0); + gl.glVertex3fv(n1, 0); + gl.glVertex3fv(n2, 0); + gl.glVertex3fv(n3, 0); + gl.glEnd(); + } + + private static void subdivide(GL2 gl, float[] v0, float[] v1, float[] v2, int shadeType) { + int depth; + float[] w0 = new float[3]; + float[] w1 = new float[3]; + float[] w2 = new float[3]; + float l; + int i, j, k, n; + + depth = 1; + for (i = 0; i < depth; i++) { + for (j = 0; i + j < depth; j++) { + k = depth - i - j; + for (n = 0; n < 3; n++) { + w0[n] = (i * v0[n] + j * v1[n] + k * v2[n]) / depth; + w1[n] = ((i + 1) * v0[n] + j * v1[n] + (k - 1) * v2[n]) + / depth; + w2[n] = (i * v0[n] + (j + 1) * v1[n] + (k - 1) * v2[n]) + / depth; + } + l = (float) Math.sqrt(w0[0] * w0[0] + w0[1] * w0[1] + w0[2] * w0[2]); + w0[0] /= l; + w0[1] /= l; + w0[2] /= l; + l = (float) Math.sqrt(w1[0] * w1[0] + w1[1] * w1[1] + w1[2] * w1[2]); + w1[0] /= l; + w1[1] /= l; + w1[2] /= l; + l = (float) Math.sqrt(w2[0] * w2[0] + w2[1] * w2[1] + w2[2] * w2[2]); + w2[0] /= l; + w2[1] /= l; + w2[2] /= l; + recorditem(gl, w1, w0, w2, shadeType); + } + } + } + + private static void drawtriangle(GL2 gl, int i, float[][] data, int[][] ndx, int shadeType) { + float[] x0 = data[ndx[i][0]]; + float[] x1 = data[ndx[i][1]]; + float[] x2 = data[ndx[i][2]]; + subdivide(gl, x0, x1, x2, shadeType); + } + + /* octahedron data: The octahedron produced is centered at the + origin and has radius 1.0 */ + private static final float[][] odata = + { + {1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {0.0f, -1.0f, 0.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, -1.0f} + }; + + private static final int[][] ondex = + { + {0, 4, 2}, + {1, 2, 4}, + {0, 3, 4}, + {1, 4, 3}, + {0, 2, 5}, + {1, 5, 2}, + {0, 5, 3}, + {1, 3, 5} + }; + + private static void octahedron(GL2 gl, int shadeType) { + int i; + + for (i = 7; i >= 0; i--) { + drawtriangle(gl, i, odata, ondex, shadeType); + } + } + + /* icosahedron data: These numbers are rigged to make an + icosahedron of radius 1.0 */ + + private static final float X = .525731112119133606f; + private static final float Z = .850650808352039932f; + + private static final float[][] idata = + { + {-X, 0, Z}, + {X, 0, Z}, + {-X, 0, -Z}, + {X, 0, -Z}, + {0, Z, X}, + {0, Z, -X}, + {0, -Z, X}, + {0, -Z, -X}, + {Z, X, 0}, + {-Z, X, 0}, + {Z, -X, 0}, + {-Z, -X, 0} + }; + + private static final int[][] index = + { + {0, 4, 1}, + {0, 9, 4}, + {9, 5, 4}, + {4, 5, 8}, + {4, 8, 1}, + {8, 10, 1}, + {8, 3, 10}, + {5, 3, 8}, + {5, 2, 3}, + {2, 7, 3}, + {7, 10, 3}, + {7, 6, 10}, + {7, 11, 6}, + {11, 0, 6}, + {0, 1, 6}, + {6, 1, 10}, + {9, 0, 11}, + {9, 11, 2}, + {9, 2, 5}, + {7, 2, 11}, + }; + + private static void icosahedron(GL2 gl, int shadeType) { + int i; + + for (i = 19; i >= 0; i--) { + drawtriangle(gl, i, idata, index, shadeType); + } + } + + /* rhombic dodecahedron data: */ + + private static final double rdod_r[][] = + { + { 0.0, 0.0, 1.0 }, + { 0.707106781187, 0.000000000000, 0.5 }, + { 0.000000000000, 0.707106781187, 0.5 }, + { -0.707106781187, 0.000000000000, 0.5 }, + { 0.000000000000, -0.707106781187, 0.5 }, + { 0.707106781187, 0.707106781187, 0.0 }, + { -0.707106781187, 0.707106781187, 0.0 }, + { -0.707106781187, -0.707106781187, 0.0 }, + { 0.707106781187, -0.707106781187, 0.0 }, + { 0.707106781187, 0.000000000000, -0.5 }, + { 0.000000000000, 0.707106781187, -0.5 }, + { -0.707106781187, 0.000000000000, -0.5 }, + { 0.000000000000, -0.707106781187, -0.5 }, + { 0.0, 0.0, -1.0 } + }; + + private static final int rdod_v[][] = + { + { 0, 1, 5, 2 }, + { 0, 2, 6, 3 }, + { 0, 3, 7, 4 }, + { 0, 4, 8, 1 }, + { 5, 10, 6, 2 }, + { 6, 11, 7, 3 }, + { 7, 12, 8, 4 }, + { 8, 9, 5, 1 }, + { 5, 9, 13, 10 }, + { 6, 10, 13, 11 }, + { 7, 11, 13, 12 }, + { 8, 12, 13, 9 } + }; + + private static final double rdod_n[][] = + { + { 0.353553390594, 0.353553390594, 0.5 }, + { -0.353553390594, 0.353553390594, 0.5 }, + { -0.353553390594, -0.353553390594, 0.5 }, + { 0.353553390594, -0.353553390594, 0.5 }, + { 0.000000000000, 1.000000000000, 0.0 }, + { -1.000000000000, 0.000000000000, 0.0 }, + { 0.000000000000, -1.000000000000, 0.0 }, + { 1.000000000000, 0.000000000000, 0.0 }, + { 0.353553390594, 0.353553390594, -0.5 }, + { -0.353553390594, 0.353553390594, -0.5 }, + { -0.353553390594, -0.353553390594, -0.5 }, + { 0.353553390594, -0.353553390594, -0.5 } + }; + + /* tetrahedron data: */ + + private static final float T = 1.73205080756887729f; + + private static final float[][] tdata = + { + {T, T, T}, + {T, -T, -T}, + {-T, T, -T}, + {-T, -T, T} + }; + + private static final int[][] tndex = + { + {0, 1, 3}, + {2, 1, 0}, + {3, 2, 0}, + {1, 2, 3} + }; + + private static final void tetrahedron(GL2 gl, int shadeType) { + for (int i = 3; i >= 0; i--) + drawtriangle(gl, i, tdata, tndex, shadeType); + } + + // Teapot implementation (a modified port of glut_teapot.c) + // + // Rim, body, lid, and bottom data must be reflected in x and + // y; handle and spout data across the y axis only. + private static final int[][] teapotPatchData = { + /* rim */ + {102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + /* body */ + {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}, + {24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40}, + /* lid */ + {96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 101, 0, 1, 2, 3,}, + {0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117}, + /* bottom */ + {118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 125, 120, 40, 39, 38, 37}, + /* handle */ + {41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56}, + {53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 65, 66, 67}, + /* spout */ + {68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83}, + {80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95} + }; + private static final float[][] teapotCPData = { + {0.2f, 0f, 2.7f}, + {0.2f, -0.112f, 2.7f}, + {0.112f, -0.2f, 2.7f}, + {0f, -0.2f, 2.7f}, + {1.3375f, 0f, 2.53125f}, + {1.3375f, -0.749f, 2.53125f}, + {0.749f, -1.3375f, 2.53125f}, + {0f, -1.3375f, 2.53125f}, + {1.4375f, 0f, 2.53125f}, + {1.4375f, -0.805f, 2.53125f}, + {0.805f, -1.4375f, 2.53125f}, + {0f, -1.4375f, 2.53125f}, + {1.5f, 0f, 2.4f}, + {1.5f, -0.84f, 2.4f}, + {0.84f, -1.5f, 2.4f}, + {0f, -1.5f, 2.4f}, + {1.75f, 0f, 1.875f}, + {1.75f, -0.98f, 1.875f}, + {0.98f, -1.75f, 1.875f}, + {0f, -1.75f, 1.875f}, + {2f, 0f, 1.35f}, + {2f, -1.12f, 1.35f}, + {1.12f, -2f, 1.35f}, + {0f, -2f, 1.35f}, + {2f, 0f, 0.9f}, + {2f, -1.12f, 0.9f}, + {1.12f, -2f, 0.9f}, + {0f, -2f, 0.9f}, + {-2f, 0f, 0.9f}, + {2f, 0f, 0.45f}, + {2f, -1.12f, 0.45f}, + {1.12f, -2f, 0.45f}, + {0f, -2f, 0.45f}, + {1.5f, 0f, 0.225f}, + {1.5f, -0.84f, 0.225f}, + {0.84f, -1.5f, 0.225f}, + {0f, -1.5f, 0.225f}, + {1.5f, 0f, 0.15f}, + {1.5f, -0.84f, 0.15f}, + {0.84f, -1.5f, 0.15f}, + {0f, -1.5f, 0.15f}, + {-1.6f, 0f, 2.025f}, + {-1.6f, -0.3f, 2.025f}, + {-1.5f, -0.3f, 2.25f}, + {-1.5f, 0f, 2.25f}, + {-2.3f, 0f, 2.025f}, + {-2.3f, -0.3f, 2.025f}, + {-2.5f, -0.3f, 2.25f}, + {-2.5f, 0f, 2.25f}, + {-2.7f, 0f, 2.025f}, + {-2.7f, -0.3f, 2.025f}, + {-3f, -0.3f, 2.25f}, + {-3f, 0f, 2.25f}, + {-2.7f, 0f, 1.8f}, + {-2.7f, -0.3f, 1.8f}, + {-3f, -0.3f, 1.8f}, + {-3f, 0f, 1.8f}, + {-2.7f, 0f, 1.575f}, + {-2.7f, -0.3f, 1.575f}, + {-3f, -0.3f, 1.35f}, + {-3f, 0f, 1.35f}, + {-2.5f, 0f, 1.125f}, + {-2.5f, -0.3f, 1.125f}, + {-2.65f, -0.3f, 0.9375f}, + {-2.65f, 0f, 0.9375f}, + {-2f, -0.3f, 0.9f}, + {-1.9f, -0.3f, 0.6f}, + {-1.9f, 0f, 0.6f}, + {1.7f, 0f, 1.425f}, + {1.7f, -0.66f, 1.425f}, + {1.7f, -0.66f, 0.6f}, + {1.7f, 0f, 0.6f}, + {2.6f, 0f, 1.425f}, + {2.6f, -0.66f, 1.425f}, + {3.1f, -0.66f, 0.825f}, + {3.1f, 0f, 0.825f}, + {2.3f, 0f, 2.1f}, + {2.3f, -0.25f, 2.1f}, + {2.4f, -0.25f, 2.025f}, + {2.4f, 0f, 2.025f}, + {2.7f, 0f, 2.4f}, + {2.7f, -0.25f, 2.4f}, + {3.3f, -0.25f, 2.4f}, + {3.3f, 0f, 2.4f}, + {2.8f, 0f, 2.475f}, + {2.8f, -0.25f, 2.475f}, + {3.525f, -0.25f, 2.49375f}, + {3.525f, 0f, 2.49375f}, + {2.9f, 0f, 2.475f}, + {2.9f, -0.15f, 2.475f}, + {3.45f, -0.15f, 2.5125f}, + {3.45f, 0f, 2.5125f}, + {2.8f, 0f, 2.4f}, + {2.8f, -0.15f, 2.4f}, + {3.2f, -0.15f, 2.4f}, + {3.2f, 0f, 2.4f}, + {0f, 0f, 3.15f}, + {0.8f, 0f, 3.15f}, + {0.8f, -0.45f, 3.15f}, + {0.45f, -0.8f, 3.15f}, + {0f, -0.8f, 3.15f}, + {0f, 0f, 2.85f}, + {1.4f, 0f, 2.4f}, + {1.4f, -0.784f, 2.4f}, + {0.784f, -1.4f, 2.4f}, + {0f, -1.4f, 2.4f}, + {0.4f, 0f, 2.55f}, + {0.4f, -0.224f, 2.55f}, + {0.224f, -0.4f, 2.55f}, + {0f, -0.4f, 2.55f}, + {1.3f, 0f, 2.55f}, + {1.3f, -0.728f, 2.55f}, + {0.728f, -1.3f, 2.55f}, + {0f, -1.3f, 2.55f}, + {1.3f, 0f, 2.4f}, + {1.3f, -0.728f, 2.4f}, + {0.728f, -1.3f, 2.4f}, + {0f, -1.3f, 2.4f}, + {0f, 0f, 0f}, + {1.425f, -0.798f, 0f}, + {1.5f, 0f, 0.075f}, + {1.425f, 0f, 0f}, + {0.798f, -1.425f, 0f}, + {0f, -1.5f, 0.075f}, + {0f, -1.425f, 0f}, + {1.5f, -0.84f, 0.075f}, + {0.84f, -1.5f, 0.075f} + }; + // Since GL2.glMap2f expects a packed array of floats, we must convert + // from a 3-dimensional array to a 1-dimensional array + private static final float[] teapotTex = { + 0, 0, 1, 0, 0, 1, 1, 1 + }; + + private static void teapot(GL2 gl, + int grid, + double scale, + int type, + boolean backCompatible) + { + // As mentioned above, GL2.glMap2f expects a packed array of floats + float[] p = new float[4*4*3]; + float[] q = new float[4*4*3]; + float[] r = new float[4*4*3]; + float[] s = new float[4*4*3]; + int i, j, k, l; + + gl.glPushAttrib(GL2.GL_ENABLE_BIT | GL2.GL_EVAL_BIT | GL2.GL_POLYGON_BIT); + gl.glEnable(GL2.GL_AUTO_NORMAL); + gl.glEnable(GL2.GL_NORMALIZE); + gl.glEnable(GL2.GL_MAP2_VERTEX_3); + gl.glEnable(GL2.GL_MAP2_TEXTURE_COORD_2); + gl.glPushMatrix(); + if (!backCompatible) { + // The time has come to have the teapot no longer be inside out + gl.glFrontFace(GL2.GL_CW); + gl.glScaled(0.5*scale, 0.5*scale, 0.5*scale); + } else { + // We want the teapot in it's backward compatible position and + // orientation + gl.glRotatef(270.0f, 1, 0, 0); + gl.glScalef((float)(0.5 * scale), + (float)(0.5 * scale), + (float)(0.5 * scale)); + gl.glTranslatef(0.0f, 0.0f, -1.5f); + } + for (i = 0; i < 10; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) { + for (l = 0; l < 3; l++) { + p[(j*4+k)*3+l] = teapotCPData[teapotPatchData[i][j * 4 + k]][l]; + q[(j*4+k)*3+l] = + teapotCPData[teapotPatchData[i][j * 4 + (3 - k)]][l]; + if (l == 1) + q[(j*4+k)*3+l] *= -1.0; + if (i < 6) { + r[(j*4+k)*3+l] = + teapotCPData[teapotPatchData[i][j * 4 + (3 - k)]][l]; + if (l == 0) + r[(j*4+k)*3+l] *= -1.0; + s[(j*4+k)*3+l] = teapotCPData[teapotPatchData[i][j * 4 + k]][l]; + if (l == 0) + s[(j*4+k)*3+l] *= -1.0; + if (l == 1) + s[(j*4+k)*3+l] *= -1.0; + } + } + } + } + gl.glMap2f(GL2.GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, teapotTex, 0); + gl.glMap2f(GL2.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, p, 0); + gl.glMapGrid2f(grid, 0.0f, 1.0f, grid, 0.0f, 1.0f); + evaluateTeapotMesh(gl, grid, type, i, !backCompatible); + gl.glMap2f(GL2.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, q, 0); + evaluateTeapotMesh(gl, grid, type, i, !backCompatible); + if (i < 6) { + gl.glMap2f(GL2.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, r, 0); + evaluateTeapotMesh(gl, grid, type, i, !backCompatible); + gl.glMap2f(GL2.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, s, 0); + evaluateTeapotMesh(gl, grid, type, i, !backCompatible); + } + } + gl.glPopMatrix(); + gl.glPopAttrib(); + } + + private static void evaluateTeapotMesh(GL2 gl, + int grid, + int type, + int partNum, + boolean repairSingularities) + { + if (repairSingularities && (partNum == 5 || partNum == 3)) { + // Instead of using evaluators that give bad results at singularities, + // evaluate by hand + gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, type); + for (int nv = 0; nv < grid; nv++) { + if (nv == 0) { + // Draw a small triangle-fan to fill the hole + gl.glDisable(GL2.GL_AUTO_NORMAL); + gl.glNormal3f(0, 0, partNum == 3 ? 1 : -1); + gl.glBegin(GL2.GL_TRIANGLE_FAN); + { + gl.glEvalCoord2f(0, 0); + // Note that we draw in clock-wise order to match the evaluator + // method + for (int nu = 0; nu <= grid; nu++) + { + gl.glEvalCoord2f(nu / (float)grid, (1f / grid) / (float)grid); + } + } + gl.glEnd(); + gl.glEnable(GL2.GL_AUTO_NORMAL); + } + // Draw the rest of the piece as an evaluated quad-strip + gl.glBegin(GL2.GL_QUAD_STRIP); + { + // Note that we draw in clock-wise order to match the evaluator method + for (int nu = grid; nu >= 0; nu--) { + gl.glEvalCoord2f(nu / (float)grid, (nv + 1) / (float)grid); + gl.glEvalCoord2f(nu / (float)grid, Math.max(nv, 1f / grid) + / (float)grid); + } + } + gl.glEnd(); + } + } else { + gl.glEvalMesh2(type, 0, grid, 0, grid); + } + } + + //---------------------------------------------------------------------- + // Font implementation + // + + private static void bitmapCharacterImpl(GL2 gl, int font, char cin) { + BitmapFontRec fontinfo = getBitmapFont(font); + int c = cin & 0xFFFF; + if (c < fontinfo.first || + c >= fontinfo.first + fontinfo.num_chars) + return; + BitmapCharRec ch = fontinfo.ch[c - fontinfo.first]; + if (ch != null) { + gl.glBitmap(ch.width, ch.height, ch.xorig, ch.yorig, + ch.advance, 0, ch.bitmap, 0); + } + } + + private static final BitmapFontRec[] bitmapFonts = new BitmapFontRec[9]; + private static final StrokeFontRec[] strokeFonts = new StrokeFontRec[9]; + + private static BitmapFontRec getBitmapFont(int font) { + BitmapFontRec rec = bitmapFonts[font]; + if (rec == null) { + switch (font) { + case BITMAP_9_BY_15: + rec = GLUTBitmap9x15.glutBitmap9By15; + break; + case BITMAP_8_BY_13: + rec = GLUTBitmap8x13.glutBitmap8By13; + break; + case BITMAP_TIMES_ROMAN_10: + rec = GLUTBitmapTimesRoman10.glutBitmapTimesRoman10; + break; + case BITMAP_TIMES_ROMAN_24: + rec = GLUTBitmapTimesRoman24.glutBitmapTimesRoman24; + break; + case BITMAP_HELVETICA_10: + rec = GLUTBitmapHelvetica10.glutBitmapHelvetica10; + break; + case BITMAP_HELVETICA_12: + rec = GLUTBitmapHelvetica12.glutBitmapHelvetica12; + break; + case BITMAP_HELVETICA_18: + rec = GLUTBitmapHelvetica18.glutBitmapHelvetica18; + break; + default: + throw new GLException("Unknown bitmap font number " + font); + } + bitmapFonts[font] = rec; + } + return rec; + } + + private static StrokeFontRec getStrokeFont(int font) { + StrokeFontRec rec = strokeFonts[font]; + if (rec == null) { + switch (font) { + case STROKE_ROMAN: + rec = GLUTStrokeRoman.glutStrokeRoman; + break; + case STROKE_MONO_ROMAN: + rec = GLUTStrokeMonoRoman.glutStrokeMonoRoman; + break; + default: + throw new GLException("Unknown stroke font number " + font); + } + } + return rec; + } + + private static void beginBitmap(GL2 gl, + int[] swapbytes, + int[] lsbfirst, + int[] rowlength, + int[] skiprows, + int[] skippixels, + int[] alignment) { + gl.glGetIntegerv(GL2.GL_UNPACK_SWAP_BYTES, swapbytes, 0); + gl.glGetIntegerv(GL2.GL_UNPACK_LSB_FIRST, lsbfirst, 0); + gl.glGetIntegerv(GL2.GL_UNPACK_ROW_LENGTH, rowlength, 0); + gl.glGetIntegerv(GL2.GL_UNPACK_SKIP_ROWS, skiprows, 0); + gl.glGetIntegerv(GL2.GL_UNPACK_SKIP_PIXELS, skippixels, 0); + gl.glGetIntegerv(GL2.GL_UNPACK_ALIGNMENT, alignment, 0); + /* Little endian machines (DEC Alpha for example) could + benefit from setting GL_UNPACK_LSB_FIRST to GL_TRUE + instead of GL_FALSE, but this would require changing the + generated bitmaps too. */ + gl.glPixelStorei(GL2.GL_UNPACK_SWAP_BYTES, GL2.GL_FALSE); + gl.glPixelStorei(GL2.GL_UNPACK_LSB_FIRST, GL2.GL_FALSE); + gl.glPixelStorei(GL2.GL_UNPACK_ROW_LENGTH, 0); + gl.glPixelStorei(GL2.GL_UNPACK_SKIP_ROWS, 0); + gl.glPixelStorei(GL2.GL_UNPACK_SKIP_PIXELS, 0); + gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, 1); + } + + private static void endBitmap(GL2 gl, + int[] swapbytes, + int[] lsbfirst, + int[] rowlength, + int[] skiprows, + int[] skippixels, + int[] alignment) { + /* Restore saved modes. */ + gl.glPixelStorei(GL2.GL_UNPACK_SWAP_BYTES, swapbytes[0]); + gl.glPixelStorei(GL2.GL_UNPACK_LSB_FIRST, lsbfirst[0]); + gl.glPixelStorei(GL2.GL_UNPACK_ROW_LENGTH, rowlength[0]); + gl.glPixelStorei(GL2.GL_UNPACK_SKIP_ROWS, skiprows[0]); + gl.glPixelStorei(GL2.GL_UNPACK_SKIP_PIXELS, skippixels[0]); + gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, alignment[0]); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmap8x13.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmap8x13.java new file mode 100644 index 000000000..07ded652a --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmap8x13.java @@ -0,0 +1,2078 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +class GLUTBitmap8x13 { + +/* GENERATED FILE -- DO NOT MODIFY */ + + +static final BitmapCharRec ch0 = new BitmapCharRec(0,0,0,0,8,null); + +static final BitmapCharRec ch32 = new BitmapCharRec(0,0,0,0,8,null); + +static final BitmapCharRec ch127 = new BitmapCharRec(0,0,0,0,8,null); + +static final BitmapCharRec ch160 = new BitmapCharRec(0,0,0,0,8,null); + +/* char: 0xff */ + +static final byte[] ch255data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x0,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch255 = new BitmapCharRec(6,12,-1,2,8,ch255data); + +/* char: 0xfe */ + +static final byte[] ch254data = { +(byte) 0x80,(byte) 0x80,(byte) 0xb8,(byte) 0xc4,(byte) 0x84,(byte) 0x84,(byte) 0xc4,(byte) 0xb8,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch254 = new BitmapCharRec(6,10,-1,2,8,ch254data); + +/* char: 0xfd */ + +static final byte[] ch253data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch253 = new BitmapCharRec(6,12,-1,2,8,ch253data); + +/* char: 0xfc */ + +static final byte[] ch252data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x0,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch252 = new BitmapCharRec(6,10,-1,0,8,ch252data); + +/* char: 0xfb */ + +static final byte[] ch251data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x0,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch251 = new BitmapCharRec(6,10,-1,0,8,ch251data); + +/* char: 0xfa */ + +static final byte[] ch250data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch250 = new BitmapCharRec(6,10,-1,0,8,ch250data); + +/* char: 0xf9 */ + +static final byte[] ch249data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch249 = new BitmapCharRec(6,10,-1,0,8,ch249data); + +/* char: 0xf8 */ + +static final byte[] ch248data = { +(byte) 0x80,(byte) 0x78,(byte) 0xc4,(byte) 0xa4,(byte) 0x94,(byte) 0x8c,(byte) 0x78,(byte) 0x4, +}; + +static final BitmapCharRec ch248 = new BitmapCharRec(6,8,-1,1,8,ch248data); + +/* char: 0xf7 */ + +static final byte[] ch247data = { +(byte) 0x20,(byte) 0x20,(byte) 0x0,(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch247 = new BitmapCharRec(5,7,-1,-1,8,ch247data); + +/* char: 0xf6 */ + +static final byte[] ch246data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch246 = new BitmapCharRec(6,10,-1,0,8,ch246data); + +/* char: 0xf5 */ + +static final byte[] ch245data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch245 = new BitmapCharRec(6,10,-1,0,8,ch245data); + +/* char: 0xf4 */ + +static final byte[] ch244data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch244 = new BitmapCharRec(6,10,-1,0,8,ch244data); + +/* char: 0xf3 */ + +static final byte[] ch243data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch243 = new BitmapCharRec(6,10,-1,0,8,ch243data); + +/* char: 0xf2 */ + +static final byte[] ch242data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch242 = new BitmapCharRec(6,10,-1,0,8,ch242data); + +/* char: 0xf1 */ + +static final byte[] ch241data = { +(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xc4,(byte) 0xb8,(byte) 0x0,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch241 = new BitmapCharRec(6,10,-1,0,8,ch241data); + +/* char: 0xf0 */ + +static final byte[] ch240data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x8,(byte) 0x50,(byte) 0x30,(byte) 0x48, +}; + +static final BitmapCharRec ch240 = new BitmapCharRec(6,10,-1,0,8,ch240data); + +/* char: 0xef */ + +static final byte[] ch239data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x60,(byte) 0x0,(byte) 0x0,(byte) 0x50,(byte) 0x50, +}; + +static final BitmapCharRec ch239 = new BitmapCharRec(5,10,-1,0,8,ch239data); + +/* char: 0xee */ + +static final byte[] ch238data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x60,(byte) 0x0,(byte) 0x0,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch238 = new BitmapCharRec(5,10,-1,0,8,ch238data); + +/* char: 0xed */ + +static final byte[] ch237data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x60,(byte) 0x0,(byte) 0x0,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch237 = new BitmapCharRec(5,10,-1,0,8,ch237data); + +/* char: 0xec */ + +static final byte[] ch236data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x60,(byte) 0x0,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch236 = new BitmapCharRec(5,10,-1,0,8,ch236data); + +/* char: 0xeb */ + +static final byte[] ch235data = { +(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0xfc,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch235 = new BitmapCharRec(6,10,-1,0,8,ch235data); + +/* char: 0xea */ + +static final byte[] ch234data = { +(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0xfc,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch234 = new BitmapCharRec(6,10,-1,0,8,ch234data); + +/* char: 0xe9 */ + +static final byte[] ch233data = { +(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0xfc,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch233 = new BitmapCharRec(6,10,-1,0,8,ch233data); + +/* char: 0xe8 */ + +static final byte[] ch232data = { +(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0xfc,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch232 = new BitmapCharRec(6,10,-1,0,8,ch232data); + +/* char: 0xe7 */ + +static final byte[] ch231data = { +(byte) 0x20,(byte) 0x10,(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch231 = new BitmapCharRec(6,8,-1,2,8,ch231data); + +/* char: 0xe6 */ + +static final byte[] ch230data = { +(byte) 0x6c,(byte) 0x92,(byte) 0x90,(byte) 0x7c,(byte) 0x12,(byte) 0x6c, +}; + +static final BitmapCharRec ch230 = new BitmapCharRec(7,6,0,0,8,ch230data); + +/* char: 0xe5 */ + +static final byte[] ch229data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x7c,(byte) 0x4,(byte) 0x78,(byte) 0x0,(byte) 0x30,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch229 = new BitmapCharRec(6,10,-1,0,8,ch229data); + +/* char: 0xe4 */ + +static final byte[] ch228data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x7c,(byte) 0x4,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch228 = new BitmapCharRec(6,10,-1,0,8,ch228data); + +/* char: 0xe3 */ + +static final byte[] ch227data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x7c,(byte) 0x4,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch227 = new BitmapCharRec(6,10,-1,0,8,ch227data); + +/* char: 0xe2 */ + +static final byte[] ch226data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x7c,(byte) 0x4,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch226 = new BitmapCharRec(6,10,-1,0,8,ch226data); + +/* char: 0xe1 */ + +static final byte[] ch225data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x7c,(byte) 0x4,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch225 = new BitmapCharRec(6,10,-1,0,8,ch225data); + +/* char: 0xe0 */ + +static final byte[] ch224data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x7c,(byte) 0x4,(byte) 0x78,(byte) 0x0,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch224 = new BitmapCharRec(6,10,-1,0,8,ch224data); + +/* char: 0xdf */ + +static final byte[] ch223data = { +(byte) 0x80,(byte) 0xb8,(byte) 0xc4,(byte) 0x84,(byte) 0x84,(byte) 0xf8,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch223 = new BitmapCharRec(6,9,-1,1,8,ch223data); + +/* char: 0xde */ + +static final byte[] ch222data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xf8,(byte) 0x80, +}; + +static final BitmapCharRec ch222 = new BitmapCharRec(6,9,-1,0,8,ch222data); + +/* char: 0xdd */ + +static final byte[] ch221data = { +(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x50,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch221 = new BitmapCharRec(5,10,-1,0,8,ch221data); + +/* char: 0xdc */ + +static final byte[] ch220data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch220 = new BitmapCharRec(6,10,-1,0,8,ch220data); + +/* char: 0xdb */ + +static final byte[] ch219data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch219 = new BitmapCharRec(6,10,-1,0,8,ch219data); + +/* char: 0xda */ + +static final byte[] ch218data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch218 = new BitmapCharRec(6,10,-1,0,8,ch218data); + +/* char: 0xd9 */ + +static final byte[] ch217data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch217 = new BitmapCharRec(6,10,-1,0,8,ch217data); + +/* char: 0xd8 */ + +static final byte[] ch216data = { +(byte) 0x80,(byte) 0x78,(byte) 0xc4,(byte) 0xa4,(byte) 0xa4,(byte) 0xa4,(byte) 0x94,(byte) 0x94,(byte) 0x8c,(byte) 0x78,(byte) 0x4, +}; + +static final BitmapCharRec ch216 = new BitmapCharRec(6,11,-1,1,8,ch216data); + +/* char: 0xd7 */ + +static final byte[] ch215data = { +(byte) 0x84,(byte) 0x48,(byte) 0x30,(byte) 0x30,(byte) 0x48,(byte) 0x84, +}; + +static final BitmapCharRec ch215 = new BitmapCharRec(6,6,-1,-1,8,ch215data); + +/* char: 0xd6 */ + +static final byte[] ch214data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch214 = new BitmapCharRec(7,10,0,0,8,ch214data); + +/* char: 0xd5 */ + +static final byte[] ch213data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x28,(byte) 0x14, +}; + +static final BitmapCharRec ch213 = new BitmapCharRec(7,10,0,0,8,ch213data); + +/* char: 0xd4 */ + +static final byte[] ch212data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x24,(byte) 0x18, +}; + +static final BitmapCharRec ch212 = new BitmapCharRec(7,10,0,0,8,ch212data); + +/* char: 0xd3 */ + +static final byte[] ch211data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch211 = new BitmapCharRec(7,10,0,0,8,ch211data); + +/* char: 0xd2 */ + +static final byte[] ch210data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x8,(byte) 0x10, +}; + +static final BitmapCharRec ch210 = new BitmapCharRec(7,10,0,0,8,ch210data); + +/* char: 0xd1 */ + +static final byte[] ch209data = { +(byte) 0x82,(byte) 0x86,(byte) 0x8a,(byte) 0x92,(byte) 0xa2,(byte) 0xc2,(byte) 0x82,(byte) 0x0,(byte) 0x28,(byte) 0x14, +}; + +static final BitmapCharRec ch209 = new BitmapCharRec(7,10,0,0,8,ch209data); + +/* char: 0xd0 */ + +static final byte[] ch208data = { +(byte) 0xfc,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0xe2,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0xfc, +}; + +static final BitmapCharRec ch208 = new BitmapCharRec(7,9,0,0,8,ch208data); + +/* char: 0xcf */ + +static final byte[] ch207data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x0,(byte) 0x50,(byte) 0x50, +}; + +static final BitmapCharRec ch207 = new BitmapCharRec(5,10,-1,0,8,ch207data); + +/* char: 0xce */ + +static final byte[] ch206data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x0,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch206 = new BitmapCharRec(5,10,-1,0,8,ch206data); + +/* char: 0xcd */ + +static final byte[] ch205data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch205 = new BitmapCharRec(5,10,-1,0,8,ch205data); + +/* char: 0xcc */ + +static final byte[] ch204data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch204 = new BitmapCharRec(5,10,-1,0,8,ch204data); + +/* char: 0xcb */ + +static final byte[] ch203data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x0,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch203 = new BitmapCharRec(6,10,-1,0,8,ch203data); + +/* char: 0xca */ + +static final byte[] ch202data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x0,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch202 = new BitmapCharRec(6,10,-1,0,8,ch202data); + +/* char: 0xc9 */ + +static final byte[] ch201data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch201 = new BitmapCharRec(6,10,-1,0,8,ch201data); + +/* char: 0xc8 */ + +static final byte[] ch200data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch200 = new BitmapCharRec(6,10,-1,0,8,ch200data); + +/* char: 0xc7 */ + +static final byte[] ch199data = { +(byte) 0x20,(byte) 0x10,(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch199 = new BitmapCharRec(6,11,-1,2,8,ch199data); + +/* char: 0xc6 */ + +static final byte[] ch198data = { +(byte) 0x9e,(byte) 0x90,(byte) 0x90,(byte) 0xf0,(byte) 0x9c,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x6e, +}; + +static final BitmapCharRec ch198 = new BitmapCharRec(7,9,0,0,8,ch198data); + +/* char: 0xc5 */ + +static final byte[] ch197data = { +(byte) 0x84,(byte) 0x84,(byte) 0xfc,(byte) 0x84,(byte) 0x84,(byte) 0x48,(byte) 0x30,(byte) 0x30,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch197 = new BitmapCharRec(6,10,-1,0,8,ch197data); + +/* char: 0xc4 */ + +static final byte[] ch196data = { +(byte) 0x84,(byte) 0x84,(byte) 0xfc,(byte) 0x84,(byte) 0x84,(byte) 0x48,(byte) 0x30,(byte) 0x0,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch196 = new BitmapCharRec(6,10,-1,0,8,ch196data); + +/* char: 0xc3 */ + +static final byte[] ch195data = { +(byte) 0x84,(byte) 0x84,(byte) 0xfc,(byte) 0x84,(byte) 0x84,(byte) 0x48,(byte) 0x30,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch195 = new BitmapCharRec(6,10,-1,0,8,ch195data); + +/* char: 0xc2 */ + +static final byte[] ch194data = { +(byte) 0x84,(byte) 0x84,(byte) 0xfc,(byte) 0x84,(byte) 0x84,(byte) 0x48,(byte) 0x30,(byte) 0x0,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch194 = new BitmapCharRec(6,10,-1,0,8,ch194data); + +/* char: 0xc1 */ + +static final byte[] ch193data = { +(byte) 0x84,(byte) 0x84,(byte) 0xfc,(byte) 0x84,(byte) 0x84,(byte) 0x48,(byte) 0x30,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch193 = new BitmapCharRec(6,10,-1,0,8,ch193data); + +/* char: 0xc0 */ + +static final byte[] ch192data = { +(byte) 0x84,(byte) 0x84,(byte) 0xfc,(byte) 0x84,(byte) 0x84,(byte) 0x48,(byte) 0x30,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch192 = new BitmapCharRec(6,10,-1,0,8,ch192data); + +/* char: 0xbf */ + +static final byte[] ch191data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x0,(byte) 0x20, +}; + +static final BitmapCharRec ch191 = new BitmapCharRec(6,9,-1,0,8,ch191data); + +/* char: 0xbe */ + +static final byte[] ch190data = { +(byte) 0x6,(byte) 0x1a,(byte) 0x12,(byte) 0xa,(byte) 0x66,(byte) 0x92,(byte) 0x10,(byte) 0x20,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch190 = new BitmapCharRec(7,10,0,0,8,ch190data); + +/* char: 0xbd */ + +static final byte[] ch189data = { +(byte) 0x1e,(byte) 0x10,(byte) 0xc,(byte) 0x2,(byte) 0xf2,(byte) 0x4c,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch189 = new BitmapCharRec(7,10,0,0,8,ch189data); + +/* char: 0xbc */ + +static final byte[] ch188data = { +(byte) 0x6,(byte) 0x1a,(byte) 0x12,(byte) 0xa,(byte) 0xe6,(byte) 0x42,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch188 = new BitmapCharRec(7,10,0,0,8,ch188data); + +/* char: 0xbb */ + +static final byte[] ch187data = { +(byte) 0x90,(byte) 0x48,(byte) 0x24,(byte) 0x12,(byte) 0x24,(byte) 0x48,(byte) 0x90, +}; + +static final BitmapCharRec ch187 = new BitmapCharRec(7,7,0,-1,8,ch187data); + +/* char: 0xba */ + +static final byte[] ch186data = { +(byte) 0xf0,(byte) 0x0,(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch186 = new BitmapCharRec(4,6,-1,-3,8,ch186data); + +/* char: 0xb9 */ + +static final byte[] ch185data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch185 = new BitmapCharRec(3,6,-1,-4,8,ch185data); + +/* char: 0xb8 */ + +static final byte[] ch184data = { +(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch184 = new BitmapCharRec(2,2,-3,2,8,ch184data); + +/* char: 0xb7 */ + +static final byte[] ch183data = { +(byte) 0xc0, +}; + +static final BitmapCharRec ch183 = new BitmapCharRec(2,1,-3,-4,8,ch183data); + +/* char: 0xb6 */ + +static final byte[] ch182data = { +(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x68,(byte) 0xe8,(byte) 0xe8,(byte) 0xe8,(byte) 0x7c, +}; + +static final BitmapCharRec ch182 = new BitmapCharRec(6,9,-1,0,8,ch182data); + +/* char: 0xb5 */ + +static final byte[] ch181data = { +(byte) 0x80,(byte) 0xb4,(byte) 0xcc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch181 = new BitmapCharRec(6,7,-1,1,8,ch181data); + +/* char: 0xb4 */ + +static final byte[] ch180data = { +(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch180 = new BitmapCharRec(2,2,-3,-8,8,ch180data); + +/* char: 0xb3 */ + +static final byte[] ch179data = { +(byte) 0x60,(byte) 0x90,(byte) 0x10,(byte) 0x20,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch179 = new BitmapCharRec(4,6,-1,-4,8,ch179data); + +/* char: 0xb2 */ + +static final byte[] ch178data = { +(byte) 0xf0,(byte) 0x80,(byte) 0x60,(byte) 0x10,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch178 = new BitmapCharRec(4,6,-1,-4,8,ch178data); + +/* char: 0xb1 */ + +static final byte[] ch177data = { +(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch177 = new BitmapCharRec(5,7,-1,-1,8,ch177data); + +/* char: 0xb0 */ + +static final byte[] ch176data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch176 = new BitmapCharRec(4,4,-2,-5,8,ch176data); + +/* char: 0xaf */ + +static final byte[] ch175data = { +(byte) 0xfc, +}; + +static final BitmapCharRec ch175 = new BitmapCharRec(6,1,-1,-8,8,ch175data); + +/* char: 0xae */ + +static final byte[] ch174data = { +(byte) 0x38,(byte) 0x44,(byte) 0xaa,(byte) 0xb2,(byte) 0xaa,(byte) 0xaa,(byte) 0x92,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch174 = new BitmapCharRec(7,9,0,-1,8,ch174data); + +/* char: 0xad */ + +static final byte[] ch173data = { +(byte) 0xfc, +}; + +static final BitmapCharRec ch173 = new BitmapCharRec(6,1,-1,-4,8,ch173data); + +/* char: 0xac */ + +static final byte[] ch172data = { +(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0xfc, +}; + +static final BitmapCharRec ch172 = new BitmapCharRec(6,4,-1,-1,8,ch172data); + +/* char: 0xab */ + +static final byte[] ch171data = { +(byte) 0x12,(byte) 0x24,(byte) 0x48,(byte) 0x90,(byte) 0x48,(byte) 0x24,(byte) 0x12, +}; + +static final BitmapCharRec ch171 = new BitmapCharRec(7,7,0,-1,8,ch171data); + +/* char: 0xaa */ + +static final byte[] ch170data = { +(byte) 0xf8,(byte) 0x0,(byte) 0x78,(byte) 0x88,(byte) 0x78,(byte) 0x8,(byte) 0x70, +}; + +static final BitmapCharRec ch170 = new BitmapCharRec(5,7,-1,-2,8,ch170data); + +/* char: 0xa9 */ + +static final byte[] ch169data = { +(byte) 0x38,(byte) 0x44,(byte) 0x92,(byte) 0xaa,(byte) 0xa2,(byte) 0xaa,(byte) 0x92,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch169 = new BitmapCharRec(7,9,0,-1,8,ch169data); + +/* char: 0xa8 */ + +static final byte[] ch168data = { +(byte) 0xd8, +}; + +static final BitmapCharRec ch168 = new BitmapCharRec(5,1,-1,-8,8,ch168data); + +/* char: 0xa7 */ + +static final byte[] ch167data = { +(byte) 0x60,(byte) 0x90,(byte) 0x10,(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60,(byte) 0x80,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch167 = new BitmapCharRec(4,10,-2,0,8,ch167data); + +/* char: 0xa6 */ + +static final byte[] ch166data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch166 = new BitmapCharRec(1,9,-3,0,8,ch166data); + +/* char: 0xa5 */ + +static final byte[] ch165data = { +(byte) 0x10,(byte) 0x10,(byte) 0x7c,(byte) 0x10,(byte) 0x7c,(byte) 0x28,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch165 = new BitmapCharRec(7,9,0,0,8,ch165data); + +/* char: 0xa4 */ + +static final byte[] ch164data = { +(byte) 0x84,(byte) 0x78,(byte) 0x48,(byte) 0x48,(byte) 0x78,(byte) 0x84, +}; + +static final BitmapCharRec ch164 = new BitmapCharRec(6,6,-1,-1,8,ch164data); + +/* char: 0xa3 */ + +static final byte[] ch163data = { +(byte) 0xdc,(byte) 0x62,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x70,(byte) 0x20,(byte) 0x22,(byte) 0x1c, +}; + +static final BitmapCharRec ch163 = new BitmapCharRec(7,9,0,0,8,ch163data); + +/* char: 0xa2 */ + +static final byte[] ch162data = { +(byte) 0x20,(byte) 0x70,(byte) 0xa8,(byte) 0xa0,(byte) 0xa0,(byte) 0xa8,(byte) 0x70,(byte) 0x20, +}; + +static final BitmapCharRec ch162 = new BitmapCharRec(5,8,-1,-1,8,ch162data); + +/* char: 0xa1 */ + +static final byte[] ch161data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch161 = new BitmapCharRec(1,9,-3,0,8,ch161data); + +/* char: 0x7e '~' */ + +static final byte[] ch126data = { +(byte) 0x90,(byte) 0xa8,(byte) 0x48, +}; + +static final BitmapCharRec ch126 = new BitmapCharRec(5,3,-1,-6,8,ch126data); + +/* char: 0x7d '}' */ + +static final byte[] ch125data = { +(byte) 0xe0,(byte) 0x10,(byte) 0x10,(byte) 0x20,(byte) 0x18,(byte) 0x20,(byte) 0x10,(byte) 0x10,(byte) 0xe0, +}; + +static final BitmapCharRec ch125 = new BitmapCharRec(5,9,-1,0,8,ch125data); + +/* char: 0x7c '|' */ + +static final byte[] ch124data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch124 = new BitmapCharRec(1,9,-3,0,8,ch124data); + +/* char: 0x7b '{' */ + +static final byte[] ch123data = { +(byte) 0x38,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0xc0,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x38, +}; + +static final BitmapCharRec ch123 = new BitmapCharRec(5,9,-2,0,8,ch123data); + +/* char: 0x7a 'z' */ + +static final byte[] ch122data = { +(byte) 0xfc,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0xfc, +}; + +static final BitmapCharRec ch122 = new BitmapCharRec(6,6,-1,0,8,ch122data); + +/* char: 0x79 'y' */ + +static final byte[] ch121data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch121 = new BitmapCharRec(6,8,-1,2,8,ch121data); + +/* char: 0x78 'x' */ + +static final byte[] ch120data = { +(byte) 0x84,(byte) 0x48,(byte) 0x30,(byte) 0x30,(byte) 0x48,(byte) 0x84, +}; + +static final BitmapCharRec ch120 = new BitmapCharRec(6,6,-1,0,8,ch120data); + +/* char: 0x77 'w' */ + +static final byte[] ch119data = { +(byte) 0x44,(byte) 0xaa,(byte) 0x92,(byte) 0x92,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch119 = new BitmapCharRec(7,6,0,0,8,ch119data); + +/* char: 0x76 'v' */ + +static final byte[] ch118data = { +(byte) 0x20,(byte) 0x50,(byte) 0x50,(byte) 0x88,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch118 = new BitmapCharRec(5,6,-1,0,8,ch118data); + +/* char: 0x75 'u' */ + +static final byte[] ch117data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch117 = new BitmapCharRec(6,6,-1,0,8,ch117data); + +/* char: 0x74 't' */ + +static final byte[] ch116data = { +(byte) 0x38,(byte) 0x44,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xf8,(byte) 0x40,(byte) 0x40, +}; + +static final BitmapCharRec ch116 = new BitmapCharRec(6,8,-1,0,8,ch116data); + +/* char: 0x73 's' */ + +static final byte[] ch115data = { +(byte) 0x78,(byte) 0x84,(byte) 0x18,(byte) 0x60,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch115 = new BitmapCharRec(6,6,-1,0,8,ch115data); + +/* char: 0x72 'r' */ + +static final byte[] ch114data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x44,(byte) 0xb8, +}; + +static final BitmapCharRec ch114 = new BitmapCharRec(6,6,-1,0,8,ch114data); + +/* char: 0x71 'q' */ + +static final byte[] ch113data = { +(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x8c,(byte) 0x74, +}; + +static final BitmapCharRec ch113 = new BitmapCharRec(6,8,-1,2,8,ch113data); + +/* char: 0x70 'p' */ + +static final byte[] ch112data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xb8,(byte) 0xc4,(byte) 0x84,(byte) 0xc4,(byte) 0xb8, +}; + +static final BitmapCharRec ch112 = new BitmapCharRec(6,8,-1,2,8,ch112data); + +/* char: 0x6f 'o' */ + +static final byte[] ch111data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch111 = new BitmapCharRec(6,6,-1,0,8,ch111data); + +/* char: 0x6e 'n' */ + +static final byte[] ch110data = { +(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xc4,(byte) 0xb8, +}; + +static final BitmapCharRec ch110 = new BitmapCharRec(6,6,-1,0,8,ch110data); + +/* char: 0x6d 'm' */ + +static final byte[] ch109data = { +(byte) 0x82,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0xec, +}; + +static final BitmapCharRec ch109 = new BitmapCharRec(7,6,0,0,8,ch109data); + +/* char: 0x6c 'l' */ + +static final byte[] ch108data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x60, +}; + +static final BitmapCharRec ch108 = new BitmapCharRec(5,9,-1,0,8,ch108data); + +/* char: 0x6b 'k' */ + +static final byte[] ch107data = { +(byte) 0x84,(byte) 0x88,(byte) 0x90,(byte) 0xe0,(byte) 0x90,(byte) 0x88,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch107 = new BitmapCharRec(6,9,-1,0,8,ch107data); + +/* char: 0x6a 'j' */ + +static final byte[] ch106data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x18,(byte) 0x0,(byte) 0x8, +}; + +static final BitmapCharRec ch106 = new BitmapCharRec(5,10,-1,2,8,ch106data); + +/* char: 0x69 'i' */ + +static final byte[] ch105data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x60,(byte) 0x0,(byte) 0x20, +}; + +static final BitmapCharRec ch105 = new BitmapCharRec(5,8,-1,0,8,ch105data); + +/* char: 0x68 'h' */ + +static final byte[] ch104data = { +(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xc4,(byte) 0xb8,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch104 = new BitmapCharRec(6,9,-1,0,8,ch104data); + +/* char: 0x67 'g' */ + +static final byte[] ch103data = { +(byte) 0x78,(byte) 0x84,(byte) 0x78,(byte) 0x80,(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x74, +}; + +static final BitmapCharRec ch103 = new BitmapCharRec(6,8,-1,2,8,ch103data); + +/* char: 0x66 'f' */ + +static final byte[] ch102data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xf8,(byte) 0x40,(byte) 0x40,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch102 = new BitmapCharRec(6,9,-1,0,8,ch102data); + +/* char: 0x65 'e' */ + +static final byte[] ch101data = { +(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0xfc,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch101 = new BitmapCharRec(6,6,-1,0,8,ch101data); + +/* char: 0x64 'd' */ + +static final byte[] ch100data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x84,(byte) 0x8c,(byte) 0x74,(byte) 0x4,(byte) 0x4,(byte) 0x4, +}; + +static final BitmapCharRec ch100 = new BitmapCharRec(6,9,-1,0,8,ch100data); + +/* char: 0x63 'c' */ + +static final byte[] ch99data = { +(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch99 = new BitmapCharRec(6,6,-1,0,8,ch99data); + +/* char: 0x62 'b' */ + +static final byte[] ch98data = { +(byte) 0xb8,(byte) 0xc4,(byte) 0x84,(byte) 0x84,(byte) 0xc4,(byte) 0xb8,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch98 = new BitmapCharRec(6,9,-1,0,8,ch98data); + +/* char: 0x61 'a' */ + +static final byte[] ch97data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x7c,(byte) 0x4,(byte) 0x78, +}; + +static final BitmapCharRec ch97 = new BitmapCharRec(6,6,-1,0,8,ch97data); + +/* char: 0x60 '`' */ + +static final byte[] ch96data = { +(byte) 0x10,(byte) 0x60,(byte) 0xe0, +}; + +static final BitmapCharRec ch96 = new BitmapCharRec(4,3,-2,-6,8,ch96data); + +/* char: 0x5f '_' */ + +static final byte[] ch95data = { +(byte) 0xfe, +}; + +static final BitmapCharRec ch95 = new BitmapCharRec(7,1,0,1,8,ch95data); + +/* char: 0x5e '^' */ + +static final byte[] ch94data = { +(byte) 0x88,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch94 = new BitmapCharRec(5,3,-1,-6,8,ch94data); + +/* char: 0x5d ']' */ + +static final byte[] ch93data = { +(byte) 0xf0,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xf0, +}; + +static final BitmapCharRec ch93 = new BitmapCharRec(4,9,-1,0,8,ch93data); + +/* char: 0x5c '\' */ + +static final byte[] ch92data = { +(byte) 0x2,(byte) 0x2,(byte) 0x4,(byte) 0x8,(byte) 0x10,(byte) 0x20,(byte) 0x40,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch92 = new BitmapCharRec(7,9,0,0,8,ch92data); + +/* char: 0x5b '[' */ + +static final byte[] ch91data = { +(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf0, +}; + +static final BitmapCharRec ch91 = new BitmapCharRec(4,9,-2,0,8,ch91data); + +/* char: 0x5a 'Z' */ + +static final byte[] ch90data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0xfc, +}; + +static final BitmapCharRec ch90 = new BitmapCharRec(6,9,-1,0,8,ch90data); + +/* char: 0x59 'Y' */ + +static final byte[] ch89data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch89 = new BitmapCharRec(7,9,0,0,8,ch89data); + +/* char: 0x58 'X' */ + +static final byte[] ch88data = { +(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch88 = new BitmapCharRec(7,9,0,0,8,ch88data); + +/* char: 0x57 'W' */ + +static final byte[] ch87data = { +(byte) 0x44,(byte) 0xaa,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch87 = new BitmapCharRec(7,9,0,0,8,ch87data); + +/* char: 0x56 'V' */ + +static final byte[] ch86data = { +(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch86 = new BitmapCharRec(7,9,0,0,8,ch86data); + +/* char: 0x55 'U' */ + +static final byte[] ch85data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch85 = new BitmapCharRec(6,9,-1,0,8,ch85data); + +/* char: 0x54 'T' */ + +static final byte[] ch84data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xfe, +}; + +static final BitmapCharRec ch84 = new BitmapCharRec(7,9,0,0,8,ch84data); + +/* char: 0x53 'S' */ + +static final byte[] ch83data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x4,(byte) 0x78,(byte) 0x80,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch83 = new BitmapCharRec(6,9,-1,0,8,ch83data); + +/* char: 0x52 'R' */ + +static final byte[] ch82data = { +(byte) 0x84,(byte) 0x88,(byte) 0x90,(byte) 0xa0,(byte) 0xf8,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xf8, +}; + +static final BitmapCharRec ch82 = new BitmapCharRec(6,9,-1,0,8,ch82data); + +/* char: 0x51 'Q' */ + +static final byte[] ch81data = { +(byte) 0x4,(byte) 0x78,(byte) 0x94,(byte) 0xa4,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch81 = new BitmapCharRec(6,10,-1,1,8,ch81data); + +/* char: 0x50 'P' */ + +static final byte[] ch80data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xf8, +}; + +static final BitmapCharRec ch80 = new BitmapCharRec(6,9,-1,0,8,ch80data); + +/* char: 0x4f 'O' */ + +static final byte[] ch79data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch79 = new BitmapCharRec(6,9,-1,0,8,ch79data); + +/* char: 0x4e 'N' */ + +static final byte[] ch78data = { +(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x8c,(byte) 0x94,(byte) 0xa4,(byte) 0xc4,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch78 = new BitmapCharRec(6,9,-1,0,8,ch78data); + +/* char: 0x4d 'M' */ + +static final byte[] ch77data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x92,(byte) 0x92,(byte) 0xaa,(byte) 0xc6,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch77 = new BitmapCharRec(7,9,0,0,8,ch77data); + +/* char: 0x4c 'L' */ + +static final byte[] ch76data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch76 = new BitmapCharRec(6,9,-1,0,8,ch76data); + +/* char: 0x4b 'K' */ + +static final byte[] ch75data = { +(byte) 0x84,(byte) 0x88,(byte) 0x90,(byte) 0xa0,(byte) 0xc0,(byte) 0xa0,(byte) 0x90,(byte) 0x88,(byte) 0x84, +}; + +static final BitmapCharRec ch75 = new BitmapCharRec(6,9,-1,0,8,ch75data); + +/* char: 0x4a 'J' */ + +static final byte[] ch74data = { +(byte) 0x70,(byte) 0x88,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x3c, +}; + +static final BitmapCharRec ch74 = new BitmapCharRec(6,9,-1,0,8,ch74data); + +/* char: 0x49 'I' */ + +static final byte[] ch73data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8, +}; + +static final BitmapCharRec ch73 = new BitmapCharRec(5,9,-1,0,8,ch73data); + +/* char: 0x48 'H' */ + +static final byte[] ch72data = { +(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xfc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch72 = new BitmapCharRec(6,9,-1,0,8,ch72data); + +/* char: 0x47 'G' */ + +static final byte[] ch71data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x9c,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch71 = new BitmapCharRec(6,9,-1,0,8,ch71data); + +/* char: 0x46 'F' */ + +static final byte[] ch70data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc, +}; + +static final BitmapCharRec ch70 = new BitmapCharRec(6,9,-1,0,8,ch70data); + +/* char: 0x45 'E' */ + +static final byte[] ch69data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc, +}; + +static final BitmapCharRec ch69 = new BitmapCharRec(6,9,-1,0,8,ch69data); + +/* char: 0x44 'D' */ + +static final byte[] ch68data = { +(byte) 0xfc,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0xfc, +}; + +static final BitmapCharRec ch68 = new BitmapCharRec(7,9,0,0,8,ch68data); + +/* char: 0x43 'C' */ + +static final byte[] ch67data = { +(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch67 = new BitmapCharRec(6,9,-1,0,8,ch67data); + +/* char: 0x42 'B' */ + +static final byte[] ch66data = { +(byte) 0xfc,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x7c,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0xfc, +}; + +static final BitmapCharRec ch66 = new BitmapCharRec(7,9,0,0,8,ch66data); + +/* char: 0x41 'A' */ + +static final byte[] ch65data = { +(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xfc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch65 = new BitmapCharRec(6,9,-1,0,8,ch65data); + +/* char: 0x40 '@' */ + +static final byte[] ch64data = { +(byte) 0x78,(byte) 0x80,(byte) 0x94,(byte) 0xac,(byte) 0xa4,(byte) 0x9c,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch64 = new BitmapCharRec(6,9,-1,0,8,ch64data); + +/* char: 0x3f '?' */ + +static final byte[] ch63data = { +(byte) 0x10,(byte) 0x0,(byte) 0x10,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch63 = new BitmapCharRec(6,9,-1,0,8,ch63data); + +/* char: 0x3e '>' */ + +static final byte[] ch62data = { +(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x10,(byte) 0x20,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch62 = new BitmapCharRec(5,9,-1,0,8,ch62data); + +/* char: 0x3d '=' */ + +static final byte[] ch61data = { +(byte) 0xfc,(byte) 0x0,(byte) 0x0,(byte) 0xfc, +}; + +static final BitmapCharRec ch61 = new BitmapCharRec(6,4,-1,-2,8,ch61data); + +/* char: 0x3c '<' */ + +static final byte[] ch60data = { +(byte) 0x8,(byte) 0x10,(byte) 0x20,(byte) 0x40,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch60 = new BitmapCharRec(5,9,-2,0,8,ch60data); + +/* char: 0x3b ';' */ + +static final byte[] ch59data = { +(byte) 0x80,(byte) 0x60,(byte) 0x70,(byte) 0x0,(byte) 0x0,(byte) 0x20,(byte) 0x70,(byte) 0x20, +}; + +static final BitmapCharRec ch59 = new BitmapCharRec(4,8,-1,1,8,ch59data); + +/* char: 0x3a ':' */ + +static final byte[] ch58data = { +(byte) 0x40,(byte) 0xe0,(byte) 0x40,(byte) 0x0,(byte) 0x0,(byte) 0x40,(byte) 0xe0,(byte) 0x40, +}; + +static final BitmapCharRec ch58 = new BitmapCharRec(3,8,-2,1,8,ch58data); + +/* char: 0x39 '9' */ + +static final byte[] ch57data = { +(byte) 0x70,(byte) 0x8,(byte) 0x4,(byte) 0x4,(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch57 = new BitmapCharRec(6,9,-1,0,8,ch57data); + +/* char: 0x38 '8' */ + +static final byte[] ch56data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch56 = new BitmapCharRec(6,9,-1,0,8,ch56data); + +/* char: 0x37 '7' */ + +static final byte[] ch55data = { +(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x10,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0xfc, +}; + +static final BitmapCharRec ch55 = new BitmapCharRec(6,9,-1,0,8,ch55data); + +/* char: 0x36 '6' */ + +static final byte[] ch54data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0xc4,(byte) 0xb8,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x38, +}; + +static final BitmapCharRec ch54 = new BitmapCharRec(6,9,-1,0,8,ch54data); + +/* char: 0x35 '5' */ + +static final byte[] ch53data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x4,(byte) 0xc4,(byte) 0xb8,(byte) 0x80,(byte) 0x80,(byte) 0xfc, +}; + +static final BitmapCharRec ch53 = new BitmapCharRec(6,9,-1,0,8,ch53data); + +/* char: 0x34 '4' */ + +static final byte[] ch52data = { +(byte) 0x8,(byte) 0x8,(byte) 0xfc,(byte) 0x88,(byte) 0x88,(byte) 0x48,(byte) 0x28,(byte) 0x18,(byte) 0x8, +}; + +static final BitmapCharRec ch52 = new BitmapCharRec(6,9,-1,0,8,ch52data); + +/* char: 0x33 '3' */ + +static final byte[] ch51data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x4,(byte) 0x38,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0xfc, +}; + +static final BitmapCharRec ch51 = new BitmapCharRec(6,9,-1,0,8,ch51data); + +/* char: 0x32 '2' */ + +static final byte[] ch50data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x40,(byte) 0x30,(byte) 0x8,(byte) 0x4,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch50 = new BitmapCharRec(6,9,-1,0,8,ch50data); + +/* char: 0x31 '1' */ + +static final byte[] ch49data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xa0,(byte) 0x60,(byte) 0x20, +}; + +static final BitmapCharRec ch49 = new BitmapCharRec(5,9,-1,0,8,ch49data); + +/* char: 0x30 '0' */ + +static final byte[] ch48data = { +(byte) 0x30,(byte) 0x48,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch48 = new BitmapCharRec(6,9,-1,0,8,ch48data); + +/* char: 0x2f '/' */ + +static final byte[] ch47data = { +(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0x2,(byte) 0x2, +}; + +static final BitmapCharRec ch47 = new BitmapCharRec(7,9,0,0,8,ch47data); + +/* char: 0x2e '.' */ + +static final byte[] ch46data = { +(byte) 0x40,(byte) 0xe0,(byte) 0x40, +}; + +static final BitmapCharRec ch46 = new BitmapCharRec(3,3,-2,1,8,ch46data); + +/* char: 0x2d '-' */ + +static final byte[] ch45data = { +(byte) 0xfc, +}; + +static final BitmapCharRec ch45 = new BitmapCharRec(6,1,-1,-4,8,ch45data); + +/* char: 0x2c ',' */ + +static final byte[] ch44data = { +(byte) 0x80,(byte) 0x60,(byte) 0x70, +}; + +static final BitmapCharRec ch44 = new BitmapCharRec(4,3,-1,1,8,ch44data); + +/* char: 0x2b '+' */ + +static final byte[] ch43data = { +(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch43 = new BitmapCharRec(5,5,-1,-2,8,ch43data); + +/* char: 0x2a '*' */ + +static final byte[] ch42data = { +(byte) 0x48,(byte) 0x30,(byte) 0xfc,(byte) 0x30,(byte) 0x48, +}; + +static final BitmapCharRec ch42 = new BitmapCharRec(6,5,-1,-2,8,ch42data); + +/* char: 0x29 ')' */ + +static final byte[] ch41data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch41 = new BitmapCharRec(3,9,-2,0,8,ch41data); + +/* char: 0x28 '(' */ + +static final byte[] ch40data = { +(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch40 = new BitmapCharRec(3,9,-3,0,8,ch40data); + +/* char: 0x27 ''' */ + +static final byte[] ch39data = { +(byte) 0x80,(byte) 0x60,(byte) 0x70, +}; + +static final BitmapCharRec ch39 = new BitmapCharRec(4,3,-1,-6,8,ch39data); + +/* char: 0x26 '&' */ + +static final byte[] ch38data = { +(byte) 0x74,(byte) 0x88,(byte) 0x94,(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch38 = new BitmapCharRec(6,7,-1,0,8,ch38data); + +/* char: 0x25 '%' */ + +static final byte[] ch37data = { +(byte) 0x88,(byte) 0x54,(byte) 0x48,(byte) 0x20,(byte) 0x10,(byte) 0x10,(byte) 0x48,(byte) 0xa4,(byte) 0x44, +}; + +static final BitmapCharRec ch37 = new BitmapCharRec(6,9,-1,0,8,ch37data); + +/* char: 0x24 '$' */ + +static final byte[] ch36data = { +(byte) 0x20,(byte) 0xf0,(byte) 0x28,(byte) 0x70,(byte) 0xa0,(byte) 0x78,(byte) 0x20, +}; + +static final BitmapCharRec ch36 = new BitmapCharRec(5,7,-1,-1,8,ch36data); + +/* char: 0x23 '#' */ + +static final byte[] ch35data = { +(byte) 0x48,(byte) 0x48,(byte) 0xfc,(byte) 0x48,(byte) 0xfc,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch35 = new BitmapCharRec(6,7,-1,-1,8,ch35data); + +/* char: 0x22 '"' */ + +static final byte[] ch34data = { +(byte) 0x90,(byte) 0x90,(byte) 0x90, +}; + +static final BitmapCharRec ch34 = new BitmapCharRec(4,3,-2,-6,8,ch34data); + +/* char: 0x21 '!' */ + +static final byte[] ch33data = { +(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch33 = new BitmapCharRec(1,9,-3,0,8,ch33data); + +/* char: 0x1f */ + +static final byte[] ch31data = { +(byte) 0x80, +}; + +static final BitmapCharRec ch31 = new BitmapCharRec(1,1,-3,-3,8,ch31data); + +/* char: 0x1e */ + +static final byte[] ch30data = { +(byte) 0xdc,(byte) 0x62,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x70,(byte) 0x20,(byte) 0x22,(byte) 0x1c, +}; + +static final BitmapCharRec ch30 = new BitmapCharRec(7,9,0,0,8,ch30data); + +/* char: 0x1d */ + +static final byte[] ch29data = { +(byte) 0x80,(byte) 0x40,(byte) 0xfe,(byte) 0x10,(byte) 0xfe,(byte) 0x4,(byte) 0x2, +}; + +static final BitmapCharRec ch29 = new BitmapCharRec(7,7,0,0,8,ch29data); + +/* char: 0x1c */ + +static final byte[] ch28data = { +(byte) 0x88,(byte) 0x48,(byte) 0x48,(byte) 0x48,(byte) 0x48,(byte) 0xfc, +}; + +static final BitmapCharRec ch28 = new BitmapCharRec(6,6,-1,0,8,ch28data); + +/* char: 0x1b */ + +static final byte[] ch27data = { +(byte) 0xfe,(byte) 0x80,(byte) 0x20,(byte) 0x8,(byte) 0x2,(byte) 0x8,(byte) 0x20,(byte) 0x80, +}; + +static final BitmapCharRec ch27 = new BitmapCharRec(7,8,0,0,8,ch27data); + +/* char: 0x1a */ + +static final byte[] ch26data = { +(byte) 0xfe,(byte) 0x2,(byte) 0x8,(byte) 0x20,(byte) 0x80,(byte) 0x20,(byte) 0x8,(byte) 0x2, +}; + +static final BitmapCharRec ch26 = new BitmapCharRec(7,8,0,0,8,ch26data); + +/* char: 0x19 */ + +static final byte[] ch25data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch25 = new BitmapCharRec(1,13,-3,2,8,ch25data); + +/* char: 0x18 */ + +static final byte[] ch24data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xff, +}; + +static final BitmapCharRec ch24 = new BitmapCharRec(8,6,0,2,8,ch24data); + +/* char: 0x17 */ + +static final byte[] ch23data = { +(byte) 0xff,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch23 = new BitmapCharRec(8,8,0,-3,8,ch23data); + +/* char: 0x16 */ + +static final byte[] ch22data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xf0,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch22 = new BitmapCharRec(4,13,0,2,8,ch22data); + +/* char: 0x15 */ + +static final byte[] ch21data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch21 = new BitmapCharRec(5,13,-3,2,8,ch21data); + +/* char: 0x14 */ + +static final byte[] ch20data = { +(byte) 0xff, +}; + +static final BitmapCharRec ch20 = new BitmapCharRec(8,1,0,1,8,ch20data); + +/* char: 0x13 */ + +static final byte[] ch19data = { +(byte) 0xff, +}; + +static final BitmapCharRec ch19 = new BitmapCharRec(8,1,0,-1,8,ch19data); + +/* char: 0x12 */ + +static final byte[] ch18data = { +(byte) 0xff, +}; + +static final BitmapCharRec ch18 = new BitmapCharRec(8,1,0,-3,8,ch18data); + +/* char: 0x11 */ + +static final byte[] ch17data = { +(byte) 0xff, +}; + +static final BitmapCharRec ch17 = new BitmapCharRec(8,1,0,-5,8,ch17data); + +/* char: 0x10 */ + +static final byte[] ch16data = { +(byte) 0xff, +}; + +static final BitmapCharRec ch16 = new BitmapCharRec(8,1,0,-7,8,ch16data); + +/* char: 0xf */ + +static final byte[] ch15data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xff,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch15 = new BitmapCharRec(8,13,0,2,8,ch15data); + +/* char: 0xe */ + +static final byte[] ch14data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch14 = new BitmapCharRec(5,8,-3,-3,8,ch14data); + +/* char: 0xd */ + +static final byte[] ch13data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8, +}; + +static final BitmapCharRec ch13 = new BitmapCharRec(5,6,-3,2,8,ch13data); + +/* char: 0xc */ + +static final byte[] ch12data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xf0, +}; + +static final BitmapCharRec ch12 = new BitmapCharRec(4,6,0,2,8,ch12data); + +/* char: 0xb */ + +static final byte[] ch11data = { +(byte) 0xf0,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch11 = new BitmapCharRec(4,8,0,-3,8,ch11data); + +/* char: 0xa */ + +static final byte[] ch10data = { +(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x3e,(byte) 0x20,(byte) 0x50,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch10 = new BitmapCharRec(7,9,0,2,8,ch10data); + +/* char: 0x9 */ + +static final byte[] ch9data = { +(byte) 0x3e,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x88,(byte) 0x98,(byte) 0xa8,(byte) 0xc8,(byte) 0x88, +}; + +static final BitmapCharRec ch9 = new BitmapCharRec(7,9,0,2,8,ch9data); + +/* char: 0x8 */ + +static final byte[] ch8data = { +(byte) 0xfe,(byte) 0x10,(byte) 0x10,(byte) 0xfe,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch8 = new BitmapCharRec(7,6,0,0,8,ch8data); + +/* char: 0x7 */ + +static final byte[] ch7data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch7 = new BitmapCharRec(5,4,-1,-5,8,ch7data); + +/* char: 0x6 */ + +static final byte[] ch6data = { +(byte) 0x20,(byte) 0x20,(byte) 0x3c,(byte) 0x20,(byte) 0x3e,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch6 = new BitmapCharRec(7,9,0,2,8,ch6data); + +/* char: 0x5 */ + +static final byte[] ch5data = { +(byte) 0x22,(byte) 0x22,(byte) 0x3c,(byte) 0x22,(byte) 0x3c,(byte) 0x78,(byte) 0x80,(byte) 0x80,(byte) 0x78, +}; + +static final BitmapCharRec ch5 = new BitmapCharRec(7,9,0,2,8,ch5data); + +/* char: 0x4 */ + +static final byte[] ch4data = { +(byte) 0x10,(byte) 0x10,(byte) 0x1c,(byte) 0x10,(byte) 0x9e,(byte) 0x80,(byte) 0xe0,(byte) 0x80,(byte) 0xf0, +}; + +static final BitmapCharRec ch4 = new BitmapCharRec(7,9,0,2,8,ch4data); + +/* char: 0x3 */ + +static final byte[] ch3data = { +(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x3e,(byte) 0x88,(byte) 0x88,(byte) 0xf8,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch3 = new BitmapCharRec(7,9,0,2,8,ch3data); + +/* char: 0x2 */ + +static final byte[] ch2data = { +(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa, +}; + +static final BitmapCharRec ch2 = new BitmapCharRec(8,12,0,2,8,ch2data); + +/* char: 0x1 */ + +static final byte[] ch1data = { +(byte) 0x10,(byte) 0x38,(byte) 0x7c,(byte) 0xfe,(byte) 0x7c,(byte) 0x38,(byte) 0x10, +}; + +static final BitmapCharRec ch1 = new BitmapCharRec(7,7,0,-1,8,ch1data); + +static final BitmapCharRec[] chars = { +ch0, +ch1, +ch2, +ch3, +ch4, +ch5, +ch6, +ch7, +ch8, +ch9, +ch10, +ch11, +ch12, +ch13, +ch14, +ch15, +ch16, +ch17, +ch18, +ch19, +ch20, +ch21, +ch22, +ch23, +ch24, +ch25, +ch26, +ch27, +ch28, +ch29, +ch30, +ch31, +ch32, +ch33, +ch34, +ch35, +ch36, +ch37, +ch38, +ch39, +ch40, +ch41, +ch42, +ch43, +ch44, +ch45, +ch46, +ch47, +ch48, +ch49, +ch50, +ch51, +ch52, +ch53, +ch54, +ch55, +ch56, +ch57, +ch58, +ch59, +ch60, +ch61, +ch62, +ch63, +ch64, +ch65, +ch66, +ch67, +ch68, +ch69, +ch70, +ch71, +ch72, +ch73, +ch74, +ch75, +ch76, +ch77, +ch78, +ch79, +ch80, +ch81, +ch82, +ch83, +ch84, +ch85, +ch86, +ch87, +ch88, +ch89, +ch90, +ch91, +ch92, +ch93, +ch94, +ch95, +ch96, +ch97, +ch98, +ch99, +ch100, +ch101, +ch102, +ch103, +ch104, +ch105, +ch106, +ch107, +ch108, +ch109, +ch110, +ch111, +ch112, +ch113, +ch114, +ch115, +ch116, +ch117, +ch118, +ch119, +ch120, +ch121, +ch122, +ch123, +ch124, +ch125, +ch126, +ch127, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +ch160, +ch161, +ch162, +ch163, +ch164, +ch165, +ch166, +ch167, +ch168, +ch169, +ch170, +ch171, +ch172, +ch173, +ch174, +ch175, +ch176, +ch177, +ch178, +ch179, +ch180, +ch181, +ch182, +ch183, +ch184, +ch185, +ch186, +ch187, +ch188, +ch189, +ch190, +ch191, +ch192, +ch193, +ch194, +ch195, +ch196, +ch197, +ch198, +ch199, +ch200, +ch201, +ch202, +ch203, +ch204, +ch205, +ch206, +ch207, +ch208, +ch209, +ch210, +ch211, +ch212, +ch213, +ch214, +ch215, +ch216, +ch217, +ch218, +ch219, +ch220, +ch221, +ch222, +ch223, +ch224, +ch225, +ch226, +ch227, +ch228, +ch229, +ch230, +ch231, +ch232, +ch233, +ch234, +ch235, +ch236, +ch237, +ch238, +ch239, +ch240, +ch241, +ch242, +ch243, +ch244, +ch245, +ch246, +ch247, +ch248, +ch249, +ch250, +ch251, +ch252, +ch253, +ch254, +ch255, +}; + + public static final BitmapFontRec glutBitmap8By13 = new BitmapFontRec("-misc-fixed-medium-r-normal--13-120-75-75-C-80-iso8859-1", + 256, + 0, + chars); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmap9x15.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmap9x15.java new file mode 100644 index 000000000..5d357f3f7 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmap9x15.java @@ -0,0 +1,2079 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +class GLUTBitmap9x15 { + +/* GENERATED FILE -- DO NOT MODIFY */ + +static final BitmapCharRec ch0 = new BitmapCharRec(0,0,0,0,9,null); + +static final BitmapCharRec ch32 = new BitmapCharRec(0,0,0,0,9,null); + +static final BitmapCharRec ch127 = new BitmapCharRec(0,0,0,0,9,null); + +static final BitmapCharRec ch160 = new BitmapCharRec(0,0,0,0,9,null); + +/* char: 0xff */ + +static final byte[] ch255data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch255 = new BitmapCharRec(6,14,-1,3,9,ch255data); + +/* char: 0xfe */ + +static final byte[] ch254data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xbc,(byte) 0xc2,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xc2,(byte) 0xbc,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch254 = new BitmapCharRec(7,12,-1,3,9,ch254data); + +/* char: 0xfd */ + +static final byte[] ch253data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch253 = new BitmapCharRec(6,14,-1,3,9,ch253data); + +/* char: 0xfc */ + +static final byte[] ch252data = { +(byte) 0x7a,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch252 = new BitmapCharRec(7,11,-1,0,9,ch252data); + +/* char: 0xfb */ + +static final byte[] ch251data = { +(byte) 0x7a,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x0,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch251 = new BitmapCharRec(7,11,-1,0,9,ch251data); + +/* char: 0xfa */ + +static final byte[] ch250data = { +(byte) 0x7a,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch250 = new BitmapCharRec(7,11,-1,0,9,ch250data); + +/* char: 0xf9 */ + +static final byte[] ch249data = { +(byte) 0x7a,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x0,(byte) 0x18,(byte) 0x20, +}; + +static final BitmapCharRec ch249 = new BitmapCharRec(7,11,-1,0,9,ch249data); + +/* char: 0xf8 */ + +static final byte[] ch248data = { +(byte) 0x80,(byte) 0x7c,(byte) 0xa2,(byte) 0xa2,(byte) 0x92,(byte) 0x8a,(byte) 0x8a,(byte) 0x7c,(byte) 0x2, +}; + +static final BitmapCharRec ch248 = new BitmapCharRec(7,9,-1,1,9,ch248data); + +/* char: 0xf7 */ + +static final byte[] ch247data = { +(byte) 0x10,(byte) 0x38,(byte) 0x10,(byte) 0x0,(byte) 0xfe,(byte) 0x0,(byte) 0x10,(byte) 0x38,(byte) 0x10, +}; + +static final BitmapCharRec ch247 = new BitmapCharRec(7,9,-1,0,9,ch247data); + +/* char: 0xf6 */ + +static final byte[] ch246data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch246 = new BitmapCharRec(7,11,-1,0,9,ch246data); + +/* char: 0xf5 */ + +static final byte[] ch245data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch245 = new BitmapCharRec(7,11,-1,0,9,ch245data); + +/* char: 0xf4 */ + +static final byte[] ch244data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch244 = new BitmapCharRec(7,11,-1,0,9,ch244data); + +/* char: 0xf3 */ + +static final byte[] ch243data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch243 = new BitmapCharRec(7,11,-1,0,9,ch243data); + +/* char: 0xf2 */ + +static final byte[] ch242data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x18,(byte) 0x20, +}; + +static final BitmapCharRec ch242 = new BitmapCharRec(7,11,-1,0,9,ch242data); + +/* char: 0xf1 */ + +static final byte[] ch241data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xc2,(byte) 0xbc,(byte) 0x0,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch241 = new BitmapCharRec(7,11,-1,0,9,ch241data); + +/* char: 0xf0 */ + +static final byte[] ch240data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x8,(byte) 0x50,(byte) 0x30,(byte) 0x48, +}; + +static final BitmapCharRec ch240 = new BitmapCharRec(7,11,-1,0,9,ch240data); + +/* char: 0xef */ + +static final byte[] ch239data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x50,(byte) 0x50, +}; + +static final BitmapCharRec ch239 = new BitmapCharRec(5,11,-2,0,9,ch239data); + +/* char: 0xee */ + +static final byte[] ch238data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch238 = new BitmapCharRec(5,11,-2,0,9,ch238data); + +/* char: 0xed */ + +static final byte[] ch237data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x60,(byte) 0x10, +}; + +static final BitmapCharRec ch237 = new BitmapCharRec(5,11,-2,0,9,ch237data); + +/* char: 0xec */ + +static final byte[] ch236data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x30,(byte) 0x40, +}; + +static final BitmapCharRec ch236 = new BitmapCharRec(5,11,-2,0,9,ch236data); + +/* char: 0xeb */ + +static final byte[] ch235data = { +(byte) 0x7c,(byte) 0x80,(byte) 0x80,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch235 = new BitmapCharRec(7,11,-1,0,9,ch235data); + +/* char: 0xea */ + +static final byte[] ch234data = { +(byte) 0x7c,(byte) 0x80,(byte) 0x80,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch234 = new BitmapCharRec(7,11,-1,0,9,ch234data); + +/* char: 0xe9 */ + +static final byte[] ch233data = { +(byte) 0x7c,(byte) 0x80,(byte) 0x80,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch233 = new BitmapCharRec(7,11,-1,0,9,ch233data); + +/* char: 0xe8 */ + +static final byte[] ch232data = { +(byte) 0x7c,(byte) 0x80,(byte) 0x80,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x18,(byte) 0x20, +}; + +static final BitmapCharRec ch232 = new BitmapCharRec(7,11,-1,0,9,ch232data); + +/* char: 0xe7 */ + +static final byte[] ch231data = { +(byte) 0x30,(byte) 0x48,(byte) 0x18,(byte) 0x7c,(byte) 0x82,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch231 = new BitmapCharRec(7,10,-1,3,9,ch231data); + +/* char: 0xe6 */ + +static final byte[] ch230data = { +(byte) 0x6e,(byte) 0x92,(byte) 0x90,(byte) 0x7c,(byte) 0x12,(byte) 0x92,(byte) 0x6c, +}; + +static final BitmapCharRec ch230 = new BitmapCharRec(7,7,-1,0,9,ch230data); + +/* char: 0xe5 */ + +static final byte[] ch229data = { +(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x7e,(byte) 0x2,(byte) 0x2,(byte) 0x7c,(byte) 0x0,(byte) 0x18,(byte) 0x24,(byte) 0x18, +}; + +static final BitmapCharRec ch229 = new BitmapCharRec(7,11,-1,0,9,ch229data); + +/* char: 0xe4 */ + +static final byte[] ch228data = { +(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x7e,(byte) 0x2,(byte) 0x2,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch228 = new BitmapCharRec(7,11,-1,0,9,ch228data); + +/* char: 0xe3 */ + +static final byte[] ch227data = { +(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x7e,(byte) 0x2,(byte) 0x2,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch227 = new BitmapCharRec(7,11,-1,0,9,ch227data); + +/* char: 0xe2 */ + +static final byte[] ch226data = { +(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x7e,(byte) 0x2,(byte) 0x2,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch226 = new BitmapCharRec(7,11,-1,0,9,ch226data); + +/* char: 0xe1 */ + +static final byte[] ch225data = { +(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x7e,(byte) 0x2,(byte) 0x2,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch225 = new BitmapCharRec(7,11,-1,0,9,ch225data); + +/* char: 0xe0 */ + +static final byte[] ch224data = { +(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x7e,(byte) 0x2,(byte) 0x2,(byte) 0x7c,(byte) 0x0,(byte) 0x0,(byte) 0x18,(byte) 0x20, +}; + +static final BitmapCharRec ch224 = new BitmapCharRec(7,11,-1,0,9,ch224data); + +/* char: 0xdf */ + +static final byte[] ch223data = { +(byte) 0x80,(byte) 0xbc,(byte) 0xc2,(byte) 0x82,(byte) 0x82,(byte) 0xfc,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch223 = new BitmapCharRec(7,9,-1,1,9,ch223data); + +/* char: 0xde */ + +static final byte[] ch222data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfc,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch222 = new BitmapCharRec(7,10,-1,0,9,ch222data); + +/* char: 0xdd */ + +static final byte[] ch221data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x82,(byte) 0x82,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch221 = new BitmapCharRec(7,11,-1,0,9,ch221data); + +/* char: 0xdc */ + +static final byte[] ch220data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch220 = new BitmapCharRec(7,11,-1,0,9,ch220data); + +/* char: 0xdb */ + +static final byte[] ch219data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x0,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch219 = new BitmapCharRec(7,11,-1,0,9,ch219data); + +/* char: 0xda */ + +static final byte[] ch218data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch218 = new BitmapCharRec(7,11,-1,0,9,ch218data); + +/* char: 0xd9 */ + +static final byte[] ch217data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x0,(byte) 0x18,(byte) 0x20, +}; + +static final BitmapCharRec ch217 = new BitmapCharRec(7,11,-1,0,9,ch217data); + +/* char: 0xd8 */ + +static final byte[] ch216data = { +(byte) 0x80,(byte) 0x7c,(byte) 0xc2,(byte) 0xa2,(byte) 0xa2,(byte) 0x92,(byte) 0x92,(byte) 0x8a,(byte) 0x8a,(byte) 0x86,(byte) 0x7c,(byte) 0x2, +}; + +static final BitmapCharRec ch216 = new BitmapCharRec(7,12,-1,1,9,ch216data); + +/* char: 0xd7 */ + +static final byte[] ch215data = { +(byte) 0x82,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x82, +}; + +static final BitmapCharRec ch215 = new BitmapCharRec(7,7,-1,-1,9,ch215data); + +/* char: 0xd6 */ + +static final byte[] ch214data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch214 = new BitmapCharRec(7,11,-1,0,9,ch214data); + +/* char: 0xd5 */ + +static final byte[] ch213data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch213 = new BitmapCharRec(7,11,-1,0,9,ch213data); + +/* char: 0xd4 */ + +static final byte[] ch212data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch212 = new BitmapCharRec(7,11,-1,0,9,ch212data); + +/* char: 0xd3 */ + +static final byte[] ch211data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch211 = new BitmapCharRec(7,11,-1,0,9,ch211data); + +/* char: 0xd2 */ + +static final byte[] ch210data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x0,(byte) 0x18,(byte) 0x20, +}; + +static final BitmapCharRec ch210 = new BitmapCharRec(7,11,-1,0,9,ch210data); + +/* char: 0xd1 */ + +static final byte[] ch209data = { +(byte) 0x82,(byte) 0x86,(byte) 0x8a,(byte) 0x92,(byte) 0x92,(byte) 0xa2,(byte) 0xc2,(byte) 0x82,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch209 = new BitmapCharRec(7,11,-1,0,9,ch209data); + +/* char: 0xd0 */ + +static final byte[] ch208data = { +(byte) 0xfc,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0xf2,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0xfc, +}; + +static final BitmapCharRec ch208 = new BitmapCharRec(7,10,-1,0,9,ch208data); + +/* char: 0xcf */ + +static final byte[] ch207data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x0,(byte) 0x50,(byte) 0x50, +}; + +static final BitmapCharRec ch207 = new BitmapCharRec(5,11,-2,0,9,ch207data); + +/* char: 0xce */ + +static final byte[] ch206data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x0,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch206 = new BitmapCharRec(5,11,-2,0,9,ch206data); + +/* char: 0xcd */ + +static final byte[] ch205data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x0,(byte) 0x60,(byte) 0x10, +}; + +static final BitmapCharRec ch205 = new BitmapCharRec(5,11,-2,0,9,ch205data); + +/* char: 0xcc */ + +static final byte[] ch204data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x0,(byte) 0x30,(byte) 0x40, +}; + +static final BitmapCharRec ch204 = new BitmapCharRec(5,11,-2,0,9,ch204data); + +/* char: 0xcb */ + +static final byte[] ch203data = { +(byte) 0xfe,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x78,(byte) 0x40,(byte) 0x40,(byte) 0xfe,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch203 = new BitmapCharRec(7,11,-1,0,9,ch203data); + +/* char: 0xca */ + +static final byte[] ch202data = { +(byte) 0xfe,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x78,(byte) 0x40,(byte) 0x40,(byte) 0xfe,(byte) 0x0,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch202 = new BitmapCharRec(7,11,-1,0,9,ch202data); + +/* char: 0xc9 */ + +static final byte[] ch201data = { +(byte) 0xfe,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x78,(byte) 0x40,(byte) 0x40,(byte) 0xfe,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch201 = new BitmapCharRec(7,11,-1,0,9,ch201data); + +/* char: 0xc8 */ + +static final byte[] ch200data = { +(byte) 0xfe,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x78,(byte) 0x40,(byte) 0x40,(byte) 0xfe,(byte) 0x0,(byte) 0x18,(byte) 0x20, +}; + +static final BitmapCharRec ch200 = new BitmapCharRec(7,11,-1,0,9,ch200data); + +/* char: 0xc7 */ + +static final byte[] ch199data = { +(byte) 0x30,(byte) 0x48,(byte) 0x18,(byte) 0x7c,(byte) 0x82,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch199 = new BitmapCharRec(7,13,-1,3,9,ch199data); + +/* char: 0xc6 */ + +static final byte[] ch198data = { +(byte) 0x9e,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xfc,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x6e, +}; + +static final BitmapCharRec ch198 = new BitmapCharRec(7,10,-1,0,9,ch198data); + +/* char: 0xc5 */ + +static final byte[] ch197data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x38,(byte) 0x10,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch197 = new BitmapCharRec(7,11,-1,0,9,ch197data); + +/* char: 0xc4 */ + +static final byte[] ch196data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x38,(byte) 0x0,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch196 = new BitmapCharRec(7,11,-1,0,9,ch196data); + +/* char: 0xc3 */ + +static final byte[] ch195data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x38,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch195 = new BitmapCharRec(7,11,-1,0,9,ch195data); + +/* char: 0xc2 */ + +static final byte[] ch194data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x38,(byte) 0x0,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch194 = new BitmapCharRec(7,11,-1,0,9,ch194data); + +/* char: 0xc1 */ + +static final byte[] ch193data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x38,(byte) 0x0,(byte) 0x30,(byte) 0x8, +}; + +static final BitmapCharRec ch193 = new BitmapCharRec(7,11,-1,0,9,ch193data); + +/* char: 0xc0 */ + +static final byte[] ch192data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x38,(byte) 0x0,(byte) 0x18,(byte) 0x20, +}; + +static final BitmapCharRec ch192 = new BitmapCharRec(7,11,-1,0,9,ch192data); + +/* char: 0xbf */ + +static final byte[] ch191data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x10, +}; + +static final BitmapCharRec ch191 = new BitmapCharRec(7,10,-1,0,9,ch191data); + +/* char: 0xbe */ + +static final byte[] ch190data = { +(byte) 0x6,(byte) 0x1a,(byte) 0x12,(byte) 0xa,(byte) 0x66,(byte) 0x92,(byte) 0x10,(byte) 0x20,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch190 = new BitmapCharRec(7,10,-1,0,9,ch190data); + +/* char: 0xbd */ + +static final byte[] ch189data = { +(byte) 0x1e,(byte) 0x10,(byte) 0xc,(byte) 0x2,(byte) 0xf2,(byte) 0x4c,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch189 = new BitmapCharRec(7,10,-1,0,9,ch189data); + +/* char: 0xbc */ + +static final byte[] ch188data = { +(byte) 0x6,(byte) 0x1a,(byte) 0x12,(byte) 0xa,(byte) 0xe6,(byte) 0x42,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch188 = new BitmapCharRec(7,10,-1,0,9,ch188data); + +/* char: 0xbb */ + +static final byte[] ch187data = { +(byte) 0x90,(byte) 0x48,(byte) 0x24,(byte) 0x12,(byte) 0x12,(byte) 0x24,(byte) 0x48,(byte) 0x90, +}; + +static final BitmapCharRec ch187 = new BitmapCharRec(7,8,-1,-1,9,ch187data); + +/* char: 0xba */ + +static final byte[] ch186data = { +(byte) 0xf8,(byte) 0x0,(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch186 = new BitmapCharRec(5,6,-1,-5,9,ch186data); + +/* char: 0xb9 */ + +static final byte[] ch185data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch185 = new BitmapCharRec(3,6,-1,-4,9,ch185data); + +/* char: 0xb8 */ + +static final byte[] ch184data = { +(byte) 0x60,(byte) 0x90,(byte) 0x30, +}; + +static final BitmapCharRec ch184 = new BitmapCharRec(4,3,-2,3,9,ch184data); + +/* char: 0xb7 */ + +static final byte[] ch183data = { +(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch183 = new BitmapCharRec(2,2,-4,-4,9,ch183data); + +/* char: 0xb6 */ + +static final byte[] ch182data = { +(byte) 0xa,(byte) 0xa,(byte) 0xa,(byte) 0xa,(byte) 0xa,(byte) 0x7a,(byte) 0x8a,(byte) 0x8a,(byte) 0x8a,(byte) 0x7e, +}; + +static final BitmapCharRec ch182 = new BitmapCharRec(7,10,-1,0,9,ch182data); + +/* char: 0xb5 */ + +static final byte[] ch181data = { +(byte) 0x80,(byte) 0x80,(byte) 0xba,(byte) 0xc6,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch181 = new BitmapCharRec(7,9,-1,2,9,ch181data); + +/* char: 0xb4 */ + +static final byte[] ch180data = { +(byte) 0xc0,(byte) 0x20, +}; + +static final BitmapCharRec ch180 = new BitmapCharRec(3,2,-3,-9,9,ch180data); + +/* char: 0xb3 */ + +static final byte[] ch179data = { +(byte) 0x60,(byte) 0x90,(byte) 0x10,(byte) 0x20,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch179 = new BitmapCharRec(4,6,-1,-4,9,ch179data); + +/* char: 0xb2 */ + +static final byte[] ch178data = { +(byte) 0xf0,(byte) 0x80,(byte) 0x60,(byte) 0x10,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch178 = new BitmapCharRec(4,6,-1,-4,9,ch178data); + +/* char: 0xb1 */ + +static final byte[] ch177data = { +(byte) 0xfe,(byte) 0x0,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xfe,(byte) 0x10,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch177 = new BitmapCharRec(7,9,-1,-1,9,ch177data); + +/* char: 0xb0 */ + +static final byte[] ch176data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch176 = new BitmapCharRec(4,4,-3,-6,9,ch176data); + +/* char: 0xaf */ + +static final byte[] ch175data = { +(byte) 0xfc, +}; + +static final BitmapCharRec ch175 = new BitmapCharRec(6,1,-1,-9,9,ch175data); + +/* char: 0xae */ + +static final byte[] ch174data = { +(byte) 0x3c,(byte) 0x42,(byte) 0xa5,(byte) 0xa9,(byte) 0xbd,(byte) 0xa5,(byte) 0xb9,(byte) 0x42,(byte) 0x3c, +}; + +static final BitmapCharRec ch174 = new BitmapCharRec(8,9,0,-1,9,ch174data); + +/* char: 0xad */ + +static final byte[] ch173data = { +(byte) 0xfc, +}; + +static final BitmapCharRec ch173 = new BitmapCharRec(6,1,-1,-4,9,ch173data); + +/* char: 0xac */ + +static final byte[] ch172data = { +(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0xfc, +}; + +static final BitmapCharRec ch172 = new BitmapCharRec(6,4,-1,-2,9,ch172data); + +/* char: 0xab */ + +static final byte[] ch171data = { +(byte) 0x12,(byte) 0x24,(byte) 0x48,(byte) 0x90,(byte) 0x90,(byte) 0x48,(byte) 0x24,(byte) 0x12, +}; + +static final BitmapCharRec ch171 = new BitmapCharRec(7,8,-1,-1,9,ch171data); + +/* char: 0xaa */ + +static final byte[] ch170data = { +(byte) 0xf8,(byte) 0x0,(byte) 0x78,(byte) 0x90,(byte) 0x70,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch170 = new BitmapCharRec(5,7,-3,-3,9,ch170data); + +/* char: 0xa9 */ + +static final byte[] ch169data = { +(byte) 0x3c,(byte) 0x42,(byte) 0x99,(byte) 0xa5,(byte) 0xa1,(byte) 0xa5,(byte) 0x99,(byte) 0x42,(byte) 0x3c, +}; + +static final BitmapCharRec ch169 = new BitmapCharRec(8,9,0,-1,9,ch169data); + +/* char: 0xa8 */ + +static final byte[] ch168data = { +(byte) 0xa0,(byte) 0xa0, +}; + +static final BitmapCharRec ch168 = new BitmapCharRec(3,2,-3,-9,9,ch168data); + +/* char: 0xa7 */ + +static final byte[] ch167data = { +(byte) 0x70,(byte) 0x88,(byte) 0x8,(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x80,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch167 = new BitmapCharRec(5,11,-2,1,9,ch167data); + +/* char: 0xa6 */ + +static final byte[] ch166data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch166 = new BitmapCharRec(1,11,-4,1,9,ch166data); + +/* char: 0xa5 */ + +static final byte[] ch165data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x7c,(byte) 0x10,(byte) 0x7c,(byte) 0x28,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch165 = new BitmapCharRec(7,10,-1,0,9,ch165data); + +/* char: 0xa4 */ + +static final byte[] ch164data = { +(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x44,(byte) 0x7c,(byte) 0x82, +}; + +static final BitmapCharRec ch164 = new BitmapCharRec(7,6,-1,-3,9,ch164data); + +/* char: 0xa3 */ + +static final byte[] ch163data = { +(byte) 0x5c,(byte) 0xa2,(byte) 0x60,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x22,(byte) 0x1c, +}; + +static final BitmapCharRec ch163 = new BitmapCharRec(7,10,-1,0,9,ch163data); + +/* char: 0xa2 */ + +static final byte[] ch162data = { +(byte) 0x40,(byte) 0x78,(byte) 0xa4,(byte) 0xa0,(byte) 0x90,(byte) 0x94,(byte) 0x78,(byte) 0x8, +}; + +static final BitmapCharRec ch162 = new BitmapCharRec(6,8,-1,0,9,ch162data); + +/* char: 0xa1 */ + +static final byte[] ch161data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch161 = new BitmapCharRec(1,11,-4,0,9,ch161data); + +/* char: 0x7e '~' */ + +static final byte[] ch126data = { +(byte) 0x8c,(byte) 0x92,(byte) 0x62, +}; + +static final BitmapCharRec ch126 = new BitmapCharRec(7,3,-1,-7,9,ch126data); + +/* char: 0x7d '}' */ + +static final byte[] ch125data = { +(byte) 0xe0,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x20,(byte) 0x18,(byte) 0x18,(byte) 0x20,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xe0, +}; + +static final BitmapCharRec ch125 = new BitmapCharRec(5,12,-1,1,9,ch125data); + +/* char: 0x7c '|' */ + +static final byte[] ch124data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch124 = new BitmapCharRec(1,12,-4,1,9,ch124data); + +/* char: 0x7b '{' */ + +static final byte[] ch123data = { +(byte) 0x38,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0xc0,(byte) 0xc0,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x38, +}; + +static final BitmapCharRec ch123 = new BitmapCharRec(5,12,-3,1,9,ch123data); + +/* char: 0x7a 'z' */ + +static final byte[] ch122data = { +(byte) 0xfe,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0xfe, +}; + +static final BitmapCharRec ch122 = new BitmapCharRec(7,7,-1,0,9,ch122data); + +/* char: 0x79 'y' */ + +static final byte[] ch121data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch121 = new BitmapCharRec(6,10,-1,3,9,ch121data); + +/* char: 0x78 'x' */ + +static final byte[] ch120data = { +(byte) 0x82,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x82, +}; + +static final BitmapCharRec ch120 = new BitmapCharRec(7,7,-1,0,9,ch120data); + +/* char: 0x77 'w' */ + +static final byte[] ch119data = { +(byte) 0x44,(byte) 0xaa,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch119 = new BitmapCharRec(7,7,-1,0,9,ch119data); + +/* char: 0x76 'v' */ + +static final byte[] ch118data = { +(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch118 = new BitmapCharRec(7,7,-1,0,9,ch118data); + +/* char: 0x75 'u' */ + +static final byte[] ch117data = { +(byte) 0x7a,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch117 = new BitmapCharRec(7,7,-1,0,9,ch117data); + +/* char: 0x74 't' */ + +static final byte[] ch116data = { +(byte) 0x1c,(byte) 0x22,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xfc,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch116 = new BitmapCharRec(7,9,-1,0,9,ch116data); + +/* char: 0x73 's' */ + +static final byte[] ch115data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x2,(byte) 0x7c,(byte) 0x80,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch115 = new BitmapCharRec(7,7,-1,0,9,ch115data); + +/* char: 0x72 'r' */ + +static final byte[] ch114data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x42,(byte) 0x62,(byte) 0x9c, +}; + +static final BitmapCharRec ch114 = new BitmapCharRec(7,7,-1,0,9,ch114data); + +/* char: 0x71 'q' */ + +static final byte[] ch113data = { +(byte) 0x2,(byte) 0x2,(byte) 0x2,(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x86,(byte) 0x7a, +}; + +static final BitmapCharRec ch113 = new BitmapCharRec(7,10,-1,3,9,ch113data); + +/* char: 0x70 'p' */ + +static final byte[] ch112data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xbc,(byte) 0xc2,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xc2,(byte) 0xbc, +}; + +static final BitmapCharRec ch112 = new BitmapCharRec(7,10,-1,3,9,ch112data); + +/* char: 0x6f 'o' */ + +static final byte[] ch111data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch111 = new BitmapCharRec(7,7,-1,0,9,ch111data); + +/* char: 0x6e 'n' */ + +static final byte[] ch110data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xc2,(byte) 0xbc, +}; + +static final BitmapCharRec ch110 = new BitmapCharRec(7,7,-1,0,9,ch110data); + +/* char: 0x6d 'm' */ + +static final byte[] ch109data = { +(byte) 0x82,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0xec, +}; + +static final BitmapCharRec ch109 = new BitmapCharRec(7,7,-1,0,9,ch109data); + +/* char: 0x6c 'l' */ + +static final byte[] ch108data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xe0, +}; + +static final BitmapCharRec ch108 = new BitmapCharRec(5,10,-2,0,9,ch108data); + +/* char: 0x6b 'k' */ + +static final byte[] ch107data = { +(byte) 0x82,(byte) 0x8c,(byte) 0xb0,(byte) 0xc0,(byte) 0xb0,(byte) 0x8c,(byte) 0x82,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch107 = new BitmapCharRec(7,10,-1,0,9,ch107data); + +/* char: 0x6a 'j' */ + +static final byte[] ch106data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0x1c,(byte) 0x0,(byte) 0x0,(byte) 0xc, +}; + +static final BitmapCharRec ch106 = new BitmapCharRec(6,13,-1,3,9,ch106data); + +/* char: 0x69 'i' */ + +static final byte[] ch105data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x60, +}; + +static final BitmapCharRec ch105 = new BitmapCharRec(5,10,-2,0,9,ch105data); + +/* char: 0x68 'h' */ + +static final byte[] ch104data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xc2,(byte) 0xbc,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch104 = new BitmapCharRec(7,10,-1,0,9,ch104data); + +/* char: 0x67 'g' */ + +static final byte[] ch103data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x80,(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x7a, +}; + +static final BitmapCharRec ch103 = new BitmapCharRec(7,10,-1,3,9,ch103data); + +/* char: 0x66 'f' */ + +static final byte[] ch102data = { +(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x22,(byte) 0x22,(byte) 0x1c, +}; + +static final BitmapCharRec ch102 = new BitmapCharRec(7,10,-1,0,9,ch102data); + +/* char: 0x65 'e' */ + +static final byte[] ch101data = { +(byte) 0x7c,(byte) 0x80,(byte) 0x80,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch101 = new BitmapCharRec(7,7,-1,0,9,ch101data); + +/* char: 0x64 'd' */ + +static final byte[] ch100data = { +(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x86,(byte) 0x7a,(byte) 0x2,(byte) 0x2,(byte) 0x2, +}; + +static final BitmapCharRec ch100 = new BitmapCharRec(7,10,-1,0,9,ch100data); + +/* char: 0x63 'c' */ + +static final byte[] ch99data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch99 = new BitmapCharRec(7,7,-1,0,9,ch99data); + +/* char: 0x62 'b' */ + +static final byte[] ch98data = { +(byte) 0xbc,(byte) 0xc2,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xc2,(byte) 0xbc,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch98 = new BitmapCharRec(7,10,-1,0,9,ch98data); + +/* char: 0x61 'a' */ + +static final byte[] ch97data = { +(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x7e,(byte) 0x2,(byte) 0x2,(byte) 0x7c, +}; + +static final BitmapCharRec ch97 = new BitmapCharRec(7,7,-1,0,9,ch97data); + +/* char: 0x60 '`' */ + +static final byte[] ch96data = { +(byte) 0x10,(byte) 0x20,(byte) 0x40,(byte) 0xc0, +}; + +static final BitmapCharRec ch96 = new BitmapCharRec(4,4,-3,-6,9,ch96data); + +/* char: 0x5f '_' */ + +static final byte[] ch95data = { +(byte) 0xff, +}; + +static final BitmapCharRec ch95 = new BitmapCharRec(8,1,0,1,9,ch95data); + +/* char: 0x5e '^' */ + +static final byte[] ch94data = { +(byte) 0x82,(byte) 0x44,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch94 = new BitmapCharRec(7,4,-1,-6,9,ch94data); + +/* char: 0x5d ']' */ + +static final byte[] ch93data = { +(byte) 0xf0,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xf0, +}; + +static final BitmapCharRec ch93 = new BitmapCharRec(4,12,-2,1,9,ch93data); + +/* char: 0x5c '\' */ + +static final byte[] ch92data = { +(byte) 0x2,(byte) 0x4,(byte) 0x4,(byte) 0x8,(byte) 0x10,(byte) 0x10,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch92 = new BitmapCharRec(7,10,-1,0,9,ch92data); + +/* char: 0x5b '[' */ + +static final byte[] ch91data = { +(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf0, +}; + +static final BitmapCharRec ch91 = new BitmapCharRec(4,12,-3,1,9,ch91data); + +/* char: 0x5a 'Z' */ + +static final byte[] ch90data = { +(byte) 0xfe,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0x2,(byte) 0xfe, +}; + +static final BitmapCharRec ch90 = new BitmapCharRec(7,10,-1,0,9,ch90data); + +/* char: 0x59 'Y' */ + +static final byte[] ch89data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch89 = new BitmapCharRec(7,10,-1,0,9,ch89data); + +/* char: 0x58 'X' */ + +static final byte[] ch88data = { +(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch88 = new BitmapCharRec(7,10,-1,0,9,ch88data); + +/* char: 0x57 'W' */ + +static final byte[] ch87data = { +(byte) 0x44,(byte) 0xaa,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch87 = new BitmapCharRec(7,10,-1,0,9,ch87data); + +/* char: 0x56 'V' */ + +static final byte[] ch86data = { +(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x82,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch86 = new BitmapCharRec(7,10,-1,0,9,ch86data); + +/* char: 0x55 'U' */ + +static final byte[] ch85data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch85 = new BitmapCharRec(7,10,-1,0,9,ch85data); + +/* char: 0x54 'T' */ + +static final byte[] ch84data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xfe, +}; + +static final BitmapCharRec ch84 = new BitmapCharRec(7,10,-1,0,9,ch84data); + +/* char: 0x53 'S' */ + +static final byte[] ch83data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x2,(byte) 0xc,(byte) 0x70,(byte) 0x80,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch83 = new BitmapCharRec(7,10,-1,0,9,ch83data); + +/* char: 0x52 'R' */ + +static final byte[] ch82data = { +(byte) 0x82,(byte) 0x82,(byte) 0x84,(byte) 0x88,(byte) 0x90,(byte) 0xfc,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfc, +}; + +static final BitmapCharRec ch82 = new BitmapCharRec(7,10,-1,0,9,ch82data); + +/* char: 0x51 'Q' */ + +static final byte[] ch81data = { +(byte) 0x6,(byte) 0x8,(byte) 0x7c,(byte) 0x92,(byte) 0xa2,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch81 = new BitmapCharRec(7,12,-1,2,9,ch81data); + +/* char: 0x50 'P' */ + +static final byte[] ch80data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfc, +}; + +static final BitmapCharRec ch80 = new BitmapCharRec(7,10,-1,0,9,ch80data); + +/* char: 0x4f 'O' */ + +static final byte[] ch79data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch79 = new BitmapCharRec(7,10,-1,0,9,ch79data); + +/* char: 0x4e 'N' */ + +static final byte[] ch78data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x86,(byte) 0x8a,(byte) 0x92,(byte) 0xa2,(byte) 0xc2,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch78 = new BitmapCharRec(7,10,-1,0,9,ch78data); + +/* char: 0x4d 'M' */ + +static final byte[] ch77data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x92,(byte) 0x92,(byte) 0xaa,(byte) 0xaa,(byte) 0xc6,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch77 = new BitmapCharRec(7,10,-1,0,9,ch77data); + +/* char: 0x4c 'L' */ + +static final byte[] ch76data = { +(byte) 0xfe,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch76 = new BitmapCharRec(7,10,-1,0,9,ch76data); + +/* char: 0x4b 'K' */ + +static final byte[] ch75data = { +(byte) 0x82,(byte) 0x84,(byte) 0x88,(byte) 0x90,(byte) 0xa0,(byte) 0xe0,(byte) 0x90,(byte) 0x88,(byte) 0x84,(byte) 0x82, +}; + +static final BitmapCharRec ch75 = new BitmapCharRec(7,10,-1,0,9,ch75data); + +/* char: 0x4a 'J' */ + +static final byte[] ch74data = { +(byte) 0x78,(byte) 0x84,(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0x1e, +}; + +static final BitmapCharRec ch74 = new BitmapCharRec(7,10,-1,0,9,ch74data); + +/* char: 0x49 'I' */ + +static final byte[] ch73data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8, +}; + +static final BitmapCharRec ch73 = new BitmapCharRec(5,10,-2,0,9,ch73data); + +/* char: 0x48 'H' */ + +static final byte[] ch72data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch72 = new BitmapCharRec(7,10,-1,0,9,ch72data); + +/* char: 0x47 'G' */ + +static final byte[] ch71data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x8e,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch71 = new BitmapCharRec(7,10,-1,0,9,ch71data); + +/* char: 0x46 'F' */ + +static final byte[] ch70data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x78,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xfe, +}; + +static final BitmapCharRec ch70 = new BitmapCharRec(7,10,-1,0,9,ch70data); + +/* char: 0x45 'E' */ + +static final byte[] ch69data = { +(byte) 0xfe,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x78,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xfe, +}; + +static final BitmapCharRec ch69 = new BitmapCharRec(7,10,-1,0,9,ch69data); + +/* char: 0x44 'D' */ + +static final byte[] ch68data = { +(byte) 0xfc,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0xfc, +}; + +static final BitmapCharRec ch68 = new BitmapCharRec(7,10,-1,0,9,ch68data); + +/* char: 0x43 'C' */ + +static final byte[] ch67data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch67 = new BitmapCharRec(7,10,-1,0,9,ch67data); + +/* char: 0x42 'B' */ + +static final byte[] ch66data = { +(byte) 0xfc,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0x7c,(byte) 0x42,(byte) 0x42,(byte) 0x42,(byte) 0xfc, +}; + +static final BitmapCharRec ch66 = new BitmapCharRec(7,10,-1,0,9,ch66data); + +/* char: 0x41 'A' */ + +static final byte[] ch65data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch65 = new BitmapCharRec(7,10,-1,0,9,ch65data); + +/* char: 0x40 '@' */ + +static final byte[] ch64data = { +(byte) 0x7c,(byte) 0x80,(byte) 0x80,(byte) 0x9a,(byte) 0xa6,(byte) 0xa2,(byte) 0x9e,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch64 = new BitmapCharRec(7,10,-1,0,9,ch64data); + +/* char: 0x3f '?' */ + +static final byte[] ch63data = { +(byte) 0x10,(byte) 0x0,(byte) 0x10,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0x2,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch63 = new BitmapCharRec(7,10,-1,0,9,ch63data); + +/* char: 0x3e '>' */ + +static final byte[] ch62data = { +(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x8,(byte) 0x10,(byte) 0x20,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch62 = new BitmapCharRec(5,10,-2,0,9,ch62data); + +/* char: 0x3d '=' */ + +static final byte[] ch61data = { +(byte) 0xfe,(byte) 0x0,(byte) 0x0,(byte) 0xfe, +}; + +static final BitmapCharRec ch61 = new BitmapCharRec(7,4,-1,-2,9,ch61data); + +/* char: 0x3c '<' */ + +static final byte[] ch60data = { +(byte) 0x8,(byte) 0x10,(byte) 0x20,(byte) 0x40,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch60 = new BitmapCharRec(5,10,-2,0,9,ch60data); + +/* char: 0x3b ';' */ + +static final byte[] ch59data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch59 = new BitmapCharRec(2,10,-4,3,9,ch59data); + +/* char: 0x3a ':' */ + +static final byte[] ch58data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch58 = new BitmapCharRec(2,7,-4,0,9,ch58data); + +/* char: 0x39 '9' */ + +static final byte[] ch57data = { +(byte) 0x78,(byte) 0x4,(byte) 0x2,(byte) 0x2,(byte) 0x7a,(byte) 0x86,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch57 = new BitmapCharRec(7,10,-1,0,9,ch57data); + +/* char: 0x38 '8' */ + +static final byte[] ch56data = { +(byte) 0x38,(byte) 0x44,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x38,(byte) 0x44,(byte) 0x82,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch56 = new BitmapCharRec(7,10,-1,0,9,ch56data); + +/* char: 0x37 '7' */ + +static final byte[] ch55data = { +(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0x2,(byte) 0x2,(byte) 0xfe, +}; + +static final BitmapCharRec ch55 = new BitmapCharRec(7,10,-1,0,9,ch55data); + +/* char: 0x36 '6' */ + +static final byte[] ch54data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xc2,(byte) 0xbc,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x3c, +}; + +static final BitmapCharRec ch54 = new BitmapCharRec(7,10,-1,0,9,ch54data); + +/* char: 0x35 '5' */ + +static final byte[] ch53data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x2,(byte) 0x2,(byte) 0x2,(byte) 0xc2,(byte) 0xbc,(byte) 0x80,(byte) 0x80,(byte) 0xfe, +}; + +static final BitmapCharRec ch53 = new BitmapCharRec(7,10,-1,0,9,ch53data); + +/* char: 0x34 '4' */ + +static final byte[] ch52data = { +(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0xfe,(byte) 0x84,(byte) 0x44,(byte) 0x24,(byte) 0x14,(byte) 0xc,(byte) 0x4, +}; + +static final BitmapCharRec ch52 = new BitmapCharRec(7,10,-1,0,9,ch52data); + +/* char: 0x33 '3' */ + +static final byte[] ch51data = { +(byte) 0x7c,(byte) 0x82,(byte) 0x2,(byte) 0x2,(byte) 0x2,(byte) 0x1c,(byte) 0x8,(byte) 0x4,(byte) 0x2,(byte) 0xfe, +}; + +static final BitmapCharRec ch51 = new BitmapCharRec(7,10,-1,0,9,ch51data); + +/* char: 0x32 '2' */ + +static final byte[] ch50data = { +(byte) 0xfe,(byte) 0x80,(byte) 0x40,(byte) 0x30,(byte) 0x8,(byte) 0x4,(byte) 0x2,(byte) 0x82,(byte) 0x82,(byte) 0x7c, +}; + +static final BitmapCharRec ch50 = new BitmapCharRec(7,10,-1,0,9,ch50data); + +/* char: 0x31 '1' */ + +static final byte[] ch49data = { +(byte) 0xfe,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x90,(byte) 0x50,(byte) 0x30,(byte) 0x10, +}; + +static final BitmapCharRec ch49 = new BitmapCharRec(7,10,-1,0,9,ch49data); + +/* char: 0x30 '0' */ + +static final byte[] ch48data = { +(byte) 0x38,(byte) 0x44,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch48 = new BitmapCharRec(7,10,-1,0,9,ch48data); + +/* char: 0x2f '/' */ + +static final byte[] ch47data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0x4,(byte) 0x2, +}; + +static final BitmapCharRec ch47 = new BitmapCharRec(7,10,-1,0,9,ch47data); + +/* char: 0x2e '.' */ + +static final byte[] ch46data = { +(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch46 = new BitmapCharRec(2,2,-4,0,9,ch46data); + +/* char: 0x2d '-' */ + +static final byte[] ch45data = { +(byte) 0xfe, +}; + +static final BitmapCharRec ch45 = new BitmapCharRec(7,1,-1,-4,9,ch45data); + +/* char: 0x2c ',' */ + +static final byte[] ch44data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch44 = new BitmapCharRec(2,5,-4,3,9,ch44data); + +/* char: 0x2b '+' */ + +static final byte[] ch43data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xfe,(byte) 0x10,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch43 = new BitmapCharRec(7,7,-1,-1,9,ch43data); + +/* char: 0x2a '*' */ + +static final byte[] ch42data = { +(byte) 0x10,(byte) 0x92,(byte) 0x54,(byte) 0x38,(byte) 0x54,(byte) 0x92,(byte) 0x10, +}; + +static final BitmapCharRec ch42 = new BitmapCharRec(7,7,-1,-1,9,ch42data); + +/* char: 0x29 ')' */ + +static final byte[] ch41data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch41 = new BitmapCharRec(3,12,-3,1,9,ch41data); + +/* char: 0x28 '(' */ + +static final byte[] ch40data = { +(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch40 = new BitmapCharRec(3,12,-3,1,9,ch40data); + +/* char: 0x27 ''' */ + +static final byte[] ch39data = { +(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x30, +}; + +static final BitmapCharRec ch39 = new BitmapCharRec(4,4,-3,-6,9,ch39data); + +/* char: 0x26 '&' */ + +static final byte[] ch38data = { +(byte) 0x62,(byte) 0x94,(byte) 0x88,(byte) 0x94,(byte) 0x62,(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch38 = new BitmapCharRec(7,10,-1,0,9,ch38data); + +/* char: 0x25 '%' */ + +static final byte[] ch37data = { +(byte) 0x84,(byte) 0x4a,(byte) 0x4a,(byte) 0x24,(byte) 0x10,(byte) 0x10,(byte) 0x48,(byte) 0xa4,(byte) 0xa4,(byte) 0x42, +}; + +static final BitmapCharRec ch37 = new BitmapCharRec(7,10,-1,0,9,ch37data); + +/* char: 0x24 '$' */ + +static final byte[] ch36data = { +(byte) 0x10,(byte) 0x7c,(byte) 0x92,(byte) 0x12,(byte) 0x12,(byte) 0x14,(byte) 0x38,(byte) 0x50,(byte) 0x90,(byte) 0x92,(byte) 0x7c,(byte) 0x10, +}; + +static final BitmapCharRec ch36 = new BitmapCharRec(7,12,-1,1,9,ch36data); + +/* char: 0x23 '#' */ + +static final byte[] ch35data = { +(byte) 0x48,(byte) 0x48,(byte) 0xfc,(byte) 0x48,(byte) 0x48,(byte) 0xfc,(byte) 0x48,(byte) 0x48, +}; + +static final BitmapCharRec ch35 = new BitmapCharRec(6,8,-1,-1,9,ch35data); + +/* char: 0x22 '"' */ + +static final byte[] ch34data = { +(byte) 0x90,(byte) 0x90,(byte) 0x90, +}; + +static final BitmapCharRec ch34 = new BitmapCharRec(4,3,-3,-7,9,ch34data); + +/* char: 0x21 '!' */ + +static final byte[] ch33data = { +(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch33 = new BitmapCharRec(1,11,-4,0,9,ch33data); + +/* char: 0x1f */ + +static final byte[] ch31data = { +(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch31 = new BitmapCharRec(2,2,-4,-2,9,ch31data); + +/* char: 0x1e */ + +static final byte[] ch30data = { +(byte) 0x5c,(byte) 0xa2,(byte) 0x60,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x22,(byte) 0x1c, +}; + +static final BitmapCharRec ch30 = new BitmapCharRec(7,10,-1,0,9,ch30data); + +/* char: 0x1d */ + +static final byte[] ch29data = { +(byte) 0x80,(byte) 0x40,(byte) 0xfe,(byte) 0x10,(byte) 0xfe,(byte) 0x4,(byte) 0x2, +}; + +static final BitmapCharRec ch29 = new BitmapCharRec(7,7,-1,0,9,ch29data); + +/* char: 0x1c */ + +static final byte[] ch28data = { +(byte) 0x44,(byte) 0x24,(byte) 0x24,(byte) 0x24,(byte) 0x24,(byte) 0x24,(byte) 0xfe, +}; + +static final BitmapCharRec ch28 = new BitmapCharRec(7,7,-1,0,9,ch28data); + +/* char: 0x1b */ + +static final byte[] ch27data = { +(byte) 0xfe,(byte) 0x0,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x8,(byte) 0x10,(byte) 0x20,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch27 = new BitmapCharRec(7,12,-1,2,9,ch27data); + +/* char: 0x1a */ + +static final byte[] ch26data = { +(byte) 0xfc,(byte) 0x0,(byte) 0x4,(byte) 0x8,(byte) 0x10,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x4, +}; + +static final BitmapCharRec ch26 = new BitmapCharRec(6,12,-2,2,9,ch26data); + +/* char: 0x19 */ + +static final byte[] ch25data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch25 = new BitmapCharRec(1,15,-4,3,9,ch25data); + +/* char: 0x18 */ + +static final byte[] ch24data = { +(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0xff,(byte) 0x80, +}; + +static final BitmapCharRec ch24 = new BitmapCharRec(9,7,0,3,9,ch24data); + +/* char: 0x17 */ + +static final byte[] ch23data = { +(byte) 0xff,(byte) 0x80,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0, +(byte) 0x8,(byte) 0x0, +}; + +static final BitmapCharRec ch23 = new BitmapCharRec(9,9,0,-3,9,ch23data); + +/* char: 0x16 */ + +static final byte[] ch22data = { +(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0xf8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8, +}; + +static final BitmapCharRec ch22 = new BitmapCharRec(5,15,0,3,9,ch22data); + +/* char: 0x15 */ + +static final byte[] ch21data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch21 = new BitmapCharRec(5,15,-4,3,9,ch21data); + +/* char: 0x14 */ + +static final byte[] ch20data = { +(byte) 0xff,(byte) 0x80, +}; + +static final BitmapCharRec ch20 = new BitmapCharRec(9,1,0,1,9,ch20data); + +/* char: 0x13 */ + +static final byte[] ch19data = { +(byte) 0xff,(byte) 0x80, +}; + +static final BitmapCharRec ch19 = new BitmapCharRec(9,1,0,-1,9,ch19data); + +/* char: 0x12 */ + +static final byte[] ch18data = { +(byte) 0xff,(byte) 0x80, +}; + +static final BitmapCharRec ch18 = new BitmapCharRec(9,1,0,-3,9,ch18data); + +/* char: 0x11 */ + +static final byte[] ch17data = { +(byte) 0xff,(byte) 0x80, +}; + +static final BitmapCharRec ch17 = new BitmapCharRec(9,1,0,-5,9,ch17data); + +/* char: 0x10 */ + +static final byte[] ch16data = { +(byte) 0xff,(byte) 0x80, +}; + +static final BitmapCharRec ch16 = new BitmapCharRec(9,1,0,-7,9,ch16data); + +/* char: 0xf */ + +static final byte[] ch15data = { +(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0x8,(byte) 0x0, +(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0, +}; + +static final BitmapCharRec ch15 = new BitmapCharRec(9,15,0,3,9,ch15data); + +/* char: 0xe */ + +static final byte[] ch14data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch14 = new BitmapCharRec(5,9,-4,-3,9,ch14data); + +/* char: 0xd */ + +static final byte[] ch13data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8, +}; + +static final BitmapCharRec ch13 = new BitmapCharRec(5,7,-4,3,9,ch13data); + +/* char: 0xc */ + +static final byte[] ch12data = { +(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0xf8, +}; + +static final BitmapCharRec ch12 = new BitmapCharRec(5,7,0,3,9,ch12data); + +/* char: 0xb */ + +static final byte[] ch11data = { +(byte) 0xf8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8, +}; + +static final BitmapCharRec ch11 = new BitmapCharRec(5,9,0,-3,9,ch11data); + +/* char: 0xa */ + +static final byte[] ch10data = { +(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x3e,(byte) 0x0,(byte) 0x20,(byte) 0x50,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch10 = new BitmapCharRec(7,10,-1,2,9,ch10data); + +/* char: 0x9 */ + +static final byte[] ch9data = { +(byte) 0x3e,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x88,(byte) 0x98,(byte) 0xa8,(byte) 0xc8,(byte) 0x88, +}; + +static final BitmapCharRec ch9 = new BitmapCharRec(7,10,-1,2,9,ch9data); + +/* char: 0x8 */ + +static final byte[] ch8data = { +(byte) 0xfe,(byte) 0x10,(byte) 0x10,(byte) 0xfe,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch8 = new BitmapCharRec(7,6,-1,0,9,ch8data); + +/* char: 0x7 */ + +static final byte[] ch7data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch7 = new BitmapCharRec(5,4,-2,-6,9,ch7data); + +/* char: 0x6 */ + +static final byte[] ch6data = { +(byte) 0x20,(byte) 0x20,(byte) 0x3c,(byte) 0x20,(byte) 0x3e,(byte) 0x0,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch6 = new BitmapCharRec(7,10,-1,2,9,ch6data); + +/* char: 0x5 */ + +static final byte[] ch5data = { +(byte) 0x22,(byte) 0x22,(byte) 0x3c,(byte) 0x22,(byte) 0x3c,(byte) 0x0,(byte) 0x78,(byte) 0x80,(byte) 0x80,(byte) 0x78, +}; + +static final BitmapCharRec ch5 = new BitmapCharRec(7,10,-1,2,9,ch5data); + +/* char: 0x4 */ + +static final byte[] ch4data = { +(byte) 0x10,(byte) 0x10,(byte) 0x1c,(byte) 0x10,(byte) 0x1e,(byte) 0x80,(byte) 0x80,(byte) 0xe0,(byte) 0x80,(byte) 0xf0, +}; + +static final BitmapCharRec ch4 = new BitmapCharRec(7,10,-1,2,9,ch4data); + +/* char: 0x3 */ + +static final byte[] ch3data = { +(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x3e,(byte) 0x0,(byte) 0x88,(byte) 0x88,(byte) 0xf8,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch3 = new BitmapCharRec(7,10,-1,2,9,ch3data); + +/* char: 0x2 */ + +static final byte[] ch2data = { +(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa,(byte) 0x55,(byte) 0xaa, +}; + +static final BitmapCharRec ch2 = new BitmapCharRec(8,14,0,3,9,ch2data); + +/* char: 0x1 */ + +static final byte[] ch1data = { +(byte) 0x10,(byte) 0x38,(byte) 0x7c,(byte) 0xfe,(byte) 0x7c,(byte) 0x38,(byte) 0x10, +}; + +static final BitmapCharRec ch1 = new BitmapCharRec(7,7,-1,0,9,ch1data); + +static final BitmapCharRec[] chars = { +ch0, +ch1, +ch2, +ch3, +ch4, +ch5, +ch6, +ch7, +ch8, +ch9, +ch10, +ch11, +ch12, +ch13, +ch14, +ch15, +ch16, +ch17, +ch18, +ch19, +ch20, +ch21, +ch22, +ch23, +ch24, +ch25, +ch26, +ch27, +ch28, +ch29, +ch30, +ch31, +ch32, +ch33, +ch34, +ch35, +ch36, +ch37, +ch38, +ch39, +ch40, +ch41, +ch42, +ch43, +ch44, +ch45, +ch46, +ch47, +ch48, +ch49, +ch50, +ch51, +ch52, +ch53, +ch54, +ch55, +ch56, +ch57, +ch58, +ch59, +ch60, +ch61, +ch62, +ch63, +ch64, +ch65, +ch66, +ch67, +ch68, +ch69, +ch70, +ch71, +ch72, +ch73, +ch74, +ch75, +ch76, +ch77, +ch78, +ch79, +ch80, +ch81, +ch82, +ch83, +ch84, +ch85, +ch86, +ch87, +ch88, +ch89, +ch90, +ch91, +ch92, +ch93, +ch94, +ch95, +ch96, +ch97, +ch98, +ch99, +ch100, +ch101, +ch102, +ch103, +ch104, +ch105, +ch106, +ch107, +ch108, +ch109, +ch110, +ch111, +ch112, +ch113, +ch114, +ch115, +ch116, +ch117, +ch118, +ch119, +ch120, +ch121, +ch122, +ch123, +ch124, +ch125, +ch126, +ch127, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +ch160, +ch161, +ch162, +ch163, +ch164, +ch165, +ch166, +ch167, +ch168, +ch169, +ch170, +ch171, +ch172, +ch173, +ch174, +ch175, +ch176, +ch177, +ch178, +ch179, +ch180, +ch181, +ch182, +ch183, +ch184, +ch185, +ch186, +ch187, +ch188, +ch189, +ch190, +ch191, +ch192, +ch193, +ch194, +ch195, +ch196, +ch197, +ch198, +ch199, +ch200, +ch201, +ch202, +ch203, +ch204, +ch205, +ch206, +ch207, +ch208, +ch209, +ch210, +ch211, +ch212, +ch213, +ch214, +ch215, +ch216, +ch217, +ch218, +ch219, +ch220, +ch221, +ch222, +ch223, +ch224, +ch225, +ch226, +ch227, +ch228, +ch229, +ch230, +ch231, +ch232, +ch233, +ch234, +ch235, +ch236, +ch237, +ch238, +ch239, +ch240, +ch241, +ch242, +ch243, +ch244, +ch245, +ch246, +ch247, +ch248, +ch249, +ch250, +ch251, +ch252, +ch253, +ch254, +ch255, +}; + + public static final BitmapFontRec glutBitmap9By15 = new BitmapFontRec("-misc-fixed-medium-r-normal--15-140-75-75-C-90-iso8859-1", + 256, + 0, + chars); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapHelvetica10.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapHelvetica10.java new file mode 100644 index 000000000..b9c7e6e50 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapHelvetica10.java @@ -0,0 +1,1798 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +class GLUTBitmapHelvetica10 { + +/* GENERATED FILE -- DO NOT MODIFY */ + +/* char: 0xff */ + +static final byte[] ch255data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x60,(byte) 0xa0,(byte) 0xa0,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch255 = new BitmapCharRec(4,10,0,2,5,ch255data); + +/* char: 0xfe */ + +static final byte[] ch254data = { +(byte) 0x80,(byte) 0x80,(byte) 0xb0,(byte) 0xc8,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch254 = new BitmapCharRec(5,10,0,2,6,ch254data); + +/* char: 0xfd */ + +static final byte[] ch253data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x60,(byte) 0xa0,(byte) 0xa0,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch253 = new BitmapCharRec(4,11,0,2,5,ch253data); + +/* char: 0xfc */ + +static final byte[] ch252data = { +(byte) 0x70,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch252 = new BitmapCharRec(4,8,0,0,5,ch252data); + +/* char: 0xfb */ + +static final byte[] ch251data = { +(byte) 0x70,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch251 = new BitmapCharRec(4,9,0,0,5,ch251data); + +/* char: 0xfa */ + +static final byte[] ch250data = { +(byte) 0x70,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch250 = new BitmapCharRec(4,9,0,0,5,ch250data); + +/* char: 0xf9 */ + +static final byte[] ch249data = { +(byte) 0x70,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch249 = new BitmapCharRec(4,9,0,0,5,ch249data); + +/* char: 0xf8 */ + +static final byte[] ch248data = { +(byte) 0x70,(byte) 0x88,(byte) 0xc8,(byte) 0xa8,(byte) 0x98,(byte) 0x74, +}; + +static final BitmapCharRec ch248 = new BitmapCharRec(6,6,0,0,6,ch248data); + +/* char: 0xf7 */ + +static final byte[] ch247data = { +(byte) 0x20,(byte) 0x0,(byte) 0xf8,(byte) 0x0,(byte) 0x20, +}; + +static final BitmapCharRec ch247 = new BitmapCharRec(5,5,0,-1,6,ch247data); + +/* char: 0xf6 */ + +static final byte[] ch246data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch246 = new BitmapCharRec(5,8,0,0,6,ch246data); + +/* char: 0xf5 */ + +static final byte[] ch245data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch245 = new BitmapCharRec(5,9,0,0,6,ch245data); + +/* char: 0xf4 */ + +static final byte[] ch244data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch244 = new BitmapCharRec(5,9,0,0,6,ch244data); + +/* char: 0xf3 */ + +static final byte[] ch243data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch243 = new BitmapCharRec(5,9,0,0,6,ch243data); + +/* char: 0xf2 */ + +static final byte[] ch242data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch242 = new BitmapCharRec(5,9,0,0,6,ch242data); + +/* char: 0xf1 */ + +static final byte[] ch241data = { +(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xe0,(byte) 0x0,(byte) 0xa0,(byte) 0x50, +}; + +static final BitmapCharRec ch241 = new BitmapCharRec(4,9,0,0,5,ch241data); + +/* char: 0xf0 */ + +static final byte[] ch240data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x78,(byte) 0x90,(byte) 0x60,(byte) 0x50, +}; + +static final BitmapCharRec ch240 = new BitmapCharRec(5,9,0,0,6,ch240data); + +/* char: 0xef */ + +static final byte[] ch239data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch239 = new BitmapCharRec(3,8,0,0,2,ch239data); + +/* char: 0xee */ + +static final byte[] ch238data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch238 = new BitmapCharRec(3,9,1,0,2,ch238data); + +/* char: 0xed */ + +static final byte[] ch237data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch237 = new BitmapCharRec(2,9,0,0,2,ch237data); + +/* char: 0xec */ + +static final byte[] ch236data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch236 = new BitmapCharRec(2,9,1,0,2,ch236data); + +/* char: 0xeb */ + +static final byte[] ch235data = { +(byte) 0x60,(byte) 0x90,(byte) 0x80,(byte) 0xf0,(byte) 0x90,(byte) 0x60,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch235 = new BitmapCharRec(4,8,0,0,5,ch235data); + +/* char: 0xea */ + +static final byte[] ch234data = { +(byte) 0x60,(byte) 0x90,(byte) 0x80,(byte) 0xf0,(byte) 0x90,(byte) 0x60,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch234 = new BitmapCharRec(4,9,0,0,5,ch234data); + +/* char: 0xe9 */ + +static final byte[] ch233data = { +(byte) 0x60,(byte) 0x90,(byte) 0x80,(byte) 0xf0,(byte) 0x90,(byte) 0x60,(byte) 0x0,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch233 = new BitmapCharRec(4,9,0,0,5,ch233data); + +/* char: 0xe8 */ + +static final byte[] ch232data = { +(byte) 0x60,(byte) 0x90,(byte) 0x80,(byte) 0xf0,(byte) 0x90,(byte) 0x60,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch232 = new BitmapCharRec(4,9,0,0,5,ch232data); + +/* char: 0xe7 */ + +static final byte[] ch231data = { +(byte) 0x60,(byte) 0x20,(byte) 0x60,(byte) 0x90,(byte) 0x80,(byte) 0x80,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch231 = new BitmapCharRec(4,8,0,2,5,ch231data); + +/* char: 0xe6 */ + +static final byte[] ch230data = { +(byte) 0x6c,(byte) 0x92,(byte) 0x90,(byte) 0x7e,(byte) 0x12,(byte) 0xec, +}; + +static final BitmapCharRec ch230 = new BitmapCharRec(7,6,0,0,8,ch230data); + +/* char: 0xe5 */ + +static final byte[] ch229data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x70,(byte) 0x10,(byte) 0xe0,(byte) 0x20,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch229 = new BitmapCharRec(5,9,0,0,5,ch229data); + +/* char: 0xe4 */ + +static final byte[] ch228data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x70,(byte) 0x10,(byte) 0xe0,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch228 = new BitmapCharRec(5,8,0,0,5,ch228data); + +/* char: 0xe3 */ + +static final byte[] ch227data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x70,(byte) 0x10,(byte) 0xe0,(byte) 0x0,(byte) 0xa0,(byte) 0x50, +}; + +static final BitmapCharRec ch227 = new BitmapCharRec(5,9,0,0,5,ch227data); + +/* char: 0xe2 */ + +static final byte[] ch226data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x70,(byte) 0x10,(byte) 0xe0,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch226 = new BitmapCharRec(5,9,0,0,5,ch226data); + +/* char: 0xe1 */ + +static final byte[] ch225data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x70,(byte) 0x10,(byte) 0xe0,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch225 = new BitmapCharRec(5,9,0,0,5,ch225data); + +/* char: 0xe0 */ + +static final byte[] ch224data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x70,(byte) 0x10,(byte) 0xe0,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch224 = new BitmapCharRec(5,9,0,0,5,ch224data); + +/* char: 0xdf */ + +static final byte[] ch223data = { +(byte) 0xa0,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xa0,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch223 = new BitmapCharRec(4,8,0,0,5,ch223data); + +/* char: 0xde */ + +static final byte[] ch222data = { +(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x88,(byte) 0x88,(byte) 0xf0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch222 = new BitmapCharRec(5,8,-1,0,7,ch222data); + +/* char: 0xdd */ + +static final byte[] ch221data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x82,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch221 = new BitmapCharRec(7,11,0,0,7,ch221data); + +/* char: 0xdc */ + +static final byte[] ch220data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x48, +}; + +static final BitmapCharRec ch220 = new BitmapCharRec(6,10,-1,0,8,ch220data); + +/* char: 0xdb */ + +static final byte[] ch219data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch219 = new BitmapCharRec(6,11,-1,0,8,ch219data); + +/* char: 0xda */ + +static final byte[] ch218data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch218 = new BitmapCharRec(6,11,-1,0,8,ch218data); + +/* char: 0xd9 */ + +static final byte[] ch217data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch217 = new BitmapCharRec(6,11,-1,0,8,ch217data); + +/* char: 0xd8 */ + +static final byte[] ch216data = { +(byte) 0x80,(byte) 0x78,(byte) 0xc4,(byte) 0xa4,(byte) 0xa4,(byte) 0x94,(byte) 0x94,(byte) 0x8c,(byte) 0x78,(byte) 0x4, +}; + +static final BitmapCharRec ch216 = new BitmapCharRec(6,10,-1,1,8,ch216data); + +/* char: 0xd7 */ + +static final byte[] ch215data = { +(byte) 0x88,(byte) 0x50,(byte) 0x20,(byte) 0x50,(byte) 0x88, +}; + +static final BitmapCharRec ch215 = new BitmapCharRec(5,5,0,-1,6,ch215data); + +/* char: 0xd6 */ + +static final byte[] ch214data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x48, +}; + +static final BitmapCharRec ch214 = new BitmapCharRec(6,10,-1,0,8,ch214data); + +/* char: 0xd5 */ + +static final byte[] ch213data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch213 = new BitmapCharRec(6,11,-1,0,8,ch213data); + +/* char: 0xd4 */ + +static final byte[] ch212data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch212 = new BitmapCharRec(6,11,-1,0,8,ch212data); + +/* char: 0xd3 */ + +static final byte[] ch211data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch211 = new BitmapCharRec(6,11,-1,0,8,ch211data); + +/* char: 0xd2 */ + +static final byte[] ch210data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch210 = new BitmapCharRec(6,11,-1,0,8,ch210data); + +/* char: 0xd1 */ + +static final byte[] ch209data = { +(byte) 0x8c,(byte) 0x8c,(byte) 0x94,(byte) 0x94,(byte) 0xa4,(byte) 0xa4,(byte) 0xc4,(byte) 0xc4,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch209 = new BitmapCharRec(6,11,-1,0,8,ch209data); + +/* char: 0xd0 */ + +static final byte[] ch208data = { +(byte) 0x78,(byte) 0x44,(byte) 0x42,(byte) 0x42,(byte) 0xf2,(byte) 0x42,(byte) 0x44,(byte) 0x78, +}; + +static final BitmapCharRec ch208 = new BitmapCharRec(7,8,0,0,8,ch208data); + +/* char: 0xcf */ + +static final byte[] ch207data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch207 = new BitmapCharRec(3,10,0,0,3,ch207data); + +/* char: 0xce */ + +static final byte[] ch206data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch206 = new BitmapCharRec(3,11,0,0,3,ch206data); + +/* char: 0xcd */ + +static final byte[] ch205data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch205 = new BitmapCharRec(2,11,-1,0,3,ch205data); + +/* char: 0xcc */ + +static final byte[] ch204data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch204 = new BitmapCharRec(2,11,0,0,3,ch204data); + +/* char: 0xcb */ + +static final byte[] ch203data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch203 = new BitmapCharRec(5,10,-1,0,7,ch203data); + +/* char: 0xca */ + +static final byte[] ch202data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch202 = new BitmapCharRec(5,11,-1,0,7,ch202data); + +/* char: 0xc9 */ + +static final byte[] ch201data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch201 = new BitmapCharRec(5,11,-1,0,7,ch201data); + +/* char: 0xc8 */ + +static final byte[] ch200data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch200 = new BitmapCharRec(5,11,-1,0,7,ch200data); + +/* char: 0xc7 */ + +static final byte[] ch199data = { +(byte) 0x30,(byte) 0x10,(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch199 = new BitmapCharRec(6,10,-1,2,8,ch199data); + +/* char: 0xc6 */ + +static final byte[] ch198data = { +(byte) 0x8f,(byte) 0x80,(byte) 0x88,(byte) 0x0,(byte) 0x78,(byte) 0x0,(byte) 0x48,(byte) 0x0,(byte) 0x2f,(byte) 0x80,(byte) 0x28,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x1f,(byte) 0x80, +}; + +static final BitmapCharRec ch198 = new BitmapCharRec(9,8,0,0,10,ch198data); + +/* char: 0xc5 */ + +static final byte[] ch197data = { +(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x28,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch197 = new BitmapCharRec(7,11,0,0,7,ch197data); + +/* char: 0xc4 */ + +static final byte[] ch196data = { +(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x28,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x28, +}; + +static final BitmapCharRec ch196 = new BitmapCharRec(7,10,0,0,7,ch196data); + +/* char: 0xc3 */ + +static final byte[] ch195data = { +(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x28,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x28,(byte) 0x14, +}; + +static final BitmapCharRec ch195 = new BitmapCharRec(7,11,0,0,7,ch195data); + +/* char: 0xc2 */ + +static final byte[] ch194data = { +(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x28,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch194 = new BitmapCharRec(7,11,0,0,7,ch194data); + +/* char: 0xc1 */ + +static final byte[] ch193data = { +(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x28,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch193 = new BitmapCharRec(7,11,0,0,7,ch193data); + +/* char: 0xc0 */ + +static final byte[] ch192data = { +(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x28,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch192 = new BitmapCharRec(7,11,0,0,7,ch192data); + +/* char: 0xbf */ + +static final byte[] ch191data = { +(byte) 0x60,(byte) 0x90,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x0,(byte) 0x20, +}; + +static final BitmapCharRec ch191 = new BitmapCharRec(4,8,-1,2,6,ch191data); + +/* char: 0xbe */ + +static final byte[] ch190data = { +(byte) 0x21,(byte) 0x0,(byte) 0x17,(byte) 0x80,(byte) 0x13,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0xc8,(byte) 0x0,(byte) 0x24,(byte) 0x0,(byte) 0x44,(byte) 0x0,(byte) 0xe2,(byte) 0x0, +}; + +static final BitmapCharRec ch190 = new BitmapCharRec(9,8,0,0,9,ch190data); + +/* char: 0xbd */ + +static final byte[] ch189data = { +(byte) 0x27,(byte) 0x12,(byte) 0x15,(byte) 0xb,(byte) 0x48,(byte) 0x44,(byte) 0xc4,(byte) 0x42, +}; + +static final BitmapCharRec ch189 = new BitmapCharRec(8,8,0,0,9,ch189data); + +/* char: 0xbc */ + +static final byte[] ch188data = { +(byte) 0x21,(byte) 0x0,(byte) 0x17,(byte) 0x80,(byte) 0x13,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x48,(byte) 0x0,(byte) 0x44,(byte) 0x0,(byte) 0xc4,(byte) 0x0,(byte) 0x42,(byte) 0x0, +}; + +static final BitmapCharRec ch188 = new BitmapCharRec(9,8,0,0,9,ch188data); + +/* char: 0xbb */ + +static final byte[] ch187data = { +(byte) 0xa0,(byte) 0x50,(byte) 0x28,(byte) 0x50,(byte) 0xa0, +}; + +static final BitmapCharRec ch187 = new BitmapCharRec(5,5,0,0,6,ch187data); + +/* char: 0xba */ + +static final byte[] ch186data = { +(byte) 0xe0,(byte) 0x0,(byte) 0xe0,(byte) 0xa0,(byte) 0xe0, +}; + +static final BitmapCharRec ch186 = new BitmapCharRec(3,5,0,-3,4,ch186data); + +/* char: 0xb9 */ + +static final byte[] ch185data = { +(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch185 = new BitmapCharRec(2,4,0,-3,3,ch185data); + +/* char: 0xb8 */ + +static final byte[] ch184data = { +(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch184 = new BitmapCharRec(2,2,0,2,3,ch184data); + +/* char: 0xb7 */ + +static final byte[] ch183data = { +(byte) 0xc0, +}; + +static final BitmapCharRec ch183 = new BitmapCharRec(2,1,0,-3,3,ch183data); + +/* char: 0xb6 */ + +static final byte[] ch182data = { +(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x68,(byte) 0xe8,(byte) 0xe8,(byte) 0xe8,(byte) 0x7c, +}; + +static final BitmapCharRec ch182 = new BitmapCharRec(6,10,0,2,6,ch182data); + +/* char: 0xb5 */ + +static final byte[] ch181data = { +(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90, +}; + +static final BitmapCharRec ch181 = new BitmapCharRec(4,8,0,2,5,ch181data); + +/* char: 0xb4 */ + +static final byte[] ch180data = { +(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch180 = new BitmapCharRec(2,2,0,-6,3,ch180data); + +/* char: 0xb3 */ + +static final byte[] ch179data = { +(byte) 0xc0,(byte) 0x20,(byte) 0x40,(byte) 0xe0, +}; + +static final BitmapCharRec ch179 = new BitmapCharRec(3,4,0,-3,3,ch179data); + +/* char: 0xb2 */ + +static final byte[] ch178data = { +(byte) 0xe0,(byte) 0x40,(byte) 0xa0,(byte) 0x60, +}; + +static final BitmapCharRec ch178 = new BitmapCharRec(3,4,0,-3,3,ch178data); + +/* char: 0xb1 */ + +static final byte[] ch177data = { +(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch177 = new BitmapCharRec(5,7,0,0,6,ch177data); + +/* char: 0xb0 */ + +static final byte[] ch176data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch176 = new BitmapCharRec(4,4,0,-3,4,ch176data); + +/* char: 0xaf */ + +static final byte[] ch175data = { +(byte) 0xe0, +}; + +static final BitmapCharRec ch175 = new BitmapCharRec(3,1,0,-7,3,ch175data); + +/* char: 0xae */ + +static final byte[] ch174data = { +(byte) 0x38,(byte) 0x44,(byte) 0xaa,(byte) 0xb2,(byte) 0xba,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch174 = new BitmapCharRec(7,7,-1,0,9,ch174data); + +/* char: 0xad */ + +static final byte[] ch173data = { +(byte) 0xe0, +}; + +static final BitmapCharRec ch173 = new BitmapCharRec(3,1,0,-3,4,ch173data); + +/* char: 0xac */ + +static final byte[] ch172data = { +(byte) 0x8,(byte) 0x8,(byte) 0xf8, +}; + +static final BitmapCharRec ch172 = new BitmapCharRec(5,3,-1,-2,7,ch172data); + +/* char: 0xab */ + +static final byte[] ch171data = { +(byte) 0x28,(byte) 0x50,(byte) 0xa0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch171 = new BitmapCharRec(5,5,0,0,6,ch171data); + +/* char: 0xaa */ + +static final byte[] ch170data = { +(byte) 0xe0,(byte) 0x0,(byte) 0xa0,(byte) 0x20,(byte) 0xe0, +}; + +static final BitmapCharRec ch170 = new BitmapCharRec(3,5,0,-3,4,ch170data); + +/* char: 0xa9 */ + +static final byte[] ch169data = { +(byte) 0x38,(byte) 0x44,(byte) 0x9a,(byte) 0xa2,(byte) 0x9a,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch169 = new BitmapCharRec(7,7,-1,0,9,ch169data); + +/* char: 0xa8 */ + +static final byte[] ch168data = { +(byte) 0xa0, +}; + +static final BitmapCharRec ch168 = new BitmapCharRec(3,1,0,-7,3,ch168data); + +/* char: 0xa7 */ + +static final byte[] ch167data = { +(byte) 0x70,(byte) 0x88,(byte) 0x18,(byte) 0x70,(byte) 0xc8,(byte) 0x98,(byte) 0x70,(byte) 0xc0,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch167 = new BitmapCharRec(5,10,0,2,6,ch167data); + +/* char: 0xa6 */ + +static final byte[] ch166data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch166 = new BitmapCharRec(1,10,-1,2,3,ch166data); + +/* char: 0xa5 */ + +static final byte[] ch165data = { +(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0xf8,(byte) 0x50,(byte) 0x50,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch165 = new BitmapCharRec(5,8,0,0,6,ch165data); + +/* char: 0xa4 */ + +static final byte[] ch164data = { +(byte) 0x90,(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60,(byte) 0x90, +}; + +static final BitmapCharRec ch164 = new BitmapCharRec(4,6,0,-1,5,ch164data); + +/* char: 0xa3 */ + +static final byte[] ch163data = { +(byte) 0xb0,(byte) 0x48,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x40,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch163 = new BitmapCharRec(5,8,0,0,6,ch163data); + +/* char: 0xa2 */ + +static final byte[] ch162data = { +(byte) 0x40,(byte) 0x70,(byte) 0xa8,(byte) 0xa0,(byte) 0xa0,(byte) 0xa8,(byte) 0x70,(byte) 0x10, +}; + +static final BitmapCharRec ch162 = new BitmapCharRec(5,8,0,1,6,ch162data); + +/* char: 0xa1 */ + +static final byte[] ch161data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch161 = new BitmapCharRec(1,8,-1,2,3,ch161data); + +/* char: 0xa0 */ + +static final BitmapCharRec ch160 = new BitmapCharRec(0,0,0,0,3,null); + +/* char: 0x7e '~' */ + +static final byte[] ch126data = { +(byte) 0x98,(byte) 0x64, +}; + +static final BitmapCharRec ch126 = new BitmapCharRec(6,2,0,-3,7,ch126data); + +/* char: 0x7d '}' */ + +static final byte[] ch125data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch125 = new BitmapCharRec(3,10,0,2,3,ch125data); + +/* char: 0x7c '|' */ + +static final byte[] ch124data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch124 = new BitmapCharRec(1,10,-1,2,3,ch124data); + +/* char: 0x7b '{' */ + +static final byte[] ch123data = { +(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch123 = new BitmapCharRec(3,10,0,2,3,ch123data); + +/* char: 0x7a 'z' */ + +static final byte[] ch122data = { +(byte) 0xf0,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0xf0, +}; + +static final BitmapCharRec ch122 = new BitmapCharRec(4,6,0,0,5,ch122data); + +/* char: 0x79 'y' */ + +static final byte[] ch121data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x60,(byte) 0xa0,(byte) 0xa0,(byte) 0x90,(byte) 0x90, +}; + +static final BitmapCharRec ch121 = new BitmapCharRec(4,8,0,2,5,ch121data); + +/* char: 0x78 'x' */ + +static final byte[] ch120data = { +(byte) 0x88,(byte) 0x88,(byte) 0x50,(byte) 0x20,(byte) 0x50,(byte) 0x88, +}; + +static final BitmapCharRec ch120 = new BitmapCharRec(5,6,0,0,6,ch120data); + +/* char: 0x77 'w' */ + +static final byte[] ch119data = { +(byte) 0x28,(byte) 0x28,(byte) 0x54,(byte) 0x54,(byte) 0x92,(byte) 0x92, +}; + +static final BitmapCharRec ch119 = new BitmapCharRec(7,6,0,0,8,ch119data); + +/* char: 0x76 'v' */ + +static final byte[] ch118data = { +(byte) 0x20,(byte) 0x20,(byte) 0x50,(byte) 0x50,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch118 = new BitmapCharRec(5,6,0,0,6,ch118data); + +/* char: 0x75 'u' */ + +static final byte[] ch117data = { +(byte) 0x70,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90, +}; + +static final BitmapCharRec ch117 = new BitmapCharRec(4,6,0,0,5,ch117data); + +/* char: 0x74 't' */ + +static final byte[] ch116data = { +(byte) 0x60,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x40,(byte) 0x40, +}; + +static final BitmapCharRec ch116 = new BitmapCharRec(3,8,0,0,4,ch116data); + +/* char: 0x73 's' */ + +static final byte[] ch115data = { +(byte) 0x60,(byte) 0x90,(byte) 0x10,(byte) 0x60,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch115 = new BitmapCharRec(4,6,0,0,5,ch115data); + +/* char: 0x72 'r' */ + +static final byte[] ch114data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xc0,(byte) 0xa0, +}; + +static final BitmapCharRec ch114 = new BitmapCharRec(3,6,0,0,4,ch114data); + +/* char: 0x71 'q' */ + +static final byte[] ch113data = { +(byte) 0x8,(byte) 0x8,(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x98,(byte) 0x68, +}; + +static final BitmapCharRec ch113 = new BitmapCharRec(5,8,0,2,6,ch113data); + +/* char: 0x70 'p' */ + +static final byte[] ch112data = { +(byte) 0x80,(byte) 0x80,(byte) 0xb0,(byte) 0xc8,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0, +}; + +static final BitmapCharRec ch112 = new BitmapCharRec(5,8,0,2,6,ch112data); + +/* char: 0x6f 'o' */ + +static final byte[] ch111data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch111 = new BitmapCharRec(5,6,0,0,6,ch111data); + +/* char: 0x6e 'n' */ + +static final byte[] ch110data = { +(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0, +}; + +static final BitmapCharRec ch110 = new BitmapCharRec(5,6,0,0,6,ch110data); + +/* char: 0x6d 'm' */ + +static final byte[] ch109data = { +(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0xec, +}; + +static final BitmapCharRec ch109 = new BitmapCharRec(7,6,0,0,8,ch109data); + +/* char: 0x6c 'l' */ + +static final byte[] ch108data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch108 = new BitmapCharRec(1,8,0,0,2,ch108data); + +/* char: 0x6b 'k' */ + +static final byte[] ch107data = { +(byte) 0x90,(byte) 0x90,(byte) 0xa0,(byte) 0xc0,(byte) 0xa0,(byte) 0x90,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch107 = new BitmapCharRec(4,8,0,0,5,ch107data); + +/* char: 0x6a 'j' */ + +static final byte[] ch106data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch106 = new BitmapCharRec(1,9,0,1,2,ch106data); + +/* char: 0x69 'i' */ + +static final byte[] ch105data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch105 = new BitmapCharRec(1,8,0,0,2,ch105data); + +/* char: 0x68 'h' */ + +static final byte[] ch104data = { +(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch104 = new BitmapCharRec(5,8,0,0,6,ch104data); + +/* char: 0x67 'g' */ + +static final byte[] ch103data = { +(byte) 0x70,(byte) 0x8,(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x98,(byte) 0x68, +}; + +static final BitmapCharRec ch103 = new BitmapCharRec(5,8,0,2,6,ch103data); + +/* char: 0x66 'f' */ + +static final byte[] ch102data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x40,(byte) 0x30, +}; + +static final BitmapCharRec ch102 = new BitmapCharRec(4,8,0,0,4,ch102data); + +/* char: 0x65 'e' */ + +static final byte[] ch101data = { +(byte) 0x60,(byte) 0x90,(byte) 0x80,(byte) 0xf0,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch101 = new BitmapCharRec(4,6,0,0,5,ch101data); + +/* char: 0x64 'd' */ + +static final byte[] ch100data = { +(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x98,(byte) 0x68,(byte) 0x8,(byte) 0x8, +}; + +static final BitmapCharRec ch100 = new BitmapCharRec(5,8,0,0,6,ch100data); + +/* char: 0x63 'c' */ + +static final byte[] ch99data = { +(byte) 0x60,(byte) 0x90,(byte) 0x80,(byte) 0x80,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch99 = new BitmapCharRec(4,6,0,0,5,ch99data); + +/* char: 0x62 'b' */ + +static final byte[] ch98data = { +(byte) 0xb0,(byte) 0xc8,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch98 = new BitmapCharRec(5,8,0,0,6,ch98data); + +/* char: 0x61 'a' */ + +static final byte[] ch97data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x70,(byte) 0x10,(byte) 0xe0, +}; + +static final BitmapCharRec ch97 = new BitmapCharRec(5,6,0,0,5,ch97data); + +/* char: 0x60 '`' */ + +static final byte[] ch96data = { +(byte) 0x80,(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch96 = new BitmapCharRec(2,3,0,-5,3,ch96data); + +/* char: 0x5f '_' */ + +static final byte[] ch95data = { +(byte) 0xfc, +}; + +static final BitmapCharRec ch95 = new BitmapCharRec(6,1,0,2,6,ch95data); + +/* char: 0x5e '^' */ + +static final byte[] ch94data = { +(byte) 0x88,(byte) 0x50,(byte) 0x50,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch94 = new BitmapCharRec(5,5,0,-3,6,ch94data); + +/* char: 0x5d ']' */ + +static final byte[] ch93data = { +(byte) 0xc0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0, +}; + +static final BitmapCharRec ch93 = new BitmapCharRec(2,10,0,2,3,ch93data); + +/* char: 0x5c '\' */ + +static final byte[] ch92data = { +(byte) 0x20,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch92 = new BitmapCharRec(3,8,0,0,3,ch92data); + +/* char: 0x5b '[' */ + +static final byte[] ch91data = { +(byte) 0xc0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xc0, +}; + +static final BitmapCharRec ch91 = new BitmapCharRec(2,10,-1,2,3,ch91data); + +/* char: 0x5a 'Z' */ + +static final byte[] ch90data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0xf8, +}; + +static final BitmapCharRec ch90 = new BitmapCharRec(5,8,-1,0,7,ch90data); + +/* char: 0x59 'Y' */ + +static final byte[] ch89data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x82, +}; + +static final BitmapCharRec ch89 = new BitmapCharRec(7,8,0,0,7,ch89data); + +/* char: 0x58 'X' */ + +static final byte[] ch88data = { +(byte) 0x88,(byte) 0x88,(byte) 0x50,(byte) 0x50,(byte) 0x20,(byte) 0x50,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch88 = new BitmapCharRec(5,8,-1,0,7,ch88data); + +/* char: 0x57 'W' */ + +static final byte[] ch87data = { +(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x55,(byte) 0x0,(byte) 0x49,(byte) 0x0,(byte) 0x49,(byte) 0x0,(byte) 0x88,(byte) 0x80,(byte) 0x88,(byte) 0x80, +}; + +static final BitmapCharRec ch87 = new BitmapCharRec(9,8,0,0,9,ch87data); + +/* char: 0x56 'V' */ + +static final byte[] ch86data = { +(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch86 = new BitmapCharRec(7,8,0,0,7,ch86data); + +/* char: 0x55 'U' */ + +static final byte[] ch85data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch85 = new BitmapCharRec(6,8,-1,0,8,ch85data); + +/* char: 0x54 'T' */ + +static final byte[] ch84data = { +(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xf8, +}; + +static final BitmapCharRec ch84 = new BitmapCharRec(5,8,0,0,5,ch84data); + +/* char: 0x53 'S' */ + +static final byte[] ch83data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x8,(byte) 0x70,(byte) 0x80,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch83 = new BitmapCharRec(5,8,-1,0,7,ch83data); + +/* char: 0x52 'R' */ + +static final byte[] ch82data = { +(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xf0,(byte) 0x88,(byte) 0x88,(byte) 0xf0, +}; + +static final BitmapCharRec ch82 = new BitmapCharRec(5,8,-1,0,7,ch82data); + +/* char: 0x51 'Q' */ + +static final byte[] ch81data = { +(byte) 0x2,(byte) 0x7c,(byte) 0x8c,(byte) 0x94,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch81 = new BitmapCharRec(7,9,-1,1,8,ch81data); + +/* char: 0x50 'P' */ + +static final byte[] ch80data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x88,(byte) 0x88,(byte) 0xf0, +}; + +static final BitmapCharRec ch80 = new BitmapCharRec(5,8,-1,0,7,ch80data); + +/* char: 0x4f 'O' */ + +static final byte[] ch79data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch79 = new BitmapCharRec(6,8,-1,0,8,ch79data); + +/* char: 0x4e 'N' */ + +static final byte[] ch78data = { +(byte) 0x8c,(byte) 0x8c,(byte) 0x94,(byte) 0x94,(byte) 0xa4,(byte) 0xa4,(byte) 0xc4,(byte) 0xc4, +}; + +static final BitmapCharRec ch78 = new BitmapCharRec(6,8,-1,0,8,ch78data); + +/* char: 0x4d 'M' */ + +static final byte[] ch77data = { +(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0xaa,(byte) 0xaa,(byte) 0xc6,(byte) 0xc6,(byte) 0x82, +}; + +static final BitmapCharRec ch77 = new BitmapCharRec(7,8,-1,0,9,ch77data); + +/* char: 0x4c 'L' */ + +static final byte[] ch76data = { +(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch76 = new BitmapCharRec(4,8,-1,0,6,ch76data); + +/* char: 0x4b 'K' */ + +static final byte[] ch75data = { +(byte) 0x88,(byte) 0x88,(byte) 0x90,(byte) 0x90,(byte) 0xe0,(byte) 0xa0,(byte) 0x90,(byte) 0x88, +}; + +static final BitmapCharRec ch75 = new BitmapCharRec(5,8,-1,0,7,ch75data); + +/* char: 0x4a 'J' */ + +static final byte[] ch74data = { +(byte) 0x60,(byte) 0x90,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch74 = new BitmapCharRec(4,8,0,0,5,ch74data); + +/* char: 0x49 'I' */ + +static final byte[] ch73data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch73 = new BitmapCharRec(1,8,-1,0,3,ch73data); + +/* char: 0x48 'H' */ + +static final byte[] ch72data = { +(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xfc,(byte) 0x84,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch72 = new BitmapCharRec(6,8,-1,0,8,ch72data); + +/* char: 0x47 'G' */ + +static final byte[] ch71data = { +(byte) 0x74,(byte) 0x8c,(byte) 0x84,(byte) 0x8c,(byte) 0x80,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch71 = new BitmapCharRec(6,8,-1,0,8,ch71data); + +/* char: 0x46 'F' */ + +static final byte[] ch70data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0xf8, +}; + +static final BitmapCharRec ch70 = new BitmapCharRec(5,8,-1,0,6,ch70data); + +/* char: 0x45 'E' */ + +static final byte[] ch69data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0xf8, +}; + +static final BitmapCharRec ch69 = new BitmapCharRec(5,8,-1,0,7,ch69data); + +/* char: 0x44 'D' */ + +static final byte[] ch68data = { +(byte) 0xf0,(byte) 0x88,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x88,(byte) 0xf0, +}; + +static final BitmapCharRec ch68 = new BitmapCharRec(6,8,-1,0,8,ch68data); + +/* char: 0x43 'C' */ + +static final byte[] ch67data = { +(byte) 0x78,(byte) 0x84,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch67 = new BitmapCharRec(6,8,-1,0,8,ch67data); + +/* char: 0x42 'B' */ + +static final byte[] ch66data = { +(byte) 0xf0,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xf0,(byte) 0x88,(byte) 0x88,(byte) 0xf0, +}; + +static final BitmapCharRec ch66 = new BitmapCharRec(5,8,-1,0,7,ch66data); + +/* char: 0x41 'A' */ + +static final byte[] ch65data = { +(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x28,(byte) 0x28,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch65 = new BitmapCharRec(7,8,0,0,7,ch65data); + +/* char: 0x40 '@' */ + +static final byte[] ch64data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x40,(byte) 0x0,(byte) 0x9b,(byte) 0x0,(byte) 0xa4,(byte) 0x80,(byte) 0xa4,(byte) 0x80,(byte) 0xa2,(byte) 0x40,(byte) 0x92,(byte) 0x40,(byte) 0x4d,(byte) 0x40, +(byte) 0x20,(byte) 0x80,(byte) 0x1f,(byte) 0x0, +}; + +static final BitmapCharRec ch64 = new BitmapCharRec(10,10,0,2,11,ch64data); + +/* char: 0x3f '?' */ + +static final byte[] ch63data = { +(byte) 0x40,(byte) 0x0,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch63 = new BitmapCharRec(4,8,-1,0,6,ch63data); + +/* char: 0x3e '>' */ + +static final byte[] ch62data = { +(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch62 = new BitmapCharRec(3,5,-1,-1,6,ch62data); + +/* char: 0x3d '=' */ + +static final byte[] ch61data = { +(byte) 0xf0,(byte) 0x0,(byte) 0xf0, +}; + +static final BitmapCharRec ch61 = new BitmapCharRec(4,3,0,-2,5,ch61data); + +/* char: 0x3c '<' */ + +static final byte[] ch60data = { +(byte) 0x20,(byte) 0x40,(byte) 0x80,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch60 = new BitmapCharRec(3,5,-1,-1,6,ch60data); + +/* char: 0x3b ';' */ + +static final byte[] ch59data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x40, +}; + +static final BitmapCharRec ch59 = new BitmapCharRec(2,8,0,2,3,ch59data); + +/* char: 0x3a ':' */ + +static final byte[] ch58data = { +(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch58 = new BitmapCharRec(1,6,-1,0,3,ch58data); + +/* char: 0x39 '9' */ + +static final byte[] ch57data = { +(byte) 0x70,(byte) 0x88,(byte) 0x8,(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch57 = new BitmapCharRec(5,8,0,0,6,ch57data); + +/* char: 0x38 '8' */ + +static final byte[] ch56data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch56 = new BitmapCharRec(5,8,0,0,6,ch56data); + +/* char: 0x37 '7' */ + +static final byte[] ch55data = { +(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x10,(byte) 0x10,(byte) 0x8,(byte) 0xf8, +}; + +static final BitmapCharRec ch55 = new BitmapCharRec(5,8,0,0,6,ch55data); + +/* char: 0x36 '6' */ + +static final byte[] ch54data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0,(byte) 0x80,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch54 = new BitmapCharRec(5,8,0,0,6,ch54data); + +/* char: 0x35 '5' */ + +static final byte[] ch53data = { +(byte) 0x70,(byte) 0x88,(byte) 0x8,(byte) 0x8,(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0xf8, +}; + +static final BitmapCharRec ch53 = new BitmapCharRec(5,8,0,0,6,ch53data); + +/* char: 0x34 '4' */ + +static final byte[] ch52data = { +(byte) 0x10,(byte) 0x10,(byte) 0xf8,(byte) 0x90,(byte) 0x50,(byte) 0x50,(byte) 0x30,(byte) 0x10, +}; + +static final BitmapCharRec ch52 = new BitmapCharRec(5,8,0,0,6,ch52data); + +/* char: 0x33 '3' */ + +static final byte[] ch51data = { +(byte) 0x70,(byte) 0x88,(byte) 0x8,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch51 = new BitmapCharRec(5,8,0,0,6,ch51data); + +/* char: 0x32 '2' */ + +static final byte[] ch50data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x40,(byte) 0x30,(byte) 0x8,(byte) 0x8,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch50 = new BitmapCharRec(5,8,0,0,6,ch50data); + +/* char: 0x31 '1' */ + +static final byte[] ch49data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch49 = new BitmapCharRec(2,8,-1,0,6,ch49data); + +/* char: 0x30 '0' */ + +static final byte[] ch48data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch48 = new BitmapCharRec(5,8,0,0,6,ch48data); + +/* char: 0x2f '/' */ + +static final byte[] ch47data = { +(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch47 = new BitmapCharRec(3,8,0,0,3,ch47data); + +/* char: 0x2e '.' */ + +static final byte[] ch46data = { +(byte) 0x80, +}; + +static final BitmapCharRec ch46 = new BitmapCharRec(1,1,-1,0,3,ch46data); + +/* char: 0x2d '-' */ + +static final byte[] ch45data = { +(byte) 0xf8, +}; + +static final BitmapCharRec ch45 = new BitmapCharRec(5,1,-1,-3,7,ch45data); + +/* char: 0x2c ',' */ + +static final byte[] ch44data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40, +}; + +static final BitmapCharRec ch44 = new BitmapCharRec(2,3,0,2,3,ch44data); + +/* char: 0x2b '+' */ + +static final byte[] ch43data = { +(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch43 = new BitmapCharRec(5,5,0,-1,6,ch43data); + +/* char: 0x2a '*' */ + +static final byte[] ch42data = { +(byte) 0xa0,(byte) 0x40,(byte) 0xa0, +}; + +static final BitmapCharRec ch42 = new BitmapCharRec(3,3,0,-5,4,ch42data); + +/* char: 0x29 ')' */ + +static final byte[] ch41data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch41 = new BitmapCharRec(3,10,-1,2,4,ch41data); + +/* char: 0x28 '(' */ + +static final byte[] ch40data = { +(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch40 = new BitmapCharRec(3,10,0,2,4,ch40data); + +/* char: 0x27 ''' */ + +static final byte[] ch39data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40, +}; + +static final BitmapCharRec ch39 = new BitmapCharRec(2,3,-1,-5,3,ch39data); + +/* char: 0x26 '&' */ + +static final byte[] ch38data = { +(byte) 0x64,(byte) 0x98,(byte) 0x98,(byte) 0xa4,(byte) 0x60,(byte) 0x50,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch38 = new BitmapCharRec(6,8,-1,0,8,ch38data); + +/* char: 0x25 '%' */ + +static final byte[] ch37data = { +(byte) 0x26,(byte) 0x29,(byte) 0x16,(byte) 0x10,(byte) 0x8,(byte) 0x68,(byte) 0x94,(byte) 0x64, +}; + +static final BitmapCharRec ch37 = new BitmapCharRec(8,8,0,0,9,ch37data); + +/* char: 0x24 '$' */ + +static final byte[] ch36data = { +(byte) 0x20,(byte) 0x70,(byte) 0xa8,(byte) 0x28,(byte) 0x70,(byte) 0xa0,(byte) 0xa8,(byte) 0x70,(byte) 0x20, +}; + +static final BitmapCharRec ch36 = new BitmapCharRec(5,9,0,1,6,ch36data); + +/* char: 0x23 '#' */ + +static final byte[] ch35data = { +(byte) 0x50,(byte) 0x50,(byte) 0xf8,(byte) 0x28,(byte) 0x7c,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch35 = new BitmapCharRec(6,7,0,0,6,ch35data); + +/* char: 0x22 '"' */ + +static final byte[] ch34data = { +(byte) 0xa0,(byte) 0xa0, +}; + +static final BitmapCharRec ch34 = new BitmapCharRec(3,2,-1,-6,4,ch34data); + +/* char: 0x21 '!' */ + +static final byte[] ch33data = { +(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch33 = new BitmapCharRec(1,8,-1,0,3,ch33data); + +/* char: 0x20 ' ' */ + +static final BitmapCharRec ch32 = new BitmapCharRec(0,0,0,0,3,null); + +static final BitmapCharRec[] chars = { +ch32, +ch33, +ch34, +ch35, +ch36, +ch37, +ch38, +ch39, +ch40, +ch41, +ch42, +ch43, +ch44, +ch45, +ch46, +ch47, +ch48, +ch49, +ch50, +ch51, +ch52, +ch53, +ch54, +ch55, +ch56, +ch57, +ch58, +ch59, +ch60, +ch61, +ch62, +ch63, +ch64, +ch65, +ch66, +ch67, +ch68, +ch69, +ch70, +ch71, +ch72, +ch73, +ch74, +ch75, +ch76, +ch77, +ch78, +ch79, +ch80, +ch81, +ch82, +ch83, +ch84, +ch85, +ch86, +ch87, +ch88, +ch89, +ch90, +ch91, +ch92, +ch93, +ch94, +ch95, +ch96, +ch97, +ch98, +ch99, +ch100, +ch101, +ch102, +ch103, +ch104, +ch105, +ch106, +ch107, +ch108, +ch109, +ch110, +ch111, +ch112, +ch113, +ch114, +ch115, +ch116, +ch117, +ch118, +ch119, +ch120, +ch121, +ch122, +ch123, +ch124, +ch125, +ch126, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +ch160, +ch161, +ch162, +ch163, +ch164, +ch165, +ch166, +ch167, +ch168, +ch169, +ch170, +ch171, +ch172, +ch173, +ch174, +ch175, +ch176, +ch177, +ch178, +ch179, +ch180, +ch181, +ch182, +ch183, +ch184, +ch185, +ch186, +ch187, +ch188, +ch189, +ch190, +ch191, +ch192, +ch193, +ch194, +ch195, +ch196, +ch197, +ch198, +ch199, +ch200, +ch201, +ch202, +ch203, +ch204, +ch205, +ch206, +ch207, +ch208, +ch209, +ch210, +ch211, +ch212, +ch213, +ch214, +ch215, +ch216, +ch217, +ch218, +ch219, +ch220, +ch221, +ch222, +ch223, +ch224, +ch225, +ch226, +ch227, +ch228, +ch229, +ch230, +ch231, +ch232, +ch233, +ch234, +ch235, +ch236, +ch237, +ch238, +ch239, +ch240, +ch241, +ch242, +ch243, +ch244, +ch245, +ch246, +ch247, +ch248, +ch249, +ch250, +ch251, +ch252, +ch253, +ch254, +ch255, +}; + + public static final BitmapFontRec glutBitmapHelvetica10 = new BitmapFontRec("-adobe-helvetica-medium-r-normal--10-100-75-75-p-56-iso8859-1", + 224, + 32, + chars); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapHelvetica12.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapHelvetica12.java new file mode 100644 index 000000000..bc86f6216 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapHelvetica12.java @@ -0,0 +1,1808 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +class GLUTBitmapHelvetica12 { + +/* GENERATED FILE -- DO NOT MODIFY */ + +/* char: 0xff */ + +static final byte[] ch255data = { +(byte) 0xc0,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x30,(byte) 0x50,(byte) 0x50,(byte) 0x48,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch255 = new BitmapCharRec(5,12,-1,3,7,ch255data); + +/* char: 0xfe */ + +static final byte[] ch254data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xb0,(byte) 0xc8,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch254 = new BitmapCharRec(5,12,-1,3,7,ch254data); + +/* char: 0xfd */ + +static final byte[] ch253data = { +(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x50,(byte) 0x50,(byte) 0x90,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch253 = new BitmapCharRec(5,13,-1,3,7,ch253data); + +/* char: 0xfc */ + +static final byte[] ch252data = { +(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch252 = new BitmapCharRec(5,9,-1,0,7,ch252data); + +/* char: 0xfb */ + +static final byte[] ch251data = { +(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch251 = new BitmapCharRec(5,10,-1,0,7,ch251data); + +/* char: 0xfa */ + +static final byte[] ch250data = { +(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch250 = new BitmapCharRec(5,10,-1,0,7,ch250data); + +/* char: 0xf9 */ + +static final byte[] ch249data = { +(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch249 = new BitmapCharRec(5,10,-1,0,7,ch249data); + +/* char: 0xf8 */ + +static final byte[] ch248data = { +(byte) 0xb8,(byte) 0x44,(byte) 0x64,(byte) 0x54,(byte) 0x4c,(byte) 0x44,(byte) 0x3a, +}; + +static final BitmapCharRec ch248 = new BitmapCharRec(7,7,0,0,7,ch248data); + +/* char: 0xf7 */ + +static final byte[] ch247data = { +(byte) 0x20,(byte) 0x0,(byte) 0xf8,(byte) 0x0,(byte) 0x20, +}; + +static final BitmapCharRec ch247 = new BitmapCharRec(5,5,-1,-1,7,ch247data); + +/* char: 0xf6 */ + +static final byte[] ch246data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch246 = new BitmapCharRec(5,9,-1,0,7,ch246data); + +/* char: 0xf5 */ + +static final byte[] ch245data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch245 = new BitmapCharRec(5,10,-1,0,7,ch245data); + +/* char: 0xf4 */ + +static final byte[] ch244data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch244 = new BitmapCharRec(5,10,-1,0,7,ch244data); + +/* char: 0xf3 */ + +static final byte[] ch243data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch243 = new BitmapCharRec(5,10,-1,0,7,ch243data); + +/* char: 0xf2 */ + +static final byte[] ch242data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch242 = new BitmapCharRec(5,10,-1,0,7,ch242data); + +/* char: 0xf1 */ + +static final byte[] ch241data = { +(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch241 = new BitmapCharRec(5,10,-1,0,7,ch241data); + +/* char: 0xf0 */ + +static final byte[] ch240data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x78,(byte) 0x8,(byte) 0x50,(byte) 0x30,(byte) 0x68, +}; + +static final BitmapCharRec ch240 = new BitmapCharRec(5,10,-1,0,7,ch240data); + +/* char: 0xef */ + +static final byte[] ch239data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch239 = new BitmapCharRec(3,9,0,0,3,ch239data); + +/* char: 0xee */ + +static final byte[] ch238data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch238 = new BitmapCharRec(3,10,0,0,3,ch238data); + +/* char: 0xed */ + +static final byte[] ch237data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch237 = new BitmapCharRec(2,10,-1,0,3,ch237data); + +/* char: 0xec */ + +static final byte[] ch236data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch236 = new BitmapCharRec(2,10,0,0,3,ch236data); + +/* char: 0xeb */ + +static final byte[] ch235data = { +(byte) 0x70,(byte) 0x88,(byte) 0x80,(byte) 0xf8,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch235 = new BitmapCharRec(5,9,-1,0,7,ch235data); + +/* char: 0xea */ + +static final byte[] ch234data = { +(byte) 0x70,(byte) 0x88,(byte) 0x80,(byte) 0xf8,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch234 = new BitmapCharRec(5,10,-1,0,7,ch234data); + +/* char: 0xe9 */ + +static final byte[] ch233data = { +(byte) 0x70,(byte) 0x88,(byte) 0x80,(byte) 0xf8,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch233 = new BitmapCharRec(5,10,-1,0,7,ch233data); + +/* char: 0xe8 */ + +static final byte[] ch232data = { +(byte) 0x70,(byte) 0x88,(byte) 0x80,(byte) 0xf8,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch232 = new BitmapCharRec(5,10,-1,0,7,ch232data); + +/* char: 0xe7 */ + +static final byte[] ch231data = { +(byte) 0x60,(byte) 0x10,(byte) 0x20,(byte) 0x70,(byte) 0x88,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch231 = new BitmapCharRec(5,10,-1,3,7,ch231data); + +/* char: 0xe6 */ + +static final byte[] ch230data = { +(byte) 0x77,(byte) 0x0,(byte) 0x88,(byte) 0x80,(byte) 0x88,(byte) 0x0,(byte) 0x7f,(byte) 0x80,(byte) 0x8,(byte) 0x80,(byte) 0x88,(byte) 0x80,(byte) 0x77,(byte) 0x0, +}; + +static final BitmapCharRec ch230 = new BitmapCharRec(9,7,-1,0,11,ch230data); + +/* char: 0xe5 */ + +static final byte[] ch229data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x78,(byte) 0x8,(byte) 0x88,(byte) 0x70,(byte) 0x30,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch229 = new BitmapCharRec(6,10,-1,0,7,ch229data); + +/* char: 0xe4 */ + +static final byte[] ch228data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x78,(byte) 0x8,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch228 = new BitmapCharRec(6,9,-1,0,7,ch228data); + +/* char: 0xe3 */ + +static final byte[] ch227data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x78,(byte) 0x8,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch227 = new BitmapCharRec(6,10,-1,0,7,ch227data); + +/* char: 0xe2 */ + +static final byte[] ch226data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x78,(byte) 0x8,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch226 = new BitmapCharRec(6,10,-1,0,7,ch226data); + +/* char: 0xe1 */ + +static final byte[] ch225data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x78,(byte) 0x8,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch225 = new BitmapCharRec(6,10,-1,0,7,ch225data); + +/* char: 0xe0 */ + +static final byte[] ch224data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x78,(byte) 0x8,(byte) 0x88,(byte) 0x70,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch224 = new BitmapCharRec(6,10,-1,0,7,ch224data); + +/* char: 0xdf */ + +static final byte[] ch223data = { +(byte) 0xb0,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xb0,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch223 = new BitmapCharRec(5,9,-1,0,7,ch223data); + +/* char: 0xde */ + +static final byte[] ch222data = { +(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xf8,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch222 = new BitmapCharRec(6,9,-1,0,8,ch222data); + +/* char: 0xdd */ + +static final byte[] ch221data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x82,(byte) 0x82,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch221 = new BitmapCharRec(7,12,-1,0,9,ch221data); + +/* char: 0xdc */ + +static final byte[] ch220data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x48, +}; + +static final BitmapCharRec ch220 = new BitmapCharRec(6,11,-1,0,8,ch220data); + +/* char: 0xdb */ + +static final byte[] ch219data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch219 = new BitmapCharRec(6,12,-1,0,8,ch219data); + +/* char: 0xda */ + +static final byte[] ch218data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch218 = new BitmapCharRec(6,12,-1,0,8,ch218data); + +/* char: 0xd9 */ + +static final byte[] ch217data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch217 = new BitmapCharRec(6,12,-1,0,8,ch217data); + +/* char: 0xd8 */ + +static final byte[] ch216data = { +(byte) 0x80,(byte) 0x0,(byte) 0x5e,(byte) 0x0,(byte) 0x21,(byte) 0x0,(byte) 0x50,(byte) 0x80,(byte) 0x48,(byte) 0x80,(byte) 0x44,(byte) 0x80,(byte) 0x44,(byte) 0x80,(byte) 0x42,(byte) 0x80, +(byte) 0x21,(byte) 0x0,(byte) 0x1e,(byte) 0x80,(byte) 0x0,(byte) 0x40, +}; + +static final BitmapCharRec ch216 = new BitmapCharRec(10,11,0,1,10,ch216data); + +/* char: 0xd7 */ + +static final byte[] ch215data = { +(byte) 0x88,(byte) 0x50,(byte) 0x20,(byte) 0x50,(byte) 0x88, +}; + +static final BitmapCharRec ch215 = new BitmapCharRec(5,5,-1,-1,7,ch215data); + +/* char: 0xd6 */ + +static final byte[] ch214data = { +(byte) 0x3c,(byte) 0x42,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x42,(byte) 0x3c,(byte) 0x0,(byte) 0x24, +}; + +static final BitmapCharRec ch214 = new BitmapCharRec(8,11,-1,0,10,ch214data); + +/* char: 0xd5 */ + +static final byte[] ch213data = { +(byte) 0x3c,(byte) 0x42,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x42,(byte) 0x3c,(byte) 0x0,(byte) 0x28,(byte) 0x14, +}; + +static final BitmapCharRec ch213 = new BitmapCharRec(8,12,-1,0,10,ch213data); + +/* char: 0xd4 */ + +static final byte[] ch212data = { +(byte) 0x3c,(byte) 0x42,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x42,(byte) 0x3c,(byte) 0x0,(byte) 0x14,(byte) 0x8, +}; + +static final BitmapCharRec ch212 = new BitmapCharRec(8,12,-1,0,10,ch212data); + +/* char: 0xd3 */ + +static final byte[] ch211data = { +(byte) 0x3c,(byte) 0x42,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x42,(byte) 0x3c,(byte) 0x0,(byte) 0x8,(byte) 0x4, +}; + +static final BitmapCharRec ch211 = new BitmapCharRec(8,12,-1,0,10,ch211data); + +/* char: 0xd2 */ + +static final byte[] ch210data = { +(byte) 0x3c,(byte) 0x42,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x42,(byte) 0x3c,(byte) 0x0,(byte) 0x8,(byte) 0x10, +}; + +static final BitmapCharRec ch210 = new BitmapCharRec(8,12,-1,0,10,ch210data); + +/* char: 0xd1 */ + +static final byte[] ch209data = { +(byte) 0x82,(byte) 0x86,(byte) 0x8a,(byte) 0x8a,(byte) 0x92,(byte) 0xa2,(byte) 0xa2,(byte) 0xc2,(byte) 0x82,(byte) 0x0,(byte) 0x28,(byte) 0x14, +}; + +static final BitmapCharRec ch209 = new BitmapCharRec(7,12,-1,0,9,ch209data); + +/* char: 0xd0 */ + +static final byte[] ch208data = { +(byte) 0x7c,(byte) 0x42,(byte) 0x41,(byte) 0x41,(byte) 0xf1,(byte) 0x41,(byte) 0x41,(byte) 0x42,(byte) 0x7c, +}; + +static final BitmapCharRec ch208 = new BitmapCharRec(8,9,0,0,9,ch208data); + +/* char: 0xcf */ + +static final byte[] ch207data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch207 = new BitmapCharRec(3,11,0,0,3,ch207data); + +/* char: 0xce */ + +static final byte[] ch206data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch206 = new BitmapCharRec(3,12,0,0,3,ch206data); + +/* char: 0xcd */ + +static final byte[] ch205data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch205 = new BitmapCharRec(2,12,-1,0,3,ch205data); + +/* char: 0xcc */ + +static final byte[] ch204data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch204 = new BitmapCharRec(2,12,0,0,3,ch204data); + +/* char: 0xcb */ + +static final byte[] ch203data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x0,(byte) 0x28, +}; + +static final BitmapCharRec ch203 = new BitmapCharRec(6,11,-1,0,8,ch203data); + +/* char: 0xca */ + +static final byte[] ch202data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x0,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch202 = new BitmapCharRec(6,12,-1,0,8,ch202data); + +/* char: 0xc9 */ + +static final byte[] ch201data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch201 = new BitmapCharRec(6,12,-1,0,8,ch201data); + +/* char: 0xc8 */ + +static final byte[] ch200data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch200 = new BitmapCharRec(6,12,-1,0,8,ch200data); + +/* char: 0xc7 */ + +static final byte[] ch199data = { +(byte) 0x30,(byte) 0x8,(byte) 0x8,(byte) 0x3c,(byte) 0x42,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x42,(byte) 0x3c, +}; + +static final BitmapCharRec ch199 = new BitmapCharRec(7,12,-1,3,9,ch199data); + +/* char: 0xc6 */ + +static final byte[] ch198data = { +(byte) 0x8f,(byte) 0x80,(byte) 0x88,(byte) 0x0,(byte) 0x88,(byte) 0x0,(byte) 0x78,(byte) 0x0,(byte) 0x4f,(byte) 0x80,(byte) 0x48,(byte) 0x0,(byte) 0x28,(byte) 0x0,(byte) 0x28,(byte) 0x0, +(byte) 0x1f,(byte) 0x80, +}; + +static final BitmapCharRec ch198 = new BitmapCharRec(9,9,-1,0,11,ch198data); + +/* char: 0xc5 */ + +static final byte[] ch197data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch197 = new BitmapCharRec(7,12,-1,0,9,ch197data); + +/* char: 0xc4 */ + +static final byte[] ch196data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x28, +}; + +static final BitmapCharRec ch196 = new BitmapCharRec(7,11,-1,0,9,ch196data); + +/* char: 0xc3 */ + +static final byte[] ch195data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x28,(byte) 0x14, +}; + +static final BitmapCharRec ch195 = new BitmapCharRec(7,12,-1,0,9,ch195data); + +/* char: 0xc2 */ + +static final byte[] ch194data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch194 = new BitmapCharRec(7,12,-1,0,9,ch194data); + +/* char: 0xc1 */ + +static final byte[] ch193data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch193 = new BitmapCharRec(7,12,-1,0,9,ch193data); + +/* char: 0xc0 */ + +static final byte[] ch192data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x10,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch192 = new BitmapCharRec(7,12,-1,0,9,ch192data); + +/* char: 0xbf */ + +static final byte[] ch191data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x0,(byte) 0x20, +}; + +static final BitmapCharRec ch191 = new BitmapCharRec(5,9,-1,3,7,ch191data); + +/* char: 0xbe */ + +static final byte[] ch190data = { +(byte) 0x21,(byte) 0x0,(byte) 0x17,(byte) 0x80,(byte) 0x15,(byte) 0x0,(byte) 0xb,(byte) 0x0,(byte) 0xc9,(byte) 0x0,(byte) 0x24,(byte) 0x0,(byte) 0x44,(byte) 0x0,(byte) 0x22,(byte) 0x0, +(byte) 0xe1,(byte) 0x0, +}; + +static final BitmapCharRec ch190 = new BitmapCharRec(9,9,0,0,10,ch190data); + +/* char: 0xbd */ + +static final byte[] ch189data = { +(byte) 0x47,(byte) 0x80,(byte) 0x22,(byte) 0x0,(byte) 0x11,(byte) 0x0,(byte) 0x14,(byte) 0x80,(byte) 0x4b,(byte) 0x0,(byte) 0x48,(byte) 0x0,(byte) 0x44,(byte) 0x0,(byte) 0xc2,(byte) 0x0, +(byte) 0x41,(byte) 0x0, +}; + +static final BitmapCharRec ch189 = new BitmapCharRec(9,9,0,0,10,ch189data); + +/* char: 0xbc */ + +static final byte[] ch188data = { +(byte) 0x41,(byte) 0x0,(byte) 0x27,(byte) 0x80,(byte) 0x15,(byte) 0x0,(byte) 0x13,(byte) 0x0,(byte) 0x49,(byte) 0x0,(byte) 0x44,(byte) 0x0,(byte) 0x44,(byte) 0x0,(byte) 0xc2,(byte) 0x0, +(byte) 0x41,(byte) 0x0, +}; + +static final BitmapCharRec ch188 = new BitmapCharRec(9,9,0,0,10,ch188data); + +/* char: 0xbb */ + +static final byte[] ch187data = { +(byte) 0xa0,(byte) 0x50,(byte) 0x28,(byte) 0x50,(byte) 0xa0, +}; + +static final BitmapCharRec ch187 = new BitmapCharRec(5,5,-1,-1,7,ch187data); + +/* char: 0xba */ + +static final byte[] ch186data = { +(byte) 0xe0,(byte) 0x0,(byte) 0xe0,(byte) 0xa0,(byte) 0xe0, +}; + +static final BitmapCharRec ch186 = new BitmapCharRec(3,5,-1,-4,5,ch186data); + +/* char: 0xb9 */ + +static final byte[] ch185data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch185 = new BitmapCharRec(2,5,-1,-3,4,ch185data); + +/* char: 0xb8 */ + +static final byte[] ch184data = { +(byte) 0xc0,(byte) 0x20,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch184 = new BitmapCharRec(3,4,0,3,3,ch184data); + +/* char: 0xb7 */ + +static final byte[] ch183data = { +(byte) 0x80, +}; + +static final BitmapCharRec ch183 = new BitmapCharRec(1,1,-1,-3,3,ch183data); + +/* char: 0xb6 */ + +static final byte[] ch182data = { +(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x68,(byte) 0xe8,(byte) 0xe8,(byte) 0xe8,(byte) 0x68,(byte) 0x3c, +}; + +static final BitmapCharRec ch182 = new BitmapCharRec(6,12,0,3,7,ch182data); + +/* char: 0xb5 */ + +static final byte[] ch181data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xe8,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch181 = new BitmapCharRec(5,10,-1,3,7,ch181data); + +/* char: 0xb4 */ + +static final byte[] ch180data = { +(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch180 = new BitmapCharRec(2,2,0,-8,2,ch180data); + +/* char: 0xb3 */ + +static final byte[] ch179data = { +(byte) 0xc0,(byte) 0x20,(byte) 0x40,(byte) 0x20,(byte) 0xe0, +}; + +static final BitmapCharRec ch179 = new BitmapCharRec(3,5,0,-3,4,ch179data); + +/* char: 0xb2 */ + +static final byte[] ch178data = { +(byte) 0xf0,(byte) 0x40,(byte) 0x20,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch178 = new BitmapCharRec(4,5,0,-3,4,ch178data); + +/* char: 0xb1 */ + +static final byte[] ch177data = { +(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch177 = new BitmapCharRec(5,7,-1,0,7,ch177data); + +/* char: 0xb0 */ + +static final byte[] ch176data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch176 = new BitmapCharRec(4,4,0,-4,5,ch176data); + +/* char: 0xaf */ + +static final byte[] ch175data = { +(byte) 0xf0, +}; + +static final BitmapCharRec ch175 = new BitmapCharRec(4,1,0,-8,4,ch175data); + +/* char: 0xae */ + +static final byte[] ch174data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x41,(byte) 0x0,(byte) 0x94,(byte) 0x80,(byte) 0x94,(byte) 0x80,(byte) 0x98,(byte) 0x80,(byte) 0x94,(byte) 0x80,(byte) 0x9c,(byte) 0x80,(byte) 0x41,(byte) 0x0, +(byte) 0x3e,(byte) 0x0, +}; + +static final BitmapCharRec ch174 = new BitmapCharRec(9,9,-1,0,11,ch174data); + +/* char: 0xad */ + +static final byte[] ch173data = { +(byte) 0xf0, +}; + +static final BitmapCharRec ch173 = new BitmapCharRec(4,1,0,-3,5,ch173data); + +/* char: 0xac */ + +static final byte[] ch172data = { +(byte) 0x4,(byte) 0x4,(byte) 0x4,(byte) 0xfc, +}; + +static final BitmapCharRec ch172 = new BitmapCharRec(6,4,-1,-2,8,ch172data); + +/* char: 0xab */ + +static final byte[] ch171data = { +(byte) 0x28,(byte) 0x50,(byte) 0xa0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch171 = new BitmapCharRec(5,5,-1,-1,7,ch171data); + +/* char: 0xaa */ + +static final byte[] ch170data = { +(byte) 0xe0,(byte) 0x0,(byte) 0xa0,(byte) 0x20,(byte) 0xe0, +}; + +static final BitmapCharRec ch170 = new BitmapCharRec(3,5,-1,-4,5,ch170data); + +/* char: 0xa9 */ + +static final byte[] ch169data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x41,(byte) 0x0,(byte) 0x9c,(byte) 0x80,(byte) 0xa2,(byte) 0x80,(byte) 0xa0,(byte) 0x80,(byte) 0xa2,(byte) 0x80,(byte) 0x9c,(byte) 0x80,(byte) 0x41,(byte) 0x0, +(byte) 0x3e,(byte) 0x0, +}; + +static final BitmapCharRec ch169 = new BitmapCharRec(9,9,-1,0,11,ch169data); + +/* char: 0xa8 */ + +static final byte[] ch168data = { +(byte) 0xa0, +}; + +static final BitmapCharRec ch168 = new BitmapCharRec(3,1,0,-8,3,ch168data); + +/* char: 0xa7 */ + +static final byte[] ch167data = { +(byte) 0x70,(byte) 0x88,(byte) 0x8,(byte) 0x30,(byte) 0x48,(byte) 0x88,(byte) 0x88,(byte) 0x90,(byte) 0x60,(byte) 0x80,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch167 = new BitmapCharRec(5,12,0,3,6,ch167data); + +/* char: 0xa6 */ + +static final byte[] ch166data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch166 = new BitmapCharRec(1,11,-1,2,3,ch166data); + +/* char: 0xa5 */ + +static final byte[] ch165data = { +(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x50,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch165 = new BitmapCharRec(5,9,-1,0,7,ch165data); + +/* char: 0xa4 */ + +static final byte[] ch164data = { +(byte) 0x84,(byte) 0x78,(byte) 0x48,(byte) 0x48,(byte) 0x78,(byte) 0x84, +}; + +static final BitmapCharRec ch164 = new BitmapCharRec(6,6,0,-1,7,ch164data); + +/* char: 0xa3 */ + +static final byte[] ch163data = { +(byte) 0xb0,(byte) 0x48,(byte) 0x20,(byte) 0x20,(byte) 0xf0,(byte) 0x40,(byte) 0x40,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch163 = new BitmapCharRec(5,9,-1,0,7,ch163data); + +/* char: 0xa2 */ + +static final byte[] ch162data = { +(byte) 0x40,(byte) 0x70,(byte) 0xc8,(byte) 0xa0,(byte) 0xa0,(byte) 0xa0,(byte) 0xa8,(byte) 0x70,(byte) 0x10, +}; + +static final BitmapCharRec ch162 = new BitmapCharRec(5,9,-1,1,7,ch162data); + +/* char: 0xa1 */ + +static final byte[] ch161data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch161 = new BitmapCharRec(1,10,-1,3,3,ch161data); + +/* char: 0xa0 */ + +static final BitmapCharRec ch160 = new BitmapCharRec(0,0,0,0,4,null); + +/* char: 0x7e '~' */ + +static final byte[] ch126data = { +(byte) 0x98,(byte) 0x64, +}; + +static final BitmapCharRec ch126 = new BitmapCharRec(6,2,0,-3,7,ch126data); + +/* char: 0x7d '}' */ + +static final byte[] ch125data = { +(byte) 0xc0,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x10,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xc0, +}; + +static final BitmapCharRec ch125 = new BitmapCharRec(4,12,0,3,4,ch125data); + +/* char: 0x7c '|' */ + +static final byte[] ch124data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch124 = new BitmapCharRec(1,12,-1,3,3,ch124data); + +/* char: 0x7b '{' */ + +static final byte[] ch123data = { +(byte) 0x30,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x30, +}; + +static final BitmapCharRec ch123 = new BitmapCharRec(4,12,0,3,4,ch123data); + +/* char: 0x7a 'z' */ + +static final byte[] ch122data = { +(byte) 0xf0,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0xf0, +}; + +static final BitmapCharRec ch122 = new BitmapCharRec(4,7,-1,0,6,ch122data); + +/* char: 0x79 'y' */ + +static final byte[] ch121data = { +(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x50,(byte) 0x50,(byte) 0x90,(byte) 0x88,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch121 = new BitmapCharRec(5,10,-1,3,7,ch121data); + +/* char: 0x78 'x' */ + +static final byte[] ch120data = { +(byte) 0x84,(byte) 0x84,(byte) 0x48,(byte) 0x30,(byte) 0x30,(byte) 0x48,(byte) 0x84, +}; + +static final BitmapCharRec ch120 = new BitmapCharRec(6,7,0,0,6,ch120data); + +/* char: 0x77 'w' */ + +static final byte[] ch119data = { +(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x55,(byte) 0x0,(byte) 0x49,(byte) 0x0,(byte) 0x49,(byte) 0x0,(byte) 0x88,(byte) 0x80,(byte) 0x88,(byte) 0x80, +}; + +static final BitmapCharRec ch119 = new BitmapCharRec(9,7,0,0,9,ch119data); + +/* char: 0x76 'v' */ + +static final byte[] ch118data = { +(byte) 0x20,(byte) 0x20,(byte) 0x50,(byte) 0x50,(byte) 0x88,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch118 = new BitmapCharRec(5,7,-1,0,7,ch118data); + +/* char: 0x75 'u' */ + +static final byte[] ch117data = { +(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88, +}; + +static final BitmapCharRec ch117 = new BitmapCharRec(5,7,-1,0,7,ch117data); + +/* char: 0x74 't' */ + +static final byte[] ch116data = { +(byte) 0x60,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x40,(byte) 0x40, +}; + +static final BitmapCharRec ch116 = new BitmapCharRec(3,9,0,0,3,ch116data); + +/* char: 0x73 's' */ + +static final byte[] ch115data = { +(byte) 0x60,(byte) 0x90,(byte) 0x10,(byte) 0x60,(byte) 0x80,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch115 = new BitmapCharRec(4,7,-1,0,6,ch115data); + +/* char: 0x72 'r' */ + +static final byte[] ch114data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xc0,(byte) 0xa0, +}; + +static final BitmapCharRec ch114 = new BitmapCharRec(3,7,-1,0,4,ch114data); + +/* char: 0x71 'q' */ + +static final byte[] ch113data = { +(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x98,(byte) 0x68, +}; + +static final BitmapCharRec ch113 = new BitmapCharRec(5,10,-1,3,7,ch113data); + +/* char: 0x70 'p' */ + +static final byte[] ch112data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xb0,(byte) 0xc8,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0, +}; + +static final BitmapCharRec ch112 = new BitmapCharRec(5,10,-1,3,7,ch112data); + +/* char: 0x6f 'o' */ + +static final byte[] ch111data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch111 = new BitmapCharRec(5,7,-1,0,7,ch111data); + +/* char: 0x6e 'n' */ + +static final byte[] ch110data = { +(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0, +}; + +static final BitmapCharRec ch110 = new BitmapCharRec(5,7,-1,0,7,ch110data); + +/* char: 0x6d 'm' */ + +static final byte[] ch109data = { +(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0xda,(byte) 0xa4, +}; + +static final BitmapCharRec ch109 = new BitmapCharRec(7,7,-1,0,9,ch109data); + +/* char: 0x6c 'l' */ + +static final byte[] ch108data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch108 = new BitmapCharRec(1,9,-1,0,3,ch108data); + +/* char: 0x6b 'k' */ + +static final byte[] ch107data = { +(byte) 0x88,(byte) 0x90,(byte) 0xa0,(byte) 0xc0,(byte) 0xc0,(byte) 0xa0,(byte) 0x90,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch107 = new BitmapCharRec(5,9,-1,0,6,ch107data); + +/* char: 0x6a 'j' */ + +static final byte[] ch106data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0x40, +}; + +static final BitmapCharRec ch106 = new BitmapCharRec(2,12,0,3,3,ch106data); + +/* char: 0x69 'i' */ + +static final byte[] ch105data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch105 = new BitmapCharRec(1,9,-1,0,3,ch105data); + +/* char: 0x68 'h' */ + +static final byte[] ch104data = { +(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch104 = new BitmapCharRec(5,9,-1,0,7,ch104data); + +/* char: 0x67 'g' */ + +static final byte[] ch103data = { +(byte) 0x70,(byte) 0x88,(byte) 0x8,(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x98,(byte) 0x68, +}; + +static final BitmapCharRec ch103 = new BitmapCharRec(5,10,-1,3,7,ch103data); + +/* char: 0x66 'f' */ + +static final byte[] ch102data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x40,(byte) 0x30, +}; + +static final BitmapCharRec ch102 = new BitmapCharRec(4,9,0,0,3,ch102data); + +/* char: 0x65 'e' */ + +static final byte[] ch101data = { +(byte) 0x70,(byte) 0x88,(byte) 0x80,(byte) 0xf8,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch101 = new BitmapCharRec(5,7,-1,0,7,ch101data); + +/* char: 0x64 'd' */ + +static final byte[] ch100data = { +(byte) 0x68,(byte) 0x98,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x98,(byte) 0x68,(byte) 0x8,(byte) 0x8, +}; + +static final BitmapCharRec ch100 = new BitmapCharRec(5,9,-1,0,7,ch100data); + +/* char: 0x63 'c' */ + +static final byte[] ch99data = { +(byte) 0x70,(byte) 0x88,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch99 = new BitmapCharRec(5,7,-1,0,7,ch99data); + +/* char: 0x62 'b' */ + +static final byte[] ch98data = { +(byte) 0xb0,(byte) 0xc8,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch98 = new BitmapCharRec(5,9,-1,0,7,ch98data); + +/* char: 0x61 'a' */ + +static final byte[] ch97data = { +(byte) 0x74,(byte) 0x88,(byte) 0x88,(byte) 0x78,(byte) 0x8,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch97 = new BitmapCharRec(6,7,-1,0,7,ch97data); + +/* char: 0x60 '`' */ + +static final byte[] ch96data = { +(byte) 0xc0,(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch96 = new BitmapCharRec(2,3,0,-6,3,ch96data); + +/* char: 0x5f '_' */ + +static final byte[] ch95data = { +(byte) 0xfe, +}; + +static final BitmapCharRec ch95 = new BitmapCharRec(7,1,0,2,7,ch95data); + +/* char: 0x5e '^' */ + +static final byte[] ch94data = { +(byte) 0x88,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch94 = new BitmapCharRec(5,3,0,-5,6,ch94data); + +/* char: 0x5d ']' */ + +static final byte[] ch93data = { +(byte) 0xc0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0, +}; + +static final BitmapCharRec ch93 = new BitmapCharRec(2,12,0,3,3,ch93data); + +/* char: 0x5c '\' */ + +static final byte[] ch92data = { +(byte) 0x10,(byte) 0x10,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch92 = new BitmapCharRec(4,9,0,0,4,ch92data); + +/* char: 0x5b '[' */ + +static final byte[] ch91data = { +(byte) 0xc0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xc0, +}; + +static final BitmapCharRec ch91 = new BitmapCharRec(2,12,-1,3,3,ch91data); + +/* char: 0x5a 'Z' */ + +static final byte[] ch90data = { +(byte) 0xfe,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x4,(byte) 0x2,(byte) 0xfe, +}; + +static final BitmapCharRec ch90 = new BitmapCharRec(7,9,-1,0,9,ch90data); + +/* char: 0x59 'Y' */ + +static final byte[] ch89data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch89 = new BitmapCharRec(7,9,-1,0,9,ch89data); + +/* char: 0x58 'X' */ + +static final byte[] ch88data = { +(byte) 0x82,(byte) 0x44,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x82, +}; + +static final BitmapCharRec ch88 = new BitmapCharRec(7,9,-1,0,9,ch88data); + +/* char: 0x57 'W' */ + +static final byte[] ch87data = { +(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x55,(byte) 0x0,(byte) 0x55,(byte) 0x0,(byte) 0x49,(byte) 0x0,(byte) 0x88,(byte) 0x80,(byte) 0x88,(byte) 0x80, +(byte) 0x88,(byte) 0x80, +}; + +static final BitmapCharRec ch87 = new BitmapCharRec(9,9,-1,0,11,ch87data); + +/* char: 0x56 'V' */ + +static final byte[] ch86data = { +(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch86 = new BitmapCharRec(7,9,-1,0,9,ch86data); + +/* char: 0x55 'U' */ + +static final byte[] ch85data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x84, +}; + +static final BitmapCharRec ch85 = new BitmapCharRec(6,9,-1,0,8,ch85data); + +/* char: 0x54 'T' */ + +static final byte[] ch84data = { +(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0xfe, +}; + +static final BitmapCharRec ch84 = new BitmapCharRec(7,9,0,0,7,ch84data); + +/* char: 0x53 'S' */ + +static final byte[] ch83data = { +(byte) 0x78,(byte) 0x84,(byte) 0x84,(byte) 0x4,(byte) 0x18,(byte) 0x60,(byte) 0x80,(byte) 0x84,(byte) 0x78, +}; + +static final BitmapCharRec ch83 = new BitmapCharRec(6,9,-1,0,8,ch83data); + +/* char: 0x52 'R' */ + +static final byte[] ch82data = { +(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0x88,(byte) 0xf8,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xf8, +}; + +static final BitmapCharRec ch82 = new BitmapCharRec(6,9,-1,0,8,ch82data); + +/* char: 0x51 'Q' */ + +static final byte[] ch81data = { +(byte) 0x3d,(byte) 0x42,(byte) 0x85,(byte) 0x89,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x42,(byte) 0x3c, +}; + +static final BitmapCharRec ch81 = new BitmapCharRec(8,9,-1,0,10,ch81data); + +/* char: 0x50 'P' */ + +static final byte[] ch80data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xf8, +}; + +static final BitmapCharRec ch80 = new BitmapCharRec(6,9,-1,0,8,ch80data); + +/* char: 0x4f 'O' */ + +static final byte[] ch79data = { +(byte) 0x3c,(byte) 0x42,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x81,(byte) 0x42,(byte) 0x3c, +}; + +static final BitmapCharRec ch79 = new BitmapCharRec(8,9,-1,0,10,ch79data); + +/* char: 0x4e 'N' */ + +static final byte[] ch78data = { +(byte) 0x82,(byte) 0x86,(byte) 0x8a,(byte) 0x8a,(byte) 0x92,(byte) 0xa2,(byte) 0xa2,(byte) 0xc2,(byte) 0x82, +}; + +static final BitmapCharRec ch78 = new BitmapCharRec(7,9,-1,0,9,ch78data); + +/* char: 0x4d 'M' */ + +static final byte[] ch77data = { +(byte) 0x88,(byte) 0x80,(byte) 0x88,(byte) 0x80,(byte) 0x94,(byte) 0x80,(byte) 0x94,(byte) 0x80,(byte) 0xa2,(byte) 0x80,(byte) 0xa2,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80, +(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch77 = new BitmapCharRec(9,9,-1,0,11,ch77data); + +/* char: 0x4c 'L' */ + +static final byte[] ch76data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch76 = new BitmapCharRec(5,9,-1,0,7,ch76data); + +/* char: 0x4b 'K' */ + +static final byte[] ch75data = { +(byte) 0x82,(byte) 0x84,(byte) 0x88,(byte) 0x90,(byte) 0xe0,(byte) 0xa0,(byte) 0x90,(byte) 0x88,(byte) 0x84, +}; + +static final BitmapCharRec ch75 = new BitmapCharRec(7,9,-1,0,8,ch75data); + +/* char: 0x4a 'J' */ + +static final byte[] ch74data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8,(byte) 0x8, +}; + +static final BitmapCharRec ch74 = new BitmapCharRec(5,9,-1,0,7,ch74data); + +/* char: 0x49 'I' */ + +static final byte[] ch73data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch73 = new BitmapCharRec(1,9,-1,0,3,ch73data); + +/* char: 0x48 'H' */ + +static final byte[] ch72data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0xfe,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82, +}; + +static final BitmapCharRec ch72 = new BitmapCharRec(7,9,-1,0,9,ch72data); + +/* char: 0x47 'G' */ + +static final byte[] ch71data = { +(byte) 0x3a,(byte) 0x46,(byte) 0x82,(byte) 0x82,(byte) 0x8e,(byte) 0x80,(byte) 0x80,(byte) 0x42,(byte) 0x3c, +}; + +static final BitmapCharRec ch71 = new BitmapCharRec(7,9,-1,0,9,ch71data); + +/* char: 0x46 'F' */ + +static final byte[] ch70data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc, +}; + +static final BitmapCharRec ch70 = new BitmapCharRec(6,9,-1,0,8,ch70data); + +/* char: 0x45 'E' */ + +static final byte[] ch69data = { +(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xfc, +}; + +static final BitmapCharRec ch69 = new BitmapCharRec(6,9,-1,0,8,ch69data); + +/* char: 0x44 'D' */ + +static final byte[] ch68data = { +(byte) 0xf8,(byte) 0x84,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x84,(byte) 0xf8, +}; + +static final BitmapCharRec ch68 = new BitmapCharRec(7,9,-1,0,9,ch68data); + +/* char: 0x43 'C' */ + +static final byte[] ch67data = { +(byte) 0x3c,(byte) 0x42,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x42,(byte) 0x3c, +}; + +static final BitmapCharRec ch67 = new BitmapCharRec(7,9,-1,0,9,ch67data); + +/* char: 0x42 'B' */ + +static final byte[] ch66data = { +(byte) 0xf8,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xf8,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xf8, +}; + +static final BitmapCharRec ch66 = new BitmapCharRec(6,9,-1,0,8,ch66data); + +/* char: 0x41 'A' */ + +static final byte[] ch65data = { +(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x7c,(byte) 0x44,(byte) 0x44,(byte) 0x28,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch65 = new BitmapCharRec(7,9,-1,0,9,ch65data); + +/* char: 0x40 '@' */ + +static final byte[] ch64data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x40,(byte) 0x0,(byte) 0x9b,(byte) 0x0,(byte) 0xa6,(byte) 0x80,(byte) 0xa2,(byte) 0x40,(byte) 0xa2,(byte) 0x40,(byte) 0x92,(byte) 0x40,(byte) 0x4d,(byte) 0x40, +(byte) 0x60,(byte) 0x80,(byte) 0x1f,(byte) 0x0, +}; + +static final BitmapCharRec ch64 = new BitmapCharRec(10,10,-1,1,12,ch64data); + +/* char: 0x3f '?' */ + +static final byte[] ch63data = { +(byte) 0x20,(byte) 0x0,(byte) 0x20,(byte) 0x20,(byte) 0x10,(byte) 0x10,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch63 = new BitmapCharRec(5,9,-1,0,7,ch63data); + +/* char: 0x3e '>' */ + +static final byte[] ch62data = { +(byte) 0xc0,(byte) 0x30,(byte) 0xc,(byte) 0x30,(byte) 0xc0, +}; + +static final BitmapCharRec ch62 = new BitmapCharRec(6,5,-1,-1,7,ch62data); + +/* char: 0x3d '=' */ + +static final byte[] ch61data = { +(byte) 0xf8,(byte) 0x0,(byte) 0xf8, +}; + +static final BitmapCharRec ch61 = new BitmapCharRec(5,3,-1,-2,7,ch61data); + +/* char: 0x3c '<' */ + +static final byte[] ch60data = { +(byte) 0xc,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc, +}; + +static final BitmapCharRec ch60 = new BitmapCharRec(6,5,0,-1,7,ch60data); + +/* char: 0x3b ';' */ + +static final byte[] ch59data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x40, +}; + +static final BitmapCharRec ch59 = new BitmapCharRec(2,8,0,2,3,ch59data); + +/* char: 0x3a ':' */ + +static final byte[] ch58data = { +(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch58 = new BitmapCharRec(1,6,-1,0,3,ch58data); + +/* char: 0x39 '9' */ + +static final byte[] ch57data = { +(byte) 0x70,(byte) 0x88,(byte) 0x8,(byte) 0x8,(byte) 0x78,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch57 = new BitmapCharRec(5,9,-1,0,7,ch57data); + +/* char: 0x38 '8' */ + +static final byte[] ch56data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch56 = new BitmapCharRec(5,9,-1,0,7,ch56data); + +/* char: 0x37 '7' */ + +static final byte[] ch55data = { +(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x10,(byte) 0x10,(byte) 0x8,(byte) 0xf8, +}; + +static final BitmapCharRec ch55 = new BitmapCharRec(5,9,-1,0,7,ch55data); + +/* char: 0x36 '6' */ + +static final byte[] ch54data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0xc8,(byte) 0xb0,(byte) 0x80,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch54 = new BitmapCharRec(5,9,-1,0,7,ch54data); + +/* char: 0x35 '5' */ + +static final byte[] ch53data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x8,(byte) 0x8,(byte) 0xf0,(byte) 0x80,(byte) 0x80,(byte) 0xf8, +}; + +static final BitmapCharRec ch53 = new BitmapCharRec(5,9,-1,0,7,ch53data); + +/* char: 0x34 '4' */ + +static final byte[] ch52data = { +(byte) 0x8,(byte) 0x8,(byte) 0xfc,(byte) 0x88,(byte) 0x48,(byte) 0x28,(byte) 0x28,(byte) 0x18,(byte) 0x8, +}; + +static final BitmapCharRec ch52 = new BitmapCharRec(6,9,0,0,7,ch52data); + +/* char: 0x33 '3' */ + +static final byte[] ch51data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x8,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch51 = new BitmapCharRec(5,9,-1,0,7,ch51data); + +/* char: 0x32 '2' */ + +static final byte[] ch50data = { +(byte) 0xf8,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x8,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch50 = new BitmapCharRec(5,9,-1,0,7,ch50data); + +/* char: 0x31 '1' */ + +static final byte[] ch49data = { +(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xe0,(byte) 0x20, +}; + +static final BitmapCharRec ch49 = new BitmapCharRec(3,9,-1,0,7,ch49data); + +/* char: 0x30 '0' */ + +static final byte[] ch48data = { +(byte) 0x70,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x88,(byte) 0x70, +}; + +static final BitmapCharRec ch48 = new BitmapCharRec(5,9,-1,0,7,ch48data); + +/* char: 0x2f '/' */ + +static final byte[] ch47data = { +(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x10,(byte) 0x10, +}; + +static final BitmapCharRec ch47 = new BitmapCharRec(4,9,0,0,4,ch47data); + +/* char: 0x2e '.' */ + +static final byte[] ch46data = { +(byte) 0x80, +}; + +static final BitmapCharRec ch46 = new BitmapCharRec(1,1,-1,0,3,ch46data); + +/* char: 0x2d '-' */ + +static final byte[] ch45data = { +(byte) 0xf8, +}; + +static final BitmapCharRec ch45 = new BitmapCharRec(5,1,-1,-3,8,ch45data); + +/* char: 0x2c ',' */ + +static final byte[] ch44data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40, +}; + +static final BitmapCharRec ch44 = new BitmapCharRec(2,3,-1,2,4,ch44data); + +/* char: 0x2b '+' */ + +static final byte[] ch43data = { +(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch43 = new BitmapCharRec(5,5,-1,-1,7,ch43data); + +/* char: 0x2a '*' */ + +static final byte[] ch42data = { +(byte) 0xa0,(byte) 0x40,(byte) 0xa0, +}; + +static final BitmapCharRec ch42 = new BitmapCharRec(3,3,-1,-6,5,ch42data); + +/* char: 0x29 ')' */ + +static final byte[] ch41data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch41 = new BitmapCharRec(3,12,0,3,4,ch41data); + +/* char: 0x28 '(' */ + +static final byte[] ch40data = { +(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch40 = new BitmapCharRec(3,12,-1,3,4,ch40data); + +/* char: 0x27 ''' */ + +static final byte[] ch39data = { +(byte) 0x80,(byte) 0x40,(byte) 0xc0, +}; + +static final BitmapCharRec ch39 = new BitmapCharRec(2,3,-1,-6,3,ch39data); + +/* char: 0x26 '&' */ + +static final byte[] ch38data = { +(byte) 0x72,(byte) 0x8c,(byte) 0x84,(byte) 0x8a,(byte) 0x50,(byte) 0x30,(byte) 0x48,(byte) 0x48,(byte) 0x30, +}; + +static final BitmapCharRec ch38 = new BitmapCharRec(7,9,-1,0,9,ch38data); + +/* char: 0x25 '%' */ + +static final byte[] ch37data = { +(byte) 0x23,(byte) 0x0,(byte) 0x14,(byte) 0x80,(byte) 0x14,(byte) 0x80,(byte) 0x13,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x68,(byte) 0x0,(byte) 0x94,(byte) 0x0,(byte) 0x94,(byte) 0x0, +(byte) 0x62,(byte) 0x0, +}; + +static final BitmapCharRec ch37 = new BitmapCharRec(9,9,-1,0,11,ch37data); + +/* char: 0x24 '$' */ + +static final byte[] ch36data = { +(byte) 0x20,(byte) 0x70,(byte) 0xa8,(byte) 0xa8,(byte) 0x28,(byte) 0x70,(byte) 0xa0,(byte) 0xa8,(byte) 0x70,(byte) 0x20, +}; + +static final BitmapCharRec ch36 = new BitmapCharRec(5,10,-1,1,7,ch36data); + +/* char: 0x23 '#' */ + +static final byte[] ch35data = { +(byte) 0x50,(byte) 0x50,(byte) 0x50,(byte) 0xfc,(byte) 0x28,(byte) 0xfc,(byte) 0x28,(byte) 0x28, +}; + +static final BitmapCharRec ch35 = new BitmapCharRec(6,8,0,0,7,ch35data); + +/* char: 0x22 '"' */ + +static final byte[] ch34data = { +(byte) 0xa0,(byte) 0xa0,(byte) 0xa0, +}; + +static final BitmapCharRec ch34 = new BitmapCharRec(3,3,-1,-6,5,ch34data); + +/* char: 0x21 '!' */ + +static final byte[] ch33data = { +(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch33 = new BitmapCharRec(1,9,-1,0,3,ch33data); + +/* char: 0x20 ' ' */ + +static final BitmapCharRec ch32 = new BitmapCharRec(0,0,0,0,4,null); + +static final BitmapCharRec[] chars = { +ch32, +ch33, +ch34, +ch35, +ch36, +ch37, +ch38, +ch39, +ch40, +ch41, +ch42, +ch43, +ch44, +ch45, +ch46, +ch47, +ch48, +ch49, +ch50, +ch51, +ch52, +ch53, +ch54, +ch55, +ch56, +ch57, +ch58, +ch59, +ch60, +ch61, +ch62, +ch63, +ch64, +ch65, +ch66, +ch67, +ch68, +ch69, +ch70, +ch71, +ch72, +ch73, +ch74, +ch75, +ch76, +ch77, +ch78, +ch79, +ch80, +ch81, +ch82, +ch83, +ch84, +ch85, +ch86, +ch87, +ch88, +ch89, +ch90, +ch91, +ch92, +ch93, +ch94, +ch95, +ch96, +ch97, +ch98, +ch99, +ch100, +ch101, +ch102, +ch103, +ch104, +ch105, +ch106, +ch107, +ch108, +ch109, +ch110, +ch111, +ch112, +ch113, +ch114, +ch115, +ch116, +ch117, +ch118, +ch119, +ch120, +ch121, +ch122, +ch123, +ch124, +ch125, +ch126, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +ch160, +ch161, +ch162, +ch163, +ch164, +ch165, +ch166, +ch167, +ch168, +ch169, +ch170, +ch171, +ch172, +ch173, +ch174, +ch175, +ch176, +ch177, +ch178, +ch179, +ch180, +ch181, +ch182, +ch183, +ch184, +ch185, +ch186, +ch187, +ch188, +ch189, +ch190, +ch191, +ch192, +ch193, +ch194, +ch195, +ch196, +ch197, +ch198, +ch199, +ch200, +ch201, +ch202, +ch203, +ch204, +ch205, +ch206, +ch207, +ch208, +ch209, +ch210, +ch211, +ch212, +ch213, +ch214, +ch215, +ch216, +ch217, +ch218, +ch219, +ch220, +ch221, +ch222, +ch223, +ch224, +ch225, +ch226, +ch227, +ch228, +ch229, +ch230, +ch231, +ch232, +ch233, +ch234, +ch235, +ch236, +ch237, +ch238, +ch239, +ch240, +ch241, +ch242, +ch243, +ch244, +ch245, +ch246, +ch247, +ch248, +ch249, +ch250, +ch251, +ch252, +ch253, +ch254, +ch255, +}; + + public static final BitmapFontRec glutBitmapHelvetica12 = new BitmapFontRec("-adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1", + 224, + 32, + chars); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapHelvetica18.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapHelvetica18.java new file mode 100644 index 000000000..1b2e69ba4 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapHelvetica18.java @@ -0,0 +1,1917 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +class GLUTBitmapHelvetica18 { + +/* GENERATED FILE -- DO NOT MODIFY */ + +/* char: 0xff */ + +static final byte[] ch255data = { +(byte) 0x70,(byte) 0x70,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x3c,(byte) 0x24,(byte) 0x66,(byte) 0x66,(byte) 0x66,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0x0,(byte) 0x66, +(byte) 0x66, +}; + +static final BitmapCharRec ch255 = new BitmapCharRec(8,17,-1,4,10,ch255data); + +/* char: 0xfe */ + +static final byte[] ch254data = { +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xde,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xe3,(byte) 0x0,(byte) 0xc1,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xe3,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xde,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0, +}; + +static final BitmapCharRec ch254 = new BitmapCharRec(9,18,-1,4,11,ch254data); + +/* char: 0xfd */ + +static final byte[] ch253data = { +(byte) 0x70,(byte) 0x70,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x3c,(byte) 0x24,(byte) 0x66,(byte) 0x66,(byte) 0x66,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0x0,(byte) 0x18, +(byte) 0xc,(byte) 0x6, +}; + +static final BitmapCharRec ch253 = new BitmapCharRec(8,18,-1,4,10,ch253data); + +/* char: 0xfc */ + +static final byte[] ch252data = { +(byte) 0x73,(byte) 0xfb,(byte) 0xc7,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0x0,(byte) 0x66,(byte) 0x66, +}; + +static final BitmapCharRec ch252 = new BitmapCharRec(8,13,-1,0,10,ch252data); + +/* char: 0xfb */ + +static final byte[] ch251data = { +(byte) 0x73,(byte) 0xfb,(byte) 0xc7,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0x0,(byte) 0x66,(byte) 0x3c,(byte) 0x18, +}; + +static final BitmapCharRec ch251 = new BitmapCharRec(8,14,-1,0,10,ch251data); + +/* char: 0xfa */ + +static final byte[] ch250data = { +(byte) 0x73,(byte) 0xfb,(byte) 0xc7,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x6, +}; + +static final BitmapCharRec ch250 = new BitmapCharRec(8,14,-1,0,10,ch250data); + +/* char: 0xf9 */ + +static final byte[] ch249data = { +(byte) 0x73,(byte) 0xfb,(byte) 0xc7,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0x0,(byte) 0xc,(byte) 0x18,(byte) 0x30, +}; + +static final BitmapCharRec ch249 = new BitmapCharRec(8,14,-1,0,10,ch249data); + +/* char: 0xf8 */ + +static final byte[] ch248data = { +(byte) 0xce,(byte) 0x0,(byte) 0x7f,(byte) 0x80,(byte) 0x31,(byte) 0x80,(byte) 0x78,(byte) 0xc0,(byte) 0x6c,(byte) 0xc0,(byte) 0x66,(byte) 0xc0,(byte) 0x63,(byte) 0xc0,(byte) 0x31,(byte) 0x80, +(byte) 0x3f,(byte) 0xc0,(byte) 0xe,(byte) 0x60, +}; + +static final BitmapCharRec ch248 = new BitmapCharRec(11,10,0,0,11,ch248data); + +/* char: 0xf7 */ + +static final byte[] ch247data = { +(byte) 0x18,(byte) 0x18,(byte) 0x0,(byte) 0xff,(byte) 0xff,(byte) 0x0,(byte) 0x18,(byte) 0x18, +}; + +static final BitmapCharRec ch247 = new BitmapCharRec(8,8,-1,-1,10,ch247data); + +/* char: 0xf6 */ + +static final byte[] ch246data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x63,(byte) 0x0, +(byte) 0x7f,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x36,(byte) 0x0,(byte) 0x36,(byte) 0x0, +}; + +static final BitmapCharRec ch246 = new BitmapCharRec(9,13,-1,0,11,ch246data); + +/* char: 0xf5 */ + +static final byte[] ch245data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x63,(byte) 0x0, +(byte) 0x7f,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x26,(byte) 0x0,(byte) 0x2d,(byte) 0x0,(byte) 0x19,(byte) 0x0, +}; + +static final BitmapCharRec ch245 = new BitmapCharRec(9,14,-1,0,11,ch245data); + +/* char: 0xf4 */ + +static final byte[] ch244data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x63,(byte) 0x0, +(byte) 0x7f,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0xc,(byte) 0x0, +}; + +static final BitmapCharRec ch244 = new BitmapCharRec(9,14,-1,0,11,ch244data); + +/* char: 0xf3 */ + +static final byte[] ch243data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x63,(byte) 0x0, +(byte) 0x7f,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x6,(byte) 0x0, +}; + +static final BitmapCharRec ch243 = new BitmapCharRec(9,14,-1,0,11,ch243data); + +/* char: 0xf2 */ + +static final byte[] ch242data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x63,(byte) 0x0, +(byte) 0x7f,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x30,(byte) 0x0, +}; + +static final BitmapCharRec ch242 = new BitmapCharRec(9,14,-1,0,11,ch242data); + +/* char: 0xf1 */ + +static final byte[] ch241data = { +(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xe3,(byte) 0xdf,(byte) 0xce,(byte) 0x0,(byte) 0x4c,(byte) 0x5a,(byte) 0x32, +}; + +static final BitmapCharRec ch241 = new BitmapCharRec(8,14,-1,0,10,ch241data); + +/* char: 0xf0 */ + +static final byte[] ch240data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x63,(byte) 0x0, +(byte) 0x7f,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x4c,(byte) 0x0,(byte) 0x38,(byte) 0x0,(byte) 0x36,(byte) 0x0,(byte) 0x60,(byte) 0x0, +}; + +static final BitmapCharRec ch240 = new BitmapCharRec(9,14,-1,0,11,ch240data); + +/* char: 0xef */ + +static final byte[] ch239data = { +(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x0,(byte) 0xd8,(byte) 0xd8, +}; + +static final BitmapCharRec ch239 = new BitmapCharRec(5,13,0,0,4,ch239data); + +/* char: 0xee */ + +static final byte[] ch238data = { +(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x0,(byte) 0xcc,(byte) 0x78,(byte) 0x30, +}; + +static final BitmapCharRec ch238 = new BitmapCharRec(6,14,1,0,4,ch238data); + +/* char: 0xed */ + +static final byte[] ch237data = { +(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x0,(byte) 0xc0,(byte) 0x60,(byte) 0x30, +}; + +static final BitmapCharRec ch237 = new BitmapCharRec(4,14,0,0,4,ch237data); + +/* char: 0xec */ + +static final byte[] ch236data = { +(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x0,(byte) 0x30,(byte) 0x60,(byte) 0xc0, +}; + +static final BitmapCharRec ch236 = new BitmapCharRec(4,14,0,0,4,ch236data); + +/* char: 0xeb */ + +static final byte[] ch235data = { +(byte) 0x3c,(byte) 0x7f,(byte) 0xe3,(byte) 0xc0,(byte) 0xc0,(byte) 0xff,(byte) 0xc3,(byte) 0xc3,(byte) 0x7e,(byte) 0x3c,(byte) 0x0,(byte) 0x36,(byte) 0x36, +}; + +static final BitmapCharRec ch235 = new BitmapCharRec(8,13,-1,0,10,ch235data); + +/* char: 0xea */ + +static final byte[] ch234data = { +(byte) 0x3c,(byte) 0x7f,(byte) 0xe3,(byte) 0xc0,(byte) 0xc0,(byte) 0xff,(byte) 0xc3,(byte) 0xc3,(byte) 0x7e,(byte) 0x3c,(byte) 0x0,(byte) 0x66,(byte) 0x3c,(byte) 0x18, +}; + +static final BitmapCharRec ch234 = new BitmapCharRec(8,14,-1,0,10,ch234data); + +/* char: 0xe9 */ + +static final byte[] ch233data = { +(byte) 0x3c,(byte) 0x7f,(byte) 0xe3,(byte) 0xc0,(byte) 0xc0,(byte) 0xff,(byte) 0xc3,(byte) 0xc3,(byte) 0x7e,(byte) 0x3c,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x6, +}; + +static final BitmapCharRec ch233 = new BitmapCharRec(8,14,-1,0,10,ch233data); + +/* char: 0xe8 */ + +static final byte[] ch232data = { +(byte) 0x3c,(byte) 0x7f,(byte) 0xe3,(byte) 0xc0,(byte) 0xc0,(byte) 0xff,(byte) 0xc3,(byte) 0xc3,(byte) 0x7e,(byte) 0x3c,(byte) 0x0,(byte) 0x18,(byte) 0x30,(byte) 0x60, +}; + +static final BitmapCharRec ch232 = new BitmapCharRec(8,14,-1,0,10,ch232data); + +/* char: 0xe7 */ + +static final byte[] ch231data = { +(byte) 0x78,(byte) 0x6c,(byte) 0xc,(byte) 0x38,(byte) 0x3e,(byte) 0x7f,(byte) 0x63,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x63,(byte) 0x7f,(byte) 0x3e, +}; + +static final BitmapCharRec ch231 = new BitmapCharRec(8,14,-1,4,10,ch231data); + +/* char: 0xe6 */ + +static final byte[] ch230data = { +(byte) 0x75,(byte) 0xe0,(byte) 0xef,(byte) 0xf8,(byte) 0xc7,(byte) 0x18,(byte) 0xc6,(byte) 0x0,(byte) 0xe6,(byte) 0x0,(byte) 0x7f,(byte) 0xf8,(byte) 0xe,(byte) 0x18,(byte) 0xc6,(byte) 0x18, +(byte) 0xef,(byte) 0xf0,(byte) 0x7d,(byte) 0xe0, +}; + +static final BitmapCharRec ch230 = new BitmapCharRec(13,10,-1,0,15,ch230data); + +/* char: 0xe5 */ + +static final byte[] ch229data = { +(byte) 0x76,(byte) 0xee,(byte) 0xc6,(byte) 0xc6,(byte) 0xe6,(byte) 0x7e,(byte) 0xe,(byte) 0xc6,(byte) 0xee,(byte) 0x7c,(byte) 0x38,(byte) 0x6c,(byte) 0x6c,(byte) 0x38, +}; + +static final BitmapCharRec ch229 = new BitmapCharRec(7,14,-1,0,9,ch229data); + +/* char: 0xe4 */ + +static final byte[] ch228data = { +(byte) 0x76,(byte) 0xee,(byte) 0xc6,(byte) 0xc6,(byte) 0xe6,(byte) 0x7e,(byte) 0xe,(byte) 0xc6,(byte) 0xee,(byte) 0x7c,(byte) 0x0,(byte) 0x6c,(byte) 0x6c, +}; + +static final BitmapCharRec ch228 = new BitmapCharRec(7,13,-1,0,9,ch228data); + +/* char: 0xe3 */ + +static final byte[] ch227data = { +(byte) 0x76,(byte) 0xee,(byte) 0xc6,(byte) 0xc6,(byte) 0xe6,(byte) 0x7e,(byte) 0xe,(byte) 0xc6,(byte) 0xee,(byte) 0x7c,(byte) 0x0,(byte) 0x4c,(byte) 0x5a,(byte) 0x32, +}; + +static final BitmapCharRec ch227 = new BitmapCharRec(7,14,-1,0,9,ch227data); + +/* char: 0xe2 */ + +static final byte[] ch226data = { +(byte) 0x76,(byte) 0xee,(byte) 0xc6,(byte) 0xc6,(byte) 0xe6,(byte) 0x7e,(byte) 0xe,(byte) 0xc6,(byte) 0xee,(byte) 0x7c,(byte) 0x0,(byte) 0x66,(byte) 0x3c,(byte) 0x18, +}; + +static final BitmapCharRec ch226 = new BitmapCharRec(7,14,-1,0,9,ch226data); + +/* char: 0xe1 */ + +static final byte[] ch225data = { +(byte) 0x76,(byte) 0xee,(byte) 0xc6,(byte) 0xc6,(byte) 0xe6,(byte) 0x7e,(byte) 0xe,(byte) 0xc6,(byte) 0xee,(byte) 0x7c,(byte) 0x0,(byte) 0x30,(byte) 0x18,(byte) 0xc, +}; + +static final BitmapCharRec ch225 = new BitmapCharRec(7,14,-1,0,9,ch225data); + +/* char: 0xe0 */ + +static final byte[] ch224data = { +(byte) 0x76,(byte) 0xee,(byte) 0xc6,(byte) 0xc6,(byte) 0xe6,(byte) 0x7e,(byte) 0xe,(byte) 0xc6,(byte) 0xee,(byte) 0x7c,(byte) 0x0,(byte) 0x18,(byte) 0x30,(byte) 0x60, +}; + +static final BitmapCharRec ch224 = new BitmapCharRec(7,14,-1,0,9,ch224data); + +/* char: 0xdf */ + +static final byte[] ch223data = { +(byte) 0xdc,(byte) 0xde,(byte) 0xc6,(byte) 0xc6,(byte) 0xc6,(byte) 0xc6,(byte) 0xdc,(byte) 0xdc,(byte) 0xc6,(byte) 0xc6,(byte) 0xc6,(byte) 0xc6,(byte) 0x7c,(byte) 0x38, +}; + +static final BitmapCharRec ch223 = new BitmapCharRec(7,14,-1,0,9,ch223data); + +/* char: 0xde */ + +static final byte[] ch222data = { +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xc1,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc1,(byte) 0xc0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0, +}; + +static final BitmapCharRec ch222 = new BitmapCharRec(10,14,-1,0,12,ch222data); + +/* char: 0xdd */ + +static final byte[] ch221data = { +(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x19,(byte) 0x80, +(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0x0,(byte) 0x0,(byte) 0x6,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x1,(byte) 0x80, +}; + +static final BitmapCharRec ch221 = new BitmapCharRec(12,18,-1,0,14,ch221data); + +/* char: 0xdc */ + +static final byte[] ch220data = { +(byte) 0x1f,(byte) 0x0,(byte) 0x7f,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60, +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0x0,(byte) 0x0,(byte) 0x19,(byte) 0x80, +(byte) 0x19,(byte) 0x80, +}; + +static final BitmapCharRec ch220 = new BitmapCharRec(11,17,-1,0,13,ch220data); + +/* char: 0xdb */ + +static final byte[] ch219data = { +(byte) 0x1f,(byte) 0x0,(byte) 0x7f,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60, +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0x0,(byte) 0x0,(byte) 0x19,(byte) 0x80, +(byte) 0xf,(byte) 0x0,(byte) 0x6,(byte) 0x0, +}; + +static final BitmapCharRec ch219 = new BitmapCharRec(11,18,-1,0,13,ch219data); + +/* char: 0xda */ + +static final byte[] ch218data = { +(byte) 0x1f,(byte) 0x0,(byte) 0x7f,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60, +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0x0,(byte) 0x0,(byte) 0xc,(byte) 0x0, +(byte) 0x6,(byte) 0x0,(byte) 0x3,(byte) 0x0, +}; + +static final BitmapCharRec ch218 = new BitmapCharRec(11,18,-1,0,13,ch218data); + +/* char: 0xd9 */ + +static final byte[] ch217data = { +(byte) 0x1f,(byte) 0x0,(byte) 0x7f,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60, +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0x0,(byte) 0x0,(byte) 0x6,(byte) 0x0, +(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0x0, +}; + +static final BitmapCharRec ch217 = new BitmapCharRec(11,18,-1,0,13,ch217data); + +/* char: 0xd8 */ + +static final byte[] ch216data = { +(byte) 0xc7,(byte) 0xc0,(byte) 0xff,(byte) 0xf0,(byte) 0x78,(byte) 0x38,(byte) 0x38,(byte) 0x18,(byte) 0x6c,(byte) 0x1c,(byte) 0x6e,(byte) 0xc,(byte) 0x67,(byte) 0xc,(byte) 0x63,(byte) 0x8c, +(byte) 0x61,(byte) 0xcc,(byte) 0x70,(byte) 0xdc,(byte) 0x30,(byte) 0x78,(byte) 0x38,(byte) 0x38,(byte) 0x1f,(byte) 0xfc,(byte) 0x7,(byte) 0xcc, +}; + +static final BitmapCharRec ch216 = new BitmapCharRec(14,14,0,0,15,ch216data); + +/* char: 0xd7 */ + +static final byte[] ch215data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x33,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x61,(byte) 0x80, +(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch215 = new BitmapCharRec(10,9,0,0,10,ch215data); + +/* char: 0xd6 */ + +static final byte[] ch214data = { +(byte) 0xf,(byte) 0x80,(byte) 0x3f,(byte) 0xe0,(byte) 0x70,(byte) 0x70,(byte) 0x60,(byte) 0x30,(byte) 0xe0,(byte) 0x38,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18, +(byte) 0xc0,(byte) 0x18,(byte) 0xe0,(byte) 0x38,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70,(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0xd,(byte) 0x80, +(byte) 0xd,(byte) 0x80, +}; + +static final BitmapCharRec ch214 = new BitmapCharRec(13,17,-1,0,15,ch214data); + +/* char: 0xd5 */ + +static final byte[] ch213data = { +(byte) 0xf,(byte) 0x80,(byte) 0x3f,(byte) 0xe0,(byte) 0x70,(byte) 0x70,(byte) 0x60,(byte) 0x30,(byte) 0xe0,(byte) 0x38,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18, +(byte) 0xc0,(byte) 0x18,(byte) 0xe0,(byte) 0x38,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70,(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x9,(byte) 0x80, +(byte) 0xb,(byte) 0x40,(byte) 0x6,(byte) 0x40, +}; + +static final BitmapCharRec ch213 = new BitmapCharRec(13,18,-1,0,15,ch213data); + +/* char: 0xd4 */ + +static final byte[] ch212data = { +(byte) 0xf,(byte) 0x80,(byte) 0x3f,(byte) 0xe0,(byte) 0x70,(byte) 0x70,(byte) 0x60,(byte) 0x30,(byte) 0xe0,(byte) 0x38,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18, +(byte) 0xc0,(byte) 0x18,(byte) 0xe0,(byte) 0x38,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70,(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0xc,(byte) 0xc0, +(byte) 0x7,(byte) 0x80,(byte) 0x3,(byte) 0x0, +}; + +static final BitmapCharRec ch212 = new BitmapCharRec(13,18,-1,0,15,ch212data); + +/* char: 0xd3 */ + +static final byte[] ch211data = { +(byte) 0xf,(byte) 0x80,(byte) 0x3f,(byte) 0xe0,(byte) 0x70,(byte) 0x70,(byte) 0x60,(byte) 0x30,(byte) 0xe0,(byte) 0x38,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18, +(byte) 0xc0,(byte) 0x18,(byte) 0xe0,(byte) 0x38,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70,(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x3,(byte) 0x0, +(byte) 0x1,(byte) 0x80,(byte) 0x0,(byte) 0xc0, +}; + +static final BitmapCharRec ch211 = new BitmapCharRec(13,18,-1,0,15,ch211data); + +/* char: 0xd2 */ + +static final byte[] ch210data = { +(byte) 0xf,(byte) 0x80,(byte) 0x3f,(byte) 0xe0,(byte) 0x70,(byte) 0x70,(byte) 0x60,(byte) 0x30,(byte) 0xe0,(byte) 0x38,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18, +(byte) 0xc0,(byte) 0x18,(byte) 0xe0,(byte) 0x38,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70,(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x3,(byte) 0x0, +(byte) 0x6,(byte) 0x0,(byte) 0xc,(byte) 0x0, +}; + +static final BitmapCharRec ch210 = new BitmapCharRec(13,18,-1,0,15,ch210data); + +/* char: 0xd1 */ + +static final byte[] ch209data = { +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xe0,(byte) 0xc1,(byte) 0xe0,(byte) 0xc1,(byte) 0xe0,(byte) 0xc3,(byte) 0x60,(byte) 0xc6,(byte) 0x60,(byte) 0xc6,(byte) 0x60,(byte) 0xcc,(byte) 0x60, +(byte) 0xcc,(byte) 0x60,(byte) 0xd8,(byte) 0x60,(byte) 0xd8,(byte) 0x60,(byte) 0xf0,(byte) 0x60,(byte) 0xe0,(byte) 0x60,(byte) 0xe0,(byte) 0x60,(byte) 0x0,(byte) 0x0,(byte) 0x13,(byte) 0x0, +(byte) 0x16,(byte) 0x80,(byte) 0xc,(byte) 0x80, +}; + +static final BitmapCharRec ch209 = new BitmapCharRec(11,18,-1,0,13,ch209data); + +/* char: 0xd0 */ + +static final byte[] ch208data = { +(byte) 0x7f,(byte) 0x80,(byte) 0x7f,(byte) 0xc0,(byte) 0x60,(byte) 0xe0,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x30,(byte) 0x60,(byte) 0x30,(byte) 0xfc,(byte) 0x30,(byte) 0xfc,(byte) 0x30, +(byte) 0x60,(byte) 0x30,(byte) 0x60,(byte) 0x30,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0xe0,(byte) 0x7f,(byte) 0xc0,(byte) 0x7f,(byte) 0x80, +}; + +static final BitmapCharRec ch208 = new BitmapCharRec(12,14,0,0,13,ch208data); + +/* char: 0xcf */ + +static final byte[] ch207data = { +(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x0,(byte) 0xcc, +(byte) 0xcc, +}; + +static final BitmapCharRec ch207 = new BitmapCharRec(6,17,0,0,6,ch207data); + +/* char: 0xce */ + +static final byte[] ch206data = { +(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x0,(byte) 0xcc, +(byte) 0x78,(byte) 0x30, +}; + +static final BitmapCharRec ch206 = new BitmapCharRec(6,18,0,0,6,ch206data); + +/* char: 0xcd */ + +static final byte[] ch205data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0, +(byte) 0x60,(byte) 0x30, +}; + +static final BitmapCharRec ch205 = new BitmapCharRec(4,18,-2,0,6,ch205data); + +/* char: 0xcc */ + +static final byte[] ch204data = { +(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x0,(byte) 0x30, +(byte) 0x60,(byte) 0xc0, +}; + +static final BitmapCharRec ch204 = new BitmapCharRec(4,18,0,0,6,ch204data); + +/* char: 0xcb */ + +static final byte[] ch203data = { +(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x33,(byte) 0x0, +(byte) 0x33,(byte) 0x0, +}; + +static final BitmapCharRec ch203 = new BitmapCharRec(9,17,-1,0,11,ch203data); + +/* char: 0xca */ + +static final byte[] ch202data = { +(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x33,(byte) 0x0, +(byte) 0x1e,(byte) 0x0,(byte) 0xc,(byte) 0x0, +}; + +static final BitmapCharRec ch202 = new BitmapCharRec(9,18,-1,0,11,ch202data); + +/* char: 0xc9 */ + +static final byte[] ch201data = { +(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0xc,(byte) 0x0, +(byte) 0x6,(byte) 0x0,(byte) 0x3,(byte) 0x0, +}; + +static final BitmapCharRec ch201 = new BitmapCharRec(9,18,-1,0,11,ch201data); + +/* char: 0xc8 */ + +static final byte[] ch200data = { +(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0xc,(byte) 0x0, +(byte) 0x18,(byte) 0x0,(byte) 0x30,(byte) 0x0, +}; + +static final BitmapCharRec ch200 = new BitmapCharRec(9,18,-1,0,11,ch200data); + +/* char: 0xc7 */ + +static final byte[] ch199data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x1b,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0xe,(byte) 0x0,(byte) 0xf,(byte) 0x80,(byte) 0x3f,(byte) 0xe0,(byte) 0x70,(byte) 0x70,(byte) 0x60,(byte) 0x30, +(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xe0,(byte) 0x0,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70, +(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80, +}; + +static final BitmapCharRec ch199 = new BitmapCharRec(12,18,-1,4,14,ch199data); + +/* char: 0xc6 */ + +static final byte[] ch198data = { +(byte) 0xc1,(byte) 0xff,(byte) 0xc1,(byte) 0xff,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x7f,(byte) 0x80,(byte) 0x3f,(byte) 0x80,(byte) 0x31,(byte) 0xfe,(byte) 0x31,(byte) 0xfe, +(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0xd,(byte) 0x80,(byte) 0xd,(byte) 0x80,(byte) 0x7,(byte) 0xff,(byte) 0x7,(byte) 0xff, +}; + +static final BitmapCharRec ch198 = new BitmapCharRec(16,14,-1,0,18,ch198data); + +/* char: 0xc5 */ + +static final byte[] ch197data = { +(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x7f,(byte) 0xe0,(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0, +(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0xf,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x19,(byte) 0x80, +(byte) 0x19,(byte) 0x80,(byte) 0xf,(byte) 0x0, +}; + +static final BitmapCharRec ch197 = new BitmapCharRec(12,18,0,0,12,ch197data); + +/* char: 0xc4 */ + +static final byte[] ch196data = { +(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x7f,(byte) 0xe0,(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0, +(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0xf,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x19,(byte) 0x80, +(byte) 0x19,(byte) 0x80, +}; + +static final BitmapCharRec ch196 = new BitmapCharRec(12,17,0,0,12,ch196data); + +/* char: 0xc3 */ + +static final byte[] ch195data = { +(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x7f,(byte) 0xe0,(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0, +(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0xf,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x13,(byte) 0x0, +(byte) 0x16,(byte) 0x80,(byte) 0xc,(byte) 0x80, +}; + +static final BitmapCharRec ch195 = new BitmapCharRec(12,18,0,0,12,ch195data); + +/* char: 0xc2 */ + +static final byte[] ch194data = { +(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x7f,(byte) 0xe0,(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0, +(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0xf,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x19,(byte) 0x80, +(byte) 0xf,(byte) 0x0,(byte) 0x6,(byte) 0x0, +}; + +static final BitmapCharRec ch194 = new BitmapCharRec(12,18,0,0,12,ch194data); + +/* char: 0xc1 */ + +static final byte[] ch193data = { +(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x7f,(byte) 0xe0,(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0, +(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0xf,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x6,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x1,(byte) 0x80, +}; + +static final BitmapCharRec ch193 = new BitmapCharRec(12,18,0,0,12,ch193data); + +/* char: 0xc0 */ + +static final byte[] ch192data = { +(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x7f,(byte) 0xe0,(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0, +(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0xf,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x6,(byte) 0x0, +(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0x0, +}; + +static final BitmapCharRec ch192 = new BitmapCharRec(12,18,0,0,12,ch192data); + +/* char: 0xbf */ + +static final byte[] ch191data = { +(byte) 0x7c,(byte) 0xfe,(byte) 0xc6,(byte) 0xc6,(byte) 0xe0,(byte) 0x70,(byte) 0x38,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x0,(byte) 0x0,(byte) 0x18,(byte) 0x18, +}; + +static final BitmapCharRec ch191 = new BitmapCharRec(7,14,-1,4,10,ch191data); + +/* char: 0xbe */ + +static final byte[] ch190data = { +(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0xc,(byte) 0xfc,(byte) 0x6,(byte) 0xd8,(byte) 0x6,(byte) 0x78,(byte) 0x73,(byte) 0x38,(byte) 0xf9,(byte) 0x18,(byte) 0x99,(byte) 0x88, +(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x98,(byte) 0x60,(byte) 0xf8,(byte) 0x30,(byte) 0x70,(byte) 0x30, +}; + +static final BitmapCharRec ch190 = new BitmapCharRec(14,13,0,0,15,ch190data); + +/* char: 0xbd */ + +static final byte[] ch189data = { +(byte) 0x30,(byte) 0xf8,(byte) 0x30,(byte) 0xf8,(byte) 0x18,(byte) 0x60,(byte) 0xc,(byte) 0x30,(byte) 0xc,(byte) 0x18,(byte) 0x66,(byte) 0x98,(byte) 0x62,(byte) 0xf8,(byte) 0x63,(byte) 0x70, +(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xe0,(byte) 0xc0,(byte) 0xe0,(byte) 0x60,(byte) 0x60,(byte) 0x60, +}; + +static final BitmapCharRec ch189 = new BitmapCharRec(13,13,-1,0,15,ch189data); + +/* char: 0xbc */ + +static final byte[] ch188data = { +(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x19,(byte) 0xf8,(byte) 0xd,(byte) 0xb0,(byte) 0xc,(byte) 0xf0,(byte) 0x66,(byte) 0x70,(byte) 0x62,(byte) 0x30,(byte) 0x63,(byte) 0x10, +(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xe0,(byte) 0xc0,(byte) 0xe0,(byte) 0x60,(byte) 0x60,(byte) 0x60, +}; + +static final BitmapCharRec ch188 = new BitmapCharRec(13,13,-1,0,15,ch188data); + +/* char: 0xbb */ + +static final byte[] ch187data = { +(byte) 0x90,(byte) 0xd8,(byte) 0x6c,(byte) 0x36,(byte) 0x36,(byte) 0x6c,(byte) 0xd8,(byte) 0x90, +}; + +static final BitmapCharRec ch187 = new BitmapCharRec(7,8,-1,-1,9,ch187data); + +/* char: 0xba */ + +static final byte[] ch186data = { +(byte) 0xf8,(byte) 0x0,(byte) 0x70,(byte) 0xd8,(byte) 0x88,(byte) 0x88,(byte) 0xd8,(byte) 0x70, +}; + +static final BitmapCharRec ch186 = new BitmapCharRec(5,8,-1,-6,7,ch186data); + +/* char: 0xb9 */ + +static final byte[] ch185data = { +(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0xe0,(byte) 0xe0,(byte) 0x60, +}; + +static final BitmapCharRec ch185 = new BitmapCharRec(3,8,-1,-5,6,ch185data); + +/* char: 0xb8 */ + +static final byte[] ch184data = { +(byte) 0xf0,(byte) 0xd8,(byte) 0x18,(byte) 0x70,(byte) 0x60, +}; + +static final BitmapCharRec ch184 = new BitmapCharRec(5,5,0,4,5,ch184data); + +/* char: 0xb7 */ + +static final byte[] ch183data = { +(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch183 = new BitmapCharRec(2,2,-1,-4,4,ch183data); + +/* char: 0xb6 */ + +static final byte[] ch182data = { +(byte) 0x12,(byte) 0x12,(byte) 0x12,(byte) 0x12,(byte) 0x12,(byte) 0x12,(byte) 0x12,(byte) 0x12,(byte) 0x12,(byte) 0x12,(byte) 0x32,(byte) 0x72,(byte) 0xf2,(byte) 0xf2,(byte) 0xf2,(byte) 0xf2, +(byte) 0x72,(byte) 0x3f, +}; + +static final BitmapCharRec ch182 = new BitmapCharRec(8,18,-1,4,10,ch182data); + +/* char: 0xb5 */ + +static final byte[] ch181data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xdb,(byte) 0xff,(byte) 0xe7,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3, +}; + +static final BitmapCharRec ch181 = new BitmapCharRec(8,14,-1,4,10,ch181data); + +/* char: 0xb4 */ + +static final byte[] ch180data = { +(byte) 0xc0,(byte) 0x60,(byte) 0x30, +}; + +static final BitmapCharRec ch180 = new BitmapCharRec(4,3,0,-11,4,ch180data); + +/* char: 0xb3 */ + +static final byte[] ch179data = { +(byte) 0x70,(byte) 0xf8,(byte) 0x98,(byte) 0x30,(byte) 0x30,(byte) 0x98,(byte) 0xf8,(byte) 0x70, +}; + +static final BitmapCharRec ch179 = new BitmapCharRec(5,8,0,-5,6,ch179data); + +/* char: 0xb2 */ + +static final byte[] ch178data = { +(byte) 0xf8,(byte) 0xf8,(byte) 0x60,(byte) 0x30,(byte) 0x18,(byte) 0x98,(byte) 0xf8,(byte) 0x70, +}; + +static final BitmapCharRec ch178 = new BitmapCharRec(5,8,0,-5,6,ch178data); + +/* char: 0xb1 */ + +static final byte[] ch177data = { +(byte) 0xff,(byte) 0xff,(byte) 0x0,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0xff,(byte) 0xff,(byte) 0x18,(byte) 0x18,(byte) 0x18, +}; + +static final BitmapCharRec ch177 = new BitmapCharRec(8,11,-1,0,10,ch177data); + +/* char: 0xb0 */ + +static final byte[] ch176data = { +(byte) 0x70,(byte) 0xd8,(byte) 0x88,(byte) 0xd8,(byte) 0x70, +}; + +static final BitmapCharRec ch176 = new BitmapCharRec(5,5,-1,-8,7,ch176data); + +/* char: 0xaf */ + +static final byte[] ch175data = { +(byte) 0xf8, +}; + +static final BitmapCharRec ch175 = new BitmapCharRec(5,1,0,-12,5,ch175data); + +/* char: 0xae */ + +static final byte[] ch174data = { +(byte) 0xf,(byte) 0x80,(byte) 0x30,(byte) 0x60,(byte) 0x40,(byte) 0x10,(byte) 0x48,(byte) 0x50,(byte) 0x88,(byte) 0x88,(byte) 0x89,(byte) 0x8,(byte) 0x8f,(byte) 0x88,(byte) 0x88,(byte) 0x48, +(byte) 0x88,(byte) 0x48,(byte) 0x4f,(byte) 0x90,(byte) 0x40,(byte) 0x10,(byte) 0x30,(byte) 0x60,(byte) 0xf,(byte) 0x80, +}; + +static final BitmapCharRec ch174 = new BitmapCharRec(13,13,-1,0,14,ch174data); + +/* char: 0xad */ + +static final byte[] ch173data = { +(byte) 0xf8,(byte) 0xf8, +}; + +static final BitmapCharRec ch173 = new BitmapCharRec(5,2,-1,-4,7,ch173data); + +/* char: 0xac */ + +static final byte[] ch172data = { +(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80, +}; + +static final BitmapCharRec ch172 = new BitmapCharRec(9,5,-1,-3,11,ch172data); + +/* char: 0xab */ + +static final byte[] ch171data = { +(byte) 0x12,(byte) 0x36,(byte) 0x6c,(byte) 0xd8,(byte) 0xd8,(byte) 0x6c,(byte) 0x36,(byte) 0x12, +}; + +static final BitmapCharRec ch171 = new BitmapCharRec(7,8,-1,-1,9,ch171data); + +/* char: 0xaa */ + +static final byte[] ch170data = { +(byte) 0xf8,(byte) 0x0,(byte) 0x68,(byte) 0xd8,(byte) 0x48,(byte) 0x38,(byte) 0xc8,(byte) 0x70, +}; + +static final BitmapCharRec ch170 = new BitmapCharRec(5,8,-1,-6,7,ch170data); + +/* char: 0xa9 */ + +static final byte[] ch169data = { +(byte) 0xf,(byte) 0x80,(byte) 0x30,(byte) 0x60,(byte) 0x40,(byte) 0x10,(byte) 0x47,(byte) 0x10,(byte) 0x88,(byte) 0x88,(byte) 0x90,(byte) 0x8,(byte) 0x90,(byte) 0x8,(byte) 0x90,(byte) 0x8, +(byte) 0x88,(byte) 0x88,(byte) 0x47,(byte) 0x10,(byte) 0x40,(byte) 0x10,(byte) 0x30,(byte) 0x60,(byte) 0xf,(byte) 0x80, +}; + +static final BitmapCharRec ch169 = new BitmapCharRec(13,13,-1,0,15,ch169data); + +/* char: 0xa8 */ + +static final byte[] ch168data = { +(byte) 0xd8,(byte) 0xd8, +}; + +static final BitmapCharRec ch168 = new BitmapCharRec(5,2,0,-11,6,ch168data); + +/* char: 0xa7 */ + +static final byte[] ch167data = { +(byte) 0x3c,(byte) 0x7e,(byte) 0xc3,(byte) 0xc3,(byte) 0x7,(byte) 0xe,(byte) 0x3e,(byte) 0x73,(byte) 0xe3,(byte) 0xc3,(byte) 0xc7,(byte) 0x6e,(byte) 0x7c,(byte) 0xf0,(byte) 0xc3,(byte) 0xc3, +(byte) 0x7e,(byte) 0x3c, +}; + +static final BitmapCharRec ch167 = new BitmapCharRec(8,18,-1,4,10,ch167data); + +/* char: 0xa6 */ + +static final byte[] ch166data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0, +}; + +static final BitmapCharRec ch166 = new BitmapCharRec(2,17,-1,3,4,ch166data); + +/* char: 0xa5 */ + +static final byte[] ch165data = { +(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0xff,(byte) 0x18,(byte) 0xff,(byte) 0x3c,(byte) 0x66,(byte) 0x66,(byte) 0x66,(byte) 0xc3,(byte) 0xc3, +}; + +static final BitmapCharRec ch165 = new BitmapCharRec(8,13,-1,0,10,ch165data); + +/* char: 0xa4 */ + +static final byte[] ch164data = { +(byte) 0xc3,(byte) 0xff,(byte) 0x66,(byte) 0x66,(byte) 0x66,(byte) 0xff,(byte) 0xc3, +}; + +static final BitmapCharRec ch164 = new BitmapCharRec(8,7,-1,-3,10,ch164data); + +/* char: 0xa3 */ + +static final byte[] ch163data = { +(byte) 0xdf,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0x60,(byte) 0x80,(byte) 0x30,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x7e,(byte) 0x0,(byte) 0x30,(byte) 0x0, +(byte) 0x60,(byte) 0x0,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x3f,(byte) 0x0,(byte) 0x1e,(byte) 0x0, +}; + +static final BitmapCharRec ch163 = new BitmapCharRec(9,13,0,0,10,ch163data); + +/* char: 0xa2 */ + +static final byte[] ch162data = { +(byte) 0x10,(byte) 0x10,(byte) 0x3e,(byte) 0x7f,(byte) 0x6b,(byte) 0xc8,(byte) 0xc8,(byte) 0xc8,(byte) 0xc8,(byte) 0x6b,(byte) 0x7f,(byte) 0x3e,(byte) 0x4,(byte) 0x4, +}; + +static final BitmapCharRec ch162 = new BitmapCharRec(8,14,-1,2,10,ch162data); + +/* char: 0xa1 */ + +static final byte[] ch161data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch161 = new BitmapCharRec(2,14,-2,4,6,ch161data); + +/* char: 0xa0 */ + +static final BitmapCharRec ch160 = new BitmapCharRec(0,0,0,0,5,null); + +/* char: 0x7e '~' */ + +static final byte[] ch126data = { +(byte) 0xcc,(byte) 0x7e,(byte) 0x33, +}; + +static final BitmapCharRec ch126 = new BitmapCharRec(8,3,-1,-4,10,ch126data); + +/* char: 0x7d '}' */ + +static final byte[] ch125data = { +(byte) 0xc0,(byte) 0x60,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x18,(byte) 0xc,(byte) 0x18,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30, +(byte) 0x60,(byte) 0xc0, +}; + +static final BitmapCharRec ch125 = new BitmapCharRec(6,18,0,4,6,ch125data); + +/* char: 0x7c '|' */ + +static final byte[] ch124data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch124 = new BitmapCharRec(2,18,-1,4,4,ch124data); + +/* char: 0x7b '{' */ + +static final byte[] ch123data = { +(byte) 0xc,(byte) 0x18,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30, +(byte) 0x18,(byte) 0xc, +}; + +static final BitmapCharRec ch123 = new BitmapCharRec(6,18,0,4,6,ch123data); + +/* char: 0x7a 'z' */ + +static final byte[] ch122data = { +(byte) 0xfe,(byte) 0xfe,(byte) 0xc0,(byte) 0x60,(byte) 0x30,(byte) 0x18,(byte) 0xc,(byte) 0x6,(byte) 0xfe,(byte) 0xfe, +}; + +static final BitmapCharRec ch122 = new BitmapCharRec(7,10,-1,0,9,ch122data); + +/* char: 0x79 'y' */ + +static final byte[] ch121data = { +(byte) 0x70,(byte) 0x70,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x3c,(byte) 0x24,(byte) 0x66,(byte) 0x66,(byte) 0x66,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3, +}; + +static final BitmapCharRec ch121 = new BitmapCharRec(8,14,-1,4,10,ch121data); + +/* char: 0x78 'x' */ + +static final byte[] ch120data = { +(byte) 0xc3,(byte) 0xe7,(byte) 0x66,(byte) 0x3c,(byte) 0x18,(byte) 0x18,(byte) 0x3c,(byte) 0x66,(byte) 0xe7,(byte) 0xc3, +}; + +static final BitmapCharRec ch120 = new BitmapCharRec(8,10,-1,0,10,ch120data); + +/* char: 0x77 'w' */ + +static final byte[] ch119data = { +(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0x39,(byte) 0xc0,(byte) 0x29,(byte) 0x40,(byte) 0x69,(byte) 0x60,(byte) 0x66,(byte) 0x60,(byte) 0x66,(byte) 0x60,(byte) 0xc6,(byte) 0x30, +(byte) 0xc6,(byte) 0x30,(byte) 0xc6,(byte) 0x30, +}; + +static final BitmapCharRec ch119 = new BitmapCharRec(12,10,-1,0,14,ch119data); + +/* char: 0x76 'v' */ + +static final byte[] ch118data = { +(byte) 0x18,(byte) 0x18,(byte) 0x3c,(byte) 0x24,(byte) 0x66,(byte) 0x66,(byte) 0x66,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3, +}; + +static final BitmapCharRec ch118 = new BitmapCharRec(8,10,-1,0,10,ch118data); + +/* char: 0x75 'u' */ + +static final byte[] ch117data = { +(byte) 0x73,(byte) 0xfb,(byte) 0xc7,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3, +}; + +static final BitmapCharRec ch117 = new BitmapCharRec(8,10,-1,0,10,ch117data); + +/* char: 0x74 't' */ + +static final byte[] ch116data = { +(byte) 0x18,(byte) 0x38,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0xfc,(byte) 0xfc,(byte) 0x30,(byte) 0x30,(byte) 0x30, +}; + +static final BitmapCharRec ch116 = new BitmapCharRec(6,13,0,0,6,ch116data); + +/* char: 0x73 's' */ + +static final byte[] ch115data = { +(byte) 0x78,(byte) 0xfc,(byte) 0xc6,(byte) 0x6,(byte) 0x3e,(byte) 0xfc,(byte) 0xc0,(byte) 0xc6,(byte) 0x7e,(byte) 0x3c, +}; + +static final BitmapCharRec ch115 = new BitmapCharRec(7,10,-1,0,9,ch115data); + +/* char: 0x72 'r' */ + +static final byte[] ch114data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xe0,(byte) 0xd8,(byte) 0xd8, +}; + +static final BitmapCharRec ch114 = new BitmapCharRec(5,10,-1,0,6,ch114data); + +/* char: 0x71 'q' */ + +static final byte[] ch113data = { +(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x3d,(byte) 0x80,(byte) 0x7f,(byte) 0x80,(byte) 0x63,(byte) 0x80,(byte) 0xc1,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x63,(byte) 0x80,(byte) 0x7f,(byte) 0x80,(byte) 0x3d,(byte) 0x80, +}; + +static final BitmapCharRec ch113 = new BitmapCharRec(9,14,-1,4,11,ch113data); + +/* char: 0x70 'p' */ + +static final byte[] ch112data = { +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xde,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xe3,(byte) 0x0,(byte) 0xc1,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xe3,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xde,(byte) 0x0, +}; + +static final BitmapCharRec ch112 = new BitmapCharRec(9,14,-1,4,11,ch112data); + +/* char: 0x6f 'o' */ + +static final byte[] ch111data = { +(byte) 0x3e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x63,(byte) 0x0, +(byte) 0x7f,(byte) 0x0,(byte) 0x3e,(byte) 0x0, +}; + +static final BitmapCharRec ch111 = new BitmapCharRec(9,10,-1,0,11,ch111data); + +/* char: 0x6e 'n' */ + +static final byte[] ch110data = { +(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xe3,(byte) 0xdf,(byte) 0xce, +}; + +static final BitmapCharRec ch110 = new BitmapCharRec(8,10,-1,0,10,ch110data); + +/* char: 0x6d 'm' */ + +static final byte[] ch109data = { +(byte) 0xc6,(byte) 0x30,(byte) 0xc6,(byte) 0x30,(byte) 0xc6,(byte) 0x30,(byte) 0xc6,(byte) 0x30,(byte) 0xc6,(byte) 0x30,(byte) 0xc6,(byte) 0x30,(byte) 0xc6,(byte) 0x30,(byte) 0xe7,(byte) 0x30, +(byte) 0xde,(byte) 0xf0,(byte) 0xcc,(byte) 0x60, +}; + +static final BitmapCharRec ch109 = new BitmapCharRec(12,10,-1,0,14,ch109data); + +/* char: 0x6c 'l' */ + +static final byte[] ch108data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch108 = new BitmapCharRec(2,14,-1,0,4,ch108data); + +/* char: 0x6b 'k' */ + +static final byte[] ch107data = { +(byte) 0xc7,(byte) 0xc6,(byte) 0xce,(byte) 0xcc,(byte) 0xd8,(byte) 0xf8,(byte) 0xf0,(byte) 0xd8,(byte) 0xcc,(byte) 0xc6,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch107 = new BitmapCharRec(8,14,-1,0,9,ch107data); + +/* char: 0x6a 'j' */ + +static final byte[] ch106data = { +(byte) 0xe0,(byte) 0xf0,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x0,(byte) 0x0, +(byte) 0x30,(byte) 0x30, +}; + +static final BitmapCharRec ch106 = new BitmapCharRec(4,18,1,4,4,ch106data); + +/* char: 0x69 'i' */ + +static final byte[] ch105data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch105 = new BitmapCharRec(2,14,-1,0,4,ch105data); + +/* char: 0x68 'h' */ + +static final byte[] ch104data = { +(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xe3,(byte) 0xdf,(byte) 0xce,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch104 = new BitmapCharRec(8,14,-1,0,10,ch104data); + +/* char: 0x67 'g' */ + +static final byte[] ch103data = { +(byte) 0x1c,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x1,(byte) 0x80,(byte) 0x3d,(byte) 0x80,(byte) 0x7f,(byte) 0x80,(byte) 0x63,(byte) 0x80,(byte) 0xc1,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x7f,(byte) 0x80,(byte) 0x3d,(byte) 0x80, +}; + +static final BitmapCharRec ch103 = new BitmapCharRec(9,14,-1,4,11,ch103data); + +/* char: 0x66 'f' */ + +static final byte[] ch102data = { +(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0xfc,(byte) 0xfc,(byte) 0x30,(byte) 0x30,(byte) 0x3c,(byte) 0x1c, +}; + +static final BitmapCharRec ch102 = new BitmapCharRec(6,14,0,0,6,ch102data); + +/* char: 0x65 'e' */ + +static final byte[] ch101data = { +(byte) 0x3c,(byte) 0x7f,(byte) 0xe3,(byte) 0xc0,(byte) 0xc0,(byte) 0xff,(byte) 0xc3,(byte) 0xc3,(byte) 0x7e,(byte) 0x3c, +}; + +static final BitmapCharRec ch101 = new BitmapCharRec(8,10,-1,0,10,ch101data); + +/* char: 0x64 'd' */ + +static final byte[] ch100data = { +(byte) 0x3d,(byte) 0x80,(byte) 0x7f,(byte) 0x80,(byte) 0x63,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x63,(byte) 0x80, +(byte) 0x7f,(byte) 0x80,(byte) 0x3d,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80, +}; + +static final BitmapCharRec ch100 = new BitmapCharRec(9,14,-1,0,11,ch100data); + +/* char: 0x63 'c' */ + +static final byte[] ch99data = { +(byte) 0x3e,(byte) 0x7f,(byte) 0x63,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x63,(byte) 0x7f,(byte) 0x3e, +}; + +static final BitmapCharRec ch99 = new BitmapCharRec(8,10,-1,0,10,ch99data); + +/* char: 0x62 'b' */ + +static final byte[] ch98data = { +(byte) 0xde,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xe3,(byte) 0x0,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xe3,(byte) 0x0, +(byte) 0xff,(byte) 0x0,(byte) 0xde,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0, +}; + +static final BitmapCharRec ch98 = new BitmapCharRec(9,14,-1,0,11,ch98data); + +/* char: 0x61 'a' */ + +static final byte[] ch97data = { +(byte) 0x76,(byte) 0xee,(byte) 0xc6,(byte) 0xc6,(byte) 0xe6,(byte) 0x7e,(byte) 0xe,(byte) 0xc6,(byte) 0xee,(byte) 0x7c, +}; + +static final BitmapCharRec ch97 = new BitmapCharRec(7,10,-1,0,9,ch97data); + +/* char: 0x60 '`' */ + +static final byte[] ch96data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0x80,(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch96 = new BitmapCharRec(2,5,-1,-9,4,ch96data); + +/* char: 0x5f '_' */ + +static final byte[] ch95data = { +(byte) 0xff,(byte) 0xc0,(byte) 0xff,(byte) 0xc0, +}; + +static final BitmapCharRec ch95 = new BitmapCharRec(10,2,0,4,10,ch95data); + +/* char: 0x5e '^' */ + +static final byte[] ch94data = { +(byte) 0x82,(byte) 0xc6,(byte) 0x6c,(byte) 0x38,(byte) 0x10, +}; + +static final BitmapCharRec ch94 = new BitmapCharRec(7,5,-1,-8,9,ch94data); + +/* char: 0x5d ']' */ + +static final byte[] ch93data = { +(byte) 0xf0,(byte) 0xf0,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30, +(byte) 0xf0,(byte) 0xf0, +}; + +static final BitmapCharRec ch93 = new BitmapCharRec(4,18,0,4,5,ch93data); + +/* char: 0x5c '\' */ + +static final byte[] ch92data = { +(byte) 0x18,(byte) 0x18,(byte) 0x10,(byte) 0x10,(byte) 0x30,(byte) 0x30,(byte) 0x20,(byte) 0x20,(byte) 0x60,(byte) 0x60,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch92 = new BitmapCharRec(5,14,0,0,5,ch92data); + +/* char: 0x5b '[' */ + +static final byte[] ch91data = { +(byte) 0xf0,(byte) 0xf0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xf0,(byte) 0xf0, +}; + +static final BitmapCharRec ch91 = new BitmapCharRec(4,18,-1,4,5,ch91data); + +/* char: 0x5a 'Z' */ + +static final byte[] ch90data = { +(byte) 0xff,(byte) 0xc0,(byte) 0xff,(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x1c,(byte) 0x0,(byte) 0xc,(byte) 0x0, +(byte) 0x6,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x1,(byte) 0x80,(byte) 0x0,(byte) 0xc0,(byte) 0xff,(byte) 0xc0,(byte) 0xff,(byte) 0xc0, +}; + +static final BitmapCharRec ch90 = new BitmapCharRec(10,14,-1,0,12,ch90data); + +/* char: 0x59 'Y' */ + +static final byte[] ch89data = { +(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x19,(byte) 0x80, +(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30, +}; + +static final BitmapCharRec ch89 = new BitmapCharRec(12,14,-1,0,14,ch89data); + +/* char: 0x58 'X' */ + +static final byte[] ch88data = { +(byte) 0xc0,(byte) 0x60,(byte) 0xe0,(byte) 0xe0,(byte) 0x60,(byte) 0xc0,(byte) 0x71,(byte) 0xc0,(byte) 0x31,(byte) 0x80,(byte) 0x1b,(byte) 0x0,(byte) 0xe,(byte) 0x0,(byte) 0xe,(byte) 0x0, +(byte) 0x1b,(byte) 0x0,(byte) 0x31,(byte) 0x80,(byte) 0x71,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xe0,(byte) 0xe0,(byte) 0xc0,(byte) 0x60, +}; + +static final BitmapCharRec ch88 = new BitmapCharRec(11,14,-1,0,13,ch88data); + +/* char: 0x57 'W' */ + +static final byte[] ch87data = { +(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x1c,(byte) 0x38,(byte) 0x34,(byte) 0x2c,(byte) 0x36,(byte) 0x6c,(byte) 0x36,(byte) 0x6c,(byte) 0x66,(byte) 0x66,(byte) 0x66,(byte) 0x66, +(byte) 0x62,(byte) 0x46,(byte) 0x63,(byte) 0xc6,(byte) 0xc3,(byte) 0xc3,(byte) 0xc1,(byte) 0x83,(byte) 0xc1,(byte) 0x83,(byte) 0xc1,(byte) 0x83, +}; + +static final BitmapCharRec ch87 = new BitmapCharRec(16,14,-1,0,18,ch87data); + +/* char: 0x56 'V' */ + +static final byte[] ch86data = { +(byte) 0x6,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0, +(byte) 0x30,(byte) 0xc0,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30, +}; + +static final BitmapCharRec ch86 = new BitmapCharRec(12,14,-1,0,14,ch86data); + +/* char: 0x55 'U' */ + +static final byte[] ch85data = { +(byte) 0x1f,(byte) 0x0,(byte) 0x7f,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60, +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60, +}; + +static final BitmapCharRec ch85 = new BitmapCharRec(11,14,-1,0,13,ch85data); + +/* char: 0x54 'T' */ + +static final byte[] ch84data = { +(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0, +(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xff,(byte) 0xc0,(byte) 0xff,(byte) 0xc0, +}; + +static final BitmapCharRec ch84 = new BitmapCharRec(10,14,-1,0,12,ch84data); + +/* char: 0x53 'S' */ + +static final byte[] ch83data = { +(byte) 0x3f,(byte) 0x0,(byte) 0x7f,(byte) 0xc0,(byte) 0xe0,(byte) 0xe0,(byte) 0xc0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0xe0,(byte) 0x3,(byte) 0xc0,(byte) 0x1f,(byte) 0x0, +(byte) 0x7c,(byte) 0x0,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x60,(byte) 0xe0,(byte) 0xe0,(byte) 0x7f,(byte) 0xc0,(byte) 0x1f,(byte) 0x0, +}; + +static final BitmapCharRec ch83 = new BitmapCharRec(11,14,-1,0,13,ch83data); + +/* char: 0x52 'R' */ + +static final byte[] ch82data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x80, +(byte) 0xc1,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc1,(byte) 0xc0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x0, +}; + +static final BitmapCharRec ch82 = new BitmapCharRec(10,14,-1,0,12,ch82data); + +/* char: 0x51 'Q' */ + +static final byte[] ch81data = { +(byte) 0x0,(byte) 0x30,(byte) 0xf,(byte) 0xb0,(byte) 0x3f,(byte) 0xe0,(byte) 0x70,(byte) 0xf0,(byte) 0x61,(byte) 0xb0,(byte) 0xe1,(byte) 0xb8,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18, +(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18,(byte) 0xe0,(byte) 0x38,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70,(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80, +}; + +static final BitmapCharRec ch81 = new BitmapCharRec(13,15,-1,1,15,ch81data); + +/* char: 0x50 'P' */ + +static final byte[] ch80data = { +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x80, +(byte) 0xc1,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc1,(byte) 0xc0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x0, +}; + +static final BitmapCharRec ch80 = new BitmapCharRec(10,14,-1,0,12,ch80data); + +/* char: 0x4f 'O' */ + +static final byte[] ch79data = { +(byte) 0xf,(byte) 0x80,(byte) 0x3f,(byte) 0xe0,(byte) 0x70,(byte) 0x70,(byte) 0x60,(byte) 0x30,(byte) 0xe0,(byte) 0x38,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18,(byte) 0xc0,(byte) 0x18, +(byte) 0xc0,(byte) 0x18,(byte) 0xe0,(byte) 0x38,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70,(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80, +}; + +static final BitmapCharRec ch79 = new BitmapCharRec(13,14,-1,0,15,ch79data); + +/* char: 0x4e 'N' */ + +static final byte[] ch78data = { +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xe0,(byte) 0xc1,(byte) 0xe0,(byte) 0xc1,(byte) 0xe0,(byte) 0xc3,(byte) 0x60,(byte) 0xc6,(byte) 0x60,(byte) 0xc6,(byte) 0x60,(byte) 0xcc,(byte) 0x60, +(byte) 0xcc,(byte) 0x60,(byte) 0xd8,(byte) 0x60,(byte) 0xf0,(byte) 0x60,(byte) 0xf0,(byte) 0x60,(byte) 0xe0,(byte) 0x60,(byte) 0xc0,(byte) 0x60, +}; + +static final BitmapCharRec ch78 = new BitmapCharRec(11,14,-1,0,13,ch78data); + +/* char: 0x4d 'M' */ + +static final byte[] ch77data = { +(byte) 0xc3,(byte) 0xc,(byte) 0xc3,(byte) 0xc,(byte) 0xc7,(byte) 0x8c,(byte) 0xc4,(byte) 0x8c,(byte) 0xcc,(byte) 0xcc,(byte) 0xcc,(byte) 0xcc,(byte) 0xd8,(byte) 0x6c,(byte) 0xd8,(byte) 0x6c, +(byte) 0xf0,(byte) 0x3c,(byte) 0xf0,(byte) 0x3c,(byte) 0xe0,(byte) 0x1c,(byte) 0xe0,(byte) 0x1c,(byte) 0xc0,(byte) 0xc,(byte) 0xc0,(byte) 0xc, +}; + +static final BitmapCharRec ch77 = new BitmapCharRec(14,14,-1,0,16,ch77data); + +/* char: 0x4c 'L' */ + +static final byte[] ch76data = { +(byte) 0xff,(byte) 0xff,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch76 = new BitmapCharRec(8,14,-1,0,10,ch76data); + +/* char: 0x4b 'K' */ + +static final byte[] ch75data = { +(byte) 0xc0,(byte) 0x70,(byte) 0xc0,(byte) 0xe0,(byte) 0xc1,(byte) 0xc0,(byte) 0xc3,(byte) 0x80,(byte) 0xc7,(byte) 0x0,(byte) 0xce,(byte) 0x0,(byte) 0xfc,(byte) 0x0,(byte) 0xf8,(byte) 0x0, +(byte) 0xdc,(byte) 0x0,(byte) 0xce,(byte) 0x0,(byte) 0xc7,(byte) 0x0,(byte) 0xc3,(byte) 0x80,(byte) 0xc1,(byte) 0xc0,(byte) 0xc0,(byte) 0xe0, +}; + +static final BitmapCharRec ch75 = new BitmapCharRec(12,14,-1,0,13,ch75data); + +/* char: 0x4a 'J' */ + +static final byte[] ch74data = { +(byte) 0x3c,(byte) 0x7e,(byte) 0xe7,(byte) 0xc3,(byte) 0xc3,(byte) 0x3,(byte) 0x3,(byte) 0x3,(byte) 0x3,(byte) 0x3,(byte) 0x3,(byte) 0x3,(byte) 0x3,(byte) 0x3, +}; + +static final BitmapCharRec ch74 = new BitmapCharRec(8,14,-1,0,10,ch74data); + +/* char: 0x49 'I' */ + +static final byte[] ch73data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch73 = new BitmapCharRec(2,14,-2,0,6,ch73data); + +/* char: 0x48 'H' */ + +static final byte[] ch72data = { +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xff,(byte) 0xe0,(byte) 0xff,(byte) 0xe0, +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60, +}; + +static final BitmapCharRec ch72 = new BitmapCharRec(11,14,-1,0,13,ch72data); + +/* char: 0x47 'G' */ + +static final byte[] ch71data = { +(byte) 0xf,(byte) 0xb0,(byte) 0x3f,(byte) 0xf0,(byte) 0x70,(byte) 0x70,(byte) 0x60,(byte) 0x30,(byte) 0xe0,(byte) 0x30,(byte) 0xc1,(byte) 0xf0,(byte) 0xc1,(byte) 0xf0,(byte) 0xc0,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xe0,(byte) 0x30,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70,(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80, +}; + +static final BitmapCharRec ch71 = new BitmapCharRec(12,14,-1,0,14,ch71data); + +/* char: 0x46 'F' */ + +static final byte[] ch70data = { +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80, +}; + +static final BitmapCharRec ch70 = new BitmapCharRec(9,14,-1,0,11,ch70data); + +/* char: 0x45 'E' */ + +static final byte[] ch69data = { +(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80, +}; + +static final BitmapCharRec ch69 = new BitmapCharRec(9,14,-1,0,11,ch69data); + +/* char: 0x44 'D' */ + +static final byte[] ch68data = { +(byte) 0xff,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xc1,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60, +(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xc0,(byte) 0xc1,(byte) 0xc0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x0, +}; + +static final BitmapCharRec ch68 = new BitmapCharRec(11,14,-1,0,13,ch68data); + +/* char: 0x43 'C' */ + +static final byte[] ch67data = { +(byte) 0xf,(byte) 0x80,(byte) 0x3f,(byte) 0xe0,(byte) 0x70,(byte) 0x70,(byte) 0x60,(byte) 0x30,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xe0,(byte) 0x0,(byte) 0x60,(byte) 0x30,(byte) 0x70,(byte) 0x70,(byte) 0x3f,(byte) 0xe0,(byte) 0xf,(byte) 0x80, +}; + +static final BitmapCharRec ch67 = new BitmapCharRec(12,14,-1,0,14,ch67data); + +/* char: 0x42 'B' */ + +static final byte[] ch66data = { +(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0xc0,(byte) 0xc0,(byte) 0xe0,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xe0,(byte) 0xff,(byte) 0xc0,(byte) 0xff,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc1,(byte) 0xc0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x0, +}; + +static final BitmapCharRec ch66 = new BitmapCharRec(11,14,-1,0,13,ch66data); + +/* char: 0x41 'A' */ + +static final byte[] ch65data = { +(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x7f,(byte) 0xe0,(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0xc0, +(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0xf,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0, +}; + +static final BitmapCharRec ch65 = new BitmapCharRec(12,14,0,0,12,ch65data); + +/* char: 0x40 '@' */ + +static final byte[] ch64data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1f,(byte) 0xf0,(byte) 0x38,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0x67,(byte) 0x70,(byte) 0xcf,(byte) 0xf8,(byte) 0xcc,(byte) 0xcc,(byte) 0xcc,(byte) 0x66, +(byte) 0xcc,(byte) 0x66,(byte) 0xcc,(byte) 0x63,(byte) 0xc6,(byte) 0x33,(byte) 0x67,(byte) 0x73,(byte) 0x63,(byte) 0xb3,(byte) 0x30,(byte) 0x6,(byte) 0x1c,(byte) 0xe,(byte) 0xf,(byte) 0xfc, +(byte) 0x3,(byte) 0xf0, +}; + +static final BitmapCharRec ch64 = new BitmapCharRec(16,17,-1,3,18,ch64data); + +/* char: 0x3f '?' */ + +static final byte[] ch63data = { +(byte) 0x30,(byte) 0x30,(byte) 0x0,(byte) 0x0,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x38,(byte) 0x1c,(byte) 0xe,(byte) 0xc6,(byte) 0xc6,(byte) 0xfe,(byte) 0x7c, +}; + +static final BitmapCharRec ch63 = new BitmapCharRec(7,14,-1,0,10,ch63data); + +/* char: 0x3e '>' */ + +static final byte[] ch62data = { +(byte) 0xc0,(byte) 0xf0,(byte) 0x3c,(byte) 0xe,(byte) 0x3,(byte) 0xe,(byte) 0x3c,(byte) 0xf0,(byte) 0xc0, +}; + +static final BitmapCharRec ch62 = new BitmapCharRec(8,9,-1,0,10,ch62data); + +/* char: 0x3d '=' */ + +static final byte[] ch61data = { +(byte) 0xfe,(byte) 0xfe,(byte) 0x0,(byte) 0x0,(byte) 0xfe,(byte) 0xfe, +}; + +static final BitmapCharRec ch61 = new BitmapCharRec(7,6,-2,-2,11,ch61data); + +/* char: 0x3c '<' */ + +static final byte[] ch60data = { +(byte) 0x3,(byte) 0xf,(byte) 0x3c,(byte) 0x70,(byte) 0xc0,(byte) 0x70,(byte) 0x3c,(byte) 0xf,(byte) 0x3, +}; + +static final BitmapCharRec ch60 = new BitmapCharRec(8,9,-1,0,10,ch60data); + +/* char: 0x3b ';' */ + +static final byte[] ch59data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch59 = new BitmapCharRec(2,13,-1,3,5,ch59data); + +/* char: 0x3a ':' */ + +static final byte[] ch58data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch58 = new BitmapCharRec(2,10,-1,0,5,ch58data); + +/* char: 0x39 '9' */ + +static final byte[] ch57data = { +(byte) 0x7c,(byte) 0xfe,(byte) 0xc6,(byte) 0x3,(byte) 0x3,(byte) 0x3b,(byte) 0x7f,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc7,(byte) 0x7e,(byte) 0x3c, +}; + +static final BitmapCharRec ch57 = new BitmapCharRec(8,13,-1,0,10,ch57data); + +/* char: 0x38 '8' */ + +static final byte[] ch56data = { +(byte) 0x3c,(byte) 0x7e,(byte) 0xe7,(byte) 0xc3,(byte) 0xc3,(byte) 0x66,(byte) 0x7e,(byte) 0x66,(byte) 0xc3,(byte) 0xc3,(byte) 0xe7,(byte) 0x7e,(byte) 0x3c, +}; + +static final BitmapCharRec ch56 = new BitmapCharRec(8,13,-1,0,10,ch56data); + +/* char: 0x37 '7' */ + +static final byte[] ch55data = { +(byte) 0x60,(byte) 0x60,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x18,(byte) 0x18,(byte) 0xc,(byte) 0xc,(byte) 0x6,(byte) 0x3,(byte) 0xff,(byte) 0xff, +}; + +static final BitmapCharRec ch55 = new BitmapCharRec(8,13,-1,0,10,ch55data); + +/* char: 0x36 '6' */ + +static final byte[] ch54data = { +(byte) 0x3c,(byte) 0x7e,(byte) 0xe3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xfe,(byte) 0xdc,(byte) 0xc0,(byte) 0xc0,(byte) 0x63,(byte) 0x7f,(byte) 0x3c, +}; + +static final BitmapCharRec ch54 = new BitmapCharRec(8,13,-1,0,10,ch54data); + +/* char: 0x35 '5' */ + +static final byte[] ch53data = { +(byte) 0x7c,(byte) 0xfe,(byte) 0xc7,(byte) 0xc3,(byte) 0x3,(byte) 0x3,(byte) 0xc7,(byte) 0xfe,(byte) 0xfc,(byte) 0xc0,(byte) 0xc0,(byte) 0xfe,(byte) 0xfe, +}; + +static final BitmapCharRec ch53 = new BitmapCharRec(8,13,-1,0,10,ch53data); + +/* char: 0x34 '4' */ + +static final byte[] ch52data = { +(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0xc3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x33,(byte) 0x0, +(byte) 0x33,(byte) 0x0,(byte) 0x1b,(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x7,(byte) 0x0,(byte) 0x3,(byte) 0x0, +}; + +static final BitmapCharRec ch52 = new BitmapCharRec(9,13,-1,0,10,ch52data); + +/* char: 0x33 '3' */ + +static final byte[] ch51data = { +(byte) 0x3c,(byte) 0x7e,(byte) 0xc7,(byte) 0xc3,(byte) 0x3,(byte) 0x7,(byte) 0x1e,(byte) 0x1c,(byte) 0x6,(byte) 0xc3,(byte) 0xc3,(byte) 0x7e,(byte) 0x3c, +}; + +static final BitmapCharRec ch51 = new BitmapCharRec(8,13,-1,0,10,ch51data); + +/* char: 0x32 '2' */ + +static final byte[] ch50data = { +(byte) 0xff,(byte) 0xff,(byte) 0xc0,(byte) 0xe0,(byte) 0x70,(byte) 0x38,(byte) 0x1c,(byte) 0xe,(byte) 0x7,(byte) 0x3,(byte) 0xc3,(byte) 0xfe,(byte) 0x3c, +}; + +static final BitmapCharRec ch50 = new BitmapCharRec(8,13,-1,0,10,ch50data); + +/* char: 0x31 '1' */ + +static final byte[] ch49data = { +(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0xf8,(byte) 0xf8,(byte) 0x18, +}; + +static final BitmapCharRec ch49 = new BitmapCharRec(5,13,-2,0,10,ch49data); + +/* char: 0x30 '0' */ + +static final byte[] ch48data = { +(byte) 0x3c,(byte) 0x7e,(byte) 0x66,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0xc3,(byte) 0x66,(byte) 0x7e,(byte) 0x3c, +}; + +static final BitmapCharRec ch48 = new BitmapCharRec(8,13,-1,0,10,ch48data); + +/* char: 0x2f '/' */ + +static final byte[] ch47data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0x40,(byte) 0x40,(byte) 0x60,(byte) 0x60,(byte) 0x20,(byte) 0x20,(byte) 0x30,(byte) 0x30,(byte) 0x10,(byte) 0x10,(byte) 0x18,(byte) 0x18, +}; + +static final BitmapCharRec ch47 = new BitmapCharRec(5,14,0,0,5,ch47data); + +/* char: 0x2e '.' */ + +static final byte[] ch46data = { +(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch46 = new BitmapCharRec(2,2,-1,0,5,ch46data); + +/* char: 0x2d '-' */ + +static final byte[] ch45data = { +(byte) 0xff,(byte) 0xff, +}; + +static final BitmapCharRec ch45 = new BitmapCharRec(8,2,-1,-4,11,ch45data); + +/* char: 0x2c ',' */ + +static final byte[] ch44data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch44 = new BitmapCharRec(2,5,-1,3,5,ch44data); + +/* char: 0x2b '+' */ + +static final byte[] ch43data = { +(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0xff,(byte) 0xff,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18, +}; + +static final BitmapCharRec ch43 = new BitmapCharRec(8,10,-1,0,10,ch43data); + +/* char: 0x2a '*' */ + +static final byte[] ch42data = { +(byte) 0x88,(byte) 0x70,(byte) 0x70,(byte) 0xf8,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch42 = new BitmapCharRec(5,6,-1,-8,7,ch42data); + +/* char: 0x29 ')' */ + +static final byte[] ch41data = { +(byte) 0x80,(byte) 0xc0,(byte) 0x60,(byte) 0x60,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x60,(byte) 0x60, +(byte) 0xc0,(byte) 0x80, +}; + +static final BitmapCharRec ch41 = new BitmapCharRec(4,18,-1,4,6,ch41data); + +/* char: 0x28 '(' */ + +static final byte[] ch40data = { +(byte) 0x10,(byte) 0x30,(byte) 0x60,(byte) 0x60,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x60,(byte) 0x60, +(byte) 0x30,(byte) 0x10, +}; + +static final BitmapCharRec ch40 = new BitmapCharRec(4,18,-1,4,6,ch40data); + +/* char: 0x27 ''' */ + +static final byte[] ch39data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch39 = new BitmapCharRec(2,5,-1,-9,4,ch39data); + +/* char: 0x26 '&' */ + +static final byte[] ch38data = { +(byte) 0x3c,(byte) 0x70,(byte) 0x7e,(byte) 0xe0,(byte) 0xe7,(byte) 0xc0,(byte) 0xc3,(byte) 0x80,(byte) 0xc3,(byte) 0xc0,(byte) 0xc6,(byte) 0xc0,(byte) 0xee,(byte) 0xc0,(byte) 0x7c,(byte) 0x0, +(byte) 0x3c,(byte) 0x0,(byte) 0x66,(byte) 0x0,(byte) 0x66,(byte) 0x0,(byte) 0x7e,(byte) 0x0,(byte) 0x3c,(byte) 0x0, +}; + +static final BitmapCharRec ch38 = new BitmapCharRec(12,13,-1,0,13,ch38data); + +/* char: 0x25 '%' */ + +static final byte[] ch37data = { +(byte) 0x18,(byte) 0x78,(byte) 0x18,(byte) 0xfc,(byte) 0xc,(byte) 0xcc,(byte) 0xc,(byte) 0xcc,(byte) 0x6,(byte) 0xfc,(byte) 0x6,(byte) 0x78,(byte) 0x3,(byte) 0x0,(byte) 0x7b,(byte) 0x0, +(byte) 0xfd,(byte) 0x80,(byte) 0xcd,(byte) 0x80,(byte) 0xcc,(byte) 0xc0,(byte) 0xfc,(byte) 0xc0,(byte) 0x78,(byte) 0x60, +}; + +static final BitmapCharRec ch37 = new BitmapCharRec(14,13,-1,0,16,ch37data); + +/* char: 0x24 '$' */ + +static final byte[] ch36data = { +(byte) 0x8,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0xeb,(byte) 0x80,(byte) 0xc9,(byte) 0x80,(byte) 0x9,(byte) 0x80,(byte) 0xf,(byte) 0x0, +(byte) 0x3e,(byte) 0x0,(byte) 0x78,(byte) 0x0,(byte) 0xe8,(byte) 0x0,(byte) 0xc8,(byte) 0x0,(byte) 0xcb,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x8,(byte) 0x0, +}; + +static final BitmapCharRec ch36 = new BitmapCharRec(9,16,-1,2,10,ch36data); + +/* char: 0x23 '#' */ + +static final byte[] ch35data = { +(byte) 0x24,(byte) 0x0,(byte) 0x24,(byte) 0x0,(byte) 0x24,(byte) 0x0,(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0x80,(byte) 0x12,(byte) 0x0,(byte) 0x12,(byte) 0x0,(byte) 0x12,(byte) 0x0, +(byte) 0x7f,(byte) 0xc0,(byte) 0x7f,(byte) 0xc0,(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0, +}; + +static final BitmapCharRec ch35 = new BitmapCharRec(10,13,0,0,10,ch35data); + +/* char: 0x22 '"' */ + +static final byte[] ch34data = { +(byte) 0x90,(byte) 0x90,(byte) 0xd8,(byte) 0xd8,(byte) 0xd8, +}; + +static final BitmapCharRec ch34 = new BitmapCharRec(5,5,0,-9,5,ch34data); + +/* char: 0x21 '!' */ + +static final byte[] ch33data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch33 = new BitmapCharRec(2,14,-2,0,6,ch33data); + +/* char: 0x20 ' ' */ + +static final BitmapCharRec ch32 = new BitmapCharRec(0,0,0,0,5,null); + +static final BitmapCharRec[] chars = { +ch32, +ch33, +ch34, +ch35, +ch36, +ch37, +ch38, +ch39, +ch40, +ch41, +ch42, +ch43, +ch44, +ch45, +ch46, +ch47, +ch48, +ch49, +ch50, +ch51, +ch52, +ch53, +ch54, +ch55, +ch56, +ch57, +ch58, +ch59, +ch60, +ch61, +ch62, +ch63, +ch64, +ch65, +ch66, +ch67, +ch68, +ch69, +ch70, +ch71, +ch72, +ch73, +ch74, +ch75, +ch76, +ch77, +ch78, +ch79, +ch80, +ch81, +ch82, +ch83, +ch84, +ch85, +ch86, +ch87, +ch88, +ch89, +ch90, +ch91, +ch92, +ch93, +ch94, +ch95, +ch96, +ch97, +ch98, +ch99, +ch100, +ch101, +ch102, +ch103, +ch104, +ch105, +ch106, +ch107, +ch108, +ch109, +ch110, +ch111, +ch112, +ch113, +ch114, +ch115, +ch116, +ch117, +ch118, +ch119, +ch120, +ch121, +ch122, +ch123, +ch124, +ch125, +ch126, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +ch160, +ch161, +ch162, +ch163, +ch164, +ch165, +ch166, +ch167, +ch168, +ch169, +ch170, +ch171, +ch172, +ch173, +ch174, +ch175, +ch176, +ch177, +ch178, +ch179, +ch180, +ch181, +ch182, +ch183, +ch184, +ch185, +ch186, +ch187, +ch188, +ch189, +ch190, +ch191, +ch192, +ch193, +ch194, +ch195, +ch196, +ch197, +ch198, +ch199, +ch200, +ch201, +ch202, +ch203, +ch204, +ch205, +ch206, +ch207, +ch208, +ch209, +ch210, +ch211, +ch212, +ch213, +ch214, +ch215, +ch216, +ch217, +ch218, +ch219, +ch220, +ch221, +ch222, +ch223, +ch224, +ch225, +ch226, +ch227, +ch228, +ch229, +ch230, +ch231, +ch232, +ch233, +ch234, +ch235, +ch236, +ch237, +ch238, +ch239, +ch240, +ch241, +ch242, +ch243, +ch244, +ch245, +ch246, +ch247, +ch248, +ch249, +ch250, +ch251, +ch252, +ch253, +ch254, +ch255, +}; + + public static final BitmapFontRec glutBitmapHelvetica18 = new BitmapFontRec("-adobe-helvetica-medium-r-normal--18-180-75-75-p-98-iso8859-1", + 224, + 32, + chars); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapTimesRoman10.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapTimesRoman10.java new file mode 100644 index 000000000..f753b56f7 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapTimesRoman10.java @@ -0,0 +1,1797 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +class GLUTBitmapTimesRoman10 { + +/* GENERATED FILE -- DO NOT MODIFY */ + +/* char: 0xff */ + +static final byte[] ch255data = { +(byte) 0x80,(byte) 0xc0,(byte) 0x40,(byte) 0x60,(byte) 0xa0,(byte) 0x90,(byte) 0xb8,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch255 = new BitmapCharRec(5,9,0,2,5,ch255data); + +/* char: 0xfe */ + +static final byte[] ch254data = { +(byte) 0xc0,(byte) 0x80,(byte) 0xe0,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xe0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch254 = new BitmapCharRec(4,9,0,2,5,ch254data); + +/* char: 0xfd */ + +static final byte[] ch253data = { +(byte) 0x80,(byte) 0xc0,(byte) 0x40,(byte) 0x60,(byte) 0xa0,(byte) 0x90,(byte) 0xb8,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch253 = new BitmapCharRec(5,10,0,2,5,ch253data); + +/* char: 0xfc */ + +static final byte[] ch252data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch252 = new BitmapCharRec(5,7,0,0,5,ch252data); + +/* char: 0xfb */ + +static final byte[] ch251data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch251 = new BitmapCharRec(5,8,0,0,5,ch251data); + +/* char: 0xfa */ + +static final byte[] ch250data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch250 = new BitmapCharRec(5,8,0,0,5,ch250data); + +/* char: 0xf9 */ + +static final byte[] ch249data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch249 = new BitmapCharRec(5,8,0,0,5,ch249data); + +/* char: 0xf8 */ + +static final byte[] ch248data = { +(byte) 0x80,(byte) 0x70,(byte) 0x48,(byte) 0x48,(byte) 0x48,(byte) 0x38,(byte) 0x4, +}; + +static final BitmapCharRec ch248 = new BitmapCharRec(6,7,1,1,5,ch248data); + +/* char: 0xf7 */ + +static final byte[] ch247data = { +(byte) 0x20,(byte) 0x0,(byte) 0xf8,(byte) 0x0,(byte) 0x20, +}; + +static final BitmapCharRec ch247 = new BitmapCharRec(5,5,0,0,6,ch247data); + +/* char: 0xf6 */ + +static final byte[] ch246data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x60,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch246 = new BitmapCharRec(4,7,0,0,5,ch246data); + +/* char: 0xf5 */ + +static final byte[] ch245data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x60,(byte) 0x0,(byte) 0xa0,(byte) 0x50, +}; + +static final BitmapCharRec ch245 = new BitmapCharRec(4,8,0,0,5,ch245data); + +/* char: 0xf4 */ + +static final byte[] ch244data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x60,(byte) 0x0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch244 = new BitmapCharRec(4,8,0,0,5,ch244data); + +/* char: 0xf3 */ + +static final byte[] ch243data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x60,(byte) 0x0,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch243 = new BitmapCharRec(4,8,0,0,5,ch243data); + +/* char: 0xf2 */ + +static final byte[] ch242data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x60,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch242 = new BitmapCharRec(4,8,0,0,5,ch242data); + +/* char: 0xf1 */ + +static final byte[] ch241data = { +(byte) 0xd8,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xe0,(byte) 0x0,(byte) 0xa0,(byte) 0x50, +}; + +static final BitmapCharRec ch241 = new BitmapCharRec(5,8,0,0,5,ch241data); + +/* char: 0xf0 */ + +static final byte[] ch240data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x70,(byte) 0xa0,(byte) 0x70,(byte) 0x40, +}; + +static final BitmapCharRec ch240 = new BitmapCharRec(4,8,0,0,5,ch240data); + +/* char: 0xef */ + +static final byte[] ch239data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch239 = new BitmapCharRec(3,7,0,0,4,ch239data); + +/* char: 0xee */ + +static final byte[] ch238data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch238 = new BitmapCharRec(3,8,0,0,4,ch238data); + +/* char: 0xed */ + +static final byte[] ch237data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x0,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch237 = new BitmapCharRec(3,8,0,0,4,ch237data); + +/* char: 0xec */ + +static final byte[] ch236data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x0,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch236 = new BitmapCharRec(3,8,0,0,4,ch236data); + +/* char: 0xeb */ + +static final byte[] ch235data = { +(byte) 0x60,(byte) 0x80,(byte) 0xc0,(byte) 0xa0,(byte) 0x60,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch235 = new BitmapCharRec(3,7,0,0,4,ch235data); + +/* char: 0xea */ + +static final byte[] ch234data = { +(byte) 0x60,(byte) 0x80,(byte) 0xc0,(byte) 0xa0,(byte) 0x60,(byte) 0x0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch234 = new BitmapCharRec(3,8,0,0,4,ch234data); + +/* char: 0xe9 */ + +static final byte[] ch233data = { +(byte) 0x60,(byte) 0x80,(byte) 0xc0,(byte) 0xa0,(byte) 0x60,(byte) 0x0,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch233 = new BitmapCharRec(3,8,0,0,4,ch233data); + +/* char: 0xe8 */ + +static final byte[] ch232data = { +(byte) 0x60,(byte) 0x80,(byte) 0xc0,(byte) 0xa0,(byte) 0x60,(byte) 0x0,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch232 = new BitmapCharRec(3,8,0,0,4,ch232data); + +/* char: 0xe7 */ + +static final byte[] ch231data = { +(byte) 0xc0,(byte) 0x20,(byte) 0x40,(byte) 0x60,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x60, +}; + +static final BitmapCharRec ch231 = new BitmapCharRec(3,8,0,3,4,ch231data); + +/* char: 0xe6 */ + +static final byte[] ch230data = { +(byte) 0xd8,(byte) 0xa0,(byte) 0x70,(byte) 0x28,(byte) 0xd8, +}; + +static final BitmapCharRec ch230 = new BitmapCharRec(5,5,0,0,6,ch230data); + +/* char: 0xe5 */ + +static final byte[] ch229data = { +(byte) 0xe0,(byte) 0xa0,(byte) 0x60,(byte) 0x20,(byte) 0xc0,(byte) 0x40,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch229 = new BitmapCharRec(3,8,0,0,4,ch229data); + +/* char: 0xe4 */ + +static final byte[] ch228data = { +(byte) 0xe0,(byte) 0xa0,(byte) 0x60,(byte) 0x20,(byte) 0xc0,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch228 = new BitmapCharRec(3,7,0,0,4,ch228data); + +/* char: 0xe3 */ + +static final byte[] ch227data = { +(byte) 0xe0,(byte) 0xa0,(byte) 0x60,(byte) 0x20,(byte) 0xc0,(byte) 0x0,(byte) 0xa0,(byte) 0x50, +}; + +static final BitmapCharRec ch227 = new BitmapCharRec(4,8,0,0,4,ch227data); + +/* char: 0xe2 */ + +static final byte[] ch226data = { +(byte) 0xe0,(byte) 0xa0,(byte) 0x60,(byte) 0x20,(byte) 0xc0,(byte) 0x0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch226 = new BitmapCharRec(3,8,0,0,4,ch226data); + +/* char: 0xe1 */ + +static final byte[] ch225data = { +(byte) 0xe0,(byte) 0xa0,(byte) 0x60,(byte) 0x20,(byte) 0xc0,(byte) 0x0,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch225 = new BitmapCharRec(3,8,0,0,4,ch225data); + +/* char: 0xe0 */ + +static final byte[] ch224data = { +(byte) 0xe0,(byte) 0xa0,(byte) 0x60,(byte) 0x20,(byte) 0xc0,(byte) 0x0,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch224 = new BitmapCharRec(3,8,0,0,4,ch224data); + +/* char: 0xdf */ + +static final byte[] ch223data = { +(byte) 0xe0,(byte) 0x50,(byte) 0x50,(byte) 0x60,(byte) 0x50,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch223 = new BitmapCharRec(4,7,0,0,5,ch223data); + +/* char: 0xde */ + +static final byte[] ch222data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x70,(byte) 0x48,(byte) 0x70,(byte) 0x40,(byte) 0xe0, +}; + +static final BitmapCharRec ch222 = new BitmapCharRec(5,7,0,0,6,ch222data); + +/* char: 0xdd */ + +static final byte[] ch221data = { +(byte) 0x38,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x44,(byte) 0xee,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch221 = new BitmapCharRec(7,10,0,0,8,ch221data); + +/* char: 0xdc */ + +static final byte[] ch220data = { +(byte) 0x38,(byte) 0x6c,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0xee,(byte) 0x0,(byte) 0x28, +}; + +static final BitmapCharRec ch220 = new BitmapCharRec(7,9,0,0,8,ch220data); + +/* char: 0xdb */ + +static final byte[] ch219data = { +(byte) 0x38,(byte) 0x6c,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0xee,(byte) 0x0,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch219 = new BitmapCharRec(7,10,0,0,8,ch219data); + +/* char: 0xda */ + +static final byte[] ch218data = { +(byte) 0x38,(byte) 0x6c,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0xee,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch218 = new BitmapCharRec(7,10,0,0,8,ch218data); + +/* char: 0xd9 */ + +static final byte[] ch217data = { +(byte) 0x38,(byte) 0x6c,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0xee,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch217 = new BitmapCharRec(7,10,0,0,8,ch217data); + +/* char: 0xd8 */ + +static final byte[] ch216data = { +(byte) 0x80,(byte) 0x7c,(byte) 0x66,(byte) 0x52,(byte) 0x52,(byte) 0x4a,(byte) 0x66,(byte) 0x3e,(byte) 0x1, +}; + +static final BitmapCharRec ch216 = new BitmapCharRec(8,9,0,1,8,ch216data); + +/* char: 0xd7 */ + +static final byte[] ch215data = { +(byte) 0x88,(byte) 0x50,(byte) 0x20,(byte) 0x50,(byte) 0x88, +}; + +static final BitmapCharRec ch215 = new BitmapCharRec(5,5,0,0,6,ch215data); + +/* char: 0xd6 */ + +static final byte[] ch214data = { +(byte) 0x78,(byte) 0xcc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xcc,(byte) 0x78,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch214 = new BitmapCharRec(6,9,0,0,7,ch214data); + +/* char: 0xd5 */ + +static final byte[] ch213data = { +(byte) 0x78,(byte) 0xcc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xcc,(byte) 0x78,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch213 = new BitmapCharRec(6,10,0,0,7,ch213data); + +/* char: 0xd4 */ + +static final byte[] ch212data = { +(byte) 0x78,(byte) 0xcc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xcc,(byte) 0x78,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch212 = new BitmapCharRec(6,10,0,0,7,ch212data); + +/* char: 0xd3 */ + +static final byte[] ch211data = { +(byte) 0x78,(byte) 0xcc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xcc,(byte) 0x78,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch211 = new BitmapCharRec(6,10,0,0,7,ch211data); + +/* char: 0xd2 */ + +static final byte[] ch210data = { +(byte) 0x78,(byte) 0xcc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xcc,(byte) 0x78,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch210 = new BitmapCharRec(6,10,0,0,7,ch210data); + +/* char: 0xd1 */ + +static final byte[] ch209data = { +(byte) 0xe4,(byte) 0x4c,(byte) 0x4c,(byte) 0x54,(byte) 0x54,(byte) 0x64,(byte) 0xee,(byte) 0x0,(byte) 0x50,(byte) 0x28, +}; + +static final BitmapCharRec ch209 = new BitmapCharRec(7,10,0,0,8,ch209data); + +/* char: 0xd0 */ + +static final byte[] ch208data = { +(byte) 0xf8,(byte) 0x4c,(byte) 0x44,(byte) 0xe4,(byte) 0x44,(byte) 0x4c,(byte) 0xf8, +}; + +static final BitmapCharRec ch208 = new BitmapCharRec(6,7,0,0,7,ch208data); + +/* char: 0xcf */ + +static final byte[] ch207data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x0,(byte) 0xa0, +}; + +static final BitmapCharRec ch207 = new BitmapCharRec(3,9,0,0,4,ch207data); + +/* char: 0xce */ + +static final byte[] ch206data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch206 = new BitmapCharRec(3,10,0,0,4,ch206data); + +/* char: 0xcd */ + +static final byte[] ch205data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x0,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch205 = new BitmapCharRec(3,10,0,0,4,ch205data); + +/* char: 0xcc */ + +static final byte[] ch204data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x0,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch204 = new BitmapCharRec(3,10,0,0,4,ch204data); + +/* char: 0xcb */ + +static final byte[] ch203data = { +(byte) 0xf8,(byte) 0x48,(byte) 0x40,(byte) 0x70,(byte) 0x40,(byte) 0x48,(byte) 0xf8,(byte) 0x0,(byte) 0x50, +}; + +static final BitmapCharRec ch203 = new BitmapCharRec(5,9,0,0,6,ch203data); + +/* char: 0xca */ + +static final byte[] ch202data = { +(byte) 0xf8,(byte) 0x48,(byte) 0x40,(byte) 0x70,(byte) 0x40,(byte) 0x48,(byte) 0xf8,(byte) 0x0,(byte) 0x50,(byte) 0x20, +}; + +static final BitmapCharRec ch202 = new BitmapCharRec(5,10,0,0,6,ch202data); + +/* char: 0xc9 */ + +static final byte[] ch201data = { +(byte) 0xf8,(byte) 0x48,(byte) 0x40,(byte) 0x70,(byte) 0x40,(byte) 0x48,(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x10, +}; + +static final BitmapCharRec ch201 = new BitmapCharRec(5,10,0,0,6,ch201data); + +/* char: 0xc8 */ + +static final byte[] ch200data = { +(byte) 0xf8,(byte) 0x48,(byte) 0x40,(byte) 0x70,(byte) 0x40,(byte) 0x48,(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch200 = new BitmapCharRec(5,10,0,0,6,ch200data); + +/* char: 0xc7 */ + +static final byte[] ch199data = { +(byte) 0x60,(byte) 0x10,(byte) 0x20,(byte) 0x78,(byte) 0xc4,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xc4,(byte) 0x7c, +}; + +static final BitmapCharRec ch199 = new BitmapCharRec(6,10,0,3,7,ch199data); + +/* char: 0xc6 */ + +static final byte[] ch198data = { +(byte) 0xef,(byte) 0x49,(byte) 0x78,(byte) 0x2e,(byte) 0x28,(byte) 0x39,(byte) 0x1f, +}; + +static final BitmapCharRec ch198 = new BitmapCharRec(8,7,0,0,9,ch198data); + +/* char: 0xc5 */ + +static final byte[] ch197data = { +(byte) 0xee,(byte) 0x44,(byte) 0x7c,(byte) 0x28,(byte) 0x28,(byte) 0x38,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch197 = new BitmapCharRec(7,10,0,0,8,ch197data); + +/* char: 0xc4 */ + +static final byte[] ch196data = { +(byte) 0xee,(byte) 0x44,(byte) 0x7c,(byte) 0x28,(byte) 0x28,(byte) 0x38,(byte) 0x10,(byte) 0x0,(byte) 0x28, +}; + +static final BitmapCharRec ch196 = new BitmapCharRec(7,9,0,0,8,ch196data); + +/* char: 0xc3 */ + +static final byte[] ch195data = { +(byte) 0xee,(byte) 0x44,(byte) 0x7c,(byte) 0x28,(byte) 0x28,(byte) 0x38,(byte) 0x10,(byte) 0x0,(byte) 0x28,(byte) 0x14, +}; + +static final BitmapCharRec ch195 = new BitmapCharRec(7,10,0,0,8,ch195data); + +/* char: 0xc2 */ + +static final byte[] ch194data = { +(byte) 0xee,(byte) 0x44,(byte) 0x7c,(byte) 0x28,(byte) 0x28,(byte) 0x38,(byte) 0x10,(byte) 0x0,(byte) 0x28,(byte) 0x10, +}; + +static final BitmapCharRec ch194 = new BitmapCharRec(7,10,0,0,8,ch194data); + +/* char: 0xc1 */ + +static final byte[] ch193data = { +(byte) 0xee,(byte) 0x44,(byte) 0x7c,(byte) 0x28,(byte) 0x28,(byte) 0x38,(byte) 0x10,(byte) 0x0,(byte) 0x10,(byte) 0x8, +}; + +static final BitmapCharRec ch193 = new BitmapCharRec(7,10,0,0,8,ch193data); + +/* char: 0xc0 */ + +static final byte[] ch192data = { +(byte) 0xee,(byte) 0x44,(byte) 0x7c,(byte) 0x28,(byte) 0x28,(byte) 0x38,(byte) 0x10,(byte) 0x0,(byte) 0x10,(byte) 0x20, +}; + +static final BitmapCharRec ch192 = new BitmapCharRec(7,10,0,0,8,ch192data); + +/* char: 0xbf */ + +static final byte[] ch191data = { +(byte) 0xe0,(byte) 0xa0,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x0,(byte) 0x40, +}; + +static final BitmapCharRec ch191 = new BitmapCharRec(3,7,0,2,4,ch191data); + +/* char: 0xbe */ + +static final byte[] ch190data = { +(byte) 0x44,(byte) 0x3e,(byte) 0x2c,(byte) 0xd4,(byte) 0x28,(byte) 0x48,(byte) 0xe4, +}; + +static final BitmapCharRec ch190 = new BitmapCharRec(7,7,0,0,8,ch190data); + +/* char: 0xbd */ + +static final byte[] ch189data = { +(byte) 0x4e,(byte) 0x24,(byte) 0x2a,(byte) 0xf6,(byte) 0x48,(byte) 0xc8,(byte) 0x44, +}; + +static final BitmapCharRec ch189 = new BitmapCharRec(7,7,0,0,8,ch189data); + +/* char: 0xbc */ + +static final byte[] ch188data = { +(byte) 0x44,(byte) 0x3e,(byte) 0x2c,(byte) 0xf4,(byte) 0x48,(byte) 0xc8,(byte) 0x44, +}; + +static final BitmapCharRec ch188 = new BitmapCharRec(7,7,0,0,8,ch188data); + +/* char: 0xbb */ + +static final byte[] ch187data = { +(byte) 0xa0,(byte) 0x50,(byte) 0x50,(byte) 0xa0, +}; + +static final BitmapCharRec ch187 = new BitmapCharRec(4,4,0,-1,5,ch187data); + +/* char: 0xba */ + +static final byte[] ch186data = { +(byte) 0xe0,(byte) 0x0,(byte) 0x40,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch186 = new BitmapCharRec(3,5,0,-2,4,ch186data); + +/* char: 0xb9 */ + +static final byte[] ch185data = { +(byte) 0xe0,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch185 = new BitmapCharRec(3,4,0,-3,3,ch185data); + +/* char: 0xb8 */ + +static final byte[] ch184data = { +(byte) 0xc0,(byte) 0x20,(byte) 0x40, +}; + +static final BitmapCharRec ch184 = new BitmapCharRec(3,3,0,3,4,ch184data); + +/* char: 0xb7 */ + +static final byte[] ch183data = { +(byte) 0x80, +}; + +static final BitmapCharRec ch183 = new BitmapCharRec(1,1,0,-2,2,ch183data); + +/* char: 0xb6 */ + +static final byte[] ch182data = { +(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x28,(byte) 0x68,(byte) 0xe8,(byte) 0xe8,(byte) 0xe8,(byte) 0x7c, +}; + +static final BitmapCharRec ch182 = new BitmapCharRec(6,9,0,2,6,ch182data); + +/* char: 0xb5 */ + +static final byte[] ch181data = { +(byte) 0x80,(byte) 0x80,(byte) 0xe8,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90, +}; + +static final BitmapCharRec ch181 = new BitmapCharRec(5,7,0,2,5,ch181data); + +/* char: 0xb4 */ + +static final byte[] ch180data = { +(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch180 = new BitmapCharRec(2,2,0,-5,3,ch180data); + +/* char: 0xb3 */ + +static final byte[] ch179data = { +(byte) 0xc0,(byte) 0x20,(byte) 0x40,(byte) 0xe0, +}; + +static final BitmapCharRec ch179 = new BitmapCharRec(3,4,0,-3,3,ch179data); + +/* char: 0xb2 */ + +static final byte[] ch178data = { +(byte) 0xe0,(byte) 0x40,(byte) 0xa0,(byte) 0x60, +}; + +static final BitmapCharRec ch178 = new BitmapCharRec(3,4,0,-3,3,ch178data); + +/* char: 0xb1 */ + +static final byte[] ch177data = { +(byte) 0xf8,(byte) 0x0,(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch177 = new BitmapCharRec(5,7,0,0,6,ch177data); + +/* char: 0xb0 */ + +static final byte[] ch176data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch176 = new BitmapCharRec(4,4,0,-3,4,ch176data); + +/* char: 0xaf */ + +static final byte[] ch175data = { +(byte) 0xe0, +}; + +static final BitmapCharRec ch175 = new BitmapCharRec(3,1,0,-6,4,ch175data); + +/* char: 0xae */ + +static final byte[] ch174data = { +(byte) 0x38,(byte) 0x44,(byte) 0xaa,(byte) 0xb2,(byte) 0xba,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch174 = new BitmapCharRec(7,7,-1,0,9,ch174data); + +/* char: 0xad */ + +static final byte[] ch173data = { +(byte) 0xe0, +}; + +static final BitmapCharRec ch173 = new BitmapCharRec(3,1,0,-2,4,ch173data); + +/* char: 0xac */ + +static final byte[] ch172data = { +(byte) 0x8,(byte) 0x8,(byte) 0xf8, +}; + +static final BitmapCharRec ch172 = new BitmapCharRec(5,3,-1,-1,7,ch172data); + +/* char: 0xab */ + +static final byte[] ch171data = { +(byte) 0x50,(byte) 0xa0,(byte) 0xa0,(byte) 0x50, +}; + +static final BitmapCharRec ch171 = new BitmapCharRec(4,4,0,-1,5,ch171data); + +/* char: 0xaa */ + +static final byte[] ch170data = { +(byte) 0xe0,(byte) 0x0,(byte) 0xa0,(byte) 0x20,(byte) 0xc0, +}; + +static final BitmapCharRec ch170 = new BitmapCharRec(3,5,0,-2,4,ch170data); + +/* char: 0xa9 */ + +static final byte[] ch169data = { +(byte) 0x38,(byte) 0x44,(byte) 0x9a,(byte) 0xa2,(byte) 0x9a,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch169 = new BitmapCharRec(7,7,-1,0,9,ch169data); + +/* char: 0xa8 */ + +static final byte[] ch168data = { +(byte) 0xa0, +}; + +static final BitmapCharRec ch168 = new BitmapCharRec(3,1,-1,-6,5,ch168data); + +/* char: 0xa7 */ + +static final byte[] ch167data = { +(byte) 0xe0,(byte) 0x90,(byte) 0x20,(byte) 0x50,(byte) 0x90,(byte) 0xa0,(byte) 0x40,(byte) 0x90,(byte) 0x70, +}; + +static final BitmapCharRec ch167 = new BitmapCharRec(4,9,0,1,5,ch167data); + +/* char: 0xa6 */ + +static final byte[] ch166data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch166 = new BitmapCharRec(1,7,0,0,2,ch166data); + +/* char: 0xa5 */ + +static final byte[] ch165data = { +(byte) 0x70,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0xd8,(byte) 0x50,(byte) 0x88, +}; + +static final BitmapCharRec ch165 = new BitmapCharRec(5,7,0,0,5,ch165data); + +/* char: 0xa4 */ + +static final byte[] ch164data = { +(byte) 0x88,(byte) 0x70,(byte) 0x50,(byte) 0x50,(byte) 0x70,(byte) 0x88, +}; + +static final BitmapCharRec ch164 = new BitmapCharRec(5,6,0,-1,5,ch164data); + +/* char: 0xa3 */ + +static final byte[] ch163data = { +(byte) 0xf0,(byte) 0xc8,(byte) 0x40,(byte) 0xe0,(byte) 0x40,(byte) 0x50,(byte) 0x30, +}; + +static final BitmapCharRec ch163 = new BitmapCharRec(5,7,0,0,5,ch163data); + +/* char: 0xa2 */ + +static final byte[] ch162data = { +(byte) 0x80,(byte) 0xe0,(byte) 0x90,(byte) 0x80,(byte) 0x90,(byte) 0x70,(byte) 0x10, +}; + +static final BitmapCharRec ch162 = new BitmapCharRec(4,7,0,1,5,ch162data); + +/* char: 0xa1 */ + +static final byte[] ch161data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch161 = new BitmapCharRec(1,7,-1,2,3,ch161data); + +/* char: 0xa0 */ + +static final BitmapCharRec ch160 = new BitmapCharRec(0,0,0,0,2,null); + +/* char: 0x7e '~' */ + +static final byte[] ch126data = { +(byte) 0x98,(byte) 0x64, +}; + +static final BitmapCharRec ch126 = new BitmapCharRec(6,2,0,-2,7,ch126data); + +/* char: 0x7d '}' */ + +static final byte[] ch125data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch125 = new BitmapCharRec(3,9,0,2,4,ch125data); + +/* char: 0x7c '|' */ + +static final byte[] ch124data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch124 = new BitmapCharRec(1,9,0,2,2,ch124data); + +/* char: 0x7b '{' */ + +static final byte[] ch123data = { +(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch123 = new BitmapCharRec(3,9,0,2,4,ch123data); + +/* char: 0x7a 'z' */ + +static final byte[] ch122data = { +(byte) 0xf0,(byte) 0x90,(byte) 0x40,(byte) 0x20,(byte) 0xf0, +}; + +static final BitmapCharRec ch122 = new BitmapCharRec(4,5,0,0,5,ch122data); + +/* char: 0x79 'y' */ + +static final byte[] ch121data = { +(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x30,(byte) 0x50,(byte) 0x48,(byte) 0xdc, +}; + +static final BitmapCharRec ch121 = new BitmapCharRec(6,7,1,2,5,ch121data); + +/* char: 0x78 'x' */ + +static final byte[] ch120data = { +(byte) 0xd8,(byte) 0x50,(byte) 0x20,(byte) 0x50,(byte) 0xd8, +}; + +static final BitmapCharRec ch120 = new BitmapCharRec(5,5,0,0,6,ch120data); + +/* char: 0x77 'w' */ + +static final byte[] ch119data = { +(byte) 0x28,(byte) 0x6c,(byte) 0x54,(byte) 0x92,(byte) 0xdb, +}; + +static final BitmapCharRec ch119 = new BitmapCharRec(8,5,0,0,8,ch119data); + +/* char: 0x76 'v' */ + +static final byte[] ch118data = { +(byte) 0x20,(byte) 0x60,(byte) 0x50,(byte) 0x90,(byte) 0xd8, +}; + +static final BitmapCharRec ch118 = new BitmapCharRec(5,5,0,0,5,ch118data); + +/* char: 0x75 'u' */ + +static final byte[] ch117data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90, +}; + +static final BitmapCharRec ch117 = new BitmapCharRec(5,5,0,0,5,ch117data); + +/* char: 0x74 't' */ + +static final byte[] ch116data = { +(byte) 0x30,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x40, +}; + +static final BitmapCharRec ch116 = new BitmapCharRec(4,6,0,0,4,ch116data); + +/* char: 0x73 's' */ + +static final byte[] ch115data = { +(byte) 0xe0,(byte) 0x20,(byte) 0x60,(byte) 0x80,(byte) 0xe0, +}; + +static final BitmapCharRec ch115 = new BitmapCharRec(3,5,0,0,4,ch115data); + +/* char: 0x72 'r' */ + +static final byte[] ch114data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x60,(byte) 0xa0, +}; + +static final BitmapCharRec ch114 = new BitmapCharRec(3,5,0,0,4,ch114data); + +/* char: 0x71 'q' */ + +static final byte[] ch113data = { +(byte) 0x38,(byte) 0x10,(byte) 0x70,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x70, +}; + +static final BitmapCharRec ch113 = new BitmapCharRec(5,7,0,2,5,ch113data); + +/* char: 0x70 'p' */ + +static final byte[] ch112data = { +(byte) 0xc0,(byte) 0x80,(byte) 0xe0,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xe0, +}; + +static final BitmapCharRec ch112 = new BitmapCharRec(4,7,0,2,5,ch112data); + +/* char: 0x6f 'o' */ + +static final byte[] ch111data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch111 = new BitmapCharRec(4,5,0,0,5,ch111data); + +/* char: 0x6e 'n' */ + +static final byte[] ch110data = { +(byte) 0xd8,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xe0, +}; + +static final BitmapCharRec ch110 = new BitmapCharRec(5,5,0,0,5,ch110data); + +/* char: 0x6d 'm' */ + +static final byte[] ch109data = { +(byte) 0xdb,(byte) 0x92,(byte) 0x92,(byte) 0x92,(byte) 0xec, +}; + +static final BitmapCharRec ch109 = new BitmapCharRec(8,5,0,0,8,ch109data); + +/* char: 0x6c 'l' */ + +static final byte[] ch108data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0, +}; + +static final BitmapCharRec ch108 = new BitmapCharRec(3,7,0,0,4,ch108data); + +/* char: 0x6b 'k' */ + +static final byte[] ch107data = { +(byte) 0x98,(byte) 0x90,(byte) 0xe0,(byte) 0xa0,(byte) 0x90,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch107 = new BitmapCharRec(5,7,0,0,5,ch107data); + +/* char: 0x6a 'j' */ + +static final byte[] ch106data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x0,(byte) 0x40, +}; + +static final BitmapCharRec ch106 = new BitmapCharRec(2,9,0,2,3,ch106data); + +/* char: 0x69 'i' */ + +static final byte[] ch105data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x0,(byte) 0x40, +}; + +static final BitmapCharRec ch105 = new BitmapCharRec(2,7,0,0,3,ch105data); + +/* char: 0x68 'h' */ + +static final byte[] ch104data = { +(byte) 0xd8,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xe0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch104 = new BitmapCharRec(5,7,0,0,5,ch104data); + +/* char: 0x67 'g' */ + +static final byte[] ch103data = { +(byte) 0xe0,(byte) 0x90,(byte) 0x60,(byte) 0x40,(byte) 0xa0,(byte) 0xa0,(byte) 0x70, +}; + +static final BitmapCharRec ch103 = new BitmapCharRec(4,7,0,2,5,ch103data); + +/* char: 0x66 'f' */ + +static final byte[] ch102data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0,(byte) 0x40,(byte) 0x30, +}; + +static final BitmapCharRec ch102 = new BitmapCharRec(4,7,0,0,4,ch102data); + +/* char: 0x65 'e' */ + +static final byte[] ch101data = { +(byte) 0x60,(byte) 0x80,(byte) 0xc0,(byte) 0xa0,(byte) 0x60, +}; + +static final BitmapCharRec ch101 = new BitmapCharRec(3,5,0,0,4,ch101data); + +/* char: 0x64 'd' */ + +static final byte[] ch100data = { +(byte) 0x68,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x70,(byte) 0x10,(byte) 0x30, +}; + +static final BitmapCharRec ch100 = new BitmapCharRec(5,7,0,0,5,ch100data); + +/* char: 0x63 'c' */ + +static final byte[] ch99data = { +(byte) 0x60,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x60, +}; + +static final BitmapCharRec ch99 = new BitmapCharRec(3,5,0,0,4,ch99data); + +/* char: 0x62 'b' */ + +static final byte[] ch98data = { +(byte) 0xe0,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xe0,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch98 = new BitmapCharRec(4,7,0,0,5,ch98data); + +/* char: 0x61 'a' */ + +static final byte[] ch97data = { +(byte) 0xe0,(byte) 0xa0,(byte) 0x60,(byte) 0x20,(byte) 0xc0, +}; + +static final BitmapCharRec ch97 = new BitmapCharRec(3,5,0,0,4,ch97data); + +/* char: 0x60 '`' */ + +static final byte[] ch96data = { +(byte) 0xc0,(byte) 0x80, +}; + +static final BitmapCharRec ch96 = new BitmapCharRec(2,2,0,-5,3,ch96data); + +/* char: 0x5f '_' */ + +static final byte[] ch95data = { +(byte) 0xf8, +}; + +static final BitmapCharRec ch95 = new BitmapCharRec(5,1,0,3,5,ch95data); + +/* char: 0x5e '^' */ + +static final byte[] ch94data = { +(byte) 0xa0,(byte) 0xa0,(byte) 0x40, +}; + +static final BitmapCharRec ch94 = new BitmapCharRec(3,3,-1,-4,5,ch94data); + +/* char: 0x5d ']' */ + +static final byte[] ch93data = { +(byte) 0xc0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0, +}; + +static final BitmapCharRec ch93 = new BitmapCharRec(2,9,0,2,3,ch93data); + +/* char: 0x5c '\' */ + +static final byte[] ch92data = { +(byte) 0x20,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch92 = new BitmapCharRec(3,7,0,0,3,ch92data); + +/* char: 0x5b '[' */ + +static final byte[] ch91data = { +(byte) 0xc0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xc0, +}; + +static final BitmapCharRec ch91 = new BitmapCharRec(2,9,0,2,3,ch91data); + +/* char: 0x5a 'Z' */ + +static final byte[] ch90data = { +(byte) 0xf8,(byte) 0x88,(byte) 0x40,(byte) 0x20,(byte) 0x10,(byte) 0x88,(byte) 0xf8, +}; + +static final BitmapCharRec ch90 = new BitmapCharRec(5,7,0,0,6,ch90data); + +/* char: 0x59 'Y' */ + +static final byte[] ch89data = { +(byte) 0x38,(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x44,(byte) 0xee, +}; + +static final BitmapCharRec ch89 = new BitmapCharRec(7,7,0,0,8,ch89data); + +/* char: 0x58 'X' */ + +static final byte[] ch88data = { +(byte) 0xee,(byte) 0x44,(byte) 0x28,(byte) 0x10,(byte) 0x28,(byte) 0x44,(byte) 0xee, +}; + +static final BitmapCharRec ch88 = new BitmapCharRec(7,7,0,0,8,ch88data); + +/* char: 0x57 'W' */ + +static final byte[] ch87data = { +(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x55,(byte) 0x0,(byte) 0x55,(byte) 0x0,(byte) 0xc9,(byte) 0x80,(byte) 0x88,(byte) 0x80,(byte) 0xdd,(byte) 0xc0, +}; + +static final BitmapCharRec ch87 = new BitmapCharRec(10,7,0,0,10,ch87data); + +/* char: 0x56 'V' */ + +static final byte[] ch86data = { +(byte) 0x10,(byte) 0x10,(byte) 0x28,(byte) 0x28,(byte) 0x6c,(byte) 0x44,(byte) 0xee, +}; + +static final BitmapCharRec ch86 = new BitmapCharRec(7,7,0,0,8,ch86data); + +/* char: 0x55 'U' */ + +static final byte[] ch85data = { +(byte) 0x38,(byte) 0x6c,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0xee, +}; + +static final BitmapCharRec ch85 = new BitmapCharRec(7,7,0,0,8,ch85data); + +/* char: 0x54 'T' */ + +static final byte[] ch84data = { +(byte) 0x70,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xa8,(byte) 0xf8, +}; + +static final BitmapCharRec ch84 = new BitmapCharRec(5,7,0,0,6,ch84data); + +/* char: 0x53 'S' */ + +static final byte[] ch83data = { +(byte) 0xe0,(byte) 0x90,(byte) 0x10,(byte) 0x60,(byte) 0xc0,(byte) 0x90,(byte) 0x70, +}; + +static final BitmapCharRec ch83 = new BitmapCharRec(4,7,0,0,5,ch83data); + +/* char: 0x52 'R' */ + +static final byte[] ch82data = { +(byte) 0xec,(byte) 0x48,(byte) 0x50,(byte) 0x70,(byte) 0x48,(byte) 0x48,(byte) 0xf0, +}; + +static final BitmapCharRec ch82 = new BitmapCharRec(6,7,0,0,7,ch82data); + +/* char: 0x51 'Q' */ + +static final byte[] ch81data = { +(byte) 0xc,(byte) 0x18,(byte) 0x70,(byte) 0xcc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xcc,(byte) 0x78, +}; + +static final BitmapCharRec ch81 = new BitmapCharRec(6,9,0,2,7,ch81data); + +/* char: 0x50 'P' */ + +static final byte[] ch80data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x70,(byte) 0x48,(byte) 0x48,(byte) 0xf0, +}; + +static final BitmapCharRec ch80 = new BitmapCharRec(5,7,0,0,6,ch80data); + +/* char: 0x4f 'O' */ + +static final byte[] ch79data = { +(byte) 0x78,(byte) 0xcc,(byte) 0x84,(byte) 0x84,(byte) 0x84,(byte) 0xcc,(byte) 0x78, +}; + +static final BitmapCharRec ch79 = new BitmapCharRec(6,7,0,0,7,ch79data); + +/* char: 0x4e 'N' */ + +static final byte[] ch78data = { +(byte) 0xe4,(byte) 0x4c,(byte) 0x4c,(byte) 0x54,(byte) 0x54,(byte) 0x64,(byte) 0xee, +}; + +static final BitmapCharRec ch78 = new BitmapCharRec(7,7,0,0,8,ch78data); + +/* char: 0x4d 'M' */ + +static final byte[] ch77data = { +(byte) 0xeb,(byte) 0x80,(byte) 0x49,(byte) 0x0,(byte) 0x55,(byte) 0x0,(byte) 0x55,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0xe3,(byte) 0x80, +}; + +static final BitmapCharRec ch77 = new BitmapCharRec(9,7,0,0,10,ch77data); + +/* char: 0x4c 'L' */ + +static final byte[] ch76data = { +(byte) 0xf8,(byte) 0x48,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0, +}; + +static final BitmapCharRec ch76 = new BitmapCharRec(5,7,0,0,6,ch76data); + +/* char: 0x4b 'K' */ + +static final byte[] ch75data = { +(byte) 0xec,(byte) 0x48,(byte) 0x50,(byte) 0x60,(byte) 0x50,(byte) 0x48,(byte) 0xec, +}; + +static final BitmapCharRec ch75 = new BitmapCharRec(6,7,0,0,7,ch75data); + +/* char: 0x4a 'J' */ + +static final byte[] ch74data = { +(byte) 0xc0,(byte) 0xa0,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x70, +}; + +static final BitmapCharRec ch74 = new BitmapCharRec(4,7,0,0,4,ch74data); + +/* char: 0x49 'I' */ + +static final byte[] ch73data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xe0, +}; + +static final BitmapCharRec ch73 = new BitmapCharRec(3,7,0,0,4,ch73data); + +/* char: 0x48 'H' */ + +static final byte[] ch72data = { +(byte) 0xee,(byte) 0x44,(byte) 0x44,(byte) 0x7c,(byte) 0x44,(byte) 0x44,(byte) 0xee, +}; + +static final BitmapCharRec ch72 = new BitmapCharRec(7,7,0,0,8,ch72data); + +/* char: 0x47 'G' */ + +static final byte[] ch71data = { +(byte) 0x78,(byte) 0xc4,(byte) 0x84,(byte) 0x9c,(byte) 0x80,(byte) 0xc4,(byte) 0x7c, +}; + +static final BitmapCharRec ch71 = new BitmapCharRec(6,7,0,0,7,ch71data); + +/* char: 0x46 'F' */ + +static final byte[] ch70data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x70,(byte) 0x40,(byte) 0x48,(byte) 0xf8, +}; + +static final BitmapCharRec ch70 = new BitmapCharRec(5,7,0,0,6,ch70data); + +/* char: 0x45 'E' */ + +static final byte[] ch69data = { +(byte) 0xf8,(byte) 0x48,(byte) 0x40,(byte) 0x70,(byte) 0x40,(byte) 0x48,(byte) 0xf8, +}; + +static final BitmapCharRec ch69 = new BitmapCharRec(5,7,0,0,6,ch69data); + +/* char: 0x44 'D' */ + +static final byte[] ch68data = { +(byte) 0xf8,(byte) 0x4c,(byte) 0x44,(byte) 0x44,(byte) 0x44,(byte) 0x4c,(byte) 0xf8, +}; + +static final BitmapCharRec ch68 = new BitmapCharRec(6,7,0,0,7,ch68data); + +/* char: 0x43 'C' */ + +static final byte[] ch67data = { +(byte) 0x78,(byte) 0xc4,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0xc4,(byte) 0x7c, +}; + +static final BitmapCharRec ch67 = new BitmapCharRec(6,7,0,0,7,ch67data); + +/* char: 0x42 'B' */ + +static final byte[] ch66data = { +(byte) 0xf0,(byte) 0x48,(byte) 0x48,(byte) 0x70,(byte) 0x48,(byte) 0x48,(byte) 0xf0, +}; + +static final BitmapCharRec ch66 = new BitmapCharRec(5,7,0,0,6,ch66data); + +/* char: 0x41 'A' */ + +static final byte[] ch65data = { +(byte) 0xee,(byte) 0x44,(byte) 0x7c,(byte) 0x28,(byte) 0x28,(byte) 0x38,(byte) 0x10, +}; + +static final BitmapCharRec ch65 = new BitmapCharRec(7,7,0,0,8,ch65data); + +/* char: 0x40 '@' */ + +static final byte[] ch64data = { +(byte) 0x3e,(byte) 0x40,(byte) 0x92,(byte) 0xad,(byte) 0xa5,(byte) 0xa5,(byte) 0x9d,(byte) 0x42,(byte) 0x3c, +}; + +static final BitmapCharRec ch64 = new BitmapCharRec(8,9,0,2,9,ch64data); + +/* char: 0x3f '?' */ + +static final byte[] ch63data = { +(byte) 0x40,(byte) 0x0,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0xa0,(byte) 0xe0, +}; + +static final BitmapCharRec ch63 = new BitmapCharRec(3,7,0,0,4,ch63data); + +/* char: 0x3e '>' */ + +static final byte[] ch62data = { +(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch62 = new BitmapCharRec(3,5,0,0,5,ch62data); + +/* char: 0x3d '=' */ + +static final byte[] ch61data = { +(byte) 0xf8,(byte) 0x0,(byte) 0xf8, +}; + +static final BitmapCharRec ch61 = new BitmapCharRec(5,3,0,-1,6,ch61data); + +/* char: 0x3c '<' */ + +static final byte[] ch60data = { +(byte) 0x20,(byte) 0x40,(byte) 0x80,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch60 = new BitmapCharRec(3,5,-1,0,5,ch60data); + +/* char: 0x3b ';' */ + +static final byte[] ch59data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch59 = new BitmapCharRec(1,7,-1,2,3,ch59data); + +/* char: 0x3a ':' */ + +static final byte[] ch58data = { +(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x80, +}; + +static final BitmapCharRec ch58 = new BitmapCharRec(1,5,-1,0,3,ch58data); + +/* char: 0x39 '9' */ + +static final byte[] ch57data = { +(byte) 0xc0,(byte) 0x20,(byte) 0x70,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch57 = new BitmapCharRec(4,7,0,0,5,ch57data); + +/* char: 0x38 '8' */ + +static final byte[] ch56data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch56 = new BitmapCharRec(4,7,0,0,5,ch56data); + +/* char: 0x37 '7' */ + +static final byte[] ch55data = { +(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x90,(byte) 0xf0, +}; + +static final BitmapCharRec ch55 = new BitmapCharRec(4,7,0,0,5,ch55data); + +/* char: 0x36 '6' */ + +static final byte[] ch54data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0xe0,(byte) 0x40,(byte) 0x30, +}; + +static final BitmapCharRec ch54 = new BitmapCharRec(4,7,0,0,5,ch54data); + +/* char: 0x35 '5' */ + +static final byte[] ch53data = { +(byte) 0xe0,(byte) 0x90,(byte) 0x10,(byte) 0x10,(byte) 0xe0,(byte) 0x40,(byte) 0x70, +}; + +static final BitmapCharRec ch53 = new BitmapCharRec(4,7,0,0,5,ch53data); + +/* char: 0x34 '4' */ + +static final byte[] ch52data = { +(byte) 0x10,(byte) 0x10,(byte) 0xf8,(byte) 0x90,(byte) 0x50,(byte) 0x30,(byte) 0x10, +}; + +static final BitmapCharRec ch52 = new BitmapCharRec(5,7,0,0,5,ch52data); + +/* char: 0x33 '3' */ + +static final byte[] ch51data = { +(byte) 0xe0,(byte) 0x10,(byte) 0x10,(byte) 0x60,(byte) 0x10,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch51 = new BitmapCharRec(4,7,0,0,5,ch51data); + +/* char: 0x32 '2' */ + +static final byte[] ch50data = { +(byte) 0xf0,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x10,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch50 = new BitmapCharRec(4,7,0,0,5,ch50data); + +/* char: 0x31 '1' */ + +static final byte[] ch49data = { +(byte) 0xe0,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0xc0,(byte) 0x40, +}; + +static final BitmapCharRec ch49 = new BitmapCharRec(3,7,-1,0,5,ch49data); + +/* char: 0x30 '0' */ + +static final byte[] ch48data = { +(byte) 0x60,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x90,(byte) 0x60, +}; + +static final BitmapCharRec ch48 = new BitmapCharRec(4,7,0,0,5,ch48data); + +/* char: 0x2f '/' */ + +static final byte[] ch47data = { +(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch47 = new BitmapCharRec(3,7,0,0,3,ch47data); + +/* char: 0x2e '.' */ + +static final byte[] ch46data = { +(byte) 0x80, +}; + +static final BitmapCharRec ch46 = new BitmapCharRec(1,1,-1,0,3,ch46data); + +/* char: 0x2d '-' */ + +static final byte[] ch45data = { +(byte) 0xf0, +}; + +static final BitmapCharRec ch45 = new BitmapCharRec(4,1,-1,-2,7,ch45data); + +/* char: 0x2c ',' */ + +static final byte[] ch44data = { +(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch44 = new BitmapCharRec(1,3,-1,2,3,ch44data); + +/* char: 0x2b '+' */ + +static final byte[] ch43data = { +(byte) 0x20,(byte) 0x20,(byte) 0xf8,(byte) 0x20,(byte) 0x20, +}; + +static final BitmapCharRec ch43 = new BitmapCharRec(5,5,0,0,6,ch43data); + +/* char: 0x2a '*' */ + +static final byte[] ch42data = { +(byte) 0xa0,(byte) 0x40,(byte) 0xa0, +}; + +static final BitmapCharRec ch42 = new BitmapCharRec(3,3,0,-4,5,ch42data); + +/* char: 0x29 ')' */ + +static final byte[] ch41data = { +(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch41 = new BitmapCharRec(3,9,0,2,4,ch41data); + +/* char: 0x28 '(' */ + +static final byte[] ch40data = { +(byte) 0x20,(byte) 0x40,(byte) 0x40,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x40,(byte) 0x40,(byte) 0x20, +}; + +static final BitmapCharRec ch40 = new BitmapCharRec(3,9,0,2,4,ch40data); + +/* char: 0x27 ''' */ + +static final byte[] ch39data = { +(byte) 0x40,(byte) 0xc0, +}; + +static final BitmapCharRec ch39 = new BitmapCharRec(2,2,0,-5,3,ch39data); + +/* char: 0x26 '&' */ + +static final byte[] ch38data = { +(byte) 0x76,(byte) 0x8d,(byte) 0x98,(byte) 0x74,(byte) 0x6e,(byte) 0x50,(byte) 0x30, +}; + +static final BitmapCharRec ch38 = new BitmapCharRec(8,7,0,0,8,ch38data); + +/* char: 0x25 '%' */ + +static final byte[] ch37data = { +(byte) 0x44,(byte) 0x2a,(byte) 0x2a,(byte) 0x56,(byte) 0xa8,(byte) 0xa4,(byte) 0x7e, +}; + +static final BitmapCharRec ch37 = new BitmapCharRec(7,7,0,0,8,ch37data); + +/* char: 0x24 '$' */ + +static final byte[] ch36data = { +(byte) 0x20,(byte) 0xe0,(byte) 0x90,(byte) 0x10,(byte) 0x60,(byte) 0x80,(byte) 0x90,(byte) 0x70,(byte) 0x20, +}; + +static final BitmapCharRec ch36 = new BitmapCharRec(4,9,0,1,5,ch36data); + +/* char: 0x23 '#' */ + +static final byte[] ch35data = { +(byte) 0x50,(byte) 0x50,(byte) 0xf8,(byte) 0x50,(byte) 0xf8,(byte) 0x50,(byte) 0x50, +}; + +static final BitmapCharRec ch35 = new BitmapCharRec(5,7,0,0,5,ch35data); + +/* char: 0x22 '"' */ + +static final byte[] ch34data = { +(byte) 0xa0,(byte) 0xa0, +}; + +static final BitmapCharRec ch34 = new BitmapCharRec(3,2,0,-5,4,ch34data); + +/* char: 0x21 '!' */ + +static final byte[] ch33data = { +(byte) 0x80,(byte) 0x0,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80,(byte) 0x80, +}; + +static final BitmapCharRec ch33 = new BitmapCharRec(1,7,-1,0,3,ch33data); + +/* char: 0x20 ' ' */ + +static final BitmapCharRec ch32 = new BitmapCharRec(0,0,0,0,2,null); + +static final BitmapCharRec[] chars = { +ch32, +ch33, +ch34, +ch35, +ch36, +ch37, +ch38, +ch39, +ch40, +ch41, +ch42, +ch43, +ch44, +ch45, +ch46, +ch47, +ch48, +ch49, +ch50, +ch51, +ch52, +ch53, +ch54, +ch55, +ch56, +ch57, +ch58, +ch59, +ch60, +ch61, +ch62, +ch63, +ch64, +ch65, +ch66, +ch67, +ch68, +ch69, +ch70, +ch71, +ch72, +ch73, +ch74, +ch75, +ch76, +ch77, +ch78, +ch79, +ch80, +ch81, +ch82, +ch83, +ch84, +ch85, +ch86, +ch87, +ch88, +ch89, +ch90, +ch91, +ch92, +ch93, +ch94, +ch95, +ch96, +ch97, +ch98, +ch99, +ch100, +ch101, +ch102, +ch103, +ch104, +ch105, +ch106, +ch107, +ch108, +ch109, +ch110, +ch111, +ch112, +ch113, +ch114, +ch115, +ch116, +ch117, +ch118, +ch119, +ch120, +ch121, +ch122, +ch123, +ch124, +ch125, +ch126, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +ch160, +ch161, +ch162, +ch163, +ch164, +ch165, +ch166, +ch167, +ch168, +ch169, +ch170, +ch171, +ch172, +ch173, +ch174, +ch175, +ch176, +ch177, +ch178, +ch179, +ch180, +ch181, +ch182, +ch183, +ch184, +ch185, +ch186, +ch187, +ch188, +ch189, +ch190, +ch191, +ch192, +ch193, +ch194, +ch195, +ch196, +ch197, +ch198, +ch199, +ch200, +ch201, +ch202, +ch203, +ch204, +ch205, +ch206, +ch207, +ch208, +ch209, +ch210, +ch211, +ch212, +ch213, +ch214, +ch215, +ch216, +ch217, +ch218, +ch219, +ch220, +ch221, +ch222, +ch223, +ch224, +ch225, +ch226, +ch227, +ch228, +ch229, +ch230, +ch231, +ch232, +ch233, +ch234, +ch235, +ch236, +ch237, +ch238, +ch239, +ch240, +ch241, +ch242, +ch243, +ch244, +ch245, +ch246, +ch247, +ch248, +ch249, +ch250, +ch251, +ch252, +ch253, +ch254, +ch255, +}; + + public static final BitmapFontRec glutBitmapTimesRoman10 = new BitmapFontRec("-adobe-times-medium-r-normal--10-100-75-75-p-54-iso8859-1", + 224, + 32, + chars); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapTimesRoman24.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapTimesRoman24.java new file mode 100644 index 000000000..073e6e673 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTBitmapTimesRoman24.java @@ -0,0 +1,2080 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +class GLUTBitmapTimesRoman24 { + +/* GENERATED FILE -- DO NOT MODIFY */ + +/* char: 0xff */ + +static final byte[] ch255data = { +(byte) 0xe0,(byte) 0x0,(byte) 0xf0,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x4,(byte) 0x0,(byte) 0xe,(byte) 0x0,(byte) 0xe,(byte) 0x0, +(byte) 0x1a,(byte) 0x0,(byte) 0x19,(byte) 0x0,(byte) 0x19,(byte) 0x0,(byte) 0x31,(byte) 0x0,(byte) 0x30,(byte) 0x80,(byte) 0x30,(byte) 0x80,(byte) 0x60,(byte) 0x80,(byte) 0x60,(byte) 0xc0, +(byte) 0xf1,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x33,(byte) 0x0, +}; + +static final BitmapCharRec ch255 = new BitmapCharRec(11,21,0,5,11,ch255data); + +/* char: 0xfe */ + +static final byte[] ch254data = { +(byte) 0xf0,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x6e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80, +(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80, +(byte) 0x6e,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0xe0,(byte) 0x0, +}; + +static final BitmapCharRec ch254 = new BitmapCharRec(10,22,-1,5,12,ch254data); + +/* char: 0xfd */ + +static final byte[] ch253data = { +(byte) 0xe0,(byte) 0x0,(byte) 0xf0,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x4,(byte) 0x0,(byte) 0xe,(byte) 0x0,(byte) 0xe,(byte) 0x0, +(byte) 0x1a,(byte) 0x0,(byte) 0x19,(byte) 0x0,(byte) 0x19,(byte) 0x0,(byte) 0x31,(byte) 0x0,(byte) 0x30,(byte) 0x80,(byte) 0x30,(byte) 0x80,(byte) 0x60,(byte) 0x80,(byte) 0x60,(byte) 0xc0, +(byte) 0xf1,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x3,(byte) 0x80,(byte) 0x1,(byte) 0x80, +}; + +static final BitmapCharRec ch253 = new BitmapCharRec(11,22,0,5,11,ch253data); + +/* char: 0xfc */ + +static final byte[] ch252data = { +(byte) 0x1c,(byte) 0xe0,(byte) 0x3e,(byte) 0xc0,(byte) 0x71,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xe1,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x33,(byte) 0x0, +}; + +static final BitmapCharRec ch252 = new BitmapCharRec(11,16,-1,0,13,ch252data); + +/* char: 0xfb */ + +static final byte[] ch251data = { +(byte) 0x1c,(byte) 0xe0,(byte) 0x3e,(byte) 0xc0,(byte) 0x71,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xe1,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x21,(byte) 0x0,(byte) 0x12,(byte) 0x0,(byte) 0x1e,(byte) 0x0, +(byte) 0xc,(byte) 0x0, +}; + +static final BitmapCharRec ch251 = new BitmapCharRec(11,17,-1,0,13,ch251data); + +/* char: 0xfa */ + +static final byte[] ch250data = { +(byte) 0x1c,(byte) 0xe0,(byte) 0x3e,(byte) 0xc0,(byte) 0x71,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xe1,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x3,(byte) 0x80, +(byte) 0x1,(byte) 0x80, +}; + +static final BitmapCharRec ch250 = new BitmapCharRec(11,17,-1,0,13,ch250data); + +/* char: 0xf9 */ + +static final byte[] ch249data = { +(byte) 0x1c,(byte) 0xe0,(byte) 0x3e,(byte) 0xc0,(byte) 0x71,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xe1,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x2,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x38,(byte) 0x0, +(byte) 0x30,(byte) 0x0, +}; + +static final BitmapCharRec ch249 = new BitmapCharRec(11,17,-1,0,13,ch249data); + +/* char: 0xf8 */ + +static final byte[] ch248data = { +(byte) 0xc0,(byte) 0x0,(byte) 0xde,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x71,(byte) 0x80,(byte) 0xd0,(byte) 0xc0,(byte) 0xd8,(byte) 0xc0,(byte) 0xc8,(byte) 0xc0,(byte) 0xcc,(byte) 0xc0, +(byte) 0xc4,(byte) 0xc0,(byte) 0xc6,(byte) 0xc0,(byte) 0x63,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x1e,(byte) 0xc0,(byte) 0x0,(byte) 0xc0, +}; + +static final BitmapCharRec ch248 = new BitmapCharRec(10,14,-1,1,12,ch248data); + +/* char: 0xf7 */ + +static final byte[] ch247data = { +(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xff,(byte) 0xf0,(byte) 0xff,(byte) 0xf0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0, +(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0, +}; + +static final BitmapCharRec ch247 = new BitmapCharRec(12,10,-1,-2,14,ch247data); + +/* char: 0xf6 */ + +static final byte[] ch246data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x1e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x33,(byte) 0x0, +}; + +static final BitmapCharRec ch246 = new BitmapCharRec(10,16,-1,0,12,ch246data); + +/* char: 0xf5 */ + +static final byte[] ch245data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x1e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x27,(byte) 0x0,(byte) 0x1c,(byte) 0x80, +}; + +static final BitmapCharRec ch245 = new BitmapCharRec(10,16,-1,0,12,ch245data); + +/* char: 0xf4 */ + +static final byte[] ch244data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x1e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x21,(byte) 0x0,(byte) 0x12,(byte) 0x0,(byte) 0x1e,(byte) 0x0, +(byte) 0xc,(byte) 0x0, +}; + +static final BitmapCharRec ch244 = new BitmapCharRec(10,17,-1,0,12,ch244data); + +/* char: 0xf3 */ + +static final byte[] ch243data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x1e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x3,(byte) 0x80, +(byte) 0x1,(byte) 0x80, +}; + +static final BitmapCharRec ch243 = new BitmapCharRec(10,17,-1,0,12,ch243data); + +/* char: 0xf2 */ + +static final byte[] ch242data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x1e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x2,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x38,(byte) 0x0, +(byte) 0x30,(byte) 0x0, +}; + +static final BitmapCharRec ch242 = new BitmapCharRec(10,17,-1,0,12,ch242data); + +/* char: 0xf1 */ + +static final byte[] ch241data = { +(byte) 0xf1,(byte) 0xe0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x71,(byte) 0xc0,(byte) 0x6f,(byte) 0x80,(byte) 0xe7,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x27,(byte) 0x0,(byte) 0x1c,(byte) 0x80, +}; + +static final BitmapCharRec ch241 = new BitmapCharRec(11,16,-1,0,13,ch241data); + +/* char: 0xf0 */ + +static final byte[] ch240data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x1f,(byte) 0x0,(byte) 0xc6,(byte) 0x0,(byte) 0x3c,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x71,(byte) 0x80, +(byte) 0xc0,(byte) 0x0, +}; + +static final BitmapCharRec ch240 = new BitmapCharRec(10,17,-1,0,12,ch240data); + +/* char: 0xef */ + +static final byte[] ch239data = { +(byte) 0x78,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x70,(byte) 0x0,(byte) 0x0,(byte) 0xcc,(byte) 0xcc, +}; + +static final BitmapCharRec ch239 = new BitmapCharRec(6,16,0,0,6,ch239data); + +/* char: 0xee */ + +static final byte[] ch238data = { +(byte) 0x78,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x70,(byte) 0x0,(byte) 0x84,(byte) 0x48,(byte) 0x78, +(byte) 0x30, +}; + +static final BitmapCharRec ch238 = new BitmapCharRec(6,17,0,0,6,ch238data); + +/* char: 0xed */ + +static final byte[] ch237data = { +(byte) 0xf0,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0xe0,(byte) 0x0,(byte) 0x80,(byte) 0x60,(byte) 0x38, +(byte) 0x18, +}; + +static final BitmapCharRec ch237 = new BitmapCharRec(5,17,-1,0,6,ch237data); + +/* char: 0xec */ + +static final byte[] ch236data = { +(byte) 0x78,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x70,(byte) 0x0,(byte) 0x8,(byte) 0x30,(byte) 0xe0, +(byte) 0xc0, +}; + +static final BitmapCharRec ch236 = new BitmapCharRec(5,17,0,0,6,ch236data); + +/* char: 0xeb */ + +static final byte[] ch235data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x70,(byte) 0x80,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0x41,(byte) 0x80,(byte) 0x63,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x33,(byte) 0x0, +}; + +static final BitmapCharRec ch235 = new BitmapCharRec(9,16,-1,0,11,ch235data); + +/* char: 0xea */ + +static final byte[] ch234data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x70,(byte) 0x80,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0x41,(byte) 0x80,(byte) 0x63,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x21,(byte) 0x0,(byte) 0x12,(byte) 0x0,(byte) 0x1e,(byte) 0x0, +(byte) 0xc,(byte) 0x0, +}; + +static final BitmapCharRec ch234 = new BitmapCharRec(9,17,-1,0,11,ch234data); + +/* char: 0xe9 */ + +static final byte[] ch233data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x70,(byte) 0x80,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0x41,(byte) 0x80,(byte) 0x63,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x10,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x7,(byte) 0x0, +(byte) 0x3,(byte) 0x0, +}; + +static final BitmapCharRec ch233 = new BitmapCharRec(9,17,-1,0,11,ch233data); + +/* char: 0xe8 */ + +static final byte[] ch232data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x70,(byte) 0x80,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0x41,(byte) 0x80,(byte) 0x63,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x4,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x70,(byte) 0x0, +(byte) 0x60,(byte) 0x0, +}; + +static final BitmapCharRec ch232 = new BitmapCharRec(9,17,-1,0,11,ch232data); + +/* char: 0xe7 */ + +static final byte[] ch231data = { +(byte) 0x3c,(byte) 0x0,(byte) 0x66,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x7f,(byte) 0x0, +(byte) 0x70,(byte) 0x80,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x41,(byte) 0x80, +(byte) 0x63,(byte) 0x80,(byte) 0x1f,(byte) 0x0, +}; + +static final BitmapCharRec ch231 = new BitmapCharRec(9,18,-1,6,11,ch231data); + +/* char: 0xe6 */ + +static final byte[] ch230data = { +(byte) 0x70,(byte) 0xf0,(byte) 0xfb,(byte) 0xf8,(byte) 0xc7,(byte) 0x84,(byte) 0xc3,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x3b,(byte) 0x0,(byte) 0xf,(byte) 0xfc, +(byte) 0x3,(byte) 0xc,(byte) 0x63,(byte) 0xc,(byte) 0x67,(byte) 0x98,(byte) 0x3c,(byte) 0xf0, +}; + +static final BitmapCharRec ch230 = new BitmapCharRec(14,12,-1,0,16,ch230data); + +/* char: 0xe5 */ + +static final byte[] ch229data = { +(byte) 0x71,(byte) 0x80,(byte) 0xfb,(byte) 0x0,(byte) 0xc7,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x3b,(byte) 0x0,(byte) 0xf,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x67,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x1c,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0, +(byte) 0x1c,(byte) 0x0, +}; + +static final BitmapCharRec ch229 = new BitmapCharRec(9,17,-1,0,11,ch229data); + +/* char: 0xe4 */ + +static final byte[] ch228data = { +(byte) 0x71,(byte) 0x80,(byte) 0xfb,(byte) 0x0,(byte) 0xc7,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x3b,(byte) 0x0,(byte) 0xf,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x67,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x66,(byte) 0x0,(byte) 0x66,(byte) 0x0, +}; + +static final BitmapCharRec ch228 = new BitmapCharRec(9,16,-1,0,11,ch228data); + +/* char: 0xe3 */ + +static final byte[] ch227data = { +(byte) 0x71,(byte) 0x80,(byte) 0xfb,(byte) 0x0,(byte) 0xc7,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x3b,(byte) 0x0,(byte) 0xf,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x67,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x5c,(byte) 0x0,(byte) 0x3a,(byte) 0x0, +}; + +static final BitmapCharRec ch227 = new BitmapCharRec(9,16,-1,0,11,ch227data); + +/* char: 0xe2 */ + +static final byte[] ch226data = { +(byte) 0x71,(byte) 0x80,(byte) 0xfb,(byte) 0x0,(byte) 0xc7,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x3b,(byte) 0x0,(byte) 0xf,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x67,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x42,(byte) 0x0,(byte) 0x24,(byte) 0x0,(byte) 0x3c,(byte) 0x0, +(byte) 0x18,(byte) 0x0, +}; + +static final BitmapCharRec ch226 = new BitmapCharRec(9,17,-1,0,11,ch226data); + +/* char: 0xe1 */ + +static final byte[] ch225data = { +(byte) 0x71,(byte) 0x80,(byte) 0xfb,(byte) 0x0,(byte) 0xc7,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x3b,(byte) 0x0,(byte) 0xf,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x67,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x10,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x7,(byte) 0x0, +(byte) 0x3,(byte) 0x0, +}; + +static final BitmapCharRec ch225 = new BitmapCharRec(9,17,-1,0,11,ch225data); + +/* char: 0xe0 */ + +static final byte[] ch224data = { +(byte) 0x71,(byte) 0x80,(byte) 0xfb,(byte) 0x0,(byte) 0xc7,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x3b,(byte) 0x0,(byte) 0xf,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x67,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x4,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x70,(byte) 0x0, +(byte) 0x60,(byte) 0x0, +}; + +static final BitmapCharRec ch224 = new BitmapCharRec(9,17,-1,0,11,ch224data); + +/* char: 0xdf */ + +static final byte[] ch223data = { +(byte) 0xe7,(byte) 0x0,(byte) 0x6c,(byte) 0x80,(byte) 0x6c,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x61,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x63,(byte) 0x80, +(byte) 0x67,(byte) 0x0,(byte) 0x6c,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x33,(byte) 0x0, +(byte) 0x1e,(byte) 0x0, +}; + +static final BitmapCharRec ch223 = new BitmapCharRec(10,17,-1,0,12,ch223data); + +/* char: 0xde */ + +static final byte[] ch222data = { +(byte) 0xfc,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0x70,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x18, +(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x70,(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0, +(byte) 0xfc,(byte) 0x0, +}; + +static final BitmapCharRec ch222 = new BitmapCharRec(13,17,-1,0,15,ch222data); + +/* char: 0xdd */ + +static final byte[] ch221data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x3,(byte) 0xc0, +(byte) 0x3,(byte) 0x40,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x20,(byte) 0xc,(byte) 0x30,(byte) 0x1c,(byte) 0x10,(byte) 0x18,(byte) 0x18,(byte) 0x38,(byte) 0x8,(byte) 0x30,(byte) 0xc, +(byte) 0xfc,(byte) 0x3f,(byte) 0x0,(byte) 0x0,(byte) 0x1,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0x30, +}; + +static final BitmapCharRec ch221 = new BitmapCharRec(16,22,0,0,16,ch221data); + +/* char: 0xdc */ + +static final byte[] ch220data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x30,(byte) 0x18,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0xfc,(byte) 0x1f,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x6,(byte) 0x30,(byte) 0x6,(byte) 0x30, +}; + +static final BitmapCharRec ch220 = new BitmapCharRec(16,21,-1,0,18,ch220data); + +/* char: 0xdb */ + +static final byte[] ch219data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x30,(byte) 0x18,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0xfc,(byte) 0x1f,(byte) 0x0,(byte) 0x0,(byte) 0x8,(byte) 0x10,(byte) 0x6,(byte) 0x60,(byte) 0x3,(byte) 0xc0,(byte) 0x1,(byte) 0x80, +}; + +static final BitmapCharRec ch219 = new BitmapCharRec(16,22,-1,0,18,ch219data); + +/* char: 0xda */ + +static final byte[] ch218data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x30,(byte) 0x18,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0xfc,(byte) 0x1f,(byte) 0x0,(byte) 0x0,(byte) 0x1,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0x30, +}; + +static final BitmapCharRec ch218 = new BitmapCharRec(16,22,-1,0,18,ch218data); + +/* char: 0xd9 */ + +static final byte[] ch217data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x30,(byte) 0x18,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0xfc,(byte) 0x1f,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x40,(byte) 0x1,(byte) 0x80,(byte) 0x7,(byte) 0x0,(byte) 0x6,(byte) 0x0, +}; + +static final BitmapCharRec ch217 = new BitmapCharRec(16,22,-1,0,18,ch217data); + +/* char: 0xd8 */ + +static final byte[] ch216data = { +(byte) 0x20,(byte) 0x0,(byte) 0x27,(byte) 0xe0,(byte) 0x1c,(byte) 0x38,(byte) 0x38,(byte) 0x1c,(byte) 0x68,(byte) 0x6,(byte) 0x64,(byte) 0x6,(byte) 0xc2,(byte) 0x3,(byte) 0xc2,(byte) 0x3, +(byte) 0xc1,(byte) 0x3,(byte) 0xc1,(byte) 0x3,(byte) 0xc0,(byte) 0x83,(byte) 0xc0,(byte) 0x83,(byte) 0xc0,(byte) 0x43,(byte) 0x60,(byte) 0x46,(byte) 0x60,(byte) 0x26,(byte) 0x38,(byte) 0x1c, +(byte) 0x1c,(byte) 0x38,(byte) 0x7,(byte) 0xe4,(byte) 0x0,(byte) 0x4, +}; + +static final BitmapCharRec ch216 = new BitmapCharRec(16,19,-1,1,18,ch216data); + +/* char: 0xd7 */ + +static final byte[] ch215data = { +(byte) 0x80,(byte) 0x40,(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x33,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x33,(byte) 0x0, +(byte) 0x61,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0x80,(byte) 0x40, +}; + +static final BitmapCharRec ch215 = new BitmapCharRec(10,11,-2,-1,14,ch215data); + +/* char: 0xd6 */ + +static final byte[] ch214data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x38,(byte) 0x38,(byte) 0x1c,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3, +(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x38,(byte) 0x1c,(byte) 0x1c,(byte) 0x38, +(byte) 0x7,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x60, +}; + +static final BitmapCharRec ch214 = new BitmapCharRec(16,21,-1,0,18,ch214data); + +/* char: 0xd5 */ + +static final byte[] ch213data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x38,(byte) 0x38,(byte) 0x1c,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3, +(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x38,(byte) 0x1c,(byte) 0x1c,(byte) 0x38, +(byte) 0x7,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x4,(byte) 0xe0,(byte) 0x3,(byte) 0x90, +}; + +static final BitmapCharRec ch213 = new BitmapCharRec(16,21,-1,0,18,ch213data); + +/* char: 0xd4 */ + +static final byte[] ch212data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x38,(byte) 0x38,(byte) 0x1c,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3, +(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x38,(byte) 0x1c,(byte) 0x1c,(byte) 0x38, +(byte) 0x7,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x8,(byte) 0x10,(byte) 0x6,(byte) 0x60,(byte) 0x3,(byte) 0xc0,(byte) 0x1,(byte) 0x80, +}; + +static final BitmapCharRec ch212 = new BitmapCharRec(16,22,-1,0,18,ch212data); + +/* char: 0xd3 */ + +static final byte[] ch211data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x38,(byte) 0x38,(byte) 0x1c,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3, +(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x38,(byte) 0x1c,(byte) 0x1c,(byte) 0x38, +(byte) 0x7,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x1,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0x30, +}; + +static final BitmapCharRec ch211 = new BitmapCharRec(16,22,-1,0,18,ch211data); + +/* char: 0xd2 */ + +static final byte[] ch210data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x38,(byte) 0x38,(byte) 0x1c,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3, +(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x38,(byte) 0x1c,(byte) 0x1c,(byte) 0x38, +(byte) 0x7,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x40,(byte) 0x1,(byte) 0x80,(byte) 0x7,(byte) 0x0,(byte) 0x6,(byte) 0x0, +}; + +static final BitmapCharRec ch210 = new BitmapCharRec(16,22,-1,0,18,ch210data); + +/* char: 0xd1 */ + +static final byte[] ch209data = { +(byte) 0xf8,(byte) 0xc,(byte) 0x20,(byte) 0x1c,(byte) 0x20,(byte) 0x1c,(byte) 0x20,(byte) 0x34,(byte) 0x20,(byte) 0x64,(byte) 0x20,(byte) 0x64,(byte) 0x20,(byte) 0xc4,(byte) 0x21,(byte) 0x84, +(byte) 0x21,(byte) 0x84,(byte) 0x23,(byte) 0x4,(byte) 0x26,(byte) 0x4,(byte) 0x26,(byte) 0x4,(byte) 0x2c,(byte) 0x4,(byte) 0x38,(byte) 0x4,(byte) 0x38,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0xf0,(byte) 0x1f,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x4,(byte) 0xe0,(byte) 0x3,(byte) 0x90, +}; + +static final BitmapCharRec ch209 = new BitmapCharRec(16,21,-1,0,18,ch209data); + +/* char: 0xd0 */ + +static final byte[] ch208data = { +(byte) 0x7f,(byte) 0xe0,(byte) 0x18,(byte) 0x38,(byte) 0x18,(byte) 0x1c,(byte) 0x18,(byte) 0x6,(byte) 0x18,(byte) 0x6,(byte) 0x18,(byte) 0x3,(byte) 0x18,(byte) 0x3,(byte) 0x18,(byte) 0x3, +(byte) 0xff,(byte) 0x3,(byte) 0x18,(byte) 0x3,(byte) 0x18,(byte) 0x3,(byte) 0x18,(byte) 0x3,(byte) 0x18,(byte) 0x6,(byte) 0x18,(byte) 0x6,(byte) 0x18,(byte) 0x1c,(byte) 0x18,(byte) 0x38, +(byte) 0x7f,(byte) 0xe0, +}; + +static final BitmapCharRec ch208 = new BitmapCharRec(16,17,0,0,17,ch208data); + +/* char: 0xcf */ + +static final byte[] ch207data = { +(byte) 0xfc,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30, +(byte) 0xfc,(byte) 0x0,(byte) 0x0,(byte) 0xcc,(byte) 0xcc, +}; + +static final BitmapCharRec ch207 = new BitmapCharRec(6,21,-1,0,8,ch207data); + +/* char: 0xce */ + +static final byte[] ch206data = { +(byte) 0x7e,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18, +(byte) 0x7e,(byte) 0x0,(byte) 0x81,(byte) 0x66,(byte) 0x3c,(byte) 0x18, +}; + +static final BitmapCharRec ch206 = new BitmapCharRec(8,22,-1,0,8,ch206data); + +/* char: 0xcd */ + +static final byte[] ch205data = { +(byte) 0xfc,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30, +(byte) 0xfc,(byte) 0x0,(byte) 0x40,(byte) 0x30,(byte) 0x1c,(byte) 0xc, +}; + +static final BitmapCharRec ch205 = new BitmapCharRec(6,22,-1,0,8,ch205data); + +/* char: 0xcc */ + +static final byte[] ch204data = { +(byte) 0xfc,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30, +(byte) 0xfc,(byte) 0x0,(byte) 0x8,(byte) 0x30,(byte) 0xe0,(byte) 0xc0, +}; + +static final BitmapCharRec ch204 = new BitmapCharRec(6,22,-1,0,8,ch204data); + +/* char: 0xcb */ + +static final byte[] ch203data = { +(byte) 0xff,(byte) 0xf8,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40, +(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x30, +(byte) 0xff,(byte) 0xf0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80, +}; + +static final BitmapCharRec ch203 = new BitmapCharRec(13,21,-1,0,15,ch203data); + +/* char: 0xca */ + +static final byte[] ch202data = { +(byte) 0xff,(byte) 0xf8,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40, +(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x30, +(byte) 0xff,(byte) 0xf0,(byte) 0x0,(byte) 0x0,(byte) 0x10,(byte) 0x20,(byte) 0xc,(byte) 0xc0,(byte) 0x7,(byte) 0x80,(byte) 0x3,(byte) 0x0, +}; + +static final BitmapCharRec ch202 = new BitmapCharRec(13,22,-1,0,15,ch202data); + +/* char: 0xc9 */ + +static final byte[] ch201data = { +(byte) 0xff,(byte) 0xf8,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40, +(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x30, +(byte) 0xff,(byte) 0xf0,(byte) 0x0,(byte) 0x0,(byte) 0x4,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0xc0, +}; + +static final BitmapCharRec ch201 = new BitmapCharRec(13,22,-1,0,15,ch201data); + +/* char: 0xc8 */ + +static final byte[] ch200data = { +(byte) 0xff,(byte) 0xf8,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40, +(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x30, +(byte) 0xff,(byte) 0xf0,(byte) 0x0,(byte) 0x0,(byte) 0x1,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x1c,(byte) 0x0,(byte) 0x18,(byte) 0x0, +}; + +static final BitmapCharRec ch200 = new BitmapCharRec(13,22,-1,0,15,ch200data); + +/* char: 0xc7 */ + +static final byte[] ch199data = { +(byte) 0x7,(byte) 0x80,(byte) 0xc,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0x0,(byte) 0x1,(byte) 0x0,(byte) 0x7,(byte) 0xe0,(byte) 0x1e,(byte) 0x38, +(byte) 0x38,(byte) 0x8,(byte) 0x60,(byte) 0x4,(byte) 0x60,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x60,(byte) 0x4,(byte) 0x60,(byte) 0x4,(byte) 0x38,(byte) 0xc,(byte) 0x1c,(byte) 0x3c,(byte) 0x7,(byte) 0xe4, +}; + +static final BitmapCharRec ch199 = new BitmapCharRec(14,23,-1,6,16,ch199data); + +/* char: 0xc6 */ + +static final byte[] ch198data = { +(byte) 0xf9,(byte) 0xff,(byte) 0xf0,(byte) 0x30,(byte) 0x60,(byte) 0x30,(byte) 0x10,(byte) 0x60,(byte) 0x10,(byte) 0x10,(byte) 0x60,(byte) 0x10,(byte) 0x18,(byte) 0x60,(byte) 0x0,(byte) 0x8, +(byte) 0x60,(byte) 0x0,(byte) 0xf,(byte) 0xe0,(byte) 0x80,(byte) 0xc,(byte) 0x60,(byte) 0x80,(byte) 0x4,(byte) 0x7f,(byte) 0x80,(byte) 0x4,(byte) 0x60,(byte) 0x80,(byte) 0x6,(byte) 0x60, +(byte) 0x80,(byte) 0x2,(byte) 0x60,(byte) 0x0,(byte) 0x2,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0x60,(byte) 0x20,(byte) 0x1,(byte) 0x60,(byte) 0x20,(byte) 0x1,(byte) 0xe0,(byte) 0x60, +(byte) 0x3,(byte) 0xff,(byte) 0xe0, +}; + +static final BitmapCharRec ch198 = new BitmapCharRec(20,17,0,0,21,ch198data); + +/* char: 0xc5 */ + +static final byte[] ch197data = { +(byte) 0xfc,(byte) 0x1f,(byte) 0x80,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x0,(byte) 0x8, +(byte) 0xc,(byte) 0x0,(byte) 0xf,(byte) 0xf8,(byte) 0x0,(byte) 0xc,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x30,(byte) 0x0,(byte) 0x6,(byte) 0x30, +(byte) 0x0,(byte) 0x2,(byte) 0x30,(byte) 0x0,(byte) 0x2,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0, +(byte) 0x0,(byte) 0x80,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x2,(byte) 0x20,(byte) 0x0,(byte) 0x2,(byte) 0x20,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0, +}; + +static final BitmapCharRec ch197 = new BitmapCharRec(17,21,0,0,17,ch197data); + +/* char: 0xc4 */ + +static final byte[] ch196data = { +(byte) 0xfc,(byte) 0x1f,(byte) 0x80,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x0,(byte) 0x8, +(byte) 0xc,(byte) 0x0,(byte) 0xf,(byte) 0xf8,(byte) 0x0,(byte) 0xc,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x30,(byte) 0x0,(byte) 0x6,(byte) 0x30, +(byte) 0x0,(byte) 0x2,(byte) 0x30,(byte) 0x0,(byte) 0x2,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0, +(byte) 0x0,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x6,(byte) 0x30,(byte) 0x0,(byte) 0x6,(byte) 0x30,(byte) 0x0, +}; + +static final BitmapCharRec ch196 = new BitmapCharRec(17,21,0,0,17,ch196data); + +/* char: 0xc3 */ + +static final byte[] ch195data = { +(byte) 0xfc,(byte) 0x1f,(byte) 0x80,(byte) 0x30,(byte) 0x7,(byte) 0x0,(byte) 0x10,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x0,(byte) 0x8, +(byte) 0xc,(byte) 0x0,(byte) 0xf,(byte) 0xf8,(byte) 0x0,(byte) 0xc,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x30,(byte) 0x0,(byte) 0x6,(byte) 0x30, +(byte) 0x0,(byte) 0x2,(byte) 0x30,(byte) 0x0,(byte) 0x2,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0, +(byte) 0x0,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x4,(byte) 0xe0,(byte) 0x0,(byte) 0x3,(byte) 0x90,(byte) 0x0, +}; + +static final BitmapCharRec ch195 = new BitmapCharRec(17,21,0,0,17,ch195data); + +/* char: 0xc2 */ + +static final byte[] ch194data = { +(byte) 0xfc,(byte) 0x1f,(byte) 0x80,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x0,(byte) 0x8, +(byte) 0xc,(byte) 0x0,(byte) 0xf,(byte) 0xf8,(byte) 0x0,(byte) 0xc,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x30,(byte) 0x0,(byte) 0x6,(byte) 0x30, +(byte) 0x0,(byte) 0x2,(byte) 0x30,(byte) 0x0,(byte) 0x2,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0, +(byte) 0x0,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x8,(byte) 0x10,(byte) 0x0,(byte) 0x6,(byte) 0x60,(byte) 0x0,(byte) 0x3,(byte) 0xc0,(byte) 0x0,(byte) 0x1, +(byte) 0x80,(byte) 0x0, +}; + +static final BitmapCharRec ch194 = new BitmapCharRec(17,22,0,0,17,ch194data); + +/* char: 0xc1 */ + +static final byte[] ch193data = { +(byte) 0xfc,(byte) 0x1f,(byte) 0x80,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x0,(byte) 0x8, +(byte) 0xc,(byte) 0x0,(byte) 0xf,(byte) 0xf8,(byte) 0x0,(byte) 0xc,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x30,(byte) 0x0,(byte) 0x6,(byte) 0x30, +(byte) 0x0,(byte) 0x2,(byte) 0x30,(byte) 0x0,(byte) 0x2,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0, +(byte) 0x0,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x1,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0x0, +(byte) 0x30,(byte) 0x0, +}; + +static final BitmapCharRec ch193 = new BitmapCharRec(17,22,0,0,17,ch193data); + +/* char: 0xc0 */ + +static final byte[] ch192data = { +(byte) 0xfc,(byte) 0x1f,(byte) 0x80,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x0,(byte) 0x8, +(byte) 0xc,(byte) 0x0,(byte) 0xf,(byte) 0xf8,(byte) 0x0,(byte) 0xc,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x30,(byte) 0x0,(byte) 0x6,(byte) 0x30, +(byte) 0x0,(byte) 0x2,(byte) 0x30,(byte) 0x0,(byte) 0x2,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0, +(byte) 0x0,(byte) 0x80,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x20,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x3,(byte) 0x80,(byte) 0x0,(byte) 0x3, +(byte) 0x0,(byte) 0x0, +}; + +static final BitmapCharRec ch192 = new BitmapCharRec(17,22,0,0,17,ch192data); + +/* char: 0xbf */ + +static final byte[] ch191data = { +(byte) 0x3e,(byte) 0x63,(byte) 0xc1,(byte) 0xc3,(byte) 0xc3,(byte) 0xe0,(byte) 0x70,(byte) 0x30,(byte) 0x38,(byte) 0x18,(byte) 0x18,(byte) 0x8,(byte) 0x8,(byte) 0x0,(byte) 0x0,(byte) 0xc, +(byte) 0xc, +}; + +static final BitmapCharRec ch191 = new BitmapCharRec(8,17,-1,5,11,ch191data); + +/* char: 0xbe */ + +static final byte[] ch190data = { +(byte) 0x18,(byte) 0x2,(byte) 0x0,(byte) 0x8,(byte) 0x2,(byte) 0x0,(byte) 0xc,(byte) 0x7f,(byte) 0x80,(byte) 0x4,(byte) 0x22,(byte) 0x0,(byte) 0x6,(byte) 0x32,(byte) 0x0,(byte) 0x3, +(byte) 0x12,(byte) 0x0,(byte) 0x1,(byte) 0xa,(byte) 0x0,(byte) 0x71,(byte) 0x8e,(byte) 0x0,(byte) 0x88,(byte) 0x86,(byte) 0x0,(byte) 0x8c,(byte) 0xc2,(byte) 0x0,(byte) 0xc,(byte) 0x60, +(byte) 0x0,(byte) 0x8,(byte) 0x20,(byte) 0x0,(byte) 0x30,(byte) 0x30,(byte) 0x0,(byte) 0x8,(byte) 0x10,(byte) 0x0,(byte) 0x8c,(byte) 0x18,(byte) 0x0,(byte) 0x4c,(byte) 0xc,(byte) 0x0, +(byte) 0x38,(byte) 0x4,(byte) 0x0, +}; + +static final BitmapCharRec ch190 = new BitmapCharRec(17,17,0,0,18,ch190data); + +/* char: 0xbd */ + +static final byte[] ch189data = { +(byte) 0x30,(byte) 0x7e,(byte) 0x10,(byte) 0x22,(byte) 0x18,(byte) 0x10,(byte) 0x8,(byte) 0x18,(byte) 0xc,(byte) 0x8,(byte) 0x6,(byte) 0x4,(byte) 0x2,(byte) 0x6,(byte) 0xfb,(byte) 0x46, +(byte) 0x21,(byte) 0x26,(byte) 0x21,(byte) 0x9c,(byte) 0x20,(byte) 0xc0,(byte) 0x20,(byte) 0x40,(byte) 0x20,(byte) 0x60,(byte) 0x20,(byte) 0x20,(byte) 0xa0,(byte) 0x30,(byte) 0x60,(byte) 0x18, +(byte) 0x20,(byte) 0x8, +}; + +static final BitmapCharRec ch189 = new BitmapCharRec(15,17,-1,0,18,ch189data); + +/* char: 0xbc */ + +static final byte[] ch188data = { +(byte) 0x30,(byte) 0x4,(byte) 0x10,(byte) 0x4,(byte) 0x18,(byte) 0xff,(byte) 0x8,(byte) 0x44,(byte) 0xc,(byte) 0x64,(byte) 0x6,(byte) 0x24,(byte) 0x2,(byte) 0x14,(byte) 0xfb,(byte) 0x1c, +(byte) 0x21,(byte) 0xc,(byte) 0x21,(byte) 0x84,(byte) 0x20,(byte) 0xc0,(byte) 0x20,(byte) 0x40,(byte) 0x20,(byte) 0x60,(byte) 0x20,(byte) 0x20,(byte) 0xa0,(byte) 0x30,(byte) 0x60,(byte) 0x18, +(byte) 0x20,(byte) 0x8, +}; + +static final BitmapCharRec ch188 = new BitmapCharRec(16,17,-1,0,18,ch188data); + +/* char: 0xbb */ + +static final byte[] ch187data = { +(byte) 0x88,(byte) 0x0,(byte) 0xcc,(byte) 0x0,(byte) 0x66,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x19,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0x33,(byte) 0x0,(byte) 0x66,(byte) 0x0, +(byte) 0xcc,(byte) 0x0,(byte) 0x88,(byte) 0x0, +}; + +static final BitmapCharRec ch187 = new BitmapCharRec(9,10,-2,-1,12,ch187data); + +/* char: 0xba */ + +static final byte[] ch186data = { +(byte) 0xfc,(byte) 0x0,(byte) 0x78,(byte) 0xcc,(byte) 0xcc,(byte) 0xcc,(byte) 0xcc,(byte) 0xcc,(byte) 0x78, +}; + +static final BitmapCharRec ch186 = new BitmapCharRec(6,9,-1,-8,8,ch186data); + +/* char: 0xb9 */ + +static final byte[] ch185data = { +(byte) 0xf8,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0x20,(byte) 0xa0,(byte) 0x60,(byte) 0x20, +}; + +static final BitmapCharRec ch185 = new BitmapCharRec(5,10,-1,-7,7,ch185data); + +/* char: 0xb8 */ + +static final byte[] ch184data = { +(byte) 0x78,(byte) 0xcc,(byte) 0xc,(byte) 0x3c,(byte) 0x30,(byte) 0x10, +}; + +static final BitmapCharRec ch184 = new BitmapCharRec(6,6,-1,6,8,ch184data); + +/* char: 0xb7 */ + +static final byte[] ch183data = { +(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch183 = new BitmapCharRec(2,2,-2,-6,6,ch183data); + +/* char: 0xb6 */ + +static final byte[] ch182data = { +(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0, +(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x9,(byte) 0x0,(byte) 0x19,(byte) 0x0,(byte) 0x39,(byte) 0x0,(byte) 0x79,(byte) 0x0,(byte) 0x79,(byte) 0x0,(byte) 0xf9,(byte) 0x0, +(byte) 0xf9,(byte) 0x0,(byte) 0xf9,(byte) 0x0,(byte) 0x79,(byte) 0x0,(byte) 0x79,(byte) 0x0,(byte) 0x39,(byte) 0x0,(byte) 0x1f,(byte) 0x80, +}; + +static final BitmapCharRec ch182 = new BitmapCharRec(9,22,-1,5,11,ch182data); + +/* char: 0xb5 */ + +static final byte[] ch181data = { +(byte) 0x40,(byte) 0x0,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x40,(byte) 0x0,(byte) 0x40,(byte) 0x0,(byte) 0x5c,(byte) 0xe0,(byte) 0x7e,(byte) 0xc0,(byte) 0x71,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0xe1,(byte) 0xc0, +}; + +static final BitmapCharRec ch181 = new BitmapCharRec(11,17,-1,5,13,ch181data); + +/* char: 0xb4 */ + +static final byte[] ch180data = { +(byte) 0x80,(byte) 0x60,(byte) 0x38,(byte) 0x18, +}; + +static final BitmapCharRec ch180 = new BitmapCharRec(5,4,-2,-13,8,ch180data); + +/* char: 0xb3 */ + +static final byte[] ch179data = { +(byte) 0x70,(byte) 0x88,(byte) 0x8c,(byte) 0xc,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x8c,(byte) 0x4c,(byte) 0x38, +}; + +static final BitmapCharRec ch179 = new BitmapCharRec(6,10,0,-7,7,ch179data); + +/* char: 0xb2 */ + +static final byte[] ch178data = { +(byte) 0xfc,(byte) 0x44,(byte) 0x20,(byte) 0x30,(byte) 0x10,(byte) 0x8,(byte) 0xc,(byte) 0x8c,(byte) 0x4c,(byte) 0x38, +}; + +static final BitmapCharRec ch178 = new BitmapCharRec(6,10,0,-7,7,ch178data); + +/* char: 0xb1 */ + +static final byte[] ch177data = { +(byte) 0xff,(byte) 0xf0,(byte) 0xff,(byte) 0xf0,(byte) 0x0,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0, +(byte) 0xff,(byte) 0xf0,(byte) 0xff,(byte) 0xf0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0, +}; + +static final BitmapCharRec ch177 = new BitmapCharRec(12,15,-1,0,14,ch177data); + +/* char: 0xb0 */ + +static final byte[] ch176data = { +(byte) 0x38,(byte) 0x44,(byte) 0x82,(byte) 0x82,(byte) 0x82,(byte) 0x44,(byte) 0x38, +}; + +static final BitmapCharRec ch176 = new BitmapCharRec(7,7,-1,-10,9,ch176data); + +/* char: 0xaf */ + +static final byte[] ch175data = { +(byte) 0xfc,(byte) 0xfc, +}; + +static final BitmapCharRec ch175 = new BitmapCharRec(6,2,-1,-14,8,ch175data); + +/* char: 0xae */ + +static final byte[] ch174data = { +(byte) 0x7,(byte) 0xf0,(byte) 0x0,(byte) 0x1c,(byte) 0x1c,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x60,(byte) 0x3,(byte) 0x0,(byte) 0x47,(byte) 0x19,(byte) 0x0,(byte) 0xc2, +(byte) 0x31,(byte) 0x80,(byte) 0x82,(byte) 0x20,(byte) 0x80,(byte) 0x82,(byte) 0x40,(byte) 0x80,(byte) 0x83,(byte) 0xe0,(byte) 0x80,(byte) 0x82,(byte) 0x30,(byte) 0x80,(byte) 0x82,(byte) 0x10, +(byte) 0x80,(byte) 0xc2,(byte) 0x11,(byte) 0x80,(byte) 0x42,(byte) 0x31,(byte) 0x0,(byte) 0x67,(byte) 0xe3,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x1c,(byte) 0x1c,(byte) 0x0, +(byte) 0x7,(byte) 0xf0,(byte) 0x0, +}; + +static final BitmapCharRec ch174 = new BitmapCharRec(17,17,-1,0,19,ch174data); + +/* char: 0xad */ + +static final byte[] ch173data = { +(byte) 0xfe,(byte) 0xfe, +}; + +static final BitmapCharRec ch173 = new BitmapCharRec(7,2,-1,-5,9,ch173data); + +/* char: 0xac */ + +static final byte[] ch172data = { +(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0xff,(byte) 0xf0,(byte) 0xff,(byte) 0xf0, +}; + +static final BitmapCharRec ch172 = new BitmapCharRec(12,7,-1,-3,14,ch172data); + +/* char: 0xab */ + +static final byte[] ch171data = { +(byte) 0x8,(byte) 0x80,(byte) 0x19,(byte) 0x80,(byte) 0x33,(byte) 0x0,(byte) 0x66,(byte) 0x0,(byte) 0xcc,(byte) 0x0,(byte) 0xcc,(byte) 0x0,(byte) 0x66,(byte) 0x0,(byte) 0x33,(byte) 0x0, +(byte) 0x19,(byte) 0x80,(byte) 0x8,(byte) 0x80, +}; + +static final BitmapCharRec ch171 = new BitmapCharRec(9,10,-2,-1,13,ch171data); + +/* char: 0xaa */ + +static final byte[] ch170data = { +(byte) 0x7e,(byte) 0x0,(byte) 0x76,(byte) 0xcc,(byte) 0xcc,(byte) 0x7c,(byte) 0xc,(byte) 0xcc,(byte) 0x78, +}; + +static final BitmapCharRec ch170 = new BitmapCharRec(7,9,0,-8,8,ch170data); + +/* char: 0xa9 */ + +static final byte[] ch169data = { +(byte) 0x7,(byte) 0xf0,(byte) 0x0,(byte) 0x1c,(byte) 0x1c,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x61,(byte) 0xc3,(byte) 0x0,(byte) 0x47,(byte) 0x71,(byte) 0x0,(byte) 0xc4, +(byte) 0x19,(byte) 0x80,(byte) 0x8c,(byte) 0x0,(byte) 0x80,(byte) 0x88,(byte) 0x0,(byte) 0x80,(byte) 0x88,(byte) 0x0,(byte) 0x80,(byte) 0x88,(byte) 0x0,(byte) 0x80,(byte) 0x8c,(byte) 0x0, +(byte) 0x80,(byte) 0xc4,(byte) 0x19,(byte) 0x80,(byte) 0x47,(byte) 0x31,(byte) 0x0,(byte) 0x61,(byte) 0xe3,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x1c,(byte) 0x1c,(byte) 0x0, +(byte) 0x7,(byte) 0xf0,(byte) 0x0, +}; + +static final BitmapCharRec ch169 = new BitmapCharRec(17,17,-1,0,19,ch169data); + +/* char: 0xa8 */ + +static final byte[] ch168data = { +(byte) 0xcc,(byte) 0xcc, +}; + +static final BitmapCharRec ch168 = new BitmapCharRec(6,2,-1,-14,8,ch168data); + +/* char: 0xa7 */ + +static final byte[] ch167data = { +(byte) 0x38,(byte) 0x64,(byte) 0x62,(byte) 0x6,(byte) 0xe,(byte) 0x1c,(byte) 0x38,(byte) 0x74,(byte) 0xe2,(byte) 0xc3,(byte) 0x83,(byte) 0x87,(byte) 0x4e,(byte) 0x3c,(byte) 0x38,(byte) 0x70, +(byte) 0x60,(byte) 0x46,(byte) 0x26,(byte) 0x1c, +}; + +static final BitmapCharRec ch167 = new BitmapCharRec(8,20,-2,2,12,ch167data); + +/* char: 0xa6 */ + +static final byte[] ch166data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0, +}; + +static final BitmapCharRec ch166 = new BitmapCharRec(2,17,-2,0,6,ch166data); + +/* char: 0xa5 */ + +static final byte[] ch165data = { +(byte) 0xf,(byte) 0xc0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x1f,(byte) 0xe0,(byte) 0x3,(byte) 0x0,(byte) 0x1f,(byte) 0xe0, +(byte) 0x3,(byte) 0x0,(byte) 0x7,(byte) 0x80,(byte) 0xc,(byte) 0x80,(byte) 0xc,(byte) 0xc0,(byte) 0x18,(byte) 0x40,(byte) 0x18,(byte) 0x60,(byte) 0x30,(byte) 0x20,(byte) 0x70,(byte) 0x30, +(byte) 0xf8,(byte) 0x7c, +}; + +static final BitmapCharRec ch165 = new BitmapCharRec(14,17,0,0,14,ch165data); + +/* char: 0xa4 */ + +static final byte[] ch164data = { +(byte) 0xc0,(byte) 0x60,(byte) 0xee,(byte) 0xe0,(byte) 0x7f,(byte) 0xc0,(byte) 0x31,(byte) 0x80,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x31,(byte) 0x80,(byte) 0x7f,(byte) 0xc0,(byte) 0xee,(byte) 0xe0,(byte) 0xc0,(byte) 0x60, +}; + +static final BitmapCharRec ch164 = new BitmapCharRec(11,12,-1,-3,13,ch164data); + +/* char: 0xa3 */ + +static final byte[] ch163data = { +(byte) 0xe7,(byte) 0x80,(byte) 0xbe,(byte) 0xc0,(byte) 0x78,(byte) 0x40,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0, +(byte) 0x30,(byte) 0x0,(byte) 0xfc,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x31,(byte) 0x80,(byte) 0x19,(byte) 0x80, +(byte) 0xf,(byte) 0x0, +}; + +static final BitmapCharRec ch163 = new BitmapCharRec(10,17,-1,0,12,ch163data); + +/* char: 0xa2 */ + +static final byte[] ch162data = { +(byte) 0x40,(byte) 0x0,(byte) 0x40,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x70,(byte) 0x80,(byte) 0xd0,(byte) 0x0,(byte) 0xc8,(byte) 0x0,(byte) 0xc8,(byte) 0x0, +(byte) 0xc8,(byte) 0x0,(byte) 0xc4,(byte) 0x0,(byte) 0xc4,(byte) 0x0,(byte) 0x43,(byte) 0x80,(byte) 0x63,(byte) 0x80,(byte) 0x1f,(byte) 0x0,(byte) 0x1,(byte) 0x0,(byte) 0x1,(byte) 0x0, +}; + +static final BitmapCharRec ch162 = new BitmapCharRec(9,16,-1,2,12,ch162data); + +/* char: 0xa1 */ + +static final byte[] ch161data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0, +(byte) 0xc0, +}; + +static final BitmapCharRec ch161 = new BitmapCharRec(2,17,-4,5,8,ch161data); + +/* char: 0xa0 */ + +static final BitmapCharRec ch160 = new BitmapCharRec(0,0,0,0,6,null); + +/* char: 0x7e '~' */ + +static final byte[] ch126data = { +(byte) 0x83,(byte) 0x80,(byte) 0xc7,(byte) 0xc0,(byte) 0x7c,(byte) 0x60,(byte) 0x38,(byte) 0x20, +}; + +static final BitmapCharRec ch126 = new BitmapCharRec(11,4,-1,-5,13,ch126data); + +/* char: 0x7d '}' */ + +static final byte[] ch125data = { +(byte) 0xe0,(byte) 0x30,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x8,(byte) 0xc,(byte) 0x4,(byte) 0x3,(byte) 0x4,(byte) 0xc,(byte) 0x8,(byte) 0x18, +(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x30,(byte) 0xe0, +}; + +static final BitmapCharRec ch125 = new BitmapCharRec(8,22,-1,5,10,ch125data); + +/* char: 0x7c '|' */ + +static final byte[] ch124data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0, +}; + +static final BitmapCharRec ch124 = new BitmapCharRec(2,17,-2,0,6,ch124data); + +/* char: 0x7b '{' */ + +static final byte[] ch123data = { +(byte) 0x7,(byte) 0xc,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x10,(byte) 0x30,(byte) 0x20,(byte) 0xc0,(byte) 0x20,(byte) 0x30,(byte) 0x10,(byte) 0x18, +(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0xc,(byte) 0x7, +}; + +static final BitmapCharRec ch123 = new BitmapCharRec(8,22,-1,5,10,ch123data); + +/* char: 0x7a 'z' */ + +static final byte[] ch122data = { +(byte) 0xff,(byte) 0xc3,(byte) 0x61,(byte) 0x70,(byte) 0x30,(byte) 0x38,(byte) 0x18,(byte) 0x1c,(byte) 0xe,(byte) 0x86,(byte) 0xc3,(byte) 0xff, +}; + +static final BitmapCharRec ch122 = new BitmapCharRec(8,12,-1,0,10,ch122data); + +/* char: 0x79 'y' */ + +static final byte[] ch121data = { +(byte) 0xe0,(byte) 0x0,(byte) 0xf0,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x8,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x4,(byte) 0x0,(byte) 0xe,(byte) 0x0,(byte) 0xe,(byte) 0x0, +(byte) 0x1a,(byte) 0x0,(byte) 0x19,(byte) 0x0,(byte) 0x19,(byte) 0x0,(byte) 0x31,(byte) 0x0,(byte) 0x30,(byte) 0x80,(byte) 0x30,(byte) 0x80,(byte) 0x60,(byte) 0x80,(byte) 0x60,(byte) 0xc0, +(byte) 0xf1,(byte) 0xe0, +}; + +static final BitmapCharRec ch121 = new BitmapCharRec(11,17,0,5,11,ch121data); + +/* char: 0x78 'x' */ + +static final byte[] ch120data = { +(byte) 0xf1,(byte) 0xe0,(byte) 0x60,(byte) 0xc0,(byte) 0x21,(byte) 0x80,(byte) 0x33,(byte) 0x80,(byte) 0x1b,(byte) 0x0,(byte) 0xe,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x1a,(byte) 0x0, +(byte) 0x39,(byte) 0x0,(byte) 0x31,(byte) 0x80,(byte) 0x60,(byte) 0xc0,(byte) 0xf1,(byte) 0xe0, +}; + +static final BitmapCharRec ch120 = new BitmapCharRec(11,12,-1,0,13,ch120data); + +/* char: 0x77 'w' */ + +static final byte[] ch119data = { +(byte) 0x4,(byte) 0x10,(byte) 0x0,(byte) 0xe,(byte) 0x38,(byte) 0x0,(byte) 0xe,(byte) 0x38,(byte) 0x0,(byte) 0x1a,(byte) 0x28,(byte) 0x0,(byte) 0x1a,(byte) 0x64,(byte) 0x0,(byte) 0x19, +(byte) 0x64,(byte) 0x0,(byte) 0x31,(byte) 0x64,(byte) 0x0,(byte) 0x30,(byte) 0xc2,(byte) 0x0,(byte) 0x30,(byte) 0xc2,(byte) 0x0,(byte) 0x60,(byte) 0xc2,(byte) 0x0,(byte) 0x60,(byte) 0xc3, +(byte) 0x0,(byte) 0xf1,(byte) 0xe7,(byte) 0x80, +}; + +static final BitmapCharRec ch119 = new BitmapCharRec(17,12,0,0,17,ch119data); + +/* char: 0x76 'v' */ + +static final byte[] ch118data = { +(byte) 0x4,(byte) 0x0,(byte) 0xe,(byte) 0x0,(byte) 0xe,(byte) 0x0,(byte) 0x1a,(byte) 0x0,(byte) 0x19,(byte) 0x0,(byte) 0x19,(byte) 0x0,(byte) 0x31,(byte) 0x0,(byte) 0x30,(byte) 0x80, +(byte) 0x30,(byte) 0x80,(byte) 0x60,(byte) 0x80,(byte) 0x60,(byte) 0xc0,(byte) 0xf1,(byte) 0xe0, +}; + +static final BitmapCharRec ch118 = new BitmapCharRec(11,12,0,0,11,ch118data); + +/* char: 0x75 'u' */ + +static final byte[] ch117data = { +(byte) 0x1c,(byte) 0xe0,(byte) 0x3e,(byte) 0xc0,(byte) 0x71,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0xe1,(byte) 0xc0, +}; + +static final BitmapCharRec ch117 = new BitmapCharRec(11,12,-1,0,13,ch117data); + +/* char: 0x74 't' */ + +static final byte[] ch116data = { +(byte) 0x1c,(byte) 0x32,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0xfe,(byte) 0x70,(byte) 0x30,(byte) 0x10, +}; + +static final BitmapCharRec ch116 = new BitmapCharRec(7,15,0,0,7,ch116data); + +/* char: 0x73 's' */ + +static final byte[] ch115data = { +(byte) 0xf8,(byte) 0xc6,(byte) 0x83,(byte) 0x3,(byte) 0x7,(byte) 0x1e,(byte) 0x7c,(byte) 0x70,(byte) 0xe0,(byte) 0xc2,(byte) 0x66,(byte) 0x3e, +}; + +static final BitmapCharRec ch115 = new BitmapCharRec(8,12,-1,0,10,ch115data); + +/* char: 0x72 'r' */ + +static final byte[] ch114data = { +(byte) 0xf0,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x76,(byte) 0x6e,(byte) 0xe6, +}; + +static final BitmapCharRec ch114 = new BitmapCharRec(7,12,-1,0,8,ch114data); + +/* char: 0x71 'q' */ + +static final byte[] ch113data = { +(byte) 0x3,(byte) 0xc0,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1d,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80, +(byte) 0x1d,(byte) 0x80, +}; + +static final BitmapCharRec ch113 = new BitmapCharRec(10,17,-1,5,12,ch113data); + +/* char: 0x70 'p' */ + +static final byte[] ch112data = { +(byte) 0xf0,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x6e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80, +(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80, +(byte) 0xee,(byte) 0x0, +}; + +static final BitmapCharRec ch112 = new BitmapCharRec(10,17,-1,5,12,ch112data); + +/* char: 0x6f 'o' */ + +static final byte[] ch111data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x1e,(byte) 0x0, +}; + +static final BitmapCharRec ch111 = new BitmapCharRec(10,12,-1,0,12,ch111data); + +/* char: 0x6e 'n' */ + +static final byte[] ch110data = { +(byte) 0xf1,(byte) 0xe0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x71,(byte) 0xc0,(byte) 0x6f,(byte) 0x80,(byte) 0xe7,(byte) 0x0, +}; + +static final BitmapCharRec ch110 = new BitmapCharRec(11,12,-1,0,13,ch110data); + +/* char: 0x6d 'm' */ + +static final byte[] ch109data = { +(byte) 0xf1,(byte) 0xe3,(byte) 0xc0,(byte) 0x60,(byte) 0xc1,(byte) 0x80,(byte) 0x60,(byte) 0xc1,(byte) 0x80,(byte) 0x60,(byte) 0xc1,(byte) 0x80,(byte) 0x60,(byte) 0xc1,(byte) 0x80,(byte) 0x60, +(byte) 0xc1,(byte) 0x80,(byte) 0x60,(byte) 0xc1,(byte) 0x80,(byte) 0x60,(byte) 0xc1,(byte) 0x80,(byte) 0x60,(byte) 0xc1,(byte) 0x80,(byte) 0x71,(byte) 0xe3,(byte) 0x80,(byte) 0x6f,(byte) 0x9f, +(byte) 0x0,(byte) 0xe7,(byte) 0xe,(byte) 0x0, +}; + +static final BitmapCharRec ch109 = new BitmapCharRec(18,12,-1,0,20,ch109data); + +/* char: 0x6c 'l' */ + +static final byte[] ch108data = { +(byte) 0xf0,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60, +(byte) 0xe0, +}; + +static final BitmapCharRec ch108 = new BitmapCharRec(4,17,-1,0,6,ch108data); + +/* char: 0x6b 'k' */ + +static final byte[] ch107data = { +(byte) 0xf3,(byte) 0xe0,(byte) 0x61,(byte) 0xc0,(byte) 0x63,(byte) 0x80,(byte) 0x67,(byte) 0x0,(byte) 0x6e,(byte) 0x0,(byte) 0x6c,(byte) 0x0,(byte) 0x78,(byte) 0x0,(byte) 0x68,(byte) 0x0, +(byte) 0x64,(byte) 0x0,(byte) 0x66,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x67,(byte) 0xc0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0, +(byte) 0xe0,(byte) 0x0, +}; + +static final BitmapCharRec ch107 = new BitmapCharRec(11,17,-1,0,12,ch107data); + +/* char: 0x6a 'j' */ + +static final byte[] ch106data = { +(byte) 0xc0,(byte) 0xe0,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30, +(byte) 0x70,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x30,(byte) 0x30, +}; + +static final BitmapCharRec ch106 = new BitmapCharRec(4,22,0,5,6,ch106data); + +/* char: 0x69 'i' */ + +static final byte[] ch105data = { +(byte) 0xf0,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0x60,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x60, +(byte) 0x60, +}; + +static final BitmapCharRec ch105 = new BitmapCharRec(4,17,-1,0,6,ch105data); + +/* char: 0x68 'h' */ + +static final byte[] ch104data = { +(byte) 0xf1,(byte) 0xe0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x71,(byte) 0xc0,(byte) 0x6f,(byte) 0x80,(byte) 0x67,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0, +(byte) 0xe0,(byte) 0x0, +}; + +static final BitmapCharRec ch104 = new BitmapCharRec(11,17,-1,0,13,ch104data); + +/* char: 0x67 'g' */ + +static final byte[] ch103data = { +(byte) 0x3f,(byte) 0x0,(byte) 0xf1,(byte) 0xc0,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x20,(byte) 0x60,(byte) 0x60,(byte) 0x3f,(byte) 0xc0,(byte) 0x7f,(byte) 0x0,(byte) 0x60,(byte) 0x0, +(byte) 0x30,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x33,(byte) 0x0, +(byte) 0x1f,(byte) 0xc0, +}; + +static final BitmapCharRec ch103 = new BitmapCharRec(11,17,-1,5,12,ch103data); + +/* char: 0x66 'f' */ + +static final byte[] ch102data = { +(byte) 0x78,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0xfe,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x16, +(byte) 0xe, +}; + +static final BitmapCharRec ch102 = new BitmapCharRec(7,17,0,0,7,ch102data); + +/* char: 0x65 'e' */ + +static final byte[] ch101data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x70,(byte) 0x80,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xff,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0x41,(byte) 0x80,(byte) 0x63,(byte) 0x0,(byte) 0x1e,(byte) 0x0, +}; + +static final BitmapCharRec ch101 = new BitmapCharRec(9,12,-1,0,11,ch101data); + +/* char: 0x64 'd' */ + +static final byte[] ch100data = { +(byte) 0x1e,(byte) 0xc0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0xc1,(byte) 0x80, +(byte) 0xc1,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x1d,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80, +(byte) 0x3,(byte) 0x80, +}; + +static final BitmapCharRec ch100 = new BitmapCharRec(10,17,-1,0,12,ch100data); + +/* char: 0x63 'c' */ + +static final byte[] ch99data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x7f,(byte) 0x0,(byte) 0x70,(byte) 0x80,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0x41,(byte) 0x80,(byte) 0x63,(byte) 0x80,(byte) 0x1f,(byte) 0x0, +}; + +static final BitmapCharRec ch99 = new BitmapCharRec(9,12,-1,0,11,ch99data); + +/* char: 0x62 'b' */ + +static final byte[] ch98data = { +(byte) 0x5e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0,(byte) 0x60,(byte) 0xc0, +(byte) 0x60,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x73,(byte) 0x80,(byte) 0x6e,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0, +(byte) 0xe0,(byte) 0x0, +}; + +static final BitmapCharRec ch98 = new BitmapCharRec(10,17,-1,0,12,ch98data); + +/* char: 0x61 'a' */ + +static final byte[] ch97data = { +(byte) 0x71,(byte) 0x80,(byte) 0xfb,(byte) 0x0,(byte) 0xc7,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x3b,(byte) 0x0,(byte) 0xf,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x67,(byte) 0x0,(byte) 0x3e,(byte) 0x0, +}; + +static final BitmapCharRec ch97 = new BitmapCharRec(9,12,-1,0,11,ch97data); + +/* char: 0x60 '`' */ + +static final byte[] ch96data = { +(byte) 0x60,(byte) 0xe0,(byte) 0x80,(byte) 0xc0,(byte) 0x60, +}; + +static final BitmapCharRec ch96 = new BitmapCharRec(3,5,-2,-12,7,ch96data); + +/* char: 0x5f '_' */ + +static final byte[] ch95data = { +(byte) 0xff,(byte) 0xf8,(byte) 0xff,(byte) 0xf8, +}; + +static final BitmapCharRec ch95 = new BitmapCharRec(13,2,0,5,13,ch95data); + +/* char: 0x5e '^' */ + +static final byte[] ch94data = { +(byte) 0x80,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x41,(byte) 0x0,(byte) 0x63,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x36,(byte) 0x0,(byte) 0x14,(byte) 0x0,(byte) 0x1c,(byte) 0x0, +(byte) 0x8,(byte) 0x0, +}; + +static final BitmapCharRec ch94 = new BitmapCharRec(9,9,-1,-8,11,ch94data); + +/* char: 0x5d ']' */ + +static final byte[] ch93data = { +(byte) 0xf8,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18, +(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0xf8, +}; + +static final BitmapCharRec ch93 = new BitmapCharRec(5,21,-1,4,8,ch93data); + +/* char: 0x5c '\' */ + +static final byte[] ch92data = { +(byte) 0x6,(byte) 0x6,(byte) 0x4,(byte) 0xc,(byte) 0xc,(byte) 0x8,(byte) 0x18,(byte) 0x18,(byte) 0x10,(byte) 0x30,(byte) 0x30,(byte) 0x20,(byte) 0x60,(byte) 0x60,(byte) 0x40,(byte) 0xc0, +(byte) 0xc0, +}; + +static final BitmapCharRec ch92 = new BitmapCharRec(7,17,0,0,7,ch92data); + +/* char: 0x5b '[' */ + +static final byte[] ch91data = { +(byte) 0xf8,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xf8, +}; + +static final BitmapCharRec ch91 = new BitmapCharRec(5,21,-2,4,8,ch91data); + +/* char: 0x5a 'Z' */ + +static final byte[] ch90data = { +(byte) 0xff,(byte) 0xf8,(byte) 0xe0,(byte) 0x18,(byte) 0x70,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x38,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x1c,(byte) 0x0,(byte) 0xe,(byte) 0x0, +(byte) 0x6,(byte) 0x0,(byte) 0x7,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x80,(byte) 0x1,(byte) 0xc0,(byte) 0x80,(byte) 0xc0,(byte) 0x80,(byte) 0xe0,(byte) 0xc0,(byte) 0x70, +(byte) 0xff,(byte) 0xf0, +}; + +static final BitmapCharRec ch90 = new BitmapCharRec(13,17,-1,0,15,ch90data); + +/* char: 0x59 'Y' */ + +static final byte[] ch89data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x3,(byte) 0xc0, +(byte) 0x3,(byte) 0x40,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x20,(byte) 0xc,(byte) 0x30,(byte) 0x1c,(byte) 0x10,(byte) 0x18,(byte) 0x18,(byte) 0x38,(byte) 0x8,(byte) 0x30,(byte) 0xc, +(byte) 0xfc,(byte) 0x3f, +}; + +static final BitmapCharRec ch89 = new BitmapCharRec(16,17,0,0,16,ch89data); + +/* char: 0x58 'X' */ + +static final byte[] ch88data = { +(byte) 0xfc,(byte) 0xf,(byte) 0xc0,(byte) 0x30,(byte) 0x3,(byte) 0x80,(byte) 0x18,(byte) 0x7,(byte) 0x0,(byte) 0x8,(byte) 0xe,(byte) 0x0,(byte) 0x4,(byte) 0xc,(byte) 0x0,(byte) 0x6, +(byte) 0x18,(byte) 0x0,(byte) 0x2,(byte) 0x38,(byte) 0x0,(byte) 0x1,(byte) 0x70,(byte) 0x0,(byte) 0x0,(byte) 0xe0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x1,(byte) 0xc0, +(byte) 0x0,(byte) 0x3,(byte) 0xa0,(byte) 0x0,(byte) 0x3,(byte) 0x10,(byte) 0x0,(byte) 0x6,(byte) 0x8,(byte) 0x0,(byte) 0xe,(byte) 0xc,(byte) 0x0,(byte) 0x1c,(byte) 0x6,(byte) 0x0, +(byte) 0x7e,(byte) 0xf,(byte) 0x80, +}; + +static final BitmapCharRec ch88 = new BitmapCharRec(18,17,0,0,18,ch88data); + +/* char: 0x57 'W' */ + +static final byte[] ch87data = { +(byte) 0x1,(byte) 0x83,(byte) 0x0,(byte) 0x1,(byte) 0x83,(byte) 0x0,(byte) 0x1,(byte) 0x83,(byte) 0x80,(byte) 0x3,(byte) 0x87,(byte) 0x80,(byte) 0x3,(byte) 0x46,(byte) 0x80,(byte) 0x3, +(byte) 0x46,(byte) 0xc0,(byte) 0x6,(byte) 0x46,(byte) 0x40,(byte) 0x6,(byte) 0x4c,(byte) 0x40,(byte) 0x6,(byte) 0x4c,(byte) 0x60,(byte) 0xc,(byte) 0x2c,(byte) 0x60,(byte) 0xc,(byte) 0x2c, +(byte) 0x20,(byte) 0x18,(byte) 0x2c,(byte) 0x20,(byte) 0x18,(byte) 0x18,(byte) 0x30,(byte) 0x18,(byte) 0x18,(byte) 0x10,(byte) 0x30,(byte) 0x18,(byte) 0x10,(byte) 0x30,(byte) 0x18,(byte) 0x18, +(byte) 0xfc,(byte) 0x7e,(byte) 0x7e, +}; + +static final BitmapCharRec ch87 = new BitmapCharRec(23,17,0,0,23,ch87data); + +/* char: 0x56 'V' */ + +static final byte[] ch86data = { +(byte) 0x1,(byte) 0x80,(byte) 0x0,(byte) 0x1,(byte) 0x80,(byte) 0x0,(byte) 0x1,(byte) 0x80,(byte) 0x0,(byte) 0x3,(byte) 0xc0,(byte) 0x0,(byte) 0x3,(byte) 0x40,(byte) 0x0,(byte) 0x3, +(byte) 0x60,(byte) 0x0,(byte) 0x6,(byte) 0x20,(byte) 0x0,(byte) 0x6,(byte) 0x20,(byte) 0x0,(byte) 0x6,(byte) 0x30,(byte) 0x0,(byte) 0xc,(byte) 0x10,(byte) 0x0,(byte) 0xc,(byte) 0x18, +(byte) 0x0,(byte) 0x18,(byte) 0x8,(byte) 0x0,(byte) 0x18,(byte) 0x8,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x0,(byte) 0x30,(byte) 0x4,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0, +(byte) 0xfc,(byte) 0x1f,(byte) 0x80, +}; + +static final BitmapCharRec ch86 = new BitmapCharRec(17,17,0,0,17,ch86data); + +/* char: 0x55 'U' */ + +static final byte[] ch85data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x30,(byte) 0x18,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0xfc,(byte) 0x1f, +}; + +static final BitmapCharRec ch85 = new BitmapCharRec(16,17,-1,0,18,ch85data); + +/* char: 0x54 'T' */ + +static final byte[] ch84data = { +(byte) 0xf,(byte) 0xc0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x83,(byte) 0x4,(byte) 0x83,(byte) 0x4,(byte) 0xc3,(byte) 0xc, +(byte) 0xff,(byte) 0xfc, +}; + +static final BitmapCharRec ch84 = new BitmapCharRec(14,17,-1,0,16,ch84data); + +/* char: 0x53 'S' */ + +static final byte[] ch83data = { +(byte) 0x9e,(byte) 0x0,(byte) 0xf1,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0x80,(byte) 0x60,(byte) 0x80,(byte) 0x60,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0xe0,(byte) 0x3,(byte) 0xc0, +(byte) 0xf,(byte) 0x80,(byte) 0x1e,(byte) 0x0,(byte) 0x78,(byte) 0x0,(byte) 0xe0,(byte) 0x0,(byte) 0xc0,(byte) 0x40,(byte) 0xc0,(byte) 0x40,(byte) 0xc0,(byte) 0xc0,(byte) 0x63,(byte) 0xc0, +(byte) 0x1e,(byte) 0x40, +}; + +static final BitmapCharRec ch83 = new BitmapCharRec(11,17,-1,0,13,ch83data); + +/* char: 0x52 'R' */ + +static final byte[] ch82data = { +(byte) 0xfc,(byte) 0x1e,(byte) 0x30,(byte) 0x1c,(byte) 0x30,(byte) 0x38,(byte) 0x30,(byte) 0x70,(byte) 0x30,(byte) 0x60,(byte) 0x30,(byte) 0xc0,(byte) 0x31,(byte) 0xc0,(byte) 0x33,(byte) 0x80, +(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0x70,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x38,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x38,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x70, +(byte) 0xff,(byte) 0xc0, +}; + +static final BitmapCharRec ch82 = new BitmapCharRec(15,17,-1,0,16,ch82data); + +/* char: 0x51 'Q' */ + +static final byte[] ch81data = { +(byte) 0x0,(byte) 0xf,(byte) 0x0,(byte) 0x38,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0xe0,(byte) 0x1,(byte) 0xc0,(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x38,(byte) 0x38,(byte) 0x1c, +(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3, +(byte) 0xc0,(byte) 0x3,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x38,(byte) 0x1c,(byte) 0x1c,(byte) 0x38,(byte) 0x7,(byte) 0xe0, +}; + +static final BitmapCharRec ch81 = new BitmapCharRec(16,22,-1,5,18,ch81data); + +/* char: 0x50 'P' */ + +static final byte[] ch80data = { +(byte) 0xfc,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0, +(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0x70,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x70, +(byte) 0xff,(byte) 0xc0, +}; + +static final BitmapCharRec ch80 = new BitmapCharRec(13,17,-1,0,15,ch80data); + +/* char: 0x4f 'O' */ + +static final byte[] ch79data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1c,(byte) 0x38,(byte) 0x38,(byte) 0x1c,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3, +(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0xc0,(byte) 0x3,(byte) 0x60,(byte) 0x6,(byte) 0x60,(byte) 0x6,(byte) 0x38,(byte) 0x1c,(byte) 0x1c,(byte) 0x38, +(byte) 0x7,(byte) 0xe0, +}; + +static final BitmapCharRec ch79 = new BitmapCharRec(16,17,-1,0,18,ch79data); + +/* char: 0x4e 'N' */ + +static final byte[] ch78data = { +(byte) 0xf8,(byte) 0xc,(byte) 0x20,(byte) 0x1c,(byte) 0x20,(byte) 0x1c,(byte) 0x20,(byte) 0x34,(byte) 0x20,(byte) 0x64,(byte) 0x20,(byte) 0x64,(byte) 0x20,(byte) 0xc4,(byte) 0x21,(byte) 0x84, +(byte) 0x21,(byte) 0x84,(byte) 0x23,(byte) 0x4,(byte) 0x26,(byte) 0x4,(byte) 0x26,(byte) 0x4,(byte) 0x2c,(byte) 0x4,(byte) 0x38,(byte) 0x4,(byte) 0x38,(byte) 0x4,(byte) 0x30,(byte) 0x4, +(byte) 0xf0,(byte) 0x1f, +}; + +static final BitmapCharRec ch78 = new BitmapCharRec(16,17,-1,0,18,ch78data); + +/* char: 0x4d 'M' */ + +static final byte[] ch77data = { +(byte) 0xf8,(byte) 0x21,(byte) 0xf8,(byte) 0x20,(byte) 0x60,(byte) 0x60,(byte) 0x20,(byte) 0x60,(byte) 0x60,(byte) 0x20,(byte) 0xd0,(byte) 0x60,(byte) 0x20,(byte) 0xd0,(byte) 0x60,(byte) 0x21, +(byte) 0x88,(byte) 0x60,(byte) 0x21,(byte) 0x88,(byte) 0x60,(byte) 0x23,(byte) 0x8,(byte) 0x60,(byte) 0x23,(byte) 0x4,(byte) 0x60,(byte) 0x26,(byte) 0x4,(byte) 0x60,(byte) 0x26,(byte) 0x2, +(byte) 0x60,(byte) 0x2c,(byte) 0x2,(byte) 0x60,(byte) 0x2c,(byte) 0x2,(byte) 0x60,(byte) 0x38,(byte) 0x1,(byte) 0x60,(byte) 0x38,(byte) 0x1,(byte) 0x60,(byte) 0x30,(byte) 0x0,(byte) 0xe0, +(byte) 0xf0,(byte) 0x0,(byte) 0xf8, +}; + +static final BitmapCharRec ch77 = new BitmapCharRec(21,17,-1,0,22,ch77data); + +/* char: 0x4c 'L' */ + +static final byte[] ch76data = { +(byte) 0xff,(byte) 0xf8,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0, +(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0, +(byte) 0xfc,(byte) 0x0, +}; + +static final BitmapCharRec ch76 = new BitmapCharRec(13,17,-1,0,14,ch76data); + +/* char: 0x4b 'K' */ + +static final byte[] ch75data = { +(byte) 0xfc,(byte) 0x1f,(byte) 0x30,(byte) 0xe,(byte) 0x30,(byte) 0x1c,(byte) 0x30,(byte) 0x38,(byte) 0x30,(byte) 0x70,(byte) 0x30,(byte) 0xe0,(byte) 0x31,(byte) 0xc0,(byte) 0x33,(byte) 0x80, +(byte) 0x3f,(byte) 0x0,(byte) 0x3e,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x31,(byte) 0x80,(byte) 0x30,(byte) 0xc0,(byte) 0x30,(byte) 0x60,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x18, +(byte) 0xfc,(byte) 0x7e, +}; + +static final BitmapCharRec ch75 = new BitmapCharRec(16,17,-1,0,17,ch75data); + +/* char: 0x4a 'J' */ + +static final byte[] ch74data = { +(byte) 0x78,(byte) 0x0,(byte) 0xcc,(byte) 0x0,(byte) 0xc6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0, +(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0, +(byte) 0x1f,(byte) 0x80, +}; + +static final BitmapCharRec ch74 = new BitmapCharRec(9,17,-1,0,11,ch74data); + +/* char: 0x49 'I' */ + +static final byte[] ch73data = { +(byte) 0xfc,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x30, +(byte) 0xfc, +}; + +static final BitmapCharRec ch73 = new BitmapCharRec(6,17,-1,0,8,ch73data); + +/* char: 0x48 'H' */ + +static final byte[] ch72data = { +(byte) 0xfc,(byte) 0x1f,(byte) 0x80,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30, +(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x3f,(byte) 0xfe,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6, +(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x30,(byte) 0x6,(byte) 0x0, +(byte) 0xfc,(byte) 0x1f,(byte) 0x80, +}; + +static final BitmapCharRec ch72 = new BitmapCharRec(17,17,-1,0,19,ch72data); + +/* char: 0x47 'G' */ + +static final byte[] ch71data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1e,(byte) 0x38,(byte) 0x38,(byte) 0x1c,(byte) 0x60,(byte) 0xc,(byte) 0x60,(byte) 0xc,(byte) 0xc0,(byte) 0xc,(byte) 0xc0,(byte) 0xc,(byte) 0xc0,(byte) 0x3f, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x60,(byte) 0x4,(byte) 0x60,(byte) 0x4,(byte) 0x38,(byte) 0xc,(byte) 0x1c,(byte) 0x3c, +(byte) 0x7,(byte) 0xe4, +}; + +static final BitmapCharRec ch71 = new BitmapCharRec(16,17,-1,0,18,ch71data); + +/* char: 0x46 'F' */ + +static final byte[] ch70data = { +(byte) 0xfc,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x20,(byte) 0x30,(byte) 0x20, +(byte) 0x3f,(byte) 0xe0,(byte) 0x30,(byte) 0x20,(byte) 0x30,(byte) 0x20,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x30, +(byte) 0xff,(byte) 0xf0, +}; + +static final BitmapCharRec ch70 = new BitmapCharRec(12,17,-1,0,14,ch70data); + +/* char: 0x45 'E' */ + +static final byte[] ch69data = { +(byte) 0xff,(byte) 0xf8,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x8,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40, +(byte) 0x3f,(byte) 0xc0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x10,(byte) 0x30,(byte) 0x30, +(byte) 0xff,(byte) 0xf0, +}; + +static final BitmapCharRec ch69 = new BitmapCharRec(13,17,-1,0,15,ch69data); + +/* char: 0x44 'D' */ + +static final byte[] ch68data = { +(byte) 0xff,(byte) 0xc0,(byte) 0x30,(byte) 0x70,(byte) 0x30,(byte) 0x38,(byte) 0x30,(byte) 0xc,(byte) 0x30,(byte) 0xc,(byte) 0x30,(byte) 0x6,(byte) 0x30,(byte) 0x6,(byte) 0x30,(byte) 0x6, +(byte) 0x30,(byte) 0x6,(byte) 0x30,(byte) 0x6,(byte) 0x30,(byte) 0x6,(byte) 0x30,(byte) 0x6,(byte) 0x30,(byte) 0xc,(byte) 0x30,(byte) 0xc,(byte) 0x30,(byte) 0x38,(byte) 0x30,(byte) 0x70, +(byte) 0xff,(byte) 0xc0, +}; + +static final BitmapCharRec ch68 = new BitmapCharRec(15,17,-1,0,17,ch68data); + +/* char: 0x43 'C' */ + +static final byte[] ch67data = { +(byte) 0x7,(byte) 0xe0,(byte) 0x1e,(byte) 0x38,(byte) 0x38,(byte) 0x8,(byte) 0x60,(byte) 0x4,(byte) 0x60,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0, +(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x60,(byte) 0x4,(byte) 0x60,(byte) 0x4,(byte) 0x38,(byte) 0xc,(byte) 0x1c,(byte) 0x3c, +(byte) 0x7,(byte) 0xe4, +}; + +static final BitmapCharRec ch67 = new BitmapCharRec(14,17,-1,0,16,ch67data); + +/* char: 0x42 'B' */ + +static final byte[] ch66data = { +(byte) 0xff,(byte) 0xe0,(byte) 0x30,(byte) 0x78,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0xc,(byte) 0x30,(byte) 0xc,(byte) 0x30,(byte) 0xc,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x38, +(byte) 0x3f,(byte) 0xe0,(byte) 0x30,(byte) 0x40,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x18,(byte) 0x30,(byte) 0x30,(byte) 0x30,(byte) 0x70, +(byte) 0xff,(byte) 0xc0, +}; + +static final BitmapCharRec ch66 = new BitmapCharRec(14,17,-1,0,16,ch66data); + +/* char: 0x41 'A' */ + +static final byte[] ch65data = { +(byte) 0xfc,(byte) 0x1f,(byte) 0x80,(byte) 0x30,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0x6,(byte) 0x0,(byte) 0x10,(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0xc,(byte) 0x0,(byte) 0x8, +(byte) 0xc,(byte) 0x0,(byte) 0xf,(byte) 0xf8,(byte) 0x0,(byte) 0xc,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x18,(byte) 0x0,(byte) 0x4,(byte) 0x30,(byte) 0x0,(byte) 0x6,(byte) 0x30, +(byte) 0x0,(byte) 0x2,(byte) 0x30,(byte) 0x0,(byte) 0x2,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0x60,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0, +(byte) 0x0,(byte) 0x80,(byte) 0x0, +}; + +static final BitmapCharRec ch65 = new BitmapCharRec(17,17,0,0,17,ch65data); + +/* char: 0x40 '@' */ + +static final byte[] ch64data = { +(byte) 0x3,(byte) 0xf0,(byte) 0x0,(byte) 0xe,(byte) 0xc,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x0,(byte) 0x61,(byte) 0xde,(byte) 0x0,(byte) 0x63, +(byte) 0x7b,(byte) 0x0,(byte) 0xc6,(byte) 0x39,(byte) 0x80,(byte) 0xc6,(byte) 0x18,(byte) 0x80,(byte) 0xc6,(byte) 0x18,(byte) 0xc0,(byte) 0xc6,(byte) 0x18,(byte) 0x40,(byte) 0xc6,(byte) 0xc, +(byte) 0x40,(byte) 0xc3,(byte) 0xc,(byte) 0x40,(byte) 0xc3,(byte) 0x8c,(byte) 0x40,(byte) 0xe1,(byte) 0xfc,(byte) 0x40,(byte) 0x60,(byte) 0xec,(byte) 0xc0,(byte) 0x70,(byte) 0x0,(byte) 0x80, +(byte) 0x38,(byte) 0x1,(byte) 0x80,(byte) 0x1c,(byte) 0x3,(byte) 0x0,(byte) 0xf,(byte) 0xe,(byte) 0x0,(byte) 0x3,(byte) 0xf8,(byte) 0x0, +}; + +static final BitmapCharRec ch64 = new BitmapCharRec(18,20,-2,3,22,ch64data); + +/* char: 0x3f '?' */ + +static final byte[] ch63data = { +(byte) 0x30,(byte) 0x30,(byte) 0x0,(byte) 0x0,(byte) 0x10,(byte) 0x10,(byte) 0x10,(byte) 0x18,(byte) 0x18,(byte) 0xc,(byte) 0xe,(byte) 0x7,(byte) 0xc3,(byte) 0xc3,(byte) 0x83,(byte) 0xc6, +(byte) 0x7c, +}; + +static final BitmapCharRec ch63 = new BitmapCharRec(8,17,-2,0,11,ch63data); + +/* char: 0x3e '>' */ + +static final byte[] ch62data = { +(byte) 0xc0,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0x1c,(byte) 0x0,(byte) 0x7,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x60,(byte) 0x1,(byte) 0xc0,(byte) 0x7,(byte) 0x0, +(byte) 0x1c,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0xc0,(byte) 0x0, +}; + +static final BitmapCharRec ch62 = new BitmapCharRec(11,11,-1,-1,13,ch62data); + +/* char: 0x3d '=' */ + +static final byte[] ch61data = { +(byte) 0xff,(byte) 0xf0,(byte) 0xff,(byte) 0xf0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xff,(byte) 0xf0,(byte) 0xff,(byte) 0xf0, +}; + +static final BitmapCharRec ch61 = new BitmapCharRec(12,6,-1,-4,14,ch61data); + +/* char: 0x3c '<' */ + +static final byte[] ch60data = { +(byte) 0x0,(byte) 0x60,(byte) 0x1,(byte) 0xc0,(byte) 0x7,(byte) 0x0,(byte) 0x1c,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0x1c,(byte) 0x0, +(byte) 0x7,(byte) 0x0,(byte) 0x1,(byte) 0xc0,(byte) 0x0,(byte) 0x60, +}; + +static final BitmapCharRec ch60 = new BitmapCharRec(11,11,-1,-1,13,ch60data); + +/* char: 0x3b ';' */ + +static final byte[] ch59data = { +(byte) 0xc0,(byte) 0x60,(byte) 0x20,(byte) 0xe0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch59 = new BitmapCharRec(3,14,-2,3,7,ch59data); + +/* char: 0x3a ':' */ + +static final byte[] ch58data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch58 = new BitmapCharRec(2,11,-2,0,6,ch58data); + +/* char: 0x39 '9' */ + +static final byte[] ch57data = { +(byte) 0xf0,(byte) 0x0,(byte) 0x1c,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1d,(byte) 0x80,(byte) 0x73,(byte) 0xc0, +(byte) 0x61,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc1,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x77,(byte) 0x80, +(byte) 0x1e,(byte) 0x0, +}; + +static final BitmapCharRec ch57 = new BitmapCharRec(10,17,-1,0,12,ch57data); + +/* char: 0x38 '8' */ + +static final byte[] ch56data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x73,(byte) 0x80,(byte) 0xe1,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x41,(byte) 0xc0,(byte) 0x61,(byte) 0x80, +(byte) 0x37,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x33,(byte) 0x0, +(byte) 0x1e,(byte) 0x0, +}; + +static final BitmapCharRec ch56 = new BitmapCharRec(10,17,-1,0,12,ch56data); + +/* char: 0x37 '7' */ + +static final byte[] ch55data = { +(byte) 0x18,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x4,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0, +(byte) 0x2,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x1,(byte) 0x0,(byte) 0x1,(byte) 0x80,(byte) 0x81,(byte) 0x80,(byte) 0xc0,(byte) 0xc0,(byte) 0xff,(byte) 0xc0, +(byte) 0x7f,(byte) 0xc0, +}; + +static final BitmapCharRec ch55 = new BitmapCharRec(10,17,-1,0,12,ch55data); + +/* char: 0x36 '6' */ + +static final byte[] ch54data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x7b,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xe0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc1,(byte) 0x80,(byte) 0xf3,(byte) 0x80,(byte) 0xee,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x70,(byte) 0x0,(byte) 0x30,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0xe,(byte) 0x0, +(byte) 0x3,(byte) 0xc0, +}; + +static final BitmapCharRec ch54 = new BitmapCharRec(10,17,-1,0,12,ch54data); + +/* char: 0x35 '5' */ + +static final byte[] ch53data = { +(byte) 0x7e,(byte) 0x0,(byte) 0xe3,(byte) 0x80,(byte) 0xc1,(byte) 0x80,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x0,(byte) 0xc0,(byte) 0x1,(byte) 0xc0, +(byte) 0x3,(byte) 0x80,(byte) 0xf,(byte) 0x80,(byte) 0x7e,(byte) 0x0,(byte) 0x78,(byte) 0x0,(byte) 0x60,(byte) 0x0,(byte) 0x20,(byte) 0x0,(byte) 0x20,(byte) 0x0,(byte) 0x1f,(byte) 0x80, +(byte) 0x1f,(byte) 0xc0, +}; + +static final BitmapCharRec ch53 = new BitmapCharRec(10,17,-1,0,12,ch53data); + +/* char: 0x34 '4' */ + +static final byte[] ch52data = { +(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0xff,(byte) 0xc0,(byte) 0xff,(byte) 0xc0,(byte) 0xc3,(byte) 0x0,(byte) 0x43,(byte) 0x0, +(byte) 0x63,(byte) 0x0,(byte) 0x23,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x13,(byte) 0x0,(byte) 0x1b,(byte) 0x0,(byte) 0xb,(byte) 0x0,(byte) 0x7,(byte) 0x0,(byte) 0x7,(byte) 0x0, +(byte) 0x3,(byte) 0x0, +}; + +static final BitmapCharRec ch52 = new BitmapCharRec(10,17,-1,0,12,ch52data); + +/* char: 0x33 '3' */ + +static final byte[] ch51data = { +(byte) 0x78,(byte) 0x0,(byte) 0xe6,(byte) 0x0,(byte) 0xc3,(byte) 0x0,(byte) 0x1,(byte) 0x0,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x3,(byte) 0x80, +(byte) 0x7,(byte) 0x0,(byte) 0x1e,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x83,(byte) 0x0,(byte) 0x83,(byte) 0x0,(byte) 0x47,(byte) 0x0,(byte) 0x7e,(byte) 0x0, +(byte) 0x1c,(byte) 0x0, +}; + +static final BitmapCharRec ch51 = new BitmapCharRec(9,17,-1,0,12,ch51data); + +/* char: 0x32 '2' */ + +static final byte[] ch50data = { +(byte) 0xff,(byte) 0x80,(byte) 0xff,(byte) 0xc0,(byte) 0x60,(byte) 0x40,(byte) 0x30,(byte) 0x0,(byte) 0x18,(byte) 0x0,(byte) 0xc,(byte) 0x0,(byte) 0x4,(byte) 0x0,(byte) 0x6,(byte) 0x0, +(byte) 0x3,(byte) 0x0,(byte) 0x3,(byte) 0x0,(byte) 0x1,(byte) 0x80,(byte) 0x1,(byte) 0x80,(byte) 0x81,(byte) 0x80,(byte) 0x81,(byte) 0x80,(byte) 0x43,(byte) 0x80,(byte) 0x7f,(byte) 0x0, +(byte) 0x1c,(byte) 0x0, +}; + +static final BitmapCharRec ch50 = new BitmapCharRec(10,17,-1,0,12,ch50data); + +/* char: 0x31 '1' */ + +static final byte[] ch49data = { +(byte) 0xff,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x18,(byte) 0x78,(byte) 0x18, +(byte) 0x8, +}; + +static final BitmapCharRec ch49 = new BitmapCharRec(8,17,-2,0,12,ch49data); + +/* char: 0x30 '0' */ + +static final byte[] ch48data = { +(byte) 0x1e,(byte) 0x0,(byte) 0x33,(byte) 0x0,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0xe1,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x61,(byte) 0x80,(byte) 0x61,(byte) 0x80,(byte) 0x33,(byte) 0x0, +(byte) 0x1e,(byte) 0x0, +}; + +static final BitmapCharRec ch48 = new BitmapCharRec(10,17,-1,0,12,ch48data); + +/* char: 0x2f '/' */ + +static final byte[] ch47data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x60,(byte) 0x60,(byte) 0x20,(byte) 0x30,(byte) 0x30,(byte) 0x10,(byte) 0x18,(byte) 0x18,(byte) 0x8,(byte) 0xc,(byte) 0xc,(byte) 0x4,(byte) 0x6, +(byte) 0x6,(byte) 0x3,(byte) 0x3,(byte) 0x3, +}; + +static final BitmapCharRec ch47 = new BitmapCharRec(8,20,1,3,7,ch47data); + +/* char: 0x2e '.' */ + +static final byte[] ch46data = { +(byte) 0xc0,(byte) 0xc0, +}; + +static final BitmapCharRec ch46 = new BitmapCharRec(2,2,-2,0,6,ch46data); + +/* char: 0x2d '-' */ + +static final byte[] ch45data = { +(byte) 0xff,(byte) 0xf0,(byte) 0xff,(byte) 0xf0, +}; + +static final BitmapCharRec ch45 = new BitmapCharRec(12,2,-1,-6,14,ch45data); + +/* char: 0x2c ',' */ + +static final byte[] ch44data = { +(byte) 0xc0,(byte) 0x60,(byte) 0x20,(byte) 0xe0,(byte) 0xc0, +}; + +static final BitmapCharRec ch44 = new BitmapCharRec(3,5,-2,3,7,ch44data); + +/* char: 0x2b '+' */ + +static final byte[] ch43data = { +(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0xff,(byte) 0xf0,(byte) 0xff,(byte) 0xf0,(byte) 0x6,(byte) 0x0, +(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0,(byte) 0x6,(byte) 0x0, +}; + +static final BitmapCharRec ch43 = new BitmapCharRec(12,12,-1,-1,14,ch43data); + +/* char: 0x2a '*' */ + +static final byte[] ch42data = { +(byte) 0x8,(byte) 0x0,(byte) 0x1c,(byte) 0x0,(byte) 0xc9,(byte) 0x80,(byte) 0xeb,(byte) 0x80,(byte) 0x1c,(byte) 0x0,(byte) 0xeb,(byte) 0x80,(byte) 0xc9,(byte) 0x80,(byte) 0x1c,(byte) 0x0, +(byte) 0x8,(byte) 0x0, +}; + +static final BitmapCharRec ch42 = new BitmapCharRec(9,9,-2,-8,12,ch42data); + +/* char: 0x29 ')' */ + +static final byte[] ch41data = { +(byte) 0x80,(byte) 0x40,(byte) 0x20,(byte) 0x30,(byte) 0x10,(byte) 0x18,(byte) 0x18,(byte) 0xc,(byte) 0xc,(byte) 0xc,(byte) 0xc,(byte) 0xc,(byte) 0xc,(byte) 0xc,(byte) 0xc,(byte) 0x18, +(byte) 0x18,(byte) 0x10,(byte) 0x30,(byte) 0x20,(byte) 0x40,(byte) 0x80, +}; + +static final BitmapCharRec ch41 = new BitmapCharRec(6,22,-1,5,8,ch41data); + +/* char: 0x28 '(' */ + +static final byte[] ch40data = { +(byte) 0x4,(byte) 0x8,(byte) 0x10,(byte) 0x30,(byte) 0x20,(byte) 0x60,(byte) 0x60,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0x60, +(byte) 0x60,(byte) 0x20,(byte) 0x30,(byte) 0x10,(byte) 0x8,(byte) 0x4, +}; + +static final BitmapCharRec ch40 = new BitmapCharRec(6,22,-1,5,8,ch40data); + +/* char: 0x27 ''' */ + +static final byte[] ch39data = { +(byte) 0xc0,(byte) 0x60,(byte) 0x20,(byte) 0xe0,(byte) 0xc0, +}; + +static final BitmapCharRec ch39 = new BitmapCharRec(3,5,-3,-12,8,ch39data); + +/* char: 0x26 '&' */ + +static final byte[] ch38data = { +(byte) 0x3c,(byte) 0x3c,(byte) 0x7f,(byte) 0x7e,(byte) 0xe1,(byte) 0xe1,(byte) 0xc0,(byte) 0xc0,(byte) 0xc1,(byte) 0xc0,(byte) 0xc1,(byte) 0xa0,(byte) 0x63,(byte) 0x20,(byte) 0x37,(byte) 0x10, +(byte) 0x1e,(byte) 0x18,(byte) 0xe,(byte) 0x3e,(byte) 0xf,(byte) 0x0,(byte) 0x1d,(byte) 0x80,(byte) 0x18,(byte) 0xc0,(byte) 0x18,(byte) 0x40,(byte) 0x18,(byte) 0x40,(byte) 0xc,(byte) 0xc0, +(byte) 0x7,(byte) 0x80, +}; + +static final BitmapCharRec ch38 = new BitmapCharRec(16,17,-1,0,18,ch38data); + +/* char: 0x25 '%' */ + +static final byte[] ch37data = { +(byte) 0x30,(byte) 0x3c,(byte) 0x0,(byte) 0x18,(byte) 0x72,(byte) 0x0,(byte) 0xc,(byte) 0x61,(byte) 0x0,(byte) 0x4,(byte) 0x60,(byte) 0x80,(byte) 0x6,(byte) 0x60,(byte) 0x80,(byte) 0x3, +(byte) 0x30,(byte) 0x80,(byte) 0x1,(byte) 0x19,(byte) 0x80,(byte) 0x1,(byte) 0x8f,(byte) 0x0,(byte) 0x78,(byte) 0xc0,(byte) 0x0,(byte) 0xe4,(byte) 0x40,(byte) 0x0,(byte) 0xc2,(byte) 0x60, +(byte) 0x0,(byte) 0xc1,(byte) 0x30,(byte) 0x0,(byte) 0xc1,(byte) 0x10,(byte) 0x0,(byte) 0x61,(byte) 0x18,(byte) 0x0,(byte) 0x33,(byte) 0xfc,(byte) 0x0,(byte) 0x1e,(byte) 0xc,(byte) 0x0, +}; + +static final BitmapCharRec ch37 = new BitmapCharRec(17,16,-1,0,19,ch37data); + +/* char: 0x24 '$' */ + +static final byte[] ch36data = { +(byte) 0x4,(byte) 0x0,(byte) 0x4,(byte) 0x0,(byte) 0x3f,(byte) 0x0,(byte) 0xe5,(byte) 0xc0,(byte) 0xc4,(byte) 0xc0,(byte) 0x84,(byte) 0x60,(byte) 0x84,(byte) 0x60,(byte) 0x4,(byte) 0x60, +(byte) 0x4,(byte) 0xe0,(byte) 0x7,(byte) 0xc0,(byte) 0x7,(byte) 0x80,(byte) 0x1e,(byte) 0x0,(byte) 0x3c,(byte) 0x0,(byte) 0x74,(byte) 0x0,(byte) 0x64,(byte) 0x0,(byte) 0x64,(byte) 0x20, +(byte) 0x64,(byte) 0x60,(byte) 0x34,(byte) 0xe0,(byte) 0x1f,(byte) 0x80,(byte) 0x4,(byte) 0x0,(byte) 0x4,(byte) 0x0, +}; + +static final BitmapCharRec ch36 = new BitmapCharRec(11,21,0,2,12,ch36data); + +/* char: 0x23 '#' */ + +static final byte[] ch35data = { +(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0x22,(byte) 0x0,(byte) 0xff,(byte) 0xc0,(byte) 0xff,(byte) 0xc0,(byte) 0x11,(byte) 0x0, +(byte) 0x11,(byte) 0x0,(byte) 0x11,(byte) 0x0,(byte) 0x7f,(byte) 0xe0,(byte) 0x7f,(byte) 0xe0,(byte) 0x8,(byte) 0x80,(byte) 0x8,(byte) 0x80,(byte) 0x8,(byte) 0x80,(byte) 0x8,(byte) 0x80, +(byte) 0x8,(byte) 0x80, +}; + +static final BitmapCharRec ch35 = new BitmapCharRec(11,17,-1,0,13,ch35data); + +/* char: 0x22 '"' */ + +static final byte[] ch34data = { +(byte) 0x88,(byte) 0xcc,(byte) 0xcc,(byte) 0xcc,(byte) 0xcc, +}; + +static final BitmapCharRec ch34 = new BitmapCharRec(6,5,-1,-12,10,ch34data); + +/* char: 0x21 '!' */ + +static final byte[] ch33data = { +(byte) 0xc0,(byte) 0xc0,(byte) 0x0,(byte) 0x0,(byte) 0x0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0,(byte) 0xc0, +(byte) 0xc0, +}; + +static final BitmapCharRec ch33 = new BitmapCharRec(2,17,-3,0,8,ch33data); + +/* char: 0x20 ' ' */ + +static final BitmapCharRec ch32 = new BitmapCharRec(0,0,0,0,6,null); + +static final BitmapCharRec[] chars = { +ch32, +ch33, +ch34, +ch35, +ch36, +ch37, +ch38, +ch39, +ch40, +ch41, +ch42, +ch43, +ch44, +ch45, +ch46, +ch47, +ch48, +ch49, +ch50, +ch51, +ch52, +ch53, +ch54, +ch55, +ch56, +ch57, +ch58, +ch59, +ch60, +ch61, +ch62, +ch63, +ch64, +ch65, +ch66, +ch67, +ch68, +ch69, +ch70, +ch71, +ch72, +ch73, +ch74, +ch75, +ch76, +ch77, +ch78, +ch79, +ch80, +ch81, +ch82, +ch83, +ch84, +ch85, +ch86, +ch87, +ch88, +ch89, +ch90, +ch91, +ch92, +ch93, +ch94, +ch95, +ch96, +ch97, +ch98, +ch99, +ch100, +ch101, +ch102, +ch103, +ch104, +ch105, +ch106, +ch107, +ch108, +ch109, +ch110, +ch111, +ch112, +ch113, +ch114, +ch115, +ch116, +ch117, +ch118, +ch119, +ch120, +ch121, +ch122, +ch123, +ch124, +ch125, +ch126, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +null, +ch160, +ch161, +ch162, +ch163, +ch164, +ch165, +ch166, +ch167, +ch168, +ch169, +ch170, +ch171, +ch172, +ch173, +ch174, +ch175, +ch176, +ch177, +ch178, +ch179, +ch180, +ch181, +ch182, +ch183, +ch184, +ch185, +ch186, +ch187, +ch188, +ch189, +ch190, +ch191, +ch192, +ch193, +ch194, +ch195, +ch196, +ch197, +ch198, +ch199, +ch200, +ch201, +ch202, +ch203, +ch204, +ch205, +ch206, +ch207, +ch208, +ch209, +ch210, +ch211, +ch212, +ch213, +ch214, +ch215, +ch216, +ch217, +ch218, +ch219, +ch220, +ch221, +ch222, +ch223, +ch224, +ch225, +ch226, +ch227, +ch228, +ch229, +ch230, +ch231, +ch232, +ch233, +ch234, +ch235, +ch236, +ch237, +ch238, +ch239, +ch240, +ch241, +ch242, +ch243, +ch244, +ch245, +ch246, +ch247, +ch248, +ch249, +ch250, +ch251, +ch252, +ch253, +ch254, +ch255, +}; + + public static final BitmapFontRec glutBitmapTimesRoman24 = new BitmapFontRec("-adobe-times-medium-r-normal--24-240-75-75-p-124-iso8859-1", + 224, + 32, + chars); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTStrokeMonoRoman.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTStrokeMonoRoman.java new file mode 100644 index 000000000..b8296924e --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTStrokeMonoRoman.java @@ -0,0 +1,2491 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +class GLUTStrokeMonoRoman { + +/* GENERATED FILE -- DO NOT MODIFY */ + +/* char: 33 '!' */ + +static final CoordRec char33_stroke0[] = { + new CoordRec((float) 52.381, (float) 100 ), + new CoordRec((float) 52.381, (float) 33.3333 ), +}; + +static final CoordRec char33_stroke1[] = { + new CoordRec((float) 52.381, (float) 9.5238 ), + new CoordRec((float) 47.6191, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 0 ), + new CoordRec((float) 57.1429, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 9.5238 ), +}; + +static final StrokeRec char33[] = { + new StrokeRec( 2, char33_stroke0 ), + new StrokeRec( 5, char33_stroke1 ), +}; + +/* char: 34 '"' */ + +static final CoordRec char34_stroke0[] = { + new CoordRec((float) 33.3334, (float) 100 ), + new CoordRec((float) 33.3334, (float) 66.6667 ), +}; + +static final CoordRec char34_stroke1[] = { + new CoordRec((float) 71.4286, (float) 100 ), + new CoordRec((float) 71.4286, (float) 66.6667 ), +}; + +static final StrokeRec char34[] = { + new StrokeRec( 2, char34_stroke0 ), + new StrokeRec( 2, char34_stroke1 ), +}; + +/* char: 35 '#' */ + +static final CoordRec char35_stroke0[] = { + new CoordRec((float) 54.7619, (float) 119.048 ), + new CoordRec((float) 21.4286, (float) -33.3333 ), +}; + +static final CoordRec char35_stroke1[] = { + new CoordRec((float) 83.3334, (float) 119.048 ), + new CoordRec((float) 50, (float) -33.3333 ), +}; + +static final CoordRec char35_stroke2[] = { + new CoordRec((float) 21.4286, (float) 57.1429 ), + new CoordRec((float) 88.0952, (float) 57.1429 ), +}; + +static final CoordRec char35_stroke3[] = { + new CoordRec((float) 16.6667, (float) 28.5714 ), + new CoordRec((float) 83.3334, (float) 28.5714 ), +}; + +static final StrokeRec char35[] = { + new StrokeRec( 2, char35_stroke0 ), + new StrokeRec( 2, char35_stroke1 ), + new StrokeRec( 2, char35_stroke2 ), + new StrokeRec( 2, char35_stroke3 ), +}; + +/* char: 36 '$' */ + +static final CoordRec char36_stroke0[] = { + new CoordRec((float) 42.8571, (float) 119.048 ), + new CoordRec((float) 42.8571, (float) -19.0476 ), +}; + +static final CoordRec char36_stroke1[] = { + new CoordRec((float) 61.9047, (float) 119.048 ), + new CoordRec((float) 61.9047, (float) -19.0476 ), +}; + +static final CoordRec char36_stroke2[] = { + new CoordRec((float) 85.7143, (float) 85.7143 ), + new CoordRec((float) 76.1905, (float) 95.2381 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 42.8571, (float) 100 ), + new CoordRec((float) 28.5714, (float) 95.2381 ), + new CoordRec((float) 19.0476, (float) 85.7143 ), + new CoordRec((float) 19.0476, (float) 76.1905 ), + new CoordRec((float) 23.8095, (float) 66.6667 ), + new CoordRec((float) 28.5714, (float) 61.9048 ), + new CoordRec((float) 38.0952, (float) 57.1429 ), + new CoordRec((float) 66.6666, (float) 47.619 ), + new CoordRec((float) 76.1905, (float) 42.8571 ), + new CoordRec((float) 80.9524, (float) 38.0952 ), + new CoordRec((float) 85.7143, (float) 28.5714 ), + new CoordRec((float) 85.7143, (float) 14.2857 ), + new CoordRec((float) 76.1905, (float) 4.7619 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 28.5714, (float) 4.7619 ), + new CoordRec((float) 19.0476, (float) 14.2857 ), +}; + +static final StrokeRec char36[] = { + new StrokeRec( 2, char36_stroke0 ), + new StrokeRec( 2, char36_stroke1 ), + new StrokeRec( 20, char36_stroke2 ), +}; + +/* char: 37 '%' */ + +static final CoordRec char37_stroke0[] = { + new CoordRec((float) 95.2381, (float) 100 ), + new CoordRec((float) 9.5238, (float) 0 ), +}; + +static final CoordRec char37_stroke1[] = { + new CoordRec((float) 33.3333, (float) 100 ), + new CoordRec((float) 42.8571, (float) 90.4762 ), + new CoordRec((float) 42.8571, (float) 80.9524 ), + new CoordRec((float) 38.0952, (float) 71.4286 ), + new CoordRec((float) 28.5714, (float) 66.6667 ), + new CoordRec((float) 19.0476, (float) 66.6667 ), + new CoordRec((float) 9.5238, (float) 76.1905 ), + new CoordRec((float) 9.5238, (float) 85.7143 ), + new CoordRec((float) 14.2857, (float) 95.2381 ), + new CoordRec((float) 23.8095, (float) 100 ), + new CoordRec((float) 33.3333, (float) 100 ), + new CoordRec((float) 42.8571, (float) 95.2381 ), + new CoordRec((float) 57.1428, (float) 90.4762 ), + new CoordRec((float) 71.4286, (float) 90.4762 ), + new CoordRec((float) 85.7143, (float) 95.2381 ), + new CoordRec((float) 95.2381, (float) 100 ), +}; + +static final CoordRec char37_stroke2[] = { + new CoordRec((float) 76.1905, (float) 33.3333 ), + new CoordRec((float) 66.6667, (float) 28.5714 ), + new CoordRec((float) 61.9048, (float) 19.0476 ), + new CoordRec((float) 61.9048, (float) 9.5238 ), + new CoordRec((float) 71.4286, (float) 0 ), + new CoordRec((float) 80.9524, (float) 0 ), + new CoordRec((float) 90.4762, (float) 4.7619 ), + new CoordRec((float) 95.2381, (float) 14.2857 ), + new CoordRec((float) 95.2381, (float) 23.8095 ), + new CoordRec((float) 85.7143, (float) 33.3333 ), + new CoordRec((float) 76.1905, (float) 33.3333 ), +}; + +static final StrokeRec char37[] = { + new StrokeRec( 2, char37_stroke0 ), + new StrokeRec( 16, char37_stroke1 ), + new StrokeRec( 11, char37_stroke2 ), +}; + +/* char: 38 '&' */ + +static final CoordRec char38_stroke0[] = { + new CoordRec((float) 100, (float) 57.1429 ), + new CoordRec((float) 100, (float) 61.9048 ), + new CoordRec((float) 95.2381, (float) 66.6667 ), + new CoordRec((float) 90.4762, (float) 66.6667 ), + new CoordRec((float) 85.7143, (float) 61.9048 ), + new CoordRec((float) 80.9524, (float) 52.381 ), + new CoordRec((float) 71.4286, (float) 28.5714 ), + new CoordRec((float) 61.9048, (float) 14.2857 ), + new CoordRec((float) 52.3809, (float) 4.7619 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 23.8095, (float) 0 ), + new CoordRec((float) 14.2857, (float) 4.7619 ), + new CoordRec((float) 9.5238, (float) 9.5238 ), + new CoordRec((float) 4.7619, (float) 19.0476 ), + new CoordRec((float) 4.7619, (float) 28.5714 ), + new CoordRec((float) 9.5238, (float) 38.0952 ), + new CoordRec((float) 14.2857, (float) 42.8571 ), + new CoordRec((float) 47.619, (float) 61.9048 ), + new CoordRec((float) 52.3809, (float) 66.6667 ), + new CoordRec((float) 57.1429, (float) 76.1905 ), + new CoordRec((float) 57.1429, (float) 85.7143 ), + new CoordRec((float) 52.3809, (float) 95.2381 ), + new CoordRec((float) 42.8571, (float) 100 ), + new CoordRec((float) 33.3333, (float) 95.2381 ), + new CoordRec((float) 28.5714, (float) 85.7143 ), + new CoordRec((float) 28.5714, (float) 76.1905 ), + new CoordRec((float) 33.3333, (float) 61.9048 ), + new CoordRec((float) 42.8571, (float) 47.619 ), + new CoordRec((float) 66.6667, (float) 14.2857 ), + new CoordRec((float) 76.1905, (float) 4.7619 ), + new CoordRec((float) 85.7143, (float) 0 ), + new CoordRec((float) 95.2381, (float) 0 ), + new CoordRec((float) 100, (float) 4.7619 ), + new CoordRec((float) 100, (float) 9.5238 ), +}; + +static final StrokeRec char38[] = { + new StrokeRec( 34, char38_stroke0 ), +}; + +/* char: 39 ''' */ + +static final CoordRec char39_stroke0[] = { + new CoordRec((float) 52.381, (float) 100 ), + new CoordRec((float) 52.381, (float) 66.6667 ), +}; + +static final StrokeRec char39[] = { + new StrokeRec( 2, char39_stroke0 ), +}; + +/* char: 40 '(' */ + +static final CoordRec char40_stroke0[] = { + new CoordRec((float) 69.0476, (float) 119.048 ), + new CoordRec((float) 59.5238, (float) 109.524 ), + new CoordRec((float) 50, (float) 95.2381 ), + new CoordRec((float) 40.4762, (float) 76.1905 ), + new CoordRec((float) 35.7143, (float) 52.381 ), + new CoordRec((float) 35.7143, (float) 33.3333 ), + new CoordRec((float) 40.4762, (float) 9.5238 ), + new CoordRec((float) 50, (float) -9.5238 ), + new CoordRec((float) 59.5238, (float) -23.8095 ), + new CoordRec((float) 69.0476, (float) -33.3333 ), +}; + +static final StrokeRec char40[] = { + new StrokeRec( 10, char40_stroke0 ), +}; + +/* char: 41 ')' */ + +static final CoordRec char41_stroke0[] = { + new CoordRec((float) 35.7143, (float) 119.048 ), + new CoordRec((float) 45.2381, (float) 109.524 ), + new CoordRec((float) 54.7619, (float) 95.2381 ), + new CoordRec((float) 64.2857, (float) 76.1905 ), + new CoordRec((float) 69.0476, (float) 52.381 ), + new CoordRec((float) 69.0476, (float) 33.3333 ), + new CoordRec((float) 64.2857, (float) 9.5238 ), + new CoordRec((float) 54.7619, (float) -9.5238 ), + new CoordRec((float) 45.2381, (float) -23.8095 ), + new CoordRec((float) 35.7143, (float) -33.3333 ), +}; + +static final StrokeRec char41[] = { + new StrokeRec( 10, char41_stroke0 ), +}; + +/* char: 42 '*' */ + +static final CoordRec char42_stroke0[] = { + new CoordRec((float) 52.381, (float) 71.4286 ), + new CoordRec((float) 52.381, (float) 14.2857 ), +}; + +static final CoordRec char42_stroke1[] = { + new CoordRec((float) 28.5715, (float) 57.1429 ), + new CoordRec((float) 76.1905, (float) 28.5714 ), +}; + +static final CoordRec char42_stroke2[] = { + new CoordRec((float) 76.1905, (float) 57.1429 ), + new CoordRec((float) 28.5715, (float) 28.5714 ), +}; + +static final StrokeRec char42[] = { + new StrokeRec( 2, char42_stroke0 ), + new StrokeRec( 2, char42_stroke1 ), + new StrokeRec( 2, char42_stroke2 ), +}; + +/* char: 43 '+' */ + +static final CoordRec char43_stroke0[] = { + new CoordRec((float) 52.3809, (float) 85.7143 ), + new CoordRec((float) 52.3809, (float) 0 ), +}; + +static final CoordRec char43_stroke1[] = { + new CoordRec((float) 9.5238, (float) 42.8571 ), + new CoordRec((float) 95.2381, (float) 42.8571 ), +}; + +static final StrokeRec char43[] = { + new StrokeRec( 2, char43_stroke0 ), + new StrokeRec( 2, char43_stroke1 ), +}; + +/* char: 44 ',' */ + +static final CoordRec char44_stroke0[] = { + new CoordRec((float) 57.1429, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 0 ), + new CoordRec((float) 47.6191, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 9.5238 ), + new CoordRec((float) 57.1429, (float) 4.7619 ), + new CoordRec((float) 57.1429, (float) -4.7619 ), + new CoordRec((float) 52.381, (float) -14.2857 ), + new CoordRec((float) 47.6191, (float) -19.0476 ), +}; + +static final StrokeRec char44[] = { + new StrokeRec( 8, char44_stroke0 ), +}; + +/* char: 45 '-' */ + +static final CoordRec char45_stroke0[] = { + new CoordRec((float) 9.5238, (float) 42.8571 ), + new CoordRec((float) 95.2381, (float) 42.8571 ), +}; + +static final StrokeRec char45[] = { + new StrokeRec( 2, char45_stroke0 ), +}; + +/* char: 46 '.' */ + +static final CoordRec char46_stroke0[] = { + new CoordRec((float) 52.381, (float) 9.5238 ), + new CoordRec((float) 47.6191, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 0 ), + new CoordRec((float) 57.1429, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 9.5238 ), +}; + +static final StrokeRec char46[] = { + new StrokeRec( 5, char46_stroke0 ), +}; + +/* char: 47 '/' */ + +static final CoordRec char47_stroke0[] = { + new CoordRec((float) 19.0476, (float) -14.2857 ), + new CoordRec((float) 85.7143, (float) 100 ), +}; + +static final StrokeRec char47[] = { + new StrokeRec( 2, char47_stroke0 ), +}; + +/* char: 48 '0' */ + +static final CoordRec char48_stroke0[] = { + new CoordRec((float) 47.619, (float) 100 ), + new CoordRec((float) 33.3333, (float) 95.2381 ), + new CoordRec((float) 23.8095, (float) 80.9524 ), + new CoordRec((float) 19.0476, (float) 57.1429 ), + new CoordRec((float) 19.0476, (float) 42.8571 ), + new CoordRec((float) 23.8095, (float) 19.0476 ), + new CoordRec((float) 33.3333, (float) 4.7619 ), + new CoordRec((float) 47.619, (float) 0 ), + new CoordRec((float) 57.1428, (float) 0 ), + new CoordRec((float) 71.4286, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 19.0476 ), + new CoordRec((float) 85.7143, (float) 42.8571 ), + new CoordRec((float) 85.7143, (float) 57.1429 ), + new CoordRec((float) 80.9524, (float) 80.9524 ), + new CoordRec((float) 71.4286, (float) 95.2381 ), + new CoordRec((float) 57.1428, (float) 100 ), + new CoordRec((float) 47.619, (float) 100 ), +}; + +static final StrokeRec char48[] = { + new StrokeRec( 17, char48_stroke0 ), +}; + +/* char: 49 '1' */ + +static final CoordRec char49_stroke0[] = { + new CoordRec((float) 40.4762, (float) 80.9524 ), + new CoordRec((float) 50, (float) 85.7143 ), + new CoordRec((float) 64.2857, (float) 100 ), + new CoordRec((float) 64.2857, (float) 0 ), +}; + +static final StrokeRec char49[] = { + new StrokeRec( 4, char49_stroke0 ), +}; + +/* char: 50 '2' */ + +static final CoordRec char50_stroke0[] = { + new CoordRec((float) 23.8095, (float) 76.1905 ), + new CoordRec((float) 23.8095, (float) 80.9524 ), + new CoordRec((float) 28.5714, (float) 90.4762 ), + new CoordRec((float) 33.3333, (float) 95.2381 ), + new CoordRec((float) 42.8571, (float) 100 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 71.4286, (float) 95.2381 ), + new CoordRec((float) 76.1905, (float) 90.4762 ), + new CoordRec((float) 80.9524, (float) 80.9524 ), + new CoordRec((float) 80.9524, (float) 71.4286 ), + new CoordRec((float) 76.1905, (float) 61.9048 ), + new CoordRec((float) 66.6666, (float) 47.619 ), + new CoordRec((float) 19.0476, (float) 0 ), + new CoordRec((float) 85.7143, (float) 0 ), +}; + +static final StrokeRec char50[] = { + new StrokeRec( 14, char50_stroke0 ), +}; + +/* char: 51 '3' */ + +static final CoordRec char51_stroke0[] = { + new CoordRec((float) 28.5714, (float) 100 ), + new CoordRec((float) 80.9524, (float) 100 ), + new CoordRec((float) 52.3809, (float) 61.9048 ), + new CoordRec((float) 66.6666, (float) 61.9048 ), + new CoordRec((float) 76.1905, (float) 57.1429 ), + new CoordRec((float) 80.9524, (float) 52.381 ), + new CoordRec((float) 85.7143, (float) 38.0952 ), + new CoordRec((float) 85.7143, (float) 28.5714 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), + new CoordRec((float) 71.4286, (float) 4.7619 ), + new CoordRec((float) 57.1428, (float) 0 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 28.5714, (float) 4.7619 ), + new CoordRec((float) 23.8095, (float) 9.5238 ), + new CoordRec((float) 19.0476, (float) 19.0476 ), +}; + +static final StrokeRec char51[] = { + new StrokeRec( 15, char51_stroke0 ), +}; + +/* char: 52 '4' */ + +static final CoordRec char52_stroke0[] = { + new CoordRec((float) 64.2857, (float) 100 ), + new CoordRec((float) 16.6667, (float) 33.3333 ), + new CoordRec((float) 88.0952, (float) 33.3333 ), +}; + +static final CoordRec char52_stroke1[] = { + new CoordRec((float) 64.2857, (float) 100 ), + new CoordRec((float) 64.2857, (float) 0 ), +}; + +static final StrokeRec char52[] = { + new StrokeRec( 3, char52_stroke0 ), + new StrokeRec( 2, char52_stroke1 ), +}; + +/* char: 53 '5' */ + +static final CoordRec char53_stroke0[] = { + new CoordRec((float) 76.1905, (float) 100 ), + new CoordRec((float) 28.5714, (float) 100 ), + new CoordRec((float) 23.8095, (float) 57.1429 ), + new CoordRec((float) 28.5714, (float) 61.9048 ), + new CoordRec((float) 42.8571, (float) 66.6667 ), + new CoordRec((float) 57.1428, (float) 66.6667 ), + new CoordRec((float) 71.4286, (float) 61.9048 ), + new CoordRec((float) 80.9524, (float) 52.381 ), + new CoordRec((float) 85.7143, (float) 38.0952 ), + new CoordRec((float) 85.7143, (float) 28.5714 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), + new CoordRec((float) 71.4286, (float) 4.7619 ), + new CoordRec((float) 57.1428, (float) 0 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 28.5714, (float) 4.7619 ), + new CoordRec((float) 23.8095, (float) 9.5238 ), + new CoordRec((float) 19.0476, (float) 19.0476 ), +}; + +static final StrokeRec char53[] = { + new StrokeRec( 17, char53_stroke0 ), +}; + +/* char: 54 '6' */ + +static final CoordRec char54_stroke0[] = { + new CoordRec((float) 78.5714, (float) 85.7143 ), + new CoordRec((float) 73.8096, (float) 95.2381 ), + new CoordRec((float) 59.5238, (float) 100 ), + new CoordRec((float) 50, (float) 100 ), + new CoordRec((float) 35.7143, (float) 95.2381 ), + new CoordRec((float) 26.1905, (float) 80.9524 ), + new CoordRec((float) 21.4286, (float) 57.1429 ), + new CoordRec((float) 21.4286, (float) 33.3333 ), + new CoordRec((float) 26.1905, (float) 14.2857 ), + new CoordRec((float) 35.7143, (float) 4.7619 ), + new CoordRec((float) 50, (float) 0 ), + new CoordRec((float) 54.7619, (float) 0 ), + new CoordRec((float) 69.0476, (float) 4.7619 ), + new CoordRec((float) 78.5714, (float) 14.2857 ), + new CoordRec((float) 83.3334, (float) 28.5714 ), + new CoordRec((float) 83.3334, (float) 33.3333 ), + new CoordRec((float) 78.5714, (float) 47.619 ), + new CoordRec((float) 69.0476, (float) 57.1429 ), + new CoordRec((float) 54.7619, (float) 61.9048 ), + new CoordRec((float) 50, (float) 61.9048 ), + new CoordRec((float) 35.7143, (float) 57.1429 ), + new CoordRec((float) 26.1905, (float) 47.619 ), + new CoordRec((float) 21.4286, (float) 33.3333 ), +}; + +static final StrokeRec char54[] = { + new StrokeRec( 23, char54_stroke0 ), +}; + +/* char: 55 '7' */ + +static final CoordRec char55_stroke0[] = { + new CoordRec((float) 85.7143, (float) 100 ), + new CoordRec((float) 38.0952, (float) 0 ), +}; + +static final CoordRec char55_stroke1[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 85.7143, (float) 100 ), +}; + +static final StrokeRec char55[] = { + new StrokeRec( 2, char55_stroke0 ), + new StrokeRec( 2, char55_stroke1 ), +}; + +/* char: 56 '8' */ + +static final CoordRec char56_stroke0[] = { + new CoordRec((float) 42.8571, (float) 100 ), + new CoordRec((float) 28.5714, (float) 95.2381 ), + new CoordRec((float) 23.8095, (float) 85.7143 ), + new CoordRec((float) 23.8095, (float) 76.1905 ), + new CoordRec((float) 28.5714, (float) 66.6667 ), + new CoordRec((float) 38.0952, (float) 61.9048 ), + new CoordRec((float) 57.1428, (float) 57.1429 ), + new CoordRec((float) 71.4286, (float) 52.381 ), + new CoordRec((float) 80.9524, (float) 42.8571 ), + new CoordRec((float) 85.7143, (float) 33.3333 ), + new CoordRec((float) 85.7143, (float) 19.0476 ), + new CoordRec((float) 80.9524, (float) 9.5238 ), + new CoordRec((float) 76.1905, (float) 4.7619 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 28.5714, (float) 4.7619 ), + new CoordRec((float) 23.8095, (float) 9.5238 ), + new CoordRec((float) 19.0476, (float) 19.0476 ), + new CoordRec((float) 19.0476, (float) 33.3333 ), + new CoordRec((float) 23.8095, (float) 42.8571 ), + new CoordRec((float) 33.3333, (float) 52.381 ), + new CoordRec((float) 47.619, (float) 57.1429 ), + new CoordRec((float) 66.6666, (float) 61.9048 ), + new CoordRec((float) 76.1905, (float) 66.6667 ), + new CoordRec((float) 80.9524, (float) 76.1905 ), + new CoordRec((float) 80.9524, (float) 85.7143 ), + new CoordRec((float) 76.1905, (float) 95.2381 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 42.8571, (float) 100 ), +}; + +static final StrokeRec char56[] = { + new StrokeRec( 29, char56_stroke0 ), +}; + +/* char: 57 '9' */ + +static final CoordRec char57_stroke0[] = { + new CoordRec((float) 83.3334, (float) 66.6667 ), + new CoordRec((float) 78.5714, (float) 52.381 ), + new CoordRec((float) 69.0476, (float) 42.8571 ), + new CoordRec((float) 54.7619, (float) 38.0952 ), + new CoordRec((float) 50, (float) 38.0952 ), + new CoordRec((float) 35.7143, (float) 42.8571 ), + new CoordRec((float) 26.1905, (float) 52.381 ), + new CoordRec((float) 21.4286, (float) 66.6667 ), + new CoordRec((float) 21.4286, (float) 71.4286 ), + new CoordRec((float) 26.1905, (float) 85.7143 ), + new CoordRec((float) 35.7143, (float) 95.2381 ), + new CoordRec((float) 50, (float) 100 ), + new CoordRec((float) 54.7619, (float) 100 ), + new CoordRec((float) 69.0476, (float) 95.2381 ), + new CoordRec((float) 78.5714, (float) 85.7143 ), + new CoordRec((float) 83.3334, (float) 66.6667 ), + new CoordRec((float) 83.3334, (float) 42.8571 ), + new CoordRec((float) 78.5714, (float) 19.0476 ), + new CoordRec((float) 69.0476, (float) 4.7619 ), + new CoordRec((float) 54.7619, (float) 0 ), + new CoordRec((float) 45.2381, (float) 0 ), + new CoordRec((float) 30.9524, (float) 4.7619 ), + new CoordRec((float) 26.1905, (float) 14.2857 ), +}; + +static final StrokeRec char57[] = { + new StrokeRec( 23, char57_stroke0 ), +}; + +/* char: 58 ':' */ + +static final CoordRec char58_stroke0[] = { + new CoordRec((float) 52.381, (float) 66.6667 ), + new CoordRec((float) 47.6191, (float) 61.9048 ), + new CoordRec((float) 52.381, (float) 57.1429 ), + new CoordRec((float) 57.1429, (float) 61.9048 ), + new CoordRec((float) 52.381, (float) 66.6667 ), +}; + +static final CoordRec char58_stroke1[] = { + new CoordRec((float) 52.381, (float) 9.5238 ), + new CoordRec((float) 47.6191, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 0 ), + new CoordRec((float) 57.1429, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 9.5238 ), +}; + +static final StrokeRec char58[] = { + new StrokeRec( 5, char58_stroke0 ), + new StrokeRec( 5, char58_stroke1 ), +}; + +/* char: 59 ';' */ + +static final CoordRec char59_stroke0[] = { + new CoordRec((float) 52.381, (float) 66.6667 ), + new CoordRec((float) 47.6191, (float) 61.9048 ), + new CoordRec((float) 52.381, (float) 57.1429 ), + new CoordRec((float) 57.1429, (float) 61.9048 ), + new CoordRec((float) 52.381, (float) 66.6667 ), +}; + +static final CoordRec char59_stroke1[] = { + new CoordRec((float) 57.1429, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 0 ), + new CoordRec((float) 47.6191, (float) 4.7619 ), + new CoordRec((float) 52.381, (float) 9.5238 ), + new CoordRec((float) 57.1429, (float) 4.7619 ), + new CoordRec((float) 57.1429, (float) -4.7619 ), + new CoordRec((float) 52.381, (float) -14.2857 ), + new CoordRec((float) 47.6191, (float) -19.0476 ), +}; + +static final StrokeRec char59[] = { + new StrokeRec( 5, char59_stroke0 ), + new StrokeRec( 8, char59_stroke1 ), +}; + +/* char: 60 '<' */ + +static final CoordRec char60_stroke0[] = { + new CoordRec((float) 90.4762, (float) 85.7143 ), + new CoordRec((float) 14.2857, (float) 42.8571 ), + new CoordRec((float) 90.4762, (float) 0 ), +}; + +static final StrokeRec char60[] = { + new StrokeRec( 3, char60_stroke0 ), +}; + +/* char: 61 '=' */ + +static final CoordRec char61_stroke0[] = { + new CoordRec((float) 9.5238, (float) 57.1429 ), + new CoordRec((float) 95.2381, (float) 57.1429 ), +}; + +static final CoordRec char61_stroke1[] = { + new CoordRec((float) 9.5238, (float) 28.5714 ), + new CoordRec((float) 95.2381, (float) 28.5714 ), +}; + +static final StrokeRec char61[] = { + new StrokeRec( 2, char61_stroke0 ), + new StrokeRec( 2, char61_stroke1 ), +}; + +/* char: 62 '>' */ + +static final CoordRec char62_stroke0[] = { + new CoordRec((float) 14.2857, (float) 85.7143 ), + new CoordRec((float) 90.4762, (float) 42.8571 ), + new CoordRec((float) 14.2857, (float) 0 ), +}; + +static final StrokeRec char62[] = { + new StrokeRec( 3, char62_stroke0 ), +}; + +/* char: 63 '?' */ + +static final CoordRec char63_stroke0[] = { + new CoordRec((float) 23.8095, (float) 76.1905 ), + new CoordRec((float) 23.8095, (float) 80.9524 ), + new CoordRec((float) 28.5714, (float) 90.4762 ), + new CoordRec((float) 33.3333, (float) 95.2381 ), + new CoordRec((float) 42.8571, (float) 100 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 71.4285, (float) 95.2381 ), + new CoordRec((float) 76.1905, (float) 90.4762 ), + new CoordRec((float) 80.9524, (float) 80.9524 ), + new CoordRec((float) 80.9524, (float) 71.4286 ), + new CoordRec((float) 76.1905, (float) 61.9048 ), + new CoordRec((float) 71.4285, (float) 57.1429 ), + new CoordRec((float) 52.3809, (float) 47.619 ), + new CoordRec((float) 52.3809, (float) 33.3333 ), +}; + +static final CoordRec char63_stroke1[] = { + new CoordRec((float) 52.3809, (float) 9.5238 ), + new CoordRec((float) 47.619, (float) 4.7619 ), + new CoordRec((float) 52.3809, (float) 0 ), + new CoordRec((float) 57.1428, (float) 4.7619 ), + new CoordRec((float) 52.3809, (float) 9.5238 ), +}; + +static final StrokeRec char63[] = { + new StrokeRec( 14, char63_stroke0 ), + new StrokeRec( 5, char63_stroke1 ), +}; + +/* char: 64 '@' */ + +static final CoordRec char64_stroke0[] = { + new CoordRec((float) 64.2857, (float) 52.381 ), + new CoordRec((float) 54.7619, (float) 57.1429 ), + new CoordRec((float) 45.2381, (float) 57.1429 ), + new CoordRec((float) 40.4762, (float) 47.619 ), + new CoordRec((float) 40.4762, (float) 42.8571 ), + new CoordRec((float) 45.2381, (float) 33.3333 ), + new CoordRec((float) 54.7619, (float) 33.3333 ), + new CoordRec((float) 64.2857, (float) 38.0952 ), +}; + +static final CoordRec char64_stroke1[] = { + new CoordRec((float) 64.2857, (float) 57.1429 ), + new CoordRec((float) 64.2857, (float) 38.0952 ), + new CoordRec((float) 69.0476, (float) 33.3333 ), + new CoordRec((float) 78.5714, (float) 33.3333 ), + new CoordRec((float) 83.3334, (float) 42.8571 ), + new CoordRec((float) 83.3334, (float) 47.619 ), + new CoordRec((float) 78.5714, (float) 61.9048 ), + new CoordRec((float) 69.0476, (float) 71.4286 ), + new CoordRec((float) 54.7619, (float) 76.1905 ), + new CoordRec((float) 50, (float) 76.1905 ), + new CoordRec((float) 35.7143, (float) 71.4286 ), + new CoordRec((float) 26.1905, (float) 61.9048 ), + new CoordRec((float) 21.4286, (float) 47.619 ), + new CoordRec((float) 21.4286, (float) 42.8571 ), + new CoordRec((float) 26.1905, (float) 28.5714 ), + new CoordRec((float) 35.7143, (float) 19.0476 ), + new CoordRec((float) 50, (float) 14.2857 ), + new CoordRec((float) 54.7619, (float) 14.2857 ), + new CoordRec((float) 69.0476, (float) 19.0476 ), +}; + +static final StrokeRec char64[] = { + new StrokeRec( 8, char64_stroke0 ), + new StrokeRec( 19, char64_stroke1 ), +}; + +/* char: 65 'A' */ + +static final CoordRec char65_stroke0[] = { + new CoordRec((float) 52.3809, (float) 100 ), + new CoordRec((float) 14.2857, (float) 0 ), +}; + +static final CoordRec char65_stroke1[] = { + new CoordRec((float) 52.3809, (float) 100 ), + new CoordRec((float) 90.4762, (float) 0 ), +}; + +static final CoordRec char65_stroke2[] = { + new CoordRec((float) 28.5714, (float) 33.3333 ), + new CoordRec((float) 76.1905, (float) 33.3333 ), +}; + +static final StrokeRec char65[] = { + new StrokeRec( 2, char65_stroke0 ), + new StrokeRec( 2, char65_stroke1 ), + new StrokeRec( 2, char65_stroke2 ), +}; + +/* char: 66 'B' */ + +static final CoordRec char66_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final CoordRec char66_stroke1[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 76.1905, (float) 95.2381 ), + new CoordRec((float) 80.9524, (float) 90.4762 ), + new CoordRec((float) 85.7143, (float) 80.9524 ), + new CoordRec((float) 85.7143, (float) 71.4286 ), + new CoordRec((float) 80.9524, (float) 61.9048 ), + new CoordRec((float) 76.1905, (float) 57.1429 ), + new CoordRec((float) 61.9047, (float) 52.381 ), +}; + +static final CoordRec char66_stroke2[] = { + new CoordRec((float) 19.0476, (float) 52.381 ), + new CoordRec((float) 61.9047, (float) 52.381 ), + new CoordRec((float) 76.1905, (float) 47.619 ), + new CoordRec((float) 80.9524, (float) 42.8571 ), + new CoordRec((float) 85.7143, (float) 33.3333 ), + new CoordRec((float) 85.7143, (float) 19.0476 ), + new CoordRec((float) 80.9524, (float) 9.5238 ), + new CoordRec((float) 76.1905, (float) 4.7619 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final StrokeRec char66[] = { + new StrokeRec( 2, char66_stroke0 ), + new StrokeRec( 9, char66_stroke1 ), + new StrokeRec( 10, char66_stroke2 ), +}; + +/* char: 67 'C' */ + +static final CoordRec char67_stroke0[] = { + new CoordRec((float) 88.0952, (float) 76.1905 ), + new CoordRec((float) 83.3334, (float) 85.7143 ), + new CoordRec((float) 73.8096, (float) 95.2381 ), + new CoordRec((float) 64.2857, (float) 100 ), + new CoordRec((float) 45.2381, (float) 100 ), + new CoordRec((float) 35.7143, (float) 95.2381 ), + new CoordRec((float) 26.1905, (float) 85.7143 ), + new CoordRec((float) 21.4286, (float) 76.1905 ), + new CoordRec((float) 16.6667, (float) 61.9048 ), + new CoordRec((float) 16.6667, (float) 38.0952 ), + new CoordRec((float) 21.4286, (float) 23.8095 ), + new CoordRec((float) 26.1905, (float) 14.2857 ), + new CoordRec((float) 35.7143, (float) 4.7619 ), + new CoordRec((float) 45.2381, (float) 0 ), + new CoordRec((float) 64.2857, (float) 0 ), + new CoordRec((float) 73.8096, (float) 4.7619 ), + new CoordRec((float) 83.3334, (float) 14.2857 ), + new CoordRec((float) 88.0952, (float) 23.8095 ), +}; + +static final StrokeRec char67[] = { + new StrokeRec( 18, char67_stroke0 ), +}; + +/* char: 68 'D' */ + +static final CoordRec char68_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final CoordRec char68_stroke1[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 52.3809, (float) 100 ), + new CoordRec((float) 66.6666, (float) 95.2381 ), + new CoordRec((float) 76.1905, (float) 85.7143 ), + new CoordRec((float) 80.9524, (float) 76.1905 ), + new CoordRec((float) 85.7143, (float) 61.9048 ), + new CoordRec((float) 85.7143, (float) 38.0952 ), + new CoordRec((float) 80.9524, (float) 23.8095 ), + new CoordRec((float) 76.1905, (float) 14.2857 ), + new CoordRec((float) 66.6666, (float) 4.7619 ), + new CoordRec((float) 52.3809, (float) 0 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final StrokeRec char68[] = { + new StrokeRec( 2, char68_stroke0 ), + new StrokeRec( 12, char68_stroke1 ), +}; + +/* char: 69 'E' */ + +static final CoordRec char69_stroke0[] = { + new CoordRec((float) 21.4286, (float) 100 ), + new CoordRec((float) 21.4286, (float) 0 ), +}; + +static final CoordRec char69_stroke1[] = { + new CoordRec((float) 21.4286, (float) 100 ), + new CoordRec((float) 83.3334, (float) 100 ), +}; + +static final CoordRec char69_stroke2[] = { + new CoordRec((float) 21.4286, (float) 52.381 ), + new CoordRec((float) 59.5238, (float) 52.381 ), +}; + +static final CoordRec char69_stroke3[] = { + new CoordRec((float) 21.4286, (float) 0 ), + new CoordRec((float) 83.3334, (float) 0 ), +}; + +static final StrokeRec char69[] = { + new StrokeRec( 2, char69_stroke0 ), + new StrokeRec( 2, char69_stroke1 ), + new StrokeRec( 2, char69_stroke2 ), + new StrokeRec( 2, char69_stroke3 ), +}; + +/* char: 70 'F' */ + +static final CoordRec char70_stroke0[] = { + new CoordRec((float) 21.4286, (float) 100 ), + new CoordRec((float) 21.4286, (float) 0 ), +}; + +static final CoordRec char70_stroke1[] = { + new CoordRec((float) 21.4286, (float) 100 ), + new CoordRec((float) 83.3334, (float) 100 ), +}; + +static final CoordRec char70_stroke2[] = { + new CoordRec((float) 21.4286, (float) 52.381 ), + new CoordRec((float) 59.5238, (float) 52.381 ), +}; + +static final StrokeRec char70[] = { + new StrokeRec( 2, char70_stroke0 ), + new StrokeRec( 2, char70_stroke1 ), + new StrokeRec( 2, char70_stroke2 ), +}; + +/* char: 71 'G' */ + +static final CoordRec char71_stroke0[] = { + new CoordRec((float) 88.0952, (float) 76.1905 ), + new CoordRec((float) 83.3334, (float) 85.7143 ), + new CoordRec((float) 73.8096, (float) 95.2381 ), + new CoordRec((float) 64.2857, (float) 100 ), + new CoordRec((float) 45.2381, (float) 100 ), + new CoordRec((float) 35.7143, (float) 95.2381 ), + new CoordRec((float) 26.1905, (float) 85.7143 ), + new CoordRec((float) 21.4286, (float) 76.1905 ), + new CoordRec((float) 16.6667, (float) 61.9048 ), + new CoordRec((float) 16.6667, (float) 38.0952 ), + new CoordRec((float) 21.4286, (float) 23.8095 ), + new CoordRec((float) 26.1905, (float) 14.2857 ), + new CoordRec((float) 35.7143, (float) 4.7619 ), + new CoordRec((float) 45.2381, (float) 0 ), + new CoordRec((float) 64.2857, (float) 0 ), + new CoordRec((float) 73.8096, (float) 4.7619 ), + new CoordRec((float) 83.3334, (float) 14.2857 ), + new CoordRec((float) 88.0952, (float) 23.8095 ), + new CoordRec((float) 88.0952, (float) 38.0952 ), +}; + +static final CoordRec char71_stroke1[] = { + new CoordRec((float) 64.2857, (float) 38.0952 ), + new CoordRec((float) 88.0952, (float) 38.0952 ), +}; + +static final StrokeRec char71[] = { + new StrokeRec( 19, char71_stroke0 ), + new StrokeRec( 2, char71_stroke1 ), +}; + +/* char: 72 'H' */ + +static final CoordRec char72_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final CoordRec char72_stroke1[] = { + new CoordRec((float) 85.7143, (float) 100 ), + new CoordRec((float) 85.7143, (float) 0 ), +}; + +static final CoordRec char72_stroke2[] = { + new CoordRec((float) 19.0476, (float) 52.381 ), + new CoordRec((float) 85.7143, (float) 52.381 ), +}; + +static final StrokeRec char72[] = { + new StrokeRec( 2, char72_stroke0 ), + new StrokeRec( 2, char72_stroke1 ), + new StrokeRec( 2, char72_stroke2 ), +}; + +/* char: 73 'I' */ + +static final CoordRec char73_stroke0[] = { + new CoordRec((float) 52.381, (float) 100 ), + new CoordRec((float) 52.381, (float) 0 ), +}; + +static final StrokeRec char73[] = { + new StrokeRec( 2, char73_stroke0 ), +}; + +/* char: 74 'J' */ + +static final CoordRec char74_stroke0[] = { + new CoordRec((float) 76.1905, (float) 100 ), + new CoordRec((float) 76.1905, (float) 23.8095 ), + new CoordRec((float) 71.4286, (float) 9.5238 ), + new CoordRec((float) 66.6667, (float) 4.7619 ), + new CoordRec((float) 57.1429, (float) 0 ), + new CoordRec((float) 47.6191, (float) 0 ), + new CoordRec((float) 38.0953, (float) 4.7619 ), + new CoordRec((float) 33.3334, (float) 9.5238 ), + new CoordRec((float) 28.5715, (float) 23.8095 ), + new CoordRec((float) 28.5715, (float) 33.3333 ), +}; + +static final StrokeRec char74[] = { + new StrokeRec( 10, char74_stroke0 ), +}; + +/* char: 75 'K' */ + +static final CoordRec char75_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final CoordRec char75_stroke1[] = { + new CoordRec((float) 85.7143, (float) 100 ), + new CoordRec((float) 19.0476, (float) 33.3333 ), +}; + +static final CoordRec char75_stroke2[] = { + new CoordRec((float) 42.8571, (float) 57.1429 ), + new CoordRec((float) 85.7143, (float) 0 ), +}; + +static final StrokeRec char75[] = { + new StrokeRec( 2, char75_stroke0 ), + new StrokeRec( 2, char75_stroke1 ), + new StrokeRec( 2, char75_stroke2 ), +}; + +/* char: 76 'L' */ + +static final CoordRec char76_stroke0[] = { + new CoordRec((float) 23.8095, (float) 100 ), + new CoordRec((float) 23.8095, (float) 0 ), +}; + +static final CoordRec char76_stroke1[] = { + new CoordRec((float) 23.8095, (float) 0 ), + new CoordRec((float) 80.9524, (float) 0 ), +}; + +static final StrokeRec char76[] = { + new StrokeRec( 2, char76_stroke0 ), + new StrokeRec( 2, char76_stroke1 ), +}; + +/* char: 77 'M' */ + +static final CoordRec char77_stroke0[] = { + new CoordRec((float) 14.2857, (float) 100 ), + new CoordRec((float) 14.2857, (float) 0 ), +}; + +static final CoordRec char77_stroke1[] = { + new CoordRec((float) 14.2857, (float) 100 ), + new CoordRec((float) 52.3809, (float) 0 ), +}; + +static final CoordRec char77_stroke2[] = { + new CoordRec((float) 90.4762, (float) 100 ), + new CoordRec((float) 52.3809, (float) 0 ), +}; + +static final CoordRec char77_stroke3[] = { + new CoordRec((float) 90.4762, (float) 100 ), + new CoordRec((float) 90.4762, (float) 0 ), +}; + +static final StrokeRec char77[] = { + new StrokeRec( 2, char77_stroke0 ), + new StrokeRec( 2, char77_stroke1 ), + new StrokeRec( 2, char77_stroke2 ), + new StrokeRec( 2, char77_stroke3 ), +}; + +/* char: 78 'N' */ + +static final CoordRec char78_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final CoordRec char78_stroke1[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 85.7143, (float) 0 ), +}; + +static final CoordRec char78_stroke2[] = { + new CoordRec((float) 85.7143, (float) 100 ), + new CoordRec((float) 85.7143, (float) 0 ), +}; + +static final StrokeRec char78[] = { + new StrokeRec( 2, char78_stroke0 ), + new StrokeRec( 2, char78_stroke1 ), + new StrokeRec( 2, char78_stroke2 ), +}; + +/* char: 79 'O' */ + +static final CoordRec char79_stroke0[] = { + new CoordRec((float) 42.8571, (float) 100 ), + new CoordRec((float) 33.3333, (float) 95.2381 ), + new CoordRec((float) 23.8095, (float) 85.7143 ), + new CoordRec((float) 19.0476, (float) 76.1905 ), + new CoordRec((float) 14.2857, (float) 61.9048 ), + new CoordRec((float) 14.2857, (float) 38.0952 ), + new CoordRec((float) 19.0476, (float) 23.8095 ), + new CoordRec((float) 23.8095, (float) 14.2857 ), + new CoordRec((float) 33.3333, (float) 4.7619 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 71.4286, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), + new CoordRec((float) 85.7143, (float) 23.8095 ), + new CoordRec((float) 90.4762, (float) 38.0952 ), + new CoordRec((float) 90.4762, (float) 61.9048 ), + new CoordRec((float) 85.7143, (float) 76.1905 ), + new CoordRec((float) 80.9524, (float) 85.7143 ), + new CoordRec((float) 71.4286, (float) 95.2381 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 42.8571, (float) 100 ), +}; + +static final StrokeRec char79[] = { + new StrokeRec( 21, char79_stroke0 ), +}; + +/* char: 80 'P' */ + +static final CoordRec char80_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final CoordRec char80_stroke1[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 76.1905, (float) 95.2381 ), + new CoordRec((float) 80.9524, (float) 90.4762 ), + new CoordRec((float) 85.7143, (float) 80.9524 ), + new CoordRec((float) 85.7143, (float) 66.6667 ), + new CoordRec((float) 80.9524, (float) 57.1429 ), + new CoordRec((float) 76.1905, (float) 52.381 ), + new CoordRec((float) 61.9047, (float) 47.619 ), + new CoordRec((float) 19.0476, (float) 47.619 ), +}; + +static final StrokeRec char80[] = { + new StrokeRec( 2, char80_stroke0 ), + new StrokeRec( 10, char80_stroke1 ), +}; + +/* char: 81 'Q' */ + +static final CoordRec char81_stroke0[] = { + new CoordRec((float) 42.8571, (float) 100 ), + new CoordRec((float) 33.3333, (float) 95.2381 ), + new CoordRec((float) 23.8095, (float) 85.7143 ), + new CoordRec((float) 19.0476, (float) 76.1905 ), + new CoordRec((float) 14.2857, (float) 61.9048 ), + new CoordRec((float) 14.2857, (float) 38.0952 ), + new CoordRec((float) 19.0476, (float) 23.8095 ), + new CoordRec((float) 23.8095, (float) 14.2857 ), + new CoordRec((float) 33.3333, (float) 4.7619 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 71.4286, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), + new CoordRec((float) 85.7143, (float) 23.8095 ), + new CoordRec((float) 90.4762, (float) 38.0952 ), + new CoordRec((float) 90.4762, (float) 61.9048 ), + new CoordRec((float) 85.7143, (float) 76.1905 ), + new CoordRec((float) 80.9524, (float) 85.7143 ), + new CoordRec((float) 71.4286, (float) 95.2381 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 42.8571, (float) 100 ), +}; + +static final CoordRec char81_stroke1[] = { + new CoordRec((float) 57.1428, (float) 19.0476 ), + new CoordRec((float) 85.7143, (float) -9.5238 ), +}; + +static final StrokeRec char81[] = { + new StrokeRec( 21, char81_stroke0 ), + new StrokeRec( 2, char81_stroke1 ), +}; + +/* char: 82 'R' */ + +static final CoordRec char82_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final CoordRec char82_stroke1[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 76.1905, (float) 95.2381 ), + new CoordRec((float) 80.9524, (float) 90.4762 ), + new CoordRec((float) 85.7143, (float) 80.9524 ), + new CoordRec((float) 85.7143, (float) 71.4286 ), + new CoordRec((float) 80.9524, (float) 61.9048 ), + new CoordRec((float) 76.1905, (float) 57.1429 ), + new CoordRec((float) 61.9047, (float) 52.381 ), + new CoordRec((float) 19.0476, (float) 52.381 ), +}; + +static final CoordRec char82_stroke2[] = { + new CoordRec((float) 52.3809, (float) 52.381 ), + new CoordRec((float) 85.7143, (float) 0 ), +}; + +static final StrokeRec char82[] = { + new StrokeRec( 2, char82_stroke0 ), + new StrokeRec( 10, char82_stroke1 ), + new StrokeRec( 2, char82_stroke2 ), +}; + +/* char: 83 'S' */ + +static final CoordRec char83_stroke0[] = { + new CoordRec((float) 85.7143, (float) 85.7143 ), + new CoordRec((float) 76.1905, (float) 95.2381 ), + new CoordRec((float) 61.9047, (float) 100 ), + new CoordRec((float) 42.8571, (float) 100 ), + new CoordRec((float) 28.5714, (float) 95.2381 ), + new CoordRec((float) 19.0476, (float) 85.7143 ), + new CoordRec((float) 19.0476, (float) 76.1905 ), + new CoordRec((float) 23.8095, (float) 66.6667 ), + new CoordRec((float) 28.5714, (float) 61.9048 ), + new CoordRec((float) 38.0952, (float) 57.1429 ), + new CoordRec((float) 66.6666, (float) 47.619 ), + new CoordRec((float) 76.1905, (float) 42.8571 ), + new CoordRec((float) 80.9524, (float) 38.0952 ), + new CoordRec((float) 85.7143, (float) 28.5714 ), + new CoordRec((float) 85.7143, (float) 14.2857 ), + new CoordRec((float) 76.1905, (float) 4.7619 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 28.5714, (float) 4.7619 ), + new CoordRec((float) 19.0476, (float) 14.2857 ), +}; + +static final StrokeRec char83[] = { + new StrokeRec( 20, char83_stroke0 ), +}; + +/* char: 84 'T' */ + +static final CoordRec char84_stroke0[] = { + new CoordRec((float) 52.3809, (float) 100 ), + new CoordRec((float) 52.3809, (float) 0 ), +}; + +static final CoordRec char84_stroke1[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 85.7143, (float) 100 ), +}; + +static final StrokeRec char84[] = { + new StrokeRec( 2, char84_stroke0 ), + new StrokeRec( 2, char84_stroke1 ), +}; + +/* char: 85 'U' */ + +static final CoordRec char85_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 19.0476, (float) 28.5714 ), + new CoordRec((float) 23.8095, (float) 14.2857 ), + new CoordRec((float) 33.3333, (float) 4.7619 ), + new CoordRec((float) 47.619, (float) 0 ), + new CoordRec((float) 57.1428, (float) 0 ), + new CoordRec((float) 71.4286, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), + new CoordRec((float) 85.7143, (float) 28.5714 ), + new CoordRec((float) 85.7143, (float) 100 ), +}; + +static final StrokeRec char85[] = { + new StrokeRec( 10, char85_stroke0 ), +}; + +/* char: 86 'V' */ + +static final CoordRec char86_stroke0[] = { + new CoordRec((float) 14.2857, (float) 100 ), + new CoordRec((float) 52.3809, (float) 0 ), +}; + +static final CoordRec char86_stroke1[] = { + new CoordRec((float) 90.4762, (float) 100 ), + new CoordRec((float) 52.3809, (float) 0 ), +}; + +static final StrokeRec char86[] = { + new StrokeRec( 2, char86_stroke0 ), + new StrokeRec( 2, char86_stroke1 ), +}; + +/* char: 87 'W' */ + +static final CoordRec char87_stroke0[] = { + new CoordRec((float) 4.7619, (float) 100 ), + new CoordRec((float) 28.5714, (float) 0 ), +}; + +static final CoordRec char87_stroke1[] = { + new CoordRec((float) 52.3809, (float) 100 ), + new CoordRec((float) 28.5714, (float) 0 ), +}; + +static final CoordRec char87_stroke2[] = { + new CoordRec((float) 52.3809, (float) 100 ), + new CoordRec((float) 76.1905, (float) 0 ), +}; + +static final CoordRec char87_stroke3[] = { + new CoordRec((float) 100, (float) 100 ), + new CoordRec((float) 76.1905, (float) 0 ), +}; + +static final StrokeRec char87[] = { + new StrokeRec( 2, char87_stroke0 ), + new StrokeRec( 2, char87_stroke1 ), + new StrokeRec( 2, char87_stroke2 ), + new StrokeRec( 2, char87_stroke3 ), +}; + +/* char: 88 'X' */ + +static final CoordRec char88_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 85.7143, (float) 0 ), +}; + +static final CoordRec char88_stroke1[] = { + new CoordRec((float) 85.7143, (float) 100 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final StrokeRec char88[] = { + new StrokeRec( 2, char88_stroke0 ), + new StrokeRec( 2, char88_stroke1 ), +}; + +/* char: 89 'Y' */ + +static final CoordRec char89_stroke0[] = { + new CoordRec((float) 14.2857, (float) 100 ), + new CoordRec((float) 52.3809, (float) 52.381 ), + new CoordRec((float) 52.3809, (float) 0 ), +}; + +static final CoordRec char89_stroke1[] = { + new CoordRec((float) 90.4762, (float) 100 ), + new CoordRec((float) 52.3809, (float) 52.381 ), +}; + +static final StrokeRec char89[] = { + new StrokeRec( 3, char89_stroke0 ), + new StrokeRec( 2, char89_stroke1 ), +}; + +/* char: 90 'Z' */ + +static final CoordRec char90_stroke0[] = { + new CoordRec((float) 85.7143, (float) 100 ), + new CoordRec((float) 19.0476, (float) 0 ), +}; + +static final CoordRec char90_stroke1[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 85.7143, (float) 100 ), +}; + +static final CoordRec char90_stroke2[] = { + new CoordRec((float) 19.0476, (float) 0 ), + new CoordRec((float) 85.7143, (float) 0 ), +}; + +static final StrokeRec char90[] = { + new StrokeRec( 2, char90_stroke0 ), + new StrokeRec( 2, char90_stroke1 ), + new StrokeRec( 2, char90_stroke2 ), +}; + +/* char: 91 '[' */ + +static final CoordRec char91_stroke0[] = { + new CoordRec((float) 35.7143, (float) 119.048 ), + new CoordRec((float) 35.7143, (float) -33.3333 ), +}; + +static final CoordRec char91_stroke1[] = { + new CoordRec((float) 40.4762, (float) 119.048 ), + new CoordRec((float) 40.4762, (float) -33.3333 ), +}; + +static final CoordRec char91_stroke2[] = { + new CoordRec((float) 35.7143, (float) 119.048 ), + new CoordRec((float) 69.0476, (float) 119.048 ), +}; + +static final CoordRec char91_stroke3[] = { + new CoordRec((float) 35.7143, (float) -33.3333 ), + new CoordRec((float) 69.0476, (float) -33.3333 ), +}; + +static final StrokeRec char91[] = { + new StrokeRec( 2, char91_stroke0 ), + new StrokeRec( 2, char91_stroke1 ), + new StrokeRec( 2, char91_stroke2 ), + new StrokeRec( 2, char91_stroke3 ), +}; + +/* char: 92 '\' */ + +static final CoordRec char92_stroke0[] = { + new CoordRec((float) 19.0476, (float) 100 ), + new CoordRec((float) 85.7143, (float) -14.2857 ), +}; + +static final StrokeRec char92[] = { + new StrokeRec( 2, char92_stroke0 ), +}; + +/* char: 93 ']' */ + +static final CoordRec char93_stroke0[] = { + new CoordRec((float) 64.2857, (float) 119.048 ), + new CoordRec((float) 64.2857, (float) -33.3333 ), +}; + +static final CoordRec char93_stroke1[] = { + new CoordRec((float) 69.0476, (float) 119.048 ), + new CoordRec((float) 69.0476, (float) -33.3333 ), +}; + +static final CoordRec char93_stroke2[] = { + new CoordRec((float) 35.7143, (float) 119.048 ), + new CoordRec((float) 69.0476, (float) 119.048 ), +}; + +static final CoordRec char93_stroke3[] = { + new CoordRec((float) 35.7143, (float) -33.3333 ), + new CoordRec((float) 69.0476, (float) -33.3333 ), +}; + +static final StrokeRec char93[] = { + new StrokeRec( 2, char93_stroke0 ), + new StrokeRec( 2, char93_stroke1 ), + new StrokeRec( 2, char93_stroke2 ), + new StrokeRec( 2, char93_stroke3 ), +}; + +/* char: 94 '^' */ + +static final CoordRec char94_stroke0[] = { + new CoordRec((float) 52.3809, (float) 109.524 ), + new CoordRec((float) 14.2857, (float) 42.8571 ), +}; + +static final CoordRec char94_stroke1[] = { + new CoordRec((float) 52.3809, (float) 109.524 ), + new CoordRec((float) 90.4762, (float) 42.8571 ), +}; + +static final StrokeRec char94[] = { + new StrokeRec( 2, char94_stroke0 ), + new StrokeRec( 2, char94_stroke1 ), +}; + +/* char: 95 '_' */ + +static final CoordRec char95_stroke0[] = { + new CoordRec((float) 0, (float) -33.3333 ), + new CoordRec((float) 104.762, (float) -33.3333 ), + new CoordRec((float) 104.762, (float) -28.5714 ), + new CoordRec((float) 0, (float) -28.5714 ), + new CoordRec((float) 0, (float) -33.3333 ), +}; + +static final StrokeRec char95[] = { + new StrokeRec( 5, char95_stroke0 ), +}; + +/* char: 96 '`' */ + +static final CoordRec char96_stroke0[] = { + new CoordRec((float) 42.8572, (float) 100 ), + new CoordRec((float) 66.6667, (float) 71.4286 ), +}; + +static final CoordRec char96_stroke1[] = { + new CoordRec((float) 42.8572, (float) 100 ), + new CoordRec((float) 38.0953, (float) 95.2381 ), + new CoordRec((float) 66.6667, (float) 71.4286 ), +}; + +static final StrokeRec char96[] = { + new StrokeRec( 2, char96_stroke0 ), + new StrokeRec( 3, char96_stroke1 ), +}; + +/* char: 97 'a' */ + +static final CoordRec char97_stroke0[] = { + new CoordRec((float) 80.9524, (float) 66.6667 ), + new CoordRec((float) 80.9524, (float) 0 ), +}; + +static final CoordRec char97_stroke1[] = { + new CoordRec((float) 80.9524, (float) 52.381 ), + new CoordRec((float) 71.4285, (float) 61.9048 ), + new CoordRec((float) 61.9047, (float) 66.6667 ), + new CoordRec((float) 47.619, (float) 66.6667 ), + new CoordRec((float) 38.0952, (float) 61.9048 ), + new CoordRec((float) 28.5714, (float) 52.381 ), + new CoordRec((float) 23.8095, (float) 38.0952 ), + new CoordRec((float) 23.8095, (float) 28.5714 ), + new CoordRec((float) 28.5714, (float) 14.2857 ), + new CoordRec((float) 38.0952, (float) 4.7619 ), + new CoordRec((float) 47.619, (float) 0 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 71.4285, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), +}; + +static final StrokeRec char97[] = { + new StrokeRec( 2, char97_stroke0 ), + new StrokeRec( 14, char97_stroke1 ), +}; + +/* char: 98 'b' */ + +static final CoordRec char98_stroke0[] = { + new CoordRec((float) 23.8095, (float) 100 ), + new CoordRec((float) 23.8095, (float) 0 ), +}; + +static final CoordRec char98_stroke1[] = { + new CoordRec((float) 23.8095, (float) 52.381 ), + new CoordRec((float) 33.3333, (float) 61.9048 ), + new CoordRec((float) 42.8571, (float) 66.6667 ), + new CoordRec((float) 57.1428, (float) 66.6667 ), + new CoordRec((float) 66.6666, (float) 61.9048 ), + new CoordRec((float) 76.1905, (float) 52.381 ), + new CoordRec((float) 80.9524, (float) 38.0952 ), + new CoordRec((float) 80.9524, (float) 28.5714 ), + new CoordRec((float) 76.1905, (float) 14.2857 ), + new CoordRec((float) 66.6666, (float) 4.7619 ), + new CoordRec((float) 57.1428, (float) 0 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 33.3333, (float) 4.7619 ), + new CoordRec((float) 23.8095, (float) 14.2857 ), +}; + +static final StrokeRec char98[] = { + new StrokeRec( 2, char98_stroke0 ), + new StrokeRec( 14, char98_stroke1 ), +}; + +/* char: 99 'c' */ + +static final CoordRec char99_stroke0[] = { + new CoordRec((float) 80.9524, (float) 52.381 ), + new CoordRec((float) 71.4285, (float) 61.9048 ), + new CoordRec((float) 61.9047, (float) 66.6667 ), + new CoordRec((float) 47.619, (float) 66.6667 ), + new CoordRec((float) 38.0952, (float) 61.9048 ), + new CoordRec((float) 28.5714, (float) 52.381 ), + new CoordRec((float) 23.8095, (float) 38.0952 ), + new CoordRec((float) 23.8095, (float) 28.5714 ), + new CoordRec((float) 28.5714, (float) 14.2857 ), + new CoordRec((float) 38.0952, (float) 4.7619 ), + new CoordRec((float) 47.619, (float) 0 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 71.4285, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), +}; + +static final StrokeRec char99[] = { + new StrokeRec( 14, char99_stroke0 ), +}; + +/* char: 100 'd' */ + +static final CoordRec char100_stroke0[] = { + new CoordRec((float) 80.9524, (float) 100 ), + new CoordRec((float) 80.9524, (float) 0 ), +}; + +static final CoordRec char100_stroke1[] = { + new CoordRec((float) 80.9524, (float) 52.381 ), + new CoordRec((float) 71.4285, (float) 61.9048 ), + new CoordRec((float) 61.9047, (float) 66.6667 ), + new CoordRec((float) 47.619, (float) 66.6667 ), + new CoordRec((float) 38.0952, (float) 61.9048 ), + new CoordRec((float) 28.5714, (float) 52.381 ), + new CoordRec((float) 23.8095, (float) 38.0952 ), + new CoordRec((float) 23.8095, (float) 28.5714 ), + new CoordRec((float) 28.5714, (float) 14.2857 ), + new CoordRec((float) 38.0952, (float) 4.7619 ), + new CoordRec((float) 47.619, (float) 0 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 71.4285, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), +}; + +static final StrokeRec char100[] = { + new StrokeRec( 2, char100_stroke0 ), + new StrokeRec( 14, char100_stroke1 ), +}; + +/* char: 101 'e' */ + +static final CoordRec char101_stroke0[] = { + new CoordRec((float) 23.8095, (float) 38.0952 ), + new CoordRec((float) 80.9524, (float) 38.0952 ), + new CoordRec((float) 80.9524, (float) 47.619 ), + new CoordRec((float) 76.1905, (float) 57.1429 ), + new CoordRec((float) 71.4285, (float) 61.9048 ), + new CoordRec((float) 61.9047, (float) 66.6667 ), + new CoordRec((float) 47.619, (float) 66.6667 ), + new CoordRec((float) 38.0952, (float) 61.9048 ), + new CoordRec((float) 28.5714, (float) 52.381 ), + new CoordRec((float) 23.8095, (float) 38.0952 ), + new CoordRec((float) 23.8095, (float) 28.5714 ), + new CoordRec((float) 28.5714, (float) 14.2857 ), + new CoordRec((float) 38.0952, (float) 4.7619 ), + new CoordRec((float) 47.619, (float) 0 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 71.4285, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), +}; + +static final StrokeRec char101[] = { + new StrokeRec( 17, char101_stroke0 ), +}; + +/* char: 102 'f' */ + +static final CoordRec char102_stroke0[] = { + new CoordRec((float) 71.4286, (float) 100 ), + new CoordRec((float) 61.9048, (float) 100 ), + new CoordRec((float) 52.381, (float) 95.2381 ), + new CoordRec((float) 47.6191, (float) 80.9524 ), + new CoordRec((float) 47.6191, (float) 0 ), +}; + +static final CoordRec char102_stroke1[] = { + new CoordRec((float) 33.3334, (float) 66.6667 ), + new CoordRec((float) 66.6667, (float) 66.6667 ), +}; + +static final StrokeRec char102[] = { + new StrokeRec( 5, char102_stroke0 ), + new StrokeRec( 2, char102_stroke1 ), +}; + +/* char: 103 'g' */ + +static final CoordRec char103_stroke0[] = { + new CoordRec((float) 80.9524, (float) 66.6667 ), + new CoordRec((float) 80.9524, (float) -9.5238 ), + new CoordRec((float) 76.1905, (float) -23.8095 ), + new CoordRec((float) 71.4285, (float) -28.5714 ), + new CoordRec((float) 61.9047, (float) -33.3333 ), + new CoordRec((float) 47.619, (float) -33.3333 ), + new CoordRec((float) 38.0952, (float) -28.5714 ), +}; + +static final CoordRec char103_stroke1[] = { + new CoordRec((float) 80.9524, (float) 52.381 ), + new CoordRec((float) 71.4285, (float) 61.9048 ), + new CoordRec((float) 61.9047, (float) 66.6667 ), + new CoordRec((float) 47.619, (float) 66.6667 ), + new CoordRec((float) 38.0952, (float) 61.9048 ), + new CoordRec((float) 28.5714, (float) 52.381 ), + new CoordRec((float) 23.8095, (float) 38.0952 ), + new CoordRec((float) 23.8095, (float) 28.5714 ), + new CoordRec((float) 28.5714, (float) 14.2857 ), + new CoordRec((float) 38.0952, (float) 4.7619 ), + new CoordRec((float) 47.619, (float) 0 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 71.4285, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), +}; + +static final StrokeRec char103[] = { + new StrokeRec( 7, char103_stroke0 ), + new StrokeRec( 14, char103_stroke1 ), +}; + +/* char: 104 'h' */ + +static final CoordRec char104_stroke0[] = { + new CoordRec((float) 26.1905, (float) 100 ), + new CoordRec((float) 26.1905, (float) 0 ), +}; + +static final CoordRec char104_stroke1[] = { + new CoordRec((float) 26.1905, (float) 47.619 ), + new CoordRec((float) 40.4762, (float) 61.9048 ), + new CoordRec((float) 50, (float) 66.6667 ), + new CoordRec((float) 64.2857, (float) 66.6667 ), + new CoordRec((float) 73.8095, (float) 61.9048 ), + new CoordRec((float) 78.5715, (float) 47.619 ), + new CoordRec((float) 78.5715, (float) 0 ), +}; + +static final StrokeRec char104[] = { + new StrokeRec( 2, char104_stroke0 ), + new StrokeRec( 7, char104_stroke1 ), +}; + +/* char: 105 'i' */ + +static final CoordRec char105_stroke0[] = { + new CoordRec((float) 47.6191, (float) 100 ), + new CoordRec((float) 52.381, (float) 95.2381 ), + new CoordRec((float) 57.1429, (float) 100 ), + new CoordRec((float) 52.381, (float) 104.762 ), + new CoordRec((float) 47.6191, (float) 100 ), +}; + +static final CoordRec char105_stroke1[] = { + new CoordRec((float) 52.381, (float) 66.6667 ), + new CoordRec((float) 52.381, (float) 0 ), +}; + +static final StrokeRec char105[] = { + new StrokeRec( 5, char105_stroke0 ), + new StrokeRec( 2, char105_stroke1 ), +}; + +/* char: 106 'j' */ + +static final CoordRec char106_stroke0[] = { + new CoordRec((float) 57.1429, (float) 100 ), + new CoordRec((float) 61.9048, (float) 95.2381 ), + new CoordRec((float) 66.6667, (float) 100 ), + new CoordRec((float) 61.9048, (float) 104.762 ), + new CoordRec((float) 57.1429, (float) 100 ), +}; + +static final CoordRec char106_stroke1[] = { + new CoordRec((float) 61.9048, (float) 66.6667 ), + new CoordRec((float) 61.9048, (float) -14.2857 ), + new CoordRec((float) 57.1429, (float) -28.5714 ), + new CoordRec((float) 47.6191, (float) -33.3333 ), + new CoordRec((float) 38.0953, (float) -33.3333 ), +}; + +static final StrokeRec char106[] = { + new StrokeRec( 5, char106_stroke0 ), + new StrokeRec( 5, char106_stroke1 ), +}; + +/* char: 107 'k' */ + +static final CoordRec char107_stroke0[] = { + new CoordRec((float) 26.1905, (float) 100 ), + new CoordRec((float) 26.1905, (float) 0 ), +}; + +static final CoordRec char107_stroke1[] = { + new CoordRec((float) 73.8095, (float) 66.6667 ), + new CoordRec((float) 26.1905, (float) 19.0476 ), +}; + +static final CoordRec char107_stroke2[] = { + new CoordRec((float) 45.2381, (float) 38.0952 ), + new CoordRec((float) 78.5715, (float) 0 ), +}; + +static final StrokeRec char107[] = { + new StrokeRec( 2, char107_stroke0 ), + new StrokeRec( 2, char107_stroke1 ), + new StrokeRec( 2, char107_stroke2 ), +}; + +/* char: 108 'l' */ + +static final CoordRec char108_stroke0[] = { + new CoordRec((float) 52.381, (float) 100 ), + new CoordRec((float) 52.381, (float) 0 ), +}; + +static final StrokeRec char108[] = { + new StrokeRec( 2, char108_stroke0 ), +}; + +/* char: 109 'm' */ + +static final CoordRec char109_stroke0[] = { + new CoordRec((float) 0, (float) 66.6667 ), + new CoordRec((float) 0, (float) 0 ), +}; + +static final CoordRec char109_stroke1[] = { + new CoordRec((float) 0, (float) 47.619 ), + new CoordRec((float) 14.2857, (float) 61.9048 ), + new CoordRec((float) 23.8095, (float) 66.6667 ), + new CoordRec((float) 38.0952, (float) 66.6667 ), + new CoordRec((float) 47.619, (float) 61.9048 ), + new CoordRec((float) 52.381, (float) 47.619 ), + new CoordRec((float) 52.381, (float) 0 ), +}; + +static final CoordRec char109_stroke2[] = { + new CoordRec((float) 52.381, (float) 47.619 ), + new CoordRec((float) 66.6667, (float) 61.9048 ), + new CoordRec((float) 76.1905, (float) 66.6667 ), + new CoordRec((float) 90.4762, (float) 66.6667 ), + new CoordRec((float) 100, (float) 61.9048 ), + new CoordRec((float) 104.762, (float) 47.619 ), + new CoordRec((float) 104.762, (float) 0 ), +}; + +static final StrokeRec char109[] = { + new StrokeRec( 2, char109_stroke0 ), + new StrokeRec( 7, char109_stroke1 ), + new StrokeRec( 7, char109_stroke2 ), +}; + +/* char: 110 'n' */ + +static final CoordRec char110_stroke0[] = { + new CoordRec((float) 26.1905, (float) 66.6667 ), + new CoordRec((float) 26.1905, (float) 0 ), +}; + +static final CoordRec char110_stroke1[] = { + new CoordRec((float) 26.1905, (float) 47.619 ), + new CoordRec((float) 40.4762, (float) 61.9048 ), + new CoordRec((float) 50, (float) 66.6667 ), + new CoordRec((float) 64.2857, (float) 66.6667 ), + new CoordRec((float) 73.8095, (float) 61.9048 ), + new CoordRec((float) 78.5715, (float) 47.619 ), + new CoordRec((float) 78.5715, (float) 0 ), +}; + +static final StrokeRec char110[] = { + new StrokeRec( 2, char110_stroke0 ), + new StrokeRec( 7, char110_stroke1 ), +}; + +/* char: 111 'o' */ + +static final CoordRec char111_stroke0[] = { + new CoordRec((float) 45.2381, (float) 66.6667 ), + new CoordRec((float) 35.7143, (float) 61.9048 ), + new CoordRec((float) 26.1905, (float) 52.381 ), + new CoordRec((float) 21.4286, (float) 38.0952 ), + new CoordRec((float) 21.4286, (float) 28.5714 ), + new CoordRec((float) 26.1905, (float) 14.2857 ), + new CoordRec((float) 35.7143, (float) 4.7619 ), + new CoordRec((float) 45.2381, (float) 0 ), + new CoordRec((float) 59.5238, (float) 0 ), + new CoordRec((float) 69.0476, (float) 4.7619 ), + new CoordRec((float) 78.5714, (float) 14.2857 ), + new CoordRec((float) 83.3334, (float) 28.5714 ), + new CoordRec((float) 83.3334, (float) 38.0952 ), + new CoordRec((float) 78.5714, (float) 52.381 ), + new CoordRec((float) 69.0476, (float) 61.9048 ), + new CoordRec((float) 59.5238, (float) 66.6667 ), + new CoordRec((float) 45.2381, (float) 66.6667 ), +}; + +static final StrokeRec char111[] = { + new StrokeRec( 17, char111_stroke0 ), +}; + +/* char: 112 'p' */ + +static final CoordRec char112_stroke0[] = { + new CoordRec((float) 23.8095, (float) 66.6667 ), + new CoordRec((float) 23.8095, (float) -33.3333 ), +}; + +static final CoordRec char112_stroke1[] = { + new CoordRec((float) 23.8095, (float) 52.381 ), + new CoordRec((float) 33.3333, (float) 61.9048 ), + new CoordRec((float) 42.8571, (float) 66.6667 ), + new CoordRec((float) 57.1428, (float) 66.6667 ), + new CoordRec((float) 66.6666, (float) 61.9048 ), + new CoordRec((float) 76.1905, (float) 52.381 ), + new CoordRec((float) 80.9524, (float) 38.0952 ), + new CoordRec((float) 80.9524, (float) 28.5714 ), + new CoordRec((float) 76.1905, (float) 14.2857 ), + new CoordRec((float) 66.6666, (float) 4.7619 ), + new CoordRec((float) 57.1428, (float) 0 ), + new CoordRec((float) 42.8571, (float) 0 ), + new CoordRec((float) 33.3333, (float) 4.7619 ), + new CoordRec((float) 23.8095, (float) 14.2857 ), +}; + +static final StrokeRec char112[] = { + new StrokeRec( 2, char112_stroke0 ), + new StrokeRec( 14, char112_stroke1 ), +}; + +/* char: 113 'q' */ + +static final CoordRec char113_stroke0[] = { + new CoordRec((float) 80.9524, (float) 66.6667 ), + new CoordRec((float) 80.9524, (float) -33.3333 ), +}; + +static final CoordRec char113_stroke1[] = { + new CoordRec((float) 80.9524, (float) 52.381 ), + new CoordRec((float) 71.4285, (float) 61.9048 ), + new CoordRec((float) 61.9047, (float) 66.6667 ), + new CoordRec((float) 47.619, (float) 66.6667 ), + new CoordRec((float) 38.0952, (float) 61.9048 ), + new CoordRec((float) 28.5714, (float) 52.381 ), + new CoordRec((float) 23.8095, (float) 38.0952 ), + new CoordRec((float) 23.8095, (float) 28.5714 ), + new CoordRec((float) 28.5714, (float) 14.2857 ), + new CoordRec((float) 38.0952, (float) 4.7619 ), + new CoordRec((float) 47.619, (float) 0 ), + new CoordRec((float) 61.9047, (float) 0 ), + new CoordRec((float) 71.4285, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), +}; + +static final StrokeRec char113[] = { + new StrokeRec( 2, char113_stroke0 ), + new StrokeRec( 14, char113_stroke1 ), +}; + +/* char: 114 'r' */ + +static final CoordRec char114_stroke0[] = { + new CoordRec((float) 33.3334, (float) 66.6667 ), + new CoordRec((float) 33.3334, (float) 0 ), +}; + +static final CoordRec char114_stroke1[] = { + new CoordRec((float) 33.3334, (float) 38.0952 ), + new CoordRec((float) 38.0953, (float) 52.381 ), + new CoordRec((float) 47.6191, (float) 61.9048 ), + new CoordRec((float) 57.1429, (float) 66.6667 ), + new CoordRec((float) 71.4286, (float) 66.6667 ), +}; + +static final StrokeRec char114[] = { + new StrokeRec( 2, char114_stroke0 ), + new StrokeRec( 5, char114_stroke1 ), +}; + +/* char: 115 's' */ + +static final CoordRec char115_stroke0[] = { + new CoordRec((float) 78.5715, (float) 52.381 ), + new CoordRec((float) 73.8095, (float) 61.9048 ), + new CoordRec((float) 59.5238, (float) 66.6667 ), + new CoordRec((float) 45.2381, (float) 66.6667 ), + new CoordRec((float) 30.9524, (float) 61.9048 ), + new CoordRec((float) 26.1905, (float) 52.381 ), + new CoordRec((float) 30.9524, (float) 42.8571 ), + new CoordRec((float) 40.4762, (float) 38.0952 ), + new CoordRec((float) 64.2857, (float) 33.3333 ), + new CoordRec((float) 73.8095, (float) 28.5714 ), + new CoordRec((float) 78.5715, (float) 19.0476 ), + new CoordRec((float) 78.5715, (float) 14.2857 ), + new CoordRec((float) 73.8095, (float) 4.7619 ), + new CoordRec((float) 59.5238, (float) 0 ), + new CoordRec((float) 45.2381, (float) 0 ), + new CoordRec((float) 30.9524, (float) 4.7619 ), + new CoordRec((float) 26.1905, (float) 14.2857 ), +}; + +static final StrokeRec char115[] = { + new StrokeRec( 17, char115_stroke0 ), +}; + +/* char: 116 't' */ + +static final CoordRec char116_stroke0[] = { + new CoordRec((float) 47.6191, (float) 100 ), + new CoordRec((float) 47.6191, (float) 19.0476 ), + new CoordRec((float) 52.381, (float) 4.7619 ), + new CoordRec((float) 61.9048, (float) 0 ), + new CoordRec((float) 71.4286, (float) 0 ), +}; + +static final CoordRec char116_stroke1[] = { + new CoordRec((float) 33.3334, (float) 66.6667 ), + new CoordRec((float) 66.6667, (float) 66.6667 ), +}; + +static final StrokeRec char116[] = { + new StrokeRec( 5, char116_stroke0 ), + new StrokeRec( 2, char116_stroke1 ), +}; + +/* char: 117 'u' */ + +static final CoordRec char117_stroke0[] = { + new CoordRec((float) 26.1905, (float) 66.6667 ), + new CoordRec((float) 26.1905, (float) 19.0476 ), + new CoordRec((float) 30.9524, (float) 4.7619 ), + new CoordRec((float) 40.4762, (float) 0 ), + new CoordRec((float) 54.7619, (float) 0 ), + new CoordRec((float) 64.2857, (float) 4.7619 ), + new CoordRec((float) 78.5715, (float) 19.0476 ), +}; + +static final CoordRec char117_stroke1[] = { + new CoordRec((float) 78.5715, (float) 66.6667 ), + new CoordRec((float) 78.5715, (float) 0 ), +}; + +static final StrokeRec char117[] = { + new StrokeRec( 7, char117_stroke0 ), + new StrokeRec( 2, char117_stroke1 ), +}; + +/* char: 118 'v' */ + +static final CoordRec char118_stroke0[] = { + new CoordRec((float) 23.8095, (float) 66.6667 ), + new CoordRec((float) 52.3809, (float) 0 ), +}; + +static final CoordRec char118_stroke1[] = { + new CoordRec((float) 80.9524, (float) 66.6667 ), + new CoordRec((float) 52.3809, (float) 0 ), +}; + +static final StrokeRec char118[] = { + new StrokeRec( 2, char118_stroke0 ), + new StrokeRec( 2, char118_stroke1 ), +}; + +/* char: 119 'w' */ + +static final CoordRec char119_stroke0[] = { + new CoordRec((float) 14.2857, (float) 66.6667 ), + new CoordRec((float) 33.3333, (float) 0 ), +}; + +static final CoordRec char119_stroke1[] = { + new CoordRec((float) 52.3809, (float) 66.6667 ), + new CoordRec((float) 33.3333, (float) 0 ), +}; + +static final CoordRec char119_stroke2[] = { + new CoordRec((float) 52.3809, (float) 66.6667 ), + new CoordRec((float) 71.4286, (float) 0 ), +}; + +static final CoordRec char119_stroke3[] = { + new CoordRec((float) 90.4762, (float) 66.6667 ), + new CoordRec((float) 71.4286, (float) 0 ), +}; + +static final StrokeRec char119[] = { + new StrokeRec( 2, char119_stroke0 ), + new StrokeRec( 2, char119_stroke1 ), + new StrokeRec( 2, char119_stroke2 ), + new StrokeRec( 2, char119_stroke3 ), +}; + +/* char: 120 'x' */ + +static final CoordRec char120_stroke0[] = { + new CoordRec((float) 26.1905, (float) 66.6667 ), + new CoordRec((float) 78.5715, (float) 0 ), +}; + +static final CoordRec char120_stroke1[] = { + new CoordRec((float) 78.5715, (float) 66.6667 ), + new CoordRec((float) 26.1905, (float) 0 ), +}; + +static final StrokeRec char120[] = { + new StrokeRec( 2, char120_stroke0 ), + new StrokeRec( 2, char120_stroke1 ), +}; + +/* char: 121 'y' */ + +static final CoordRec char121_stroke0[] = { + new CoordRec((float) 26.1905, (float) 66.6667 ), + new CoordRec((float) 54.7619, (float) 0 ), +}; + +static final CoordRec char121_stroke1[] = { + new CoordRec((float) 83.3334, (float) 66.6667 ), + new CoordRec((float) 54.7619, (float) 0 ), + new CoordRec((float) 45.2381, (float) -19.0476 ), + new CoordRec((float) 35.7143, (float) -28.5714 ), + new CoordRec((float) 26.1905, (float) -33.3333 ), + new CoordRec((float) 21.4286, (float) -33.3333 ), +}; + +static final StrokeRec char121[] = { + new StrokeRec( 2, char121_stroke0 ), + new StrokeRec( 6, char121_stroke1 ), +}; + +/* char: 122 'z' */ + +static final CoordRec char122_stroke0[] = { + new CoordRec((float) 78.5715, (float) 66.6667 ), + new CoordRec((float) 26.1905, (float) 0 ), +}; + +static final CoordRec char122_stroke1[] = { + new CoordRec((float) 26.1905, (float) 66.6667 ), + new CoordRec((float) 78.5715, (float) 66.6667 ), +}; + +static final CoordRec char122_stroke2[] = { + new CoordRec((float) 26.1905, (float) 0 ), + new CoordRec((float) 78.5715, (float) 0 ), +}; + +static final StrokeRec char122[] = { + new StrokeRec( 2, char122_stroke0 ), + new StrokeRec( 2, char122_stroke1 ), + new StrokeRec( 2, char122_stroke2 ), +}; + +/* char: 123 '{' */ + +static final CoordRec char123_stroke0[] = { + new CoordRec((float) 64.2857, (float) 119.048 ), + new CoordRec((float) 54.7619, (float) 114.286 ), + new CoordRec((float) 50, (float) 109.524 ), + new CoordRec((float) 45.2381, (float) 100 ), + new CoordRec((float) 45.2381, (float) 90.4762 ), + new CoordRec((float) 50, (float) 80.9524 ), + new CoordRec((float) 54.7619, (float) 76.1905 ), + new CoordRec((float) 59.5238, (float) 66.6667 ), + new CoordRec((float) 59.5238, (float) 57.1429 ), + new CoordRec((float) 50, (float) 47.619 ), +}; + +static final CoordRec char123_stroke1[] = { + new CoordRec((float) 54.7619, (float) 114.286 ), + new CoordRec((float) 50, (float) 104.762 ), + new CoordRec((float) 50, (float) 95.2381 ), + new CoordRec((float) 54.7619, (float) 85.7143 ), + new CoordRec((float) 59.5238, (float) 80.9524 ), + new CoordRec((float) 64.2857, (float) 71.4286 ), + new CoordRec((float) 64.2857, (float) 61.9048 ), + new CoordRec((float) 59.5238, (float) 52.381 ), + new CoordRec((float) 40.4762, (float) 42.8571 ), + new CoordRec((float) 59.5238, (float) 33.3333 ), + new CoordRec((float) 64.2857, (float) 23.8095 ), + new CoordRec((float) 64.2857, (float) 14.2857 ), + new CoordRec((float) 59.5238, (float) 4.7619 ), + new CoordRec((float) 54.7619, (float) 0 ), + new CoordRec((float) 50, (float) -9.5238 ), + new CoordRec((float) 50, (float) -19.0476 ), + new CoordRec((float) 54.7619, (float) -28.5714 ), +}; + +static final CoordRec char123_stroke2[] = { + new CoordRec((float) 50, (float) 38.0952 ), + new CoordRec((float) 59.5238, (float) 28.5714 ), + new CoordRec((float) 59.5238, (float) 19.0476 ), + new CoordRec((float) 54.7619, (float) 9.5238 ), + new CoordRec((float) 50, (float) 4.7619 ), + new CoordRec((float) 45.2381, (float) -4.7619 ), + new CoordRec((float) 45.2381, (float) -14.2857 ), + new CoordRec((float) 50, (float) -23.8095 ), + new CoordRec((float) 54.7619, (float) -28.5714 ), + new CoordRec((float) 64.2857, (float) -33.3333 ), +}; + +static final StrokeRec char123[] = { + new StrokeRec( 10, char123_stroke0 ), + new StrokeRec( 17, char123_stroke1 ), + new StrokeRec( 10, char123_stroke2 ), +}; + +/* char: 124 '|' */ + +static final CoordRec char124_stroke0[] = { + new CoordRec((float) 52.381, (float) 119.048 ), + new CoordRec((float) 52.381, (float) -33.3333 ), +}; + +static final StrokeRec char124[] = { + new StrokeRec( 2, char124_stroke0 ), +}; + +/* char: 125 '}' */ + +static final CoordRec char125_stroke0[] = { + new CoordRec((float) 40.4762, (float) 119.048 ), + new CoordRec((float) 50, (float) 114.286 ), + new CoordRec((float) 54.7619, (float) 109.524 ), + new CoordRec((float) 59.5238, (float) 100 ), + new CoordRec((float) 59.5238, (float) 90.4762 ), + new CoordRec((float) 54.7619, (float) 80.9524 ), + new CoordRec((float) 50, (float) 76.1905 ), + new CoordRec((float) 45.2381, (float) 66.6667 ), + new CoordRec((float) 45.2381, (float) 57.1429 ), + new CoordRec((float) 54.7619, (float) 47.619 ), +}; + +static final CoordRec char125_stroke1[] = { + new CoordRec((float) 50, (float) 114.286 ), + new CoordRec((float) 54.7619, (float) 104.762 ), + new CoordRec((float) 54.7619, (float) 95.2381 ), + new CoordRec((float) 50, (float) 85.7143 ), + new CoordRec((float) 45.2381, (float) 80.9524 ), + new CoordRec((float) 40.4762, (float) 71.4286 ), + new CoordRec((float) 40.4762, (float) 61.9048 ), + new CoordRec((float) 45.2381, (float) 52.381 ), + new CoordRec((float) 64.2857, (float) 42.8571 ), + new CoordRec((float) 45.2381, (float) 33.3333 ), + new CoordRec((float) 40.4762, (float) 23.8095 ), + new CoordRec((float) 40.4762, (float) 14.2857 ), + new CoordRec((float) 45.2381, (float) 4.7619 ), + new CoordRec((float) 50, (float) 0 ), + new CoordRec((float) 54.7619, (float) -9.5238 ), + new CoordRec((float) 54.7619, (float) -19.0476 ), + new CoordRec((float) 50, (float) -28.5714 ), +}; + +static final CoordRec char125_stroke2[] = { + new CoordRec((float) 54.7619, (float) 38.0952 ), + new CoordRec((float) 45.2381, (float) 28.5714 ), + new CoordRec((float) 45.2381, (float) 19.0476 ), + new CoordRec((float) 50, (float) 9.5238 ), + new CoordRec((float) 54.7619, (float) 4.7619 ), + new CoordRec((float) 59.5238, (float) -4.7619 ), + new CoordRec((float) 59.5238, (float) -14.2857 ), + new CoordRec((float) 54.7619, (float) -23.8095 ), + new CoordRec((float) 50, (float) -28.5714 ), + new CoordRec((float) 40.4762, (float) -33.3333 ), +}; + +static final StrokeRec char125[] = { + new StrokeRec( 10, char125_stroke0 ), + new StrokeRec( 17, char125_stroke1 ), + new StrokeRec( 10, char125_stroke2 ), +}; + +/* char: 126 '~' */ + +static final CoordRec char126_stroke0[] = { + new CoordRec((float) 9.5238, (float) 28.5714 ), + new CoordRec((float) 9.5238, (float) 38.0952 ), + new CoordRec((float) 14.2857, (float) 52.381 ), + new CoordRec((float) 23.8095, (float) 57.1429 ), + new CoordRec((float) 33.3333, (float) 57.1429 ), + new CoordRec((float) 42.8571, (float) 52.381 ), + new CoordRec((float) 61.9048, (float) 38.0952 ), + new CoordRec((float) 71.4286, (float) 33.3333 ), + new CoordRec((float) 80.9524, (float) 33.3333 ), + new CoordRec((float) 90.4762, (float) 38.0952 ), + new CoordRec((float) 95.2381, (float) 47.619 ), +}; + +static final CoordRec char126_stroke1[] = { + new CoordRec((float) 9.5238, (float) 38.0952 ), + new CoordRec((float) 14.2857, (float) 47.619 ), + new CoordRec((float) 23.8095, (float) 52.381 ), + new CoordRec((float) 33.3333, (float) 52.381 ), + new CoordRec((float) 42.8571, (float) 47.619 ), + new CoordRec((float) 61.9048, (float) 33.3333 ), + new CoordRec((float) 71.4286, (float) 28.5714 ), + new CoordRec((float) 80.9524, (float) 28.5714 ), + new CoordRec((float) 90.4762, (float) 33.3333 ), + new CoordRec((float) 95.2381, (float) 47.619 ), + new CoordRec((float) 95.2381, (float) 57.1429 ), +}; + +static final StrokeRec char126[] = { + new StrokeRec( 11, char126_stroke0 ), + new StrokeRec( 11, char126_stroke1 ), +}; + +/* char: 127 */ + +static final CoordRec char127_stroke0[] = { + new CoordRec((float) 71.4286, (float) 100 ), + new CoordRec((float) 33.3333, (float) -33.3333 ), +}; + +static final CoordRec char127_stroke1[] = { + new CoordRec((float) 47.619, (float) 66.6667 ), + new CoordRec((float) 33.3333, (float) 61.9048 ), + new CoordRec((float) 23.8095, (float) 52.381 ), + new CoordRec((float) 19.0476, (float) 38.0952 ), + new CoordRec((float) 19.0476, (float) 23.8095 ), + new CoordRec((float) 23.8095, (float) 14.2857 ), + new CoordRec((float) 33.3333, (float) 4.7619 ), + new CoordRec((float) 47.619, (float) 0 ), + new CoordRec((float) 57.1428, (float) 0 ), + new CoordRec((float) 71.4286, (float) 4.7619 ), + new CoordRec((float) 80.9524, (float) 14.2857 ), + new CoordRec((float) 85.7143, (float) 28.5714 ), + new CoordRec((float) 85.7143, (float) 42.8571 ), + new CoordRec((float) 80.9524, (float) 52.381 ), + new CoordRec((float) 71.4286, (float) 61.9048 ), + new CoordRec((float) 57.1428, (float) 66.6667 ), + new CoordRec((float) 47.619, (float) 66.6667 ), +}; + +static final StrokeRec char127[] = { + new StrokeRec( 2, char127_stroke0 ), + new StrokeRec( 17, char127_stroke1 ), +}; + +static final StrokeCharRec chars[] = { + new StrokeCharRec(0, /* char0 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char1 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char2 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char3 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char4 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char5 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char6 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char7 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char8 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char9 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char10 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char11 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char12 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char13 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char14 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char15 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char16 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char17 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char18 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char19 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char20 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char21 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char22 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char23 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char24 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char25 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char26 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char27 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char28 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char29 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char30 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char31 */ null, (float) 0, (float) 0 ), + new StrokeCharRec(0, /* char32 */ null, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char33, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char34, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(4, char35, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char36, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char37, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char38, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char39, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char40, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char41, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char42, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char43, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char44, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char45, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char46, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char47, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char48, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char49, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char50, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char51, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char52, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char53, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char54, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char55, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char56, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char57, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char58, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char59, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char60, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char61, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char62, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char63, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char64, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char65, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char66, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char67, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char68, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(4, char69, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char70, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char71, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char72, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char73, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char74, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char75, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char76, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(4, char77, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char78, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char79, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char80, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char81, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char82, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char83, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char84, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char85, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char86, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(4, char87, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char88, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char89, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char90, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(4, char91, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char92, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(4, char93, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char94, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char95, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char96, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char97, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char98, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char99, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char100, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char101, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char102, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char103, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char104, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char105, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char106, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char107, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char108, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char109, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char110, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char111, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char112, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char113, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char114, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char115, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char116, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char117, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char118, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(4, char119, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char120, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char121, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char122, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char123, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(1, char124, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(3, char125, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char126, (float) 52.381, (float) 104.762 ), + new StrokeCharRec(2, char127, (float) 52.381, (float) 104.762 ), +}; + +public static final StrokeFontRec glutStrokeMonoRoman = new StrokeFontRec( "Roman", 128, chars, (float) 119.048, (float) -33.3333 ); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTStrokeRoman.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTStrokeRoman.java new file mode 100644 index 000000000..94fa1c4fd --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUTStrokeRoman.java @@ -0,0 +1,2491 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +class GLUTStrokeRoman { + +/* GENERATED FILE -- DO NOT MODIFY */ + +/* char: 33 '!' */ + +static final CoordRec char33_stroke0[] = { + new CoordRec((float) 13.3819, (float) 100), + new CoordRec((float) 13.3819, (float) 33.3333), +}; + +static final CoordRec char33_stroke1[] = { + new CoordRec((float) 13.3819, (float) 9.5238), + new CoordRec((float) 8.62, (float) 4.7619), + new CoordRec((float) 13.3819, (float) 0), + new CoordRec((float) 18.1438, (float) 4.7619), + new CoordRec((float) 13.3819, (float) 9.5238), +}; + +static final StrokeRec char33[] = { + new StrokeRec(2, char33_stroke0), + new StrokeRec(5, char33_stroke1), +}; + +/* char: 34 '"' */ + +static final CoordRec char34_stroke0[] = { + new CoordRec((float) 4.02, (float) 100), + new CoordRec((float) 4.02, (float) 66.6667), +}; + +static final CoordRec char34_stroke1[] = { + new CoordRec((float) 42.1152, (float) 100), + new CoordRec((float) 42.1152, (float) 66.6667), +}; + +static final StrokeRec char34[] = { + new StrokeRec(2, char34_stroke0), + new StrokeRec(2, char34_stroke1), +}; + +/* char: 35 '#' */ + +static final CoordRec char35_stroke0[] = { + new CoordRec((float) 41.2952, (float) 119.048), + new CoordRec((float) 7.9619, (float) -33.3333), +}; + +static final CoordRec char35_stroke1[] = { + new CoordRec((float) 69.8667, (float) 119.048), + new CoordRec((float) 36.5333, (float) -33.3333), +}; + +static final CoordRec char35_stroke2[] = { + new CoordRec((float) 7.9619, (float) 57.1429), + new CoordRec((float) 74.6286, (float) 57.1429), +}; + +static final CoordRec char35_stroke3[] = { + new CoordRec((float) 3.2, (float) 28.5714), + new CoordRec((float) 69.8667, (float) 28.5714), +}; + +static final StrokeRec char35[] = { + new StrokeRec(2, char35_stroke0), + new StrokeRec(2, char35_stroke1), + new StrokeRec(2, char35_stroke2), + new StrokeRec(2, char35_stroke3), +}; + +/* char: 36 '$' */ + +static final CoordRec char36_stroke0[] = { + new CoordRec((float) 28.6295, (float) 119.048), + new CoordRec((float) 28.6295, (float) -19.0476), +}; + +static final CoordRec char36_stroke1[] = { + new CoordRec((float) 47.6771, (float) 119.048), + new CoordRec((float) 47.6771, (float) -19.0476), +}; + +static final CoordRec char36_stroke2[] = { + new CoordRec((float) 71.4867, (float) 85.7143), + new CoordRec((float) 61.9629, (float) 95.2381), + new CoordRec((float) 47.6771, (float) 100), + new CoordRec((float) 28.6295, (float) 100), + new CoordRec((float) 14.3438, (float) 95.2381), + new CoordRec((float) 4.82, (float) 85.7143), + new CoordRec((float) 4.82, (float) 76.1905), + new CoordRec((float) 9.5819, (float) 66.6667), + new CoordRec((float) 14.3438, (float) 61.9048), + new CoordRec((float) 23.8676, (float) 57.1429), + new CoordRec((float) 52.439, (float) 47.619), + new CoordRec((float) 61.9629, (float) 42.8571), + new CoordRec((float) 66.7248, (float) 38.0952), + new CoordRec((float) 71.4867, (float) 28.5714), + new CoordRec((float) 71.4867, (float) 14.2857), + new CoordRec((float) 61.9629, (float) 4.7619), + new CoordRec((float) 47.6771, (float) 0), + new CoordRec((float) 28.6295, (float) 0), + new CoordRec((float) 14.3438, (float) 4.7619), + new CoordRec((float) 4.82, (float) 14.2857), +}; + +static final StrokeRec char36[] = { + new StrokeRec(2, char36_stroke0), + new StrokeRec(2, char36_stroke1), + new StrokeRec(20, char36_stroke2), +}; + +/* char: 37 '%' */ + +static final CoordRec char37_stroke0[] = { + new CoordRec((float) 92.0743, (float) 100), + new CoordRec((float) 6.36, (float) 0), +}; + +static final CoordRec char37_stroke1[] = { + new CoordRec((float) 30.1695, (float) 100), + new CoordRec((float) 39.6933, (float) 90.4762), + new CoordRec((float) 39.6933, (float) 80.9524), + new CoordRec((float) 34.9314, (float) 71.4286), + new CoordRec((float) 25.4076, (float) 66.6667), + new CoordRec((float) 15.8838, (float) 66.6667), + new CoordRec((float) 6.36, (float) 76.1905), + new CoordRec((float) 6.36, (float) 85.7143), + new CoordRec((float) 11.1219, (float) 95.2381), + new CoordRec((float) 20.6457, (float) 100), + new CoordRec((float) 30.1695, (float) 100), + new CoordRec((float) 39.6933, (float) 95.2381), + new CoordRec((float) 53.979, (float) 90.4762), + new CoordRec((float) 68.2648, (float) 90.4762), + new CoordRec((float) 82.5505, (float) 95.2381), + new CoordRec((float) 92.0743, (float) 100), +}; + +static final CoordRec char37_stroke2[] = { + new CoordRec((float) 73.0267, (float) 33.3333), + new CoordRec((float) 63.5029, (float) 28.5714), + new CoordRec((float) 58.741, (float) 19.0476), + new CoordRec((float) 58.741, (float) 9.5238), + new CoordRec((float) 68.2648, (float) 0), + new CoordRec((float) 77.7886, (float) 0), + new CoordRec((float) 87.3124, (float) 4.7619), + new CoordRec((float) 92.0743, (float) 14.2857), + new CoordRec((float) 92.0743, (float) 23.8095), + new CoordRec((float) 82.5505, (float) 33.3333), + new CoordRec((float) 73.0267, (float) 33.3333), +}; + +static final StrokeRec char37[] = { + new StrokeRec(2, char37_stroke0), + new StrokeRec(16, char37_stroke1), + new StrokeRec(11, char37_stroke2), +}; + +/* char: 38 '&' */ + +static final CoordRec char38_stroke0[] = { + new CoordRec((float) 101.218, (float) 57.1429), + new CoordRec((float) 101.218, (float) 61.9048), + new CoordRec((float) 96.4562, (float) 66.6667), + new CoordRec((float) 91.6943, (float) 66.6667), + new CoordRec((float) 86.9324, (float) 61.9048), + new CoordRec((float) 82.1705, (float) 52.381), + new CoordRec((float) 72.6467, (float) 28.5714), + new CoordRec((float) 63.1229, (float) 14.2857), + new CoordRec((float) 53.599, (float) 4.7619), + new CoordRec((float) 44.0752, (float) 0), + new CoordRec((float) 25.0276, (float) 0), + new CoordRec((float) 15.5038, (float) 4.7619), + new CoordRec((float) 10.7419, (float) 9.5238), + new CoordRec((float) 5.98, (float) 19.0476), + new CoordRec((float) 5.98, (float) 28.5714), + new CoordRec((float) 10.7419, (float) 38.0952), + new CoordRec((float) 15.5038, (float) 42.8571), + new CoordRec((float) 48.8371, (float) 61.9048), + new CoordRec((float) 53.599, (float) 66.6667), + new CoordRec((float) 58.361, (float) 76.1905), + new CoordRec((float) 58.361, (float) 85.7143), + new CoordRec((float) 53.599, (float) 95.2381), + new CoordRec((float) 44.0752, (float) 100), + new CoordRec((float) 34.5514, (float) 95.2381), + new CoordRec((float) 29.7895, (float) 85.7143), + new CoordRec((float) 29.7895, (float) 76.1905), + new CoordRec((float) 34.5514, (float) 61.9048), + new CoordRec((float) 44.0752, (float) 47.619), + new CoordRec((float) 67.8848, (float) 14.2857), + new CoordRec((float) 77.4086, (float) 4.7619), + new CoordRec((float) 86.9324, (float) 0), + new CoordRec((float) 96.4562, (float) 0), + new CoordRec((float) 101.218, (float) 4.7619), + new CoordRec((float) 101.218, (float) 9.5238), +}; + +static final StrokeRec char38[] = { + new StrokeRec(34, char38_stroke0), +}; + +/* char: 39 ''' */ + +static final CoordRec char39_stroke0[] = { + new CoordRec((float) 4.44, (float) 100), + new CoordRec((float) 4.44, (float) 66.6667), +}; + +static final StrokeRec char39[] = { + new StrokeRec(2, char39_stroke0), +}; + +/* char: 40 '(' */ + +static final CoordRec char40_stroke0[] = { + new CoordRec((float) 40.9133, (float) 119.048), + new CoordRec((float) 31.3895, (float) 109.524), + new CoordRec((float) 21.8657, (float) 95.2381), + new CoordRec((float) 12.3419, (float) 76.1905), + new CoordRec((float) 7.58, (float) 52.381), + new CoordRec((float) 7.58, (float) 33.3333), + new CoordRec((float) 12.3419, (float) 9.5238), + new CoordRec((float) 21.8657, (float) -9.5238), + new CoordRec((float) 31.3895, (float) -23.8095), + new CoordRec((float) 40.9133, (float) -33.3333), +}; + +static final StrokeRec char40[] = { + new StrokeRec(10, char40_stroke0), +}; + +/* char: 41 ')' */ + +static final CoordRec char41_stroke0[] = { + new CoordRec((float) 5.28, (float) 119.048), + new CoordRec((float) 14.8038, (float) 109.524), + new CoordRec((float) 24.3276, (float) 95.2381), + new CoordRec((float) 33.8514, (float) 76.1905), + new CoordRec((float) 38.6133, (float) 52.381), + new CoordRec((float) 38.6133, (float) 33.3333), + new CoordRec((float) 33.8514, (float) 9.5238), + new CoordRec((float) 24.3276, (float) -9.5238), + new CoordRec((float) 14.8038, (float) -23.8095), + new CoordRec((float) 5.28, (float) -33.3333), +}; + +static final StrokeRec char41[] = { + new StrokeRec(10, char41_stroke0), +}; + +/* char: 42 '*' */ + +static final CoordRec char42_stroke0[] = { + new CoordRec((float) 30.7695, (float) 71.4286), + new CoordRec((float) 30.7695, (float) 14.2857), +}; + +static final CoordRec char42_stroke1[] = { + new CoordRec((float) 6.96, (float) 57.1429), + new CoordRec((float) 54.579, (float) 28.5714), +}; + +static final CoordRec char42_stroke2[] = { + new CoordRec((float) 54.579, (float) 57.1429), + new CoordRec((float) 6.96, (float) 28.5714), +}; + +static final StrokeRec char42[] = { + new StrokeRec(2, char42_stroke0), + new StrokeRec(2, char42_stroke1), + new StrokeRec(2, char42_stroke2), +}; + +/* char: 43 '+' */ + +static final CoordRec char43_stroke0[] = { + new CoordRec((float) 48.8371, (float) 85.7143), + new CoordRec((float) 48.8371, (float) 0), +}; + +static final CoordRec char43_stroke1[] = { + new CoordRec((float) 5.98, (float) 42.8571), + new CoordRec((float) 91.6943, (float) 42.8571), +}; + +static final StrokeRec char43[] = { + new StrokeRec(2, char43_stroke0), + new StrokeRec(2, char43_stroke1), +}; + +/* char: 44 ',' */ + +static final CoordRec char44_stroke0[] = { + new CoordRec((float) 18.2838, (float) 4.7619), + new CoordRec((float) 13.5219, (float) 0), + new CoordRec((float) 8.76, (float) 4.7619), + new CoordRec((float) 13.5219, (float) 9.5238), + new CoordRec((float) 18.2838, (float) 4.7619), + new CoordRec((float) 18.2838, (float) -4.7619), + new CoordRec((float) 13.5219, (float) -14.2857), + new CoordRec((float) 8.76, (float) -19.0476), +}; + +static final StrokeRec char44[] = { + new StrokeRec(8, char44_stroke0), +}; + +/* char: 45 '-' */ + +static final CoordRec char45_stroke0[] = { + new CoordRec((float) 7.38, (float) 42.8571), + new CoordRec((float) 93.0943, (float) 42.8571), +}; + +static final StrokeRec char45[] = { + new StrokeRec(2, char45_stroke0), +}; + +/* char: 46 '.' */ + +static final CoordRec char46_stroke0[] = { + new CoordRec((float) 13.1019, (float) 9.5238), + new CoordRec((float) 8.34, (float) 4.7619), + new CoordRec((float) 13.1019, (float) 0), + new CoordRec((float) 17.8638, (float) 4.7619), + new CoordRec((float) 13.1019, (float) 9.5238), +}; + +static final StrokeRec char46[] = { + new StrokeRec(5, char46_stroke0), +}; + +/* char: 47 '/' */ + +static final CoordRec char47_stroke0[] = { + new CoordRec((float) 7.24, (float) -14.2857), + new CoordRec((float) 73.9067, (float) 100), +}; + +static final StrokeRec char47[] = { + new StrokeRec(2, char47_stroke0), +}; + +/* char: 48 '0' */ + +static final CoordRec char48_stroke0[] = { + new CoordRec((float) 33.5514, (float) 100), + new CoordRec((float) 19.2657, (float) 95.2381), + new CoordRec((float) 9.7419, (float) 80.9524), + new CoordRec((float) 4.98, (float) 57.1429), + new CoordRec((float) 4.98, (float) 42.8571), + new CoordRec((float) 9.7419, (float) 19.0476), + new CoordRec((float) 19.2657, (float) 4.7619), + new CoordRec((float) 33.5514, (float) 0), + new CoordRec((float) 43.0752, (float) 0), + new CoordRec((float) 57.361, (float) 4.7619), + new CoordRec((float) 66.8848, (float) 19.0476), + new CoordRec((float) 71.6467, (float) 42.8571), + new CoordRec((float) 71.6467, (float) 57.1429), + new CoordRec((float) 66.8848, (float) 80.9524), + new CoordRec((float) 57.361, (float) 95.2381), + new CoordRec((float) 43.0752, (float) 100), + new CoordRec((float) 33.5514, (float) 100), +}; + +static final StrokeRec char48[] = { + new StrokeRec(17, char48_stroke0), +}; + +/* char: 49 '1' */ + +static final CoordRec char49_stroke0[] = { + new CoordRec((float) 11.82, (float) 80.9524), + new CoordRec((float) 21.3438, (float) 85.7143), + new CoordRec((float) 35.6295, (float) 100), + new CoordRec((float) 35.6295, (float) 0), +}; + +static final StrokeRec char49[] = { + new StrokeRec(4, char49_stroke0), +}; + +/* char: 50 '2' */ + +static final CoordRec char50_stroke0[] = { + new CoordRec((float) 10.1819, (float) 76.1905), + new CoordRec((float) 10.1819, (float) 80.9524), + new CoordRec((float) 14.9438, (float) 90.4762), + new CoordRec((float) 19.7057, (float) 95.2381), + new CoordRec((float) 29.2295, (float) 100), + new CoordRec((float) 48.2771, (float) 100), + new CoordRec((float) 57.801, (float) 95.2381), + new CoordRec((float) 62.5629, (float) 90.4762), + new CoordRec((float) 67.3248, (float) 80.9524), + new CoordRec((float) 67.3248, (float) 71.4286), + new CoordRec((float) 62.5629, (float) 61.9048), + new CoordRec((float) 53.039, (float) 47.619), + new CoordRec((float) 5.42, (float) 0), + new CoordRec((float) 72.0867, (float) 0), +}; + +static final StrokeRec char50[] = { + new StrokeRec(14, char50_stroke0), +}; + +/* char: 51 '3' */ + +static final CoordRec char51_stroke0[] = { + new CoordRec((float) 14.5238, (float) 100), + new CoordRec((float) 66.9048, (float) 100), + new CoordRec((float) 38.3333, (float) 61.9048), + new CoordRec((float) 52.619, (float) 61.9048), + new CoordRec((float) 62.1429, (float) 57.1429), + new CoordRec((float) 66.9048, (float) 52.381), + new CoordRec((float) 71.6667, (float) 38.0952), + new CoordRec((float) 71.6667, (float) 28.5714), + new CoordRec((float) 66.9048, (float) 14.2857), + new CoordRec((float) 57.381, (float) 4.7619), + new CoordRec((float) 43.0952, (float) 0), + new CoordRec((float) 28.8095, (float) 0), + new CoordRec((float) 14.5238, (float) 4.7619), + new CoordRec((float) 9.7619, (float) 9.5238), + new CoordRec((float) 5, (float) 19.0476), +}; + +static final StrokeRec char51[] = { + new StrokeRec(15, char51_stroke0), +}; + +/* char: 52 '4' */ + +static final CoordRec char52_stroke0[] = { + new CoordRec((float) 51.499, (float) 100), + new CoordRec((float) 3.88, (float) 33.3333), + new CoordRec((float) 75.3086, (float) 33.3333), +}; + +static final CoordRec char52_stroke1[] = { + new CoordRec((float) 51.499, (float) 100), + new CoordRec((float) 51.499, (float) 0), +}; + +static final StrokeRec char52[] = { + new StrokeRec(3, char52_stroke0), + new StrokeRec(2, char52_stroke1), +}; + +/* char: 53 '5' */ + +static final CoordRec char53_stroke0[] = { + new CoordRec((float) 62.0029, (float) 100), + new CoordRec((float) 14.3838, (float) 100), + new CoordRec((float) 9.6219, (float) 57.1429), + new CoordRec((float) 14.3838, (float) 61.9048), + new CoordRec((float) 28.6695, (float) 66.6667), + new CoordRec((float) 42.9552, (float) 66.6667), + new CoordRec((float) 57.241, (float) 61.9048), + new CoordRec((float) 66.7648, (float) 52.381), + new CoordRec((float) 71.5267, (float) 38.0952), + new CoordRec((float) 71.5267, (float) 28.5714), + new CoordRec((float) 66.7648, (float) 14.2857), + new CoordRec((float) 57.241, (float) 4.7619), + new CoordRec((float) 42.9552, (float) 0), + new CoordRec((float) 28.6695, (float) 0), + new CoordRec((float) 14.3838, (float) 4.7619), + new CoordRec((float) 9.6219, (float) 9.5238), + new CoordRec((float) 4.86, (float) 19.0476), +}; + +static final StrokeRec char53[] = { + new StrokeRec(17, char53_stroke0), +}; + +/* char: 54 '6' */ + +static final CoordRec char54_stroke0[] = { + new CoordRec((float) 62.7229, (float) 85.7143), + new CoordRec((float) 57.961, (float) 95.2381), + new CoordRec((float) 43.6752, (float) 100), + new CoordRec((float) 34.1514, (float) 100), + new CoordRec((float) 19.8657, (float) 95.2381), + new CoordRec((float) 10.3419, (float) 80.9524), + new CoordRec((float) 5.58, (float) 57.1429), + new CoordRec((float) 5.58, (float) 33.3333), + new CoordRec((float) 10.3419, (float) 14.2857), + new CoordRec((float) 19.8657, (float) 4.7619), + new CoordRec((float) 34.1514, (float) 0), + new CoordRec((float) 38.9133, (float) 0), + new CoordRec((float) 53.199, (float) 4.7619), + new CoordRec((float) 62.7229, (float) 14.2857), + new CoordRec((float) 67.4848, (float) 28.5714), + new CoordRec((float) 67.4848, (float) 33.3333), + new CoordRec((float) 62.7229, (float) 47.619), + new CoordRec((float) 53.199, (float) 57.1429), + new CoordRec((float) 38.9133, (float) 61.9048), + new CoordRec((float) 34.1514, (float) 61.9048), + new CoordRec((float) 19.8657, (float) 57.1429), + new CoordRec((float) 10.3419, (float) 47.619), + new CoordRec((float) 5.58, (float) 33.3333), +}; + +static final StrokeRec char54[] = { + new StrokeRec(23, char54_stroke0), +}; + +/* char: 55 '7' */ + +static final CoordRec char55_stroke0[] = { + new CoordRec((float) 72.2267, (float) 100), + new CoordRec((float) 24.6076, (float) 0), +}; + +static final CoordRec char55_stroke1[] = { + new CoordRec((float) 5.56, (float) 100), + new CoordRec((float) 72.2267, (float) 100), +}; + +static final StrokeRec char55[] = { + new StrokeRec(2, char55_stroke0), + new StrokeRec(2, char55_stroke1), +}; + +/* char: 56 '8' */ + +static final CoordRec char56_stroke0[] = { + new CoordRec((float) 29.4095, (float) 100), + new CoordRec((float) 15.1238, (float) 95.2381), + new CoordRec((float) 10.3619, (float) 85.7143), + new CoordRec((float) 10.3619, (float) 76.1905), + new CoordRec((float) 15.1238, (float) 66.6667), + new CoordRec((float) 24.6476, (float) 61.9048), + new CoordRec((float) 43.6952, (float) 57.1429), + new CoordRec((float) 57.981, (float) 52.381), + new CoordRec((float) 67.5048, (float) 42.8571), + new CoordRec((float) 72.2667, (float) 33.3333), + new CoordRec((float) 72.2667, (float) 19.0476), + new CoordRec((float) 67.5048, (float) 9.5238), + new CoordRec((float) 62.7429, (float) 4.7619), + new CoordRec((float) 48.4571, (float) 0), + new CoordRec((float) 29.4095, (float) 0), + new CoordRec((float) 15.1238, (float) 4.7619), + new CoordRec((float) 10.3619, (float) 9.5238), + new CoordRec((float) 5.6, (float) 19.0476), + new CoordRec((float) 5.6, (float) 33.3333), + new CoordRec((float) 10.3619, (float) 42.8571), + new CoordRec((float) 19.8857, (float) 52.381), + new CoordRec((float) 34.1714, (float) 57.1429), + new CoordRec((float) 53.219, (float) 61.9048), + new CoordRec((float) 62.7429, (float) 66.6667), + new CoordRec((float) 67.5048, (float) 76.1905), + new CoordRec((float) 67.5048, (float) 85.7143), + new CoordRec((float) 62.7429, (float) 95.2381), + new CoordRec((float) 48.4571, (float) 100), + new CoordRec((float) 29.4095, (float) 100), +}; + +static final StrokeRec char56[] = { + new StrokeRec(29, char56_stroke0), +}; + +/* char: 57 '9' */ + +static final CoordRec char57_stroke0[] = { + new CoordRec((float) 68.5048, (float) 66.6667), + new CoordRec((float) 63.7429, (float) 52.381), + new CoordRec((float) 54.219, (float) 42.8571), + new CoordRec((float) 39.9333, (float) 38.0952), + new CoordRec((float) 35.1714, (float) 38.0952), + new CoordRec((float) 20.8857, (float) 42.8571), + new CoordRec((float) 11.3619, (float) 52.381), + new CoordRec((float) 6.6, (float) 66.6667), + new CoordRec((float) 6.6, (float) 71.4286), + new CoordRec((float) 11.3619, (float) 85.7143), + new CoordRec((float) 20.8857, (float) 95.2381), + new CoordRec((float) 35.1714, (float) 100), + new CoordRec((float) 39.9333, (float) 100), + new CoordRec((float) 54.219, (float) 95.2381), + new CoordRec((float) 63.7429, (float) 85.7143), + new CoordRec((float) 68.5048, (float) 66.6667), + new CoordRec((float) 68.5048, (float) 42.8571), + new CoordRec((float) 63.7429, (float) 19.0476), + new CoordRec((float) 54.219, (float) 4.7619), + new CoordRec((float) 39.9333, (float) 0), + new CoordRec((float) 30.4095, (float) 0), + new CoordRec((float) 16.1238, (float) 4.7619), + new CoordRec((float) 11.3619, (float) 14.2857), +}; + +static final StrokeRec char57[] = { + new StrokeRec(23, char57_stroke0), +}; + +/* char: 58 ':' */ + +static final CoordRec char58_stroke0[] = { + new CoordRec((float) 14.0819, (float) 66.6667), + new CoordRec((float) 9.32, (float) 61.9048), + new CoordRec((float) 14.0819, (float) 57.1429), + new CoordRec((float) 18.8438, (float) 61.9048), + new CoordRec((float) 14.0819, (float) 66.6667), +}; + +static final CoordRec char58_stroke1[] = { + new CoordRec((float) 14.0819, (float) 9.5238), + new CoordRec((float) 9.32, (float) 4.7619), + new CoordRec((float) 14.0819, (float) 0), + new CoordRec((float) 18.8438, (float) 4.7619), + new CoordRec((float) 14.0819, (float) 9.5238), +}; + +static final StrokeRec char58[] = { + new StrokeRec(5, char58_stroke0), + new StrokeRec(5, char58_stroke1), +}; + +/* char: 59 ';' */ + +static final CoordRec char59_stroke0[] = { + new CoordRec((float) 12.9619, (float) 66.6667), + new CoordRec((float) 8.2, (float) 61.9048), + new CoordRec((float) 12.9619, (float) 57.1429), + new CoordRec((float) 17.7238, (float) 61.9048), + new CoordRec((float) 12.9619, (float) 66.6667), +}; + +static final CoordRec char59_stroke1[] = { + new CoordRec((float) 17.7238, (float) 4.7619), + new CoordRec((float) 12.9619, (float) 0), + new CoordRec((float) 8.2, (float) 4.7619), + new CoordRec((float) 12.9619, (float) 9.5238), + new CoordRec((float) 17.7238, (float) 4.7619), + new CoordRec((float) 17.7238, (float) -4.7619), + new CoordRec((float) 12.9619, (float) -14.2857), + new CoordRec((float) 8.2, (float) -19.0476), +}; + +static final StrokeRec char59[] = { + new StrokeRec(5, char59_stroke0), + new StrokeRec(8, char59_stroke1), +}; + +/* char: 60 '<' */ + +static final CoordRec char60_stroke0[] = { + new CoordRec((float) 79.2505, (float) 85.7143), + new CoordRec((float) 3.06, (float) 42.8571), + new CoordRec((float) 79.2505, (float) 0), +}; + +static final StrokeRec char60[] = { + new StrokeRec(3, char60_stroke0), +}; + +/* char: 61 '=' */ + +static final CoordRec char61_stroke0[] = { + new CoordRec((float) 5.7, (float) 57.1429), + new CoordRec((float) 91.4143, (float) 57.1429), +}; + +static final CoordRec char61_stroke1[] = { + new CoordRec((float) 5.7, (float) 28.5714), + new CoordRec((float) 91.4143, (float) 28.5714), +}; + +static final StrokeRec char61[] = { + new StrokeRec(2, char61_stroke0), + new StrokeRec(2, char61_stroke1), +}; + +/* char: 62 '>' */ + +static final CoordRec char62_stroke0[] = { + new CoordRec((float) 2.78, (float) 85.7143), + new CoordRec((float) 78.9705, (float) 42.8571), + new CoordRec((float) 2.78, (float) 0), +}; + +static final StrokeRec char62[] = { + new StrokeRec(3, char62_stroke0), +}; + +/* char: 63 '?' */ + +static final CoordRec char63_stroke0[] = { + new CoordRec((float) 8.42, (float) 76.1905), + new CoordRec((float) 8.42, (float) 80.9524), + new CoordRec((float) 13.1819, (float) 90.4762), + new CoordRec((float) 17.9438, (float) 95.2381), + new CoordRec((float) 27.4676, (float) 100), + new CoordRec((float) 46.5152, (float) 100), + new CoordRec((float) 56.039, (float) 95.2381), + new CoordRec((float) 60.801, (float) 90.4762), + new CoordRec((float) 65.5629, (float) 80.9524), + new CoordRec((float) 65.5629, (float) 71.4286), + new CoordRec((float) 60.801, (float) 61.9048), + new CoordRec((float) 56.039, (float) 57.1429), + new CoordRec((float) 36.9914, (float) 47.619), + new CoordRec((float) 36.9914, (float) 33.3333), +}; + +static final CoordRec char63_stroke1[] = { + new CoordRec((float) 36.9914, (float) 9.5238), + new CoordRec((float) 32.2295, (float) 4.7619), + new CoordRec((float) 36.9914, (float) 0), + new CoordRec((float) 41.7533, (float) 4.7619), + new CoordRec((float) 36.9914, (float) 9.5238), +}; + +static final StrokeRec char63[] = { + new StrokeRec(14, char63_stroke0), + new StrokeRec(5, char63_stroke1), +}; + +/* char: 64 '@' */ + +static final CoordRec char64_stroke0[] = { + new CoordRec((float) 49.2171, (float) 52.381), + new CoordRec((float) 39.6933, (float) 57.1429), + new CoordRec((float) 30.1695, (float) 57.1429), + new CoordRec((float) 25.4076, (float) 47.619), + new CoordRec((float) 25.4076, (float) 42.8571), + new CoordRec((float) 30.1695, (float) 33.3333), + new CoordRec((float) 39.6933, (float) 33.3333), + new CoordRec((float) 49.2171, (float) 38.0952), +}; + +static final CoordRec char64_stroke1[] = { + new CoordRec((float) 49.2171, (float) 57.1429), + new CoordRec((float) 49.2171, (float) 38.0952), + new CoordRec((float) 53.979, (float) 33.3333), + new CoordRec((float) 63.5029, (float) 33.3333), + new CoordRec((float) 68.2648, (float) 42.8571), + new CoordRec((float) 68.2648, (float) 47.619), + new CoordRec((float) 63.5029, (float) 61.9048), + new CoordRec((float) 53.979, (float) 71.4286), + new CoordRec((float) 39.6933, (float) 76.1905), + new CoordRec((float) 34.9314, (float) 76.1905), + new CoordRec((float) 20.6457, (float) 71.4286), + new CoordRec((float) 11.1219, (float) 61.9048), + new CoordRec((float) 6.36, (float) 47.619), + new CoordRec((float) 6.36, (float) 42.8571), + new CoordRec((float) 11.1219, (float) 28.5714), + new CoordRec((float) 20.6457, (float) 19.0476), + new CoordRec((float) 34.9314, (float) 14.2857), + new CoordRec((float) 39.6933, (float) 14.2857), + new CoordRec((float) 53.979, (float) 19.0476), +}; + +static final StrokeRec char64[] = { + new StrokeRec(8, char64_stroke0), + new StrokeRec(19, char64_stroke1), +}; + +/* char: 65 'A' */ + +static final CoordRec char65_stroke0[] = { + new CoordRec((float) 40.5952, (float) 100), + new CoordRec((float) 2.5, (float) 0), +}; + +static final CoordRec char65_stroke1[] = { + new CoordRec((float) 40.5952, (float) 100), + new CoordRec((float) 78.6905, (float) 0), +}; + +static final CoordRec char65_stroke2[] = { + new CoordRec((float) 16.7857, (float) 33.3333), + new CoordRec((float) 64.4048, (float) 33.3333), +}; + +static final StrokeRec char65[] = { + new StrokeRec(2, char65_stroke0), + new StrokeRec(2, char65_stroke1), + new StrokeRec(2, char65_stroke2), +}; + +/* char: 66 'B' */ + +static final CoordRec char66_stroke0[] = { + new CoordRec((float) 11.42, (float) 100), + new CoordRec((float) 11.42, (float) 0), +}; + +static final CoordRec char66_stroke1[] = { + new CoordRec((float) 11.42, (float) 100), + new CoordRec((float) 54.2771, (float) 100), + new CoordRec((float) 68.5629, (float) 95.2381), + new CoordRec((float) 73.3248, (float) 90.4762), + new CoordRec((float) 78.0867, (float) 80.9524), + new CoordRec((float) 78.0867, (float) 71.4286), + new CoordRec((float) 73.3248, (float) 61.9048), + new CoordRec((float) 68.5629, (float) 57.1429), + new CoordRec((float) 54.2771, (float) 52.381), +}; + +static final CoordRec char66_stroke2[] = { + new CoordRec((float) 11.42, (float) 52.381), + new CoordRec((float) 54.2771, (float) 52.381), + new CoordRec((float) 68.5629, (float) 47.619), + new CoordRec((float) 73.3248, (float) 42.8571), + new CoordRec((float) 78.0867, (float) 33.3333), + new CoordRec((float) 78.0867, (float) 19.0476), + new CoordRec((float) 73.3248, (float) 9.5238), + new CoordRec((float) 68.5629, (float) 4.7619), + new CoordRec((float) 54.2771, (float) 0), + new CoordRec((float) 11.42, (float) 0), +}; + +static final StrokeRec char66[] = { + new StrokeRec(2, char66_stroke0), + new StrokeRec(9, char66_stroke1), + new StrokeRec(10, char66_stroke2), +}; + +/* char: 67 'C' */ + +static final CoordRec char67_stroke0[] = { + new CoordRec((float) 78.0886, (float) 76.1905), + new CoordRec((float) 73.3267, (float) 85.7143), + new CoordRec((float) 63.8029, (float) 95.2381), + new CoordRec((float) 54.279, (float) 100), + new CoordRec((float) 35.2314, (float) 100), + new CoordRec((float) 25.7076, (float) 95.2381), + new CoordRec((float) 16.1838, (float) 85.7143), + new CoordRec((float) 11.4219, (float) 76.1905), + new CoordRec((float) 6.66, (float) 61.9048), + new CoordRec((float) 6.66, (float) 38.0952), + new CoordRec((float) 11.4219, (float) 23.8095), + new CoordRec((float) 16.1838, (float) 14.2857), + new CoordRec((float) 25.7076, (float) 4.7619), + new CoordRec((float) 35.2314, (float) 0), + new CoordRec((float) 54.279, (float) 0), + new CoordRec((float) 63.8029, (float) 4.7619), + new CoordRec((float) 73.3267, (float) 14.2857), + new CoordRec((float) 78.0886, (float) 23.8095), +}; + +static final StrokeRec char67[] = { + new StrokeRec(18, char67_stroke0), +}; + +/* char: 68 'D' */ + +static final CoordRec char68_stroke0[] = { + new CoordRec((float) 11.96, (float) 100), + new CoordRec((float) 11.96, (float) 0), +}; + +static final CoordRec char68_stroke1[] = { + new CoordRec((float) 11.96, (float) 100), + new CoordRec((float) 45.2933, (float) 100), + new CoordRec((float) 59.579, (float) 95.2381), + new CoordRec((float) 69.1029, (float) 85.7143), + new CoordRec((float) 73.8648, (float) 76.1905), + new CoordRec((float) 78.6267, (float) 61.9048), + new CoordRec((float) 78.6267, (float) 38.0952), + new CoordRec((float) 73.8648, (float) 23.8095), + new CoordRec((float) 69.1029, (float) 14.2857), + new CoordRec((float) 59.579, (float) 4.7619), + new CoordRec((float) 45.2933, (float) 0), + new CoordRec((float) 11.96, (float) 0), +}; + +static final StrokeRec char68[] = { + new StrokeRec(2, char68_stroke0), + new StrokeRec(12, char68_stroke1), +}; + +/* char: 69 'E' */ + +static final CoordRec char69_stroke0[] = { + new CoordRec((float) 11.42, (float) 100), + new CoordRec((float) 11.42, (float) 0), +}; + +static final CoordRec char69_stroke1[] = { + new CoordRec((float) 11.42, (float) 100), + new CoordRec((float) 73.3248, (float) 100), +}; + +static final CoordRec char69_stroke2[] = { + new CoordRec((float) 11.42, (float) 52.381), + new CoordRec((float) 49.5152, (float) 52.381), +}; + +static final CoordRec char69_stroke3[] = { + new CoordRec((float) 11.42, (float) 0), + new CoordRec((float) 73.3248, (float) 0), +}; + +static final StrokeRec char69[] = { + new StrokeRec(2, char69_stroke0), + new StrokeRec(2, char69_stroke1), + new StrokeRec(2, char69_stroke2), + new StrokeRec(2, char69_stroke3), +}; + +/* char: 70 'F' */ + +static final CoordRec char70_stroke0[] = { + new CoordRec((float) 11.42, (float) 100), + new CoordRec((float) 11.42, (float) 0), +}; + +static final CoordRec char70_stroke1[] = { + new CoordRec((float) 11.42, (float) 100), + new CoordRec((float) 73.3248, (float) 100), +}; + +static final CoordRec char70_stroke2[] = { + new CoordRec((float) 11.42, (float) 52.381), + new CoordRec((float) 49.5152, (float) 52.381), +}; + +static final StrokeRec char70[] = { + new StrokeRec(2, char70_stroke0), + new StrokeRec(2, char70_stroke1), + new StrokeRec(2, char70_stroke2), +}; + +/* char: 71 'G' */ + +static final CoordRec char71_stroke0[] = { + new CoordRec((float) 78.4886, (float) 76.1905), + new CoordRec((float) 73.7267, (float) 85.7143), + new CoordRec((float) 64.2029, (float) 95.2381), + new CoordRec((float) 54.679, (float) 100), + new CoordRec((float) 35.6314, (float) 100), + new CoordRec((float) 26.1076, (float) 95.2381), + new CoordRec((float) 16.5838, (float) 85.7143), + new CoordRec((float) 11.8219, (float) 76.1905), + new CoordRec((float) 7.06, (float) 61.9048), + new CoordRec((float) 7.06, (float) 38.0952), + new CoordRec((float) 11.8219, (float) 23.8095), + new CoordRec((float) 16.5838, (float) 14.2857), + new CoordRec((float) 26.1076, (float) 4.7619), + new CoordRec((float) 35.6314, (float) 0), + new CoordRec((float) 54.679, (float) 0), + new CoordRec((float) 64.2029, (float) 4.7619), + new CoordRec((float) 73.7267, (float) 14.2857), + new CoordRec((float) 78.4886, (float) 23.8095), + new CoordRec((float) 78.4886, (float) 38.0952), +}; + +static final CoordRec char71_stroke1[] = { + new CoordRec((float) 54.679, (float) 38.0952), + new CoordRec((float) 78.4886, (float) 38.0952), +}; + +static final StrokeRec char71[] = { + new StrokeRec(19, char71_stroke0), + new StrokeRec(2, char71_stroke1), +}; + +/* char: 72 'H' */ + +static final CoordRec char72_stroke0[] = { + new CoordRec((float) 11.42, (float) 100), + new CoordRec((float) 11.42, (float) 0), +}; + +static final CoordRec char72_stroke1[] = { + new CoordRec((float) 78.0867, (float) 100), + new CoordRec((float) 78.0867, (float) 0), +}; + +static final CoordRec char72_stroke2[] = { + new CoordRec((float) 11.42, (float) 52.381), + new CoordRec((float) 78.0867, (float) 52.381), +}; + +static final StrokeRec char72[] = { + new StrokeRec(2, char72_stroke0), + new StrokeRec(2, char72_stroke1), + new StrokeRec(2, char72_stroke2), +}; + +/* char: 73 'I' */ + +static final CoordRec char73_stroke0[] = { + new CoordRec((float) 10.86, (float) 100), + new CoordRec((float) 10.86, (float) 0), +}; + +static final StrokeRec char73[] = { + new StrokeRec(2, char73_stroke0), +}; + +/* char: 74 'J' */ + +static final CoordRec char74_stroke0[] = { + new CoordRec((float) 50.119, (float) 100), + new CoordRec((float) 50.119, (float) 23.8095), + new CoordRec((float) 45.3571, (float) 9.5238), + new CoordRec((float) 40.5952, (float) 4.7619), + new CoordRec((float) 31.0714, (float) 0), + new CoordRec((float) 21.5476, (float) 0), + new CoordRec((float) 12.0238, (float) 4.7619), + new CoordRec((float) 7.2619, (float) 9.5238), + new CoordRec((float) 2.5, (float) 23.8095), + new CoordRec((float) 2.5, (float) 33.3333), +}; + +static final StrokeRec char74[] = { + new StrokeRec(10, char74_stroke0), +}; + +/* char: 75 'K' */ + +static final CoordRec char75_stroke0[] = { + new CoordRec((float) 11.28, (float) 100), + new CoordRec((float) 11.28, (float) 0), +}; + +static final CoordRec char75_stroke1[] = { + new CoordRec((float) 77.9467, (float) 100), + new CoordRec((float) 11.28, (float) 33.3333), +}; + +static final CoordRec char75_stroke2[] = { + new CoordRec((float) 35.0895, (float) 57.1429), + new CoordRec((float) 77.9467, (float) 0), +}; + +static final StrokeRec char75[] = { + new StrokeRec(2, char75_stroke0), + new StrokeRec(2, char75_stroke1), + new StrokeRec(2, char75_stroke2), +}; + +/* char: 76 'L' */ + +static final CoordRec char76_stroke0[] = { + new CoordRec((float) 11.68, (float) 100), + new CoordRec((float) 11.68, (float) 0), +}; + +static final CoordRec char76_stroke1[] = { + new CoordRec((float) 11.68, (float) 0), + new CoordRec((float) 68.8229, (float) 0), +}; + +static final StrokeRec char76[] = { + new StrokeRec(2, char76_stroke0), + new StrokeRec(2, char76_stroke1), +}; + +/* char: 77 'M' */ + +static final CoordRec char77_stroke0[] = { + new CoordRec((float) 10.86, (float) 100), + new CoordRec((float) 10.86, (float) 0), +}; + +static final CoordRec char77_stroke1[] = { + new CoordRec((float) 10.86, (float) 100), + new CoordRec((float) 48.9552, (float) 0), +}; + +static final CoordRec char77_stroke2[] = { + new CoordRec((float) 87.0505, (float) 100), + new CoordRec((float) 48.9552, (float) 0), +}; + +static final CoordRec char77_stroke3[] = { + new CoordRec((float) 87.0505, (float) 100), + new CoordRec((float) 87.0505, (float) 0), +}; + +static final StrokeRec char77[] = { + new StrokeRec(2, char77_stroke0), + new StrokeRec(2, char77_stroke1), + new StrokeRec(2, char77_stroke2), + new StrokeRec(2, char77_stroke3), +}; + +/* char: 78 'N' */ + +static final CoordRec char78_stroke0[] = { + new CoordRec((float) 11.14, (float) 100), + new CoordRec((float) 11.14, (float) 0), +}; + +static final CoordRec char78_stroke1[] = { + new CoordRec((float) 11.14, (float) 100), + new CoordRec((float) 77.8067, (float) 0), +}; + +static final CoordRec char78_stroke2[] = { + new CoordRec((float) 77.8067, (float) 100), + new CoordRec((float) 77.8067, (float) 0), +}; + +static final StrokeRec char78[] = { + new StrokeRec(2, char78_stroke0), + new StrokeRec(2, char78_stroke1), + new StrokeRec(2, char78_stroke2), +}; + +/* char: 79 'O' */ + +static final CoordRec char79_stroke0[] = { + new CoordRec((float) 34.8114, (float) 100), + new CoordRec((float) 25.2876, (float) 95.2381), + new CoordRec((float) 15.7638, (float) 85.7143), + new CoordRec((float) 11.0019, (float) 76.1905), + new CoordRec((float) 6.24, (float) 61.9048), + new CoordRec((float) 6.24, (float) 38.0952), + new CoordRec((float) 11.0019, (float) 23.8095), + new CoordRec((float) 15.7638, (float) 14.2857), + new CoordRec((float) 25.2876, (float) 4.7619), + new CoordRec((float) 34.8114, (float) 0), + new CoordRec((float) 53.859, (float) 0), + new CoordRec((float) 63.3829, (float) 4.7619), + new CoordRec((float) 72.9067, (float) 14.2857), + new CoordRec((float) 77.6686, (float) 23.8095), + new CoordRec((float) 82.4305, (float) 38.0952), + new CoordRec((float) 82.4305, (float) 61.9048), + new CoordRec((float) 77.6686, (float) 76.1905), + new CoordRec((float) 72.9067, (float) 85.7143), + new CoordRec((float) 63.3829, (float) 95.2381), + new CoordRec((float) 53.859, (float) 100), + new CoordRec((float) 34.8114, (float) 100), +}; + +static final StrokeRec char79[] = { + new StrokeRec(21, char79_stroke0), +}; + +/* char: 80 'P' */ + +static final CoordRec char80_stroke0[] = { + new CoordRec((float) 12.1, (float) 100), + new CoordRec((float) 12.1, (float) 0), +}; + +static final CoordRec char80_stroke1[] = { + new CoordRec((float) 12.1, (float) 100), + new CoordRec((float) 54.9571, (float) 100), + new CoordRec((float) 69.2429, (float) 95.2381), + new CoordRec((float) 74.0048, (float) 90.4762), + new CoordRec((float) 78.7667, (float) 80.9524), + new CoordRec((float) 78.7667, (float) 66.6667), + new CoordRec((float) 74.0048, (float) 57.1429), + new CoordRec((float) 69.2429, (float) 52.381), + new CoordRec((float) 54.9571, (float) 47.619), + new CoordRec((float) 12.1, (float) 47.619), +}; + +static final StrokeRec char80[] = { + new StrokeRec(2, char80_stroke0), + new StrokeRec(10, char80_stroke1), +}; + +/* char: 81 'Q' */ + +static final CoordRec char81_stroke0[] = { + new CoordRec((float) 33.8714, (float) 100), + new CoordRec((float) 24.3476, (float) 95.2381), + new CoordRec((float) 14.8238, (float) 85.7143), + new CoordRec((float) 10.0619, (float) 76.1905), + new CoordRec((float) 5.3, (float) 61.9048), + new CoordRec((float) 5.3, (float) 38.0952), + new CoordRec((float) 10.0619, (float) 23.8095), + new CoordRec((float) 14.8238, (float) 14.2857), + new CoordRec((float) 24.3476, (float) 4.7619), + new CoordRec((float) 33.8714, (float) 0), + new CoordRec((float) 52.919, (float) 0), + new CoordRec((float) 62.4429, (float) 4.7619), + new CoordRec((float) 71.9667, (float) 14.2857), + new CoordRec((float) 76.7286, (float) 23.8095), + new CoordRec((float) 81.4905, (float) 38.0952), + new CoordRec((float) 81.4905, (float) 61.9048), + new CoordRec((float) 76.7286, (float) 76.1905), + new CoordRec((float) 71.9667, (float) 85.7143), + new CoordRec((float) 62.4429, (float) 95.2381), + new CoordRec((float) 52.919, (float) 100), + new CoordRec((float) 33.8714, (float) 100), +}; + +static final CoordRec char81_stroke1[] = { + new CoordRec((float) 48.1571, (float) 19.0476), + new CoordRec((float) 76.7286, (float) -9.5238), +}; + +static final StrokeRec char81[] = { + new StrokeRec(21, char81_stroke0), + new StrokeRec(2, char81_stroke1), +}; + +/* char: 82 'R' */ + +static final CoordRec char82_stroke0[] = { + new CoordRec((float) 11.68, (float) 100), + new CoordRec((float) 11.68, (float) 0), +}; + +static final CoordRec char82_stroke1[] = { + new CoordRec((float) 11.68, (float) 100), + new CoordRec((float) 54.5371, (float) 100), + new CoordRec((float) 68.8229, (float) 95.2381), + new CoordRec((float) 73.5848, (float) 90.4762), + new CoordRec((float) 78.3467, (float) 80.9524), + new CoordRec((float) 78.3467, (float) 71.4286), + new CoordRec((float) 73.5848, (float) 61.9048), + new CoordRec((float) 68.8229, (float) 57.1429), + new CoordRec((float) 54.5371, (float) 52.381), + new CoordRec((float) 11.68, (float) 52.381), +}; + +static final CoordRec char82_stroke2[] = { + new CoordRec((float) 45.0133, (float) 52.381), + new CoordRec((float) 78.3467, (float) 0), +}; + +static final StrokeRec char82[] = { + new StrokeRec(2, char82_stroke0), + new StrokeRec(10, char82_stroke1), + new StrokeRec(2, char82_stroke2), +}; + +/* char: 83 'S' */ + +static final CoordRec char83_stroke0[] = { + new CoordRec((float) 74.6667, (float) 85.7143), + new CoordRec((float) 65.1429, (float) 95.2381), + new CoordRec((float) 50.8571, (float) 100), + new CoordRec((float) 31.8095, (float) 100), + new CoordRec((float) 17.5238, (float) 95.2381), + new CoordRec((float) 8, (float) 85.7143), + new CoordRec((float) 8, (float) 76.1905), + new CoordRec((float) 12.7619, (float) 66.6667), + new CoordRec((float) 17.5238, (float) 61.9048), + new CoordRec((float) 27.0476, (float) 57.1429), + new CoordRec((float) 55.619, (float) 47.619), + new CoordRec((float) 65.1429, (float) 42.8571), + new CoordRec((float) 69.9048, (float) 38.0952), + new CoordRec((float) 74.6667, (float) 28.5714), + new CoordRec((float) 74.6667, (float) 14.2857), + new CoordRec((float) 65.1429, (float) 4.7619), + new CoordRec((float) 50.8571, (float) 0), + new CoordRec((float) 31.8095, (float) 0), + new CoordRec((float) 17.5238, (float) 4.7619), + new CoordRec((float) 8, (float) 14.2857), +}; + +static final StrokeRec char83[] = { + new StrokeRec(20, char83_stroke0), +}; + +/* char: 84 'T' */ + +static final CoordRec char84_stroke0[] = { + new CoordRec((float) 35.6933, (float) 100), + new CoordRec((float) 35.6933, (float) 0), +}; + +static final CoordRec char84_stroke1[] = { + new CoordRec((float) 2.36, (float) 100), + new CoordRec((float) 69.0267, (float) 100), +}; + +static final StrokeRec char84[] = { + new StrokeRec(2, char84_stroke0), + new StrokeRec(2, char84_stroke1), +}; + +/* char: 85 'U' */ + +static final CoordRec char85_stroke0[] = { + new CoordRec((float) 11.54, (float) 100), + new CoordRec((float) 11.54, (float) 28.5714), + new CoordRec((float) 16.3019, (float) 14.2857), + new CoordRec((float) 25.8257, (float) 4.7619), + new CoordRec((float) 40.1114, (float) 0), + new CoordRec((float) 49.6352, (float) 0), + new CoordRec((float) 63.921, (float) 4.7619), + new CoordRec((float) 73.4448, (float) 14.2857), + new CoordRec((float) 78.2067, (float) 28.5714), + new CoordRec((float) 78.2067, (float) 100), +}; + +static final StrokeRec char85[] = { + new StrokeRec(10, char85_stroke0), +}; + +/* char: 86 'V' */ + +static final CoordRec char86_stroke0[] = { + new CoordRec((float) 2.36, (float) 100), + new CoordRec((float) 40.4552, (float) 0), +}; + +static final CoordRec char86_stroke1[] = { + new CoordRec((float) 78.5505, (float) 100), + new CoordRec((float) 40.4552, (float) 0), +}; + +static final StrokeRec char86[] = { + new StrokeRec(2, char86_stroke0), + new StrokeRec(2, char86_stroke1), +}; + +/* char: 87 'W' */ + +static final CoordRec char87_stroke0[] = { + new CoordRec((float) 2.22, (float) 100), + new CoordRec((float) 26.0295, (float) 0), +}; + +static final CoordRec char87_stroke1[] = { + new CoordRec((float) 49.839, (float) 100), + new CoordRec((float) 26.0295, (float) 0), +}; + +static final CoordRec char87_stroke2[] = { + new CoordRec((float) 49.839, (float) 100), + new CoordRec((float) 73.6486, (float) 0), +}; + +static final CoordRec char87_stroke3[] = { + new CoordRec((float) 97.4581, (float) 100), + new CoordRec((float) 73.6486, (float) 0), +}; + +static final StrokeRec char87[] = { + new StrokeRec(2, char87_stroke0), + new StrokeRec(2, char87_stroke1), + new StrokeRec(2, char87_stroke2), + new StrokeRec(2, char87_stroke3), +}; + +/* char: 88 'X' */ + +static final CoordRec char88_stroke0[] = { + new CoordRec((float) 2.5, (float) 100), + new CoordRec((float) 69.1667, (float) 0), +}; + +static final CoordRec char88_stroke1[] = { + new CoordRec((float) 69.1667, (float) 100), + new CoordRec((float) 2.5, (float) 0), +}; + +static final StrokeRec char88[] = { + new StrokeRec(2, char88_stroke0), + new StrokeRec(2, char88_stroke1), +}; + +/* char: 89 'Y' */ + +static final CoordRec char89_stroke0[] = { + new CoordRec((float) 1.52, (float) 100), + new CoordRec((float) 39.6152, (float) 52.381), + new CoordRec((float) 39.6152, (float) 0), +}; + +static final CoordRec char89_stroke1[] = { + new CoordRec((float) 77.7105, (float) 100), + new CoordRec((float) 39.6152, (float) 52.381), +}; + +static final StrokeRec char89[] = { + new StrokeRec(3, char89_stroke0), + new StrokeRec(2, char89_stroke1), +}; + +/* char: 90 'Z' */ + +static final CoordRec char90_stroke0[] = { + new CoordRec((float) 69.1667, (float) 100), + new CoordRec((float) 2.5, (float) 0), +}; + +static final CoordRec char90_stroke1[] = { + new CoordRec((float) 2.5, (float) 100), + new CoordRec((float) 69.1667, (float) 100), +}; + +static final CoordRec char90_stroke2[] = { + new CoordRec((float) 2.5, (float) 0), + new CoordRec((float) 69.1667, (float) 0), +}; + +static final StrokeRec char90[] = { + new StrokeRec(2, char90_stroke0), + new StrokeRec(2, char90_stroke1), + new StrokeRec(2, char90_stroke2), +}; + +/* char: 91 '[' */ + +static final CoordRec char91_stroke0[] = { + new CoordRec((float) 7.78, (float) 119.048), + new CoordRec((float) 7.78, (float) -33.3333), +}; + +static final CoordRec char91_stroke1[] = { + new CoordRec((float) 12.5419, (float) 119.048), + new CoordRec((float) 12.5419, (float) -33.3333), +}; + +static final CoordRec char91_stroke2[] = { + new CoordRec((float) 7.78, (float) 119.048), + new CoordRec((float) 41.1133, (float) 119.048), +}; + +static final CoordRec char91_stroke3[] = { + new CoordRec((float) 7.78, (float) -33.3333), + new CoordRec((float) 41.1133, (float) -33.3333), +}; + +static final StrokeRec char91[] = { + new StrokeRec(2, char91_stroke0), + new StrokeRec(2, char91_stroke1), + new StrokeRec(2, char91_stroke2), + new StrokeRec(2, char91_stroke3), +}; + +/* char: 92 '\' */ + +static final CoordRec char92_stroke0[] = { + new CoordRec((float) 5.84, (float) 100), + new CoordRec((float) 72.5067, (float) -14.2857), +}; + +static final StrokeRec char92[] = { + new StrokeRec(2, char92_stroke0), +}; + +/* char: 93 ']' */ + +static final CoordRec char93_stroke0[] = { + new CoordRec((float) 33.0114, (float) 119.048), + new CoordRec((float) 33.0114, (float) -33.3333), +}; + +static final CoordRec char93_stroke1[] = { + new CoordRec((float) 37.7733, (float) 119.048), + new CoordRec((float) 37.7733, (float) -33.3333), +}; + +static final CoordRec char93_stroke2[] = { + new CoordRec((float) 4.44, (float) 119.048), + new CoordRec((float) 37.7733, (float) 119.048), +}; + +static final CoordRec char93_stroke3[] = { + new CoordRec((float) 4.44, (float) -33.3333), + new CoordRec((float) 37.7733, (float) -33.3333), +}; + +static final StrokeRec char93[] = { + new StrokeRec(2, char93_stroke0), + new StrokeRec(2, char93_stroke1), + new StrokeRec(2, char93_stroke2), + new StrokeRec(2, char93_stroke3), +}; + +/* char: 94 '^' */ + +static final CoordRec char94_stroke0[] = { + new CoordRec((float) 44.0752, (float) 109.524), + new CoordRec((float) 5.98, (float) 42.8571), +}; + +static final CoordRec char94_stroke1[] = { + new CoordRec((float) 44.0752, (float) 109.524), + new CoordRec((float) 82.1705, (float) 42.8571), +}; + +static final StrokeRec char94[] = { + new StrokeRec(2, char94_stroke0), + new StrokeRec(2, char94_stroke1), +}; + +/* char: 95 '_' */ + +static final CoordRec char95_stroke0[] = { + new CoordRec((float)-1.1, (float) -33.3333), + new CoordRec((float) 103.662, (float) -33.3333), + new CoordRec((float) 103.662, (float) -28.5714), + new CoordRec((float)-1.1, (float) -28.5714), + new CoordRec((float)-1.1, (float) -33.3333), +}; + +static final StrokeRec char95[] = { + new StrokeRec(5, char95_stroke0), +}; + +/* char: 96 '`' */ + +static final CoordRec char96_stroke0[] = { + new CoordRec((float) 33.0219, (float) 100), + new CoordRec((float) 56.8314, (float) 71.4286), +}; + +static final CoordRec char96_stroke1[] = { + new CoordRec((float) 33.0219, (float) 100), + new CoordRec((float) 28.26, (float) 95.2381), + new CoordRec((float) 56.8314, (float) 71.4286), +}; + +static final StrokeRec char96[] = { + new StrokeRec(2, char96_stroke0), + new StrokeRec(3, char96_stroke1), +}; + +/* char: 97 'a' */ + +static final CoordRec char97_stroke0[] = { + new CoordRec((float) 63.8229, (float) 66.6667), + new CoordRec((float) 63.8229, (float) 0), +}; + +static final CoordRec char97_stroke1[] = { + new CoordRec((float) 63.8229, (float) 52.381), + new CoordRec((float) 54.299, (float) 61.9048), + new CoordRec((float) 44.7752, (float) 66.6667), + new CoordRec((float) 30.4895, (float) 66.6667), + new CoordRec((float) 20.9657, (float) 61.9048), + new CoordRec((float) 11.4419, (float) 52.381), + new CoordRec((float) 6.68, (float) 38.0952), + new CoordRec((float) 6.68, (float) 28.5714), + new CoordRec((float) 11.4419, (float) 14.2857), + new CoordRec((float) 20.9657, (float) 4.7619), + new CoordRec((float) 30.4895, (float) 0), + new CoordRec((float) 44.7752, (float) 0), + new CoordRec((float) 54.299, (float) 4.7619), + new CoordRec((float) 63.8229, (float) 14.2857), +}; + +static final StrokeRec char97[] = { + new StrokeRec(2, char97_stroke0), + new StrokeRec(14, char97_stroke1), +}; + +/* char: 98 'b' */ + +static final CoordRec char98_stroke0[] = { + new CoordRec((float) 8.76, (float) 100), + new CoordRec((float) 8.76, (float) 0), +}; + +static final CoordRec char98_stroke1[] = { + new CoordRec((float) 8.76, (float) 52.381), + new CoordRec((float) 18.2838, (float) 61.9048), + new CoordRec((float) 27.8076, (float) 66.6667), + new CoordRec((float) 42.0933, (float) 66.6667), + new CoordRec((float) 51.6171, (float) 61.9048), + new CoordRec((float) 61.141, (float) 52.381), + new CoordRec((float) 65.9029, (float) 38.0952), + new CoordRec((float) 65.9029, (float) 28.5714), + new CoordRec((float) 61.141, (float) 14.2857), + new CoordRec((float) 51.6171, (float) 4.7619), + new CoordRec((float) 42.0933, (float) 0), + new CoordRec((float) 27.8076, (float) 0), + new CoordRec((float) 18.2838, (float) 4.7619), + new CoordRec((float) 8.76, (float) 14.2857), +}; + +static final StrokeRec char98[] = { + new StrokeRec(2, char98_stroke0), + new StrokeRec(14, char98_stroke1), +}; + +/* char: 99 'c' */ + +static final CoordRec char99_stroke0[] = { + new CoordRec((float) 62.6629, (float) 52.381), + new CoordRec((float) 53.139, (float) 61.9048), + new CoordRec((float) 43.6152, (float) 66.6667), + new CoordRec((float) 29.3295, (float) 66.6667), + new CoordRec((float) 19.8057, (float) 61.9048), + new CoordRec((float) 10.2819, (float) 52.381), + new CoordRec((float) 5.52, (float) 38.0952), + new CoordRec((float) 5.52, (float) 28.5714), + new CoordRec((float) 10.2819, (float) 14.2857), + new CoordRec((float) 19.8057, (float) 4.7619), + new CoordRec((float) 29.3295, (float) 0), + new CoordRec((float) 43.6152, (float) 0), + new CoordRec((float) 53.139, (float) 4.7619), + new CoordRec((float) 62.6629, (float) 14.2857), +}; + +static final StrokeRec char99[] = { + new StrokeRec(14, char99_stroke0), +}; + +/* char: 100 'd' */ + +static final CoordRec char100_stroke0[] = { + new CoordRec((float) 61.7829, (float) 100), + new CoordRec((float) 61.7829, (float) 0), +}; + +static final CoordRec char100_stroke1[] = { + new CoordRec((float) 61.7829, (float) 52.381), + new CoordRec((float) 52.259, (float) 61.9048), + new CoordRec((float) 42.7352, (float) 66.6667), + new CoordRec((float) 28.4495, (float) 66.6667), + new CoordRec((float) 18.9257, (float) 61.9048), + new CoordRec((float) 9.4019, (float) 52.381), + new CoordRec((float) 4.64, (float) 38.0952), + new CoordRec((float) 4.64, (float) 28.5714), + new CoordRec((float) 9.4019, (float) 14.2857), + new CoordRec((float) 18.9257, (float) 4.7619), + new CoordRec((float) 28.4495, (float) 0), + new CoordRec((float) 42.7352, (float) 0), + new CoordRec((float) 52.259, (float) 4.7619), + new CoordRec((float) 61.7829, (float) 14.2857), +}; + +static final StrokeRec char100[] = { + new StrokeRec(2, char100_stroke0), + new StrokeRec(14, char100_stroke1), +}; + +/* char: 101 'e' */ + +static final CoordRec char101_stroke0[] = { + new CoordRec((float) 5.72, (float) 38.0952), + new CoordRec((float) 62.8629, (float) 38.0952), + new CoordRec((float) 62.8629, (float) 47.619), + new CoordRec((float) 58.101, (float) 57.1429), + new CoordRec((float) 53.339, (float) 61.9048), + new CoordRec((float) 43.8152, (float) 66.6667), + new CoordRec((float) 29.5295, (float) 66.6667), + new CoordRec((float) 20.0057, (float) 61.9048), + new CoordRec((float) 10.4819, (float) 52.381), + new CoordRec((float) 5.72, (float) 38.0952), + new CoordRec((float) 5.72, (float) 28.5714), + new CoordRec((float) 10.4819, (float) 14.2857), + new CoordRec((float) 20.0057, (float) 4.7619), + new CoordRec((float) 29.5295, (float) 0), + new CoordRec((float) 43.8152, (float) 0), + new CoordRec((float) 53.339, (float) 4.7619), + new CoordRec((float) 62.8629, (float) 14.2857), +}; + +static final StrokeRec char101[] = { + new StrokeRec(17, char101_stroke0), +}; + +/* char: 102 'f' */ + +static final CoordRec char102_stroke0[] = { + new CoordRec((float) 38.7752, (float) 100), + new CoordRec((float) 29.2514, (float) 100), + new CoordRec((float) 19.7276, (float) 95.2381), + new CoordRec((float) 14.9657, (float) 80.9524), + new CoordRec((float) 14.9657, (float) 0), +}; + +static final CoordRec char102_stroke1[] = { + new CoordRec((float) 0.68, (float) 66.6667), + new CoordRec((float) 34.0133, (float) 66.6667), +}; + +static final StrokeRec char102[] = { + new StrokeRec(5, char102_stroke0), + new StrokeRec(2, char102_stroke1), +}; + +/* char: 103 'g' */ + +static final CoordRec char103_stroke0[] = { + new CoordRec((float) 62.5029, (float) 66.6667), + new CoordRec((float) 62.5029, (float) -9.5238), + new CoordRec((float) 57.741, (float) -23.8095), + new CoordRec((float) 52.979, (float) -28.5714), + new CoordRec((float) 43.4552, (float) -33.3333), + new CoordRec((float) 29.1695, (float) -33.3333), + new CoordRec((float) 19.6457, (float) -28.5714), +}; + +static final CoordRec char103_stroke1[] = { + new CoordRec((float) 62.5029, (float) 52.381), + new CoordRec((float) 52.979, (float) 61.9048), + new CoordRec((float) 43.4552, (float) 66.6667), + new CoordRec((float) 29.1695, (float) 66.6667), + new CoordRec((float) 19.6457, (float) 61.9048), + new CoordRec((float) 10.1219, (float) 52.381), + new CoordRec((float) 5.36, (float) 38.0952), + new CoordRec((float) 5.36, (float) 28.5714), + new CoordRec((float) 10.1219, (float) 14.2857), + new CoordRec((float) 19.6457, (float) 4.7619), + new CoordRec((float) 29.1695, (float) 0), + new CoordRec((float) 43.4552, (float) 0), + new CoordRec((float) 52.979, (float) 4.7619), + new CoordRec((float) 62.5029, (float) 14.2857), +}; + +static final StrokeRec char103[] = { + new StrokeRec(7, char103_stroke0), + new StrokeRec(14, char103_stroke1), +}; + +/* char: 104 'h' */ + +static final CoordRec char104_stroke0[] = { + new CoordRec((float) 9.6, (float) 100), + new CoordRec((float) 9.6, (float) 0), +}; + +static final CoordRec char104_stroke1[] = { + new CoordRec((float) 9.6, (float) 47.619), + new CoordRec((float) 23.8857, (float) 61.9048), + new CoordRec((float) 33.4095, (float) 66.6667), + new CoordRec((float) 47.6952, (float) 66.6667), + new CoordRec((float) 57.219, (float) 61.9048), + new CoordRec((float) 61.981, (float) 47.619), + new CoordRec((float) 61.981, (float) 0), +}; + +static final StrokeRec char104[] = { + new StrokeRec(2, char104_stroke0), + new StrokeRec(7, char104_stroke1), +}; + +/* char: 105 'i' */ + +static final CoordRec char105_stroke0[] = { + new CoordRec((float) 10.02, (float) 100), + new CoordRec((float) 14.7819, (float) 95.2381), + new CoordRec((float) 19.5438, (float) 100), + new CoordRec((float) 14.7819, (float) 104.762), + new CoordRec((float) 10.02, (float) 100), +}; + +static final CoordRec char105_stroke1[] = { + new CoordRec((float) 14.7819, (float) 66.6667), + new CoordRec((float) 14.7819, (float) 0), +}; + +static final StrokeRec char105[] = { + new StrokeRec(5, char105_stroke0), + new StrokeRec(2, char105_stroke1), +}; + +/* char: 106 'j' */ + +static final CoordRec char106_stroke0[] = { + new CoordRec((float) 17.3876, (float) 100), + new CoordRec((float) 22.1495, (float) 95.2381), + new CoordRec((float) 26.9114, (float) 100), + new CoordRec((float) 22.1495, (float) 104.762), + new CoordRec((float) 17.3876, (float) 100), +}; + +static final CoordRec char106_stroke1[] = { + new CoordRec((float) 22.1495, (float) 66.6667), + new CoordRec((float) 22.1495, (float) -14.2857), + new CoordRec((float) 17.3876, (float) -28.5714), + new CoordRec((float) 7.8638, (float) -33.3333), + new CoordRec((float)-1.66, (float) -33.3333), +}; + +static final StrokeRec char106[] = { + new StrokeRec(5, char106_stroke0), + new StrokeRec(5, char106_stroke1), +}; + +/* char: 107 'k' */ + +static final CoordRec char107_stroke0[] = { + new CoordRec((float) 9.6, (float) 100), + new CoordRec((float) 9.6, (float) 0), +}; + +static final CoordRec char107_stroke1[] = { + new CoordRec((float) 57.219, (float) 66.6667), + new CoordRec((float) 9.6, (float) 19.0476), +}; + +static final CoordRec char107_stroke2[] = { + new CoordRec((float) 28.6476, (float) 38.0952), + new CoordRec((float) 61.981, (float) 0), +}; + +static final StrokeRec char107[] = { + new StrokeRec(2, char107_stroke0), + new StrokeRec(2, char107_stroke1), + new StrokeRec(2, char107_stroke2), +}; + +/* char: 108 'l' */ + +static final CoordRec char108_stroke0[] = { + new CoordRec((float) 10.02, (float) 100), + new CoordRec((float) 10.02, (float) 0), +}; + +static final StrokeRec char108[] = { + new StrokeRec(2, char108_stroke0), +}; + +/* char: 109 'm' */ + +static final CoordRec char109_stroke0[] = { + new CoordRec((float) 9.6, (float) 66.6667), + new CoordRec((float) 9.6, (float) 0), +}; + +static final CoordRec char109_stroke1[] = { + new CoordRec((float) 9.6, (float) 47.619), + new CoordRec((float) 23.8857, (float) 61.9048), + new CoordRec((float) 33.4095, (float) 66.6667), + new CoordRec((float) 47.6952, (float) 66.6667), + new CoordRec((float) 57.219, (float) 61.9048), + new CoordRec((float) 61.981, (float) 47.619), + new CoordRec((float) 61.981, (float) 0), +}; + +static final CoordRec char109_stroke2[] = { + new CoordRec((float) 61.981, (float) 47.619), + new CoordRec((float) 76.2667, (float) 61.9048), + new CoordRec((float) 85.7905, (float) 66.6667), + new CoordRec((float) 100.076, (float) 66.6667), + new CoordRec((float) 109.6, (float) 61.9048), + new CoordRec((float) 114.362, (float) 47.619), + new CoordRec((float) 114.362, (float) 0), +}; + +static final StrokeRec char109[] = { + new StrokeRec(2, char109_stroke0), + new StrokeRec(7, char109_stroke1), + new StrokeRec(7, char109_stroke2), +}; + +/* char: 110 'n' */ + +static final CoordRec char110_stroke0[] = { + new CoordRec((float) 9.18, (float) 66.6667), + new CoordRec((float) 9.18, (float) 0), +}; + +static final CoordRec char110_stroke1[] = { + new CoordRec((float) 9.18, (float) 47.619), + new CoordRec((float) 23.4657, (float) 61.9048), + new CoordRec((float) 32.9895, (float) 66.6667), + new CoordRec((float) 47.2752, (float) 66.6667), + new CoordRec((float) 56.799, (float) 61.9048), + new CoordRec((float) 61.561, (float) 47.619), + new CoordRec((float) 61.561, (float) 0), +}; + +static final StrokeRec char110[] = { + new StrokeRec(2, char110_stroke0), + new StrokeRec(7, char110_stroke1), +}; + +/* char: 111 'o' */ + +static final CoordRec char111_stroke0[] = { + new CoordRec((float) 28.7895, (float) 66.6667), + new CoordRec((float) 19.2657, (float) 61.9048), + new CoordRec((float) 9.7419, (float) 52.381), + new CoordRec((float) 4.98, (float) 38.0952), + new CoordRec((float) 4.98, (float) 28.5714), + new CoordRec((float) 9.7419, (float) 14.2857), + new CoordRec((float) 19.2657, (float) 4.7619), + new CoordRec((float) 28.7895, (float) 0), + new CoordRec((float) 43.0752, (float) 0), + new CoordRec((float) 52.599, (float) 4.7619), + new CoordRec((float) 62.1229, (float) 14.2857), + new CoordRec((float) 66.8848, (float) 28.5714), + new CoordRec((float) 66.8848, (float) 38.0952), + new CoordRec((float) 62.1229, (float) 52.381), + new CoordRec((float) 52.599, (float) 61.9048), + new CoordRec((float) 43.0752, (float) 66.6667), + new CoordRec((float) 28.7895, (float) 66.6667), +}; + +static final StrokeRec char111[] = { + new StrokeRec(17, char111_stroke0), +}; + +/* char: 112 'p' */ + +static final CoordRec char112_stroke0[] = { + new CoordRec((float) 9.46, (float) 66.6667), + new CoordRec((float) 9.46, (float) -33.3333), +}; + +static final CoordRec char112_stroke1[] = { + new CoordRec((float) 9.46, (float) 52.381), + new CoordRec((float) 18.9838, (float) 61.9048), + new CoordRec((float) 28.5076, (float) 66.6667), + new CoordRec((float) 42.7933, (float) 66.6667), + new CoordRec((float) 52.3171, (float) 61.9048), + new CoordRec((float) 61.841, (float) 52.381), + new CoordRec((float) 66.6029, (float) 38.0952), + new CoordRec((float) 66.6029, (float) 28.5714), + new CoordRec((float) 61.841, (float) 14.2857), + new CoordRec((float) 52.3171, (float) 4.7619), + new CoordRec((float) 42.7933, (float) 0), + new CoordRec((float) 28.5076, (float) 0), + new CoordRec((float) 18.9838, (float) 4.7619), + new CoordRec((float) 9.46, (float) 14.2857), +}; + +static final StrokeRec char112[] = { + new StrokeRec(2, char112_stroke0), + new StrokeRec(14, char112_stroke1), +}; + +/* char: 113 'q' */ + +static final CoordRec char113_stroke0[] = { + new CoordRec((float) 61.9829, (float) 66.6667), + new CoordRec((float) 61.9829, (float) -33.3333), +}; + +static final CoordRec char113_stroke1[] = { + new CoordRec((float) 61.9829, (float) 52.381), + new CoordRec((float) 52.459, (float) 61.9048), + new CoordRec((float) 42.9352, (float) 66.6667), + new CoordRec((float) 28.6495, (float) 66.6667), + new CoordRec((float) 19.1257, (float) 61.9048), + new CoordRec((float) 9.6019, (float) 52.381), + new CoordRec((float) 4.84, (float) 38.0952), + new CoordRec((float) 4.84, (float) 28.5714), + new CoordRec((float) 9.6019, (float) 14.2857), + new CoordRec((float) 19.1257, (float) 4.7619), + new CoordRec((float) 28.6495, (float) 0), + new CoordRec((float) 42.9352, (float) 0), + new CoordRec((float) 52.459, (float) 4.7619), + new CoordRec((float) 61.9829, (float) 14.2857), +}; + +static final StrokeRec char113[] = { + new StrokeRec(2, char113_stroke0), + new StrokeRec(14, char113_stroke1), +}; + +/* char: 114 'r' */ + +static final CoordRec char114_stroke0[] = { + new CoordRec((float) 9.46, (float) 66.6667), + new CoordRec((float) 9.46, (float) 0), +}; + +static final CoordRec char114_stroke1[] = { + new CoordRec((float) 9.46, (float) 38.0952), + new CoordRec((float) 14.2219, (float) 52.381), + new CoordRec((float) 23.7457, (float) 61.9048), + new CoordRec((float) 33.2695, (float) 66.6667), + new CoordRec((float) 47.5552, (float) 66.6667), +}; + +static final StrokeRec char114[] = { + new StrokeRec(2, char114_stroke0), + new StrokeRec(5, char114_stroke1), +}; + +/* char: 115 's' */ + +static final CoordRec char115_stroke0[] = { + new CoordRec((float) 57.081, (float) 52.381), + new CoordRec((float) 52.319, (float) 61.9048), + new CoordRec((float) 38.0333, (float) 66.6667), + new CoordRec((float) 23.7476, (float) 66.6667), + new CoordRec((float) 9.4619, (float) 61.9048), + new CoordRec((float) 4.7, (float) 52.381), + new CoordRec((float) 9.4619, (float) 42.8571), + new CoordRec((float) 18.9857, (float) 38.0952), + new CoordRec((float) 42.7952, (float) 33.3333), + new CoordRec((float) 52.319, (float) 28.5714), + new CoordRec((float) 57.081, (float) 19.0476), + new CoordRec((float) 57.081, (float) 14.2857), + new CoordRec((float) 52.319, (float) 4.7619), + new CoordRec((float) 38.0333, (float) 0), + new CoordRec((float) 23.7476, (float) 0), + new CoordRec((float) 9.4619, (float) 4.7619), + new CoordRec((float) 4.7, (float) 14.2857), +}; + +static final StrokeRec char115[] = { + new StrokeRec(17, char115_stroke0), +}; + +/* char: 116 't' */ + +static final CoordRec char116_stroke0[] = { + new CoordRec((float) 14.8257, (float) 100), + new CoordRec((float) 14.8257, (float) 19.0476), + new CoordRec((float) 19.5876, (float) 4.7619), + new CoordRec((float) 29.1114, (float) 0), + new CoordRec((float) 38.6352, (float) 0), +}; + +static final CoordRec char116_stroke1[] = { + new CoordRec((float) 0.54, (float) 66.6667), + new CoordRec((float) 33.8733, (float) 66.6667), +}; + +static final StrokeRec char116[] = { + new StrokeRec(5, char116_stroke0), + new StrokeRec(2, char116_stroke1), +}; + +/* char: 117 'u' */ + +static final CoordRec char117_stroke0[] = { + new CoordRec((float) 9.46, (float) 66.6667), + new CoordRec((float) 9.46, (float) 19.0476), + new CoordRec((float) 14.2219, (float) 4.7619), + new CoordRec((float) 23.7457, (float) 0), + new CoordRec((float) 38.0314, (float) 0), + new CoordRec((float) 47.5552, (float) 4.7619), + new CoordRec((float) 61.841, (float) 19.0476), +}; + +static final CoordRec char117_stroke1[] = { + new CoordRec((float) 61.841, (float) 66.6667), + new CoordRec((float) 61.841, (float) 0), +}; + +static final StrokeRec char117[] = { + new StrokeRec(7, char117_stroke0), + new StrokeRec(2, char117_stroke1), +}; + +/* char: 118 'v' */ + +static final CoordRec char118_stroke0[] = { + new CoordRec((float) 1.8, (float) 66.6667), + new CoordRec((float) 30.3714, (float) 0), +}; + +static final CoordRec char118_stroke1[] = { + new CoordRec((float) 58.9429, (float) 66.6667), + new CoordRec((float) 30.3714, (float) 0), +}; + +static final StrokeRec char118[] = { + new StrokeRec(2, char118_stroke0), + new StrokeRec(2, char118_stroke1), +}; + +/* char: 119 'w' */ + +static final CoordRec char119_stroke0[] = { + new CoordRec((float) 2.5, (float) 66.6667), + new CoordRec((float) 21.5476, (float) 0), +}; + +static final CoordRec char119_stroke1[] = { + new CoordRec((float) 40.5952, (float) 66.6667), + new CoordRec((float) 21.5476, (float) 0), +}; + +static final CoordRec char119_stroke2[] = { + new CoordRec((float) 40.5952, (float) 66.6667), + new CoordRec((float) 59.6429, (float) 0), +}; + +static final CoordRec char119_stroke3[] = { + new CoordRec((float) 78.6905, (float) 66.6667), + new CoordRec((float) 59.6429, (float) 0), +}; + +static final StrokeRec char119[] = { + new StrokeRec(2, char119_stroke0), + new StrokeRec(2, char119_stroke1), + new StrokeRec(2, char119_stroke2), + new StrokeRec(2, char119_stroke3), +}; + +/* char: 120 'x' */ + +static final CoordRec char120_stroke0[] = { + new CoordRec((float) 1.66, (float) 66.6667), + new CoordRec((float) 54.041, (float) 0), +}; + +static final CoordRec char120_stroke1[] = { + new CoordRec((float) 54.041, (float) 66.6667), + new CoordRec((float) 1.66, (float) 0), +}; + +static final StrokeRec char120[] = { + new StrokeRec(2, char120_stroke0), + new StrokeRec(2, char120_stroke1), +}; + +/* char: 121 'y' */ + +static final CoordRec char121_stroke0[] = { + new CoordRec((float) 6.5619, (float) 66.6667), + new CoordRec((float) 35.1333, (float) 0), +}; + +static final CoordRec char121_stroke1[] = { + new CoordRec((float) 63.7048, (float) 66.6667), + new CoordRec((float) 35.1333, (float) 0), + new CoordRec((float) 25.6095, (float) -19.0476), + new CoordRec((float) 16.0857, (float) -28.5714), + new CoordRec((float) 6.5619, (float) -33.3333), + new CoordRec((float) 1.8, (float) -33.3333), +}; + +static final StrokeRec char121[] = { + new StrokeRec(2, char121_stroke0), + new StrokeRec(6, char121_stroke1), +}; + +/* char: 122 'z' */ + +static final CoordRec char122_stroke0[] = { + new CoordRec((float) 56.821, (float) 66.6667), + new CoordRec((float) 4.44, (float) 0), +}; + +static final CoordRec char122_stroke1[] = { + new CoordRec((float) 4.44, (float) 66.6667), + new CoordRec((float) 56.821, (float) 66.6667), +}; + +static final CoordRec char122_stroke2[] = { + new CoordRec((float) 4.44, (float) 0), + new CoordRec((float) 56.821, (float) 0), +}; + +static final StrokeRec char122[] = { + new StrokeRec(2, char122_stroke0), + new StrokeRec(2, char122_stroke1), + new StrokeRec(2, char122_stroke2), +}; + +/* char: 123 '{' */ + +static final CoordRec char123_stroke0[] = { + new CoordRec((float) 31.1895, (float) 119.048), + new CoordRec((float) 21.6657, (float) 114.286), + new CoordRec((float) 16.9038, (float) 109.524), + new CoordRec((float) 12.1419, (float) 100), + new CoordRec((float) 12.1419, (float) 90.4762), + new CoordRec((float) 16.9038, (float) 80.9524), + new CoordRec((float) 21.6657, (float) 76.1905), + new CoordRec((float) 26.4276, (float) 66.6667), + new CoordRec((float) 26.4276, (float) 57.1429), + new CoordRec((float) 16.9038, (float) 47.619), +}; + +static final CoordRec char123_stroke1[] = { + new CoordRec((float) 21.6657, (float) 114.286), + new CoordRec((float) 16.9038, (float) 104.762), + new CoordRec((float) 16.9038, (float) 95.2381), + new CoordRec((float) 21.6657, (float) 85.7143), + new CoordRec((float) 26.4276, (float) 80.9524), + new CoordRec((float) 31.1895, (float) 71.4286), + new CoordRec((float) 31.1895, (float) 61.9048), + new CoordRec((float) 26.4276, (float) 52.381), + new CoordRec((float) 7.38, (float) 42.8571), + new CoordRec((float) 26.4276, (float) 33.3333), + new CoordRec((float) 31.1895, (float) 23.8095), + new CoordRec((float) 31.1895, (float) 14.2857), + new CoordRec((float) 26.4276, (float) 4.7619), + new CoordRec((float) 21.6657, (float) 0), + new CoordRec((float) 16.9038, (float) -9.5238), + new CoordRec((float) 16.9038, (float) -19.0476), + new CoordRec((float) 21.6657, (float) -28.5714), +}; + +static final CoordRec char123_stroke2[] = { + new CoordRec((float) 16.9038, (float) 38.0952), + new CoordRec((float) 26.4276, (float) 28.5714), + new CoordRec((float) 26.4276, (float) 19.0476), + new CoordRec((float) 21.6657, (float) 9.5238), + new CoordRec((float) 16.9038, (float) 4.7619), + new CoordRec((float) 12.1419, (float) -4.7619), + new CoordRec((float) 12.1419, (float) -14.2857), + new CoordRec((float) 16.9038, (float) -23.8095), + new CoordRec((float) 21.6657, (float) -28.5714), + new CoordRec((float) 31.1895, (float) -33.3333), +}; + +static final StrokeRec char123[] = { + new StrokeRec(10, char123_stroke0), + new StrokeRec(17, char123_stroke1), + new StrokeRec(10, char123_stroke2), +}; + +/* char: 124 '|' */ + +static final CoordRec char124_stroke0[] = { + new CoordRec((float) 11.54, (float) 119.048), + new CoordRec((float) 11.54, (float) -33.3333), +}; + +static final StrokeRec char124[] = { + new StrokeRec(2, char124_stroke0), +}; + +/* char: 125 '}' */ + +static final CoordRec char125_stroke0[] = { + new CoordRec((float) 9.18, (float) 119.048), + new CoordRec((float) 18.7038, (float) 114.286), + new CoordRec((float) 23.4657, (float) 109.524), + new CoordRec((float) 28.2276, (float) 100), + new CoordRec((float) 28.2276, (float) 90.4762), + new CoordRec((float) 23.4657, (float) 80.9524), + new CoordRec((float) 18.7038, (float) 76.1905), + new CoordRec((float) 13.9419, (float) 66.6667), + new CoordRec((float) 13.9419, (float) 57.1429), + new CoordRec((float) 23.4657, (float) 47.619), +}; + +static final CoordRec char125_stroke1[] = { + new CoordRec((float) 18.7038, (float) 114.286), + new CoordRec((float) 23.4657, (float) 104.762), + new CoordRec((float) 23.4657, (float) 95.2381), + new CoordRec((float) 18.7038, (float) 85.7143), + new CoordRec((float) 13.9419, (float) 80.9524), + new CoordRec((float) 9.18, (float) 71.4286), + new CoordRec((float) 9.18, (float) 61.9048), + new CoordRec((float) 13.9419, (float) 52.381), + new CoordRec((float) 32.9895, (float) 42.8571), + new CoordRec((float) 13.9419, (float) 33.3333), + new CoordRec((float) 9.18, (float) 23.8095), + new CoordRec((float) 9.18, (float) 14.2857), + new CoordRec((float) 13.9419, (float) 4.7619), + new CoordRec((float) 18.7038, (float) 0), + new CoordRec((float) 23.4657, (float) -9.5238), + new CoordRec((float) 23.4657, (float) -19.0476), + new CoordRec((float) 18.7038, (float) -28.5714), +}; + +static final CoordRec char125_stroke2[] = { + new CoordRec((float) 23.4657, (float) 38.0952), + new CoordRec((float) 13.9419, (float) 28.5714), + new CoordRec((float) 13.9419, (float) 19.0476), + new CoordRec((float) 18.7038, (float) 9.5238), + new CoordRec((float) 23.4657, (float) 4.7619), + new CoordRec((float) 28.2276, (float) -4.7619), + new CoordRec((float) 28.2276, (float) -14.2857), + new CoordRec((float) 23.4657, (float) -23.8095), + new CoordRec((float) 18.7038, (float) -28.5714), + new CoordRec((float) 9.18, (float) -33.3333), +}; + +static final StrokeRec char125[] = { + new StrokeRec(10, char125_stroke0), + new StrokeRec(17, char125_stroke1), + new StrokeRec(10, char125_stroke2), +}; + +/* char: 126 '~' */ + +static final CoordRec char126_stroke0[] = { + new CoordRec((float) 2.92, (float) 28.5714), + new CoordRec((float) 2.92, (float) 38.0952), + new CoordRec((float) 7.6819, (float) 52.381), + new CoordRec((float) 17.2057, (float) 57.1429), + new CoordRec((float) 26.7295, (float) 57.1429), + new CoordRec((float) 36.2533, (float) 52.381), + new CoordRec((float) 55.301, (float) 38.0952), + new CoordRec((float) 64.8248, (float) 33.3333), + new CoordRec((float) 74.3486, (float) 33.3333), + new CoordRec((float) 83.8724, (float) 38.0952), + new CoordRec((float) 88.6343, (float) 47.619), +}; + +static final CoordRec char126_stroke1[] = { + new CoordRec((float) 2.92, (float) 38.0952), + new CoordRec((float) 7.6819, (float) 47.619), + new CoordRec((float) 17.2057, (float) 52.381), + new CoordRec((float) 26.7295, (float) 52.381), + new CoordRec((float) 36.2533, (float) 47.619), + new CoordRec((float) 55.301, (float) 33.3333), + new CoordRec((float) 64.8248, (float) 28.5714), + new CoordRec((float) 74.3486, (float) 28.5714), + new CoordRec((float) 83.8724, (float) 33.3333), + new CoordRec((float) 88.6343, (float) 47.619), + new CoordRec((float) 88.6343, (float) 57.1429), +}; + +static final StrokeRec char126[] = { + new StrokeRec(11, char126_stroke0), + new StrokeRec(11, char126_stroke1), +}; + +/* char: 127 */ + +static final CoordRec char127_stroke0[] = { + new CoordRec((float) 52.381, (float) 100), + new CoordRec((float) 14.2857, (float) -33.3333), +}; + +static final CoordRec char127_stroke1[] = { + new CoordRec((float) 28.5714, (float) 66.6667), + new CoordRec((float) 14.2857, (float) 61.9048), + new CoordRec((float) 4.7619, (float) 52.381), + new CoordRec((float) 0, (float) 38.0952), + new CoordRec((float) 0, (float) 23.8095), + new CoordRec((float) 4.7619, (float) 14.2857), + new CoordRec((float) 14.2857, (float) 4.7619), + new CoordRec((float) 28.5714, (float) 0), + new CoordRec((float) 38.0952, (float) 0), + new CoordRec((float) 52.381, (float) 4.7619), + new CoordRec((float) 61.9048, (float) 14.2857), + new CoordRec((float) 66.6667, (float) 28.5714), + new CoordRec((float) 66.6667, (float) 42.8571), + new CoordRec((float) 61.9048, (float) 52.381), + new CoordRec((float) 52.381, (float) 61.9048), + new CoordRec((float) 38.0952, (float) 66.6667), + new CoordRec((float) 28.5714, (float) 66.6667), +}; + +static final StrokeRec char127[] = { + new StrokeRec(2, char127_stroke0), + new StrokeRec(17, char127_stroke1), +}; + +static final StrokeCharRec chars[] = { + new StrokeCharRec( 0, /* char0 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char1 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char2 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char3 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char4 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char5 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char6 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char7 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char8 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char9 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char10 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char11 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char12 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char13 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char14 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char15 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char16 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char17 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char18 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char19 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char20 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char21 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char22 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char23 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char24 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char25 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char26 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char27 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char28 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char29 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char30 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char31 */ null, (float) 0, (float) 0 ), + new StrokeCharRec( 0, /* char32 */ null, (float) 52.381, (float) 104.762 ), + new StrokeCharRec( 2, char33, (float) 13.3819, (float) 26.6238 ), + new StrokeCharRec( 2, char34, (float) 23.0676, (float) 51.4352 ), + new StrokeCharRec( 4, char35, (float) 36.5333, (float) 79.4886 ), + new StrokeCharRec( 3, char36, (float) 38.1533, (float) 76.2067 ), + new StrokeCharRec( 3, char37, (float) 49.2171, (float) 96.5743 ), + new StrokeCharRec( 1, char38, (float) 53.599, (float) 101.758 ), + new StrokeCharRec( 1, char39, (float) 4.44, (float) 13.62 ), + new StrokeCharRec( 1, char40, (float) 21.8657, (float) 47.1733 ), + new StrokeCharRec( 1, char41, (float) 24.3276, (float) 47.5333 ), + new StrokeCharRec( 3, char42, (float) 30.7695, (float) 59.439 ), + new StrokeCharRec( 2, char43, (float) 48.8371, (float) 97.2543 ), + new StrokeCharRec( 1, char44, (float) 13.5219, (float) 26.0638 ), + new StrokeCharRec( 1, char45, (float) 50.2371, (float) 100.754 ), + new StrokeCharRec( 1, char46, (float) 13.1019, (float) 26.4838 ), + new StrokeCharRec( 1, char47, (float) 40.5733, (float) 82.1067 ), + new StrokeCharRec( 1, char48, (float) 38.3133, (float) 77.0667 ), + new StrokeCharRec( 1, char49, (float) 30.8676, (float) 66.5295 ), + new StrokeCharRec( 1, char50, (float) 38.7533, (float) 77.6467 ), + new StrokeCharRec( 1, char51, (float) 38.3333, (float) 77.0467 ), + new StrokeCharRec( 2, char52, (float) 37.2133, (float) 80.1686 ), + new StrokeCharRec( 1, char53, (float) 38.1933, (float) 77.6867 ), + new StrokeCharRec( 1, char54, (float) 34.1514, (float) 73.8048 ), + new StrokeCharRec( 2, char55, (float) 38.8933, (float) 77.2267 ), + new StrokeCharRec( 1, char56, (float) 38.9333, (float) 77.6667 ), + new StrokeCharRec( 1, char57, (float) 39.9333, (float) 74.0648 ), + new StrokeCharRec( 2, char58, (float) 14.0819, (float) 26.2238 ), + new StrokeCharRec( 2, char59, (float) 12.9619, (float) 26.3038 ), + new StrokeCharRec( 1, char60, (float) 41.1552, (float) 81.6105 ), + new StrokeCharRec( 2, char61, (float) 48.5571, (float) 97.2543 ), + new StrokeCharRec( 1, char62, (float) 40.8752, (float) 81.6105 ), + new StrokeCharRec( 2, char63, (float) 36.9914, (float) 73.9029 ), + new StrokeCharRec( 2, char64, (float) 34.9314, (float) 74.3648 ), + new StrokeCharRec( 3, char65, (float) 40.5952, (float) 80.4905 ), + new StrokeCharRec( 3, char66, (float) 44.7533, (float) 83.6267 ), + new StrokeCharRec( 1, char67, (float) 39.9933, (float) 84.4886 ), + new StrokeCharRec( 2, char68, (float) 45.2933, (float) 85.2867 ), + new StrokeCharRec( 4, char69, (float) 39.9914, (float) 78.1848 ), + new StrokeCharRec( 3, char70, (float) 39.9914, (float) 78.7448 ), + new StrokeCharRec( 2, char71, (float) 40.3933, (float) 89.7686 ), + new StrokeCharRec( 3, char72, (float) 44.7533, (float) 89.0867 ), + new StrokeCharRec( 1, char73, (float) 10.86, (float) 21.3 ), + new StrokeCharRec( 1, char74, (float) 31.0714, (float) 59.999 ), + new StrokeCharRec( 3, char75, (float) 44.6133, (float) 79.3267 ), + new StrokeCharRec( 2, char76, (float) 40.2514, (float) 71.3229 ), + new StrokeCharRec( 4, char77, (float) 48.9552, (float) 97.2105 ), + new StrokeCharRec( 3, char78, (float) 44.4733, (float) 88.8067 ), + new StrokeCharRec( 1, char79, (float) 44.3352, (float) 88.8305 ), + new StrokeCharRec( 2, char80, (float) 45.4333, (float) 85.6667 ), + new StrokeCharRec( 2, char81, (float) 43.3952, (float) 88.0905 ), + new StrokeCharRec( 3, char82, (float) 45.0133, (float) 82.3667 ), + new StrokeCharRec( 1, char83, (float) 41.3333, (float) 80.8267 ), + new StrokeCharRec( 2, char84, (float) 35.6933, (float) 71.9467 ), + new StrokeCharRec( 1, char85, (float) 44.8733, (float) 89.4867 ), + new StrokeCharRec( 2, char86, (float) 40.4552, (float) 81.6105 ), + new StrokeCharRec( 4, char87, (float) 49.839, (float) 100.518 ), + new StrokeCharRec( 2, char88, (float) 35.8333, (float) 72.3667 ), + new StrokeCharRec( 2, char89, (float) 39.6152, (float) 79.6505 ), + new StrokeCharRec( 3, char90, (float) 35.8333, (float) 73.7467 ), + new StrokeCharRec( 4, char91, (float) 22.0657, (float) 46.1133 ), + new StrokeCharRec( 1, char92, (float) 39.1733, (float) 78.2067 ), + new StrokeCharRec( 4, char93, (float) 23.4876, (float) 46.3933 ), + new StrokeCharRec( 2, char94, (float) 44.0752, (float) 90.2305 ), + new StrokeCharRec( 1, char95, (float) 51.281, (float) 104.062 ), + new StrokeCharRec( 2, char96, (float) 42.5457, (float) 83.5714 ), + new StrokeCharRec( 2, char97, (float) 35.2514, (float) 66.6029 ), + new StrokeCharRec( 2, char98, (float) 37.3314, (float) 70.4629 ), + new StrokeCharRec( 1, char99, (float) 34.0914, (float) 68.9229 ), + new StrokeCharRec( 2, char100, (float) 33.2114, (float) 70.2629 ), + new StrokeCharRec( 1, char101, (float) 34.2914, (float) 68.5229 ), + new StrokeCharRec( 2, char102, (float) 14.9657, (float) 38.6552 ), + new StrokeCharRec( 2, char103, (float) 33.9314, (float) 70.9829 ), + new StrokeCharRec( 2, char104, (float) 33.4095, (float) 71.021 ), + new StrokeCharRec( 2, char105, (float) 14.7819, (float) 28.8638 ), + new StrokeCharRec( 2, char106, (float) 17.3876, (float) 36.2314 ), + new StrokeCharRec( 3, char107, (float) 33.4095, (float) 62.521 ), + new StrokeCharRec( 1, char108, (float) 10.02, (float) 19.34 ), + new StrokeCharRec( 3, char109, (float) 61.981, (float) 123.962 ), + new StrokeCharRec( 2, char110, (float) 32.9895, (float) 70.881 ), + new StrokeCharRec( 1, char111, (float) 33.5514, (float) 71.7448 ), + new StrokeCharRec( 2, char112, (float) 38.0314, (float) 70.8029 ), + new StrokeCharRec( 2, char113, (float) 33.4114, (float) 70.7429 ), + new StrokeCharRec( 2, char114, (float) 23.7457, (float) 49.4952 ), + new StrokeCharRec( 1, char115, (float) 28.5095, (float) 62.321 ), + new StrokeCharRec( 2, char116, (float) 14.8257, (float) 39.3152 ), + new StrokeCharRec( 2, char117, (float) 33.2695, (float) 71.161 ), + new StrokeCharRec( 2, char118, (float) 30.3714, (float) 60.6029 ), + new StrokeCharRec( 4, char119, (float) 40.5952, (float) 80.4905 ), + new StrokeCharRec( 2, char120, (float) 25.4695, (float) 56.401 ), + new StrokeCharRec( 2, char121, (float) 35.1333, (float) 66.0648 ), + new StrokeCharRec( 3, char122, (float) 28.2495, (float) 61.821 ), + new StrokeCharRec( 3, char123, (float) 21.6657, (float) 41.6295 ), + new StrokeCharRec( 1, char124, (float) 11.54, (float) 23.78 ), + new StrokeCharRec( 3, char125, (float) 18.7038, (float) 41.4695 ), + new StrokeCharRec( 2, char126, (float) 45.7771, (float) 91.2743 ), + new StrokeCharRec( 2, char127, (float) 33.3333, (float) 66.6667 ), +}; + +public static final StrokeFontRec glutStrokeRoman = new StrokeFontRec( "Roman", 128, chars, (float) 119.048, (float) -33.3333 ); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/StrokeCharRec.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/StrokeCharRec.java new file mode 100644 index 000000000..af3d538ae --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/StrokeCharRec.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +/* Copyright (c) Mark J. Kilgard, 1994, 1998. */ + +/* This program is freely distributable without licensing fees + and is provided without guarantee or warrantee expressed or + implied. This program is -not- in the public domain. */ + +class StrokeCharRec { + public int num_strokes; + public StrokeRec[] stroke; + public float center; + public float right; + + public StrokeCharRec(int num_strokes, + StrokeRec[] stroke, + float center, + float right) { + this.num_strokes = num_strokes; + this.stroke = stroke; + this.center = center; + this.right = right; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/StrokeFontRec.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/StrokeFontRec.java new file mode 100644 index 000000000..d3195f24d --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/StrokeFontRec.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +/* Copyright (c) Mark J. Kilgard, 1994, 1998. */ + +/* This program is freely distributable without licensing fees + and is provided without guarantee or warrantee expressed or + implied. This program is -not- in the public domain. */ + +class StrokeFontRec { + public String name; + public int num_chars; + public StrokeCharRec[] ch; + public float top; + public float bottom; + + public StrokeFontRec(String name, + int num_chars, + StrokeCharRec[] ch, + float top, + float bottom) { + this.name = name; + this.num_chars = num_chars; + this.ch = ch; + this.top = top; + this.bottom = bottom; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/StrokeRec.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/StrokeRec.java new file mode 100644 index 000000000..8796e8b08 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/StrokeRec.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.gl2; + +/* Copyright (c) Mark J. Kilgard, 1994, 1998. */ + +/* This program is freely distributable without licensing fees + and is provided without guarantee or warrantee expressed or + implied. This program is -not- in the public domain. */ + +class StrokeRec { + public int num_coords; + public CoordRec[] coord; + + public StrokeRec(int num_coords, + CoordRec[] coord) { + this.num_coords = num_coords; + this.coord = coord; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/TileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/TileRenderer.java new file mode 100644 index 000000000..714c134d4 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/TileRenderer.java @@ -0,0 +1,601 @@ +package com.jogamp.opengl.util.gl2; + +import java.awt.Dimension; +import java.nio.Buffer; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import javax.media.opengl.glu.gl2.*; + +/** + * A fairly direct port of Brian Paul's tile rendering library, found + * at <a href = "http://www.mesa3d.org/brianp/TR.html"> + * http://www.mesa3d.org/brianp/TR.html </a> . I've java-fied it, but + * the functionality is the same. + * + * Original code Copyright (C) 1997-2005 Brian Paul. Licensed under + * BSD-compatible terms with permission of the author. See LICENSE.txt + * for license information. + * + * @author ryanm + */ +public class TileRenderer +{ + private static final int DEFAULT_TILE_WIDTH = 256; + + private static final int DEFAULT_TILE_HEIGHT = 256; + + private static final int DEFAULT_TILE_BORDER = 0; + + // + // Enumeration flags for accessing variables + // + // @author ryanm + // + + /** + * The width of a tile + */ + public static final int TR_TILE_WIDTH = 0; + /** + * The height of a tile + */ + public static final int TR_TILE_HEIGHT = 1; + /** + * The width of the border around the tiles + */ + public static final int TR_TILE_BORDER = 2; + /** + * The width of the final image + */ + public static final int TR_IMAGE_WIDTH = 3; + /** + * The height of the final image + */ + public static final int TR_IMAGE_HEIGHT = 4; + /** + * The number of rows of tiles + */ + public static final int TR_ROWS = 5; + /** + * The number of columns of tiles + */ + public static final int TR_COLUMNS = 6; + /** + * The current row number + */ + public static final int TR_CURRENT_ROW = 7; + /** + * The current column number + */ + public static final int TR_CURRENT_COLUMN = 8; + /** + * The width of the current tile + */ + public static final int TR_CURRENT_TILE_WIDTH = 9; + /** + * The height of the current tile + */ + public static final int TR_CURRENT_TILE_HEIGHT = 10; + /** + * The order that the rows are traversed + */ + public static final int TR_ROW_ORDER = 11; + + + /** + * Indicates we are traversing rows from the top to the bottom + */ + public static final int TR_TOP_TO_BOTTOM = 1; + + /** + * Indicates we are traversing rows from the bottom to the top + */ + public static final int TR_BOTTOM_TO_TOP = 2; + + /* Final image parameters */ + private Dimension imageSize = new Dimension(); + + private int imageFormat, imageType; + + private Buffer imageBuffer; + + /* Tile parameters */ + private Dimension tileSize = new Dimension(); + + private Dimension tileSizeNB = new Dimension(); + + private int tileBorder; + + private int tileFormat, tileType; + + private Buffer tileBuffer; + + /* Projection parameters */ + private boolean perspective; + + private double left; + + private double right; + + private double bottom; + + private double top; + + private double near; + + private double far; + + /* Misc */ + private int rowOrder; + + private int rows, columns; + + private int currentTile; + + private int currentTileWidth, currentTileHeight; + + private int currentRow, currentColumn; + + private int[] viewportSave = new int[ 4 ]; + + /** + * Creates a new TileRenderer object + */ + public TileRenderer() + { + tileSize.width = DEFAULT_TILE_WIDTH; + tileSize.height = DEFAULT_TILE_HEIGHT; + tileBorder = DEFAULT_TILE_BORDER; + rowOrder = TR_BOTTOM_TO_TOP; + currentTile = -1; + } + + /** + * Sets up the number of rows and columns needed + */ + private void setup() + { + columns = ( imageSize.width + tileSizeNB.width - 1 ) / tileSizeNB.width; + rows = ( imageSize.height + tileSizeNB.height - 1 ) / tileSizeNB.height; + currentTile = 0; + + assert columns >= 0; + assert rows >= 0; + } + + /** + * Sets the size of the tiles to use in rendering. The actual + * effective size of the tile depends on the border size, ie ( + * width - 2*border ) * ( height - 2 * border ) + * + * @param width + * The width of the tiles. Must not be larger than the GL + * context + * @param height + * The height of the tiles. Must not be larger than the + * GL context + * @param border + * The width of the borders on each tile. This is needed + * to avoid artifacts when rendering lines or points with + * thickness > 1. + */ + public void setTileSize( int width, int height, int border ) + { + assert ( border >= 0 ); + assert ( width >= 1 ); + assert ( height >= 1 ); + assert ( width >= 2 * border ); + assert ( height >= 2 * border ); + + tileBorder = border; + tileSize.width = width; + tileSize.height = height; + tileSizeNB.width = width - 2 * border; + tileSizeNB.height = height - 2 * border; + setup(); + } + + /** + * Specify a buffer the tiles to be copied to. This is not + * necessary for the creation of the final image, but useful if you + * want to inspect each tile in turn. + * + * @param format + * Interpreted as in glReadPixels + * @param type + * Interpreted as in glReadPixels + * @param image + * The buffer itself. Must be large enough to contain a + * tile, minus any borders + */ + public void setTileBuffer( int format, int type, Buffer image ) + { + tileFormat = format; + tileType = type; + tileBuffer = image; + } + + /** + * Sets the desired size of the final image + * + * @param width + * The width of the final image + * @param height + * The height of the final image + */ + public void setImageSize( int width, int height ) + { + imageSize.width = width; + imageSize.height = height; + setup(); + } + + /** + * Sets the buffer in which to store the final image + * + * @param format + * Interpreted as in glReadPixels + * @param type + * Interpreted as in glReadPixels + * @param image + * the buffer itself, must be large enough to hold the + * final image + */ + public void setImageBuffer( int format, int type, Buffer image ) + { + imageFormat = format; + imageType = type; + imageBuffer = image; + } + + /** + * Gets the parameters of this TileRenderer object + * + * @param param + * The parameter that is to be retrieved + * @return the value of the parameter + */ + public int getParam( int param ) + { + switch (param) { + case TR_TILE_WIDTH: + return tileSize.width; + case TR_TILE_HEIGHT: + return tileSize.height; + case TR_TILE_BORDER: + return tileBorder; + case TR_IMAGE_WIDTH: + return imageSize.width; + case TR_IMAGE_HEIGHT: + return imageSize.height; + case TR_ROWS: + return rows; + case TR_COLUMNS: + return columns; + case TR_CURRENT_ROW: + if( currentTile < 0 ) + return -1; + else + return currentRow; + case TR_CURRENT_COLUMN: + if( currentTile < 0 ) + return -1; + else + return currentColumn; + case TR_CURRENT_TILE_WIDTH: + return currentTileWidth; + case TR_CURRENT_TILE_HEIGHT: + return currentTileHeight; + case TR_ROW_ORDER: + return rowOrder; + default: + throw new IllegalArgumentException("Invalid enumerant as argument"); + } + } + + /** + * Sets the order of row traversal + * + * @param order + * The row traversal order, must be + * eitherTR_TOP_TO_BOTTOM or TR_BOTTOM_TO_TOP + */ + public void setRowOrder( int order ) + { + if (order == TR_TOP_TO_BOTTOM || order == TR_BOTTOM_TO_TOP) { + rowOrder = order; + } else { + throw new IllegalArgumentException("Must pass TR_TOP_TO_BOTTOM or TR_BOTTOM_TO_TOP"); + } + } + + /** + * Sets the context to use an orthographic projection. Must be + * called before rendering the first tile + * + * @param left + * As in glOrtho + * @param right + * As in glOrtho + * @param bottom + * As in glOrtho + * @param top + * As in glOrtho + * @param zNear + * As in glOrtho + * @param zFar + * As in glOrtho + */ + public void trOrtho( double left, double right, double bottom, double top, double zNear, + double zFar ) + { + this.perspective = false; + this.left = left; + this.right = right; + this.bottom = bottom; + this.top = top; + this.near = zNear; + this.far = zFar; + } + + /** + * Sets the perspective projection frustrum. Must be called before + * rendering the first tile + * + * @param left + * As in glFrustrum + * @param right + * As in glFrustrum + * @param bottom + * As in glFrustrum + * @param top + * As in glFrustrum + * @param zNear + * As in glFrustrum + * @param zFar + * As in glFrustrum + */ + public void trFrustum( double left, double right, double bottom, double top, double zNear, + double zFar ) + { + this.perspective = true; + this.left = left; + this.right = right; + this.bottom = bottom; + this.top = top; + this.near = zNear; + this.far = zFar; + } + + /** + * Convenient way to specify a perspective projection + * + * @param fovy + * As in gluPerspective + * @param aspect + * As in gluPerspective + * @param zNear + * As in gluPerspective + * @param zFar + * As in gluPerspective + */ + public void trPerspective( double fovy, double aspect, double zNear, double zFar ) + { + double xmin, xmax, ymin, ymax; + ymax = zNear * Math.tan( fovy * 3.14159265 / 360.0 ); + ymin = -ymax; + xmin = ymin * aspect; + xmax = ymax * aspect; + trFrustum( xmin, xmax, ymin, ymax, zNear, zFar ); + } + + /** + * Begins rendering a tile. The projection matrix stack should be + * left alone after calling this + * + * @param gl + * The gl context + */ + public void beginTile( GL2 gl ) + { + if (currentTile <= 0) { + setup(); + /* + * Save user's viewport, will be restored after last tile + * rendered + */ + gl.glGetIntegerv( GL2.GL_VIEWPORT, viewportSave, 0 ); + } + + /* which tile (by row and column) we're about to render */ + if (rowOrder == TR_BOTTOM_TO_TOP) { + currentRow = currentTile / columns; + currentColumn = currentTile % columns; + } else { + currentRow = rows - ( currentTile / columns ) - 1; + currentColumn = currentTile % columns; + } + assert ( currentRow < rows ); + assert ( currentColumn < columns ); + + int border = tileBorder; + + int th, tw; + + /* Compute actual size of this tile with border */ + if (currentRow < rows - 1) { + th = tileSize.height; + } else { + th = imageSize.height - ( rows - 1 ) * ( tileSizeNB.height ) + 2 * border; + } + + if (currentColumn < columns - 1) { + tw = tileSize.width; + } else { + tw = imageSize.width - ( columns - 1 ) * ( tileSizeNB.width ) + 2 * border; + } + + /* Save tile size, with border */ + currentTileWidth = tw; + currentTileHeight = th; + + gl.glViewport( 0, 0, tw, th ); + + /* save current matrix mode */ + int[] matrixMode = new int[ 1 ]; + gl.glGetIntegerv( GL2.GL_MATRIX_MODE, matrixMode, 0 ); + gl.glMatrixMode( GL2.GL_PROJECTION ); + gl.glLoadIdentity(); + + /* compute projection parameters */ + double l = + left + ( right - left ) * ( currentColumn * tileSizeNB.width - border ) + / imageSize.width; + double r = l + ( right - left ) * tw / imageSize.width; + double b = + bottom + ( top - bottom ) * ( currentRow * tileSizeNB.height - border ) + / imageSize.height; + double t = b + ( top - bottom ) * th / imageSize.height; + + if( perspective ) { + gl.glFrustum( l, r, b, t, near, far ); + } else { + gl.glOrtho( l, r, b, t, near, far ); + } + + /* restore user's matrix mode */ + gl.glMatrixMode( matrixMode[ 0 ] ); + } + + /** + * Must be called after rendering the scene + * + * @param gl + * the gl context + * @return true if there are more tiles to be rendered, false if + * the final image is complete + */ + public boolean endTile( GL2 gl ) + { + int[] prevRowLength = new int[ 1 ], prevSkipRows = new int[ 1 ], prevSkipPixels = new int[ 1 ], prevAlignment = + new int[ 1 ]; + + assert ( currentTile >= 0 ); + + // be sure OpenGL rendering is finished + gl.glFlush(); + + // save current glPixelStore values + gl.glGetIntegerv( GL2.GL_PACK_ROW_LENGTH, prevRowLength, 0 ); + gl.glGetIntegerv( GL2.GL_PACK_SKIP_ROWS, prevSkipRows, 0 ); + gl.glGetIntegerv( GL2.GL_PACK_SKIP_PIXELS, prevSkipPixels, 0 ); + gl.glGetIntegerv( GL2.GL_PACK_ALIGNMENT, prevAlignment, 0 ); + + if( tileBuffer != null ) { + int srcX = tileBorder; + int srcY = tileBorder; + int srcWidth = tileSizeNB.width; + int srcHeight = tileSizeNB.height; + gl.glReadPixels( srcX, srcY, srcWidth, srcHeight, tileFormat, tileType, tileBuffer ); + } + + if( imageBuffer != null ) { + int srcX = tileBorder; + int srcY = tileBorder; + int srcWidth = currentTileWidth - 2 * tileBorder; + int srcHeight = currentTileHeight - 2 * tileBorder; + int destX = tileSizeNB.width * currentColumn; + int destY = tileSizeNB.height * currentRow; + + /* setup pixel store for glReadPixels */ + gl.glPixelStorei( GL2.GL_PACK_ROW_LENGTH, imageSize.width ); + gl.glPixelStorei( GL2.GL_PACK_SKIP_ROWS, destY ); + gl.glPixelStorei( GL2.GL_PACK_SKIP_PIXELS, destX ); + gl.glPixelStorei( GL2.GL_PACK_ALIGNMENT, 1 ); + + /* read the tile into the final image */ + gl.glReadPixels( srcX, srcY, srcWidth, srcHeight, imageFormat, imageType, imageBuffer ); + } + + /* restore previous glPixelStore values */ + gl.glPixelStorei( GL2.GL_PACK_ROW_LENGTH, prevRowLength[ 0 ] ); + gl.glPixelStorei( GL2.GL_PACK_SKIP_ROWS, prevSkipRows[ 0 ] ); + gl.glPixelStorei( GL2.GL_PACK_SKIP_PIXELS, prevSkipPixels[ 0 ] ); + gl.glPixelStorei( GL2.GL_PACK_ALIGNMENT, prevAlignment[ 0 ] ); + + /* increment tile counter, return 1 if more tiles left to render */ + currentTile++; + if( currentTile >= rows * columns ) { + /* restore user's viewport */ + gl.glViewport( viewportSave[ 0 ], viewportSave[ 1 ], viewportSave[ 2 ], viewportSave[ 3 ] ); + currentTile = -1; /* all done */ + return false; + } else { + return true; + } + } + + /** + * Tile rendering causes problems with using glRasterPos3f, so you + * should use this replacement instead + * + * @param x + * As in glRasterPos3f + * @param y + * As in glRasterPos3f + * @param z + * As in glRasterPos3f + * @param gl + * The gl context + * @param glu + * A GLUgl2 object + */ + public void trRasterPos3f( float x, float y, float z, GL2 gl, GLUgl2 glu ) + { + if (currentTile < 0) { + /* not doing tile rendering right now. Let OpenGL do this. */ + gl.glRasterPos3f( x, y, z ); + } else { + double[] modelview = new double[ 16 ], proj = new double[ 16 ]; + int[] viewport = new int[ 4 ]; + double[] win = new double[3]; + + /* Get modelview, projection and viewport */ + gl.glGetDoublev( GL2.GL_MODELVIEW_MATRIX, modelview, 0 ); + gl.glGetDoublev( GL2.GL_PROJECTION_MATRIX, proj, 0 ); + viewport[ 0 ] = 0; + viewport[ 1 ] = 0; + viewport[ 2 ] = currentTileWidth; + viewport[ 3 ] = currentTileHeight; + + /* Project object coord to window coordinate */ + if( glu.gluProject( x, y, z, modelview, 0, proj, 0, viewport, 0, win, 0 ) ) { + + /* set raster pos to window coord (0,0) */ + gl.glMatrixMode( GL2.GL_MODELVIEW ); + gl.glPushMatrix(); + gl.glLoadIdentity(); + gl.glMatrixMode( GL2.GL_PROJECTION ); + gl.glPushMatrix(); + gl.glLoadIdentity(); + gl.glOrtho( 0.0, currentTileWidth, 0.0, currentTileHeight, 0.0, 1.0 ); + gl.glRasterPos3d( 0.0, 0.0, -win[ 2 ] ); + + /* + * Now use empty bitmap to adjust raster position to + * (winX,winY) + */ + { + byte[] bitmap = { 0 }; + gl.glBitmap( 1, 1, 0.0f, 0.0f, ( float ) win[ 0 ], ( float ) win[ 1 ], bitmap , 0 ); + } + + /* restore original matrices */ + gl.glPopMatrix(); /* proj */ + gl.glMatrixMode( GL2.GL_MODELVIEW ); + gl.glPopMatrix(); + } + } + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java new file mode 100644 index 000000000..95a550ab6 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java @@ -0,0 +1,85 @@ +/** + * 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.util.glsl; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; +import java.nio.*; + +public class GLSLArrayHandler implements GLArrayHandler { + private GLArrayDataEditable ad; + + public GLSLArrayHandler(GLArrayDataEditable ad) { + this.ad = ad; + } + + protected final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) { + st.glVertexAttribPointer(gl, ad); + } + + public void enableBuffer(GL gl, boolean enable) { + if(!gl.isGL2ES2()) { + throw new GLException("GLSLArrayHandler expects a GL2ES2 implementation"); + } + GL2ES2 glsl = gl.getGL2ES2(); + ShaderState st = ShaderState.getCurrent(); + if(null==st) { + throw new GLException("No ShaderState current"); + } + + if(enable) { + st.glEnableVertexAttribArray(glsl, ad.getName()); + + Buffer buffer = ad.getBuffer(); + + if(ad.isVBO()) { + // always bind and refresh the VBO mgr, + // in case more than one gl*Pointer objects are in use + glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); + if(!ad.isBufferWritten()) { + if(null!=buffer) { + glsl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); + } + ad.setBufferWritten(true); + } + passVertexAttribPointer(glsl, st); + } else if(null!=buffer) { + passVertexAttribPointer(glsl, st); + ad.setBufferWritten(true); + } + } else { + if(ad.isVBO()) { + glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } + st.glDisableVertexAttribArray(glsl, ad.getName()); + } + } + +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java new file mode 100644 index 000000000..1f59318f2 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -0,0 +1,366 @@ +/** + * 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.util.glsl; + +import com.jogamp.common.nio.Buffers; +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; +import jogamp.opengl.Debug; + +import java.util.*; +import java.nio.*; +import java.io.*; +import java.net.*; +import java.security.*; + +public class ShaderCode { + public static final boolean DEBUG = Debug.debug("GLSLCode"); + public static final boolean DEBUG_CODE = Debug.isPropertyDefined("jogl.debug.GLSLCode", true, AccessController.getContext()); + + public static final String SUFFIX_VERTEX_SOURCE = "vp" ; + public static final String SUFFIX_VERTEX_BINARY = "bvp" ; + public static final String SUFFIX_FRAGMENT_SOURCE = "fp" ; + public static final String SUFFIX_FRAGMENT_BINARY = "bfp" ; + + public static final String SUB_PATH_NVIDIA = "nvidia" ; + + public ShaderCode(int type, int number, String[][] source) { + switch (type) { + case GL2ES2.GL_VERTEX_SHADER: + case GL2ES2.GL_FRAGMENT_SHADER: + break; + default: + throw new GLException("Unknown shader type: "+type); + } + shaderSource = source; + shaderBinaryFormat = -1; + shaderBinary = null; + shaderType = type; + shader = Buffers.newDirectIntBuffer(number); + id = getNextID(); + + if(DEBUG_CODE) { + System.out.println("Created: "+toString()); + dumpShaderSource(System.out); + } + } + + public ShaderCode(int type, int number, int binFormat, Buffer binary) { + switch (type) { + case GL2ES2.GL_VERTEX_SHADER: + case GL2ES2.GL_FRAGMENT_SHADER: + break; + default: + throw new GLException("Unknown shader type: "+type); + } + shaderSource = null; + shaderBinaryFormat = binFormat; + shaderBinary = binary; + shaderType = type; + shader = Buffers.newDirectIntBuffer(number); + id = getNextID(); + } + + public static ShaderCode create(GL2ES2 gl, int type, int number, Class context, String[] sourceFiles) { + if(!ShaderUtil.isShaderCompilerAvailable(gl)) return null; + + String[][] shaderSources = null; + if(null!=sourceFiles) { + shaderSources = new String[sourceFiles.length][1]; + for(int i=0; null!=shaderSources && i<sourceFiles.length; i++) { + shaderSources[i][0] = readShaderSource(context, sourceFiles[i]); + if(null == shaderSources[i][0]) { + shaderSources = null; + } + } + } + if(null==shaderSources) { + return null; + } + return new ShaderCode(type, number, shaderSources); + } + + public static ShaderCode create(int type, int number, Class context, int binFormat, String binaryFile) { + ByteBuffer shaderBinary = null; + if(null!=binaryFile && 0<=binFormat) { + shaderBinary = readShaderBinary(context, binaryFile); + if(null == shaderBinary) { + binFormat = -1; + } + } + if(null==shaderBinary) { + return null; + } + return new ShaderCode(type, number, binFormat, shaderBinary); + } + + public static String getFileSuffix(boolean binary, int type) { + switch (type) { + case GL2ES2.GL_VERTEX_SHADER: + return binary?SUFFIX_VERTEX_BINARY:SUFFIX_VERTEX_SOURCE; + case GL2ES2.GL_FRAGMENT_SHADER: + return binary?SUFFIX_FRAGMENT_BINARY:SUFFIX_FRAGMENT_SOURCE; + default: + throw new GLException("illegal shader type: "+type); + } + } + + public static String getBinarySubPath(int binFormat) { + switch (binFormat) { + case GLES2.GL_NVIDIA_PLATFORM_BINARY_NV: + return SUB_PATH_NVIDIA; + default: + throw new GLException("unsupported binary format: "+binFormat); + } + } + + public static ShaderCode create(GL2ES2 gl, int type, int number, Class context, + String srcRoot, String binRoot, String basename) { + ShaderCode res = null; + String srcFileName = null; + String binFileName = null; + + if(ShaderUtil.isShaderCompilerAvailable(gl)) { + String srcPath[] = new String[1]; + srcFileName = srcRoot + '/' + basename + "." + getFileSuffix(false, type); + srcPath[0] = srcFileName; + res = create(gl, type, number, context, srcPath); + if(null!=res) { + return res; + } + } + Set binFmts = ShaderUtil.getShaderBinaryFormats(gl); + for(Iterator iter=binFmts.iterator(); null==res && iter.hasNext(); ) { + int bFmt = ((Integer)(iter.next())).intValue(); + String bFmtPath = getBinarySubPath(bFmt); + if(null==bFmtPath) continue; + binFileName = binRoot + '/' + bFmtPath + '/' + basename + "." + getFileSuffix(true, type); + res = create(type, number, context, bFmt, binFileName); + } + + if(null==res) { + throw new GLException("No shader code found (source nor binary) for src: "+srcFileName+ + ", bin: "+binFileName); + } + + return res; + } + + /** + * returns the uniq shader id as an integer + * @see #key() + */ + public int id() { return id.intValue(); } + + /** + * returns the uniq shader id as an Integer + * + * @see #id() + */ + public Integer key() { return id; } + + public int shaderType() { return shaderType; } + public String shaderTypeStr() { return shaderTypeStr(shaderType); } + + public static String shaderTypeStr(int type) { + switch (type) { + case GL2ES2.GL_VERTEX_SHADER: + return "VERTEX_SHADER"; + case GL2ES2.GL_FRAGMENT_SHADER: + return "FRAGMENT_SHADER"; + } + return "UNKNOWN_SHADER"; + } + + public int shaderBinaryFormat() { return shaderBinaryFormat; } + public Buffer shaderBinary() { return shaderBinary; } + public String[][] shaderSource() { return shaderSource; } + + public boolean isValid() { return valid; } + + public IntBuffer shader() { return shader; } + + public boolean compile(GL2ES2 gl) { + return compile(gl, null); + } + public boolean compile(GL2ES2 gl, PrintStream verboseOut) { + if(isValid()) return true; + + // Create & Compile the vertex/fragment shader objects + if(null!=shaderSource) { + valid=ShaderUtil.createAndCompileShader(gl, shader, shaderType, + shaderSource, verboseOut); + } else if(null!=shaderBinary) { + valid=ShaderUtil.createAndLoadShader(gl, shader, shaderType, + shaderBinaryFormat, shaderBinary, verboseOut); + } else { + throw new GLException("no code (source or binary)"); + } + return valid; + } + + public void destroy(GL2ES2 gl) { + if(isValid()) { + if(null!=gl) { + ShaderUtil.deleteShader(gl, shader()); + } + valid=false; + } + if(null!=shaderBinary) { + shaderBinary.clear(); + shaderBinary=null; + } + shaderSource=null; + shaderBinaryFormat=-1; + shaderType=-1; + id=null; + } + + public boolean equals(Object obj) { + if(this==obj) { return true; } + if(obj instanceof ShaderCode) { + return id()==((ShaderCode)obj).id(); + } + return false; + } + public int hashCode() { + return id.intValue(); + } + public String toString() { + StringBuffer buf = new StringBuffer("ShaderCode [id="+id+", type="+shaderTypeStr()+", valid="+valid+", shader: "); + for(int i=0; i<shader.remaining(); i++) { + buf.append(" "+shader.get(i)); + } + if(null!=shaderSource) { + buf.append(", source]"); + } else if(null!=shaderBinary) { + buf.append(", binary "+shaderBinary+"]"); + } + return buf.toString(); + } + + public void dumpShaderSource(PrintStream out) { + if(null==shaderSource) { + out.println("<no shader source>"); + return; + } + int sourceNum = (null!=shaderSource)?shaderSource.length:0; + int shaderNum = (null!=shader)?shader.capacity():0; + for(int i=0; i<shaderNum; i++) { + out.println(""); + out.println("Shader #"+i+"/"+shaderNum+" name "+shader.get(i)); + out.println("--------------------------------------------------------------"); + if(i>=sourceNum) { + out.println("<no shader source>"); + } else { + String[] src = shaderSource[i]; + for(int j=0; j<src.length; j++) { + out.println("Segment "+j+"/"+src.length+" :"); + out.println(src[j]); + out.println(""); + } + } + out.println("--------------------------------------------------------------"); + } + } + + public static void readShaderSource(ClassLoader context, String path, URL url, StringBuffer result) { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); + String line = null; + while ((line = reader.readLine()) != null) { + if (line.startsWith("#include ")) { + String includeFile = line.substring(9).trim(); + // Try relative path first + String next = Locator.getRelativeOf(path, includeFile); + URL nextURL = Locator.getResource(next, context); + if (nextURL == null) { + // Try absolute path + next = includeFile; + nextURL = Locator.getResource(next, context); + } + if (nextURL == null) { + // Fail + throw new FileNotFoundException("Can't find include file " + includeFile); + } + readShaderSource(context, next, nextURL, result); + } else { + result.append(line + "\n"); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static String readShaderSource(Class context, String path) { + ClassLoader contextCL = (null!=context)?context.getClassLoader():null; + URL url = Locator.getResource(context, path); + if (url == null) { + return null; + } + File pf = new File(url.getPath()); + path = pf.getParent() + "/" ; + + StringBuffer result = new StringBuffer(); + readShaderSource(contextCL, path, url, result); + return result.toString(); + } + + public static ByteBuffer readShaderBinary(Class context, String path) { + try { + URL url = Locator.getResource(context, path); + if (url == null) { + return null; + } + return StreamUtil.readAll2Buffer(new BufferedInputStream(url.openStream())); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + protected String[][] shaderSource = null; + protected Buffer shaderBinary = null; + protected int shaderBinaryFormat = -1; + protected IntBuffer shader = null; + protected int shaderType = -1; + protected Integer id = null; + + protected boolean valid=false; + + private static synchronized Integer getNextID() { + return new Integer(nextID++); + } + protected static int nextID = 1; +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java new file mode 100644 index 000000000..131858271 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java @@ -0,0 +1,244 @@ +/** + * 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.util.glsl; + +import javax.media.opengl.*; + +import java.util.HashMap; +import java.util.Iterator; +import java.io.PrintStream; + +public class ShaderProgram { + public ShaderProgram() { + id = getNextID(); + } + + public boolean linked() { + return programLinked; + } + + public boolean inUse() { + return programInUse; + } + + public int program() { return shaderProgram; } + + /** + * returns the uniq shader id as an integer + * @see #key() + */ + public int id() { return id.intValue(); } + + /** + * returns the uniq shader id as an Integer + * + * @see #id() + */ + public Integer key() { return id; } + + /** + * Detaches all shader codes and deletes the program. + * Destroys the shader codes as well. + * Calls release(gl, true) + * + * @see #release(GL2ES2, boolean) + */ + public synchronized void destroy(GL2ES2 gl) { + release(gl, true); + } + + /** + * Detaches all shader codes and deletes the program. + * Calls release(gl, false) + * + * @see #release(GL2ES2, boolean) + */ + public synchronized void release(GL2ES2 gl) { + release(gl, false); + } + + /** + * Detaches all shader codes and deletes the program. + * If releaseShaderToo is true, destroys the shader codes as well. + */ + public synchronized void release(GL2ES2 gl, boolean releaseShaderToo) { + glUseProgram(gl, false); + for(Iterator iter=shaderMap.values().iterator(); iter.hasNext(); ) { + ShaderCode shaderCode = (ShaderCode) iter.next(); + ShaderUtil.detachShader(gl, shaderProgram, shaderCode.shader()); + if(releaseShaderToo) { + shaderCode.destroy(gl); + } + } + shaderMap.clear(); + gl.glDeleteProgram(shaderProgram); + shaderProgram=-1; + } + + // + // ShaderCode handling + // + + /** + * Adds a new shader to a this non running program. + * + * @return false if the program is in use, or the shader already exist, + * otherwise true. + */ + public synchronized boolean add(ShaderCode shaderCode) { + if(shaderMap.containsKey(shaderCode.key())) return false; + shaderMap.put(shaderCode.key(), shaderCode); + return true; + } + + public synchronized ShaderCode getShader(int id) { + return (ShaderCode) shaderMap.get(new Integer(id)); + } + + // + // Program handling + // + + /** + * Replace a shader in a 'running' program. + * Refetches all previously bin/get attribute names + * and resets all attribute data as well + * + * @param gl + * @param oldShaderID the to be replace Shader + * @param newShader the new ShaderCode + * @param verboseOut the optional verbose outputstream + * @throws GLException is the program is not linked + * + * @see ShaderState#glEnableVertexAttribArray + * @see ShaderState#glDisableVertexAttribArray + * @see ShaderState#glVertexAttribPointer + * @see ShaderState#getVertexAttribPointer + * @see ShaderState#glReleaseAllVertexAttributes + * @see ShaderState#glResetAllVertexAttributes + * @see ShaderState#glResetAllVertexAttributes + * @see ShaderState#glResetAllVertexAttributes + */ + public synchronized boolean glReplaceShader(GL2ES2 gl, int oldShaderID, ShaderCode newShader, PrintStream verboseOut) { + if(!programLinked) throw new GLException("Program is not linked"); + boolean shaderWasInUse = programInUse; + glUseProgram(gl, false); + if(!newShader.compile(gl, verboseOut)) { + return false; + } + if(oldShaderID>=0) { + ShaderCode oldShader = (ShaderCode) shaderMap.remove(new Integer(oldShaderID)); + if(null!=oldShader) { + ShaderUtil.detachShader(gl, shaderProgram, oldShader.shader()); + } + } + add(newShader); + + ShaderUtil.attachShader(gl, shaderProgram, newShader.shader()); + gl.glLinkProgram(shaderProgram); + if ( ! ShaderUtil.isProgramValid(gl, shaderProgram, System.err) ) { + return false; + } + + if(shaderWasInUse) { + glUseProgram(gl, true); + } + return true; + } + + public synchronized boolean link(GL2ES2 gl, PrintStream verboseOut) { + if(programLinked) throw new GLException("Program is already linked"); + + if(0>shaderProgram) { + shaderProgram = gl.glCreateProgram(); + } + + for(Iterator iter=shaderMap.values().iterator(); iter.hasNext(); ) { + ShaderCode shaderCode = (ShaderCode) iter.next(); + if(!shaderCode.compile(gl, verboseOut)) { + return false; + } + ShaderUtil.attachShader(gl, shaderProgram, shaderCode.shader()); + } + + // Link the program + gl.glLinkProgram(shaderProgram); + + programLinked = ShaderUtil.isProgramValid(gl, shaderProgram, System.err); + + return programLinked; + } + + public boolean equals(Object obj) { + if(this == obj) { return true; } + if(obj instanceof ShaderProgram) { + return id()==((ShaderProgram)obj).id(); + } + return false; + } + + public int hashCode() { + return id.intValue(); + } + + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append("ShaderProgram[id="+id); + buf.append(", linked="+programLinked+", inUse="+programInUse+", program: "+shaderProgram+", ["); + for(Iterator iter=shaderMap.values().iterator(); iter.hasNext(); ) { + buf.append((ShaderCode) iter.next()); + buf.append(" "); + } + buf.append("]"); + return buf.toString(); + } + + protected synchronized void glUseProgram(GL2ES2 gl, boolean on) { + if(!programLinked) throw new GLException("Program is not linked"); + if(programInUse==on) return; + gl.glUseProgram(on?shaderProgram:0); + programInUse = on; + + //Throwable tX = new Throwable("Info: ShaderProgram.glUseProgram: "+on); + //tX.printStackTrace(); + + } + + protected boolean programLinked = false; + protected boolean programInUse = false; + protected int shaderProgram=-1; + protected HashMap shaderMap = new HashMap(); + protected Integer id = null; + + private static synchronized Integer getNextID() { + return new Integer(nextID++); + } + protected static int nextID = 1; +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java new file mode 100644 index 000000000..57ae6cfda --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java @@ -0,0 +1,676 @@ +/** + * 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.util.glsl; + +import javax.media.opengl.*; +import jogamp.opengl.Debug; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.security.*; + +public class ShaderState { + public static final boolean DEBUG = Debug.isPropertyDefined("jogl.debug.GLSLState", true, AccessController.getContext()); + + public ShaderState() { + } + + public boolean verbose() { return verbose; } + + public void setVerbose(boolean v) { verbose=v; } + + /** + * Fetches the current shader state from the thread local storage (TLS) + * + * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean) + * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrent() + */ + public static synchronized ShaderState getCurrent() { + GLContext current = GLContext.getCurrent(); + if(null==current) { + throw new GLException("No context is current on this thread"); + } + return (ShaderState) current.getAttachedObject(ShaderState.class.getName()); + } + + /** + * Turns the shader program on or off.<br> + * Puts this ShaderState to to the thread local storage (TLS), + * if <code>on</code> is <code>true</code>. + * + * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean) + * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrent() + */ + public synchronized void glUseProgram(GL2ES2 gl, boolean on) { + if(on) { + if(null!=shaderProgram) { + shaderProgram.glUseProgram(gl, true); + } else { + throw new GLException("No program is attached"); + } + // update the current ShaderState to the TLS .. + gl.getContext().putAttachedObject(ShaderState.class.getName(), this); + } else if(null!=shaderProgram) { + shaderProgram.glUseProgram(gl, false); + } + } + + public boolean linked() { + return (null!=shaderProgram)?shaderProgram.linked():false; + } + + public boolean inUse() { + return (null!=shaderProgram)?shaderProgram.inUse():false; + } + + /** + * Attach or switch a shader program + * + * Attaching a shader program the first time, + * as well as switching to another program on the fly, + * while managing all attribute and uniform data. + */ + public synchronized void attachShaderProgram(GL2ES2 gl, ShaderProgram prog) { + boolean prgInUse = false; // earmarked state + + if(DEBUG) { + int curId = (null!=shaderProgram)?shaderProgram.id():-1; + int newId = (null!=prog)?prog.id():-1; + System.err.println("Info: attachShaderProgram: "+curId+" -> "+newId+"\n\t"+shaderProgram+"\n\t"+prog); + if(verbose) { + Throwable tX = new Throwable("Info: attachShaderProgram: Trace"); + tX.printStackTrace(); + } + } + if(null!=shaderProgram) { + if(shaderProgram.equals(prog)) { + // nothing to do .. + if(DEBUG) { + System.err.println("Info: attachShaderProgram: NOP: equal id: "+shaderProgram.id()); + } + return; + } + prgInUse = shaderProgram.inUse(); + shaderProgram.glUseProgram(gl, false); + } + + // register new one + shaderProgram = prog; + + if(null!=shaderProgram) { + // reinstall all data .. + shaderProgram.glUseProgram(gl, true); + glResetAllVertexAttributes(gl); + glResetAllUniforms(gl); + if(!prgInUse) { + shaderProgram.glUseProgram(gl, false); + } + } + if(DEBUG) { + System.err.println("Info: attachShaderProgram: END"); + } + } + + public ShaderProgram shaderProgram() { return shaderProgram; } + + /** + * Calls release(gl, true, true) + * + * @see #glReleaseAllVertexAttributes + * @see #glReleaseAllUniforms + * @see #release(GL2ES2, boolean, boolean) + */ + public synchronized void destroy(GL2ES2 gl) { + release(gl, true, true); + } + + /** + * Calls release(gl, false, false) + * + * @see #glReleaseAllVertexAttributes + * @see #glReleaseAllUniforms + * @see #release(GL2ES2, boolean, boolean) + */ + public synchronized void releaseAllData(GL2ES2 gl) { + release(gl, false, false); + } + + /** + * @see #glReleaseAllVertexAttributes + * @see #glReleaseAllUniforms + * @see ShaderProgram#release(GL2ES2, boolean) + */ + public synchronized void release(GL2ES2 gl, boolean releaseProgramToo, boolean releaseShaderToo) { + boolean prgInUse = false; + if(null!=shaderProgram) { + prgInUse = shaderProgram.inUse(); + if(!prgInUse) { + shaderProgram.glUseProgram(gl, true); + } + } + glReleaseAllVertexAttributes(gl); + glReleaseAllUniforms(gl); + if(null!=shaderProgram) { + if(releaseProgramToo) { + shaderProgram.release(gl, releaseShaderToo); + } else if(!prgInUse) { + shaderProgram.glUseProgram(gl, false); + } + } + } + + // + // Shader attribute handling + // + + /** + * Binds an attribute to the shader. + * This must be done before the program is linked ! + * n name - 1 idx, where name is a uniq key + * + * @throws GLException is the program is already linked + * + * @see #glBindAttribLocation + * @see javax.media.opengl.GL2ES2#glBindAttribLocation + * @see #glGetAttribLocation + * @see javax.media.opengl.GL2ES2#glGetAttribLocation + * @see #getAttribLocation + * @see ShaderProgram#glReplaceShader + */ + public void glBindAttribLocation(GL2ES2 gl, int index, String name) { + if(null==shaderProgram) throw new GLException("No program is attached"); + if(shaderProgram.linked()) throw new GLException("Program is already linked"); + Integer idx = new Integer(index); + if(!attribMap2Idx.containsKey(name)) { + attribMap2Idx.put(name, idx); + gl.glBindAttribLocation(shaderProgram.program(), index, name); + } + } + + /** + * Gets the index of a shader attribute. + * This must be done after the program is linked ! + * + * @return -1 if there is no such attribute available, + * otherwise >= 0 + * @throws GLException is the program is not linked + * + * @see #glBindAttribLocation + * @see javax.media.opengl.GL2ES2#glBindAttribLocation + * @see #glGetAttribLocation + * @see javax.media.opengl.GL2ES2#glGetAttribLocation + * @see #getAttribLocation + * @see ShaderProgram#glReplaceShader + */ + public int glGetAttribLocation(GL2ES2 gl, String name) { + if(!shaderProgram.linked()) throw new GLException("Program is not linked"); + int index = getAttribLocation(name); + if(0>index) { + index = gl.glGetAttribLocation(shaderProgram.program(), name); + if(0<=index) { + Integer idx = new Integer(index); + attribMap2Idx.put(name, idx); + if(DEBUG) { + System.err.println("Info: glGetAttribLocation: "+name+", loc: "+index); + } + } else if(verbose) { + Throwable tX = new Throwable("Info: glGetAttribLocation failed, no location for: "+name+", index: "+index); + tX.printStackTrace(); + } + } + return index; + } + + protected int getAttribLocation(String name) { + Integer idx = (Integer) attribMap2Idx.get(name); + return (null!=idx)?idx.intValue():-1; + } + + + // + // Enabled Vertex Arrays and its data + // + + /** + * Enable a vertex attribute array + * + * Even if the attribute is not found in the current shader, + * it is stored in this state. + * + * @return false, if the name is not found, otherwise true + * + * @throws GLException if the program is not in use + * + * @see #glEnableVertexAttribArray + * @see #glDisableVertexAttribArray + * @see #glVertexAttribPointer + * @see #getVertexAttribPointer + * @see #glReleaseAllVertexAttributes + * @see #glResetAllVertexAttributes + * @see ShaderProgram#glReplaceShader + */ + public boolean glEnableVertexAttribArray(GL2ES2 gl, String name) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + enabledVertexAttribArraySet.add(name); + int index = glGetAttribLocation(gl, name); + if(0>index) { + if(verbose) { + Throwable tX = new Throwable("Info: glEnableVertexAttribArray failed, no index for: "+name); + tX.printStackTrace(); + } + return false; + } + if(DEBUG) { + System.err.println("Info: glEnableVertexAttribArray: "+name+", loc: "+index); + } + gl.glEnableVertexAttribArray(index); + return true; + } + + public boolean isVertexAttribArrayEnabled(String name) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + return enabledVertexAttribArraySet.contains(name); + } + + /** + * Disables a vertex attribute array + * + * Even if the attribute is not found in the current shader, + * it is removed from this state. + * + * @return false, if the name is not found, otherwise true + * + * @throws GLException if the program is not in use + * + * @see #glEnableVertexAttribArray + * @see #glDisableVertexAttribArray + * @see #glVertexAttribPointer + * @see #getVertexAttribPointer + * @see #glReleaseAllVertexAttributes + * @see #glResetAllVertexAttributes + * @see ShaderProgram#glReplaceShader + */ + public boolean glDisableVertexAttribArray(GL2ES2 gl, String name) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + enabledVertexAttribArraySet.remove(name); + int index = glGetAttribLocation(gl, name); + if(0>index) { + if(verbose) { + Throwable tX = new Throwable("Info: glDisableVertexAttribArray failed, no index for: "+name); + tX.printStackTrace(); + } + return false; + } + if(DEBUG) { + System.err.println("Info: glDisableVertexAttribArray: "+name); + } + gl.glDisableVertexAttribArray(index); + return true; + } + + /** + * Set the vertex attribute data. + * Enable the attribute, if it is not enabled yet. + * + * Even if the attribute is not found in the current shader, + * it is stored in this state. + * + * @param data the GLArrayData's name must match the attributes one, + * it's index will be set with the attribute's location, + * if found. + * + * @return false, if the name is not found, otherwise true + * + * @throws GLException if the program is not in use + * + * @see #glEnableVertexAttribArray + * @see #glDisableVertexAttribArray + * @see #glVertexAttribPointer + * @see #getVertexAttribPointer + * @see #glReleaseAllVertexAttributes + * @see #glResetAllVertexAttributes + * @see ShaderProgram#glReplaceShader + */ + public boolean glVertexAttribPointer(GL2ES2 gl, GLArrayData data) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + if(!enabledVertexAttribArraySet.contains(data.getName())) { + if(!glEnableVertexAttribArray(gl, data.getName())) { + if(verbose) { + Throwable tX = new Throwable("Info: glVertexAttribPointer: couldn't enable: "+data); + tX.printStackTrace(); + } + } + } + int index = getAttribLocation(data.getName()); + if(0>index) { + if(verbose) { + Throwable tX = new Throwable("Info: glVertexAttribPointer failed, no index for: "+data); + tX.printStackTrace(); + } + } + data.setLocation(index); + vertexAttribMap2Data.put(data.getName(), data); + if(0<=index) { + // only pass the data, if the attribute exists in the current shader + if(DEBUG) { + System.err.println("Info: glVertexAttribPointer: "+data); + } + gl.glVertexAttribPointer(data); + return true; + } + return false; + } + + /** + * Get the vertex attribute data, previously set. + * + * @return the GLArrayData object, null if not previously set. + * + * @see #glEnableVertexAttribArray + * @see #glDisableVertexAttribArray + * @see #glVertexAttribPointer + * @see #getVertexAttribPointer + * @see #glReleaseAllVertexAttributes + * @see #glResetAllVertexAttributes + * @see ShaderProgram#glReplaceShader + */ + public GLArrayData getVertexAttribPointer(String name) { + return (GLArrayData) vertexAttribMap2Data.get(name); + } + + /** + * Releases all mapped vertex attribute data, + * disables all enabled attributes and loses all indices + * + * @throws GLException is the program is not in use but the shaderProgram is set + * + * @see #glEnableVertexAttribArray + * @see #glDisableVertexAttribArray + * @see #glVertexAttribPointer + * @see #getVertexAttribPointer + * @see #glReleaseAllVertexAttributes + * @see #glResetAllVertexAttributes + * @see #glResetAllVertexAttributes + * @see ShaderProgram#glReplaceShader + */ + public void glReleaseAllVertexAttributes(GL2ES2 gl) { + if(null!=shaderProgram) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + for(Iterator iter = vertexAttribMap2Data.keySet().iterator(); iter.hasNext(); ) { + if(!glDisableVertexAttribArray(gl, (String) iter.next())) { + throw new GLException("Internal Error: mapped vertex attribute couldn't be disabled"); + } + } + for(Iterator iter = enabledVertexAttribArraySet.iterator(); iter.hasNext(); ) { + if(!glDisableVertexAttribArray(gl, (String) iter.next())) { + throw new GLException("Internal Error: prev enabled vertex attribute couldn't be disabled"); + } + } + } + vertexAttribMap2Data.clear(); + enabledVertexAttribArraySet.clear(); + attribMap2Idx.clear(); + } + + /** + * Disables all vertex attribute arrays. + * + * Their enabled stated will be removed from this state only + * if 'removeFromState' is true. + * + * This method purpose is more for debugging. + * + * @throws GLException is the program is not in use but the shaderProgram is set + * + * @see #glEnableVertexAttribArray + * @see #glDisableVertexAttribArray + * @see #glVertexAttribPointer + * @see #getVertexAttribPointer + * @see #glReleaseAllVertexAttributes + * @see #glResetAllVertexAttributes + * @see #glResetAllVertexAttributes + * @see ShaderProgram#glReplaceShader + */ + public void glDisableAllVertexAttributeArrays(GL2ES2 gl, boolean removeFromState) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + + for(Iterator iter = enabledVertexAttribArraySet.iterator(); iter.hasNext(); ) { + String name = (String) iter.next(); + if(removeFromState) { + enabledVertexAttribArraySet.remove(name); + } + int index = glGetAttribLocation(gl, name); + if(0<=index) { + gl.glDisableVertexAttribArray(index); + } + } + } + + /** + * Reset all previously enabled mapped vertex attribute data, + * incl enabling them + * + * @throws GLException is the program is not in use + * + * @see #glEnableVertexAttribArray + * @see #glDisableVertexAttribArray + * @see #glVertexAttribPointer + * @see #getVertexAttribPointer + * @see #glReleaseAllVertexAttributes + * @see #glResetAllVertexAttributes + * @see ShaderProgram#glReplaceShader + */ + public void glResetAllVertexAttributes(GL2ES2 gl) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + attribMap2Idx.clear(); + + /** + * + for(Iterator iter = enabledVertexAttribArraySet.iterator(); iter.hasNext(); ) { + glEnableVertexAttribArray(gl, (String) iter.next()); + } + for(Iterator iter = vertexAttribMap2Data.values().iterator(); iter.hasNext(); ) { + GLArrayData data = (GLArrayData) iter.next(); + + ... + } */ + + for(Iterator iter = enabledVertexAttribArraySet.iterator(); iter.hasNext(); ) { + // get new location .. + String name = (String) iter.next(); + int loc = glGetAttribLocation(gl, name); + + // get & update data .. + GLArrayData data = getVertexAttribPointer(name); + data.setLocation(loc); + vertexAttribMap2Data.put(name, data); + + if(0>loc) { + // not used in shader + continue; + } + + // enable attrib, VBO and pass location/data + gl.glEnableVertexAttribArray(loc); + + if( data.isVBO() ) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, data.getVBOName()); + } + + gl.glVertexAttribPointer(data); + } + } + + // + // Shader Uniform handling + // + + /** + * Gets the index of a shader uniform. + * This must be done when the program is in use ! + * + * @return -1 if there is no such attribute available, + * otherwise >= 0 + + * @throws GLException is the program is not linked + * + * @see #glGetUniformLocation + * @see javax.media.opengl.GL2ES2#glGetUniformLocation + * @see #getUniformLocation + * @see ShaderProgram#glReplaceShader + */ + protected int glGetUniformLocation(GL2ES2 gl, String name) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + int index = getUniformLocation(name); + if(0>index) { + index = gl.glGetUniformLocation(shaderProgram.program(), name); + if(0<=index) { + Integer idx = new Integer(index); + uniformMap2Idx.put(name, idx); + } else if(verbose) { + Throwable tX = new Throwable("Info: glUniform failed, no location for: "+name+", index: "+index); + tX.printStackTrace(); + } + } + return index; + } + + protected int getUniformLocation(String name) { + Integer idx = (Integer) uniformMap2Idx.get(name); + return (null!=idx)?idx.intValue():-1; + } + + /** + * Set the uniform data. + * + * Even if the uniform is not found in the current shader, + * it is stored in this state. + * + * @param data the GLUniforms's name must match the uniform one, + * it's index will be set with the uniforms's location, + * if found. + * + * + * @return false, if the name is not found, otherwise true + * + * @throws GLException if the program is not in use + * + * @see #glGetUniformLocation + * @see javax.media.opengl.GL2ES2#glGetUniformLocation + * @see #getUniformLocation + * @see ShaderProgram#glReplaceShader + */ + public boolean glUniform(GL2ES2 gl, GLUniformData data) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + int location = glGetUniformLocation(gl, data.getName()); + data.setLocation(location); + uniformMap2Data.put(data.getName(), data); + if(0<=location) { + // only pass the data, if the uniform exists in the current shader + if(DEBUG) { + System.err.println("Info: glUniform: "+data); + } + gl.glUniform(data); + } + return true; + } + + /** + * Get the uniform data, previously set. + * + * @return the GLUniformData object, null if not previously set. + */ + public GLUniformData getUniform(String name) { + return (GLUniformData) uniformMap2Data.get(name); + } + + /** + * Releases all mapped uniform data + * and loses all indices + * + * @throws GLException is the program is not in use + */ + public void glReleaseAllUniforms(GL2ES2 gl) { + uniformMap2Data.clear(); + uniformMap2Idx.clear(); + } + + /** + * Reset all previously mapped uniform data + * + * @throws GLException is the program is not in use + */ + public void glResetAllUniforms(GL2ES2 gl) { + if(!shaderProgram.inUse()) throw new GLException("Program is not in use"); + uniformMap2Idx.clear(); + for(Iterator iter = uniformMap2Data.values().iterator(); iter.hasNext(); ) { + glUniform(gl, (GLUniformData) iter.next()); + } + } + + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append("ShaderState["); + buf.append(shaderProgram.toString()); + buf.append(",EnabledStates: ["); + for(Iterator iter = enabledVertexAttribArraySet.iterator(); iter.hasNext(); ) { + buf.append("\n "); + buf.append((String)iter.next()); + } + buf.append("], ["); + for(Iterator iter = vertexAttribMap2Data.values().iterator(); iter.hasNext(); ) { + GLArrayData data = (GLArrayData) iter.next(); + if(data.getLocation()>=0) { + buf.append("\n "); + buf.append(data); + } + } + buf.append("], ["); + for(Iterator iter=uniformMap2Data.values().iterator(); iter.hasNext(); ) { + GLUniformData data = (GLUniformData) iter.next(); + if(data.getLocation()>=0) { + buf.append("\n "); + buf.append(data); + } + } + buf.append("]"); + return buf.toString(); + } + + protected boolean verbose = false; + protected ShaderProgram shaderProgram=null; + protected HashMap attribMap2Idx = new HashMap(); + protected HashSet enabledVertexAttribArraySet = new HashSet(); + protected HashMap vertexAttribMap2Data = new HashMap(); + protected HashMap uniformMap2Idx = new HashMap(); + protected HashMap uniformMap2Data = new HashMap(); + +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java new file mode 100644 index 000000000..c7e845953 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java @@ -0,0 +1,476 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.opengl.util.glsl; + +import java.io.PrintStream; +import java.nio.*; +import java.util.*; + +import javax.media.opengl.*; + +public class ShaderUtil { + static abstract class Impl { + public abstract String getShaderInfoLog(GL gl, int shaderObj); + public abstract String getProgramInfoLog(GL gl, int programObj); + public abstract boolean isShaderStatusValid(GL gl, int shaderObj, int name); + public abstract boolean isShaderStatusValid(GL gl, int shaderObj, int name, PrintStream verboseOut); + public abstract boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name); + public abstract boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name, PrintStream verboseOut); + public abstract boolean isProgramStatusValid(GL gl, int programObj, int name); + public abstract boolean isProgramValid(GL gl, int programObj); + public abstract boolean isProgramValid(GL gl, int programObj, PrintStream verboseOut); + public abstract void createShader(GL gl, int type, IntBuffer shaders); + public abstract Set getShaderBinaryFormats(GL gl); + public abstract boolean isShaderCompilerAvailable(GL gl); + public abstract void shaderSource(GL gl, int shader, java.lang.String[] source); + public abstract void shaderSource(GL gl, IntBuffer shaders, java.lang.String[][] sources); + public abstract void shaderBinary(GL gl, IntBuffer shaders, int binFormat, java.nio.Buffer bin); + public abstract void compileShader(GL gl, IntBuffer shaders); + public abstract void attachShader(GL gl, int program, IntBuffer shaders); + public abstract void detachShader(GL gl, int program, IntBuffer shaders); + public abstract void deleteShader(GL gl, IntBuffer shaders); + + public abstract boolean createAndLoadShader(GL gl, IntBuffer shader, int shaderType, + int binFormat, java.nio.Buffer bin, + PrintStream verboseOut); + + public abstract boolean createAndCompileShader(GL gl, IntBuffer shader, int shaderType, + java.lang.String[][] sources, + PrintStream verboseOut); + } + + static class GL2ES2Impl extends Impl { + public String getShaderInfoLog(GL _gl, int shaderObj) { + GL2ES2 gl = _gl.getGL2ES2(); + int[] infoLogLength=new int[1]; + gl.glGetShaderiv(shaderObj, gl.GL_INFO_LOG_LENGTH, infoLogLength, 0); + + if(infoLogLength[0]==0) { + return "(no info log)"; + } + int[] charsWritten=new int[1]; + byte[] infoLogBytes = new byte[infoLogLength[0]]; + gl.glGetShaderInfoLog(shaderObj, infoLogLength[0], charsWritten, 0, infoLogBytes, 0); + + return new String(infoLogBytes, 0, charsWritten[0]); + } + + public String getProgramInfoLog(GL _gl, int programObj) { + GL2ES2 gl = _gl.getGL2ES2(); + int[] infoLogLength=new int[1]; + gl.glGetProgramiv(programObj, gl.GL_INFO_LOG_LENGTH, infoLogLength, 0); + + if(infoLogLength[0]==0) { + return "(no info log)"; + } + int[] charsWritten=new int[1]; + byte[] infoLogBytes = new byte[infoLogLength[0]]; + gl.glGetProgramInfoLog(programObj, infoLogLength[0], charsWritten, 0, infoLogBytes, 0); + + return new String(infoLogBytes, 0, charsWritten[0]); + } + + public boolean isShaderStatusValid(GL _gl, int shaderObj, int name) { + return isShaderStatusValid(_gl, shaderObj, name, null); + } + + public boolean isShaderStatusValid(GL _gl, int shaderObj, int name, PrintStream verboseOut) { + GL2ES2 gl = _gl.getGL2ES2(); + int[] ires = new int[1]; + gl.glGetShaderiv(shaderObj, name, ires, 0); + + boolean res = ires[0]==1; + if(!res && null!=verboseOut) { + verboseOut.println("Shader status invalid: "+ getShaderInfoLog(gl, shaderObj)); + } + return res; + } + + public boolean isShaderStatusValid(GL _gl, IntBuffer shaders, int name) { + return isShaderStatusValid(_gl, shaders, name, null); + } + + public boolean isShaderStatusValid(GL _gl, IntBuffer shaders, int name, PrintStream verboseOut) { + boolean res = true; + for (int i = shaders.position(); i < shaders.limit(); i++) { + res = isShaderStatusValid(_gl, shaders.get(i), name, verboseOut) && res; + } + return res; + } + + public boolean isProgramStatusValid(GL _gl, int programObj, int name) { + GL2ES2 gl = _gl.getGL2ES2(); + int[] ires = new int[1]; + gl.glGetProgramiv(programObj, name, ires, 0); + + return ires[0]==1; + } + + public boolean isProgramValid(GL _gl, int programObj) { + return isProgramValid(_gl, programObj, null); + } + + public boolean isProgramValid(GL _gl, int programObj, PrintStream verboseOut) { + GL2ES2 gl = _gl.getGL2ES2(); + int[] ires = new int[1]; + if(!gl.glIsProgram(programObj)) { + if(null!=verboseOut) { + verboseOut.println("Program name invalid: "+programObj); + } + return false; + } + if(!isProgramStatusValid(gl, programObj, gl.GL_LINK_STATUS)) { + if(null!=verboseOut) { + verboseOut.println("Program link failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj)); + } + return false; + } + if ( !gl.isGLES2() || isShaderCompilerAvailable(gl) ) { + // failed on APX2500 (ES2.0, no compiler) for valid programs + gl.glValidateProgram(programObj); + if(!isProgramStatusValid(gl, programObj, gl.GL_VALIDATE_STATUS)) { + if(null!=verboseOut) { + verboseOut.println("Program validation failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj)); + } + return false; + } + } + return true; + } + + public void createShader(GL _gl, int type, IntBuffer shaders) { + GL2ES2 gl = _gl.getGL2ES2(); + for (int i = shaders.position(); i < shaders.limit(); i++) { + shaders.put(i, gl.glCreateShader(type)); + } + } + + private Boolean shaderCompilerAvailable = null; + private Set shaderBinaryFormats = null; + + public Set getShaderBinaryFormats(GL _gl) { + GL2ES2 gl = _gl.getGL2ES2(); + if(null==shaderBinaryFormats) { + if(gl.getContext()!=GLContext.getCurrent()) { + return new HashSet(0); // bail out + } + + int[] param = new int[1]; + shaderBinaryFormats = new HashSet(); + + if (gl.isGLES2()) { + gl.glGetIntegerv(GL2ES2.GL_NUM_SHADER_BINARY_FORMATS, param, 0); + int numFormats = param[0]; + if(numFormats>0) { + int[] formats = new int[numFormats]; + gl.glGetIntegerv(GL2ES2.GL_SHADER_BINARY_FORMATS, formats, 0); + for(int i=0; i<numFormats; i++) { + shaderBinaryFormats.add(new Integer(formats[i])); + } + } + } + } + return shaderBinaryFormats; + } + + + public boolean isShaderCompilerAvailable(GL _gl) { + GL2ES2 gl = _gl.getGL2ES2(); + if(null==shaderCompilerAvailable) { + if(gl.getContext()!=GLContext.getCurrent()) { + return false; // bail out + } + Set bfs = getShaderBinaryFormats(gl); + if(gl.isGLES2()) { + byte[] param = new byte[1]; + gl.glGetBooleanv(GL2ES2.GL_SHADER_COMPILER, param, 0); + boolean v = param[0]!=(byte)0x00; + if(!v && bfs.size()==0) { + // no supported binary formats, hence a compiler must be available! + v = true; + } + shaderCompilerAvailable = new Boolean(v); + } else if( gl.isGL2ES2() ) { + shaderCompilerAvailable = new Boolean(true); + } else { + throw new GLException("Invalid OpenGL profile"); + } + } + return shaderCompilerAvailable.booleanValue(); + } + + public void shaderSource(GL _gl, int shader, java.lang.String[] source) + { + GL2ES2 gl = _gl.getGL2ES2(); + if(!isShaderCompilerAvailable(_gl)) { + throw new GLException("No compiler is available"); + } + + int count = (null!=source)?source.length:0; + if(count==0) { + throw new GLException("No sources specified"); + } + + int[] lengths = new int[count]; + for(int i=0; i<count; i++) { + lengths[i] = source[i].length(); + } + gl.glShaderSource(shader, count, source, lengths, 0); + } + + public void shaderSource(GL _gl, IntBuffer shaders, java.lang.String[][] sources) + { + int sourceNum = (null!=sources)?sources.length:0; + int shaderNum = (null!=shaders)?shaders.remaining():0; + if(shaderNum<=0 || sourceNum<=0 || shaderNum!=sourceNum) { + throw new GLException("Invalid number of shaders and/or sources: shaders="+ + shaderNum+", sources="+sourceNum); + } + for(int i=0; i<sourceNum; i++) { + shaderSource(_gl, shaders.get(shaders.position() + i), sources[i]); + } + } + + public void shaderBinary(GL _gl, IntBuffer shaders, int binFormat, java.nio.Buffer bin) + { + GL2ES2 gl = _gl.getGL2ES2(); + if(getShaderBinaryFormats(gl).size()<=0) { + throw new GLException("No binary formats are supported"); + } + + int shaderNum = shaders.remaining(); + if(shaderNum<=0) { + throw new GLException("No shaders specified"); + } + if(null==bin) { + throw new GLException("Null shader binary"); + } + int binLength = bin.remaining(); + if(0>=binLength) { + throw new GLException("Empty shader binary (remaining == 0)"); + } + gl.glShaderBinary(shaderNum, shaders, binFormat, bin, binLength); + } + + public void compileShader(GL _gl, IntBuffer shaders) + { + GL2ES2 gl = _gl.getGL2ES2(); + for (int i = shaders.position(); i < shaders.limit(); i++) { + gl.glCompileShader(shaders.get(i)); + } + } + + public void attachShader(GL _gl, int program, IntBuffer shaders) + { + GL2ES2 gl = _gl.getGL2ES2(); + for (int i = shaders.position(); i < shaders.limit(); i++) { + gl.glAttachShader(program, shaders.get(i)); + } + } + + public void detachShader(GL _gl, int program, IntBuffer shaders) + { + GL2ES2 gl = _gl.getGL2ES2(); + for (int i = shaders.position(); i < shaders.limit(); i++) { + gl.glDetachShader(program, shaders.get(i)); + } + } + + public void deleteShader(GL _gl, IntBuffer shaders) + { + GL2ES2 gl = _gl.getGL2ES2(); + for (int i = shaders.position(); i < shaders.limit(); i++) { + gl.glDeleteShader(shaders.get(i)); + + } + } + + public boolean createAndLoadShader(GL _gl, IntBuffer shader, int shaderType, + int binFormat, java.nio.Buffer bin, + PrintStream verboseOut) + { + GL2ES2 gl = _gl.getGL2ES2(); + int err = gl.glGetError(); // flush previous errors .. + if(err!=GL.GL_NO_ERROR && null!=verboseOut) { + verboseOut.println("createAndLoadShader: Pre GL Error: 0x"+Integer.toHexString(err)); + } + + createShader(gl, shaderType, shader); + err = gl.glGetError(); + if(err!=GL.GL_NO_ERROR) { + throw new GLException("createAndLoadShader: CreateShader failed, GL Error: 0x"+Integer.toHexString(err)); + } + + + shaderBinary(gl, shader, binFormat, bin); + + err = gl.glGetError(); + if(err!=GL.GL_NO_ERROR && null!=verboseOut) { + verboseOut.println("createAndLoadShader: ShaderBinary failed, GL Error: 0x"+Integer.toHexString(err)); + } + return err == GL.GL_NO_ERROR; + } + + public boolean createAndCompileShader(GL _gl, IntBuffer shader, int shaderType, + java.lang.String[][] sources, + PrintStream verboseOut) + { + GL2ES2 gl = _gl.getGL2ES2(); + int err = gl.glGetError(); // flush previous errors .. + if(err!=GL.GL_NO_ERROR && null!=verboseOut) { + verboseOut.println("createAndCompileShader: Pre GL Error: 0x"+Integer.toHexString(err)); + } + + createShader(gl, shaderType, shader); + err = gl.glGetError(); + if(err!=GL.GL_NO_ERROR) { + throw new GLException("createAndCompileShader: CreateShader failed, GL Error: 0x"+Integer.toHexString(err)); + } + + shaderSource(gl, shader, sources); + err = gl.glGetError(); + if(err!=GL.GL_NO_ERROR) { + throw new GLException("createAndCompileShader: ShaderSource failed, GL Error: 0x"+Integer.toHexString(err)); + } + + compileShader(gl, shader); + err = gl.glGetError(); + if(err!=GL.GL_NO_ERROR && null!=verboseOut) { + verboseOut.println("createAndCompileShader: CompileShader failed, GL Error: 0x"+Integer.toHexString(err)); + } + + return isShaderStatusValid(gl, shader, gl.GL_COMPILE_STATUS, verboseOut) && err == GL.GL_NO_ERROR; + } + + } + + public static String getShaderInfoLog(GL gl, int shaderObj) { + return getImpl(gl).getShaderInfoLog(gl, shaderObj); + } + + public static String getProgramInfoLog(GL gl, int programObj) { + return getImpl(gl).getProgramInfoLog(gl, programObj); + } + + public static boolean isShaderStatusValid(GL gl, int shaderObj, int name) { + return getImpl(gl).isShaderStatusValid(gl, shaderObj, name); + } + + public static boolean isShaderStatusValid(GL gl, int shaderObj, int name, PrintStream verboseOut) { + return getImpl(gl).isShaderStatusValid(gl, shaderObj, name, verboseOut); + } + + public static boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name) { + return getImpl(gl).isShaderStatusValid(gl, shaders, name); + } + + public static boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name, PrintStream verboseOut) { + return getImpl(gl).isShaderStatusValid(gl, shaders, name, verboseOut); + } + + public static boolean isProgramStatusValid(GL gl, int programObj, int name) { + return getImpl(gl).isProgramStatusValid(gl, programObj, name); + } + + public static boolean isProgramValid(GL gl, int programObj) { + return getImpl(gl).isProgramValid(gl, programObj); + } + + public static boolean isProgramValid(GL gl, int programObj, PrintStream verboseOut) { + return getImpl(gl).isProgramValid(gl, programObj, verboseOut); + } + + public static void createShader(GL gl, int type, IntBuffer shaders) { + getImpl(gl).createShader(gl, type, shaders); + } + + public static Set getShaderBinaryFormats(GL gl) { + return getImpl(gl).getShaderBinaryFormats(gl); + } + + public static boolean isShaderCompilerAvailable(GL gl) { + return getImpl(gl).isShaderCompilerAvailable(gl); + } + + public static void shaderSource(GL gl, int shader, java.lang.String[] source) { + getImpl(gl).shaderSource(gl, shader, source); + } + + public static void shaderSource(GL gl, IntBuffer shaders, java.lang.String[][] sources) { + getImpl(gl).shaderSource(gl, shaders, sources); + } + + public static void shaderBinary(GL gl, IntBuffer shaders, int binFormat, java.nio.Buffer bin) { + getImpl(gl).shaderBinary(gl, shaders, binFormat, bin); + } + + public static void compileShader(GL gl, IntBuffer shaders) { + getImpl(gl).compileShader(gl, shaders); + } + + public static void attachShader(GL gl, int program, IntBuffer shaders) { + getImpl(gl).attachShader(gl, program, shaders); + } + + public static void detachShader(GL gl, int program, IntBuffer shaders) { + getImpl(gl).detachShader(gl, program, shaders); + } + + public static void deleteShader(GL gl, IntBuffer shaders) { + getImpl(gl).deleteShader(gl, shaders); + } + + public static boolean createAndLoadShader(GL gl, IntBuffer shader, int shaderType, + int binFormat, java.nio.Buffer bin, + PrintStream verboseOut) { + return getImpl(gl).createAndLoadShader(gl, shader, shaderType, binFormat, bin, verboseOut); + } + + public static boolean createAndCompileShader(GL gl, IntBuffer shader, int shaderType, + java.lang.String[][] sources, + PrintStream verboseOut) { + return getImpl(gl).createAndCompileShader(gl, shader, shaderType, sources, verboseOut); + } + + private static Impl getImpl(GL _gl) { + GL2ES2 gl = _gl.getGL2ES2(); + GLContext context = gl.getContext(); + Impl impl = (Impl) context.getAttachedObject(ShaderUtil.class.getName()); + if (impl == null) { + impl = new GL2ES2Impl(); + context.putAttachedObject(ShaderUtil.class.getName(), impl); + } + return impl; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java new file mode 100644 index 000000000..9d7eecb60 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java @@ -0,0 +1,90 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package com.jogamp.opengl.util.glsl.fixedfunc; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; + +import jogamp.opengl.util.glsl.fixedfunc.*; + +/** + * Tool to pipeline GL2ES2 into a fixed function emulation implementing GL2ES1. + */ +public class FixedFuncUtil { + /** + * @return If gl is a GL2ES1 and force is false, return the type cast object, + * otherwise create a fixed function emulation pipeline with the GL2ES2 impl. + * @throws GLException if the GL object is neither GL2ES1 nor GL2ES2 + */ + public static final GL2ES1 getFixedFuncImpl(GL gl, boolean force) { + if(!force && gl.isGL2ES1()) { + return gl.getGL2ES1(); + } else if(gl.isGL2ES2()) { + GL2ES2 es2 = gl.getGL2ES2(); + FixedFuncHook hook = new FixedFuncHook(es2); + FixedFuncImpl impl = new FixedFuncImpl(es2, hook); + gl.getContext().setGL(impl); + return impl; + } + throw new GLException("GL Object is neither GL2ES1 nor GL2ES2: "+gl.getContext()); + } + + /** + * @return If gl is a GL2ES1, return the type cast object, + * otherwise create a fixed function emulation pipeline with the GL2ES2 impl. + * @throws GLException if the GL object is neither GL2ES1 nor GL2ES2 + */ + public static final GL2ES1 getFixedFuncImpl(GL gl) { + return getFixedFuncImpl(gl, false); + } + + /** + * Mapping fixed function (client) array indices to + * GLSL array attribute names. + * + * Useful for uniq mapping of canonical array index names as listed. + * + * @see #mgl_Vertex + * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_VERTEX_ARRAY + * @see #mgl_Normal + * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_NORMAL_ARRAY + * @see #mgl_Color + * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_COLOR_ARRAY + * @see #mgl_MultiTexCoord + * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_TEXTURE_COORD_ARRAY + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glEnableClientState + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glVertexPointer + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glColorPointer + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glNormalPointer + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glTexCoordPointer + */ + public static String getPredefinedArrayIndexName(int glArrayIndex) { + return FixedFuncPipeline.getPredefinedArrayIndexName(glArrayIndex); + } + + /** + * String name for + * @see javax.media.opengl.GL2#GL_VERTEX_ARRAY + */ + public static final String mgl_Vertex = FixedFuncPipeline.mgl_Vertex; + + /** + * String name for + * @see javax.media.opengl.GL2#GL_NORMAL_ARRAY + */ + public static final String mgl_Normal = FixedFuncPipeline.mgl_Normal; + + /** + * String name for + * @see javax.media.opengl.GL2#GL_COLOR_ARRAY + */ + public static final String mgl_Color = FixedFuncPipeline.mgl_Color; + + /** + * String name for + * @see javax.media.opengl.GL2#GL_TEXTURE_COORD_ARRAY + */ + public static final String mgl_MultiTexCoord = FixedFuncPipeline.mgl_MultiTexCoord; +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java new file mode 100644 index 000000000..a0eed50ea --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java @@ -0,0 +1,185 @@ +package com.jogamp.opengl.util.glsl.sdk; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.glsl.*; + +import java.io.*; +import java.net.*; + +/** + * Precompiles a shader into a vendor binary format. Input is the + * resource name of the shader, such as + * "com/jogamp/opengl/impl/glsl/fixed/shader/a.fp". + * Output is "com/jogamp/opengl/impl/glsl/fixed/shader/bin/nvidia/a.bfp". + * + * All path and suffixes are determined by the ShaderCode class, + * which ensures runtime compatibility. + * + * @see com.jogamp.opengl.util.glsl.ShaderCode + */ + +public abstract class CompileShader { + + public abstract int getBinaryFormat(); + + public abstract File getSDKCompilerDir(); + + public abstract String getVertexShaderCompiler(); + + public abstract String getFragmentShaderCompiler(); + + public void processOneShader(String resourceName) + throws IOException, UnsupportedEncodingException, InterruptedException + { + int type = -1; + String outName=null; + int suffixLen = -1; + if(resourceName.endsWith(ShaderCode.getFileSuffix(false, GL2ES2.GL_FRAGMENT_SHADER))) { + suffixLen = 2; + type = GL2ES2.GL_FRAGMENT_SHADER; + } else if(resourceName.endsWith(".frag")) { + suffixLen = 4; + type = GL2ES2.GL_FRAGMENT_SHADER; + } else if(resourceName.endsWith(ShaderCode.getFileSuffix(false, GL2ES2.GL_VERTEX_SHADER))) { + suffixLen = 2; + type = GL2ES2.GL_VERTEX_SHADER; + } else if(resourceName.endsWith(".vert")) { + suffixLen = 4; + type = GL2ES2.GL_VERTEX_SHADER; + } + String justName = basename(resourceName); + outName = justName.substring(0, justName.length() - suffixLen) + + ShaderCode.getFileSuffix(true, type); + URL resourceURL = Locator.getResource(null, resourceName); + String dirName = dirname(resourceURL.getPath()); + + outName = dirName + File.separator + "bin" + File.separator + + ShaderCode.getBinarySubPath(getBinaryFormat()) + File.separator + + outName; + processOneShader(resourceName, outName, type); + } + + public void processOneShader(String resourceName, String outName, int type) + throws IOException, UnsupportedEncodingException, InterruptedException + { + URL resourceURL = Locator.getResource(null, resourceName); + String dirName = dirname(resourceURL.getPath()); + + String shader = ShaderCode.readShaderSource(null, resourceName); + if(null==shader) { + System.err.println("Can't find shader source " + resourceName + " - ignored"); + return; + } + System.err.println("Preprocessing: "+ resourceName+", in dir: "+dirName); + String justName = basename(resourceName); + String processor; + switch (type) { + case GL2ES2.GL_VERTEX_SHADER: + processor = getVertexShaderCompiler(); + break; + case GL2ES2.GL_FRAGMENT_SHADER: + processor = getFragmentShaderCompiler(); + break; + default: + throw new GLException("Unknown shader type: "+type); + } + File outputFile = new File(outName); + + // Write shader to a file in java.io.tmpdir + File tmpDir = new File(dirName+File.separator+"tmp"); + tmpDir.mkdirs(); + File tmpFile = new File(tmpDir, justName); + Writer writer = new BufferedWriter(new FileWriter(tmpFile)); + writer.write(shader, 0, shader.length()); + writer.flush(); + writer.close(); + System.err.println("Preprocessed: "+ tmpFile.getAbsolutePath()); + + File processorDir = getSDKCompilerDir(); + + System.err.println("SDK: "+ processorDir.getAbsolutePath() + ", compiler: "+processor); + + System.err.println("Output: "+ outputFile.getAbsolutePath()); + + // Run the tool + Process process = Runtime.getRuntime().exec(new String[] { + processorDir.getAbsolutePath() + File.separator + processor, + tmpFile.getAbsolutePath(), + outputFile.getAbsolutePath() + }); // , null, processorDir); + new StreamMonitor(process.getInputStream()); + new StreamMonitor(process.getErrorStream()); + process.waitFor(); + // Delete the temporary file + // tmpFile.delete(); + } + + protected static String basename(String path) { + int lastSlash = path.lastIndexOf("/"); + if (lastSlash < 0) { + lastSlash = path.lastIndexOf("\\"); + } + String basename; + if (lastSlash < 0) { + basename = path; + } else { + basename = path.substring(lastSlash + 1); + } + return basename; + } + + protected static String dirname(String path) { + int lastSlash = path.lastIndexOf("/"); + if (lastSlash < 0) { + lastSlash = path.lastIndexOf("\\"); + } + String dirname; + if (lastSlash < 0) { + dirname = new String(); + } else { + dirname = path.substring(0, lastSlash + 1); + } + return dirname; + } + + public void run(String[] args) { + try { + for (int i = 0; i < args.length; i++) { + processOneShader(args[i]); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static class StreamMonitor implements Runnable { + private InputStream istream; + public StreamMonitor(InputStream stream) { + istream = stream; + new Thread(this, "Output Reader Thread").start(); + } + + public void run() + { + byte[] buffer = new byte[4096]; + try { + int numRead = 0; + do { + numRead = istream.read(buffer); + if (numRead > 0) { + System.out.write(buffer, 0, numRead); + System.out.flush(); + } + } while (numRead >= 0); + } + catch (IOException e) { + try { + istream.close(); + } catch (IOException e2) { + } + // Should allow clean exit when process shuts down + } + } + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShaderNVidia.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShaderNVidia.java new file mode 100644 index 000000000..8eb9ef579 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShaderNVidia.java @@ -0,0 +1,53 @@ +package com.jogamp.opengl.util.glsl.sdk; + +import javax.media.opengl.*; + +import java.io.*; + +/** Precompiles a shader into NVidia binary format. Input is the + resource name of the shader, such as + "com/jogamp/opengl/impl/glsl/fixed/shader/a.fp". + Output is "com/jogamp/opengl/impl/glsl/fixed/shader/bin/nvidia/a.bfp". */ + +public class CompileShaderNVidia extends CompileShader { + private static final String NVAPSDK; + + static { + String nvapSDKProp = System.getProperty("NVAPSDK"); + if (nvapSDKProp != null) { + NVAPSDK = nvapSDKProp; + } else { + NVAPSDK = "C:\\nvap_sdk_0_3_x"; + } + } + + public int getBinaryFormat() { + return GLES2.GL_NVIDIA_PLATFORM_BINARY_NV; + } + + public File getSDKCompilerDir() { + File compilerDir = new File( NVAPSDK + File.separator + "tools" + File.separator ); + File compilerFile = new File( compilerDir, getVertexShaderCompiler()); + if(!compilerFile.exists()) { + compilerDir = new File( NVAPSDK ); + compilerFile = new File( compilerDir, getVertexShaderCompiler()); + } + if(!compilerFile.exists()) { + throw new GLException("Can't find compiler: "+getVertexShaderCompiler() + " in : " + + NVAPSDK+", "+NVAPSDK + File.separator + "tools"); + } + return compilerDir; + } + + public String getVertexShaderCompiler() { + return "glslv.bat"; + } + + public String getFragmentShaderCompiler() { + return "glslf.bat"; + } + + public static void main(String[] args) { + new CompileShaderNVidia().run(args); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/BackingStoreManager.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/BackingStoreManager.java new file mode 100644 index 000000000..7b6a1b479 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/BackingStoreManager.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.packrect; + +/** This interface must be implemented by the end user and is called + in response to events like addition of rectangles into the + RectanglePacker. It is used both when a full re-layout must be + done as well as when the data in the backing store must be copied + to a new one. */ + +public interface BackingStoreManager { + public Object allocateBackingStore(int w, int h); + public void deleteBackingStore(Object backingStore); + + /** Indication whether this BackingStoreManager supports compaction; + in other words, the allocation of a new backing store and + movement of the contents of the backing store from the old to + the new one. If it does not, then RectanglePacker.add() may + throw an exception if additionFailed() can not make enough room + available. If an implementation returns false, this also implies + that the backing store can not grow, so that preExpand() will + never be called. */ + public boolean canCompact(); + + /** Notification that expansion of the backing store is about to be + done due to addition of the given rectangle. Gives the manager a + chance to do some compaction and potentially remove old entries + from the backing store, if it acts like a least-recently-used + cache. This method receives as argument the number of attempts + so far to add the given rectangle. Manager should return true if + the RectanglePacker should retry the addition (which may result + in this method being called again, with an increased attempt + number) or false if the RectanglePacker should just expand the + backing store. The caller should not call RectanglePacker.add() + in its preExpand() method. */ + public boolean preExpand(Rect cause, int attemptNumber); + + /** Notification that addition of the given Rect failed because a + maximum size was set in the RectanglePacker and the backing + store could not be expanded, or because compaction (and, + therefore, implicitly expansion) was not supported. Should + return false if the manager can do nothing more to handle the + failed addition, which will cause a RuntimeException to be + thrown from the RectanglePacker. */ + public boolean additionFailed(Rect cause, int attemptNumber); + + /** Notification that movement is starting. */ + public void beginMovement(Object oldBackingStore, Object newBackingStore); + + /** Tells the manager to move the contents of the given rect from + the old location on the old backing store to the new location on + the new backing store. The backing stores can be identical in + the case of compacting the existing backing store instead of + reallocating it. */ + public void move(Object oldBackingStore, + Rect oldLocation, + Object newBackingStore, + Rect newLocation); + + /** Notification that movement is ending. */ + public void endMovement(Object oldBackingStore, Object newBackingStore); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java new file mode 100644 index 000000000..5ba3f7330 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.packrect; + +import java.util.*; + +public class Level { + private int width; + private int height; + private int yPos; + private LevelSet holder; + + private List/*<Rect>*/ rects = new ArrayList/*<Rect>*/(); + private List/*<Rect>*/ freeList; + private int nextAddX; + + static class RectXComparator implements Comparator { + public int compare(Object o1, Object o2) { + Rect r1 = (Rect) o1; + Rect r2 = (Rect) o2; + return r1.x() - r2.x(); + } + + public boolean equals(Object obj) { + return this == obj; + } + } + private static final Comparator rectXComparator = new RectXComparator(); + + public Level(int width, int height, int yPos, LevelSet holder) { + this.width = width; + this.height = height; + this.yPos = yPos; + this.holder = holder; + } + + public int w() { return width; } + public int h() { return height; } + public int yPos() { return yPos; } + + /** Tries to add the given rectangle to this level only allowing + non-disruptive changes like trivial expansion of the last level + in the RectanglePacker and allocation from the free list. More + disruptive changes like compaction of the level must be + requested explicitly. */ + public boolean add(Rect rect) { + if (rect.h() > height) { + // See whether it's worth trying to expand vertically + if (nextAddX + rect.w() > width) { + return false; + } + + // See whether we're the last level and can expand + if (!holder.canExpand(this, rect.h())) { + return false; + } + + // Trivially expand and try the allocation + holder.expand(this, height, rect.h()); + height = rect.h(); + } + + // See whether we can add at the end + if (nextAddX + rect.w() <= width) { + rect.setPosition(nextAddX, yPos); + rects.add(rect); + nextAddX += rect.w(); + return true; + } + + // See whether we can add from the free list + if (freeList != null) { + Rect candidate = null; + for (Iterator iter = freeList.iterator(); iter.hasNext(); ) { + Rect cur = (Rect) iter.next(); + if (cur.canContain(rect)) { + candidate = cur; + break; + } + } + + if (candidate != null) { + // Remove the candidate from the free list + freeList.remove(candidate); + // Set up and add the real rect + rect.setPosition(candidate.x(), candidate.y()); + rects.add(rect); + // Re-add any remaining free space + if (candidate.w() > rect.w()) { + candidate.setPosition(candidate.x() + rect.w(), candidate.y()); + candidate.setSize(candidate.w() - rect.w(), height); + freeList.add(candidate); + } + + coalesceFreeList(); + + return true; + } + } + + return false; + } + + /** Removes the given Rect from this Level. */ + public boolean remove(Rect rect) { + if (!rects.remove(rect)) + return false; + + // If this is the rightmost rectangle, instead of adding its space + // to the free list, we can just decrease the nextAddX + if (rect.maxX() + 1 == nextAddX) { + nextAddX -= rect.w(); + } else { + if (freeList == null) { + freeList = new ArrayList/*<Rect>*/(); + } + freeList.add(new Rect(rect.x(), rect.y(), rect.w(), height, null)); + coalesceFreeList(); + } + + return true; + } + + /** Indicates whether this Level contains no rectangles. */ + public boolean isEmpty() { + return rects.isEmpty(); + } + + /** Indicates whether this Level could satisfy an allocation request + if it were compacted. */ + public boolean couldAllocateIfCompacted(Rect rect) { + if (rect.h() > height) + return false; + if (freeList == null) + return false; + int freeListWidth = 0; + for (Iterator iter = freeList.iterator(); iter.hasNext(); ) { + Rect cur = (Rect) iter.next(); + freeListWidth += cur.w(); + } + // Add on the remaining space at the end + freeListWidth += (width - nextAddX); + return (freeListWidth >= rect.w()); + } + + public void compact(Object backingStore, BackingStoreManager manager) { + Collections.sort(rects, rectXComparator); + int nextCompactionDest = 0; + manager.beginMovement(backingStore, backingStore); + for (Iterator iter = rects.iterator(); iter.hasNext(); ) { + Rect cur = (Rect) iter.next(); + if (cur.x() != nextCompactionDest) { + manager.move(backingStore, cur, + backingStore, new Rect(nextCompactionDest, cur.y(), cur.w(), cur.h(), null)); + cur.setPosition(nextCompactionDest, cur.y()); + } + nextCompactionDest += cur.w(); + } + nextAddX = nextCompactionDest; + freeList.clear(); + manager.endMovement(backingStore, backingStore); + } + + public Iterator iterator() { + return rects.iterator(); + } + + /** Visits all Rects contained in this Level. */ + public void visit(RectVisitor visitor) { + for (Iterator iter = rects.iterator(); iter.hasNext(); ) { + Rect rect = (Rect) iter.next(); + visitor.visit(rect); + } + } + + /** Updates the references to the Rect objects in this Level with + the "next locations" of those Rects. This is actually used to + update the new Rects in a newly laid-out LevelSet with the + original Rects. */ + public void updateRectangleReferences() { + for (int i = 0; i < rects.size(); i++) { + Rect cur = (Rect) rects.get(i); + Rect next = cur.getNextLocation(); + next.setPosition(cur.x(), cur.y()); + if (cur.w() != next.w() || cur.h() != next.h()) + throw new RuntimeException("Unexpected disparity in rectangle sizes during updateRectangleReferences"); + rects.set(i, next); + } + } + + private void coalesceFreeList() { + if (freeList == null) + return; + if (freeList.isEmpty()) + return; + + // Try to coalesce adjacent free blocks in the free list + Collections.sort(freeList, rectXComparator); + int i = 0; + while (i < freeList.size() - 1) { + Rect r1 = (Rect) freeList.get(i); + Rect r2 = (Rect) freeList.get(i+1); + if (r1.maxX() + 1 == r2.x()) { + // Coalesce r1 and r2 into one block + freeList.remove(i+1); + r1.setSize(r1.w() + r2.w(), r1.h()); + } else { + ++i; + } + } + // See whether the last block bumps up against the addition point + Rect last = (Rect) freeList.get(freeList.size() - 1); + if (last.maxX() + 1 == nextAddX) { + nextAddX -= last.w(); + freeList.remove(freeList.size() - 1); + } + if (freeList.isEmpty()) { + freeList = null; + } + } + + //---------------------------------------------------------------------- + // Debugging functionality + // + + public void dumpFreeSpace() { + int freeListWidth = 0; + for (Iterator iter = freeList.iterator(); iter.hasNext(); ) { + Rect cur = (Rect) iter.next(); + System.err.println(" Free rectangle at " + cur); + freeListWidth += cur.w(); + } + // Add on the remaining space at the end + System.err.println(" Remaining free space " + (width - nextAddX)); + freeListWidth += (width - nextAddX); + System.err.println(" Total free space " + freeListWidth); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java new file mode 100644 index 000000000..6783aec3b --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.packrect; + +import java.util.*; + +/** Manages a list of Levels; this is the core data structure + contained within the RectanglePacker and encompasses the storage + algorithm for the contained Rects. */ + +public class LevelSet { + // Maintained in sorted order by increasing Y coordinate + private List/*<Level>*/ levels = new ArrayList/*<Level>*/(); + private int nextAddY; + private int w; + private int h; + + /** A LevelSet manages all of the backing store for a region of a + specified width and height. */ + public LevelSet(int w, int h) { + this.w = w; + this.h = h; + } + + public int w() { return w; } + public int h() { return h; } + + /** Returns true if the given rectangle was successfully added to + the LevelSet given its current dimensions, false if not. Caller + is responsible for performing compaction, expansion, etc. as a + consequence. */ + public boolean add(Rect rect) { + if (rect.w() > w) + return false; + + // Go in reverse order through the levels seeing whether we can + // trivially satisfy the allocation request + for (int i = levels.size() - 1; i >= 0; --i) { + Level level = (Level) levels.get(i); + if (level.add(rect)) + return true; + } + + // See whether compaction could satisfy this allocation. This + // increases the computational complexity of the addition process, + // but prevents us from expanding unnecessarily. + for (int i = levels.size() - 1; i >= 0; --i) { + Level level = (Level) levels.get(i); + if (level.couldAllocateIfCompacted(rect)) + return false; + } + + // OK, we need to either add a new Level or expand the backing + // store. Try to add a new Level. + if (nextAddY + rect.h() > h) + return false; + + Level newLevel = new Level(w, rect.h(), nextAddY, this); + levels.add(newLevel); + nextAddY += rect.h(); + boolean res = newLevel.add(rect); + if (!res) + throw new RuntimeException("Unexpected failure in addition to new Level"); + return true; + } + + /** Removes the given Rect from this LevelSet. */ + public boolean remove(Rect rect) { + for (int i = levels.size() - 1; i >= 0; --i) { + Level level = (Level) levels.get(i); + if (level.remove(rect)) + return true; + } + + return false; + } + + /** Allocates the given Rectangle, performing compaction of a Level + if necessary. This is the correct fallback path to {@link + #add(Rect)} above. Returns true if allocated successfully, false + otherwise (indicating the need to expand the backing store). */ + public boolean compactAndAdd(Rect rect, + Object backingStore, + BackingStoreManager manager) { + for (int i = levels.size() - 1; i >= 0; --i) { + Level level = (Level) levels.get(i); + if (level.couldAllocateIfCompacted(rect)) { + level.compact(backingStore, manager); + boolean res = level.add(rect); + if (!res) + throw new RuntimeException("Unexpected failure to add after compaction"); + return true; + } + } + + return false; + } + + /** Indicates whether it's legal to trivially increase the height of + the given Level. This is only possible if it's the last Level + added and there's enough room in the backing store. */ + public boolean canExpand(Level level, int height) { + if (levels.isEmpty()) + return false; // Should not happen + if (levels.get(levels.size() - 1) == level && + (h - nextAddY >= height - level.h())) + return true; + return false; + } + + public void expand(Level level, int oldHeight, int newHeight) { + nextAddY += (newHeight - oldHeight); + } + + /** Gets the used height of the levels in this LevelSet. */ + public int getUsedHeight() { + return nextAddY; + } + + /** Sets the height of this LevelSet. It is only legal to reduce the + height to greater than or equal to the currently used height. */ + public void setHeight(int height) throws IllegalArgumentException { + if (height < getUsedHeight()) { + throw new IllegalArgumentException("May not reduce height below currently used height"); + } + h = height; + } + + /** Returns the vertical fragmentation ratio of this LevelSet. This + is defined as the ratio of the sum of the heights of all + completely empty Levels divided by the overall used height of + the LevelSet. A high vertical fragmentation ratio indicates that + it may be profitable to perform a compaction. */ + public float verticalFragmentationRatio() { + int freeHeight = 0; + int usedHeight = getUsedHeight(); + if (usedHeight == 0) + return 0.0f; + for (Iterator iter = iterator(); iter.hasNext(); ) { + Level level = (Level) iter.next(); + if (level.isEmpty()) { + freeHeight += level.h(); + } + } + return (float) freeHeight / (float) usedHeight; + } + + public Iterator iterator() { + return levels.iterator(); + } + + /** Visits all Rects contained in this LevelSet. */ + public void visit(RectVisitor visitor) { + for (Iterator iter = levels.iterator(); iter.hasNext(); ) { + Level level = (Level) iter.next(); + level.visit(visitor); + } + } + + /** Updates the references to the Rect objects in this LevelSet with + the "next locations" of those Rects. This is actually used to + update the new Rects in a newly laid-out LevelSet with the + original Rects. */ + public void updateRectangleReferences() { + for (Iterator iter = levels.iterator(); iter.hasNext(); ) { + Level level = (Level) iter.next(); + level.updateRectangleReferences(); + } + } + + /** Clears out all Levels stored in this LevelSet. */ + public void clear() { + levels.clear(); + nextAddY = 0; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java new file mode 100644 index 000000000..6206c4a11 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.packrect; + +/** Represents a rectangular region on the backing store. The edges of + the rectangle are the infinitely thin region between adjacent + pixels on the screen. The origin of the rectangle is its + upper-left corner. It is inclusive of the pixels on the top and + left edges and exclusive of the pixels on the bottom and right + edges. For example, a rect at position (0, 0) and of size (1, 1) + would include only the pixel at (0, 0). <P> + + Negative coordinates and sizes are not supported, since they make + no sense in the context of the packer, which deals only with + positively sized regions. <P> + + This class contains a user data field for efficient hookup to + external data structures as well as enough other hooks to + efficiently plug into the rectangle packer. */ + +public class Rect { + private int x; + private int y; + private int w; + private int h; + + // The level we're currently installed in in the parent + // RectanglePacker, or null if not hooked in to the table yet + private Level level; + + // The user's object this rectangle represents. + private Object userData; + + // Used transiently during re-layout of the backing store (when + // there is no room left due either to fragmentation or just being + // out of space) + private Rect nextLocation; + + public Rect() { + this(null); + } + + public Rect(Object userData) { + this(0, 0, 0, 0, userData); + } + + public Rect(int x, int y, int w, int h, Object userData) { + setPosition(x, y); + setSize(w, h); + setUserData(userData); + } + + public int x() { return x; } + public int y() { return y; } + public int w() { return w; } + public int h() { return h; } + public Object getUserData() { return userData; } + public Rect getNextLocation() { return nextLocation; } + + public void setPosition(int x, int y) { + if (x < 0) + throw new IllegalArgumentException("Negative x"); + if (y < 0) + throw new IllegalArgumentException("Negative y"); + this.x = x; + this.y = y; + } + + public void setSize(int w, int h) throws IllegalArgumentException { + if (w < 0) + throw new IllegalArgumentException("Negative width"); + if (h < 0) + throw new IllegalArgumentException("Negative height"); + this.w = w; + this.h = h; + } + + public void setUserData(Object obj) { userData = obj; } + public void setNextLocation(Rect nextLocation) { this.nextLocation = nextLocation; } + + // Helpers for computations. + + /** Returns the maximum x-coordinate contained within this + rectangle. Note that this returns a different result than Java + 2D's rectangles; for a rectangle of position (0, 0) and size (1, + 1) this will return 0, not 1. Returns -1 if the width of this + rectangle is 0. */ + public int maxX() { + if (w() < 1) + return -1; + return x() + w() - 1; + } + + /** Returns the maximum y-coordinate contained within this + rectangle. Note that this returns a different result than Java + 2D's rectangles; for a rectangle of position (0, 0) and size (1, + 1) this will return 0, not 1. Returns -1 if the height of this + rectangle is 0. */ + public int maxY() { + if (h() < 1) + return -1; + return y() + h() - 1; + } + + public boolean canContain(Rect other) { + return (w() >= other.w() && + h() >= other.h()); + } + + public String toString() { + return "[Rect x: " + x() + " y: " + y() + " w: " + w() + " h: " + h() + "]"; + } + + // Unclear whether it's a good idea to override hashCode and equals + // for these objects + /* + public boolean equals(Object other) { + if (other == null || (!(other instanceof Rect))) { + return false; + } + + Rect r = (Rect) other; + return (this.x() == r.x() && + this.y() == r.y() && + this.w() == r.w() && + this.h() == r.h()); + } + + public int hashCode() { + return (x + y * 13 + w * 17 + h * 23); + } + */ +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/RectVisitor.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectVisitor.java new file mode 100644 index 000000000..49cfc82e6 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectVisitor.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.packrect; + +/** Iteration construct without exposing the internals of the + RectanglePacker and without implementing a complex Iterator. */ + +public interface RectVisitor { + public void visit(Rect rect); +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java new file mode 100644 index 000000000..1496a04a6 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java @@ -0,0 +1,306 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.packrect; + +import java.util.*; + +/** Packs rectangles supplied by the user (typically representing + image regions) into a larger backing store rectangle (typically + representing a large texture). Supports automatic compaction of + the space on the backing store, and automatic expansion of the + backing store, when necessary. */ + +public class RectanglePacker { + private BackingStoreManager manager; + private Object backingStore; + private LevelSet levels; + private float EXPANSION_FACTOR = 0.5f; + private float SHRINK_FACTOR = 0.3f; + + private int initialWidth; + private int initialHeight; + + private int maxWidth = -1; + private int maxHeight = -1; + + static class RectHComparator implements Comparator { + public int compare(Object o1, Object o2) { + Rect r1 = (Rect) o1; + Rect r2 = (Rect) o2; + return r2.h() - r1.h(); + } + + public boolean equals(Object obj) { + return this == obj; + } + } + private static final Comparator rectHComparator = new RectHComparator(); + + public RectanglePacker(BackingStoreManager manager, + int initialWidth, + int initialHeight) { + this.manager = manager; + levels = new LevelSet(initialWidth, initialHeight); + this.initialWidth = initialWidth; + this.initialHeight = initialHeight; + } + + public Object getBackingStore() { + if (backingStore == null) { + backingStore = manager.allocateBackingStore(levels.w(), levels.h()); + } + + return backingStore; + } + + /** Sets up a maximum width and height for the backing store. These + are optional and if not specified the backing store will grow as + necessary. Setting up a maximum width and height introduces the + possibility that additions will fail; these are handled with the + BackingStoreManager's allocationFailed notification. */ + public void setMaxSize(int maxWidth, int maxHeight) { + this.maxWidth = maxWidth; + this.maxHeight = maxHeight; + } + + /** Decides upon an (x, y) position for the given rectangle (leaving + its width and height unchanged) and places it on the backing + store. May provoke re-layout of other Rects already added. If + the BackingStoreManager does not support compaction, and {@link + BackingStoreManager#preExpand BackingStoreManager.preExpand} + does not clear enough space for the incoming rectangle, then + this method will throw a RuntimeException. */ + public void add(Rect rect) throws RuntimeException { + // Allocate backing store if we don't have any yet + if (backingStore == null) + backingStore = manager.allocateBackingStore(levels.w(), levels.h()); + + int attemptNumber = 0; + boolean tryAgain = false; + + do { + // Try to allocate + if (levels.add(rect)) + return; + + if (manager.canCompact()) { + // Try to allocate with horizontal compaction + if (levels.compactAndAdd(rect, backingStore, manager)) + return; + // Let the manager have a chance at potentially evicting some entries + tryAgain = manager.preExpand(rect, attemptNumber++); + } else { + tryAgain = manager.additionFailed(rect, attemptNumber++); + } + } while (tryAgain); + + if (!manager.canCompact()) { + throw new RuntimeException("BackingStoreManager does not support compaction or expansion, and didn't clear space for new rectangle"); + } + + compactImpl(rect); + + // Retry the addition of the incoming rectangle + add(rect); + // Done + } + + /** Removes the given rectangle from this RectanglePacker. */ + public void remove(Rect rect) { + levels.remove(rect); + } + + /** Visits all Rects contained in this RectanglePacker. */ + public void visit(RectVisitor visitor) { + levels.visit(visitor); + } + + /** Returns the vertical fragmentation ratio of this + RectanglePacker. This is defined as the ratio of the sum of the + heights of all completely empty Levels divided by the overall + used height of the LevelSet. A high vertical fragmentation ratio + indicates that it may be profitable to perform a compaction. */ + public float verticalFragmentationRatio() { + return levels.verticalFragmentationRatio(); + } + + /** Forces a compaction cycle, which typically results in allocating + a new backing store and copying all entries to it. */ + public void compact() { + compactImpl(null); + } + + // The "cause" rect may be null + private void compactImpl(Rect cause) { + // Have to either expand, compact or both. Need to figure out what + // direction to go. Prefer to expand vertically. Expand + // horizontally only if rectangle being added is too wide. FIXME: + // may want to consider rebalancing the width and height to be + // more equal if it turns out we keep expanding in the vertical + // direction. + boolean done = false; + int newWidth = levels.w(); + int newHeight = levels.h(); + LevelSet nextLevelSet = null; + int attemptNumber = 0; + boolean needAdditionFailureNotification = false; + + while (!done) { + if (cause != null) { + if (cause.w() > newWidth) { + newWidth = cause.w(); + } else { + newHeight = (int) (newHeight * (1.0f + EXPANSION_FACTOR)); + } + } + + // Clamp to maximum values + needAdditionFailureNotification = false; + if (maxWidth > 0 && newWidth > maxWidth) { + newWidth = maxWidth; + needAdditionFailureNotification = true; + } + if (maxHeight > 0 && newHeight > maxHeight) { + newHeight = maxHeight; + needAdditionFailureNotification = true; + } + + nextLevelSet = new LevelSet(newWidth, newHeight); + + // Make copies of all existing rectangles + List/*<Rect>*/ newRects = new ArrayList/*<Rect>*/(); + for (Iterator i1 = levels.iterator(); i1.hasNext(); ) { + Level level = (Level) i1.next(); + for (Iterator i2 = level.iterator(); i2.hasNext(); ) { + Rect cur = (Rect) i2.next(); + Rect newRect = new Rect(0, 0, cur.w(), cur.h(), null); + cur.setNextLocation(newRect); + // Hook up the reverse mapping too for easier replacement + newRect.setNextLocation(cur); + newRects.add(newRect); + } + } + // Sort them by decreasing height (note: this isn't really + // guaranteed to improve the chances of a successful layout) + Collections.sort(newRects, rectHComparator); + // Try putting all of these rectangles into the new level set + done = true; + for (Iterator iter = newRects.iterator(); iter.hasNext(); ) { + if (!nextLevelSet.add((Rect) iter.next())) { + done = false; + break; + } + } + + if (done && cause != null) { + // Try to add the new rectangle as well + if (nextLevelSet.add(cause)) { + // We're OK + } else { + done = false; + } + } + + // Don't send addition failure notifications if we're only doing + // a compaction + if (!done && needAdditionFailureNotification && cause != null) { + manager.additionFailed(cause, attemptNumber); + } + ++attemptNumber; + } + + // See whether the implicit compaction that just occurred has + // yielded excess empty space. + if (nextLevelSet.getUsedHeight() > 0 && + nextLevelSet.getUsedHeight() < nextLevelSet.h() * SHRINK_FACTOR) { + int shrunkHeight = Math.max(initialHeight, + (int) (nextLevelSet.getUsedHeight() * (1.0f + EXPANSION_FACTOR))); + if (maxHeight > 0 && shrunkHeight > maxHeight) { + shrunkHeight = maxHeight; + } + nextLevelSet.setHeight(shrunkHeight); + } + + // If we temporarily added the new rectangle to the new LevelSet, + // take it out since we don't "really" add it here but in add(), above + if (cause != null) { + nextLevelSet.remove(cause); + } + + // OK, now we have a new layout and a mapping from the old to the + // new locations of rectangles on the backing store. Allocate a + // new backing store, move the contents over and deallocate the + // old one. + Object newBackingStore = manager.allocateBackingStore(nextLevelSet.w(), + nextLevelSet.h()); + manager.beginMovement(backingStore, newBackingStore); + for (Iterator i1 = levels.iterator(); i1.hasNext(); ) { + Level level = (Level) i1.next(); + for (Iterator i2 = level.iterator(); i2.hasNext(); ) { + Rect cur = (Rect) i2.next(); + manager.move(backingStore, cur, + newBackingStore, cur.getNextLocation()); + } + } + // Replace references to temporary rectangles with original ones + nextLevelSet.updateRectangleReferences(); + manager.endMovement(backingStore, newBackingStore); + // Now delete the old backing store + manager.deleteBackingStore(backingStore); + // Update to new versions of backing store and LevelSet + backingStore = newBackingStore; + levels = nextLevelSet; + } + + /** Clears all Rects contained in this RectanglePacker. */ + public void clear() { + levels.clear(); + } + + /** Disposes the backing store allocated by the + BackingStoreManager. This RectanglePacker may no longer be used + after calling this method. */ + public void dispose() { + if (backingStore != null) + manager.deleteBackingStore(backingStore); + backingStore = null; + levels = null; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/package.html b/src/jogl/classes/com/jogamp/opengl/util/packrect/package.html new file mode 100644 index 000000000..c1c5db477 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/package.html @@ -0,0 +1,9 @@ +<BODY> +This package implements a rectangle packing algorithm suitable for +tracking the placement of multiple rectangles inside a larger one. It +is useful for cases such as placing the contents of multiple windows +on a larger backing store texture for a compositing window manager; +placing multiple rasterized strings in a texture map for quick +rendering to the screen; and many other situations where it is useful +to carve up a larger texture into smaller pieces dynamically. <P> +</BODY> diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java new file mode 100644 index 000000000..38f8ff974 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java @@ -0,0 +1,1120 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.jogamp.opengl.util.texture; + +import java.nio.*; +import java.security.*; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import javax.media.nativewindow.NativeWindowFactory; +import jogamp.opengl.*; +import com.jogamp.opengl.util.texture.*; +import com.jogamp.opengl.util.texture.spi.*; + +/** + * Represents an OpenGL texture object. Contains convenience routines + * for enabling/disabling OpenGL texture state, binding this texture, + * and computing texture coordinates for both the entire image as well + * as a sub-image. + * + * <p><a name="nonpow2"><b>Non-power-of-two restrictions</b></a> + * <br> When creating an OpenGL texture object, the Texture class will + * attempt to leverage the <a + * href="http://www.opengl.org/registry/specs/ARB/texture_non_power_of_two.txt">GL_ARB_texture_non_power_of_two</a> + * and <a + * href="http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt">GL_ARB_texture_rectangle</a> + * extensions (in that order) whenever possible. If neither extension + * is available, the Texture class will simply upload a non-pow2-sized + * image into a standard pow2-sized texture (without any special + * scaling). Since the choice of extension (or whether one is used at + * all) depends on the user's machine configuration, developers are + * recommended to use {@link #getImageTexCoords} and {@link + * #getSubImageTexCoords}, as those methods will calculate the + * appropriate texture coordinates for the situation. + * + * <p>One caveat in this approach is that certain texture wrap modes + * (e.g. <code>GL_REPEAT</code>) are not legal when the GL_ARB_texture_rectangle + * extension is in use. Another issue to be aware of is that in the + * default pow2 scenario, if the original image does not have pow2 + * dimensions, then wrapping may not work as one might expect since + * the image does not extend to the edges of the pow2 texture. If + * texture wrapping is important, it is recommended to use only + * pow2-sized images with the Texture class. + * + * <p><a name="perftips"><b>Performance Tips</b></a> + * <br> For best performance, try to avoid calling {@link #enable} / + * {@link #bind} / {@link #disable} any more than necessary. For + * example, applications using many Texture objects in the same scene + * may want to reduce the number of calls to both {@link #enable} and + * {@link #disable}. To do this it is necessary to call {@link + * #getTarget} to make sure the OpenGL texture target is the same for + * all of the Texture objects in use; non-power-of-two textures using + * the GL_ARB_texture_rectangle extension use a different target than + * power-of-two textures using the GL_TEXTURE_2D target. Note that + * when switching between textures it is necessary to call {@link + * #bind}, but when drawing many triangles all using the same texture, + * for best performance only one call to {@link #bind} should be made. + * + * <p><a name="premult"><b>Alpha premultiplication and blending</b></a> + * <br> The mathematically correct way to perform blending in OpenGL + * (with the SrcOver "source over destination" mode, or any other + * Porter-Duff rule) is to use "premultiplied color components", which + * means the R/G/ B color components have already been multiplied by + * the alpha value. To make things easier for developers, the Texture + * class will automatically convert non-premultiplied image data into + * premultiplied data when storing it into an OpenGL texture. As a + * result, it is important to use the correct blending function; for + * example, the SrcOver rule is expressed as: +<pre> + gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); +</pre> + * Also, when using a texture function like <code>GL_MODULATE</code> where + * the current color plays a role, it is important to remember to make + * sure that the color is specified in a premultiplied form, for + * example: +<pre> + float a = ...; + float r = r * a; + float g = g * a; + float b = b * a; + gl.glColor4f(r, g, b, a); +</pre> + * + * For reference, here is a list of the Porter-Duff compositing rules + * and the associated OpenGL blend functions (source and destination + * factors) to use in the face of premultiplied alpha: + * +<CENTER> +<TABLE WIDTH="75%"> +<TR> <TD> Rule <TD> Source <TD> Dest +<TR> <TD> Clear <TD> GL_ZERO <TD> GL_ZERO +<TR> <TD> Src <TD> GL_ONE <TD> GL_ZERO +<TR> <TD> SrcOver <TD> GL_ONE <TD> GL_ONE_MINUS_SRC_ALPHA +<TR> <TD> DstOver <TD> GL_ONE_MINUS_DST_ALPHA <TD> GL_ONE +<TR> <TD> SrcIn <TD> GL_DST_ALPHA <TD> GL_ZERO +<TR> <TD> DstIn <TD> GL_ZERO <TD> GL_SRC_ALPHA +<TR> <TD> SrcOut <TD> GL_ONE_MINUS_DST_ALPHA <TD> GL_ZERO +<TR> <TD> DstOut <TD> GL_ZERO <TD> GL_ONE_MINUS_SRC_ALPHA +<TR> <TD> Dst <TD> GL_ZERO <TD> GL_ONE +<TR> <TD> SrcAtop <TD> GL_DST_ALPHA <TD> GL_ONE_MINUS_SRC_ALPHA +<TR> <TD> DstAtop <TD> GL_ONE_MINUS_DST_ALPHA <TD> GL_SRC_ALPHA +<TR> <TD> AlphaXor <TD> GL_ONE_MINUS_DST_ALPHA <TD> GL_ONE_MINUS_SRC_ALPHA +</TABLE> +</CENTER> + * + * @author Chris Campbell + * @author Kenneth Russell + */ +public class Texture { + /** The GL target type. */ + private int target; + /** The GL texture ID. */ + private int texID; + /** The width of the texture. */ + private int texWidth; + /** The height of the texture. */ + private int texHeight; + /** The width of the image. */ + private int imgWidth; + /** The height of the image. */ + private int imgHeight; + /** The original aspect ratio of the image, before any rescaling + that might have occurred due to using the GLU mipmap routines. */ + private float aspectRatio; + /** Indicates whether the TextureData requires a vertical flip of + the texture coords. */ + private boolean mustFlipVertically; + /** Indicates whether we're using automatic mipmap generation + support (GL_GENERATE_MIPMAP). */ + private boolean usingAutoMipmapGeneration; + + /** The texture coordinates corresponding to the entire image. */ + private TextureCoords coords; + + /** An estimate of the amount of texture memory this texture consumes. */ + private int estimatedMemorySize; + + private static final AccessControlContext localACC = AccessController.getContext(); + + private static final boolean DEBUG = Debug.debug("Texture"); + private static final boolean VERBOSE = Debug.verbose(); + + // For testing alternate code paths on more capable hardware + private static final boolean disableNPOT = Debug.isPropertyDefined("jogl.texture.nonpot", true, localACC); + private static final boolean disableTexRect = Debug.isPropertyDefined("jogl.texture.notexrect", true, localACC); + + public Texture(TextureData data) throws GLException { + texID = 0; + updateImage(data); + } + + // Constructor for use when creating e.g. cube maps, where there is + // no initial texture data + public Texture(int target) throws GLException { + texID = 0; + this.target = target; + } + + // Package-private constructor for creating a texture object which wraps + // an existing texture ID from another package + Texture(int textureID, + int target, + int texWidth, + int texHeight, + int imgWidth, + int imgHeight, + boolean mustFlipVertically) { + this.texID = textureID; + this.target = target; + this.mustFlipVertically = mustFlipVertically; + this.texWidth = texWidth; + this.texHeight = texHeight; + setImageSize(imgWidth, imgHeight, target); + } + + /** + * Enables this texture's target (e.g., GL_TEXTURE_2D) in the + * current GL context's state. This method is a shorthand equivalent + * of the following OpenGL code: + <pre> + gl.glEnable(texture.getTarget()); + </pre> + * + * See the <a href="#perftips">performance tips</a> above for hints + * on how to maximize performance when using many Texture objects. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void enable() throws GLException { + GLContext.getCurrentGL().glEnable(target); + } + + /** + * Disables this texture's target (e.g., GL_TEXTURE_2D) in the + * current GL context's state. This method is a shorthand equivalent + * of the following OpenGL code: + <pre> + gl.glDisable(texture.getTarget()); + </pre> + * + * See the <a href="#perftips">performance tips</a> above for hints + * on how to maximize performance when using many Texture objects. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void disable() throws GLException { + GLContext.getCurrentGL().glDisable(target); + } + + /** + * Binds this texture to the current GL context. This method is a + * shorthand equivalent of the following OpenGL code: + <pre> + gl.glBindTexture(texture.getTarget(), texture.getTextureObject()); + </pre> + * + * See the <a href="#perftips">performance tips</a> above for hints + * on how to maximize performance when using many Texture objects. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void bind() throws GLException { + validateTexID(null, true); + GLContext.getCurrentGL().glBindTexture(target, texID); + } + + /** + * Disposes the native resources used by this texture object. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + * @deprecated use destroy(GL) + */ + public void dispose() throws GLException { + destroy(GLContext.getCurrentGL()); + } + + /** + * Disposes the native resources used by this texture object. + * + * @throws GLException if any OpenGL-related errors occurred + * @deprecated use destroy(GL) + */ + public void dispose(GL gl) throws GLException { + destroy(gl); + } + + /** + * Destroys the native resources used by this texture object. + * + * @throws GLException if any OpenGL-related errors occurred + */ + public void destroy(GL gl) throws GLException { + if(0<texID) { + gl.glDeleteTextures(1, new int[] {texID}, 0); + texID = 0; + } + } + + /** + * Returns the OpenGL "target" of this texture. + * + * @return the OpenGL target of this texture + * @see javax.media.opengl.GL#GL_TEXTURE_2D + * @see javax.media.opengl.GL2#GL_TEXTURE_RECTANGLE_ARB + */ + public int getTarget() { + return target; + } + + /** + * Returns the width of the allocated OpenGL texture in pixels. + * Note that the texture width will be greater than or equal to the + * width of the image contained within. + * + * @return the width of the texture + */ + public int getWidth() { + return texWidth; + } + + /** + * Returns the height of the allocated OpenGL texture in pixels. + * Note that the texture height will be greater than or equal to the + * height of the image contained within. + * + * @return the height of the texture + */ + public int getHeight() { + return texHeight; + } + + /** + * Returns the width of the image contained within this texture. + * Note that for non-power-of-two textures in particular this may + * not be equal to the result of {@link #getWidth}. It is + * recommended that applications call {@link #getImageTexCoords} and + * {@link #getSubImageTexCoords} rather than using this API + * directly. + * + * @return the width of the image + */ + public int getImageWidth() { + return imgWidth; + } + + /** + * Returns the height of the image contained within this texture. + * Note that for non-power-of-two textures in particular this may + * not be equal to the result of {@link #getHeight}. It is + * recommended that applications call {@link #getImageTexCoords} and + * {@link #getSubImageTexCoords} rather than using this API + * directly. + * + * @return the height of the image + */ + public int getImageHeight() { + return imgHeight; + } + + /** + * Returns the original aspect ratio of the image, defined as (image + * width) / (image height), before any scaling that might have + * occurred as a result of using the GLU mipmap routines. + */ + public float getAspectRatio() { + return aspectRatio; + } + + /** + * Returns the set of texture coordinates corresponding to the + * entire image. If the TextureData indicated that the texture + * coordinates must be flipped vertically, the returned + * TextureCoords will take that into account. + * + * @return the texture coordinates corresponding to the entire image + */ + public TextureCoords getImageTexCoords() { + return coords; + } + + /** + * Returns the set of texture coordinates corresponding to the + * specified sub-image. The (x1, y1) and (x2, y2) points are + * specified in terms of pixels starting from the lower-left of the + * image. (x1, y1) should specify the lower-left corner of the + * sub-image and (x2, y2) the upper-right corner of the sub-image. + * If the TextureData indicated that the texture coordinates must be + * flipped vertically, the returned TextureCoords will take that + * into account; this should not be handled by the end user in the + * specification of the y1 and y2 coordinates. + * + * @return the texture coordinates corresponding to the specified sub-image + */ + public TextureCoords getSubImageTexCoords(int x1, int y1, int x2, int y2) { + if (target == GL2.GL_TEXTURE_RECTANGLE_ARB) { + if (mustFlipVertically) { + return new TextureCoords(x1, texHeight - y1, x2, texHeight - y2); + } else { + return new TextureCoords(x1, y1, x2, y2); + } + } else { + float tx1 = (float)x1 / (float)texWidth; + float ty1 = (float)y1 / (float)texHeight; + float tx2 = (float)x2 / (float)texWidth; + float ty2 = (float)y2 / (float)texHeight; + if (mustFlipVertically) { + float yMax = (float) imgHeight / (float) texHeight; + return new TextureCoords(tx1, yMax - ty1, tx2, yMax - ty2); + } else { + return new TextureCoords(tx1, ty1, tx2, ty2); + } + } + } + + /** + * Updates the entire content area of this texture using the data in + * the given image. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void updateImage(TextureData data) throws GLException { + updateImage(data, 0); + } + + /** + * Indicates whether this texture's texture coordinates must be + * flipped vertically in order to properly display the texture. This + * is handled automatically by {@link #getImageTexCoords + * getImageTexCoords} and {@link #getSubImageTexCoords + * getSubImageTexCoords}, but applications may generate or otherwise + * produce texture coordinates which must be corrected. + */ + public boolean getMustFlipVertically() { + return mustFlipVertically; + } + + /** + * Updates the content area of the specified target of this texture + * using the data in the given image. In general this is intended + * for construction of cube maps. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void updateImage(TextureData data, int target) throws GLException { + GL gl = GLContext.getCurrentGL(); + validateTexID(gl, true); + + imgWidth = data.getWidth(); + imgHeight = data.getHeight(); + aspectRatio = (float) imgWidth / (float) imgHeight; + mustFlipVertically = data.getMustFlipVertically(); + + int texTarget = 0; + int texParamTarget = this.target; + + // See whether we have automatic mipmap generation support + boolean haveAutoMipmapGeneration = + (gl.isExtensionAvailable("GL_VERSION_1_4") || + gl.isExtensionAvailable("GL_SGIS_generate_mipmap")); + + // Indicate to the TextureData what functionality is available + data.setHaveEXTABGR(gl.isExtensionAvailable("GL_EXT_abgr")); + data.setHaveGL12(gl.isExtensionAvailable("GL_VERSION_1_2")); + + // Indicates whether both width and height are power of two + boolean isPOT = isPowerOfTwo(imgWidth) && isPowerOfTwo(imgHeight); + + // Note that automatic mipmap generation doesn't work for + // GL_ARB_texture_rectangle + if (!isPOT && !haveNPOT(gl)) { + haveAutoMipmapGeneration = false; + } + + boolean expandingCompressedTexture = false; + boolean done = false; + if (data.getMipmap() && !haveAutoMipmapGeneration) { + // GLU always scales the texture's dimensions to be powers of + // two. It also doesn't really matter exactly what the texture + // width and height are because the texture coords are always + // between 0.0 and 1.0. + imgWidth = nextPowerOfTwo(imgWidth); + imgHeight = nextPowerOfTwo(imgHeight); + texWidth = imgWidth; + texHeight = imgHeight; + texTarget = GL.GL_TEXTURE_2D; + done = true; + } + + if (!done && preferTexRect(gl) && !isPOT && + haveTexRect(gl) && !data.isDataCompressed() && !gl.isGL3() && !gl.isGLES()) { + // GL_ARB_texture_rectangle does not work for compressed textures + if (DEBUG) { + System.err.println("Using GL_ARB_texture_rectangle preferentially on this hardware"); + } + + texWidth = imgWidth; + texHeight = imgHeight; + texTarget = GL2.GL_TEXTURE_RECTANGLE_ARB; + done = true; + } + + if (!done && (isPOT || haveNPOT(gl))) { + if (DEBUG) { + if (isPOT) { + System.err.println("Power-of-two texture"); + } else { + System.err.println("Using GL_ARB_texture_non_power_of_two"); + } + } + + texWidth = imgWidth; + texHeight = imgHeight; + texTarget = GL.GL_TEXTURE_2D; + done = true; + } + + if (!done && haveTexRect(gl) && !data.isDataCompressed() && !gl.isGL3() && !gl.isGLES()) { + // GL_ARB_texture_rectangle does not work for compressed textures + if (DEBUG) { + System.err.println("Using GL_ARB_texture_rectangle"); + } + + texWidth = imgWidth; + texHeight = imgHeight; + texTarget = GL2.GL_TEXTURE_RECTANGLE_ARB; + done = true; + } + + if (!done) { + // If we receive non-power-of-two compressed texture data and + // don't have true hardware support for compressed textures, we + // can fake this support by producing an empty "compressed" + // texture image, using glCompressedTexImage2D with that to + // allocate the texture, and glCompressedTexSubImage2D with the + // incoming data. + if (data.isDataCompressed()) { + if (data.getMipmapData() != null) { + + // We don't currently support expanding of compressed, + // mipmapped non-power-of-two textures to the nearest power + // of two; the obvious port of the non-mipmapped code didn't + // work + throw new GLException("Mipmapped non-power-of-two compressed textures only supported on OpenGL 2.0 hardware (GL_ARB_texture_non_power_of_two)"); + } + + expandingCompressedTexture = true; + } + + if (DEBUG) { + System.err.println("Expanding texture to power-of-two dimensions"); + } + + if (data.getBorder() != 0) { + throw new RuntimeException("Scaling up a non-power-of-two texture which has a border won't work"); + } + texWidth = nextPowerOfTwo(imgWidth); + texHeight = nextPowerOfTwo(imgHeight); + texTarget = GL.GL_TEXTURE_2D; + } + + texParamTarget = texTarget; + setImageSize(imgWidth, imgHeight, texTarget); + + if (target != 0) { + // Allow user to override auto detection and skip bind step (for + // cubemap construction) + texTarget = target; + if (this.target == 0) { + throw new GLException("Override of target failed; no target specified yet"); + } + texParamTarget = this.target; + gl.glBindTexture(texParamTarget, texID); + } else { + gl.glBindTexture(texTarget, texID); + } + + if (data.getMipmap() && !haveAutoMipmapGeneration) { + int[] align = new int[1]; + gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, align, 0); // save alignment + gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, data.getAlignment()); + + if (data.isDataCompressed()) { + throw new GLException("May not request mipmap generation for compressed textures"); + } + + try { + // FIXME: may need check for GLUnsupportedException + GLU glu = GLU.createGLU(gl); + glu.gluBuild2DMipmaps(texTarget, data.getInternalFormat(), + data.getWidth(), data.getHeight(), + data.getPixelFormat(), data.getPixelType(), data.getBuffer()); + } finally { + gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, align[0]); // restore alignment + } + } else { + checkCompressedTextureExtensions(data); + Buffer[] mipmapData = data.getMipmapData(); + if (mipmapData != null) { + int width = texWidth; + int height = texHeight; + for (int i = 0; i < mipmapData.length; i++) { + if (data.isDataCompressed()) { + // Need to use glCompressedTexImage2D directly to allocate and fill this image + // Avoid spurious memory allocation when possible + gl.glCompressedTexImage2D(texTarget, i, data.getInternalFormat(), + width, height, data.getBorder(), + mipmapData[i].remaining(), mipmapData[i]); + } else { + // Allocate texture image at this level + gl.glTexImage2D(texTarget, i, data.getInternalFormat(), + width, height, data.getBorder(), + data.getPixelFormat(), data.getPixelType(), null); + updateSubImageImpl(data, texTarget, i, 0, 0, 0, 0, data.getWidth(), data.getHeight()); + } + + width = Math.max(width / 2, 1); + height = Math.max(height / 2, 1); + } + } else { + if (data.isDataCompressed()) { + if (!expandingCompressedTexture) { + // Need to use glCompressedTexImage2D directly to allocate and fill this image + // Avoid spurious memory allocation when possible + gl.glCompressedTexImage2D(texTarget, 0, data.getInternalFormat(), + texWidth, texHeight, data.getBorder(), + data.getBuffer().capacity(), data.getBuffer()); + } else { + ByteBuffer buf = DDSImage.allocateBlankBuffer(texWidth, + texHeight, + data.getInternalFormat()); + gl.glCompressedTexImage2D(texTarget, 0, data.getInternalFormat(), + texWidth, texHeight, data.getBorder(), + buf.capacity(), buf); + updateSubImageImpl(data, texTarget, 0, 0, 0, 0, 0, data.getWidth(), data.getHeight()); + } + } else { + if (data.getMipmap() && haveAutoMipmapGeneration && gl.isGL2ES1()) { + // For now, only use hardware mipmapping for uncompressed 2D + // textures where the user hasn't explicitly specified + // mipmap data; don't know about interactions between + // GL_GENERATE_MIPMAP and glCompressedTexImage2D + gl.glTexParameteri(texParamTarget, GL2ES1.GL_GENERATE_MIPMAP, GL.GL_TRUE); + usingAutoMipmapGeneration = true; + } + + gl.glTexImage2D(texTarget, 0, data.getInternalFormat(), + texWidth, texHeight, data.getBorder(), + data.getPixelFormat(), data.getPixelType(), null); + updateSubImageImpl(data, texTarget, 0, 0, 0, 0, 0, data.getWidth(), data.getHeight()); + } + } + } + + int minFilter = (data.getMipmap() ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR); + int magFilter = GL.GL_LINEAR; + int wrapMode = (gl.isExtensionAvailable("GL_VERSION_1_2") || !gl.isGL2()) ? GL.GL_CLAMP_TO_EDGE : GL2.GL_CLAMP; + + // REMIND: figure out what to do for GL_TEXTURE_RECTANGLE_ARB + if (texTarget != GL2.GL_TEXTURE_RECTANGLE_ARB) { + gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_MIN_FILTER, minFilter); + gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_MAG_FILTER, magFilter); + gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_WRAP_S, wrapMode); + gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_WRAP_T, wrapMode); + if (this.target == GL2.GL_TEXTURE_CUBE_MAP) { + gl.glTexParameteri(texParamTarget, GL2.GL_TEXTURE_WRAP_R, wrapMode); + } + } + + // Don't overwrite target if we're loading e.g. faces of a cube + // map + if ((this.target == 0) || + (this.target == GL.GL_TEXTURE_2D) || + (this.target == GL2.GL_TEXTURE_RECTANGLE_ARB)) { + this.target = texTarget; + } + + // This estimate will be wrong for cube maps + estimatedMemorySize = data.getEstimatedMemorySize(); + } + + /** + * Updates a subregion of the content area of this texture using the + * given data. If automatic mipmap generation is in use (see {@link + * #isUsingAutoMipmapGeneration isUsingAutoMipmapGeneration}), + * updates to the base (level 0) mipmap will cause the lower-level + * mipmaps to be regenerated, and updates to other mipmap levels + * will be ignored. Otherwise, if automatic mipmap generation is not + * in use, only updates the specified mipmap level and does not + * re-generate mipmaps if they were originally produced or loaded. + * + * @param data the image data to be uploaded to this texture + * @param mipmapLevel the mipmap level of the texture to set. If + * this is non-zero and the TextureData contains mipmap data, the + * appropriate mipmap level will be selected. + * @param x the x offset (in pixels) relative to the lower-left corner + * of this texture + * @param y the y offset (in pixels) relative to the lower-left corner + * of this texture + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void updateSubImage(TextureData data, int mipmapLevel, int x, int y) throws GLException { + if (usingAutoMipmapGeneration && mipmapLevel != 0) { + // When we're using mipmap generation via GL_GENERATE_MIPMAP, we + // don't need to update other mipmap levels + return; + } + bind(); + updateSubImageImpl(data, target, mipmapLevel, x, y, 0, 0, data.getWidth(), data.getHeight()); + } + + /** + * Updates a subregion of the content area of this texture using the + * specified sub-region of the given data. If automatic mipmap + * generation is in use (see {@link #isUsingAutoMipmapGeneration + * isUsingAutoMipmapGeneration}), updates to the base (level 0) + * mipmap will cause the lower-level mipmaps to be regenerated, and + * updates to other mipmap levels will be ignored. Otherwise, if + * automatic mipmap generation is not in use, only updates the + * specified mipmap level and does not re-generate mipmaps if they + * were originally produced or loaded. This method is only supported + * for uncompressed TextureData sources. + * + * @param data the image data to be uploaded to this texture + * @param mipmapLevel the mipmap level of the texture to set. If + * this is non-zero and the TextureData contains mipmap data, the + * appropriate mipmap level will be selected. + * @param dstx the x offset (in pixels) relative to the lower-left corner + * of this texture where the update will be applied + * @param dsty the y offset (in pixels) relative to the lower-left corner + * of this texture where the update will be applied + * @param srcx the x offset (in pixels) relative to the lower-left corner + * of the supplied TextureData from which to fetch the update rectangle + * @param srcy the y offset (in pixels) relative to the lower-left corner + * of the supplied TextureData from which to fetch the update rectangle + * @param width the width (in pixels) of the rectangle to be updated + * @param height the height (in pixels) of the rectangle to be updated + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void updateSubImage(TextureData data, int mipmapLevel, + int dstx, int dsty, + int srcx, int srcy, + int width, int height) throws GLException { + if (data.isDataCompressed()) { + throw new GLException("updateSubImage specifying a sub-rectangle is not supported for compressed TextureData"); + } + if (usingAutoMipmapGeneration && mipmapLevel != 0) { + // When we're using mipmap generation via GL_GENERATE_MIPMAP, we + // don't need to update other mipmap levels + return; + } + bind(); + updateSubImageImpl(data, target, mipmapLevel, dstx, dsty, srcx, srcy, width, height); + } + + /** + * Sets the OpenGL floating-point texture parameter for the + * texture's target. This gives control over parameters such as + * GL_TEXTURE_MAX_ANISOTROPY_EXT. Causes this texture to be bound to + * the current texture state. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void setTexParameterf(int parameterName, + float value) { + bind(); + GL gl = GLContext.getCurrentGL(); + gl.glTexParameterf(target, parameterName, value); + } + + /** + * Sets the OpenGL multi-floating-point texture parameter for the + * texture's target. Causes this texture to be bound to the current + * texture state. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void setTexParameterfv(int parameterName, + FloatBuffer params) { + bind(); + GL gl = GLContext.getCurrentGL(); + gl.glTexParameterfv(target, parameterName, params); + } + + /** + * Sets the OpenGL multi-floating-point texture parameter for the + * texture's target. Causes this texture to be bound to the current + * texture state. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void setTexParameterfv(int parameterName, + float[] params, int params_offset) { + bind(); + GL gl = GLContext.getCurrentGL(); + gl.glTexParameterfv(target, parameterName, params, params_offset); + } + + /** + * Sets the OpenGL integer texture parameter for the texture's + * target. This gives control over parameters such as + * GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T, which by default are set + * to GL_CLAMP_TO_EDGE if OpenGL 1.2 is supported on the current + * platform and GL_CLAMP if not. Causes this texture to be bound to + * the current texture state. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void setTexParameteri(int parameterName, + int value) { + bind(); + GL gl = GLContext.getCurrentGL(); + gl.glTexParameteri(target, parameterName, value); + } + + /** + * Sets the OpenGL multi-integer texture parameter for the texture's + * target. Causes this texture to be bound to the current texture + * state. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void setTexParameteriv(int parameterName, + IntBuffer params) { + bind(); + GL gl = GLContext.getCurrentGL(); + gl.glTexParameteriv(target, parameterName, params); + } + + /** + * Sets the OpenGL multi-integer texture parameter for the texture's + * target. Causes this texture to be bound to the current texture + * state. + * + * @throws GLException if no OpenGL context was current or if any + * OpenGL-related errors occurred + */ + public void setTexParameteriv(int parameterName, + int[] params, int params_offset) { + bind(); + GL gl = GLContext.getCurrentGL(); + gl.glTexParameteriv(target, parameterName, params, params_offset); + } + + /** + * Returns the underlying OpenGL texture object for this texture. + * Most applications will not need to access this, since it is + * handled automatically by the bind() and dispose() APIs. + */ + public int getTextureObject() { + validateTexID(null, false); + return texID; + } + + /** Returns an estimate of the amount of texture memory in bytes + this Texture consumes. It should only be treated as an estimate; + most applications should not need to query this but instead let + the OpenGL implementation page textures in and out as + necessary. */ + public int getEstimatedMemorySize() { + return estimatedMemorySize; + } + + /** Indicates whether this Texture is using automatic mipmap + generation (via the OpenGL texture parameter + GL_GENERATE_MIPMAP). This will automatically be used when + mipmapping is requested via the TextureData and either OpenGL + 1.4 or the GL_SGIS_generate_mipmap extension is available. If + so, updates to the base image (mipmap level 0) will + automatically propagate down to the lower mipmap levels. Manual + updates of the mipmap data at these lower levels will be + ignored. */ + public boolean isUsingAutoMipmapGeneration() { + return usingAutoMipmapGeneration; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + /** + * Returns true if the given value is a power of two. + * + * @return true if the given value is a power of two, false otherwise + */ + private static boolean isPowerOfTwo(int val) { + return ((val & (val - 1)) == 0); + } + + /** + * Returns the nearest power of two that is larger than the given value. + * If the given value is already a power of two, this method will simply + * return that value. + * + * @param val the value + * @return the next power of two + */ + private static int nextPowerOfTwo(int val) { + int ret = 1; + while (ret < val) { + ret <<= 1; + } + return ret; + } + + /** + * Updates the actual image dimensions; usually only called from + * <code>updateImage</code>. + */ + private void setImageSize(int width, int height, int target) { + imgWidth = width; + imgHeight = height; + if (target == GL2.GL_TEXTURE_RECTANGLE_ARB) { + if (mustFlipVertically) { + coords = new TextureCoords(0, imgHeight, imgWidth, 0); + } else { + coords = new TextureCoords(0, 0, imgWidth, imgHeight); + } + } else { + if (mustFlipVertically) { + coords = new TextureCoords(0, (float) imgHeight / (float) texHeight, + (float) imgWidth / (float) texWidth, 0); + } else { + coords = new TextureCoords(0, 0, + (float) imgWidth / (float) texWidth, + (float) imgHeight / (float) texHeight); + } + } + } + + private void updateSubImageImpl(TextureData data, int newTarget, int mipmapLevel, + int dstx, int dsty, + int srcx, int srcy, int width, int height) throws GLException { + GL gl = GLContext.getCurrentGL(); + data.setHaveEXTABGR(gl.isExtensionAvailable("GL_EXT_abgr")); + data.setHaveGL12(gl.isExtensionAvailable("GL_VERSION_1_2")); + + Buffer buffer = data.getBuffer(); + if (buffer == null && data.getMipmapData() == null) { + // Assume user just wanted to get the Texture object allocated + return; + } + + int rowlen = data.getRowLength(); + int dataWidth = data.getWidth(); + int dataHeight = data.getHeight(); + if (data.getMipmapData() != null) { + // Compute the width, height and row length at the specified mipmap level + // Note we do not support specification of the row length for + // mipmapped textures at this point + for (int i = 0; i < mipmapLevel; i++) { + width = Math.max(width / 2, 1); + height = Math.max(height / 2, 1); + + dataWidth = Math.max(dataWidth / 2, 1); + dataHeight = Math.max(dataHeight / 2, 1); + } + rowlen = 0; + buffer = data.getMipmapData()[mipmapLevel]; + } + + // Clip incoming rectangles to what is available both on this + // texture and in the incoming TextureData + if (srcx < 0) { + width += srcx; + srcx = 0; + } + if (srcy < 0) { + height += srcy; + srcy = 0; + } + // NOTE: not sure whether the following two are the correct thing to do + if (dstx < 0) { + width += dstx; + dstx = 0; + } + if (dsty < 0) { + height += dsty; + dsty = 0; + } + + if (srcx + width > dataWidth) { + width = dataWidth - srcx; + } + if (srcy + height > dataHeight) { + height = dataHeight - srcy; + } + if (dstx + width > texWidth) { + width = texWidth - dstx; + } + if (dsty + height > texHeight) { + height = texHeight - dsty; + } + + checkCompressedTextureExtensions(data); + + if (data.isDataCompressed()) { + gl.glCompressedTexSubImage2D(newTarget, mipmapLevel, + dstx, dsty, width, height, + data.getInternalFormat(), + buffer.remaining(), buffer); + } else { + int[] align = { 0 }; + int[] rowLength = { 0 }; + int[] skipRows = { 0 }; + int[] skipPixels = { 0 }; + gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, align, 0); // save alignment + if(gl.isGL2GL3()) { + gl.glGetIntegerv(GL2GL3.GL_UNPACK_ROW_LENGTH, rowLength, 0); // save row length + gl.glGetIntegerv(GL2GL3.GL_UNPACK_SKIP_ROWS, skipRows, 0); // save skipped rows + gl.glGetIntegerv(GL2GL3.GL_UNPACK_SKIP_PIXELS, skipPixels, 0); // save skipped pixels + } + gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, data.getAlignment()); + if (DEBUG && VERBOSE) { + System.out.println("Row length = " + rowlen); + System.out.println("skip pixels = " + srcx); + System.out.println("skip rows = " + srcy); + System.out.println("dstx = " + dstx); + System.out.println("dsty = " + dsty); + System.out.println("width = " + width); + System.out.println("height = " + height); + } + if(gl.isGL2GL3()) { + gl.glPixelStorei(GL2GL3.GL_UNPACK_ROW_LENGTH, rowlen); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_ROWS, srcy); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_PIXELS, srcx); + } else { + if ( rowlen!=0 && rowlen!=width && + srcy!=0 && srcx!=0 ) { + throw new GLException("rowlen and/or x/y offset only available for GL2"); + } + } + + gl.glTexSubImage2D(newTarget, mipmapLevel, + dstx, dsty, width, height, + data.getPixelFormat(), data.getPixelType(), + buffer); + gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, align[0]); // restore alignment + if(gl.isGL2GL3()) { + gl.glPixelStorei(GL2GL3.GL_UNPACK_ROW_LENGTH, rowLength[0]); // restore row length + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_ROWS, skipRows[0]); // restore skipped rows + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_PIXELS, skipPixels[0]); // restore skipped pixels + } + } + } + + private void checkCompressedTextureExtensions(TextureData data) { + GL gl = GLContext.getCurrentGL(); + if (data.isDataCompressed()) { + switch (data.getInternalFormat()) { + case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + if (!gl.isExtensionAvailable("GL_EXT_texture_compression_s3tc") && + !gl.isExtensionAvailable("GL_NV_texture_compression_vtc")) { + throw new GLException("DXTn compressed textures not supported by this graphics card"); + } + break; + default: + // FI1027GXME: should test availability of more texture + // compression extensions here + break; + } + } + } + + private void validateTexID(GL gl, boolean throwException) { + if( 0 < texID ) return; + if(null==gl) { + GLContext ctx = GLContext.getCurrent(); + if(null!=ctx) { + gl = ctx.getGL(); + } else if(throwException) { + throw new GLException("No context current, can't create texture ID"); + } + } + + if(null!=gl) { + int[] tmp = new int[1]; + gl.glGenTextures(1, tmp, 0); + texID = tmp[0]; + } + } + + // Helper routines for disabling certain codepaths + private static boolean haveNPOT(GL gl) { + return (!disableNPOT && + ( gl.isGLES2() || + gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two") ) ); + } + + private static boolean haveTexRect(GL gl) { + return (!disableTexRect && + TextureIO.isTexRectEnabled() && + gl.isExtensionAvailable("GL_ARB_texture_rectangle")); + } + + private static boolean preferTexRect(GL gl) { + // Prefer GL_ARB_texture_rectangle on ATI hardware on Mac OS X + // due to software fallbacks + + if (NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false))) { + String vendor = gl.glGetString(GL.GL_VENDOR); + if (vendor != null && vendor.startsWith("ATI")) { + return true; + } + } + + return false; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java new file mode 100644 index 000000000..8d8b3679d --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.jogamp.opengl.util.texture; + +/** Specifies texture coordinates for a rectangular area of a + texture. Note that some textures are inherently flipped vertically + from OpenGL's standard coordinate system. This class takes care of + this vertical flip so that the "bottom" and "top" coordinates may + sometimes be reversed. From the point of view of code rendering + textured polygons, it can always map the bottom and left texture + coordinates from the TextureCoords to the lower left point of the + textured polygon and achieve correct results. */ + +public class TextureCoords { + // These represent the lower-left point + private float left; + private float bottom; + // These represent the upper-right point + private float right; + private float top; + + public TextureCoords(float left, float bottom, + float right, float top) { + this.left = left; + this.bottom = bottom; + this.right = right; + this.top = top; + } + + /** Returns the leftmost (x) texture coordinate of this + rectangle. */ + public float left() { return left; } + + /** Returns the rightmost (x) texture coordinate of this + rectangle. */ + public float right() { return right; } + + /** Returns the bottommost (y) texture coordinate of this + rectangle. */ + public float bottom() { return bottom; } + + /** Returns the topmost (y) texture coordinate of this + rectangle. */ + public float top() { return top; } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java new file mode 100644 index 000000000..f598422bf --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.jogamp.opengl.util.texture; + +import java.nio.*; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; + +/** + * Represents the data for an OpenGL texture. This is separated from + * the notion of a Texture to support things like streaming in of + * textures in a background thread without requiring an OpenGL context + * to be current on that thread. + * + * @author Chris Campbell + * @author Kenneth Russell + * @author Sven Gothel + */ + +public class TextureData { + protected int width; + protected int height; + private int border; + protected int pixelFormat; + protected int pixelType; + protected int internalFormat; // perhaps inferred from pixelFormat? + protected boolean mipmap; // indicates whether mipmaps should be generated + // (ignored if mipmaps are supplied from the file) + private boolean dataIsCompressed; + protected boolean mustFlipVertically; // Must flip texture coordinates + // vertically to get OpenGL output + // to look correct + protected Buffer buffer; // the actual data... + private Buffer[] mipmapData; // ...or a series of mipmaps + private Flusher flusher; + protected int rowLength; + protected int alignment; // 1, 2, or 4 bytes + protected int estimatedMemorySize; + + // These booleans are a concession to the AWTTextureData subclass + protected boolean haveEXTABGR; + protected boolean haveGL12; + protected GLProfile glProfile; + + /** + * Constructs a new TextureData object with the specified parameters + * and data contained in the given Buffer. The optional Flusher can + * be used to clean up native resources associated with this + * TextureData when processing is complete; for example, closing of + * memory-mapped files that might otherwise require a garbage + * collection to reclaim and close. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param internalFormat the OpenGL internal format for the + * resulting texture; must be specified, may + * not be 0 + * @param width the width in pixels of the texture + * @param height the height in pixels of the texture + * @param border the number of pixels of border this texture + * data has (0 or 1) + * @param pixelFormat the OpenGL pixel format for the + * resulting texture; must be specified, may + * not be 0 + * @param pixelType the OpenGL type of the pixels of the texture + * @param mipmap indicates whether mipmaps should be + * autogenerated (using GLU) for the resulting + * texture. Currently if mipmap is true then + * dataIsCompressed may not be true. + * @param dataIsCompressed indicates whether the texture data is in + * compressed form + * (e.g. GL_COMPRESSED_RGB_S3TC_DXT1_EXT) + * @param mustFlipVertically indicates whether the texture + * coordinates must be flipped vertically + * in order to properly display the + * texture + * @param buffer the buffer containing the texture data + * @param flusher optional flusher to perform cleanup tasks + * upon call to flush() + * + * @throws IllegalArgumentException if any parameters of the texture + * data were invalid, such as requesting mipmap generation for a + * compressed texture + */ + public TextureData(GLProfile glp, + int internalFormat, + int width, + int height, + int border, + int pixelFormat, + int pixelType, + boolean mipmap, + boolean dataIsCompressed, + boolean mustFlipVertically, + Buffer buffer, + Flusher flusher) throws IllegalArgumentException { + if (mipmap && dataIsCompressed) { + throw new IllegalArgumentException("Can not generate mipmaps for compressed textures"); + } + + this.glProfile = glp; + this.width = width; + this.height = height; + this.border = border; + this.pixelFormat = pixelFormat; + this.pixelType = pixelType; + this.internalFormat = internalFormat; + this.mipmap = mipmap; + this.dataIsCompressed = dataIsCompressed; + this.mustFlipVertically = mustFlipVertically; + this.buffer = buffer; + this.flusher = flusher; + alignment = 1; // FIXME: is this correct enough in all situations? + estimatedMemorySize = estimatedMemorySize(buffer); + } + + /** + * Constructs a new TextureData object with the specified parameters + * and data for multiple mipmap levels contained in the given array + * of Buffers. The optional Flusher can be used to clean up native + * resources associated with this TextureData when processing is + * complete; for example, closing of memory-mapped files that might + * otherwise require a garbage collection to reclaim and close. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param internalFormat the OpenGL internal format for the + * resulting texture; must be specified, may + * not be 0 + * @param width the width in pixels of the topmost mipmap + * level of the texture + * @param height the height in pixels of the topmost mipmap + * level of the texture + * @param border the number of pixels of border this texture + * data has (0 or 1) + * @param pixelFormat the OpenGL pixel format for the + * resulting texture; must be specified, may + * not be 0 + * @param pixelType the OpenGL type of the pixels of the texture + * @param dataIsCompressed indicates whether the texture data is in + * compressed form + * (e.g. GL_COMPRESSED_RGB_S3TC_DXT1_EXT) + * @param mustFlipVertically indicates whether the texture + * coordinates must be flipped vertically + * in order to properly display the + * texture + * @param mipmapData the buffers containing all mipmap levels + * of the texture's data + * @param flusher optional flusher to perform cleanup tasks + * upon call to flush() + * + * @throws IllegalArgumentException if any parameters of the texture + * data were invalid, such as requesting mipmap generation for a + * compressed texture + */ + public TextureData(GLProfile glp, + int internalFormat, + int width, + int height, + int border, + int pixelFormat, + int pixelType, + boolean dataIsCompressed, + boolean mustFlipVertically, + Buffer[] mipmapData, + Flusher flusher) throws IllegalArgumentException { + this.glProfile = glp; + this.width = width; + this.height = height; + this.border = border; + this.pixelFormat = pixelFormat; + this.pixelType = pixelType; + this.internalFormat = internalFormat; + this.dataIsCompressed = dataIsCompressed; + this.mustFlipVertically = mustFlipVertically; + this.mipmapData = (Buffer[]) mipmapData.clone(); + this.flusher = flusher; + alignment = 1; // FIXME: is this correct enough in all situations? + for (int i = 0; i < mipmapData.length; i++) { + estimatedMemorySize += estimatedMemorySize(mipmapData[i]); + } + } + + /** Used only by subclasses */ + protected TextureData(GLProfile glp) { this.glProfile = glp; } + + /** Returns the width in pixels of the texture data. */ + public int getWidth() { return width; } + /** Returns the height in pixels of the texture data. */ + public int getHeight() { return height; } + /** Returns the border in pixels of the texture data. */ + public int getBorder() { + return border; + } + /** Returns the intended OpenGL pixel format of the texture data. */ + public int getPixelFormat() { + return pixelFormat; + } + /** Returns the intended OpenGL pixel type of the texture data. */ + public int getPixelType() { + return pixelType; + } + /** Returns the intended OpenGL internal format of the texture data. */ + public int getInternalFormat() { + return internalFormat; + } + /** Returns whether mipmaps should be generated for the texture data. */ + public boolean getMipmap() { + return mipmap; + } + /** Indicates whether the texture data is in compressed form. */ + public boolean isDataCompressed() { + return dataIsCompressed; + } + /** Indicates whether the texture coordinates must be flipped + vertically for proper display. */ + public boolean getMustFlipVertically() { + return mustFlipVertically; + } + /** Returns the texture data, or null if it is specified as a set of mipmaps. */ + public Buffer getBuffer() { + return buffer; + } + /** Returns all mipmap levels for the texture data, or null if it is + specified as a single image. */ + public Buffer[] getMipmapData() { + return mipmapData; + } + /** Returns the required byte alignment for the texture data. */ + public int getAlignment() { + return alignment; + } + /** Returns the row length needed for correct GL_UNPACK_ROW_LENGTH + specification. This is currently only supported for + non-mipmapped, non-compressed textures. */ + public int getRowLength() { + return rowLength; + } + + /** Sets the width in pixels of the texture data. */ + public void setWidth(int width) { this.width = width; } + /** Sets the height in pixels of the texture data. */ + public void setHeight(int height) { this.height = height; } + /** Sets the border in pixels of the texture data. */ + public void setBorder(int border) { this.border = border; } + /** Sets the intended OpenGL pixel format of the texture data. */ + public void setPixelFormat(int pixelFormat) { this.pixelFormat = pixelFormat; } + /** Sets the intended OpenGL pixel type of the texture data. */ + public void setPixelType(int pixelType) { this.pixelType = pixelType; } + /** Sets the intended OpenGL internal format of the texture data. */ + public void setInternalFormat(int internalFormat) { this.internalFormat = internalFormat; } + /** Sets whether mipmaps should be generated for the texture data. */ + public void setMipmap(boolean mipmap) { this.mipmap = mipmap; } + /** Sets whether the texture data is in compressed form. */ + public void setIsDataCompressed(boolean compressed) { this.dataIsCompressed = compressed; } + /** Sets whether the texture coordinates must be flipped vertically + for proper display. */ + public void setMustFlipVertically(boolean mustFlipVertically) { this.mustFlipVertically = mustFlipVertically; } + /** Sets the texture data. */ + public void setBuffer(Buffer buffer) { + this.buffer = buffer; + estimatedMemorySize = estimatedMemorySize(buffer); + } + /** Sets the required byte alignment for the texture data. */ + public void setAlignment(int alignment) { this.alignment = alignment; } + /** Sets the row length needed for correct GL_UNPACK_ROW_LENGTH + specification. This is currently only supported for + non-mipmapped, non-compressed textures. */ + public void setRowLength(int rowLength) { this.rowLength = rowLength; } + /** Indicates to this TextureData whether the GL_EXT_abgr extension + is available. Used for optimization along some code paths to + avoid data copies. */ + public void setHaveEXTABGR(boolean haveEXTABGR) { + this.haveEXTABGR = haveEXTABGR; + } + /** Indicates to this TextureData whether OpenGL version 1.2 is + available. If not, falls back to relatively inefficient code + paths for several input data types (several kinds of packed + pixel formats, in particular). */ + public void setHaveGL12(boolean haveGL12) { + this.haveGL12 = haveGL12; + } + + /** Returns the GLProfile this texture data is intended and created for. */ + public GLProfile getGLProfile() { return glProfile; } + + /** Returns an estimate of the amount of memory in bytes this + TextureData will consume once uploaded to the graphics card. It + should only be treated as an estimate; most applications should + not need to query this but instead let the OpenGL implementation + page textures in and out as necessary. */ + public int getEstimatedMemorySize() { + return estimatedMemorySize; + } + + /** Flushes resources associated with this TextureData by calling + Flusher.flush(). */ + public void flush() { + if (flusher != null) { + flusher.flush(); + flusher = null; + } + } + + /** Calls flush() + * @see #flush() + */ + public void destroy() { + flush(); + } + + /** Defines a callback mechanism to allow the user to explicitly + deallocate native resources (memory-mapped files, etc.) + associated with a particular TextureData. */ + public static interface Flusher { + /** Flushes any native resources associated with this + TextureData. */ + public void flush(); + } + + public String toString() { + return "TextureData["+width+"x"+height+", internFormat "+internalFormat+", pixelFormat "+pixelFormat+", pixelType "+pixelType+", border "+border+", estSize "+estimatedMemorySize+", alignment "+alignment+", rowlen "+rowLength; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + protected static int estimatedMemorySize(Buffer buffer) { + if (buffer == null) { + return 0; + } + return buffer.capacity() * GLBuffers.sizeOfBufferElem(buffer); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java new file mode 100644 index 000000000..e86ff161b --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java @@ -0,0 +1,1258 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture; + +import java.io.*; +import java.net.*; +import java.nio.*; +import java.util.*; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import jogamp.opengl.Debug; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.texture.spi.*; + +/** <P> Provides input and output facilities for both loading OpenGL + textures from disk and streams as well as writing textures already + in memory back to disk. </P> + + <P> The TextureIO class supports an arbitrary number of plug-in + readers and writers via TextureProviders and TextureWriters. + TextureProviders know how to produce TextureData objects from + files, InputStreams and URLs. TextureWriters know how to write + TextureData objects to disk in various file formats. The + TextureData class represents the raw data of the texture before it + has been converted to an OpenGL texture object. The Texture class + represents the OpenGL texture object and provides easy facilities + for using the texture. </P> + + <P> There are several built-in TextureProviders and TextureWriters + supplied with the TextureIO implementation. The most basic + provider uses the platform's Image I/O facilities to read in a + BufferedImage and convert it to a texture. This is the baseline + provider and is registered so that it is the last one consulted. + All others are asked first to open a given file. </P> + + <P> There are three other providers registered by default as of + the time of this writing. One handles SGI RGB (".sgi", ".rgb") + images from both files and streams. One handles DirectDraw Surface + (".dds") images read from files, though can not read these images + from streams. One handles Targa (".tga") images read from both + files and streams. These providers are executed in an arbitrary + order. Some of these providers require the file's suffix to either + be specified via the newTextureData methods or for the file to be + named with the appropriate suffix. In general a file suffix should + be provided to the newTexture and newTextureData methods if at all + possible. </P> + + <P> Note that additional TextureProviders, if reading images from + InputStreams, must use the mark()/reset() methods on InputStream + when probing for e.g. magic numbers at the head of the file to + make sure not to disturb the state of the InputStream for + downstream TextureProviders. </P> + + <P> There are analogous TextureWriters provided for writing + textures back to disk if desired. As of this writing, there are + four TextureWriters registered by default: one for Targa files, + one for SGI RGB files, one for DirectDraw surface (.dds) files, + and one for ImageIO-supplied formats such as .jpg and .png. Some + of these writers have certain limitations such as only being able + to write out textures stored in GL_RGB or GL_RGBA format. The DDS + writer supports fetching and writing to disk of texture data in + DXTn compressed format. Whether this will occur is dependent on + whether the texture's internal format is one of the DXTn + compressed formats and whether the target file is .dds format. +*/ + +public class TextureIO { + /** Constant which can be used as a file suffix to indicate a + DirectDraw Surface file. */ + public static final String DDS = "dds"; + + /** Constant which can be used as a file suffix to indicate an SGI + RGB file. */ + public static final String SGI = "sgi"; + + /** Constant which can be used as a file suffix to indicate an SGI + RGB file. */ + public static final String SGI_RGB = "rgb"; + + /** Constant which can be used as a file suffix to indicate a GIF + file. */ + public static final String GIF = "gif"; + + /** Constant which can be used as a file suffix to indicate a JPEG + file. */ + public static final String JPG = "jpg"; + + /** Constant which can be used as a file suffix to indicate a PNG + file. */ + public static final String PNG = "png"; + + /** Constant which can be used as a file suffix to indicate a Targa + file. */ + public static final String TGA = "tga"; + + /** Constant which can be used as a file suffix to indicate a TIFF + file. */ + public static final String TIFF = "tiff"; + + private static final boolean DEBUG = Debug.debug("TextureIO"); + + // For manually disabling the use of the texture rectangle + // extensions so you know the texture target is GL_TEXTURE_2D; this + // is useful for shader writers (thanks to Chris Campbell for this + // observation) + private static boolean texRectEnabled = true; + + //---------------------------------------------------------------------- + // methods that *do not* require a current context + // These methods assume RGB or RGBA textures. + // Some texture providers may not recognize the file format unless + // the fileSuffix is specified, so it is strongly recommended to + // specify it wherever it is known. + // Some texture providers may also only support one kind of input, + // i.e., reading from a file as opposed to a stream. + + /** + * Creates a TextureData from the given file. Does no OpenGL work. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param file the file from which to read the texture data + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @param fileSuffix the suffix of the file name to be used as a + * hint of the file format to the underlying + * texture provider, or null if none and should be + * auto-detected (some texture providers do not + * support this) + * @return the texture data from the file, or null if none of the + * registered texture providers could read the file + * @throws IOException if an error occurred while reading the file + */ + public static TextureData newTextureData(GLProfile glp, File file, + boolean mipmap, + String fileSuffix) throws IOException { + if (fileSuffix == null) { + fileSuffix = FileUtil.getFileSuffix(file); + } + return newTextureDataImpl(glp, file, 0, 0, mipmap, fileSuffix); + } + + /** + * Creates a TextureData from the given stream. Does no OpenGL work. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param stream the stream from which to read the texture data + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @param fileSuffix the suffix of the file name to be used as a + * hint of the file format to the underlying + * texture provider, or null if none and should be + * auto-detected (some texture providers do not + * support this) + * @return the texture data from the stream, or null if none of the + * registered texture providers could read the stream + * @throws IOException if an error occurred while reading the stream + */ + public static TextureData newTextureData(GLProfile glp, InputStream stream, + boolean mipmap, + String fileSuffix) throws IOException { + return newTextureDataImpl(glp, stream, 0, 0, mipmap, fileSuffix); + } + + /** + * Creates a TextureData from the given URL. Does no OpenGL work. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param url the URL from which to read the texture data + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @param fileSuffix the suffix of the file name to be used as a + * hint of the file format to the underlying + * texture provider, or null if none and should be + * auto-detected (some texture providers do not + * support this) + * @return the texture data from the URL, or null if none of the + * registered texture providers could read the URL + * @throws IOException if an error occurred while reading the URL + */ + public static TextureData newTextureData(GLProfile glp, URL url, + boolean mipmap, + String fileSuffix) throws IOException { + if (fileSuffix == null) { + fileSuffix = FileUtil.getFileSuffix(url.getPath()); + } + return newTextureDataImpl(glp, url, 0, 0, mipmap, fileSuffix); + } + + //---------------------------------------------------------------------- + // These methods make no assumption about the OpenGL internal format + // or pixel format of the texture; they must be specified by the + // user. It is not allowed to supply 0 (indicating no preference) + // for either the internalFormat or the pixelFormat; + // IllegalArgumentException will be thrown in this case. + + /** + * Creates a TextureData from the given file, using the specified + * OpenGL internal format and pixel format for the texture which + * will eventually result. The internalFormat and pixelFormat must + * be specified and may not be zero; to use default values, use the + * variant of this method which does not take these arguments. Does + * no OpenGL work. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param file the file from which to read the texture data + * @param internalFormat the OpenGL internal format of the texture + * which will eventually result from the TextureData + * @param pixelFormat the OpenGL pixel format of the texture + * which will eventually result from the TextureData + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @param fileSuffix the suffix of the file name to be used as a + * hint of the file format to the underlying + * texture provider, or null if none and should be + * auto-detected (some texture providers do not + * support this) + * @return the texture data from the file, or null if none of the + * registered texture providers could read the file + * @throws IllegalArgumentException if either internalFormat or + * pixelFormat was 0 + * @throws IOException if an error occurred while reading the file + */ + public static TextureData newTextureData(GLProfile glp, File file, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException, IllegalArgumentException { + if ((internalFormat == 0) || (pixelFormat == 0)) { + throw new IllegalArgumentException("internalFormat and pixelFormat must be non-zero"); + } + + if (fileSuffix == null) { + fileSuffix = FileUtil.getFileSuffix(file); + } + + return newTextureDataImpl(glp, file, internalFormat, pixelFormat, mipmap, fileSuffix); + } + + /** + * Creates a TextureData from the given stream, using the specified + * OpenGL internal format and pixel format for the texture which + * will eventually result. The internalFormat and pixelFormat must + * be specified and may not be zero; to use default values, use the + * variant of this method which does not take these arguments. Does + * no OpenGL work. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param stream the stream from which to read the texture data + * @param internalFormat the OpenGL internal format of the texture + * which will eventually result from the TextureData + * @param pixelFormat the OpenGL pixel format of the texture + * which will eventually result from the TextureData + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @param fileSuffix the suffix of the file name to be used as a + * hint of the file format to the underlying + * texture provider, or null if none and should be + * auto-detected (some texture providers do not + * support this) + * @return the texture data from the stream, or null if none of the + * registered texture providers could read the stream + * @throws IllegalArgumentException if either internalFormat or + * pixelFormat was 0 + * @throws IOException if an error occurred while reading the stream + */ + public static TextureData newTextureData(GLProfile glp, InputStream stream, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException, IllegalArgumentException { + if ((internalFormat == 0) || (pixelFormat == 0)) { + throw new IllegalArgumentException("internalFormat and pixelFormat must be non-zero"); + } + + return newTextureDataImpl(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix); + } + + /** + * Creates a TextureData from the given URL, using the specified + * OpenGL internal format and pixel format for the texture which + * will eventually result. The internalFormat and pixelFormat must + * be specified and may not be zero; to use default values, use the + * variant of this method which does not take these arguments. Does + * no OpenGL work. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param url the URL from which to read the texture data + * @param internalFormat the OpenGL internal format of the texture + * which will eventually result from the TextureData + * @param pixelFormat the OpenGL pixel format of the texture + * which will eventually result from the TextureData + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @param fileSuffix the suffix of the file name to be used as a + * hint of the file format to the underlying + * texture provider, or null if none and should be + * auto-detected (some texture providers do not + * support this) + * @return the texture data from the URL, or null if none of the + * registered texture providers could read the URL + * @throws IllegalArgumentException if either internalFormat or + * pixelFormat was 0 + * @throws IOException if an error occurred while reading the URL + */ + public static TextureData newTextureData(GLProfile glp, URL url, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException, IllegalArgumentException { + if ((internalFormat == 0) || (pixelFormat == 0)) { + throw new IllegalArgumentException("internalFormat and pixelFormat must be non-zero"); + } + + if (fileSuffix == null) { + fileSuffix = FileUtil.getFileSuffix(url.getPath()); + } + + return newTextureDataImpl(glp, url, internalFormat, pixelFormat, mipmap, fileSuffix); + } + + //---------------------------------------------------------------------- + // methods that *do* require a current context + // + + /** + * Creates an OpenGL texture object from the specified TextureData + * using the current OpenGL context. + * + * @param data the texture data to turn into an OpenGL texture + * @throws GLException if no OpenGL context is current or if an + * OpenGL error occurred + * @throws IllegalArgumentException if the passed TextureData was null + */ + public static Texture newTexture(TextureData data) throws GLException, IllegalArgumentException { + if (data == null) { + throw new IllegalArgumentException("Null TextureData"); + } + return new Texture(data); + } + + /** + * Creates an OpenGL texture object from the specified file using + * the current OpenGL context. + * + * @param file the file from which to read the texture data + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @throws IOException if an error occurred while reading the file + * @throws GLException if no OpenGL context is current or if an + * OpenGL error occurred + */ + public static Texture newTexture(File file, boolean mipmap) throws IOException, GLException { + GLProfile glp = GLContext.getCurrentGL().getGLProfile(); + TextureData data = newTextureData(glp, file, mipmap, FileUtil.getFileSuffix(file)); + Texture texture = newTexture(data); + data.flush(); + return texture; + } + + /** + * Creates an OpenGL texture object from the specified stream using + * the current OpenGL context. + * + * @param stream the stream from which to read the texture data + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @param fileSuffix the suffix of the file name to be used as a + * hint of the file format to the underlying + * texture provider, or null if none and should be + * auto-detected (some texture providers do not + * support this) + * @throws IOException if an error occurred while reading the stream + * @throws GLException if no OpenGL context is current or if an + * OpenGL error occurred + */ + public static Texture newTexture(InputStream stream, boolean mipmap, String fileSuffix) throws IOException, GLException { + GLProfile glp = GLContext.getCurrentGL().getGLProfile(); + TextureData data = newTextureData(glp, stream, mipmap, fileSuffix); + Texture texture = newTexture(data); + data.flush(); + return texture; + } + + /** + * Creates an OpenGL texture object from the specified URL using the + * current OpenGL context. + * + * @param url the URL from which to read the texture data + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @param fileSuffix the suffix of the file name to be used as a + * hint of the file format to the underlying + * texture provider, or null if none and should be + * auto-detected (some texture providers do not + * support this) + * @throws IOException if an error occurred while reading the URL + * @throws GLException if no OpenGL context is current or if an + * OpenGL error occurred + */ + public static Texture newTexture(URL url, boolean mipmap, String fileSuffix) throws IOException, GLException { + if (fileSuffix == null) { + fileSuffix = FileUtil.getFileSuffix(url.getPath()); + } + GLProfile glp = GLContext.getCurrentGL().getGLProfile(); + TextureData data = newTextureData(glp, url, mipmap, fileSuffix); + Texture texture = newTexture(data); + data.flush(); + return texture; + } + + /** + * Creates an OpenGL texture object associated with the given OpenGL + * texture target using the current OpenGL context. The texture has + * no initial data. This is used, for example, to construct cube + * maps out of multiple TextureData objects. + * + * @param target the OpenGL target type, eg GL.GL_TEXTURE_2D, + * GL.GL_TEXTURE_RECTANGLE_ARB + * + * @throws GLException if no OpenGL context is current or if an + * OpenGL error occurred + */ + public static Texture newTexture(int target) throws GLException { + return new Texture(target); + } + + /** + * Wraps an OpenGL texture ID from an external library and allows + * some of the base methods from the Texture class, such as + * binding and querying of texture coordinates, to be used with + * it. Attempts to update such textures' contents will yield + * undefined results. + * + * @param textureID the OpenGL texture object to wrap + * @param target the OpenGL texture target, eg GL.GL_TEXTURE_2D, + * GL2.GL_TEXTURE_RECTANGLE + * @param texWidth the width of the texture in pixels + * @param texHeight the height of the texture in pixels + * @param imgWidth the width of the image within the texture in + * pixels (if the content is a sub-rectangle in the upper + * left corner); otherwise, pass in texWidth + * @param imgHeight the height of the image within the texture in + * pixels (if the content is a sub-rectangle in the upper + * left corner); otherwise, pass in texHeight + * @param mustFlipVertically indicates whether the texture + * coordinates must be flipped vertically + * in order to properly display the + * texture + */ + public static Texture newTexture(int textureID, + int target, + int texWidth, + int texHeight, + int imgWidth, + int imgHeight, + boolean mustFlipVertically) { + return new Texture(textureID, + target, + texWidth, + texHeight, + imgWidth, + imgHeight, + mustFlipVertically); + } + + /** + * Writes the given texture to a file. The type of the file is + * inferred from its suffix. An OpenGL context must be current in + * order to fetch the texture data back from the OpenGL pipeline. + * This method causes the specified Texture to be bound to the + * GL_TEXTURE_2D state. If no suitable writer for the requested file + * format was found, throws an IOException. <P> + * + * Reasonable attempts are made to produce good results in the + * resulting images. The Targa, SGI and ImageIO writers produce + * results in the correct vertical orientation for those file + * formats. The DDS writer performs no vertical flip of the data, + * even in uncompressed mode. (It is impossible to perform such a + * vertical flip with compressed data.) Applications should keep + * this in mind when using this routine to save textures to disk for + * later re-loading. <P> + * + * Any mipmaps for the specified texture are currently discarded + * when it is written to disk, regardless of whether the underlying + * file format supports multiple mipmaps in a given file. + * + * @throws IOException if an error occurred during writing or no + * suitable writer was found + * @throws GLException if no OpenGL context was current or an + * OpenGL-related error occurred + */ + public static void write(Texture texture, File file) throws IOException, GLException { + if (texture.getTarget() != GL.GL_TEXTURE_2D) { + throw new GLException("Only GL_TEXTURE_2D textures are supported"); + } + + // First fetch the texture data + GL _gl = GLContext.getCurrentGL(); + if (!_gl.isGL2()) { + throw new GLException("Only GL2 supports fetching compressed images, GL: " + _gl); + } + GL2 gl = _gl.getGL2(); + + texture.bind(); + int internalFormat = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_INTERNAL_FORMAT); + int width = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_WIDTH); + int height = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_HEIGHT); + int border = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_BORDER); + TextureData data = null; + if (internalFormat == GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT || + internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT || + internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT || + internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) { + // Fetch using glGetCompressedTexImage + int size = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_COMPRESSED_IMAGE_SIZE); + ByteBuffer res = ByteBuffer.allocate(size); + gl.glGetCompressedTexImage(GL.GL_TEXTURE_2D, 0, res); + data = new TextureData(gl.getGLProfile(), internalFormat, width, height, border, internalFormat, GL.GL_UNSIGNED_BYTE, + false, true, true, res, null); + } else { + int bytesPerPixel = 0; + int fetchedFormat = 0; + switch (internalFormat) { + case GL.GL_RGB: + case GL2.GL_BGR: + case GL.GL_RGB8: + bytesPerPixel = 3; + fetchedFormat = GL.GL_RGB; + break; + case GL.GL_RGBA: + case GL2.GL_BGRA: + case GL2.GL_ABGR_EXT: + case GL.GL_RGBA8: + bytesPerPixel = 4; + fetchedFormat = GL.GL_RGBA; + break; + default: + throw new IOException("Unsupported texture internal format 0x" + Integer.toHexString(internalFormat)); + } + + // Fetch using glGetTexImage + int packAlignment = glGetInteger(GL.GL_PACK_ALIGNMENT); + int packRowLength = glGetInteger(GL2.GL_PACK_ROW_LENGTH); + int packSkipRows = glGetInteger(GL2.GL_PACK_SKIP_ROWS); + int packSkipPixels = glGetInteger(GL2.GL_PACK_SKIP_PIXELS); + int packSwapBytes = glGetInteger(GL2.GL_PACK_SWAP_BYTES); + + gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1); + gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, 0); + gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, 0); + gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, 0); + gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, 0); + + ByteBuffer res = ByteBuffer.allocate((width + (2 * border)) * + (height + (2 * border)) * + bytesPerPixel); + if (DEBUG) { + System.out.println("Allocated buffer of size " + res.remaining() + " for fetched image (" + + ((fetchedFormat == GL.GL_RGB) ? "GL_RGB" : "GL_RGBA") + ")"); + } + gl.glGetTexImage(GL.GL_TEXTURE_2D, 0, fetchedFormat, GL.GL_UNSIGNED_BYTE, res); + + gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, packAlignment); + gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, packRowLength); + gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, packSkipRows); + gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, packSkipPixels); + gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, packSwapBytes); + + data = new TextureData(gl.getGLProfile(), internalFormat, width, height, border, fetchedFormat, GL.GL_UNSIGNED_BYTE, + false, false, false, res, null); + + if (DEBUG) { + System.out.println("data.getPixelFormat() = " + + ((data.getPixelFormat() == GL.GL_RGB) ? "GL_RGB" : "GL_RGBA")); + } + } + + write(data, file); + } + + public static void write(TextureData data, File file) throws IOException, GLException { + for (Iterator iter = textureWriters.iterator(); iter.hasNext(); ) { + TextureWriter writer = (TextureWriter) iter.next(); + if (writer.write(file, data)) { + return; + } + } + + throw new IOException("No suitable texture writer found for "+file.getAbsolutePath()); + } + + //---------------------------------------------------------------------- + // SPI support + // + + /** Adds a TextureProvider to support reading of a new file + format. */ + public static void addTextureProvider(TextureProvider provider) { + // Must always add at the front so the ImageIO provider is last, + // so we don't accidentally use it instead of a user's possibly + // more optimal provider + textureProviders.add(0, provider); + } + + /** Adds a TextureWriter to support writing of a new file + format. */ + public static void addTextureWriter(TextureWriter writer) { + // Must always add at the front so the ImageIO writer is last, + // so we don't accidentally use it instead of a user's possibly + // more optimal writer + textureWriters.add(0, writer); + } + + //--------------------------------------------------------------------------- + // Global disabling of texture rectangle extension + // + + /** Toggles the use of the GL_ARB_texture_rectangle extension by the + TextureIO classes. By default, on hardware supporting this + extension, the TextureIO classes may use the + GL_ARB_texture_rectangle extension for non-power-of-two + textures. (If the hardware supports the + GL_ARB_texture_non_power_of_two extension, that one is + preferred.) In some situations, for example when writing + shaders, it is advantageous to force the texture target to + always be GL_TEXTURE_2D in order to have one version of the + shader, even at the expense of texture memory in the case where + NPOT textures are not supported. This method allows the use of + the GL_ARB_texture_rectangle extension to be turned off globally + for this purpose. The default is that the use of the extension + is enabled. */ + public static void setTexRectEnabled(boolean enabled) { + texRectEnabled = enabled; + } + + /** Indicates whether the GL_ARB_texture_rectangle extension is + allowed to be used for non-power-of-two textures; see {@link + #setTexRectEnabled setTexRectEnabled}. */ + public static boolean isTexRectEnabled() { + return texRectEnabled; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private static List/*<TextureProvider>*/ textureProviders = new ArrayList/*<TextureProvider>*/(); + private static List/*<TextureWriter>*/ textureWriters = new ArrayList/*<TextureWriter>*/(); + + static { + // ImageIO provider, the fall-back, must be the first one added + if(GLProfile.isAWTAvailable()) { + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureProvider provider = (TextureProvider) + Class.forName("com.jogamp.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); + addTextureProvider(provider); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } + } + } + + // Other special-case providers + addTextureProvider(new DDSTextureProvider()); + addTextureProvider(new SGITextureProvider()); + addTextureProvider(new TGATextureProvider()); + + // ImageIO writer, the fall-back, must be the first one added + if(GLProfile.isAWTAvailable()) { + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureWriter writer = (TextureWriter) + Class.forName("com.jogamp.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); + addTextureWriter(writer); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } + } catch (Error e) { + if (DEBUG) { + e.printStackTrace(); + } + } + } + + // Other special-case writers + addTextureWriter(new DDSTextureWriter()); + addTextureWriter(new SGITextureWriter()); + addTextureWriter(new TGATextureWriter()); + addTextureWriter(new NetPbmTextureWriter()); + } + + // Implementation methods + private static TextureData newTextureDataImpl(GLProfile glp, File file, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + if (file == null) { + throw new IOException("File was null"); + } + + fileSuffix = toLowerCase(fileSuffix); + + for (Iterator iter = textureProviders.iterator(); iter.hasNext(); ) { + TextureProvider provider = (TextureProvider) iter.next(); + TextureData data = provider.newTextureData(glp, file, + internalFormat, + pixelFormat, + mipmap, + fileSuffix); + if (data != null) { + return data; + } + } + + throw new IOException("No suitable reader for given file "+file.getAbsolutePath()); + } + + private static TextureData newTextureDataImpl(GLProfile glp, InputStream stream, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + if (stream == null) { + throw new IOException("Stream was null"); + } + + fileSuffix = toLowerCase(fileSuffix); + + // Note: use of BufferedInputStream works around 4764639/4892246 + if (!(stream instanceof BufferedInputStream)) { + stream = new BufferedInputStream(stream); + } + + for (Iterator iter = textureProviders.iterator(); iter.hasNext(); ) { + TextureProvider provider = (TextureProvider) iter.next(); + TextureData data = provider.newTextureData(glp, stream, + internalFormat, + pixelFormat, + mipmap, + fileSuffix); + if (data != null) { + return data; + } + } + + throw new IOException("No suitable reader for given stream"); + } + + private static TextureData newTextureDataImpl(GLProfile glp, URL url, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + if (url == null) { + throw new IOException("URL was null"); + } + + fileSuffix = toLowerCase(fileSuffix); + + for (Iterator iter = textureProviders.iterator(); iter.hasNext(); ) { + TextureProvider provider = (TextureProvider) iter.next(); + TextureData data = provider.newTextureData(glp, url, + internalFormat, + pixelFormat, + mipmap, + fileSuffix); + if (data != null) { + return data; + } + } + + throw new IOException("No suitable reader for given URL "+url); + } + + //---------------------------------------------------------------------- + // DDS provider -- supports files only for now + static class DDSTextureProvider implements TextureProvider { + public TextureData newTextureData(GLProfile glp, File file, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + if (DDS.equals(fileSuffix) || + DDS.equals(FileUtil.getFileSuffix(file))) { + DDSImage image = DDSImage.read(file); + return newTextureData(glp, image, internalFormat, pixelFormat, mipmap); + } + + return null; + } + + public TextureData newTextureData(GLProfile glp, InputStream stream, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + if (DDS.equals(fileSuffix) || + DDSImage.isDDSImage(stream)) { + byte[] data = StreamUtil.readAll2Array(stream); + ByteBuffer buf = ByteBuffer.wrap(data); + DDSImage image = DDSImage.read(buf); + return newTextureData(glp, image, internalFormat, pixelFormat, mipmap); + } + + return null; + } + + public TextureData newTextureData(GLProfile glp, URL url, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + InputStream stream = new BufferedInputStream(url.openStream()); + try { + return newTextureData(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix); + } finally { + stream.close(); + } + } + + private TextureData newTextureData(GLProfile glp, final DDSImage image, + int internalFormat, + int pixelFormat, + boolean mipmap) { + DDSImage.ImageInfo info = image.getMipMap(0); + if (pixelFormat == 0) { + switch (image.getPixelFormat()) { + case DDSImage.D3DFMT_R8G8B8: + pixelFormat = GL.GL_RGB; + break; + default: + pixelFormat = GL.GL_RGBA; + break; + } + } + if (info.isCompressed()) { + switch (info.getCompressionFormat()) { + case DDSImage.D3DFMT_DXT1: + internalFormat = GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT; + break; + case DDSImage.D3DFMT_DXT3: + internalFormat = GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + break; + case DDSImage.D3DFMT_DXT5: + internalFormat = GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + break; + default: + throw new RuntimeException("Unsupported DDS compression format \"" + + DDSImage.getCompressionFormatName(info.getCompressionFormat()) + "\""); + } + } + if (internalFormat == 0) { + switch (image.getPixelFormat()) { + case DDSImage.D3DFMT_R8G8B8: + pixelFormat = GL.GL_RGB; + break; + default: + pixelFormat = GL.GL_RGBA; + break; + } + } + TextureData.Flusher flusher = new TextureData.Flusher() { + public void flush() { + image.close(); + } + }; + TextureData data; + if (mipmap && image.getNumMipMaps() > 0) { + Buffer[] mipmapData = new Buffer[image.getNumMipMaps()]; + for (int i = 0; i < image.getNumMipMaps(); i++) { + mipmapData[i] = image.getMipMap(i).getData(); + } + data = new TextureData(glp, internalFormat, + info.getWidth(), + info.getHeight(), + 0, + pixelFormat, + GL.GL_UNSIGNED_BYTE, + info.isCompressed(), + true, + mipmapData, + flusher); + } else { + // Fix this up for the end user because we can't generate + // mipmaps for compressed textures + mipmap = false; + data = new TextureData(glp, internalFormat, + info.getWidth(), + info.getHeight(), + 0, + pixelFormat, + GL.GL_UNSIGNED_BYTE, + mipmap, + info.isCompressed(), + true, + info.getData(), + flusher); + } + return data; + } + } + + //---------------------------------------------------------------------- + // Base class for SGI RGB and TGA image providers + static abstract class StreamBasedTextureProvider implements TextureProvider { + public TextureData newTextureData(GLProfile glp, File file, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + InputStream inStream = new BufferedInputStream(new FileInputStream(file)); + try { + // The SGIImage and TGAImage implementations use InputStreams + // anyway so there isn't much point in having a separate code + // path for files + return newTextureData(glp, inStream, + internalFormat, + pixelFormat, + mipmap, + ((fileSuffix != null) ? fileSuffix : FileUtil.getFileSuffix(file))); + } finally { + inStream.close(); + } + } + + public TextureData newTextureData(GLProfile glp, URL url, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + InputStream stream = new BufferedInputStream(url.openStream()); + try { + return newTextureData(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix); + } finally { + stream.close(); + } + } + } + + //---------------------------------------------------------------------- + // SGI RGB image provider + static class SGITextureProvider extends StreamBasedTextureProvider { + public TextureData newTextureData(GLProfile glp, InputStream stream, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + if (SGI.equals(fileSuffix) || + SGI_RGB.equals(fileSuffix) || + SGIImage.isSGIImage(stream)) { + SGIImage image = SGIImage.read(stream); + if (pixelFormat == 0) { + pixelFormat = image.getFormat(); + } + if (internalFormat == 0) { + internalFormat = image.getFormat(); + } + return new TextureData(glp, internalFormat, + image.getWidth(), + image.getHeight(), + 0, + pixelFormat, + GL.GL_UNSIGNED_BYTE, + mipmap, + false, + false, + ByteBuffer.wrap(image.getData()), + null); + } + + return null; + } + } + + //---------------------------------------------------------------------- + // TGA (Targa) image provider + static class TGATextureProvider extends StreamBasedTextureProvider { + public TextureData newTextureData(GLProfile glp, InputStream stream, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + if (TGA.equals(fileSuffix)) { + TGAImage image = TGAImage.read(stream); + if (pixelFormat == 0) { + pixelFormat = image.getGLFormat(); + } + if (internalFormat == 0) { + GL gl = GLContext.getCurrentGL(); + if(gl.isGL2()) { + internalFormat = GL.GL_RGBA8; + } else { + internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB; + } + } + return new TextureData(glp, internalFormat, + image.getWidth(), + image.getHeight(), + 0, + pixelFormat, + GL.GL_UNSIGNED_BYTE, + mipmap, + false, + false, + image.getData(), + null); + } + + return null; + } + } + + //---------------------------------------------------------------------- + // DDS texture writer + // + static class DDSTextureWriter implements TextureWriter { + public boolean write(File file, + TextureData data) throws IOException { + if (DDS.equals(FileUtil.getFileSuffix(file))) { + // See whether the DDS writer can handle this TextureData + int pixelFormat = data.getPixelFormat(); + int pixelType = data.getPixelType(); + if (pixelType != GL.GL_BYTE && + pixelType != GL.GL_UNSIGNED_BYTE) { + throw new IOException("DDS writer only supports byte / unsigned byte textures"); + } + + int d3dFormat = 0; + // FIXME: some of these are probably not completely correct and would require swizzling + switch (pixelFormat) { + case GL.GL_RGB: d3dFormat = DDSImage.D3DFMT_R8G8B8; break; + case GL.GL_RGBA: d3dFormat = DDSImage.D3DFMT_A8R8G8B8; break; + case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT: d3dFormat = DDSImage.D3DFMT_DXT1; break; + case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: throw new IOException("RGBA DXT1 not yet supported"); + case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: d3dFormat = DDSImage.D3DFMT_DXT3; break; + case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: d3dFormat = DDSImage.D3DFMT_DXT5; break; + default: throw new IOException("Unsupported pixel format 0x" + Integer.toHexString(pixelFormat) + " by DDS writer"); + } + + ByteBuffer[] mipmaps = null; + if (data.getMipmapData() != null) { + mipmaps = new ByteBuffer[data.getMipmapData().length]; + for (int i = 0; i < mipmaps.length; i++) { + mipmaps[i] = (ByteBuffer) data.getMipmapData()[i]; + } + } else { + mipmaps = new ByteBuffer[] { (ByteBuffer) data.getBuffer() }; + } + + DDSImage image = DDSImage.createFromData(d3dFormat, + data.getWidth(), + data.getHeight(), + mipmaps); + image.write(file); + return true; + } + + return false; + } + } + + //---------------------------------------------------------------------- + // SGI (rgb) texture writer + // + static class SGITextureWriter implements TextureWriter { + public boolean write(File file, + TextureData data) throws IOException { + String fileSuffix = FileUtil.getFileSuffix(file); + if (SGI.equals(fileSuffix) || + SGI_RGB.equals(fileSuffix)) { + // See whether the SGI writer can handle this TextureData + int pixelFormat = data.getPixelFormat(); + int pixelType = data.getPixelType(); + if ((pixelFormat == GL.GL_RGB || + pixelFormat == GL.GL_RGBA) && + (pixelType == GL.GL_BYTE || + pixelType == GL.GL_UNSIGNED_BYTE)) { + ByteBuffer buf = ((data.getBuffer() != null) ? + (ByteBuffer) data.getBuffer() : + (ByteBuffer) data.getMipmapData()[0]); + byte[] bytes; + if (buf.hasArray()) { + bytes = buf.array(); + } else { + buf.rewind(); + bytes = new byte[buf.remaining()]; + buf.get(bytes); + buf.rewind(); + } + + SGIImage image = SGIImage.createFromData(data.getWidth(), + data.getHeight(), + (pixelFormat == GL.GL_RGBA), + bytes); + image.write(file, false); + return true; + } + + throw new IOException("SGI writer doesn't support this pixel format / type (only GL_RGB/A + bytes)"); + } + + return false; + } + } + + //---------------------------------------------------------------------- + // TGA (Targa) texture writer + + static class TGATextureWriter implements TextureWriter { + public boolean write(File file, + TextureData data) throws IOException { + if (TGA.equals(FileUtil.getFileSuffix(file))) { + // See whether the TGA writer can handle this TextureData + int pixelFormat = data.getPixelFormat(); + int pixelType = data.getPixelType(); + if ((pixelFormat == GL.GL_RGB || + pixelFormat == GL.GL_RGBA) && + (pixelType == GL.GL_BYTE || + pixelType == GL.GL_UNSIGNED_BYTE)) { + ByteBuffer buf = ((data.getBuffer() != null) ? + (ByteBuffer) data.getBuffer() : + (ByteBuffer) data.getMipmapData()[0]); + // Must reverse order of red and blue channels to get correct results + int skip = ((pixelFormat == GL.GL_RGB) ? 3 : 4); + for (int i = 0; i < buf.remaining(); i += skip) { + byte red = buf.get(i + 0); + byte blue = buf.get(i + 2); + buf.put(i + 0, blue); + buf.put(i + 2, red); + } + + TGAImage image = TGAImage.createFromData(data.getWidth(), + data.getHeight(), + (pixelFormat == GL.GL_RGBA), + false, + ((data.getBuffer() != null) ? + (ByteBuffer) data.getBuffer() : + (ByteBuffer) data.getMipmapData()[0])); + image.write(file); + return true; + } + + throw new IOException("TGA writer doesn't support this pixel format / type (only GL_RGB/A + bytes)"); + } + + return false; + } + } + + //---------------------------------------------------------------------- + // Helper routines + // + + private static int glGetInteger(int pname) { + int[] tmp = new int[1]; + GL gl = GLContext.getCurrentGL(); + gl.glGetIntegerv(pname, tmp, 0); + return tmp[0]; + } + + private static int glGetTexLevelParameteri(GL2 gl, int target, int level, int pname) { + int[] tmp = new int[1]; + gl.glGetTexLevelParameteriv(target, 0, pname, tmp, 0); + return tmp[0]; + } + + private static String toLowerCase(String arg) { + if (arg == null) { + return null; + } + + return arg.toLowerCase(); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java new file mode 100644 index 000000000..39ec74b97 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java @@ -0,0 +1,498 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.jogamp.opengl.util.texture.awt; + +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Transparency; +import java.awt.color.*; +import java.awt.image.*; +import java.nio.*; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.texture.*; + +public class AWTTextureData extends TextureData { + // Mechanism for lazily converting input BufferedImages with custom + // ColorModels to standard ones for uploading to OpenGL, as well as + // backing off from the optimizations of hoping that either + // GL_EXT_abgr or OpenGL 1.2 are present + private BufferedImage imageForLazyCustomConversion; + private boolean expectingEXTABGR; + private boolean expectingGL12; + + private static final ColorModel rgbaColorModel = + new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + new int[] {8, 8, 8, 8}, true, true, + Transparency.TRANSLUCENT, + DataBuffer.TYPE_BYTE); + private static final ColorModel rgbColorModel = + new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + new int[] {8, 8, 8, 0}, false, false, + Transparency.OPAQUE, + DataBuffer.TYPE_BYTE); + + + /** + * Constructs a new TextureData object with the specified parameters + * and data contained in the given BufferedImage. The resulting + * TextureData "wraps" the contents of the BufferedImage, so if a + * modification is made to the BufferedImage between the time the + * TextureData is constructed and when a Texture is made from the + * TextureData, that modification will be visible in the resulting + * Texture. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param internalFormat the OpenGL internal format for the + * resulting texture; may be 0, in which case + * it is inferred from the image's type + * @param pixelFormat the OpenGL internal format for the + * resulting texture; may be 0, in which case + * it is inferred from the image's type (note: + * this argument is currently always ignored) + * @param mipmap indicates whether mipmaps should be + * autogenerated (using GLU) for the resulting + * texture + * @param image the image containing the texture data + */ + public AWTTextureData(GLProfile glp, + int internalFormat, + int pixelFormat, + boolean mipmap, + BufferedImage image) { + super(glp); + if (internalFormat == 0) { + this.internalFormat = image.getColorModel().hasAlpha() ? GL.GL_RGBA : GL.GL_RGB; + } else { + this.internalFormat = internalFormat; + } + createFromImage(glp, image); + this.mipmap = mipmap; + if (buffer != null) { + estimatedMemorySize = estimatedMemorySize(buffer); + } else { + // In the lazy custom conversion case we don't yet have a buffer + if (imageForLazyCustomConversion != null) { + estimatedMemorySize = estimatedMemorySize(wrapImageDataBuffer(imageForLazyCustomConversion)); + } + } + } + + /** Returns the intended OpenGL pixel format of the texture data. */ + public int getPixelFormat() { + if (imageForLazyCustomConversion != null) { + if (!((expectingEXTABGR && haveEXTABGR) || + (expectingGL12 && haveGL12))) { + revertPixelFormatAndType(); + } + } + return pixelFormat; + } + /** Returns the intended OpenGL pixel type of the texture data. */ + public int getPixelType() { + if (imageForLazyCustomConversion != null) { + if (!((expectingEXTABGR && haveEXTABGR) || + (expectingGL12 && haveGL12))) { + revertPixelFormatAndType(); + } + } + return pixelType; + } + + /** Returns the texture data, or null if it is specified as a set of mipmaps. */ + public Buffer getBuffer() { + if (imageForLazyCustomConversion != null) { + if (!((expectingEXTABGR && haveEXTABGR) || + (expectingGL12 && haveGL12))) { + revertPixelFormatAndType(); + // Must present the illusion to the end user that we are simply + // wrapping the input BufferedImage + createFromCustom(imageForLazyCustomConversion); + } + } + return buffer; + } + + private void createFromImage(GLProfile glp, BufferedImage image) { + pixelType = 0; // Determine from image + mustFlipVertically = true; + + width = image.getWidth(); + height = image.getHeight(); + + int scanlineStride; + + SampleModel sm = image.getRaster().getSampleModel(); + if (sm instanceof SinglePixelPackedSampleModel) { + scanlineStride = + ((SinglePixelPackedSampleModel)sm).getScanlineStride(); + } else if (sm instanceof MultiPixelPackedSampleModel) { + scanlineStride = + ((MultiPixelPackedSampleModel)sm).getScanlineStride(); + } else if (sm instanceof ComponentSampleModel) { + scanlineStride = + ((ComponentSampleModel)sm).getScanlineStride(); + } else { + // This will only happen for TYPE_CUSTOM anyway + setupLazyCustomConversion(image); + return; + } + + width = image.getWidth(); + height = image.getHeight(); + + if (glp.isGL2GL3()) { + switch (image.getType()) { + case BufferedImage.TYPE_INT_RGB: + pixelFormat = GL2GL3.GL_BGRA; + pixelType = GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV; + rowLength = scanlineStride; + alignment = 4; + expectingGL12 = true; + setupLazyCustomConversion(image); + break; + case BufferedImage.TYPE_INT_ARGB_PRE: + pixelFormat = GL2GL3.GL_BGRA; + pixelType = GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV; + rowLength = scanlineStride; + alignment = 4; + expectingGL12 = true; + setupLazyCustomConversion(image); + break; + case BufferedImage.TYPE_INT_BGR: + pixelFormat = GL.GL_RGBA; + pixelType = GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV; + rowLength = scanlineStride; + alignment = 4; + expectingGL12 = true; + setupLazyCustomConversion(image); + break; + case BufferedImage.TYPE_3BYTE_BGR: + { + // we can pass the image data directly to OpenGL only if + // we have an integral number of pixels in each scanline + if ((scanlineStride % 3) == 0) { + pixelFormat = GL2GL3.GL_BGR; + pixelType = GL.GL_UNSIGNED_BYTE; + rowLength = scanlineStride / 3; + alignment = 1; + } else { + setupLazyCustomConversion(image); + return; + } + } + break; + case BufferedImage.TYPE_4BYTE_ABGR_PRE: + { + // we can pass the image data directly to OpenGL only if + // we have an integral number of pixels in each scanline + // and only if the GL_EXT_abgr extension is present + + // NOTE: disabling this code path for now as it appears it's + // buggy at least on some NVidia drivers and doesn't perform + // the necessary byte swapping (FIXME: needs more + // investigation) + if ((scanlineStride % 4) == 0 && glp.isGL2() && false) { + pixelFormat = GL2.GL_ABGR_EXT; + pixelType = GL.GL_UNSIGNED_BYTE; + rowLength = scanlineStride / 4; + alignment = 4; + + // Store a reference to the original image for later in + // case it turns out that we don't have GL_EXT_abgr at the + // time we're going to do the texture upload to OpenGL + setupLazyCustomConversion(image); + expectingEXTABGR = true; + break; + } else { + setupLazyCustomConversion(image); + return; + } + } + case BufferedImage.TYPE_USHORT_565_RGB: + pixelFormat = GL.GL_RGB; + pixelType = GL.GL_UNSIGNED_SHORT_5_6_5; + rowLength = scanlineStride; + alignment = 2; + expectingGL12 = true; + setupLazyCustomConversion(image); + break; + case BufferedImage.TYPE_USHORT_555_RGB: + pixelFormat = GL2GL3.GL_BGRA; + pixelType = GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV; + rowLength = scanlineStride; + alignment = 2; + expectingGL12 = true; + setupLazyCustomConversion(image); + break; + case BufferedImage.TYPE_BYTE_GRAY: + pixelFormat = GL.GL_LUMINANCE; + pixelType = GL.GL_UNSIGNED_BYTE; + rowLength = scanlineStride; + alignment = 1; + break; + case BufferedImage.TYPE_USHORT_GRAY: + pixelFormat = GL.GL_LUMINANCE; + pixelType = GL.GL_UNSIGNED_SHORT; + rowLength = scanlineStride; + alignment = 2; + break; + // Note: TYPE_INT_ARGB and TYPE_4BYTE_ABGR images go down the + // custom code path to satisfy the invariant that images with an + // alpha channel always go down with premultiplied alpha. + case BufferedImage.TYPE_INT_ARGB: + case BufferedImage.TYPE_4BYTE_ABGR: + case BufferedImage.TYPE_BYTE_BINARY: + case BufferedImage.TYPE_BYTE_INDEXED: + case BufferedImage.TYPE_CUSTOM: + default: + ColorModel cm = image.getColorModel(); + if (cm.equals(rgbColorModel)) { + pixelFormat = GL.GL_RGB; + pixelType = GL.GL_UNSIGNED_BYTE; + rowLength = scanlineStride / 3; + alignment = 1; + } else if (cm.equals(rgbaColorModel)) { + pixelFormat = GL.GL_RGBA; + pixelType = GL.GL_UNSIGNED_BYTE; + rowLength = scanlineStride / 4; // FIXME: correct? + alignment = 4; + } else { + setupLazyCustomConversion(image); + return; + } + break; + } + } else { + switch (image.getType()) { + case BufferedImage.TYPE_INT_RGB: + pixelFormat = GL.GL_RGB; + pixelType = GL.GL_UNSIGNED_BYTE; + rowLength = scanlineStride; + alignment = 3; + expectingGL12 = true; + setupLazyCustomConversion(image); + break; + case BufferedImage.TYPE_INT_ARGB_PRE: + throw new GLException("INT_ARGB_PRE n.a."); + case BufferedImage.TYPE_INT_BGR: + throw new GLException("INT_BGR n.a."); + case BufferedImage.TYPE_3BYTE_BGR: + throw new GLException("INT_BGR n.a."); + case BufferedImage.TYPE_4BYTE_ABGR_PRE: + throw new GLException("INT_BGR n.a."); + case BufferedImage.TYPE_USHORT_565_RGB: + pixelFormat = GL.GL_RGB; + pixelType = GL.GL_UNSIGNED_SHORT_5_6_5; + rowLength = scanlineStride; + alignment = 2; + expectingGL12 = true; + setupLazyCustomConversion(image); + break; + case BufferedImage.TYPE_USHORT_555_RGB: + pixelFormat = GL.GL_RGBA; + pixelType = GL.GL_UNSIGNED_SHORT_5_5_5_1; + rowLength = scanlineStride; + alignment = 2; + expectingGL12 = true; + setupLazyCustomConversion(image); + break; + case BufferedImage.TYPE_BYTE_GRAY: + pixelFormat = GL.GL_LUMINANCE; + pixelType = GL.GL_UNSIGNED_BYTE; + rowLength = scanlineStride; + alignment = 1; + break; + case BufferedImage.TYPE_USHORT_GRAY: + throw new GLException("USHORT_GRAY n.a."); + // Note: TYPE_INT_ARGB and TYPE_4BYTE_ABGR images go down the + // custom code path to satisfy the invariant that images with an + // alpha channel always go down with premultiplied alpha. + case BufferedImage.TYPE_INT_ARGB: + case BufferedImage.TYPE_4BYTE_ABGR: + case BufferedImage.TYPE_BYTE_BINARY: + case BufferedImage.TYPE_BYTE_INDEXED: + case BufferedImage.TYPE_CUSTOM: + default: + ColorModel cm = image.getColorModel(); + if (cm.equals(rgbColorModel)) { + pixelFormat = GL.GL_RGB; + pixelType = GL.GL_UNSIGNED_BYTE; + rowLength = scanlineStride / 3; + alignment = 1; + } else if (cm.equals(rgbaColorModel)) { + pixelFormat = GL.GL_RGBA; + pixelType = GL.GL_UNSIGNED_BYTE; + rowLength = scanlineStride / 4; // FIXME: correct? + alignment = 4; + } else { + setupLazyCustomConversion(image); + return; + } + break; + } + } + + createNIOBufferFromImage(image); + } + + private void setupLazyCustomConversion(BufferedImage image) { + imageForLazyCustomConversion = image; + boolean hasAlpha = image.getColorModel().hasAlpha(); + if (pixelFormat == 0) { + pixelFormat = hasAlpha ? GL.GL_RGBA : GL.GL_RGB; + } + alignment = 1; // FIXME: do we need better? + rowLength = width; // FIXME: correct in all cases? + + // Allow previously-selected pixelType (if any) to override that + // we can infer from the DataBuffer + DataBuffer data = image.getRaster().getDataBuffer(); + if (data instanceof DataBufferByte || isPackedInt(image)) { + // Don't use GL_UNSIGNED_INT for BufferedImage packed int images + if (pixelType == 0) pixelType = GL.GL_UNSIGNED_BYTE; + } else if (data instanceof DataBufferDouble) { + throw new RuntimeException("DataBufferDouble rasters not supported by OpenGL"); + } else if (data instanceof DataBufferFloat) { + if (pixelType == 0) pixelType = GL.GL_FLOAT; + } else if (data instanceof DataBufferInt) { + // FIXME: should we support signed ints? + if (pixelType == 0) pixelType = GL2GL3.GL_UNSIGNED_INT; + } else if (data instanceof DataBufferShort) { + if (pixelType == 0) pixelType = GL.GL_SHORT; + } else if (data instanceof DataBufferUShort) { + if (pixelType == 0) pixelType = GL.GL_UNSIGNED_SHORT; + } else { + throw new RuntimeException("Unexpected DataBuffer type?"); + } + } + + private void createFromCustom(BufferedImage image) { + int width = image.getWidth(); + int height = image.getHeight(); + + // create a temporary image that is compatible with OpenGL + boolean hasAlpha = image.getColorModel().hasAlpha(); + ColorModel cm = null; + int dataBufferType = image.getRaster().getDataBuffer().getDataType(); + // Don't use integer components for packed int images + if (isPackedInt(image)) { + dataBufferType = DataBuffer.TYPE_BYTE; + } + if (dataBufferType == DataBuffer.TYPE_BYTE) { + cm = hasAlpha ? rgbaColorModel : rgbColorModel; + } else { + if (hasAlpha) { + cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + null, true, true, + Transparency.TRANSLUCENT, + dataBufferType); + } else { + cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + null, false, false, + Transparency.OPAQUE, + dataBufferType); + } + } + + boolean premult = cm.isAlphaPremultiplied(); + WritableRaster raster = + cm.createCompatibleWritableRaster(width, height); + BufferedImage texImage = new BufferedImage(cm, raster, premult, null); + + // copy the source image into the temporary image + Graphics2D g = texImage.createGraphics(); + g.setComposite(AlphaComposite.Src); + g.drawImage(image, 0, 0, null); + g.dispose(); + + // Wrap the buffer from the temporary image + createNIOBufferFromImage(texImage); + } + + private boolean isPackedInt(BufferedImage image) { + int imgType = image.getType(); + return (imgType == BufferedImage.TYPE_INT_RGB || + imgType == BufferedImage.TYPE_INT_BGR || + imgType == BufferedImage.TYPE_INT_ARGB || + imgType == BufferedImage.TYPE_INT_ARGB_PRE); + } + + private void revertPixelFormatAndType() { + // Knowing we don't have e.g. OpenGL 1.2 functionality available, + // and knowing we're in the process of doing the fallback code + // path, re-infer a vanilla pixel format and type compatible with + // OpenGL 1.1 + pixelFormat = 0; + pixelType = 0; + setupLazyCustomConversion(imageForLazyCustomConversion); + } + + private void createNIOBufferFromImage(BufferedImage image) { + buffer = wrapImageDataBuffer(image); + } + + private Buffer wrapImageDataBuffer(BufferedImage image) { + // + // Note: Grabbing the DataBuffer will defeat Java2D's image + // management mechanism (as of JDK 5/6, at least). This shouldn't + // be a problem for most JOGL apps, but those that try to upload + // the image into an OpenGL texture and then use the same image in + // Java2D rendering might find the 2D rendering is not as fast as + // it could be. + // + + DataBuffer data = image.getRaster().getDataBuffer(); + if (data instanceof DataBufferByte) { + return ByteBuffer.wrap(((DataBufferByte) data).getData()); + } else if (data instanceof DataBufferDouble) { + throw new RuntimeException("DataBufferDouble rasters not supported by OpenGL"); + } else if (data instanceof DataBufferFloat) { + return FloatBuffer.wrap(((DataBufferFloat) data).getData()); + } else if (data instanceof DataBufferInt) { + return IntBuffer.wrap(((DataBufferInt) data).getData()); + } else if (data instanceof DataBufferShort) { + return ShortBuffer.wrap(((DataBufferShort) data).getData()); + } else if (data instanceof DataBufferUShort) { + return ShortBuffer.wrap(((DataBufferUShort) data).getData()); + } else { + throw new RuntimeException("Unexpected DataBuffer type?"); + } + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureIO.java b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureIO.java new file mode 100644 index 000000000..fdd1365f7 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureIO.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.awt; + +import java.awt.image.*; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.texture.*; + +public class AWTTextureIO extends TextureIO { + /** + * Creates a TextureData from the given BufferedImage. Does no + * OpenGL work. + * We assume a desktop GLProfile GL2GL3, otherwise use the other factory. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param image the BufferedImage containing the texture data + * @param mipmap whether mipmaps should be produced for this + * texture by autogenerating them + * @return the texture data from the image + * + * @see #newTextureData(GLProfile, BufferedImage, boolean) + */ + public static TextureData newTextureData(GLProfile glp, BufferedImage image, + boolean mipmap) { + return newTextureDataImpl(glp, image, 0, 0, mipmap); + } + + /** + * Creates a TextureData from the given BufferedImage, using the + * specified OpenGL internal format and pixel format for the texture + * which will eventually result. The internalFormat and pixelFormat + * must be specified and may not be zero; to use default values, use + * the variant of this method which does not take these + * arguments. Does no OpenGL work. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param image the BufferedImage containing the texture data + * @param internalFormat the OpenGL internal format of the texture + * which will eventually result from the TextureData + * @param pixelFormat the OpenGL pixel format of the texture + * which will eventually result from the TextureData + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * @return the texture data from the image + * @throws IllegalArgumentException if either internalFormat or + * pixelFormat was 0 + */ + public static TextureData newTextureData(GLProfile glp, BufferedImage image, + int internalFormat, + int pixelFormat, + boolean mipmap) throws IllegalArgumentException { + if ((internalFormat == 0) || (pixelFormat == 0)) { + throw new IllegalArgumentException("internalFormat and pixelFormat must be non-zero"); + } + + return newTextureDataImpl(glp, image, internalFormat, pixelFormat, mipmap); + } + + /** + * Creates an OpenGL texture object from the specified BufferedImage + * using the current OpenGL context. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param image the BufferedImage from which to read the texture data + * @param mipmap whether mipmaps should be produced for this + * texture by autogenerating them + * @throws GLException if no OpenGL context is current or if an + * OpenGL error occurred + */ + public static Texture newTexture(GLProfile glp, BufferedImage image, boolean mipmap) throws GLException { + TextureData data = newTextureData(glp, image, mipmap); + Texture texture = newTexture(data); + data.flush(); + return texture; + } + + private static TextureData newTextureDataImpl(GLProfile glp, + BufferedImage image, + int internalFormat, + int pixelFormat, + boolean mipmap) { + return new AWTTextureData(glp, internalFormat, pixelFormat, mipmap, image); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java new file mode 100644 index 000000000..e3092162d --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java @@ -0,0 +1,919 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi; + +import java.io.*; +import java.nio.*; +import java.nio.channels.*; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.texture.*; + +/** A reader and writer for DirectDraw Surface (.dds) files, which are + used to describe textures. These files can contain multiple mipmap + levels in one file. This class is currently minimal and does not + support all of the possible file formats. */ + +public class DDSImage { + + /** Simple class describing images and data; does not encapsulate + image format information. User is responsible for transmitting + that information in another way. */ + + public static class ImageInfo { + private ByteBuffer data; + private int width; + private int height; + private boolean isCompressed; + private int compressionFormat; + + public ImageInfo(ByteBuffer data, int width, int height, boolean compressed, int compressionFormat) { + this.data = data; this.width = width; this.height = height; + this.isCompressed = compressed; this.compressionFormat = compressionFormat; + } + public int getWidth() { return width; } + public int getHeight() { return height; } + public ByteBuffer getData() { return data; } + public boolean isCompressed() { return isCompressed; } + public int getCompressionFormat() { + if (!isCompressed()) + throw new RuntimeException("Should not call unless compressed"); + return compressionFormat; + } + } + + private FileInputStream fis; + private FileChannel chan; + private ByteBuffer buf; + private Header header; + + // + // Selected bits in header flags + // + + public static final int DDSD_CAPS = 0x00000001; // Capacities are valid + public static final int DDSD_HEIGHT = 0x00000002; // Height is valid + public static final int DDSD_WIDTH = 0x00000004; // Width is valid + public static final int DDSD_PITCH = 0x00000008; // Pitch is valid + public static final int DDSD_BACKBUFFERCOUNT = 0x00000020; // Back buffer count is valid + public static final int DDSD_ZBUFFERBITDEPTH = 0x00000040; // Z-buffer bit depth is valid (shouldn't be used in DDSURFACEDESC2) + public static final int DDSD_ALPHABITDEPTH = 0x00000080; // Alpha bit depth is valid + public static final int DDSD_LPSURFACE = 0x00000800; // lpSurface is valid + public static final int DDSD_PIXELFORMAT = 0x00001000; // ddpfPixelFormat is valid + public static final int DDSD_MIPMAPCOUNT = 0x00020000; // Mip map count is valid + public static final int DDSD_LINEARSIZE = 0x00080000; // dwLinearSize is valid + public static final int DDSD_DEPTH = 0x00800000; // dwDepth is valid + + public static final int DDPF_ALPHAPIXELS = 0x00000001; // Alpha channel is present + public static final int DDPF_ALPHA = 0x00000002; // Only contains alpha information + public static final int DDPF_FOURCC = 0x00000004; // FourCC code is valid + public static final int DDPF_PALETTEINDEXED4 = 0x00000008; // Surface is 4-bit color indexed + public static final int DDPF_PALETTEINDEXEDTO8 = 0x00000010; // Surface is indexed into a palette which stores indices + // into the destination surface's 8-bit palette + public static final int DDPF_PALETTEINDEXED8 = 0x00000020; // Surface is 8-bit color indexed + public static final int DDPF_RGB = 0x00000040; // RGB data is present + public static final int DDPF_COMPRESSED = 0x00000080; // Surface will accept pixel data in the format specified + // and compress it during the write + public static final int DDPF_RGBTOYUV = 0x00000100; // Surface will accept RGB data and translate it during + // the write to YUV data. The format of the data to be written + // will be contained in the pixel format structure. The DDPF_RGB + // flag will be set. + public static final int DDPF_YUV = 0x00000200; // Pixel format is YUV - YUV data in pixel format struct is valid + public static final int DDPF_ZBUFFER = 0x00000400; // Pixel format is a z buffer only surface + public static final int DDPF_PALETTEINDEXED1 = 0x00000800; // Surface is 1-bit color indexed + public static final int DDPF_PALETTEINDEXED2 = 0x00001000; // Surface is 2-bit color indexed + public static final int DDPF_ZPIXELS = 0x00002000; // Surface contains Z information in the pixels + + // Selected bits in DDS capabilities flags + public static final int DDSCAPS_TEXTURE = 0x00001000; // Can be used as a texture + public static final int DDSCAPS_MIPMAP = 0x00400000; // Is one level of a mip-map + public static final int DDSCAPS_COMPLEX = 0x00000008; // Complex surface structure, such as a cube map + + // Selected bits in DDS extended capabilities flags + public static final int DDSCAPS2_CUBEMAP = 0x00000200; + public static final int DDSCAPS2_CUBEMAP_POSITIVEX = 0x00000400; + public static final int DDSCAPS2_CUBEMAP_NEGATIVEX = 0x00000800; + public static final int DDSCAPS2_CUBEMAP_POSITIVEY = 0x00001000; + public static final int DDSCAPS2_CUBEMAP_NEGATIVEY = 0x00002000; + public static final int DDSCAPS2_CUBEMAP_POSITIVEZ = 0x00004000; + public static final int DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x00008000; + + // Known pixel formats + public static final int D3DFMT_UNKNOWN = 0; + public static final int D3DFMT_R8G8B8 = 20; + public static final int D3DFMT_A8R8G8B8 = 21; + public static final int D3DFMT_X8R8G8B8 = 22; + // The following are also valid FourCC codes + public static final int D3DFMT_DXT1 = 0x31545844; + public static final int D3DFMT_DXT2 = 0x32545844; + public static final int D3DFMT_DXT3 = 0x33545844; + public static final int D3DFMT_DXT4 = 0x34545844; + public static final int D3DFMT_DXT5 = 0x35545844; + + /** Reads a DirectDraw surface from the specified file name, + returning the resulting DDSImage. + + @param filename File name + @return DDS image object + @throws java.io.IOException if an I/O exception occurred + */ + public static DDSImage read(String filename) throws IOException { + return read(new File(filename)); + } + + /** Reads a DirectDraw surface from the specified file, returning + the resulting DDSImage. + + @param file File object + @return DDS image object + @throws java.io.IOException if an I/O exception occurred + */ + public static DDSImage read(File file) throws IOException { + DDSImage image = new DDSImage(); + image.readFromFile(file); + return image; + } + + /** Reads a DirectDraw surface from the specified ByteBuffer, returning + the resulting DDSImage. + + @param buf Input data + @return DDS image object + @throws java.io.IOException if an I/O exception occurred + */ + public static DDSImage read(ByteBuffer buf) throws IOException { + DDSImage image = new DDSImage(); + image.readFromBuffer(buf); + return image; + } + + /** Closes open files and resources associated with the open + DDSImage. No other methods may be called on this object once + this is called. */ + public void close() { + try { + if (chan != null) { + chan.close(); + chan = null; + } + if (fis != null) { + fis.close(); + fis = null; + } + buf = null; + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Creates a new DDSImage from data supplied by the user. The + * resulting DDSImage can be written to disk using the write() + * method. + * + * @param d3dFormat the D3DFMT_ constant describing the data; it is + * assumed that it is packed tightly + * @param width the width in pixels of the topmost mipmap image + * @param height the height in pixels of the topmost mipmap image + * @param mipmapData the data for each mipmap level of the resulting + * DDSImage; either only one mipmap level should + * be specified, or they all must be + * @throws IllegalArgumentException if the data does not match the + * specified arguments + * @return DDS image object + */ + public static DDSImage createFromData(int d3dFormat, + int width, + int height, + ByteBuffer[] mipmapData) throws IllegalArgumentException { + DDSImage image = new DDSImage(); + image.initFromData(d3dFormat, width, height, mipmapData); + return image; + } + + /** Determines from the magic number whether the given InputStream + points to a DDS image. The given InputStream must return true + from markSupported() and support a minimum of four bytes of + read-ahead. + + @param in Stream to check + @return true if input stream is DDS image or false otherwise + @throws java.io.IOException if an I/O exception occurred + */ + public static boolean isDDSImage(InputStream in) throws IOException { + if (!(in instanceof BufferedInputStream)) { + in = new BufferedInputStream(in); + } + if (!in.markSupported()) { + throw new IOException("Can not test non-destructively whether given InputStream is a DDS image"); + } + in.mark(4); + int magic = 0; + for (int i = 0; i < 4; i++) { + int tmp = in.read(); + if (tmp < 0) { + in.reset(); + return false; + } + magic = ((magic >>> 8) | (tmp << 24)); + } + in.reset(); + return (magic == MAGIC); + } + + /** + * Writes this DDSImage to the specified file name. + * @param filename File name to write to + * @throws java.io.IOException if an I/O exception occurred + */ + public void write(String filename) throws IOException { + write(new File(filename)); + } + + /** + * Writes this DDSImage to the specified file name. + * @param file File object to write to + * @throws java.io.IOException if an I/O exception occurred + */ + public void write(File file) throws IOException { + FileOutputStream stream = new FileOutputStream(file); + FileChannel chan = stream.getChannel(); + // Create ByteBuffer for header in case the start of our + // ByteBuffer isn't actually memory-mapped + ByteBuffer hdr = ByteBuffer.allocate(Header.writtenSize()); + hdr.order(ByteOrder.LITTLE_ENDIAN); + header.write(hdr); + hdr.rewind(); + chan.write(hdr); + buf.position(Header.writtenSize()); + chan.write(buf); + chan.force(true); + chan.close(); + stream.close(); + } + + /** Test for presence/absence of surface description flags (DDSD_*) + * @param flag DDSD_* flags set to test + * @return true if flag present or false otherwise + */ + public boolean isSurfaceDescFlagSet(int flag) { + return ((header.flags & flag) != 0); + } + + /** Test for presence/absence of pixel format flags (DDPF_*) */ + public boolean isPixelFormatFlagSet(int flag) { + return ((header.pfFlags & flag) != 0); + } + + /** Gets the pixel format of this texture (D3DFMT_*) based on some + heuristics. Returns D3DFMT_UNKNOWN if could not recognize the + pixel format. */ + public int getPixelFormat() { + if (isCompressed()) { + return getCompressionFormat(); + } else if (isPixelFormatFlagSet(DDPF_RGB)) { + if (isPixelFormatFlagSet(DDPF_ALPHAPIXELS)) { + if (getDepth() == 32 && + header.pfRBitMask == 0x00FF0000 && + header.pfGBitMask == 0x0000FF00 && + header.pfBBitMask == 0x000000FF && + header.pfABitMask == 0xFF000000) { + return D3DFMT_A8R8G8B8; + } + } else { + if (getDepth() == 24 && + header.pfRBitMask == 0x00FF0000 && + header.pfGBitMask == 0x0000FF00 && + header.pfBBitMask == 0x000000FF) { + return D3DFMT_R8G8B8; + } else if (getDepth() == 32 && + header.pfRBitMask == 0x00FF0000 && + header.pfGBitMask == 0x0000FF00 && + header.pfBBitMask == 0x000000FF) { + return D3DFMT_X8R8G8B8; + } + } + } + + return D3DFMT_UNKNOWN; + } + + /** + * Indicates whether this texture is cubemap + * @return true if cubemap or false otherwise + */ + public boolean isCubemap() { + return ((header.ddsCaps1 & DDSCAPS_COMPLEX) != 0) && ((header.ddsCaps2 & DDSCAPS2_CUBEMAP) != 0); + } + + /** + * Indicates whethe this cubemap side present + * @param side Side to test + * @return true if side present or false otherwise + */ + public boolean isCubemapSidePresent(int side) { + return isCubemap() && (header.ddsCaps2 & side) != 0; + } + + /** Indicates whether this texture is compressed. */ + public boolean isCompressed() { + return (isPixelFormatFlagSet(DDPF_FOURCC)); + } + + /** If this surface is compressed, returns the kind of compression + used (DXT1..DXT5). */ + public int getCompressionFormat() { + return header.pfFourCC; + } + + /** Width of the texture (or the top-most mipmap if mipmaps are + present) */ + public int getWidth() { + return header.width; + } + + /** Height of the texture (or the top-most mipmap if mipmaps are + present) */ + public int getHeight() { + return header.height; + } + + /** Total number of bits per pixel. Only valid if DDPF_RGB is + present. For A8R8G8B8, would be 32. */ + public int getDepth() { + return header.pfRGBBitCount; + } + + /** Number of mip maps in the texture */ + public int getNumMipMaps() { + if (!isSurfaceDescFlagSet(DDSD_MIPMAPCOUNT)) { + return 0; + } + return header.mipMapCountOrAux; + } + + /** Gets the <i>i</i>th mipmap data (0..getNumMipMaps() - 1) + * @param map Mipmap index + * @return Image object + */ + public ImageInfo getMipMap(int map) { + return getMipMap( 0, map ); + } + + /** + * Gets the <i>i</i>th mipmap data (0..getNumMipMaps() - 1) + * @param side Cubemap side or 0 for 2D texture + * @param map Mipmap index + * @return Image object + */ + public ImageInfo getMipMap(int side, int map) { + if (!isCubemap() && (side != 0)) { + throw new RuntimeException( "Illegal side for 2D texture: " + side ); + } + if (isCubemap() && !isCubemapSidePresent(side)) { + throw new RuntimeException( "Illegal side, side not present: " + side ); + } + if (getNumMipMaps() > 0 && + ((map < 0) || (map >= getNumMipMaps()))) { + throw new RuntimeException("Illegal mipmap number " + map + " (0.." + (getNumMipMaps() - 1) + ")"); + } + + // Figure out how far to seek + int seek = Header.writtenSize(); + if (isCubemap()) { + seek += sideShiftInBytes(side); + } + for (int i = 0; i < map; i++) { + seek += mipMapSizeInBytes(i); + } + buf.limit(seek + mipMapSizeInBytes(map)); + buf.position(seek); + ByteBuffer next = buf.slice(); + buf.position(0); + buf.limit(buf.capacity()); + return new ImageInfo(next, mipMapWidth(map), mipMapHeight(map), isCompressed(), getCompressionFormat()); + } + + /** Returns an array of ImageInfos corresponding to all mipmap + levels of this DDS file. + @return Mipmap image objects set + */ + public ImageInfo[] getAllMipMaps() { + return getAllMipMaps(0); + } + + /** + * Returns an array of ImageInfos corresponding to all mipmap + * levels of this DDS file. + * @param side Cubemap side or 0 for 2D texture + * @return Mipmap image objects set + */ + public ImageInfo[] getAllMipMaps( int side ) { + int numLevels = getNumMipMaps(); + if (numLevels == 0) { + numLevels = 1; + } + ImageInfo[] result = new ImageInfo[numLevels]; + for (int i = 0; i < numLevels; i++) { + result[i] = getMipMap(side, i); + } + return result; + } + + /** Converts e.g. DXT1 compression format constant (see {@link + #getCompressionFormat}) into "DXT1". + @param compressionFormat Compression format constant + @return String format code + */ + public static String getCompressionFormatName(int compressionFormat) { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < 4; i++) { + char c = (char) (compressionFormat & 0xFF); + buf.append(c); + compressionFormat = compressionFormat >> 8; + } + return buf.toString(); + } + + /** Allocates a temporary, empty ByteBuffer suitable for use in a + call to glCompressedTexImage2D. This is used by the Texture + class to expand non-power-of-two DDS compressed textures to + power-of-two sizes on hardware not supporting OpenGL 2.0 and the + NPOT texture extension. The specified OpenGL internal format + must be one of GL_COMPRESSED_RGB_S3TC_DXT1_EXT, + GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, or + GL_COMPRESSED_RGBA_S3TC_DXT5_EXT. + */ + public static ByteBuffer allocateBlankBuffer(int width, + int height, + int openGLInternalFormat) { + int size = width * height; + switch (openGLInternalFormat) { + case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + size /= 2; + break; + + case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + break; + + default: + throw new IllegalArgumentException("Illegal OpenGL texture internal format " + + openGLInternalFormat); + } + if (size == 0) + size = 1; + return GLBuffers.newDirectByteBuffer(size); + } + + public void debugPrint() { + PrintStream tty = System.err; + tty.println("Compressed texture: " + isCompressed()); + if (isCompressed()) { + int fmt = getCompressionFormat(); + String name = getCompressionFormatName(fmt); + tty.println("Compression format: 0x" + Integer.toHexString(fmt) + " (" + name + ")"); + } + tty.println("Width: " + header.width + " Height: " + header.height); + tty.println("header.pitchOrLinearSize: " + header.pitchOrLinearSize); + tty.println("header.pfRBitMask: 0x" + Integer.toHexString(header.pfRBitMask)); + tty.println("header.pfGBitMask: 0x" + Integer.toHexString(header.pfGBitMask)); + tty.println("header.pfBBitMask: 0x" + Integer.toHexString(header.pfBBitMask)); + tty.println("SurfaceDesc flags:"); + boolean recognizedAny = false; + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_CAPS, "DDSD_CAPS"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_HEIGHT, "DDSD_HEIGHT"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_WIDTH, "DDSD_WIDTH"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_PITCH, "DDSD_PITCH"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_BACKBUFFERCOUNT, "DDSD_BACKBUFFERCOUNT"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_ZBUFFERBITDEPTH, "DDSD_ZBUFFERBITDEPTH"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_ALPHABITDEPTH, "DDSD_ALPHABITDEPTH"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_LPSURFACE, "DDSD_LPSURFACE"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_PIXELFORMAT, "DDSD_PIXELFORMAT"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_MIPMAPCOUNT, "DDSD_MIPMAPCOUNT"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_LINEARSIZE, "DDSD_LINEARSIZE"); + recognizedAny |= printIfRecognized(tty, header.flags, DDSD_DEPTH, "DDSD_DEPTH"); + if (!recognizedAny) { + tty.println("(none)"); + } + tty.println("Raw SurfaceDesc flags: 0x" + Integer.toHexString(header.flags)); + tty.println("Pixel format flags:"); + recognizedAny = false; + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_ALPHAPIXELS, "DDPF_ALPHAPIXELS"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_ALPHA, "DDPF_ALPHA"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_FOURCC, "DDPF_FOURCC"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_PALETTEINDEXED4, "DDPF_PALETTEINDEXED4"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_PALETTEINDEXEDTO8, "DDPF_PALETTEINDEXEDTO8"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_PALETTEINDEXED8, "DDPF_PALETTEINDEXED8"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_RGB, "DDPF_RGB"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_COMPRESSED, "DDPF_COMPRESSED"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_RGBTOYUV, "DDPF_RGBTOYUV"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_YUV, "DDPF_YUV"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_ZBUFFER, "DDPF_ZBUFFER"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_PALETTEINDEXED1, "DDPF_PALETTEINDEXED1"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_PALETTEINDEXED2, "DDPF_PALETTEINDEXED2"); + recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_ZPIXELS, "DDPF_ZPIXELS"); + if (!recognizedAny) { + tty.println("(none)"); + } + tty.println("Raw pixel format flags: 0x" + Integer.toHexString(header.pfFlags)); + tty.println("Depth: " + getDepth()); + tty.println("Number of mip maps: " + getNumMipMaps()); + int fmt = getPixelFormat(); + tty.print("Pixel format: "); + switch (fmt) { + case D3DFMT_R8G8B8: tty.println("D3DFMT_R8G8B8"); break; + case D3DFMT_A8R8G8B8: tty.println("D3DFMT_A8R8G8B8"); break; + case D3DFMT_X8R8G8B8: tty.println("D3DFMT_X8R8G8B8"); break; + case D3DFMT_DXT1: tty.println("D3DFMT_DXT1"); break; + case D3DFMT_DXT2: tty.println("D3DFMT_DXT2"); break; + case D3DFMT_DXT3: tty.println("D3DFMT_DXT3"); break; + case D3DFMT_DXT4: tty.println("D3DFMT_DXT4"); break; + case D3DFMT_DXT5: tty.println("D3DFMT_DXT5"); break; + case D3DFMT_UNKNOWN: tty.println("D3DFMT_UNKNOWN"); break; + default: tty.println("(unknown pixel format " + fmt + ")"); break; + } + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private static final int MAGIC = 0x20534444; + + static class Header { + int size; // size of the DDSURFACEDESC structure + int flags; // determines what fields are valid + int height; // height of surface to be created + int width; // width of input surface + int pitchOrLinearSize; + int backBufferCountOrDepth; + int mipMapCountOrAux; // number of mip-map levels requested (in this context) + int alphaBitDepth; // depth of alpha buffer requested + int reserved1; // reserved + int surface; // pointer to the associated surface memory + // NOTE: following two entries are from DDCOLORKEY data structure + // Are overlaid with color for empty cubemap faces (unused in this reader) + int colorSpaceLowValue; + int colorSpaceHighValue; + int destBltColorSpaceLowValue; + int destBltColorSpaceHighValue; + int srcOverlayColorSpaceLowValue; + int srcOverlayColorSpaceHighValue; + int srcBltColorSpaceLowValue; + int srcBltColorSpaceHighValue; + // NOTE: following entries are from DDPIXELFORMAT data structure + // Are overlaid with flexible vertex format description of vertex + // buffers (unused in this reader) + int pfSize; // size of DDPIXELFORMAT structure + int pfFlags; // pixel format flags + int pfFourCC; // (FOURCC code) + // Following five entries have multiple interpretations, not just + // RGBA (but that's all we support right now) + int pfRGBBitCount; // how many bits per pixel + int pfRBitMask; // mask for red bits + int pfGBitMask; // mask for green bits + int pfBBitMask; // mask for blue bits + int pfABitMask; // mask for alpha channel + int ddsCaps1; // Texture and mip-map flags + int ddsCaps2; // Advanced capabilities including cubemap support + int ddsCapsReserved1; + int ddsCapsReserved2; + int textureStage; // stage in multitexture cascade + + void read(ByteBuffer buf) throws IOException { + int magic = buf.getInt(); + if (magic != MAGIC) { + throw new IOException("Incorrect magic number 0x" + + Integer.toHexString(magic) + + " (expected " + MAGIC + ")"); + } + + size = buf.getInt(); + flags = buf.getInt(); + height = buf.getInt(); + width = buf.getInt(); + pitchOrLinearSize = buf.getInt(); + backBufferCountOrDepth = buf.getInt(); + mipMapCountOrAux = buf.getInt(); + alphaBitDepth = buf.getInt(); + reserved1 = buf.getInt(); + surface = buf.getInt(); + colorSpaceLowValue = buf.getInt(); + colorSpaceHighValue = buf.getInt(); + destBltColorSpaceLowValue = buf.getInt(); + destBltColorSpaceHighValue = buf.getInt(); + srcOverlayColorSpaceLowValue = buf.getInt(); + srcOverlayColorSpaceHighValue = buf.getInt(); + srcBltColorSpaceLowValue = buf.getInt(); + srcBltColorSpaceHighValue = buf.getInt(); + pfSize = buf.getInt(); + pfFlags = buf.getInt(); + pfFourCC = buf.getInt(); + pfRGBBitCount = buf.getInt(); + pfRBitMask = buf.getInt(); + pfGBitMask = buf.getInt(); + pfBBitMask = buf.getInt(); + pfABitMask = buf.getInt(); + ddsCaps1 = buf.getInt(); + ddsCaps2 = buf.getInt(); + ddsCapsReserved1 = buf.getInt(); + ddsCapsReserved2 = buf.getInt(); + textureStage = buf.getInt(); + } + + // buf must be in little-endian byte order + void write(ByteBuffer buf) { + buf.putInt(MAGIC); + buf.putInt(size); + buf.putInt(flags); + buf.putInt(height); + buf.putInt(width); + buf.putInt(pitchOrLinearSize); + buf.putInt(backBufferCountOrDepth); + buf.putInt(mipMapCountOrAux); + buf.putInt(alphaBitDepth); + buf.putInt(reserved1); + buf.putInt(surface); + buf.putInt(colorSpaceLowValue); + buf.putInt(colorSpaceHighValue); + buf.putInt(destBltColorSpaceLowValue); + buf.putInt(destBltColorSpaceHighValue); + buf.putInt(srcOverlayColorSpaceLowValue); + buf.putInt(srcOverlayColorSpaceHighValue); + buf.putInt(srcBltColorSpaceLowValue); + buf.putInt(srcBltColorSpaceHighValue); + buf.putInt(pfSize); + buf.putInt(pfFlags); + buf.putInt(pfFourCC); + buf.putInt(pfRGBBitCount); + buf.putInt(pfRBitMask); + buf.putInt(pfGBitMask); + buf.putInt(pfBBitMask); + buf.putInt(pfABitMask); + buf.putInt(ddsCaps1); + buf.putInt(ddsCaps2); + buf.putInt(ddsCapsReserved1); + buf.putInt(ddsCapsReserved2); + buf.putInt(textureStage); + } + + private static int size() { + return 124; + } + + private static int pfSize() { + return 32; + } + + private static int writtenSize() { + return 128; + } + } + + private DDSImage() { + } + + private void readFromFile(File file) throws IOException { + fis = new FileInputStream(file); + chan = fis.getChannel(); + ByteBuffer buf = chan.map(FileChannel.MapMode.READ_ONLY, + 0, (int) file.length()); + readFromBuffer(buf); + } + + private void readFromBuffer(ByteBuffer buf) throws IOException { + this.buf = buf; + buf.order(ByteOrder.LITTLE_ENDIAN); + header = new Header(); + header.read(buf); + fixupHeader(); + } + + private void initFromData(int d3dFormat, + int width, + int height, + ByteBuffer[] mipmapData) throws IllegalArgumentException { + // Check size of mipmap data compared against format, width and + // height + int topmostMipmapSize = width * height; + int pitchOrLinearSize = width; + boolean isCompressed = false; + switch (d3dFormat) { + case D3DFMT_R8G8B8: topmostMipmapSize *= 3; pitchOrLinearSize *= 3; break; + case D3DFMT_A8R8G8B8: topmostMipmapSize *= 4; pitchOrLinearSize *= 4; break; + case D3DFMT_X8R8G8B8: topmostMipmapSize *= 4; pitchOrLinearSize *= 4; break; + case D3DFMT_DXT1: + case D3DFMT_DXT2: + case D3DFMT_DXT3: + case D3DFMT_DXT4: + case D3DFMT_DXT5: + topmostMipmapSize = computeCompressedBlockSize(width, height, 1, d3dFormat); + pitchOrLinearSize = topmostMipmapSize; + isCompressed = true; + break; + default: + throw new IllegalArgumentException("d3dFormat must be one of the known formats"); + } + + // Now check the mipmaps against this size + int curSize = topmostMipmapSize; + int totalSize = 0; + for (int i = 0; i < mipmapData.length; i++) { + if (mipmapData[i].remaining() != curSize) { + throw new IllegalArgumentException("Mipmap level " + i + + " didn't match expected data size (expected " + curSize + ", got " + + mipmapData[i].remaining() + ")"); + } + curSize /= 4; + totalSize += mipmapData[i].remaining(); + } + + // OK, create one large ByteBuffer to hold all of the mipmap data + totalSize += Header.writtenSize(); + ByteBuffer buf = ByteBuffer.allocate(totalSize); + buf.position(Header.writtenSize()); + for (int i = 0; i < mipmapData.length; i++) { + buf.put(mipmapData[i]); + } + this.buf = buf; + + // Allocate and initialize a Header + header = new Header(); + header.size = Header.size(); + header.flags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; + if (mipmapData.length > 1) { + header.flags |= DDSD_MIPMAPCOUNT; + header.mipMapCountOrAux = mipmapData.length; + } + header.width = width; + header.height = height; + if (isCompressed) { + header.flags |= DDSD_LINEARSIZE; + header.pfFlags |= DDPF_FOURCC; + header.pfFourCC = d3dFormat; + } else { + header.flags |= DDSD_PITCH; + // Figure out the various settings from the pixel format + header.pfFlags |= DDPF_RGB; + switch (d3dFormat) { + case D3DFMT_R8G8B8: header.pfRGBBitCount = 24; break; + case D3DFMT_A8R8G8B8: header.pfRGBBitCount = 32; header.pfFlags |= DDPF_ALPHAPIXELS; break; + case D3DFMT_X8R8G8B8: header.pfRGBBitCount = 32; break; + } + header.pfRBitMask = 0x00FF0000; + header.pfGBitMask = 0x0000FF00; + header.pfBBitMask = 0x000000FF; + if (d3dFormat == D3DFMT_A8R8G8B8) { + header.pfABitMask = 0xFF000000; + } + } + header.pitchOrLinearSize = pitchOrLinearSize; + header.pfSize = Header.pfSize(); + // Not sure whether we can get away with leaving the rest of the + // header blank + } + + // Microsoft doesn't follow their own specifications and the + // simplest conversion using the DxTex tool to e.g. a DXT3 texture + // results in an illegal .dds file without either DDSD_PITCH or + // DDSD_LINEARSIZE set in the header's flags. This code, adapted + // from the DevIL library, fixes up the header in these situations. + private void fixupHeader() { + if (isCompressed() && !isSurfaceDescFlagSet(DDSD_LINEARSIZE)) { + // Figure out how big the linear size should be + int depth = header.backBufferCountOrDepth; + if (depth == 0) { + depth = 1; + } + + header.pitchOrLinearSize = computeCompressedBlockSize(getWidth(), getHeight(), depth, getCompressionFormat()); + header.flags |= DDSD_LINEARSIZE; + } + } + + private static int computeCompressedBlockSize(int width, + int height, + int depth, + int compressionFormat) { + int blockSize = ((width + 3)/4) * ((height + 3)/4) * ((depth + 3)/4); + switch (compressionFormat) { + case D3DFMT_DXT1: blockSize *= 8; break; + default: blockSize *= 16; break; + } + return blockSize; + } + + private int mipMapWidth(int map) { + int width = getWidth(); + for (int i = 0; i < map; i++) { + width >>= 1; + } + return Math.max(width, 1); + } + + private int mipMapHeight(int map) { + int height = getHeight(); + for (int i = 0; i < map; i++) { + height >>= 1; + } + return Math.max(height, 1); + } + + private int mipMapSizeInBytes(int map) { + int width = mipMapWidth(map); + int height = mipMapHeight(map); + if (isCompressed()) { + int blockSize = (getCompressionFormat() == D3DFMT_DXT1 ? 8 : 16); + return ((width+3)/4)*((height+3)/4)*blockSize; + } else { + return width * height * (getDepth() / 8); + } + } + + private int sideSizeInBytes() { + int numLevels = getNumMipMaps(); + if (numLevels == 0) { + numLevels = 1; + } + + int size = 0; + for (int i = 0; i < numLevels; i++) { + size += mipMapSizeInBytes(i); + } + + return size; + } + + private int sideShiftInBytes(int side) { + int[] sides = { + DDSCAPS2_CUBEMAP_POSITIVEX, + DDSCAPS2_CUBEMAP_NEGATIVEX, + DDSCAPS2_CUBEMAP_POSITIVEY, + DDSCAPS2_CUBEMAP_NEGATIVEY, + DDSCAPS2_CUBEMAP_POSITIVEZ, + DDSCAPS2_CUBEMAP_NEGATIVEZ + }; + + int shift = 0; + int sideSize = sideSizeInBytes(); + for (int i = 0; i < sides.length; i++) { + int temp = sides[i]; + if ((temp & side) != 0) { + return shift; + } + + shift += sideSize; + } + + throw new RuntimeException("Illegal side: " + side); + } + + private boolean printIfRecognized(PrintStream tty, int flags, int flag, String what) { + if ((flags & flag) != 0) { + tty.println(what); + return true; + } + return false; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java new file mode 100644 index 000000000..d5f49599c --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi; + +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.FilterInputStream; +import java.io.InputStream; +import java.io.FileInputStream; +import java.io.EOFException; +import java.io.IOException; + +/** + * Little Endian Data Input Stream. + * + * This class implements an input stream filter to allow reading + * of java native datatypes from an input stream which has those + * native datatypes stored in a little endian byte order.<p> + * + * This is the sister class of the DataInputStream which allows + * for reading of java native datatypes from an input stream with + * the datatypes stored in big endian byte order.<p> + * + * This class implements the minimum required and calls DataInputStream + * for some of the required methods for DataInput.<p> + * + * Not all methods are implemented due to lack of immediatte requirement + * for that functionality. It is not clear if it is ever going to be + * functionally required to be able to read UTF data in a LittleEndianManner<p> + * + * @author Robin Luiten + * @version 1.1 15/Dec/1997 + */ +public class LEDataInputStream extends FilterInputStream implements DataInput +{ + /** + * To reuse some of the non endian dependent methods from + * DataInputStreams methods. + */ + DataInputStream dataIn; + + public LEDataInputStream(InputStream in) + { + super(in); + dataIn = new DataInputStream(in); + } + + public void close() throws IOException + { + dataIn.close(); // better close as we create it. + // this will close underlying as well. + } + + public synchronized final int read(byte b[]) throws IOException + { + return dataIn.read(b, 0, b.length); + } + + public synchronized final int read(byte b[], int off, int len) throws IOException + { + int rl = dataIn.read(b, off, len); + return rl; + } + + public final void readFully(byte b[]) throws IOException + { + dataIn.readFully(b, 0, b.length); + } + + public final void readFully(byte b[], int off, int len) throws IOException + { + dataIn.readFully(b, off, len); + } + + public final int skipBytes(int n) throws IOException + { + return dataIn.skipBytes(n); + } + + public final boolean readBoolean() throws IOException + { + int ch = dataIn.read(); + if (ch < 0) + throw new EOFException(); + return (ch != 0); + } + + public final byte readByte() throws IOException + { + int ch = dataIn.read(); + if (ch < 0) + throw new EOFException(); + return (byte)(ch); + } + + public final int readUnsignedByte() throws IOException + { + int ch = dataIn.read(); + if (ch < 0) + throw new EOFException(); + return ch; + } + + public final short readShort() throws IOException + { + int ch1 = dataIn.read(); + int ch2 = dataIn.read(); + if ((ch1 | ch2) < 0) + throw new EOFException(); + return (short)((ch1 << 0) + (ch2 << 8)); + } + + public final int readUnsignedShort() throws IOException + { + int ch1 = dataIn.read(); + int ch2 = dataIn.read(); + if ((ch1 | ch2) < 0) + throw new EOFException(); + return (ch1 << 0) + (ch2 << 8); + } + + public final char readChar() throws IOException + { + int ch1 = dataIn.read(); + int ch2 = dataIn.read(); + if ((ch1 | ch2) < 0) + throw new EOFException(); + return (char)((ch1 << 0) + (ch2 << 8)); + } + + public final int readInt() throws IOException + { + int ch1 = dataIn.read(); + int ch2 = dataIn.read(); + int ch3 = dataIn.read(); + int ch4 = dataIn.read(); + if ((ch1 | ch2 | ch3 | ch4) < 0) + throw new EOFException(); + return ((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24)); + } + + public final long readLong() throws IOException + { + int i1 = readInt(); + int i2 = readInt(); + return ((long)(i1) & 0xFFFFFFFFL) + (i2 << 32); + } + + public final float readFloat() throws IOException + { + return Float.intBitsToFloat(readInt()); + } + + public final double readDouble() throws IOException + { + return Double.longBitsToDouble(readLong()); + } + + /** + * dont call this it is not implemented. + * @return empty new string + **/ + public final String readLine() throws IOException + { + return new String(); + } + + /** + * dont call this it is not implemented + * @return empty new string + **/ + public final String readUTF() throws IOException + { + return new String(); + } + + /** + * dont call this it is not implemented + * @return empty new string + **/ + public final static String readUTF(DataInput in) throws IOException + { + return new String(); + } +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataOutputStream.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataOutputStream.java new file mode 100644 index 000000000..e1e1ca924 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataOutputStream.java @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi; + +import java.io.DataOutput; +import java.io.DataOutputStream; +import java.io.FilterOutputStream; +import java.io.OutputStream; +import java.io.IOException; + +/** + * Little Endian Data Output Stream. + * + * This class implements an output stream filter to allow writing + * of java native datatypes to an output stream which has those + * native datatypes stored in a little endian byte order.<p> + * + * This is the sister class of the DataOutputStream which allows + * for writing of java native datatypes to an output stream with + * the datatypes stored in big endian byte order.<p> + * + * This class implements the minimum required and calls DataOutputStream + * for some of the required methods for DataOutput.<p> + * + * Not all methods are implemented due to lack of immediate requirement + * for that functionality. It is not clear if it is ever going to be + * functionally required to be able to read UTF data in a LittleEndianManner<p> + * + */ +public class LEDataOutputStream extends FilterOutputStream implements DataOutput +{ + /** + * To reuse some of the non endian dependent methods from + * DataOutputStream's methods. + */ + DataOutputStream dataOut; + + public LEDataOutputStream(OutputStream out) + { + super(out); + dataOut = new DataOutputStream(out); + } + + public void close() throws IOException + { + dataOut.close(); // better close as we create it. + // this will close underlying as well. + } + + public synchronized final void write(byte b[]) throws IOException + { + dataOut.write(b, 0, b.length); + } + + public synchronized final void write(byte b[], int off, int len) throws IOException + { + dataOut.write(b, off, len); + } + + public final void write(int b) throws IOException + { + dataOut.write(b); + } + + public final void writeBoolean(boolean v) throws IOException + { + dataOut.writeBoolean(v); + } + + public final void writeByte(int v) throws IOException + { + dataOut.writeByte(v); + } + + /** Don't call this -- not implemented */ + public final void writeBytes(String s) throws IOException + { + throw new UnsupportedOperationException(); + } + + public final void writeChar(int v) throws IOException + { + dataOut.writeChar(((v >> 8) & 0xff) | + ((v & 0xff) << 8)); + } + + /** Don't call this -- not implemented */ + public final void writeChars(String s) throws IOException + { + throw new UnsupportedOperationException(); + } + + public final void writeDouble(double v) throws IOException + { + writeLong(Double.doubleToRawLongBits(v)); + } + + public final void writeFloat(float v) throws IOException + { + writeInt(Float.floatToRawIntBits(v)); + } + + public final void writeInt(int v) throws IOException + { + dataOut.writeInt((v >>> 24) | + ((v >>> 8) & 0xff00) | + ((v << 8) & 0x00ff00) | + (v << 24)); + } + + public final void writeLong(long v) throws IOException + { + writeInt((int) v); + writeInt((int) (v >>> 32)); + } + + public final void writeShort(int v) throws IOException + { + dataOut.writeShort(((v >> 8) & 0xff) | + ((v & 0xff) << 8)); + } + + /** Don't call this -- not implemented */ + public final void writeUTF(String s) throws IOException + { + throw new UnsupportedOperationException(); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java new file mode 100644 index 000000000..499dce7fb --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi; + +import java.io.*; +import java.net.*; +import java.nio.*; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.texture.*; +import com.jogamp.opengl.util.texture.spi.*; + +public class NetPbmTextureWriter implements TextureWriter { + int magic; + + public NetPbmTextureWriter() { + this(0); // auto + } + + /** + * supported magic values are:<br> + * <pre> + * magic 0 - detect by file suffix (TextureIO compliant) + * magic 6 - PPM binary RGB + * magic 7 - PAM binary RGB or RGBA + * </pre> + */ + public NetPbmTextureWriter(int magic) { + switch(magic) { + case 0: + case 6: + case 7: + break; + default: + throw new GLException("Unsupported magic: "+magic+", should be 0 (auto), 6 (PPM) or 7 (PAM)"); + } + this.magic = magic; + } + + public int getMagic() { return magic; } + + public static final String PPM = "ppm"; + public static final String PAM = "pam"; + + public String getSuffix() { return (magic==6)?PPM:PAM; } + + public boolean write(File file, + TextureData data) throws IOException { + + // file suffix selection + if (0==magic) { + if (PPM.equals(FileUtil.getFileSuffix(file))) { + magic = 6; + } else if (PAM.equals(FileUtil.getFileSuffix(file))) { + magic = 7; + } else { + return false; + } + } + + int pixelFormat = data.getPixelFormat(); + int pixelType = data.getPixelType(); + if ((pixelFormat == GL.GL_RGB || + pixelFormat == GL.GL_RGBA) && + (pixelType == GL.GL_BYTE || + pixelType == GL.GL_UNSIGNED_BYTE)) { + + int comps = ( pixelFormat == GL.GL_RGBA ) ? 4 : 3 ; + + if(magic==6 && comps==4) { + throw new IOException("NetPbmTextureWriter magic 6 (PPM) doesn't RGBA pixel format, use magic 7 (PAM)"); + } + + FileOutputStream fos = new FileOutputStream(file); + + StringBuffer header = new StringBuffer(); + header.append("P"); + header.append(magic); + header.append("\n"); + if(7==magic) { + header.append("WIDTH "); + } + header.append(data.getWidth()); + if(7==magic) { + header.append("\nHEIGHT "); + } else { + header.append(" "); + } + header.append(data.getHeight()); + if(7==magic) { + header.append("\nDEPTH "); + header.append(comps); + header.append("\nMAXVAL 255\nTUPLTYPE "); + if(pixelFormat == GL.GL_RGBA) { + header.append("RGB_ALPHA"); + } else { + header.append("RGB"); + } + header.append("\nENDHDR\n"); + } else { + header.append("\n255\n"); + } + + fos.write(header.toString().getBytes()); + + ByteBuffer buf = (ByteBuffer) data.getBuffer(); + if (buf == null) { + buf = (ByteBuffer) data.getMipmapData()[0]; + } + buf.rewind(); + + byte[] bufArray = null; + + try { + bufArray = buf.array(); + } catch (Throwable t) {} + if(null==bufArray) { + bufArray = new byte[data.getWidth()*data.getHeight()*comps]; + buf.get(bufArray); + buf.rewind(); + } + + fos.write(bufArray); + fos.close(); + + return true; + } + + throw new IOException("NetPbmTextureWriter writer doesn't support this pixel format / type (only GL_RGB/A + bytes)"); + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java new file mode 100644 index 000000000..bb5040a31 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java @@ -0,0 +1,670 @@ +/* + * Portions Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi; + +import java.io.*; +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; + +/** <p> Reads and writes SGI RGB/RGBA images. </p> + + <p> Written from <a href = + "http://astronomy.swin.edu.au/~pbourke/dataformats/sgirgb/">Paul + Bourke's adaptation</a> of the <a href = + "http://astronomy.swin.edu.au/~pbourke/dataformats/sgirgb/sgiversion.html">SGI + specification</a>. </p> +*/ + +public class SGIImage { + private Header header; + private int format; + private byte[] data; + // Used for decoding RLE-compressed images + private int[] rowStart; + private int[] rowSize; + private int rleEnd; + private byte[] tmpData; + private byte[] tmpRead; + + private static final int MAGIC = 474; + + static class Header { + short magic; // IRIS image file magic number + // This should be decimal 474 + byte storage; // Storage format + // 0 for uncompressed + // 1 for RLE compression + byte bpc; // Number of bytes per pixel channel + // Legally 1 or 2 + short dimension; // Number of dimensions + // Legally 1, 2, or 3 + // 1 means a single row, XSIZE long + // 2 means a single 2D image + // 3 means multiple 2D images + short xsize; // X size in pixels + short ysize; // Y size in pixels + short zsize; // Number of channels + // 1 indicates greyscale + // 3 indicates RGB + // 4 indicates RGB and Alpha + int pixmin; // Minimum pixel value + // This is the lowest pixel value in the image + int pixmax; // Maximum pixel value + // This is the highest pixel value in the image + int dummy; // Ignored + // Normally set to 0 + String imagename; // Image name; 80 bytes long + // Must be null terminated, therefore at most 79 bytes + int colormap; // Colormap ID + // 0 - normal mode + // 1 - dithered, 3 mits for red and green, 2 for blue, obsolete + // 2 - index colour, obsolete + // 3 - not an image but a colourmap + // 404 bytes char DUMMY Ignored + // Should be set to 0, makes the header 512 bytes. + + Header() { + magic = MAGIC; + } + + Header(DataInputStream in) throws IOException { + magic = in.readShort(); + storage = in.readByte(); + bpc = in.readByte(); + dimension = in.readShort(); + xsize = in.readShort(); + ysize = in.readShort(); + zsize = in.readShort(); + pixmin = in.readInt(); + pixmax = in.readInt(); + dummy = in.readInt(); + byte[] tmpname = new byte[80]; + in.read(tmpname); + int numChars = 0; + while (tmpname[numChars++] != 0); + imagename = new String(tmpname, 0, numChars); + colormap = in.readInt(); + byte[] tmp = new byte[404]; + in.read(tmp); + } + + public String toString() { + return ("magic: " + magic + + " storage: " + (int) storage + + " bpc: " + (int) bpc + + " dimension: " + dimension + + " xsize: " + xsize + + " ysize: " + ysize + + " zsize: " + zsize + + " pixmin: " + pixmin + + " pixmax: " + pixmax + + " imagename: " + imagename + + " colormap: " + colormap); + } + } + + private SGIImage(Header header) { + this.header = header; + } + + /** Reads an SGI image from the specified file. */ + public static SGIImage read(String filename) throws IOException { + return read(new FileInputStream(filename)); + } + + /** Reads an SGI image from the specified InputStream. */ + public static SGIImage read(InputStream in) throws IOException { + DataInputStream dIn = new DataInputStream(new BufferedInputStream(in)); + + Header header = new Header(dIn); + SGIImage res = new SGIImage(header); + res.decodeImage(dIn); + return res; + } + + /** Writes this SGIImage to the specified file name. If + flipVertically is set, outputs the scanlines from top to bottom + rather than the default bottom to top order. */ + public void write(String filename, boolean flipVertically) throws IOException { + write(new File(filename), flipVertically); + } + + /** Writes this SGIImage to the specified file. If flipVertically is + set, outputs the scanlines from top to bottom rather than the + default bottom to top order. */ + public void write(File file, boolean flipVertically) throws IOException { + writeImage(file, data, header.xsize, header.ysize, header.zsize, flipVertically); + } + + /** Creates an SGIImage from the specified data in either RGB or + RGBA format. */ + public static SGIImage createFromData(int width, + int height, + boolean hasAlpha, + byte[] data) { + Header header = new Header(); + header.xsize = (short) width; + header.ysize = (short) height; + header.zsize = (short) (hasAlpha ? 4 : 3); + SGIImage image = new SGIImage(header); + image.data = data; + return image; + } + + /** Determines from the magic number whether the given InputStream + points to an SGI RGB image. The given InputStream must return + true from markSupported() and support a minimum of two bytes + of read-ahead. */ + public static boolean isSGIImage(InputStream in) throws IOException { + if (!(in instanceof BufferedInputStream)) { + in = new BufferedInputStream(in); + } + if (!in.markSupported()) { + throw new IOException("Can not test non-destructively whether given InputStream is an SGI RGB image"); + } + DataInputStream dIn = new DataInputStream(in); + dIn.mark(4); + short magic = dIn.readShort(); + dIn.reset(); + return (magic == MAGIC); + } + + /** Returns the width of the image. */ + public int getWidth() { + return header.xsize; + } + + /** Returns the height of the image. */ + public int getHeight() { + return header.ysize; + } + + /** Returns the OpenGL format for this texture; e.g. GL.GL_RGB or GL.GL_RGBA. */ + public int getFormat() { + return format; + } + + /** Returns the raw data for this texture in the correct + (bottom-to-top) order for calls to glTexImage2D. */ + public byte[] getData() { return data; } + + public String toString() { + return header.toString(); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void decodeImage(DataInputStream in) throws IOException { + if (header.storage == 1) { + // Read RLE compression data; row starts and sizes + int x = header.ysize * header.zsize; + rowStart = new int[x]; + rowSize = new int[x]; + rleEnd = 4 * 2 * x + 512; + for (int i = 0; i < x; i++) { + rowStart[i] = in.readInt(); + } + for (int i = 0; i < x; i++) { + rowSize[i] = in.readInt(); + } + tmpRead = new byte[header.xsize * 256]; + } + tmpData = readAll(in); + + int xsize = header.xsize; + int ysize = header.ysize; + int zsize = header.zsize; + int lptr = 0; + + data = new byte[xsize * ysize * 4]; + byte[] rbuf = new byte[xsize]; + byte[] gbuf = new byte[xsize]; + byte[] bbuf = new byte[xsize]; + byte[] abuf = new byte[xsize]; + for (int y = 0; y < ysize; y++) { + if (zsize >= 4) { + getRow(rbuf, y, 0); + getRow(gbuf, y, 1); + getRow(bbuf, y, 2); + getRow(abuf, y, 3); + rgbatorgba(rbuf, gbuf, bbuf, abuf, data, lptr); + } else if (zsize == 3) { + getRow(rbuf, y, 0); + getRow(gbuf, y, 1); + getRow(bbuf, y, 2); + rgbtorgba(rbuf, gbuf, bbuf, data, lptr); + } else if (zsize == 2) { + getRow(rbuf, y, 0); + getRow(abuf, y, 1); + latorgba(rbuf, abuf, data, lptr); + } else { + getRow(rbuf, y, 0); + bwtorgba(rbuf, data, lptr); + } + lptr += 4 * xsize; + } + rowStart = null; + rowSize = null; + tmpData = null; + tmpRead = null; + format = GL.GL_RGBA; + header.zsize = 4; + } + + private void getRow(byte[] buf, int y, int z) { + if (header.storage == 1) { + int offs = rowStart[y + z * header.ysize] - rleEnd; + System.arraycopy(tmpData, offs, tmpRead, 0, rowSize[y + z * header.ysize]); + int iPtr = 0; + int oPtr = 0; + for (;;) { + byte pixel = tmpRead[iPtr++]; + int count = (int) (pixel & 0x7F); + if (count == 0) { + return; + } + if ((pixel & 0x80) != 0) { + while ((count--) > 0) { + buf[oPtr++] = tmpRead[iPtr++]; + } + } else { + pixel = tmpRead[iPtr++]; + while ((count--) > 0) { + buf[oPtr++] = pixel; + } + } + } + } else { + int offs = (y * header.xsize) + (z * header.xsize * header.ysize); + System.arraycopy(tmpData, offs, buf, 0, header.xsize); + } + } + + private void bwtorgba(byte[] b, byte[] dest, int lptr) { + for (int i = 0; i < b.length; i++) { + dest[4 * i + lptr + 0] = b[i]; + dest[4 * i + lptr + 1] = b[i]; + dest[4 * i + lptr + 2] = b[i]; + dest[4 * i + lptr + 3] = (byte) 0xFF; + } + } + + private void latorgba(byte[] b, byte[] a, byte[] dest, int lptr) { + for (int i = 0; i < b.length; i++) { + dest[4 * i + lptr + 0] = b[i]; + dest[4 * i + lptr + 1] = b[i]; + dest[4 * i + lptr + 2] = b[i]; + dest[4 * i + lptr + 3] = a[i]; + } + } + + private void rgbtorgba(byte[] r, byte[] g, byte[] b, byte[] dest, int lptr) { + for (int i = 0; i < b.length; i++) { + dest[4 * i + lptr + 0] = r[i]; + dest[4 * i + lptr + 1] = g[i]; + dest[4 * i + lptr + 2] = b[i]; + dest[4 * i + lptr + 3] = (byte) 0xFF; + } + } + + private void rgbatorgba(byte[] r, byte[] g, byte[] b, byte[] a, byte[] dest, int lptr) { + for (int i = 0; i < b.length; i++) { + dest[4 * i + lptr + 0] = r[i]; + dest[4 * i + lptr + 1] = g[i]; + dest[4 * i + lptr + 2] = b[i]; + dest[4 * i + lptr + 3] = a[i]; + } + } + + private static byte imgref(byte[] i, + int x, + int y, + int z, + int xs, + int ys, + int zs) { + return i[(xs*ys*z)+(xs*y)+x]; + } + + + private void writeHeader(DataOutputStream stream, + int xsize, int ysize, int zsize, boolean rle) throws IOException { + // effects: outputs the 512-byte IRIS RGB header to STREAM, using xsize, + // ysize, and depth as the dimensions of the image. NOTE that + // the following defaults are used: + // STORAGE = 1 (storage format = RLE) + // BPC = 1 (# bytes/channel) + // DIMENSION = 3 + // PIXMIN = 0 + // PIXMAX = 255 + // IMAGENAME = <80 nulls> + // COLORMAP = 0 + // See ftp://ftp.sgi.com/pub/sgi/SGIIMAGESPEC for more details. + + // write out MAGIC, STORAGE, BPC + stream.writeShort(474); + stream.write((rle ? 1 : 0)); + stream.write(1); + + // write out DIMENSION + stream.writeShort(3); + + // write XSIZE, YSIZE, ZSIZE + stream.writeShort(xsize); + stream.writeShort(ysize); + stream.writeShort(zsize); + + // write PIXMIN, PIXMAX + stream.writeInt(0); + stream.writeInt(255); + + // write DUMMY + stream.writeInt(0); + + // write IMAGENAME + for (int i = 0; i < 80; i++) + stream.write(0); + + // write COLORMAP + stream.writeInt(0); + + // write DUMMY (404 bytes) + for (int i = 0; i < 404; i++) + stream.write(0); + } + + private void writeImage(File file, + byte[] data, + int xsize, + int ysize, + int zsize, + boolean yflip) throws IOException { + // Input data is in RGBRGBRGB or RGBARGBARGBA format; first unswizzle it + byte[] tmpData = new byte[xsize * ysize * zsize]; + int dest = 0; + for (int i = 0; i < zsize; i++) { + for (int j = i; j < (xsize * ysize * zsize); j += zsize) { + tmpData[dest++] = data[j]; + } + } + data = tmpData; + + // requires: DATA must be an array of size XSIZE * YSIZE * ZSIZE, + // indexed in the following manner: + // data[0] ...data[xsize-1] == first row of first channel + // data[xsize]...data[2*xsize-1] == second row of first channel + // ... data[(ysize - 1) * xsize]...data[(ysize * xsize) - 1] == + // last row of first channel + // Later channels follow the same format. + // *** NOTE that "first row" is defined by the BOTTOM ROW of + // the image. That is, the origin is in the lower left corner. + // effects: writes out an SGI image to FILE, RLE-compressed, INCLUDING + // header, of dimensions (xsize, ysize, zsize), and containing + // the data in DATA. If YFLIP is set, outputs the data in DATA + // in reverse order vertically (equivalent to a flip about the + // x axis). + + // Build the offset tables + int[] starttab = new int[ysize * zsize]; + int[] lengthtab = new int[ysize * zsize]; + + // Temporary buffer for holding RLE data. + // Note that this makes the assumption that RLE-compressed data will + // never exceed twice the size of the input data. + // There are surely formal proofs about how big the RLE buffer should + // be, as well as what the optimal look-ahead size is (i.e. don't switch + // copy/repeat modes for less than N repeats). However, I'm going from + // empirical evidence here; the break-even point seems to be a look- + // ahead of 3. (That is, if the three values following this one are all + // the same as the current value, switch to repeat mode.) + int lookahead = 3; + byte[] rlebuf = new byte[2 * xsize * ysize * zsize]; + + int cur_loc = 0; // current offset location. + int ptr = 0; + int total_size = 0; + int ystart = 0; + int yincr = 1; + int yend = ysize; + + if (yflip) { + ystart = ysize - 1; + yend = -1; + yincr = -1; + } + + boolean DEBUG = false; + + for (int z = 0; z < zsize; z++) { + for (int y = ystart; y != yend; y += yincr) { + // RLE-compress each row. + + int x = 0; + byte count = 0; + boolean repeat_mode = false; + boolean should_switch = false; + int start_ptr = ptr; + int num_ptr = ptr++; + byte repeat_val = 0; + + while (x < xsize) { + // see if we should switch modes + should_switch = false; + if (repeat_mode) { + if (imgref(data, x, y, z, xsize, ysize, zsize) != repeat_val) { + should_switch = true; + } + } else { + // look ahead to see if we should switch to repeat mode. + // stay within the scanline for the lookahead + if ((x + lookahead) < xsize) { + should_switch = true; + for (int i = 1; i <= lookahead; i++) { + if (DEBUG) + System.err.println("left side was " + ((int) imgref(data, x, y, z, xsize, ysize, zsize)) + + ", right side was " + (int)imgref(data, x+i, y, z, xsize, ysize, zsize)); + + if (imgref(data, x, y, z, xsize, ysize, zsize) != + imgref(data, x+i, y, z, xsize, ysize, zsize)) + should_switch = false; + } + } + } + + if (should_switch || (count == 127)) { + // update the number of elements we repeated/copied + if (x > 0) { + if (repeat_mode) + rlebuf[num_ptr] = count; + else + rlebuf[num_ptr] = (byte) (count | 0x80); + } + // perform mode switch if necessary; output repeat_val if + // switching FROM repeat mode, and set it if switching + // TO repeat mode. + if (repeat_mode) { + if (should_switch) + repeat_mode = false; + rlebuf[ptr++] = repeat_val; + } else { + if (should_switch) + repeat_mode = true; + repeat_val = imgref(data, x, y, z, xsize, ysize, zsize); + } + + if (x > 0) { + // reset the number pointer + num_ptr = ptr++; + // reset number of bytes copied + count = 0; + } + } + + // if not in repeat mode, copy element to ptr + if (!repeat_mode) { + rlebuf[ptr++] = imgref(data, x, y, z, xsize, ysize, zsize); + } + count++; + + if (x == xsize - 1) { + // Need to store the number of pixels we copied/repeated. + if (repeat_mode) { + rlebuf[num_ptr] = count; + // If we ended the row in repeat mode, store the + // repeated value + rlebuf[ptr++] = repeat_val; + } + else + rlebuf[num_ptr] = (byte) (count | 0x80); + + // output zero counter for the last value in the row + rlebuf[ptr++] = 0; + } + + x++; + } + // output this row's length into the length table + int rowlen = ptr - start_ptr; + if (yflip) + lengthtab[ysize*z+(ysize-y-1)] = rowlen; + else + lengthtab[ysize*z+y] = rowlen; + // add to the start table, and update the current offset + if (yflip) + starttab[ysize*z+(ysize-y-1)] = cur_loc; + else + starttab[ysize*z+y] = cur_loc; + cur_loc += rowlen; + } + } + + // Now we have the offset tables computed, as well as the RLE data. + // Output this information to the file. + total_size = ptr; + + if (DEBUG) + System.err.println("total_size was " + total_size); + + DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); + + writeHeader(stream, xsize, ysize, zsize, true); + + int SIZEOF_INT = 4; + for (int i = 0; i < (ysize * zsize); i++) + stream.writeInt(starttab[i] + 512 + (2 * ysize * zsize * SIZEOF_INT)); + for (int i = 0; i < (ysize * zsize); i++) + stream.writeInt(lengthtab[i]); + for (int i = 0; i < total_size; i++) + stream.write(rlebuf[i]); + + stream.close(); + } + + private byte[] readAll(DataInputStream in) throws IOException { + byte[] dest = new byte[16384]; + int pos = 0; + int numRead = 0; + + boolean done = false; + + do { + numRead = in.read(dest, pos, dest.length - pos); + if (pos == dest.length) { + // Resize destination buffer + byte[] newDest = new byte[2 * dest.length]; + System.arraycopy(dest, 0, newDest, 0, pos); + dest = newDest; + } + if (numRead > 0) { + pos += numRead; + } + + done = ((numRead == -1) || (in.available() == 0)); + } while (!done); + + // Trim destination buffer + if (pos != dest.length) { + byte[] finalDest = new byte[pos]; + System.arraycopy(dest, 0, finalDest, 0, pos); + dest = finalDest; + } + + return dest; + } + + // Test case + /* + import java.awt.image.*; + import javax.swing.*; + + public static void main(String[] args) { + for (int i = 0; i < args.length; i++) { + try { + System.out.println(args[i] + ":"); + SGIImage image = SGIImage.read(args[i]); + System.out.println(image); + BufferedImage img = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); + WritableRaster raster = img.getRaster(); + DataBufferByte db = (DataBufferByte) raster.getDataBuffer(); + byte[] src = image.getData(); + byte[] dest = db.getData(); + for (int j = 0; j < src.length; j += 4) { + dest[j + 0] = src[j + 3]; + dest[j + 1] = src[j + 2]; + dest[j + 2] = src[j + 1]; + dest[j + 3] = src[j + 0]; + } + // System.arraycopy(src, 0, dest, 0, src.length); + ImageIcon icon = new ImageIcon(img); + JLabel label = new JLabel(); + label.setIcon(icon); + JFrame frame = new JFrame(args[i]); + frame.getContentPane().add(label); + frame.pack(); + frame.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + */ +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java new file mode 100644 index 000000000..16ba538b5 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi; + +import java.io.*; +import java.nio.*; +import java.nio.channels.*; +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.texture.spi.*; +import com.jogamp.opengl.util.texture.*; + +/** + * Targa image reader and writer adapted from sources of the <a href = + * "http://java.sun.com/products/jimi/">Jimi</a> image I/O class library. + * + * <P> + * + * Image decoder for image data stored in TGA file format. + * Currently only the original TGA file format is supported. This is + * because the new TGA format has data at the end of the file, getting + * to the end of a file in an InputStream orient environment presents + * several difficulties which are avoided at the moment. + * + * <P> + * + * This is a simple decoder and is only setup to load a single image + * from the input stream + * + * <P> + * + * @author Robin Luiten + * @author Kenneth Russell + * @version $Revision: 1768 $ + */ + +public class TGAImage { + private Header header; + private int format; + private int bpp; + private ByteBuffer data; + + private TGAImage(Header header) { + this.header = header; + } + + /** + * This class reads in all of the TGA image header in addition it also + * reads in the imageID field as it is convenient to handle that here. + * + * @author Robin Luiten + * @version 1.1 + */ + public static class Header { + /** Set of possible file format TGA types */ + public final static int TYPE_NEW = 0; + public final static int TYPE_OLD = 1; + public final static int TYPE_UNK = 2; // cant rewind stream so unknown for now. + + /** Set of possible image types in TGA file */ + public final static int NO_IMAGE = 0; // no image data + public final static int UCOLORMAPPED = 1; // uncompressed color mapped image + public final static int UTRUECOLOR = 2; // uncompressed true color image + public final static int UBLACKWHITE = 3; // uncompressed black and white image + public final static int COLORMAPPED = 9; // compressed color mapped image + public final static int TRUECOLOR = 10; // compressed true color image + public final static int BLACKWHITE = 11; // compressed black and white image + + /** Field image descriptor bitfield values definitions */ + public final static int ID_ATTRIBPERPIXEL = 0xF; + public final static int ID_RIGHTTOLEFT = 0x10; + public final static int ID_TOPTOBOTTOM = 0x20; + public final static int ID_INTERLEAVE = 0xC0; + + /** Field image descriptor / interleave values */ + public final static int I_NOTINTERLEAVED = 0; + public final static int I_TWOWAY = 1; + public final static int I_FOURWAY = 2; + + /** Type of this TGA file format */ + private int tgaType; + + /** initial TGA image data fields */ + private int idLength; // byte value + private int colorMapType; // byte value + private int imageType; // byte value + + /** TGA image colour map fields */ + private int firstEntryIndex; + private int colorMapLength; + private byte colorMapEntrySize; + + /** TGA image specification fields */ + private int xOrigin; + private int yOrigin; + private int width; + private int height; + private byte pixelDepth; + private byte imageDescriptor; + + private byte[] imageIDbuf; + private String imageID; + + // For construction from user data + Header() { + tgaType = TYPE_OLD; // dont try and get footer. + } + + Header(LEDataInputStream in) throws IOException { + int ret; + + tgaType = TYPE_OLD; // dont try and get footer. + + // initial header fields + idLength = in.readUnsignedByte(); + colorMapType = in.readUnsignedByte(); + imageType = in.readUnsignedByte(); + + // color map header fields + firstEntryIndex = in.readUnsignedShort(); + colorMapLength = in.readUnsignedShort(); + colorMapEntrySize = in.readByte(); + + // TGA image specification fields + xOrigin = in.readUnsignedShort(); + yOrigin = in.readUnsignedShort(); + width = in.readUnsignedShort(); + height = in.readUnsignedShort(); + pixelDepth = in.readByte(); + imageDescriptor = in.readByte(); + + if (idLength > 0) { + imageIDbuf = new byte[idLength]; + in.read(imageIDbuf, 0, idLength); + imageID = new String(imageIDbuf, "US-ASCII"); + } + } + + public int tgaType() { return tgaType; } + + /** initial TGA image data fields */ + public int idLength() { return idLength; } + public int colorMapType() { return colorMapType; } + public int imageType() { return imageType; } + + /** TGA image colour map fields */ + public int firstEntryIndex() { return firstEntryIndex; } + public int colorMapLength() { return colorMapLength; } + public byte colorMapEntrySize() { return colorMapEntrySize; } + + /** TGA image specification fields */ + public int xOrigin() { return xOrigin; } + public int yOrigin() { return yOrigin; } + public int width() { return width; } + public int height() { return height; } + public byte pixelDepth() { return pixelDepth; } + public byte imageDescriptor() { return imageDescriptor; } + + /** bitfields in imageDescriptor */ + public byte attribPerPixel() { return (byte)(imageDescriptor & ID_ATTRIBPERPIXEL); } + public boolean rightToLeft() { return ((imageDescriptor & ID_RIGHTTOLEFT) != 0); } + public boolean topToBottom() { return ((imageDescriptor & ID_TOPTOBOTTOM) != 0); } + public byte interleave() { return (byte)((imageDescriptor & ID_INTERLEAVE) >> 6); } + + public byte[] imageIDbuf() { return imageIDbuf; } + public String imageID() { return imageID; } + + public String toString() { + return "TGA Header " + + " id length: " + idLength + + " color map type: "+ colorMapType + + " image type: "+ imageType + + " first entry index: " + firstEntryIndex + + " color map length: " + colorMapLength + + " color map entry size: " + colorMapEntrySize + + " x Origin: " + xOrigin + + " y Origin: " + yOrigin + + " width: "+ width + + " height: "+ height + + " pixel depth: "+ pixelDepth + + " image descriptor: "+ imageDescriptor + + (imageIDbuf == null ? "" : (" ID String: " + imageID)); + } + + public int size() { return 18 + idLength; } + + // buf must be in little-endian byte order + private void write(ByteBuffer buf) { + buf.put((byte) idLength); + buf.put((byte) colorMapType); + buf.put((byte) imageType); + buf.putShort((short) firstEntryIndex); + buf.putShort((short) colorMapLength); + buf.put((byte) colorMapEntrySize); + buf.putShort((short) xOrigin); + buf.putShort((short) yOrigin); + buf.putShort((short) width); + buf.putShort((short) height); + buf.put((byte) pixelDepth); + buf.put((byte) imageDescriptor); + if (idLength > 0) { + try { + byte[] chars = imageID.getBytes("US-ASCII"); + buf.put(chars); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + } + } + + + /** + * Identifies the image type of the tga image data and loads + * it into the JimiImage structure. This was taken from the + * prototype and modified for the new Jimi structure + */ + private void decodeImage(LEDataInputStream dIn) throws IOException { + switch (header.imageType()) { + case Header.UCOLORMAPPED: + throw new IOException("TGADecoder Uncompressed Colormapped images not supported"); + + case Header.UTRUECOLOR: // pixelDepth 15, 16, 24 and 32 + switch (header.pixelDepth) { + case 16: + throw new IOException("TGADecoder Compressed 16-bit True Color images not supported"); + + case 24: + case 32: + decodeRGBImageU24_32(dIn); + break; + } + break; + + case Header.UBLACKWHITE: + throw new IOException("TGADecoder Uncompressed Grayscale images not supported"); + + case Header.COLORMAPPED: + throw new IOException("TGADecoder Compressed Colormapped images not supported"); + + case Header.TRUECOLOR: + throw new IOException("TGADecoder Compressed True Color images not supported"); + + case Header.BLACKWHITE: + throw new IOException("TGADecoder Compressed Grayscale images not supported"); + } + } + + /** + * This assumes that the body is for a 24 bit or 32 bit for a + * RGB or ARGB image respectively. + */ + private void decodeRGBImageU24_32(LEDataInputStream dIn) throws IOException { + int i; // row index + int j; // column index + int y; // output row index + int raw; // index through the raw input buffer + int rawWidth = header.width() * (header.pixelDepth() / 8); + byte[] rawBuf = new byte[rawWidth]; + byte[] tmpData = new byte[rawWidth * header.height()]; + + for (i = 0; i < header.height(); ++i) { + dIn.readFully(rawBuf, 0, rawWidth); + + if (header.topToBottom()) + y = header.height - i - 1; // range 0 to (header.height - 1) + else + y = i; + + System.arraycopy(rawBuf, 0, tmpData, y * rawWidth, rawBuf.length); + } + + GL gl = GLContext.getCurrentGL(); + if (header.pixelDepth() == 24) { + bpp=3; + if(gl.isGL2GL3()) { + format = GL2GL3.GL_BGR; + } else { + format = GL.GL_RGB; + swapBGR(tmpData, rawWidth, header.height(), bpp); + } + } else { + assert header.pixelDepth() == 32; + bpp=4; + + if(gl.isGL2GL3()) { + format = GL2GL3.GL_BGRA; + } else { + format = GL.GL_RGBA; + swapBGR(tmpData, rawWidth, header.height(), bpp); + } + } + + data = ByteBuffer.wrap(tmpData); + } + + private static void swapBGR(byte[] data, int bWidth, int height, int bpp) { + byte r,b; + int k; + for(int i=0; i<height; ++i) { + for(int j=0; j<bWidth; j+=bpp) { + k=i*bWidth+j; + b=data[k+0]; + r=data[k+2]; + data[k+0]=r; + data[k+2]=b; + } + } + } + + /** Returns the width of the image. */ + public int getWidth() { return header.width(); } + + /** Returns the height of the image. */ + public int getHeight() { return header.height(); } + + /** Returns the OpenGL format for this texture; e.g. GL.GL_BGR or GL.GL_BGRA. */ + public int getGLFormat() { return format; } + + /** Returns the bytes per pixel */ + public int getBytesPerPixel() { return bpp; } + + /** Returns the raw data for this texture in the correct + (bottom-to-top) order for calls to glTexImage2D. */ + public ByteBuffer getData() { return data; } + + /** Reads a Targa image from the specified file. */ + public static TGAImage read(String filename) throws IOException { + return read(new FileInputStream(filename)); + } + + /** Reads a Targa image from the specified InputStream. */ + public static TGAImage read(InputStream in) throws IOException { + LEDataInputStream dIn = new LEDataInputStream(new BufferedInputStream(in)); + + Header header = new Header(dIn); + TGAImage res = new TGAImage(header); + res.decodeImage(dIn); + return res; + } + + /** Writes the image in Targa format to the specified file name. */ + public void write(String filename) throws IOException { + write(new File(filename)); + } + + /** Writes the image in Targa format to the specified file. */ + public void write(File file) throws IOException { + FileOutputStream stream = new FileOutputStream(file); + FileChannel chan = stream.getChannel(); + ByteBuffer buf = ByteBuffer.allocate(header.size()); + buf.order(ByteOrder.LITTLE_ENDIAN); + header.write(buf); + buf.rewind(); + chan.write(buf); + chan.write(data); + data.rewind(); + chan.force(true); + chan.close(); + stream.close(); + } + + /** Creates a TGAImage from data supplied by the end user. Shares + data with the passed ByteBuffer. Assumes the data is already in + the correct byte order for writing to disk, i.e., BGR or + BGRA. */ + public static TGAImage createFromData(int width, + int height, + boolean hasAlpha, + boolean topToBottom, + ByteBuffer data) { + Header header = new Header(); + header.imageType = Header.UTRUECOLOR; + header.width = width; + header.height = height; + header.pixelDepth = (byte) (hasAlpha ? 32 : 24); + header.imageDescriptor = (byte) (topToBottom ? Header.ID_TOPTOBOTTOM : 0); + // Note ID not supported + TGAImage ret = new TGAImage(header); + ret.data = data; + return ret; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TextureProvider.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TextureProvider.java new file mode 100644 index 000000000..88018edbe --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TextureProvider.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi; + +import java.io.*; +import java.net.*; +import javax.media.opengl.GLProfile; + +import com.jogamp.opengl.util.texture.*; + +/** Plug-in interface to TextureIO to support reading OpenGL textures + from new file formats. For all methods, either internalFormat or + pixelFormat may be 0 in which case they must be inferred as + e.g. RGB or RGBA depending on the file contents. +*/ + +public interface TextureProvider { + + /** + * Produces a TextureData object from a file, or returns null if the + * file format was not supported by this TextureProvider. Does not + * do any OpenGL-related work. The resulting TextureData can be + * converted into an OpenGL texture in a later step. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param file the file from which to read the texture data + * + * @param internalFormat the OpenGL internal format to be used for + * the texture, or 0 if it should be inferred + * from the file's contents + * + * @param pixelFormat the OpenGL pixel format to be used for + * the texture, or 0 if it should be inferred + * from the file's contents + * + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * + * @param fileSuffix the file suffix to be used as a hint to the + * provider to more quickly decide whether it + * can handle the file, or null if the + * provider should infer the type from the + * file's contents + * + * @throws IOException if an error occurred while reading the file + */ + public TextureData newTextureData(GLProfile glp, File file, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException; + + /** + * Produces a TextureData object from a stream, or returns null if + * the file format was not supported by this TextureProvider. Does + * not do any OpenGL-related work. The resulting TextureData can be + * converted into an OpenGL texture in a later step. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param stream the stream from which to read the texture data + * + * @param internalFormat the OpenGL internal format to be used for + * the texture, or 0 if it should be inferred + * from the file's contents + * + * @param pixelFormat the OpenGL pixel format to be used for + * the texture, or 0 if it should be inferred + * from the file's contents + * + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * + * @param fileSuffix the file suffix to be used as a hint to the + * provider to more quickly decide whether it + * can handle the file, or null if the + * provider should infer the type from the + * file's contents + * + * @throws IOException if an error occurred while reading the stream + */ + public TextureData newTextureData(GLProfile glp, InputStream stream, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException; + + /** + * Produces a TextureData object from a URL, or returns null if the + * file format was not supported by this TextureProvider. Does not + * do any OpenGL-related work. The resulting TextureData can be + * converted into an OpenGL texture in a later step. + * + * @param glp the OpenGL Profile this texture data should be + * created for. + * @param url the URL from which to read the texture data + * + * @param internalFormat the OpenGL internal format to be used for + * the texture, or 0 if it should be inferred + * from the file's contents + * + * @param pixelFormat the OpenGL pixel format to be used for + * the texture, or 0 if it should be inferred + * from the file's contents + * + * @param mipmap whether mipmaps should be produced for this + * texture either by autogenerating them or + * reading them from the file. Some file formats + * support multiple mipmaps in a single file in + * which case those mipmaps will be used rather + * than generating them. + * + * @param fileSuffix the file suffix to be used as a hint to the + * provider to more quickly decide whether it + * can handle the file, or null if the + * provider should infer the type from the + * file's contents + * + * @throws IOException if an error occurred while reading the URL + */ + public TextureData newTextureData(GLProfile glp, URL url, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException; +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TextureWriter.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TextureWriter.java new file mode 100644 index 000000000..55527cef5 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TextureWriter.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi; + +import java.io.*; + +import com.jogamp.opengl.util.texture.*; + +/** Plug-in interface to TextureIO to support writing OpenGL textures + to new file formats. */ + +public interface TextureWriter { + /** Writes the given TextureData to the passed file. Returns true if + this TextureWriter successfully handled the writing of the file, + otherwise false. May throw IOException if either this writer did + not support certain parameters of the TextureData or if an I/O + error occurred. */ + public boolean write(File file, + TextureData data) throws IOException; +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureProvider.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureProvider.java new file mode 100644 index 000000000..6e2f1b992 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureProvider.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi.awt; + +import java.awt.Graphics; +import java.awt.image.*; +import java.io.*; +import java.net.*; +import javax.imageio.*; +import javax.media.opengl.GLProfile; + +import jogamp.opengl.Debug; +import com.jogamp.opengl.util.texture.*; +import com.jogamp.opengl.util.texture.awt.*; +import com.jogamp.opengl.util.texture.spi.*; + +public class IIOTextureProvider implements TextureProvider { + private static final boolean DEBUG = Debug.debug("TextureIO"); + + public TextureData newTextureData(GLProfile glp, File file, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + BufferedImage img = ImageIO.read(file); + if (img == null) { + return null; + } + if (DEBUG) { + System.out.println("TextureIO.newTextureData(): BufferedImage type for " + file + " = " + + img.getType()); + } + return new AWTTextureData(glp, internalFormat, pixelFormat, mipmap, img); + } + + public TextureData newTextureData(GLProfile glp, InputStream stream, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + BufferedImage img = ImageIO.read(stream); + if (img == null) { + return null; + } + if (DEBUG) { + System.out.println("TextureIO.newTextureData(): BufferedImage type for stream = " + + img.getType()); + } + return new AWTTextureData(glp, internalFormat, pixelFormat, mipmap, img); + } + + public TextureData newTextureData(GLProfile glp, URL url, + int internalFormat, + int pixelFormat, + boolean mipmap, + String fileSuffix) throws IOException { + InputStream stream = url.openStream(); + try { + return newTextureData(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix); + } finally { + stream.close(); + } + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java new file mode 100644 index 000000000..405211204 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.util.texture.spi.awt; + +import java.awt.Graphics; +import java.awt.image.*; +import java.io.*; +import java.net.*; +import java.nio.*; +import javax.imageio.*; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.awt.*; +import com.jogamp.opengl.util.texture.*; +import com.jogamp.opengl.util.texture.spi.*; + +public class IIOTextureWriter implements TextureWriter { + public boolean write(File file, + TextureData data) throws IOException { + int pixelFormat = data.getPixelFormat(); + int pixelType = data.getPixelType(); + if ((pixelFormat == GL.GL_RGB || + pixelFormat == GL.GL_RGBA) && + (pixelType == GL.GL_BYTE || + pixelType == GL.GL_UNSIGNED_BYTE)) { + // Convert TextureData to appropriate BufferedImage + // FIXME: almost certainly not obeying correct pixel order + BufferedImage image = new BufferedImage(data.getWidth(), data.getHeight(), + (pixelFormat == GL.GL_RGB) ? + BufferedImage.TYPE_3BYTE_BGR : + BufferedImage.TYPE_4BYTE_ABGR); + byte[] imageData = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); + ByteBuffer buf = (ByteBuffer) data.getBuffer(); + if (buf == null) { + buf = (ByteBuffer) data.getMipmapData()[0]; + } + buf.rewind(); + buf.get(imageData); + buf.rewind(); + + // Swizzle image components to be correct + if (pixelFormat == GL.GL_RGB) { + for (int i = 0; i < imageData.length; i += 3) { + byte red = imageData[i + 0]; + byte blue = imageData[i + 2]; + imageData[i + 0] = blue; + imageData[i + 2] = red; + } + } else { + for (int i = 0; i < imageData.length; i += 4) { + byte red = imageData[i + 0]; + byte green = imageData[i + 1]; + byte blue = imageData[i + 2]; + byte alpha = imageData[i + 3]; + imageData[i + 0] = alpha; + imageData[i + 1] = blue; + imageData[i + 2] = green; + imageData[i + 3] = red; + } + } + + // Flip image vertically for the user's convenience + ImageUtil.flipImageVertically(image); + + // Happened to notice that writing RGBA images to JPEGS is broken + if (TextureIO.JPG.equals(FileUtil.getFileSuffix(file)) && + image.getType() == BufferedImage.TYPE_4BYTE_ABGR) { + BufferedImage tmpImage = new BufferedImage(image.getWidth(), image.getHeight(), + BufferedImage.TYPE_3BYTE_BGR); + Graphics g = tmpImage.getGraphics(); + g.drawImage(image, 0, 0, null); + g.dispose(); + image = tmpImage; + } + + return ImageIO.write(image, FileUtil.getFileSuffix(file), file); + } + + throw new IOException("ImageIO writer doesn't support this pixel format / type (only GL_RGB/A + bytes)"); + } +} diff --git a/src/jogl/classes/com/jogamp/openmax/OMXEventListener.java b/src/jogl/classes/com/jogamp/openmax/OMXEventListener.java new file mode 100644 index 000000000..08cfeccde --- /dev/null +++ b/src/jogl/classes/com/jogamp/openmax/OMXEventListener.java @@ -0,0 +1,14 @@ + +package com.jogamp.openmax; + +public interface OMXEventListener { + + static final int EVENT_CHANGE_SIZE = 1<<0; + static final int EVENT_CHANGE_FPS = 1<<1; + static final int EVENT_CHANGE_BPS = 1<<2; + static final int EVENT_CHANGE_LENGTH = 1<<3; + + public void changedAttributes(OMXInstance omx, int event_mask); + +} + diff --git a/src/jogl/classes/com/jogamp/openmax/OMXInstance.java b/src/jogl/classes/com/jogamp/openmax/OMXInstance.java new file mode 100644 index 000000000..fcd055f8b --- /dev/null +++ b/src/jogl/classes/com/jogamp/openmax/OMXInstance.java @@ -0,0 +1,509 @@ + +package com.jogamp.openmax; + +import javax.media.opengl.*; +import javax.media.opengl.glu.GLU; +import com.jogamp.opengl.util.texture.*; + +import jogamp.opengl.egl.EGL; +import jogamp.opengl.egl.EGLContext; +import jogamp.opengl.egl.EGLDrawable; +import jogamp.opengl.egl.EGLExt; + +import java.net.URL; +import java.nio.ByteBuffer; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.*; + +public class OMXInstance { + private long moviePtr = 0; + + protected String path = null; + protected URL url = null; + + // *** Texture impl + protected Texture texture = null; // holds the last fetched texture + + protected float playSpeed = 1.0f; + + /** + * The following data is set by the setStream function, + * and may be set by the native OMX implementation, + * in case the stream attributes changes (see attributesUpdated) + */ + protected int width = 0; + protected int height = 0; + protected int fps = 0; // frames per seconds + protected long bps = 0; // bits per seconds + protected long totalFrames = 0; // duration in frames + protected String acodec = null; + protected String vcodec = null; + + /** + * Old stream values, before the last attributesUpdated) + */ + protected int o_width = 0; + protected int o_height = 0; + protected int o_fps = 0; // frames per seconds + protected long o_bps = 0; // bits per seconds + protected long o_totalFrames = 0; // duration in frames + + static class EGLImageTexture { + public EGLImageTexture(com.jogamp.opengl.util.texture.Texture t, long i, long s) { + texture = t; image = i; sync = s; + } + public String toString() { + return "EGLImageTexture[" + texture + ", image " + image + ", sync "+sync+"]"; + } + protected com.jogamp.opengl.util.texture.Texture texture; + protected long image; + protected long sync; + } + private EGLImageTexture[] eglImgTexs=null; + private HashMap eglImgTexsMap = new HashMap(); + protected int textureNum; + + private EGLExt eglExt = null; + private long eglSurface = 0; + private long eglDisplay = 0; + private long eglContext = 0; + private int sWidth=0, sHeight=0; + + private GL initGLData(GL gl) { + if(null==gl) { + throw new RuntimeException("No current GL"); + } + EGLContext eglCtx = (EGLContext) gl.getContext(); + if(null==eglCtx) { + throw new RuntimeException("No current EGL context"); + } + EGLDrawable eglDrawable = (EGLDrawable) eglCtx.getGLDrawable(); + if(null==eglDrawable) { + throw new RuntimeException("No valid drawable"); + } + eglContext = eglCtx.getHandle(); + eglDisplay = eglDrawable.getDisplay(); + eglSurface = eglDrawable.getHandle(); + eglExt = eglCtx.getEGLExt(); + if(null==eglExt) { + throw new RuntimeException("No valid EGLExt"); + } + + int iTmp[] = new int[1]; + EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_WIDTH, iTmp, 0); + sWidth=iTmp[0]; + EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_HEIGHT, iTmp, 0); + sHeight=iTmp[0]; + System.out.println("surface size: "+width+"x"+height); + System.out.println(eglDrawable); + System.out.println(eglCtx); + System.out.println("EGL Extensions : "+EGL.eglQueryString(eglDisplay, EGL.EGL_EXTENSIONS)); + System.out.println("EGL CLIENT APIs: "+EGL.eglQueryString(eglDisplay, EGL.EGL_CLIENT_APIS)); + return gl; + } + + public OMXInstance() { + moviePtr = _createInstance(); + if(0==moviePtr) { + throw new GLException("Couldn't create OMXInstance"); + } + } + native long _createInstance(); + + public synchronized void setStream(int textureNum, URL u) { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + this.textureNum=textureNum; + url = u; + if (url == null) { + System.out.println("setURL (null)"); + stop(); + return; + } + path=null; + if (url.getProtocol() == null || "file".equals(url.getProtocol())) { + // CV only accepts absolute paths + try { + File file = new File(url.getPath()); + if (!file.exists()) { + throw new RuntimeException(new FileNotFoundException(file.toString())); + } + path = file.getCanonicalPath(); + System.out.println("setURL: path "+path); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + path = replaceAll(path, "\\", "/").trim(); + if(null==path) { + throw new RuntimeException("Couldn't parse stream URL: "+url); + } + System.out.println("setURL: clean path "+path); + + System.out.println("setURL: p1 "+this); + _setStream(moviePtr, textureNum, path); + System.out.println("setURL: p2 "+this); + } + native void _setStream(long moviePtr, int textureNum, String path); + + public synchronized void setStreamAllEGLImageTexture2D(GL gl) { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + if(null==vcodec) { + return; + } + gl = initGLData(gl); + + if(null!=eglImgTexs) { + removeAllEGLImageTexture2D(gl); + } else { + eglImgTexs = new EGLImageTexture[textureNum]; + } + + int[] tmp = new int[1]; + int tex, e; + + errorCheckGL(gl, "i.1"); + gl.glEnable(gl.GL_TEXTURE_2D); + errorCheckGL(gl, "i.2"); + + for(int i=0; i<textureNum; i++) { + String s0 = String.valueOf(i); + gl.glGenTextures(1, tmp, 0); + tex=tmp[0]; + if( (e=gl.glGetError()) != GL.GL_NO_ERROR || 0>tex ) { + throw new RuntimeException("TextureName creation failed: "+e); + } + gl.glBindTexture(gl.GL_TEXTURE_2D, tex); + + // create space for buffer with a texture + gl.glTexImage2D( + gl.GL_TEXTURE_2D, // target + 0, // level + gl.GL_RGBA, // internal format + width, // width + height, // height + 0, // border + gl.GL_RGBA, // format + gl.GL_UNSIGNED_BYTE, // type + null); // pixels -- will be provided later + gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST); + gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST); + + long image=0, sync=0; + + // create EGLImage from texture + tmp[0] = EGL.EGL_NONE; + image = eglExt.eglCreateImageKHR( + eglDisplay, + eglContext, + eglExt.EGL_GL_TEXTURE_2D_KHR, + tex, + tmp, 0); + if (0==image) { + throw new RuntimeException("EGLImage creation failed: "+EGL.eglGetError()+", dpy "+eglDisplay+", ctx "+eglContext+", tex "+tex); + } + + // Create sync object so that we can be sure that gl has finished + // rendering the EGLImage texture before we tell OpenMAX to fill + // it with a new frame. + tmp[0] = EGL.EGL_NONE; + sync = eglExt.eglCreateSyncKHR( + eglDisplay, + eglExt.EGL_SYNC_FENCE_KHR, tmp, 0); + + _setStreamEGLImageTexture2D(moviePtr, i, tex, image, sync); + + eglImgTexs[i] = new EGLImageTexture( + com.jogamp.opengl.util.texture.TextureIO.newTexture(tex, + javax.media.opengl.GL2.GL_TEXTURE_2D, + width, + height, + width, + height, + true), + image, sync); + eglImgTexsMap.put(new Integer(tex), eglImgTexs[i]); + } + gl.glDisable(gl.GL_TEXTURE_2D); + } + native void _setStreamEGLImageTexture2D(long moviePtr, int i, int tex, long image, long sync); + + public synchronized void activateStream() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + _activateStream(moviePtr); + } + native void _activateStream(long moviePtr); + + public synchronized void detachVideoRenderer() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + _detachVideoRenderer(moviePtr); + } + native void _detachVideoRenderer(long moviePtr); // stop before + + public synchronized void attachVideoRenderer() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + _attachVideoRenderer(moviePtr); + } + native void _attachVideoRenderer(long moviePtr); // detach before + + public synchronized void setPlaySpeed(float rate) { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + _setPlaySpeed(moviePtr, rate); + playSpeed = rate; + } + public synchronized float getPlaySpeed() { + return playSpeed; + } + native void _setPlaySpeed(long moviePtr, float rate); + + /** @return time position after issuing the command */ + public synchronized float play() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _play(moviePtr); + } + native float _play(long moviePtr); + + /** @return time position after issuing the command */ + public synchronized float pause() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _pause(moviePtr); + } + native float _pause(long moviePtr); + + /** @return time position after issuing the command */ + public synchronized float stop() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _stop(moviePtr); + } + native float _stop(long moviePtr); + + /** @return time position after issuing the command */ + public synchronized float seek(float pos) { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _seek(moviePtr, pos); + } + native float _seek(long moviePtr, float position); + + public synchronized Texture getLastTextureID() { + return texture; + } + public synchronized Texture getNextTextureID() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + texture=null; + EGLImageTexture eglImgTex = (EGLImageTexture) eglImgTexsMap.get(new Integer(_getNextTextureID(moviePtr))); + if(null!=eglImgTex) { + texture = eglImgTex.texture; + } + return texture; + } + native int _getNextTextureID(long moviePtr); + + public synchronized float getCurrentPosition() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _getCurrentPosition(moviePtr); + } + native float _getCurrentPosition(long moviePtr); + + public synchronized void destroy(GL gl) { + removeAllEGLImageTexture2D(gl); + if (moviePtr != 0) { + long ptr = moviePtr; + moviePtr = 0; + _destroyInstance(ptr); + + eglExt=null; + eglSurface=0; + eglDisplay=0; + eglContext=0; + } + } + protected synchronized void finalize() { + if (moviePtr != 0) { + destroy(null); + } + } + native void _destroyInstance(long moviePtr); + + public synchronized boolean isValid() { + return (moviePtr != 0); + } + public synchronized String getPath() { + return path; + } + public synchronized URL getURL() { + return url; + } + public synchronized String getVideoCodec() { + return vcodec; + } + public synchronized String getAudioCodec() { + return acodec; + } + public synchronized long getTotalFrames() { + return totalFrames; + } + public synchronized long getBitrate() { + return bps; + } + public synchronized int getFramerate() { + return fps; + } + public synchronized int getWidth() { + return width; + } + public synchronized int getHeight() { + return height; + } + public synchronized String toString() { + return "OMXInstance [ stream [ video [ "+vcodec+", "+width+"x"+height+", "+fps+"fps, "+bps+"bsp, "+totalFrames+"f ] ] ]"; + } + + /** + * Java callback method issued by the native OMX backend + */ + private void saveAttributes() { + o_width = width; + o_height = height; + o_fps = fps; + o_bps = bps; + o_totalFrames = totalFrames; + } + + private void attributesUpdated() { + int event_mask = 0; + if( o_width != width || o_height != height ) { + event_mask |= OMXEventListener.EVENT_CHANGE_SIZE; + } + if( o_fps != fps ) { + event_mask |= OMXEventListener.EVENT_CHANGE_FPS; + } + if( o_bps != bps ) { + event_mask |= OMXEventListener.EVENT_CHANGE_BPS; + } + if( o_totalFrames != totalFrames ) { + event_mask |= OMXEventListener.EVENT_CHANGE_LENGTH; + } + if(0==event_mask) { + return; + } + + ArrayList listeners = null; + synchronized(this) { + listeners = eventListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + OMXEventListener l = (OMXEventListener) i.next(); + l.changedAttributes(this, event_mask); + } + } + + private String replaceAll(String orig, String search, String repl) { + String dest=null; + // In case replaceAll / java.util.regex.* is not supported (-> CVM) + int i=0,j; + dest = new String(); + while((j=orig.indexOf(search, i))>=0) { + dest=dest.concat(orig.substring(i, j)); + dest=dest.concat(repl); + i=j+1; + } + return dest.concat(orig.substring(i, orig.length())); + } + + private void removeAllEGLImageTexture2D(GL gl) { + if (moviePtr != 0) { + if(null==eglExt) { + throw new RuntimeException("No valid EGLExt"); + } + + texture = null; + for(int i=0; i<textureNum; i++) { + if(null!=eglImgTexs[i]) { + if(0!=eglImgTexs[i].image) { + eglExt.eglDestroyImageKHR( + eglDisplay, + eglImgTexs[i].image); + } + if(0!=eglImgTexs[i].sync) { + eglExt.eglDestroySyncKHR(eglDisplay, eglImgTexs[i].sync); + } + if(null!=gl) { + eglImgTexs[i].texture.destroy(gl); + } + eglImgTexs[i]=null; + } + } + eglImgTexsMap.clear(); + } + } + + private void errorCheckGL(GL gl, String s) { + int e; + if( (e=gl.glGetError()) != GL.GL_NO_ERROR ) { + System.out.println("GL Error: ("+s+"): "+e); + } + } + + private void errorCheckEGL(String s) { + int e; + if( (e=EGL.eglGetError()) != EGL.EGL_SUCCESS ) { + System.out.println("EGL Error: ("+s+"): "+e); + } + } + + + // + // OMXEventListener Support + // + + public synchronized void addEventListener(OMXEventListener l) { + if(l == null) { + return; + } + ArrayList newEventListeners = (ArrayList) eventListeners.clone(); + newEventListeners.add(l); + eventListeners = newEventListeners; + } + + public synchronized void removeEventListener(OMXEventListener l) { + if (l == null) { + return; + } + ArrayList newEventListeners = (ArrayList) eventListeners.clone(); + newEventListeners.remove(l); + eventListeners = newEventListeners; + } + + public synchronized OMXEventListener[] getEventListeners() { + return (OMXEventListener[]) eventListeners.toArray(); + } + + private ArrayList eventListeners = new ArrayList(); + +} + diff --git a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java new file mode 100644 index 000000000..9352ad4f3 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2003-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +import javax.media.nativewindow.NativeWindowException; +import jogamp.opengl.Debug; +import java.util.List; +import javax.media.nativewindow.CapabilitiesImmutable; + +/** <P> The default implementation of the {@link + GLCapabilitiesChooser} interface, which provides consistent visual + selection behavior across platforms. The precise algorithm is + deliberately left loosely specified. Some properties are: </P> + + <UL> + + <LI> As long as there is at least one available non-null + GLCapabilities which matches the "stereo" option, will return a + valid index. + + <LI> Attempts to match as closely as possible the given + GLCapabilities, but will select one with fewer capabilities (i.e., + lower color depth) if necessary. + + <LI> Prefers hardware-accelerated visuals to + non-hardware-accelerated. + + <LI> If there is no exact match, prefers a more-capable visual to + a less-capable one. + + <LI> If there is more than one exact match, chooses an arbitrary + one. + + <LI> May select the opposite of a double- or single-buffered + visual (based on the user's request) in dire situations. + + <LI> Color depth (including alpha) mismatches are weighted higher + than depth buffer mismatches, which are in turn weighted higher + than accumulation buffer (including alpha) and stencil buffer + depth mismatches. + + <LI> If a valid windowSystemRecommendedChoice parameter is + supplied, chooses that instead of using the cross-platform code. + + </UL> +*/ + +public class DefaultGLCapabilitiesChooser implements GLCapabilitiesChooser { + private static final boolean DEBUG = Debug.debug("CapabilitiesChooser"); + + public int chooseCapabilities(final CapabilitiesImmutable desired, + final List /*<CapabilitiesImmutable>*/ available, + final int windowSystemRecommendedChoice) { + if ( null == desired ) { + throw new NativeWindowException("Null desired capabilities"); + } + if ( 0 == available.size() ) { + throw new NativeWindowException("Empty available capabilities"); + } + + final GLCapabilitiesImmutable gldes = (GLCapabilitiesImmutable) desired; + final int availnum = available.size(); + + if (DEBUG) { + System.err.println("Desired: " + gldes); + System.err.println("Available: " + availnum); + for (int i = 0; i < available.size(); i++) { + System.err.println(i + ": " + available.get(i)); + } + System.err.println("Window system's recommended choice: " + windowSystemRecommendedChoice); + } + + if (windowSystemRecommendedChoice >= 0 && + windowSystemRecommendedChoice < availnum && + null != available.get(windowSystemRecommendedChoice)) { + if (DEBUG) { + System.err.println("Choosing window system's recommended choice of " + windowSystemRecommendedChoice); + System.err.println(available.get(windowSystemRecommendedChoice)); + } + return windowSystemRecommendedChoice; + } + + // Create score array + int[] scores = new int[availnum]; + int NO_SCORE = -9999999; + int DOUBLE_BUFFER_MISMATCH_PENALTY = 1000; + int STENCIL_MISMATCH_PENALTY = 500; + // Pseudo attempt to keep equal rank penalties scale-equivalent + // (e.g., stencil mismatch is 3 * accum because there are 3 accum + // components) + int COLOR_MISMATCH_PENALTY_SCALE = 36; + int DEPTH_MISMATCH_PENALTY_SCALE = 6; + int ACCUM_MISMATCH_PENALTY_SCALE = 1; + int STENCIL_MISMATCH_PENALTY_SCALE = 3; + for (int i = 0; i < scores.length; i++) { + scores[i] = NO_SCORE; + } + // Compute score for each + for (int i = 0; i < availnum; i++) { + GLCapabilitiesImmutable cur = (GLCapabilitiesImmutable) available.get(i); + if (cur == null) { + continue; + } + if (gldes.isOnscreen() != cur.isOnscreen()) { + continue; + } + if (!gldes.isOnscreen() && gldes.isPBuffer() && !cur.isPBuffer()) { + continue; // only skip if requested Offscreen && PBuffer, but no PBuffer available + } + if (gldes.getStereo() != cur.getStereo()) { + continue; + } + int score = 0; + // Compute difference in color depth + // (Note that this decides the direction of all other penalties) + score += (COLOR_MISMATCH_PENALTY_SCALE * + ((cur.getRedBits() + cur.getGreenBits() + cur.getBlueBits() + cur.getAlphaBits()) - + (gldes.getRedBits() + gldes.getGreenBits() + gldes.getBlueBits() + gldes.getAlphaBits()))); + // Compute difference in depth buffer depth + score += (DEPTH_MISMATCH_PENALTY_SCALE * sign(score) * + Math.abs(cur.getDepthBits() - gldes.getDepthBits())); + // Compute difference in accumulation buffer depth + score += (ACCUM_MISMATCH_PENALTY_SCALE * sign(score) * + Math.abs((cur.getAccumRedBits() + cur.getAccumGreenBits() + cur.getAccumBlueBits() + cur.getAccumAlphaBits()) - + (gldes.getAccumRedBits() + gldes.getAccumGreenBits() + gldes.getAccumBlueBits() + gldes.getAccumAlphaBits()))); + // Compute difference in stencil bits + score += STENCIL_MISMATCH_PENALTY_SCALE * sign(score) * (cur.getStencilBits() - gldes.getStencilBits()); + if (cur.getDoubleBuffered() != gldes.getDoubleBuffered()) { + score += sign(score) * DOUBLE_BUFFER_MISMATCH_PENALTY; + } + if ((gldes.getStencilBits() > 0) && (cur.getStencilBits() == 0)) { + score += sign(score) * STENCIL_MISMATCH_PENALTY; + } + scores[i] = score; + } + // Now prefer hardware-accelerated visuals by pushing scores of + // non-hardware-accelerated visuals out + boolean gotHW = false; + int maxAbsoluteHWScore = 0; + for (int i = 0; i < availnum; i++) { + int score = scores[i]; + if (score == NO_SCORE) { + continue; + } + GLCapabilitiesImmutable cur = (GLCapabilitiesImmutable) available.get(i); + if (cur.getHardwareAccelerated()) { + int absScore = Math.abs(score); + if (!gotHW || + (absScore > maxAbsoluteHWScore)) { + gotHW = true; + maxAbsoluteHWScore = absScore; + } + } + } + if (gotHW) { + for (int i = 0; i < availnum; i++) { + int score = scores[i]; + if (score == NO_SCORE) { + continue; + } + GLCapabilitiesImmutable cur = (GLCapabilitiesImmutable) available.get(i); + if (!cur.getHardwareAccelerated()) { + if (score <= 0) { + score -= maxAbsoluteHWScore; + } else if (score > 0) { + score += maxAbsoluteHWScore; + } + scores[i] = score; + } + } + } + + if (DEBUG) { + System.err.print("Scores: ["); + for (int i = 0; i < availnum; i++) { + if (i > 0) { + System.err.print(","); + } + System.err.print(" " + scores[i]); + } + System.err.println(" ]"); + } + + // Ready to select. Choose score closest to 0. + int scoreClosestToZero = NO_SCORE; + int chosenIndex = -1; + for (int i = 0; i < availnum; i++) { + int score = scores[i]; + if (score == NO_SCORE) { + continue; + } + // Don't substitute a positive score for a smaller negative score + if ((scoreClosestToZero == NO_SCORE) || + (Math.abs(score) < Math.abs(scoreClosestToZero) && + ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) { + scoreClosestToZero = score; + chosenIndex = i; + } + } + if (chosenIndex < 0) { + throw new NativeWindowException("Unable to select one of the provided GLCapabilities"); + } + if (DEBUG) { + System.err.println("Chosen index: " + chosenIndex); + System.err.println("Chosen capabilities:"); + System.err.println(available.get(chosenIndex)); + } + + return chosenIndex; + } + + private static int sign(int score) { + if (score < 0) { + return -1; + } + return 1; + } + +} diff --git a/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java b/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java new file mode 100644 index 000000000..2c8c7cca3 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java @@ -0,0 +1,194 @@ +/** + * 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 javax.media.opengl; + +/** + * An animator control interface, + * which implementation may drive a {@link javax.media.opengl.GLAutoDrawable} animation. + */ +public interface GLAnimatorControl { + + /** + * @return Time of the first display call in milliseconds. + * This value is reset if started or resumed. + * + * @see #start() + * @see #resume() + */ + long getStartTime(); + + /** + * @return Time of the last display call in milliseconds. + * This value is reset if started or resumed. + * + * @see #start() + * @see #resume() + */ + long getCurrentTime(); + + /** + * @return Duration <code>getCurrentTime() - getStartTime()</code>. + * + * @see #getStartTime() + * @see #getCurrentTime() + */ + long getDuration(); + + + /** + * @return Number of frame cycles displayed + * since the first display call, ie <code>getStartTime()</code>. + * This value is reset if started or resumed. + * + * @see #start() + * @see #resume() + */ + int getTotalFrames(); + + /** Reset all performance counter (startTime, currentTime, frame number) */ + public void resetCounter(); + + /** + * Indicates whether this animator is running, ie. has been started and not stopped. + * + * @see #start() + * @see #stop() + * @see #pause() + * @see #resume() + */ + boolean isStarted(); + + /** + * Indicates whether this animator is running and animating,<br> + * the latter is true if it has {@link GLAutoDrawable}s to render and is not paused. + * + * @see #start() + * @see #stop() + * @see #pause() + * @see #resume() + */ + boolean isAnimating(); + + /** + * Indicates whether this animator is running and paused. + * + * @see #start() + * @see #stop() + * @see #pause() + * @see #resume() + */ + boolean isPaused(); + + /** + * @return The animation thread if running, otherwise null. + * + * @see #start() + * @see #stop() + */ + Thread getThread(); + + /** + * Starts this animator, if not running. + * <P> + * In most situations this method blocks until + * completion, except when called from the animation thread itself + * or in some cases from an implementation-internal thread like the + * AWT event queue thread. + * <P> + * If started, all counters (time, frames, ..) are reset to zero. + * + * @return true is started due to this call, + * otherwise false, ie started already or unable to start. + * + * @see #stop() + * @see #isAnimating() + * @see #getThread() + */ + boolean start(); + + /** + * Stops this animator. + * <P> + * In most situations this method blocks until + * completion, except when called from the animation thread itself + * or in some cases from an implementation-internal thread like the + * AWT event queue thread. + * + * @return true is stopped due to this call, + * otherwise false, ie not started or unable to stop. + * + * @see #start() + * @see #isAnimating() + * @see #getThread() + */ + boolean stop(); + + /** + * Pauses this animator. + * <P> + * In most situations this method blocks until + * completion, except when called from the animation thread itself + * or in some cases from an implementation-internal thread like the + * AWT event queue thread. + * + * @return false if if not started or already paused, otherwise true + * + * @see #resume() + * @see #isAnimating() + */ + boolean pause(); + + /** + * Resumes animation if paused. + * <P> + * In most situations this method blocks until + * completion, except when called from the animation thread itself + * or in some cases from an implementation-internal thread like the + * AWT event queue thread. + * <P> + * If resumed, all counters (time, frames, ..) are reset to zero. + * + * @return false if if not started or not paused, otherwise true + * + * @see #pause() + * @see #isAnimating() + */ + boolean resume(); + + /** + * Removes a drawable from the animator's list of rendering drawables.<br> + * This method should get called in case a drawable becomes invalid, + * and will not be recovered.<br> + * This allows the animator thread to become idle in case the last drawable + * has reached it's end of life.<br> + * + * @param drawable the to be removed drawable + */ + void remove(GLAutoDrawable drawable); +} diff --git a/src/jogl/classes/javax/media/opengl/GLArrayData.java b/src/jogl/classes/javax/media/opengl/GLArrayData.java new file mode 100644 index 000000000..6c8122f27 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLArrayData.java @@ -0,0 +1,141 @@ +/** + * 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 javax.media.opengl; + +import java.nio.*; + +/** + * + * The total number of bytes hold by the referenced buffer is: + * getComponentSize()* getComponentNumber() * getElementNumber() + * + */ +public interface GLArrayData { + + /** + * Returns true if this data set is intended for a GLSL vertex shader attribute, + * otherwise false, ie intended for fixed function vertex pointer + */ + public boolean isVertexAttribute(); + + /** + * The index of the predefined array index, see list below, + * or -1 in case of a shader attribute array. + * + * @see javax.media.opengl.GL2#GL_VERTEX_ARRAY + * @see javax.media.opengl.GL2#GL_NORMAL_ARRAY + * @see javax.media.opengl.GL2#GL_COLOR_ARRAY + * @see javax.media.opengl.GL2#GL_TEXTURE_COORD_ARRAY + */ + public int getIndex(); + + /** + * The name of the reflecting shader array attribute. + */ + public String getName(); + + /** + * Set a new name for this array. + */ + public void setName(String newName); + + + /** + * Returns the shader attribute location for this name, + * -1 if not yet determined + */ + public int getLocation(); + + /** + * Sets the determined location of the shader attribute + * This is usually done within ShaderState. + * + * @see com.jogamp.opengl.util.glsl.ShaderState#glVertexAttribPointer(GL2ES2, GLArrayData) + */ + public void setLocation(int v); + + /** + * Determines wheather the data is server side (VBO), + * or a client side array (false). + */ + public boolean isVBO(); + + /** + * The offset, if it's an VBO, otherwise -1 + */ + public long getOffset(); + + /** + * The VBO name, if it's an VBO, otherwise -1 + */ + public int getVBOName(); + + /** + * The Buffer holding the data, may be null in case of VBO + */ + public Buffer getBuffer(); + + /** + * The number of components per element + */ + public int getComponentNumber(); + + /** + * The component's GL data type, ie. GL_FLOAT + */ + public int getComponentType(); + + /** + * The components size in bytes + */ + public int getComponentSize(); + + /** + * Return the number of elements. + */ + public int getElementNumber(); + + /** + * True, if GL shall normalize fixed point data while converting + * them into float + */ + public boolean getNormalized(); + + /** + * The distance to the next payload, + * allowing interleaved arrays. + */ + public int getStride(); + + public String toString(); + + public void destroy(GL gl); + +} + diff --git a/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java new file mode 100644 index 000000000..cf24d1028 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +import jogamp.opengl.Debug; +import java.security.*; + +/** A higher-level abstraction than {@link GLDrawable} which supplies + an event based mechanism ({@link GLEventListener}) for performing + OpenGL rendering. A GLAutoDrawable automatically creates a primary + rendering context which is associated with the GLAutoDrawable for + the lifetime of the object. This context has the {@link + GLContext#setSynchronized synchronized} property enabled so that + calls to {@link GLContext#makeCurrent makeCurrent} will block if + the context is current on another thread. This allows the internal + GLContext for the GLAutoDrawable to be used both by the event + based rendering mechanism as well by end users directly.<P> + + The implementation shall initialize itself as soon as possible, + ie if the attached {@link javax.media.nativewindow.NativeSurface NativeSurface} becomes visible/realized. + The following protocol shall be satisfied: + <ul> + <li> Create the {@link GLDrawable} with the requested {@link GLCapabilities}</li> + <li> Notify {@link GLDrawable} to validate the {@link GLCapabilities} by calling {@link GLDrawable#setRealized setRealized(true)}.</li> + <li> Create the new {@link GLContext}.</li> + <li> Initialize all OpenGL resources by calling {@link GLEventListener#init init(..)} for all + registered {@link GLEventListener}s. This can be done immediatly, or with the followup {@link #display display(..)} call.</li> + <li> Send a reshape event by calling {@link GLEventListener#reshape reshape(..)} for all + registered {@link GLEventListener}s. This shall be done after the {@link GLEventListener#init init(..)} calls.</li> + </ul><P> + + Another implementation detail is the drawable reconfiguration. One use case is where a window is being + dragged to another screen with a different pixel configuration, ie {@link GLCapabilities}. The implementation + shall be able to detect such cases in conjunction with the associated {@link javax.media.nativewindow.NativeSurface NativeSurface}.<br> + For example, AWT's {@link java.awt.Canvas} 's {@link java.awt.Canvas#getGraphicsConfiguration getGraphicsConfiguration()} + is capable to determine a display device change. This is demonstrated within {@link javax.media.opengl.awt.GLCanvas}'s + and NEWT's <code>AWTCanvas</code> {@link javax.media.opengl.awt.GLCanvas#getGraphicsConfiguration getGraphicsConfiguration()} + specialization. Another demonstration is NEWT's {@link javax.media.nativewindow.NativeWindow NativeWindow} + implementation on the Windows platform, which utilizes the native platform's <i>MonitorFromWindow(HWND)</i> function.<br> + All OpenGL resources shall be regenerated, while the drawable's {@link GLCapabilities} has + to be choosen again. The following protocol shall be satisfied. + <ul> + <li> Controlled disposal:</li> + <ul> + <li> Dispose all OpenGL resources by calling {@link GLEventListener#dispose dispose(..)} for all + registered {@link GLEventListener}s.</li> + <li> Destroy the {@link GLContext}.</li> + <li> Notify {@link GLDrawable} of the invalid state by calling {@link GLDrawable#setRealized setRealized(false)}.</li> + </ul> + <li> Controlled regeneration:</li> + <ul> + <li> Create the new {@link GLDrawable} with the requested {@link GLCapabilities} + <li> Notify {@link GLDrawable} to revalidate the {@link GLCapabilities} by calling {@link GLDrawable#setRealized setRealized(true)}.</li> + <li> Create the new {@link GLContext}.</li> + <li> Initialize all OpenGL resources by calling {@link GLEventListener#init init(..)} for all + registered {@link GLEventListener}s. This can be done immediatly, or with the followup {@link #display display(..)} call.</li> + <li> Send a reshape event by calling {@link GLEventListener#reshape reshape(..)} for all + registered {@link GLEventListener}s. This shall be done after the {@link GLEventListener#init init(..)} calls.</li> + </ul> + </ul> + Note: Current graphics driver keep the surface configuration for a given window, even if the window is moved to + a monitor with a different pixel configuration, ie 32bpp to 16bpp. However, it is best to not assume such behavior + and make your application comply with the above protocol.<P> + + However, to not introduce to much breakage with older applications and because of the situation + mentioned above, the <code>boolean</code> system property <code>jogl.screenchange.action</code> will control the + screen change action as follows:<br> + + <PRE> + -Djogl.screenchange.action=false Disable the drawable reconfiguration (the default) + -Djogl.screenchange.action=true Enable the drawable reconfiguration + </PRE> + */ +public interface GLAutoDrawable extends GLDrawable { + /** Flag reflecting wheather the drawable reconfiguration will be issued in + * case a screen device change occured, e.g. in a multihead environment, + * where you drag the window to another monitor. */ + public static final boolean SCREEN_CHANGE_ACTION_ENABLED = Debug.getBooleanProperty("jogl.screenchange.action", true, AccessController.getContext()); + + /** + * Returns the context associated with this drawable. The returned + * context will be synchronized. + * Don't rely on it's identity, the context may change. + */ + public GLContext getContext(); + + /** + * Associate a new context to this drawable. + */ + public void setContext(GLContext context); + + /** Adds a {@link GLEventListener} to the end of this drawable queue. + The listeners are notified of events in the order of the queue. */ + public void addGLEventListener(GLEventListener listener); + + /** + * Adds a {@link GLEventListener} at the given index of this drawable queue. + * The listeners are notified of events in the order of the queue. + * @param index Position where the listener will be inserted. + * Should be within (0 <= index && index <= size()). + * An index value of -1 is interpreted as the end of the list, size(). + * @param listener The GLEventListener object to be inserted + * @throws IndexOutOfBoundsException If the index is not within (0 <= index && index <= size()), or -1 + */ + public void addGLEventListener(int index, GLEventListener listener) + throws IndexOutOfBoundsException; + + /** Removes a {@link GLEventListener} from this drawable. Note that + if this is done from within a particular drawable's {@link + GLEventListener} handler (reshape, display, etc.) that it is not + guaranteed that all other listeners will be evaluated properly + during this update cycle. */ + public void removeGLEventListener(GLEventListener listener); + + /** + * <p> + * Registers the usage of an animator, an {@link javax.media.opengl.GLAnimatorControl} implementation. + * The animator will be queried whether it's animating, ie periodically issuing {@link #display()} calls or not.</p><br> + * <p> + * This method shall be called by an animator implementation only,<br> + * e.g. {@link com.jogamp.opengl.util.Animator#add(javax.media.opengl.GLAutoDrawable)}, passing it's control implementation,<br> + * and {@link com.jogamp.opengl.util.Animator#remove(javax.media.opengl.GLAutoDrawable)}, passing <code>null</code>.</p><br> + * <p> + * Impacts {@link #display()} and {@link #invoke(boolean, GLRunnable)} semantics.</p><br> + * + * @param animator <code>null</code> reference indicates no animator is using + * this <code>GLAutoDrawable</code>,<br> + * a valid reference indicates an animator is using this <code>GLAutoDrawable</code>. + * + * @throws GLException if an animator is already registered. + * @see #display() + * @see #invoke(boolean, GLRunnable) + * @see javax.media.opengl.GLAnimatorControl + */ + public abstract void setAnimator(GLAnimatorControl animatorControl) throws GLException; + + /** + * @return the registered {@link javax.media.opengl.GLAnimatorControl} implementation, using this <code>GLAutoDrawable</code>. + * + * @see #setAnimator(javax.media.opengl.GLAnimatorControl) + * @see javax.media.opengl.GLAnimatorControl + */ + public GLAnimatorControl getAnimator(); + + /** + * <p> + * Enqueues a one-shot {@link javax.media.opengl.GLRunnable}, + * which will be executed with the next {@link #display()} call.</p> + * <p> + * If a {@link javax.media.opengl.GLAnimatorControl} is registered, or if it's not animating, the default situation,<br> + * or if the current thread is the animator thread,<br> + * a {@link #display()} call has to be issued after enqueue the <code>GLRunnable</code>.<br> + * No extra synchronization must be performed in case <code>wait</code> is true, since it is executed in the current thread.</p> + * <p> + * If {@link javax.media.opengl.GLAnimatorControl} is registered and is animating,<br> + * no call of {@link #display()} must be issued, since the animator thread will performs it.<br> + * If <code>wait</code> is true, the implementation must wait until the <code>GLRunnable</code> is executed.<br> + * </p><br> + * + * @see #setAnimator(javax.media.opengl.GLAnimatorControl) + * @see #display() + * @see javax.media.opengl.GLRunnable + */ + public void invoke(boolean wait, GLRunnable glRunnable); + + /** Destroys all resources associated with this GLAutoDrawable, + inclusive the GLContext. + If a window is attached to it's implementation, it shall be closed. + Causes disposing of all OpenGL resources + by calling {@link GLEventListener#dispose dispose(..)} for all + registered {@link GLEventListener}s. Called automatically by the + window system toolkit upon receiving a destroy notification. This + routine may be called manually. */ + public void destroy(); + + /** + * <p> + * Causes OpenGL rendering to be performed for this GLAutoDrawable + * in the following order: + * <ul> + * <li> Calling {@link GLEventListener#display display(..)} for all + * registered {@link GLEventListener}s. </li> + * <li> Executes all one-shot {@link javax.media.opengl.GLRunnable}, + * enqueued via {@link #invoke(boolean, GLRunnable)}.</li> + * </ul></p> + * <p> + * May be called periodically by a running {@link javax.media.opengl.GLAnimatorControl} implementation,<br> + * which must register itself with {@link #setAnimator(javax.media.opengl.GLAnimatorControl)}.</p> + * <p> + * Called automatically by the window system toolkit upon receiving a repaint() request, <br> + * except an {@link javax.media.opengl.GLAnimatorControl} implementation {@link javax.media.opengl.GLAnimatorControl#isAnimating()}.</p> + * <p> + * This routine may also be called manually for better control over the + * rendering process. It is legal to call another GLAutoDrawable's + * display method from within the {@link GLEventListener#display + * display(..)} callback.</p> + * <p> + * In case of a new generated OpenGL context, + * the implementation shall call {@link GLEventListener#init init(..)} for all + * registered {@link GLEventListener}s <i>before</i> making the + * actual {@link GLEventListener#display display(..)} calls, + * in case this has not been done yet.</p> + * + * @see #setAnimator(javax.media.opengl.GLAnimatorControl) + */ + public void display(); + + /** Enables or disables automatic buffer swapping for this drawable. + By default this property is set to true; when true, after all + GLEventListeners have been called for a display() event, the + front and back buffers are swapped, displaying the results of + the render. When disabled, the user is responsible for calling + {@link #swapBuffers(..)} manually. */ + public void setAutoSwapBufferMode(boolean onOrOff); + + /** Indicates whether automatic buffer swapping is enabled for this + drawable. See {@link #setAutoSwapBufferMode}. */ + public boolean getAutoSwapBufferMode(); + + /** Returns the {@link GL} pipeline object this GLAutoDrawable uses. + If this method is called outside of the {@link + GLEventListener}'s callback methods (init, display, etc.) it may + return null. Users should not rely on the identity of the + returned GL object; for example, users should not maintain a + hash table with the GL object as the key. Additionally, the GL + object should not be cached in client code, but should be + re-fetched from the GLAutoDrawable at the beginning of each call + to init, display, etc. */ + public GL getGL(); + + /** Sets the {@link GL} pipeline object this GLAutoDrawable uses. + This should only be called from within the GLEventListener's + callback methods, and usually only from within the init() + method, in order to install a composable pipeline. See the JOGL + demos for examples. + @return the set GL pipeline or null if not successful */ + public GL setGL(GL gl); + +} diff --git a/src/jogl/classes/javax/media/opengl/GLBase.java b/src/jogl/classes/javax/media/opengl/GLBase.java new file mode 100644 index 000000000..90b320ed3 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLBase.java @@ -0,0 +1,347 @@ +/** + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * 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 javax.media.opengl; + +import java.nio.*; + +/** + * <P>The base interface from which all GL profiles derive, providing + * checked conversion down to concrete profiles, access to the + * OpenGL context associated with the GL and extension/function + * availability queries as described below.</P> + * + * <P> While the APIs for vendor extensions are unconditionally + * exposed, the underlying functions may not be present. The method + * {@link #isFunctionAvailable} should be used to query the + * availability of any non-core function before it is used for the + * first time; for example, + * <code>gl.isFunctionAvailable("glProgramStringARB")</code>. On + * certain platforms (Windows in particular), the most "core" + * functionality is only OpenGL 1.1, so in theory any routines first + * exposed in OpenGL 1.2, 1.3, and 1.4, 1.5, or 2.0 as well as vendor + * extensions should all be queried. Calling an unavailable function + * will cause a {@link GLException} to be raised. </P> + * + * {@link #isExtensionAvailable} may also be used to determine whether + * a specific extension is available before calling the routines or + * using the functionality it exposes: for example, + * <code>gl.isExtensionAvailable("GL_ARB_vertex_program");</code>. + * However, in this case it is up to the end user to know which + * routines or functionality are associated with which OpenGL + * extensions. It may also be used to test for the availability of a + * particular version of OpenGL: for example, + * <code>gl.isExtensionAvailable("GL_VERSION_1_5");</code>. + * + * <P> Exceptions to the window system extension naming rules: + * + * <UL> + * + * <LI> The memory allocators for the NVidia vertex_array_range (VAR) + * extension, in particular <code>wglAllocateMemoryNV</code> / + * <code>glXAllocateMemoryNV</code> and associated routines. {@link + * #glAllocateMemoryNV} has been provided for window system-independent + * access to VAR. {@link #isFunctionAvailable} will translate an argument + * of "glAllocateMemoryNV" or "glFreeMemoryNV" into the appropriate + * window system-specific name. </P> + * + * <LI> WGL_ARB_pbuffer, WGL_ARB_pixel_format, and other + * platform-specific pbuffer functionality; the availability of + * pbuffers can be queried on Windows, X11 and Mac OS X platforms by + * querying {@link #isExtensionAvailable} with an argument of + * "GL_ARB_pbuffer" or "GL_ARB_pixel_format". + * + * </UL> <P> + * + */ +public interface GLBase { + + /** + * Indicates whether this GL object conforms to any of the common GL profiles. + * @return whether this GL object conforms to any of the common GL profiles + */ + public boolean isGL(); + + /** + * Indicates whether this GL object conforms to the GL4 compatibility profile. + * The GL4 compatibility profile merges the GL2 profile and GL4 core profile. + * @return whether this GL object conforms to the GL4 compatibility profile + */ + public boolean isGL4bc(); + + /** + * Indicates whether this GL object conforms to the GL4 core profile. + * The GL4 core profile reflects OpenGL versions greater or equal 3.1 + * @return whether this GL object conforms to the GL4 core profile + */ + public boolean isGL4(); + + /** + * Indicates whether this GL object conforms to the GL3 compatibility profile. + * The GL3 compatibility profile merges the GL2 profile and GL3 core profile. + * @return whether this GL object conforms to the GL3 compatibility profile + */ + public boolean isGL3bc(); + + /** + * Indicates whether this GL object conforms to the GL3 core profile. + * The GL3 core profile reflects OpenGL versions greater or equal 3.1 + * @return whether this GL object conforms to the GL3 core profile + */ + public boolean isGL3(); + + /** + * Indicates whether this GL object conforms to the GL2 profile. + * The GL2 profile reflects OpenGL versions greater or equal 1.5 + * @return whether this GL object conforms to the GL2 profile + */ + public boolean isGL2(); + + /** + * Indicates whether this GL object conforms to the GLES1 profile. + * @return whether this GL object conforms to the GLES1 profile + */ + public boolean isGLES1(); + + /** + * Indicates whether this GL object conforms to the GLES2 profile. + * @return whether this GL object conforms to the GLES2 profile + */ + public boolean isGLES2(); + + /** + * Indicates whether this GL object conforms to one of the OpenGL ES compatible profiles. + * @return whether this GL object conforms to one of the OpenGL ES profiles + */ + public boolean isGLES(); + + /** + * Indicates whether this GL object conforms to the GL2ES1 compatible profile. + * @return whether this GL object conforms to the GL2ES1 profile + */ + public boolean isGL2ES1(); + + /** + * Indicates whether this GL object conforms to the GL2ES2 compatible profile. + * @return whether this GL object conforms to the GL2ES2 profile + */ + public boolean isGL2ES2(); + + /** + * Indicates whether this GL object conforms to the GL2GL3 compatible profile. + * @return whether this GL object conforms to the GL2GL3 profile + */ + public boolean isGL2GL3(); + + /** Indicates whether this GL object supports GLSL. */ + public boolean hasGLSL(); + + /** + * Casts this object to the GL interface. + * @return this object cast to the GL interface + * @throws GLException if this GLObject is not a GL implementation + */ + public GL getGL() throws GLException; + + /** + * Casts this object to the GL4bc interface. + * @return this object cast to the GL4bc interface + * @throws GLException if this GLObject is not a GL4bc implementation + */ + public GL4bc getGL4bc() throws GLException; + + /** + * Casts this object to the GL4 interface. + * @return this object cast to the GL4 interface + * @throws GLException if this GLObject is not a GL4 implementation + */ + public GL4 getGL4() throws GLException; + + /** + * Casts this object to the GL3bc interface. + * @return this object cast to the GL3bc interface + * @throws GLException if this GLObject is not a GL3bc implementation + */ + public GL3bc getGL3bc() throws GLException; + + /** + * Casts this object to the GL3 interface. + * @return this object cast to the GL3 interface + * @throws GLException if this GLObject is not a GL3 implementation + */ + public GL3 getGL3() throws GLException; + + /** + * Casts this object to the GL2 interface. + * @return this object cast to the GL2 interface + * @throws GLException if this GLObject is not a GL2 implementation + */ + public GL2 getGL2() throws GLException; + + /** + * Casts this object to the GLES1 interface. + * @return this object cast to the GLES1 interface + * @throws GLException if this GLObject is not a GLES1 implementation + */ + public GLES1 getGLES1() throws GLException; + + /** + * Casts this object to the GLES2 interface. + * @return this object cast to the GLES2 interface + * @throws GLException if this GLObject is not a GLES2 implementation + */ + public GLES2 getGLES2() throws GLException; + + /** + * Casts this object to the GL2ES1 interface. + * @return this object cast to the GL2ES1 interface + * @throws GLException if this GLObject is not a GL2ES1 implementation + */ + public GL2ES1 getGL2ES1() throws GLException; + + /** + * Casts this object to the GL2ES2 interface. + * @return this object cast to the GL2ES2 interface + * @throws GLException if this GLObject is not a GL2ES2 implementation + */ + public GL2ES2 getGL2ES2() throws GLException; + + /** + * Casts this object to the GL2GL3 interface. + * @return this object cast to the GL2GL3 interface + * @throws GLException if this GLObject is not a GL2GL3 implementation + */ + public GL2GL3 getGL2GL3() throws GLException; + + /** + * Returns the GLProfile with which this GL object is associated. + * @return the GLProfile with which this GL object is associated + */ + public GLProfile getGLProfile(); + + /** + * Returns the GLContext with which this GL object is associated. + * @return the GLContext with which this GL object is associated + */ + public GLContext getContext(); + + /** + * Returns true if the specified OpenGL core- or extension-function can be + * used successfully through this GL instance given the current host (OpenGL + * <i>client</i>) and display (OpenGL <i>server</i>) configuration.<P> + * By "successfully" we mean that the function is both <i>callable</i> + * on the machine running the program and <i>available</i> on the current + * display.<P> + * + * In order to call a function successfully, the function must be both + * <i>callable</i> on the machine running the program and <i>available</i> on + * the display device that is rendering the output (note: on non-networked, + * single-display machines these two conditions are identical; on networked and/or + * multi-display machines this becomes more complicated). These conditions are + * met if the function is either part of the core OpenGL version supported by + * both the host and display, or it is an OpenGL extension function that both + * the host and display support. <P> + * + * A GL function is <i>callable</i> if it is successfully linked at runtime, + * hence the GLContext must be made current at least once. + * + * @param glFunctionName the name of the OpenGL function (e.g., use + * "glBindRenderbufferEXT" or "glBindRenderbuffer" to check if {@link + * GL#glBindRenderbuffer(int,int)} is available). + */ + public boolean isFunctionAvailable(String glFunctionName); + + /** + * Returns true if the specified OpenGL extension can be + * used successfully through this GL instance given the current host (OpenGL + * <i>client</i>) and display (OpenGL <i>server</i>) configuration.<P> + * + * @param glExtensionName the name of the OpenGL extension (e.g., + * "GL_ARB_vertex_program"). + */ + public boolean isExtensionAvailable(String glExtensionName); + + /** Provides a platform-independent way to specify the minimum swap + interval for buffer swaps. An argument of 0 disables + sync-to-vertical-refresh completely, while an argument of 1 + causes the application to wait until the next vertical refresh + until swapping buffers. The default, which is platform-specific, + is usually either 0 or 1. This function is not guaranteed to + have an effect, and in particular only affects heavyweight + onscreen components. + + @see #getSwapInterval + @throws GLException if this context is not the current + */ + public void setSwapInterval(int interval); + + /** Provides a platform-independent way to get the swap + interval set by {@link #setSwapInterval}. <br> + + If the interval is not set by {@link #setSwapInterval} yet, + -1 is returned, indicating that the platforms default + is being used. + + @see #setSwapInterval + */ + public int getSwapInterval(); + + /** + * Returns an object through which platform-specific OpenGL extensions + * (EGL, GLX, WGL, etc.) may be accessed. The data type of the returned + * object and its associated capabilities are undefined. Most + * applications will never need to call this method. It is highly + * recommended that any applications which do call this method perform + * all accesses on the returned object reflectively to guard + * themselves against changes to the implementation. + */ + public Object getPlatformGLExtensions(); + + /** + * Returns an object providing access to the specified OpenGL + * extension. This is intended to provide a mechanism for vendors who + * wish to provide access to new OpenGL extensions without changing + * the public API of the core package. For example, a user may request + * access to extension "GL_VENDOR_foo" and receive back an object + * which implements a vendor-specified interface which can call the + * OpenGL extension functions corresponding to that extension. It is + * up to the vendor to specify both the extension name and Java API + * for accessing it, including which class or interface contains the + * functions. + * + * <P> + * + * Note: it is the intent to add new extensions as quickly as possible + * to the core GL API. Therefore it is unlikely that most vendors will + * use this extension mechanism, but it is being provided for + * completeness. + */ + public Object getExtension(String extensionName); +} + diff --git a/src/jogl/classes/javax/media/opengl/GLCapabilities.java b/src/jogl/classes/javax/media/opengl/GLCapabilities.java new file mode 100644 index 000000000..1ae9e40aa --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLCapabilities.java @@ -0,0 +1,462 @@ +/* + * Copyright (c) 2003-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +import javax.media.nativewindow.Capabilities; + +/** Specifies a set of OpenGL capabilities.<br> + At creation time of a {@link GLDrawable} using {@link GLDrawableFactory}, + an instance of this class is passed, + describing the desired capabilities that a rendering context + must support, such as the OpenGL profile, color depth and whether stereo is enabled.<br> + + The actual capabilites of created {@link GLDrawable}s are then reflected by their own + GLCapabilites instance, which can be queried with {@link GLDrawable#getGLCapabilities()}.<br> + + It currently contains the minimal number of routines which allow + configuration on all supported window systems. */ +public class GLCapabilities extends Capabilities implements Cloneable, GLCapabilitiesImmutable { + private GLProfile glProfile = null; + private boolean pbuffer = false; + private boolean doubleBuffered = true; + private boolean stereo = false; + private boolean hardwareAccelerated = true; + private int depthBits = 16; + private int stencilBits = 0; + private int accumRedBits = 0; + private int accumGreenBits = 0; + private int accumBlueBits = 0; + private int accumAlphaBits = 0; + // Shift bits from PIXELFORMATDESCRIPTOR not present because they + // are unlikely to be supported on Windows anyway + + // Support for full-scene antialiasing (FSAA) + private boolean sampleBuffers = false; + private int numSamples = 2; + + // Bits for pbuffer creation + private boolean pbufferFloatingPointBuffers; + private boolean pbufferRenderToTexture; + private boolean pbufferRenderToTextureRectangle; + + /** Creates a GLCapabilities object. All attributes are in a default state. + * @param glp GLProfile, or null for the default GLProfile + */ + public GLCapabilities(GLProfile glp) { + glProfile = (null!=glp)?glp:GLProfile.getDefault(GLProfile.getDefaultDevice()); + } + + public Object cloneMutable() { + return clone(); + } + + public Object clone() { + try { + return super.clone(); + } catch (RuntimeException e) { + throw new GLException(e); + } + } + + public int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + this.glProfile.hashCode() ; + hash = ((hash << 5) - hash) + ( this.pbuffer ? 1 : 0 ); + hash = ((hash << 5) - hash) + ( this.stereo ? 1 : 0 ); + hash = ((hash << 5) - hash) + ( this.hardwareAccelerated ? 1 : 0 ); + hash = ((hash << 5) - hash) + this.depthBits; + hash = ((hash << 5) - hash) + this.stencilBits; + hash = ((hash << 5) - hash) + this.accumRedBits; + hash = ((hash << 5) - hash) + this.accumGreenBits; + hash = ((hash << 5) - hash) + this.accumBlueBits; + hash = ((hash << 5) - hash) + this.accumAlphaBits; + hash = ((hash << 5) - hash) + ( this.sampleBuffers ? 1 : 0 ); + hash = ((hash << 5) - hash) + this.numSamples; + hash = ((hash << 5) - hash) + ( this.pbufferFloatingPointBuffers ? 1 : 0 ); + hash = ((hash << 5) - hash) + ( this.pbufferRenderToTexture ? 1 : 0 ); + hash = ((hash << 5) - hash) + ( this.pbufferRenderToTextureRectangle ? 1 : 0 ); + return hash; + } + + public boolean equals(Object obj) { + if(this == obj) { return true; } + if(!(obj instanceof GLCapabilitiesImmutable)) { + return false; + } + GLCapabilitiesImmutable other = (GLCapabilitiesImmutable)obj; + boolean res = super.equals(obj) && + other.getGLProfile()==glProfile && + other.isPBuffer()==pbuffer && + other.getStereo()==stereo && + other.getHardwareAccelerated()==hardwareAccelerated && + other.getDepthBits()==depthBits && + other.getStencilBits()==stencilBits && + other.getAccumRedBits()==accumRedBits && + other.getAccumGreenBits()==accumGreenBits && + other.getAccumBlueBits()==accumBlueBits && + other.getAccumAlphaBits()==accumAlphaBits && + other.getSampleBuffers()==sampleBuffers && + other.getPbufferFloatingPointBuffers()==pbufferFloatingPointBuffers && + other.getPbufferRenderToTexture()==pbufferRenderToTexture && + other.getPbufferRenderToTextureRectangle()==pbufferRenderToTextureRectangle; + if(sampleBuffers) { + res = res && other.getNumSamples()==numSamples; + } + return res; + } + + /** comparing hw/sw, stereo, multisample, stencil, RGBA and depth only */ + public int compareTo(Object o) { + if ( ! ( o instanceof GLCapabilities ) ) { + Class c = (null != o) ? o.getClass() : null ; + throw new ClassCastException("Not a GLCapabilities object: " + c); + } + + final GLCapabilities caps = (GLCapabilities) o; + + if(hardwareAccelerated && !caps.hardwareAccelerated) { + return 1; + } else if(!hardwareAccelerated && caps.hardwareAccelerated) { + return -1; + } + + if(stereo && !caps.stereo) { + return 1; + } else if(!stereo && caps.stereo) { + return -1; + } + + final int ms = sampleBuffers ? numSamples : 0; + final int xms = caps.sampleBuffers ? caps.numSamples : 0; + + if(ms > xms) { + return 1; + } else if( ms < xms ) { + return -1; + } + + if(stencilBits > caps.stencilBits) { + return 1; + } else if(stencilBits < caps.stencilBits) { + return -1; + } + + final int sc = super.compareTo(caps); // RGBA + if(0 != sc) { + return sc; + } + + if(depthBits > caps.depthBits) { + return 1; + } else if(depthBits < caps.depthBits) { + return -1; + } + + return 0; // they are equal: hw/sw, stereo, multisample, stencil, RGBA and depth + } + + /** Returns the GL profile you desire or used by the drawable. */ + public GLProfile getGLProfile() { + return glProfile; + } + + /** Sets the GL profile you desire */ + public void setGLProfile(GLProfile profile) { + glProfile=profile; + } + + /** Indicates whether pbuffer is used/requested. */ + public boolean isPBuffer() { + return pbuffer; + } + + /** + * Enables or disables pbuffer usage.<br> + * If enabled, onscreen := false. + * Defaults to false. + */ + public void setPBuffer(boolean onOrOff) { + if(onOrOff) { + setOnscreen(false); + } + pbuffer = onOrOff; + } + + /** + * Sets whether the drawable surface supports onscreen.<br> + * If enabled, pbuffer := false.<br> + * Defaults to true. + */ + public void setOnscreen(boolean onscreen) { + if(onscreen) { + setPBuffer(false); + } + super.setOnscreen(onscreen); + } + + /** Indicates whether double-buffering is enabled. */ + public boolean getDoubleBuffered() { + return doubleBuffered; + } + + /** Enables or disables double buffering. */ + public void setDoubleBuffered(boolean onOrOff) { + doubleBuffered = onOrOff; + } + + /** Indicates whether stereo is enabled. */ + public boolean getStereo() { + return stereo; + } + + /** Enables or disables stereo viewing. */ + public void setStereo(boolean onOrOff) { + stereo = onOrOff; + } + + /** Indicates whether hardware acceleration is enabled. */ + public boolean getHardwareAccelerated() { + return hardwareAccelerated; + } + + /** Enables or disables hardware acceleration. */ + public void setHardwareAccelerated(boolean onOrOff) { + hardwareAccelerated = onOrOff; + } + + /** Returns the number of bits requested for the depth buffer. */ + public int getDepthBits() { + return depthBits; + } + + /** Sets the number of bits requested for the depth buffer. */ + public void setDepthBits(int depthBits) { + this.depthBits = depthBits; + } + + /** Returns the number of bits requested for the stencil buffer. */ + public int getStencilBits() { + return stencilBits; + } + + /** Sets the number of bits requested for the stencil buffer. */ + public void setStencilBits(int stencilBits) { + this.stencilBits = stencilBits; + } + + /** Returns the number of bits requested for the accumulation + buffer's red component. On some systems only the accumulation + buffer depth, which is the sum of the red, green, and blue bits, + is considered. */ + public int getAccumRedBits() { + return accumRedBits; + } + + /** Sets the number of bits requested for the accumulation buffer's + red component. On some systems only the accumulation buffer + depth, which is the sum of the red, green, and blue bits, is + considered. */ + public void setAccumRedBits(int accumRedBits) { + this.accumRedBits = accumRedBits; + } + + /** Returns the number of bits requested for the accumulation + buffer's green component. On some systems only the accumulation + buffer depth, which is the sum of the red, green, and blue bits, + is considered. */ + public int getAccumGreenBits() { + return accumGreenBits; + } + + /** Sets the number of bits requested for the accumulation buffer's + green component. On some systems only the accumulation buffer + depth, which is the sum of the red, green, and blue bits, is + considered. */ + public void setAccumGreenBits(int accumGreenBits) { + this.accumGreenBits = accumGreenBits; + } + + /** Returns the number of bits requested for the accumulation + buffer's blue component. On some systems only the accumulation + buffer depth, which is the sum of the red, green, and blue bits, + is considered. */ + public int getAccumBlueBits() { + return accumBlueBits; + } + + /** Sets the number of bits requested for the accumulation buffer's + blue component. On some systems only the accumulation buffer + depth, which is the sum of the red, green, and blue bits, is + considered. */ + public void setAccumBlueBits(int accumBlueBits) { + this.accumBlueBits = accumBlueBits; + } + + /** Returns the number of bits requested for the accumulation + buffer's alpha component. On some systems only the accumulation + buffer depth, which is the sum of the red, green, and blue bits, + is considered. */ + public int getAccumAlphaBits() { + return accumAlphaBits; + } + + /** Sets number of bits requested for accumulation buffer's alpha + component. On some systems only the accumulation buffer depth, + which is the sum of the red, green, and blue bits, is + considered. */ + public void setAccumAlphaBits(int accumAlphaBits) { + this.accumAlphaBits = accumAlphaBits; + } + + /** Indicates whether sample buffers for full-scene antialiasing + (FSAA) should be allocated for this drawable. Defaults to + false. */ + public void setSampleBuffers(boolean onOrOff) { + sampleBuffers = onOrOff; + } + + /** Returns whether sample buffers for full-scene antialiasing + (FSAA) should be allocated for this drawable. Defaults to + false. */ + public boolean getSampleBuffers() { + return sampleBuffers; + } + + /** If sample buffers are enabled, indicates the number of buffers + to be allocated. Defaults to 2. */ + public void setNumSamples(int numSamples) { + this.numSamples = numSamples; + } + + /** Returns the number of sample buffers to be allocated if sample + buffers are enabled. Defaults to 2. */ + public int getNumSamples() { + return numSamples; + } + + /** For pbuffers only, indicates whether floating-point buffers + should be used if available. Defaults to false. */ + public void setPbufferFloatingPointBuffers(boolean onOrOff) { + pbufferFloatingPointBuffers = onOrOff; + } + + /** For pbuffers only, returns whether floating-point buffers should + be used if available. Defaults to false. */ + public boolean getPbufferFloatingPointBuffers() { + return pbufferFloatingPointBuffers; + } + + /** For pbuffers only, indicates whether the render-to-texture + extension should be used if available. Defaults to false. */ + public void setPbufferRenderToTexture(boolean onOrOff) { + pbufferRenderToTexture = onOrOff; + } + + /** For pbuffers only, returns whether the render-to-texture + extension should be used if available. Defaults to false. */ + public boolean getPbufferRenderToTexture() { + return pbufferRenderToTexture; + } + + /** For pbuffers only, indicates whether the + render-to-texture-rectangle extension should be used if + available. Defaults to false. */ + public void setPbufferRenderToTextureRectangle(boolean onOrOff) { + pbufferRenderToTextureRectangle = onOrOff; + } + + /** For pbuffers only, returns whether the render-to-texture + extension should be used. Defaults to false. */ + public boolean getPbufferRenderToTextureRectangle() { + return pbufferRenderToTextureRectangle; + } + + public StringBuffer toString(StringBuffer sink) { + if(null == sink) { + sink = new StringBuffer(); + } + + int samples = sampleBuffers ? numSamples : 0 ; + + super.toString(sink); + + sink.append(", accum-rgba ").append(accumRedBits).append("/").append(accumGreenBits).append("/").append(accumBlueBits).append("/").append(accumAlphaBits); + sink.append(", dp/st/ms: ").append(depthBits).append("/").append(stencilBits).append("/").append(samples); + if(doubleBuffered) { + sink.append(", dbl"); + } else { + sink.append(", one"); + } + if(stereo) { + sink.append(", stereo"); + } else { + sink.append(", mono "); + } + if(hardwareAccelerated) { + sink.append(", hw, "); + } else { + sink.append(", sw, "); + } + sink.append(glProfile); + if(!isOnscreen()) { + if(pbuffer) { + sink.append(", pbuffer [r2t ").append(pbufferRenderToTexture?1:0) + .append(", r2tr ").append(pbufferRenderToTextureRectangle?1:0) + .append(", float ").append(pbufferFloatingPointBuffers?1:0) + .append("]"); + } else { + sink.append(", pixmap"); + } + } + + return sink; + } + + /** Returns a textual representation of this GLCapabilities + object. */ + public String toString() { + StringBuffer msg = new StringBuffer(); + msg.append("GLCaps["); + toString(msg); + msg.append("]"); + return msg.toString(); + } +} diff --git a/src/jogl/classes/javax/media/opengl/GLCapabilitiesChooser.java b/src/jogl/classes/javax/media/opengl/GLCapabilitiesChooser.java new file mode 100644 index 000000000..73a77de27 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLCapabilitiesChooser.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2003-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +import javax.media.nativewindow.CapabilitiesChooser; + +/** Provides a mechanism by which applications can customize the + window type selection for a given {@link GLCapabilities}. + Developers can implement this interface and pass an instance into + the appropriate method of {@link GLDrawableFactory}; the chooser + will be called during the OpenGL context creation process. Note + that this is only a marker interface; its signature is the same as + {@link CapabilitiesChooser}, but the array of {@link Capabilities} + objects passed to {@link #chooseCapabilities chooseCapabilities} + will actually be an array of {@link GLCapabilities}. */ + +public interface GLCapabilitiesChooser extends CapabilitiesChooser { +} diff --git a/src/jogl/classes/javax/media/opengl/GLCapabilitiesImmutable.java b/src/jogl/classes/javax/media/opengl/GLCapabilitiesImmutable.java new file mode 100644 index 000000000..a89aec080 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLCapabilitiesImmutable.java @@ -0,0 +1,150 @@ +/** + * 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 javax.media.opengl; + +import com.jogamp.common.type.WriteCloneable; +import javax.media.nativewindow.CapabilitiesImmutable; + +/** + * Specifies an immutable set of OpenGL capabilities.<br> + * + * @see javax.media.opengl.GLCapabilities + * @see javax.media.nativewindow.CapabilitiesImmutable + */ +public interface GLCapabilitiesImmutable extends WriteCloneable, CapabilitiesImmutable { + + /** + * Returns the number of bits requested for the accumulation + * buffer's alpha component. On some systems only the accumulation + * buffer depth, which is the sum of the red, green, and blue bits, + * is considered. + */ + int getAccumAlphaBits(); + + /** + * Returns the number of bits requested for the accumulation + * buffer's blue component. On some systems only the accumulation + * buffer depth, which is the sum of the red, green, and blue bits, + * is considered. + */ + int getAccumBlueBits(); + + /** + * Returns the number of bits requested for the accumulation + * buffer's green component. On some systems only the accumulation + * buffer depth, which is the sum of the red, green, and blue bits, + * is considered. + */ + int getAccumGreenBits(); + + /** + * Returns the number of bits requested for the accumulation + * buffer's red component. On some systems only the accumulation + * buffer depth, which is the sum of the red, green, and blue bits, + * is considered. + */ + int getAccumRedBits(); + + /** + * Returns the number of bits requested for the depth buffer. + */ + int getDepthBits(); + + /** + * Indicates whether double-buffering is enabled. + */ + boolean getDoubleBuffered(); + + /** + * Returns the GL profile you desire or used by the drawable. + */ + GLProfile getGLProfile(); + + /** + * Indicates whether hardware acceleration is enabled. + */ + boolean getHardwareAccelerated(); + + /** + * Returns the number of sample buffers to be allocated if sample + * buffers are enabled. Defaults to 2. + */ + int getNumSamples(); + + /** + * For pbuffers only, returns whether floating-point buffers should + * be used if available. Defaults to false. + */ + boolean getPbufferFloatingPointBuffers(); + + /** + * For pbuffers only, returns whether the render-to-texture + * extension should be used if available. Defaults to false. + */ + boolean getPbufferRenderToTexture(); + + /** + * For pbuffers only, returns whether the render-to-texture + * extension should be used. Defaults to false. + */ + boolean getPbufferRenderToTextureRectangle(); + + /** + * Returns whether sample buffers for full-scene antialiasing + * (FSAA) should be allocated for this drawable. Defaults to + * false. + */ + boolean getSampleBuffers(); + + /** + * Returns the number of bits requested for the stencil buffer. + */ + int getStencilBits(); + + /** + * Indicates whether stereo is enabled. + */ + boolean getStereo(); + + /** + * Indicates whether pbuffer is used/requested. + */ + boolean isPBuffer(); + + Object cloneMutable(); + + @Override + boolean equals(Object obj); + + @Override + int hashCode(); + + @Override + String toString(); +} diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java new file mode 100644 index 000000000..b859dee00 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -0,0 +1,780 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +import java.util.HashMap; +import java.util.HashSet; +import javax.media.nativewindow.AbstractGraphicsDevice; +import jogamp.opengl.Debug; + +/** Abstraction for an OpenGL rendering context. In order to perform + OpenGL rendering, a context must be "made current" on the current + thread. OpenGL rendering semantics specify that only one context + may be current on the current thread at any given time, and also + that a given context may be current on only one thread at any + given time. Because components can be added to and removed from + the component hierarchy at any time, it is possible that the + underlying OpenGL context may need to be destroyed and recreated + multiple times over the lifetime of a given component. This + process is handled by the implementation, and the GLContext + abstraction provides a stable object which clients can use to + refer to a given context. */ +public abstract class GLContext { + protected static final boolean DEBUG0 = Debug.debug("GLContext"); + + /** Indicates that the context was not made current during the last call to {@link #makeCurrent makeCurrent}. */ + public static final int CONTEXT_NOT_CURRENT = 0; + /** Indicates that the context was made current during the last call to {@link #makeCurrent makeCurrent}. */ + public static final int CONTEXT_CURRENT = 1; + /** Indicates that a newly-created context was made current during the last call to {@link #makeCurrent makeCurrent}. */ + public static final int CONTEXT_CURRENT_NEW = 2; + + /** <code>ARB_create_context</code> related: created via ARB_create_context */ + protected static final int CTX_IS_ARB_CREATED = 1 << 0; + /** <code>ARB_create_context</code> related: compatibility profile */ + protected static final int CTX_PROFILE_COMPAT = 1 << 1; + /** <code>ARB_create_context</code> related: core profile */ + protected static final int CTX_PROFILE_CORE = 1 << 2; + /** <code>ARB_create_context</code> related: ES profile */ + protected static final int CTX_PROFILE_ES = 1 << 3; + /** <code>ARB_create_context</code> related: flag forward compatible */ + protected static final int CTX_OPTION_FORWARD = 1 << 4; + /** <code>ARB_create_context</code> related: not flag forward compatible */ + protected static final int CTX_OPTION_ANY = 1 << 5; + /** <code>ARB_create_context</code> related: flag debug */ + protected static final int CTX_OPTION_DEBUG = 1 << 6; + + /** GLContext {@link com.jogamp.gluegen.runtime.ProcAddressTable} caching related: GL software implementation */ + protected static final int CTX_IMPL_ACCEL_SOFT = 1 << 0; + /** GLContext {@link com.jogamp.gluegen.runtime.ProcAddressTable} caching related: GL hardware implementation */ + protected static final int CTX_IMPL_ACCEL_HARD = 1 << 1; + + private static ThreadLocal currentContext = new ThreadLocal(); + + private HashMap/*<int, Object>*/ attachedObjects = new HashMap(); + + /** The underlying native OpenGL context */ + protected long contextHandle; + + protected GLContext() { + resetStates(); + } + + protected int ctxMajorVersion; + protected int ctxMinorVersion; + protected int ctxOptions; + protected String ctxVersionString; + + protected void resetStates() { + ctxMajorVersion=-1; + ctxMinorVersion=-1; + ctxOptions=0; + ctxVersionString=null; + if(null!=attachedObjects) { + attachedObjects.clear(); + } + contextHandle=0; + } + + /** + * Returns the GLDrawable to which this context may be used to + * draw. + */ + public abstract GLDrawable getGLDrawable(); + + /** + * Return availability of GL read drawable. + * @return true if a GL read drawable is supported with your driver, otherwise false. + */ + public abstract boolean isGLReadDrawableAvailable(); + + /** + * Set the read GLDrawable for read framebuffer operations.<br> + * The caller should query if this feature is supported via {@link #isGLReadDrawableAvailable()}. + * + * @param read the read GLDrawable for read framebuffer operations. + * If null is passed, the default write drawable will be set. + * + * @throws GLException in case a read drawable is not supported + * and the given drawable is not null and not equal to the internal write drawable. + * + * @see #isGLReadDrawableAvailable() + * @see #getGLReadDrawable() + */ + public abstract void setGLReadDrawable(GLDrawable read); + + /** + * Returns the read GLDrawable this context uses for read framebuffer operations. + * @see #isGLReadDrawableAvailable() + * @see #setGLReadDrawable(javax.media.opengl.GLDrawable) + */ + public abstract GLDrawable getGLReadDrawable(); + + /** + * Makes this GLContext current on the calling thread. + * + * There are two return values that indicate success and one that + * indicates failure. A return value of CONTEXT_CURRENT_NEW + * indicates that that context has been made current, and that + * this is the first time this context has been made current, or + * that the state of the underlying context or drawable may have + * changed since the last time this context was made current. In + * this case, the application may wish to initialize the state. A + * return value of CONTEXT_CURRENT indicates that the context has + * been made currrent, with its previous state restored. + * + * If the context could not be made current (for example, because + * the underlying drawable has not ben realized on the display) , + * a value of CONTEXT_NOT_CURRENT is returned. + * + * If the context is in use by another thread at the time of the + * call, then if isSynchronized() is true the call will + * block. If isSynchronized() is false, an exception will be + * thrown and the context will remain current on the other thread. + * + * @return CONTEXT_CURRENT if the context was successfully made current + * @return CONTEXT_CURRENT_NEW if the context was successfully made + * current, but need to be initialized. + * + * @return CONTEXT_NOT_CURRENT if the context could not be made current. + * + * @throws GLException if synchronization is disabled and the + * context is current on another thread, or because the context + * could not be created or made current due to non-recoverable, + * window system-specific errors. + */ + public abstract int makeCurrent() throws GLException; + + /** + * Releases control of this GLContext from the current thread. + * + * @throws GLException if the context had not previously been made + * current on the current thread + */ + public abstract void release() throws GLException; + + /** + * Copies selected groups of OpenGL state variables from the + * supplied source context into this one. The <code>mask</code> + * parameter indicates which groups of state variables are to be + * copied. <code>mask</code> contains the bitwise OR of the same + * symbolic names that are passed to the GL command {@link + * GL#glPushAttrib glPushAttrib}. The single symbolic constant + * {@link GL2#GL_ALL_ATTRIB_BITS GL_ALL_ATTRIB_BITS} can be used to + * copy the maximum possible portion of rendering state. <P> + * + * Not all values for GL state can be copied. For example, pixel + * pack and unpack state, render mode state, and select and feedback + * state are not copied. The state that can be copied is exactly the + * state that is manipulated by the GL command {@link + * GL2#glPushAttrib glPushAttrib}. <P> + * + * On most platforms, this context may not be current to any thread, + * including the calling thread, when this method is called. Some + * platforms have additional requirements such as whether this + * context or the source context must occasionally be made current + * in order for the results of the copy to be seen; these + * requirements are beyond the scope of this specification. + * + * @param source the source OpenGL context from which to copy state + * @param mask a mask of symbolic names indicating which groups of state to copy + + * @throws GLException if an OpenGL-related error occurred + */ + public abstract void copy(GLContext source, int mask) throws GLException; + + /** + * Returns the GL object bound to this thread current context. + * If no context is current, throw an GLException + * + * @return the current context's GL object on this thread + * @throws GLException if no context is current + */ + public static GL getCurrentGL() throws GLException { + GLContext glc = getCurrent(); + if(null==glc) { + throw new GLException("No OpenGL context current on this thread"); + } + return glc.getGL(); + } + + /** + * Returns this thread current context. + * If no context is current, returns null. + * + * @return the context current on this thread, or null if no context + * is current. + */ + public static GLContext getCurrent() { + return (GLContext) currentContext.get(); + } + + /** + * @return true if this GLContext is current on this thread + */ + public final boolean isCurrent() { + return getCurrent() == this ; + } + + /** + * Sets the thread-local variable returned by {@link #getCurrent} + * and has no other side-effects. For use by third parties adding + * new GLContext implementations; not for use by end users. + */ + protected static void setCurrent(GLContext cur) { + currentContext.set(cur); + } + + /** + * Destroys this OpenGL context and frees its associated + * resources. The context should have been released before this + * method is called. + */ + public abstract void destroy(); + + /** + * Returns true if 'makeCurrent' will exhibit synchronized behavior. + */ + public abstract boolean isSynchronized(); + + /** + * Determines whether 'makeCurrent' will exhibit synchronized behavior. + */ + public abstract void setSynchronized(boolean isSynchronized); + + /** + * Returns the GL pipeline object for this GLContext. + * + * @return the aggregated GL instance, or null if this context was not yet made current. + */ + public abstract GL getGL(); + + /** + * Sets the GL pipeline object for this GLContext. + * + * @return the set GL pipeline or null if not successful + */ + public abstract GL setGL(GL gl); + + /** + * Returns the native GL context handle + */ + public final long getHandle() { return contextHandle; } + + /** + * Indicates whether the underlying OpenGL context has been created. + */ + public final boolean isCreated() { + return 0 != contextHandle; + } + + /** + * Returns the attached user object for the given name to this GLContext. + */ + public final Object getAttachedObject(int name) { + return attachedObjects.get(new Integer(name)); + } + + /** + * Returns the attached user object for the given name to this GLContext. + */ + public final Object getAttachedObject(String name) { + return attachedObjects.get(name); + } + + /** + * Sets the attached user object for the given name to this GLContext. + * Returns the previously set object or null. + */ + public final Object putAttachedObject(int name, Object obj) { + return attachedObjects.put(new Integer(name), obj); + } + + /** + * Sets the attached user object for the given name to this GLContext. + * Returns the previously set object or null. + */ + public final Object putAttachedObject(String name, Object obj) { + return attachedObjects.put(name, obj); + } + + /** + * Classname, GL, GLDrawable + */ + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(getClass().getName()); + sb.append(" ["); + this.append(sb); + sb.append("] "); + return sb.toString(); + } + + public final StringBuffer append(StringBuffer sb) { + sb.append("OpenGL "); + sb.append(getGLVersionMajor()); + sb.append("."); + sb.append(getGLVersionMinor()); + sb.append(", options 0x"); + sb.append(Integer.toHexString(ctxOptions)); + sb.append(", "); + sb.append(getGLVersion()); + sb.append(", handle "); + sb.append(toHexString(contextHandle)); + sb.append(", "); + sb.append(getGL()); + if(getGLDrawable()!=getGLReadDrawable()) { + sb.append(",\n\tRead Drawable : "); + sb.append(getGLReadDrawable()); + sb.append(",\n\tWrite Drawable: "); + sb.append(getGLDrawable()); + } else { + sb.append(",\n\tDrawable: "); + sb.append(getGLDrawable()); + } + return sb; + } + + /** Returns a non-null (but possibly empty) string containing the + space-separated list of available platform-dependent (e.g., WGL, + GLX) extensions. Can only be called while this context is + current. */ + public abstract String getPlatformExtensionsString(); + + /** Returns a non-null (but possibly empty) string containing the + space-separated list of available extensions. + Can only be called while this context is current. + This is equivalent to + {@link javax.media.opengl.GL#glGetString(int) glGetString}({@link javax.media.opengl.GL#GL_EXTENSIONS GL_EXTENSIONS}) + */ + public abstract String getGLExtensionsString(); + + public final int getGLVersionMajor() { return ctxMajorVersion; } + public final int getGLVersionMinor() { return ctxMinorVersion; } + public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); } + public final boolean isGLCoreProfile() { return ( 0 != ( CTX_PROFILE_CORE & ctxOptions ) ); } + public final boolean isGLEmbeddedProfile() { return ( 0 != ( CTX_PROFILE_ES & ctxOptions ) ); } + public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); } + public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); } + + /** + * Returns a valid OpenGL version string, ie<br> + * <pre> + * major.minor ([option]?[options,]*) - gl-version + * </pre><br> + * + * <ul> + * <li> options + * <ul> + * <li> <code>old</code> refers to the non ARB_create_context created context</li> + * <li> <code>new</code> refers to the ARB_create_context created context</li> + * <li> <code>compatible profile</code></li> + * <li> <code>core profile</code></li> + * <li> <code>forward compatible</code></li> + * <li> <code>any</code> refers to the non forward compatible context</li> + * <li> <code>ES</code> refers to the GLES context variant</li> + * </ul></li> + * <li> <i>gl-version</i> the GL_VERSION string</li> + * </ul> + * + * e.g.: + * <table border="0"> + * <tr> <td></td> <td></td> </tr> + * <tr> + * <td>row 2, cell 1</td> + * <td>row 2, cell 2</td> + * </tr> + * </table> + * + * <table border="0"> + * <tr><td></td> <td>ES2</td> <td><code>2.0 (ES, any, new) - 2.0 ES Profile</code></td></tr> + * <tr><td>ATI</td><td>GL2</td> <td><code>3.0 (compatibility profile, any, new) - 3.2.9704 Compatibility Profile Context</code></td></tr> + * <tr><td>ATI</td><td>GL3</td> <td><code>3.3 (core profile, any, new) - 1.4 (3.2.9704 Compatibility Profile Context)</code></td></tr> + * <tr><td>ATI</td><td>GL3bc</td><td><code>3.3 (compatibility profile, any, new) - 1.4 (3.2.9704 Compatibility Profile Context)</code></td></tr> + * <tr><td>NV</td><td>GL2</td> <td><code>3.0 (compatibility profile, any, new) - 3.0.0 NVIDIA 195.36.07.03</code></td></tr> + * <tr><td>NV</td><td>GL3</td> <td><code>3.3 (core profile, any, new) - 3.3.0 NVIDIA 195.36.07.03</code></td></tr> + * <tr><td>NV</td><td>GL3bc</td> <td><code>3.3 (compatibility profile, any, new) - 3.3.0 NVIDIA 195.36.07.03</code></td></tr> + * </table> + */ + public final String getGLVersion() { + return ctxVersionString; + } + + public final boolean isGL4bc() { + return ctxMajorVersion>=4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) + && 0 != (ctxOptions & CTX_PROFILE_COMPAT); + } + + public final boolean isGL4() { + return ctxMajorVersion>=4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) + && 0 != (ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_CORE)); + } + + public final boolean isGL3bc() { + return ( ctxMajorVersion>3 || ctxMajorVersion==3 && ctxMinorVersion>=1 ) + && 0 != (ctxOptions & CTX_IS_ARB_CREATED) + && 0 != (ctxOptions & CTX_PROFILE_COMPAT); + } + + public final boolean isGL3() { + return ( ctxMajorVersion>3 || ctxMajorVersion==3 && ctxMinorVersion>=1 ) + && 0 != (ctxOptions & CTX_IS_ARB_CREATED) + && 0 != (ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_CORE)); + } + + public final boolean isGL2() { + return ctxMajorVersion>=1 && 0!=(ctxOptions & CTX_PROFILE_COMPAT); + } + + public final boolean isGL2GL3() { + return isGL2() || isGL3(); + } + + public final boolean isGLES1() { + return ctxMajorVersion==1 && 0!=(ctxOptions & CTX_PROFILE_ES); + } + + public final boolean isGLES2() { + return ctxMajorVersion==2 && 0!=(ctxOptions & CTX_PROFILE_ES); + } + + public final boolean isGLES() { + return isGLEmbeddedProfile(); + } + + public final boolean isGL2ES1() { + return isGL2() || isGLES1() ; + } + + public final boolean isGL2ES2() { + return isGL2GL3() || isGLES2() ; + } + + public final boolean hasGLSL() { + return isGL2ES2() ; + } + + public static final int GL_VERSIONS[][] = { + /* 0.*/ { -1 }, + /* 1.*/ { 0, 1, 2, 3, 4, 5 }, + /* 2.*/ { 0, 1 }, + /* 3.*/ { 0, 1, 2, 3 }, + /* 4.*/ { 0, 1 } }; + + public static final int getMaxMajor() { + return GL_VERSIONS.length-1; + } + + public static final int getMaxMinor(int major) { + if(1>major || major>=GL_VERSIONS.length) return -1; + return GL_VERSIONS[major].length-1; + } + + public static final boolean isValidGLVersion(int major, int minor) { + if(1>major || major>=GL_VERSIONS.length) return false; + if(0>minor || minor>=GL_VERSIONS[major].length) return false; + return true; + } + + public static final boolean decrementGLVersion(int major[], int minor[]) { + if(null==major || major.length<1 ||null==minor || minor.length<1) { + throw new GLException("invalid array arguments"); + } + int m = major[0]; + int n = minor[0]; + if(!isValidGLVersion(m, n)) return false; + + // decrement .. + n -= 1; + if(n < 0) { + m -= 1; + n = GL_VERSIONS[m].length-1; + } + if(!isValidGLVersion(m, n)) return false; + major[0]=m; + minor[0]=n; + + return true; + } + + protected static int compose8bit(int one, int two, int three, int four) { + return ( ( one & 0x000000FF ) << 24 ) | + ( ( two & 0x000000FF ) << 16 ) | + ( ( three & 0x000000FF ) << 8 ) | + ( ( four & 0x000000FF ) ) ; + } + + protected static int getComposed8bit(int bits32, int which ) { + switch (which) { + case 1: return ( bits32 & 0xFF000000 ) >> 24 ; + case 2: return ( bits32 & 0x00FF0000 ) >> 16 ; + case 3: return ( bits32 & 0x0000FF00 ) >> 8 ; + case 4: return ( bits32 & 0xFF0000FF ) ; + } + throw new GLException("argument which out of range: "+which); + } + + protected static String composed8BitToString(int bits32, boolean hex1, boolean hex2, boolean hex3, boolean hex4) { + int a = getComposed8bit(bits32, 1); + int b = getComposed8bit(bits32, 2); + int c = getComposed8bit(bits32, 3); + int d = getComposed8bit(bits32, 4); + return "["+toString(a, hex1)+", "+toString(b, hex2)+", "+toString(c, hex3)+", "+toString(d, hex4)+"]"; + } + + private static void validateProfileBits(int bits, String argName) { + int num = 0; + if( 0 != ( CTX_PROFILE_COMPAT & bits ) ) { num++; } + if( 0 != ( CTX_PROFILE_CORE & bits ) ) { num++; } + if( 0 != ( CTX_PROFILE_ES & bits ) ) { num++; } + if(1!=num) { + throw new GLException("Internal Error: "+argName+": 1 != num-profiles: "+num); + } + } + + // + // version mapping + // + + /** + * @see #getDeviceVersionAvailableKey(javax.media.nativewindow.AbstractGraphicsDevice, int, int) + */ + protected static /*final*/ HashMap/*<DeviceVersionAvailableKey, Integer>*/ deviceVersionAvailable = new HashMap(); + + /** + * @see #getUniqueDeviceString(javax.media.nativewindow.AbstractGraphicsDevice) + */ + private static /*final*/ HashSet/*<UniqueDeviceString>*/ deviceVersionsAvailableSet = new HashSet(); + + protected static String getDeviceVersionAvailableKey(AbstractGraphicsDevice device, int major, int profile) { + return device.getUniqueID() + "-" + toHexString(compose8bit(major, profile, 0, 0)); + } + + protected static boolean getAvailableGLVersionsSet(AbstractGraphicsDevice device) { + synchronized ( deviceVersionsAvailableSet ) { + return deviceVersionsAvailableSet.contains(device.getUniqueID()); + } + } + + protected static void setAvailableGLVersionsSet(AbstractGraphicsDevice device) { + synchronized ( deviceVersionsAvailableSet ) { + String devKey = device.getUniqueID(); + if ( deviceVersionsAvailableSet.contains(devKey) ) { + throw new InternalError("Already set: "+devKey); + } + deviceVersionsAvailableSet.add(devKey); + if (DEBUG0) { + String msg = getThreadName() + ": !!! createContextARB: SET mappedVersionsAvailableSet "+devKey; + // Throwable t = new Throwable(msg); + // t.printStackTrace(); + System.err.println(msg); + } + } + } + + /** + * Called by {@link jogamp.opengl.GLContextImpl#createContextARBMapVersionsAvailable} not intended to be used by + * implementations. However, if {@link #createContextARB} is not being used within + * {@link javax.media.opengl.GLDrawableFactory#getOrCreateSharedContext(javax.media.nativewindow.AbstractGraphicsDevice)}, + * GLProfile has to map the available versions. + * + * @param reqMajor Key Value either 1, 2, 3 or 4 + * @param profile Key Value either {@link #CTX_PROFILE_COMPAT}, {@link #CTX_PROFILE_CORE} or {@link #CTX_PROFILE_ES} + * @return the old mapped value + * + * @see #createContextARBMapVersionsAvailable + */ + protected static Integer mapAvailableGLVersion(AbstractGraphicsDevice device, + int reqMajor, int profile, int resMajor, int resMinor, int resCtp) + { + validateProfileBits(profile, "profile"); + validateProfileBits(resCtp, "resCtp"); + + String key = getDeviceVersionAvailableKey(device, reqMajor, profile); + Integer val = new Integer(compose8bit(resMajor, resMinor, resCtp, 0)); + synchronized(deviceVersionAvailable) { + val = (Integer) deviceVersionAvailable.put( key, val ); + } + return val; + } + + protected static Integer getAvailableGLVersion(AbstractGraphicsDevice device, int reqMajor, int profile) { + String key = getDeviceVersionAvailableKey(device, reqMajor, profile); + Integer val; + synchronized(deviceVersionAvailable) { + val = (Integer) deviceVersionAvailable.get( key ); + } + return val; + } + + /** + * @param reqMajor Key Value either 1, 2, 3 or 4 + * @param reqProfile Key Value either {@link #CTX_PROFILE_COMPAT}, {@link #CTX_PROFILE_CORE} or {@link #CTX_PROFILE_ES} + * @param major if not null, returns the used major version + * @param minor if not null, returns the used minor version + * @param ctp if not null, returns the used context profile + */ + protected static boolean getAvailableGLVersion(AbstractGraphicsDevice device, + int reqMajor, int reqProfile, int[] major, int minor[], int ctp[]) { + + Integer valI = getAvailableGLVersion(device, reqMajor, reqProfile); + if(null==valI) { + return false; + } + + int val = valI.intValue(); + + if(null!=major) { + major[0] = getComposed8bit(val, 1); + } + if(null!=minor) { + minor[0] = getComposed8bit(val, 2); + } + if(null!=ctp) { + ctp[0] = getComposed8bit(val, 3); + } + return true; + } + + /** + * @param major Key Value either 1, 2, 3 or 4 + * @param profile Key Value either {@link #CTX_PROFILE_COMPAT}, {@link #CTX_PROFILE_CORE} or {@link #CTX_PROFILE_ES} + */ + public static boolean isGLVersionAvailable(AbstractGraphicsDevice device, int major, int profile) { + return null != getAvailableGLVersion(device, major, profile); + } + + public static boolean isGLES1Available(AbstractGraphicsDevice device) { + return isGLVersionAvailable(device, 1, GLContext.CTX_PROFILE_ES); + } + + public static boolean isGLES2Available(AbstractGraphicsDevice device) { + return isGLVersionAvailable(device, 2, GLContext.CTX_PROFILE_ES); + } + + public static boolean isGL4bcAvailable(AbstractGraphicsDevice device) { + return isGLVersionAvailable(device, 4, CTX_PROFILE_COMPAT); + } + + public static boolean isGL4Available(AbstractGraphicsDevice device) { + return isGLVersionAvailable(device, 4, CTX_PROFILE_CORE); + } + + public static boolean isGL3bcAvailable(AbstractGraphicsDevice device) { + return isGLVersionAvailable(device, 3, CTX_PROFILE_COMPAT); + } + + public static boolean isGL3Available(AbstractGraphicsDevice device) { + return isGLVersionAvailable(device, 3, CTX_PROFILE_CORE); + } + + public static boolean isGL2Available(AbstractGraphicsDevice device) { + return isGLVersionAvailable(device, 2, CTX_PROFILE_COMPAT); + } + + /** + * @param major Key Value either 1, 2, 3 or 4 + * @param profile Key Value either {@link #CTX_PROFILE_COMPAT}, {@link #CTX_PROFILE_CORE} or {@link #CTX_PROFILE_ES} + */ + public static String getAvailableGLVersionAsString(AbstractGraphicsDevice device, int major, int profile) { + int _major[] = { 0 }; + int _minor[] = { 0 }; + int _ctp[] = { 0 }; + if(getAvailableGLVersion(device, major, profile, _major, _minor, _ctp)) { + return getGLVersion(_major[0], _minor[0], _ctp[0], null); + } + return null; + } + + public static String getGLVersion(int major, int minor, int ctp, String gl_version) { + boolean needColon = false; + StringBuffer sb = new StringBuffer(); + sb.append(major); + sb.append("."); + sb.append(minor); + sb.append(" ("); + needColon = appendString(sb, "ES", needColon, 0 != ( CTX_PROFILE_ES & ctp )); + needColon = appendString(sb, "compatibility profile", needColon, 0 != ( CTX_PROFILE_COMPAT & ctp )); + needColon = appendString(sb, "core profile", needColon, 0 != ( CTX_PROFILE_CORE & ctp )); + needColon = appendString(sb, "forward compatible", needColon, 0 != ( CTX_OPTION_FORWARD & ctp )); + needColon = appendString(sb, "any", needColon, 0 != ( CTX_OPTION_ANY & ctp )); + needColon = appendString(sb, "new", needColon, 0 != ( CTX_IS_ARB_CREATED & ctp )); + needColon = appendString(sb, "old", needColon, 0 == ( CTX_IS_ARB_CREATED & ctp )); + sb.append(")"); + if(null!=gl_version) { + sb.append(" - "); + sb.append(gl_version); + } + return sb.toString(); + } + + protected static String toString(int val, boolean hex) { + if(hex) { + return "0x" + Integer.toHexString(val); + } + return String.valueOf(val); + } + + protected static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + protected static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + + private static boolean appendString(StringBuffer sb, String string, boolean needColon, boolean condition) { + if(condition) { + if(needColon) { + sb.append(", "); + } + sb.append(string); + needColon=true; + } + return needColon; + } + + protected static String getThreadName() { + return Thread.currentThread().getName(); + } + +} + diff --git a/src/jogl/classes/javax/media/opengl/GLDrawable.java b/src/jogl/classes/javax/media/opengl/GLDrawable.java new file mode 100644 index 000000000..f4cd77059 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLDrawable.java @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeSurface; + + +/** An abstraction for an OpenGL rendering target. A GLDrawable's + primary functionality is to create OpenGL contexts which can be + used to perform rendering. A GLDrawable does not automatically + create an OpenGL context, but all implementations of {@link + GLAutoDrawable} do so upon creation. */ + +public interface GLDrawable { + /** + * Creates a new context for drawing to this drawable that will + * optionally share display lists and other server-side OpenGL + * objects with the specified GLContext. <P> + * + * The GLContext <code>share</code> need not be associated with this + * GLDrawable and may be null if sharing of display lists and other + * objects is not desired. See the note in the overview + * documentation on + * <a href="../../../overview-summary.html#SHARING">context sharing</a>. + */ + public GLContext createContext(GLContext shareWith); + + /** + * Indicates to on-screen GLDrawable implementations whether the + * underlying window has been created and can be drawn into. End + * users do not need to call this method; it is not necessary to + * call <code>setRealized</code> on a GLCanvas, a GLJPanel, or a + * GLPbuffer, as these perform the appropriate calls on their + * underlying GLDrawables internally. + * + * <P> + * + * Developers implementing new OpenGL components for various window + * toolkits need to call this method against GLDrawables obtained + * from the GLDrawableFactory via the {@link + * GLDrawableFactory#getGLDrawable + * GLDrawableFactory.getGLDrawable()} method. It must typically be + * called with an argument of <code>true</code> when the component + * associated with the GLDrawable is realized and with an argument + * of <code>false</code> just before the component is unrealized. + * For the AWT, this means calling <code>setRealized(true)</code> in + * the <code>addNotify</code> method and with an argument of + * <code>false</code> in the <code>removeNotify</code> method. + * + * <P> + * + * <code>GLDrawable</code> implementations should handle multiple + * cycles of <code>setRealized(true)</code> / + * <code>setRealized(false)</code> calls. Most, if not all, Java + * window toolkits have a persistent object associated with a given + * component, regardless of whether that component is currently + * realized. The <CODE>GLDrawable</CODE> object associated with a + * particular component is intended to be similarly persistent. A + * <CODE>GLDrawable</CODE> is intended to be created for a given + * component when it is constructed and live as long as that + * component. <code>setRealized</code> allows the + * <code>GLDrawable</code> to re-initialize and destroy any + * associated resources as the component becomes realized and + * unrealized, respectively. + * + * <P> + * + * With an argument of <code>true</code>, + * the minimum implementation shall call + * {@link NativeSurface#lockSurface() NativeSurface's lockSurface()} and if successfull: + * <ul> + * <li> Update the {@link GLCapabilities}, which are associated with + * the attached {@link NativeSurface}'s {@link AbstractGraphicsConfiguration}.</li> + * <li> Release the lock with {@link NativeSurface#unlockSurface() NativeSurface's unlockSurface()}.</li> + * </ul><br> + * This is important since {@link NativeSurface#lockSurface() NativeSurface's lockSurface()} + * ensures resolving the window/surface handles, and the drawable's {@link GLCapabilities} + * might have changed. + * + * <P> + * + * Calling this method has no other effects. For example, if + * <code>removeNotify</code> is called on a Canvas implementation + * for which a GLDrawable has been created, it is also necessary to + * destroy all OpenGL contexts associated with that GLDrawable. This + * is not done automatically by the implementation. + */ + public void setRealized(boolean realized); + + /** @return true if this drawable is realized, otherwise false */ + public boolean isRealized(); + + /** Returns the current width of this GLDrawable. */ + public int getWidth(); + + /** Returns the current height of this GLDrawable. */ + public int getHeight(); + + /** Swaps the front and back buffers of this drawable. For {@link + GLAutoDrawable} implementations, when automatic buffer swapping + is enabled (as is the default), this method is called + automatically and should not be called by the end user. */ + public void swapBuffers() throws GLException; + + /** Fetches the {@link GLCapabilitiesImmutable} corresponding to the chosen + OpenGL capabilities (pixel format / visual / GLProfile) for this drawable.<br> + On some platforms, the pixel format is not directly associated + with the drawable; a best attempt is made to return a reasonable + value in this case. <br> + This object shall be directly associated to the attached {@link NativeSurface}'s + {@link AbstractGraphicsConfiguration}, and if changes are necessary, + they should reflect those as well. + @return A copy of the queried object. + */ + public GLCapabilitiesImmutable getChosenGLCapabilities(); + + /** Fetches the {@link GLProfile} for this drawable. + Returns the GLProfile object, no copy. + */ + public GLProfile getGLProfile(); + + public NativeSurface getNativeSurface(); + + /** + * This is the GL/Windowing drawable handle.<br> + * It is usually the {@link javax.media.nativewindow.NativeSurface#getSurfaceHandle()}, + * ie the native surface handle of the underlying windowing toolkit.<br> + * However, on X11/GLX this reflects a GLXDrawable, which represents a GLXWindow, GLXPixmap, or GLXPbuffer.<br> + * On EGL, this represents the EGLSurface.<br> + */ + public long getHandle(); + + public GLDrawableFactory getFactory(); + + public String toString(); +} diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java new file mode 100644 index 000000000..73b2b3823 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -0,0 +1,554 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.List; + +import com.jogamp.common.JogampRuntimeException; +import jogamp.common.Debug; +import com.jogamp.common.util.ReflectionUtil; + +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.ProxySurface; + +/** <P> Provides a virtual machine- and operating system-independent + mechanism for creating {@link GLDrawable}s. </P> + + <P> The {@link javax.media.opengl.GLCapabilities} objects passed + in to the various factory methods are used as a hint for the + properties of the returned drawable. The default capabilities + selection algorithm (equivalent to passing in a null {@link + GLCapabilitiesChooser}) is described in {@link + DefaultGLCapabilitiesChooser}. Sophisticated applications needing + to change the selection algorithm may pass in their own {@link + GLCapabilitiesChooser} which can select from the available pixel + formats. The GLCapabilitiesChooser mechanism may not be supported + by all implementations or on all platforms, in which case any + passed GLCapabilitiesChooser will be ignored. </P> + + <P> Because of the multithreaded nature of the Java platform's + Abstract Window Toolkit, it is typically not possible to immediately + reject a given {@link GLCapabilities} as being unsupportable by + either returning <code>null</code> from the creation routines or + raising a {@link GLException}. The semantics of the rejection + process are (unfortunately) left unspecified for now. The current + implementation will cause a {@link GLException} to be raised + during the first repaint of the {@link javax.media.opengl.awt.GLCanvas} or {@link + javax.media.opengl.awt.GLJPanel} if the capabilities can not be met.<br> + {@link javax.media.opengl.GLPbuffer} are always + created immediately and their creation will fail with a + {@link javax.media.opengl.GLException} if errors occur. </P> + + <P> The concrete GLDrawableFactory subclass instantiated by {@link + #getFactory getFactory} can be changed by setting the system + property <code>opengl.factory.class.name</code> to the + fully-qualified name of the desired class. </P> +*/ + +public abstract class GLDrawableFactory { + + private static final GLDrawableFactory eglFactory; + private static final GLDrawableFactory nativeOSFactory; + private static final String nativeOSType; + static final String macosxFactoryClassNameCGL = "jogamp.opengl.macosx.cgl.MacOSXCGLDrawableFactory"; + static final String macosxFactoryClassNameAWTCGL = "jogamp.opengl.macosx.cgl.awt.MacOSXAWTCGLDrawableFactory"; + + protected static ArrayList/*<GLDrawableFactoryImpl>*/ glDrawableFactories = new ArrayList(); + + // Shutdown hook mechanism for the factory + private static boolean factoryShutdownHookRegistered = false; + private static Thread factoryShutdownHook = null; + + /** + * Instantiate singleton factories if available, EGLES1, EGLES2 and the OS native ones. + */ + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + registerFactoryShutdownHook(); + return null; + } + }); + + nativeOSType = NativeWindowFactory.getNativeWindowType(true); + + GLDrawableFactory tmp = null; + String factoryClassName = Debug.getProperty("jogl.gldrawablefactory.class.name", true, AccessController.getContext()); + ClassLoader cl = GLDrawableFactory.class.getClassLoader(); + if (null == factoryClassName) { + if ( nativeOSType.equals(NativeWindowFactory.TYPE_X11) ) { + factoryClassName = "jogamp.opengl.x11.glx.X11GLXDrawableFactory"; + } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_WINDOWS) ) { + factoryClassName = "jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory"; + } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_MACOSX) ) { + if(ReflectionUtil.isClassAvailable(macosxFactoryClassNameAWTCGL, cl)) { + factoryClassName = macosxFactoryClassNameAWTCGL; + } else { + factoryClassName = macosxFactoryClassNameCGL; + } + } else { + // may use egl*Factory .. + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - No native OS Factory for: "+nativeOSType+"; May use EGLDrawableFactory, if available." ); + } + } + } + if (null != factoryClassName) { + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - Native OS Factory for: "+nativeOSType+": "+factoryClassName); + } + try { + tmp = (GLDrawableFactory) ReflectionUtil.createInstance(factoryClassName, cl); + } catch (JogampRuntimeException jre) { + if (GLProfile.DEBUG) { + System.err.println("Info: GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName); + jre.printStackTrace(); + } + } + } + nativeOSFactory = tmp; + + tmp = null; + try { + tmp = (GLDrawableFactory) ReflectionUtil.createInstance("jogamp.opengl.egl.EGLDrawableFactory", cl); + } catch (JogampRuntimeException jre) { + if (GLProfile.DEBUG) { + System.err.println("Info: GLDrawableFactory.static - EGLDrawableFactory - not available"); + jre.printStackTrace(); + } + } + eglFactory = tmp; + } + + private static synchronized void registerFactoryShutdownHook() { + if (factoryShutdownHookRegistered) { + return; + } + factoryShutdownHook = new Thread(new Runnable() { + public void run() { + GLDrawableFactory.shutdownImpl(); + } + }); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().addShutdownHook(factoryShutdownHook); + return null; + } + }); + factoryShutdownHookRegistered = true; + } + + private static synchronized void unregisterFactoryShutdownHook() { + if (!factoryShutdownHookRegistered) { + return; + } + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().removeShutdownHook(factoryShutdownHook); + return null; + } + }); + factoryShutdownHookRegistered = false; + } + + private static void shutdownImpl() { + synchronized(glDrawableFactories) { + for(int i=0; i<glDrawableFactories.size(); i++) { + GLDrawableFactory factory = (GLDrawableFactory) glDrawableFactories.get(i); + factory.shutdownInstance(); + } + glDrawableFactories.clear(); + } + } + + protected static void shutdown() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + unregisterFactoryShutdownHook(); + return null; + } + }); + shutdownImpl(); + } + + private AbstractGraphicsDevice defaultSharedDevice = null; + + protected GLDrawableFactory() { + synchronized(glDrawableFactories) { + glDrawableFactories.add(this); + } + } + + protected void enterThreadCriticalZone() {}; + protected void leaveThreadCriticalZone() {}; + + protected abstract void shutdownInstance(); + + /** + * Retrieve the default <code>device</code> {@link AbstractGraphicsDevice#getConnection() connection}, + * {@link AbstractGraphicsDevice#getUnitID() unit ID} and {@link AbstractGraphicsDevice#getUniqueID() unique ID name}. for this factory<br> + * The implementation must return a non <code>null</code> default device, which must not be opened, ie. it's native handle is <code>null</code>. + * @return the default shared device for this factory, eg. :0.0 on X11 desktop. + */ + public abstract AbstractGraphicsDevice getDefaultDevice(); + + /** + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared the target device, may be <code>null</code> for the platform's default device. + * @return true if the device is compatible with this factory, ie. if it can be used for creation. Otherwise false. + */ + public abstract boolean getIsDeviceCompatible(AbstractGraphicsDevice device); + + protected final AbstractGraphicsDevice validateDevice(AbstractGraphicsDevice device) { + if(null==device) { + device = getDefaultDevice(); + if(null==device) { + throw new InternalError("no default device"); + } + if (GLProfile.DEBUG) { + System.err.println("Info: GLDrawableFactory.validateDevice: using default device : "+device); + } + } else if( !getIsDeviceCompatible(device) ) { + if (GLProfile.DEBUG) { + System.err.println("Info: GLDrawableFactory.validateDevice: device not compatible : "+device); + } + return null; + } + return device; + } + + /** + * Returns true if a shared context is already mapped to the <code>device</code> {@link AbstractGraphicsDevice#getConnection()}, + * or if a new shared context could be created and mapped. Otherwise return false.<br> + * Creation of the shared context is tried only once. + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared the target device, may be <code>null</code> for the platform's default device. + */ + public final boolean getIsSharedContextAvailable(AbstractGraphicsDevice device) { + return null != getOrCreateSharedContext(device); + } + + /** + * Returns the shared context mapped to the <code>device</code> {@link AbstractGraphicsDevice#getConnection()}, + * either a preexisting or newly created, or <code>null</code> if creation failed or not supported.<br> + * Creation of the shared context is tried only once. + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared the target device, may be <code>null</code> for the platform's default device. + */ + public final GLContext getOrCreateSharedContext(AbstractGraphicsDevice device) { + device = validateDevice(device); + if(null!=device) { + return getOrCreateSharedContextImpl(device); + } + return null; + } + protected abstract GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device); + + /** + * Returns the sole GLDrawableFactory instance for the desktop (X11, WGL, ..) if exist or null + */ + public static GLDrawableFactory getDesktopFactory() { + return nativeOSFactory; + } + + /** + * Returns the sole GLDrawableFactory instance for EGL if exist or null + */ + public static GLDrawableFactory getEGLFactory() { + return eglFactory; + } + + /** + * Returns the sole GLDrawableFactory instance. + * + * @param glProfile GLProfile to determine the factory type, ie EGLDrawableFactory, + * or one of the native GLDrawableFactory's, ie X11/GLX, Windows/WGL or MacOSX/CGL. + */ + public static GLDrawableFactory getFactory(GLProfile glProfile) throws GLException { + return getFactoryImpl(glProfile.getImplName()); + } + + protected static GLDrawableFactory getFactoryImpl(String glProfileImplName) throws GLException { + if ( GLProfile.usesNativeGLES(glProfileImplName) ) { + if(null==eglFactory) throw new GLException("EGLDrawableFactory unavailable: "+glProfileImplName); + return eglFactory; + } + if(null!=nativeOSFactory) { + return nativeOSFactory; + } + if(null!=eglFactory) { + return eglFactory; + } + throw new GLException("No native platform GLDrawableFactory, nor EGLDrawableFactory available: "+glProfileImplName); + } + + protected static GLDrawableFactory getFactoryImpl(AbstractGraphicsDevice device) throws GLException { + if(null != nativeOSFactory && nativeOSFactory.getIsDeviceCompatible(device)) { + return nativeOSFactory; + } + if(null != eglFactory && eglFactory.getIsDeviceCompatible(device)) { + return eglFactory; + } + throw new GLException("No native platform GLDrawableFactory, nor EGLDrawableFactory available: "+device); + } + + /** + * Returns an array of available GLCapabilities for the device.<br> + * The list is sorted by the native ID, ascending.<br> + * The chosen GLProfile statement in the result may not refer to the maximum available profile + * due to implementation constraints, ie using the shared resource. + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared the target device, may be <code>null</code> for the platform's default device. + * @return A list of {@link javax.media.opengl.GLCapabilitiesImmutable}'s, maybe empty if none is available. + */ + public final List/*GLCapabilitiesImmutable*/ getAvailableCapabilities(AbstractGraphicsDevice device) { + device = validateDevice(device); + if(null!=device) { + return getAvailableCapabilitiesImpl(device); + } + return null; + } + protected abstract List/*GLCapabilitiesImmutable*/ getAvailableCapabilitiesImpl(AbstractGraphicsDevice device); + + //---------------------------------------------------------------------- + // Methods to create high-level objects + + /** + * Returns a GLDrawable according to it's chosen Capabilities,<br> + * which determines pixel format, on- and offscreen incl. PBuffer type. + * <p> + * The native platform's chosen Capabilties are referenced within the target + * NativeSurface's AbstractGraphicsConfiguration.<p> + * + * In case target's {@link javax.media.nativewindow.Capabilities#isOnscreen()} is true,<br> + * an onscreen GLDrawable will be realized. + * <p> + * In case target's {@link javax.media.nativewindow.Capabilities#isOnscreen()} is false,<br> + * either a Pbuffer drawable is created if target's {@link javax.media.opengl.GLCapabilities#isPBuffer()} is true,<br> + * or a simple pixmap/bitmap drawable is created. The latter is unlikely to be hardware accelerated.<br> + * <p> + * + * @throws IllegalArgumentException if the passed target is null + * @throws GLException if any window system-specific errors caused + * the creation of the GLDrawable to fail. + * + * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + */ + public abstract GLDrawable createGLDrawable(NativeSurface target) + throws IllegalArgumentException, GLException; + + /** + * Creates a Offscreen GLDrawable incl it's offscreen {@link javax.media.nativewindow.NativeSurface} with the given capabilites and dimensions. + * <p> + * A Pbuffer drawable/surface is created if both {@link javax.media.opengl.GLCapabilities#isPBuffer() caps.isPBuffer()} + * and {@link #canCreateGLPbuffer(javax.media.nativewindow.AbstractGraphicsDevice) canCreateGLPbuffer(device)} is true.<br> + * Otherwise a simple pixmap/bitmap drawable/surface is created, which is unlikely to be hardware accelerated.<br> + * </p> + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared device to be used, may be <code>null</code> for the platform's default device. + * @param caps the requested GLCapabilties + * @param chooser the custom chooser, may be null for default + * @param width the requested offscreen width + * @param height the requested offscreen height + * + * @return the created offscreen GLDrawable + * + * @throws GLException if any window system-specific errors caused + * the creation of the Offscreen to fail. + */ + public abstract GLDrawable createOffscreenDrawable(AbstractGraphicsDevice device, + GLCapabilitiesImmutable capabilities, + GLCapabilitiesChooser chooser, + int width, int height) + throws GLException; + + /** + * Creates an offscreen NativeSurface.<br> + * A Pbuffer surface is created if both {@link javax.media.opengl.GLCapabilities#isPBuffer() caps.isPBuffer()} + * and {@link #canCreateGLPbuffer(javax.media.nativewindow.AbstractGraphicsDevice) canCreateGLPbuffer(device)} is true.<br> + * Otherwise a simple pixmap/bitmap surface is created. The latter is unlikely to be hardware accelerated.<br> + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared the target device, may be <code>null</code> for the platform's default device. + * @param caps the requested GLCapabilties + * @param chooser the custom chooser, may be null for default + * @param width the requested offscreen width + * @param height the requested offscreen height + * @return the created offscreen native surface + * + * @throws GLException if any window system-specific errors caused + * the creation of the GLDrawable to fail. + */ + public abstract NativeSurface createOffscreenSurface(AbstractGraphicsDevice device, + GLCapabilitiesImmutable caps, + GLCapabilitiesChooser chooser, + int width, int height); + + /** + * Highly experimental API entry, allowing developer of new windowing system bindings + * to leverage the native window handle to produce a NativeSurface implementation (ProxySurface), having the required GLCapabilities.<br> + * Such surface can be used to instantiate a GLDrawable and hence test your new binding w/o the + * costs of providing a full set of abstraction like the AWT GLCanvas or even the native NEWT bindings. + * + * @param device the platform's target device, shall not be <code>null</code> + * @param windowHandle the native window handle + * @param caps the requested GLCapabilties + * @param chooser the custom chooser, may be null for default + * @return The proxy surface wrapping the windowHandle on the device + */ + public abstract ProxySurface createProxySurface(AbstractGraphicsDevice device, + long windowHandle, + GLCapabilitiesImmutable caps, + GLCapabilitiesChooser chooser); + + /** + * Returns true if it is possible to create a GLPbuffer. Some older + * graphics cards do not have this capability. + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared the target device, may be <code>null</code> for the platform's default device. + */ + public abstract boolean canCreateGLPbuffer(AbstractGraphicsDevice device); + + /** + * Creates a GLPbuffer with the given capabilites and dimensions. <P> + * + * See the note in the overview documentation on + * <a href="../../../overview-summary.html#SHARING">context sharing</a>. + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared the target device, may be <code>null</code> for the platform's default device. + * @param capabilities the requested capabilities + * @param chooser the custom chooser, may be null for default + * @param initialWidth initial width of pbuffer + * @param initialHeight initial height of pbuffer + * @param shareWith a shared GLContext this GLPbuffer shall use + * + * @return the new {@link GLPbuffer} specific {@link GLAutoDrawable} + * + * @throws GLException if any window system-specific errors caused + * the creation of the GLPbuffer to fail. + */ + public abstract GLPbuffer createGLPbuffer(AbstractGraphicsDevice device, + GLCapabilitiesImmutable capabilities, + GLCapabilitiesChooser chooser, + int initialWidth, + int initialHeight, + GLContext shareWith) + throws GLException; + + //---------------------------------------------------------------------- + // Methods for interacting with third-party OpenGL libraries + + /** + * <P> Creates a GLContext object representing an existing OpenGL + * context in an external (third-party) OpenGL-based library. This + * GLContext object may be used to draw into this preexisting + * context using its {@link GL} and {@link + * javax.media.opengl.glu.GLU} objects. New contexts created through + * {@link GLDrawable}s may share textures and display lists with + * this external context. </P> + * + * <P> The underlying OpenGL context must be current on the current + * thread at the time this method is called. The user is responsible + * for the maintenance of the underlying OpenGL context; calls to + * <code>makeCurrent</code> and <code>release</code> on the returned + * GLContext object have no effect. If the underlying OpenGL context + * is destroyed, the <code>destroy</code> method should be called on + * the <code>GLContext</code>. A new <code>GLContext</code> object + * should be created for each newly-created underlying OpenGL + * context. + * + * @throws GLException if any window system-specific errors caused + * the creation of the external GLContext to fail. + */ + public abstract GLContext createExternalGLContext() + throws GLException; + + /** + * Returns true if it is possible to create an external GLDrawable + * object via {@link #createExternalGLDrawable}. + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared the target device, may be <code>null</code> for the platform's default device. + */ + public abstract boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device); + + /** + * <P> Creates a {@link GLDrawable} object representing an existing + * OpenGL drawable in an external (third-party) OpenGL-based + * library. This GLDrawable object may be used to create new, + * fully-functional {@link GLContext}s on the OpenGL drawable. This + * is useful when interoperating with a third-party OpenGL-based + * library and it is essential to not perturb the state of the + * library's existing context, even to the point of not sharing + * textures or display lists with that context. </P> + * + * <P> An underlying OpenGL context must be current on the desired + * drawable and the current thread at the time this method is + * called. The user is responsible for the maintenance of the + * underlying drawable. If one or more contexts are created on the + * drawable using {@link GLDrawable#createContext}, and the drawable + * is deleted by the third-party library, the user is responsible + * for calling {@link GLContext#destroy} on these contexts. </P> + * + * <P> Calls to <code>setSize</code>, <code>getWidth</code> and + * <code>getHeight</code> are illegal on the returned GLDrawable. If + * these operations are required by the user, they must be performed + * by the third-party library. </P> + * + * <P> It is legal to create both an external GLContext and + * GLDrawable representing the same third-party OpenGL entities. + * This can be used, for example, to query current state information + * using the external GLContext and then create and set up new + * GLContexts using the external GLDrawable. </P> + * + * <P> This functionality may not be available on all platforms and + * {@link #canCreateExternalGLDrawable} should be called first to + * see if it is present. For example, on X11 platforms, this API + * requires the presence of GLX 1.3 or later. + * + * @throws GLException if any window system-specific errors caused + * the creation of the external GLDrawable to fail. + */ + public abstract GLDrawable createExternalGLDrawable() + throws GLException; +} diff --git a/src/jogl/classes/javax/media/opengl/GLEventListener.java b/src/jogl/classes/javax/media/opengl/GLEventListener.java new file mode 100644 index 000000000..15fae4a39 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLEventListener.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +import java.util.EventListener; + +/** Declares events which client code can use to manage OpenGL + rendering into a {@link GLAutoDrawable}. At the time any of these + methods is called, the drawable has made its associated OpenGL + context current, so it is valid to make OpenGL calls. */ + +public interface GLEventListener extends EventListener { + /** Called by the drawable immediately after the OpenGL context is + initialized. Can be used to perform one-time OpenGL + initialization per GLContext, such as setup of lights and display lists.<p> + + Note that this method may be called more than once if the underlying + OpenGL context for the GLAutoDrawable is destroyed and + recreated, for example if a GLCanvas is removed from the widget + hierarchy and later added again. + */ + public void init(GLAutoDrawable drawable); + + /** Notifies the listener to perform the release of all OpenGL + resources per GLContext, such as memory buffers and GLSL programs.<P> + + Called by the drawable before the OpenGL context is + destroyed by an external event, like a reconfiguration of the + {@link GLAutoDrawable} closing an attached window, + but also manually by calling {@link GLAutoDrawable#destroy destroy}.<P> + + Note that this event does not imply the end of life of the application. + It could be produced with a followup call to {@link #init(GLAutoDrawable)} + in case the GLContext has been recreated, + e.g. due to a pixel configuration change in a multihead environment. + */ + public void dispose(GLAutoDrawable drawable); + + /** Called by the drawable to initiate OpenGL rendering by the + client. After all GLEventListeners have been notified of a + display event, the drawable will swap its buffers if {@link + GLAutoDrawable#setAutoSwapBufferMode setAutoSwapBufferMode} is + enabled. */ + public void display(GLAutoDrawable drawable); + + /** Called by the drawable during the first repaint after the + component has been resized. The client can update the viewport + and view volume of the window appropriately, for example by a + call to {@link javax.media.opengl.GL#glViewport}; note that for + convenience the component has already called <code>glViewport(x, + y, width, height)</code> when this method is called, so the + client may not have to do anything in this method. + */ + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height); +} diff --git a/src/jogl/classes/javax/media/opengl/GLException.java b/src/jogl/classes/javax/media/opengl/GLException.java new file mode 100644 index 000000000..644042e15 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLException.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +/** A generic exception for OpenGL errors used throughout the binding + as a substitute for {@link RuntimeException}. */ + +public class GLException extends RuntimeException { + /** Constructs a GLException object. */ + public GLException() { + super(); + } + + /** Constructs a GLException object with the specified detail + message. */ + public GLException(String message) { + super(message); + } + + /** Constructs a GLException object with the specified detail + message and root cause. */ + public GLException(String message, Throwable cause) { + super(message, cause); + } + + /** Constructs a GLException object with the specified root + cause. */ + public GLException(Throwable cause) { + super(cause); + } +} diff --git a/src/jogl/classes/javax/media/opengl/GLPbuffer.java b/src/jogl/classes/javax/media/opengl/GLPbuffer.java new file mode 100644 index 000000000..0250365b0 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLPbuffer.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +/** Provides offscreen rendering support via pbuffers. The principal + addition of this interface is a {@link #destroy} method to + deallocate the pbuffer and its associated resources. It also + contains experimental methods for accessing the pbuffer's contents + as a texture map and enabling rendering to floating-point frame + buffers. These methods are not guaranteed to be supported on all + platforms and may be deprecated in a future release. */ + +public interface GLPbuffer extends GLAutoDrawable { + /** Indicates the GL_APPLE_float_pixels extension is being used for this pbuffer. */ + public static final int APPLE_FLOAT = 1; + + /** Indicates the GL_ATI_texture_float extension is being used for this pbuffer. */ + public static final int ATI_FLOAT = 2; + + /** Indicates the GL_NV_float_buffer extension is being used for this pbuffer. */ + public static final int NV_FLOAT = 3; + + /** Binds this pbuffer to its internal texture target. Only valid to + call if offscreen render-to-texture has been specified in the + NWCapabilities for this GLPbuffer. If the + render-to-texture-rectangle capability has also been specified, + this will use e.g. wglBindTexImageARB as its implementation and + cause the texture to be bound to e.g. the + GL_TEXTURE_RECTANGLE_NV state; otherwise, during the display() + phase the pixels will have been copied into an internal texture + target and this will cause that to be bound to the GL_TEXTURE_2D + state. */ + public void bindTexture(); + + /** Unbinds the pbuffer from its internal texture target. */ + public void releaseTexture(); + + /** Destroys the native resources associated with this pbuffer. It + is not valid to call display() or any other routines on this + pbuffer after it has been destroyed. Before destroying the + pbuffer, the application must destroy any additional OpenGL + contexts which have been created for the pbuffer via {@link + #createContext}. */ + public void destroy(); + + /** Indicates which vendor's extension is being used to support + floating point channels in this pbuffer if that capability was + requested in the NWCapabilities during pbuffer creation. Returns + one of NV_FLOAT, ATI_FLOAT or APPLE_FLOAT, or throws GLException + if floating-point channels were not requested for this pbuffer. + This function may only be called once the init method for this + pbuffer's GLEventListener has been called. */ + public int getFloatingPointMode(); +} diff --git a/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java b/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java new file mode 100644 index 000000000..926651c1d --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package javax.media.opengl; + +import java.lang.reflect.*; +import java.util.StringTokenizer; + +import jogamp.opengl.*; + +/** + * Factory for pipelining GL instances + */ +public class GLPipelineFactory { + public static final boolean DEBUG = Debug.debug("GLPipelineFactory"); + + /** + * Creates a pipelined GL instance using the given downstream <code>downstream</code> + * and optional arguments <code>additionalArgs</code> for the constructor.<br> + * + * The upstream GL instance is determined as follows: + * <ul> + * <li> Use <code>pipelineClazzBaseName</code> as the class name's full basename, incl. package name</li> + * <li> For the <code>downstream</code> class and it's superclasses, do:</li> + * <ul> + * <li> For all <code>downstream</code> class and superclass interfaces, do:</li> + * <ul> + * <li> If <code>reqInterface</code> is not null and the interface is unequal, continue loop.</li> + * <li> If <code>downstream</code> is not instance of interface, continue loop.</li> + * <li> If upstream class is available use it, end loop.</li> + * </ul> + * </ul> + * </ul><br> + * + * @param pipelineClazzBaseName the basename of the pipline class name + * @param reqInterface optional requested interface to be used, may be null, in which case the first matching one is used + * @param downstream is always the 1st argument for the upstream constructor + * @param additionalArgs additional arguments for the upstream constructor + */ + public static final GL create(String pipelineClazzBaseName, Class reqInterface, GL downstream, Object[] additionalArgs) { + Class downstreamClazz = downstream.getClass(); + Class upstreamClazz = null; + Class interfaceClazz = null; + + if(DEBUG) { + System.out.println("GLPipelineFactory: Start "+downstreamClazz.getName()+", req. Interface: "+reqInterface+" -> "+pipelineClazzBaseName); + } + + // For all classes: child -> parent + do { + // For all interfaces: right -> left == child -> parent + // It is important that this matches with the gluegen cfg file's 'Implements' clause ! + Class[] clazzes = downstreamClazz.getInterfaces(); + for(int i=clazzes.length-1; null==upstreamClazz && i>=0; i--) { + if(DEBUG) { + System.out.println("GLPipelineFactory: Try "+downstreamClazz.getName()+" Interface["+i+"]: "+clazzes[i].getName()); + } + if( reqInterface != null && !reqInterface.getName().equals(clazzes[i].getName()) ) { + if(DEBUG) { + System.out.println("GLPipelineFactory: requested Interface "+reqInterface+" is _not_ "+ clazzes[i].getName()); + } + continue; // not the requested one .. + } + if( ! clazzes[i].isInstance(downstream) ) { + if(DEBUG) { + System.out.println("GLPipelineFactory: "+downstream.getClass().getName() + " is _not_ instance of "+ clazzes[i].getName()); + } + continue; // not a compatible one + } else { + if(DEBUG) { + System.out.println("GLPipelineFactory: "+downstream.getClass().getName() + " _is_ instance of "+ clazzes[i].getName()); + } + } + upstreamClazz = getUpstreamClazz(clazzes[i], pipelineClazzBaseName); + if( null != upstreamClazz ) { + interfaceClazz = clazzes[i]; + } + } + + if(null==upstreamClazz) { + downstreamClazz = downstreamClazz.getSuperclass(); + } + } while (null!=downstreamClazz && null==upstreamClazz); + + + if(null==upstreamClazz) { + throw new GLException("No pipeline ("+pipelineClazzBaseName+"*) available for :"+downstream.getClass().getName()); + } + + if(DEBUG) { + System.out.println("GLPipelineFactory: Got : "+ upstreamClazz.getName()+", base interface: "+interfaceClazz.getName()); + } + + Class[] cstrArgTypes = new Class[ 1 + ( ( null==additionalArgs ) ? 0 : additionalArgs.length ) ] ; + { + int i = 0; + cstrArgTypes[i++] = interfaceClazz; + for(int j=0; null!=additionalArgs && j<additionalArgs.length; j++) { + cstrArgTypes[i++] = additionalArgs[j].getClass(); + } + } + Constructor cstr = null; + try { + cstr = upstreamClazz.getDeclaredConstructor( cstrArgTypes ); + } catch(NoSuchMethodException nsme) { + throw new GLException("Couldn't find pipeline constructor: " + upstreamClazz.getName() + + " ( "+getArgsClassNameList(downstreamClazz, additionalArgs) +" )"); + } + Object instance = null; + try { + Object[] cstrArgs = new Object[ 1 + ( ( null==additionalArgs ) ? 0 : additionalArgs.length ) ] ; + { + int i = 0; + cstrArgs[i++] = downstream; + for(int j=0; null!=additionalArgs && j<additionalArgs.length; j++) { + cstrArgs[i++] = additionalArgs[j]; + } + } + instance = cstr.newInstance( cstrArgs ) ; + } catch (Throwable t) { t.printStackTrace(); } + if(null==instance) { + throw new GLException("Error: Couldn't create instance of pipeline: "+upstreamClazz.getName()+ + " ( "+getArgsClassNameList(downstreamClazz, additionalArgs) +" )"); + } + if( ! (instance instanceof GL) ) { + throw new GLException("Error: "+upstreamClazz.getName()+" not an instance of GL"); + } + return (GL) instance; + } + + private static final String getArgsClassNameList(Class arg0, Object[] args) { + StringBuffer sb = new StringBuffer(); + sb.append(arg0.getName()); + if(args!=null) { + for(int j=0; j<args.length; j++) { + sb.append(", "); + sb.append(args[j].getClass().getName()); + } + } + return sb.toString(); + } + + private static final Class getUpstreamClazz(Class downstreamClazz, String pipelineClazzBaseName) { + String downstreamClazzName = downstreamClazz.getName(); + + StringTokenizer st = new StringTokenizer(downstreamClazzName, "."); + String downstreamClazzBaseName = downstreamClazzName; + while(st.hasMoreTokens()) { + downstreamClazzBaseName = st.nextToken(); + } + String upstreamClazzName = pipelineClazzBaseName+downstreamClazzBaseName; + + Class upstreamClazz = null; + try { + upstreamClazz = Class.forName(upstreamClazzName, true, GLPipelineFactory.class.getClassLoader()); + } catch (Throwable e) { e.printStackTrace(); } + + return upstreamClazz; + } +} + diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java new file mode 100644 index 000000000..17313f770 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -0,0 +1,1609 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package javax.media.opengl; + +import jogamp.opengl.Debug; +import jogamp.opengl.GLDrawableFactoryImpl; +import jogamp.opengl.GLDynamicLookupHelper; +import jogamp.opengl.DesktopGLDynamicLookupHelper; + +import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.jvm.JVMUtil; +import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.nativewindow.NativeWindowVersion; +import com.jogamp.opengl.JoglVersion; + +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.fixedfunc.GLPointerFunc; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +/** + * Specifies the the OpenGL profile. + * + * This class static singleton initialization queries the availability of all OpenGL Profiles + * and instantiates singleton GLProfile objects for each available profile. + * + * The platform default profile may be used, using {@link GLProfile#GetProfileDefault()}, + * or more specialized versions using the other static GetProfile methods. + */ +public class GLProfile { + + public static final boolean DEBUG = Debug.debug("GLProfile"); + + /** + * Static one time initialization of JOGL. + * <p> + * The parameter <code>firstUIActionOnProcess</code> has an impact on concurrent locking,<br> + * see {@link javax.media.nativewindow.NativeWindowFactory#initSingleton(boolean) NativeWindowFactory.initSingleton(firstUIActionOnProcess)}. + * </p> + * <p> + * Applications shall call this methods <b>ASAP</b>, before any other UI invocation.<br> + * You may issue the call in your <code>main class</code> static block, which is the earliest point in your application/applet lifecycle, + * or within the <code>main function</code>.<br> + * In case applications are able to initialize JOGL before any other UI action,<br> + * they shall invoke this method with <code>firstUIActionOnProcess=true</code> and benefit from fast native multithreading support on all platforms if possible.</P> + * <P> + * RCP Application (Applet's, Webstart, Netbeans, ..) using JOGL may not be able to initialize JOGL + * before the first UI action.<br> + * In such case you shall invoke this method with <code>firstUIActionOnProcess=false</code>.<br> + * On some platforms, notably X11 with AWT usage, JOGL will utilize special locking mechanisms which may slow down your + * application.</P> + * <P> + * Remark: NEWT is currently not affected by this behavior, ie always uses native multithreading.</P> + * <P> + * However, in case this method is not invoked, hence GLProfile is not initialized explicitly by the user,<br> + * the first call to {@link #getDefault()}, {@link #get(java.lang.String)}, etc, will initialize with <code>firstUIActionOnProcess=false</code>,<br> + * hence without the possibility to enable native multithreading.<br> + * This is not the recommended way, since it may has a performance impact, but it allows you to run code without explicit initialization.</P> + * <P> + * In case no explicit initialization was invoked and the implicit initialization didn't happen,<br> + * you may encounter the following exception: + * <pre> + * javax.media.opengl.GLException: No default profile available + * </pre></P> + * + * @param firstUIActionOnProcess Should be <code>true</code> if called before the first UI action of the running program, + * otherwise <code>false</code>. + */ + public static synchronized void initSingleton(final boolean firstUIActionOnProcess) { + if(!initialized) { + initialized = true; + // run the whole static initialization privileged to speed up, + // since this skips checking further access + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + initProfilesForDefaultDevices(firstUIActionOnProcess); + return null; + } + }); + } + } + + /** + * Trigger eager initialization of GLProfiles for the given device, + * in case it isn't done yet. + */ + public static void initProfiles(AbstractGraphicsDevice device) { + getProfileMap(device); + } + + /** + * Manual shutdown method, may be called after your last JOGL use + * within the running JVM.<br> + * It releases all temporary created resources, ie issues {@link javax.media.opengl.GLDrawableFactory#shutdown()}.<br> + * The shutdown implementation is called via the JVM shutdown hook, if not manually invoked here.<br> + * Invoke <code>shutdown()</code> manually is recommended, due to the unreliable JVM state within the shutdown hook.<br> + */ + public static synchronized void shutdown() { + if(initialized) { + initialized = false; + GLDrawableFactory.shutdown(); + } + } + + // + // Query platform available OpenGL implementation + // + + public static boolean isGL4bcAvailable(AbstractGraphicsDevice device) { + return null != getProfileMap(device).get(GL4bc); + } + + public static boolean isGL4Available(AbstractGraphicsDevice device) { + return null != getProfileMap(device).get(GL4); + } + + public static boolean isGL3bcAvailable(AbstractGraphicsDevice device) { + return null != getProfileMap(device).get(GL3bc); + } + + public static boolean isGL3Available(AbstractGraphicsDevice device) { + return null != getProfileMap(device).get(GL3); + } + + public static boolean isGL2Available(AbstractGraphicsDevice device) { + return null != getProfileMap(device).get(GL2); + } + + public static boolean isGLES2Available(AbstractGraphicsDevice device) { + return null != getProfileMap(device).get(GLES2); + } + + public static boolean isGLES1Available(AbstractGraphicsDevice device) { + return null != getProfileMap(device).get(GLES1); + } + + public static boolean isGL2ES1Available(AbstractGraphicsDevice device) { + return null != getProfileMap(device).get(GL2ES1); + } + + public static boolean isGL2ES2Available(AbstractGraphicsDevice device) { + return null != getProfileMap(device).get(GL2ES2); + } + + /** Uses the default device */ + public static boolean isGL4bcAvailable() { + return isGL4bcAvailable(null); + } + + /** Uses the default device */ + public static boolean isGL4Available() { + return isGL4Available(null); + } + + /** Uses the default device */ + public static boolean isGL3bcAvailable() { + return isGL3bcAvailable(null); + } + + /** Uses the default device */ + public static boolean isGL3Available() { + return isGL3Available(null); + } + + /** Uses the default device */ + public static boolean isGL2Available() { + return isGL2Available(null); + } + + /** Uses the default device */ + public static boolean isGLES2Available() { + return isGLES2Available(null); + } + + /** Uses the default device */ + public static boolean isGLES1Available() { + return isGLES1Available(null); + } + + /** Uses the default device */ + public static boolean isGL2ES1Available() { + return isGL2ES1Available(null); + } + + /** Uses the default device */ + public static boolean isGL2ES2Available() { + return isGL2ES2Available(null); + } + + public static String glAvailabilityToString(AbstractGraphicsDevice device) { + boolean avail; + StringBuffer sb = new StringBuffer(); + + validateInitialization(); + + if(null==device) { + device = defaultDevice; + } + + sb.append("GLAvailability[Native[GL4bc "); + avail=isGL4bcAvailable(device); + sb.append(avail); + if(avail) { + glAvailabilityToString(device, sb, 4, GLContext.CTX_PROFILE_COMPAT); + } + + sb.append(", GL4 "); + avail=isGL4Available(device); + sb.append(avail); + if(avail) { + glAvailabilityToString(device, sb, 4, GLContext.CTX_PROFILE_CORE); + } + + sb.append(", GL3bc "); + avail=isGL3bcAvailable(device); + sb.append(avail); + if(avail) { + glAvailabilityToString(device, sb, 3, GLContext.CTX_PROFILE_COMPAT); + } + + sb.append(", GL3 "); + avail=isGL3Available(device); + sb.append(avail); + if(avail) { + glAvailabilityToString(device, sb, 3, GLContext.CTX_PROFILE_CORE); + } + + sb.append(", GL2 "); + avail=isGL2Available(device); + sb.append(avail); + if(avail) { + glAvailabilityToString(device, sb, 2, GLContext.CTX_PROFILE_COMPAT); + } + + sb.append(", GL2ES1 "); + sb.append(isGL2ES1Available(device)); + + sb.append(", GLES1 "); + avail=isGLES1Available(device); + sb.append(avail); + if(avail) { + glAvailabilityToString(device, sb, 1, GLContext.CTX_PROFILE_ES); + } + + sb.append(", GL2ES2 "); + sb.append(isGL2ES2Available(device)); + + sb.append(", GLES2 "); + avail=isGLES2Available(device); + sb.append(avail); + if(avail) { + glAvailabilityToString(device, sb, 2, GLContext.CTX_PROFILE_ES); + } + + sb.append("], Profiles["); + for(Iterator i=getProfileMap(device).values().iterator(); i.hasNext(); ) { + sb.append(((GLProfile)i.next()).toString()); + sb.append(", "); + } + sb.append(", default "); + sb.append(getDefault(device)); + sb.append("]]"); + + return sb.toString(); + } + + /** Uses the default device */ + public static String glAvailabilityToString() { + return glAvailabilityToString(null); + } + + // + // Public (user-visible) profiles + // + + /** The desktop OpenGL compatibility profile 4.x, with x >= 0, ie GL2 plus GL4.<br> + <code>bc</code> stands for backward compatibility. */ + public static final String GL4bc = "GL4bc"; + + /** The desktop OpenGL core profile 4.x, with x >= 0 */ + public static final String GL4 = "GL4"; + + /** The desktop OpenGL compatibility profile 3.x, with x >= 1, ie GL2 plus GL3.<br> + <code>bc</code> stands for backward compatibility. */ + public static final String GL3bc = "GL3bc"; + + /** The desktop OpenGL core profile 3.x, with x >= 1 */ + public static final String GL3 = "GL3"; + + /** The desktop OpenGL profile 1.x up to 3.0 */ + public static final String GL2 = "GL2"; + + /** The embedded OpenGL profile ES 1.x, with x >= 0 */ + public static final String GLES1 = "GLES1"; + + /** The embedded OpenGL profile ES 2.x, with x >= 0 */ + public static final String GLES2 = "GLES2"; + + /** The intersection of the desktop GL2 and embedded ES1 profile */ + public static final String GL2ES1 = "GL2ES1"; + + /** The intersection of the desktop GL3, GL2 and embedded ES2 profile */ + public static final String GL2ES2 = "GL2ES2"; + + /** The intersection of the desktop GL3 and GL2 profile */ + public static final String GL2GL3 = "GL2GL3"; + + /** The default profile, used for the device default profile map */ + private static final String GL_DEFAULT = "GL_DEFAULT"; + + /** + * All GL Profiles in the order of default detection. + * Desktop compatibility profiles (the one with fixed function pipeline) comes first + * from highest to lowest version. + * + * <ul> + * <li> GL4bc + * <li> GL3bc + * <li> GL2 + * <li> GL2GL3 + * <li> GL4 + * <li> GL3 + * <li> GL2ES2 + * <li> GLES2 + * <li> GL2ES1 + * <li> GLES1 + * </ul> + * + */ + public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL4bc, GL3bc, GL2, GL2GL3, GL4, GL3, GL2ES2, GLES2, GL2ES1, GLES1 }; + + /** + * Order of maximum profiles. + * + * <ul> + * <li> GL4bc + * <li> GL4 + * <li> GL3bc + * <li> GL3 + * <li> GL2 + * <li> GL2GL3 + * <li> GL2ES2 + * <li> GLES2 + * <li> GL2ES1 + * <li> GLES1 + * </ul> + * + */ + public static final String[] GL_PROFILE_LIST_MAX = new String[] { GL4bc, GL4, GL3bc, GL3, GL2, GL2GL3, GL2ES2, GLES2, GL2ES1, GLES1 }; + + /** + * Order of minimum original desktop profiles. + * + * <ul> + * <li> GL2 + * <li> GL3bc + * <li> GL4bc + * <li> GL3 + * <li> GL4 + * </ul> + * + */ + public static final String[] GL_PROFILE_LIST_MIN_DESKTOP = new String[] { GL2, GL3bc, GL4bc, GL3, GL4 }; + + /** + * Order of maximum fixed function profiles + * + * <ul> + * <li> GL4bc + * <li> GL3bc + * <li> GL2 + * <li> GL2ES1 + * <li> GLES1 + * </ul> + * + */ + public static final String[] GL_PROFILE_LIST_MAX_FIXEDFUNC = new String[] { GL4bc, GL3bc, GL2, GL2ES1, GLES1 }; + + /** + * Order of maximum programmable shader profiles + * + * <ul> + * <li> GL4 + * <li> GL4bc + * <li> GL3 + * <li> GL3bc + * <li> GL2 + * <li> GL2ES2 + * <li> GLES2 + * </ul> + * + */ + public static final String[] GL_PROFILE_LIST_MAX_PROGSHADER = new String[] { GL4bc, GL4, GL3bc, GL3, GL2, GL2ES2, GLES2 }; + + /** + * All GL2ES2 Profiles in the order of default detection. + * + * <ul> + * <li> GL2ES2 + * <li> GL2 + * <li> GL3 + * <li> GL4 + * <li> GLES2 + * </ul> + * + */ + public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL4, GL3, GL2, GLES2 }; + + /** + * All GL2ES1 Profiles in the order of default detection. + * + * <ul> + * <li> GL2ES1 + * <li> GL2 + * <li> GL3bc + * <li> GL4bc + * <li> GLES1 + * </ul> + * + */ + public static final String[] GL_PROFILE_LIST_GL2ES1 = new String[] { GL2ES1, GL4bc, GL3bc, GL2, GLES1 }; + + /** + * All GLES Profiles in the order of default detection. + * + * <ul> + * <li> GLES2 + * <li> GLES1 + * </ul> + * + */ + public static final String[] GL_PROFILE_LIST_GLES = new String[] { GLES2, GLES1 }; + + /** Returns a default GLProfile object, reflecting the best for the running platform. + * It selects the first of the set {@link GLProfile#GL_PROFILE_LIST_ALL} + * @see #GL_PROFILE_LIST_ALL + */ + public static GLProfile getDefault(AbstractGraphicsDevice device) { + GLProfile glp = get(device, GL_DEFAULT); + return glp; + } + + /** Uses the default device */ + public static GLProfile getDefault() { + return getDefault(defaultDevice); + } + + /** + * Returns the highest profile. + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MAX} + * + * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_MAX + */ + public static GLProfile getMaximum(AbstractGraphicsDevice device) + throws GLException + { + return get(device, GL_PROFILE_LIST_MAX); + } + + /** Uses the default device */ + public static GLProfile getMaximum() + throws GLException + { + return get(GL_PROFILE_LIST_MAX); + } + + /** + * Returns the lowest desktop profile. + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MIN_DESKTOP} + * + * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_MIN_DESKTOP + */ + public static GLProfile getMinDesktop(AbstractGraphicsDevice device) + throws GLException + { + return get(device, GL_PROFILE_LIST_MIN_DESKTOP); + } + + /** Uses the default device */ + public static GLProfile getMinDesktop() + throws GLException + { + return get(GL_PROFILE_LIST_MIN_DESKTOP); + } + + + /** + * Returns the highest profile, implementing the fixed function pipeline. + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MAX_FIXEDFUNC} + * + * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_MAX_FIXEDFUNC + */ + public static GLProfile getMaxFixedFunc(AbstractGraphicsDevice device) + throws GLException + { + return get(device, GL_PROFILE_LIST_MAX_FIXEDFUNC); + } + + /** Uses the default device */ + public static GLProfile getMaxFixedFunc() + throws GLException + { + return get(GL_PROFILE_LIST_MAX_FIXEDFUNC); + } + + /** + * Returns the highest profile, implementing the programmable shader pipeline. + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MAX_PROGSHADER} + * + * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_MAX_PROGSHADER + */ + public static GLProfile getMaxProgrammable(AbstractGraphicsDevice device) + throws GLException + { + return get(device, GL_PROFILE_LIST_MAX_PROGSHADER); + } + + /** Uses the default device */ + public static GLProfile getMaxProgrammable() + throws GLException + { + return get(GL_PROFILE_LIST_MAX_PROGSHADER); + } + + /** + * Returns a profile, implementing the interface GL2ES1. + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES1} + * + * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_GL2ES1 + */ + public static GLProfile getGL2ES1(AbstractGraphicsDevice device) + throws GLException + { + return get(device, GL_PROFILE_LIST_GL2ES1); + } + + /** Uses the default device */ + public static GLProfile getGL2ES1() + throws GLException + { + return get(GL_PROFILE_LIST_GL2ES1); + } + + /** + * Returns a profile, implementing the interface GL2ES2. + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES2} + * + * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_GL2ES2 + */ + public static GLProfile getGL2ES2(AbstractGraphicsDevice device) + throws GLException + { + return get(device, GL_PROFILE_LIST_GL2ES2); + } + + /** Uses the default device */ + public static GLProfile getGL2ES2() + throws GLException + { + return get(GL_PROFILE_LIST_GL2ES2); + } + + /** Returns a GLProfile object. + * verifies the given profile and chooses an appropriate implementation. + * A generic value of <code>null</code> or <code>GL</code> will result in + * the default profile. + * + * @throws GLException if no implementation for the given profile is found. + */ + public static GLProfile get(AbstractGraphicsDevice device, String profile) + throws GLException + { + if(null==profile || profile.equals("GL")) { + profile = GL_DEFAULT; + } + return (GLProfile) getProfileMap(device).get(profile); + } + + /** Uses the default device */ + public static GLProfile get(String profile) + throws GLException + { + return get(defaultDevice, profile); + } + + /** + * Returns the first profile from the given list, + * where an implementation is available. + * + * @throws GLException if no implementation for the given profile is found. + */ + public static GLProfile get(AbstractGraphicsDevice device, String[] profiles) + throws GLException + { + HashMap map = getProfileMap(device); + for(int i=0; i<profiles.length; i++) { + String profile = profiles[i]; + GLProfile glProfile = (GLProfile) map.get(profile); + if(null!=glProfile) { + return glProfile; + } + } + throw new GLException("Profiles "+array2String(profiles)+" not available on device "+device); + } + + /** Uses the default device */ + public static GLProfile get(String[] profiles) + throws GLException + { + return get(defaultDevice, profiles); + } + + /** Indicates whether the native OpenGL ES1 profile is in use. + * This requires an EGL interface. + */ + public static boolean usesNativeGLES1(String profileImpl) { + return GLES1.equals(profileImpl); + } + + /** Indicates whether the native OpenGL ES2 profile is in use. + * This requires an EGL or ES2 compatible interface. + */ + public static boolean usesNativeGLES2(String profileImpl) { + return GLES2.equals(profileImpl); + } + + /** Indicates whether either of the native OpenGL ES profiles are in use. */ + public static boolean usesNativeGLES(String profileImpl) { + return usesNativeGLES2(profileImpl) || usesNativeGLES1(profileImpl); + } + + /** @return {@link javax.media.nativewindow.NativeWindowFactory#isAWTAvailable()} and + JOGL's AWT part */ + public static boolean isAWTAvailable() { return isAWTAvailable; } + + public static String getGLTypeName(int type) { + switch (type) { + case GL.GL_UNSIGNED_BYTE: + return "GL_UNSIGNED_BYTE"; + case GL.GL_BYTE: + return "GL_BYTE"; + case GL.GL_UNSIGNED_SHORT: + return "GL_UNSIGNED_SHORT"; + case GL.GL_SHORT: + return "GL_SHORT"; + case GL.GL_FLOAT: + return "GL_FLOAT"; + case GL.GL_FIXED: + return "GL_FIXED"; + case javax.media.opengl.GL2ES2.GL_INT: + return "GL_INT"; + case javax.media.opengl.GL2ES2.GL_UNSIGNED_INT: + return "GL_UNSIGNED_INT"; + case javax.media.opengl.GL2.GL_DOUBLE: + return "GL_DOUBLE"; + case javax.media.opengl.GL2.GL_2_BYTES: + return "GL_2_BYTES"; + case javax.media.opengl.GL2.GL_3_BYTES: + return "GL_3_BYTES"; + case javax.media.opengl.GL2.GL_4_BYTES: + return "GL_4_BYTES"; + } + return null; + } + + public static String getGLArrayName(int array) { + switch(array) { + case GLPointerFunc.GL_VERTEX_ARRAY: + return "GL_VERTEX_ARRAY"; + case GLPointerFunc.GL_NORMAL_ARRAY: + return "GL_NORMAL_ARRAY"; + case GLPointerFunc.GL_COLOR_ARRAY: + return "GL_COLOR_ARRAY"; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + return "GL_TEXTURE_COORD_ARRAY"; + } + return null; + } + + public final String getGLImplBaseClassName() { + return getGLImplBaseClassName(profileImpl); + } + + /** + * @param o GLProfile object to compare with + * @return true if given Object is a GLProfile and + * if both, profile and profileImpl is equal with this. + */ + public final boolean equals(Object o) { + if(this==o) { return true; } + if(o instanceof GLProfile) { + GLProfile glp = (GLProfile)o; + return profile.equals(glp.getName()) && profileImpl.equals(glp.getImplName()) ; + } + return false; + } + + public int hashCode() { + int hash = 5; + hash = 97 * hash + (this.profileImpl != null ? this.profileImpl.hashCode() : 0); + hash = 97 * hash + (this.profile != null ? this.profile.hashCode() : 0); + return hash; + } + + /** + * @param glp GLProfile to compare with + * @throws GLException if given GLProfile and this aren't equal + */ + public final void verifyEquality(GLProfile glp) throws GLException { + if(!this.equals(glp)) { + throw new GLException("GLProfiles are not equal: "+this+" != "+glp); + } + } + + public final String getName() { + return profile; + } + + public final String getImplName() { + return profileImpl; + } + + /** Indicates whether this profile is capable of GL4bc. */ + public final boolean isGL4bc() { + return GL4bc.equals(profile); + } + + /** Indicates whether this profile is capable of GL4. */ + public final boolean isGL4() { + return isGL4bc() || GL4.equals(profile); + } + + /** Indicates whether this profile is capable of GL3bc. */ + public final boolean isGL3bc() { + return isGL4bc() || GL3bc.equals(profile); + } + + /** Indicates whether this profile is capable of GL3. */ + public final boolean isGL3() { + return isGL4() || isGL3bc() || GL3.equals(profile); + } + + /** Indicates whether this context is a GL2 context */ + public final boolean isGL2() { + return isGL3bc() || GL2.equals(profile); + } + + /** Indicates whether this profile is capable of GLES1. */ + public final boolean isGLES1() { + return GLES1.equals(profile); + } + + /** Indicates whether this profile is capable of GLES2. */ + public final boolean isGLES2() { + return GLES2.equals(profile); + } + + /** Indicates whether this profile is capable of GL2ES1. */ + public final boolean isGL2ES1() { + return GL2ES1.equals(profile) || isGL2() || isGLES1() ; + } + + /** Indicates whether this profile is capable os GL2ES2. */ + public final boolean isGL2ES2() { + return GL2ES2.equals(profile) || isGL2() || isGL3() || isGLES2() ; + } + + /** Indicates whether this profile is capable os GL2GL3. */ + public final boolean isGL2GL3() { + return GL2GL3.equals(profile) || isGL2() || isGL3() ; + } + + /** Indicates whether this profile supports GLSL. */ + public final boolean hasGLSL() { + return isGL2ES2() ; + } + + /** Indicates whether this profile uses the native OpenGL ES1 implementations. */ + public final boolean usesNativeGLES1() { + return GLES1.equals(profileImpl); + } + + /** Indicates whether this profile uses the native OpenGL ES2 implementations. */ + public final boolean usesNativeGLES2() { + return GLES2.equals(profileImpl); + } + + /** Indicates whether this profile uses either of the native OpenGL ES implementations. */ + public final boolean usesNativeGLES() { + return usesNativeGLES2() || usesNativeGLES1(); + } + + /** + * General validation if type is a valid GL data type + * for the current profile + */ + public boolean isValidDataType(int type, boolean throwException) { + switch(type) { + case GL.GL_UNSIGNED_BYTE: + case GL.GL_BYTE: + case GL.GL_UNSIGNED_SHORT: + case GL.GL_SHORT: + case GL.GL_FLOAT: + case GL.GL_FIXED: + return true; + case javax.media.opengl.GL2ES2.GL_INT: + case javax.media.opengl.GL2ES2.GL_UNSIGNED_INT: + if( isGL2ES2() ) { + return true; + } + case javax.media.opengl.GL2.GL_DOUBLE: + if( isGL3() ) { + return true; + } + case javax.media.opengl.GL2.GL_2_BYTES: + case javax.media.opengl.GL2.GL_3_BYTES: + case javax.media.opengl.GL2.GL_4_BYTES: + if( isGL2() ) { + return true; + } + } + if(throwException) { + throw new GLException("Illegal data type on profile "+this+": "+type); + } + return false; + } + + public boolean isValidArrayDataType(int index, int comps, int type, + boolean isVertexAttribPointer, boolean throwException) { + String arrayName = getGLArrayName(index); + if(isGLES1()) { + if(isVertexAttribPointer) { + if(throwException) { + throw new GLException("Illegal array type for "+arrayName+" on profile GLES1: VertexAttribPointer"); + } + return false; + } + switch(index) { + case GLPointerFunc.GL_VERTEX_ARRAY: + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + switch(type) { + case GL.GL_BYTE: + case GL.GL_SHORT: + case GL.GL_FIXED: + case GL.GL_FLOAT: + break; + default: + if(throwException) { + throw new GLException("Illegal data type for "+arrayName+" on profile GLES1: "+type); + } + return false; + } + switch(comps) { + case 0: + case 2: + case 3: + case 4: + break; + default: + if(throwException) { + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); + } + return false; + } + break; + case GLPointerFunc.GL_NORMAL_ARRAY: + switch(type) { + case GL.GL_BYTE: + case GL.GL_SHORT: + case GL.GL_FIXED: + case GL.GL_FLOAT: + break; + default: + if(throwException) { + throw new GLException("Illegal data type for "+arrayName+" on profile GLES1: "+type); + } + return false; + } + switch(comps) { + case 0: + case 3: + break; + default: + if(throwException) { + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); + } + return false; + } + break; + case GLPointerFunc.GL_COLOR_ARRAY: + switch(type) { + case GL.GL_UNSIGNED_BYTE: + case GL.GL_FIXED: + case GL.GL_FLOAT: + break; + default: + if(throwException) { + throw new GLException("Illegal data type for "+arrayName+" on profile GLES1: "+type); + } + return false; + } + switch(comps) { + case 0: + case 4: + break; + default: + if(throwException) { + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); + } + return false; + } + break; + } + } else if(isGLES2()) { + // simply ignore !isVertexAttribPointer case, since it is simulated anyway .. + switch(type) { + case GL.GL_UNSIGNED_BYTE: + case GL.GL_BYTE: + case GL.GL_UNSIGNED_SHORT: + case GL.GL_SHORT: + case GL.GL_FLOAT: + case GL.GL_FIXED: + break; + default: + if(throwException) { + throw new GLException("Illegal data type for "+arrayName+" on profile GLES2: "+type); + } + return false; + } + switch(comps) { + case 0: + case 1: + case 2: + case 3: + case 4: + break; + default: + if(throwException) { + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); + } + return false; + } + } else if( isGL2ES2() ) { + if(isVertexAttribPointer) { + switch(type) { + case GL.GL_UNSIGNED_BYTE: + case GL.GL_BYTE: + case GL.GL_UNSIGNED_SHORT: + case GL.GL_SHORT: + case GL.GL_FLOAT: + case javax.media.opengl.GL2ES2.GL_INT: + case javax.media.opengl.GL2ES2.GL_UNSIGNED_INT: + case javax.media.opengl.GL2.GL_DOUBLE: + break; + default: + if(throwException) { + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); + } + return false; + } + switch(comps) { + case 0: + case 1: + case 2: + case 3: + case 4: + break; + default: + if(throwException) { + throw new GLException("Illegal component number for "+arrayName+" on profile GL2: "+comps); + } + return false; + } + } else { + switch(index) { + case GLPointerFunc.GL_VERTEX_ARRAY: + switch(type) { + case GL.GL_SHORT: + case GL.GL_FLOAT: + case javax.media.opengl.GL2ES2.GL_INT: + case javax.media.opengl.GL2.GL_DOUBLE: + break; + default: + if(throwException) { + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); + } + return false; + } + switch(comps) { + case 0: + case 2: + case 3: + case 4: + break; + default: + if(throwException) { + throw new GLException("Illegal component number for "+arrayName+" on profile GL2: "+comps); + } + return false; + } + break; + case GLPointerFunc.GL_NORMAL_ARRAY: + switch(type) { + case GL.GL_BYTE: + case GL.GL_SHORT: + case GL.GL_FLOAT: + case javax.media.opengl.GL2ES2.GL_INT: + case javax.media.opengl.GL2.GL_DOUBLE: + break; + default: + if(throwException) { + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); + } + return false; + } + switch(comps) { + case 0: + case 3: + break; + default: + if(throwException) { + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); + } + return false; + } + break; + case GLPointerFunc.GL_COLOR_ARRAY: + switch(type) { + case GL.GL_UNSIGNED_BYTE: + case GL.GL_BYTE: + case GL.GL_UNSIGNED_SHORT: + case GL.GL_SHORT: + case GL.GL_FLOAT: + case javax.media.opengl.GL2ES2.GL_INT: + case javax.media.opengl.GL2ES2.GL_UNSIGNED_INT: + case javax.media.opengl.GL2.GL_DOUBLE: + break; + default: + if(throwException) { + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); + } + return false; + } + switch(comps) { + case 0: + case 3: + case 4: + break; + default: + if(throwException) { + throw new GLException("Illegal component number for "+arrayName+" on profile GL2: "+comps); + } + return false; + } + break; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + switch(type) { + case GL.GL_SHORT: + case GL.GL_FLOAT: + case javax.media.opengl.GL2ES2.GL_INT: + case javax.media.opengl.GL2.GL_DOUBLE: + break; + default: + if(throwException) { + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); + } + return false; + } + switch(comps) { + case 0: + case 1: + case 2: + case 3: + case 4: + break; + default: + if(throwException) { + throw new GLException("Illegal component number for "+arrayName+" on profile GL2: "+comps); + } + return false; + } + break; + } + } + } + return true; + } + + public String toString() { + return "GLProfile[" + profile + "/" + profileImpl + "]"; + } + + static { + JVMUtil.initSingleton(); + } + + private static /*final*/ boolean isAWTAvailable; + + private static /*final*/ boolean hasDesktopGL; + private static /*final*/ boolean hasGL234Impl; + private static /*final*/ boolean hasGLES2Impl; + private static /*final*/ boolean hasGLES1Impl; + + private static /*final*/ GLDrawableFactoryImpl eglFactory; + private static /*final*/ GLDrawableFactoryImpl desktopFactory; + private static /*final*/ AbstractGraphicsDevice defaultDevice; + private static /*final*/ AbstractGraphicsDevice defaultDesktopDevice; + private static /*final*/ AbstractGraphicsDevice defaultEGLDevice; + + static boolean initialized = false; + + /** + * Tries the profiles implementation and native libraries. + * Throws an GLException if no profile could be found at all. + */ + private static void initProfilesForDefaultDevices(boolean firstUIActionOnProcess) { + NativeWindowFactory.initSingleton(firstUIActionOnProcess); + + if(DEBUG) { + System.err.println("GLProfile.init firstUIActionOnProcess: "+ firstUIActionOnProcess + + ", thread: " + Thread.currentThread().getName()); + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(GlueGenVersion.getInstance()); + System.err.println(NativeWindowVersion.getInstance()); + System.err.println(JoglVersion.getInstance()); + } + + ClassLoader classloader = GLProfile.class.getClassLoader(); + + isAWTAvailable = NativeWindowFactory.isAWTAvailable() && + ReflectionUtil.isClassAvailable("javax.media.opengl.awt.GLCanvas", classloader) ; // JOGL + + hasGL234Impl = ReflectionUtil.isClassAvailable("jogamp.opengl.gl4.GL4bcImpl", classloader); + + // + // Iteration of desktop GL availability detection + // utilizing the detected GL version in the shared context. + // + // - Instantiate GLDrawableFactory incl its shared dummy drawable/context, + // which will register at GLContext .. + // + Throwable t=null; + // if successfull it has a shared dummy drawable and context created + try { + desktopFactory = (GLDrawableFactoryImpl) GLDrawableFactory.getFactoryImpl(GL2); + if(null != desktopFactory) { + DesktopGLDynamicLookupHelper glLookupHelper = (DesktopGLDynamicLookupHelper) desktopFactory.getGLDynamicLookupHelper(0); + if(null!=glLookupHelper) { + hasDesktopGL = glLookupHelper.hasGLBinding(); + } + } + } catch (LinkageError le) { + t=le; + } catch (RuntimeException re) { + t=re; + } catch (Throwable tt) { + t=tt; + } + if(DEBUG) { + if(null!=t) { + t.printStackTrace(); + } + if(null == desktopFactory) { + System.err.println("Info: GLProfile.init - Desktop GLDrawable factory not available"); + } + } + + if(null == desktopFactory) { + hasDesktopGL = false; + hasGL234Impl = false; + } else { + defaultDesktopDevice = desktopFactory.getDefaultDevice(); + defaultDevice = defaultDesktopDevice; + } + + if ( ReflectionUtil.isClassAvailable("jogamp.opengl.egl.EGLDrawableFactory", classloader) ) { + t=null; + try { + eglFactory = (GLDrawableFactoryImpl) GLDrawableFactory.getFactoryImpl(GLES2); + if(null != eglFactory) { + GLDynamicLookupHelper eglLookupHelper = eglFactory.getGLDynamicLookupHelper(2); + if(null!=eglLookupHelper) { + hasGLES2Impl = eglLookupHelper.isLibComplete(); + } + eglLookupHelper = eglFactory.getGLDynamicLookupHelper(1); + if(null!=eglLookupHelper) { + hasGLES1Impl = eglLookupHelper.isLibComplete(); + } + } + } catch (LinkageError le) { + t=le; + } catch (SecurityException se) { + t=se; + } catch (NullPointerException npe) { + t=npe; + } catch (RuntimeException re) { + t=re; + } + if(DEBUG) { + if(null!=t) { + t.printStackTrace(); + } + if(null == eglFactory) { + System.err.println("Info: GLProfile.init - EGL GLDrawable factory not available"); + } + } + } + + if(null == eglFactory) { + hasGLES2Impl = false; + hasGLES1Impl = false; + } else { + defaultEGLDevice = eglFactory.getDefaultDevice(); + if (null==defaultDevice) { + defaultDevice = defaultEGLDevice; + } + } + + boolean addedAnyProfile = initProfilesForDevice(defaultDesktopDevice) || + initProfilesForDevice(defaultEGLDevice); + + if(DEBUG) { + System.err.println("GLProfile.init isAWTAvailable "+isAWTAvailable); + System.err.println("GLProfile.init has desktopFactory "+(null!=desktopFactory)); + System.err.println("GLProfile.init hasDesktopGL "+hasDesktopGL); + System.err.println("GLProfile.init hasGL234Impl "+hasGL234Impl); + System.err.println("GLProfile.init has eglFactory "+(null!=eglFactory)); + System.err.println("GLProfile.init hasGLES1Impl "+hasGLES1Impl); + System.err.println("GLProfile.init hasGLES2Impl "+hasGLES2Impl); + System.err.println("GLProfile.init defaultDesktopDevice "+defaultDesktopDevice); + System.err.println("GLProfile.init defaultEGLDevice "+defaultEGLDevice); + System.err.println("GLProfile.init defaultDevice "+defaultDevice); + } + + if(!addedAnyProfile) { + throw new GLException("No profile available: "+array2String(GL_PROFILE_LIST_ALL)+", "+ glAvailabilityToString()); + } + } + + /** + * @param device the device for which profiles shall be initialized + * @return true if any profile for the device exists, otherwise false + */ + private static synchronized boolean initProfilesForDevice(AbstractGraphicsDevice device) { + if(null == device) { + return false; + } + GLDrawableFactory factory = GLDrawableFactory.getFactoryImpl(device); + factory.enterThreadCriticalZone(); + try { + return initProfilesForDeviceImpl(device); + } finally { + factory.leaveThreadCriticalZone(); + } + } + private static synchronized boolean initProfilesForDeviceImpl(AbstractGraphicsDevice device) { + boolean isSet = GLContext.getAvailableGLVersionsSet(device); + + if(DEBUG) { + String msg = "Info: GLProfile.initProfilesForDevice: "+device+", isSet "+isSet; + Throwable t = new Throwable(msg); + t.printStackTrace(); + // System.err.println(msg); + } + if(isSet) { + return null != GLProfile.getDefault(device); + } + + boolean addedDesktopProfile = false; + boolean addedEGLProfile = false; + + if( hasDesktopGL && desktopFactory.getIsDeviceCompatible(device)) { + // 1st pretend we have all Desktop and EGL profiles .. + computeProfileMap(device, true /* desktopCtxUndef*/, true /* eglCtxUndef */); + + // Triggers eager initialization of share context in GLDrawableFactory for the device, + // hence querying all available GLProfiles + boolean desktopSharedCtxAvail = desktopFactory.getIsSharedContextAvailable(device); + if (DEBUG) { + System.err.println("GLProfile.initProfilesForDevice: "+device+": desktop Shared Ctx "+desktopSharedCtxAvail); + } + if( null == GLContext.getAvailableGLVersion(device, 2, GLContext.CTX_PROFILE_COMPAT) ) { + // nobody yet set the available desktop versions, see {@link GLContextImpl#makeCurrent}, + // so we have to add the usual suspect + GLContext.mapAvailableGLVersion(device, + 2, GLContext.CTX_PROFILE_COMPAT, + 1, 5, GLContext.CTX_PROFILE_COMPAT|GLContext.CTX_OPTION_ANY); + } + addedDesktopProfile = computeProfileMap(device, false /* desktopCtxUndef*/, false /* eglCtxUndef */); + } else if( null!=eglFactory && ( hasGLES2Impl || hasGLES1Impl ) && eglFactory.getIsDeviceCompatible(device)) { + // 1st pretend we have all EGL profiles .. + computeProfileMap(device, false /* desktopCtxUndef*/, true /* eglCtxUndef */); + + // Triggers eager initialization of share context in GLDrawableFactory for the device, + // hence querying all available GLProfiles + boolean eglSharedCtxAvail = eglFactory.getIsSharedContextAvailable(device); + if (DEBUG) { + System.err.println("GLProfile.initProfilesForDevice: "+device+": egl Shared Ctx "+eglSharedCtxAvail); + } + if(hasGLES2Impl && null == GLContext.getAvailableGLVersion(device, 2, GLContext.CTX_PROFILE_ES) ) { + // nobody yet set the available desktop versions, see {@link GLContextImpl#makeCurrent}, + // so we have to add the usual suspect + GLContext.mapAvailableGLVersion(device, + 2, GLContext.CTX_PROFILE_ES, + 2, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_OPTION_ANY); + } + if(hasGLES1Impl && null == GLContext.getAvailableGLVersion(device, 1, GLContext.CTX_PROFILE_ES)) { + // nobody yet set the available desktop versions, see {@link GLContextImpl#makeCurrent}, + // so we have to add the usual suspect + GLContext.mapAvailableGLVersion(device, + 1, GLContext.CTX_PROFILE_ES, + 1, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_OPTION_ANY); + } + addedEGLProfile = computeProfileMap(device, false /* desktopCtxUndef*/, false /* eglCtxUndef */); + } else { + setProfileMap(device, new HashMap()); // empty + if(DEBUG) { + System.err.println("GLProfile: EGLFactory - Device is not available: "+device); + } + } + + if(!GLContext.getAvailableGLVersionsSet(device)) { + GLContext.setAvailableGLVersionsSet(device); + } + + if (DEBUG) { + System.err.println("GLProfile.initProfilesForDevice: "+device.getConnection()+": added profile(s): desktop "+addedDesktopProfile+", egl "+addedEGLProfile); + System.err.println("GLProfile.initProfilesForDevice: "+device.getConnection()+": "+glAvailabilityToString(device)); + if(addedDesktopProfile) { + dumpGLInfo(desktopFactory, device); + List/*<GLCapabilitiesImmutable>*/ availCaps = desktopFactory.getAvailableCapabilities(device); + for(int i=0; i<availCaps.size(); i++) { + System.err.println(availCaps.get(i)); + } + } else if(addedEGLProfile) { + dumpGLInfo(eglFactory, device); + List/*<GLCapabilitiesImmutable>*/ availCaps = eglFactory.getAvailableCapabilities(device); + for(int i=0; i<availCaps.size(); i++) { + System.err.println(availCaps.get(i)); + } + } + } + + return addedDesktopProfile || addedEGLProfile; + } + + private static void dumpGLInfo(GLDrawableFactoryImpl factory, AbstractGraphicsDevice device) { + GLContext ctx = factory.getOrCreateSharedContext(device); + if(null != ctx) { + System.err.println("GLProfile.dumpGLInfo: "+ctx); + ctx.makeCurrent(); + try { + System.err.println(JoglVersion.getGLInfo(ctx.getGL(), null)); + } finally { + ctx.release(); + } + } else { + System.err.println("GLProfile.dumpGLInfo: shared context n/a"); + } + } + + public static AbstractGraphicsDevice getDefaultDevice() { + validateInitialization(); + return defaultDevice; + } + + public static AbstractGraphicsDevice getDefaultDesktopDevice() { + validateInitialization(); + return defaultDesktopDevice; + } + + public static AbstractGraphicsDevice getDefaultEGLDevice() { + validateInitialization(); + return defaultEGLDevice; + } + + private static void validateInitialization() { + if(!initialized) { + synchronized(GLProfile.class) { + if(!initialized) { + initSingleton(false); + } + } + } + } + + private static String array2String(String[] list) { + StringBuffer msg = new StringBuffer(); + msg.append("["); + for (int i = 0; i < list.length; i++) { + if (i > 0) + msg.append(", "); + msg.append(list[i]); + } + msg.append("]"); + return msg.toString(); + } + + private static void glAvailabilityToString(AbstractGraphicsDevice device, StringBuffer sb, int major, int profile) { + String str = GLContext.getAvailableGLVersionAsString(device, major, profile); + if(null==str) { + throw new GLException("Internal Error"); + } + sb.append("["); + sb.append(str); + sb.append("]"); + } + + private static boolean computeProfileMap(AbstractGraphicsDevice device, boolean desktopCtxUndef, boolean eglCtxUndef) { + if (DEBUG) { + System.err.println("GLProfile.init map "+device.getConnection()+", desktopCtxUndef "+desktopCtxUndef+", eglCtxUndef "+eglCtxUndef); + } + GLProfile defaultGLProfile = null; + HashMap/*<String, GLProfile>*/ _mappedProfiles = new HashMap(GL_PROFILE_LIST_ALL.length + 1 /* default */); + for(int i=0; i<GL_PROFILE_LIST_ALL.length; i++) { + String profile = GL_PROFILE_LIST_ALL[i]; + String profileImpl = computeProfileImpl(device, profile, desktopCtxUndef, eglCtxUndef); + if(null!=profileImpl) { + GLProfile glProfile = new GLProfile(profile, profileImpl); + _mappedProfiles.put(profile, glProfile); + if (DEBUG) { + System.err.println("GLProfile.init map "+glProfile+" on devide "+device.getConnection()); + } + if(null==defaultGLProfile) { + defaultGLProfile=glProfile; + if (DEBUG) { + System.err.println("GLProfile.init map default "+glProfile+" on device "+device.getConnection()); + } + } + } else { + if (DEBUG) { + System.err.println("GLProfile.init map *** no mapping for "+profile+" on device "+device.getConnection()); + } + } + } + if(null!=defaultGLProfile) { + _mappedProfiles.put(GL_DEFAULT, defaultGLProfile); + } + setProfileMap(device, _mappedProfiles); + return _mappedProfiles.size() > 0; + } + + /** + * Returns the profile implementation + */ + private static String computeProfileImpl(AbstractGraphicsDevice device, String profile, boolean desktopCtxUndef, boolean eglCtxUndef) { + if (GL2ES1.equals(profile)) { + if(hasGL234Impl) { + if(desktopCtxUndef || GLContext.isGL2Available(device)) { + return GL2; + } else if(GLContext.isGL3bcAvailable(device)) { + return GL3bc; + } else if(GLContext.isGL4bcAvailable(device)) { + return GL4bc; + } + } + if(hasGLES1Impl && ( eglCtxUndef || GLContext.isGLES1Available(device))) { + return GLES1; + } + } else if (GL2ES2.equals(profile)) { + if(hasGL234Impl) { + if(desktopCtxUndef || GLContext.isGL2Available(device)) { + return GL2; + } else if(GLContext.isGL3Available(device)) { + return GL3; + } else if(GLContext.isGL4Available(device)) { + return GL4; + } + } + if(hasGLES2Impl && ( eglCtxUndef || GLContext.isGLES2Available(device))) { + return GLES2; + } + } else if(GL2GL3.equals(profile)) { + if(hasGL234Impl) { + if(desktopCtxUndef || GLContext.isGL2Available(device)) { + return GL2; + } else if(GLContext.isGL3bcAvailable(device)) { + return GL3bc; + } else if(GLContext.isGL4bcAvailable(device)) { + return GL4bc; + } else if(GLContext.isGL3Available(device)) { + return GL3; + } else if(GLContext.isGL4Available(device)) { + return GL4; + } + } + } else if(GL4bc.equals(profile) && hasGL234Impl && ( desktopCtxUndef || GLContext.isGL4bcAvailable(device))) { + return GL4bc; + } else if(GL4.equals(profile) && hasGL234Impl && ( desktopCtxUndef || GLContext.isGL4Available(device))) { + return GL4; + } else if(GL3bc.equals(profile) && hasGL234Impl && ( desktopCtxUndef || GLContext.isGL3bcAvailable(device))) { + return GL3bc; + } else if(GL3.equals(profile) && hasGL234Impl && ( desktopCtxUndef || GLContext.isGL3Available(device))) { + return GL3; + } else if(GL2.equals(profile) && hasGL234Impl && ( desktopCtxUndef || GLContext.isGL2Available(device))) { + return GL2; + } else if(GLES2.equals(profile) && hasGLES2Impl && ( eglCtxUndef || GLContext.isGLES2Available(device))) { + return GLES2; + } else if(GLES1.equals(profile) && hasGLES1Impl && ( eglCtxUndef || GLContext.isGLES1Available(device))) { + return GLES1; + } + return null; + } + + private static String getGLImplBaseClassName(String profileImpl) { + if ( GL4bc.equals(profileImpl) || + GL4.equals(profileImpl) || + GL3bc.equals(profileImpl) || + GL3.equals(profileImpl) || + GL2.equals(profileImpl) ) { + return "jogamp.opengl.gl4.GL4bc"; + } else if(GLES1.equals(profileImpl) || GL2ES1.equals(profileImpl)) { + return "jogamp.opengl.es1.GLES1"; + } else if(GLES2.equals(profileImpl) || GL2ES2.equals(profileImpl)) { + return "jogamp.opengl.es2.GLES2"; + } else { + throw new GLException("unsupported profile \"" + profileImpl + "\""); + } + } + + private static /*final*/ HashMap/*<device_connection, HashMap<GL-String, GLProfile>*/ deviceConn2ProfileMap = new HashMap(); + + /** + * This implementation support lazy initialization, while avoiding recursion/deadlocks.<br> + * If no mapping 'device -> GLProfiles-Map' exists yet, it triggers<br> + * - create empty mapping device -> GLProfiles-Map <br> + * - initialization<br< + * + * @param device the key 'device -> GLProfiles-Map' + * @return the GLProfile HashMap + */ + private static HashMap getProfileMap(AbstractGraphicsDevice device) { + validateInitialization(); + if(null==device) { + device = defaultDevice; + } + String deviceKey = device.getUniqueID(); + HashMap map = (HashMap) deviceConn2ProfileMap.get(deviceKey); + if(null==map) { + initProfilesForDevice(device); + if( null == deviceConn2ProfileMap.get(deviceKey) ) { + throw new InternalError("initProfilesForDevice(..) didn't issue setProfileMap(..) on "+device); + } + } + return map; + } + + private static void setProfileMap(AbstractGraphicsDevice device, HashMap/*<GL-String, GLProfile>*/mappedProfiles) { + validateInitialization(); + synchronized ( deviceConn2ProfileMap ) { + deviceConn2ProfileMap.put(device.getUniqueID(), mappedProfiles); + } + } + + private GLProfile(String profile, String profileImpl) { + this.profile = profile; + this.profileImpl = profileImpl; + } + + private String profileImpl = null; + private String profile = null; +} diff --git a/src/jogl/classes/javax/media/opengl/GLRunnable.java b/src/jogl/classes/javax/media/opengl/GLRunnable.java new file mode 100644 index 000000000..de0f5df48 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLRunnable.java @@ -0,0 +1,47 @@ +/** + * 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 javax.media.opengl; + +/** + * <p> + * Declares one-shot OpenGL commands usable for injection into a {@link GLAutoDrawable},<br> + * via {@link GLAutoDrawable#invoke(boolean, javax.media.opengl.GLRunnable)}.<br> + * {@link GLAutoDrawable} executes these commands within it's {@link GLAutoDrawable#display()} + * method while the OpenGL context is current.<br> + * <p> + * This might be useful to inject OpenGL commands from an I/O event listener. + */ +public interface GLRunnable { + /** + * Called by the drawable to initiate one-shot OpenGL commands by the + * client, like {@link GLEventListener#display(GLAutoDrawable)}. + */ + void run(GLAutoDrawable drawable); +} + diff --git a/src/jogl/classes/javax/media/opengl/GLUniformData.java b/src/jogl/classes/javax/media/opengl/GLUniformData.java new file mode 100644 index 000000000..9b0d5f151 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLUniformData.java @@ -0,0 +1,154 @@ + +package javax.media.opengl; + +import java.nio.*; + +public class GLUniformData { + + /** + * int atom + * + * Number of objects is 1 + * + */ + public GLUniformData(String name, int val) { + init(name, 1, new Integer(val)); + } + + /** + * float atom + * + * Number of objects is 1 + * + */ + public GLUniformData(String name, float val) { + init(name, 1, new Float(val)); + } + + /** + * Multiple IntBuffer Vector + * + * Number of objects is calculated by data.limit()/components + * + * @param components number of elements of one object, ie 4 for GL_FLOAT_VEC4, + */ + public GLUniformData(String name, int components, IntBuffer data) { + init(name, components, data); + } + + /** + * Multiple FloatBuffer Vector + * + * Number of objects is calculated by data.limit()/components + * + * @param components number of elements of one object, ie 4 for GL_FLOAT_VEC4, + */ + public GLUniformData(String name, int components, FloatBuffer data) { + init(name, components, data); + } + + /** + * Multiple FloatBuffer Matrix + * + * Number of objects is calculated by data.limit()/(rows*columns) + * + * @param rows the matrix rows + * @param column the matrix column + */ + public GLUniformData(String name, int rows, int columns, FloatBuffer data) { + init(name, rows, columns, data); + } + + public void setData(int data) { init(new Integer(data)); } + public void setData(float data) { init(new Float(data)); } + public void setData(IntBuffer data) { init(data); } + public void setData(FloatBuffer data) { init(data); } + + public int intValue() { return ((Integer)data).intValue(); }; + public float floatValue() { return ((Float)data).floatValue(); }; + public IntBuffer intBufferValue() { return (IntBuffer)data; }; + public FloatBuffer floatBufferValue() { return (FloatBuffer)data; }; + + public String toString() { + return "GLUniformData[name "+name+ + ", location "+location+ + ", size "+rows+"*"+columns+ + ", count "+count+ + ", matrix "+isMatrix+ + ", data "+data+ + "]"; + } + + private void init(String name, int rows, int columns, Object data) { + if( 2>rows || rows>4 || 2>columns || columns>4 ) { + throw new GLException("rowsXcolumns must be within [2..4]X[2..4], is: "+rows+"X"+columns); + } + this.name=name; + this.rows=rows; + this.columns=columns; + this.isMatrix=true; + this.location=-1; + init(data); + } + + private void init(String name, int components, Object data) { + if( 1>components || components>4 ) { + throw new GLException("components must be within [1..4], is: "+components); + } + this.name=name; + this.columns=components; + this.rows=1; + this.isMatrix=false; + this.location=-1; + init(data); + } + + private void init(Object data) { + if(data instanceof Buffer) { + int sz = rows*columns; + Buffer buffer = (Buffer)data; + if(buffer.limit()<sz || 0!=buffer.limit()%sz) { + throw new GLException("data buffer size invalid: new buffer limit: "+buffer.limit()+"\n\t"+this); + } + this.count=buffer.limit()/(rows*columns); + } else { + if(isMatrix) { + throw new GLException("Atom type not allowed for matrix : "+this); + } + this.count=1; + } + this.data=data; + } + + public String getName() { return name; } + + public int getLocation() { return location; } + + /** + * Sets the determined location of the shader uniform. + */ + public void setLocation(int location) { this.location=location; } + + public Object getObject() { + return data; + } + public Buffer getBuffer() { + return (data instanceof Buffer)?(Buffer)data:null; + } + public boolean isBuffer() { + return (data instanceof Buffer); + } + public boolean isMatrix() { return isMatrix; } + + public int count() { return count; } + public int components() { return rows*columns; } + public int rows() { return rows; } + public int columns() { return columns; } + + private String name; + private int location; + private int rows, columns; + private int count; + private Object data; + private boolean isMatrix; +} diff --git a/src/jogl/classes/javax/media/opengl/Threading.java b/src/jogl/classes/javax/media/opengl/Threading.java new file mode 100644 index 000000000..d0f3ebb93 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/Threading.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl; + +import jogamp.opengl.*; + +/** This API provides access to the threading model for the implementation of + the classes in this package. + + <P> + + OpenGL is specified as a thread-safe API, but in practice there + are multithreading-related issues on most, if not all, of the + platforms which support it. For example, some OpenGL + implementations do not behave well when one context is made + current first on one thread, released, and then made current on a + second thread, although this is legal according to the OpenGL + specification. On other platforms there are other problems. + + <P> + + Due to these limitations, and due to the inherent multithreading + in the Java platform (in particular, in the Abstract Window + Toolkit), it is often necessary to limit the multithreading + occurring in the typical application using the OpenGL API. + + <P> + + In the current reference implementation, for instance, multithreading + has been limited by + forcing all OpenGL-related work for GLAutoDrawables on to a single + thread. In other words, if an application uses only the + GLAutoDrawable and GLEventListener callback mechanism, it is + guaranteed to have the most correct single-threaded behavior on + all platforms. + + <P> + + Applications using the GLContext makeCurrent/release API directly + will inherently break this single-threaded model, as these methods + require that the OpenGL context be made current on the current + thread immediately. For applications wishing to integrate better + with an implementation that uses the single-threaded model, this + class provides public access to the mechanism used by the implementation. + + <P> + + Users can execute Runnables on the + internal thread used for performing OpenGL work, and query whether + the current thread is already this thread. Using these mechanisms + the user can move work from the current thread on to the internal + OpenGL thread if desired. + + <P> + + This class also provides mechanisms for querying whether this + internal serialization of OpenGL work is in effect, and a + programmatic way of disabling it. In the current reference + implementation it is enabled by default, although it could be + disabled in the future if OpenGL drivers become more robust on + all platforms. + + <P> + + In addition to specifying programmatically whether the single + thread for OpenGL work is enabled, users may switch it on and off + using the system property <code>opengl.1thread</code>. Valid values + for this system property are: + + <PRE> + -Dopengl.1thread=false Disable single-threading of OpenGL work + -Dopengl.1thread=true Enable single-threading of OpenGL work (default -- on a newly-created worker thread) + -Dopengl.1thread=auto Select default single-threading behavior (currently on) + -Dopengl.1thread=awt Enable single-threading of OpenGL work on AWT event dispatch thread (current default on all + platforms, and also the default behavior older releases) + -Dopengl.1thread=worker Enable single-threading of OpenGL work on newly-created worker thread (not suitable for Mac + OS X or X11 platforms, and risky on Windows in applet environments) + </PRE> +*/ + +public class Threading { + + /** No reason to ever instantiate this class */ + private Threading() {} + + /** If an implementation of the javax.media.opengl APIs offers a + multithreading option but the default behavior is single-threading, + this API provides a mechanism for end users to disable single-threading + in this implementation. Users are strongly discouraged from + calling this method unless they are aware of all of the + consequences and are prepared to enforce some amount of + threading restrictions in their applications. Disabling + single-threading, for example, may have unintended consequences + on GLAutoDrawable implementations such as GLCanvas, GLJPanel and + GLPbuffer. Currently there is no supported way to re-enable it + once disabled, partly to discourage careless use of this + method. This method should be called as early as possible in an + application. */ + public static void disableSingleThreading() { + ThreadingImpl.disableSingleThreading(); + } + + /** Indicates whether OpenGL work is being automatically forced to a + single thread in this implementation. */ + public static boolean isSingleThreaded() { + return ThreadingImpl.isSingleThreaded(); + } + + /** Indicates whether the current thread is the single thread on + which this implementation of the javax.media.opengl APIs + performs all of its OpenGL-related work. This method should only + be called if the single-thread model is in effect. */ + public static boolean isOpenGLThread() throws GLException { + return ThreadingImpl.isOpenGLThread(); + } + + /** Executes the passed Runnable on the single thread used for all + OpenGL work in this javax.media.opengl API implementation. It is + not specified exactly which thread is used for this + purpose. This method should only be called if the single-thread + model is in use and if the current thread is not the OpenGL + thread (i.e., if <code>isOpenGLThread()</code> returns + false). It is up to the end user to check to see whether the + current thread is the OpenGL thread and either execute the + Runnable directly or perform the work inside it. */ + public static void invokeOnOpenGLThread(Runnable r) throws GLException { + ThreadingImpl.invokeOnOpenGLThread(r); + } +} diff --git a/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java b/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java new file mode 100644 index 000000000..d1e725b00 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl.awt; + +import javax.media.opengl.*; + +public interface AWTGLAutoDrawable extends GLAutoDrawable, ComponentEvents { + /** Requests a new width and height for this AWTGLAutoDrawable. */ + public void setSize(int width, int height); + + /** Schedules a repaint of the component at some point in the + future. */ + public void repaint(); +} diff --git a/src/jogl/classes/javax/media/opengl/awt/ComponentEvents.java b/src/jogl/classes/javax/media/opengl/awt/ComponentEvents.java new file mode 100644 index 000000000..0c4f63c2d --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/awt/ComponentEvents.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl.awt; + +import javax.media.opengl.*; +import java.awt.event.*; +import java.beans.PropertyChangeListener; + +/** Factors out the listener manipulation for the events supported by + all of the {@link GLDrawable} implementations. Provided to reduce + clutter in the documentation for GLDrawable. */ + +public interface ComponentEvents { + public void addComponentListener(ComponentListener l); + public void removeComponentListener(ComponentListener l); + public void addFocusListener(FocusListener l); + public void removeFocusListener(FocusListener l); + public void addHierarchyBoundsListener(HierarchyBoundsListener l); + public void removeHierarchyBoundsListener(HierarchyBoundsListener l); + public void addHierarchyListener(HierarchyListener l); + public void removeHierarchyListener(HierarchyListener l); + public void addInputMethodListener(InputMethodListener l); + public void removeInputMethodListener(InputMethodListener l); + public void addKeyListener(KeyListener l); + public void removeKeyListener(KeyListener l); + public void addMouseListener(MouseListener l); + public void removeMouseListener(MouseListener l); + public void addMouseMotionListener(MouseMotionListener l); + public void removeMouseMotionListener(MouseMotionListener l); + public void addMouseWheelListener(MouseWheelListener l); + public void removeMouseWheelListener(MouseWheelListener l); + public void addPropertyChangeListener(PropertyChangeListener listener); + public void removePropertyChangeListener(PropertyChangeListener listener); + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener); + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener); +} diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java new file mode 100644 index 000000000..4076dac54 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -0,0 +1,1074 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl.awt; + +import java.beans.Beans; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import java.awt.Canvas; +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.geom.Rectangle2D; + +import java.awt.EventQueue; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +import javax.media.nativewindow.WindowClosingProtocol; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; +import javax.media.nativewindow.awt.AWTWindowClosingProtocol; + +import javax.media.opengl.GL; +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLRunnable; +import javax.media.opengl.Threading; + +import com.jogamp.nativewindow.NativeWindowVersion; +import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.opengl.JoglVersion; + +import com.jogamp.common.util.locks.RecursiveLock; +import jogamp.opengl.Debug; +import jogamp.opengl.GLContextImpl; +import jogamp.opengl.GLDrawableHelper; +import jogamp.opengl.ThreadingImpl; + +// FIXME: Subclasses need to call resetGLFunctionAvailability() on their +// context whenever the displayChanged() function is called on our +// GLEventListeners + +/** A heavyweight AWT component which provides OpenGL rendering + support. This is the primary implementation of an AWT {@link GLDrawable}; + {@link GLJPanel} is provided for compatibility with Swing user + interfaces when adding a heavyweight doesn't work either because + of Z-ordering or LayoutManager problems. + * + * <h5><A NAME="java2dgl">Java2D OpenGL Remarks</A></h5> + * + * To avoid any conflicts with a potential Java2D OpenGL context,<br> + * you shall consider setting the following JVM properties:<br> + * <ul> + * <li><pre>sun.java2d.opengl=false</pre></li> + * <li><pre>sun.java2d.noddraw=true</pre></li> + * </ul> + * This is especially true in case you want to utilize a GLProfile other than + * {@link GLProfile#GL2}, eg. using {@link GLProfile#getMaxFixedFunc()}.<br> + * On the other hand, if you like to experiment with GLJPanel's utilization + * of Java2D's OpenGL pipeline, you have to set them to + * <ul> + * <li><pre>sun.java2d.opengl=true</pre></li> + * <li><pre>sun.java2d.noddraw=true</pre></li> + * </ul> + * + * <h5><A NAME="backgrounderase">Disable Background Erase</A></h5> + * + * GLCanvas tries to disable background erase for the AWT Canvas + * before native peer creation (X11) and after it (Windows), <br> + * utilizing the optional {@link java.awt.Toolkit} method <code>disableBeackgroundErase(java.awt.Canvas)</code>.<br> + * However if this does not give you the desired results, you may want to disable AWT background erase in general: + * <ul> + * <li><pre>sun.awt.noerasebackground=true</pre></li> + * </ul> + */ + +public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosingProtocol { + + private static final boolean DEBUG; + + static { + DEBUG = Debug.debug("GLCanvas"); + } + + private GLDrawableHelper drawableHelper = new GLDrawableHelper(); + private AWTGraphicsConfiguration awtConfig; + private GLDrawable drawable; + private GLContextImpl context; + private boolean sendReshape = false; + + // copy of the cstr args, mainly for recreation + private GLCapabilitiesImmutable capsReqUser; + private GLCapabilitiesChooser chooser; + private GLContext shareWith; + private GraphicsDevice device; + + private AWTWindowClosingProtocol awtWindowClosingProtocol = + new AWTWindowClosingProtocol(this, new Runnable() { + public void run() { + GLCanvas.this.destroy(); + } + }); + + /** Creates a new GLCanvas component with a default set of OpenGL + capabilities, using the default OpenGL capabilities selection + mechanism, on the default screen device. */ + public GLCanvas() { + this(null); + } + + /** Creates a new GLCanvas component with the requested set of + OpenGL capabilities, using the default OpenGL capabilities + selection mechanism, on the default screen device. + * @see GLCanvas#GLCanvas(javax.media.opengl.GLCapabilitiesImmutable, javax.media.opengl.GLCapabilitiesChooser, javax.media.opengl.GLContext, java.awt.GraphicsDevice) + */ + public GLCanvas(GLCapabilitiesImmutable capsReqUser) { + this(capsReqUser, null, null, null); + } + + /** Creates a new GLCanvas component with the requested set of + OpenGL capabilities, using the default OpenGL capabilities + selection mechanism, on the default screen device. + * This constructor variant also supports using a shared GLContext. + * + * @see GLCanvas#GLCanvas(javax.media.opengl.GLCapabilitiesImmutable, javax.media.opengl.GLCapabilitiesChooser, javax.media.opengl.GLContext, java.awt.GraphicsDevice) + */ + public GLCanvas(GLCapabilitiesImmutable capsReqUser, GLContext shareWith) { + this(capsReqUser, null, shareWith, null); + } + + /** Creates a new GLCanvas component. The passed GLCapabilities + specifies the OpenGL capabilities for the component; if null, a + default set of capabilities is used. The GLCapabilitiesChooser + specifies the algorithm for selecting one of the available + GLCapabilities for the component; a DefaultGLCapabilitesChooser + is used if null is passed for this argument. The passed + GLContext specifies an OpenGL context with which to share + textures, display lists and other OpenGL state, and may be null + if sharing is not desired. See the note in the overview + documentation on <a + href="../../../overview-summary.html#SHARING">context + sharing</a>. The passed GraphicsDevice indicates the screen on + which to create the GLCanvas; the GLDrawableFactory uses the + default screen device of the local GraphicsEnvironment if null + is passed for this argument. */ + public GLCanvas(GLCapabilitiesImmutable capsReqUser, + GLCapabilitiesChooser chooser, + GLContext shareWith, + GraphicsDevice device) { + /* + * Determination of the native window is made in 'super.addNotify()', + * which creates the native peer using AWT's GraphicsConfiguration. + * GraphicsConfiguration is returned by this class overwritten + * 'getGraphicsConfiguration()', which returns our OpenGL compatible + * 'chosen' GraphicsConfiguration. + */ + super(); + + if(null==capsReqUser) { + capsReqUser = new GLCapabilities(GLProfile.getDefault(GLProfile.getDefaultDesktopDevice())); + } else { + // don't allow the user to change data + capsReqUser = (GLCapabilitiesImmutable) capsReqUser.cloneMutable(); + } + + if(null==device) { + GraphicsConfiguration gc = super.getGraphicsConfiguration(); + if(null!=gc) { + device = gc.getDevice(); + } + } + + // instantiation will be issued in addNotify() + this.capsReqUser = capsReqUser; + this.chooser = chooser; + this.shareWith = shareWith; + this.device = device; + } + + /** + * Overridden to choose a GraphicsConfiguration on a parent container's + * GraphicsDevice because both devices + */ + @Override + public GraphicsConfiguration getGraphicsConfiguration() { + /* + * Workaround for problems with Xinerama and java.awt.Component.checkGD + * when adding to a container on a different graphics device than the + * one that this Canvas is associated with. + * + * GC will be null unless: + * - A native peer has assigned it. This means we have a native + * peer, and are already comitted to a graphics configuration. + * - This canvas has been added to a component hierarchy and has + * an ancestor with a non-null GC, but the native peer has not + * yet been created. This means we can still choose the GC on + * all platforms since the peer hasn't been created. + */ + final GraphicsConfiguration gc = super.getGraphicsConfiguration(); + /* + * chosen is only non-null on platforms where the GLDrawableFactory + * returns a non-null GraphicsConfiguration (in the GLCanvas + * constructor). + * + * if gc is from this Canvas' native peer then it should equal chosen, + * otherwise it is from an ancestor component that this Canvas is being + * added to, and we go into this block. + */ + GraphicsConfiguration chosen = awtConfig.getGraphicsConfiguration(); + + if (gc != null && chosen != null && !chosen.equals(gc)) { + /* + * Check for compatibility with gc. If they differ by only the + * device then return a new GCconfig with the super-class' GDevice + * (and presumably the same visual ID in Xinerama). + * + */ + if (!chosen.getDevice().getIDstring().equals(gc.getDevice().getIDstring())) { + /* + * Here we select a GraphicsConfiguration on the alternate + * device that is presumably identical to the chosen + * configuration, but on the other device. + * + * Should really check to ensure that we select a configuration + * with the same X visual ID for Xinerama screens, otherwise the + * GLDrawable may have the wrong visual ID (I don't think this + * ever gets updated). May need to add a method to + * X11GLDrawableFactory to do this in a platform specific + * manner. + * + * However, on platforms where we can actually get into this + * block, both devices should have the same visual list, and the + * same configuration should be selected here. + */ + AWTGraphicsConfiguration config = chooseGraphicsConfiguration( (GLCapabilitiesImmutable)awtConfig.getChosenCapabilities(), + (GLCapabilitiesImmutable)awtConfig.getRequestedCapabilities(), + chooser, gc.getDevice()); + final GraphicsConfiguration compatible = (null!=config)?config.getGraphicsConfiguration():null; + boolean equalCaps = config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities()); + if(DEBUG) { + Exception e = new Exception("Info: Call Stack: "+Thread.currentThread().getName()); + e.printStackTrace(); + System.err.println("!!! Created Config (n): HAVE GC "+chosen); + System.err.println("!!! Created Config (n): THIS GC "+gc); + System.err.println("!!! Created Config (n): Choosen GC "+compatible); + System.err.println("!!! Created Config (n): HAVE CF "+awtConfig); + System.err.println("!!! Created Config (n): Choosen CF "+config); + System.err.println("!!! Created Config (n): EQUALS CAPS "+equalCaps); + } + + if (compatible != null) { + /* + * Save the new GC for equals test above, and to return to + * any outside callers of this method. + */ + chosen = compatible; + + awtConfig = config; + + if( !equalCaps && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) { + dispose(true); + } + } + } + + /* + * If a compatible GC was not found in the block above, this will + * return the GC that was selected in the constructor (and might + * cause an exception in Component.checkGD when adding to a + * container, but in this case that would be the desired behavior). + * + */ + return chosen; + } else if (gc == null) { + /* + * The GC is null, which means we have no native peer, and are not + * part of a (realized) component hierarchy. So we return the + * desired visual that was selected in the constructor (possibly + * null). + */ + return chosen; + } + + /* + * Otherwise we have not explicitly selected a GC in the constructor, so + * just return what Canvas would have. + */ + return gc; + } + + public GLContext createContext(GLContext shareWith) { + drawableSync.lock(); + try { + return (null != drawable) ? drawable.createContext(shareWith) : null; + } finally { + drawableSync.unlock(); + } + } + + public void setRealized(boolean realized) { + } + + public boolean isRealized() { + drawableSync.lock(); + try { + return ( null != drawable ) ? drawable.isRealized() : false; + } finally { + drawableSync.unlock(); + } + } + + public int getDefaultCloseOperation() { + return awtWindowClosingProtocol.getDefaultCloseOperation(); + } + + public int setDefaultCloseOperation(int op) { + return awtWindowClosingProtocol.setDefaultCloseOperation(op); + } + + public void display() { + if( !validateGLDrawable() ) { + if(DEBUG) { + System.err.println("Info: GLCanvas display - skipped GL render, drawable not valid yet"); + } + return; // not yet available .. + } + maybeDoSingleThreadedWorkaround(displayOnEventDispatchThreadAction, + displayAction); + + awtWindowClosingProtocol.addClosingListenerOneShot(); + } + + private void dispose(boolean regenerate) { + drawableSync.lock(); + try { + if(DEBUG) { + Exception ex1 = new Exception("Info: dispose("+regenerate+") - start, hasContext " + + (null!=context) + ", hasDrawable " + (null!=drawable)); + ex1.printStackTrace(); + } + + if(null!=context) { + boolean animatorPaused = false; + GLAnimatorControl animator = getAnimator(); + if(null!=animator) { + // can't remove us from animator for recreational addNotify() + animatorPaused = animator.pause(); + } + + disposeRegenerate=regenerate; + + if (Threading.isSingleThreaded() && + !Threading.isOpenGLThread()) { + // Workaround for termination issues with applets -- + // sun.applet.AppletPanel should probably be performing the + // remove() call on the EDT rather than on its own thread + // Hint: User should run remove from EDT. + if (ThreadingImpl.isAWTMode() && + Thread.holdsLock(getTreeLock())) { + // The user really should not be invoking remove() from this + // thread -- but since he/she is, we can not go over to the + // EDT at this point. Try to destroy the context from here. + if(context.isCreated()) { + drawableHelper.invokeGL(drawable, context, disposeAction, null); + } + } else if(context.isCreated()) { + Threading.invokeOnOpenGLThread(disposeOnEventDispatchThreadAction); + } + } else if(context.isCreated()) { + drawableHelper.invokeGL(drawable, context, disposeAction, null); + } + + if(animatorPaused) { + animator.resume(); + } + } + if(!regenerate) { + disposeAbstractGraphicsDevice(); + } + + if(DEBUG) { + System.err.println("dispose("+regenerate+") - stop"); + } + } finally { + drawableSync.unlock(); + } + } + + /** + * Just an alias for removeNotify + */ + public void destroy() { + removeNotify(); + } + + /** Overridden to cause OpenGL rendering to be performed during + repaint cycles. Subclasses which override this method must call + super.paint() in their paint() method in order to function + properly. <P> + + <B>Overrides:</B> + <DL><DD><CODE>paint</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ + @Override + public void paint(Graphics g) { + if (Beans.isDesignTime()) { + // Make GLCanvas behave better in NetBeans GUI builder + g.setColor(Color.BLACK); + g.fillRect(0, 0, getWidth(), getHeight()); + FontMetrics fm = g.getFontMetrics(); + String name = getName(); + if (name == null) { + name = getClass().getName(); + int idx = name.lastIndexOf('.'); + if (idx >= 0) { + name = name.substring(idx + 1); + } + } + Rectangle2D bounds = fm.getStringBounds(name, g); + g.setColor(Color.WHITE); + g.drawString(name, + (int) ((getWidth() - bounds.getWidth()) / 2), + (int) ((getHeight() + bounds.getHeight()) / 2)); + return; + } + if( ! this.drawableHelper.isExternalAnimatorAnimating() ) { + display(); + } + } + + RecursiveLock drawableSync = new RecursiveLock(); + + /** Overridden to track when this component is added to a container. + Subclasses which override this method must call + super.addNotify() in their addNotify() method in order to + function properly. <P> + + <B>Overrides:</B> + <DL><DD><CODE>addNotify</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ + @Override + public void addNotify() { + if(DEBUG) { + Exception ex1 = new Exception(Thread.currentThread().getName()+" - Info: addNotify - start, bounds: "+this.getBounds()); + ex1.printStackTrace(); + } + + drawableSync.lock(); + try { + /** + * 'super.addNotify()' determines the GraphicsConfiguration, + * while calling this class's overriden 'getGraphicsConfiguration()' method + * after which it creates the native peer. + * Hence we have to set the 'awtConfig' before since it's GraphicsConfiguration + * is being used in getGraphicsConfiguration(). + * This code order also allows recreation, ie re-adding the GLCanvas. + */ + awtConfig = chooseGraphicsConfiguration(capsReqUser, capsReqUser, chooser, device); + if(null==awtConfig) { + throw new GLException("Error: NULL AWTGraphicsConfiguration"); + } + + if (!Beans.isDesignTime()) { + // no lock required, since this resource ain't available yet + drawable = GLDrawableFactory.getFactory(capsReqUser.getGLProfile()) + .createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig)); + context = (GLContextImpl) drawable.createContext(shareWith); + context.setSynchronized(true); + } + + // before native peer is valid: X11 + disableBackgroundErase(); + + // issues getGraphicsConfiguration() and creates the native peer + super.addNotify(); + + // after native peer is valid: Windows + disableBackgroundErase(); + + // init drawable by paint/display makes the init sequence more equal + // for all launch flavors (applet/javaws/..) + // validateGLDrawable(); + + if(DEBUG) { + System.err.println(Thread.currentThread().getName()+" - Info: addNotify - end: peer: "+getPeer()); + } + } finally { + drawableSync.unlock(); + } + } + + private boolean validateGLDrawable() { + boolean realized = false; + if (!Beans.isDesignTime()) { + drawableSync.lock(); + try { + if ( null != drawable ) { + realized = drawable.isRealized(); + if ( !realized && 0 < drawable.getWidth() * drawable.getHeight() ) { + drawable.setRealized(true); + realized = true; + sendReshape=true; // ensure a reshape is being send .. + if(DEBUG) { + String msg = Thread.currentThread().getName()+" - Realized Drawable: "+drawable.toString(); + // System.err.println(msg); + Throwable t = new Throwable(msg); + t.printStackTrace(); + } + } + } + } finally { + drawableSync.unlock(); + } + } + return realized; + } + + /** <p>Overridden to track when this component is removed from a + container. Subclasses which override this method must call + super.removeNotify() in their removeNotify() method in order to + function properly. </p> + <p>User shall not call this method outside of EDT, read the AWT/Swing specs + about this.</p> + <B>Overrides:</B> + <DL><DD><CODE>removeNotify</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ + @Override + public void removeNotify() { + if(DEBUG) { + Exception ex1 = new Exception(Thread.currentThread().getName()+" - Info: removeNotify - start"); + ex1.printStackTrace(); + } + + awtWindowClosingProtocol.removeClosingListener(); + + if (Beans.isDesignTime()) { + super.removeNotify(); + } else { + drawableSync.lock(); + try { + dispose(false); + } finally { + context=null; + drawable=null; + awtConfig=null; + super.removeNotify(); + drawableSync.unlock(); + } + } + if(DEBUG) { + System.err.println(Thread.currentThread().getName()+" - Info: removeNotify - end, peer: "+getPeer()); + } + } + + /** Overridden to cause {@link GLDrawableHelper#reshape} to be + called on all registered {@link GLEventListener}s. Subclasses + which override this method must call super.reshape() in + their reshape() method in order to function properly. <P> + + <B>Overrides:</B> + <DL><DD><CODE>reshape</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ + @Override + public void reshape(int x, int y, int width, int height) { + super.reshape(x, y, width, height); + sendReshape = true; + } + + /** <B>Overrides:</B> + <DL><DD><CODE>update</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ + /** + * Overridden from Canvas to prevent the AWT's clearing of the + * canvas from interfering with the OpenGL rendering. + */ + @Override + public void update(Graphics g) { + paint(g); + } + + public void addGLEventListener(GLEventListener listener) { + drawableHelper.addGLEventListener(listener); + } + + public void addGLEventListener(int index, GLEventListener listener) { + drawableHelper.addGLEventListener(index, listener); + } + + public void removeGLEventListener(GLEventListener listener) { + drawableHelper.removeGLEventListener(listener); + } + + public void setAnimator(GLAnimatorControl animatorControl) { + drawableHelper.setAnimator(animatorControl); + } + + public GLAnimatorControl getAnimator() { + return drawableHelper.getAnimator(); + } + + public void invoke(boolean wait, GLRunnable glRunnable) { + drawableHelper.invoke(this, wait, glRunnable); + } + + public void setContext(GLContext ctx) { + context=(GLContextImpl)ctx; + } + + public GLContext getContext() { + return context; + } + + public GL getGL() { + if (Beans.isDesignTime()) { + return null; + } + GLContext ctx = getContext(); + return (ctx == null) ? null : ctx.getGL(); + } + + public GL setGL(GL gl) { + GLContext ctx = getContext(); + if (ctx != null) { + ctx.setGL(gl); + return gl; + } + return null; + } + + + public void setAutoSwapBufferMode(boolean onOrOff) { + drawableHelper.setAutoSwapBufferMode(onOrOff); + } + + public boolean getAutoSwapBufferMode() { + return drawableHelper.getAutoSwapBufferMode(); + } + + public void swapBuffers() { + maybeDoSingleThreadedWorkaround(swapBuffersOnEventDispatchThreadAction, swapBuffersAction); + } + + public GLProfile getGLProfile() { + return capsReqUser.getGLProfile(); + } + + public GLCapabilitiesImmutable getChosenGLCapabilities() { + if (awtConfig == null) { + throw new GLException("No AWTGraphicsConfiguration: "+this); + } + + return (GLCapabilitiesImmutable)awtConfig.getChosenCapabilities(); + } + + public GLCapabilitiesImmutable getRequestedGLCapabilities() { + if (awtConfig == null) { + return capsReqUser; + } + + return (GLCapabilitiesImmutable)awtConfig.getRequestedCapabilities(); + } + + public NativeSurface getNativeSurface() { + drawableSync.lock(); + try { + return (null != drawable) ? drawable.getNativeSurface() : null; + } finally { + drawableSync.unlock(); + } + } + + public long getHandle() { + drawableSync.lock(); + try { + return (null != drawable) ? drawable.getHandle() : 0; + } finally { + drawableSync.unlock(); + } + } + + public GLDrawableFactory getFactory() { + drawableSync.lock(); + try { + return (null != drawable) ? drawable.getFactory() : null; + } finally { + drawableSync.unlock(); + } + } + + @Override + public String toString() { + final int dw = (null!=drawable) ? drawable.getWidth() : -1; + final int dh = (null!=drawable) ? drawable.getHeight() : -1; + + return "AWT-GLCanvas[Realized "+isRealized()+ + ",\n\t"+((null!=drawable)?drawable.getClass().getName():"null-drawable")+ + ",\n\tRealized "+isRealized()+ + ",\n\tFactory "+getFactory()+ + ",\n\thandle 0x"+Long.toHexString(getHandle())+ + ",\n\tDrawable size "+dw+"x"+dh+ + ",\n\tAWT pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + ",\n\tvisible "+isVisible()+ + ",\n\t"+awtConfig+"]"; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void maybeDoSingleThreadedWorkaround(Runnable eventDispatchThreadAction, + Runnable invokeGLAction) { + if (Threading.isSingleThreaded() && + !Threading.isOpenGLThread()) { + Threading.invokeOnOpenGLThread(eventDispatchThreadAction); + } else { + drawableHelper.invokeGL(drawable, context, invokeGLAction, initAction); + } + } + + class DisposeAction implements Runnable { + public void run() { + drawableHelper.dispose(GLCanvas.this); + + if(null!=context) { + context.makeCurrent(); // implicit wait for lock .. + context.destroy(); + context=null; + } + + if(null!=drawable) { + drawable.setRealized(false); + drawable=null; + } + + if(disposeRegenerate) { + // recreate GLDrawable to reflect it's new graphics configuration + drawable = GLDrawableFactory.getFactory(capsReqUser.getGLProfile()) + .createGLDrawable(NativeWindowFactory.getNativeWindow(GLCanvas.this, awtConfig)); + if(DEBUG) { + System.err.println("GLCanvas.dispose(true): new drawable: "+drawable); + } + drawable.setRealized(true); + context = (GLContextImpl) drawable.createContext(shareWith); + context.setSynchronized(true); + sendReshape=true; // ensure a reshape is being send .. + } + } + } + private boolean disposeRegenerate; + private DisposeAction disposeAction = new DisposeAction(); + + private DisposeOnEventDispatchThreadAction disposeOnEventDispatchThreadAction = + new DisposeOnEventDispatchThreadAction(); + + class DisposeOnEventDispatchThreadAction implements Runnable { + public void run() { + drawableHelper.invokeGL(drawable, context, disposeAction, null); + } + } + + class DisposeAbstractGraphicsDeviceAction implements Runnable { + public void run() { + AbstractGraphicsConfiguration aconfig = (null!=awtConfig) ? awtConfig.getNativeGraphicsConfiguration() : null; + AbstractGraphicsScreen ascreen = (null!=aconfig) ? aconfig.getScreen() : null; + AbstractGraphicsDevice adevice = (null!=ascreen) ? ascreen.getDevice() : null; + if(null!=adevice) { + String adeviceMsg=null; + if(DEBUG) { + adeviceMsg = adevice.toString(); + } + boolean closed = adevice.close(); + if(DEBUG) { + System.err.println(Thread.currentThread().getName() + " - GLCanvas.dispose(false): closed GraphicsDevice: "+adeviceMsg+", result: "+closed); + } + } + awtConfig=null; + } + } + private DisposeAbstractGraphicsDeviceAction disposeAbstractGraphicsDeviceAction = new DisposeAbstractGraphicsDeviceAction(); + + /** + * Disposes the AbstractGraphicsDevice within EDT, + * since resources created (X11: Display), must be destroyed in the same thread, where they have been created. + * + * @see #chooseGraphicsConfiguration(javax.media.opengl.GLCapabilitiesImmutable, javax.media.opengl.GLCapabilitiesImmutable, javax.media.opengl.GLCapabilitiesChooser, java.awt.GraphicsDevice) + */ + void disposeAbstractGraphicsDevice() { + if( EventQueue.isDispatchThread() || Thread.holdsLock(getTreeLock()) ) { + disposeAbstractGraphicsDeviceAction.run(); + } else { + try { + EventQueue.invokeAndWait(disposeAbstractGraphicsDeviceAction); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (InterruptedException e) { + throw new GLException(e); + } + } + } + + class InitAction implements Runnable { + public void run() { + drawableHelper.init(GLCanvas.this); + } + } + private InitAction initAction = new InitAction(); + + class DisplayAction implements Runnable { + public void run() { + if (sendReshape) { + if(DEBUG) { + System.err.println(Thread.currentThread().getName()+" - reshape: "+getWidth()+"x"+getHeight()); + } + // Note: we ignore the given x and y within the parent component + // since we are drawing directly into this heavyweight component. + drawableHelper.reshape(GLCanvas.this, 0, 0, getWidth(), getHeight()); + sendReshape = false; + } + + drawableHelper.display(GLCanvas.this); + } + } + private DisplayAction displayAction = new DisplayAction(); + + class SwapBuffersAction implements Runnable { + public void run() { + drawable.swapBuffers(); + } + } + private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); + + // Workaround for ATI driver bugs related to multithreading issues + // like simultaneous rendering via Animators to canvases that are + // being resized on the AWT event dispatch thread + class DisplayOnEventDispatchThreadAction implements Runnable { + public void run() { + drawableHelper.invokeGL(drawable, context, displayAction, initAction); + } + } + private DisplayOnEventDispatchThreadAction displayOnEventDispatchThreadAction = + new DisplayOnEventDispatchThreadAction(); + class SwapBuffersOnEventDispatchThreadAction implements Runnable { + public void run() { + drawableHelper.invokeGL(drawable, context, swapBuffersAction, initAction); + } + } + private SwapBuffersOnEventDispatchThreadAction swapBuffersOnEventDispatchThreadAction = + new SwapBuffersOnEventDispatchThreadAction(); + + // Disables the AWT's erasing of this Canvas's background on Windows + // in Java SE 6. This internal API is not available in previous + // releases, but the system property + // -Dsun.awt.noerasebackground=true can be specified to get similar + // results globally in previous releases. + private static boolean disableBackgroundEraseInitialized; + private static Method disableBackgroundEraseMethod; + private void disableBackgroundErase() { + if (!disableBackgroundEraseInitialized) { + try { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + Class clazz = getToolkit().getClass(); + while (clazz != null && disableBackgroundEraseMethod == null) { + try { + disableBackgroundEraseMethod = + clazz.getDeclaredMethod("disableBackgroundErase", + new Class[] { Canvas.class }); + disableBackgroundEraseMethod.setAccessible(true); + } catch (Exception e) { + clazz = clazz.getSuperclass(); + } + } + } catch (Exception e) { + } + return null; + } + }); + } catch (Exception e) { + } + disableBackgroundEraseInitialized = true; + if(DEBUG) { + System.err.println("GLCanvas: TK disableBackgroundErase method found: "+ + (null!=disableBackgroundEraseMethod)); + } + } + if (disableBackgroundEraseMethod != null) { + Throwable t=null; + try { + disableBackgroundEraseMethod.invoke(getToolkit(), new Object[] { this }); + } catch (Exception e) { + t = e; + } + if(DEBUG) { + System.err.println("GLCanvas: TK disableBackgroundErase error: "+t); + } + } + } + + /** + * Issues the GraphicsConfigurationFactory's choosing facility within EDT, + * since resources created (X11: Display), must be destroyed in the same thread, where they have been created. + * + * @param capsChosen + * @param capsRequested + * @param chooser + * @param device + * @return the chosen AWTGraphicsConfiguration + * + * @see #disposeAbstractGraphicsDevice() + */ + private AWTGraphicsConfiguration chooseGraphicsConfiguration(final GLCapabilitiesImmutable capsChosen, + final GLCapabilitiesImmutable capsRequested, + final GLCapabilitiesChooser chooser, + final GraphicsDevice device) { + // Make GLCanvas behave better in NetBeans GUI builder + if (Beans.isDesignTime()) { + return null; + } + + final AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(device, AbstractGraphicsDevice.DEFAULT_UNIT); + AWTGraphicsConfiguration config = null; + + if( EventQueue.isDispatchThread() || Thread.holdsLock(getTreeLock()) ) { + config = (AWTGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capsChosen, + capsRequested, + chooser, aScreen); + } else { + try { + final ArrayList bucket = new ArrayList(1); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + AWTGraphicsConfiguration c = (AWTGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capsChosen, + capsRequested, + chooser, aScreen); + bucket.add(c); + } + }); + config = ( bucket.size() > 0 ) ? (AWTGraphicsConfiguration)bucket.get(0) : null ; + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (InterruptedException e) { + throw new GLException(e); + } + } + + if (config == null) { + throw new GLException("Error: Couldn't fetch AWTGraphicsConfiguration"); + } + + return config; + } + + /** + * A most simple JOGL AWT test entry + */ + public static void main(String args[]) { + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(GlueGenVersion.getInstance()); + System.err.println(NativeWindowVersion.getInstance()); + System.err.println(JoglVersion.getInstance()); + + GLDrawableFactory factory = GLDrawableFactory.getDesktopFactory(); + List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null); + for(int i=0; i<availCaps.size(); i++) { + System.err.println(availCaps.get(i)); + } + + GLCapabilitiesImmutable caps = new GLCapabilities( GLProfile.getDefault(GLProfile.getDefaultDesktopDevice()) ); + Frame frame = new Frame("JOGL AWT Test"); + + GLCanvas glCanvas = new GLCanvas(caps); + frame.add(glCanvas); + frame.setSize(128, 128); + + glCanvas.addGLEventListener(new GLEventListener() { + public void init(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + System.err.println(JoglVersion.getGLInfo(gl, null)); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void display(GLAutoDrawable drawable) { + } + + public void dispose(GLAutoDrawable drawable) { + } + }); + + final Frame _frame = frame; + final GLCanvas _glCanvas = glCanvas; + + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _frame.setVisible(true); + }}); + } catch (Throwable t) { + t.printStackTrace(); + } + glCanvas.display(); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _frame.setVisible(false); + _frame.remove(_glCanvas); + _frame.dispose(); + }}); + } catch (Throwable t) { + t.printStackTrace(); + } + } + +} diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java new file mode 100644 index 000000000..d58ad0304 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -0,0 +1,1721 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.opengl.awt; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.beans.Beans; +import java.security.AccessControlContext; +import java.security.AccessController; + +import java.awt.Color; +import java.awt.EventQueue; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsEnvironment; +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferByte; +import java.awt.image.DataBufferInt; +import javax.swing.JPanel; + +import javax.media.nativewindow.WindowClosingProtocol; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.awt.AWTWindowClosingProtocol; + +import javax.media.opengl.DefaultGLCapabilitiesChooser; +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.GL2GL3; +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLRunnable; +import javax.media.opengl.Threading; +import com.jogamp.opengl.util.FBObject; +import jogamp.opengl.Debug; +import jogamp.opengl.GLContextImpl; +import jogamp.opengl.GLDrawableFactoryImpl; +import jogamp.opengl.GLDrawableHelper; +import jogamp.opengl.GLDrawableImpl; +import jogamp.opengl.ThreadingImpl; +import jogamp.opengl.awt.Java2D; +import jogamp.opengl.awt.Java2DGLContext; + +// FIXME: Subclasses need to call resetGLFunctionAvailability() on their +// context whenever the displayChanged() function is called on their +// GLEventListeners + +/** A lightweight Swing component which provides OpenGL rendering + support. Provided for compatibility with Swing user interfaces + when adding a heavyweight doesn't work either because of + Z-ordering or LayoutManager problems. + <P> + The GLJPanel can be made transparent by creating it with a + GLCapabilities object with alpha bits specified and calling {@link + #setOpaque}(false). Pixels with resulting OpenGL alpha values less + than 1.0 will be overlaid on any underlying Swing rendering. </P> + <P> + Notes specific to the Reference Implementation: This component + attempts to use hardware-accelerated rendering via pbuffers and + falls back on to software rendering if problems occur. + Note that because this component attempts to use pbuffers for + rendering, and because pbuffers can not be resized, somewhat + surprising behavior may occur during resize operations; the {@link + GLEventListener#init} method may be called multiple times as the + pbuffer is resized to be able to cover the size of the GLJPanel. + This behavior is correct, as the textures and display lists for + the GLJPanel will have been lost during the resize operation. The + application should attempt to make its GLEventListener.init() + methods as side-effect-free as possible. </P> + <P> + * Please read <A HREF="GLCanvas.html#java2dgl">Java2D OpenGL Remarks</A>. + * </P> +*/ + +public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosingProtocol { + private static final boolean DEBUG = Debug.debug("GLJPanel"); + private static final boolean VERBOSE = Debug.verbose(); + + private GLDrawableHelper drawableHelper = new GLDrawableHelper(); + private volatile boolean isInitialized; + + // Data used for either pbuffers or pixmap-based offscreen surfaces + private GLCapabilitiesImmutable offscreenCaps; + private GLProfile glProfile; + private GLDrawableFactoryImpl factory; + private GLCapabilitiesChooser chooser; + private GLContext shareWith; + // Width of the actual GLJPanel + private int panelWidth = 0; + private int panelHeight = 0; + // Lazy reshape notification + private boolean handleReshape = false; + private boolean sendReshape = true; + + // The backend in use + private Backend backend; + + // Used by all backends either directly or indirectly to hook up callbacks + private Updater updater = new Updater(); + + private static final AccessControlContext localACC = AccessController.getContext(); + + // Turns off the pbuffer-based backend (used by default, unless the + // Java 2D / OpenGL pipeline is in use) + private static boolean hardwareAccelerationDisabled = + Debug.isPropertyDefined("jogl.gljpanel.nohw", true, localACC); + + // Turns off the fallback to software-based rendering from + // pbuffer-based rendering + private static boolean softwareRenderingDisabled = + Debug.isPropertyDefined("jogl.gljpanel.nosw", true, localACC); + + // Indicates whether the Java 2D OpenGL pipeline is enabled + private boolean oglPipelineEnabled = + Java2D.isOGLPipelineActive() && + !Debug.isPropertyDefined("jogl.gljpanel.noogl", true, localACC); + + // For handling reshape events lazily + // private int reshapeX; + // private int reshapeY; + private int reshapeWidth; + private int reshapeHeight; + + // These are always set to (0, 0) except when the Java2D / OpenGL + // pipeline is active + private int viewportX; + private int viewportY; + + private AWTWindowClosingProtocol awtWindowClosingProtocol = + new AWTWindowClosingProtocol(this, new Runnable() { + public void run() { + GLJPanel.this.destroy(); + } + }); + + static { + // Force eager initialization of part of the Java2D class since + // otherwise it's likely it will try to be initialized while on + // the Queue Flusher Thread, which is not allowed + if (Java2D.isOGLPipelineActive() && Java2D.isFBOEnabled()) { + Java2D.getShareContext(GraphicsEnvironment. + getLocalGraphicsEnvironment(). + getDefaultScreenDevice()); + } + } + + /** Creates a new GLJPanel component with a default set of OpenGL + capabilities and using the default OpenGL capabilities selection + mechanism. */ + public GLJPanel() { + this(null); + } + + /** Creates a new GLJPanel component with the requested set of + OpenGL capabilities, using the default OpenGL capabilities + selection mechanism. */ + public GLJPanel(GLCapabilitiesImmutable userCapsRequest) { + this(userCapsRequest, null, null); + } + + /** Creates a new GLJPanel component. The passed GLCapabilities + specifies the OpenGL capabilities for the component; if null, a + default set of capabilities is used. The GLCapabilitiesChooser + specifies the algorithm for selecting one of the available + GLCapabilities for the component; a DefaultGLCapabilitesChooser + is used if null is passed for this argument. The passed + GLContext specifies an OpenGL context with which to share + textures, display lists and other OpenGL state, and may be null + if sharing is not desired. See the note in the overview documentation on + <a href="../../../overview-summary.html#SHARING">context sharing</a>. + <P> + Note: Sharing cannot be enabled using J2D OpenGL FBO sharing, + since J2D GL Context must be shared and we can only share one context. + */ + public GLJPanel(GLCapabilitiesImmutable userCapsRequest, GLCapabilitiesChooser chooser, GLContext shareWith) { + super(); + + // Works around problems on many vendors' cards; we don't need a + // back buffer for the offscreen surface anyway + { + GLCapabilities caps; + if (userCapsRequest != null) { + caps = (GLCapabilities) userCapsRequest.cloneMutable(); + } else { + caps = new GLCapabilities(null); + } + caps.setDoubleBuffered(false); + offscreenCaps = caps; + } + this.glProfile = offscreenCaps.getGLProfile(); + this.factory = GLDrawableFactoryImpl.getFactoryImpl(glProfile); + this.chooser = ((chooser != null) ? chooser : new DefaultGLCapabilitiesChooser()); + this.shareWith = shareWith; + } + + public void display() { + if (EventQueue.isDispatchThread()) { + // Want display() to be synchronous, so call paintImmediately() + paintImmediately(0, 0, getWidth(), getHeight()); + } else { + // Multithreaded redrawing of Swing components is not allowed, + // so do everything on the event dispatch thread + try { + EventQueue.invokeAndWait(paintImmediatelyAction); + } catch (Exception e) { + throw new GLException(e); + } + } + } + + protected void dispose(boolean regenerate) { + if(DEBUG) { + Exception ex1 = new Exception("Info: dispose("+regenerate+") - start"); + ex1.printStackTrace(); + } + + if (backend != null) { + boolean animatorPaused = false; + GLAnimatorControl animator = getAnimator(); + if(null!=animator) { + if(regenerate) { + animatorPaused = animator.pause(); + } else { + animator.remove(this); + } + } + + disposeRegenerate=regenerate; + disposeContext=backend.getContext(); + disposeDrawable=backend.getDrawable(); + + if (Threading.isSingleThreaded() && + !Threading.isOpenGLThread()) { + // Workaround for termination issues with applets -- + // sun.applet.AppletPanel should probably be performing the + // remove() call on the EDT rather than on its own thread + if (ThreadingImpl.isAWTMode() && + Thread.holdsLock(getTreeLock())) { + // The user really should not be invoking remove() from this + // thread -- but since he/she is, we can not go over to the + // EDT at this point. Try to destroy the context from here. + if(disposeContext.isCreated()) { + drawableHelper.invokeGL(disposeDrawable, disposeContext, disposeAction, null); + } + } else if(disposeContext.isCreated()) { + Threading.invokeOnOpenGLThread(disposeOnEventDispatchThreadAction); + } + } else if(disposeContext.isCreated()) { + drawableHelper.invokeGL(disposeDrawable, disposeContext, disposeAction, null); + } + + if(!regenerate) { + AbstractGraphicsDevice adevice = disposeDrawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); + String adeviceMsg=null; + if(DEBUG) { + adeviceMsg = adevice.toString(); + } + // boolean closed = adevice.close(); + boolean closed = false; + if (DEBUG) { + System.err.println("GLJPanel.dispose(false): closed GraphicsDevice: " + adeviceMsg + ", result: " + closed); + } + } + + backend.setContext(disposeContext); + if(null==disposeContext) { + isInitialized = false; + } + + if(animatorPaused) { + animator.resume(); + } + } + + if(DEBUG) { + System.err.println("dispose("+regenerate+") - stop"); + } + } + + /** + * Just an alias for removeNotify + */ + public void destroy() { + removeNotify(); + } + + /** Overridden to cause OpenGL rendering to be performed during + repaint cycles. Subclasses which override this method must call + super.paintComponent() in their paintComponent() method in order + to function properly. <P> + + <B>Overrides:</B> + <DL><DD><CODE>paintComponent</CODE> in class <CODE>javax.swing.JComponent</CODE></DD></DL> */ + protected void paintComponent(final Graphics g) { + if (Beans.isDesignTime()) { + // Make GLJPanel behave better in NetBeans GUI builder + g.setColor(Color.BLACK); + g.fillRect(0, 0, getWidth(), getHeight()); + FontMetrics fm = g.getFontMetrics(); + String name = getName(); + if (name == null) { + name = getClass().getName(); + int idx = name.lastIndexOf('.'); + if (idx >= 0) { + name = name.substring(idx + 1); + } + } + Rectangle2D bounds = fm.getStringBounds(name, g); + g.setColor(Color.WHITE); + g.drawString(name, + (int) ((getWidth() - bounds.getWidth()) / 2), + (int) ((getHeight() + bounds.getHeight()) / 2)); + return; + } + + if (backend == null || !isInitialized) { + createAndInitializeBackend(); + } + + if (!isInitialized) { + return; + } + + // NOTE: must do this when the context is not current as it may + // involve destroying the pbuffer (current context) and + // re-creating it -- tricky to do properly while the context is + // current + if (handleReshape) { + handleReshape(); + } + + updater.setGraphics(g); + backend.doPaintComponent(g); + } + + /** Overridden to track when this component is added to a container. + Subclasses which override this method must call + super.addNotify() in their addNotify() method in order to + function properly. <P> + + <B>Overrides:</B> + <DL><DD><CODE>addNotify</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ + public void addNotify() { + super.addNotify(); + if (DEBUG) { + System.err.println("GLJPanel.addNotify()"); + } + } + + /** Overridden to track when this component is removed from a + container. Subclasses which override this method must call + super.removeNotify() in their removeNotify() method in order to + function properly. <P> + + <B>Overrides:</B> + <DL><DD><CODE>removeNotify</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ + public void removeNotify() { + if(DEBUG) { + Exception ex1 = new Exception("Info: removeNotify - start"); + ex1.printStackTrace(); + } + + awtWindowClosingProtocol.removeClosingListener(); + + dispose(false); + if (backend != null) { + backend.destroy(); + backend = null; + } + isInitialized = false; + super.removeNotify(); + if(DEBUG) { + System.err.println("Info: removeNotify - end"); + } + } + + /** Overridden to cause {@link GLDrawableHelper#reshape} to be + called on all registered {@link GLEventListener}s. Subclasses + which override this method must call super.reshape() in + their reshape() method in order to function properly. <P> + + <B>Overrides:</B> + <DL><DD><CODE>reshape</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ + public void reshape(int x, int y, int width, int height) { + super.reshape(x, y, width, height); + + // reshapeX = x; + // reshapeY = y; + reshapeWidth = width; + reshapeHeight = height; + handleReshape = true; + } + + public void setOpaque(boolean opaque) { + if (backend != null) { + backend.setOpaque(opaque); + } + super.setOpaque(opaque); + } + + public void addGLEventListener(GLEventListener listener) { + drawableHelper.addGLEventListener(listener); + } + + public void addGLEventListener(int index, GLEventListener listener) { + drawableHelper.addGLEventListener(index, listener); + } + + public void removeGLEventListener(GLEventListener listener) { + drawableHelper.removeGLEventListener(listener); + } + + public void setAnimator(GLAnimatorControl animatorControl) { + drawableHelper.setAnimator(animatorControl); + } + + public GLAnimatorControl getAnimator() { + return drawableHelper.getAnimator(); + } + + public void invoke(boolean wait, GLRunnable glRunnable) { + drawableHelper.invoke(this, wait, glRunnable); + } + + public GLContext createContext(GLContext shareWith) { + return backend.createContext(shareWith); + } + + public void setRealized(boolean realized) { + } + + public boolean isRealized() { + return isInitialized; + } + + public void setContext(GLContext ctx) { + if (backend == null) { + return; + } + backend.setContext(ctx); + } + + public GLContext getContext() { + if (backend == null) { + return null; + } + return backend.getContext(); + } + + public GL getGL() { + if (Beans.isDesignTime()) { + return null; + } + GLContext context = getContext(); + return (context == null) ? null : context.getGL(); + } + + public GL setGL(GL gl) { + GLContext context = getContext(); + if (context != null) { + context.setGL(gl); + return gl; + } + return null; + } + + public void setAutoSwapBufferMode(boolean onOrOff) { + // In the current implementation this is a no-op. Both the pbuffer + // and pixmap based rendering paths use a single-buffered surface + // so swapping the buffers doesn't do anything. We also don't + // currently have the provision to skip copying the data to the + // Swing portion of the GLJPanel in any of the rendering paths. + } + + public boolean getAutoSwapBufferMode() { + // In the current implementation this is a no-op. Both the pbuffer + // and pixmap based rendering paths use a single-buffered surface + // so swapping the buffers doesn't do anything. We also don't + // currently have the provision to skip copying the data to the + // Swing portion of the GLJPanel in any of the rendering paths. + return true; + } + + public void swapBuffers() { + // In the current implementation this is a no-op. Both the pbuffer + // and pixmap based rendering paths use a single-buffered surface + // so swapping the buffers doesn't do anything. We also don't + // currently have the provision to skip copying the data to the + // Swing portion of the GLJPanel in any of the rendering paths. + } + + /** For a translucent GLJPanel (one for which {@link #setOpaque + setOpaque}(false) has been called), indicates whether the + application should preserve the OpenGL color buffer + (GL_COLOR_BUFFER_BIT) for correct rendering of the GLJPanel and + underlying widgets which may show through portions of the + GLJPanel with alpha values less than 1. Most Swing + implementations currently expect the GLJPanel to be completely + cleared (e.g., by <code>glClear(GL_COLOR_BUFFER_BIT | + GL_DEPTH_BUFFER_BIT)</code>), but for certain optimized Swing + implementations which use OpenGL internally, it may be possible + to perform OpenGL rendering using the GLJPanel into the same + OpenGL drawable as the Swing implementation uses. */ + public boolean shouldPreserveColorBufferIfTranslucent() { + return oglPipelineEnabled; + } + + public GLCapabilitiesImmutable getChosenGLCapabilities() { + return backend.getChosenGLCapabilities(); + } + + public final GLProfile getGLProfile() { + return glProfile; + } + + public NativeSurface getNativeSurface() { + throw new GLException("FIXME"); + } + + public long getHandle() { + throw new GLException("FIXME"); + } + + public final GLDrawableFactory getFactory() { + return factory; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void createAndInitializeBackend() { + if (panelWidth == 0 || + panelHeight == 0) { + // See whether we have a non-zero size yet and can go ahead with + // initialization + if (reshapeWidth == 0 || + reshapeHeight == 0) { + return; + } + + // Pull down reshapeWidth and reshapeHeight into panelWidth and + // panelHeight eagerly in order to complete initialization, and + // force a reshape later + panelWidth = reshapeWidth; + panelHeight = reshapeHeight; + } + + do { + if (backend == null) { + if (oglPipelineEnabled) { + backend = new J2DOGLBackend(); + } else { + if (!hardwareAccelerationDisabled && + factory.canCreateGLPbuffer(null)) { + backend = new PbufferBackend(); + } else { + if (softwareRenderingDisabled) { + throw new GLException("Fallback to software rendering disabled by user"); + } + backend = new SoftwareBackend(); + } + } + } + + if (!isInitialized) { + backend.initialize(); + } + // The backend might set itself to null, indicating it punted to + // a different implementation -- try again + } while (backend == null); + + awtWindowClosingProtocol.addClosingListenerOneShot(); + } + + public int getDefaultCloseOperation() { + return awtWindowClosingProtocol.getDefaultCloseOperation(); + } + + public int setDefaultCloseOperation(int op) { + return awtWindowClosingProtocol.setDefaultCloseOperation(op); + } + + private void handleReshape() { + panelWidth = reshapeWidth; + panelHeight = reshapeHeight; + + if (DEBUG) { + System.err.println("GLJPanel.handleReshape: (w,h) = (" + + panelWidth + "," + panelHeight + ")"); + } + + sendReshape = true; + backend.handleReshape(); + handleReshape = false; + } + + // This is used as the GLEventListener for the pbuffer-based backend + // as well as the callback mechanism for the other backends + class Updater implements GLEventListener { + private Graphics g; + + public void setGraphics(Graphics g) { + this.g = g; + } + + public void init(GLAutoDrawable drawable) { + if (!backend.preGL(g)) { + return; + } + drawableHelper.init(GLJPanel.this); + backend.postGL(g, false); + } + + public void dispose(GLAutoDrawable drawable) { + drawableHelper.dispose(GLJPanel.this); + } + + public void display(GLAutoDrawable drawable) { + if (!backend.preGL(g)) { + return; + } + if (sendReshape) { + if (DEBUG||VERBOSE) { + System.err.println("display: reshape(" + viewportX + "," + viewportY + " " + panelWidth + "x" + panelHeight + ")"); + } + drawableHelper.reshape(GLJPanel.this, viewportX, viewportY, panelWidth, panelHeight); + sendReshape = false; + } + + drawableHelper.display(GLJPanel.this); + backend.postGL(g, true); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + // This is handled above and dispatched directly to the appropriate context + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + } + + public String toString() { + return "AWT-GLJPanel[ "+((null!=backend)?backend.getDrawable().getClass().getName():"null-drawable")+"]"; + } + + private boolean disposeRegenerate; + private GLContext disposeContext; + private GLDrawable disposeDrawable; + private DisposeAction disposeAction = new DisposeAction(); + + class DisposeAction implements Runnable { + public void run() { + updater.dispose(GLJPanel.this); + + if (null != disposeContext) { + disposeContext.destroy(); + disposeContext = null; + } + if (null != disposeDrawable) { + disposeDrawable.setRealized(false); + } + if (null != disposeDrawable) { + if (disposeRegenerate) { + disposeDrawable.setRealized(true); + disposeContext = (GLContextImpl) disposeDrawable.createContext(shareWith); + disposeContext.setSynchronized(true); + } + } + } + } + + private DisposeOnEventDispatchThreadAction disposeOnEventDispatchThreadAction = + new DisposeOnEventDispatchThreadAction(); + + class DisposeOnEventDispatchThreadAction implements Runnable { + public void run() { + drawableHelper.invokeGL(disposeDrawable, disposeContext, disposeAction, null); + } + } + + + class InitAction implements Runnable { + public void run() { + updater.init(GLJPanel.this); + } + } + private InitAction initAction = new InitAction(); + + class DisplayAction implements Runnable { + public void run() { + updater.display(GLJPanel.this); + } + } + private DisplayAction displayAction = new DisplayAction(); + + class PaintImmediatelyAction implements Runnable { + public void run() { + paintImmediately(0, 0, getWidth(), getHeight()); + } + } + private PaintImmediatelyAction paintImmediatelyAction = new PaintImmediatelyAction(); + + private int getNextPowerOf2(int number) { + // Workaround for problems where 0 width or height are transiently + // seen during layout + if (number == 0) { + return 2; + } + + if (((number-1) & number) == 0) { + //ex: 8 -> 0b1000; 8-1=7 -> 0b0111; 0b1000&0b0111 == 0 + return number; + } + int power = 0; + while (number > 0) { + number = number>>1; + power++; + } + return (1<<power); + } + + private int getGLInteger(GL gl, int which) { + int[] tmp = new int[1]; + gl.glGetIntegerv(which, tmp, 0); + return tmp[0]; + } + + //---------------------------------------------------------------------- + // Implementations of the various backends + // + + // Abstraction of the different rendering backends: i.e., pure + // software / pixmap rendering, pbuffer-based acceleration, Java 2D + // / JOGL bridge + static interface Backend { + // Called each time the backend needs to initialize itself + public void initialize(); + + // Called when the backend should clean up its resources + public void destroy(); + + // Called when the opacity of the GLJPanel is changed + public void setOpaque(boolean opaque); + + // Called to manually create an additional OpenGL context against + // this GLJPanel + public GLContext createContext(GLContext shareWith); + + // Called to set the current backend's GLContext + public void setContext(GLContext ctx); + + // Called to get the current backend's GLContext + public GLContext getContext(); + + // Called to get the current backend's GLDrawable + public GLDrawable getDrawable(); + + // Called to fetch the "real" GLCapabilities for the backend + public GLCapabilitiesImmutable getChosenGLCapabilities(); + + // Called to fetch the "real" GLProfile for the backend + public GLProfile getGLProfile(); + + // Called to handle a reshape event. When this is called, the + // OpenGL context associated with the backend is not current, to + // make it easier to destroy and re-create pbuffers if necessary. + public void handleReshape(); + + // Called before the OpenGL work is done in init() and display(). + // If false is returned, this render is aborted. + public boolean preGL(Graphics g); + + // Called after the OpenGL work is done in init() and display(). + // The isDisplay argument indicates whether this was called on + // behalf of a call to display() rather than init(). + public void postGL(Graphics g, boolean isDisplay); + + // Called from within paintComponent() to initiate the render + public void doPaintComponent(Graphics g); + } + + // Base class used by both the software (pixmap) and pbuffer + // backends, both of which rely on reading back the OpenGL frame + // buffer and drawing it with a BufferedImage + abstract class AbstractReadbackBackend implements Backend { + // This image is exactly the correct size to render into the panel + protected BufferedImage offscreenImage; + // One of these is used to store the read back pixels before storing + // in the BufferedImage + protected ByteBuffer readBackBytes; + protected IntBuffer readBackInts; + protected int readBackWidthInPixels; + protected int readBackHeightInPixels; + + private int awtFormat; + private int glFormat; + private int glType; + + // For saving/restoring of OpenGL state during ReadPixels + private int[] swapbytes = new int[1]; + private int[] rowlength = new int[1]; + private int[] skiprows = new int[1]; + private int[] skippixels = new int[1]; + private int[] alignment = new int[1]; + + public void setOpaque(boolean opaque) { + if (opaque != isOpaque()) { + if (offscreenImage != null) { + offscreenImage.flush(); + offscreenImage = null; + } + } + } + + public boolean preGL(Graphics g) { + // Empty in this implementation + return true; + } + + public void postGL(Graphics g, boolean isDisplay) { + if (isDisplay) { + // Must now copy pixels from offscreen context into surface + if (offscreenImage == null) { + if (panelWidth > 0 && panelHeight > 0) { + // It looks like NVidia's drivers (at least the ones on my + // notebook) are buggy and don't allow a sub-rectangle to be + // read from a pbuffer...this doesn't really matter because + // it's the Graphics.drawImage() calls that are the + // bottleneck + + int awtFormat = 0; + + // Should be more flexible in these BufferedImage formats; + // perhaps see what the preferred image types are on the + // given platform + if (isOpaque()) { + awtFormat = BufferedImage.TYPE_INT_RGB; + } else { + awtFormat = BufferedImage.TYPE_INT_ARGB; + } + + offscreenImage = new BufferedImage(panelWidth, + panelHeight, + awtFormat); + switch (awtFormat) { + case BufferedImage.TYPE_3BYTE_BGR: + glFormat = GL2.GL_BGR; + glType = GL2.GL_UNSIGNED_BYTE; + readBackBytes = ByteBuffer.allocate(readBackWidthInPixels * readBackHeightInPixels * 3); + break; + + case BufferedImage.TYPE_INT_RGB: + case BufferedImage.TYPE_INT_ARGB: + glFormat = GL2.GL_BGRA; + glType = getGLPixelType(); + readBackInts = IntBuffer.allocate(readBackWidthInPixels * readBackHeightInPixels); + break; + + default: + // FIXME: Support more off-screen image types (current + // offscreen context implementations don't use others, and + // some of the OpenGL formats aren't supported in the 1.1 + // headers, which we're currently using) + throw new GLException("Unsupported offscreen image type " + awtFormat); + } + } + } + + if (offscreenImage != null) { + GL2 gl = getGL().getGL2(); + // Save current modes + gl.glGetIntegerv(GL2.GL_PACK_SWAP_BYTES, swapbytes, 0); + gl.glGetIntegerv(GL2.GL_PACK_ROW_LENGTH, rowlength, 0); + gl.glGetIntegerv(GL2.GL_PACK_SKIP_ROWS, skiprows, 0); + gl.glGetIntegerv(GL2.GL_PACK_SKIP_PIXELS, skippixels, 0); + gl.glGetIntegerv(GL2.GL_PACK_ALIGNMENT, alignment, 0); + + gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, GL.GL_FALSE); + gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, readBackWidthInPixels); + gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, 0); + gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, 0); + gl.glPixelStorei(GL2.GL_PACK_ALIGNMENT, 1); + + // Actually read the pixels. + gl.glReadBuffer(GL2.GL_FRONT); + if (readBackBytes != null) { + gl.glReadPixels(0, 0, readBackWidthInPixels, readBackHeightInPixels, glFormat, glType, readBackBytes); + } else if (readBackInts != null) { + gl.glReadPixels(0, 0, readBackWidthInPixels, readBackHeightInPixels, glFormat, glType, readBackInts); + } + + // Restore saved modes. + gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, swapbytes[0]); + gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, rowlength[0]); + gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, skiprows[0]); + gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, skippixels[0]); + gl.glPixelStorei(GL2.GL_PACK_ALIGNMENT, alignment[0]); + + if (readBackBytes != null || readBackInts != null) { + // Copy temporary data into raster of BufferedImage for faster + // blitting Note that we could avoid this copy in the cases + // where !offscreenContext.offscreenImageNeedsVerticalFlip(), + // but that's the software rendering path which is very slow + // anyway + Object src = null; + Object dest = null; + int srcIncr = 0; + int destIncr = 0; + + if (readBackBytes != null) { + src = readBackBytes.array(); + dest = ((DataBufferByte) offscreenImage.getRaster().getDataBuffer()).getData(); + srcIncr = readBackWidthInPixels * 3; + destIncr = offscreenImage.getWidth() * 3; + } else { + src = readBackInts.array(); + dest = ((DataBufferInt) offscreenImage.getRaster().getDataBuffer()).getData(); + srcIncr = readBackWidthInPixels; + destIncr = offscreenImage.getWidth(); + } + + if (flipVertically()) { + int srcPos = 0; + int destPos = (offscreenImage.getHeight() - 1) * destIncr; + for (; destPos >= 0; srcPos += srcIncr, destPos -= destIncr) { + System.arraycopy(src, srcPos, dest, destPos, destIncr); + } + } else { + int srcPos = 0; + int destEnd = destIncr * offscreenImage.getHeight(); + for (int destPos = 0; destPos < destEnd; srcPos += srcIncr, destPos += destIncr) { + System.arraycopy(src, srcPos, dest, destPos, destIncr); + } + } + + // Note: image will be drawn back in paintComponent() for + // correctness on all platforms + } + } + } + } + + public void doPaintComponent(Graphics g) { + doPaintComponentImpl(); + if (offscreenImage != null) { + // Draw resulting image in one shot + g.drawImage(offscreenImage, 0, 0, + offscreenImage.getWidth(), + offscreenImage.getHeight(), + GLJPanel.this); + } + } + + protected abstract void doPaintComponentImpl(); + protected abstract int getGLPixelType(); + protected abstract boolean flipVertically(); + } + + class SoftwareBackend extends AbstractReadbackBackend { + // Implementation using software rendering + private GLDrawableImpl offscreenDrawable; + private GLContextImpl offscreenContext; + + public void initialize() { + // Fall-through path: create an offscreen context instead + offscreenDrawable = (GLDrawableImpl) factory.createOffscreenDrawable( + null /* default platform device */, + offscreenCaps, + chooser, + Math.max(1, panelWidth), + Math.max(1, panelHeight)); + offscreenContext = (GLContextImpl) offscreenDrawable.createContext(shareWith); + offscreenContext.setSynchronized(true); + isInitialized = true; + } + + public void destroy() { + if (offscreenContext != null) { + offscreenContext.destroy(); + offscreenContext = null; + } + if (offscreenDrawable != null) { + offscreenDrawable.destroy(); + offscreenDrawable = null; + } + } + + public GLContext createContext(GLContext shareWith) { + return offscreenDrawable.createContext(shareWith); + } + + public void setContext(GLContext ctx) { + offscreenContext=(GLContextImpl)ctx; + } + + public GLContext getContext() { + return offscreenContext; + } + + public GLDrawable getDrawable() { + return offscreenDrawable; + } + + public GLCapabilitiesImmutable getChosenGLCapabilities() { + if (offscreenDrawable == null) { + return null; + } + return offscreenDrawable.getChosenGLCapabilities(); + } + + public GLProfile getGLProfile() { + if (offscreenDrawable == null) { + return null; + } + return offscreenDrawable.getGLProfile(); + } + + public void handleReshape() { + destroy(); + initialize(); + readBackWidthInPixels = Math.max(1, panelWidth); + readBackHeightInPixels = Math.max(1, panelHeight); + + if (offscreenImage != null) { + offscreenImage.flush(); + offscreenImage = null; + } + } + + protected void doPaintComponentImpl() { + drawableHelper.invokeGL(offscreenDrawable, offscreenContext, displayAction, initAction); + } + + protected int getGLPixelType() { + return offscreenContext.getOffscreenContextPixelDataType(); + } + + protected boolean flipVertically() { + return offscreenContext.offscreenImageNeedsVerticalFlip(); + } + } + + class PbufferBackend extends AbstractReadbackBackend { + private GLPbuffer pbuffer; + private int pbufferWidth = 256; + private int pbufferHeight = 256; + + public void initialize() { + if (pbuffer != null) { + throw new InternalError("Creating pbuffer twice without destroying it (memory leak / correctness bug)"); + } + try { + pbuffer = factory.createGLPbuffer(null /* default platform device */, + offscreenCaps, + null, + pbufferWidth, + pbufferHeight, + shareWith); + pbuffer.addGLEventListener(updater); + isInitialized = true; + } catch (GLException e) { + if (DEBUG) { + e.printStackTrace(); + System.err.println("Info: GLJPanel: Falling back on software rendering because of problems creating pbuffer"); + } + hardwareAccelerationDisabled = true; + backend = null; + isInitialized = false; + createAndInitializeBackend(); + } + } + + public void destroy() { + if (pbuffer != null) { + pbuffer.destroy(); + pbuffer = null; + } + } + + public GLContext createContext(GLContext shareWith) { + return pbuffer.createContext(shareWith); + } + + public void setContext(GLContext ctx) { + if (pbuffer == null && Beans.isDesignTime()) { + return; + } + pbuffer.setContext(ctx); + } + + public GLContext getContext() { + // Workaround for crashes in NetBeans GUI builder + if (pbuffer == null && Beans.isDesignTime()) { + return null; + } + return pbuffer.getContext(); + } + + public GLDrawable getDrawable() { + return pbuffer; + } + + public GLCapabilitiesImmutable getChosenGLCapabilities() { + if (pbuffer == null) { + return null; + } + return pbuffer.getChosenGLCapabilities(); + } + + public GLProfile getGLProfile() { + if (pbuffer == null) { + return null; + } + return pbuffer.getGLProfile(); + } + + public void handleReshape() { + // Use factor larger than 2 during shrinks for some hysteresis + float shrinkFactor = 2.5f; + if ((panelWidth > pbufferWidth) || (panelHeight > pbufferHeight) || + (panelWidth < (pbufferWidth / shrinkFactor)) || (panelHeight < (pbufferHeight / shrinkFactor))) { + if (DEBUG) { + System.err.println("Resizing pbuffer from (" + pbufferWidth + ", " + pbufferHeight + ") " + + " to fit (" + panelWidth + ", " + panelHeight + ")"); + } + // Must destroy and recreate pbuffer to fit + if (pbuffer != null) { + // Watch for errors during pbuffer destruction (due to + // buggy / bad OpenGL drivers, in particular SiS) and fall + // back to software rendering + try { + pbuffer.destroy(); + } catch (GLException e) { + hardwareAccelerationDisabled = true; + backend = null; + isInitialized = false; + // Just disabled hardware acceleration during this resize operation; do a fixup + readBackWidthInPixels = Math.max(1, panelWidth); + readBackHeightInPixels = Math.max(1, panelHeight); + if (DEBUG) { + System.err.println("Warning: falling back to software rendering due to bugs in OpenGL drivers"); + e.printStackTrace(); + } + createAndInitializeBackend(); + return; + } + } + pbuffer = null; + isInitialized = false; + pbufferWidth = getNextPowerOf2(panelWidth); + pbufferHeight = getNextPowerOf2(panelHeight); + if (DEBUG && !hardwareAccelerationDisabled) { + System.err.println("New pbuffer size is (" + pbufferWidth + ", " + pbufferHeight + ")"); + } + initialize(); + } + + // It looks like NVidia's drivers (at least the ones on my + // notebook) are buggy and don't allow a rectangle of less than + // the pbuffer's width to be read...this doesn't really matter + // because it's the Graphics.drawImage() calls that are the + // bottleneck. Should probably make the size of the offscreen + // image be the exact size of the pbuffer to save some work on + // resize operations... + readBackWidthInPixels = pbufferWidth; + readBackHeightInPixels = panelHeight; + + if (offscreenImage != null) { + offscreenImage.flush(); + offscreenImage = null; + } + } + + protected void doPaintComponentImpl() { + pbuffer.display(); + } + + protected int getGLPixelType() { + // This seems to be a good choice on all platforms + return GL2.GL_UNSIGNED_INT_8_8_8_8_REV; + } + + protected boolean flipVertically() { + return true; + } + } + + class J2DOGLBackend implements Backend { + // Opaque Object identifier representing the Java2D surface we are + // drawing to; used to determine when to destroy and recreate JOGL + // context + private Object j2dSurface; + // Graphics object being used during Java2D update action + // (absolutely essential to cache this) + private Graphics cached2DGraphics; + // No-op context representing the Java2D OpenGL context + private GLContext j2dContext; + // Context associated with no-op drawable representing the JOGL + // OpenGL context + private GLDrawable joglDrawable; + // The real OpenGL context JOGL uses to render + private GLContext joglContext; + // State captured from Java2D OpenGL context necessary in order to + // properly render into Java2D back buffer + private int[] drawBuffer = new int[1]; + private int[] readBuffer = new int[1]; + // This is required when the FBO option of the Java2D / OpenGL + // pipeline is active + private int[] frameBuffer = new int[1]; + // Current (as of this writing) NVidia drivers have a couple of bugs + // relating to the sharing of framebuffer and renderbuffer objects + // between contexts. It appears we have to (a) reattach the color + // attachment and (b) actually create new depth buffer storage and + // attach it in order for the FBO to behave properly in our context. + private boolean checkedForFBObjectWorkarounds; + private boolean fbObjectWorkarounds; + private int[] frameBufferDepthBuffer; + private int[] frameBufferTexture; + private boolean createNewDepthBuffer; + // Current (as of this writing) ATI drivers have problems when the + // same FBO is bound in two different contexts. Here we check for + // this case and explicitly release the FBO from Java2D's context + // before switching to ours. Java2D will re-bind the FBO when it + // makes its context current the next time. Interestingly, if we run + // this code path on NVidia hardware, it breaks the rendering + // results -- no output is generated. This doesn't appear to be an + // interaction with the abovementioned NVidia-specific workarounds, + // as even if we disable that code the FBO is still reported as + // incomplete in our context. + private boolean checkedGLVendor; + private boolean vendorIsATI; + + // Holding on to this GraphicsConfiguration is a workaround for a + // problem in the Java 2D / JOGL bridge when FBOs are enabled; see + // comment related to Issue 274 below + private GraphicsConfiguration workaroundConfig; + + public void initialize() { + // No-op in this implementation; everything is done lazily + isInitialized = true; + } + + public void destroy() { + Java2D.invokeWithOGLContextCurrent(null, new Runnable() { + public void run() { + if (joglContext != null) { + joglContext.destroy(); + joglContext = null; + } + joglDrawable = null; + if (j2dContext != null) { + j2dContext.destroy(); + j2dContext = null; + } + } + }); + } + + public void setOpaque(boolean opaque) { + // Empty in this implementation + } + + public GLContext createContext(GLContext shareWith) { + // FIXME: should implement this, but it was not properly + // implemented before the refactoring anyway + throw new GLException("Not yet implemented"); + } + + public void setContext(GLContext ctx) { + joglContext=ctx; + } + + public GLContext getContext() { + return joglContext; + } + + public GLDrawable getDrawable() { + return joglDrawable; + } + + public GLCapabilitiesImmutable getChosenGLCapabilities() { + // FIXME: should do better than this; is it possible to using only platform-independent code? + return new GLCapabilities(null); + } + + public GLProfile getGLProfile() { + // FIXME: should do better than this; is it possible to using only platform-independent code? + return GLProfile.getDefault(GLProfile.getDefaultDesktopDevice()); + } + + public void handleReshape() { + // Empty in this implementation + } + + public boolean preGL(Graphics g) { + GL2 gl = joglContext.getGL().getGL2(); + // Set up needed state in JOGL context from Java2D context + gl.glEnable(GL2.GL_SCISSOR_TEST); + Rectangle r = Java2D.getOGLScissorBox(g); + + if (r == null) { + if (DEBUG && VERBOSE) { + System.err.println("Java2D.getOGLScissorBox() returned null"); + } + return false; + } + if (DEBUG && VERBOSE) { + System.err.println("GLJPanel: gl.glScissor(" + r.x + ", " + r.y + ", " + r.width + ", " + r.height + ")"); + } + + gl.glScissor(r.x, r.y, r.width, r.height); + Rectangle oglViewport = Java2D.getOGLViewport(g, panelWidth, panelHeight); + // If the viewport X or Y changes, in addition to the panel's + // width or height, we need to send a reshape operation to the + // client + if ((viewportX != oglViewport.x) || + (viewportY != oglViewport.y)) { + sendReshape = true; + if (DEBUG) { + System.err.println("Sending reshape because viewport changed"); + System.err.println(" viewportX (" + viewportX + ") ?= oglViewport.x (" + oglViewport.x + ")"); + System.err.println(" viewportY (" + viewportY + ") ?= oglViewport.y (" + oglViewport.y + ")"); + } + } + viewportX = oglViewport.x; + viewportY = oglViewport.y; + + // If the FBO option is active, bind to the FBO from the Java2D + // context. + // Note that all of the plumbing in the context sharing stuff will + // allow us to bind to this object since it's in our namespace. + if (Java2D.isFBOEnabled() && + Java2D.getOGLSurfaceType(g) == Java2D.FBOBJECT) { + + // The texture target for Java2D's OpenGL pipeline when using FBOs + // -- either GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_ARB + int fboTextureTarget = Java2D.getOGLTextureType(g); + + if (!checkedForFBObjectWorkarounds) { + checkedForFBObjectWorkarounds = true; + gl.glBindTexture(fboTextureTarget, 0); + gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, frameBuffer[0]); + int status = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER); + if (status != GL.GL_FRAMEBUFFER_COMPLETE) { + // Need to do workarounds + fbObjectWorkarounds = true; + createNewDepthBuffer = true; + if (DEBUG || VERBOSE) { + System.err.println("GLJPanel: ERR GL_FRAMEBUFFER_BINDING: Discovered Invalid J2D FBO("+frameBuffer[0]+"): "+FBObject.getStatusString(status) + + ", frame_buffer_object workarounds to be necessary"); + } + } else { + // Don't need the frameBufferTexture temporary any more + frameBufferTexture = null; + if (DEBUG || VERBOSE) { + System.err.println("GLJPanel: OK GL_FRAMEBUFFER_BINDING: "+frameBuffer[0]); + } + } + } + + if (fbObjectWorkarounds && createNewDepthBuffer) { + if (frameBufferDepthBuffer == null) + frameBufferDepthBuffer = new int[1]; + + // Create our own depth renderbuffer and associated storage + // If we have an old one, delete it + if (frameBufferDepthBuffer[0] != 0) { + gl.glDeleteRenderbuffers(1, frameBufferDepthBuffer, 0); + frameBufferDepthBuffer[0] = 0; + } + + gl.glBindTexture(fboTextureTarget, frameBufferTexture[0]); + int[] width = new int[1]; + int[] height = new int[1]; + gl.glGetTexLevelParameteriv(fboTextureTarget, 0, GL2.GL_TEXTURE_WIDTH, width, 0); + gl.glGetTexLevelParameteriv(fboTextureTarget, 0, GL2.GL_TEXTURE_HEIGHT, height, 0); + + gl.glGenRenderbuffers(1, frameBufferDepthBuffer, 0); + if (DEBUG) { + System.err.println("GLJPanel: Generated frameBufferDepthBuffer " + frameBufferDepthBuffer[0] + + " with width " + width[0] + ", height " + height[0]); + } + + gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, frameBufferDepthBuffer[0]); + // FIXME: may need a loop here like in Java2D + gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL2GL3.GL_DEPTH_COMPONENT24, width[0], height[0]); + + gl.glBindRenderbuffer(GL2.GL_RENDERBUFFER, 0); + createNewDepthBuffer = false; + } + + gl.glBindTexture(fboTextureTarget, 0); + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, frameBuffer[0]); + + if (fbObjectWorkarounds) { + // Hook up the color and depth buffer attachment points for this framebuffer + gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, + GL.GL_COLOR_ATTACHMENT0, + fboTextureTarget, + frameBufferTexture[0], + 0); + if (DEBUG && VERBOSE) { + System.err.println("GLJPanel: frameBufferDepthBuffer: " + frameBufferDepthBuffer[0]); + } + gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, + GL.GL_DEPTH_ATTACHMENT, + GL.GL_RENDERBUFFER, + frameBufferDepthBuffer[0]); + } + + if (DEBUG) { + int status = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER); + if (status != GL.GL_FRAMEBUFFER_COMPLETE) { + throw new GLException("Error: framebuffer was incomplete: status = 0x" + + Integer.toHexString(status)); + } + } + } else { + if (DEBUG && VERBOSE) { + System.err.println("GLJPanel: Setting up drawBuffer " + drawBuffer[0] + + " and readBuffer " + readBuffer[0]); + } + + gl.glDrawBuffer(drawBuffer[0]); + gl.glReadBuffer(readBuffer[0]); + } + + return true; + } + + public void postGL(Graphics g, boolean isDisplay) { + // Cause OpenGL pipeline to flush its results because + // otherwise it's possible we will buffer up multiple frames' + // rendering results, resulting in apparent mouse lag + GL gl = getGL(); + gl.glFinish(); + + if (Java2D.isFBOEnabled() && + Java2D.getOGLSurfaceType(g) == Java2D.FBOBJECT) { + // Unbind the framebuffer from our context to work around + // apparent driver bugs or at least unspecified behavior causing + // OpenGL to run out of memory with certain cards and drivers + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); + } + } + + public void doPaintComponent(final Graphics g) { + // This is a workaround for an issue in the Java 2D / JOGL + // bridge (reported by an end user as JOGL Issue 274) where Java + // 2D can occasionally leave its internal OpenGL context current + // to the on-screen window rather than its internal "scratch" + // pbuffer surface to which the FBO is attached. JOGL expects to + // find a stable OpenGL drawable (on Windows, an HDC) upon which + // it can create another OpenGL context. It turns out that, on + // Windows, when Java 2D makes its internal OpenGL context + // current against the window in order to put pixels on the + // screen, it gets the device context for the window, makes its + // context current, and releases the device context. This means + // that when JOGL's Runnable gets to run below, the HDC is + // already invalid. The workaround for this is to force Java 2D + // to make its context current to the scratch surface, which we + // can do by executing an empty Runnable with the "shared" + // context current. This will be fixed in a Java SE 6 update + // release, hopefully 6u2. + if (Java2D.isFBOEnabled()) { + if (workaroundConfig == null) { + workaroundConfig = GraphicsEnvironment. + getLocalGraphicsEnvironment(). + getDefaultScreenDevice(). + getDefaultConfiguration(); + } + Java2D.invokeWithOGLSharedContextCurrent(workaroundConfig, new Runnable() { public void run() {}}); + } + + Java2D.invokeWithOGLContextCurrent(g, new Runnable() { + public void run() { + if (DEBUG && VERBOSE) { + System.err.println("-- In invokeWithOGLContextCurrent"); + } + + // Create no-op context representing Java2D context + if (j2dContext == null) { + j2dContext = factory.createExternalGLContext(); + if (DEBUG||VERBOSE) { + System.err.println("-- Created External Context: "+j2dContext); + } + if (DEBUG) { +// j2dContext.setGL(new DebugGL2(j2dContext.getGL().getGL2())); + } + + // Check to see whether we can support the requested + // capabilities or need to fall back to a pbuffer + // FIXME: add more checks? + + j2dContext.makeCurrent(); + GL gl = j2dContext.getGL(); + if ((getGLInteger(gl, GL.GL_RED_BITS) < offscreenCaps.getRedBits()) || + (getGLInteger(gl, GL.GL_GREEN_BITS) < offscreenCaps.getGreenBits()) || + (getGLInteger(gl, GL.GL_BLUE_BITS) < offscreenCaps.getBlueBits()) || + // (getGLInteger(gl, GL.GL_ALPHA_BITS) < offscreenCaps.getAlphaBits()) || + (getGLInteger(gl, GL2.GL_ACCUM_RED_BITS) < offscreenCaps.getAccumRedBits()) || + (getGLInteger(gl, GL2.GL_ACCUM_GREEN_BITS) < offscreenCaps.getAccumGreenBits()) || + (getGLInteger(gl, GL2.GL_ACCUM_BLUE_BITS) < offscreenCaps.getAccumBlueBits()) || + (getGLInteger(gl, GL2.GL_ACCUM_ALPHA_BITS) < offscreenCaps.getAccumAlphaBits()) || + // (getGLInteger(gl, GL2.GL_DEPTH_BITS) < offscreenCaps.getDepthBits()) || + (getGLInteger(gl, GL.GL_STENCIL_BITS) < offscreenCaps.getStencilBits())) { + if (DEBUG) { + System.err.println("GLJPanel: Falling back to pbuffer-based support because Java2D context insufficient"); + System.err.println(" Available Required"); + System.err.println("GL_RED_BITS " + getGLInteger(gl, GL.GL_RED_BITS) + " " + offscreenCaps.getRedBits()); + System.err.println("GL_GREEN_BITS " + getGLInteger(gl, GL.GL_GREEN_BITS) + " " + offscreenCaps.getGreenBits()); + System.err.println("GL_BLUE_BITS " + getGLInteger(gl, GL.GL_BLUE_BITS) + " " + offscreenCaps.getBlueBits()); + System.err.println("GL_ALPHA_BITS " + getGLInteger(gl, GL.GL_ALPHA_BITS) + " " + offscreenCaps.getAlphaBits()); + System.err.println("GL_ACCUM_RED_BITS " + getGLInteger(gl, GL2.GL_ACCUM_RED_BITS) + " " + offscreenCaps.getAccumRedBits()); + System.err.println("GL_ACCUM_GREEN_BITS " + getGLInteger(gl, GL2.GL_ACCUM_GREEN_BITS) + " " + offscreenCaps.getAccumGreenBits()); + System.err.println("GL_ACCUM_BLUE_BITS " + getGLInteger(gl, GL2.GL_ACCUM_BLUE_BITS) + " " + offscreenCaps.getAccumBlueBits()); + System.err.println("GL_ACCUM_ALPHA_BITS " + getGLInteger(gl, GL2.GL_ACCUM_ALPHA_BITS) + " " + offscreenCaps.getAccumAlphaBits()); + System.err.println("GL_DEPTH_BITS " + getGLInteger(gl, GL.GL_DEPTH_BITS) + " " + offscreenCaps.getDepthBits()); + System.err.println("GL_STENCIL_BITS " + getGLInteger(gl, GL.GL_STENCIL_BITS) + " " + offscreenCaps.getStencilBits()); + } + isInitialized = false; + backend = null; + oglPipelineEnabled = false; + handleReshape = true; + j2dContext.release(); + j2dContext.destroy(); + j2dContext = null; + return; + } + j2dContext.release(); + } + + j2dContext.makeCurrent(); + try { + captureJ2DState(j2dContext.getGL(), g); + Object curSurface = Java2D.getOGLSurfaceIdentifier(g); + if (curSurface != null) { + if (j2dSurface != curSurface) { + if (joglContext != null) { + joglContext.destroy(); + joglContext = null; + joglDrawable = null; + sendReshape = true; + if (DEBUG||VERBOSE) { + System.err.println("Sending reshape because surface changed"); + System.err.println("New surface = " + curSurface); + } + } + j2dSurface = curSurface; + if (DEBUG || VERBOSE) { + System.err.print("-- Surface type: "); + int surfaceType = Java2D.getOGLSurfaceType(g); + if (surfaceType == Java2D.UNDEFINED) { + System.err.println("UNDEFINED"); + } else if (surfaceType == Java2D.WINDOW) { + System.err.println("WINDOW"); + } else if (surfaceType == Java2D.PBUFFER) { + System.err.println("PBUFFER"); + } else if (surfaceType == Java2D.TEXTURE) { + System.err.println("TEXTURE"); + } else if (surfaceType == Java2D.FLIP_BACKBUFFER) { + System.err.println("FLIP_BACKBUFFER"); + } else if (surfaceType == Java2D.FBOBJECT) { + System.err.println("FBOBJECT"); + } else { + System.err.println("(Unknown surface type " + surfaceType + ")"); + } + } + } + if (joglContext == null) { + AbstractGraphicsDevice device = j2dContext.getGLDrawable().getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); + if (factory.canCreateExternalGLDrawable(device)) { + joglDrawable = factory.createExternalGLDrawable(); + // FIXME: Need to share with j2d context, due to FBO resource .. + // - ORIG: joglContext = joglDrawable.createContext(shareWith); + joglContext = joglDrawable.createContext(j2dContext); + if (DEBUG||VERBOSE) { + System.err.println("-- Created External Drawable: "+joglDrawable); + System.err.println("-- Created Context: "+joglContext); + } + } else if (factory.canCreateContextOnJava2DSurface(device)) { + // Mac OS X code path + // FIXME: Need to share with j2d context, due to FBO resource .. + // - ORIG: joglContext = factory.createContextOnJava2DSurface(g, shareWith); + joglContext = factory.createContextOnJava2DSurface(g, j2dContext); + if (DEBUG||VERBOSE) { + System.err.println("-- Created Context: "+joglContext); + } + } + /*if (DEBUG) { + joglContext.setGL(new DebugGL2(joglContext.getGL().getGL2())); + }*/ + + if (Java2D.isFBOEnabled() && + Java2D.getOGLSurfaceType(g) == Java2D.FBOBJECT && + fbObjectWorkarounds) { + createNewDepthBuffer = true; + } + } + if (joglContext instanceof Java2DGLContext) { + // Mac OS X code path + ((Java2DGLContext) joglContext).setGraphics(g); + } + + drawableHelper.invokeGL(joglDrawable, joglContext, displayAction, initAction); + } + } finally { + j2dContext.release(); + } + } + }); + } + + private void captureJ2DState(GL gl, Graphics g) { + gl.glGetIntegerv(GL2.GL_DRAW_BUFFER, drawBuffer, 0); + gl.glGetIntegerv(GL2.GL_READ_BUFFER, readBuffer, 0); + if (Java2D.isFBOEnabled() && + Java2D.getOGLSurfaceType(g) == Java2D.FBOBJECT) { + gl.glGetIntegerv(GL.GL_FRAMEBUFFER_BINDING, frameBuffer, 0); + if(!gl.glIsFramebuffer(frameBuffer[0])) { + checkedForFBObjectWorkarounds=true; + fbObjectWorkarounds = true; + createNewDepthBuffer = true; + if (DEBUG || VERBOSE) { + System.err.println("GLJPanel: Fetched ERR GL_FRAMEBUFFER_BINDING: "+frameBuffer[0]+" - NOT A FBO"+ + ", frame_buffer_object workarounds to be necessary"); + } + } else if (DEBUG) { + System.err.println("GLJPanel: Fetched OK GL_FRAMEBUFFER_BINDING: "+frameBuffer[0]); + } + + if(fbObjectWorkarounds || !checkedForFBObjectWorkarounds) { + // See above for description of what we are doing here + if (frameBufferTexture == null) + frameBufferTexture = new int[1]; + + // Query the framebuffer for its color buffer so we can hook + // it back up in our context (should not be necessary) + gl.glGetFramebufferAttachmentParameteriv(GL.GL_FRAMEBUFFER, + GL.GL_COLOR_ATTACHMENT0, + GL.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, + frameBufferTexture, 0); + if (DEBUG && VERBOSE) { + System.err.println("GLJPanel: FBO COLOR_ATTACHMENT0: " + frameBufferTexture[0]); + } + } + + if (!checkedGLVendor) { + checkedGLVendor = true; + String vendor = gl.glGetString(GL.GL_VENDOR); + + if ((vendor != null) && + vendor.startsWith("ATI")) { + vendorIsATI = true; + } + } + + if (vendorIsATI) { + // Unbind the FBO from Java2D's context as it appears that + // driver bugs on ATI's side are causing problems if the FBO is + // simultaneously bound to more than one context. Java2D will + // re-bind the FBO during the next validation of its context. + // Note: this breaks rendering at least on NVidia hardware + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); + } + } + } + } +} diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java new file mode 100644 index 000000000..5563ea9c8 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java @@ -0,0 +1,49 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package javax.media.opengl.fixedfunc; + +import java.nio.*; + +import javax.media.opengl.*; + +public interface GLLightingFunc { + public static final int GL_LIGHT0 = 0x4000; + public static final int GL_LIGHT1 = 0x4001; + public static final int GL_LIGHT2 = 0x4002; + public static final int GL_LIGHT3 = 0x4003; + public static final int GL_LIGHT4 = 0x4004; + public static final int GL_LIGHT5 = 0x4005; + public static final int GL_LIGHT6 = 0x4006; + public static final int GL_LIGHT7 = 0x4007; + public static final int GL_LIGHTING = 0xB50; + public static final int GL_AMBIENT = 0x1200; + public static final int GL_DIFFUSE = 0x1201; + public static final int GL_SPECULAR = 0x1202; + public static final int GL_POSITION = 0x1203; + public static final int GL_SPOT_DIRECTION = 0x1204; + public static final int GL_SPOT_EXPONENT = 0x1205; + public static final int GL_SPOT_CUTOFF = 0x1206; + public static final int GL_CONSTANT_ATTENUATION = 0x1207; + public static final int GL_LINEAR_ATTENUATION = 0x1208; + public static final int GL_QUADRATIC_ATTENUATION = 0x1209; + public static final int GL_EMISSION = 0x1600; + public static final int GL_SHININESS = 0x1601; + public static final int GL_AMBIENT_AND_DIFFUSE = 0x1602; + public static final int GL_COLOR_MATERIAL = 0xB57; + public static final int GL_NORMALIZE = 0xBA1; + + public static final int GL_FLAT = 0x1D00; + public static final int GL_SMOOTH = 0x1D01; + + public void glLightfv(int light, int pname, java.nio.FloatBuffer params); + public void glLightfv(int light, int pname, float[] params, int params_offset); + public void glMaterialf(int face, int pname, float param); + public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params); + public void glMaterialfv(int face, int pname, float[] params, int params_offset); + public void glColor4f(float red, float green, float blue, float alpha); + public void glShadeModel(int mode); + +} + diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java new file mode 100644 index 000000000..b899f3c0a --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java @@ -0,0 +1,74 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package javax.media.opengl.fixedfunc; + +import java.nio.*; + +public interface GLMatrixFunc { + + public static final int GL_MATRIX_MODE = 0x0BA0; + public static final int GL_MODELVIEW = 0x1700; + public static final int GL_PROJECTION = 0x1701; + // public static final int GL_TEXTURE = 0x1702; // Use GL.GL_TEXTURE due to ambiguous GL usage + public static final int GL_MODELVIEW_MATRIX = 0x0BA6; + public static final int GL_PROJECTION_MATRIX = 0x0BA7; + public static final int GL_TEXTURE_MATRIX = 0x0BA8; + + /** + * glGetFloatv + * @param pname GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX or GL_TEXTURE_MATRIX + * @param params the FloatBuffer's position remains unchanged, + * which is the same behavior than the native JOGL GL impl + */ + public void glGetFloatv(int pname, java.nio.FloatBuffer params); + public void glGetFloatv(int pname, float[] params, int params_offset); + /** + * glGetIntegerv + * @param pname GL_MATRIX_MODE + * @param params the FloatBuffer's position remains unchanged + * which is the same behavior than the native JOGL GL impl + */ + public void glGetIntegerv(int pname, IntBuffer params); + public void glGetIntegerv(int pname, int[] params, int params_offset); + + /** + * sets the current matrix + * @param pname GL_MODELVIEW, GL_PROJECTION or GL.GL_TEXTURE + */ + public void glMatrixMode(int mode) ; + + public void glPushMatrix(); + public void glPopMatrix(); + + public void glLoadIdentity() ; + + /** + * glLoadMatrixf + * @param params the FloatBuffer's position remains unchanged, + * which is the same behavior than the native JOGL GL impl + */ + public void glLoadMatrixf(java.nio.FloatBuffer m) ; + public void glLoadMatrixf(float[] m, int m_offset); + + /** + * glMultMatrixf + * @param m the FloatBuffer's position remains unchanged, + * which is the same behavior than the native JOGL GL impl + */ + public void glMultMatrixf(java.nio.FloatBuffer m) ; + public void glMultMatrixf(float[] m, int m_offset); + + public void glTranslatef(float x, float y, float z) ; + + public void glRotatef(float angle, float x, float y, float z); + + public void glScalef(float x, float y, float z) ; + + public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) ; + + public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar); + +} + diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java new file mode 100644 index 000000000..ed7bef5d4 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java @@ -0,0 +1,38 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package javax.media.opengl.fixedfunc; + +import java.nio.*; + +import javax.media.opengl.*; + +public interface GLPointerFunc { + public static final int GL_VERTEX_ARRAY = 0x8074; + public static final int GL_NORMAL_ARRAY = 0x8075; + public static final int GL_COLOR_ARRAY = 0x8076; + public static final int GL_TEXTURE_COORD_ARRAY = 0x8078; + + public void glEnableClientState(int arrayName); + public void glDisableClientState(int arrayName); + + public void glVertexPointer(GLArrayData array); + public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer); + public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset); + + public void glColorPointer(GLArrayData array); + public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer); + public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset); + public void glColor4f(float red, float green, float blue, float alpha); + + public void glNormalPointer(GLArrayData array); + public void glNormalPointer(int type, int stride, java.nio.Buffer pointer); + public void glNormalPointer(int type, int stride, long pointer_buffer_offset); + + public void glTexCoordPointer(GLArrayData array); + public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer); + public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset); + +} + diff --git a/src/jogl/classes/javax/media/opengl/glu/GLUnurbs.java b/src/jogl/classes/javax/media/opengl/glu/GLUnurbs.java new file mode 100644 index 000000000..2641115d0 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/glu/GLUnurbs.java @@ -0,0 +1,8 @@ +package javax.media.opengl.glu; + +/** + * Wrapper for a GLU NURBS object. + */ + +public interface GLUnurbs { +} diff --git a/src/jogl/classes/javax/media/opengl/glu/GLUquadric.java b/src/jogl/classes/javax/media/opengl/glu/GLUquadric.java new file mode 100644 index 000000000..49451a34b --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/glu/GLUquadric.java @@ -0,0 +1,33 @@ +package javax.media.opengl.glu; + +import javax.media.opengl.GL; +import com.jogamp.opengl.util.ImmModeSink; + +/** + * Wrapper for a GLU quadric object. + */ + +public interface GLUquadric { + // enable/disables the Immediate Mode Sink module. + // This defaults to false for GLUgl2, + // and is always true for GLUes1. + public void enableImmModeSink(boolean val); + + public boolean isImmModeSinkEnabled(); + + // set Immediate Mode usage. + // This defaults to false at GLU creation time. + // If enabled rendering will happen immediately, + // otherwise rendering will be hold in the ImmModeSink + // object, to be rendered deferred. + public void setImmMode(boolean val); + + public boolean getImmMode(); + + // creates a new ImmModeSink (VBO Buffers) and + // returns the old vbo buffer with it's rendering result + public ImmModeSink replaceImmModeSink(); + + // gl may be null, then the GL client states are not disabled + public void resetImmModeSink(GL gl); +} diff --git a/src/jogl/classes/javax/media/opengl/glu/GLUtessellator.java b/src/jogl/classes/javax/media/opengl/glu/GLUtessellator.java new file mode 100644 index 000000000..f98bbe158 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/glu/GLUtessellator.java @@ -0,0 +1,66 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package javax.media.opengl.glu; + +/** + * The <b>GLUtessellator</b> object is used to hold the data, such as the + * vertices, edges and callback objects, to describe and tessellate complex + * polygons. A <b>GLUtessellator</b> object is used with the + * {@link GLU GLU} tessellator methods and + * {@link GLUtessellatorCallback GLU callbacks}. + * + * @author Eric Veach, July 1994 + * @author Java Port: Pepijn Van Eechhoudt, July 2003 + * @author Java Port: Nathan Parker Burg, August 2003 + */ +public interface GLUtessellator {} diff --git a/src/jogl/classes/javax/media/opengl/glu/GLUtessellatorCallback.java b/src/jogl/classes/javax/media/opengl/glu/GLUtessellatorCallback.java new file mode 100644 index 000000000..0f05619a4 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/glu/GLUtessellatorCallback.java @@ -0,0 +1,356 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package javax.media.opengl.glu; + +/** + * <b>GLUtessellatorCallback</b> interface provides methods that the user will + * override to define the callbacks for a tessellation object. + * + * @author Eric Veach, July 1994 + * @author Java Port: Pepijn Van Eeckhoudt, July 2003 + * @author Java Port: Nathan Parker Burg, August 2003 + */ +public interface GLUtessellatorCallback { + /** + * The <b>begin</b> callback method is invoked like + * {@link javax.media.opengl.GL#glBegin glBegin} to indicate the start of a + * (triangle) primitive. The method takes a single argument of type int. If + * the <b>GLU_TESS_BOUNDARY_ONLY</b> property is set to <b>GL_FALSE</b>, then + * the argument is set to either <b>GL_TRIANGLE_FAN</b>, + * <b>GL_TRIANGLE_STRIP</b>, or <b>GL_TRIANGLES</b>. If the + * <b>GLU_TESS_BOUNDARY_ONLY</b> property is set to <b>GL_TRUE</b>, then the + * argument will be set to <b>GL_LINE_LOOP</b>. + * + * @param type + * Specifics the type of begin/end pair being defined. The following + * values are valid: <b>GL_TRIANGLE_FAN</b>, <b>GL_TRIANGLE_STRIP</b>, + * <b>GL_TRIANGLES</b> or <b>GL_LINE_LOOP</b>. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #end end + * @see #begin begin + */ + public void begin(int type); + + /** + * The same as the {@link #begin begin} callback method except that + * it takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. + * + * @param type + * Specifics the type of begin/end pair being defined. The following + * values are valid: <b>GL_TRIANGLE_FAN</b>, <b>GL_TRIANGLE_STRIP</b>, + * <b>GL_TRIANGLES</b> or <b>GL_LINE_LOOP</b>. + * @param polygonData + * Specifics a reference to user-defined data. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #endData endData + * @see #begin begin + */ + public void beginData(int type, Object polygonData); + + + /** + * The <b>edgeFlag</b> callback method is similar to + * {@link javax.media.opengl.GL#glEdgeFlag glEdgeFlag}. The method takes + * a single boolean boundaryEdge that indicates which edges lie on the + * polygon boundary. If the boundaryEdge is <b>GL_TRUE</b>, then each vertex + * that follows begins an edge that lies on the polygon boundary, that is, + * an edge that separates an interior region from an exterior one. If the + * boundaryEdge is <b>GL_FALSE</b>, then each vertex that follows begins an + * edge that lies in the polygon interior. The edge flag callback (if + * defined) is invoked before the first vertex callback.<P> + * + * Since triangle fans and triangle strips do not support edge flags, the + * begin callback is not called with <b>GL_TRIANGLE_FAN</b> or + * <b>GL_TRIANGLE_STRIP</b> if a non-null edge flag callback is provided. + * (If the callback is initialized to null, there is no impact on + * performance). Instead, the fans and strips are converted to independent + * triangles. + * + * @param boundaryEdge + * Specifics which edges lie on the polygon boundary. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #edgeFlagData edgeFlagData + */ + public void edgeFlag(boolean boundaryEdge); + + + /** + * The same as the {@link #edgeFlag edgeFlage} callback method + * except that it takes an additional reference argument. This + * reference is identical to the opaque reference provided when + * {@link GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. + * + * @param boundaryEdge + * Specifics which edges lie on the polygon boundary. + * @param polygonData + * Specifics a reference to user-defined data. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #edgeFlag edgeFlag + */ + public void edgeFlagData(boolean boundaryEdge, Object polygonData); + + + /** + * The <b>vertex</b> callback method is invoked between the {@link + * #begin begin} and {@link #end end} callback methods. It is + * similar to {@link javax.media.opengl.GL#glVertex3f glVertex3f}, + * and it defines the vertices of the triangles created by the + * tessellation process. The method takes a reference as its only + * argument. This reference is identical to the opaque reference + * provided by the user when the vertex was described (see {@link + * GLU#gluTessVertex gluTessVertex}). + * + * @param vertexData + * Specifics a reference to the vertices of the triangles created + * by the tessellation process. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #vertexData vertexData + */ + public void vertex(Object vertexData); + + + /** + * The same as the {@link #vertex vertex} callback method except + * that it takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. + * + * @param vertexData + * Specifics a reference to the vertices of the triangles created + * by the tessellation process. + * @param polygonData + * Specifics a reference to user-defined data. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #vertex vertex + */ + public void vertexData(Object vertexData, Object polygonData); + + + /** + * The end callback serves the same purpose as + * {@link javax.media.opengl.GL#glEnd glEnd}. It indicates the end of a + * primitive and it takes no arguments. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #begin begin + * @see #endData endData + */ + public void end(); + + + /** + * The same as the {@link #end end} callback method except that it + * takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. + * + * @param polygonData + * Specifics a reference to user-defined data. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #beginData beginData + * @see #end end + */ + public void endData(Object polygonData); + + + /** + * The <b>combine</b> callback method is called to create a new vertex when + * the tessellation detects an intersection, or wishes to merge features. The + * method takes four arguments: an array of three elements each of type + * double, an array of four references, an array of four elements each of + * type float, and a reference to a reference.<P> + * + * The vertex is defined as a linear combination of up to four existing + * vertices, stored in <i>data</i>. The coefficients of the linear combination + * are given by <i>weight</i>; these weights always add up to 1. All vertex + * pointers are valid even when some of the weights are 0. <i>coords</i> gives + * the location of the new vertex.<P> + * + * The user must allocate another vertex, interpolate parameters using + * <i>data</i> and <i>weight</i>, and return the new vertex pointer in + * <i>outData</i>. This handle is supplied during rendering callbacks. The + * user is responsible for freeing the memory some time after + * {@link GLU#gluTessEndPolygon gluTessEndPolygon} is + * called.<P> + * + * For example, if the polygon lies in an arbitrary plane in 3-space, and a + * color is associated with each vertex, the <b>GLU_TESS_COMBINE</b> + * callback might look like this: + * </UL> + * <PRE> + * void myCombine(double[] coords, Object[] data, + * float[] weight, Object[] outData) + * { + * MyVertex newVertex = new MyVertex(); + * + * newVertex.x = coords[0]; + * newVertex.y = coords[1]; + * newVertex.z = coords[2]; + * newVertex.r = weight[0]*data[0].r + + * weight[1]*data[1].r + + * weight[2]*data[2].r + + * weight[3]*data[3].r; + * newVertex.g = weight[0]*data[0].g + + * weight[1]*data[1].g + + * weight[2]*data[2].g + + * weight[3]*data[3].g; + * newVertex.b = weight[0]*data[0].b + + * weight[1]*data[1].b + + * weight[2]*data[2].b + + * weight[3]*data[3].b; + * newVertex.a = weight[0]*data[0].a + + * weight[1]*data[1].a + + * weight[2]*data[2].a + + * weight[3]*data[3].a; + * outData = newVertex; + * }</PRE> + * + * @param coords + * Specifics the location of the new vertex. + * @param data + * Specifics the vertices used to create the new vertex. + * @param weight + * Specifics the weights used to create the new vertex. + * @param outData + * Reference user the put the coodinates of the new vertex. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #combineData combineData + */ + public void combine(double[] coords, Object[] data, + float[] weight, Object[] outData); + + + /** + * The same as the {@link #combine combine} callback method except + * that it takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. + * + * @param coords + * Specifics the location of the new vertex. + * @param data + * Specifics the vertices used to create the new vertex. + * @param weight + * Specifics the weights used to create the new vertex. + * @param outData + * Reference user the put the coodinates of the new vertex. + * @param polygonData + * Specifics a reference to user-defined data. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #combine combine + */ + public void combineData(double[] coords, Object[] data, + float[] weight, Object[] outData, + Object polygonData); + + + /** + * The <b>error</b> callback method is called when an error is encountered. + * The one argument is of type int; it indicates the specific error that + * occurred and will be set to one of <b>GLU_TESS_MISSING_BEGIN_POLYGON</b>, + * <b>GLU_TESS_MISSING_END_POLYGON</b>, <b>GLU_TESS_MISSING_BEGIN_CONTOUR</b>, + * <b>GLU_TESS_MISSING_END_CONTOUR</b>, <b>GLU_TESS_COORD_TOO_LARGE</b>, + * <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> or <b>GLU_OUT_OF_MEMORY</b>. + * Character strings describing these errors can be retrieved with the + * {@link GLU#gluErrorString gluErrorString} call.<P> + * + * The GLU library will recover from the first four errors by inserting the + * missing call(s). <b>GLU_TESS_COORD_TOO_LARGE</b> indicates that some + * vertex coordinate exceeded the predefined constant + * <b>GLU_TESS_MAX_COORD</b> in absolute value, and that the value has been + * clamped. (Coordinate values must be small enough so that two can be + * multiplied together without overflow.) + * <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> indicates that the tessellation + * detected an intersection between two edges in the input data, and the + * <b>GLU_TESS_COMBINE</b> or <b>GLU_TESS_COMBINE_DATA</b> callback was not + * provided. No output is generated. <b>GLU_OUT_OF_MEMORY</b> indicates that + * there is not enough memory so no output is generated. + * + * @param errnum + * Specifics the error number code. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #errorData errorData + */ + public void error(int errnum); + + + /** + * The same as the {@link #error error} callback method except that + * it takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. + * + * @param errnum + * Specifics the error number code. + * @param polygonData + * Specifics a reference to user-defined data. + * + * @see GLU#gluTessCallback gluTessCallback + * @see #error error + */ + public void errorData(int errnum, Object polygonData); + + //void mesh(jogamp.opengl.tessellator.GLUmesh mesh); +} diff --git a/src/jogl/classes/javax/media/opengl/glu/GLUtessellatorCallbackAdapter.java b/src/jogl/classes/javax/media/opengl/glu/GLUtessellatorCallbackAdapter.java new file mode 100644 index 000000000..bd12dfb9d --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/glu/GLUtessellatorCallbackAdapter.java @@ -0,0 +1,84 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package javax.media.opengl.glu; + +/** + * The <b>GLUtessellatorCallbackAdapter</b> provides a default implementation of + * {@link GLUtessellatorCallback GLUtessellatorCallback} + * with empty callback methods. This class can be extended to provide user + * defined callback methods. + * + * @author Eric Veach, July 1994 + * @author Java Port: Pepijn Van Eechhoudt, July 2003 + * @author Java Port: Nathan Parker Burg, August 2003 + */ + +public class GLUtessellatorCallbackAdapter implements GLUtessellatorCallback { + public void begin(int type) {} + public void edgeFlag(boolean boundaryEdge) {} + public void vertex(Object vertexData) {} + public void end() {} +// public void mesh(jogamp.opengl.tessellator.GLUmesh mesh) {} + public void error(int errnum) {} + public void combine(double[] coords, Object[] data, + float[] weight, Object[] outData) {} + public void beginData(int type, Object polygonData) {} + public void edgeFlagData(boolean boundaryEdge, + Object polygonData) {} + public void vertexData(Object vertexData, Object polygonData) {} + public void endData(Object polygonData) {} + public void errorData(int errnum, Object polygonData) {} + public void combineData(double[] coords, Object[] data, + float[] weight, Object[] outData, + Object polygonData) {} +} diff --git a/src/jogl/classes/jogamp/opengl/Debug.java b/src/jogl/classes/jogamp/opengl/Debug.java new file mode 100644 index 000000000..83c79c1d3 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/Debug.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import java.security.*; + +/** Helper routines for logging and debugging. */ + +public class Debug { + // Some common properties + private static boolean verbose; + private static boolean debugAll; + private static AccessControlContext localACC; + + static { + localACC=AccessController.getContext(); + verbose = isPropertyDefined("jogl.verbose", true); + debugAll = isPropertyDefined("jogl.debug", true); + if (verbose) { + Package p = Package.getPackage("javax.media.opengl"); + System.err.println("JOGL specification version " + p.getSpecificationVersion()); + System.err.println("JOGL implementation version " + p.getImplementationVersion()); + System.err.println("JOGL implementation vendor " + p.getImplementationVendor()); + } + } + + static int getIntProperty(final String property, final boolean jnlpAlias) { + return getIntProperty(property, jnlpAlias, localACC); + } + + public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + int i=0; + try { + Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + i = iv.intValue(); + } catch (NumberFormatException nfe) {} + return i; + } + + static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { + return getBooleanProperty(property, jnlpAlias, localACC); + } + + public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + return b.booleanValue(); + } + + static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { + return isPropertyDefined(property, jnlpAlias, localACC); + } + + public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; + } + + static String getProperty(final String property, final boolean jnlpAlias) { + return getProperty(property, jnlpAlias, localACC); + } + + public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + String s=null; + if(null!=acc && acc.equals(localACC)) { + s = (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val=null; + try { + val = System.getProperty(property); + } catch (Exception e) {} + if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + val = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + return val; + } + }); + } else { + try { + s = System.getProperty(property); + } catch (Exception e) {} + if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + s = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + } + return s; + } + public static final String jnlp_prefix = "jnlp." ; + + public static boolean verbose() { + return verbose; + } + + public static boolean debugAll() { + return debugAll; + } + + public static boolean debug(String subcomponent) { + return debugAll() || isPropertyDefined("jogl.debug." + subcomponent, true); + } +} diff --git a/src/jogl/classes/jogamp/opengl/DesktopGLDynamicLibraryBundleInfo.java b/src/jogl/classes/jogamp/opengl/DesktopGLDynamicLibraryBundleInfo.java new file mode 100644 index 000000000..dc33541e6 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/DesktopGLDynamicLibraryBundleInfo.java @@ -0,0 +1,58 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl; + +import java.util.List; +import java.util.ArrayList; + +public abstract class DesktopGLDynamicLibraryBundleInfo extends GLDynamicLibraryBundleInfo { + private static int posGlueLibGLDESKTOP; + private static List/*<String>*/ glueLibNames; + static { + glueLibNames = new ArrayList(); + + glueLibNames.addAll(getGlueLibNamesPreload()); + + posGlueLibGLDESKTOP = glueLibNames.size(); + glueLibNames.add("jogl_desktop"); + } + + public static final int getGlueLibPosGLDESKTOP() { + return posGlueLibGLDESKTOP; + } + + public DesktopGLDynamicLibraryBundleInfo() { + super(); + } + + public final List/*<String>*/ getGlueLibNames() { + return glueLibNames; + } +} + diff --git a/src/jogl/classes/jogamp/opengl/DesktopGLDynamicLookupHelper.java b/src/jogl/classes/jogamp/opengl/DesktopGLDynamicLookupHelper.java new file mode 100644 index 000000000..4879c617e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/DesktopGLDynamicLookupHelper.java @@ -0,0 +1,63 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl; + +import com.jogamp.common.os.NativeLibrary; +import java.util.*; + +public class DesktopGLDynamicLookupHelper extends GLDynamicLookupHelper { + + public DesktopGLDynamicLookupHelper(DesktopGLDynamicLibraryBundleInfo info) { + super(info); + } + + public DesktopGLDynamicLibraryBundleInfo getDesktopGLBundleInfo() { return (DesktopGLDynamicLibraryBundleInfo) getBundleInfo(); } + + public boolean hasGLBinding() { + return isToolLibLoaded() && isGlueLibLoaded(DesktopGLDynamicLibraryBundleInfo.getGlueLibPosGLDESKTOP()); + } + + public synchronized boolean loadGLULibrary() { + /** hacky code .. where all platform GLU libs are tried ..*/ + if(null==gluLib) { + List/*<String>*/ gluLibNames = new ArrayList(); + gluLibNames.add("/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib"); // osx + gluLibNames.add("libGLU.so"); // unix + gluLibNames.add("GLU32"); // windows + gluLibNames.add("GLU"); // generic + gluLib = loadFirstAvailable(gluLibNames, null, true); + if(null != gluLib) { + nativeLibraries.add(gluLib); + } + } + return null != gluLib ; + } + NativeLibrary gluLib = null; +} + diff --git a/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java b/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java new file mode 100644 index 000000000..b5223a5b6 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import javax.media.opengl.*; +import java.util.*; + +/** + * A utility object intended to be used by implementations to act as a cache + * of which OpenGL extensions are currently available on both the host machine + * and display. + */ +final class ExtensionAvailabilityCache { + protected static final boolean DEBUG = GLContextImpl.DEBUG; + private static final boolean DEBUG_AVAILABILITY = Debug.isPropertyDefined("jogl.debug.ExtensionAvailabilityCache", true); + + ExtensionAvailabilityCache(GLContextImpl context) + { + this.context = context; + } + + /** + * Flush the cache. The cache will be rebuilt lazily as calls to {@link + * #isExtensionAvailable(String)} are received. + */ + final void flush() + { + if(DEBUG) { + System.out.println("ExtensionAvailabilityCache: Flush availability OpenGL "+context.getGLVersion()); + } + availableExtensionCache.clear(); + initialized = false; + } + + /** + * Flush the cache and rebuild the cache. + */ + final void reset() { + flush(); + initAvailableExtensions(); + } + + final boolean isInitialized() { + return initialized && !availableExtensionCache.isEmpty() ; + } + + final boolean isExtensionAvailable(String glExtensionName) { + initAvailableExtensions(); + return availableExtensionCache.contains(mapGLExtensionName(glExtensionName)); + } + + final String getPlatformExtensionsString() { + initAvailableExtensions(); + return glXExtensions; + } + + final String getGLExtensionsString() { + initAvailableExtensions(); + if(DEBUG) { + System.err.println("ExtensionAvailabilityCache: getGLExtensions() called"); + } + return glExtensions; + } + + private final void initAvailableExtensions() { + GL gl = context.getGL(); + // if hash is empty (meaning it was flushed), pre-cache it with the list + // of extensions that are in the GL_EXTENSIONS string + if (availableExtensionCache.isEmpty() || !initialized) { + if (DEBUG) { + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Pre-caching init "+gl+", OpenGL "+context.getGLVersion()); + } + + boolean useGetStringi = false; + + // Use 'glGetStringi' only for ARB GL3 context, + // on GL2 platforms the function might be available, but not working. + if ( context.isGL3() ) { + if ( ! context.isFunctionAvailable("glGetStringi") ) { + if(DEBUG) { + System.err.println("GLContext: GL >= 3.1 usage, but no glGetStringi"); + } + } else { + useGetStringi = true; + } + } + + if (DEBUG) { + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Pre-caching extension availability OpenGL "+context.getGLVersion()+ + ", use "+ ( useGetStringi ? "glGetStringi" : "glGetString" ) ); + } + + StringBuffer sb = new StringBuffer(); + if(useGetStringi) { + GL2GL3 gl2gl3 = gl.getGL2GL3(); + int[] numExtensions = { 0 } ; + gl2gl3.glGetIntegerv(gl2gl3.GL_NUM_EXTENSIONS, numExtensions, 0); + for (int i = 0; i < numExtensions[0]; i++) { + sb.append(gl2gl3.glGetStringi(gl2gl3.GL_EXTENSIONS, i)); + if(i < numExtensions[0]) { + sb.append(" "); + } + } + if (DEBUG) { + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL_EXTENSIONS: "+numExtensions[0]); + } + if(0==numExtensions[0]) { + // fall back .. + useGetStringi=false; + } + } + if(!useGetStringi) { + sb.append(gl.glGetString(GL.GL_EXTENSIONS)); + } + glExtensions = sb.toString(); + glXExtensions = context.getPlatformExtensionsString(); + + sb.append(" "); + sb.append(glXExtensions); + + String allAvailableExtensions = sb.toString(); + if (DEBUG_AVAILABILITY) { + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL vendor: " + gl.glGetString(GL.GL_VENDOR)); + } + StringTokenizer tok = new StringTokenizer(allAvailableExtensions); + while (tok.hasMoreTokens()) { + String availableExt = tok.nextToken().trim(); + availableExt = availableExt.intern(); + availableExtensionCache.add(availableExt); + if (DEBUG_AVAILABILITY) { + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Available: " + availableExt); + } + } + if (DEBUG) { + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: ALL EXTENSIONS: "+availableExtensionCache.size()); + } + + int major[] = new int[] { context.getGLVersionMajor() }; + int minor[] = new int[] { context.getGLVersionMinor() }; + while (GLContext.isValidGLVersion(major[0], minor[0])) { + availableExtensionCache.add("GL_VERSION_" + major[0] + "_" + minor[0]); + if (DEBUG) { + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Added GL_VERSION_" + major[0] + "_" + minor[0] + " to known extensions"); + } + if(!GLContext.decrementGLVersion(major, minor)) break; + } + + // put a dummy var in here so that the cache is no longer empty even if + // no extensions are in the GL_EXTENSIONS string + availableExtensionCache.add("<INTERNAL_DUMMY_PLACEHOLDER>"); + + initialized = true; + } + } + + // FIXME: hack to re-enable GL_NV_vertex_array_range extension after + // recent upgrade to new wglext.h and glxext.h headers + private static String mapGLExtensionName(String extensionName) { + if (extensionName != null && + (extensionName.equals("WGL_NV_vertex_array_range") || + extensionName.equals("GLX_NV_vertex_array_range"))) + return "GL_NV_vertex_array_range"; + return extensionName; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private boolean initialized = false; + private String glExtensions = null; + private String glXExtensions = null; + private HashSet availableExtensionCache = new HashSet(50); + private GLContextImpl context; + + static String getThreadName() { + return Thread.currentThread().getName(); + } + +} diff --git a/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java b/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java new file mode 100644 index 000000000..15e3affee --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import javax.media.opengl.*; +import com.jogamp.common.util.IntLongHashMap; + +/** + * Tracks as closely as possible the sizes of allocated OpenGL buffer + * objects. When glMapBuffer or glMapBufferARB is called, in order to + * turn the resulting base address into a java.nio.ByteBuffer, we need + * to know the size in bytes of the allocated OpenGL buffer object. + * Previously we would compute this size by using + * glGetBufferParameterivARB with a pname of GL_BUFFER_SIZE, but + * it appears doing so each time glMapBuffer is called is too costly + * on at least Apple's new multithreaded OpenGL implementation. <P> + * + * Instead we now try to track the sizes of allocated buffer objects. + * We watch calls to glBindBuffer to see which buffer is bound to + * which target and to glBufferData to see how large the buffer's + * allocated size is. When glMapBuffer is called, we consult our table + * of buffer sizes to see if we can return an answer without a glGet + * call. <P> + * + * We share the GLBufferSizeTracker objects among all GLContexts for + * which sharing is enabled, because the namespace for buffer objects + * is the same for these contexts. <P> + * + * Tracking the state of which buffer objects are bound is done in the + * GLBufferStateTracker and is not completely trivial. In the face of + * calls to glPushClientAttrib / glPopClientAttrib we currently punt + * and re-fetch the bound buffer object for the state in question; + * see, for example, glVertexPointer and the calls down to + * GLBufferStateTracker.getBoundBufferObject(). Note that we currently + * ignore new binding targets such as GL_TRANSFORM_FEEDBACK_BUFFER_NV; + * the fact that new binding targets may be added in the future makes + * it impossible to cache state for these new targets. <P> + * + * Ignoring new binding targets, the primary situation in which we may + * not be able to return a cached answer is in the case of an error, + * where glBindBuffer may not have been called before trying to call + * glBufferData. Also, if external native code modifies a buffer + * object, we may return an incorrect answer. (FIXME: this case + * requires more thought, and perhaps stochastic and + * exponential-fallback checking. However, note that it can only occur + * in the face of external native code which requires that the + * application be signed anyway, so there is no security risk in this + * area.) + */ + +public class GLBufferSizeTracker { + // Map from buffer names to sizes. + // Note: should probably have some way of shrinking this map, but + // can't just make it a WeakHashMap because nobody holds on to the + // keys; would have to always track creation and deletion of buffer + // objects, which is probably sub-optimal. The expected usage + // pattern of buffer objects indicates that the fact that this map + // never shrinks is probably not that bad. + private IntLongHashMap bufferSizeMap; + + protected static final boolean DEBUG = Debug.debug("GLStatusTracker"); + + public GLBufferSizeTracker() { + bufferSizeMap = new IntLongHashMap(); + bufferSizeMap.setKeyNotFoundValue(-1); + } + + public void setBufferSize(GLBufferStateTracker bufferStateTracker, + int target, GL caller, long size) { + // Need to do some similar queries to getBufferSize below + int buffer = bufferStateTracker.getBoundBufferObject(target, caller); + boolean valid = bufferStateTracker.isBoundBufferObjectKnown(target); + if (valid) { + if (buffer == 0) { + // FIXME: this really should not happen if we know what's + // going on. Very likely there is an OpenGL error in the + // application if we get here. Could silently return 0, but it + // seems better to get an early warning that something is + // wrong. + throw new GLException("Error: no OpenGL buffer object appears to be bound to target 0x" + + Integer.toHexString(target)); + } + setDirectStateBufferSize(buffer, caller, size); + } + // We don't know the current buffer state. Note that the buffer + // state tracker will have made the appropriate OpenGL query if it + // didn't know what was going on, so at this point we have nothing + // left to do except drop this piece of information on the floor. + } + + public void setDirectStateBufferSize(int buffer, GL caller, long size) { + bufferSizeMap.put(buffer, size); + } + + public long getBufferSize(GLBufferStateTracker bufferStateTracker, + int target, + GL caller) { + // See whether we know what buffer is currently bound to the given + // state + int buffer = bufferStateTracker.getBoundBufferObject(target, caller); + boolean valid = bufferStateTracker.isBoundBufferObjectKnown(target); + if (valid) { + if (0 == buffer) { + // FIXME: this really should not happen if we know what's + // going on. Very likely there is an OpenGL error in the + // application if we get here. Could silently return 0, but it + // seems better to get an early warning that something is + // wrong. + throw new GLException("Error: no OpenGL buffer object appears to be bound to target 0x" + + Integer.toHexString(target)); + } + return getBufferSizeImpl(target, buffer, caller); + } + // We don't know what's going on in this case; query the GL for an answer + // FIXME: both functions return 'int' types, which is not suitable, + // since buffer lenght is 64bit ? + int[] tmp = new int[1]; + caller.glGetBufferParameteriv(target, GL.GL_BUFFER_SIZE, tmp, 0); + if (DEBUG) { + System.err.println("GLBufferSizeTracker.getBufferSize(): no cached buffer information"); + } + return (long) tmp[0]; + } + + public long getDirectStateBufferSize(int buffer, GL caller) { + return getBufferSizeImpl(0, buffer, caller); + } + + private long getBufferSizeImpl(int target, int buffer, GL caller) { + // See whether we know the size of this buffer object; at this + // point we almost certainly should if the application is + // written correctly + long sz = bufferSizeMap.get(buffer); + if (0 > sz) { + // For robustness, try to query this value from the GL as we used to + // FIXME: both functions return 'int' types, which is not suitable, + // since buffer lenght is 64bit ? + int[] tmp = new int[1]; + if(0==target) { + // DirectState .. + if(caller.isFunctionAvailable("glGetNamedBufferParameterivEXT")) { + caller.getGL2().glGetNamedBufferParameterivEXT(buffer, GL.GL_BUFFER_SIZE, tmp, 0); + } else { + throw new GLException("Error: getDirectStateBufferSize called with unknown state and GL function 'glGetNamedBufferParameterivEXT' n/a to query size"); + } + } else { + caller.glGetBufferParameteriv(target, GL.GL_BUFFER_SIZE, tmp, 0); + } + if (tmp[0] == 0) { + // Assume something is wrong rather than silently going along + throw new GLException("Error: buffer size returned by "+ + ((0==target)?"glGetNamedBufferParameterivEXT":"glGetBufferParameteriv")+ + " was zero; probably application error"); + } + // Assume we just don't know what's happening + sz = (long) tmp[0]; + bufferSizeMap.put(buffer, sz); + if (DEBUG) { + System.err.println("GLBufferSizeTracker.getBufferSize(): made slow query to cache size " + + sz + + " for buffer " + + buffer); + } + } + return sz; + } + + // This should be called on any major event where we might start + // producing wrong answers, such as OpenGL context creation and + // destruction if we don't know whether there are other currently- + // created contexts that might be keeping the buffer objects alive + // that we're dealing with + public void clearCachedBufferSizes() { + bufferSizeMap.clear(); + } +} diff --git a/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java b/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java new file mode 100644 index 000000000..d028bf98d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import javax.media.opengl.*; +import com.jogamp.common.util.IntIntHashMap; + +/** + * Tracks as closely as possible which OpenGL buffer object is bound + * to which binding target in the current OpenGL context. + * GLBufferStateTracker objects are allocated on a per-OpenGL-context basis. + * This class is used to verify that e.g. the vertex + * buffer object extension is in use when the glVertexPointer variant + * taking a long as argument is called. <P> + * + * Note that because the enumerated value used for the binding of a + * buffer object (e.g. GL_ARRAY_BUFFER) is different than that used to + * query the binding using glGetIntegerv (e.g. + * GL_ARRAY_BUFFER_BINDING), then in the face of new binding targets + * being added to the GL (e.g. GL_TRANSFORM_FEEDBACK_BUFFER_NV) it is + * impossible to set up a query of the buffer object currently bound + * to a particular state. It turns out that for some uses, such as + * finding the size of the currently bound buffer, this doesn't + * matter, though of course without knowing the buffer object we can't + * re-associate the queried size with the buffer object ID. <P> + * + * Because the namespace of buffer objects is the unsigned integers + * with 0 reserved by the GL, and because we have to be able to return + * both 0 and other integers as valid answers from + * getBoundBufferObject(), we need a second query, which is to ask + * whether we know the state of the binding for a given target. For + * "unknown" targets such as GL_TRANSFORM_FEEDBACK_BUFFER_NV we return + * false from this, but we also clear the valid bit and later refresh + * the binding state if glPushClientAttrib / glPopClientAttrib are + * called, since we don't want the complexity of tracking stacks of + * these attributes. + * + */ + +public class GLBufferStateTracker { + protected static final boolean DEBUG = GLBufferSizeTracker.DEBUG; + + // Maps binding targets to buffer objects. A null value indicates + // that the binding is unknown. A zero value indicates that it is + // known that no buffer is bound to the target, according to the + // OpenGL specifications. + // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml + private IntIntHashMap bindingMap; + + private int[] bufTmp = new int[1]; + + public GLBufferStateTracker() { + bindingMap = new IntIntHashMap(); + bindingMap.setKeyNotFoundValue(-1); + + // Start with known unbound targets for known keys + bindingMap.put(GL.GL_ARRAY_BUFFER, 0); + bindingMap.put(GL.GL_ELEMENT_ARRAY_BUFFER, 0); + bindingMap.put(GL2.GL_PIXEL_PACK_BUFFER, 0); + bindingMap.put(GL2.GL_PIXEL_UNPACK_BUFFER, 0); + } + + public void setBoundBufferObject(int target, int buffer) { + bindingMap.put(target, buffer); + } + + /** Note: returns an unspecified value if the binding for the + specified target (e.g. GL_ARRAY_BUFFER) is currently unknown. + You must use isBoundBufferObjectKnown() to see whether the + return value is valid. */ + public int getBoundBufferObject(int target, GL caller) { + int value = bindingMap.get(target); + if (0 > value) { + // User probably either called glPushClientAttrib / + // glPopClientAttrib or is querying an unknown target. See + // whether we know how to fetch this state. + boolean gotQueryTarget = true; + int queryTarget = 0; + switch (target) { + case GL.GL_ARRAY_BUFFER: queryTarget = GL.GL_ARRAY_BUFFER_BINDING; break; + case GL.GL_ELEMENT_ARRAY_BUFFER: queryTarget = GL.GL_ELEMENT_ARRAY_BUFFER_BINDING; break; + case GL2.GL_PIXEL_PACK_BUFFER: queryTarget = GL2.GL_PIXEL_PACK_BUFFER_BINDING; break; + case GL2.GL_PIXEL_UNPACK_BUFFER: queryTarget = GL2.GL_PIXEL_UNPACK_BUFFER_BINDING; break; + default: gotQueryTarget = false; break; + } + if (gotQueryTarget) { + caller.glGetIntegerv(queryTarget, bufTmp, 0); + if (DEBUG) { + System.err.println("GLBufferStateTracker.getBoundBufferObject(): queried bound buffer " + + bufTmp[0] + + " for query target 0x" + Integer.toHexString(queryTarget)); + } + setBoundBufferObject(target, bufTmp[0]); + return bufTmp[0]; + } + return 0; + } + return value; + } + + /** Indicates whether the binding state for the specified target is + currently known, ie it could be bound or not but it must be tracked.<br> + Should be called after getBoundBufferObject() + because that method may change the answer for a given target. */ + public boolean isBoundBufferObjectKnown(int target) { + return 0 < bindingMap.get(target) ; + } + + /** Clears out the known/unknown state of the various buffer object + binding states. These will be refreshed later on an as-needed + basis. This is called by the implementations of + glPushClientAttrib / glPopClientAttrib. Might want to call this + from GLContext.makeCurrent() in the future to possibly increase + the robustness of these caches in the face of external native + code manipulating OpenGL state. */ + public void clearBufferObjectState() { + bindingMap.clear(); + } +} diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java new file mode 100644 index 000000000..d5059eb74 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -0,0 +1,1044 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; + +import com.jogamp.common.os.DynamicLookupHelper; +import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.gluegen.runtime.FunctionAddressResolver; +import com.jogamp.gluegen.runtime.ProcAddressTable; +import com.jogamp.gluegen.runtime.opengl.GLExtensionNames; +import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeSurface; +import javax.media.opengl.GL; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +public abstract class GLContextImpl extends GLContext { + protected static final boolean DEBUG = Debug.debug("GLContext"); + + protected GLContextLock lock = new GLContextLock(); + + /** + * Context full qualified name: display_type + display_connection + major + minor + ctp. + * This is the key for all cached GL ProcAddressTables, etc, to support multi display/device setups. + */ + private String contextFQN; + + // Cache of the functions that are available to be called at the current + // moment in time + protected ExtensionAvailabilityCache extensionAvailability; + // Table that holds the addresses of the native C-language entry points for + // OpenGL functions. + private ProcAddressTable glProcAddressTable; + + // Tracks creation and initialization of buffer objects to avoid + // repeated glGet calls upon glMapBuffer operations + private GLBufferSizeTracker bufferSizeTracker; // Singleton - Set by GLContextShareSet + private GLBufferStateTracker bufferStateTracker = new GLBufferStateTracker(); + private GLStateTracker glStateTracker = new GLStateTracker(); + + protected GLDrawableImpl drawable; + protected GLDrawableImpl drawableRead; + + protected GL gl; + + protected static final Object mappedContextTypeObjectLock; + protected static final HashMap mappedExtensionAvailabilityCache; + protected static final HashMap mappedGLProcAddress; + protected static final HashMap mappedGLXProcAddress; + + static { + mappedContextTypeObjectLock = new Object(); + mappedExtensionAvailabilityCache = new HashMap(); + mappedGLProcAddress = new HashMap(); + mappedGLXProcAddress = new HashMap(); + } + + public GLContextImpl(GLDrawableImpl drawable, GLContext shareWith) { + super(); + + if (shareWith != null) { + GLContextShareSet.registerSharing(this, shareWith); + } + GLContextShareSet.registerForBufferObjectSharing(shareWith, this); + + this.drawable = drawable; + this.drawableRead = drawable; + } + + protected void resetStates() { + // Because we don't know how many other contexts we might be + // sharing with (and it seems too complicated to implement the + // GLObjectTracker's ref/unref scheme for the buffer-related + // optimizations), simply clear the cache of known buffers' sizes + // when we destroy contexts + if (bufferSizeTracker != null) { + bufferSizeTracker.clearCachedBufferSizes(); + } + + if (bufferStateTracker != null) { + bufferStateTracker.clearBufferObjectState(); + } + + if (glStateTracker != null) { + glStateTracker.clearStates(false); + } + + extensionAvailability = null; + glProcAddressTable = null; + gl = null; + contextFQN = null; + + super.resetStates(); + } + + public final void setGLReadDrawable(GLDrawable read) { + if(null!=read && drawable!=read && !isGLReadDrawableAvailable()) { + throw new GLException("GL Read Drawable not available"); + } + boolean lockHeld = lock.isHeld(); + if(lockHeld) { + release(); + } + drawableRead = ( null != read ) ? (GLDrawableImpl) read : drawable; + if(lockHeld) { + makeCurrent(); + } + } + + public final GLDrawable getGLReadDrawable() { + return drawableRead; + } + + public final GLDrawable getGLDrawable() { + return drawable; + } + + public final GLDrawableImpl getDrawableImpl() { + return (GLDrawableImpl) getGLDrawable(); + } + + public final GL getGL() { + return gl; + } + + public GL setGL(GL gl) { + if(DEBUG) { + String sgl1 = (null!=this.gl)?this.gl.getClass().getSimpleName()+", "+this.gl.toString():"<null>"; + String sgl2 = (null!=gl)?gl.getClass().getSimpleName()+", "+gl.toString():"<null>"; + Exception e = new Exception("Info: setGL (OpenGL "+getGLVersion()+"): "+Thread.currentThread().getName()+", "+sgl1+" -> "+sgl2); + e.printStackTrace(); + } + this.gl = gl; + return gl; + } + + // This is only needed for Mac OS X on-screen contexts + protected void update() throws GLException { } + + public boolean isSynchronized() { + return !lock.getFailFastMode(); + } + + public void setSynchronized(boolean isSynchronized) { + lock.setFailFastMode(!isSynchronized); + } + + public abstract Object getPlatformGLExtensions(); + + // Note: the surface is locked within [makeCurrent .. swap .. release] + public void release() throws GLException { + if (!lock.isHeld()) { + throw new GLException("Context not current on current thread"); + } + setCurrent(null); + try { + releaseImpl(); + } finally { + if (drawable.isSurfaceLocked()) { + drawable.unlockSurface(); + } + lock.unlock(); + } + } + protected abstract void releaseImpl() throws GLException; + + public final void destroy() { + if (lock.isHeld()) { + // release current context + release(); + } + + // Must hold the lock around the destroy operation to make sure we + // don't destroy the context out from under another thread rendering to it + lock.lock(); + try { + /* FIXME: refactor dependence on Java 2D / JOGL bridge + if (tracker != null) { + // Don't need to do anything for contexts that haven't been + // created yet + if (isCreated()) { + // If we are tracking creation and destruction of server-side + // OpenGL objects, we must decrement the reference count of the + // GLObjectTracker upon context destruction. + // + // Note that we can only eagerly delete these server-side + // objects if there is another context currrent right now + // which shares textures and display lists with this one. + tracker.unref(deletedObjectTracker); + } + } + */ + + if (contextHandle != 0) { + int lockRes = drawable.lockSurface(); + if (NativeSurface.LOCK_SURFACE_NOT_READY == lockRes) { + // this would be odd .. + throw new GLException("Surface not ready to lock: "+drawable); + } + try { + destroyImpl(); + contextHandle = 0; + GLContextShareSet.contextDestroyed(this); + } finally { + drawable.unlockSurface(); + } + } + } finally { + lock.unlock(); + } + + resetStates(); + } + protected abstract void destroyImpl() throws GLException; + + public final void copy(GLContext source, int mask) throws GLException { + if (source.getHandle() == 0) { + throw new GLException("Source OpenGL context has not been created"); + } + if (getHandle() == 0) { + throw new GLException("Destination OpenGL context has not been created"); + } + + int lockRes = drawable.lockSurface(); + if (NativeSurface.LOCK_SURFACE_NOT_READY == lockRes) { + // this would be odd .. + throw new GLException("Surface not ready to lock"); + } + try { + copyImpl(source, mask); + } finally { + drawable.unlockSurface(); + } + } + protected abstract void copyImpl(GLContext source, int mask) throws GLException; + + //---------------------------------------------------------------------- + // + + /** + * MakeCurrent functionality, which also issues the creation of the actual OpenGL context.<br> + * The complete callgraph for general OpenGL context creation is:<br> + * <ul> + * <li> {@link #makeCurrent} <i>GLContextImpl</i></li> + * <li> {@link #makeCurrentImpl} <i>Platform Implementation</i></li> + * <li> {@link #create} <i>Platform Implementation</i></li> + * <li> If <code>ARB_create_context</code> is supported: + * <ul> + * <li> {@link #createContextARB} <i>GLContextImpl</i></li> + * <li> {@link #createContextARBImpl} <i>Platform Implementation</i></li> + * </ul></li> + * </ul><br> + * + * Once at startup, ie triggered by the singleton constructor of a {@link GLDrawableFactoryImpl} specialization, + * calling {@link #createContextARB} will query all available OpenGL versions:<br> + * <ul> + * <li> <code>FOR ALL GL* DO</code>: + * <ul> + * <li> {@link #createContextARBMapVersionsAvailable} + * <ul> + * <li> {@link #createContextARBVersions}</li> + * </ul></li> + * <li> {@link #mapVersionAvailable}</li> + * </ul></li> + * </ul><br> + * + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #mapVersionAvailable + * @see #destroyContextARBImpl + */ + public int makeCurrent() throws GLException { + // One context can only be current by one thread, + // and one thread can only have one context current! + GLContext current = getCurrent(); + if (current != null) { + if (current == this) { + // Assume we don't need to make this context current again + // For Mac OS X, however, we need to update the context to track resizes + update(); + return CONTEXT_CURRENT; + } else { + current.release(); + } + } + + if (GLWorkerThread.isStarted() && + !GLWorkerThread.isWorkerThread()) { + // Kick the GLWorkerThread off its current context + GLWorkerThread.invokeLater(new Runnable() { public void run() {} }); + } + + if (!isCreated()) { + // verify if the drawable has chosen Capabilities + if (null == getGLDrawable().getChosenGLCapabilities()) { + throw new GLException("drawable has no chosen GLCapabilities: "+getGLDrawable()); + } + } + + lock.lock(); + int res = 0; + try { + res = makeCurrentLocking(); + + /* FIXME: refactor dependence on Java 2D / JOGL bridge + if ((tracker != null) && + (res == CONTEXT_CURRENT_NEW)) { + // Increase reference count of GLObjectTracker + tracker.ref(); + } + */ + } catch (GLException e) { + lock.unlock(); + throw(e); + } + if (res == CONTEXT_NOT_CURRENT) { + lock.unlock(); + } else { + if(res == CONTEXT_CURRENT_NEW) { + // check if the drawable's and the GL's GLProfile are equal + // throws an GLException if not + getGLDrawable().getGLProfile().verifyEquality(gl.getGLProfile()); + } + setCurrent(this); + + /* FIXME: refactor dependence on Java 2D / JOGL bridge + + // Try cleaning up any stale server-side OpenGL objects + // FIXME: not sure what to do here if this throws + if (deletedObjectTracker != null) { + deletedObjectTracker.clean(getGL()); + } + */ + } + return res; + } + + // Note: the surface is locked within [makeCurrent .. swap .. release] + protected final int makeCurrentLocking() throws GLException { + boolean exceptionOccurred = false; + int lockRes = drawable.lockSurface(); + try { + if (NativeSurface.LOCK_SURFACE_NOT_READY == lockRes) { + return CONTEXT_NOT_CURRENT; + } + try { + if (NativeSurface.LOCK_SURFACE_CHANGED == lockRes) { + drawable.updateHandle(); + } + if (0 == drawable.getHandle()) { + throw new GLException("drawable has invalid handle: "+drawable); + } + boolean newCreated = false; + if (!isCreated()) { + GLProfile.initProfiles( + getGLDrawable().getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice()); + newCreated = createImpl(); // may throws exception if fails! + if (DEBUG) { + if(newCreated) { + System.err.println(getThreadName() + ": !!! Create GL context OK: " + toHexString(contextHandle) + " for " + getClass().getName()); + } else { + System.err.println(getThreadName() + ": !!! Create GL context FAILED for " + getClass().getName()); + } + } + if(!newCreated) { + return CONTEXT_NOT_CURRENT; + } + GLContextShareSet.contextCreated(this); + } + makeCurrentImpl(newCreated); + return newCreated ? CONTEXT_CURRENT_NEW : CONTEXT_CURRENT ; + } catch (RuntimeException e) { + exceptionOccurred = true; + throw e; + } + } finally { + if (exceptionOccurred) { + drawable.unlockSurface(); + } + } + } + protected abstract void makeCurrentImpl(boolean newCreatedContext) throws GLException; + protected abstract boolean createImpl() throws GLException ; + + /** + * Platform dependent but harmonized implementation of the <code>ARB_create_context</code> + * mechanism to create a context.<br> + * + * This method is called from {@link #createContextARB}.<br> + * + * The implementation shall verify this context with a + * <code>MakeContextCurrent</code> call.<br> + * + * The implementation shall leave the context current.<br> + * + * @param share the shared context or null + * @param direct flag if direct is requested + * @param ctxOptionFlags <code>ARB_create_context</code> related, see references below + * @param major major number + * @param minor minor number + * @return the valid context if successfull, or null + * + * @see #makeCurrent + * @see #CTX_PROFILE_COMPAT + * @see #CTX_OPTION_FORWARD + * @see #CTX_OPTION_DEBUG + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #destroyContextARBImpl + */ + protected abstract long createContextARBImpl(long share, boolean direct, int ctxOptionFlags, + int major, int minor); + + /** + * Destroy the context created by {@link #createContextARBImpl}. + * + * @see #makeCurrent + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #destroyContextARBImpl + */ + protected abstract void destroyContextARBImpl(long context); + + /** + * Platform independent part of using the <code>ARB_create_context</code> + * mechanism to create a context.<br> + * + * The implementation of {@link #create} shall use this protocol in case the platform supports <code>ARB_create_context</code>.<br> + * + * This method may call {@link #createContextARBImpl} and {@link #destroyContextARBImpl}. <br> + * + * This method will also query all available native OpenGL context when first called,<br> + * usually the first call should happen with the shared GLContext of the DrawableFactory.<br> + * + * The implementation makes the context current, if successful<br> + * + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #destroyContextARBImpl + */ + protected final long createContextARB(long share, boolean direct, + int major[], int minor[], int ctp[]) + { + AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice device = config.getScreen().getDevice(); + GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + GLProfile glp = glCaps.getGLProfile(); + + if (DEBUG) { + System.err.println(getThreadName() + ": !!! createContextARB: mappedVersionsAvailableSet("+device.getConnection()+"): "+ + GLContext.getAvailableGLVersionsSet(device)); + } + + if ( !GLContext.getAvailableGLVersionsSet(device) ) { + mapGLVersions(device); + } + + int reqMajor; + if(glp.isGL4()) { + reqMajor=4; + } else if (glp.isGL3()) { + reqMajor=3; + } else /* if (glp.isGL2()) */ { + reqMajor=2; + } + + boolean compat = glp.isGL2(); // incl GL3bc and GL4bc + int _major[] = { 0 }; + int _minor[] = { 0 }; + int _ctp[] = { 0 }; + long _ctx = 0; + + if( GLContext.getAvailableGLVersion(device, reqMajor, compat?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE, + _major, _minor, _ctp)) { + _ctx = createContextARBImpl(share, direct, _ctp[0], _major[0], _minor[0]); + if(0!=_ctx) { + setGLFunctionAvailability(true, _major[0], _minor[0], _ctp[0]); + } + } + return _ctx; + } + + private final void mapGLVersions(AbstractGraphicsDevice device) { + synchronized (GLContext.deviceVersionAvailable) { + createContextARBMapVersionsAvailable(4, false /* core */); // GL4 + createContextARBMapVersionsAvailable(4, true /* compat */); // GL4bc + createContextARBMapVersionsAvailable(3, false /* core */); // GL3 + createContextARBMapVersionsAvailable(3, true /* compat */); // GL3bc + createContextARBMapVersionsAvailable(2, true /* compat */); // GL2 + GLContext.setAvailableGLVersionsSet(device); + } + } + + private final void createContextARBMapVersionsAvailable(int reqMajor, boolean compat) + { + resetStates(); + + long _context; + int reqProfile = compat ? CTX_PROFILE_COMPAT : CTX_PROFILE_CORE ; + int ctp = CTX_IS_ARB_CREATED | CTX_PROFILE_CORE | CTX_OPTION_ANY; // default + if(compat) { + ctp &= ~CTX_PROFILE_CORE ; + ctp |= CTX_PROFILE_COMPAT ; + } + + // To ensure GL profile compatibility within the JOGL application + // we always try to map against the highest GL version, + // so the user can always cast to the highest available one. + int majorMax, minorMax; + int majorMin, minorMin; + int major[] = new int[1]; + int minor[] = new int[1]; + if( 4 == reqMajor ) { + majorMax=4; minorMax=GLContext.getMaxMinor(majorMax); + majorMin=4; minorMin=0; + } else if( 3 == reqMajor ) { + majorMax=3; minorMax=GLContext.getMaxMinor(majorMax); + majorMin=3; minorMin=1; + } else /* if( glp.isGL2() ) */ { + majorMax=3; minorMax=0; + majorMin=1; minorMin=1; // our minimum desktop OpenGL runtime requirements + } + _context = createContextARBVersions(0, true, ctp, + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + + if(0==_context && !compat) { + ctp &= ~CTX_PROFILE_COMPAT ; + ctp |= CTX_PROFILE_CORE ; + ctp &= ~CTX_OPTION_ANY ; + ctp |= CTX_OPTION_FORWARD ; + _context = createContextARBVersions(0, true, ctp, + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + if(0==_context) { + // Try a compatible one .. even though not requested .. last resort + ctp &= ~CTX_PROFILE_CORE ; + ctp |= CTX_PROFILE_COMPAT ; + ctp &= ~CTX_OPTION_FORWARD ; + ctp |= CTX_OPTION_ANY ; + _context = createContextARBVersions(0, true, ctp, + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + } + } + if(0!=_context) { + AbstractGraphicsDevice device = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); + GLContext.mapAvailableGLVersion(device, reqMajor, reqProfile, major[0], minor[0], ctp); + setGLFunctionAvailability(true, major[0], minor[0], ctp); + destroyContextARBImpl(_context); + resetStates(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! createContextARBMapVersionsAvailable HAVE: "+ + GLContext.getAvailableGLVersionAsString(device, reqMajor, reqProfile)); + } + } else if (DEBUG) { + System.err.println(getThreadName() + ": !!! createContextARBMapVersionsAvailable NOPE: "+reqMajor+"."+reqProfile); + } + } + + private final long createContextARBVersions(long share, boolean direct, int ctxOptionFlags, + int majorMax, int minorMax, + int majorMin, int minorMin, + int major[], int minor[]) { + major[0]=majorMax; + minor[0]=minorMax; + long _context=0; + + while ( 0==_context && + GLContext.isValidGLVersion(major[0], minor[0]) && + ( major[0]>majorMin || major[0]==majorMin && minor[0] >=minorMin ) ) { + + if (DEBUG) { + System.err.println(getThreadName() + ": createContextARBVersions: share "+share+", direct "+direct+", version "+major[0]+"."+minor[0]); + } + _context = createContextARBImpl(share, direct, ctxOptionFlags, major[0], minor[0]); + + if(0==_context) { + if(!GLContext.decrementGLVersion(major, minor)) break; + } + } + return _context; + } + + //---------------------------------------------------------------------- + // Managing the actual OpenGL version, usually figured at creation time. + // As a last resort, the GL_VERSION string may be used .. + // + + /** + * If major > 0 || minor > 0 : Use passed values, determined at creation time + * If major==0 && minor == 0 : Use GL_VERSION + * Otherwise .. don't touch .. + */ + private final void setContextVersion(int major, int minor, int ctp) { + if (0==ctp) { + throw new GLException("Invalid GL Version "+major+"."+minor+", ctp "+toHexString(ctp)); + } + if(major>0 || minor>0) { + if (!GLContext.isValidGLVersion(major, minor)) { + GLException e = new GLException("Invalid GL Version "+major+"."+minor+", ctp "+toHexString(ctp)); + throw e; + } + ctxMajorVersion = major; + ctxMinorVersion = minor; + ctxOptions = ctp; + ctxVersionString = getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, getGL().glGetString(GL.GL_VERSION)); + return; + } + + if(major==0 && minor==0) { + String versionStr = getGL().glGetString(GL.GL_VERSION); + if(null==versionStr) { + throw new GLException("GL_VERSION is NULL: "+this); + } + ctxOptions = ctp; + + // Set version + GLVersionNumber version = new GLVersionNumber(versionStr); + if (version.isValid()) { + ctxMajorVersion = version.getMajor(); + ctxMinorVersion = version.getMinor(); + // We cannot promote a non ARB context to >= 3.1, + // reduce it to 3.0 then. + if ( ( ctxMajorVersion>3 || ctxMajorVersion==3 && ctxMinorVersion>=1 ) + && 0 == (ctxOptions & CTX_IS_ARB_CREATED) ) { + ctxMajorVersion = 3; + ctxMinorVersion = 0; + } + ctxVersionString = getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, versionStr); + return; + } + } + } + + //---------------------------------------------------------------------- + // Helpers for various context implementations + // + + private Object createInstance(GLProfile glp, String suffix, Class[] cstrArgTypes, Object[] cstrArgs) { + return ReflectionUtil.createInstance(glp.getGLImplBaseClassName()+suffix, cstrArgTypes, cstrArgs, getClass().getClassLoader()); + } + + private boolean verifyInstance(GLProfile glp, String suffix, Object instance) { + return ReflectionUtil.instanceOf(instance, glp.getGLImplBaseClassName()+suffix); + } + + /** Create the GL for this context. */ + protected GL createGL(GLProfile glp) { + GL gl = (GL) createInstance(glp, "Impl", new Class[] { GLProfile.class, GLContextImpl.class }, new Object[] { glp, this } ); + + /* FIXME: refactor dependence on Java 2D / JOGL bridge + if (tracker != null) { + gl.setObjectTracker(tracker); + } + */ + return gl; + } + + public final ProcAddressTable getGLProcAddressTable() { + return glProcAddressTable; + } + + /** + * Shall return the platform extension ProcAddressTable, + * ie for GLXExt, EGLExt, .. + */ + public abstract ProcAddressTable getPlatformExtProcAddressTable(); + + /** + * Pbuffer support; given that this is a GLContext associated with a + * pbuffer, binds this pbuffer to its texture target. + */ + public abstract void bindPbufferToTexture(); + + /** + * Pbuffer support; given that this is a GLContext associated with a + * pbuffer, releases this pbuffer from its texture target. + */ + public abstract void releasePbufferFromTexture(); + + public abstract ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3); + + public final void setSwapInterval(final int interval) { + GLContext current = getCurrent(); + if (current != this) { + throw new GLException("This context is not current. Current context: "+current+ + ", this context "+this); + } + setSwapIntervalImpl(interval); + } + protected void setSwapIntervalImpl(final int interval) { /** nop per default .. **/ } + protected int currentSwapInterval = -1; // default: not set yet .. + public int getSwapInterval() { + return currentSwapInterval; + } + + /** Maps the given "platform-independent" function name to a real function + name. Currently this is only used to map "glAllocateMemoryNV" and + associated routines to wglAllocateMemoryNV / glXAllocateMemoryNV. */ + protected String mapToRealGLFunctionName(String glFunctionName) { + Map/*<String, String>*/ map = getFunctionNameMap(); + String lookup = ( null != map ) ? (String) map.get(glFunctionName) : null; + if (lookup != null) { + return lookup; + } + return glFunctionName; + } + protected abstract Map/*<String, String>*/ getFunctionNameMap() ; + + /** Maps the given "platform-independent" extension name to a real + function name. Currently this is only used to map + "GL_ARB_pbuffer" to "WGL_ARB_pbuffer/GLX_SGIX_pbuffer" and + "GL_ARB_pixel_format" to "WGL_ARB_pixel_format/n.a." + */ + protected String mapToRealGLExtensionName(String glExtensionName) { + Map/*<String, String>*/ map = getExtensionNameMap(); + String lookup = ( null != map ) ? (String) map.get(glExtensionName) : null; + if (lookup != null) { + return lookup; + } + return glExtensionName; + } + protected abstract Map/*<String, String>*/ getExtensionNameMap() ; + + /** Helper routine which resets a ProcAddressTable generated by the + GLEmitter by looking up anew all of its function pointers. */ + protected void resetProcAddressTable(ProcAddressTable table) { + table.reset(getDrawableImpl().getGLDynamicLookupHelper() ); + } + + /** + * Sets the OpenGL implementation class and + * the cache of which GL functions are available for calling through this + * context. See {@link #isFunctionAvailable(String)} for more information on + * the definition of "available". + * <br> + * All ProcaddressTables are being determined, the GL version is being set + * and the extension cache is determined as well. + * + * @param force force the setting, even if is already being set. + * This might be useful if you change the OpenGL implementation. + * @param major OpenGL major version + * @param minor OpenGL minor version + * @param ctxProfileBits OpenGL context profile and option bits, see {@link javax.media.opengl.GLContext#CTX_OPTION_ANY} + * + * @see #setContextVersion + * @see javax.media.opengl.GLContext#CTX_OPTION_ANY + * @see javax.media.opengl.GLContext#CTX_PROFILE_COMPAT + */ + protected final void setGLFunctionAvailability(boolean force, int major, int minor, int ctxProfileBits) { + if(null!=this.gl && null!=glProcAddressTable && !force) { + return; // already done and not forced + } + if(null==this.gl || force) { + setGL(createGL(getGLDrawable().getGLProfile())); + } + + updateGLXProcAddressTable(); + + AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); + final int ctxImplBits = drawable.getChosenGLCapabilities().getHardwareAccelerated() ? GLContext.CTX_IMPL_ACCEL_HARD : GLContext.CTX_IMPL_ACCEL_SOFT; + contextFQN = getContextFQN(adevice, major, minor, ctxProfileBits, ctxImplBits); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Context FQN: "+contextFQN); + } + + // + // UpdateGLProcAddressTable functionality + // + if(null==this.gl) { + throw new GLException("setGLFunctionAvailability not called yet"); + } + + ProcAddressTable table = null; + synchronized(mappedContextTypeObjectLock) { + table = (ProcAddressTable) mappedGLProcAddress.get( contextFQN ); + if(null != table && !verifyInstance(gl.getGLProfile(), "ProcAddressTable", table)) { + throw new InternalError("GLContext GL ProcAddressTable mapped key("+contextFQN+") -> "+ + table.getClass().getName()+" not matching "+gl.getGLProfile().getGLImplBaseClassName()); + } + } + if(null != table) { + glProcAddressTable = table; + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext GL ProcAddressTable reusing key("+contextFQN+") -> "+table.hashCode()); + } + } else { + if (glProcAddressTable == null) { + glProcAddressTable = (ProcAddressTable) createInstance(gl.getGLProfile(), "ProcAddressTable", + new Class[] { FunctionAddressResolver.class } , + new Object[] { new GLProcAddressResolver() } ); + } + resetProcAddressTable(getGLProcAddressTable()); + synchronized(mappedContextTypeObjectLock) { + mappedGLProcAddress.put(contextFQN, getGLProcAddressTable()); + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext GL ProcAddressTable mapping key("+contextFQN+") -> "+getGLProcAddressTable().hashCode()); + } + } + } + + // + // Set GL Version + // + setContextVersion(major, minor, ctxProfileBits); + + // + // Update ExtensionAvailabilityCache + // + ExtensionAvailabilityCache eCache; + synchronized(mappedContextTypeObjectLock) { + eCache = (ExtensionAvailabilityCache) mappedExtensionAvailabilityCache.get( contextFQN ); + } + if(null != eCache) { + extensionAvailability = eCache; + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext GL ExtensionAvailabilityCache reusing key("+contextFQN+") -> "+eCache.hashCode()); + } + } else { + if(null==extensionAvailability) { + extensionAvailability = new ExtensionAvailabilityCache(this); + } + extensionAvailability.reset(); + synchronized(mappedContextTypeObjectLock) { + mappedExtensionAvailabilityCache.put(contextFQN, extensionAvailability); + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext GL ExtensionAvailabilityCache mapping key("+contextFQN+") -> "+extensionAvailability.hashCode()); + } + } + } + + hasNativeES2Methods = isGLES2() || isExtensionAvailable("GL_ARB_ES2_compatibility") ; + } + + /** + * Updates the platform's 'GLX' function cache + */ + protected abstract void updateGLXProcAddressTable(); + + protected boolean hasNativeES2Methods = false; + + public final boolean hasNativeES2Methods() { return hasNativeES2Methods; } + + /** + * Returns true if the specified OpenGL core- or extension-function can be + * successfully called using this GL context given the current host (OpenGL + * <i>client</i>) and display (OpenGL <i>server</i>) configuration. + * + * See {@link GL#isFunctionAvailable(String)} for more details. + * + * @param glFunctionName the name of the OpenGL function (e.g., use + * "glPolygonOffsetEXT" or "glPolygonOffset" to check if the {@link + * javax.media.opengl.GL#glPolygonOffset(float,float)} is available). + */ + public boolean isFunctionAvailable(String glFunctionName) { + // Check GL 1st (cached) + ProcAddressTable pTable = getGLProcAddressTable(); // null if ctx not created once + if(null!=pTable) { + try { + if(0!=pTable.getAddressFor(glFunctionName)) { + return true; + } + } catch (Exception e) {} + } + + // Check platform extensions 2nd (cached) - had to be enabled once + pTable = getPlatformExtProcAddressTable(); // null if ctx not created once + if(null!=pTable) { + try { + if(0!=pTable.getAddressFor(glFunctionName)) { + return true; + } + } catch (Exception e) {} + } + + // dynamic function lookup at last incl name aliasing (not cached) + DynamicLookupHelper dynLookup = getDrawableImpl().getGLDynamicLookupHelper(); + String tmpBase = GLExtensionNames.normalizeVEN(GLExtensionNames.normalizeARB(glFunctionName, true), true); + long addr = 0; + int variants = GLExtensionNames.getFuncNamePermutationNumber(tmpBase); + for(int i = 0; 0==addr && i < variants; i++) { + String tmp = GLExtensionNames.getFuncNamePermutation(tmpBase, i); + try { + addr = dynLookup.dynamicLookupFunction(tmp); + } catch (Exception e) { } + } + if(0!=addr) { + return true; + } + return false; + } + + /** + * Returns true if the specified OpenGL extension can be + * successfully called using this GL context given the current host (OpenGL + * <i>client</i>) and display (OpenGL <i>server</i>) configuration. + * + * See {@link GL#isExtensionAvailable(String)} for more details. + * + * @param glExtensionName the name of the OpenGL extension (e.g., + * "GL_VERTEX_PROGRAM_ARB"). + */ + public boolean isExtensionAvailable(String glExtensionName) { + if(null!=extensionAvailability) { + return extensionAvailability.isExtensionAvailable(mapToRealGLExtensionName(glExtensionName)); + } + return false; + } + + public String getPlatformExtensionsString() { + if(null!=extensionAvailability) { + return extensionAvailability.getPlatformExtensionsString(); + } + return null; + } + + public String getGLExtensionsString() { + if(null!=extensionAvailability) { + return extensionAvailability.getGLExtensionsString(); + } + return null; + } + + public final boolean isExtensionCacheInitialized() { + if(null!=extensionAvailability) { + return extensionAvailability.isInitialized(); + } + return false; + } + + protected static String getContextFQN(AbstractGraphicsDevice device, int major, int minor, int ctxProfileBits, int ctxImplBits) { + return device.getUniqueID() + "-" + toHexString(compose8bit(major, minor, ctxProfileBits, ctxImplBits)); + } + + protected String getContextFQN() { + return contextFQN; + } + + /** Indicates which floating-point pbuffer implementation is in + use. Returns one of GLPbuffer.APPLE_FLOAT, GLPbuffer.ATI_FLOAT, + or GLPbuffer.NV_FLOAT. */ + public int getFloatingPointMode() throws GLException { + throw new GLException("Not supported on non-pbuffer contexts"); + } + + /** On some platforms the mismatch between OpenGL's coordinate + system (origin at bottom left) and the window system's + coordinate system (origin at top left) necessitates a vertical + flip of pixels read from offscreen contexts. */ + public abstract boolean offscreenImageNeedsVerticalFlip(); + + /** Only called for offscreen contexts; needed by glReadPixels */ + public abstract int getOffscreenContextPixelDataType(); + + + //---------------------------------------------------------------------- + // Helpers for buffer object optimizations + + public void setBufferSizeTracker(GLBufferSizeTracker bufferSizeTracker) { + this.bufferSizeTracker = bufferSizeTracker; + } + + public GLBufferSizeTracker getBufferSizeTracker() { + return bufferSizeTracker; + } + + public GLBufferStateTracker getBufferStateTracker() { + return bufferStateTracker; + } + + public GLStateTracker getGLStateTracker() { + return glStateTracker; + } + + //--------------------------------------------------------------------------- + // Helpers for context optimization where the last context is left + // current on the OpenGL worker thread + // + + public boolean hasWaiters() { + return lock.hasWaiters(); + } + +} diff --git a/src/jogl/classes/jogamp/opengl/GLContextLock.java b/src/jogl/classes/jogamp/opengl/GLContextLock.java new file mode 100644 index 000000000..f725508d8 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLContextLock.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import javax.media.opengl.*; + +/** Implements the makeCurrent / release locking behavior of the + GLContext class. When "fail fast mode" is enabled, attempts to + lock the same GLContextLock on more than one thread cause + GLException to be raised. This lock is not recursive. Attempts to + lock it more than once on a given thread will cause GLException to + be raised. */ + +public class GLContextLock { + protected static final boolean DEBUG = GLContextImpl.DEBUG; + + static class SyncData { + boolean failFastMode = true; + Thread owner = null; + int waiters = 0; + Exception lockedStack = null; // only enabled if DEBUG + } + private SyncData sdata = new SyncData(); // synchronized (flow/mem) mutable access + + /** Locks this GLContextLock on the current thread. If fail fast + mode is enabled and the GLContextLock is already owned by + another thread, throws GLException. */ + public final void lock() throws GLException { + synchronized(sdata) { + Thread current = Thread.currentThread(); + if (sdata.owner == null) { + sdata.owner = current; + if(DEBUG) { + sdata.lockedStack = new Exception("Error: Previously made current (1) by "+sdata.owner+", lock: "+this); + } + } else if (sdata.owner != current) { + while (sdata.owner != null) { + if (sdata.failFastMode) { + if(null!=sdata.lockedStack) { + sdata.lockedStack.printStackTrace(); + } + throw new GLException("Error: Attempt to make context current on thread " + current + + " which is already current on thread " + sdata.owner); + } else { + try { + ++sdata.waiters; + sdata.wait(); + } catch (InterruptedException e) { + throw new GLException(e); + } finally { + --sdata.waiters; + } + } + } + sdata.owner = current; + if(DEBUG) { + sdata.lockedStack = new Exception("Previously made current (2) by "+sdata.owner+", lock: "+this); + } + } else { + throw new GLException("Attempt to make the same context current twice on thread " + current); + } + } + } + + /** Unlocks this GLContextLock. */ + public final void unlock() throws GLException { + synchronized (sdata) { + Thread current = Thread.currentThread(); + if (sdata.owner == current) { + sdata.owner = null; + sdata.lockedStack = null; + // Assuming notify() implementation weaks up the longest waiting thread, to avoid starvation. + // Otherwise we would need to have a Thread queue implemented, using sleep(timeout) and interrupt. + sdata.notify(); + } else { + if (sdata.owner != null) { + throw new GLException("Attempt by thread " + current + + " to release context owned by thread " + sdata.owner); + } else { + throw new GLException("Attempt by thread " + current + + " to release unowned context"); + } + } + } + } + + /** Indicates whether this lock is held by the current thread. */ + public final boolean isHeld() { + synchronized(sdata) { + return (Thread.currentThread() == sdata.owner); + } + } + + public final void setFailFastMode(boolean onOrOff) { + synchronized(sdata) { + sdata.failFastMode = onOrOff; + } + } + + public final boolean getFailFastMode() { + synchronized(sdata) { + return sdata.failFastMode; + } + } + + public final boolean hasWaiters() { + synchronized(sdata) { + return (0 != sdata.waiters); + } + } + + /** holding the owners stack trace when lock is acquired and DEBUG is true */ + public final Exception getLockedStack() { + synchronized(sdata) { + return sdata.lockedStack; + } + } + +} diff --git a/src/jogl/classes/jogamp/opengl/GLContextShareSet.java b/src/jogl/classes/jogamp/opengl/GLContextShareSet.java new file mode 100644 index 000000000..bbb46148c --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLContextShareSet.java @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +// FIXME: refactor Java SE dependencies +// import java.awt.GraphicsConfiguration; +// import java.awt.GraphicsDevice; +// import java.awt.GraphicsEnvironment; +import java.lang.ref.*; +import java.util.*; +import javax.media.opengl.*; + +/** Provides a mechanism by which OpenGL contexts can share textures + and display lists in the face of multithreading and asynchronous + context creation as is inherent in the AWT and Swing. */ + +public class GLContextShareSet { + // FIXME: refactor Java SE dependencies + // private static boolean forceTracking = Debug.isPropertyDefined("jogl.glcontext.forcetracking"); + private static final boolean DEBUG = Debug.debug("GLContext"); + + // This class is implemented with a WeakHashMap that goes from the + // contexts as keys to a complex data structure as value that tracks + // context creation and deletion. + + private static Map/*<GLContext, ShareSet>*/ shareMap = new WeakHashMap(); + private static Object dummyValue = new Object(); + + private static class ShareSet { + private Map allShares = new WeakHashMap(); + private Map createdShares = new WeakHashMap(); + private Map destroyedShares = new WeakHashMap(); + + public void add(GLContext ctx) { + if (allShares.put(ctx, dummyValue) == null) { + // FIXME: downcast to GLContextImpl undesirable + if (((GLContextImpl) ctx).isCreated()) { + createdShares.put(ctx, dummyValue); + } else { + destroyedShares.put(ctx, dummyValue); + } + } + } + + public GLContext getCreatedShare(GLContext ignore) { + for (Iterator iter = createdShares.keySet().iterator(); iter.hasNext(); ) { + GLContext ctx = (GLContext) iter.next(); + if (ctx != ignore) { + return ctx; + } + } + return null; + } + + public void contextCreated(GLContext ctx) { + Object res = destroyedShares.remove(ctx); + assert res != null : "State of ShareSet corrupted; thought context " + + ctx + " should have been in destroyed set but wasn't"; + res = createdShares.put(ctx, dummyValue); + assert res == null : "State of ShareSet corrupted; thought context " + + ctx + " shouldn't have been in created set but was"; + } + + public void contextDestroyed(GLContext ctx) { + Object res = createdShares.remove(ctx); + assert res != null : "State of ShareSet corrupted; thought context " + + ctx + " should have been in created set but wasn't"; + res = destroyedShares.put(ctx, dummyValue); + assert res == null : "State of ShareSet corrupted; thought context " + + ctx + " shouldn't have been in destroyed set but was"; + } + } + + /** Indicate that contexts <code>share1</code> and + <code>share2</code> will share textures and display lists. Both + must be non-null. */ + public static synchronized void registerSharing(GLContext share1, GLContext share2) { + if (share1 == null || share2 == null) { + throw new IllegalArgumentException("Both share1 and share2 must be non-null"); + } + ShareSet share = entryFor(share1); + if (share == null) { + share = entryFor(share2); + } + if (share == null) { + share = new ShareSet(); + } + share.add(share1); + share.add(share2); + addEntry(share1, share); + addEntry(share2, share); + } + + public static synchronized GLContext getShareContext(GLContext contextToCreate) { + ShareSet share = entryFor(contextToCreate); + if (share == null) { + return null; + } + return share.getCreatedShare(contextToCreate); + } + + public static synchronized void contextCreated(GLContext context) { + ShareSet share = entryFor(context); + if (share != null) { + share.contextCreated(context); + } + } + + public static synchronized void contextDestroyed(GLContext context) { + ShareSet share = entryFor(context); + if (share != null) { + share.contextDestroyed(context); + } + } + + /** In order to avoid glGet calls for buffer object checks related + to glVertexPointer, etc. calls as well as glMapBuffer calls, we + need to share the same GLBufferSizeTracker object between + contexts sharing textures and display lists. For now we keep + this mechanism orthogonal to the GLObjectTracker to hopefully + keep things easier to understand. (The GLObjectTracker is + currently only needed in a fairly esoteric case, when the + Java2D/JOGL bridge is active, but the GLBufferSizeTracker + mechanism is now always required.) */ + public static void registerForBufferObjectSharing(GLContext olderContextOrNull, GLContext newContext) { + // FIXME: downcasts to GLContextImpl undesirable + GLContextImpl older = (GLContextImpl) olderContextOrNull; + GLContextImpl newer = (GLContextImpl) newContext; + GLBufferSizeTracker tracker = null; + if (older != null) { + tracker = older.getBufferSizeTracker(); + assert (tracker != null) + : "registerForBufferObjectSharing was not called properly for the older context, or has a bug in it"; + } + if (tracker == null) { + tracker = new GLBufferSizeTracker(); + } + newer.setBufferSizeTracker(tracker); + } + + // FIXME: refactor Java SE dependencies + // /** Indicates that the two supplied contexts (which must be able to + // share textures and display lists) should be in the same + // namespace for tracking of server-side object creation and + // deletion. Because the sharing necessary behind the scenes is + // different than that requested at the user level, the two notions + // are different. This must be called immediately after the + // creation of the new context (which is the second argument) + // before any server-side OpenGL objects have been created in that + // context. */ + // public static void registerForObjectTracking(GLContext olderContextOrNull, + // GLContext newContext, + // GLContext realShareContext) { + // if (isObjectTrackingEnabled() || isObjectTrackingDebuggingEnabled()) { + // GLContextImpl impl1 = null; + // GLContextImpl impl2 = null; + // GLObjectTracker tracker = null; + // + // synchronized (GLContextShareSet.class) { + // if (olderContextOrNull != null && + // newContext != null) { + // if (entryFor(olderContextOrNull) != entryFor(newContext)) { + // throw new IllegalArgumentException("old and new contexts must be able to share textures and display lists"); + // } + // } + // + // // FIXME: downcast to GLContextImpl undesirable + // impl1 = (GLContextImpl) olderContextOrNull; + // impl2 = (GLContextImpl) newContext; + // + // GLObjectTracker deletedObjectTracker = null; + // GLContextImpl shareImpl = (GLContextImpl) realShareContext; + // // Before we zap the "user-level" object trackers, make sure + // // that all contexts in the share set share the destroyed object + // // tracker + // if (shareImpl != null) { + // deletedObjectTracker = shareImpl.getDeletedObjectTracker(); + // } + // if (deletedObjectTracker == null) { + // // Must create one and possibly set it up in the older context + // deletedObjectTracker = new GLObjectTracker(); + // if (DEBUG) { + // System.err.println("Created deletedObjectTracker " + deletedObjectTracker + " because " + + // ((shareImpl == null) ? "shareImpl was null" : "shareImpl's (" + shareImpl + ") deletedObjectTracker was null")); + // } + // + // if (shareImpl != null) { + // // FIXME: think should really assert in this case + // shareImpl.setDeletedObjectTracker(deletedObjectTracker); + // if (DEBUG) { + // System.err.println("Set deletedObjectTracker " + deletedObjectTracker + " in shareImpl context " + shareImpl); + // } + // } + // } + // impl2.setDeletedObjectTracker(deletedObjectTracker); + // if (DEBUG) { + // System.err.println("Set deletedObjectTracker " + deletedObjectTracker + " in impl2 context " + impl2); + // } + // } + // + // // Must not hold lock around this operation + // // Don't share object trackers with the primordial share context from Java2D + // if (Java2D.isOGLPipelineActive()) { + // // FIXME: probably need to do something different here + // // Need to be able to figure out the GraphicsDevice for the + // // older context if it's on-screen + // GraphicsDevice device = GraphicsEnvironment. + // getLocalGraphicsEnvironment(). + // getDefaultScreenDevice(); + // GLContext j2dShareContext = Java2D.getShareContext(device); + // if (impl1 != null && impl1 == j2dShareContext) { + // impl1 = null; + // } + // } + // + // synchronized (GLContextShareSet.class) { + // if (impl1 != null) { + // tracker = impl1.getObjectTracker(); + // assert (tracker != null) + // : "registerForObjectTracking was not called properly for the older context"; + // } + // if (tracker == null) { + // tracker = new GLObjectTracker(); + // } + // // Note that we don't assert that the tracker is non-null for + // // impl2 because the way we use this functionality we actually + // // overwrite the initially-set object tracker in the new context + // impl2.setObjectTracker(tracker); + // } + // } + // } + + //---------------------------------------------------------------------- + // Internals only below this point + + + private static ShareSet entryFor(GLContext context) { + return (ShareSet) shareMap.get(context); + } + + private static void addEntry(GLContext context, ShareSet share) { + if (shareMap.get(context) == null) { + shareMap.put(context, share); + } + } + + // FIXME: refactor Java SE dependencies + // private static boolean isObjectTrackingEnabled() { + // return ((Java2D.isOGLPipelineActive() && Java2D.isFBOEnabled()) || + // isObjectTrackingDebuggingEnabled()); + // } + // + // private static boolean isObjectTrackingDebuggingEnabled() { + // return forceTracking; + // } +} diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java new file mode 100644 index 000000000..e04ced6fa --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java @@ -0,0 +1,467 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import java.nio.*; +import javax.media.nativewindow.*; +import javax.media.opengl.*; + +/** Extends GLDrawableFactory with a few methods for handling + typically software-accelerated offscreen rendering (Device + Independent Bitmaps on Windows, pixmaps on X11). Direct access to + these GLDrawables is not supplied directly to end users, though + they may be instantiated by the GLJPanel implementation. */ +public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { + protected static final boolean DEBUG = GLDrawableImpl.DEBUG; + + protected GLDrawableFactoryImpl() { + super(); + } + + /** + * Returns the shared device mapped to the <code>device</code> {@link AbstractGraphicsDevice#getConnection()}, + * either a preexisting or newly created, or <code>null</code> if creation failed or not supported.<br> + * Creation of the shared context is tried only once. + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared device to be used, may be <code>null</code> for the platform's default device. + */ + protected final AbstractGraphicsDevice getOrCreateSharedDevice(AbstractGraphicsDevice device) { + if(null==device) { + device = getDefaultDevice(); + if(null==device) { + throw new InternalError("no default device"); + } + if (GLProfile.DEBUG) { + System.err.println("Info: GLDrawableFactoryImpl.getOrCreateSharedContext: using default device : "+device); + } + } else if( !getIsDeviceCompatible(device) ) { + if (GLProfile.DEBUG) { + System.err.println("Info: GLDrawableFactoryImpl.getOrCreateSharedContext: device not compatible : "+device); + } + return null; + } + return getOrCreateSharedDeviceImpl(device); + } + protected abstract AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device); + + /** + * Returns the GLDynamicLookupHelper + * @param profile if EGL/ES, profile <code>1</code> refers to ES1 and <code>2</code> to ES2, + * otherwise the profile is ignored. + */ + public abstract GLDynamicLookupHelper getGLDynamicLookupHelper(int profile); + + //--------------------------------------------------------------------------- + // Dispatching GLDrawable construction in respect to the NativeSurface Capabilities + // + public GLDrawable createGLDrawable(NativeSurface target) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + GLDrawable result = null; + adevice.lock(); + try { + if(caps.isOnscreen()) { + if(DEBUG) { + System.err.println("GLDrawableFactoryImpl.createGLDrawable -> OnscreenDrawable: "+target); + } + result = createOnscreenDrawableImpl(target); + } else { + if( ! ( target instanceof SurfaceChangeable ) ) { + throw new IllegalArgumentException("Passed NativeSurface must implement SurfaceChangeable for offscreen: "+target); + } + if(DEBUG) { + System.err.println("GLDrawableFactoryImpl.createGLDrawable -> OffScreenDrawable (PBuffer: "+caps.isPBuffer()+"): "+target); + } + result = createOffscreenDrawableImpl(target); + } + } finally { + adevice.unlock(); + } + if(DEBUG) { + System.err.println("GLDrawableFactoryImpl.createGLDrawable: "+result); + } + return result; + } + + //--------------------------------------------------------------------------- + // + // Onscreen GLDrawable construction + // + + protected abstract GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target); + + //--------------------------------------------------------------------------- + // + // PBuffer GLDrawable construction + // + + public abstract boolean canCreateGLPbuffer(AbstractGraphicsDevice device); + + public GLPbuffer createGLPbuffer(AbstractGraphicsDevice deviceReq, + GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser, + int width, + int height, + GLContext shareWith) { + if(height<=0 || height<=0) { + throw new GLException("Width and height of pbuffer must be positive (were (" + + width + ", " + height + "))"); + } + + AbstractGraphicsDevice device = getOrCreateSharedDevice(deviceReq); + if(null == device) { + throw new GLException("No shared device for requested: "+deviceReq); + } + + if (!canCreateGLPbuffer(device)) { + throw new GLException("Pbuffer support not available with device: "+device); + } + + GLCapabilitiesImmutable capsChosen = GLGraphicsConfigurationUtil.fixGLPBufferGLCapabilities(capsRequested); + GLDrawableImpl drawable = null; + device.lock(); + try { + drawable = (GLDrawableImpl) createGLDrawable( createOffscreenSurfaceImpl(device, capsChosen, capsRequested, chooser, width, height) ); + } finally { + device.unlock(); + } + + if(null==drawable) { + throw new GLException("Could not create Pbuffer drawable for: "+device+", "+capsChosen+", "+width+"x"+height); + } + return new GLPbufferImpl( drawable, shareWith); + } + + + //--------------------------------------------------------------------------- + // + // Offscreen GLDrawable construction + // + + protected abstract GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) ; + + public GLDrawable createOffscreenDrawable(AbstractGraphicsDevice deviceReq, + GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser, + int width, + int height) { + if(width<=0 || height<=0) { + throw new GLException("Width and height of pbuffer must be positive (were (" + + width + ", " + height + "))"); + } + AbstractGraphicsDevice device = getOrCreateSharedDevice(deviceReq); + if(null == device) { + throw new GLException("No shared device for requested: "+deviceReq); + } + GLCapabilitiesImmutable capsChosen = GLGraphicsConfigurationUtil.fixOffScreenGLCapabilities(capsRequested, canCreateGLPbuffer(deviceReq)); + + device.lock(); + try { + return createGLDrawable( createOffscreenSurfaceImpl(device, capsChosen, capsRequested, chooser, width, height) ); + } finally { + device.unlock(); + } + } + + public NativeSurface createOffscreenSurface(AbstractGraphicsDevice deviceReq, + GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser, + int width, int height) { + AbstractGraphicsDevice device = getOrCreateSharedDevice(deviceReq); + if(null == device) { + throw new GLException("No shared device for requested: "+deviceReq); + } + GLCapabilitiesImmutable capsChosen = GLGraphicsConfigurationUtil.fixOffScreenGLCapabilities(capsRequested, canCreateGLPbuffer(deviceReq)); + + device.lock(); + try { + return createOffscreenSurfaceImpl(device, capsChosen, capsRequested, chooser, width, height); + } finally { + device.unlock(); + } + } + + /** + * creates an offscreen NativeSurface, which must implement SurfaceChangeable as well, + * so the windowing system related implementation is able to set the surface handle. + */ + protected abstract NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, + GLCapabilitiesImmutable capabilities, GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser, + int width, int height); + + public ProxySurface createProxySurface(AbstractGraphicsDevice device, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser) { + if(null == device) { + throw new GLException("No shared device for requested: "+device); + } + + device.lock(); + try { + return createProxySurfaceImpl(device, windowHandle, capsRequested, chooser); + } finally { + device.unlock(); + } + } + + protected abstract ProxySurface createProxySurfaceImpl(AbstractGraphicsDevice device, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser); + + //--------------------------------------------------------------------------- + // + // External GLDrawable construction + // + + protected abstract GLContext createExternalGLContextImpl(); + + public GLContext createExternalGLContext() { + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + return createExternalGLContextImpl(); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } + } + + protected abstract GLDrawable createExternalGLDrawableImpl(); + + public GLDrawable createExternalGLDrawable() { + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + return createExternalGLDrawableImpl(); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } + } + + + //--------------------------------------------------------------------------- + // + // GLDrawableFactoryImpl details + // + + protected void maybeDoSingleThreadedWorkaround(Runnable action) { + if (Threading.isSingleThreaded() && + !Threading.isOpenGLThread()) { + Threading.invokeOnOpenGLThread(action); + } else { + action.run(); + } + } + + /** + * Returns the sole GLDrawableFactoryImpl instance. + * + * @param glProfile GLProfile to determine the factory type, ie EGLDrawableFactory, + * or one of the native GLDrawableFactory's, ie X11/GLX, Windows/WGL or MacOSX/CGL. + */ + public static GLDrawableFactoryImpl getFactoryImpl(GLProfile glp) { + return (GLDrawableFactoryImpl) getFactory(glp); + } + + //--------------------------------------------------------------------------- + // Support for Java2D/JOGL bridge on Mac OS X; the external + // GLDrawable mechanism in the public API is sufficient to + // implement this functionality on all other platforms + // + + public abstract boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device); + + public abstract GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) + throws GLException; + + //---------------------------------------------------------------------- + // Gamma adjustment support + // Thanks to the LWJGL team for illustrating how to make these + // adjustments on various OSs. + + /* + * Portions Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE COPYRIGHT OWNER 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. + */ + + /** + * Sets the gamma, brightness, and contrast of the current main + * display. Returns true if the settings were changed, false if + * not. If this method returns true, the display settings will + * automatically be reset upon JVM exit (assuming the JVM does not + * crash); if the user wishes to change the display settings back to + * normal ahead of time, use resetDisplayGamma(). Throws + * IllegalArgumentException if any of the parameters were + * out-of-bounds. + * + * @param gamma The gamma value, typically > 1.0 (default value is + * 1.0) + * @param brightness The brightness value between -1.0 and 1.0, + * inclusive (default value is 0) + * @param contrast The contrast, greater than 0.0 (default value is 1) + * @throws IllegalArgumentException if any of the parameters were + * out-of-bounds + */ + public boolean setDisplayGamma(float gamma, float brightness, float contrast) throws IllegalArgumentException { + if ((brightness < -1.0f) || (brightness > 1.0f)) { + throw new IllegalArgumentException("Brightness must be between -1.0 and 1.0"); + } + if (contrast < 0) { + throw new IllegalArgumentException("Contrast must be greater than 0.0"); + } + // FIXME: ensure gamma is > 1.0? Are smaller / negative values legal? + int rampLength = getGammaRampLength(); + if (rampLength == 0) { + return false; + } + float[] gammaRamp = new float[rampLength]; + for (int i = 0; i < rampLength; i++) { + float intensity = (float) i / (float) (rampLength - 1); + // apply gamma + float rampEntry = (float) java.lang.Math.pow(intensity, gamma); + // apply brightness + rampEntry += brightness; + // apply contrast + rampEntry = (rampEntry - 0.5f) * contrast + 0.5f; + // Clamp entry to [0, 1] + if (rampEntry > 1.0f) + rampEntry = 1.0f; + else if (rampEntry < 0.0f) + rampEntry = 0.0f; + gammaRamp[i] = rampEntry; + } + registerGammaShutdownHook(); + return setGammaRamp(gammaRamp); + } + + public synchronized void resetDisplayGamma() { + if (gammaShutdownHook == null) { + throw new IllegalArgumentException("Should not call this unless setDisplayGamma called first"); + } + resetGammaRamp(originalGammaRamp); + unregisterGammaShutdownHook(); + } + + //------------------------------------------------------ + // Gamma-related methods to be implemented by subclasses + // + + /** Returns the length of the computed gamma ramp for this OS and + hardware. Returns 0 if gamma changes are not supported. */ + protected int getGammaRampLength() { + return 0; + } + + /** Sets the gamma ramp for the main screen. Returns false if gamma + ramp changes were not supported. */ + protected boolean setGammaRamp(float[] ramp) { + return false; + } + + /** Gets the current gamma ramp. This is basically an opaque value + used only on some platforms to reset the gamma ramp to its + original settings. */ + protected Buffer getGammaRamp() { + return null; + } + + /** Resets the gamma ramp, potentially using the specified Buffer as + data to restore the original values. */ + protected void resetGammaRamp(Buffer originalGammaRamp) { + } + + // Shutdown hook mechanism for resetting gamma + private boolean gammaShutdownHookRegistered; + private Thread gammaShutdownHook; + private Buffer originalGammaRamp; + private synchronized void registerGammaShutdownHook() { + if (gammaShutdownHookRegistered) + return; + if (gammaShutdownHook == null) { + gammaShutdownHook = new Thread(new Runnable() { + public void run() { + synchronized (GLDrawableFactoryImpl.this) { + resetGammaRamp(originalGammaRamp); + } + } + }); + originalGammaRamp = getGammaRamp(); + } + Runtime.getRuntime().addShutdownHook(gammaShutdownHook); + gammaShutdownHookRegistered = true; + } + + private synchronized void unregisterGammaShutdownHook() { + if (!gammaShutdownHookRegistered) + return; + if (gammaShutdownHook == null) { + throw new InternalError("Error in gamma shutdown hook logic"); + } + Runtime.getRuntime().removeShutdownHook(gammaShutdownHook); + gammaShutdownHookRegistered = false; + // Leave the original gamma ramp data alone + } +} diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java new file mode 100644 index 000000000..d079a1bd1 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java @@ -0,0 +1,387 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import java.util.*; +import javax.media.opengl.*; + +/** Encapsulates the implementation of most of the GLAutoDrawable's + methods to be able to share it between GLCanvas and GLJPanel. */ + +public class GLDrawableHelper { + protected static final boolean DEBUG = GLDrawableImpl.DEBUG; + private static final boolean VERBOSE = Debug.verbose(); + private Object listenersLock = new Object(); + private List listeners; + private volatile boolean listenersIter; // avoid java.util.ConcurrentModificationException + private Set listenersToBeInit; + private boolean autoSwapBufferMode; + private Object glRunnablesLock = new Object(); + private ArrayList glRunnables; + private GLAnimatorControl animatorCtrl; + + public GLDrawableHelper() { + reset(); + } + + public final void reset() { + synchronized(listenersLock) { + listeners = new ArrayList(); + listenersIter = false; + listenersToBeInit = new HashSet(); + } + autoSwapBufferMode = true; + synchronized(glRunnablesLock) { + glRunnables = new ArrayList(); + } + animatorCtrl = null; + } + + @Override + public final String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("GLAnimatorControl: "+animatorCtrl+", "); + synchronized(listenersLock) { + sb.append("GLEventListeners num "+listeners.size()+" ["); + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + Object l = listeners.get(i); + sb.append(l); + sb.append("[init "); + sb.append( !listenersToBeInit.contains(l) ); + sb.append("], "); + } + listenersIter = false; + } + sb.append("]"); + return sb.toString(); + } + + public final void addGLEventListener(GLEventListener listener) { + addGLEventListener(-1, listener); + } + + public final void addGLEventListener(int index, GLEventListener listener) { + synchronized(listenersLock) { + if(0>index) { + index = listeners.size(); + } + // GLEventListener may be added after context is created, + // hence we earmark initialization for the next display call. + listenersToBeInit.add(listener); + if(!listenersIter) { + // fast path + listeners.add(index, listener); + } else { + // copy mode in case this is issued while iterating, eg via init, display, .. + List newListeners = (List) ((ArrayList) listeners).clone(); + newListeners.add(index, listener); + listeners = newListeners; + } + } + } + + public final void removeGLEventListener(GLEventListener listener) { + synchronized(listenersLock) { + if(!listenersIter) { + // fast path + listeners.remove(listener); + } else { + // copy mode in case this is issued while iterating, eg via init, display, .. + List newListeners = (List) ((ArrayList) listeners).clone(); + newListeners.remove(listener); + listeners = newListeners; + } + listenersToBeInit.remove(listener); + } + } + + /** + * Issues {@link javax.media.opengl.GLEventListener#dispose(javax.media.opengl.GLAutoDrawable)} + * to all listeners. + * @param drawable + */ + public final void dispose(GLAutoDrawable drawable) { + synchronized(listenersLock) { + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + GLEventListener listener = (GLEventListener) listeners.get(i) ; + listener.dispose(drawable); + } + listenersIter = false; + } + } + + private boolean init(GLEventListener l, GLAutoDrawable drawable, boolean sendReshape) { + if(listenersToBeInit.remove(l)) { + l.init(drawable); + if(sendReshape) { + reshape(l, drawable, 0, 0, drawable.getWidth(), drawable.getHeight(), true /* setViewport */); + } + return true; + } + return false; + } + + public final void init(GLAutoDrawable drawable) { + synchronized(listenersLock) { + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + GLEventListener listener = (GLEventListener) listeners.get(i) ; + + // If make current ctx, invoked by invokGL(..), results in a new ctx, init gets called. + // This may happen not just for initial setup, but for ctx recreation due to resource change (drawable/window), + // hence the must always be initialized unconditional. + listenersToBeInit.add(listener); + + if ( ! init( listener, drawable, false ) ) { + throw new GLException("GLEventListener "+listener+" already initialized: "+drawable); + } + } + listenersIter = false; + } + } + + public final void display(GLAutoDrawable drawable) { + synchronized(listenersLock) { + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + GLEventListener listener = (GLEventListener) listeners.get(i) ; + // GLEventListener may need to be init, + // in case this one is added after the realization of the GLAutoDrawable + init( listener, drawable, true ) ; + listener.display(drawable); + } + listenersIter = false; + } + execGLRunnables(drawable); + } + + private void reshape(GLEventListener listener, GLAutoDrawable drawable, + int x, int y, int width, int height, boolean setViewport) { + if(setViewport) { + drawable.getGL().glViewport(x, y, width, height); + } + listener.reshape(drawable, x, y, width, height); + } + + public final void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + synchronized(listenersLock) { + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + reshape((GLEventListener) listeners.get(i), drawable, x, y, width, height, 0==i); + } + listenersIter = false; + } + } + + private void execGLRunnables(GLAutoDrawable drawable) { + if(glRunnables.size()>0) { + // swap one-shot list asap + ArrayList _glRunnables = null; + synchronized(glRunnablesLock) { + if(glRunnables.size()>0) { + _glRunnables = glRunnables; + glRunnables = new ArrayList(); + } + } + if(null!=_glRunnables) { + for (int i=0; i < _glRunnables.size(); i++) { + ((GLRunnable) _glRunnables.get(i)).run(drawable); + } + } + } + } + + public final void setAnimator(GLAnimatorControl animator) throws GLException { + synchronized(glRunnablesLock) { + if(animatorCtrl!=animator && null!=animator && null!=animatorCtrl) { + throw new GLException("Trying to register GLAnimatorControl "+animator+", where "+animatorCtrl+" is already registered. Unregister first."); + } + animatorCtrl = animator; + } + } + + public final GLAnimatorControl getAnimator() { + synchronized(glRunnablesLock) { + return animatorCtrl; + } + } + + public final boolean isExternalAnimatorRunning() { + return ( null != animatorCtrl ) ? animatorCtrl.isStarted() && animatorCtrl.getThread() != Thread.currentThread() : false ; + } + + public final boolean isExternalAnimatorAnimating() { + return ( null != animatorCtrl ) ? animatorCtrl.isAnimating() && animatorCtrl.getThread() != Thread.currentThread() : false ; + } + + public final void invoke(GLAutoDrawable drawable, boolean wait, GLRunnable glRunnable) { + if( null == drawable || null == glRunnable ) { + return; + } + Throwable throwable = null; + GLRunnableTask rTask = null; + Object rTaskLock = new Object(); + synchronized(rTaskLock) { + boolean deferred; + synchronized(glRunnablesLock) { + deferred = isExternalAnimatorAnimating(); + if(!deferred) { + wait = false; // don't wait if exec immediatly + } + rTask = new GLRunnableTask(glRunnable, + wait ? rTaskLock : null, + wait /* catch Exceptions if waiting for result */); + glRunnables.add(rTask); + } + if( !deferred ) { + drawable.display(); + } else if( wait ) { + try { + rTaskLock.wait(); // free lock, allow execution of rTask + } catch (InterruptedException ie) { + throwable = ie; + } + if(null==throwable) { + throwable = rTask.getThrowable(); + } + if(null!=throwable) { + throw new RuntimeException(throwable); + } + } + } + } + + public final void setAutoSwapBufferMode(boolean onOrOff) { + autoSwapBufferMode = onOrOff; + } + + public final boolean getAutoSwapBufferMode() { + return autoSwapBufferMode; + } + + private static final ThreadLocal perThreadInitAction = new ThreadLocal(); + + /** Principal helper method which runs a Runnable with the context + made current. This could have been made part of GLContext, but a + desired goal is to be able to implement GLAutoDrawable's in terms of + the GLContext's public APIs, and putting it into a separate + class helps ensure that we don't inadvertently use private + methods of the GLContext or its implementing classes.<br> + * <br> + * Remark: In case this method is called to dispose the GLDrawable/GLAutoDrawable, + * <code>initAction</code> shall be <code>null</code> to mark this cause.<br> + * + * @param drawable + * @param context + * @param runnable + * @param initAction + */ + public final void invokeGL(GLDrawable drawable, + GLContext context, + Runnable runnable, + Runnable initAction) { + if(null==context) { + if (DEBUG) { + Exception e = new GLException(Thread.currentThread().getName()+" Info: GLDrawableHelper " + this + ".invokeGL(): NULL GLContext"); + e.printStackTrace(); + } + return; + } + + if(null==initAction) { + // disposal case + if(!context.isCreated()) { + throw new GLException(Thread.currentThread().getName()+" GLDrawableHelper " + this + ".invokeGL(): Dispose case (no init action given): Native context is not created: "+context); + } + } + + // Support for recursive makeCurrent() calls as well as calling + // other drawables' display() methods from within another one's + GLContext lastContext = GLContext.getCurrent(); + Runnable lastInitAction = (Runnable) perThreadInitAction.get(); + if (lastContext != null) { + lastContext.release(); + } + + int res = 0; + try { + res = context.makeCurrent(); + if (res != GLContext.CONTEXT_NOT_CURRENT) { + if(null!=initAction) { + perThreadInitAction.set(initAction); + if (res == GLContext.CONTEXT_CURRENT_NEW) { + if (DEBUG) { + System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running initAction"); + } + initAction.run(); + } + } + if(null!=runnable) { + if (DEBUG && VERBOSE) { + System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running runnable"); + } + runnable.run(); + if (autoSwapBufferMode && null != initAction) { + if (drawable != null) { + drawable.swapBuffers(); + } + } + } + } + } finally { + try { + if (res != GLContext.CONTEXT_NOT_CURRENT) { + context.release(); + } + } catch (Exception e) { + } + if (lastContext != null) { + int res2 = lastContext.makeCurrent(); + if (res2 == GLContext.CONTEXT_CURRENT_NEW) { + lastInitAction.run(); + } + } + } + } + +} diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java new file mode 100644 index 000000000..af14e5f43 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; + +public abstract class GLDrawableImpl implements GLDrawable { + protected static final boolean DEBUG = Debug.debug("GLDrawable"); + + protected GLDrawableImpl(GLDrawableFactory factory, + NativeSurface comp, + boolean realized) { + this.factory = factory; + this.surface = comp; + this.realized = realized; + this.requestedCapabilities = (GLCapabilitiesImmutable) surface.getGraphicsConfiguration().getNativeGraphicsConfiguration().getRequestedCapabilities(); + } + + /** + * Returns the DynamicLookupHelper + */ + public abstract GLDynamicLookupHelper getGLDynamicLookupHelper(); + + public GLDrawableFactoryImpl getFactoryImpl() { + return (GLDrawableFactoryImpl) getFactory(); + } + + /** For offscreen GLDrawables (pbuffers and "pixmap" drawables), + indicates that native resources should be reclaimed. */ + public void destroy() { + surface.getGraphicsConfiguration().getScreen().getDevice().lock(); + try { + destroyImpl(); + } finally { + surface.getGraphicsConfiguration().getScreen().getDevice().unlock(); + } + } + protected void destroyImpl() { + throw new GLException("Should not call this (should only be called for offscreen GLDrawables)"); + } + + public final void swapBuffers() throws GLException { + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)surface.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + if ( caps.getDoubleBuffered() ) { + if(!surface.surfaceSwap()) { + int lockRes = lockSurface(); // it's recursive, so it's ok within [makeCurrent .. release] + if (NativeSurface.LOCK_SURFACE_NOT_READY == lockRes) { + return; + } + try { + AbstractGraphicsDevice aDevice = getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); + if (NativeSurface.LOCK_SURFACE_CHANGED == lockRes) { + updateHandle(); + } + swapBuffersImpl(); + } finally { + unlockSurface(); + } + } + } else { + GLContext ctx = GLContext.getCurrent(); + if(null!=ctx && ctx.getGLDrawable()==this) { + ctx.getGL().glFinish(); + } + } + surface.surfaceUpdated(this, surface, System.currentTimeMillis()); + } + protected abstract void swapBuffersImpl(); + + public static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + + public GLProfile getGLProfile() { + return requestedCapabilities.getGLProfile(); + } + + public GLCapabilitiesImmutable getChosenGLCapabilities() { + return (GLCapabilitiesImmutable) surface.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + } + + public GLCapabilitiesImmutable getRequestedGLCapabilities() { + return requestedCapabilities; + } + + public NativeSurface getNativeSurface() { + return surface; + } + + protected void destroyHandle() {} + protected void updateHandle() {} + + public long getHandle() { + return surface.getSurfaceHandle(); + } + + public GLDrawableFactory getFactory() { + return factory; + } + + public final synchronized void setRealized(boolean realizedArg) { + if ( realized != realizedArg ) { + if(DEBUG) { + System.err.println("setRealized: "+getClass().getName()+" "+realized+" -> "+realizedArg); + } + realized = realizedArg; + AbstractGraphicsDevice aDevice = surface.getGraphicsConfiguration().getScreen().getDevice(); + if(realizedArg) { + if(NativeSurface.LOCK_SURFACE_NOT_READY >= lockSurface()) { + throw new GLException("GLDrawableImpl.setRealized(true): already realized, but surface not ready (lockSurface)"); + } + } else { + aDevice.lock(); + } + try { + setRealizedImpl(); + if(realizedArg) { + updateHandle(); + } else { + destroyHandle(); + } + } finally { + if(realizedArg) { + unlockSurface(); + } else { + aDevice.unlock(); + } + } + } else if(DEBUG) { + System.err.println("setRealized: "+getClass().getName()+" "+this.realized+" == "+realizedArg); + } + } + protected abstract void setRealizedImpl(); + + public synchronized boolean isRealized() { + return realized; + } + + public int getWidth() { + return surface.getWidth(); + } + + public int getHeight() { + return surface.getHeight(); + } + + public int lockSurface() throws GLException { + return surface.lockSurface(); + } + + public void unlockSurface() { + surface.unlockSurface(); + } + + public boolean isSurfaceLocked() { + return surface.isSurfaceLocked(); + } + + public String toString() { + return getClass().getName()+"[Realized "+isRealized()+ + ",\n\tFactory "+getFactory()+ + ",\n\thandle "+toHexString(getHandle())+ + ",\n\tWindow "+getNativeSurface()+"]"; + } + + protected GLDrawableFactory factory; + protected NativeSurface surface; + protected GLCapabilitiesImmutable requestedCapabilities; + + // Indicates whether the surface (if an onscreen context) has been + // realized. Plausibly, before the surface is realized the JAWT + // should return an error or NULL object from some of its + // operations; this appears to be the case on Win32 but is not true + // at least with Sun's current X11 implementation (1.4.x), which + // crashes with no other error reported if the DrawingSurfaceInfo is + // fetched from a locked DrawingSurface during the validation as a + // result of calling show() on the main thread. To work around this + // we prevent any JAWT or OpenGL operations from being done until + // addNotify() is called on the surface. + protected boolean realized; + +} diff --git a/src/jogl/classes/jogamp/opengl/GLDynamicLibraryBundleInfo.java b/src/jogl/classes/jogamp/opengl/GLDynamicLibraryBundleInfo.java new file mode 100644 index 000000000..bedf431f5 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLDynamicLibraryBundleInfo.java @@ -0,0 +1,54 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl; + +import com.jogamp.common.os.DynamicLibraryBundleInfo; +import java.util.*; + +public abstract class GLDynamicLibraryBundleInfo implements DynamicLibraryBundleInfo { + static List/*<String>*/ glueLibNamesPreload; + static { + glueLibNamesPreload = new ArrayList(); + glueLibNamesPreload.add("nativewindow_x11"); + } + + protected GLDynamicLibraryBundleInfo() { + } + + /** default **/ + public boolean shallLinkGlobal() { return false; } + + /** default **/ + public boolean shallLookupGlobal() { return false; } + + public static List/*<String>*/ getGlueLibNamesPreload() { + return glueLibNamesPreload; + } +} + diff --git a/src/jogl/classes/jogamp/opengl/GLDynamicLookupHelper.java b/src/jogl/classes/jogamp/opengl/GLDynamicLookupHelper.java new file mode 100644 index 000000000..d2dac8148 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLDynamicLookupHelper.java @@ -0,0 +1,44 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl; + +import com.jogamp.common.os.DynamicLibraryBundle; + +public class GLDynamicLookupHelper extends DynamicLibraryBundle { + + public GLDynamicLookupHelper(GLDynamicLibraryBundleInfo info) { + super(info); + } + + public GLDynamicLibraryBundleInfo getGLBundleInfo() { return (GLDynamicLibraryBundleInfo) getBundleInfo(); } + + /** NOP per default */ + public boolean loadGLULibrary() { return false; } +} + diff --git a/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationFactory.java new file mode 100644 index 000000000..e51e997a3 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationFactory.java @@ -0,0 +1,97 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl; + +import java.util.List; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.NativeWindowException; +import javax.media.opengl.DefaultGLCapabilitiesChooser; + +public abstract class GLGraphicsConfigurationFactory extends GraphicsConfigurationFactory { + + protected static int chooseCapabilities(CapabilitiesChooser chooser, CapabilitiesImmutable capsRequested, + List /*<CapabilitiesImmutable>*/ availableCaps, int recommendedIndex) { + if (null == capsRequested) { + throw new NativeWindowException("Null requested capabilities"); + } + if ( 0 == availableCaps.size() ) { + if (DEBUG) { + System.err.println("Empty available capabilities"); + } + return -1; // none available + } + + if(null == chooser && 0 <= recommendedIndex) { + if (DEBUG) { + System.err.println("chooseCapabilities: Using recommendedIndex: idx " + recommendedIndex); + } + return recommendedIndex; + } + int chosenIndex = recommendedIndex; + + if (null == chooser) { + chooser = new DefaultGLCapabilitiesChooser(); + } + + try { + chosenIndex = chooser.chooseCapabilities(capsRequested, availableCaps, recommendedIndex); + if(0 <= chosenIndex) { + if (DEBUG) { + System.err.println("chooseCapabilities: Chosen idx " + chosenIndex); + } + return chosenIndex; + } + } catch (NativeWindowException e) { + if (DEBUG) { + e.printStackTrace(); + } + } + + // keep on going .. + // seek first available one .. + for (chosenIndex = 0; chosenIndex < availableCaps.size() && availableCaps.get(chosenIndex) == null; chosenIndex++) { + // nop + } + if (chosenIndex == availableCaps.size()) { + // give up .. + if (DEBUG) { + System.err.println("chooseCapabilities: Failed .. nothing available, bail out"); + } + return -1; + } + if (DEBUG) { + System.err.println("chooseCapabilities: Fall back to 1st available idx " + chosenIndex); + } + + return chosenIndex; + } + +} diff --git a/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationUtil.java b/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationUtil.java new file mode 100644 index 000000000..066ea8120 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationUtil.java @@ -0,0 +1,147 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl; + +import java.util.ArrayList; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; + +public class GLGraphicsConfigurationUtil { + public static final int WINDOW_BIT = 1 << 0; + public static final int BITMAP_BIT = 1 << 1; + public static final int PBUFFER_BIT = 1 << 2; + public static final int ALL_BITS = WINDOW_BIT | BITMAP_BIT | PBUFFER_BIT ; + + public static final StringBuffer winAttributeBits2String(StringBuffer sb, int winattrbits) { + if(null==sb) { + sb = new StringBuffer(); + } + boolean seperator = false; + if( 0 != ( WINDOW_BIT & winattrbits ) ) { + sb.append("WINDOW"); + seperator=true; + } + if( 0 != ( BITMAP_BIT & winattrbits ) ) { + if(seperator) { + sb.append(", "); + } + sb.append("BITMAP"); + seperator=true; + } + if( 0 != ( PBUFFER_BIT & winattrbits ) ) { + if(seperator) { + sb.append(", "); + } + sb.append("PBUFFER"); + } + return sb; + } + + /** + * @return bitmask representing the input boolean in exclusive or logic, ie only one bit will be set + */ + public static final int getWinAttributeBits(boolean isOnscreen, boolean isPBuffer) { + int winattrbits = 0; + if(isOnscreen) { + winattrbits |= WINDOW_BIT; + } else if (!isPBuffer) { + winattrbits |= BITMAP_BIT; + } else { + winattrbits |= PBUFFER_BIT; + } + return winattrbits; + } + + /** + * @see #getWinAttributeBits(boolean, boolean) + */ + public static final int getWinAttributeBits(GLCapabilitiesImmutable caps) { + return getWinAttributeBits(caps.isOnscreen(), caps.isPBuffer()); + } + + public static final boolean addGLCapabilitiesPermutations(ArrayList capsBucket, GLCapabilitiesImmutable temp, int winattrbits) { + int preSize = capsBucket.size(); + if( 0 != ( WINDOW_BIT & winattrbits ) ) { + GLCapabilities cpy = (GLCapabilities) temp.cloneMutable(); + cpy.setOnscreen(true); + capsBucket.add(cpy); + } + if( 0 != ( PBUFFER_BIT & winattrbits ) ) { + GLCapabilities cpy = (GLCapabilities) temp.cloneMutable(); + cpy.setPBuffer(true); + capsBucket.add(cpy); + } + if( 0 != ( BITMAP_BIT & winattrbits ) ) { + GLCapabilities cpy = (GLCapabilities) temp.cloneMutable(); + cpy.setOnscreen(false); + cpy.setPBuffer(false); + capsBucket.add(cpy); + } + return capsBucket.size() > preSize; + } + + public static GLCapabilitiesImmutable fixGLCapabilities(GLCapabilitiesImmutable capsRequested, boolean pbufferAvailable) + { + if( !capsRequested.isOnscreen() ) { + return fixOffScreenGLCapabilities(capsRequested, pbufferAvailable); + } + return capsRequested; + } + + public static GLCapabilitiesImmutable fixOffScreenGLCapabilities(GLCapabilitiesImmutable capsRequested, boolean pbufferAvailable) + { + if( capsRequested.getDoubleBuffered() || + capsRequested.isOnscreen() || + ( !pbufferAvailable && capsRequested.isPBuffer() ) ) + { + // fix caps .. + GLCapabilities caps2 = (GLCapabilities) capsRequested.cloneMutable(); + caps2.setDoubleBuffered(false); // FIXME DBLBUFOFFSCRN + caps2.setOnscreen(false); + if(caps2.isPBuffer() && !pbufferAvailable) { + caps2.setPBuffer(false); + } + return caps2; + } + return capsRequested; + } + + public static GLCapabilitiesImmutable fixGLPBufferGLCapabilities(GLCapabilitiesImmutable capsRequested) + { + if( capsRequested.getDoubleBuffered() || capsRequested.isOnscreen() || !capsRequested.isPBuffer()) { + // fix caps .. + GLCapabilities caps2 = (GLCapabilities) capsRequested.cloneMutable(); + caps2.setDoubleBuffered(false); // FIXME DBLBUFOFFSCRN + caps2.setPBuffer(true); + return caps2; + } + return capsRequested; + } + +} diff --git a/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java new file mode 100644 index 000000000..671390fbb --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java @@ -0,0 +1,299 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import com.jogamp.common.util.locks.RecursiveLock; +import javax.media.nativewindow.NativeSurface; +import javax.media.opengl.GL; +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLRunnable; + +/** Platform-independent class exposing pbuffer functionality to + applications. This class is not exposed in the public API as it + would probably add no value; however it implements the GLDrawable + interface so can be interacted with via its display() method. */ + +public class GLPbufferImpl implements GLPbuffer { + private GLDrawableImpl pbufferDrawable; + private GLContextImpl context; + private GLDrawableHelper drawableHelper = new GLDrawableHelper(); + private int floatMode; + + public GLPbufferImpl(GLDrawableImpl pbufferDrawable, + GLContext parentContext) { + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) + pbufferDrawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + if(caps.isOnscreen()) { + if(caps.isPBuffer()) { + throw new IllegalArgumentException("Error: Given drawable is Onscreen and Pbuffer: "+pbufferDrawable); + } + throw new IllegalArgumentException("Error: Given drawable is Onscreen: "+pbufferDrawable); + } else { + if(!caps.isPBuffer()) { + throw new IllegalArgumentException("Error: Given drawable is not Pbuffer: "+pbufferDrawable); + } + } + this.pbufferDrawable = pbufferDrawable; + context = (GLContextImpl) pbufferDrawable.createContext(parentContext); + context.setSynchronized(true); + } + + public GLContext createContext(GLContext shareWith) { + return pbufferDrawable.createContext(shareWith); + } + + public void setRealized(boolean realized) { + } + + public boolean isRealized() { + return true; + } + + class DisposeAction implements Runnable { + public void run() { + // Lock: Covered by DestroyAction .. + drawableHelper.dispose(GLPbufferImpl.this); + } + } + DisposeAction disposeAction = new DisposeAction(); + + public void destroy() { + if(pbufferDrawable.isRealized()) { + if (null != context && context.isCreated()) { + try { + drawableHelper.invokeGL(pbufferDrawable, context, disposeAction, null); + } catch (GLException gle) { + gle.printStackTrace(); + } + context.destroy(); + // drawableHelper.reset(); + } + pbufferDrawable.destroy(); + } + } + + public void setSize(int width, int height) { + // FIXME + throw new GLException("Not yet implemented"); + } + + public NativeSurface getNativeSurface() { + return pbufferDrawable.getNativeSurface(); + } + + public long getHandle() { + return pbufferDrawable.getHandle(); + } + + public GLDrawableFactory getFactory() { + return pbufferDrawable.getFactory(); + } + + public int getWidth() { + return pbufferDrawable.getWidth(); + } + + public int getHeight() { + return pbufferDrawable.getHeight(); + } + + public void display() { + invokeGL(displayAction); + } + + public void repaint() { + display(); + } + + public void addGLEventListener(GLEventListener listener) { + drawableHelper.addGLEventListener(listener); + } + + public void addGLEventListener(int index, GLEventListener listener) { + drawableHelper.addGLEventListener(index, listener); + } + + public void removeGLEventListener(GLEventListener listener) { + drawableHelper.removeGLEventListener(listener); + } + + public void setAnimator(GLAnimatorControl animatorControl) { + drawableHelper.setAnimator(animatorControl); + } + + public GLAnimatorControl getAnimator() { + return drawableHelper.getAnimator(); + } + + public void invoke(boolean wait, GLRunnable glRunnable) { + drawableHelper.invoke(this, wait, glRunnable); + } + + public void setContext(GLContext ctx) { + context=(GLContextImpl)ctx; + } + + public GLContext getContext() { + return context; + } + + public GLDrawable getDrawable() { + return pbufferDrawable; + } + + public GL getGL() { + return getContext().getGL(); + } + + public GL setGL(GL gl) { + return getContext().setGL(gl); + } + + public void setAutoSwapBufferMode(boolean onOrOff) { + drawableHelper.setAutoSwapBufferMode(onOrOff); + } + + public boolean getAutoSwapBufferMode() { + return drawableHelper.getAutoSwapBufferMode(); + } + + public void swapBuffers() { + invokeGL(swapBuffersAction); + } + + public void bindTexture() { + // Doesn't make much sense to try to do this on the event dispatch + // thread given that it has to be called while the context is current + context.bindPbufferToTexture(); + } + + public void releaseTexture() { + // Doesn't make much sense to try to do this on the event dispatch + // thread given that it has to be called while the context is current + context.releasePbufferFromTexture(); + } + + public GLCapabilitiesImmutable getChosenGLCapabilities() { + if (pbufferDrawable == null) + return null; + + return pbufferDrawable.getChosenGLCapabilities(); + } + + public GLCapabilitiesImmutable getRequestedGLCapabilities() { + if (pbufferDrawable == null) + return null; + + return pbufferDrawable.getRequestedGLCapabilities(); + } + + public GLProfile getGLProfile() { + if (pbufferDrawable == null) + return null; + + return pbufferDrawable.getGLProfile(); + } + + private RecursiveLock recurLock = new RecursiveLock(); + + public int lockSurface() throws GLException { + recurLock.lock(); + return NativeSurface.LOCK_SUCCESS; + } + + public void unlockSurface() { + recurLock.unlock(); + } + + public boolean isSurfaceLocked() { + return recurLock.isLocked(); + } + + public Throwable getLockedStack() { + return recurLock.getLockedStack(); + } + + public int getFloatingPointMode() { + if (floatMode == 0) { + throw new GLException("Pbuffer not initialized, or floating-point support not requested"); + } + return floatMode; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void invokeGL(Runnable invokeGLAction) { + drawableHelper.invokeGL(pbufferDrawable, context, invokeGLAction, initAction); + } + + + class InitAction implements Runnable { + public void run() { + floatMode = context.getFloatingPointMode(); + drawableHelper.init(GLPbufferImpl.this); + } + } + private InitAction initAction = new InitAction(); + + class DisplayAction implements Runnable { + public void run() { + drawableHelper.display(GLPbufferImpl.this); + } + } + private DisplayAction displayAction = new DisplayAction(); + + class SwapBuffersAction implements Runnable { + public void run() { + pbufferDrawable.swapBuffers(); + } + } + private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); +} diff --git a/src/jogl/classes/jogamp/opengl/GLRunnableTask.java b/src/jogl/classes/jogamp/opengl/GLRunnableTask.java new file mode 100644 index 000000000..e5b66b985 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLRunnableTask.java @@ -0,0 +1,89 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl; + +import javax.media.opengl.GLRunnable; +import javax.media.opengl.GLAutoDrawable; + +/** + * Helper class to provide a Runnable queue implementation with a Runnable wrapper + * which notifies after execution for the <code>invokeAndWait()</code> semantics. + */ +public class GLRunnableTask implements GLRunnable { + GLRunnable runnable; + Object notifyObject; + boolean catchExceptions; + boolean isExecuted; + + Throwable runnableException; + + public GLRunnableTask(GLRunnable runnable, Object notifyObject, boolean catchExceptions) { + this.runnable = runnable ; + this.notifyObject = notifyObject ; + this.catchExceptions = catchExceptions; + isExecuted = false; + } + + public void run(GLAutoDrawable drawable) { + if(null == notifyObject) { + try { + runnable.run(drawable); + } catch (Throwable t) { + runnableException = t; + if(catchExceptions) { + runnableException.printStackTrace(); + } else { + throw new RuntimeException(runnableException); + } + } finally { + isExecuted=true; + } + } else { + synchronized (notifyObject) { + try { + runnable.run(drawable); + } catch (Throwable t) { + runnableException = t; + if(catchExceptions) { + runnableException.printStackTrace(); + } else { + throw new RuntimeException(runnableException); + } + } finally { + isExecuted=true; + notifyObject.notifyAll(); + } + } + } + } + + public boolean isExecuted() { return isExecuted; } + public Throwable getThrowable() { return runnableException; } +} + diff --git a/src/jogl/classes/jogamp/opengl/GLStateTracker.java b/src/jogl/classes/jogamp/opengl/GLStateTracker.java new file mode 100644 index 000000000..3bf06ac7a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLStateTracker.java @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import javax.media.opengl.*; +import com.jogamp.common.util.IntIntHashMap; +import java.nio.IntBuffer; +import java.util.ArrayList; + +/** + * Tracks as closely as possible OpenGL states. + * GLStateTracker objects are allocated on a per-OpenGL-context basis. + * <p> + * Currently supported states: PixelStorei + */ +public class GLStateTracker { + + /** Minimum value of MAX_CLIENT_ATTRIB_STACK_DEPTH */ + public static final int MIN_CLIENT_ATTRIB_STACK_DEPTH = 16; + + /** static size of pixel state map */ + static final int PIXEL_STATE_MAP_SIZE = 16; + /** avoid rehash of static size pixel state map */ + static final int PIXEL_STATE_MAP_CAPACITY = 32; + + private volatile boolean enabled = true; + + private IntIntHashMap pixelStateMap; + private final ArrayList<SavedState> stack; + + private static class SavedState { + + /** + * Empty pixel-store state + */ + private IntIntHashMap pixelStateMap; + + /** + * set (client) pixel-store state, deep copy + */ + private void setPixelStateMap(IntIntHashMap pixelStateMap) { + this.pixelStateMap = (IntIntHashMap) pixelStateMap.clone(); + } + + /** + * get (client) pixel-store state, return reference + */ + private IntIntHashMap getPixelStateMap() { return pixelStateMap; } + + } + + + public GLStateTracker() { + pixelStateMap = new IntIntHashMap(PIXEL_STATE_MAP_CAPACITY, 0.75f); + pixelStateMap.setKeyNotFoundValue(-1); + resetStates(); + + stack = new ArrayList<SavedState>(MIN_CLIENT_ATTRIB_STACK_DEPTH); + } + + public void clearStates(boolean enable) { + enabled = enable; + pixelStateMap.clear(); + } + + public void setEnabled(boolean on) { + enabled = on; + } + + public boolean isEnabled() { + return enabled; + } + + /** @return true if found in our map, otherwise false, + * which forces the caller to query GL. */ + public boolean getInt(int pname, int[] params, int params_offset) { + if(enabled) { + int value = pixelStateMap.get(pname); + if(0 <= value) { + params[params_offset] = value; + return true; + } + } + return false; + } + + /** @return true if found in our map, otherwise false, + * which forces the caller to query GL. */ + public boolean getInt(int pname, IntBuffer params, int dummy) { + if(enabled) { + int value = pixelStateMap.get(pname); + if(0 <= value) { + params.put(params.position(), value); + return true; + } + } + return false; + } + + public void setInt(int pname, int param) { + if(enabled) { + pixelStateMap.put(pname, param); + } + } + + public void pushAttrib(int flags) { + if(enabled) { + SavedState state = new SavedState(); // empty-slot + if( 0 != (flags&GL2.GL_CLIENT_PIXEL_STORE_BIT) ) { + // save client pixel-store state + state.setPixelStateMap(pixelStateMap); + } + stack.add(stack.size(), state); // push + } + } + + public void popAttrib() { + if(enabled) { + if(stack.isEmpty()) { + throw new GLException("stack contains no elements"); + } + SavedState state = stack.remove(stack.size()-1); // pop + + if(null==state) { + throw new GLException("null stack element (remaining stack size "+stack.size()+")"); + } + + if ( null != state.getPixelStateMap() ) { + // use pulled client pixel-store state from stack + pixelStateMap = state.getPixelStateMap(); + } // else: empty-slot, not pushed by GL_CLIENT_PIXEL_STORE_BIT + } + } + + private void resetStates() { + pixelStateMap.clear(); + + // 16 values -> PIXEL_STATE_MAP_SIZE + pixelStateMap.put(GL.GL_PACK_ALIGNMENT, 4); + pixelStateMap.put(GL2GL3.GL_PACK_SWAP_BYTES, GL.GL_FALSE); + pixelStateMap.put(GL2GL3.GL_PACK_LSB_FIRST, GL.GL_FALSE); + pixelStateMap.put(GL2GL3.GL_PACK_ROW_LENGTH, 0); + pixelStateMap.put(GL2GL3.GL_PACK_SKIP_ROWS, 0); + pixelStateMap.put(GL2GL3.GL_PACK_SKIP_PIXELS, 0); + pixelStateMap.put(GL2GL3.GL_PACK_IMAGE_HEIGHT, 0); + pixelStateMap.put(GL2GL3.GL_PACK_SKIP_IMAGES, 0); + + pixelStateMap.put(GL.GL_UNPACK_ALIGNMENT, 4); + pixelStateMap.put(GL2GL3.GL_UNPACK_SWAP_BYTES, GL.GL_FALSE); + pixelStateMap.put(GL2GL3.GL_UNPACK_LSB_FIRST, GL.GL_FALSE); + pixelStateMap.put(GL2GL3.GL_UNPACK_ROW_LENGTH, 0); + pixelStateMap.put(GL2GL3.GL_UNPACK_SKIP_ROWS, 0); + pixelStateMap.put(GL2GL3.GL_UNPACK_SKIP_PIXELS, 0); + pixelStateMap.put(GL2GL3.GL_UNPACK_IMAGE_HEIGHT, 0); + pixelStateMap.put(GL2GL3.GL_UNPACK_SKIP_IMAGES, 0); + } +} + diff --git a/src/jogl/classes/jogamp/opengl/GLVersionNumber.java b/src/jogl/classes/jogamp/opengl/GLVersionNumber.java new file mode 100644 index 000000000..5bd008f83 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLVersionNumber.java @@ -0,0 +1,123 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl; + +import java.util.StringTokenizer; +import com.jogamp.common.util.VersionNumber; + +/** + * A class for storing and comparing OpenGL version numbers. + * This only works for desktop OpenGL at the moment. + */ +class GLVersionNumber extends VersionNumber { + + protected boolean valid; + + public GLVersionNumber(int majorRev, int minorRev, int subMinorRev) { + super(majorRev, minorRev, subMinorRev); + valid = true; + } + + public GLVersionNumber(String versionString) { + super(); + valid = false; + try { + if (versionString.startsWith("GL_VERSION_")) { + StringTokenizer tok = new StringTokenizer(versionString, "_"); + tok.nextToken(); // GL_ + tok.nextToken(); // VERSION_ + if (!tok.hasMoreTokens()) { + major = 0; + return; + } + major = Integer.valueOf(tok.nextToken()).intValue(); + if (!tok.hasMoreTokens()) { + minor = 0; + return; + } + minor = Integer.valueOf(tok.nextToken()).intValue(); + if (!tok.hasMoreTokens()) { + sub = 0; + return; + } + sub = Integer.valueOf(tok.nextToken()).intValue(); + } else { + int radix = 10; + if (versionString.length() > 2) { + if (Character.isDigit(versionString.charAt(0)) && versionString.charAt(1) == '.' && Character.isDigit(versionString.charAt(2))) { + major = Character.digit(versionString.charAt(0), radix); + minor = Character.digit(versionString.charAt(2), radix); + // See if there's version-specific information which might + // imply a more recent OpenGL version + StringTokenizer tok = new StringTokenizer(versionString, " "); + if (tok.hasMoreTokens()) { + tok.nextToken(); + if (tok.hasMoreTokens()) { + String token = tok.nextToken(); + int i = 0; + while (i < token.length() && !Character.isDigit(token.charAt(i))) { + i++; + } + if (i < token.length() - 2 && Character.isDigit(token.charAt(i)) && token.charAt(i + 1) == '.' && Character.isDigit(token.charAt(i + 2))) { + int altMajor = Character.digit(token.charAt(i), radix); + int altMinor = Character.digit(token.charAt(i + 2), radix); + // Avoid possibly confusing situations by putting some + // constraints on the upgrades we do to the major and + // minor versions + if ((altMajor == major && altMinor > minor) || altMajor == major + 1) { + major = altMajor; + minor = altMinor; + } + } + } + } + } + } + } + valid = true; + } catch (Exception e) { + e.printStackTrace(); + // FIXME: refactor desktop OpenGL dependencies and make this + // class work properly for OpenGL ES + System.err.println("Info: ExtensionAvailabilityCache: FunctionAvailabilityCache.Version.<init>: " + e); + major = 1; + minor = 0; + /* + throw (IllegalArgumentException) + new IllegalArgumentException( + "Illegally formatted version identifier: \"" + versionString + "\"") + .initCause(e); + */ + } + } + + public final boolean isValid() { + return valid; + } +} diff --git a/src/jogl/classes/jogamp/opengl/GLWorkerThread.java b/src/jogl/classes/jogamp/opengl/GLWorkerThread.java new file mode 100644 index 000000000..ac9655fbb --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/GLWorkerThread.java @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import java.lang.reflect.InvocationTargetException; +import java.util.*; +import javax.media.opengl.*; + +/** Singleton thread upon which all OpenGL work is performed by + default. Unfortunately many vendors' OpenGL drivers are not really + thread-safe and stability is much improved by performing OpenGL + work on at most one thread. This is the default behavior of the + GLAutoDrawable implementations according to the {@link + javax.media.opengl.Threading Threading} class. The GLWorkerThread + replaces the original AWT event queue thread-based mechanism for + two reasons: first, more than one AWT event queue thread may be + spawned, for example if a dialog is being shown; second, it avoids + blocking the AWT event queue thread during OpenGL rendering. */ + +public class GLWorkerThread { + private static volatile boolean started; + private static volatile Thread thread; + private static Object lock; + private static volatile boolean shouldTerminate; + private static volatile Throwable exception; + + // The Runnable to execute immediately on the worker thread + private static volatile Runnable work; + // Queue of Runnables to be asynchronously invoked + private static List queue = new LinkedList(); + + /** Should only be called by Threading class if creation of the + GLWorkerThread was requested via the opengl.1thread system + property. <br> + * Start the GLWorkerThread iff not started yet! + */ + public static void start() { + if (!started) { // volatile: ok + synchronized (GLWorkerThread.class) { + if (!started) { + lock = new Object(); + thread = new Thread(new WorkerRunnable(), + "JOGL GLWorkerThread"); + thread.setDaemon(true); + started = true; + synchronized (lock) { + thread.start(); + try { + lock.wait(); + } catch (InterruptedException e) { + } + } + + /* + + // Note: it appears that there is a bug in NVidia's current + // drivers where if a context was ever made current on a + // given thread and that thread has exited before program + // exit, a crash occurs in the drivers. Releasing the + // context from the given thread does not work around the + // problem. + // + // For the time being, we're going to work around this + // problem by not terminating the GLWorkerThread. In theory, + // shutting down the GLWorkerThread cleanly could be a good + // general solution to the problem of needing to + // cooperatively terminate all Animators at program exit. + // + // It appears that this doesn't even work around all of the + // kinds of crashes. Causing the context to be unilaterally + // released from the GLWorkerThread after each invocation + // seems to work around all of the kinds of crashes seen. + // + // These appear to be similar to the kinds of crashes seen + // when the Java2D/OpenGL pipeline terminates, and those are + // a known issue being fixed, so presumably these will be + // fixed in NVidia's next driver set. + + // Install shutdown hook to terminate daemon thread more or + // less cooperatively + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + Object lockTemp = lock; + if (lockTemp == null) { + // Already terminating (?) + return; + } + synchronized (lockTemp) { + shouldTerminate = true; + lockTemp.notifyAll(); + try { + lockTemp.wait(500); + } catch (InterruptedException e) { + } + } + } + }); + return null; + } + }); + + */ + + } else { + throw new RuntimeException("Should not start GLWorkerThread twice"); + } + } + } + } + + public static void invokeAndWait(Runnable runnable) + throws InvocationTargetException, InterruptedException { + if (!started) { + throw new RuntimeException("May not invokeAndWait on worker thread without starting it first"); + } + + Object lockTemp = lock; + if (lockTemp == null) { + return; // Terminating + } + + synchronized (lockTemp) { + if (thread == null) { + // Terminating + return; + } + + work = runnable; + lockTemp.notifyAll(); + lockTemp.wait(); + if (exception != null) { + Throwable localException = exception; + exception = null; + throw new InvocationTargetException(localException); + } + } + } + + public static void invokeLater(Runnable runnable) { + if (!started) { + throw new RuntimeException("May not invokeLater on worker thread without starting it first"); + } + + Object lockTemp = lock; + if (lockTemp == null) { + return; // Terminating + } + + synchronized (lockTemp) { + if (thread == null) { + // Terminating + return; + } + + queue.add(runnable); + lockTemp.notifyAll(); + } + } + + /** Indicates whether the OpenGL worker thread was started, i.e., + whether it is currently in use. */ + public static boolean isStarted() { + return started; + } + + /** Indicates whether the current thread is the OpenGL worker + thread. */ + public static boolean isWorkerThread() { + return (Thread.currentThread() == thread); + } + + static class WorkerRunnable implements Runnable { + public void run() { + // Notify starting thread that we're ready + synchronized (lock) { + lock.notifyAll(); + } + + while (!shouldTerminate) { + synchronized (lock) { + while (!shouldTerminate && + (work == null) && + queue.isEmpty()) { + try { + // Avoid race conditions with wanting to release contexts on this thread + lock.wait(1000); + } catch (InterruptedException e) { + } + + if (GLContext.getCurrent() != null) { + // Test later to see whether we need to release this context + break; + } + } + + if (shouldTerminate) { + lock.notifyAll(); + thread = null; + lock = null; + return; + } + + if (work != null) { + try { + work.run(); + } catch (Throwable t) { + exception = t; + } finally { + work = null; + lock.notifyAll(); + } + } + + while (!queue.isEmpty()) { + try { + Runnable curAsync = (Runnable) queue.remove(0); + curAsync.run(); + } catch (Throwable t) { + System.err.println("Exception occurred on JOGL OpenGL worker thread:"); + t.printStackTrace(); + } + } + + // See about releasing current context + GLContext curContext = GLContext.getCurrent(); + if (curContext != null && + (curContext instanceof GLContextImpl)) { + GLContextImpl impl = (GLContextImpl) curContext; + if (impl.hasWaiters()) { + impl.release(); + } + } + } + } + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/MemoryObject.java b/src/jogl/classes/jogamp/opengl/MemoryObject.java new file mode 100644 index 000000000..8b2cf0c4c --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/MemoryObject.java @@ -0,0 +1,122 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl; + +import java.nio.ByteBuffer; +import java.util.HashMap; + +/** + * + */ +public class MemoryObject { + private long addr; + private long size; + private int hash32; + private ByteBuffer buffer=null; + + public MemoryObject(long addr, long size) { + this.addr = addr; + this.size = size; + this.hash32 = getHash32(addr, size); + } + + public void setBuffer(ByteBuffer buffer) { + this.buffer = buffer; + } + + public ByteBuffer getBuffer() { + return this.buffer; + } + + /** + * @return the 32bit hash value generated via {@link #getHash32(long, long)} + */ + public int hashCode() { + return hash32; + } + + /** + * Ignores the optional attached <code>ByteBuffer</code> intentionally.<br> + * + * @return true of reference is equal or <code>obj</code> is of type <code>MemoryObject</code> + * and <code>addr</code> and <code>size</code> is equal.<br> + */ + public boolean equals(Object obj) { + if(this == obj) { return true; } + if(obj instanceof MemoryObject) { + MemoryObject m = (MemoryObject) obj; + return addr == m.addr && size == m.size ; + } + return false; + } + + /** + * Generates a 32bit hash value by <code>addr</code> and <code>size</code>.<br> + * Ignores the optional attached <code>ByteBuffer</code> intentionally.<br> + */ + public static int getHash32(long addr, long size) { + // avoid xor collisions of eg low/high parts + // 31 * x == (x << 5) - x + int hash = 31 + (int) addr ; // lo addr + hash = ((hash << 5) - hash) + (int) ( addr >>> 32 ) ; // hi addr + hash = ((hash << 5) - hash) + (int) size ; // lo size + hash = ((hash << 5) - hash) + (int) ( size >>> 32 ) ; // hi size + + return hash; + } + + /** + * Generates a 64bit hash value by <code>addr</code> and <code>size</code>.<br> + * Ignores the optional attached <code>ByteBuffer</code> intentionally.<br> + */ + public static long getHash64(long addr, long size) { + // 31 * x == (x << 5) - x + final long hash = 31 + addr; + return ((hash << 5) - hash) + size; + } + + public String toString() { + return "MemoryObject[addr 0x"+Long.toHexString(addr)+", size 0x"+Long.toHexString(size)+", hash32: 0x"+Integer.toHexString(hash32)+"]"; + } + + /** + * @param map the identity HashMap, MemoryObject to MemoryObject + * @param obj0 the MemoryObject + * @return either the already mapped MemoryObject - not changing the map, or the newly mapped one. + */ + public static MemoryObject getOrAddSafe(HashMap/*<MemoryObject,MemoryObject>*/ map, MemoryObject obj0) { + MemoryObject obj1 = (MemoryObject) map.get(obj0); // get identity (fast) + if(null == obj1) { + map.put(obj0, obj0); + obj1 = obj0; + } + return obj1; + } + +}
\ No newline at end of file diff --git a/src/jogl/classes/jogamp/opengl/ProjectFloat.java b/src/jogl/classes/jogamp/opengl/ProjectFloat.java new file mode 100644 index 000000000..a6316b242 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/ProjectFloat.java @@ -0,0 +1,1058 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** $Date: 2009-03-13 22:20:29 -0700 (Fri, 13 Mar 2009) $ $Revision: 1867 $ +** $Header$ +*/ + +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE COPYRIGHT OWNER 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. + */ + +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ +package jogamp.opengl; + +import java.nio.*; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.GLMatrixFunc; +import com.jogamp.common.nio.Buffers; + +/** + * ProjectFloat.java + * <p/> + * <p/> + * Created 11-jan-2004 + * + * @author Erik Duijs + * @author Kenneth Russell + */ +public class ProjectFloat { + private static final float[] IDENTITY_MATRIX = + new float[] { + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f }; + + private static final float[] ZERO_MATRIX = + new float[] { + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f }; + + // Note that we have cloned parts of the implementation in order to + // support incoming Buffers. The reason for this is to avoid loading + // non-direct buffer subclasses unnecessarily, because doing so can + // cause performance decreases on direct buffer operations, at least + // on the current HotSpot JVM. It would be nicer (and make the code + // simpler) to simply have the array-based entry points delegate to + // the versions taking Buffers by wrapping the arrays. + + // Array-based implementation + private final float[] matrix = new float[16]; + private final float[][] tempInvertMatrix = new float[4][4]; + + private final float[] in = new float[4]; + private final float[] out = new float[4]; + + private final float[] forward = new float[3]; + private final float[] side = new float[3]; + private final float[] up = new float[3]; + + // Buffer-based implementation + private FloatBuffer locbuf; + private final FloatBuffer matrixBuf; + private final FloatBuffer tempInvertMatrixBuf; + + private final FloatBuffer inBuf; + private final FloatBuffer outBuf; + + private final FloatBuffer forwardBuf; + private final FloatBuffer sideBuf; + private final FloatBuffer upBuf; + + public ProjectFloat() { + // Use direct buffers to avoid loading indirect buffer + // implementations for applications trying to avoid doing so. + // Slice up one big buffer because some NIO implementations + // allocate a huge amount of memory to back even the smallest of + // buffers. + locbuf = Buffers.newDirectFloatBuffer(2*16+2*4+3*3); + int pos = 0; + int sz = 16; + matrixBuf = slice(locbuf, pos, sz); + pos += sz; + tempInvertMatrixBuf = slice(locbuf, pos, sz); + pos += sz; + sz = 4; + inBuf = slice(locbuf, pos, sz); + pos += sz; + outBuf = slice(locbuf, pos, sz); + pos += sz; + sz = 3; + forwardBuf = slice(locbuf, pos, sz); + pos += sz; + sideBuf = slice(locbuf, pos, sz); + pos += sz; + upBuf = slice(locbuf, pos, sz); + } + + public void destroy() { + if(locbuf!=null) { + locbuf.clear(); + locbuf=null; + } + } + + private static FloatBuffer slice(FloatBuffer buf, int pos, int len) { + buf.position(pos); + buf.limit(pos + len); + return buf.slice(); + } + + /** + * Make matrix an identity matrix + */ + public static void gluMakeIdentityf(FloatBuffer m) { + int oldPos = m.position(); + m.put(IDENTITY_MATRIX); + m.position(oldPos); + } + + /** + * Make matrix an zero matrix + */ + public static void gluMakeZero(FloatBuffer m) { + int oldPos = m.position(); + m.put(ZERO_MATRIX); + m.position(oldPos); + } + + /** + * Make matrix an identity matrix + */ + public static void gluMakeIdentityf(float[] m) { + for (int i = 0; i < 16; i++) { + m[i] = IDENTITY_MATRIX[i]; + } + } + + /** + * Method __gluMultMatrixVecf + * + * @param matrix + * @param in + * @param out + */ + private void __gluMultMatrixVecf(float[] matrix, int matrix_offset, float[] in, float[] out) { + for (int i = 0; i < 4; i++) { + out[i] = + in[0] * matrix[0*4+i+matrix_offset] + + in[1] * matrix[1*4+i+matrix_offset] + + in[2] * matrix[2*4+i+matrix_offset] + + in[3] * matrix[3*4+i+matrix_offset]; + } + } + + /** + * Method __gluMultMatrixVecf + * + * @param matrix + * @param in + * @param out + */ + private void __gluMultMatrixVecf(FloatBuffer matrix, FloatBuffer in, FloatBuffer out) { + int inPos = in.position(); + int outPos = out.position(); + int matrixPos = matrix.position(); + for (int i = 0; i < 4; i++) { + out.put(i + outPos, + in.get(0+inPos) * matrix.get(0*4+i+matrixPos) + + in.get(1+inPos) * matrix.get(1*4+i+matrixPos) + + in.get(2+inPos) * matrix.get(2*4+i+matrixPos) + + in.get(3+inPos) * matrix.get(3*4+i+matrixPos)); + } + } + + /** + * @param src + * @param inverse + * + * @return + */ + public boolean gluInvertMatrixf(float[] src, float[] inverse) { + int i, j, k, swap; + float t; + float[][] temp = tempInvertMatrix; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + temp[i][j] = src[i*4+j]; + } + } + gluMakeIdentityf(inverse); + + for (i = 0; i < 4; i++) { + // + // Look for largest element in column + // + swap = i; + for (j = i + 1; j < 4; j++) { + if (Math.abs(temp[j][i]) > Math.abs(temp[i][i])) { + swap = j; + } + } + + if (swap != i) { + // + // Swap rows. + // + for (k = 0; k < 4; k++) { + t = temp[i][k]; + temp[i][k] = temp[swap][k]; + temp[swap][k] = t; + + t = inverse[i*4+k]; + inverse[i*4+k] = inverse[swap*4+k]; + inverse[swap*4+k] = t; + } + } + + if (temp[i][i] == 0) { + // + // No non-zero pivot. The matrix is singular, which shouldn't + // happen. This means the user gave us a bad matrix. + // + return false; + } + + t = temp[i][i]; + for (k = 0; k < 4; k++) { + temp[i][k] /= t; + inverse[i*4+k] /= t; + } + for (j = 0; j < 4; j++) { + if (j != i) { + t = temp[j][i]; + for (k = 0; k < 4; k++) { + temp[j][k] -= temp[i][k] * t; + inverse[j*4+k] -= inverse[i*4+k]*t; + } + } + } + } + return true; + } + + /** + * @param src + * @param inverse + * + * @return + */ + public boolean gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) { + int i, j, k, swap; + float t; + + int srcPos = src.position(); + int invPos = inverse.position(); + + FloatBuffer temp = tempInvertMatrixBuf; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + temp.put(i*4+j, src.get(i*4+j + srcPos)); + } + } + gluMakeIdentityf(inverse); + + for (i = 0; i < 4; i++) { + // + // Look for largest element in column + // + swap = i; + for (j = i + 1; j < 4; j++) { + if (Math.abs(temp.get(j*4+i)) > Math.abs(temp.get(i*4+i))) { + swap = j; + } + } + + if (swap != i) { + // + // Swap rows. + // + for (k = 0; k < 4; k++) { + t = temp.get(i*4+k); + temp.put(i*4+k, temp.get(swap*4+k)); + temp.put(swap*4+k, t); + + t = inverse.get(i*4+k + invPos); + inverse.put(i*4+k + invPos, inverse.get(swap*4+k + invPos)); + inverse.put(swap*4+k + invPos, t); + } + } + + if (temp.get(i*4+i) == 0) { + // + // No non-zero pivot. The matrix is singular, which shouldn't + // happen. This means the user gave us a bad matrix. + // + return false; + } + + t = temp.get(i*4+i); + for (k = 0; k < 4; k++) { + temp.put(i*4+k, temp.get(i*4+k) / t); + inverse.put(i*4+k + invPos, inverse.get(i*4+k + invPos) / t); + } + for (j = 0; j < 4; j++) { + if (j != i) { + t = temp.get(j*4+i); + for (k = 0; k < 4; k++) { + temp.put(j*4+k, temp.get(j*4+k) - temp.get(i*4+k) * t); + inverse.put(j*4+k + invPos, inverse.get(j*4+k + invPos) - inverse.get(i*4+k + invPos) * t); + } + } + } + } + return true; + } + + + /** + * @param a + * @param b + * @param r + */ + private void gluMultMatricesf(float[] a, int a_offset, float[] b, int b_offset, float[] r) { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + r[i*4+j] = + a[i*4+0+a_offset]*b[0*4+j+b_offset] + + a[i*4+1+a_offset]*b[1*4+j+b_offset] + + a[i*4+2+a_offset]*b[2*4+j+b_offset] + + a[i*4+3+a_offset]*b[3*4+j+b_offset]; + } + } + } + + + /** + * @param a + * @param b + * @param r + */ + public static void gluMultMatricesf(FloatBuffer a, FloatBuffer b, FloatBuffer r) { + int aPos = a.position(); + int bPos = b.position(); + int rPos = r.position(); + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + r.put(i*4+j + rPos, + a.get(i*4+0+aPos)*b.get(0*4+j+bPos) + + a.get(i*4+1+aPos)*b.get(1*4+j+bPos) + + a.get(i*4+2+aPos)*b.get(2*4+j+bPos) + + a.get(i*4+3+aPos)*b.get(3*4+j+bPos)); + } + } + } + + /** + * Normalize vector + * + * @param v + */ + public static void normalize(float[] v) { + float r; + + r = (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + if ( r == 0.0 || r == 1.0) + return; + + r = 1.0f / r; + + v[0] *= r; + v[1] *= r; + v[2] *= r; + + return; + } + + /** + * Normalize vector + * + * @param v + */ + public static void normalize(FloatBuffer v) { + float r; + + int vPos = v.position(); + + r = (float) Math.sqrt(v.get(0+vPos) * v.get(0+vPos) + + v.get(1+vPos) * v.get(1+vPos) + + v.get(2+vPos) * v.get(2+vPos)); + if ( r == 0.0 || r == 1.0) + return; + + r = 1.0f / r; + + v.put(0+vPos, v.get(0+vPos) * r); + v.put(1+vPos, v.get(1+vPos) * r); + v.put(2+vPos, v.get(2+vPos) * r); + + return; + } + + + /** + * Calculate cross-product + * + * @param v1 + * @param v2 + * @param result + */ + private static void cross(float[] v1, float[] v2, float[] result) { + result[0] = v1[1] * v2[2] - v1[2] * v2[1]; + result[1] = v1[2] * v2[0] - v1[0] * v2[2]; + result[2] = v1[0] * v2[1] - v1[1] * v2[0]; + } + + /** + * Calculate cross-product + * + * @param v1 + * @param v2 + * @param result + */ + private static void cross(FloatBuffer v1, FloatBuffer v2, FloatBuffer result) { + int v1Pos = v1.position(); + int v2Pos = v2.position(); + int rPos = result.position(); + + result.put(0+rPos, v1.get(1+v1Pos) * v2.get(2+v2Pos) - v1.get(2+v1Pos) * v2.get(1+v2Pos)); + result.put(1+rPos, v1.get(2+v1Pos) * v2.get(0+v2Pos) - v1.get(0+v1Pos) * v2.get(2+v2Pos)); + result.put(2+rPos, v1.get(0+v1Pos) * v2.get(1+v2Pos) - v1.get(1+v1Pos) * v2.get(0+v2Pos)); + } + + /** + * Method gluOrtho2D. + * + * @param left + * @param right + * @param bottom + * @param top + */ + public void gluOrtho2D(GLMatrixFunc gl, float left, float right, float bottom, float top) { + gl.glOrthof(left, right, bottom, top, -1, 1); + } + + /** + * Method gluPerspective. + * + * @param fovy + * @param aspect + * @param zNear + * @param zFar + */ + public void gluPerspective(GLMatrixFunc gl, float fovy, float aspect, float zNear, float zFar) { + float sine, cotangent, deltaZ; + float radians = fovy / 2 * (float) Math.PI / 180; + + deltaZ = zFar - zNear; + sine = (float) Math.sin(radians); + + if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) { + return; + } + + cotangent = (float) Math.cos(radians) / sine; + + gluMakeIdentityf(matrixBuf); + + matrixBuf.put(0 * 4 + 0, cotangent / aspect); + matrixBuf.put(1 * 4 + 1, cotangent); + matrixBuf.put(2 * 4 + 2, - (zFar + zNear) / deltaZ); + matrixBuf.put(2 * 4 + 3, -1); + matrixBuf.put(3 * 4 + 2, -2 * zNear * zFar / deltaZ); + matrixBuf.put(3 * 4 + 3, 0); + + gl.glMultMatrixf(matrixBuf); + } + + /** + * Method gluLookAt + * + * @param eyex + * @param eyey + * @param eyez + * @param centerx + * @param centery + * @param centerz + * @param upx + * @param upy + * @param upz + */ + public void gluLookAt(GLMatrixFunc gl, + float eyex, + float eyey, + float eyez, + float centerx, + float centery, + float centerz, + float upx, + float upy, + float upz) { + FloatBuffer forward = this.forwardBuf; + FloatBuffer side = this.sideBuf; + FloatBuffer up = this.upBuf; + + forward.put(0, centerx - eyex); + forward.put(1, centery - eyey); + forward.put(2, centerz - eyez); + + up.put(0, upx); + up.put(1, upy); + up.put(2, upz); + + normalize(forward); + + /* Side = forward x up */ + cross(forward, up, side); + normalize(side); + + /* Recompute up as: up = side x forward */ + cross(side, forward, up); + + gluMakeIdentityf(matrixBuf); + matrixBuf.put(0 * 4 + 0, side.get(0)); + matrixBuf.put(1 * 4 + 0, side.get(1)); + matrixBuf.put(2 * 4 + 0, side.get(2)); + + matrixBuf.put(0 * 4 + 1, up.get(0)); + matrixBuf.put(1 * 4 + 1, up.get(1)); + matrixBuf.put(2 * 4 + 1, up.get(2)); + + matrixBuf.put(0 * 4 + 2, -forward.get(0)); + matrixBuf.put(1 * 4 + 2, -forward.get(1)); + matrixBuf.put(2 * 4 + 2, -forward.get(2)); + + gl.glMultMatrixf(matrixBuf); + gl.glTranslatef(-eyex, -eyey, -eyez); + } + + /** + * Method gluProject + * + * @param objx + * @param objy + * @param objz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param win_pos + * + * @return + */ + public boolean gluProject(float objx, + float objy, + float objz, + float[] modelMatrix, + int modelMatrix_offset, + float[] projMatrix, + int projMatrix_offset, + int[] viewport, + int viewport_offset, + float[] win_pos, + int win_pos_offset ) { + + float[] in = this.in; + float[] out = this.out; + + in[0] = objx; + in[1] = objy; + in[2] = objz; + in[3] = 1.0f; + + __gluMultMatrixVecf(modelMatrix, modelMatrix_offset, in, out); + __gluMultMatrixVecf(projMatrix, projMatrix_offset, out, in); + + if (in[3] == 0.0f) + return false; + + in[3] = (1.0f / in[3]) * 0.5f; + + // Map x, y and z to range 0-1 + in[0] = in[0] * in[3] + 0.5f; + in[1] = in[1] * in[3] + 0.5f; + in[2] = in[2] * in[3] + 0.5f; + + // Map x,y to viewport + win_pos[0+win_pos_offset] = in[0] * viewport[2+viewport_offset] + viewport[0+viewport_offset]; + win_pos[1+win_pos_offset] = in[1] * viewport[3+viewport_offset] + viewport[1+viewport_offset]; + win_pos[2+win_pos_offset] = in[2]; + + return true; + } + + /** + * Method gluProject + * + * @param objx + * @param objy + * @param objz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param win_pos + * + * @return + */ + public boolean gluProject(float objx, + float objy, + float objz, + FloatBuffer modelMatrix, + FloatBuffer projMatrix, + IntBuffer viewport, + FloatBuffer win_pos) { + + FloatBuffer in = this.inBuf; + FloatBuffer out = this.outBuf; + + in.put(0, objx); + in.put(1, objy); + in.put(2, objz); + in.put(3, 1.0f); + + __gluMultMatrixVecf(modelMatrix, in, out); + __gluMultMatrixVecf(projMatrix, out, in); + + if (in.get(3) == 0.0f) + return false; + + in.put(3, (1.0f / in.get(3)) * 0.5f); + + // Map x, y and z to range 0-1 + in.put(0, in.get(0) * in.get(3) + 0.5f); + in.put(1, in.get(1) * in.get(3) + 0.5f); + in.put(2, in.get(2) * in.get(3) + 0.5f); + + // Map x,y to viewport + int vPos = viewport.position(); + int wPos = win_pos.position(); + win_pos.put(0+wPos, in.get(0) * viewport.get(2+vPos) + viewport.get(0+vPos)); + win_pos.put(1+wPos, in.get(1) * viewport.get(3+vPos) + viewport.get(1+vPos)); + win_pos.put(2+wPos, in.get(2)); + + return true; + } + + + /** + * Method gluUnproject + * + * @param winx + * @param winy + * @param winz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param obj_pos + * + * @return + */ + public boolean gluUnProject(float winx, + float winy, + float winz, + float[] modelMatrix, + int modelMatrix_offset, + float[] projMatrix, + int projMatrix_offset, + int[] viewport, + int viewport_offset, + float[] obj_pos, + int obj_pos_offset) { + float[] in = this.in; + float[] out = this.out; + + gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); + + if (!gluInvertMatrixf(matrix, matrix)) + return false; + + in[0] = winx; + in[1] = winy; + in[2] = winz; + in[3] = 1.0f; + + // Map x and y from window coordinates + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; + + // Map to range -1 to 1 + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecf(matrix, 0, in, out); + + if (out[3] == 0.0) + return false; + + out[3] = 1.0f / out[3]; + + obj_pos[0+obj_pos_offset] = out[0] * out[3]; + obj_pos[1+obj_pos_offset] = out[1] * out[3]; + obj_pos[2+obj_pos_offset] = out[2] * out[3]; + + return true; + } + + + /** + * Method gluUnproject + * + * @param winx + * @param winy + * @param winz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param obj_pos + * + * @return + */ + public boolean gluUnProject(float winx, + float winy, + float winz, + FloatBuffer modelMatrix, + FloatBuffer projMatrix, + IntBuffer viewport, + FloatBuffer obj_pos) { + FloatBuffer in = this.inBuf; + FloatBuffer out = this.outBuf; + + gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); + + if (!gluInvertMatrixf(matrixBuf, matrixBuf)) + return false; + + in.put(0, winx); + in.put(1, winy); + in.put(2, winz); + in.put(3, 1.0f); + + // Map x and y from window coordinates + int vPos = viewport.position(); + int oPos = obj_pos.position(); + in.put(0, (in.get(0) - viewport.get(0+vPos)) / viewport.get(2+vPos)); + in.put(1, (in.get(1) - viewport.get(1+vPos)) / viewport.get(3+vPos)); + + // Map to range -1 to 1 + in.put(0, in.get(0) * 2 - 1); + in.put(1, in.get(1) * 2 - 1); + in.put(2, in.get(2) * 2 - 1); + + __gluMultMatrixVecf(matrixBuf, in, out); + + if (out.get(3) == 0.0f) + return false; + + out.put(3, 1.0f / out.get(3)); + + obj_pos.put(0+oPos, out.get(0) * out.get(3)); + obj_pos.put(1+oPos, out.get(1) * out.get(3)); + obj_pos.put(2+oPos, out.get(2) * out.get(3)); + + return true; + } + + + /** + * Method gluUnproject4 + * + * @param winx + * @param winy + * @param winz + * @param clipw + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param near + * @param far + * @param obj_pos + * + * @return + */ + public boolean gluUnProject4(float winx, + float winy, + float winz, + float clipw, + float[] modelMatrix, + int modelMatrix_offset, + float[] projMatrix, + int projMatrix_offset, + int[] viewport, + int viewport_offset, + float near, + float far, + float[] obj_pos, + int obj_pos_offset ) { + float[] in = this.in; + float[] out = this.out; + + gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); + + if (!gluInvertMatrixf(matrix, matrix)) + return false; + + in[0] = winx; + in[1] = winy; + in[2] = winz; + in[3] = clipw; + + // Map x and y from window coordinates + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; + in[2] = (in[2] - near) / (far - near); + + // Map to range -1 to 1 + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecf(matrix, 0, in, out); + + if (out[3] == 0.0f) + return false; + + obj_pos[0+obj_pos_offset] = out[0]; + obj_pos[1+obj_pos_offset] = out[1]; + obj_pos[2+obj_pos_offset] = out[2]; + obj_pos[3+obj_pos_offset] = out[3]; + return true; + } + + /** + * Method gluUnproject4 + * + * @param winx + * @param winy + * @param winz + * @param clipw + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param near + * @param far + * @param obj_pos + * + * @return + */ + public boolean gluUnProject4(float winx, + float winy, + float winz, + float clipw, + FloatBuffer modelMatrix, + FloatBuffer projMatrix, + IntBuffer viewport, + float near, + float far, + FloatBuffer obj_pos) { + FloatBuffer in = this.inBuf; + FloatBuffer out = this.outBuf; + + gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); + + if (!gluInvertMatrixf(matrixBuf, matrixBuf)) + return false; + + in.put(0, winx); + in.put(1, winy); + in.put(2, winz); + in.put(3, clipw); + + // Map x and y from window coordinates + int vPos = viewport.position(); + in.put(0, (in.get(0) - viewport.get(0+vPos)) / viewport.get(2+vPos)); + in.put(1, (in.get(1) - viewport.get(1+vPos)) / viewport.get(3+vPos)); + in.put(2, (in.get(2) - near) / (far - near)); + + // Map to range -1 to 1 + in.put(0, in.get(0) * 2 - 1); + in.put(1, in.get(1) * 2 - 1); + in.put(2, in.get(2) * 2 - 1); + + __gluMultMatrixVecf(matrixBuf, in, out); + + if (out.get(3) == 0.0f) + return false; + + int oPos = obj_pos.position(); + obj_pos.put(0+oPos, out.get(0)); + obj_pos.put(1+oPos, out.get(1)); + obj_pos.put(2+oPos, out.get(2)); + obj_pos.put(3+oPos, out.get(3)); + return true; + } + + + /** + * Method gluPickMatrix + * + * @param x + * @param y + * @param deltaX + * @param deltaY + * @param viewport + */ + public void gluPickMatrix(GLMatrixFunc gl, + float x, + float y, + float deltaX, + float deltaY, + IntBuffer viewport) { + if (deltaX <= 0 || deltaY <= 0) { + return; + } + + /* Translate and scale the picked region to the entire window */ + int vPos = viewport.position(); + gl.glTranslatef((viewport.get(2+vPos) - 2 * (x - viewport.get(0+vPos))) / deltaX, + (viewport.get(3+vPos) - 2 * (y - viewport.get(1+vPos))) / deltaY, + 0); + gl.glScalef(viewport.get(2) / deltaX, viewport.get(3) / deltaY, 1.0f); + } + + /** + * Method gluPickMatrix + * + * @param x + * @param y + * @param deltaX + * @param deltaY + * @param viewport + * @param viewport_offset + */ + public void gluPickMatrix(GLMatrixFunc gl, + float x, + float y, + float deltaX, + float deltaY, + int[] viewport, + int viewport_offset) { + if (deltaX <= 0 || deltaY <= 0) { + return; + } + + /* Translate and scale the picked region to the entire window */ + gl.glTranslatef((viewport[2+viewport_offset] - 2 * (x - viewport[0+viewport_offset])) / deltaX, + (viewport[3+viewport_offset] - 2 * (y - viewport[1+viewport_offset])) / deltaY, + 0); + gl.glScalef(viewport[2+viewport_offset] / deltaX, viewport[3+viewport_offset] / deltaY, 1.0f); + } +} diff --git a/src/jogl/classes/jogamp/opengl/SharedResourceRunner.java b/src/jogl/classes/jogamp/opengl/SharedResourceRunner.java new file mode 100644 index 000000000..386679992 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/SharedResourceRunner.java @@ -0,0 +1,249 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.opengl; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; + +public class SharedResourceRunner implements Runnable { + protected static final boolean DEBUG = GLDrawableImpl.DEBUG; + + public static interface Resource { + AbstractGraphicsDevice getDevice(); + AbstractGraphicsScreen getScreen(); + GLDrawableImpl getDrawable(); + GLContextImpl getContext(); + } + + public static interface Implementation { + Resource createSharedResource(String connection); + void releaseSharedResource(Resource shared); + void clear(); + + Resource mapPut(String connection, Resource resource); + Resource mapGet(String connection); + Collection/*<Resource>*/ mapValues(); + } + + Implementation impl = null; + + boolean ready = false; + boolean released = false; + boolean shouldRelease = false; + String initConnection = null; + String releaseConnection = null; + + HashSet devicesTried = new HashSet(); + + private boolean getDeviceTried(String connection) { + synchronized (devicesTried) { + return devicesTried.contains(connection); + } + } + private void addDeviceTried(String connection) { + synchronized (devicesTried) { + devicesTried.add(connection); + } + } + private void removeDeviceTried(String connection) { + synchronized (devicesTried) { + devicesTried.remove(connection); + } + } + + public SharedResourceRunner(Implementation impl) { + this.impl = impl; + } + + public SharedResourceRunner.Resource getShared(AbstractGraphicsDevice device) { + String connection = device.getConnection(); + return impl.mapGet(connection); + } + + public SharedResourceRunner.Resource getOrCreateShared(AbstractGraphicsDevice device) { + String connection = device.getConnection(); + SharedResourceRunner.Resource sr = impl.mapGet(connection); + + if (null == sr && !getDeviceTried(connection)) { + addDeviceTried(connection); + if (DEBUG) { + System.err.println("getOrCreateShared() " + connection + ": trying"); + } + doAndWait(connection, null); + sr = impl.mapGet(connection); + if (DEBUG) { + Throwable t = new Throwable("getOrCreateSharedl() " + connection + ": done"); + t.printStackTrace(); + } + } + return sr; + } + + public SharedResourceRunner.Resource releaseShared(AbstractGraphicsDevice device) { + String connection = device.getConnection(); + SharedResourceRunner.Resource sr = impl.mapGet(connection); + + if (null != sr) { + removeDeviceTried(connection); + if (DEBUG) { + System.err.println("releaseShared() " + connection + ": trying"); + } + doAndWait(null, connection); + if (DEBUG) { + Throwable t = new Throwable("releaseSharedl() " + connection + ": done"); + t.printStackTrace(); + } + } + return sr; + } + + private final void doAndWait(String initConnection, String releaseConnection) { + // wait until thread becomes ready to init new device, + // pass the device and release the sync + String threadName = Thread.currentThread().getName(); + if (DEBUG) { + System.err.println(threadName + " doAndWait START init: " + initConnection + ", release: "+releaseConnection); + } + synchronized (this) { + while (!ready) { + try { + this.wait(); + } catch (InterruptedException ex) { + } + } + if (DEBUG) { + System.err.println(threadName + " initializeAndWait set command init: " + initConnection + ", release: "+releaseConnection); + } + this.initConnection = initConnection; + this.releaseConnection = releaseConnection; + this.notifyAll(); + + // wait until thread has init/released the device + while (!ready || null != this.initConnection || null != this.releaseConnection) { + try { + this.wait(); + } catch (InterruptedException ex) { + } + } + if (DEBUG) { + System.err.println(threadName + " initializeAndWait END init: " + initConnection + ", release: "+releaseConnection); + } + } + // done + } + + public final void releaseAndWait() { + synchronized (this) { + shouldRelease = true; + this.notifyAll(); + + while (!released) { + try { + this.wait(); + } catch (InterruptedException ex) { + } + } + } + } + + public final void run() { + String threadName = Thread.currentThread().getName(); + + if (DEBUG) { + System.err.println(threadName + " STARTED"); + } + + synchronized (this) { + while (!shouldRelease) { + try { + // wait for stop or init + ready = true; + if (DEBUG) { + System.err.println(threadName + " -> ready"); + } + notifyAll(); + this.wait(); + } catch (InterruptedException ex) { } + ready = false; + + if (!shouldRelease) { + if (DEBUG) { + System.err.println(threadName + " woke up for device connection init: " + initConnection + + ", release: " + releaseConnection); + } + if(null != initConnection) { + if (DEBUG) { + System.err.println(threadName + " create Shared for: " + initConnection); + } + Resource sr = impl.createSharedResource(initConnection); + if (null != sr) { + impl.mapPut(initConnection, sr); + } + } + if(null != releaseConnection) { + if (DEBUG) { + System.err.println(threadName + " release Shared for: " + releaseConnection); + } + Resource sr = impl.mapPut(releaseConnection, null); + if (null != sr) { + impl.releaseSharedResource(sr); + } + } + } + initConnection = null; + releaseConnection = null; + } + + if (DEBUG) { + System.err.println(threadName + " release START"); + } + + releaseSharedResources(); + + if (DEBUG) { + System.err.println(threadName + " release END"); + } + + released = true; + ready = false; + notifyAll(); + } + } + + private void releaseSharedResources() { + Collection/*<Resource>*/ sharedResources = impl.mapValues(); + for (Iterator iter = sharedResources.iterator(); iter.hasNext();) { + Resource sr = (Resource) iter.next(); + impl.releaseSharedResource(sr); + } + impl.clear(); + } +} diff --git a/src/jogl/classes/jogamp/opengl/SystemUtil.java b/src/jogl/classes/jogamp/opengl/SystemUtil.java new file mode 100644 index 000000000..befe1a315 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/SystemUtil.java @@ -0,0 +1,18 @@ +package jogamp.opengl; + +public class SystemUtil { + + private static volatile boolean getenvSupported = true; + /** Wrapper for System.getenv(), which doesn't work on platforms + earlier than JDK 5 */ + public static String getenv(String variableName) { + if (getenvSupported) { + try { + return System.getenv(variableName); + } catch (Error e) { + getenvSupported = false; + } + } + return null; + } +} diff --git a/src/jogl/classes/jogamp/opengl/ThreadingImpl.java b/src/jogl/classes/jogamp/opengl/ThreadingImpl.java new file mode 100644 index 000000000..67a950185 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/ThreadingImpl.java @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.opengl; + +import java.lang.reflect.InvocationTargetException; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +/** Implementation of the {@link javax.media.opengl.Threading} class. */ + +public class ThreadingImpl { + public static final int AWT = 1; + public static final int WORKER = 2; + + protected static final boolean DEBUG = Debug.debug("Threading"); + + private static boolean singleThreaded = true; + private static int mode; + private static boolean hasAWT; + // We need to know whether we're running on X11 platforms to change + // our behavior when the Java2D/JOGL bridge is active + private static boolean _isX11; + + private static final ThreadingPlugin threadingPlugin; + + static { + Object threadingPluginTmp = + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String workaround = Debug.getProperty("jogl.1thread", true); + ClassLoader cl = ThreadingImpl.class.getClassLoader(); + // Default to using the AWT thread on all platforms except + // Windows. On OS X there is instability apparently due to + // using the JAWT on non-AWT threads. On X11 platforms there + // are potential deadlocks which can be caused if the AWT + // EventQueue thread hands work off to the GLWorkerThread + // while holding the AWT lock. The optimization of + // makeCurrent / release calls isn't worth these stability + // problems. + hasAWT = GLProfile.isAWTAvailable(); + + String osType = NativeWindowFactory.getNativeWindowType(false); + _isX11 = NativeWindowFactory.TYPE_X11.equals(osType); + + int defaultMode = ( hasAWT ? AWT : WORKER ); + + mode = defaultMode; + if (workaround != null) { + workaround = workaround.toLowerCase(); + if (workaround.equals("true") || + workaround.equals("auto")) { + // Nothing to do; singleThreaded and mode already set up + } else if (workaround.equals("worker")) { + singleThreaded = true; + mode = WORKER; + } else if (hasAWT && workaround.equals("awt")) { + singleThreaded = true; + mode = AWT; + } else { + singleThreaded = false; + } + } + printWorkaroundNotice(); + + Object threadingPluginObj=null; + if(hasAWT) { + // try to fetch the AWTThreadingPlugin + Exception error=null; + try { + threadingPluginObj = ReflectionUtil.createInstance("jogamp.opengl.awt.AWTThreadingPlugin", cl); + } catch (JogampRuntimeException jre) { error = jre; } + if(AWT == mode && null==threadingPluginObj) { + throw new GLException("Mode is AWT, but class 'jogamp.opengl.awt.AWTThreadingPlugin' is not available", error); + } + } + return threadingPluginObj; + } + }); + threadingPlugin = (ThreadingPlugin) threadingPluginTmp; + if(DEBUG) { + System.err.println("Threading: hasAWT "+hasAWT+", mode "+((mode==AWT)?"AWT":"WORKER")+", plugin "+threadingPlugin); + } + } + + /** No reason to ever instantiate this class */ + private ThreadingImpl() {} + + public static boolean isX11() { return _isX11; } + public static int getMode() { return mode; } + + /** If an implementation of the javax.media.opengl APIs offers a + multithreading option but the default behavior is single-threading, + this API provides a mechanism for end users to disable single-threading + in this implementation. Users are strongly discouraged from + calling this method unless they are aware of all of the + consequences and are prepared to enforce some amount of + threading restrictions in their applications. Disabling + single-threading, for example, may have unintended consequences + on GLAutoDrawable implementations such as GLCanvas, GLJPanel and + GLPbuffer. Currently there is no supported way to re-enable it + once disabled, partly to discourage careless use of this + method. This method should be called as early as possible in an + application. */ + public static void disableSingleThreading() { + singleThreaded = false; + if (Debug.verbose()) { + System.err.println("Application forced disabling of single-threading of javax.media.opengl implementation"); + } + } + + /** Indicates whether OpenGL work is being automatically forced to a + single thread in this implementation. */ + public static boolean isSingleThreaded() { + return singleThreaded; + } + + /** Indicates whether the current thread is the single thread on + which this implementation of the javax.media.opengl APIs + performs all of its OpenGL-related work. This method should only + be called if the single-thread model is in effect. */ + public static boolean isOpenGLThread() throws GLException { + if (!isSingleThreaded()) { + throw new GLException("Should only call this in single-threaded mode"); + } + + if(null!=threadingPlugin) { + return threadingPlugin.isOpenGLThread(); + } + + switch (mode) { + case AWT: + throw new InternalError(); + case WORKER: + return GLWorkerThread.isWorkerThread(); + default: + throw new InternalError("Illegal single-threading mode " + mode); + } + } + + /** Executes the passed Runnable on the single thread used for all + OpenGL work in this javax.media.opengl API implementation. It is + not specified exactly which thread is used for this + purpose. This method should only be called if the single-thread + model is in use and if the current thread is not the OpenGL + thread (i.e., if <code>isOpenGLThread()</code> returns + false). It is up to the end user to check to see whether the + current thread is the OpenGL thread and either execute the + Runnable directly or perform the work inside it. */ + public static void invokeOnOpenGLThread(Runnable r) throws GLException { + if (!isSingleThreaded()) { + throw new GLException ("Should only call this in single-threaded mode"); + } + + if (isOpenGLThread()) { + throw new GLException ("Should only call this from other threads than the OpenGL thread"); + } + + if(null!=threadingPlugin) { + threadingPlugin.invokeOnOpenGLThread(r); + return; + } + + switch (mode) { + case AWT: + throw new InternalError(); + + case WORKER: + GLWorkerThread.start(); // singleton start via volatile-dbl-checked-locking + try { + GLWorkerThread.invokeAndWait(r); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (InterruptedException e) { + throw new GLException(e); + } + break; + + default: + throw new InternalError("Illegal single-threading mode " + mode); + } + } + + /** This is a workaround for AWT-related deadlocks which only seem + to show up in the context of applets */ + public static boolean isAWTMode() { + return (mode == AWT); + } + + private static void printWorkaroundNotice() { + if (singleThreaded && Debug.verbose()) { + System.err.println("Using " + + (mode == AWT ? "AWT" : "OpenGL worker") + + " thread for performing OpenGL work in javax.media.opengl implementation"); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/ThreadingPlugin.java b/src/jogl/classes/jogamp/opengl/ThreadingPlugin.java new file mode 100644 index 000000000..0b0748b59 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/ThreadingPlugin.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl; + +import javax.media.opengl.*; + +public interface ThreadingPlugin { + /** Indicates whether the current thread is the single thread on + which this implementation of the javax.media.opengl APIs + performs all of its OpenGL-related work. This method should only + be called if the single-thread model is in effect. */ + public boolean isOpenGLThread() throws GLException; + + /** Executes the passed Runnable on the single thread used for all + OpenGL work in this javax.media.opengl API implementation. It is + not specified exactly which thread is used for this + purpose. This method should only be called if the single-thread + model is in use and if the current thread is not the OpenGL + thread (i.e., if <code>isOpenGLThread()</code> returns + false). It is up to the end user to check to see whether the + current thread is the OpenGL thread and either execute the + Runnable directly or perform the work inside it. */ + public void invokeOnOpenGLThread(Runnable r) throws GLException; +} + diff --git a/src/jogl/classes/jogamp/opengl/awt/AWTThreadingPlugin.java b/src/jogl/classes/jogamp/opengl/awt/AWTThreadingPlugin.java new file mode 100644 index 000000000..dd493f5ee --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/awt/AWTThreadingPlugin.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.awt; + +import javax.media.opengl.*; + +import java.awt.event.*; + +import java.awt.EventQueue; +import java.lang.reflect.InvocationTargetException; + +import jogamp.opengl.*; + +public class AWTThreadingPlugin implements ThreadingPlugin { + + public AWTThreadingPlugin() {} + + public boolean isOpenGLThread() throws GLException { + switch (ThreadingImpl.getMode()) { + case ThreadingImpl.AWT: + // FIXME: See the FIXME below in 'invokeOnOpenGLThread' + if (Java2D.isOGLPipelineActive() && !ThreadingImpl.isX11()) { + return Java2D.isQueueFlusherThread(); + } else { + return EventQueue.isDispatchThread(); + } + case ThreadingImpl.WORKER: + if (Java2D.isOGLPipelineActive()) { + // FIXME: ideally only the QFT would be considered to be the + // "OpenGL thread", but we can not currently run all of + // JOGL's OpenGL work on that thread. See the FIXME in + // invokeOnOpenGLThread. + return (Java2D.isQueueFlusherThread() || + (ThreadingImpl.isX11() && GLWorkerThread.isWorkerThread())); + } else { + return GLWorkerThread.isWorkerThread(); + } + default: + throw new InternalError("Illegal single-threading mode " + ThreadingImpl.getMode()); + } + } + + public void invokeOnOpenGLThread(Runnable r) throws GLException { + switch (ThreadingImpl.getMode()) { + case ThreadingImpl.AWT: + // FIXME: ideally should run all OpenGL work on the Java2D QFT + // thread when it's enabled, but unfortunately there are + // deadlock issues on X11 platforms when making our + // heavyweight OpenGL contexts current on the QFT because we + // perform the JAWT lock inside the makeCurrent() + // implementation, which attempts to grab the AWT lock on the + // QFT which is not allowed. For now, on X11 platforms, + // continue to perform this work on the EDT. + if (Java2D.isOGLPipelineActive() && !ThreadingImpl.isX11()) { + Java2D.invokeWithOGLContextCurrent(null, r); + } else { + try { + EventQueue.invokeAndWait(r); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (InterruptedException e) { + throw new GLException(e); + } + } + break; + + case ThreadingImpl.WORKER: + GLWorkerThread.start(); // singleton start via volatile-dbl-checked-locking + try { + GLWorkerThread.invokeAndWait(r); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (InterruptedException e) { + throw new GLException(e); + } + break; + + default: + throw new InternalError("Illegal single-threading mode " + ThreadingImpl.getMode()); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/awt/AWTUtil.java b/src/jogl/classes/jogamp/opengl/awt/AWTUtil.java new file mode 100644 index 000000000..51143ab51 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/awt/AWTUtil.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package jogamp.opengl.awt; + +import jogamp.nativewindow.jawt.*; + +import javax.media.opengl.*; + +import java.lang.reflect.*; +import java.awt.GraphicsEnvironment; + +public class AWTUtil { + // See whether we're running in headless mode + private static boolean headlessMode; + private static Class j2dClazz = null; + private static Method isOGLPipelineActive = null; + private static Method isQueueFlusherThread = null; + private static boolean j2dOk = false; + + static { + lockedToolkit = false; + headlessMode = GraphicsEnvironment.isHeadless(); + if(!headlessMode) { + try { + j2dClazz = Class.forName("jogamp.opengl.awt.Java2D"); + isOGLPipelineActive = j2dClazz.getMethod("isOGLPipelineActive", (Class[])null); + isQueueFlusherThread = j2dClazz.getMethod("isQueueFlusherThread", (Class[])null); + j2dOk = true; + } catch (Exception e) {} + } + } + + private static boolean lockedToolkit; + + public static synchronized void lockToolkit() throws GLException { + if (lockedToolkit) { + throw new GLException("Toolkit already locked"); + } + lockedToolkit = true; + + if (headlessMode) { + // Workaround for running (to some degree) in headless + // environments but still supporting rendering via pbuffers + // For full correctness, would need to implement a Lock class + return; + } + + if(j2dOk) { + try { + if( !((Boolean)isOGLPipelineActive.invoke(null, (Object[])null)).booleanValue() || + !((Boolean)isQueueFlusherThread.invoke(null, (Object[])null)).booleanValue() ) { + JAWTUtil.lockToolkit(); + } + } catch (Exception e) { j2dOk=false; } + } + if(!j2dOk) { + JAWTUtil.lockToolkit(); + } + } + + public static synchronized void unlockToolkit() { + if (lockedToolkit) { + lockedToolkit = false; + if (headlessMode) { + // Workaround for running (to some degree) in headless + // environments but still supporting rendering via pbuffers + // For full correctness, would need to implement a Lock class + return; + } + + if(j2dOk) { + try { + if( !((Boolean)isOGLPipelineActive.invoke(null, (Object[])null)).booleanValue() || + !((Boolean)isQueueFlusherThread.invoke(null, (Object[])null)).booleanValue() ) { + JAWTUtil.unlockToolkit(); + } + } catch (Exception e) { j2dOk=false; } + } + if(!j2dOk) { + JAWTUtil.unlockToolkit(); + } + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/awt/Java2D.java b/src/jogl/classes/jogamp/opengl/awt/Java2D.java new file mode 100644 index 000000000..e240169e1 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/awt/Java2D.java @@ -0,0 +1,569 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.awt; + +import jogamp.opengl.*; + +import java.awt.*; +import java.awt.image.*; +import java.lang.reflect.*; +import java.security.*; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; + +/** Defines integration with the Java2D OpenGL pipeline. This + integration is only supported in 1.6 and is highly experimental. */ + +public class Java2D { + private static boolean DEBUG = Debug.debug("Java2D"); + private static boolean VERBOSE = Debug.verbose(); + private static boolean isHeadless; + private static boolean isOGLPipelineActive; + private static Method invokeWithOGLContextCurrentMethod; + private static Method isQueueFlusherThreadMethod; + private static Method getOGLViewportMethod; + private static Method getOGLScissorBoxMethod; + private static Method getOGLSurfaceIdentifierMethod; + // This one is currently optional and is only in very recent Mustang builds + private static Method getOGLTextureTypeMethod; + + // The following methods and fields are needed for proper support of + // Frame Buffer Objects in the Java2D/OpenGL pipeline + // (-Dsun.java2d.opengl.fbobject=true) + private static boolean fbObjectSupportInitialized; + private static Method invokeWithOGLSharedContextCurrentMethod; + private static Method getOGLSurfaceTypeMethod; + + // Publicly-visible constants for OpenGL surface types + public static final int UNDEFINED = getOGLUtilitiesIntField("UNDEFINED"); + public static final int WINDOW = getOGLUtilitiesIntField("WINDOW"); + public static final int PBUFFER = getOGLUtilitiesIntField("PBUFFER"); + public static final int TEXTURE = getOGLUtilitiesIntField("TEXTURE"); + public static final int FLIP_BACKBUFFER = getOGLUtilitiesIntField("FLIP_BACKBUFFER"); + public static final int FBOBJECT = getOGLUtilitiesIntField("FBOBJECT"); + + // If FBOs are enabled in the Java2D/OpenGL pipeline, all contexts + // created by JOGL must share textures and display lists with the + // Java2D contexts in order to access the frame buffer object for + // potential rendering, and to simultaneously support sharing of + // textures and display lists with one another. Java2D has the + // notion of a single shared context with which all other contexts + // (on the same display device?) share textures and display lists; + // this is an approximation to that notion which will be refined + // later. + private static boolean initializedJ2DFBOShareContext; + private static GLContext j2dFBOShareContext; + + // Accessors for new methods in sun.java2d.opengl.CGLSurfaceData + // class on OS X for enabling bridge + // public static long createOGLContextOnSurface(Graphics g, long ctx); + // public static boolean makeOGLContextCurrentOnSurface(Graphics g, long ctx); + // public static void destroyOGLContext(long ctx); + private static Method createOGLContextOnSurfaceMethod; + private static Method makeOGLContextCurrentOnSurfaceMethod; + private static Method destroyOGLContextMethod; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + if (DEBUG && VERBOSE) { + System.err.println("Checking for Java2D/OpenGL support"); + } + try { + isHeadless = true; + // Figure out whether the default graphics configuration is an + // OpenGL graphics configuration + GraphicsConfiguration cfg = + GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice(). + getDefaultConfiguration(); + // If we get here, we aren't running in headless mode + isHeadless = false; + String name = cfg.getClass().getName(); + if (DEBUG && VERBOSE) { + System.err.println("Java2D support: default GraphicsConfiguration = " + name); + } + isOGLPipelineActive = (name.startsWith("sun.java2d.opengl")); + + if (isOGLPipelineActive) { + try { + // Try to get methods we need to integrate + Class utils = Class.forName("sun.java2d.opengl.OGLUtilities"); + invokeWithOGLContextCurrentMethod = utils.getDeclaredMethod("invokeWithOGLContextCurrent", + new Class[] { + Graphics.class, + Runnable.class + }); + invokeWithOGLContextCurrentMethod.setAccessible(true); + + isQueueFlusherThreadMethod = utils.getDeclaredMethod("isQueueFlusherThread", + new Class[] {}); + isQueueFlusherThreadMethod.setAccessible(true); + + getOGLViewportMethod = utils.getDeclaredMethod("getOGLViewport", + new Class[] { + Graphics.class, + Integer.TYPE, + Integer.TYPE + }); + getOGLViewportMethod.setAccessible(true); + + getOGLScissorBoxMethod = utils.getDeclaredMethod("getOGLScissorBox", + new Class[] { + Graphics.class + }); + getOGLScissorBoxMethod.setAccessible(true); + + getOGLSurfaceIdentifierMethod = utils.getDeclaredMethod("getOGLSurfaceIdentifier", + new Class[] { + Graphics.class + }); + getOGLSurfaceIdentifierMethod.setAccessible(true); + + // Try to get additional methods required for proper FBO support + fbObjectSupportInitialized = true; + try { + invokeWithOGLSharedContextCurrentMethod = utils.getDeclaredMethod("invokeWithOGLSharedContextCurrent", + new Class[] { + GraphicsConfiguration.class, + Runnable.class + }); + invokeWithOGLSharedContextCurrentMethod.setAccessible(true); + + getOGLSurfaceTypeMethod = utils.getDeclaredMethod("getOGLSurfaceType", + new Class[] { + Graphics.class + }); + getOGLSurfaceTypeMethod.setAccessible(true); + } catch (Exception e) { + fbObjectSupportInitialized = false; + if (DEBUG && VERBOSE) { + e.printStackTrace(); + System.err.println("Info: Disabling Java2D/JOGL FBO support"); + } + } + + // Try to get an additional method for FBO support in recent Mustang builds + try { + getOGLTextureTypeMethod = utils.getDeclaredMethod("getOGLTextureType", + new Class[] { + Graphics.class + }); + getOGLTextureTypeMethod.setAccessible(true); + } catch (Exception e) { + if (DEBUG && VERBOSE) { + e.printStackTrace(); + System.err.println("Info: GL_ARB_texture_rectangle FBO support disabled"); + } + } + + // Try to set up APIs for enabling the bridge on OS X, + // where it isn't possible to create generalized + // external GLDrawables + Class cglSurfaceData = null; + try { + cglSurfaceData = Class.forName("sun.java2d.opengl.CGLSurfaceData"); + } catch (Exception e) { + if (DEBUG && VERBOSE) { + e.printStackTrace(); + System.err.println("Info: Unable to find class sun.java2d.opengl.CGLSurfaceData for OS X"); + } + } + if (cglSurfaceData != null) { + // FIXME: for now, assume that FBO support is not enabled on OS X + fbObjectSupportInitialized = false; + + // We need to find these methods in order to make the bridge work on OS X + createOGLContextOnSurfaceMethod = cglSurfaceData.getDeclaredMethod("createOGLContextOnSurface", + new Class[] { + Graphics.class, + Long.TYPE + }); + createOGLContextOnSurfaceMethod.setAccessible(true); + + makeOGLContextCurrentOnSurfaceMethod = cglSurfaceData.getDeclaredMethod("makeOGLContextCurrentOnSurface", + new Class[] { + Graphics.class, + Long.TYPE + }); + makeOGLContextCurrentOnSurfaceMethod.setAccessible(true); + + destroyOGLContextMethod = cglSurfaceData.getDeclaredMethod("destroyOGLContext", + new Class[] { + Long.TYPE + }); + destroyOGLContextMethod.setAccessible(true); + } + } catch (Exception e) { + if (DEBUG && VERBOSE) { + e.printStackTrace(); + System.err.println("Info: Disabling Java2D/JOGL integration"); + } + isOGLPipelineActive = false; + } + } + } catch (HeadlessException e) { + // The AWT is running in headless mode, so the Java 2D / JOGL bridge is clearly disabled + } + + if (DEBUG) { + System.err.println("JOGL/Java2D integration " + (isOGLPipelineActive ? "enabled" : "disabled")); + } + return null; + } + }); + } + + public static boolean isOGLPipelineActive() { + return isOGLPipelineActive; + } + + public static boolean isFBOEnabled() { + return fbObjectSupportInitialized; + } + + public static boolean isQueueFlusherThread() { + checkActive(); + + try { + return ((Boolean) isQueueFlusherThreadMethod.invoke(null, (Object[])null)).booleanValue(); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** Makes current the OpenGL context associated with the passed + Graphics object and runs the given Runnable on the Queue + Flushing Thread in one atomic action. */ + public static void invokeWithOGLContextCurrent(Graphics g, Runnable r) throws GLException { + checkActive(); + + try { + // FIXME: this may need adjustment + // This seems to be needed in many applications which don't + // initialize an OpenGL context before this and which would + // otherwise cause initFBOShareContext to be called from the + // Queue Flusher Thread, which isn't allowed + initFBOShareContext(GraphicsEnvironment. + getLocalGraphicsEnvironment(). + getDefaultScreenDevice()); + + AWTUtil.lockToolkit(); + try { + invokeWithOGLContextCurrentMethod.invoke(null, new Object[] {g, r}); + } finally { + AWTUtil.unlockToolkit(); + } + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** Makes current the "shared" OpenGL context associated with the + given GraphicsConfiguration object, allowing JOGL to share + server-side OpenGL objects like textures and display lists with + this context when necessary. This is needed when Java2D's FBO + support is enabled, because in order to render into that FBO, + JOGL must share textures and display lists with it. Returns + false if the passed GraphicsConfiguration was not an OpenGL + GraphicsConfiguration. */ + public static boolean invokeWithOGLSharedContextCurrent(GraphicsConfiguration g, Runnable r) throws GLException { + checkActive(); + + try { + AWTUtil.lockToolkit(); + try { + return ((Boolean) invokeWithOGLSharedContextCurrentMethod.invoke(null, new Object[] {g, r})).booleanValue(); + } finally { + AWTUtil.unlockToolkit(); + } + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** Returns the OpenGL viewport associated with the given Graphics + object, assuming that the Graphics object is associated with a + component of the specified width and height. The user should + call glViewport() with the returned rectangle's bounds in order + to get correct rendering results. Should only be called from the + Queue Flusher Thread. */ + public static Rectangle getOGLViewport(Graphics g, + int componentWidth, + int componentHeight) { + checkActive(); + + try { + return (Rectangle) getOGLViewportMethod.invoke(null, new Object[] {g, + new Integer(componentWidth), + new Integer(componentHeight)}); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** Returns the OpenGL scissor region associated with the given + Graphics object, taking into account all clipping regions, etc. + To avoid destroying Java2D's previous rendering results, this + method should be called and the resulting rectangle's bounds + passed to a call to glScissor(). Should only be called from the + Queue Flusher Thread. */ + public static Rectangle getOGLScissorBox(Graphics g) { + checkActive(); + + try { + return (Rectangle) getOGLScissorBoxMethod.invoke(null, new Object[] {g}); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** Returns an opaque "surface identifier" associated with the given + Graphics object. If this changes from invocation to invocation, + the underlying OpenGL drawable for the Graphics object has + changed and a new external GLDrawable and GLContext should be + created (and the old ones destroyed). Should only be called from + the Queue Flusher Thread.*/ + public static Object getOGLSurfaceIdentifier(Graphics g) { + checkActive(); + + try { + return getOGLSurfaceIdentifierMethod.invoke(null, new Object[] {g}); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** Returns the underlying surface type for the given Graphics + object. This indicates, in particular, whether Java2D is + currently rendering into a pbuffer or FBO. */ + public static int getOGLSurfaceType(Graphics g) { + checkActive(); + + try { + // FIXME: fallback path for pre-b73 (?) Mustang builds -- remove + // once fbobject support is in OGLUtilities + if (!fbObjectSupportInitialized) { + return 0; + } + + return ((Integer) getOGLSurfaceTypeMethod.invoke(null, new Object[] { g })).intValue(); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** Returns the underlying texture target of the given Graphics + object assuming it is rendering to an FBO. Returns either + GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_ARB. */ + public static int getOGLTextureType(Graphics g) { + checkActive(); + + if (getOGLTextureTypeMethod == null) { + return GL.GL_TEXTURE_2D; + } + + try { + return ((Integer) getOGLTextureTypeMethod.invoke(null, new Object[] { g })).intValue(); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** Returns either the given GLContext or a substitute one with + which clients should share textures and display lists. Needed + when the Java2D/OpenGL pipeline is active and FBOs are being + used for rendering. FIXME: may need to alter the API in the + future to indicate which GraphicsDevice the source context is + associated with. */ + public static GLContext filterShareContext(GLContext shareContext) { + if (isHeadless) + return shareContext; + + // FIXME: this may need adjustment + initFBOShareContext(GraphicsEnvironment. + getLocalGraphicsEnvironment(). + getDefaultScreenDevice()); + if (j2dFBOShareContext != null) { + return j2dFBOShareContext; + } + return shareContext; + } + + /** Returns the GLContext associated with the Java2D "share + context", with which all contexts created by JOGL must share + textures and display lists when the FBO option is enabled for + the Java2D/OpenGL pipeline. */ + public static GLContext getShareContext(GraphicsDevice device) { + initFBOShareContext(device); + // FIXME: for full generality probably need to have multiple of + // these, one per GraphicsConfiguration seen? + return j2dFBOShareContext; + } + + //---------------------------------------------------------------------- + // Mac OS X-specific methods + // + + /** (Mac OS X-specific) Creates a new OpenGL context on the surface + associated with the given Graphics object, sharing textures and + display lists with the specified (CGLContextObj) share context. */ + public static long createOGLContextOnSurface(Graphics g, long shareCtx) { + checkActive(); + + try { + return ((Long) createOGLContextOnSurfaceMethod.invoke(null, new Object[] { g, new Long(shareCtx) })).longValue(); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** (Mac OS X-specific) Makes the given OpenGL context current on + the surface associated with the given Graphics object. */ + public static boolean makeOGLContextCurrentOnSurface(Graphics g, long ctx) { + checkActive(); + + try { + return ((Boolean) makeOGLContextCurrentOnSurfaceMethod.invoke(null, new Object[] { g, new Long(ctx) })).booleanValue(); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** (Mac OS X-specific) Destroys the given OpenGL context. */ + public static void destroyOGLContext(long ctx) { + checkActive(); + + try { + destroyOGLContextMethod.invoke(null, new Object[] { new Long(ctx) }); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private static void checkActive() { + if (!isOGLPipelineActive()) { + throw new GLException("Java2D OpenGL pipeline not active (or necessary support not present)"); + } + } + + private static int getOGLUtilitiesIntField(final String name) { + Integer i = (Integer) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + Class utils = Class.forName("sun.java2d.opengl.OGLUtilities"); + Field f = utils.getField(name); + f.setAccessible(true); + return f.get(null); + } catch (Exception e) { + if (DEBUG && VERBOSE) { + e.printStackTrace(); + } + return null; + } + } + }); + if (i == null) + return 0; + if (DEBUG && VERBOSE) { + System.err.println("OGLUtilities." + name + " = " + i.intValue()); + } + return i.intValue(); + } + + private static void initFBOShareContext(final GraphicsDevice device) { + // Note 1: this must not be done in the static initalizer due to + // deadlock problems. + + // Note 2: the first execution of this method must not be from the + // Java2D Queue Flusher Thread. + + if (isOGLPipelineActive() && + isFBOEnabled() && + !initializedJ2DFBOShareContext) { + + // FIXME: this technique is probably not adequate in multi-head + // situations. Ideally we would keep track of a given share + // context on a per-GraphicsConfiguration basis or something + // similar rather than keeping one share context in a global + // variable. + initializedJ2DFBOShareContext = true; + if (DEBUG) { + System.err.println("Starting initialization of J2D FBO share context"); + } + invokeWithOGLSharedContextCurrent(device.getDefaultConfiguration(), new Runnable() { + public void run() { + j2dFBOShareContext = GLDrawableFactory.getFactory(GLProfile.getDefault(GLProfile.getDefaultDesktopDevice())).createExternalGLContext(); + } + }); + if (DEBUG) { + System.err.println("Ending initialization of J2D FBO share context"); + } + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/awt/Java2DGLContext.java b/src/jogl/classes/jogamp/opengl/awt/Java2DGLContext.java new file mode 100644 index 000000000..4a5b1db54 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/awt/Java2DGLContext.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.awt; + +import jogamp.opengl.*; +import java.awt.Graphics; + +/** Provides a construct by which the shared GLJPanel code can + * interact with a few methods in the Mac OS X-specific Java2D/JOGL + * bridge implementation. + */ + +public interface Java2DGLContext { + public void setGraphics(Graphics g); +} diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java new file mode 100644 index 000000000..864b9583d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.egl; + +import javax.media.opengl.*; +import jogamp.opengl.*; +import com.jogamp.gluegen.runtime.ProcAddressTable; +import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver; +import java.nio.*; +import java.util.*; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; + +public abstract class EGLContext extends GLContextImpl { + private boolean eglQueryStringInitialized; + private boolean eglQueryStringAvailable; + private EGLExt eglExt; + // Table that holds the addresses of the native C-language entry points for + // EGL extension functions. + private EGLExtProcAddressTable eglExtProcAddressTable; + + EGLContext(GLDrawableImpl drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + public Object getPlatformGLExtensions() { + return getEGLExt(); + } + + public EGLExt getEGLExt() { + if (eglExt == null) { + eglExt = new EGLExtImpl(this); + } + return eglExt; + } + + public final ProcAddressTable getPlatformExtProcAddressTable() { + return eglExtProcAddressTable; + } + + public final EGLExtProcAddressTable getEGLExtProcAddressTable() { + return eglExtProcAddressTable; + } + + protected Map/*<String, String>*/ getFunctionNameMap() { return null; } + + protected Map/*<String, String>*/ getExtensionNameMap() { return null; } + + public final boolean isGLReadDrawableAvailable() { + return true; + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + if(EGL.EGL_NO_DISPLAY==((EGLDrawable)drawable).getDisplay() ) { + throw new GLException("drawable not properly initialized, NO DISPLAY: "+drawable); + } + if (EGL.eglGetCurrentContext() != contextHandle) { + if (!EGL.eglMakeCurrent(((EGLDrawable)drawable).getDisplay(), + drawable.getHandle(), + drawableRead.getHandle(), + contextHandle)) { + throw new GLException("Error making context 0x" + + Long.toHexString(contextHandle) + " current: error code " + EGL.eglGetError()); + } + } + } + + protected void releaseImpl() throws GLException { + if (!EGL.eglMakeCurrent(((EGLDrawable)drawable).getDisplay(), + EGL.EGL_NO_SURFACE, + EGL.EGL_NO_SURFACE, + EGL.EGL_NO_CONTEXT)) { + throw new GLException("Error freeing OpenGL context 0x" + + Long.toHexString(contextHandle) + ": error code " + EGL.eglGetError()); + } + } + + protected void destroyImpl() throws GLException { + if (!EGL.eglDestroyContext(((EGLDrawable)drawable).getDisplay(), contextHandle)) { + throw new GLException("Error destroying OpenGL context 0x" + + Long.toHexString(contextHandle) + ": error code " + EGL.eglGetError()); + } + } + + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + return 0; // FIXME + } + + protected void destroyContextARBImpl(long _context) { + // FIXME + } + + protected boolean createImpl() throws GLException { + long eglDisplay = ((EGLDrawable)drawable).getDisplay(); + EGLGraphicsConfiguration config = ((EGLDrawable)drawable).getGraphicsConfiguration(); + GLProfile glProfile = drawable.getGLProfile(); + long eglConfig = config.getNativeConfig(); + long shareWith = EGL.EGL_NO_CONTEXT; + + if (eglDisplay == 0) { + throw new GLException("Error: attempted to create an OpenGL context without a display connection"); + } + if (eglConfig == 0) { + throw new GLException("Error: attempted to create an OpenGL context without a graphics configuration"); + } + + try { + // might be unavailable on EGL < 1.2 + if(!EGL.eglBindAPI(EGL.EGL_OPENGL_ES_API)) { + throw new GLException("eglBindAPI to ES failed , error 0x"+Integer.toHexString(EGL.eglGetError())); + } + } catch (GLException glex) { + if (DEBUG) { + glex.printStackTrace(); + } + } + + EGLContext other = (EGLContext) GLContextShareSet.getShareContext(this); + if (other != null) { + shareWith = other.getHandle(); + if (shareWith == 0) { + throw new GLException("GLContextShareSet returned an invalid OpenGL context"); + } + } + + int[] contextAttrs = new int[] { + EGL.EGL_CONTEXT_CLIENT_VERSION, -1, + EGL.EGL_NONE + }; + if (glProfile.usesNativeGLES2()) { + contextAttrs[1] = 2; + } else if (glProfile.usesNativeGLES1()) { + contextAttrs[1] = 1; + } else { + throw new GLException("Error creating OpenGL context - invalid GLProfile: "+glProfile); + } + contextHandle = EGL.eglCreateContext(eglDisplay, eglConfig, shareWith, contextAttrs, 0); + if (contextHandle == 0) { + throw new GLException("Error creating OpenGL context: eglDisplay 0x"+Long.toHexString(eglDisplay)+ + ", "+glProfile+", error 0x"+Integer.toHexString(EGL.eglGetError())); + } + GLContextShareSet.contextCreated(this); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Created OpenGL context 0x" + + Long.toHexString(contextHandle) + + ",\n\twrite surface 0x" + Long.toHexString(drawable.getHandle()) + + ",\n\tread surface 0x" + Long.toHexString(drawableRead.getHandle())+ + ",\n\t"+this+ + ",\n\tsharing with 0x" + Long.toHexString(shareWith)); + } + if (!EGL.eglMakeCurrent(((EGLDrawable)drawable).getDisplay(), + drawable.getHandle(), + drawableRead.getHandle(), + contextHandle)) { + throw new GLException("Error making context 0x" + + Long.toHexString(contextHandle) + " current: error code " + EGL.eglGetError()); + } + setGLFunctionAvailability(true, glProfile.usesNativeGLES2()?2:1, 0, CTX_PROFILE_ES|CTX_OPTION_ANY); + return true; + } + + protected final void updateGLXProcAddressTable() { + AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); + String key = adevice.getUniqueID(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Initializing EGLextension address table: "+key); + } + eglQueryStringInitialized = false; + eglQueryStringAvailable = false; + + EGLExtProcAddressTable table = null; + synchronized(mappedContextTypeObjectLock) { + table = (EGLExtProcAddressTable) mappedGLXProcAddress.get( key ); + } + if(null != table) { + eglExtProcAddressTable = table; + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext EGL ProcAddressTable reusing key("+key+") -> "+table.hashCode()); + } + } else { + if (eglExtProcAddressTable == null) { + // FIXME: cache ProcAddressTables by capability bits so we can + // share them among contexts with the same capabilities + eglExtProcAddressTable = new EGLExtProcAddressTable(new GLProcAddressResolver()); + } + resetProcAddressTable(getEGLExtProcAddressTable()); + synchronized(mappedContextTypeObjectLock) { + mappedGLXProcAddress.put(key, getEGLExtProcAddressTable()); + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext EGL ProcAddressTable mapping key("+key+") -> "+getEGLExtProcAddressTable().hashCode()); + } + } + } + } + + public synchronized String getPlatformExtensionsString() { + if (!eglQueryStringInitialized) { + eglQueryStringAvailable = + getDrawableImpl().getGLDynamicLookupHelper().dynamicLookupFunction("eglQueryString") != 0; + eglQueryStringInitialized = true; + } + if (eglQueryStringAvailable) { + String ret = EGL.eglQueryString(((EGLDrawable)drawable).getDisplay(), + EGL.EGL_EXTENSIONS); + if (DEBUG) { + System.err.println("!!! EGL extensions: " + ret); + } + return ret; + } else { + return ""; + } + } + + protected void setSwapIntervalImpl(int interval) { + if (EGL.eglSwapInterval(((EGLDrawable)drawable).getDisplay(), interval)) { + currentSwapInterval = interval ; + } + } + + public abstract void bindPbufferToTexture(); + + public abstract void releasePbufferFromTexture(); + + //---------------------------------------------------------------------- + // Currently unimplemented stuff + // + + protected void copyImpl(GLContext source, int mask) throws GLException { + throw new GLException("Not yet implemented"); + } + + + public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } +} diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java new file mode 100644 index 000000000..7ffbf9053 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.egl; + +import jogamp.opengl.GLDynamicLookupHelper; +import jogamp.opengl.GLDrawableImpl; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; +import javax.media.opengl.*; + +public abstract class EGLDrawable extends GLDrawableImpl { + protected boolean ownEGLDisplay = false; // for destruction + protected boolean ownEGLSurface = false; // for destruction + private EGLGraphicsConfiguration eglConfig; + protected long eglDisplay; + protected long eglSurface; + + protected EGLDrawable(EGLDrawableFactory factory, + NativeSurface component) throws GLException { + super(factory, component, false); + eglSurface=EGL.EGL_NO_SURFACE; + eglDisplay=0; + } + + public long getDisplay() { + return eglDisplay; + } + + public long getHandle() { + return eglSurface; + } + + public EGLGraphicsConfiguration getGraphicsConfiguration() { + return eglConfig; + } + + public GLCapabilitiesImmutable getChosenGLCapabilities() { + return (null==eglConfig)?super.getChosenGLCapabilities():(GLCapabilitiesImmutable)eglConfig.getChosenCapabilities(); + } + + public abstract GLContext createContext(GLContext shareWith); + + protected abstract long createSurface(long eglDpy, long eglNativeCfg, long surfaceHandle); + + private void recreateSurface() { + // create a new EGLSurface .. + if(EGL.EGL_NO_SURFACE!=eglSurface) { + EGL.eglDestroySurface(eglDisplay, eglSurface); + } + + if(DEBUG) { + System.err.println("createSurface using eglDisplay 0x"+Long.toHexString(eglDisplay)+", "+eglConfig); + } + + eglSurface = createSurface(eglDisplay, eglConfig.getNativeConfig(), surface.getSurfaceHandle()); + if (EGL.EGL_NO_SURFACE==eglSurface) { + throw new GLException("Creation of window surface failed: "+eglConfig+", error 0x"+Integer.toHexString(EGL.eglGetError())); + } + + if(DEBUG) { + System.err.println("setSurface using component: handle 0x"+Long.toHexString(surface.getSurfaceHandle())+" -> 0x"+Long.toHexString(eglSurface)); + } + } + + protected void setRealizedImpl() { + if (realized) { + AbstractGraphicsConfiguration aConfig = surface.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice aDevice = aConfig.getScreen().getDevice(); + if(aDevice instanceof EGLGraphicsDevice) { + if(DEBUG) { + System.err.println("EGLDrawable.setRealized: using existing EGL config: "+this); + } + // just fetch the data .. trust but verify .. + eglDisplay = aDevice.getHandle(); + if (eglDisplay == EGL.EGL_NO_DISPLAY) { + throw new GLException("Invalid EGL display in EGLGraphicsDevice from "+aDevice); + } + if(aConfig instanceof EGLGraphicsConfiguration) { + eglConfig = (EGLGraphicsConfiguration) aConfig; // done .. + if (null == eglConfig) { + throw new GLException("Null EGLGraphicsConfiguration from "+aConfig); + } + + int[] tmp = new int[1]; + if ( 0 != surface.getSurfaceHandle() && + EGL.eglQuerySurface(eglDisplay, surface.getSurfaceHandle(), EGL.EGL_CONFIG_ID, tmp, 0) ) { + // surface holds static EGLSurface + eglSurface = surface.getSurfaceHandle(); + if(DEBUG) { + System.err.println("setSurface re-using component's EGLSurface: handle 0x"+Long.toHexString(eglSurface)); + } + } else { + // EGLSurface is ours .. + ownEGLSurface=true; + + eglConfig.updateGraphicsConfiguration(); + + recreateSurface(); + } + } else { + throw new GLException("EGLGraphicsDevice hold by non EGLGraphicsConfiguration: "+aConfig); + } + } else { + if(DEBUG) { + System.err.println("EGLDrawable.setRealized: creating new EGL config: "+this); + } + // create a new EGL config .. + ownEGLDisplay=true; + // EGLSurface is ours .. + ownEGLSurface=true; + + long nDisplay=0; + if( NativeWindowFactory.TYPE_WINDOWS.equals(NativeWindowFactory.getNativeWindowType(false)) ) { + nDisplay = surface.getSurfaceHandle(); // don't even ask .. + } else { + nDisplay = aDevice.getHandle(); // 0 == EGL.EGL_DEFAULT_DISPLAY + } + eglDisplay = EGL.eglGetDisplay(nDisplay); + if (eglDisplay == EGL.EGL_NO_DISPLAY) { + if(DEBUG) { + System.err.println("eglDisplay("+Long.toHexString(nDisplay)+" <surfaceHandle>): failed, using EGL_DEFAULT_DISPLAY"); + } + nDisplay = EGL.EGL_DEFAULT_DISPLAY; + eglDisplay = EGL.eglGetDisplay(nDisplay); + } + if (eglDisplay == EGL.EGL_NO_DISPLAY) { + throw new GLException("Failed to created EGL display: nhandle 0x"+Long.toHexString(nDisplay)+", "+aDevice+", error 0x"+Integer.toHexString(EGL.eglGetError())); + } else if(DEBUG) { + System.err.println("eglDisplay("+Long.toHexString(nDisplay)+"): 0x"+Long.toHexString(eglDisplay)); + } + if (!EGL.eglInitialize(eglDisplay, null, null)) { + throw new GLException("eglInitialize failed"+", error 0x"+Integer.toHexString(EGL.eglGetError())); + } + EGLGraphicsDevice e = new EGLGraphicsDevice(eglDisplay, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); + DefaultGraphicsScreen s = new DefaultGraphicsScreen(e, aConfig.getScreen().getIndex()); + // yes, use the already choosen/requested Capabilities (x11,win32,..) + GLCapabilitiesImmutable capsChosen = (GLCapabilitiesImmutable) aConfig.getChosenCapabilities(); + GLCapabilitiesImmutable capsRequested = (GLCapabilitiesImmutable) aConfig.getRequestedCapabilities(); + eglConfig = (EGLGraphicsConfiguration) GraphicsConfigurationFactory.getFactory(e).chooseGraphicsConfiguration( + capsChosen, capsRequested, null, s); + if (null == eglConfig) { + throw new GLException("Couldn't create EGLGraphicsConfiguration from "+s); + } else if(DEBUG) { + System.err.println("Chosen eglConfig: "+eglConfig); + } + recreateSurface(); + } + } else if (ownEGLSurface && eglSurface != EGL.EGL_NO_SURFACE) { + // Destroy the window surface + if (!EGL.eglDestroySurface(eglDisplay, eglSurface)) { + throw new GLException("Error destroying window surface (eglDestroySurface)"); + } + eglSurface = EGL.EGL_NO_SURFACE; + if (ownEGLDisplay && EGL.EGL_NO_DISPLAY!=eglDisplay) { + EGL.eglTerminate(eglDisplay); + } + eglDisplay=EGL.EGL_NO_DISPLAY; + eglConfig=null; + } + } + + public int getWidth() { + int[] tmp = new int[1]; + if (!EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_WIDTH, tmp, 0)) { + throw new GLException("Error querying surface width"); + } + return tmp[0]; + } + + public int getHeight() { + int[] tmp = new int[1]; + if (!EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_HEIGHT, tmp, 0)) { + throw new GLException("Error querying surface height"); + } + return tmp[0]; + } + + public GLDynamicLookupHelper getGLDynamicLookupHelper() { + if (getGLProfile().usesNativeGLES2()) { + return getFactoryImpl().getGLDynamicLookupHelper(2); + } else if (getGLProfile().usesNativeGLES1()) { + return getFactoryImpl().getGLDynamicLookupHelper(1); + } else { + throw new GLException("Unsupported: "+getGLProfile()); + } + } + + public String toString() { + return getClass().getName()+"[realized "+isRealized()+ + ",\n\tfactory "+getFactory()+ + ",\n\tsurface "+getNativeSurface()+ + ",\n\teglSurface 0x"+Long.toHexString(eglSurface)+ + ",\n\teglConfig "+eglConfig+ + ",\n\trequested "+getRequestedGLCapabilities()+ + ",\n\tchosen "+getChosenGLCapabilities()+"]"; + } +} diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java new file mode 100644 index 000000000..b6599de1b --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.egl; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.EGLGraphicsDevice; +import javax.media.opengl.*; + +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; +import jogamp.opengl.*; +import jogamp.nativewindow.WrappedSurface; + +import java.util.HashMap; +import java.util.List; + +public class EGLDrawableFactory extends GLDrawableFactoryImpl { + + private static final GLDynamicLookupHelper eglES1DynamicLookupHelper; + private static final GLDynamicLookupHelper eglES2DynamicLookupHelper; + + static { + // Register our GraphicsConfigurationFactory implementations + // The act of constructing them causes them to be registered + new EGLGraphicsConfigurationFactory(); + + // Check for other underlying stuff .. + if(NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { + try { + ReflectionUtil.createInstance("jogamp.opengl.x11.glx.X11GLXGraphicsConfigurationFactory", EGLDrawableFactory.class.getClassLoader()); + } catch (JogampRuntimeException jre) { /* n/a .. */ } + } + + // FIXME: Probably need to move EGL from a static model + // to a dynamic one, where there can be 2 instances + // for each ES profile with their own ProcAddressTable. + + GLDynamicLookupHelper tmp=null; + try { + tmp = new GLDynamicLookupHelper(new EGLES1DynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + eglES1DynamicLookupHelper = tmp; + if(null!=eglES1DynamicLookupHelper && eglES1DynamicLookupHelper.isLibComplete()) { + EGL.resetProcAddressTable(eglES1DynamicLookupHelper); + } + + tmp=null; + try { + tmp = new GLDynamicLookupHelper(new EGLES2DynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + eglES2DynamicLookupHelper = tmp; + if(null!=eglES2DynamicLookupHelper && eglES2DynamicLookupHelper.isLibComplete()) { + EGL.resetProcAddressTable(eglES2DynamicLookupHelper); + } + } + + public EGLDrawableFactory() { + super(); + defaultDevice = new EGLGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); + } + + static class SharedResource { + private EGLGraphicsDevice device; + //private EGLDrawable drawable; + //private EGLContext context; + + SharedResource(EGLGraphicsDevice dev /*, EGLDrawable draw, EGLContext ctx */) { + device = dev; + // drawable = draw; + // context = ctx; + } + EGLGraphicsDevice getDevice() { return device; } + } + HashMap/*<connection, SharedResource>*/ sharedMap = new HashMap(); + EGLGraphicsDevice defaultDevice; + + public final AbstractGraphicsDevice getDefaultDevice() { + return defaultDevice; + } + + public final boolean getIsDeviceCompatible(AbstractGraphicsDevice device) { + if(device instanceof EGLGraphicsDevice) { + return true; + } + return false; + } + + private SharedResource getOrCreateShared(AbstractGraphicsDevice device) { + String connection = device.getConnection(); + SharedResource sr; + synchronized(sharedMap) { + sr = (SharedResource) sharedMap.get(connection); + } + if(null==sr) { + long eglDisplay = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); + if (eglDisplay == EGL.EGL_NO_DISPLAY) { + throw new GLException("Failed to created EGL default display: error 0x"+Integer.toHexString(EGL.eglGetError())); + } else if(DEBUG) { + System.err.println("eglDisplay(EGL_DEFAULT_DISPLAY): 0x"+Long.toHexString(eglDisplay)); + } + if (!EGL.eglInitialize(eglDisplay, null, null)) { + throw new GLException("eglInitialize failed"+", error 0x"+Integer.toHexString(EGL.eglGetError())); + } + EGLGraphicsDevice sharedDevice = new EGLGraphicsDevice(eglDisplay, connection, device.getUnitID()); + sr = new SharedResource(sharedDevice); + synchronized(sharedMap) { + sharedMap.put(connection, sr); + } + if (DEBUG) { + System.err.println("!!! SharedDevice: "+sharedDevice); + } + } + return sr; + } + + + protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { + // FIXME: not implemented .. needs a dummy EGL surface - NEEDED ? + return null; + } + + protected AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared(device); + if(null!=sr) { + return sr.getDevice(); + } + return null; + } + + SharedResource getOrCreateSharedResource(AbstractGraphicsDevice device) { + return (SharedResource) getOrCreateShared(device); + } + + public GLDynamicLookupHelper getGLDynamicLookupHelper(int esProfile) { + if (2==esProfile) { + if(null==eglES2DynamicLookupHelper) { + throw new GLException("GLDynamicLookupHelper for ES2 not available"); + } + return eglES2DynamicLookupHelper; + } else if (1==esProfile) { + if(null==eglES1DynamicLookupHelper) { + throw new GLException("GLDynamicLookupHelper for ES1 not available"); + } + return eglES1DynamicLookupHelper; + } else { + throw new GLException("Unsupported: ES"+esProfile); + } + } + + protected final void shutdownInstance() {} + + protected List/*GLCapabilitiesImmutable*/ getAvailableCapabilitiesImpl(AbstractGraphicsDevice device) { + return EGLGraphicsConfigurationFactory.getAvailableCapabilities(this, device); + } + + protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + return new EGLOnscreenDrawable(this, target); + } + + protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(!caps.isPBuffer()) { + throw new GLException("Not yet implemented"); + } + // PBuffer GLDrawable Creation + return new EGLPbufferDrawable(this, target); + } + + public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + return true; + } + + protected NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { + WrappedSurface ns = new WrappedSurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(device, capsChosen, capsRequested, chooser)); + ns.setSize(width, height); + return ns; + } + + protected ProxySurface createProxySurfaceImpl(AbstractGraphicsDevice device, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser) { + WrappedSurface ns = new WrappedSurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(device, capsRequested, capsRequested, chooser), windowHandle); + return ns; + } + + protected GLContext createExternalGLContextImpl() { + AbstractGraphicsScreen absScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_EGL); + return new EGLExternalContext(absScreen); + } + + public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { + return false; + } + + protected GLDrawable createExternalGLDrawableImpl() { + throw new GLException("Not yet implemented"); + } + + public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { + return false; + } + + public GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) + throws GLException { + throw new GLException("Unimplemented on this platform"); + } +} diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDynamicLibraryBundleInfo.java b/src/jogl/classes/jogamp/opengl/egl/EGLDynamicLibraryBundleInfo.java new file mode 100644 index 000000000..22d39fdae --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDynamicLibraryBundleInfo.java @@ -0,0 +1,73 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl.egl; + +import com.jogamp.common.os.DynamicLookupHelper; +import com.jogamp.common.os.NativeLibrary; +import java.util.*; +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import jogamp.opengl.*; +import java.security.*; + +/** + * Abstract implementation of the DynamicLookupHelper for EGL, + * which decouples it's dependencies to EGLDrawable. + * + * Currently two implementations exist, one for ES1 and one for ES2. + */ +public abstract class EGLDynamicLibraryBundleInfo extends GLDynamicLibraryBundleInfo { + + protected EGLDynamicLibraryBundleInfo() { + super(); + } + + /** Might be a desktop GL library, and might need to allow symbol access to subsequent libs */ + public boolean shallLinkGlobal() { return true; } + + public final List getToolGetProcAddressFuncNameList() { + List res = new ArrayList(); + res.add("eglGetProcAddress"); + return res; + } + + public final long toolDynamicLookupFunction(long toolGetProcAddressHandle, String funcName) { + return EGL.eglGetProcAddress(toolGetProcAddressHandle, funcName); + } + + protected List/*<String>*/ getEGLLibNamesList() { + List/*<String>*/ eglLibNames = new ArrayList(); + // EGL + eglLibNames.add("EGL"); + // for windows distributions using the 'unlike' lib prefix, + // where our tool does not add it. + eglLibNames.add("libEGL"); + return eglLibNames; + } +} diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLES1DynamicLibraryBundleInfo.java b/src/jogl/classes/jogamp/opengl/egl/EGLES1DynamicLibraryBundleInfo.java new file mode 100644 index 000000000..a62c847ca --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLES1DynamicLibraryBundleInfo.java @@ -0,0 +1,73 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl.egl; + +import java.util.*; +import jogamp.opengl.*; + +public class EGLES1DynamicLibraryBundleInfo extends EGLDynamicLibraryBundleInfo { + static List/*<String>*/ glueLibNames; + static { + glueLibNames = new ArrayList(); + glueLibNames.addAll(GLDynamicLibraryBundleInfo.getGlueLibNamesPreload()); + glueLibNames.add("jogl_es1"); + } + + protected EGLES1DynamicLibraryBundleInfo() { + super(); + } + + public List getToolLibNames() { + List/*<List>*/ libNames = new ArrayList(); + + List/*<String>*/ glesLibNames = new ArrayList(); + glesLibNames.add("GLES_CM"); + glesLibNames.add("GLES_CL"); + glesLibNames.add("GLESv1_CM"); + // for windows distributions using the 'unlike' lib prefix, + // where our tool does not add it. + glesLibNames.add("libGLES_CM"); + glesLibNames.add("libGLES_CL"); + glesLibNames.add("libGLESv1_CM"); + // last but not least, we may even use the desktop GL library, + // which would be eg Mesa + Gallium EGL .. + glesLibNames.add("libGL.so.1"); + glesLibNames.add("libGL.so"); + glesLibNames.add("GL"); + + libNames.add(glesLibNames); + libNames.add(getEGLLibNamesList()); + return libNames; + } + + public List/*<String>*/ getGlueLibNames() { + return glueLibNames; + } +} + diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLES2DynamicLibraryBundleInfo.java b/src/jogl/classes/jogamp/opengl/egl/EGLES2DynamicLibraryBundleInfo.java new file mode 100644 index 000000000..0477fc2c7 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLES2DynamicLibraryBundleInfo.java @@ -0,0 +1,73 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl.egl; + +import java.util.*; +import jogamp.opengl.*; + +public class EGLES2DynamicLibraryBundleInfo extends EGLDynamicLibraryBundleInfo { + static List/*<String>*/ glueLibNames; + static { + glueLibNames = new ArrayList(); + glueLibNames.addAll(GLDynamicLibraryBundleInfo.getGlueLibNamesPreload()); + glueLibNames.add("jogl_es2"); + } + + protected EGLES2DynamicLibraryBundleInfo() { + super(); + } + + public List getToolLibNames() { + List/*<List>*/ libNames = new ArrayList(); + + List/*<String>*/ glesLibNames = new ArrayList(); + glesLibNames.add("GLES20"); + glesLibNames.add("GLESv2"); + glesLibNames.add("GLESv2_CM"); + // for windows distributions using the 'unlike' lib prefix + // where our tool does not add it. + glesLibNames.add("libGLES20"); + glesLibNames.add("libGLESv2"); + glesLibNames.add("libGLESv2_CM"); + // last but not least, we may even use the desktop GL library, + // which would be eg Mesa + Gallium EGL .. + glesLibNames.add("libGL.so.1"); + glesLibNames.add("libGL.so"); + glesLibNames.add("GL"); + + libNames.add(glesLibNames); + libNames.add(getEGLLibNamesList()); + return libNames; + } + + public List/*<String>*/ getGlueLibNames() { + return glueLibNames; + } +} + diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java new file mode 100644 index 000000000..dd06dc148 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.egl; + +import javax.media.opengl.*; +import jogamp.opengl.*; +import javax.media.nativewindow.*; + +public class EGLExternalContext extends EGLContext { + private GLContext lastContext; + + public EGLExternalContext(AbstractGraphicsScreen screen) { + super(null, null); + GLContextShareSet.contextCreated(this); + setGLFunctionAvailability(false, 0, 0, CTX_IS_ARB_CREATED|CTX_PROFILE_ES|CTX_OPTION_ANY); + getGLStateTracker().setEnabled(false); // external context usage can't track state in Java + } + + public int makeCurrent() throws GLException { + // Save last context if necessary to allow external GLContexts to + // talk to other GLContexts created by this library + GLContext cur = getCurrent(); + if (cur != null && cur != this) { + lastContext = cur; + setCurrent(null); + } + return super.makeCurrent(); + } + + public void release() throws GLException { + super.release(); + setCurrent(lastContext); + lastContext = null; + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + } + + protected void releaseImpl() throws GLException { + } + + protected void destroyImpl() throws GLException { + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + +} diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java b/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java new file mode 100644 index 000000000..cead0358d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java @@ -0,0 +1,96 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl.egl; + +import java.util.Comparator; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +public class EGLGLCapabilities extends GLCapabilities { + long eglcfg; + int eglcfgid; + + /** Comparing EGLConfig ID only */ + public static class EglCfgIDComparator implements Comparator { + + public int compare(Object o1, Object o2) { + if ( ! ( o1 instanceof EGLGLCapabilities ) ) { + Class c = (null != o1) ? o1.getClass() : null ; + throw new ClassCastException("arg1 not a EGLGLCapabilities object: " + c); + } + if ( ! ( o2 instanceof EGLGLCapabilities ) ) { + Class c = (null != o2) ? o2.getClass() : null ; + throw new ClassCastException("arg2 not a EGLGLCapabilities object: " + c); + } + + final EGLGLCapabilities caps1 = (EGLGLCapabilities) o1; + final long id1 = caps1.getEGLConfigID(); + + final EGLGLCapabilities caps2 = (EGLGLCapabilities) o2; + final long id2 = caps2.getEGLConfigID(); + + if(id1 > id2) { + return 1; + } else if(id1 < id2) { + return -1; + } + return 0; + } + } + + public EGLGLCapabilities(long eglcfg, int eglcfgid, GLProfile glp) { + super(glp); + this.eglcfg = eglcfg; + this.eglcfgid = eglcfgid; + } + + public Object cloneMutable() { + return clone(); + } + + public Object clone() { + try { + return super.clone(); + } catch (RuntimeException e) { + throw new GLException(e); + } + } + + final public long getEGLConfig() { return eglcfg; } + final public int getEGLConfigID() { return eglcfgid; } + + public StringBuffer toString(StringBuffer sink) { + if(null == sink) { + sink = new StringBuffer(); + } + sink.append("0x").append(Long.toHexString(eglcfgid)).append(": "); + return super.toString(sink); + } +}
\ No newline at end of file diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java new file mode 100644 index 000000000..4d8f2ac3e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.egl; + +import java.util.ArrayList; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; +import javax.media.opengl.*; +import com.jogamp.common.nio.PointerBuffer; +import jogamp.opengl.*; + +public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable { + protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); + + public final long getNativeConfig() { + return ((EGLGLCapabilities)capabilitiesChosen).getEGLConfig(); + } + + public final int getNativeConfigID() { + return ((EGLGLCapabilities)capabilitiesChosen).getEGLConfigID(); + } + + EGLGraphicsConfiguration(AbstractGraphicsScreen absScreen, + EGLGLCapabilities capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser) { + super(absScreen, capsChosen, capsRequested); + this.chooser = chooser; + } + + public static EGLGraphicsConfiguration create(GLCapabilitiesImmutable capsRequested, AbstractGraphicsScreen absScreen, int cfgID) { + AbstractGraphicsDevice absDevice = absScreen.getDevice(); + if(null==absDevice || !(absDevice instanceof EGLGraphicsDevice)) { + throw new GLException("GraphicsDevice must be a valid EGLGraphicsDevice"); + } + long dpy = absDevice.getHandle(); + if (dpy == EGL.EGL_NO_DISPLAY) { + throw new GLException("Invalid EGL display: "+absDevice); + } + GLProfile glp = capsRequested.getGLProfile(); + long cfg = EGLConfigId2EGLConfig(glp, dpy, cfgID); + EGLGLCapabilities caps = EGLConfig2Capabilities(glp, dpy, cfg, false, capsRequested.isOnscreen(), capsRequested.isPBuffer()); + return new EGLGraphicsConfiguration(absScreen, caps, capsRequested, new DefaultGLCapabilitiesChooser()); + } + + @Override + public Object clone() { + return super.clone(); + } + + void updateGraphicsConfiguration() { + EGLGraphicsConfiguration newConfig = (EGLGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(getScreen().getDevice()).chooseGraphicsConfiguration( + getChosenCapabilities(), getRequestedCapabilities(), chooser, getScreen()); + if(null!=newConfig) { + // FIXME: setScreen( ... ); + setChosenCapabilities(newConfig.getChosenCapabilities()); + if(DEBUG) { + System.err.println("!!! updateGraphicsConfiguration: "+this); + } + } + } + + public static long EGLConfigId2EGLConfig(GLProfile glp, long display, int configID) { + int[] attrs = new int[] { + EGL.EGL_CONFIG_ID, configID, + EGL.EGL_NONE + }; + PointerBuffer configs = PointerBuffer.allocateDirect(1); + int[] numConfigs = new int[1]; + if (!EGL.eglChooseConfig(display, + attrs, 0, + configs, 1, + numConfigs, 0)) { + return 0; + } + if (numConfigs[0] == 0) { + return 0; + } + return configs.get(0); + } + + static int EGLConfigDrawableTypeBits(final long display, final long config) { + int val = 0; + + int[] stype = new int[1]; + if(! EGL.eglGetConfigAttrib(display, config, EGL.EGL_SURFACE_TYPE, stype, 0)) { + throw new GLException("Could not determine EGL_SURFACE_TYPE !!!"); + } + + if ( 0 != ( stype[0] & EGL.EGL_WINDOW_BIT ) ) { + val |= GLGraphicsConfigurationUtil.WINDOW_BIT; + } + if ( 0 != ( stype[0] & EGL.EGL_PIXMAP_BIT ) ) { + val |= GLGraphicsConfigurationUtil.BITMAP_BIT; + } + if ( 0 != ( stype[0] & EGL.EGL_PBUFFER_BIT ) ) { + val |= GLGraphicsConfigurationUtil.PBUFFER_BIT; + } + + return val; + } + + public static EGLGLCapabilities EGLConfig2Capabilities(GLProfile glp, long display, long config, + boolean relaxed, boolean onscreen, boolean usePBuffer) { + ArrayList bucket = new ArrayList(); + final int winattrmask = GLGraphicsConfigurationUtil.getWinAttributeBits(onscreen, usePBuffer); + if( EGLConfig2Capabilities(bucket, glp, display, config, winattrmask) ) { + return (EGLGLCapabilities) bucket.get(0); + } else if ( relaxed && EGLConfig2Capabilities(bucket, glp, display, config, GLGraphicsConfigurationUtil.ALL_BITS) ) { + return (EGLGLCapabilities) bucket.get(0); + } + return null; + } + + public static boolean EGLConfig2Capabilities(ArrayList capsBucket, + GLProfile glp, long display, long config, + int winattrmask) { + final int allDrawableTypeBits = EGLConfigDrawableTypeBits(display, config); + final int drawableTypeBits = winattrmask & allDrawableTypeBits; + + if( 0 == drawableTypeBits ) { + return false; + } + + int[] val = new int[1]; + + // get the configID + if(!EGL.eglGetConfigAttrib(display, config, EGL.EGL_CONFIG_ID, val, 0)) { + if(DEBUG) { + // FIXME: this happens on a ATI PC Emulation .. + System.err.println("EGL couldn't retrieve ConfigID for config "+toHexString(config)+", error "+toHexString(EGL.eglGetError())); + } + return false; + } + GLCapabilities caps = new EGLGLCapabilities(config, val[0], glp); + + // Read the actual configuration into the choosen caps + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_RED_SIZE, val, 0)) { + caps.setRedBits(val[0]); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_GREEN_SIZE, val, 0)) { + caps.setGreenBits(val[0]); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_BLUE_SIZE, val, 0)) { + caps.setBlueBits(val[0]); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_ALPHA_SIZE, val, 0)) { + caps.setAlphaBits(val[0]); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_STENCIL_SIZE, val, 0)) { + caps.setStencilBits(val[0]); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_DEPTH_SIZE, val, 0)) { + caps.setDepthBits(val[0]); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_SAMPLES, val, 0)) { + caps.setSampleBuffers(val[0]>0?true:false); + caps.setNumSamples(val[0]); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_TYPE, val, 0)) { + caps.setBackgroundOpaque(val[0] != EGL.EGL_TRANSPARENT_RGB); + } + if(!caps.isBackgroundOpaque()) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_RED_VALUE, val, 0)) { + caps.setTransparentRedValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_GREEN_VALUE, val, 0)) { + caps.setTransparentGreenValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); + } + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_BLUE_VALUE, val, 0)) { + caps.setTransparentBlueValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); + } + /** Not defined in EGL + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_ALPHA_VALUE, val, 0)) { + caps.setTransparentAlphaValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); + } */ + } + return GLGraphicsConfigurationUtil.addGLCapabilitiesPermutations(capsBucket, caps, drawableTypeBits ); + } + + public static int[] GLCapabilities2AttribList(GLCapabilitiesImmutable caps) { + int[] attrs = new int[32]; + int idx=0; + + attrs[idx++] = EGL.EGL_SURFACE_TYPE; + attrs[idx++] = caps.isOnscreen() ? ( EGL.EGL_WINDOW_BIT ) : ( caps.isPBuffer() ? EGL.EGL_PBUFFER_BIT : EGL.EGL_PIXMAP_BIT ) ; + + attrs[idx++] = EGL.EGL_RED_SIZE; + attrs[idx++] = caps.getRedBits(); + + attrs[idx++] = EGL.EGL_GREEN_SIZE; + attrs[idx++] = caps.getGreenBits(); + + attrs[idx++] = EGL.EGL_BLUE_SIZE; + attrs[idx++] = caps.getBlueBits(); + + attrs[idx++] = EGL.EGL_ALPHA_SIZE; + attrs[idx++] = caps.getAlphaBits() > 0 ? caps.getAlphaBits() : EGL.EGL_DONT_CARE; + + attrs[idx++] = EGL.EGL_STENCIL_SIZE; + attrs[idx++] = caps.getStencilBits() > 0 ? caps.getStencilBits() : EGL.EGL_DONT_CARE; + + attrs[idx++] = EGL.EGL_DEPTH_SIZE; + attrs[idx++] = caps.getDepthBits(); + + attrs[idx++] = EGL.EGL_SAMPLES; + attrs[idx++] = caps.getSampleBuffers() ? caps.getNumSamples() : 1; + + attrs[idx++] = EGL.EGL_TRANSPARENT_TYPE; + attrs[idx++] = caps.isBackgroundOpaque() ? EGL.EGL_NONE : EGL.EGL_TRANSPARENT_TYPE; + + // 20 + + if(!caps.isBackgroundOpaque()) { + attrs[idx++] = EGL.EGL_TRANSPARENT_RED_VALUE; + attrs[idx++] = caps.getTransparentRedValue()>=0?caps.getTransparentRedValue():EGL.EGL_DONT_CARE; + + attrs[idx++] = EGL.EGL_TRANSPARENT_GREEN_VALUE; + attrs[idx++] = caps.getTransparentGreenValue()>=0?caps.getTransparentGreenValue():EGL.EGL_DONT_CARE; + + attrs[idx++] = EGL.EGL_TRANSPARENT_BLUE_VALUE; + attrs[idx++] = caps.getTransparentBlueValue()>=0?caps.getTransparentBlueValue():EGL.EGL_DONT_CARE; + + /** Not define in EGL + attrs[idx++] = EGL.EGL_TRANSPARENT_ALPHA_VALUE; + attrs[idx++] = caps.getTransparentAlphaValue()>=0?caps.getTransparentAlphaValue():EGL.EGL_DONT_CARE; */ + } + + // 26 + + attrs[idx++] = EGL.EGL_RENDERABLE_TYPE; + if(caps.getGLProfile().usesNativeGLES1()) { + attrs[idx++] = EGL.EGL_OPENGL_ES_BIT; + } + else if(caps.getGLProfile().usesNativeGLES2()) { + attrs[idx++] = EGL.EGL_OPENGL_ES2_BIT; + } else { + attrs[idx++] = EGL.EGL_OPENGL_BIT; + } + + // 28 + + attrs[idx++] = EGL.EGL_NONE; + + return attrs; + } + + public static int[] CreatePBufferSurfaceAttribList(int width, int height, int texFormat) { + int[] attrs = new int[16]; + int idx=0; + + attrs[idx++] = EGL.EGL_WIDTH; + attrs[idx++] = width; + + attrs[idx++] = EGL.EGL_HEIGHT; + attrs[idx++] = height; + + attrs[idx++] = EGL.EGL_TEXTURE_FORMAT; + attrs[idx++] = texFormat; + + attrs[idx++] = EGL.EGL_TEXTURE_TARGET; + attrs[idx++] = EGL.EGL_NO_TEXTURE==texFormat ? EGL.EGL_NO_TEXTURE : EGL.EGL_TEXTURE_2D; + + attrs[idx++] = EGL.EGL_NONE; + + return attrs; + } + + @Override + public String toString() { + return getClass().getSimpleName()+"["+getScreen()+", eglConfigID "+toHexString(getNativeConfigID())+ + ",\n\trequested " + getRequestedCapabilities()+ + ",\n\tchosen " + getChosenCapabilities()+ + "]"; + + } + + private GLCapabilitiesChooser chooser; +} + diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java new file mode 100644 index 000000000..bcaabfc48 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.egl; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.egl.EGLGraphicsDevice; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLDrawableFactory; + +import com.jogamp.common.nio.PointerBuffer; +import jogamp.opengl.GLGraphicsConfigurationFactory; +import jogamp.opengl.GLGraphicsConfigurationUtil; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.io.PrintStream; + + +/** Subclass of GraphicsConfigurationFactory used when non-AWT tookits + are used on X11 platforms. Toolkits will likely need to delegate + to this one to change the accepted and returned types of the + GraphicsDevice and GraphicsConfiguration abstractions. */ + +public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory { + protected static final boolean DEBUG = GraphicsConfigurationFactory.DEBUG || jogamp.opengl.Debug.debug("EGL"); + static EGLGLCapabilities.EglCfgIDComparator EglCfgIDComparator = new EGLGLCapabilities.EglCfgIDComparator(); + + EGLGraphicsConfigurationFactory() { + // become the selector for KD/EGL .. + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.egl.EGLGraphicsDevice.class, this); + } + + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl ( + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { + if (absScreen == null) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only AbstractGraphicsDevice objects"); + } + + if (! (capsChosen instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - chosen"); + } + + if (! (capsRequested instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - requested"); + } + + if (chooser != null && + !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilitiesChooser objects"); + } + + return chooseGraphicsConfigurationStatic((GLCapabilitiesImmutable) capsChosen, + (GLCapabilitiesImmutable) capsRequested, + (GLCapabilitiesChooser) chooser, + absScreen); + } + + protected static List/*<EGLGLCapabilities>*/ getAvailableCapabilities(EGLDrawableFactory factory, AbstractGraphicsDevice device) { + EGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResource(device); + if(null == sharedResource) { + throw new GLException("Shared resource for device n/a: "+device); + } + EGLGraphicsDevice eglDevice = sharedResource.getDevice(); + long eglDisplay = eglDevice.getHandle(); + + List/*<EGLGLCapabilities>*/ availableCaps = null; + int[] maxConfigs = new int[1]; + + if(!EGL.eglGetConfigs(eglDisplay, null, 0, maxConfigs, 0)) { + throw new GLException("Graphics configuration get maxConfigs (eglGetConfigs) call failed, error "+toHexString(EGL.eglGetError())); + } + if(0 == maxConfigs[0]) { + throw new GLException("Graphics configuration get maxConfigs (eglGetConfigs) no configs"); + } + + PointerBuffer configs = PointerBuffer.allocateDirect(maxConfigs[0]); + int[] numConfigs = new int[1]; + + if(!EGL.eglGetConfigs(eglDisplay, configs, configs.capacity(), numConfigs, 0)) { + throw new GLException("Graphics configuration get all configs (eglGetConfigs) call failed, error "+toHexString(EGL.eglGetError())); + } + if (numConfigs[0] > 0) { + GLProfile glp = GLProfile.getDefault(device); + availableCaps = eglConfigs2GLCaps(glp, eglDisplay, configs, numConfigs[0], GLGraphicsConfigurationUtil.ALL_BITS); + if( null != availableCaps && availableCaps.size() > 1) { + Collections.sort(availableCaps, EglCfgIDComparator); + } + } + + return availableCaps; + } + + private static EGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilitiesImmutable capsChosen, + GLCapabilitiesImmutable capsReq, + GLCapabilitiesChooser chooser, + AbstractGraphicsScreen absScreen) { + if (capsChosen == null) { + capsChosen = new GLCapabilities(null); + } + + if(null==absScreen) { + throw new GLException("Null AbstractGraphicsScreen"); + } + AbstractGraphicsDevice absDevice = absScreen.getDevice(); + + if(null==absDevice || !(absDevice instanceof EGLGraphicsDevice)) { + throw new GLException("GraphicsDevice must be a valid EGLGraphicsDevice"); + } + long eglDisplay = absDevice.getHandle(); + + if (eglDisplay == EGL.EGL_NO_DISPLAY) { + throw new GLException("Invalid EGL display: "+absDevice); + } + + EGLDrawableFactory factory = (EGLDrawableFactory) GLDrawableFactory.getEGLFactory(); + capsChosen = GLGraphicsConfigurationUtil.fixGLCapabilities( capsChosen, factory.canCreateGLPbuffer(absDevice) ); + + GLProfile glp = capsChosen.getGLProfile(); + + EGLGraphicsConfiguration res = eglChooseConfig(eglDisplay, capsChosen, capsReq, chooser, absScreen); + if(null!=res) { + return res; + } + if(DEBUG) { + System.err.println("eglChooseConfig failed with given capabilities "+capsChosen); + } + + // Last try .. add a fixed embedded profile [ATI, Nokia, Intel, ..] + // + // rgb888 - d16, s4 + GLCapabilities fixedCaps = new GLCapabilities(glp); + fixedCaps.setRedBits(8); + fixedCaps.setGreenBits(8); + fixedCaps.setBlueBits(8); + fixedCaps.setDepthBits(16); + fixedCaps.setSampleBuffers(true); + fixedCaps.setNumSamples(4); + if(DEBUG) { + System.err.println("trying fixed caps (1): "+fixedCaps); + } + res = eglChooseConfig(eglDisplay, fixedCaps, capsReq, chooser, absScreen); + if(null!=res) { + return res; + } + + // + // rgb565 - d16, s0 + fixedCaps = new GLCapabilities(glp); + fixedCaps.setRedBits(5); + fixedCaps.setGreenBits(6); + fixedCaps.setBlueBits(5); + fixedCaps.setDepthBits(16); + if(DEBUG) { + System.err.println("trying fixed caps (2): "+fixedCaps); + } + res = eglChooseConfig(eglDisplay, fixedCaps, capsReq, chooser, absScreen); + if(null!=res) { + return res; + } + + // + // rgb565 - d16, s4 + fixedCaps = new GLCapabilities(glp); + fixedCaps.setRedBits(5); + fixedCaps.setGreenBits(6); + fixedCaps.setBlueBits(5); + fixedCaps.setDepthBits(16); + fixedCaps.setSampleBuffers(true); + fixedCaps.setNumSamples(4); + if(DEBUG) { + System.err.println("trying fixed caps (3): "+fixedCaps); + } + res = eglChooseConfig(eglDisplay, fixedCaps, capsReq, chooser, absScreen); + if(null!=res) { + return res; + } + throw new GLException("Graphics configuration failed [direct caps, eglGetConfig/chooser and fixed-caps(1-3)]"); + } + + static EGLGraphicsConfiguration eglChooseConfig(long eglDisplay, + GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser, + AbstractGraphicsScreen absScreen) { + GLProfile glp = capsChosen.getGLProfile(); + boolean onscreen = capsChosen.isOnscreen(); + boolean usePBuffer = capsChosen.isPBuffer(); + List/*<EGLGLCapabilities>*/ availableCaps = null; + final int winattrmask = GLGraphicsConfigurationUtil.getWinAttributeBits(onscreen, usePBuffer); + int recommendedIndex = -1; + long recommendedEGLConfig = -1; + int[] maxConfigs = new int[1]; + + if(!EGL.eglGetConfigs(eglDisplay, null, 0, maxConfigs, 0)) { + throw new GLException("Graphics configuration get maxConfigs (eglGetConfigs) call failed, error "+toHexString(EGL.eglGetError())); + } + if(0 == maxConfigs[0]) { + throw new GLException("Graphics configuration get maxConfigs (eglGetConfigs) no configs"); + } + if (DEBUG) { + System.err.println("!!! eglChooseConfig maxConfigs: "+maxConfigs[0]); + } + + int[] attrs = EGLGraphicsConfiguration.GLCapabilities2AttribList(capsChosen); + PointerBuffer configs = PointerBuffer.allocateDirect(maxConfigs[0]); + int[] numConfigs = new int[1]; + + // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as preferred choice + if (!EGL.eglChooseConfig(eglDisplay, + attrs, 0, + configs, configs.capacity(), + numConfigs, 0)) { + throw new GLException("Graphics configuration selection (eglChooseConfig) failed for "+capsChosen+", error "+toHexString(EGL.eglGetError())); + } + if (numConfigs[0] > 0) { + availableCaps = eglConfigs2GLCaps(glp, eglDisplay, configs, numConfigs[0], winattrmask); + if(availableCaps.size() > 0) { + recommendedEGLConfig = configs.get(0); + recommendedIndex = 0; + if (DEBUG) { + System.err.println("!!! eglChooseConfig recommended fbcfg " + toHexString(recommendedEGLConfig) + ", idx " + recommendedIndex); + System.err.println("!!! user caps " + capsChosen); + System.err.println("!!! fbcfg caps " + availableCaps.get(recommendedIndex)); + } + } else if (DEBUG) { + System.err.println("!!! eglChooseConfig no caps for recommended fbcfg " + toHexString(configs.get(0))); + System.err.println("!!! user caps " + capsChosen); + } + } + + // 2nd choice: get all GLCapabilities available, no preferred recommendedIndex available + if( null == availableCaps || 0 == availableCaps.size() ) { + // reset .. + recommendedEGLConfig = -1; + recommendedIndex = -1; + + if(!EGL.eglGetConfigs(eglDisplay, configs, configs.capacity(), numConfigs, 0)) { + throw new GLException("Graphics configuration get all configs (eglGetConfigs) call failed, error "+toHexString(EGL.eglGetError())); + } + if (numConfigs[0] > 0) { + availableCaps = eglConfigs2GLCaps(glp, eglDisplay, configs, numConfigs[0], winattrmask); + } + } + + if( null == availableCaps || 0 == availableCaps.size() ) { + if(DEBUG) { + // FIXME: this happens on a ATI PC Emulation .. + System.err.println("Graphics configuration 1st choice and 2nd choice failed - no configs"); + } + return null; + } + + int chosenIndex = chooseCapabilities(chooser, capsChosen, availableCaps, recommendedIndex); + if ( 0 > chosenIndex ) { + if (DEBUG) { + Thread.dumpStack(); + } + return null; + } + EGLGLCapabilities chosenCaps = (EGLGLCapabilities) availableCaps.get(chosenIndex); + + return new EGLGraphicsConfiguration(absScreen, chosenCaps, capsRequested, chooser); + } + + static List/*<GLCapabilitiesImmutable>*/ eglConfigs2GLCaps(GLProfile glp, long eglDisplay, PointerBuffer configs, int num, int winattrmask) { + ArrayList caps = new ArrayList(num); + for(int i=0; i<num; i++) { + EGLGraphicsConfiguration.EGLConfig2Capabilities(caps, glp, eglDisplay, configs.get(i), winattrmask); + } + return caps; + } + + static void printCaps(String prefix, List/*GLCapabilitiesImmutable*/ caps, PrintStream out) { + for(int i=0; i<caps.size(); i++) { + out.println(prefix+"["+i+"] "+caps.get(i)); + } + } + + static EGLGraphicsConfiguration createOffscreenGraphicsConfiguration(AbstractGraphicsDevice device, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsReq, GLCapabilitiesChooser chooser) { + if(capsChosen.isOnscreen()) { + throw new GLException("Error: Onscreen set: "+capsChosen); + } + + if(capsChosen.getDoubleBuffered()) { + // OFFSCREEN !DOUBLE_BUFFER // FIXME DBLBUFOFFSCRN + GLCapabilities caps2 = (GLCapabilities) capsChosen.cloneMutable(); + caps2.setDoubleBuffered(false); + capsChosen = caps2; + } + + DefaultGraphicsScreen screen = new DefaultGraphicsScreen(device, 0); + EGLGraphicsConfiguration eglConfig = chooseGraphicsConfigurationStatic(capsChosen, capsReq, chooser, screen); + if (null == eglConfig) { + throw new GLException("Couldn't create EGLGraphicsConfiguration from "+screen); + } else if(DEBUG) { + System.err.println("Chosen eglConfig: "+eglConfig); + } + return eglConfig; + } +} + diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLOnscreenContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLOnscreenContext.java new file mode 100644 index 000000000..dd0a3db3a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLOnscreenContext.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.egl; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import jogamp.opengl.*; +import com.jogamp.gluegen.runtime.ProcAddressTable; +import java.nio.*; +import java.util.*; + +public class EGLOnscreenContext extends EGLContext { + public EGLOnscreenContext(EGLOnscreenDrawable drawable, GLContext shareWith) { + super(drawable, shareWith); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + +} + diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLOnscreenDrawable.java b/src/jogl/classes/jogamp/opengl/egl/EGLOnscreenDrawable.java new file mode 100644 index 000000000..4359f2ac3 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLOnscreenDrawable.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.egl; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +public class EGLOnscreenDrawable extends EGLDrawable { + protected EGLOnscreenDrawable(EGLDrawableFactory factory, NativeSurface component) throws GLException { + super(factory, component); + } + + public GLContext createContext(GLContext shareWith) { + return new EGLOnscreenContext(this, shareWith); + } + + protected long createSurface(long eglDpy, long eglNativeCfg, long surfaceHandle) { + return EGL.eglCreateWindowSurface(eglDpy, eglNativeCfg, surfaceHandle, null); + } + + protected void swapBuffersImpl() { + EGL.eglSwapBuffers(eglDisplay, eglSurface); + } + +} + diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLPbufferContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLPbufferContext.java new file mode 100644 index 000000000..2cad7daac --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLPbufferContext.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.egl; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import jogamp.opengl.*; +import com.jogamp.gluegen.runtime.ProcAddressTable; +import java.nio.*; +import java.util.*; + +public class EGLPbufferContext extends EGLContext { + public EGLPbufferContext(EGLPbufferDrawable drawable, GLContext shareWith) { + super(drawable, shareWith); + } + + public int getFloatingPointMode() { + return 0; // FIXME ?? + } + + public void bindPbufferToTexture() { + throw new GLException("Not yet implemented"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Not yet implemented"); + } +} + diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLPbufferDrawable.java b/src/jogl/classes/jogamp/opengl/egl/EGLPbufferDrawable.java new file mode 100644 index 000000000..6cbd1ee6a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/egl/EGLPbufferDrawable.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.egl; + +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.SurfaceChangeable; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLException; + +public class EGLPbufferDrawable extends EGLDrawable { + private int texFormat; + protected static final boolean useTexture = false; // No yet .. + + protected EGLPbufferDrawable(EGLDrawableFactory factory, NativeSurface target) { + super(factory, target); + ownEGLDisplay = true; + + // get choosen ones .. + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) + getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + + if(useTexture) { + this.texFormat = caps.getAlphaBits() > 0 ? EGL.EGL_TEXTURE_RGBA : EGL.EGL_TEXTURE_RGB ; + } else { + this.texFormat = EGL.EGL_NO_TEXTURE; + } + + if (DEBUG) { + System.out.println("Pbuffer config: " + getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration()); + } + + setRealized(true); + + if (DEBUG) { + System.out.println("Created pbuffer: " + this); + } + + } + + protected long createSurface(long eglDpy, long eglNativeCfg, long surfaceHandle) { + NativeSurface nw = getNativeSurface(); + int[] attrs = EGLGraphicsConfiguration.CreatePBufferSurfaceAttribList(nw.getWidth(), nw.getHeight(), texFormat); + long surf = EGL.eglCreatePbufferSurface(eglDpy, eglNativeCfg, attrs, 0); + if (EGL.EGL_NO_SURFACE==surf) { + throw new GLException("Creation of window surface (eglCreatePbufferSurface) failed, dim "+nw.getWidth()+"x"+nw.getHeight()+", error 0x"+Integer.toHexString(EGL.eglGetError())); + } else if(DEBUG) { + System.err.println("PBuffer setSurface result: eglSurface 0x"+Long.toHexString(surf)); + } + ((SurfaceChangeable)nw).setSurfaceHandle(surf); + return surf; + } + + public GLContext createContext(GLContext shareWith) { + return new EGLPbufferContext(this, shareWith); + } + + protected void swapBuffersImpl() { + if(DEBUG) { + System.err.println("unhandled swapBuffersImpl() called for: "+this); + } + } +} + diff --git a/src/jogl/classes/jogamp/opengl/gl2/ProjectDouble.java b/src/jogl/classes/jogamp/opengl/gl2/ProjectDouble.java new file mode 100644 index 000000000..9165dbc4b --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/gl2/ProjectDouble.java @@ -0,0 +1,1042 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** $Date: 2009-03-13 22:20:29 -0700 (Fri, 13 Mar 2009) $ $Revision: 1867 $ +** $Header$ +*/ + +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE COPYRIGHT OWNER 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. + */ + +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ +package jogamp.opengl.gl2; + +import java.nio.*; + +import javax.media.opengl.*; +import jogamp.opengl.*; +import com.jogamp.common.nio.Buffers; + +/** + * Project.java + * <p/> + * <p/> + * Created 11-jan-2004 + * + * @author Erik Duijs + * @author Kenneth Russell + */ +public class ProjectDouble { + private static final double[] IDENTITY_MATRIX = + new double[] { + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0 }; + + // Note that we have cloned parts of the implementation in order to + // support incoming Buffers. The reason for this is to avoid loading + // non-direct buffer subclasses unnecessarily, because doing so can + // cause performance decreases on direct buffer operations, at least + // on the current HotSpot JVM. It would be nicer (and make the code + // simpler) to simply have the array-based entry points delegate to + // the versions taking Buffers by wrapping the arrays. + + // Array-based implementation + private final double[] matrix = new double[16]; + + private final double[][] tempMatrix = new double[4][4]; + private final double[] in = new double[4]; + private final double[] out = new double[4]; + + private final double[] forward = new double[3]; + private final double[] side = new double[3]; + private final double[] up = new double[3]; + + // Buffer-based implementation + private DoubleBuffer locbuf; + private final DoubleBuffer matrixBuf; + + private final DoubleBuffer tempMatrixBuf; + private final DoubleBuffer inBuf; + private final DoubleBuffer outBuf; + + private final DoubleBuffer forwardBuf; + private final DoubleBuffer sideBuf; + private final DoubleBuffer upBuf; + + public ProjectDouble() { + // Use direct buffers to avoid loading indirect buffer + // implementations for applications trying to avoid doing so. + // Slice up one big buffer because some NIO implementations + // allocate a huge amount of memory to back even the smallest of + // buffers. + DoubleBuffer locbuf = Buffers.newDirectDoubleBuffer(128); + int pos = 0; + int sz = 16; + matrixBuf = slice(locbuf, pos, sz); + pos += sz; + tempMatrixBuf = slice(locbuf, pos, sz); + pos += sz; + sz = 4; + inBuf = slice(locbuf, pos, sz); + pos += sz; + outBuf = slice(locbuf, pos, sz); + pos += sz; + sz = 3; + forwardBuf = slice(locbuf, pos, sz); + pos += sz; + sideBuf = slice(locbuf, pos, sz); + pos += sz; + upBuf = slice(locbuf, pos, sz); + } + + public void destroy() { + if(locbuf!=null) { + locbuf.clear(); + locbuf=null; + } + } + + private static DoubleBuffer slice(DoubleBuffer buf, int pos, int len) { + buf.position(pos); + buf.limit(pos + len); + return buf.slice(); + } + + /** + * Make matrix an identity matrix + */ + private void __gluMakeIdentityd(DoubleBuffer m) { + int oldPos = m.position(); + m.put(IDENTITY_MATRIX); + m.position(oldPos); + } + + /** + * Make matrix an identity matrix + */ + private void __gluMakeIdentityd(double[] m) { + for (int i = 0; i < 16; i++) { + m[i] = IDENTITY_MATRIX[i]; + } + } + + /** + * Method __gluMultMatrixVecd + * + * @param matrix + * @param in + * @param out + */ + private void __gluMultMatrixVecd(double[] matrix, int matrix_offset, double[] in, double[] out) { + for (int i = 0; i < 4; i++) { + out[i] = + in[0] * matrix[0*4+i+matrix_offset] + + in[1] * matrix[1*4+i+matrix_offset] + + in[2] * matrix[2*4+i+matrix_offset] + + in[3] * matrix[3*4+i+matrix_offset]; + } + } + + /** + * Method __gluMultMatrixVecd + * + * @param matrix + * @param in + * @param out + */ + private void __gluMultMatrixVecd(DoubleBuffer matrix, DoubleBuffer in, DoubleBuffer out) { + int inPos = in.position(); + int outPos = out.position(); + int matrixPos = matrix.position(); + for (int i = 0; i < 4; i++) { + out.put(i + outPos, + in.get(0+inPos) * matrix.get(0*4+i+matrixPos) + + in.get(1+inPos) * matrix.get(1*4+i+matrixPos) + + in.get(2+inPos) * matrix.get(2*4+i+matrixPos) + + in.get(3+inPos) * matrix.get(3*4+i+matrixPos)); + } + } + + /** + * @param src + * @param inverse + * + * @return + */ + private boolean __gluInvertMatrixd(double[] src, double[] inverse) { + int i, j, k, swap; + double t; + double[][] temp = tempMatrix; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + temp[i][j] = src[i*4+j]; + } + } + __gluMakeIdentityd(inverse); + + for (i = 0; i < 4; i++) { + // + // Look for largest element in column + // + swap = i; + for (j = i + 1; j < 4; j++) { + if (Math.abs(temp[j][i]) > Math.abs(temp[i][i])) { + swap = j; + } + } + + if (swap != i) { + // + // Swap rows. + // + for (k = 0; k < 4; k++) { + t = temp[i][k]; + temp[i][k] = temp[swap][k]; + temp[swap][k] = t; + + t = inverse[i*4+k]; + inverse[i*4+k] = inverse[swap*4+k]; + inverse[swap*4+k] = t; + } + } + + if (temp[i][i] == 0) { + // + // No non-zero pivot. The matrix is singular, which shouldn't + // happen. This means the user gave us a bad matrix. + // + return false; + } + + t = temp[i][i]; + for (k = 0; k < 4; k++) { + temp[i][k] /= t; + inverse[i*4+k] /= t; + } + for (j = 0; j < 4; j++) { + if (j != i) { + t = temp[j][i]; + for (k = 0; k < 4; k++) { + temp[j][k] -= temp[i][k] * t; + inverse[j*4+k] -= inverse[i*4+k]*t; + } + } + } + } + return true; + } + + /** + * @param src + * @param inverse + * + * @return + */ + private boolean __gluInvertMatrixd(DoubleBuffer src, DoubleBuffer inverse) { + int i, j, k, swap; + double t; + + int srcPos = src.position(); + int invPos = inverse.position(); + + DoubleBuffer temp = tempMatrixBuf; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + temp.put(i*4+j, src.get(i*4+j + srcPos)); + } + } + __gluMakeIdentityd(inverse); + + for (i = 0; i < 4; i++) { + // + // Look for largest element in column + // + swap = i; + for (j = i + 1; j < 4; j++) { + if (Math.abs(temp.get(j*4+i)) > Math.abs(temp.get(i*4+i))) { + swap = j; + } + } + + if (swap != i) { + // + // Swap rows. + // + for (k = 0; k < 4; k++) { + t = temp.get(i*4+k); + temp.put(i*4+k, temp.get(swap*4+k)); + temp.put(swap*4+k, t); + + t = inverse.get(i*4+k + invPos); + inverse.put(i*4+k + invPos, inverse.get(swap*4+k + invPos)); + inverse.put(swap*4+k + invPos, t); + } + } + + if (temp.get(i*4+i) == 0) { + // + // No non-zero pivot. The matrix is singular, which shouldn't + // happen. This means the user gave us a bad matrix. + // + return false; + } + + t = temp.get(i*4+i); + for (k = 0; k < 4; k++) { + temp.put(i*4+k, temp.get(i*4+k) / t); + inverse.put(i*4+k + invPos, inverse.get(i*4+k + invPos) / t); + } + for (j = 0; j < 4; j++) { + if (j != i) { + t = temp.get(j*4+i); + for (k = 0; k < 4; k++) { + temp.put(j*4+k, temp.get(j*4+k) - temp.get(i*4+k) * t); + inverse.put(j*4+k + invPos, inverse.get(j*4+k + invPos) - inverse.get(i*4+k + invPos) * t); + } + } + } + } + return true; + } + + + /** + * @param a + * @param b + * @param r + */ + private void __gluMultMatricesd(double[] a, int a_offset, double[] b, int b_offset, double[] r) { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + r[i*4+j] = + a[i*4+0+a_offset]*b[0*4+j+b_offset] + + a[i*4+1+a_offset]*b[1*4+j+b_offset] + + a[i*4+2+a_offset]*b[2*4+j+b_offset] + + a[i*4+3+a_offset]*b[3*4+j+b_offset]; + } + } + } + + + /** + * @param a + * @param b + * @param r + */ + private void __gluMultMatricesd(DoubleBuffer a, DoubleBuffer b, DoubleBuffer r) { + int aPos = a.position(); + int bPos = b.position(); + int rPos = r.position(); + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + r.put(i*4+j + rPos, + a.get(i*4+0+aPos)*b.get(0*4+j+bPos) + + a.get(i*4+1+aPos)*b.get(1*4+j+bPos) + + a.get(i*4+2+aPos)*b.get(2*4+j+bPos) + + a.get(i*4+3+aPos)*b.get(3*4+j+bPos)); + } + } + } + + /** + * Normalize vector + * + * @param v + */ + private static void normalize(double[] v) { + double r; + + r = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + if ( r == 0.0 ) + return; + + r = 1.0 / r; + + v[0] *= r; + v[1] *= r; + v[2] *= r; + + return; + } + + /** + * Normalize vector + * + * @param v + */ + private static void normalize(DoubleBuffer v) { + double r; + + int vPos = v.position(); + + r = Math.sqrt(v.get(0+vPos) * v.get(0+vPos) + + v.get(1+vPos) * v.get(1+vPos) + + v.get(2+vPos) * v.get(2+vPos)); + if ( r == 0.0 ) + return; + + r = 1.0 / r; + + v.put(0+vPos, v.get(0+vPos) * r); + v.put(1+vPos, v.get(1+vPos) * r); + v.put(2+vPos, v.get(2+vPos) * r); + + return; + } + + + /** + * Calculate cross-product + * + * @param v1 + * @param v2 + * @param result + */ + private static void cross(double[] v1, double[] v2, double[] result) { + result[0] = v1[1] * v2[2] - v1[2] * v2[1]; + result[1] = v1[2] * v2[0] - v1[0] * v2[2]; + result[2] = v1[0] * v2[1] - v1[1] * v2[0]; + } + + /** + * Calculate cross-product + * + * @param v1 + * @param v2 + * @param result + */ + private static void cross(DoubleBuffer v1, DoubleBuffer v2, DoubleBuffer result) { + int v1Pos = v1.position(); + int v2Pos = v2.position(); + int rPos = result.position(); + + result.put(0+rPos, v1.get(1+v1Pos) * v2.get(2+v2Pos) - v1.get(2+v1Pos) * v2.get(1+v2Pos)); + result.put(1+rPos, v1.get(2+v1Pos) * v2.get(0+v2Pos) - v1.get(0+v1Pos) * v2.get(2+v2Pos)); + result.put(2+rPos, v1.get(0+v1Pos) * v2.get(1+v2Pos) - v1.get(1+v1Pos) * v2.get(0+v2Pos)); + } + + /** + * Method gluOrtho2D. + * + * @param left + * @param right + * @param bottom + * @param top + */ + public void gluOrtho2D(GL2 gl, double left, double right, double bottom, double top) { + gl.glOrtho(left, right, bottom, top, -1, 1); + } + + /** + * Method gluPerspective. + * + * @param fovy + * @param aspect + * @param zNear + * @param zFar + */ + public void gluPerspective(GL2 gl, double fovy, double aspect, double zNear, double zFar) { + double sine, cotangent, deltaZ; + double radians = fovy / 2 * Math.PI / 180; + + deltaZ = zFar - zNear; + sine = Math.sin(radians); + + if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) { + return; + } + + cotangent = Math.cos(radians) / sine; + + __gluMakeIdentityd(matrixBuf); + + matrixBuf.put(0 * 4 + 0, cotangent / aspect); + matrixBuf.put(1 * 4 + 1, cotangent); + matrixBuf.put(2 * 4 + 2, - (zFar + zNear) / deltaZ); + matrixBuf.put(2 * 4 + 3, -1); + matrixBuf.put(3 * 4 + 2, -2 * zNear * zFar / deltaZ); + matrixBuf.put(3 * 4 + 3, 0); + + gl.glMultMatrixd(matrixBuf); + } + + /** + * Method gluLookAt + * + * @param eyex + * @param eyey + * @param eyez + * @param centerx + * @param centery + * @param centerz + * @param upx + * @param upy + * @param upz + */ + public void gluLookAt(GL2 gl, + double eyex, + double eyey, + double eyez, + double centerx, + double centery, + double centerz, + double upx, + double upy, + double upz) { + DoubleBuffer forward = this.forwardBuf; + DoubleBuffer side = this.sideBuf; + DoubleBuffer up = this.upBuf; + + forward.put(0, centerx - eyex); + forward.put(1, centery - eyey); + forward.put(2, centerz - eyez); + + up.put(0, upx); + up.put(1, upy); + up.put(2, upz); + + normalize(forward); + + /* Side = forward x up */ + cross(forward, up, side); + normalize(side); + + /* Recompute up as: up = side x forward */ + cross(side, forward, up); + + __gluMakeIdentityd(matrixBuf); + matrixBuf.put(0 * 4 + 0, side.get(0)); + matrixBuf.put(1 * 4 + 0, side.get(1)); + matrixBuf.put(2 * 4 + 0, side.get(2)); + + matrixBuf.put(0 * 4 + 1, up.get(0)); + matrixBuf.put(1 * 4 + 1, up.get(1)); + matrixBuf.put(2 * 4 + 1, up.get(2)); + + matrixBuf.put(0 * 4 + 2, -forward.get(0)); + matrixBuf.put(1 * 4 + 2, -forward.get(1)); + matrixBuf.put(2 * 4 + 2, -forward.get(2)); + + gl.glMultMatrixd(matrixBuf); + gl.glTranslated(-eyex, -eyey, -eyez); + } + + /** + * Method gluProject + * + * @param objx + * @param objy + * @param objz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param win_pos + * + * @return + */ + public boolean gluProject(double objx, + double objy, + double objz, + double[] modelMatrix, + int modelMatrix_offset, + double[] projMatrix, + int projMatrix_offset, + int[] viewport, + int viewport_offset, + double[] win_pos, + int win_pos_offset ) { + + double[] in = this.in; + double[] out = this.out; + + in[0] = objx; + in[1] = objy; + in[2] = objz; + in[3] = 1.0; + + __gluMultMatrixVecd(modelMatrix, modelMatrix_offset, in, out); + __gluMultMatrixVecd(projMatrix, projMatrix_offset, out, in); + + if (in[3] == 0.0) + return false; + + in[3] = (1.0 / in[3]) * 0.5; + + // Map x, y and z to range 0-1 + in[0] = in[0] * in[3] + 0.5f; + in[1] = in[1] * in[3] + 0.5f; + in[2] = in[2] * in[3] + 0.5f; + + // Map x,y to viewport + win_pos[0+win_pos_offset] = in[0] * viewport[2+viewport_offset] + viewport[0+viewport_offset]; + win_pos[1+win_pos_offset] = in[1] * viewport[3+viewport_offset] + viewport[1+viewport_offset]; + win_pos[2+win_pos_offset] = in[2]; + + return true; + } + + /** + * Method gluProject + * + * @param objx + * @param objy + * @param objz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param win_pos + * + * @return + */ + public boolean gluProject(double objx, + double objy, + double objz, + DoubleBuffer modelMatrix, + DoubleBuffer projMatrix, + IntBuffer viewport, + DoubleBuffer win_pos) { + + DoubleBuffer in = this.inBuf; + DoubleBuffer out = this.outBuf; + + in.put(0, objx); + in.put(1, objy); + in.put(2, objz); + in.put(3, 1.0); + + __gluMultMatrixVecd(modelMatrix, in, out); + __gluMultMatrixVecd(projMatrix, out, in); + + if (in.get(3) == 0.0) + return false; + + in.put(3, (1.0 / in.get(3)) * 0.5); + + // Map x, y and z to range 0-1 + in.put(0, in.get(0) * in.get(3) + 0.5f); + in.put(1, in.get(1) * in.get(3) + 0.5f); + in.put(2, in.get(2) * in.get(3) + 0.5f); + + // Map x,y to viewport + int vPos = viewport.position(); + int wPos = win_pos.position(); + win_pos.put(0+wPos, in.get(0) * viewport.get(2+vPos) + viewport.get(0+vPos)); + win_pos.put(1+wPos, in.get(1) * viewport.get(3+vPos) + viewport.get(1+vPos)); + win_pos.put(2+wPos, in.get(2)); + + return true; + } + + + /** + * Method gluUnproject + * + * @param winx + * @param winy + * @param winz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param obj_pos + * + * @return + */ + public boolean gluUnProject(double winx, + double winy, + double winz, + double[] modelMatrix, + int modelMatrix_offset, + double[] projMatrix, + int projMatrix_offset, + int[] viewport, + int viewport_offset, + double[] obj_pos, + int obj_pos_offset) { + double[] in = this.in; + double[] out = this.out; + + __gluMultMatricesd(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); + + if (!__gluInvertMatrixd(matrix, matrix)) + return false; + + in[0] = winx; + in[1] = winy; + in[2] = winz; + in[3] = 1.0; + + // Map x and y from window coordinates + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; + + // Map to range -1 to 1 + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecd(matrix, 0, in, out); + + if (out[3] == 0.0) + return false; + + out[3] = 1.0 / out[3]; + + obj_pos[0+obj_pos_offset] = out[0] * out[3]; + obj_pos[1+obj_pos_offset] = out[1] * out[3]; + obj_pos[2+obj_pos_offset] = out[2] * out[3]; + + return true; + } + + + /** + * Method gluUnproject + * + * @param winx + * @param winy + * @param winz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param obj_pos + * + * @return + */ + public boolean gluUnProject(double winx, + double winy, + double winz, + DoubleBuffer modelMatrix, + DoubleBuffer projMatrix, + IntBuffer viewport, + DoubleBuffer obj_pos) { + DoubleBuffer in = this.inBuf; + DoubleBuffer out = this.outBuf; + + __gluMultMatricesd(modelMatrix, projMatrix, matrixBuf); + + if (!__gluInvertMatrixd(matrixBuf, matrixBuf)) + return false; + + in.put(0, winx); + in.put(1, winy); + in.put(2, winz); + in.put(3, 1.0); + + // Map x and y from window coordinates + int vPos = viewport.position(); + int oPos = obj_pos.position(); + in.put(0, (in.get(0) - viewport.get(0+vPos)) / viewport.get(2+vPos)); + in.put(1, (in.get(1) - viewport.get(1+vPos)) / viewport.get(3+vPos)); + + // Map to range -1 to 1 + in.put(0, in.get(0) * 2 - 1); + in.put(1, in.get(1) * 2 - 1); + in.put(2, in.get(2) * 2 - 1); + + __gluMultMatrixVecd(matrixBuf, in, out); + + if (out.get(3) == 0.0) + return false; + + out.put(3, 1.0 / out.get(3)); + + obj_pos.put(0+oPos, out.get(0) * out.get(3)); + obj_pos.put(1+oPos, out.get(1) * out.get(3)); + obj_pos.put(2+oPos, out.get(2) * out.get(3)); + + return true; + } + + + /** + * Method gluUnproject4 + * + * @param winx + * @param winy + * @param winz + * @param clipw + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param near + * @param far + * @param obj_pos + * + * @return + */ + public boolean gluUnProject4(double winx, + double winy, + double winz, + double clipw, + double[] modelMatrix, + int modelMatrix_offset, + double[] projMatrix, + int projMatrix_offset, + int[] viewport, + int viewport_offset, + double near, + double far, + double[] obj_pos, + int obj_pos_offset ) { + double[] in = this.in; + double[] out = this.out; + + __gluMultMatricesd(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); + + if (!__gluInvertMatrixd(matrix, matrix)) + return false; + + in[0] = winx; + in[1] = winy; + in[2] = winz; + in[3] = clipw; + + // Map x and y from window coordinates + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; + in[2] = (in[2] - near) / (far - near); + + // Map to range -1 to 1 + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecd(matrix, 0, in, out); + + if (out[3] == 0.0) + return false; + + obj_pos[0+obj_pos_offset] = out[0]; + obj_pos[1+obj_pos_offset] = out[1]; + obj_pos[2+obj_pos_offset] = out[2]; + obj_pos[3+obj_pos_offset] = out[3]; + return true; + } + + /** + * Method gluUnproject4 + * + * @param winx + * @param winy + * @param winz + * @param clipw + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param near + * @param far + * @param obj_pos + * + * @return + */ + public boolean gluUnProject4(double winx, + double winy, + double winz, + double clipw, + DoubleBuffer modelMatrix, + DoubleBuffer projMatrix, + IntBuffer viewport, + double near, + double far, + DoubleBuffer obj_pos) { + DoubleBuffer in = this.inBuf; + DoubleBuffer out = this.outBuf; + + __gluMultMatricesd(modelMatrix, projMatrix, matrixBuf); + + if (!__gluInvertMatrixd(matrixBuf, matrixBuf)) + return false; + + in.put(0, winx); + in.put(1, winy); + in.put(2, winz); + in.put(3, clipw); + + // Map x and y from window coordinates + int vPos = viewport.position(); + in.put(0, (in.get(0) - viewport.get(0+vPos)) / viewport.get(2+vPos)); + in.put(1, (in.get(1) - viewport.get(1+vPos)) / viewport.get(3+vPos)); + in.put(2, (in.get(2) - near) / (far - near)); + + // Map to range -1 to 1 + in.put(0, in.get(0) * 2 - 1); + in.put(1, in.get(1) * 2 - 1); + in.put(2, in.get(2) * 2 - 1); + + __gluMultMatrixVecd(matrixBuf, in, out); + + if (out.get(3) == 0.0) + return false; + + int oPos = obj_pos.position(); + obj_pos.put(0+oPos, out.get(0)); + obj_pos.put(1+oPos, out.get(1)); + obj_pos.put(2+oPos, out.get(2)); + obj_pos.put(3+oPos, out.get(3)); + return true; + } + + + /** + * Method gluPickMatrix + * + * @param x + * @param y + * @param deltaX + * @param deltaY + * @param viewport + */ + public void gluPickMatrix(GL2 gl, + double x, + double y, + double deltaX, + double deltaY, + IntBuffer viewport) { + if (deltaX <= 0 || deltaY <= 0) { + return; + } + + /* Translate and scale the picked region to the entire window */ + int vPos = viewport.position(); + gl.glTranslated((viewport.get(2+vPos) - 2 * (x - viewport.get(0+vPos))) / deltaX, + (viewport.get(3+vPos) - 2 * (y - viewport.get(1+vPos))) / deltaY, + 0); + gl.glScaled(viewport.get(2) / deltaX, viewport.get(3) / deltaY, 1.0); + } + + /** + * Method gluPickMatrix + * + * @param x + * @param y + * @param deltaX + * @param deltaY + * @param viewport + * @param viewport_offset + */ + public void gluPickMatrix(GL2 gl, + double x, + double y, + double deltaX, + double deltaY, + int[] viewport, + int viewport_offset) { + if (deltaX <= 0 || deltaY <= 0) { + return; + } + + /* Translate and scale the picked region to the entire window */ + gl.glTranslated((viewport[2+viewport_offset] - 2 * (x - viewport[0+viewport_offset])) / deltaX, + (viewport[3+viewport_offset] - 2 * (y - viewport[1+viewport_offset])) / deltaY, + 0); + gl.glScaled(viewport[2+viewport_offset] / deltaX, viewport[3+viewport_offset] / deltaY, 1.0); + } +} diff --git a/src/jogl/classes/jogamp/opengl/gl2/Util.java b/src/jogl/classes/jogamp/opengl/gl2/Util.java new file mode 100644 index 000000000..83f98a65f --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/gl2/Util.java @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE COPYRIGHT OWNER 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. + */ + +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package jogamp.opengl.gl2; + +import jogamp.opengl.*; + +import java.nio.IntBuffer; +import javax.media.opengl.*; + +/** + * Util.java + * <p/> + * <p/> + * Created 7-jan-2004 + * + * @author Erik Duijs + */ +class Util { + + /** + * temp int[] of one for getting an int from some GL functions + */ + private int[] scratch = new int[1]; + + /** + * Return ceiling of integer division + * + * @param a + * @param b + * + * @return int + */ + protected static int ceil(int a, int b) { + return (a % b == 0 ? a / b : a / b + 1); + } + + /** + * Method compPerPix. + * + * @param format + * + * @return int + */ + protected static int compPerPix(int format) { + /* Determine number of components per pixel */ + switch ( format ) { + case GL2.GL_COLOR_INDEX: + case GL2.GL_STENCIL_INDEX: + case GL2.GL_DEPTH_COMPONENT: + case GL2.GL_RED: + case GL2.GL_GREEN: + case GL2.GL_BLUE: + case GL2.GL_ALPHA: + case GL2.GL_LUMINANCE: + return 1; + case GL2.GL_LUMINANCE_ALPHA: + return 2; + case GL2.GL_RGB: + case GL2.GL_BGR: + return 3; + case GL2.GL_RGBA: + case GL2.GL_BGRA: + return 4; + default : + return -1; + } + } + + /** + * Method nearestPower. + * <p/> + * Compute the nearest power of 2 number. This algorithm is a little strange, but it works quite well. + * + * @param value + * + * @return int + */ + protected static int nearestPower(int value) { + int i; + + i = 1; + + /* Error! */ + if ( value == 0 ) + return -1; + + for ( ; ; ) { + if ( value == 1 ) { + return i; + } else if ( value == 3 ) { + return i << 2; + } + value >>= 1; + i <<= 1; + } + } + + /** + * Method bytesPerPixel. + * + * @param format + * @param type + * + * @return int + */ + protected static int bytesPerPixel(int format, int type) { + int n, m; + + switch ( format ) { + case GL2.GL_COLOR_INDEX: + case GL2.GL_STENCIL_INDEX: + case GL2.GL_DEPTH_COMPONENT: + case GL2.GL_RED: + case GL2.GL_GREEN: + case GL2.GL_BLUE: + case GL2.GL_ALPHA: + case GL2.GL_LUMINANCE: + n = 1; + break; + case GL2.GL_LUMINANCE_ALPHA: + n = 2; + break; + case GL2.GL_RGB: + case GL2.GL_BGR: + n = 3; + break; + case GL2.GL_RGBA: + case GL2.GL_BGRA: + n = 4; + break; + default : + n = 0; + } + + switch ( type ) { + case GL2.GL_UNSIGNED_BYTE: + m = 1; + break; + case GL2.GL_BYTE: + m = 1; + break; + case GL2.GL_BITMAP: + m = 1; + break; + case GL2.GL_UNSIGNED_SHORT: + m = 2; + break; + case GL2.GL_SHORT: + m = 2; + break; + case GL2.GL_UNSIGNED_INT: + m = 4; + break; + case GL2.GL_INT: + m = 4; + break; + case GL2.GL_FLOAT: + m = 4; + break; + default : + m = 0; + } + + return n * m; + } + + /** + * Convenience method for returning an int, rather than getting it out of a buffer yourself. + * + * @param what + * + * @return int + */ + protected int glGetIntegerv(GL gl, int what) { + gl.glGetIntegerv(what, scratch, 0); + return scratch[0]; + } +} diff --git a/src/jogl/classes/jogamp/opengl/gl2/fixme/GLObjectTracker.java b/src/jogl/classes/jogamp/opengl/gl2/fixme/GLObjectTracker.java new file mode 100644 index 000000000..903a82fac --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/gl2/fixme/GLObjectTracker.java @@ -0,0 +1,835 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.gl2; + +import jogamp.opengl.*; + +import java.nio.*; +import javax.media.opengl.*; + +/** + * Tracks the creation of server-side OpenGL objects which can be + * shared between contexts. Ordinarily, when an OpenGL context is + * deleted and no other contexts are sharing server-side objects with + * it, all of the server-side objects are automatically deleted by the + * OpenGL implementation. It is not necessary for the end user to + * explicitly delete these objects. However, when the Java2D/OpenGL + * pipeline is active and frame buffer objects are being used for + * rendering, it is necessary for all OpenGL contexts created by JOGL + * to share server-side objects with the Java2D OpenGL context. This + * means that these objects "leak" into the namespace used by Java2D. + * In order to prevent memory leaks and to present the same + * programming model to the end user, it is necessary to track the + * creation and destruction of all of these server-side OpenGL objects + * and to explicitly release them when all of the JOGL-created + * contexts which can see them have been released. <P> + * + * The {@link #ref ref} and {@link #unref unref} methods should be + * used during the creation and destruction of OpenGL contexts by JOGL + * in order to update the liveness of the objects being tracked. The + * various other methods should be called by the OpenGL binding in the + * various named methods. + */ + +public class GLObjectTracker { + private static final boolean DEBUG = Debug.debug("GLStatusTracker"); + + //---------------------------------------------------------------------- + // Adders + // + + // glGenBuffers + public synchronized void addBuffers(int n, IntBuffer ids) { + add(getList(BUFFERS), n, ids); + } + + // glGenBuffers + public synchronized void addBuffers(int n, int[] ids, int ids_offset) { + add(getList(BUFFERS), n, ids, ids_offset); + } + + // glGenBuffersARB + public synchronized void addBuffersARB(int n, IntBuffer ids) { + add(getList(BUFFERS_ARB), n, ids); + } + + // glGenBuffersARB + public synchronized void addBuffersARB(int n, int[] ids, int ids_offset) { + add(getList(BUFFERS_ARB), n, ids, ids_offset); + } + + // glGenFencesAPPLE + public synchronized void addFencesAPPLE(int n, IntBuffer ids) { + add(getList(FENCES_APPLE), n, ids); + } + + // glGenFencesAPPLE + public synchronized void addFencesAPPLE(int n, int[] ids, int ids_offset) { + add(getList(FENCES_APPLE), n, ids, ids_offset); + } + + // glGenFencesNV + public synchronized void addFencesNV(int n, IntBuffer ids) { + add(getList(FENCES_NV), n, ids); + } + + // glGenFencesNV + public synchronized void addFencesNV(int n, int[] ids, int ids_offset) { + add(getList(FENCES_NV), n, ids, ids_offset); + } + + // glGenFragmentShadersATI + public synchronized void addFragmentShadersATI(int start, int n) { + add(getList(FRAGMENT_SHADERS_ATI), start, n); + } + + // glGenFramebuffersEXT + public synchronized void addFramebuffersEXT(int n, IntBuffer ids) { + add(getList(FRAMEBUFFERS_EXT), n, ids); + } + + // glGenFramebuffersEXT + public synchronized void addFramebuffersEXT(int n, int[] ids, int ids_offset) { + add(getList(FRAMEBUFFERS_EXT), n, ids, ids_offset); + } + + // glGenLists + public synchronized void addLists(int start, int n) { + add(getList(LISTS), start, n); + } + + // glGenOcclusionQueriesNV + public synchronized void addOcclusionQueriesNV(int n, IntBuffer ids) { + add(getList(OCCLUSION_QUERIES_NV), n, ids); + } + + // glGenOcclusionQueriesNV + public synchronized void addOcclusionQueriesNV(int n, int[] ids, int ids_offset) { + add(getList(OCCLUSION_QUERIES_NV), n, ids, ids_offset); + } + + // glCreateProgram + public synchronized void addProgramObject(int obj) { + add(getList(PROGRAM_OBJECTS), obj, 1); + } + + // glCreateProgramObjectARB + public synchronized void addProgramObjectARB(int obj) { + add(getList(PROGRAM_AND_SHADER_OBJECTS_ARB), obj, 1); + } + + // glGenProgramsARB + public synchronized void addProgramsARB(int n, IntBuffer ids) { + add(getList(PROGRAMS_ARB), n, ids); + } + + // glGenProgramsARB + public synchronized void addProgramsARB(int n, int[] ids, int ids_offset) { + add(getList(PROGRAMS_ARB), n, ids, ids_offset); + } + + // glGenProgramsNV + public synchronized void addProgramsNV(int n, IntBuffer ids) { + add(getList(PROGRAMS_NV), n, ids); + } + + // glGenProgramsNV + public synchronized void addProgramsNV(int n, int[] ids, int ids_offset) { + add(getList(PROGRAMS_NV), n, ids, ids_offset); + } + + // glGenQueries + public synchronized void addQueries(int n, IntBuffer ids) { + add(getList(QUERIES), n, ids); + } + + // glGenQueries + public synchronized void addQueries(int n, int[] ids, int ids_offset) { + add(getList(QUERIES), n, ids, ids_offset); + } + + // glGenQueriesARB + public synchronized void addQueriesARB(int n, IntBuffer ids) { + add(getList(QUERIES_ARB), n, ids); + } + + // glGenQueriesARB + public synchronized void addQueriesARB(int n, int[] ids, int ids_offset) { + add(getList(QUERIES_ARB), n, ids, ids_offset); + } + + // glGenRenderbuffersEXT + public synchronized void addRenderbuffersEXT(int n, IntBuffer ids) { + add(getList(RENDERBUFFERS_EXT), n, ids); + } + + // glGenRenderbuffersEXT + public synchronized void addRenderbuffersEXT(int n, int[] ids, int ids_offset) { + add(getList(RENDERBUFFERS_EXT), n, ids, ids_offset); + } + + // glCreateShader + public synchronized void addShaderObject(int obj) { + add(getList(SHADER_OBJECTS), obj, 1); + } + + // glCreateShaderObjectARB + public synchronized void addShaderObjectARB(int obj) { + add(getList(PROGRAM_AND_SHADER_OBJECTS_ARB), obj, 1); + } + + // glGenTextures + public synchronized void addTextures(int n, IntBuffer ids) { + add(getList(TEXTURES), n, ids); + } + + // glGenTextures + public synchronized void addTextures(int n, int[] ids, int ids_offset) { + add(getList(TEXTURES), n, ids, ids_offset); + } + + // glGenVertexArraysAPPLE + public synchronized void addVertexArraysAPPLE(int n, IntBuffer ids) { + add(getList(VERTEX_ARRAYS_APPLE), n, ids); + } + + // glGenVertexArraysAPPLE + public synchronized void addVertexArraysAPPLE(int n, int[] ids, int ids_offset) { + add(getList(VERTEX_ARRAYS_APPLE), n, ids, ids_offset); + } + + // glGenVertexShadersEXT + public synchronized void addVertexShadersEXT(int start, int n) { + add(getList(VERTEX_SHADERS_EXT), start, n); + } + + //---------------------------------------------------------------------- + // Removers + // + + // glDeleteBuffers + public synchronized void removeBuffers(int n, IntBuffer ids) { + remove(getList(BUFFERS), n, ids); + } + + // glDeleteBuffers + public synchronized void removeBuffers(int n, int[] ids, int ids_offset) { + remove(getList(BUFFERS), n, ids, ids_offset); + } + + // glDeleteBuffersARB + public synchronized void removeBuffersARB(int n, IntBuffer ids) { + remove(getList(BUFFERS_ARB), n, ids); + } + + // glDeleteBuffersARB + public synchronized void removeBuffersARB(int n, int[] ids, int ids_offset) { + remove(getList(BUFFERS_ARB), n, ids, ids_offset); + } + + // glDeleteFencesAPPLE + public synchronized void removeFencesAPPLE(int n, IntBuffer ids) { + remove(getList(FENCES_APPLE), n, ids); + } + + // glDeleteFencesAPPLE + public synchronized void removeFencesAPPLE(int n, int[] ids, int ids_offset) { + remove(getList(FENCES_APPLE), n, ids, ids_offset); + } + + // glDeleteFencesNV + public synchronized void removeFencesNV(int n, IntBuffer ids) { + remove(getList(FENCES_NV), n, ids); + } + + // glDeleteFencesNV + public synchronized void removeFencesNV(int n, int[] ids, int ids_offset) { + remove(getList(FENCES_NV), n, ids, ids_offset); + } + + // glDeleteFragmentShaderATI + public synchronized void removeFragmentShaderATI(int obj) { + remove(getList(FRAGMENT_SHADERS_ATI), obj, 1); + } + + // glDeleteFramebuffersEXT + public synchronized void removeFramebuffersEXT(int n, IntBuffer ids) { + remove(getList(FRAMEBUFFERS_EXT), n, ids); + } + + // glDeleteFramebuffersEXT + public synchronized void removeFramebuffersEXT(int n, int[] ids, int ids_offset) { + remove(getList(FRAMEBUFFERS_EXT), n, ids, ids_offset); + } + + // glDeleteLists + public synchronized void removeLists(int start, int n) { + remove(getList(LISTS), start, n); + } + + // glDeleteOcclusionQueriesNV + public synchronized void removeOcclusionQueriesNV(int n, IntBuffer ids) { + remove(getList(OCCLUSION_QUERIES_NV), n, ids); + } + + // glDeleteOcclusionQueriesNV + public synchronized void removeOcclusionQueriesNV(int n, int[] ids, int ids_offset) { + remove(getList(OCCLUSION_QUERIES_NV), n, ids, ids_offset); + } + + // glDeleteProgram + public synchronized void removeProgramObject(int obj) { + remove(getList(PROGRAM_OBJECTS), obj, 1); + } + + // glDeleteObjectARB + public synchronized void removeProgramOrShaderObjectARB(int obj) { + remove(getList(PROGRAM_AND_SHADER_OBJECTS_ARB), obj, 1); + } + + // glDeleteProgramsARB + public synchronized void removeProgramsARB(int n, IntBuffer ids) { + remove(getList(PROGRAMS_ARB), n, ids); + } + + // glDeleteProgramsARB + public synchronized void removeProgramsARB(int n, int[] ids, int ids_offset) { + remove(getList(PROGRAMS_ARB), n, ids, ids_offset); + } + + // glDeleteProgramsNV + public synchronized void removeProgramsNV(int n, IntBuffer ids) { + remove(getList(PROGRAMS_NV), n, ids); + } + + // glDeleteProgramsNV + public synchronized void removeProgramsNV(int n, int[] ids, int ids_offset) { + remove(getList(PROGRAMS_NV), n, ids, ids_offset); + } + + // glDeleteQueries + public synchronized void removeQueries(int n, IntBuffer ids) { + remove(getList(QUERIES), n, ids); + } + + // glDeleteQueries + public synchronized void removeQueries(int n, int[] ids, int ids_offset) { + remove(getList(QUERIES), n, ids, ids_offset); + } + + // glDeleteQueriesARB + public synchronized void removeQueriesARB(int n, IntBuffer ids) { + remove(getList(QUERIES_ARB), n, ids); + } + + // glDeleteQueriesARB + public synchronized void removeQueriesARB(int n, int[] ids, int ids_offset) { + remove(getList(QUERIES_ARB), n, ids, ids_offset); + } + + // glDeleteRenderbuffersEXT + public synchronized void removeRenderbuffersEXT(int n, IntBuffer ids) { + remove(getList(RENDERBUFFERS_EXT), n, ids); + } + + // glDeleteRenderbuffersEXT + public synchronized void removeRenderbuffersEXT(int n, int[] ids, int ids_offset) { + remove(getList(RENDERBUFFERS_EXT), n, ids, ids_offset); + } + + // glDeleteShader + public synchronized void removeShaderObject(int obj) { + remove(getList(SHADER_OBJECTS), obj, 1); + } + + // glDeleteTextures + public synchronized void removeTextures(int n, IntBuffer ids) { + remove(getList(TEXTURES), n, ids); + } + + // glDeleteTextures + public synchronized void removeTextures(int n, int[] ids, int ids_offset) { + remove(getList(TEXTURES), n, ids, ids_offset); + } + + // glDeleteVertexArraysAPPLE + public synchronized void removeVertexArraysAPPLE(int n, IntBuffer ids) { + remove(getList(VERTEX_ARRAYS_APPLE), n, ids); + } + + // glDeleteVertexArraysAPPLE + public synchronized void removeVertexArraysAPPLE(int n, int[] ids, int ids_offset) { + remove(getList(VERTEX_ARRAYS_APPLE), n, ids, ids_offset); + } + + // glDeleteVertexShaderEXT + public synchronized void removeVertexShaderEXT(int obj) { + remove(getList(VERTEX_SHADERS_EXT), obj, 1); + } + + //---------------------------------------------------------------------- + // Reference count maintenance and manual deletion + // + + public synchronized void transferAll(GLObjectTracker other) { + for (int i = 0; i < lists.length; i++) { + getList(i).addAll(other.lists[i]); + if (other.lists[i] != null) { + other.lists[i].clear(); + } + } + dirty = true; + } + + public synchronized void ref() { + ++refCount; + } + + public void unref(GLObjectTracker deletedObjectPool) { + boolean tryDelete = false; + synchronized (this) { + if (--refCount == 0) { + tryDelete = true; + } + } + if (tryDelete) { + // See whether we should try to do the work now or whether we + // have to postpone + GLContext cur = GLContext.getCurrent(); + if ((cur != null) && + (cur instanceof GLContextImpl)) { + GLContextImpl curImpl = (GLContextImpl) cur; + if (deletedObjectPool != null && + deletedObjectPool == curImpl.getDeletedObjectTracker()) { + // Should be safe to delete these objects now + try { + delete((GL2)curImpl.getGL()); + return; + } catch (GLException e) { + // Shouldn't happen, but if it does, transfer all objects + // to the deleted object pool hoping we can later clean + // them up + deletedObjectPool.transferAll(this); + throw(e); + } + } + } + // If we get here, we couldn't attempt to delete the objects + // right now; instead try to transfer them to the + // deletedObjectPool for later cleanup (FIXME: should consider + // throwing an exception if deletedObjectPool is null, since + // that shouldn't happen) + if (DEBUG) { + String s = null; + if (cur == null) { + s = "current context was null"; + } else if (!(cur instanceof GLContextImpl)) { + s = "current context was not a GLContextImpl"; + } else if (deletedObjectPool == null) { + s = "no current deletedObjectPool"; + } else if (deletedObjectPool != ((GLContextImpl) cur).getDeletedObjectTracker()) { + s = "deletedObjectTracker didn't match"; + if (((GLContextImpl) cur).getDeletedObjectTracker() == null) { + s += " (other was null)"; + } + } else { + s = "unknown reason"; + } + System.err.println("Deferred destruction of server-side OpenGL objects into " + deletedObjectPool + ": " + s); + } + + if (deletedObjectPool != null) { + deletedObjectPool.transferAll(this); + } + } + } + + public void clean(GL2 gl) { + if (dirty) { + try { + delete(gl); + dirty = false; + } catch (GLException e) { + // FIXME: not sure what to do here; probably a bad idea to be + // throwing exceptions during an otherwise-successful makeCurrent + } + } + } + + + //---------------------------------------------------------------------- + // Internals only below this point + // + + // Kinds of sharable server-side OpenGL objects this class tracks + private static final int BUFFERS = 0; + private static final int BUFFERS_ARB = 1; + private static final int FENCES_APPLE = 2; + private static final int FENCES_NV = 3; + private static final int FRAGMENT_SHADERS_ATI = 4; + private static final int FRAMEBUFFERS_EXT = 5; + private static final int LISTS = 6; + private static final int OCCLUSION_QUERIES_NV = 7; + private static final int PROGRAM_AND_SHADER_OBJECTS_ARB = 8; + private static final int PROGRAM_OBJECTS = 9; + private static final int PROGRAMS_ARB = 10; + private static final int PROGRAMS_NV = 11; + private static final int QUERIES = 12; + private static final int QUERIES_ARB = 13; + private static final int RENDERBUFFERS_EXT = 14; + private static final int SHADER_OBJECTS = 15; + private static final int TEXTURES = 16; + private static final int VERTEX_ARRAYS_APPLE = 17; + private static final int VERTEX_SHADERS_EXT = 18; + private static final int NUM_OBJECT_TYPES = 19; + + static abstract class Deleter { + public abstract void delete(GL2 gl, int obj); + } + + static class ObjectList { + private static final int MIN_CAPACITY = 4; + + private int size; + private int capacity; + private int[] data; + private Deleter deleter; + private String name; + + public ObjectList(Deleter deleter) { + this.deleter = deleter; + clear(); + } + + public void add(int obj) { + if (size == capacity) { + int newCapacity = 2 * capacity; + int[] newData = new int[newCapacity]; + System.arraycopy(data, 0, newData, 0, size); + data = newData; + capacity = newCapacity; + } + + data[size++] = obj; + } + + public void addAll(ObjectList other) { + if (other == null) { + return; + } + for (int i = 0; i < other.size; i++) { + add(other.data[i]); + } + } + + public boolean remove(int value) { + for (int i = 0; i < size; i++) { + if (data[i] == value) { + if (i < size - 1) { + System.arraycopy(data, i+1, data, i, size - i - 1); + } + --size; + if ((size < capacity / 4) && + (capacity > MIN_CAPACITY)) { + int newCapacity = capacity / 4; + if (newCapacity < MIN_CAPACITY) { + newCapacity = MIN_CAPACITY; + } + int[] newData = new int[newCapacity]; + System.arraycopy(data, 0, newData, 0, size); + data = newData; + capacity = newCapacity; + } + return true; + } + } + return false; + } + + public void setName(String name) { + if (DEBUG) { + this.name = name; + } + } + + public void delete(GL2 gl) { + // Just in case we start throwing exceptions during deletion, + // make sure we make progress rather than going into an infinite + // loop + while (size > 0) { + int obj = data[size - 1]; + --size; + if (DEBUG) { + System.err.println("Deleting server-side OpenGL object " + obj + + ((name != null) ? (" (" + name + ")") : "")); + } + deleter.delete(gl, obj); + } + } + + public void clear() { + size = 0; + capacity = MIN_CAPACITY; + data = new int[capacity]; + } + } + + private ObjectList[] lists = new ObjectList[NUM_OBJECT_TYPES]; + private int refCount; + private boolean dirty; + + private void add(ObjectList list, int n, IntBuffer ids) { + int pos = ids.position(); + for (int i = 0; i < n; i++) { + list.add(ids.get(pos + i)); + } + } + + private void add(ObjectList list, int n, int[] ids, int ids_offset) { + for (int i = 0; i < n; i++) { + list.add(ids[i + ids_offset]); + } + } + + private void add(ObjectList list, int start, int n) { + for (int i = 0; i < n; i++) { + list.add(start + i); + } + } + + private void remove(ObjectList list, int n, IntBuffer ids) { + int pos = ids.position(); + for (int i = 0; i < n; i++) { + list.remove(ids.get(pos + i)); + } + } + + private void remove(ObjectList list, int n, int[] ids, int ids_offset) { + for (int i = 0; i < n; i++) { + list.remove(ids[i + ids_offset]); + } + } + + private void remove(ObjectList list, int start, int n) { + for (int i = 0; i < n; i++) { + list.remove(start + i); + } + } + + private ObjectList getList(int which) { + ObjectList list = lists[which]; + if (list == null) { + Deleter deleter = null; + String name = null; + // Figure out which deleter we need + switch (which) { + case BUFFERS: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteBuffers(1, new int[] { obj }, 0); + } + }; + name = "buffer"; + break; + case BUFFERS_ARB: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteBuffersARB(1, new int[] { obj }, 0); + } + }; + name = "ARB buffer"; + break; + case FENCES_APPLE: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteFencesAPPLE(1, new int[] { obj }, 0); + } + }; + name = "APPLE fence"; + break; + case FENCES_NV: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteFencesNV(1, new int[] { obj }, 0); + } + }; + name = "NV fence"; + break; + case FRAGMENT_SHADERS_ATI: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteFragmentShaderATI(obj); + } + }; + name = "ATI fragment shader"; + break; + case FRAMEBUFFERS_EXT: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteFramebuffersEXT(1, new int[] { obj }, 0); + } + }; + name = "EXT framebuffer"; + break; + case LISTS: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteLists(obj, 1); + } + }; + name = "display list"; + break; + case OCCLUSION_QUERIES_NV: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteOcclusionQueriesNV(1, new int[] { obj }, 0); + } + }; + name = "NV occlusion query"; + break; + case PROGRAM_AND_SHADER_OBJECTS_ARB: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteObjectARB(obj); + } + }; + name = "ARB program or shader object"; + break; + case PROGRAM_OBJECTS: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteProgram(obj); + } + }; + name = "program object"; + break; + case PROGRAMS_ARB: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteProgramsARB(1, new int[] { obj }, 0); + } + }; + name = "ARB program object"; + break; + case PROGRAMS_NV: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteProgramsNV(1, new int[] { obj }, 0); + } + }; + name = "NV program"; + break; + case QUERIES: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteQueries(1, new int[] { obj }, 0); + } + }; + name = "query"; + break; + case QUERIES_ARB: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteQueriesARB(1, new int[] { obj }, 0); + } + }; + name = "ARB query"; + break; + case RENDERBUFFERS_EXT: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteRenderbuffersEXT(1, new int[] { obj }, 0); + } + }; + name = "EXT renderbuffer"; + break; + case SHADER_OBJECTS: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteShader(obj); + } + }; + name = "shader object"; + break; + case TEXTURES: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteTextures(1, new int[] { obj }, 0); + } + }; + name = "texture"; + break; + case VERTEX_ARRAYS_APPLE: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteVertexArraysAPPLE(1, new int[] { obj }, 0); + } + }; + name = "APPLE vertex array"; + break; + case VERTEX_SHADERS_EXT: + deleter = new Deleter() { + public void delete(GL2 gl, int obj) { + gl.glDeleteVertexShaderEXT(obj); + } + }; + name = "EXT vertex shader"; + break; + default: + throw new InternalError("Unexpected OpenGL object type " + which); + } + + list = new ObjectList(deleter); + list.setName(name); + lists[which] = list; + } + return list; + } + + private void delete(GL2 gl) { + for (int i = 0; i < lists.length; i++) { + ObjectList list = lists[i]; + if (list != null) { + list.delete(gl); + lists[i] = null; + } + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/GLUquadricImpl.java b/src/jogl/classes/jogamp/opengl/glu/GLUquadricImpl.java new file mode 100644 index 000000000..5eb73cd2e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/GLUquadricImpl.java @@ -0,0 +1,1212 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** $Date: 2009-03-04 17:23:34 -0800 (Wed, 04 Mar 2009) $ $Revision: 1856 $ +** $Header$ +*/ + +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE COPYRIGHT OWNER 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. + */ + +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package jogamp.opengl.glu; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import com.jogamp.opengl.util.ImmModeSink; +import java.nio.*; + +/** + * GLUquadricImpl.java + * + * + * Created 22-dec-2003 (originally Quadric.java) + * @author Erik Duijs + * @author Kenneth Russell, Sven Gothel + */ + +public class GLUquadricImpl implements GLUquadric { + private boolean useGLSL; + private int drawStyle; + private int orientation; + private boolean textureFlag; + private int normals; + private boolean immModeSinkEnabled; + private boolean immModeSinkImmediate; + public int normalType; + public GL gl; + + public static final boolean USE_NORM = true; + public static final boolean USE_TEXT = false; + + private ImmModeSink immModeSink=null; + + public GLUquadricImpl(GL gl, boolean useGLSL) { + this.gl=gl; + this.useGLSL = useGLSL; + drawStyle = GLU.GLU_FILL; + orientation = GLU.GLU_OUTSIDE; + textureFlag = false; + normals = GLU.GLU_SMOOTH; + normalType = gl.isGLES1()?GL.GL_BYTE:GL.GL_FLOAT; + immModeSinkImmediate=true; + immModeSinkEnabled=!gl.isGL2(); + replaceImmModeSink(); + } + + public void enableImmModeSink(boolean val) { + if(gl.isGL2()) { + immModeSinkEnabled=val; + } else { + immModeSinkEnabled=true; + } + if(null==immModeSink && immModeSinkEnabled) { + replaceImmModeSink(); + } + } + + public boolean isImmModeSinkEnabled() { + return immModeSinkEnabled; + } + + public void setImmMode(boolean val) { + if(immModeSinkEnabled) { + immModeSinkImmediate=val; + } else { + immModeSinkImmediate=true; + } + } + + public boolean getImmMode() { + return immModeSinkImmediate; + } + + public ImmModeSink replaceImmModeSink() { + if(!immModeSinkEnabled) return null; + + ImmModeSink res = immModeSink; + if(useGLSL) { + immModeSink = ImmModeSink.createGLSL (gl, GL.GL_STATIC_DRAW, 32, + 3, GL.GL_FLOAT, // vertex + 0, GL.GL_FLOAT, // color + USE_NORM?3:0, normalType,// normal + USE_TEXT?2:0, GL.GL_FLOAT); // texture + } else { + immModeSink = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 32, + 3, GL.GL_FLOAT, // vertex + 0, GL.GL_FLOAT, // color + USE_NORM?3:0, normalType,// normal + USE_TEXT?2:0, GL.GL_FLOAT); // texture + } + return res; + } + + public void resetImmModeSink(GL gl) { + if(immModeSinkEnabled) { + immModeSink.reset(gl); + } + } + + /** + * specifies the draw style for quadrics. + * + * The legal values are as follows: + * + * GLU.FILL: Quadrics are rendered with polygon primitives. The polygons + * are drawn in a counterclockwise fashion with respect to + * their normals (as defined with glu.quadricOrientation). + * + * GLU.LINE: Quadrics are rendered as a set of lines. + * + * GLU.SILHOUETTE: Quadrics are rendered as a set of lines, except that edges + * separating coplanar faces will not be drawn. + * + * GLU.POINT: Quadrics are rendered as a set of points. + * + * @param drawStyle The drawStyle to set + */ + public void setDrawStyle(int drawStyle) { + this.drawStyle = drawStyle; + } + + /** + * specifies what kind of normals are desired for quadrics. + * The legal values are as follows: + * + * GLU.NONE: No normals are generated. + * + * GLU.FLAT: One normal is generated for every facet of a quadric. + * + * GLU.SMOOTH: One normal is generated for every vertex of a quadric. This + * is the default. + * + * @param normals The normals to set + */ + public void setNormals(int normals) { + this.normals = normals; + } + + /** + * specifies what kind of orientation is desired for. + * The orientation values are as follows: + * + * GLU.OUTSIDE: Quadrics are drawn with normals pointing outward. + * + * GLU.INSIDE: Normals point inward. The default is GLU.OUTSIDE. + * + * Note that the interpretation of outward and inward depends on the quadric + * being drawn. + * + * @param orientation The orientation to set + */ + public void setOrientation(int orientation) { + this.orientation = orientation; + } + + /** + * specifies if texture coordinates should be generated for + * quadrics rendered with qobj. If the value of textureCoords is true, + * then texture coordinates are generated, and if textureCoords is false, + * they are not.. The default is false. + * + * The manner in which texture coordinates are generated depends upon the + * specific quadric rendered. + * + * @param textureFlag The textureFlag to set + */ + public void setTextureFlag(boolean textureFlag) { + this.textureFlag = textureFlag; + } + + /** + * Returns the drawStyle. + * @return int + */ + public int getDrawStyle() { + return drawStyle; + } + + /** + * Returns the normals. + * @return int + */ + public int getNormals() { + return normals; + } + + /** + * Returns the orientation. + * @return int + */ + public int getOrientation() { + return orientation; + } + + /** + * Returns the textureFlag. + * @return boolean + */ + public boolean getTextureFlag() { + return textureFlag; + } + + + /** + * draws a cylinder oriented along the z axis. The base of the + * cylinder is placed at z = 0, and the top at z=height. Like a sphere, a + * cylinder is subdivided around the z axis into slices, and along the z axis + * into stacks. + * + * Note that if topRadius is set to zero, then this routine will generate a + * cone. + * + * If the orientation is set to GLU.OUTSIDE (with glu.quadricOrientation), then + * any generated normals point away from the z axis. Otherwise, they point + * toward the z axis. + * + * If texturing is turned on (with glu.quadricTexture), then texture + * coordinates are generated so that t ranges linearly from 0.0 at z = 0 to + * 1.0 at z = height, and s ranges from 0.0 at the +y axis, to 0.25 at the +x + * axis, to 0.5 at the -y axis, to 0.75 at the -x axis, and back to 1.0 at the + * +y axis. + * + * @param baseRadius Specifies the radius of the cylinder at z = 0. + * @param topRadius Specifies the radius of the cylinder at z = height. + * @param height Specifies the height of the cylinder. + * @param slices Specifies the number of subdivisions around the z axis. + * @param stacks Specifies the number of subdivisions along the z axis. + */ + public void drawCylinder(GL gl, float baseRadius, float topRadius, float height, int slices, int stacks) { + + float da, r, dr, dz; + float x, y, z, nz, nsign; + int i, j; + + if (orientation == GLU.GLU_INSIDE) { + nsign = -1.0f; + } else { + nsign = 1.0f; + } + + da = 2.0f * PI / slices; + dr = (topRadius - baseRadius) / stacks; + dz = height / stacks; + nz = (baseRadius - topRadius) / height; + // Z component of normal vectors + + if (drawStyle == GLU.GLU_POINT) { + glBegin(gl, GL.GL_POINTS); + for (i = 0; i < slices; i++) { + x = cos((i * da)); + y = sin((i * da)); + normal3f(gl, x * nsign, y * nsign, nz * nsign); + + z = 0.0f; + r = baseRadius; + for (j = 0; j <= stacks; j++) { + glVertex3f(gl, (x * r), (y * r), z); + z += dz; + r += dr; + } + } + glEnd(gl); + } else if (drawStyle == GLU.GLU_LINE || drawStyle == GLU.GLU_SILHOUETTE) { + // Draw rings + if (drawStyle == GLU.GLU_LINE) { + z = 0.0f; + r = baseRadius; + for (j = 0; j <= stacks; j++) { + glBegin(gl, GL.GL_LINE_LOOP); + for (i = 0; i < slices; i++) { + x = cos((i * da)); + y = sin((i * da)); + normal3f(gl, x * nsign, y * nsign, nz * nsign); + glVertex3f(gl, (x * r), (y * r), z); + } + glEnd(gl); + z += dz; + r += dr; + } + } else { + // draw one ring at each end + if (baseRadius != 0.0) { + glBegin(gl, GL.GL_LINE_LOOP); + for (i = 0; i < slices; i++) { + x = cos((i * da)); + y = sin((i * da)); + normal3f(gl, x * nsign, y * nsign, nz * nsign); + glVertex3f(gl, (x * baseRadius), (y * baseRadius), 0.0f); + } + glEnd(gl); + glBegin(gl, GL.GL_LINE_LOOP); + for (i = 0; i < slices; i++) { + x = cos((i * da)); + y = sin((i * da)); + normal3f(gl, x * nsign, y * nsign, nz * nsign); + glVertex3f(gl, (x * topRadius), (y * topRadius), height); + } + glEnd(gl); + } + } + // draw length lines + glBegin(gl, GL.GL_LINES); + for (i = 0; i < slices; i++) { + x = cos((i * da)); + y = sin((i * da)); + normal3f(gl, x * nsign, y * nsign, nz * nsign); + glVertex3f(gl, (x * baseRadius), (y * baseRadius), 0.0f); + glVertex3f(gl, (x * topRadius), (y * topRadius), (height)); + } + glEnd(gl); + } else if (drawStyle == GLU.GLU_FILL) { + float ds = 1.0f / slices; + float dt = 1.0f / stacks; + float t = 0.0f; + z = 0.0f; + r = baseRadius; + for (j = 0; j < stacks; j++) { + float s = 0.0f; + glBegin(gl, immModeSink.GL_QUAD_STRIP); + for (i = 0; i <= slices; i++) { + if (i == slices) { + x = sin(0.0f); + y = cos(0.0f); + } else { + x = sin((i * da)); + y = cos((i * da)); + } + if (nsign == 1.0f) { + normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); + TXTR_COORD(gl, s, t); + glVertex3f(gl, (x * r), (y * r), z); + normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); + TXTR_COORD(gl, s, t + dt); + glVertex3f(gl, (x * (r + dr)), (y * (r + dr)), (z + dz)); + } else { + normal3f(gl, x * nsign, y * nsign, nz * nsign); + TXTR_COORD(gl, s, t); + glVertex3f(gl, (x * r), (y * r), z); + normal3f(gl, x * nsign, y * nsign, nz * nsign); + TXTR_COORD(gl, s, t + dt); + glVertex3f(gl, (x * (r + dr)), (y * (r + dr)), (z + dz)); + } + s += ds; + } // for slices + glEnd(gl); + r += dr; + t += dt; + z += dz; + } // for stacks + } + } + + /** + * renders a disk on the z = 0 plane. The disk has a radius of + * outerRadius, and contains a concentric circular hole with a radius of + * innerRadius. If innerRadius is 0, then no hole is generated. The disk is + * subdivided around the z axis into slices (like pizza slices), and also + * about the z axis into rings (as specified by slices and loops, + * respectively). + * + * With respect to orientation, the +z side of the disk is considered to be + * "outside" (see glu.quadricOrientation). This means that if the orientation + * is set to GLU.OUTSIDE, then any normals generated point along the +z axis. + * Otherwise, they point along the -z axis. + * + * If texturing is turned on (with glu.quadricTexture), texture coordinates are + * generated linearly such that where r=outerRadius, the value at (r, 0, 0) is + * (1, 0.5), at (0, r, 0) it is (0.5, 1), at (-r, 0, 0) it is (0, 0.5), and at + * (0, -r, 0) it is (0.5, 0). + */ + public void drawDisk(GL gl, float innerRadius, float outerRadius, int slices, int loops) + { + float da, dr; + + /* Normal vectors */ + if (normals != GLU.GLU_NONE) { + if (orientation == GLU.GLU_OUTSIDE) { + glNormal3f(gl, 0.0f, 0.0f, +1.0f); + } + else { + glNormal3f(gl, 0.0f, 0.0f, -1.0f); + } + } + + da = 2.0f * PI / slices; + dr = (outerRadius - innerRadius) / loops; + + switch (drawStyle) { + case GLU.GLU_FILL: + { + /* texture of a gluDisk is a cut out of the texture unit square + * x, y in [-outerRadius, +outerRadius]; s, t in [0, 1] + * (linear mapping) + */ + float dtc = 2.0f * outerRadius; + float sa, ca; + float r1 = innerRadius; + int l; + for (l = 0; l < loops; l++) { + float r2 = r1 + dr; + if (orientation == GLU.GLU_OUTSIDE) { + int s; + glBegin(gl, immModeSink.GL_QUAD_STRIP); + for (s = 0; s <= slices; s++) { + float a; + if (s == slices) + a = 0.0f; + else + a = s * da; + sa = sin(a); + ca = cos(a); + TXTR_COORD(gl, 0.5f + sa * r2 / dtc, 0.5f + ca * r2 / dtc); + glVertex2f(gl, r2 * sa, r2 * ca); + TXTR_COORD(gl, 0.5f + sa * r1 / dtc, 0.5f + ca * r1 / dtc); + glVertex2f(gl, r1 * sa, r1 * ca); + } + glEnd(gl); + } + else { + int s; + glBegin(gl, immModeSink.GL_QUAD_STRIP); + for (s = slices; s >= 0; s--) { + float a; + if (s == slices) + a = 0.0f; + else + a = s * da; + sa = sin(a); + ca = cos(a); + TXTR_COORD(gl, 0.5f - sa * r2 / dtc, 0.5f + ca * r2 / dtc); + glVertex2f(gl, r2 * sa, r2 * ca); + TXTR_COORD(gl, 0.5f - sa * r1 / dtc, 0.5f + ca * r1 / dtc); + glVertex2f(gl, r1 * sa, r1 * ca); + } + glEnd(gl); + } + r1 = r2; + } + break; + } + case GLU.GLU_LINE: + { + int l, s; + /* draw loops */ + for (l = 0; l <= loops; l++) { + float r = innerRadius + l * dr; + glBegin(gl, GL.GL_LINE_LOOP); + for (s = 0; s < slices; s++) { + float a = s * da; + glVertex2f(gl, r * sin(a), r * cos(a)); + } + glEnd(gl); + } + /* draw spokes */ + for (s = 0; s < slices; s++) { + float a = s * da; + float x = sin(a); + float y = cos(a); + glBegin(gl, GL.GL_LINE_STRIP); + for (l = 0; l <= loops; l++) { + float r = innerRadius + l * dr; + glVertex2f(gl, r * x, r * y); + } + glEnd(gl); + } + break; + } + case GLU.GLU_POINT: + { + int s; + glBegin(gl, GL.GL_POINTS); + for (s = 0; s < slices; s++) { + float a = s * da; + float x = sin(a); + float y = cos(a); + int l; + for (l = 0; l <= loops; l++) { + float r = innerRadius * l * dr; + glVertex2f(gl, r * x, r * y); + } + } + glEnd(gl); + break; + } + case GLU.GLU_SILHOUETTE: + { + if (innerRadius != 0.0) { + float a; + glBegin(gl, GL.GL_LINE_LOOP); + for (a = 0.0f; a < 2.0 * PI; a += da) { + float x = innerRadius * sin(a); + float y = innerRadius * cos(a); + glVertex2f(gl, x, y); + } + glEnd(gl); + } + { + float a; + glBegin(gl, GL.GL_LINE_LOOP); + for (a = 0; a < 2.0f * PI; a += da) { + float x = outerRadius * sin(a); + float y = outerRadius * cos(a); + glVertex2f(gl, x, y); + } + glEnd(gl); + } + break; + } + default: + return; + } + } + + /** + * renders a partial disk on the z=0 plane. A partial disk is similar to a + * full disk, except that only the subset of the disk from startAngle + * through startAngle + sweepAngle is included (where 0 degrees is along + * the +y axis, 90 degrees along the +x axis, 180 along the -y axis, and + * 270 along the -x axis). + * + * The partial disk has a radius of outerRadius, and contains a concentric + * circular hole with a radius of innerRadius. If innerRadius is zero, then + * no hole is generated. The partial disk is subdivided around the z axis + * into slices (like pizza slices), and also about the z axis into rings + * (as specified by slices and loops, respectively). + * + * With respect to orientation, the +z side of the partial disk is + * considered to be outside (see gluQuadricOrientation). This means that if + * the orientation is set to GLU.GLU_OUTSIDE, then any normals generated point + * along the +z axis. Otherwise, they point along the -z axis. + * + * If texturing is turned on (with gluQuadricTexture), texture coordinates + * are generated linearly such that where r=outerRadius, the value at (r, 0, 0) + * is (1, 0.5), at (0, r, 0) it is (0.5, 1), at (-r, 0, 0) it is (0, 0.5), + * and at (0, -r, 0) it is (0.5, 0). + */ + public void drawPartialDisk(GL gl, + float innerRadius, + float outerRadius, + int slices, + int loops, + float startAngle, + float sweepAngle) { + int i, j, max; + float[] sinCache = new float[CACHE_SIZE]; + float[] cosCache = new float[CACHE_SIZE]; + float angle; + float x, y; + float sintemp, costemp; + float deltaRadius; + float radiusLow, radiusHigh; + float texLow = 0, texHigh = 0; + float angleOffset; + int slices2; + int finish; + + if (slices >= CACHE_SIZE) + slices = CACHE_SIZE - 1; + if (slices < 2 + || loops < 1 + || outerRadius <= 0.0f + || innerRadius < 0.0f + || innerRadius > outerRadius) { + //gluQuadricError(qobj, GLU.GLU_INVALID_VALUE); + System.err.println("PartialDisk: GLU_INVALID_VALUE"); + return; + } + + if (sweepAngle < -360.0f) + sweepAngle = 360.0f; + if (sweepAngle > 360.0f) + sweepAngle = 360.0f; + if (sweepAngle < 0) { + startAngle += sweepAngle; + sweepAngle = -sweepAngle; + } + + if (sweepAngle == 360.0f) { + slices2 = slices; + } else { + slices2 = slices + 1; + } + + /* Compute length (needed for normal calculations) */ + deltaRadius = outerRadius - innerRadius; + + /* Cache is the vertex locations cache */ + + angleOffset = startAngle / 180.0f * PI; + for (i = 0; i <= slices; i++) { + angle = angleOffset + ((PI * sweepAngle) / 180.0f) * i / slices; + sinCache[i] = sin(angle); + cosCache[i] = cos(angle); + } + + if (sweepAngle == 360.0f) { + sinCache[slices] = sinCache[0]; + cosCache[slices] = cosCache[0]; + } + + switch (normals) { + case GLU.GLU_FLAT : + case GLU.GLU_SMOOTH : + if (orientation == GLU.GLU_OUTSIDE) { + glNormal3f(gl, 0.0f, 0.0f, 1.0f); + } else { + glNormal3f(gl, 0.0f, 0.0f, -1.0f); + } + break; + default : + case GLU.GLU_NONE : + break; + } + + switch (drawStyle) { + case GLU.GLU_FILL : + if (innerRadius == .0f) { + finish = loops - 1; + /* Triangle strip for inner polygons */ + glBegin(gl, GL.GL_TRIANGLE_FAN); + if (textureFlag) { + glTexCoord2f(gl, 0.5f, 0.5f); + } + glVertex3f(gl, 0.0f, 0.0f, 0.0f); + radiusLow = outerRadius - deltaRadius * ((float) (loops - 1) / loops); + if (textureFlag) { + texLow = radiusLow / outerRadius / 2; + } + + if (orientation == GLU.GLU_OUTSIDE) { + for (i = slices; i >= 0; i--) { + if (textureFlag) { + glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, + texLow * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + } else { + for (i = 0; i <= slices; i++) { + if (textureFlag) { + glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, + texLow * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + } + glEnd(gl); + } else { + finish = loops; + } + for (j = 0; j < finish; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + radiusHigh = outerRadius - deltaRadius * ((float) (j + 1) / loops); + if (textureFlag) { + texLow = radiusLow / outerRadius / 2; + texHigh = radiusHigh / outerRadius / 2; + } + + glBegin(gl, immModeSink.GL_QUAD_STRIP); + for (i = 0; i <= slices; i++) { + if (orientation == GLU.GLU_OUTSIDE) { + if (textureFlag) { + glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, + texLow * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + + if (textureFlag) { + glTexCoord2f(gl, texHigh * sinCache[i] + 0.5f, + texHigh * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusHigh * sinCache[i], + radiusHigh * cosCache[i], + 0.0f); + } else { + if (textureFlag) { + glTexCoord2f(gl, texHigh * sinCache[i] + 0.5f, + texHigh * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusHigh * sinCache[i], + radiusHigh * cosCache[i], + 0.0f); + + if (textureFlag) { + glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, + texLow * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + } + glEnd(gl); + } + break; + case GLU.GLU_POINT : + glBegin(gl, GL.GL_POINTS); + for (i = 0; i < slices2; i++) { + sintemp = sinCache[i]; + costemp = cosCache[i]; + for (j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + + if (textureFlag) { + texLow = radiusLow / outerRadius / 2; + + glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, + texLow * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusLow * sintemp, radiusLow * costemp, 0.0f); + } + } + glEnd(gl); + break; + case GLU.GLU_LINE : + if (innerRadius == outerRadius) { + glBegin(gl, GL.GL_LINE_STRIP); + + for (i = 0; i <= slices; i++) { + if (textureFlag) { + glTexCoord2f(gl, sinCache[i] / 2 + 0.5f, cosCache[i] / 2 + 0.5f); + } + glVertex3f(gl, innerRadius * sinCache[i], innerRadius * cosCache[i], 0.0f); + } + glEnd(gl); + break; + } + for (j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + if (textureFlag) { + texLow = radiusLow / outerRadius / 2; + } + + glBegin(gl, GL.GL_LINE_STRIP); + for (i = 0; i <= slices; i++) { + if (textureFlag) { + glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, + texLow * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + glEnd(gl); + } + for (i = 0; i < slices2; i++) { + sintemp = sinCache[i]; + costemp = cosCache[i]; + glBegin(gl, GL.GL_LINE_STRIP); + for (j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + if (textureFlag) { + texLow = radiusLow / outerRadius / 2; + } + + if (textureFlag) { + glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, + texLow * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusLow * sintemp, radiusLow * costemp, 0.0f); + } + glEnd(gl); + } + break; + case GLU.GLU_SILHOUETTE : + if (sweepAngle < 360.0f) { + for (i = 0; i <= slices; i += slices) { + sintemp = sinCache[i]; + costemp = cosCache[i]; + glBegin(gl, GL.GL_LINE_STRIP); + for (j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + + if (textureFlag) { + texLow = radiusLow / outerRadius / 2; + glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, + texLow * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusLow * sintemp, radiusLow * costemp, 0.0f); + } + glEnd(gl); + } + } + for (j = 0; j <= loops; j += loops) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + if (textureFlag) { + texLow = radiusLow / outerRadius / 2; + } + + glBegin(gl, GL.GL_LINE_STRIP); + for (i = 0; i <= slices; i++) { + if (textureFlag) { + glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, + texLow * cosCache[i] + 0.5f); + } + glVertex3f(gl, radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + glEnd(gl); + if (innerRadius == outerRadius) + break; + } + break; + default : + break; + } + } + + /** + * draws a sphere of the given radius centered around the origin. + * The sphere is subdivided around the z axis into slices and along the z axis + * into stacks (similar to lines of longitude and latitude). + * + * If the orientation is set to GLU.OUTSIDE (with glu.quadricOrientation), then + * any normals generated point away from the center of the sphere. Otherwise, + * they point toward the center of the sphere. + + * If texturing is turned on (with glu.quadricTexture), then texture + * coordinates are generated so that t ranges from 0.0 at z=-radius to 1.0 at + * z=radius (t increases linearly along longitudinal lines), and s ranges from + * 0.0 at the +y axis, to 0.25 at the +x axis, to 0.5 at the -y axis, to 0.75 + * at the -x axis, and back to 1.0 at the +y axis. + */ + public void drawSphere(GL gl, float radius, int slices, int stacks) { + // TODO + + float rho, drho, theta, dtheta; + float x, y, z; + float s, t, ds, dt; + int i, j, imin, imax; + boolean normals; + float nsign; + + normals = (this.normals != GLU.GLU_NONE); + + if (orientation == GLU.GLU_INSIDE) { + nsign = -1.0f; + } else { + nsign = 1.0f; + } + + drho = PI / stacks; + dtheta = 2.0f * PI / slices; + + if (drawStyle == GLU.GLU_FILL) { + if (!textureFlag) { + // draw +Z end as a triangle fan + glBegin(gl, GL.GL_TRIANGLE_FAN); + glNormal3f(gl, 0.0f, 0.0f, 1.0f); + glVertex3f(gl, 0.0f, 0.0f, nsign * radius); + for (j = 0; j <= slices; j++) { + theta = (j == slices) ? 0.0f : j * dtheta; + x = -sin(theta) * sin(drho); + y = cos(theta) * sin(drho); + z = nsign * cos(drho); + if (normals) { + glNormal3f(gl, x * nsign, y * nsign, z * nsign); + } + glVertex3f(gl, x * radius, y * radius, z * radius); + } + glEnd(gl); + } + + ds = 1.0f / slices; + dt = 1.0f / stacks; + t = 1.0f; // because loop now runs from 0 + if (textureFlag) { + imin = 0; + imax = stacks; + } else { + imin = 1; + imax = stacks - 1; + } + + // draw intermediate stacks as quad strips + for (i = imin; i < imax; i++) { + rho = i * drho; + glBegin(gl, immModeSink.GL_QUAD_STRIP); + s = 0.0f; + for (j = 0; j <= slices; j++) { + theta = (j == slices) ? 0.0f : j * dtheta; + x = -sin(theta) * sin(rho); + y = cos(theta) * sin(rho); + z = nsign * cos(rho); + if (normals) { + glNormal3f(gl, x * nsign, y * nsign, z * nsign); + } + TXTR_COORD(gl, s, t); + glVertex3f(gl, x * radius, y * radius, z * radius); + x = -sin(theta) * sin(rho + drho); + y = cos(theta) * sin(rho + drho); + z = nsign * cos(rho + drho); + if (normals) { + glNormal3f(gl, x * nsign, y * nsign, z * nsign); + } + TXTR_COORD(gl, s, t - dt); + s += ds; + glVertex3f(gl, x * radius, y * radius, z * radius); + } + glEnd(gl); + t -= dt; + } + + if (!textureFlag) { + // draw -Z end as a triangle fan + glBegin(gl, GL.GL_TRIANGLE_FAN); + glNormal3f(gl, 0.0f, 0.0f, -1.0f); + glVertex3f(gl, 0.0f, 0.0f, -radius * nsign); + rho = PI - drho; + s = 1.0f; + for (j = slices; j >= 0; j--) { + theta = (j == slices) ? 0.0f : j * dtheta; + x = -sin(theta) * sin(rho); + y = cos(theta) * sin(rho); + z = nsign * cos(rho); + if (normals) + glNormal3f(gl, x * nsign, y * nsign, z * nsign); + s -= ds; + glVertex3f(gl, x * radius, y * radius, z * radius); + } + glEnd(gl); + } + } else if ( + drawStyle == GLU.GLU_LINE + || drawStyle == GLU.GLU_SILHOUETTE) { + // draw stack lines + for (i = 1; + i < stacks; + i++) { // stack line at i==stacks-1 was missing here + rho = i * drho; + glBegin(gl, GL.GL_LINE_LOOP); + for (j = 0; j < slices; j++) { + theta = j * dtheta; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + if (normals) + glNormal3f(gl, x * nsign, y * nsign, z * nsign); + glVertex3f(gl, x * radius, y * radius, z * radius); + } + glEnd(gl); + } + // draw slice lines + for (j = 0; j < slices; j++) { + theta = j * dtheta; + glBegin(gl, GL.GL_LINE_STRIP); + for (i = 0; i <= stacks; i++) { + rho = i * drho; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + if (normals) + glNormal3f(gl, x * nsign, y * nsign, z * nsign); + glVertex3f(gl, x * radius, y * radius, z * radius); + } + glEnd(gl); + } + } else if (drawStyle == GLU.GLU_POINT) { + // top and bottom-most points + glBegin(gl, GL.GL_POINTS); + if (normals) + glNormal3f(gl, 0.0f, 0.0f, nsign); + glVertex3f(gl, 0.0f, 0.0f, radius); + if (normals) + glNormal3f(gl, 0.0f, 0.0f, -nsign); + glVertex3f(gl, 0.0f, 0.0f, -radius); + + // loop over stacks + for (i = 1; i < stacks - 1; i++) { + rho = i * drho; + for (j = 0; j < slices; j++) { + theta = j * dtheta; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + if (normals) + glNormal3f(gl, x * nsign, y * nsign, z * nsign); + glVertex3f(gl, x * radius, y * radius, z * radius); + } + } + glEnd(gl); + } + } + + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private static final float PI = (float)Math.PI; + private static final int CACHE_SIZE = 240; + + private final void glBegin(GL gl, int mode) { + if(immModeSinkEnabled) { + immModeSink.glBegin(mode); + } else { + gl.getGL2().glBegin(mode); + } + } + + private final void glEnd(GL gl) { + if(immModeSinkEnabled) { + immModeSink.glEnd(gl, immModeSinkImmediate); + } else { + gl.getGL2().glEnd(); + } + } + + private final void glVertex2f(GL gl, float x, float y) { + if(immModeSinkEnabled) { + immModeSink.glVertex2f(x, y); + } else { + gl.getGL2().glVertex2f(x, y); + } + } + + private final void glVertex3f(GL gl, float x, float y, float z) { + if(immModeSinkEnabled) { + immModeSink.glVertex3f(x, y, z); + } else { + gl.getGL2().glVertex3f(x, y, z); + } + } + + private final void glNormal3f_s(GL gl, float x, float y, float z) { + short a=(short)(x*0xFFFF); + short b=(short)(y*0xFFFF); + short c=(short)(z*0xFFFF); + if(immModeSinkEnabled) { + immModeSink.glNormal3s(a, b, c); + } else { + gl.getGL2().glNormal3s(a, b, c); + } + } + + private final void glNormal3f_b(GL gl, float x, float y, float z) { + byte a=(byte)(x*0xFF); + byte b=(byte)(y*0xFF); + byte c=(byte)(z*0xFF); + if(immModeSinkEnabled) { + immModeSink.glNormal3b(a, b, c); + } else { + gl.getGL2().glNormal3b(a, b, c); + } + } + + private final void glNormal3f(GL gl, float x, float y, float z) { + switch(normalType) { + case GL.GL_FLOAT: + if(immModeSinkEnabled) { + immModeSink.glNormal3f(x,y,z); + } else { + gl.getGL2().glNormal3f(x,y,z); + } + break; + case GL.GL_SHORT: + glNormal3f_s(gl, x, y, z); + break; + case GL.GL_BYTE: + glNormal3f_b(gl, x, y, z); + break; + } + } + + private final void glTexCoord2f(GL gl, float x, float y) { + if(immModeSinkEnabled) { + immModeSink.glTexCoord2f(x, y); + } else { + gl.getGL2().glTexCoord2f(x, y); + } + } + + /** + * Call glNormal3f after scaling normal to unit length. + * + * @param x + * @param y + * @param z + */ + private void normal3f(GL gl, float x, float y, float z) { + float mag; + + mag = (float)Math.sqrt(x * x + y * y + z * z); + if (mag > 0.00001F) { + x /= mag; + y /= mag; + z /= mag; + } + glNormal3f(gl, x, y, z); + } + + private final void TXTR_COORD(GL gl, float x, float y) { + if (textureFlag) glTexCoord2f(gl, x,y); + } + + private float sin(float r) { + return (float)Math.sin(r); + } + + private float cos(float r) { + return (float)Math.cos(r); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/Glue.java b/src/jogl/classes/jogamp/opengl/glu/Glue.java new file mode 100644 index 000000000..636d17f29 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/Glue.java @@ -0,0 +1,114 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu; + +/** + * + * @author Administrator + */ +public class Glue { + private static String[] __gluNurbsErrors = { + " ", + "spline order un-supported", + "too few knots", + "valid knot range is empty", + "decreasing knot sequence knot", + "knot multiplicity greater than order of spline", + "gluEndCurve() must follow gluBeginCurve()", + "gluBeginCurve() must precede gluEndCurve()", + "missing or extra geometric data", + "can't draw piecewise linear trimming curves", + "missing or extra domain data", + "missing or extra domain data", + "gluEndTrim() must precede gluEndSurface()", + "gluBeginSurface() must precede gluEndSurface()", + "curve of improper type passed as trim curve", + "gluBeginSurface() must precede gluBeginTrim()", + "gluEndTrim() must follow gluBeginTrim()", + "gluBeginTrim() must follow gluEndTrim()", + "invalid or missing trim curve", + "gluBeginTrim() must precede gluPwlCurve()", + "piecewise linear trimming curve referenced twice", + "piecewise linear trimming curve and nurbs curve mixed", + "improper usage of trim data type", + "nurbs curve referenced twice", + "nurbs curve and piecewise linear trimming curve mixed", + "nurbs surface referenced twice", + "invalid property", + "gluEndSurface() must follow gluBeginSurface()", + "intersecting or misoriented trim curve", + "intersecting trim curves", + "UNUSED", + "inconnected trim curves", + "unknown knot error", + "negative vertex count encountered", + "negative byte-stride encountered", + "unknown type descriptor", + "null control point reference", + "duplicate point on piecewise linear trimming curve" + } ; + + /** Creates a new instance of Glue */ + public Glue() { + } + + public static String __gluNURBSErrorString( int errno ) { + return( __gluNurbsErrors[ errno ] ); + } + + private static String[] __gluTessErrors = { + " ", + "gluTessBeginPolygon() must precede a gluTessEndPolygon", + "gluTessBeginContour() must precede a gluTessEndContour()", + "gluTessEndPolygon() must follow a gluTessBeginPolygon()", + "gluTessEndContour() must follow a gluTessBeginContour()", + "a coordinate is too large", + "need combine callback" + }; + + public static String __gluTessErrorString( int errno ) { + return( __gluTessErrors[ errno ] ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/error/Error.java b/src/jogl/classes/jogamp/opengl/glu/error/Error.java new file mode 100644 index 000000000..2f49db9a4 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/error/Error.java @@ -0,0 +1,100 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.error; + +import javax.media.opengl.GL; +import javax.media.opengl.glu.GLU; +import jogamp.opengl.glu.Glue; + +/** + * + * @author Administrator + */ +public class Error { + + private static String[] glErrorStrings = { + "invalid enumerant", + "invalid value", + "invalid operation", + "stack overflow", + "stack underflow", + "out of memory", + "invalid framebuffer operation" + }; + + private static String[] gluErrorStrings = { + "invalid enumerant", + "invalid value", + "out of memory", + "", + "invalid operation" + }; + + /** Creates a new instance of Error */ + public Error() { + } + + public static String gluErrorString( int errorCode ) { + if( errorCode == 0 ) { + return( "no error" ); + } + if( (errorCode >= GL.GL_INVALID_ENUM) && (errorCode <= GL.GL_INVALID_FRAMEBUFFER_OPERATION) ) { + return( glErrorStrings[ errorCode - GL.GL_INVALID_ENUM ] ); + } + if( errorCode == 0x8031 /* GL.GL_TABLE_TOO_LARGE */ ) { + return( "table too large" ); + } + if( (errorCode >= GLU.GLU_INVALID_ENUM) && (errorCode <= GLU.GLU_INVALID_OPERATION) ) { + return( gluErrorStrings[ errorCode - GLU.GLU_INVALID_ENUM ] ); + } +// if( (errorCode >= GLU.GLU_NURBS_ERROR1) && (errorCode <= GLU.GLU_NURBS_ERROR37) ) { +// return( gluErrorStrings[ errorCode - (GLU.GLU_NURBS_ERROR1 - 1) ] ); +// } + if( (errorCode >= GLU.GLU_TESS_ERROR1) && (errorCode <= GLU.GLU_TESS_ERROR8) ) { + return( Glue.__gluTessErrorString(errorCode - (GLU.GLU_TESS_ERROR1 - 1)) ); + } + return( "error ("+errorCode+")" ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2Backend.java b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2Backend.java new file mode 100644 index 000000000..2cc5e06ae --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2Backend.java @@ -0,0 +1,49 @@ +package jogamp.opengl.glu.gl2.nurbs; +import jogamp.opengl.glu.nurbs.*; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class responsible for rendering + * @author Tomas Hrasky + * + */ +public class GL2Backend extends Backend { + public GL2Backend() { + super(); + curveEvaluator = new GL2CurveEvaluator(); + surfaceEvaluator = new GL2SurfaceEvaluator(); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2CurveEvaluator.java b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2CurveEvaluator.java new file mode 100644 index 000000000..043edac89 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2CurveEvaluator.java @@ -0,0 +1,205 @@ +package jogamp.opengl.glu.gl2.nurbs; +import jogamp.opengl.glu.nurbs.*; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.glu.GLU; +import javax.media.opengl.glu.gl2.GLUgl2; + +/** + * Class rendering curves with OpenGL + * @author Tomáš Hráský + * + */ +class GL2CurveEvaluator implements CurveEvaluator { + + /** + * Output triangles (for callback) or render curve + */ + private boolean output_triangles; + + /** + * OpenGL object + */ + private GL2 gl; + + /** + * Not used + */ + private int vertex_flag; + + /** + * Not used + */ + private int normal_flag; + + /** + * Not used + */ + private int color_flag; + + /** + * Not used + */ + private int texcoord_flag; + + /** + * Number of bezier arc - used for color distinguishing of arcs forming NURBS curve + */ + private int poradi; + + /** + * Makes new Evaluator + */ + public GL2CurveEvaluator() { + gl = GLUgl2.getCurrentGL2(); + } + + /** + * Pushes eval bit + */ + public void bgnmap1f() { + // DONE + if (output_triangles) { + vertex_flag = 0; + normal_flag = 0; + color_flag = 0; + texcoord_flag = 0; + } else { + gl.glPushAttrib(GL2.GL_EVAL_BIT); + } + + } + + /** + * Pops all OpenGL attributes + */ + public void endmap1f() { + // DONE + if (output_triangles) { + + } else { + gl.glPopAttrib(); + } + + } + + /** + * Initializes opengl evaluator + * @param type curve type + * @param ulo lowest u + * @param uhi highest u + * @param stride control point coords + * @param order curve order + * @param ps control points + */ + public void map1f(int type, float ulo, float uhi, int stride, int order, + CArrayOfFloats ps) { + if (output_triangles) { + // TODO code for callback (output_triangles probably indicates callback) + // System.out.println("TODO curveevaluator.map1f-output_triangles"); + } else { + gl.glMap1f(type, ulo, uhi, stride, order, ps.getArray(), ps + .getPointer()); + + // DEBUG - drawing bézier control points + // gl.glColor3d(.5,.5,.5); + // gl.glPointSize(5); + // gl.glBegin(GL2.GL_POINTS); + // float[] ctrlpoints=ps.getArray(); + // for(int i=ps.getPointer();i<ps.getPointer()+order;i++){ + // gl.glVertex3d(ctrlpoints[i * 4], ctrlpoints[i * 4 + 1],0); + // } + // gl.glEnd(); + } + + } + + /** + * Calls opengl enable + * @param type what to enable + */ + public void enable(int type) { + // DONE + gl.glEnable(type); + } + + /** + * Calls glMapGrid1f + * @param nu steps + * @param u1 low u + * @param u2 high u + */ + public void mapgrid1f(int nu, float u1, float u2) { + if (output_triangles) { + // System.out.println("TODO curveevaluator.mapgrid1f"); + } else + gl.glMapGrid1f(nu, u1, u2); + // // System.out.println("upravit NU"); + // gl.glMapGrid1f(50,u1,u2); + } + + /** + * Evaluates a curve using glEvalMesh1f + * @param style Backend.N_MESHFILL/N_MESHLINE/N_MESHPOINT + * @param from lowest param + * @param to highest param + */ + public void mapmesh1f(int style, int from, int to) { + /* //DEBUG drawing control points + this.poradi++; + if (poradi % 2 == 0) + gl.glColor3f(1, 0, 0); + else + gl.glColor3f(0, 1, 0); + */ + if (output_triangles) { + // TODO code for callback + // System.out.println("TODO openglcurveevaluator.mapmesh1f output_triangles"); + } else { + switch (style) { + case Backend.N_MESHFILL: + case Backend.N_MESHLINE: + gl.glEvalMesh1(GL2.GL_LINE, from, to); + break; + case Backend.N_MESHPOINT: + gl.glEvalMesh1(GL2.GL_POINT, from, to); + break; + } + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2SurfaceEvaluator.java b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2SurfaceEvaluator.java new file mode 100644 index 000000000..bc63994cb --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2SurfaceEvaluator.java @@ -0,0 +1,217 @@ +package jogamp.opengl.glu.gl2.nurbs; +import jogamp.opengl.glu.nurbs.*; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.glu.GLU; +import javax.media.opengl.glu.gl2.GLUgl2; + +/** + * Class rendering surfaces with OpenGL + * @author Tomas Hrasky + * + */ +class GL2SurfaceEvaluator implements SurfaceEvaluator { + + /** + * JOGL OpenGL object + */ + private GL2 gl; + + /** + * Output triangles (callback) + */ + private boolean output_triangles; + + /** + * Number of patch - used for distinguishing bezier plates forming NURBS surface with different colors + */ + private int poradi; + + /** + * Creates new evaluator + */ + public GL2SurfaceEvaluator() { + gl = GLUgl2.getCurrentGL2(); + } + + /** + * Pushes eval bit + */ + public void bgnmap2f() { + + if (output_triangles) { + // TODO outp triangles surfaceevaluator bgnmap2f + // System.out.println("TODO surfaceevaluator.bgnmap2f output triangles"); + } else { + gl.glPushAttrib(GL2.GL_EVAL_BIT); + // System.out.println("TODO surfaceevaluator.bgnmap2f glgetintegerv"); + } + + } + + /** + * Sets glPolygonMode + * @param style polygon mode (N_MESHFILL/N_MESHLINE/N_MESHPOINT) + */ + public void polymode(int style) { + if (!output_triangles) { + switch (style) { + default: + case NurbsConsts.N_MESHFILL: + gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); + break; + case NurbsConsts.N_MESHLINE: + gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); + break; + case NurbsConsts.N_MESHPOINT: + gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_POINT); + break; + } + } + + } + + /** + * Pops all attributes + */ + public void endmap2f() { + // TODO Auto-generated method stub + if (output_triangles) { + // System.out.println("TODO surfaceevaluator.endmap2f output triangles"); + } else { + gl.glPopAttrib(); + // TODO use LOD + } + } + + /** + * Empty method + * @param ulo + * @param uhi + * @param vlo + * @param vhi + */ + public void domain2f(float ulo, float uhi, float vlo, float vhi) { + // DONE + } + + /** + * Defines 2D mesh + * @param nu number of steps in u direction + * @param u0 lowest u + * @param u1 highest u + * @param nv number of steps in v direction + * @param v0 lowest v + * @param v1 highest v + */ + public void mapgrid2f(int nu, float u0, float u1, int nv, float v0, float v1) { + + if (output_triangles) { + // System.out.println("TODO openglsurfaceavaluator.mapgrid2f output_triangles"); + } else { + gl.glMapGrid2d(nu, u0, u1, nv, v0, v1); + } + + } + + /** + * Evaluates surface + * @param style surface style + * @param umin minimum U + * @param umax maximum U + * @param vmin minimum V + * @param vmax maximum V + */ + public void mapmesh2f(int style, int umin, int umax, int vmin, int vmax) { + if (output_triangles) { + // System.out.println("TODO openglsurfaceavaluator.mapmesh2f output_triangles"); + } else { + /* //DEBUG - draw control points + this.poradi++; + if (poradi % 2 == 0) + gl.glColor3f(1, 0, 0); + else if (poradi % 2 == 1) + gl.glColor3f(0, 1, 0); + */ + switch (style) { + case NurbsConsts.N_MESHFILL: + gl.glEvalMesh2(GL2.GL_FILL, umin, umax, vmin, vmax); + break; + case NurbsConsts.N_MESHLINE: + gl.glEvalMesh2(GL2.GL_LINE, umin, umax, vmin, vmax); + break; + case NurbsConsts.N_MESHPOINT: + gl.glEvalMesh2(GL2.GL_POINT, umin, umax, vmin, vmax); + break; + } + } + } + + /** + * Initializes evaluator + * @param type surface type + * @param ulo lowest u + * @param uhi highest u + * @param ustride number of objects between control points in u direction + * @param uorder surface order in u direction + * @param vlo lowest v + * @param vhi highest v + * @param vstride number of control points' coords + * @param vorder surface order in v direction + * @param pts control points + */ + public void map2f(int type, float ulo, float uhi, int ustride, int uorder, + float vlo, float vhi, int vstride, int vorder, CArrayOfFloats pts) { + // TODO Auto-generated method stub + if (output_triangles) { + // System.out.println("TODO openglsurfaceevaluator.map2f output_triangles"); + } else { + gl.glMap2f(type, ulo, uhi, ustride, uorder, vlo, vhi, vstride, + vorder, pts.getArray(), pts.getPointer()); + } + } + + /** + * Calls opengl enable + * @param type what to enable + */ + public void enable(int type) { + //DONE + gl.glEnable(type); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GLUgl2nurbsImpl.java b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GLUgl2nurbsImpl.java new file mode 100644 index 000000000..bd0eaf771 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GLUgl2nurbsImpl.java @@ -0,0 +1,862 @@ +package jogamp.opengl.glu.gl2.nurbs; +import jogamp.opengl.glu.nurbs.*; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +import java.lang.reflect.Method; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.glu.GLUnurbs; + +/** + * Base object for working with NURBS curves and surfaces + * + * @author Tomas Hrasky + * + */ +public class GLUgl2nurbsImpl implements GLUnurbs { + + /** + * Curve type - no type + */ + public static final int CT_NONE = 0; + + /** + * Curve type - NURBS curve + */ + public static final int CT_NURBSCURVE = 1; + + /** + * Curve type - picewise linear curve + */ + public static final int CT_NPWLCURVE = 2; + + /** + * Matrixes autoloading + */ + private boolean autoloadmode; + + /** + * Using callback + */ + private int callBackFlag; + + /** + * Object for error call backs + */ + private Object errorCallback; + + /** + * List of map definitions + */ + Maplist maplist; + + /** + * Indicates validity of data + */ + private int isDataValid; + + /** + * Are we in the middle of curve processing + */ + private int inCurve; + + /** + * Current curve + */ + private O_curve currentCurve; + + /** + * Are we in trim + */ + private boolean inTrim; + + /** + * Are we playbacking curve/surface rendering + */ + private boolean playBack; + + /** + * Next curve in linked list + */ + private O_curve nextCurve; + + /** + * Is curve modified + */ + private int isCurveModified; + + /** + * Object holding rendering settings + */ + private Renderhints renderhints; + + /** + * Display list + */ + private DisplayList dl; + + /** + * Object for subdividing curves and surfaces + */ + private Subdivider subdivider; + + /** + * Object responsible for rendering + */ + private Backend backend; + + /** + * Next picewise linear curve in linked list + */ + private O_pwlcurve nextPwlcurve; + + /** + * Next trimming NURBS curve in linked list + */ + private O_nurbscurve nextNurbscurve; + + /** + * Are we in the middle of surface processing + */ + private int inSurface; + + /** + * Are there any changes in trimming + */ + private boolean isTrimModified; + + /** + * Are there any changes in surface data + */ + private boolean isDataSurfaceModified; + + /** + * Nurber of trmims of processed surface + */ + private int numTrims; + + /** + * Current processed surface + */ + private O_surface currentSurface; + + /** + * Next trimming curve + */ + private O_trim nextTrim; + + /** + * Nextr surface in linked list + */ + private O_nurbssurface nextNurbssurface; + + /** + * Are there any changes in surface + */ + private boolean isSurfaceModified; + + /** + * Initializes default GLUgl2nurbs object + */ + public GLUgl2nurbsImpl() { + // DONE + maplist = new Maplist(backend); + renderhints = new Renderhints(); + subdivider = new Subdivider(); + // original code + + redefineMaps(); + + defineMap(GL2.GL_MAP2_NORMAL, 0, 3); + defineMap(GL2.GL_MAP1_NORMAL, 0, 3); + defineMap(GL2.GL_MAP2_TEXTURE_COORD_1, 0, 1); + defineMap(GL2.GL_MAP1_TEXTURE_COORD_1, 0, 1); + defineMap(GL2.GL_MAP2_TEXTURE_COORD_2, 0, 2); + defineMap(GL2.GL_MAP1_TEXTURE_COORD_2, 0, 2); + defineMap(GL2.GL_MAP2_TEXTURE_COORD_3, 0, 3); + defineMap(GL2.GL_MAP1_TEXTURE_COORD_3, 0, 3); + defineMap(GL2.GL_MAP2_TEXTURE_COORD_4, 1, 4); + defineMap(GL2.GL_MAP1_TEXTURE_COORD_4, 1, 4); + defineMap(GL2.GL_MAP2_VERTEX_4, 1, 4); + defineMap(GL2.GL_MAP1_VERTEX_4, 1, 4); + defineMap(GL2.GL_MAP2_VERTEX_3, 0, 3); + defineMap(GL2.GL_MAP1_VERTEX_3, 0, 3); + defineMap(GL2.GL_MAP2_COLOR_4, 0, 4); + defineMap(GL2.GL_MAP1_COLOR_4, 0, 4); + defineMap(GL2.GL_MAP2_INDEX, 0, 1); + defineMap(GL2.GL_MAP1_INDEX, 0, 1); + + setnurbsproperty(GL2.GL_MAP1_VERTEX_3, NurbsConsts.N_SAMPLINGMETHOD, + (float) NurbsConsts.N_PATHLENGTH); + setnurbsproperty(GL2.GL_MAP1_VERTEX_4, NurbsConsts.N_SAMPLINGMETHOD, + (float) NurbsConsts.N_PATHLENGTH); + setnurbsproperty(GL2.GL_MAP2_VERTEX_3, NurbsConsts.N_SAMPLINGMETHOD, + (float) NurbsConsts.N_PATHLENGTH); + setnurbsproperty(GL2.GL_MAP2_VERTEX_4, NurbsConsts.N_SAMPLINGMETHOD, + (float) NurbsConsts.N_PATHLENGTH); + + setnurbsproperty(GL2.GL_MAP1_VERTEX_3, NurbsConsts.N_PIXEL_TOLERANCE, + (float) 50.0); + setnurbsproperty(GL2.GL_MAP1_VERTEX_4, NurbsConsts.N_PIXEL_TOLERANCE, + (float) 50.0); + setnurbsproperty(GL2.GL_MAP2_VERTEX_3, NurbsConsts.N_PIXEL_TOLERANCE, + (float) 50.0); + setnurbsproperty(GL2.GL_MAP2_VERTEX_4, NurbsConsts.N_PIXEL_TOLERANCE, + (float) 50.0); + + setnurbsproperty(GL2.GL_MAP1_VERTEX_3, NurbsConsts.N_ERROR_TOLERANCE, + (float) 0.50); + setnurbsproperty(GL2.GL_MAP1_VERTEX_4, NurbsConsts.N_ERROR_TOLERANCE, + (float) 0.50); + setnurbsproperty(GL2.GL_MAP2_VERTEX_3, NurbsConsts.N_ERROR_TOLERANCE, + (float) 0.50); + setnurbsproperty(GL2.GL_MAP2_VERTEX_4, NurbsConsts.N_ERROR_TOLERANCE, + (float) 0.50); + + setnurbsproperty(GL2.GL_MAP1_VERTEX_3, NurbsConsts.N_S_STEPS, + (float) 100.0); + setnurbsproperty(GL2.GL_MAP1_VERTEX_4, NurbsConsts.N_S_STEPS, + (float) 100.0); + setnurbsproperty(GL2.GL_MAP2_VERTEX_3, NurbsConsts.N_S_STEPS, + (float) 100.0); + setnurbsproperty(GL2.GL_MAP2_VERTEX_4, NurbsConsts.N_S_STEPS, + (float) 100.0); + + setnurbsproperty(GL2.GL_MAP1_VERTEX_3, NurbsConsts.N_SAMPLINGMETHOD, + NurbsConsts.N_PATHLENGTH); + + set_domain_distance_u_rate(100.0); + set_domain_distance_v_rate(100.0); + set_is_domain_distance_sampling(0); + + this.autoloadmode = true; + + this.callBackFlag = 0; + + this.errorCallback = null; + } + + /** + * Sets domain distance for dom.dist. sampling in u direction + * + * @param d + * distance + */ + private void set_domain_distance_u_rate(double d) { + // DONE + subdivider.set_domain_distance_u_rate(d); + } + + /** + * Sets domain distance for dom.dist. sampling in v direction + * + * @param d + * distance + */ + private void set_domain_distance_v_rate(double d) { + // DONE + subdivider.set_domain_distance_v_rate(d); + } + + /** + * Begins new NURBS curve + */ + public void bgncurve() { + // DONE + O_curve o_curve = new O_curve(); + thread("do_bgncurve", o_curve); + } + + /** + * Calls a method with given name and passes argumet + * + * @param name + * name of a method to be called + * @param arg + * parameter to be passed to called method + */ + private void thread(String name, Object arg) { + // DONE + Class partype[] = new Class[1]; + partype[0] = arg.getClass(); + Method m; + try { + m = this.getClass().getMethod(name, partype); + if (dl != null) { + dl.append(this, m, arg); + } else { + m.invoke(this, new Object[] { arg }); + } + } catch (Throwable e) { + e.printStackTrace(); + } + + } + + /** + * Calls a method with given name + * + * @param name + * name of a method to be called + */ + private void thread2(String name) { + // DONE + try { + Method m = this.getClass().getMethod(name, (Class[]) null); + if (dl != null) { + dl.append(this, m, null); + } else { + m.invoke(this, (Object[]) null); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + + /** + * Begins a NURBS curve + * + * @param o_curve + * curve object + */ + public void do_bgncurve(O_curve o_curve) { + if (inCurve > 0) { + do_nurbserror(6); + endcurve(); + } + inCurve = 1; + currentCurve = o_curve; + + currentCurve.curvetype = CT_NONE; + + if (inTrim) { + if (!nextCurve.equals(o_curve)) { + isCurveModified = 1; + nextCurve = o_curve; + } + } else { + if (!playBack) + bgnrender(); + isDataValid = 1; + } + nextCurve = o_curve.next; + // kind of solution of union + nextPwlcurve = o_curve.o_pwlcurve; + nextNurbscurve = o_curve.o_nurbscurve; + } + + /** + * Begins new surface + * + * @param o_surface + * surface object + */ + public void do_bgnsurface(O_surface o_surface) { + // DONE + if (inSurface > 0) { + do_nurbserror(27); + endsurface(); + } + inSurface = 1; + if (!playBack) + bgnrender(); + + isTrimModified = false; + isDataSurfaceModified = false; + isDataValid = 1; + numTrims = 0; + currentSurface = o_surface; + nextTrim = o_surface.o_trim; + nextNurbssurface = o_surface.o_nurbssurface; + } + + /** + * End a curve + */ + public void endcurve() { + // DONE + thread2("do_endcurve"); + } + + /** + * Ends surface + */ + public void do_endsurface() { + // DONE + if (inTrim) { + do_nurbserror(12); + endtrim(); + } + + if (inSurface <= 0) { + do_nurbserror(13); + return; + } + + inSurface = 0; + + nextNurbssurface = null; + + if (isDataValid <= 0) { + return; + } + + if (nextTrim != null) { + isTrimModified = true; + nextTrim = null; + } + + // TODO errval ?? + if (numTrims > 0) { + // System.out.println("TODO glunurbs.do_endsurface - numtrims > 0"); + } + + subdivider.beginQuilts(new GL2Backend()); + for (O_nurbssurface n = currentSurface.o_nurbssurface; n != null; n = n.next) { + subdivider.addQuilt(n.bezier_patches); + } + subdivider.endQuilts(); + subdivider.drawSurfaces(); + if (!playBack) + endrender(); + + } + + /** + * Ends a curve + */ + public void do_endcurve() { + // DONE + // // System.out.println("do_endcurve"); + if (inCurve <= 0) { + do_nurbserror(7); + return; + } + inCurve = 0; + + nextCurve = null; + + if (currentCurve.curvetype == CT_NURBSCURVE) { + // nextNurbscurve = null; + // currentCurve.o_nurbscurve=null; + } else { + // nextPwlcurve = null; + // currentCurve.o_pwlcurve=null; + } + if (!inTrim) { + if (isDataValid <= 0) { + return; + } + // TODO errval? + if (currentCurve.curvetype == CT_NURBSCURVE) { + subdivider.beginQuilts(new GL2Backend()); + + for (O_nurbscurve n = currentCurve.o_nurbscurve; n != null; n = n.next) + subdivider.addQuilt(n.bezier_curves); + + subdivider.endQuilts(); + subdivider.drawCurves(); + if (!playBack) + endrender(); + } else { + if (!playBack) + endrender(); + do_nurbserror(9); + } + } + + } + + /** + * Method for handling error codes + * + * @param i + * error code + */ + private void do_nurbserror(int i) { + // TODO nurberror + // System.out.println("TODO nurbserror " + i); + } + + /** + * Begin rendering + */ + private void bgnrender() { + // DONE + if (autoloadmode) { + loadGLMatrices(); + } + } + + /** + * Load matrices from OpenGL state machine + */ + private void loadGLMatrices() { + // TODO Auto-generated method stub + // System.out.println("TODO glunurbs.loadGLMatrices"); + } + + /** + * End rendering + */ + private void endrender() { + // DONE + } + + /** + * Make a NURBS curve + * + * @param nknots + * number of knots in knot vector + * @param knot + * knot vector + * @param stride + * number of control points coordinates + * @param ctlarray + * control points + * @param order + * order of the curve + * @param realType + * type of the curve + */ + public void nurbscurve(int nknots, float[] knot, int stride, + float[] ctlarray, int order, int realType) { + // DONE + Mapdesc mapdesc = maplist.locate(realType); + if (mapdesc == null) { + do_nurbserror(35); + isDataValid = 0; + return; + } + if (ctlarray == null) { + do_nurbserror(36); + isDataValid = 0; + return; + } + if (stride < 0) { + do_nurbserror(34); + isDataValid = 0; + return; + } + Knotvector knots = new Knotvector(nknots, stride, order, knot); + + if (!do_check_knots(knots, "curve")) + return; + + O_nurbscurve o_nurbscurve = new O_nurbscurve(realType); + o_nurbscurve.bezier_curves = new Quilt(mapdesc); + CArrayOfFloats ctrlcarr = new CArrayOfFloats(ctlarray); + o_nurbscurve.bezier_curves.toBezier(knots, ctrlcarr, mapdesc + .getNCoords()); + thread("do_nurbscurve", o_nurbscurve); + } + + /** + * Check knot vector specification + * + * @param knots + * knot vector + * @param msg + * error message + * @return knot vector is / is not valid + */ + public boolean do_check_knots(Knotvector knots, String msg) { + // DONE + int status = knots.validate(); + if (status > 0) { + do_nurbserror(status); + if (renderhints.errorchecking != NurbsConsts.N_NOMSG) + knots.show(msg); + } + return (status > 0) ? false : true; + } + + /** + * Draw a curve + * + * @param o_nurbscurve + * NURBS curve object + */ + public void do_nurbscurve(O_nurbscurve o_nurbscurve) { + // DONE + + if (inCurve <= 0) { + bgncurve(); + inCurve = 2; + } + + if (o_nurbscurve.used) { + do_nurbserror(23); + isDataValid = 0; + return; + } else + o_nurbscurve.used = true; + + if (currentCurve.curvetype == CT_NONE) { + currentCurve.curvetype = CT_NURBSCURVE; + } else if (currentCurve.curvetype != CT_NURBSCURVE) { + do_nurbserror(24); + isDataValid = 0; + return; + } + + // it was necessary to overcome problem with pointer to pointer here + + // if(!o_nurbscurve.equals(nextNurbscurve)){ + if (!o_nurbscurve.equals(currentCurve.o_nurbscurve)) { + isCurveModified = 1; + currentCurve.o_nurbscurve = o_nurbscurve; + // nextNurbscurve=o_nurbscurve; + + } + + nextNurbscurve = o_nurbscurve.next; + + if (!currentCurve.equals(o_nurbscurve.owner)) { + isCurveModified = 1; + o_nurbscurve.owner = currentCurve; + } + + if (o_nurbscurve.owner == null) + isCurveModified = 1; + + if (inCurve == 2) + endcurve(); + } + + /** + * Draw NURBS surface + * + * @param o_nurbssurface + * NURBS surface object + */ + public void do_nurbssurface(O_nurbssurface o_nurbssurface) { + // DONE + if (inSurface <= 0) { + bgnsurface(); + inSurface = 2; + } + if (o_nurbssurface.used) { + do_nurbserror(25); + isDataValid = 0; + return; + } else + o_nurbssurface.used = true; + + if (!o_nurbssurface.equals(nextNurbscurve)) { + isSurfaceModified = true; + // nextNurbssurface=o_nurbssurface; + currentSurface.o_nurbssurface = o_nurbssurface; + } + + if (!currentSurface.equals(o_nurbssurface.owner)) { + isSurfaceModified = true; + o_nurbssurface.owner = currentSurface; + } + + nextNurbssurface = o_nurbssurface.next; + + if (inSurface == 2) + endsurface(); + } + + /** + * (Re)Inicialize maps + */ + public void redefineMaps() { + // DONE + maplist.initialize(); + } + + /** + * Define a map of given properties + * + * @param type + * map type + * @param rational + * is rational + * @param ncoords + * number of control point coordinates + */ + public void defineMap(int type, int rational, int ncoords) { + // DONE + maplist.define(type, rational, ncoords); + } + + /** + * Set NURBS property + * + * @param type + * property type + * @param tag + * property tag + * @param value + * property value + */ + public void setnurbsproperty(int type, int tag, float value) { + // DONE + Mapdesc mapdesc = maplist.locate(type); + if (mapdesc == null) { + do_nurbserror(35); + return; + } + if (!mapdesc.isProperty(tag)) { + do_nurbserror(26); + return; + } + Property prop = new Property(type, tag, value); + thread("do_setnurbsproperty2", prop); + } + + /** + * Set parameters of existing property + * + * @param prop + * property + */ + public void do_setnurbsproperty2(Property prop) { + Mapdesc mapdesc = maplist.find(prop.type); + mapdesc.setProperty(prop.tag, prop.value); + } + + /** + * Set given property to rendering hints + * + * @param prop + * property to be set + */ + public void do_setnurbsproperty(Property prop) { + // DONE + renderhints.setProperty(prop); + // TODO freeproperty? + } + + /** + * Sets wheteher we use domain distance sampling + * + * @param i + * domain distance sampling flag + */ + public void set_is_domain_distance_sampling(int i) { + // DONE + subdivider.set_is_domain_distance_sampling(i); + } + + /** + * Begin new surface + */ + public void bgnsurface() { + // DONE + O_surface o_surface = new O_surface(); + // TODO nuid + // System.out.println("TODO glunurbs.bgnsurface nuid"); + thread("do_bgnsurface", o_surface); + } + + /** + * End current surface + */ + public void endsurface() { + // DONE + thread2("do_endsurface"); + } + + /** + * End surface trimming + */ + private void endtrim() { + // TODO Auto-generated method stub + // System.out.println("TODO glunurbs.endtrim"); + } + + /** + * Make NURBS surface + * + * @param sknot_count + * number of knots in s direction + * @param sknot + * knot vector in s direction + * @param tknot_count + * number of knots in t direction + * @param tknot + * knot vector in t direction + * @param s_stride + * number of coords of control points in s direction + * @param t_stride + * number of coords of control points in t direction + * @param ctlarray + * control points + * @param sorder + * order of curve in s direction + * @param torder + * order of curve in t direction + * @param type + * NURBS surface type (rational,...) + */ + public void nurbssurface(int sknot_count, float[] sknot, int tknot_count, + float[] tknot, int s_stride, int t_stride, float[] ctlarray, + int sorder, int torder, int type) { + // DONE + Mapdesc mapdesc = maplist.locate(type); + if (mapdesc == null) { + do_nurbserror(35); + isDataValid = 0; + return; + } + if (s_stride < 0 || t_stride < 0) { + do_nurbserror(34); + isDataValid = 0; + return; + } + Knotvector sknotvector = new Knotvector(sknot_count, s_stride, sorder, + sknot); + if (!do_check_knots(sknotvector, "surface")) + return; + Knotvector tknotvector = new Knotvector(tknot_count, t_stride, torder, + tknot); + if (!do_check_knots(tknotvector, "surface")) + return; + + O_nurbssurface o_nurbssurface = new O_nurbssurface(type); + o_nurbssurface.bezier_patches = new Quilt(mapdesc); + + CArrayOfFloats ctrlarr = new CArrayOfFloats(ctlarray); + o_nurbssurface.bezier_patches.toBezier(sknotvector, tknotvector, + ctrlarr, mapdesc.getNCoords()); + thread("do_nurbssurface", o_nurbssurface); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/BuildMipmap.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/BuildMipmap.java new file mode 100644 index 000000000..f5fe17a7b --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/BuildMipmap.java @@ -0,0 +1,1597 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.glu.GLU; +import jogamp.opengl.Debug; +import com.jogamp.common.nio.Buffers; +import java.nio.*; +import java.io.*; + +/** + * + * @author Administrator + */ +public class BuildMipmap { + + private static final boolean DEBUG = Debug.debug("BuildMipmap"); + private static final boolean VERBOSE = Debug.verbose(); + + /** Creates a new instance of BuildMipmap */ + public BuildMipmap() { + } + + public static int gluBuild1DMipmapLevelsCore( GL gl, int target, int internalFormat, + int width, int widthPowerOf2, int format, int type, int userLevel, + int baseLevel, int maxLevel, ByteBuffer data ) { + int newwidth; + int level, levels; + ShortBuffer newImage = null; + int newImage_width; + ShortBuffer otherImage = null; + ShortBuffer imageTemp = null; + int memReq; + int maxsize; + int cmpts; + PixelStorageModes psm = new PixelStorageModes(); + + assert( Mipmap.checkMipmapArgs( internalFormat, format, type ) == 0 ); + assert( width >= 1 ); + + newwidth = widthPowerOf2; + levels = Mipmap.computeLog( newwidth ); + + levels += userLevel; + + Mipmap.retrieveStoreModes( gl, psm ); + try { + newImage = Buffers.newDirectByteBuffer( Mipmap.image_size( width, 1, format, + GL2.GL_UNSIGNED_SHORT ) ).asShortBuffer(); + } catch( OutOfMemoryError ome ) { + return( GLU.GLU_OUT_OF_MEMORY ); + } + newImage_width = width; + + Image.fill_image( psm, width, 1, format, type, Mipmap.is_index( format ), data, newImage ); + cmpts = Mipmap.elements_per_group( format, type ); + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, 2 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, 0 ); + + // if swap_bytes was set, swapping occurred in fill_image + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, GL2.GL_FALSE ); + + for( level = userLevel; level <= levels; level++ ) { + if( newImage_width == newwidth ) { + // user newimage for this level + if( baseLevel <= level && level <= maxLevel ) { + gl.getGL2().glTexImage1D( target, level, internalFormat, newImage_width, 0, format, + GL2.GL_UNSIGNED_SHORT, newImage ); + } + } else { + if( otherImage == null ) { + memReq = Mipmap.image_size( newwidth, 1, format, GL2.GL_UNSIGNED_SHORT ); + try { + otherImage = Buffers.newDirectByteBuffer( memReq ).asShortBuffer(); + } catch( OutOfMemoryError ome ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + } + ScaleInternal.scale_internal( cmpts, newImage_width, 1, newImage, newwidth, 1, otherImage ); + // swap newImage and otherImage + imageTemp = otherImage; + otherImage = newImage; + newImage = imageTemp; + + newImage_width = newwidth; + if( baseLevel <= level && level <= maxLevel ) { + gl.getGL2().glTexImage1D( target, level, internalFormat, newImage_width, 0, + format, GL2.GL_UNSIGNED_SHORT, newImage ); + } + } + if( newwidth > 1 ) { + newwidth /= 2; + } + } + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + + return( 0 ); + } + + public static int bitmapBuild2DMipmaps( GL gl, int target, int internalFormat, + int width, int height, int format, int type, ByteBuffer data ) { + int newwidth[] = new int[1]; + int newheight[] = new int[1]; + int level, levels; + ShortBuffer newImage = null; + int newImage_width; + int newImage_height; + ShortBuffer otherImage = null; + ShortBuffer tempImage = null; + int memReq; + int maxsize; + int cmpts; + PixelStorageModes psm = new PixelStorageModes(); + + Mipmap.retrieveStoreModes( gl, psm ); + + Mipmap.closestFit( gl, target, width, height, internalFormat, format, type, newwidth, newheight ); + + levels = Mipmap.computeLog( newwidth[0] ); + level = Mipmap.computeLog( newheight[0] ); + if( level > levels ) { + levels = level; + } + + try { + newImage = Buffers.newDirectByteBuffer( Mipmap.image_size( width, height, + format, GL2.GL_UNSIGNED_SHORT ) ).asShortBuffer(); + } catch( OutOfMemoryError ome ) { + return( GLU.GLU_OUT_OF_MEMORY ); + } + newImage_width = width; + newImage_height = height; + + Image.fill_image( psm, width, height, format, type, Mipmap.is_index( format ), data, newImage ); + + cmpts = Mipmap.elements_per_group( format, type ); + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, 2 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, 0 ); + + // if swap_bytes is set, swapping occurred in fill_image + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, GL2.GL_FALSE ); + + for( level = 0; level < levels; level++ ) { + if( newImage_width == newwidth[0] && newImage_height == newheight[0] ) { + newImage.rewind(); + gl.glTexImage2D( target, level, internalFormat, newImage_width, + newImage_height, 0, format, GL2.GL_UNSIGNED_SHORT, newImage ); + } else { + if( otherImage == null ) { + memReq = Mipmap.image_size( newwidth[0], newheight[0], format, GL2.GL_UNSIGNED_SHORT ); + try { + otherImage = Buffers.newDirectByteBuffer( memReq ).asShortBuffer(); + } catch( OutOfMemoryError ome ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + } + ScaleInternal.scale_internal( cmpts, newImage_width, newImage_height, + newImage, newwidth[0], newheight[0], otherImage ); + // swap newImage and otherImage + tempImage = otherImage; + otherImage = newImage; + newImage = tempImage; + + newImage_width = newwidth[0]; + newImage_height = newheight[0]; + newImage.rewind(); + gl.glTexImage2D( target, level, internalFormat, newImage_width, newImage_height, + 0, format, GL2.GL_UNSIGNED_SHORT, newImage ); + } + if( newheight[0] > 1 ) { + newwidth[0] /= 2; + } + if( newheight[0] > 1 ) { + newheight[0] /= 2; + } + } + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + + return( 0 ); + } + + public static int gluBuild2DMipmapLevelsCore( GL gl, int target, int internalFormat, + int width, int height, int widthPowerOf2, int heightPowerOf2, + int format, int type, int userLevel, int baseLevel, int maxLevel, + ByteBuffer data ) { // PointerWrapper data + int newwidth; + int newheight; + int level, levels; + int usersImage; + ByteBuffer srcImage = null; + ByteBuffer dstImage = null; + ByteBuffer tempImage = null; + int newImage_width; + int newImage_height; + short[] SWAP_IMAGE = null; + int memReq; + int maxsize; + int cmpts; + int mark=-1; + + boolean myswap_bytes; + int groups_per_line, element_size, group_size; + int rowsize, padding; + PixelStorageModes psm = new PixelStorageModes(); + + assert( Mipmap.checkMipmapArgs( internalFormat, format, type ) == 0 ); + assert( width >= 1 && height >= 1 ); + + if( type == GL2.GL_BITMAP ) { + return( bitmapBuild2DMipmaps( gl, target, internalFormat, width, height, format, type, data ) ); + } + + newwidth = widthPowerOf2; + newheight = heightPowerOf2; + levels = Mipmap.computeLog( newwidth ); + level = Mipmap.computeLog( newheight ); + if( level > levels ) { + levels = level; + } + + levels += userLevel; + + Mipmap.retrieveStoreModes( gl, psm ); + myswap_bytes = psm.getUnpackSwapBytes(); + cmpts = Mipmap.elements_per_group( format, type ); + if( psm.getUnpackRowLength() > 0 ) { + groups_per_line = psm.getUnpackRowLength(); + } else { + groups_per_line = width; + } + + element_size = Mipmap.bytes_per_element( type ); + group_size = element_size * cmpts; + if( element_size == 1 ) { + myswap_bytes = false; + } + + rowsize = groups_per_line * group_size; + padding = ( rowsize % psm.getUnpackAlignment() ); + if( padding != 0 ) { + rowsize += psm.getUnpackAlignment() - padding; + } + + mark = psm.getUnpackSkipRows() * rowsize + psm.getUnpackSkipPixels() * group_size; + data.position( mark ); + + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, 0 ); + + level = userLevel; + + // already power of two square + if( width == newwidth && height == newheight ) { + // use usersImage for level userLevel + if( baseLevel <= level && level <= maxLevel ) { + data.rewind(); + gl.glTexImage2D( target, level, internalFormat, width, height, 0, format, type, data ); + } + if( levels == 0 ) { /* we're done. clean up and return */ + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + return( 0 ); + } + int nextWidth = newwidth / 2; + int nextHeight = newheight / 2; + + // clamp to 1 + if( nextWidth < 1 ) { + nextWidth = 1; + } + if( nextHeight < 1 ) { + nextHeight = 1; + } + memReq = Mipmap.image_size( nextWidth, nextHeight, format, type ); + + try { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + case( GL2.GL_BYTE ): + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_INT ): + case( GL2.GL_FLOAT ): + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + dstImage = Buffers.newDirectByteBuffer( memReq ); + break; + default: + return( GLU.GLU_INVALID_ENUM ); + } + } catch( OutOfMemoryError ome ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + if( dstImage != null ) { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + HalveImage.halveImage_ubyte( cmpts, width, height, data, dstImage, element_size, rowsize, group_size ); + break; + case( GL2.GL_BYTE ): + HalveImage.halveImage_byte( cmpts, width, height, data, dstImage, element_size, rowsize, group_size ); + break; + case( GL2.GL_UNSIGNED_SHORT ): + HalveImage.halveImage_ushort( cmpts, width, height, data, dstImage.asShortBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_SHORT ): + HalveImage.halveImage_short( cmpts, width, height, data, dstImage.asShortBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT ): + HalveImage.halveImage_uint( cmpts, width, height, data, dstImage.asIntBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_INT ): + HalveImage.halveImage_int( cmpts, width, height, data, dstImage.asIntBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_FLOAT ): + HalveImage.halveImage_float( cmpts, width, height, data, dstImage.asFloatBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + assert( format == GL2.GL_RGB ); + HalveImage.halveImagePackedPixel( 3, new Extract332(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + assert( format == GL2.GL_RGB ); + HalveImage.halveImagePackedPixel( 3, new Extract233rev(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + HalveImage.halveImagePackedPixel( 3, new Extract565(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + HalveImage.halveImagePackedPixel( 3, new Extract565rev(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + HalveImage.halveImagePackedPixel( 4, new Extract4444(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + HalveImage.halveImagePackedPixel( 4, new Extract4444rev(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + HalveImage.halveImagePackedPixel( 4, new Extract5551(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + HalveImage.halveImagePackedPixel( 4, new Extract1555rev(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + HalveImage.halveImagePackedPixel( 4, new Extract8888(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + HalveImage.halveImagePackedPixel( 4, new Extract8888rev(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + HalveImage.halveImagePackedPixel( 4, new Extract1010102(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + HalveImage.halveImagePackedPixel( 4, new Extract2101010rev(), width, height, data, dstImage, element_size, rowsize, myswap_bytes ); + break; + default: + assert( false ); + break; + } + } + newwidth = width / 2; + newheight = height / 2; + // clamp to 1 + if( newwidth < 1 ) { + newwidth = 1; + } + if( newheight < 1 ) { + newheight = 1; + } + + myswap_bytes = false; + rowsize = newwidth * group_size; + memReq = Mipmap.image_size( newwidth, newheight, format, type ); + // swap srcImage and dstImage + tempImage = srcImage; + srcImage = dstImage; + dstImage = tempImage; + try { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + case( GL2.GL_BYTE ): + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_INT ): + case( GL2.GL_FLOAT ): + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + dstImage = Buffers.newDirectByteBuffer( memReq ); + break; + default: + return( GLU.GLU_INVALID_ENUM ); + } + } catch( OutOfMemoryError ome ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + // level userLevel+1 is in srcImage; level userLevel already saved + level = userLevel + 1; + } else { // user's image is not nice powerof2 size square + memReq = Mipmap.image_size( newwidth, newheight, format, type ); + try { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + case( GL2.GL_BYTE ): + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_INT ): + case( GL2.GL_FLOAT ): + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + dstImage = Buffers.newDirectByteBuffer( memReq ); + break; + default: + return( GLU.GLU_INVALID_ENUM ); + } + } catch( OutOfMemoryError ome ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + data.position( mark ); + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + ScaleInternal.scale_internal_ubyte( cmpts, width, height, data, + newwidth, newheight, dstImage, element_size, rowsize, group_size ); + break; + case( GL2.GL_BYTE ): + ScaleInternal.scale_internal_byte( cmpts, width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, group_size ); + break; + case( GL2.GL_UNSIGNED_SHORT ): + ScaleInternal.scale_internal_ushort( cmpts, width, height, data, newwidth, + newheight, dstImage.asShortBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_SHORT ): + ScaleInternal.scale_internal_ushort( cmpts, width, height, data, newwidth, + newheight, dstImage.asShortBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT ): + ScaleInternal.scale_internal_uint( cmpts, width, height, data, newwidth, + newheight, dstImage.asIntBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_INT ): + ScaleInternal.scale_internal_int( cmpts, width, height, data, newwidth, + newheight, dstImage.asIntBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_FLOAT ): + ScaleInternal.scale_internal_float( cmpts, width, height, data, newwidth, + newheight, dstImage.asFloatBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + ScaleInternal.scaleInternalPackedPixel( 3, new Extract332(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + ScaleInternal.scaleInternalPackedPixel( 3, new Extract233rev(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + ScaleInternal.scaleInternalPackedPixel( 3, new Extract565(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + ScaleInternal.scaleInternalPackedPixel( 3, new Extract565rev(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + ScaleInternal.scaleInternalPackedPixel( 4, new Extract4444(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + ScaleInternal.scaleInternalPackedPixel( 4, new Extract4444rev(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + ScaleInternal.scaleInternalPackedPixel( 4, new Extract5551(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + ScaleInternal.scaleInternalPackedPixel( 4, new Extract1555rev(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + ScaleInternal.scaleInternalPackedPixel( 4, new Extract8888(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + ScaleInternal.scaleInternalPackedPixel( 4, new Extract8888rev(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + ScaleInternal.scaleInternalPackedPixel( 4, new Extract1010102(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + ScaleInternal.scaleInternalPackedPixel( 4, new Extract2101010rev(), width, height, data, newwidth, + newheight, dstImage, element_size, rowsize, myswap_bytes ); + break; + default: + assert( false ); + break; + } + myswap_bytes = false; + rowsize = newwidth * group_size; + // swap dstImage and srcImage + tempImage = srcImage; + srcImage = dstImage; + dstImage = tempImage; + + if( levels != 0 ) { // use as little memory as possible + int nextWidth = newwidth / 2; + int nextHeight = newheight / 2; + if( nextWidth < 1 ) { + nextWidth = 1; + } + if( nextHeight < 1 ) { + nextHeight = 1; + } + + memReq = Mipmap.image_size( nextWidth, nextHeight, format, type ); + try { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + case( GL2.GL_BYTE ): + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_INT ): + case( GL2.GL_FLOAT ): + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + dstImage = Buffers.newDirectByteBuffer( memReq ); + break; + default: + return( GLU.GLU_INVALID_ENUM ); + } + } catch( OutOfMemoryError ome ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + } + // level userLevel is in srcImage; nothing saved yet + level = userLevel; + } + + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, GL2.GL_FALSE ); + if( baseLevel <= level && level <= maxLevel ) { + srcImage.rewind(); + gl.glTexImage2D( target, level, internalFormat, newwidth, newheight, 0, format, type, srcImage ); + if (DEBUG) { + System.err.println("GL Error(" + level + "): " + gl.glGetError() ); + if (VERBOSE) { + srcImage.limit( Mipmap.image_size( newwidth, newheight, format, type ) ); + writeTargaFile("glu2DMipmapJ" + level + ".tga", + srcImage, newwidth, newheight); + srcImage.clear(); + } + } + } + + level++; // update current level for the loop + for( ; level <= levels; level++ ) { + srcImage.rewind(); + dstImage.rewind(); + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + HalveImage.halveImage_ubyte( cmpts, newwidth, newheight, srcImage, dstImage, element_size, rowsize, group_size ); + break; + case( GL2.GL_BYTE ): + HalveImage.halveImage_byte( cmpts, newwidth, newheight, srcImage, dstImage, element_size, rowsize, group_size ); + break; + case( GL2.GL_UNSIGNED_SHORT ): + HalveImage.halveImage_ushort( cmpts, newwidth, newheight, srcImage, dstImage.asShortBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_SHORT ): + HalveImage.halveImage_short( cmpts, newwidth, newheight, srcImage, dstImage.asShortBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT ): + HalveImage.halveImage_uint( cmpts, newwidth, newheight, srcImage, dstImage.asIntBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_INT ): + HalveImage.halveImage_int( cmpts, newwidth, newheight, srcImage, dstImage.asIntBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_FLOAT ): + HalveImage.halveImage_float( cmpts, newwidth, newheight, srcImage, dstImage.asFloatBuffer(), element_size, rowsize, group_size, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + assert( format == GL2.GL_RGB ); + HalveImage.halveImagePackedPixel( 3, new Extract332(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + assert( format == GL2.GL_RGB ); + HalveImage.halveImagePackedPixel( 3, new Extract233rev(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + HalveImage.halveImagePackedPixel( 3, new Extract565(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + HalveImage.halveImagePackedPixel( 3, new Extract565rev(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + HalveImage.halveImagePackedPixel( 4, new Extract4444(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + HalveImage.halveImagePackedPixel( 4, new Extract4444rev(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + HalveImage.halveImagePackedPixel( 4, new Extract5551(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + HalveImage.halveImagePackedPixel( 4, new Extract1555rev(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + HalveImage.halveImagePackedPixel( 4, new Extract8888(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + HalveImage.halveImagePackedPixel( 4, new Extract8888rev(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + HalveImage.halveImagePackedPixel( 4, new Extract1010102(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + HalveImage.halveImagePackedPixel( 4, new Extract2101010rev(), newwidth, newheight, srcImage, dstImage, element_size, rowsize, myswap_bytes ); + break; + default: + assert( false ); + break; + } + + // swap dstImage and srcImage + tempImage = srcImage; + srcImage = dstImage; + dstImage = tempImage; + + if( newwidth > 1 ) { + newwidth /= 2; + rowsize /= 2; + } + if( newheight > 1 ) { + newheight /= 2; + } + // compute amount to pad per row if any + int rowPad = rowsize % psm.getUnpackAlignment(); + + // should row be padded + if( rowPad == 0 ) { + // call teximage with srcImage untouched since its not padded + if( baseLevel <= level && level <= maxLevel ) { + srcImage.rewind(); + gl.glTexImage2D( target, level, internalFormat, newwidth, newheight, 0, format, type, srcImage ); + if (DEBUG) { + System.err.println("GL Error(" + level + "): " + gl.glGetError() ); + if (VERBOSE) { + srcImage.limit( Mipmap.image_size( newwidth, newheight, format, type ) ); + writeTargaFile("glu2DMipmapJ" + level + ".tga", + srcImage, newwidth, newheight); + srcImage.clear(); + } + } + } + } else { + // compute length of new row in bytes, including padding + int newRowLength = rowsize + psm.getUnpackAlignment() - rowPad; + int ii, jj; + int dstTrav; + int srcTrav; + + // allocate new image for mipmap of size newRowLength x newheight + ByteBuffer newMipmapImage = null; + try { + newMipmapImage = ByteBuffer.allocateDirect( newRowLength * newheight ); + } catch( OutOfMemoryError ome ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + srcImage.rewind(); + // copy image from srcImage into newMipmapImage by rows + for( ii = 0; ii < newheight; ii++ ) { + newMipmapImage.position(newRowLength * ii); + for( jj = 0; jj < rowsize; jj++ ) { + newMipmapImage.put( srcImage.get() ); + } + } + + // and use this new image for mipmapping instead + if( baseLevel <= level && level <= maxLevel ) { + newMipmapImage.rewind(); + gl.glTexImage2D( target, level, internalFormat, newwidth, newheight, 0, format, type, newMipmapImage ); + if (DEBUG) { + System.err.println("GL Error(" + level + " padded): " + gl.glGetError() ); + if (VERBOSE) { + writeTargaFile("glu2DMipmapJ" + level + ".tga", + newMipmapImage, newwidth, newheight); + } + } + } + } + } + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); + + return( 0 ); + } + + public static int fastBuild2DMipmaps( GL gl, PixelStorageModes psm, int target, + int components, int width, int height, int format, int type, ByteBuffer data ) { + int[] newwidth = new int[1]; + int[] newheight = new int[1]; + int level, levels; + ByteBuffer newImage; + int newImage_width; + int newImage_height; + ByteBuffer otherImage; + ByteBuffer imageTemp; + int memReq; + int maxsize; + int cmpts; + + Mipmap.closestFit( gl, target, width, height, components, format, type, newwidth, + newheight ); + + levels = Mipmap.computeLog( newwidth[0] ); + level = Mipmap.computeLog( newheight[0] ); + if( level > levels ) { + levels = level; + } + + cmpts = Mipmap.elements_per_group( format, type ); + + otherImage = null; + // No need to copy the user data if its packed correctly. + // Make sure that later routines don't change that data. + + if( psm.getUnpackSkipRows() == 0 && psm.getUnpackSkipPixels() == 0 ) { + newImage = data; + newImage_width = width; + newImage_height = height; + } else { + int rowsize; + int group_per_line; + int elements_per_line; + int start; + int iter; + int iter2; + int i, j; + + try { + newImage = Buffers.newDirectByteBuffer( Mipmap.image_size(width, height, format, GL2.GL_UNSIGNED_BYTE ) ); + } catch( OutOfMemoryError err ) { + return( GLU.GLU_OUT_OF_MEMORY ); + } + newImage_width = width; + newImage_height = height; + + // Abbreviated version of fill_image for the restricted case. + if( psm.getUnpackRowLength() > 0 ) { + group_per_line = psm.getUnpackRowLength(); + } else { + group_per_line = width; + } + rowsize = group_per_line * cmpts; + elements_per_line = width * cmpts; + start = psm.getUnpackSkipRows() * rowsize + psm.getUnpackSkipPixels() * cmpts; + + for( i = 0; i < height; i++ ) { + iter = start; + data.position( iter ); + for( j = 0; j < elements_per_line; j++ ) { + newImage.put( data.get() ); + } + start += rowsize; + } + } + + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, 1 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, GL2.GL_FALSE ); + + for( level = 0; level <= levels; level++ ) { + if( newImage_width == newwidth[0] && newImage_height == newheight[0] ) { + // use newImage for this level + newImage.rewind(); + gl.glTexImage2D( target, level, components, newImage_width, newImage_height, + 0, format, GL2.GL_UNSIGNED_BYTE, newImage ); + } else { + if( otherImage == null ) { + memReq = Mipmap.image_size( newwidth[0], newheight[0], format, GL2.GL_UNSIGNED_BYTE ); + try { + otherImage = Buffers.newDirectByteBuffer( memReq ); + } catch( OutOfMemoryError err ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, ( psm.getUnpackSwapBytes() ? 1 : 0 ) ) ; + return( GLU.GLU_OUT_OF_MEMORY ); + } + } + // swap newImage and otherImage + imageTemp = otherImage; + otherImage = newImage; + newImage = imageTemp; + + newImage_width = newwidth[0]; + newImage_height = newheight[0]; + newImage.rewind(); + gl.glTexImage2D( target, level, components, newImage_width, newImage_height, + 0, format, GL2.GL_UNSIGNED_BYTE, newImage ); + } + if( newwidth[0] > 1 ) { + newwidth[0] /= 2; + } + if( newheight[0] > 1 ) { + newheight[0] /= 2; + } + } + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, ( psm.getUnpackSwapBytes() ? 1 : 0 ) ) ; + + return( 0 ); + } + + public static int gluBuild3DMipmapLevelsCore( GL gl, int target, int internalFormat, + int width, int height, int depth, int widthPowerOf2, int heightPowerOf2, + int depthPowerOf2, int format, int type, int userLevel, int baseLevel, + int maxLevel, ByteBuffer data ) { + int newWidth; + int newHeight; + int newDepth; + int level, levels; + ByteBuffer usersImage; + ByteBuffer srcImage, dstImage, tempImage; + int newImageWidth; + int newImageHeight; + int newImageDepth; + int memReq; + int maxSize; + int cmpts; + int mark=-1; + + boolean myswapBytes; + int groupsPerLine, elementSize, groupSize; + int rowsPerImage, imageSize; + int rowSize, padding; + PixelStorageModes psm = new PixelStorageModes(); + + assert( Mipmap.checkMipmapArgs( internalFormat, format, type ) == 0 ); + assert( width >= 1 && height >= 1 && depth >= 1 ); + assert( type != GL2.GL_BITMAP ); + + srcImage = dstImage = null; + + newWidth = widthPowerOf2; + newHeight = heightPowerOf2; + newDepth = depthPowerOf2; + levels = Mipmap.computeLog( newWidth ); + level = Mipmap.computeLog( newHeight ); + if( level > levels ) { + levels = level; + } + level = Mipmap.computeLog( newDepth ); + if( level > levels ) { + levels = level; + } + + levels += userLevel; + + Mipmap.retrieveStoreModes3D( gl, psm ); + myswapBytes = psm.getUnpackSwapBytes(); + cmpts = Mipmap.elements_per_group( format, type ); + if( psm.getUnpackRowLength() > 0 ) { + groupsPerLine = psm.getUnpackRowLength(); + } else { + groupsPerLine = width; + } + + elementSize = Mipmap.bytes_per_element( type ); + groupSize = elementSize * cmpts; + if( elementSize == 1 ) { + myswapBytes = false; + } + + // 3dstuff + if( psm.getUnpackImageHeight() > 0 ) { + rowsPerImage = psm.getUnpackImageHeight(); + } else { + rowsPerImage = height; + } + + rowSize = groupsPerLine * groupSize; + padding = ( rowSize % psm.getUnpackAlignment() ); + if( padding != 0 ) { + rowSize += psm.getUnpackAlignment() - padding; + } + + imageSize = rowsPerImage * rowSize; + + usersImage = ByteBuffer.wrap(data.array()); + mark = psm.getUnpackSkipRows() * rowSize + + psm.getUnpackSkipPixels() * groupSize + + psm.getUnpackSkipImages() * imageSize; + usersImage.position( mark ); + + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_IMAGES, 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_IMAGE_HEIGHT, 0 ); + + level = userLevel; + + if( width == newWidth && height == newHeight && depth == newDepth ) { + // use usersImage for level userlevel + if( baseLevel <= level && level <= maxLevel ) { + gl.getGL2().glTexImage3D( target, level, internalFormat, width, height, depth, + 0, format, type, usersImage ); + } + if( levels == 0 ) { /* we're done. clean up and return */ + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, psm.getUnpackSwapBytes() ? 1 : 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_IMAGES, psm.getUnpackSkipImages() ); + gl.glPixelStorei( GL2.GL_UNPACK_IMAGE_HEIGHT, psm.getUnpackImageHeight() ); + return( 0 ); + } + int nextWidth = newWidth / 2; + int nextHeight = newHeight / 2; + int nextDepth = newDepth / 2; + + // clamp to one + if( nextWidth < 1 ) { + nextWidth = 1; + } + if( nextHeight < 1 ) { + nextHeight = 1; + } + if( nextDepth < 1 ) { + nextDepth = 1; + } + memReq = Mipmap.imageSize3D( nextWidth, nextHeight, nextDepth, format, type ); + try { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + case( GL2.GL_BYTE ): + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_INT ): + case( GL2.GL_FLOAT ): + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + dstImage = Buffers.newDirectByteBuffer( memReq ); + break; + default: + return( GLU.GLU_INVALID_ENUM ); + } + } catch( OutOfMemoryError err ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, psm.getUnpackSwapBytes() ? 1 : 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_IMAGES, psm.getUnpackSkipImages() ); + gl.glPixelStorei( GL2.GL_UNPACK_IMAGE_HEIGHT, psm.getUnpackImageHeight() ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + + if( dstImage != null ) { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractUByte(), width, height, depth, + usersImage, dstImage, elementSize, + groupSize, rowSize, imageSize, myswapBytes ); + } else { + HalveImage.halveImage_ubyte( cmpts, width, height, usersImage, + dstImage, elementSize, rowSize, groupSize ); + } + break; + case( GL2.GL_BYTE ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractSByte(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_byte( cmpts, width, height, usersImage, + dstImage, elementSize, rowSize, groupSize ); + } + break; + case( GL2.GL_UNSIGNED_SHORT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractUShort(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_ushort( cmpts, width, height, usersImage, + dstImage.asShortBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_SHORT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractSShort(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_short( cmpts, width, height, usersImage, + dstImage.asShortBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_UNSIGNED_INT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractUInt(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_uint( cmpts, width, height, usersImage, + dstImage.asIntBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_INT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractSInt(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_int( cmpts, width, height, usersImage, + dstImage.asIntBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_FLOAT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractFloat(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_float( cmpts, width, height, usersImage, + dstImage.asFloatBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + assert( format == GL2.GL_RGB ); + HalveImage.halveImagePackedPixel3D( 3, new Extract332(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + assert( format == GL2.GL_RGB ); + HalveImage.halveImagePackedPixel3D( 3, new Extract233rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + HalveImage.halveImagePackedPixel3D( 3, new Extract565(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + HalveImage.halveImagePackedPixel3D( 3, new Extract565rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + HalveImage.halveImagePackedPixel3D( 4, new Extract4444(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + HalveImage.halveImagePackedPixel3D( 4, new Extract4444rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + HalveImage.halveImagePackedPixel3D( 4, new Extract5551(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + HalveImage.halveImagePackedPixel3D( 4, new Extract1555rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + HalveImage.halveImagePackedPixel3D( 4, new Extract8888(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + HalveImage.halveImagePackedPixel3D( 4, new Extract8888rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + HalveImage.halveImagePackedPixel3D( 4, new Extract1010102(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + HalveImage.halveImagePackedPixel3D( 4, new Extract2101010rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + default: + assert( false ); + break; + } + } + newWidth = width / 2; + newHeight = height / 2; + newDepth = depth / 2; + // clamp to 1 + if( newWidth < 1 ) { + newWidth = 1; + } + if( newHeight < 1 ) { + newHeight = 1; + } + if( newDepth < 1 ) { + newDepth = 1; + } + + myswapBytes = false; + rowSize = newWidth * groupSize; + imageSize = rowSize * newHeight; + memReq = Mipmap.imageSize3D( newWidth, newHeight, newDepth, format, type ); + // swap srcImage and dstImage + tempImage = srcImage; + srcImage = dstImage; + dstImage = tempImage; + try { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + case( GL2.GL_BYTE ): + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_INT ): + case( GL2.GL_FLOAT ): + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + dstImage = Buffers.newDirectByteBuffer( memReq ); + break; + default: + return( GLU.GLU_INVALID_ENUM ); + } + } catch( OutOfMemoryError err ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, psm.getUnpackSwapBytes() ? 1 : 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_IMAGES, psm.getUnpackSkipImages() ); + gl.glPixelStorei( GL2.GL_UNPACK_IMAGE_HEIGHT, psm.getUnpackImageHeight() ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + + // level userLevel + 1 is in srcImage; level userLevel already saved + level = userLevel + 1; + } else { + memReq = Mipmap.imageSize3D( newWidth, newHeight, newDepth, format, type ); + try { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + case( GL2.GL_BYTE ): + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_INT ): + case( GL2.GL_FLOAT ): + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + dstImage = Buffers.newDirectByteBuffer( memReq ); + break; + default: + return( GLU.GLU_INVALID_ENUM ); + } + } catch( OutOfMemoryError err ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, psm.getUnpackSwapBytes() ? 1 : 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_IMAGES, psm.getUnpackSkipImages() ); + gl.glPixelStorei( GL2.GL_UNPACK_IMAGE_HEIGHT, psm.getUnpackImageHeight() ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + + ScaleInternal.gluScaleImage3D( gl, format, width, height, depth, type, + usersImage, newWidth, newHeight, newDepth, type, dstImage ); + + myswapBytes = false; + rowSize = newWidth * groupSize; + imageSize = rowSize * newHeight; + // swap dstImage and srcImage + tempImage = srcImage; + srcImage = dstImage; + dstImage = tempImage; + + if( levels != 0 ) { + int nextWidth = newWidth / 2; + int nextHeight = newHeight / 2; + int nextDepth = newDepth / 2; + if( nextWidth < 1 ) { + nextWidth = 1; + } + if( nextHeight < 1 ) { + nextHeight = 1; + } + if( nextDepth < 1 ) { + nextDepth = 1; + } + memReq = Mipmap.imageSize3D( nextWidth, nextHeight, nextDepth, format, type ); + try { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + case( GL2.GL_BYTE ): + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_INT ): + case( GL2.GL_FLOAT ): + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + dstImage = Buffers.newDirectByteBuffer( memReq ); + break; + default: + return( GLU.GLU_INVALID_ENUM ); + } + } catch( OutOfMemoryError err ) { + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, psm.getUnpackSwapBytes() ? 1 : 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_IMAGES, psm.getUnpackSkipImages() ); + gl.glPixelStorei( GL2.GL_UNPACK_IMAGE_HEIGHT, psm.getUnpackImageHeight() ); + return( GLU.GLU_OUT_OF_MEMORY ); + } + } + // level userLevel is in srcImage; nothing saved yet + level = userLevel; + } + + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, GL2.GL_FALSE ); + if( baseLevel <= level && level <= maxLevel ) { + usersImage.position( mark ); + gl.getGL2().glTexImage3D( target, level, internalFormat, width, height, depth, + 0, format, type, usersImage ); + } + level++; + for( ; level <= levels; level++ ) { + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractUByte(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_ubyte( cmpts, width, height, usersImage, + dstImage, elementSize, rowSize, groupSize ); + } + break; + case( GL2.GL_BYTE ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractSByte(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_byte( cmpts, width, height, usersImage, + dstImage, elementSize, rowSize, groupSize ); + } + break; + case( GL2.GL_UNSIGNED_SHORT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractUShort(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_ushort( cmpts, width, height, usersImage, + dstImage.asShortBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_SHORT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractSShort(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_short( cmpts, width, height, usersImage, + dstImage.asShortBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_UNSIGNED_INT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractUInt(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_uint( cmpts, width, height, usersImage, + dstImage.asIntBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_INT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractSInt(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_int( cmpts, width, height, usersImage, + dstImage.asIntBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_FLOAT ): + if( depth > 1 ) { + HalveImage.halveImage3D( cmpts, new ExtractFloat(), width, height, depth, + usersImage, dstImage, elementSize, groupSize, rowSize, + imageSize, myswapBytes ); + } else { + HalveImage.halveImage_float( cmpts, width, height, usersImage, + dstImage.asFloatBuffer(), elementSize, rowSize, groupSize, myswapBytes ); + } + break; + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + HalveImage.halveImagePackedPixel3D( 3, new Extract332(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + HalveImage.halveImagePackedPixel3D( 3, new Extract233rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + HalveImage.halveImagePackedPixel3D( 3, new Extract565(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + HalveImage.halveImagePackedPixel3D( 3, new Extract565rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + HalveImage.halveImagePackedPixel3D( 4, new Extract4444(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + HalveImage.halveImagePackedPixel3D( 4, new Extract4444rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + HalveImage.halveImagePackedPixel3D( 4, new Extract5551(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + HalveImage.halveImagePackedPixel3D( 4, new Extract1555rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + HalveImage.halveImagePackedPixel3D( 4, new Extract8888(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + HalveImage.halveImagePackedPixel3D( 4, new Extract8888rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + HalveImage.halveImagePackedPixel3D( 4, new Extract1010102(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + HalveImage.halveImagePackedPixel3D( 4, new Extract2101010rev(), width, height, depth, usersImage, + dstImage, elementSize, rowSize, imageSize, myswapBytes ); + break; + default: + assert( false ); + break; + } + + tempImage = srcImage; + srcImage = dstImage; + dstImage = tempImage; + + if( newWidth > 1 ) { + newWidth /= 2; + rowSize /= 2; + } + if( newHeight > 1 ) { + newHeight /= 2; + imageSize = rowSize * newHeight; + } + if( newDepth > 1 ) { + newDepth /= 2; + } + if( baseLevel <= level && level <= maxLevel ) { + usersImage.position( mark ); + gl.getGL2().glTexImage3D( target, level, internalFormat, width, height, depth, + 0, format, type, usersImage ); + } + } + gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, psm.getUnpackSkipPixels() ); + gl.glPixelStorei( GL2.GL_UNPACK_ROW_LENGTH, psm.getUnpackRowLength() ); + gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, psm.getUnpackSwapBytes() ? 1 : 0 ); + gl.glPixelStorei( GL2.GL_UNPACK_SKIP_IMAGES, psm.getUnpackSkipImages() ); + gl.glPixelStorei( GL2.GL_UNPACK_IMAGE_HEIGHT, psm.getUnpackImageHeight() ); + return( 0 ); + } + + private static final int TARGA_HEADER_SIZE = 18; + private static void writeTargaFile(String filename, ByteBuffer data, + int width, int height) { + try { + FileOutputStream fos = new FileOutputStream(new File(filename)); + ByteBuffer header = ByteBuffer.allocateDirect(TARGA_HEADER_SIZE); + header.put(0, (byte) 0).put(1, (byte) 0); + header.put(2, (byte) 2); // uncompressed type + header.put(12, (byte) (width & 0xFF)); // width + header.put(13, (byte) (width >> 8)); // width + header.put(14, (byte) (height & 0xFF)); // height + header.put(15, (byte) (height >> 8)); // height + header.put(16, (byte) 24); // pixel size + fos.write(header.array()); + fos.write(data.array()); + data.clear(); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract.java new file mode 100644 index 000000000..a564269fb --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract.java @@ -0,0 +1,56 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.ByteBuffer; + +/** + * + * @author Administrator + */ +public interface Extract { + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ); + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ); +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract1010102.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract1010102.java new file mode 100644 index 000000000..10ea1d729 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract1010102.java @@ -0,0 +1,97 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.ByteBuffer; + +/** + * + * @author Administrator + */ +public class Extract1010102 implements Extract { + + /** Creates a new instance of Extract1010102 */ + public Extract1010102() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + long uint = 0; + + if( isSwap ) { + uint = 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( packedPixel.getInt() ); + } else { + uint = 0x00000000FFFFFFFF & packedPixel.getInt(); + } + + // 11111111,11000000,00000000,00000000 == 0xFFC00000 + // 00000000,00111111,11110000,00000000 == 0x003F0000 + // 00000000,00000000,00001111,11111100 == 0x00000FFC + // 00000000,00000000,00000000,00000011 == 0x00000003 + + extractComponents[0] = (float)( ( uint & 0xFFC00000 ) >> 22 ) / 1023.0f; + extractComponents[1] = (float)( ( uint & 0x003FF000 ) >> 12 ) / 1023.0f; + extractComponents[2] = (float)( ( uint & 0x00000FFC ) >> 2 ) / 1023.0f; + extractComponents[3] = (float)( ( uint & 0x00000003 ) ) / 3.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11110000,00000000 == 0xF000 + // 00001111,00000000 == 0x0F00 + // 00000000,11110000 == 0x00F0 + // 00000000,00001111 == 0x000F + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + assert( 0.0f <= shoveComponents[3] && shoveComponents[3] <= 1.0f ); + + // due to limited precision, need to round before shoving + long uint = (((int)((shoveComponents[0] * 1023) + 0.5f) << 22) & 0xFFC00000 ); + uint |= (((int)((shoveComponents[1] * 1023) + 0.5f) << 12) & 0x003FF000 ); + uint |= (((int)((shoveComponents[2] * 1023) + 0.5f) << 2) & 0x00000FFC ); + uint |= (((int)((shoveComponents[3] * 3) + 0.5f) ) & 0x00000003 ); + packedPixel.asIntBuffer().put( index, (int)uint ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract1555rev.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract1555rev.java new file mode 100644 index 000000000..1234da5f8 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract1555rev.java @@ -0,0 +1,97 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.ByteBuffer; + +/** + * + * @author Administrator + */ +public class Extract1555rev implements Extract { + + /** Creates a new instance of Extract1555rev */ + public Extract1555rev() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + int ushort = 0; + + if( isSwap ) { + ushort = 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( packedPixel.getShort() ); + } else { + ushort = 0x0000FFFF & packedPixel.getShort(); + } + + // 00000000,00011111 == 0x001F + // 00000011,11100000 == 0x03E0 + // 01111100,00000000 == 0x7C00 + // 10000000,00000000 == 0x8000 + + extractComponents[0] = (float)( ( ushort & 0x001F ) ) / 31.0f; + extractComponents[1] = (float)( ( ushort & 0x003E ) >> 5 ) / 31.0f; + extractComponents[2] = (float)( ( ushort & 0x7C00 ) >> 10) / 31.0f; + extractComponents[3] = (float)( ( ushort & 0x8000 ) >> 15); + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 00000000,00011111 == 0x001F + // 00000011,11100000 == 0x03E0 + // 01111100,00000000 == 0x7C00 + // 10000000,00000000 == 0x8000 + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + assert( 0.0f <= shoveComponents[3] && shoveComponents[3] <= 1.0f ); + + // due to limited precision, need to round before shoving + int ushort = (((int)((shoveComponents[0] * 31) + 0.5f) ) & 0x0000001F ); + ushort |= (((int)((shoveComponents[1] * 31) + 0.5f) << 5) & 0x000003E0 ); + ushort |= (((int)((shoveComponents[2] * 31) + 0.5f) << 10) & 0x00007C00 ); + ushort |= (((int)((shoveComponents[3]) + 0.5f) << 15) & 0x00008000 ); + packedPixel.asShortBuffer().put( index, (short)ushort ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract2101010rev.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract2101010rev.java new file mode 100644 index 000000000..226254f99 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract2101010rev.java @@ -0,0 +1,97 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.ByteBuffer; + +/** + * + * @author Administrator + */ +public class Extract2101010rev implements Extract { + + /** Creates a new instance of Extract2101010 */ + public Extract2101010rev() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + long uint = 0; + + if( isSwap ) { + uint = 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( packedPixel.getInt() ); + } else { + uint = 0x00000000FFFFFFFF & packedPixel.getInt(); + } + + // 11111111,11000000,00000000,00000000 == 0xFFC00000 + // 00000000,00111111,11110000,00000000 == 0x003F0000 + // 00000000,00000000,00001111,11111100 == 0x00000FFC + // 00000000,00000000,00000000,00000011 == 0x00000003 + + extractComponents[0] = (float)( ( uint & 0x000003FF ) ) / 1023.0f; + extractComponents[1] = (float)( ( uint & 0x000FFC00 ) >> 10 ) / 1023.0f; + extractComponents[2] = (float)( ( uint & 0x3FF00000 ) >> 20 ) / 1023.0f; + extractComponents[3] = (float)( ( uint & 0xC0000000 ) >> 30 ) / 3.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11110000,00000000 == 0xF000 + // 00001111,00000000 == 0x0F00 + // 00000000,11110000 == 0x00F0 + // 00000000,00001111 == 0x000F + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + assert( 0.0f <= shoveComponents[3] && shoveComponents[3] <= 1.0f ); + + // due to limited precision, need to round before shoving + long uint = (((int)((shoveComponents[0] * 1023) + 0.5f) ) & 0x000003FF ); + uint |= (((int)((shoveComponents[1] * 1023) + 0.5f) << 10) & 0x000FFC00 ); + uint |= (((int)((shoveComponents[2] * 1023) + 0.5f) << 20) & 0x3FF00000 ); + uint |= (((int)((shoveComponents[3] * 3) + 0.5f) << 30) & 0xC0000000 ); + packedPixel.asIntBuffer().put( index, (int)uint ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract233rev.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract233rev.java new file mode 100644 index 000000000..9fa2a3a54 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract233rev.java @@ -0,0 +1,85 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.ByteBuffer; + +/** + * + * @author Administrator + */ +public class Extract233rev implements Extract { + + /** Creates a new instance of Extract223rev */ + public Extract233rev() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + // 11100000 == 0xe0 + // 00011100 == 0x1c + // 00000011 == 0x03 + byte ubyte = packedPixel.get(); + extractComponents[0] = (float)((ubyte & 0x07) ) / 7.0f; + extractComponents[1] = (float)((ubyte & 0x38) >> 3) / 7.0f; + extractComponents[2] = (float)((ubyte & 0xC0) >> 6) / 3.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11100000 == 0xE0 + // 00011100 == 0x1C + // 00000011 == 0x03 + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + + // due to limited precision, need to round before shoving + byte b = (byte)( ( (int)( ( shoveComponents[0] * 7 ) + 0.5f ) ) & 0x07 ); + b |= (byte)( ( (int)( ( shoveComponents[1] * 7 ) + 0.5f ) << 3 ) & 0x38 ); + b |= (byte)( ( (int)( ( shoveComponents[2] * 3 ) + 0.5f ) << 6 ) & 0xC0 ); + packedPixel.position( index ); + packedPixel.put( b ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract332.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract332.java new file mode 100644 index 000000000..92d141be5 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract332.java @@ -0,0 +1,84 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.ByteBuffer; + +/** + * + * @author Administrator + */ +public class Extract332 implements Extract { + + /** Creates a new instance of Extract332 */ + public Extract332() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + // 11100000 == 0xe0 + // 00011100 == 0x1c + // 00000011 == 0x03 + byte ubyte = packedPixel.get(); + extractComponents[0] = (float)((ubyte & 0xe0) >> 5) / 7.0f; + extractComponents[1] = (float)((ubyte & 0x1c) >> 2) / 7.0f; + extractComponents[2] = (float)((ubyte & 0x03)) / 3.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11100000 == 0xE0 + // 00011100 == 0x1C + // 00000011 == 0x03 + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + + // due to limited precision, need to round before shoving + byte b = (byte)( ( (int)( ( shoveComponents[0] * 7 ) + 0.5f ) << 5 ) & 0xE0 ); + b |= (byte)( ( (int)( ( shoveComponents[1] * 7 ) + 0.5f ) << 2 ) & 0x1C ); + b |= (byte)( ( (int)( ( shoveComponents[2] * 3 ) + 0.5f ) ) & 0x03 ); + packedPixel.put( index, b ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract4444.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract4444.java new file mode 100644 index 000000000..af99d154c --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract4444.java @@ -0,0 +1,96 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class Extract4444 implements Extract { + + /** Creates a new instance of Extract4444 */ + public Extract4444() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + int ushort = 0; + + if( isSwap ) { + ushort = 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( packedPixel.getShort() ); + } else { + ushort = 0x0000FFFF & packedPixel.getShort(); + } + + // 11110000,00000000 == 0xF000 + // 00001111,00000000 == 0x0F00 + // 00000000,11110000 == 0x00F0 + // 00000000,00001111 == 0x000F + + extractComponents[0] = (float)( ( ushort & 0xF000 ) >> 12 ) / 15.0f; + extractComponents[1] = (float)( ( ushort & 0x0F00 ) >> 8 ) / 15.0f; + extractComponents[2] = (float)( ( ushort & 0x00F0 ) >> 4 ) / 15.0f; + extractComponents[3] = (float)( ( ushort & 0x000F ) ) / 15.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11110000,00000000 == 0xF000 + // 00001111,00000000 == 0x0F00 + // 00000000,11110000 == 0x00F0 + // 00000000,00001111 == 0x000F + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + + // due to limited precision, need to round before shoving + int ushort = (((int)((shoveComponents[0] * 15) + 0.5f) << 12) & 0x0000F000 ); + ushort |= (((int)((shoveComponents[1] * 15) + 0.5f) << 8) & 0x00000F00 ); + ushort |= (((int)((shoveComponents[2] * 15) + 0.5f) << 4) & 0x000000F0 ); + ushort |= (((int)((shoveComponents[3] * 15) + 0.5f) ) & 0x0000000F ); + packedPixel.asShortBuffer().put( index, (short)ushort ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract4444rev.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract4444rev.java new file mode 100644 index 000000000..e5bce60d8 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract4444rev.java @@ -0,0 +1,97 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class Extract4444rev implements Extract { + + /** Creates a new instance of Extract4444rev */ + public Extract4444rev() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + int ushort = 0; + + if( isSwap ) { + ushort = 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( packedPixel.getShort() ); + } else { + ushort = 0x0000FFFF & packedPixel.getShort(); + } + + // 00000000,00001111 == 0x000F + // 00000000,11110000 == 0x00F0 + // 00001111,00000000 == 0x0F00 + // 11110000,00000000 == 0xF000 + + extractComponents[0] = (float)( ( ushort & 0x000F ) ) / 15.0f; + extractComponents[1] = (float)( ( ushort & 0x00F0 ) >> 4 ) / 15.0f; + extractComponents[2] = (float)( ( ushort & 0x0F00 ) >> 8 ) / 15.0f; + extractComponents[3] = (float)( ( ushort & 0xF000 ) >> 12 ) / 15.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11110000,00000000 == 0xF000 + // 00001111,00000000 == 0x0F00 + // 00000000,11110000 == 0x00F0 + // 00000000,00001111 == 0x000F + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + assert( 0.0f <= shoveComponents[3] && shoveComponents[3] <= 1.0f ); + + // due to limited precision, need to round before shoving + int ushort = (((int)((shoveComponents[0] * 15) + 0.5f) ) & 0x0000000F ); + ushort |= (((int)((shoveComponents[1] * 15) + 0.5f) << 4) & 0x000000F0 ); + ushort |= (((int)((shoveComponents[2] * 15) + 0.5f) << 8) & 0x00000F00 ); + ushort |= (((int)((shoveComponents[3] * 15) + 0.5f) << 12) & 0x0000F000 ); + packedPixel.asShortBuffer().put( index, (short)ushort ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract5551.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract5551.java new file mode 100644 index 000000000..5c383103e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract5551.java @@ -0,0 +1,97 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class Extract5551 implements Extract { + + /** Creates a new instance of Extract5551 */ + public Extract5551() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + int ushort = 0; + + if( isSwap ) { + ushort = 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( packedPixel.getShort() ); + } else { + ushort = 0x0000FFFF & packedPixel.getShort(); + } + + // 11111000,00000000 == 0xF800 + // 00000111,11000000 == 0x07C0 + // 00000000,00111110 == 0x003E + // 00000000,00000001 == 0x0001 + + extractComponents[0] = (float)( ( ushort & 0xF800 ) >> 11 ) / 31.0f; + extractComponents[1] = (float)( ( ushort & 0x00F0 ) >> 6 ) / 31.0f; + extractComponents[2] = (float)( ( ushort & 0x0F00 ) >> 1 ) / 31.0f; + extractComponents[3] = (float)( ( ushort & 0xF000 ) ); + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11110000,00000000 == 0xF000 + // 00001111,00000000 == 0x0F00 + // 00000000,11110000 == 0x00F0 + // 00000000,00001111 == 0x000F + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + assert( 0.0f <= shoveComponents[3] && shoveComponents[3] <= 1.0f ); + + // due to limited precision, need to round before shoving + int ushort = (((int)((shoveComponents[0] * 31) + 0.5f) << 11) & 0x0000F800 ); + ushort |= (((int)((shoveComponents[1] * 31) + 0.5f) << 6) & 0x000007C0 ); + ushort |= (((int)((shoveComponents[2] * 31) + 0.5f) << 1) & 0x0000003E ); + ushort |= (((int)((shoveComponents[3]) + 0.5f)) & 0x00000001 ); + packedPixel.asShortBuffer().put( index, (short)ushort ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract565.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract565.java new file mode 100644 index 000000000..f6193dd2d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract565.java @@ -0,0 +1,92 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class Extract565 implements Extract { + + /** Creates a new instance of Extract565 */ + public Extract565() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + int ushort = 0; + + if( isSwap ) { + ushort = 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( packedPixel.getShort() ); + } else { + ushort = 0x0000FFFF & packedPixel.getShort(); + } + + // 11111000,00000000 == 0xF800 + // 00000111,11100000 == 0x07E0 + // 00000000,00111111 == 0x001F + + extractComponents[0] = (float)( ( ushort & 0xF800 ) >> 11 ) / 31.0f; + extractComponents[1] = (float)( ( ushort & 0x07E0 ) >> 5 ) / 63.0f; + extractComponents[2] = (float)( ( ushort & 0x001F ) ) / 31.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11111000,00000000 == 0xF800 + // 00000111,11100000 == 0x07E0 + // 00000000,00111111 == 0x001F + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + + // due to limited precision, need to round before shoving + int ushort = (((int)((shoveComponents[0] * 31) + 0.5f) << 11) & 0x0000F800 ); + ushort |= (((int)((shoveComponents[1] * 63) + 0.5f) << 5) & 0x000007E0 ); + ushort |= (((int)((shoveComponents[2] * 31) + 0.5f) ) & 0x0000001F ); + packedPixel.asShortBuffer().put( index, (short)ushort ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract565rev.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract565rev.java new file mode 100644 index 000000000..2e455adfa --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract565rev.java @@ -0,0 +1,92 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class Extract565rev implements Extract { + + /** Creates a new instance of Extract565rev */ + public Extract565rev() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + int ushort = 0; + + if( isSwap ) { + ushort = 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( packedPixel.getShort() ); + } else { + ushort = 0x0000FFFF & packedPixel.getShort(); + } + + // 00000000,00011111 == 0x001F + // 00000111,11100000 == 0x07E0 + // 11111000,00000000 == 0xF800 + + extractComponents[0] = (float)( ( ushort & 0x001F ) ) / 31.0f; + extractComponents[1] = (float)( ( ushort & 0x07E0 ) >> 5 ) / 63.0f; + extractComponents[2] = (float)( ( ushort & 0xF800 ) >> 11 ) / 31.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 00000000,00111111 == 0x001F + // 00000111,11100000 == 0x07E0 + // 11111000,00000000 == 0xF800 + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + + // due to limited precision, need to round before shoving + int ushort = (((int)((shoveComponents[0] * 31) + 0.5f) ) & 0x0000001F ); + ushort |= (((int)((shoveComponents[1] * 63) + 0.5f) << 5) & 0x000007E0 ); + ushort |= (((int)((shoveComponents[2] * 31) + 0.5f) << 11) & 0x0000F800 ); + packedPixel.asShortBuffer().put( index, (short)ushort ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract8888.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract8888.java new file mode 100644 index 000000000..137fa3c21 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract8888.java @@ -0,0 +1,97 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class Extract8888 implements Extract { + + /** Creates a new instance of Extract8888 */ + public Extract8888() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + long uint = 0; + + if( isSwap ) { + uint = 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( packedPixel.getInt() ); + } else { + uint = 0x00000000FFFFFFFF & packedPixel.getInt(); + } + + // 11111000,00000000 == 0xF800 + // 00000111,11000000 == 0x07C0 + // 00000000,00111110 == 0x003E + // 00000000,00000001 == 0x0001 + + extractComponents[0] = (float)( ( uint & 0xFF000000 ) >> 24 ) / 255.0f; + extractComponents[1] = (float)( ( uint & 0x00FF0000 ) >> 16 ) / 255.0f; + extractComponents[2] = (float)( ( uint & 0x0000FF00 ) >> 8 ) / 255.0f; + extractComponents[3] = (float)( ( uint & 0x000000FF ) ) / 255.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11110000,00000000 == 0xF000 + // 00001111,00000000 == 0x0F00 + // 00000000,11110000 == 0x00F0 + // 00000000,00001111 == 0x000F + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + assert( 0.0f <= shoveComponents[3] && shoveComponents[3] <= 1.0f ); + + // due to limited precision, need to round before shoving + long uint = (((int)((shoveComponents[0] * 255) + 0.5f) << 24) & 0xFF000000 ); + uint |= (((int)((shoveComponents[1] * 255) + 0.5f) << 16) & 0x00FF0000 ); + uint |= (((int)((shoveComponents[2] * 255) + 0.5f) << 8) & 0x0000FF00 ); + uint |= (((int)((shoveComponents[3] * 255) + 0.5f) ) & 0x000000FF ); + packedPixel.asIntBuffer().put( index, (int)uint ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract8888rev.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract8888rev.java new file mode 100644 index 000000000..2ac942c84 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Extract8888rev.java @@ -0,0 +1,97 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class Extract8888rev implements Extract { + + /** Creates a new instance of Extract8888rev */ + public Extract8888rev() { + } + + public void extract( boolean isSwap, ByteBuffer packedPixel, float[] extractComponents ) { + long uint = 0; + + if( isSwap ) { + uint = 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( packedPixel.getInt() ); + } else { + uint = 0x00000000FFFFFFFF & packedPixel.getInt(); + } + + // 11111000,00000000 == 0xF800 + // 00000111,11000000 == 0x07C0 + // 00000000,00111110 == 0x003E + // 00000000,00000001 == 0x0001 + + extractComponents[0] = (float)( ( uint & 0x000000FF ) ) / 255.0f; + extractComponents[1] = (float)( ( uint & 0x0000FF00 ) >> 8 ) / 255.0f; + extractComponents[2] = (float)( ( uint & 0x00FF0000 ) >> 16 ) / 255.0f; + extractComponents[3] = (float)( ( uint & 0xFF000000 ) >> 24 ) / 255.0f; + } + + public void shove( float[] shoveComponents, int index, ByteBuffer packedPixel ) { + // 11110000,00000000 == 0xF000 + // 00001111,00000000 == 0x0F00 + // 00000000,11110000 == 0x00F0 + // 00000000,00001111 == 0x000F + + assert( 0.0f <= shoveComponents[0] && shoveComponents[0] <= 1.0f ); + assert( 0.0f <= shoveComponents[1] && shoveComponents[1] <= 1.0f ); + assert( 0.0f <= shoveComponents[2] && shoveComponents[2] <= 1.0f ); + assert( 0.0f <= shoveComponents[3] && shoveComponents[3] <= 1.0f ); + + // due to limited precision, need to round before shoving + long uint = (((int)((shoveComponents[0] * 255) + 0.5f) ) & 0x000000FF ); + uint |= (((int)((shoveComponents[1] * 255) + 0.5f) << 8) & 0x0000FF00 ); + uint |= (((int)((shoveComponents[2] * 255) + 0.5f) << 16) & 0x00FF0000 ); + uint |= (((int)((shoveComponents[3] * 255) + 0.5f) << 24) & 0xFF000000 ); + packedPixel.asIntBuffer().put( index, (int)uint ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractFloat.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractFloat.java new file mode 100644 index 000000000..52c2191b9 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractFloat.java @@ -0,0 +1,74 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class ExtractFloat implements ExtractPrimitive { + + /** Creates a new instance of ExtractFloat */ + public ExtractFloat() { + } + + public double extract( boolean isSwap, ByteBuffer data ) { + float f = 0; + if( isSwap ) { + f = Mipmap.GLU_SWAP_4_BYTES( data.getInt() ); + } else { + f = data.getInt(); + } + assert( f <= 1.0f ); + return( f ); + } + + public void shove( double value, int index, ByteBuffer data ) { + assert(0.0 <= value && value < 1.0); + data.asFloatBuffer().put( index, (float)value ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractPrimitive.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractPrimitive.java new file mode 100644 index 000000000..926096649 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractPrimitive.java @@ -0,0 +1,56 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.ByteBuffer; + +/** + * + * @author Administrator + */ +public interface ExtractPrimitive { + public double extract( boolean isSwap, ByteBuffer pointer ); + public void shove( double value, int index, ByteBuffer pointer ); +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractSByte.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractSByte.java new file mode 100644 index 000000000..2e1a9a0a6 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractSByte.java @@ -0,0 +1,69 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.ByteBuffer; + +/** + * + * @author Administrator + */ +public class ExtractSByte implements ExtractPrimitive { + + /** Creates a new instance of ExtractUByte */ + public ExtractSByte() { + } + + public double extract( boolean isSwap, ByteBuffer sbyte ) { + byte b = sbyte.get(); + assert( b <= 127 ); + return( b ); + } + + public void shove( double value, int index, ByteBuffer data ) { + data.position( index ); + data.put( (byte)value ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractSInt.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractSInt.java new file mode 100644 index 000000000..ca80747c4 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractSInt.java @@ -0,0 +1,76 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class ExtractSInt implements ExtractPrimitive { + + /** Creates a new instance of ExtractSInt */ + public ExtractSInt() { + } + + public double extract( boolean isSwap, ByteBuffer uint ) { + int i = 0; + if( isSwap ) { + i = Mipmap.GLU_SWAP_4_BYTES( uint.getInt() ); + } else { + i = uint.getInt(); + } + assert( i <= 0x7FFFFFFF ); + return( i ); + } + + public void shove( double value, int index, ByteBuffer data ) { + assert(0.0 <= value && value < Integer.MAX_VALUE); + IntBuffer ib = data.asIntBuffer(); + ib.position( index ); + ib.put( (int)value ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractSShort.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractSShort.java new file mode 100644 index 000000000..979c3b449 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractSShort.java @@ -0,0 +1,76 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class ExtractSShort implements ExtractPrimitive { + + /** Creates a new instance of ExtractSShort */ + public ExtractSShort() { + } + + public double extract( boolean isSwap, ByteBuffer ushort ) { + short s = 0; + if( isSwap ) { + s = Mipmap.GLU_SWAP_2_BYTES( ushort.getShort() ); + } else { + s = ushort.getShort(); + } + assert( s <= 32767 ); + return( s ); + } + + public void shove( double value, int index, ByteBuffer data ) { + assert(0.0 <= value && value < 32768.0); + ShortBuffer sb = data.asShortBuffer(); + sb.position( index ); + sb.put( (short)value ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractUByte.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractUByte.java new file mode 100644 index 000000000..4d14212ab --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractUByte.java @@ -0,0 +1,70 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.ByteBuffer; + +/** + * + * @author Administrator + */ +public class ExtractUByte implements ExtractPrimitive { + + /** Creates a new instance of ExtractUByte */ + public ExtractUByte() { + } + + public double extract( boolean isSwap, ByteBuffer ubyte ) { + int i = 0x000000FF & ubyte.get(); + assert( i <= 255 ); + return( i ); + } + + public void shove( double value, int index, ByteBuffer data ) { + assert(0.0 <= value && value < 256.0); + data.position( index ); + data.put( (byte)value ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractUInt.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractUInt.java new file mode 100644 index 000000000..c088ca301 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractUInt.java @@ -0,0 +1,76 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class ExtractUInt implements ExtractPrimitive { + + /** Creates a new instance of ExtractUInt */ + public ExtractUInt() { + } + + public double extract( boolean isSwap, ByteBuffer uint ) { + long i = 0; + if( isSwap ) { + i = 0xFFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( uint.getInt() ); + } else { + i = 0xFFFFFFFF & uint.getInt(); + } + assert( i <= 0xFFFFFFFF ); + return( i ); + } + + public void shove( double value, int index, ByteBuffer data ) { + assert(0.0 <= value && value < 0xFFFFFFFF); + IntBuffer ib = data.asIntBuffer(); + ib.position( index ); + ib.put( (int)value ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractUShort.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractUShort.java new file mode 100644 index 000000000..81db60f0f --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/ExtractUShort.java @@ -0,0 +1,76 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class ExtractUShort implements ExtractPrimitive { + + /** Creates a new instance of ExtracUShort */ + public ExtractUShort() { + } + + public double extract( boolean isSwap, ByteBuffer ushort ) { + int i = 0; + if( isSwap ) { + i = 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( ushort.getShort() ); + } else { + i = 0x0000FFFF & ushort.getShort(); + } + assert( i <= 65535 ); + return( i ); + } + + public void shove( double value, int index, ByteBuffer data ) { + assert(0.0 <= value && value < 65536.0); + ShortBuffer sb = data.asShortBuffer(); + sb.position( index ); + sb.put( (short)value ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/HalveImage.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/HalveImage.java new file mode 100644 index 000000000..7549044ba --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/HalveImage.java @@ -0,0 +1,1533 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import javax.media.opengl.GL; +import java.nio.*; + +/** + * + * @author Administrator + */ +public class HalveImage { + + private static final int BOX2 = 2; + private static final int BOX4 = 4; + private static final int BOX8 = 8; + + public static void halveImage( int components, int width, int height, + ShortBuffer datain, ShortBuffer dataout ) { + int i, j, k; + int newwidth, newheight; + int delta; + int t = 0; + short temp = 0; + + newwidth = width / 2; + newheight = height /2; + delta = width * components; + + // Piece of cake + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + datain.position( t ); + temp = datain.get(); + datain.position( t + components ); + temp += datain.get(); + datain.position( t + delta ); + temp += datain.get(); + datain.position( t + delta + components ); + temp +=datain.get(); + temp += 2; + temp /= 4; + dataout.put( temp ); + t++; + } + t += components; + } + t += delta; + } + } + + public static void halveImage_ubyte( int components, int width, int height, + ByteBuffer datain, ByteBuffer dataout, + int element_size, int ysize, int group_size ) { + int i, j, k; + int newwidth, newheight; + int s; + int t; + + // Handle case where there is only 1 column/row + if( width == 1 || height == 1 ) { + assert( !( width == 1 && height == 1 ) ); // can't be 1x1 + halve1Dimage_ubyte( components, width, height, datain, dataout, element_size, ysize, group_size ); + return; + } + + newwidth = width / 2; + newheight = height / 2; + s = 0; + t = 0; + + int temp = 0; + // piece of cake + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + datain.position( t ); + temp = ( 0x000000FF & datain.get() ); + datain.position( t + group_size ); + temp += ( 0x000000FF & datain.get() ); + datain.position( t + ysize ); + temp += ( 0x000000FF & datain.get() ); + datain.position( t + ysize + group_size ); + temp += ( 0x000000FF & datain.get() ) + 2; + dataout.put( (byte)(temp / 4) ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } + + public static void halve1Dimage_ubyte( int components, int width, int height, + ByteBuffer datain, ByteBuffer dataout, + int element_size, int ysize, int group_size ) { + int halfWidth = width / 2; + int halfHeight = height / 2; + int src = 0; + int dest = 0; + int jj; + int temp = 0; + + assert( width == 1 || height == 1 ); // Must be 1D + assert( width != height ); // can't be square + + if( height == 1 ) { // 1 row + assert( width != 1 ); // widthxheight can't be 1x1 + halfHeight = 1; + + for( jj = 0; jj < halfWidth; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + datain.position( src ); + temp = ( 0x000000FF & datain.get() ); + datain.position( src + group_size ); + temp += ( 0x000000FF & datain.get() ); + temp /= 2; + dataout.put( (byte)temp ); + /* + dataout.setByte( (byte)(((0x000000FF & datain.setIndexInBytes(src).getByte()) + + (0x000000FF & datain.setIndexInBytes( src + group_size ).getByte())) / 2 ) ); + */ + src += element_size; + //dataout.plusPlus(); + dest++; + } + src += group_size; // skip to next 2 + } + int padBytes = ysize - ( width * group_size ); + src += padBytes; // for assertion only + } else if( width == 1 ) { // 1 column + int padBytes = ysize - ( width * group_size ); + assert( height != 1 ); + halfWidth = 1; + // one vertical column with possible pad bytes per row + // average two at a time + for( jj = 0; jj < halfHeight; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + datain.position( src ); + temp = ( 0x000000FF & datain.get() ); + datain.position( src + ysize ); + temp += ( 0x000000FF & datain.get() ); + temp /= 2; + dataout.put( (byte)temp ); + /* + dataout.setByte( (byte)(((0x000000FF & datain.setIndexInBytes(src).getByte()) + + (0x000000FF & datain.setIndexInBytes(src + ysize).getByte()) ) / 2 ) ); + */ + src += element_size; + //dataout.plusPlus(); + dest++; + } + src += padBytes; // add pad bytes, if any, to get to end of row + src += ysize; + } + } + assert( src == ysize * height ); + assert( dest == components * element_size * halfWidth * halfHeight ); + } + + public static void halveImage_byte( int components, int width, int height, + ByteBuffer datain, ByteBuffer dataout, int element_size, + int ysize, int group_size ) { + int i, j, k; + int newwidth, newheight; + int s = 0; + int t = 0; + byte temp = (byte)0; + + // handle case where there is only 1 column + if( width == 1 || height == 1 ) { + assert( !( width == 1 && height == 1 ) ); + halve1Dimage_byte( components, width, height, datain, dataout, element_size, + ysize, group_size ); + return; + } + + newwidth = width / 2; + newheight = height / 2; + + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + datain.position( t ); + temp = datain.get(); + datain.position( t + group_size ); + temp += datain.get(); + datain.position( t + ysize ); + temp += datain.get(); + datain.position( t + ysize + group_size ); + temp += datain.get(); + temp += 2; + temp /= 4; + dataout.put( temp ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } + + public static void halve1Dimage_byte( int components, int width, int height, + ByteBuffer datain, ByteBuffer dataout, + int element_size, int ysize, int group_size ) { + int halfWidth = width / 2; + int halfHeight = width / 2; + int src = 0; + int dest = 0; + int jj; + byte temp = (byte)0; + + assert( width == 1 || height == 1 ); // must be 1D + assert( width != height ); // can't be square + + if( height == 1 ) { // 1 row + assert( width != 1 ); // widthxheight can't be 1 + halfHeight = 1; + + for( jj = 0; jj < halfWidth; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + datain.position( src ); + temp = datain.get(); + datain.position( src + group_size ); + temp += datain.get(); + temp /= 2; + dataout.put( temp ); + src += element_size; + dest++; + } + src += group_size; // skip to next 2 + } + int padBytes = ysize - ( width * group_size ); + src += padBytes; // for assert only + } else if( width == 1 ) { // 1 column + int padBytes = ysize - ( width * group_size ); + assert( height != 1 ); // widthxheight can't be 1 + halfWidth = 1; + // one vertical column with possible pad bytes per row + // average two at a time + + for( jj = 0; jj < halfHeight; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + datain.position( src ); + temp = datain.get(); + datain.position( src + ysize ); + temp += datain.get(); + temp /= 2; + src += element_size; + dest++; + } + src += padBytes; // add pad bytes, if any, to get to end of row + src += ysize; + } + assert( src == ysize * height ); + } + assert( dest == components * element_size * halfWidth * halfHeight ); + } + + public static void halveImage_ushort( int components, int width, int height, + ByteBuffer datain, ShortBuffer dataout, int element_size, + int ysize, int group_size, boolean myswap_bytes ) { + int i, j, k, l; + int newwidth, newheight; + int s = 0; + int t = 0; + int temp = 0; + // handle case where there is only 1 column/row + if( width == 1 || height == 1 ) { + assert( !( width == 1 && height == 1 ) ); // can't be 1x1 + halve1Dimage_ushort( components, width, height, datain, dataout, element_size, + ysize, group_size, myswap_bytes ); + return; + } + + newwidth = width / 2; + newheight = height / 2; + + // Piece of cake + if( !myswap_bytes ) { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + datain.position( t ); + temp = ( 0x0000FFFF & datain.getShort() ); + datain.position( t + group_size ); + temp += ( 0x0000FFFF & datain.getShort() ); + datain.position( t + ysize ); + temp += ( 0x0000FFFF & datain.getShort() ); + datain.position( t + ysize + group_size ); + temp += ( 0x0000FFFF & datain.getShort() ); + dataout.put( (short)( ( temp + 2 ) / 4 ) ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } else { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + datain.position( t ); + temp = ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ) ); + datain.position( t + group_size ); + temp += ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ) ); + datain.position( t + ysize ); + temp += ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ) ); + datain.position( t + ysize + group_size ); + temp += ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ) ); + dataout.put( (short)( ( temp + 2 ) / 4 ) ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } + } + + public static void halve1Dimage_ushort( int components, int width, int height, + ByteBuffer datain, ShortBuffer dataout, int element_size, + int ysize, int group_size, boolean myswap_bytes ) { + int halfWidth = width / 2; + int halfHeight = height / 2; + int src = 0; + int dest = 0; + int jj; + + assert( width == 1 || height == 1 ); // must be 1D + assert( width != height ); // can't be square + + if( height == 1 ) { // 1 row + assert( width != 1 ); // widthxheight can't be 1 + halfHeight = 1; + + for( jj = 0; jj < halfWidth; jj++ ) { + int kk; + for( kk = 0; kk < halfHeight; kk++ ) { + int[] ushort = new int[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + ushort[0] = ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ) ); + datain.position( src + group_size ); + ushort[1] = (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ) ); + } else { + datain.position( src ); + ushort[0] = (0x0000FFFF & datain.getShort() ); + datain.position( src + group_size ); + ushort[1] = (0x0000FFFF & datain.getShort() ); + } + dataout.put( (short)( (ushort[0] + ushort[1]) / 2 ) ); + src += element_size; + dest += 2; + } + src += group_size; // skip to next 2 + } + int padBytes = ysize - ( width * group_size ); + src += padBytes; // for assertion only + } else if( width == 1 ) { // 1 column + int padBytes = ysize - ( width * group_size ); + assert( height != 1 ); // widthxheight can't be 1 + halfWidth = 1; + // one vertical column with possible pad bytes per row + // average two at a time + + for( jj = 0; jj < halfHeight; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + int[] ushort = new int[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + ushort[0] = ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ) ); + datain.position( src + ysize ); + ushort[0] = ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ) ); + } else { + datain.position( src ); + ushort[0] = ( 0x0000FFFF & datain.getShort() ); + datain.position( src + ysize ); + ushort[1] = ( 0x0000FFFF & datain.getShort() ); + } + dataout.put( (short)((ushort[0] + ushort[1]) / 2) ); + src += element_size; + dest += 2; + } + src += padBytes; // add pad bytes, if any, to get to end of row + src += ysize; + } + assert( src == ysize * height ); + } + assert( dest == components * element_size * halfWidth * halfHeight ); + } + + public static void halveImage_short( int components, int width, int height, + ByteBuffer datain, ShortBuffer dataout, int element_size, + int ysize, int group_size, boolean myswap_bytes ) { + int i, j, k, l; + int newwidth, newheight; + int s = 0; + int t = 0; + short temp = (short)0; + // handle case where there is only 1 column/row + if( width == 1 || height == 1 ) { + assert( !( width == 1 && height == 1 ) ); // can't be 1x1 + halve1Dimage_short( components, width, height, datain, dataout, element_size, + ysize, group_size, myswap_bytes ); + return; + } + + newwidth = width / 2; + newheight = height / 2; + + // Piece of cake + if( !myswap_bytes ) { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + datain.position( t ); + temp = datain.getShort(); + datain.position( t + group_size ); + temp += datain.getShort(); + datain.position( t + ysize ); + temp += datain.getShort(); + datain.position( t + ysize + group_size ); + temp += datain.getShort(); + temp += 2; + temp /= 4; + dataout.put( (short)temp ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } else { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + short b; + int buf; + datain.position( t ); + temp = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + datain.position( t + group_size ); + temp += Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + datain.position( t + ysize ); + temp += Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + datain.position( t + ysize + group_size ); + temp += Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + temp += 2; + temp /= 4; + dataout.put( temp ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } + } + + public static void halve1Dimage_short( int components, int width, int height, + ByteBuffer datain, ShortBuffer dataout, int element_size, int ysize, + int group_size, boolean myswap_bytes ) { + int halfWidth = width / 2; + int halfHeight = height / 2; + int src = 0; + int dest = 0; + int jj; + + assert( width == 1 || height == 1 ); // must be 1D + assert( width != height ); // can't be square + + if( height == 1 ) { // 1 row + assert( width != 1 ); // can't be 1x1 + halfHeight = 1; + + for( jj = 0; jj < halfWidth; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + short[] sshort = new short[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + sshort[0] = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + datain.position( src + group_size ); + sshort[1] = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + } else { + datain.position( src ); + sshort[0] = datain.getShort(); + datain.position( src + group_size ); + sshort[1] = datain.getShort(); + } + dataout.put( (short)(( sshort[0] + sshort[1] ) / 2) ); + src += element_size; + dest += 2; + } + src += group_size; // skip to next 2 + } + int padBytes = ysize - ( width * group_size ); + src += padBytes; // for assertion only + } else if( width == 1 ) { + int padBytes = ysize - ( width * group_size ); + assert( height != 1 ); + halfWidth = 1; + // one vertical column with possible pad bytes per row + // average two at a time + + for( jj = 0; jj < halfHeight; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + short[] sshort = new short[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + sshort[0] = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + datain.position( src + ysize ); + sshort[1] = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + } else { + datain.position( src ); + sshort[0] = datain.getShort(); + datain.position( src + ysize ); + sshort[1] = datain.getShort(); + } + dataout.put( (short)(( sshort[0] + sshort[1] ) / 2) ); + src += element_size; + dest += 2; + } + src += padBytes; // add pad bytes, if any, to get to end of row + src += ysize; + } + assert( src == ysize * height ); + } + assert( dest == ( components * element_size * halfWidth * halfHeight ) ); + } + + public static void halveImage_uint( int components, int width, int height, + ByteBuffer datain, IntBuffer dataout, int element_size, + int ysize, int group_size, boolean myswap_bytes ) { + int i, j, k, l; + int newwidth, newheight; + int s = 0; + int t = 0; + double temp = 0; + + // handle case where there is only 1 column/row + if( width == 1 || height == 1 ) { + assert( !( width == 1 && height == 1 ) ); // can't be 1x1 + halve1Dimage_uint( components, width, height, datain, dataout, element_size, + ysize, group_size, myswap_bytes ); + return; + } + + newwidth = width / 2; + newheight = height / 2; + + // Piece of cake + if( !myswap_bytes ) { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + datain.position( t ); + temp = (0x000000007FFFFFFFL & datain.getInt() ); + datain.position( t + group_size ); + temp += (0x000000007FFFFFFFL & datain.getInt() ); + datain.position( t + ysize ); + temp += (0x000000007FFFFFFFL & datain.getInt() ); + datain.position( t + ysize + group_size ); + temp += (0x000000007FFFFFFFL & datain.getInt() ); + dataout.put( (int)( ( temp / 4 ) + 0.5 ) ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } else { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + // need to cast to double to hold large unsigned ints + double buf; + datain.position( t ); + buf = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + datain.position( t + group_size ); + buf += ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + datain.position( t + ysize ); + buf += ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + datain.position( t + ysize + group_size ); + buf += ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + temp /= 4; + temp += 0.5; + dataout.put( (int)temp ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } + } + + public static void halve1Dimage_uint( int components, int width, int height, + ByteBuffer datain, IntBuffer dataout, int element_size, int ysize, + int group_size, boolean myswap_bytes ) { + int halfWidth = width / 2; + int halfHeight = height / 2; + int src = 0; + int dest = 0; + int jj; + + assert( width == 1 || height == 1 ); // must be 1D + assert( width != height ); // can't be square + + if( height == 1 ) { // 1 row + assert( width != 1 ); // widthxheight can't be 1 + halfHeight = 1; + + for( jj = 0; jj < halfWidth; jj++ ) { + int kk; + for( kk = 0; kk < halfHeight; kk++ ) { + long[] uint = new long[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + uint[0] = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + datain.position( src + group_size ); + uint[1] = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + } else { + datain.position( src ); + uint[0] = ( 0x00000000FFFFFFFF & datain.getInt() ); + datain.position( src + group_size ); + uint[1] = (0x00000000FFFFFFFF & datain.getInt() ); + } + dataout.put( (int)( ( uint[0] + uint[1] ) / 2.0 ) ); + src += element_size; + dest += 4; + } + src += group_size; // skip to next 2 + } + int padBytes = ysize - ( width * group_size ); + src += padBytes; // for assertion only + } else if( width == 1 ) { // 1 column + int padBytes = ysize - ( width * group_size ); + assert( height != 1 ); // widthxheight can't be 1 + halfWidth = 1; + // one vertical column with possible pad bytes per row + // average two at a time + + for( jj = 0; jj < halfHeight; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + long[] uint = new long[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + uint[0] = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + datain.position( src + group_size ); + uint[0] = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + } else { + datain.position( src ); + uint[0] = ( 0x00000000FFFFFFFF & datain.getInt() ); + datain.position( src + ysize ); + uint[1] = ( 0x00000000FFFFFFFF & datain.getInt() ); + } + dataout.put( (int)( ( uint[0] + uint[1] ) / 2.0 ) ); + src += element_size; + dest += 4; + } + src += padBytes; // add pad bytes, if any, to get to end of row + src += ysize; + } + assert( src == ysize * height ); + } + assert( dest == components * element_size * halfWidth * halfHeight ); + } + + public static void halveImage_int( int components, int width, int height, + ByteBuffer datain, IntBuffer dataout, int element_size, + int ysize, int group_size, boolean myswap_bytes ) { + int i, j, k, l; + int newwidth, newheight; + int s = 0; + int t = 0; + int temp = 0; + + // handle case where there is only 1 column/row + if( width == 1 || height == 1 ) { + assert( !( width == 1 && height == 1 ) ); // can't be 1x1 + halve1Dimage_int( components, width, height, datain, dataout, element_size, + ysize, group_size, myswap_bytes ); + return; + } + + newwidth = width / 2; + newheight = height / 2; + + // Piece of cake + if( !myswap_bytes ) { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + datain.position( t ); + temp = datain.getInt(); + datain.position( t + group_size ); + temp += datain.getInt(); + datain.position( t + ysize ); + temp += datain.getInt(); + datain.position( t + ysize + group_size ); + temp += datain.getInt(); + temp = (int)( ( temp / 4.0f ) + 0.5f ); + dataout.put( temp ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } else { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + long b; + float buf; + datain.position( t ); + b = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + buf = b; + datain.position( t + group_size ); + b = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + buf += b; + datain.position( t + ysize ); + b = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + buf += b; + datain.position( t + ysize + group_size ); + b = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + buf += b; + dataout.put( (int)( ( buf / 4.0f ) + 0.5f ) ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } + } + + public static void halve1Dimage_int( int components, int width, int height, + ByteBuffer datain, IntBuffer dataout, int element_size, int ysize, + int group_size, boolean myswap_bytes ) { + int halfWidth = width / 2; + int halfHeight = height / 2; + int src = 0; + int dest = 0; + int jj; + + assert( width == 1 || height == 1 ); // must be 1D + assert( width != height ); // can't be square + + if( height == 1 ) { // 1 row + assert( width != 1 ); // can't be 1x1 + halfHeight = 1; + + for( jj = 0; jj < halfWidth; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + long[] uint = new long[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + uint[0] = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + datain.position( src + group_size ); + uint[1] = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + } else { + datain.position( src ); + uint[0] = ( 0x00000000FFFFFFFF & datain.getInt() ); + datain.position( src + group_size ); + uint[1] = ( 0x00000000FFFFFFFF & datain.getInt() ); + } + dataout.put( (int)( ( (float)uint[0] + (float)uint[1] ) / 2.0f) ); + src += element_size; + dest += 4; + } + src += group_size; // skip to next 2 + } + int padBytes = ysize - ( width * group_size ); + src += padBytes; // for assertion only + } else if( width == 1 ) { + int padBytes = ysize - ( width * group_size ); + assert( height != 1 ); + halfWidth = 1; + // one vertical column with possible pad bytes per row + // average two at a time + + for( jj = 0; jj < halfHeight; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + long[] uint = new long[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + uint[0] = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + datain.position( src + ysize ); + uint[1] = ( 0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ) ); + } else { + datain.position( src ); + uint[0] = ( 0x00000000FFFFFFFF & datain.getInt() ); + datain.position( src + ysize ); + uint[1] = ( 0x00000000FFFFFFFF & datain.getInt() ); + } + dataout.put( (int)(( (float)uint[0] + (float)uint[1] ) / 2.0f) ); + src += element_size; + dest += 4; + } + src += padBytes; // add pad bytes, if any, to get to end of row + src += ysize; + } + assert( src == ysize * height ); + } + assert( dest == ( components * element_size * halfWidth * halfHeight ) ); + } + + public static void halveImage_float( int components, int width, int height, + ByteBuffer datain, FloatBuffer dataout, int element_size, + int ysize, int group_size, boolean myswap_bytes ) { + int i, j, k, l; + int newwidth, newheight; + int s = 0; + int t = 0; + float temp = 0.0f; + // handle case where there is only 1 column/row + if( width == 1 || height == 1 ) { + assert( !( width == 1 && height == 1 ) ); // can't be 1x1 + halve1Dimage_float( components, width, height, datain, dataout, element_size, + ysize, group_size, myswap_bytes ); + return; + } + + newwidth = width / 2; + newheight = height / 2; + + // Piece of cake + if( !myswap_bytes ) { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + datain.position( t ); + temp = datain.getFloat(); + datain.position( t + group_size ); + temp += datain.getFloat(); + datain.position( t + ysize ); + temp += datain.getFloat(); + datain.position( t + ysize + group_size ); + temp /= 4.0f; + dataout.put( temp ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } else { + for( i = 0; i < newheight; i++ ) { + for( j = 0; j < newwidth; j++ ) { + for( k = 0; k < components; k++ ) { + float buf; + datain.position( t ); + buf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + datain.position( t + group_size ); + buf += Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + datain.position( t + ysize ); + buf += Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + datain.position( t + ysize + group_size ); + buf += Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + dataout.put( buf / 4.0f ); + t += element_size; + } + t += group_size; + } + t += ysize; + } + } + } + + public static void halve1Dimage_float( int components, int width, int height, + ByteBuffer datain, FloatBuffer dataout, int element_size, int ysize, + int group_size, boolean myswap_bytes ) { + int halfWidth = width / 2; + int halfHeight = height / 2; + int src = 0; + int dest = 0; + int jj; + + assert( width == 1 || height == 1 ); // must be 1D + assert( width != height ); // can't be square + + if( height == 1 ) { // 1 row + assert( width != 1 ); // can't be 1x1 + halfHeight = 1; + + for( jj = 0; jj < halfWidth; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + float[] sfloat = new float[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + sfloat[0] = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + datain.position( src + group_size ); + sfloat[1] = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + } else { + datain.position( src ); + sfloat[0] = datain.getFloat(); + datain.position( src + group_size ); + sfloat[1] = datain.getFloat(); + } + dataout.put( (sfloat[0] + sfloat[1]) / 2.0f ); + src += element_size; + dest += 4; + } + src += group_size; // skip to next 2 + } + int padBytes = ysize - ( width * group_size ); + src += padBytes; // for assertion only + } else if( width == 1 ) { + int padBytes = ysize - ( width * group_size ); + assert( height != 1 ); + halfWidth = 1; + // one vertical column with possible pad bytes per row + // average two at a time + + for( jj = 0; jj < halfHeight; jj++ ) { + int kk; + for( kk = 0; kk < components; kk++ ) { + float[] sfloat = new float[BOX2]; + if( myswap_bytes ) { + datain.position( src ); + sfloat[0] = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + datain.position( src + ysize ); + sfloat[1] = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + } else { + datain.position( src ); + sfloat[0] = datain.getFloat(); + datain.position( src + ysize ); + sfloat[1] = datain.getFloat(); + } + dataout.put( ( sfloat[0] + sfloat[1] ) / 2.0f ); + src += element_size; + dest += 4; + } + src += padBytes; // add pad bytes, if any, to get to end of row + src += ysize; + } + assert( src == ysize * height ); + } + assert( dest == ( components * element_size * halfWidth * halfHeight ) ); + } + + public static void halveImagePackedPixel( int components, Extract extract, int width, + int height, ByteBuffer datain, ByteBuffer dataout, + int pixelSizeInBytes, int rowSizeInBytes, boolean isSwap ) { + if( width == 1 || height == 1 ) { + assert( !( width == 1 && height == 1 ) ); + halve1DimagePackedPixel( components, extract, width, height, datain, dataout, + pixelSizeInBytes, rowSizeInBytes, isSwap ); + return; + } + int ii, jj; + + int halfWidth = width / 2; + int halfHeight = height / 2; + int src = 0; + int padBytes = rowSizeInBytes - ( width * pixelSizeInBytes ); + int outIndex = 0; + + for( ii = 0; ii < halfHeight; ii++ ) { + for( jj = 0; jj < halfWidth; jj++ ) { + float totals[] = new float[4]; + float extractTotals[][] = new float[BOX4][4]; + int cc; + + datain.position( src ); + extract.extract( isSwap, datain, extractTotals[0] ); + datain.position( src + pixelSizeInBytes ); + extract.extract( isSwap, datain, extractTotals[1] ); + datain.position( src + rowSizeInBytes ); + extract.extract( isSwap, datain, extractTotals[2] ); + datain.position( src + rowSizeInBytes + pixelSizeInBytes ); + extract.extract( isSwap, datain, extractTotals[3] ); + for( cc = 0; cc < components; cc++ ) { + int kk = 0; + // grab 4 pixels to average + totals[cc] = 0.0f; + for( kk = 0; kk < BOX4; kk++ ) { + totals[cc] += extractTotals[kk][cc]; + } + totals[cc] /= BOX4; + } + extract.shove( totals, outIndex, dataout ); + outIndex++; + src += pixelSizeInBytes + pixelSizeInBytes; + } + // skip past pad bytes, if any, to get to next row + src += padBytes; + src += rowSizeInBytes; + } + assert( src == rowSizeInBytes * height ); + assert( outIndex == halfWidth * halfHeight ); + } + + public static void halve1DimagePackedPixel( int components, Extract extract, int width, + int height, ByteBuffer datain, ByteBuffer dataout, + int pixelSizeInBytes, int rowSizeInBytes, boolean isSwap ) { + int halfWidth = width / 2; + int halfHeight = height / 2; + int src = 0; + int jj; + + assert( width == 1 || height == 1 ); + assert( width != height ); + + if( height == 1 ) { + int outIndex = 0; + + assert( width != 1 ); + halfHeight = 1; + + // one horizontal row with possible pad bytes + + for( jj = 0; jj < halfWidth; jj++ ) { + float[] totals = new float[4]; + float[][] extractTotals = new float[BOX2][4]; + int cc; + + datain.position( src ); + extract.extract( isSwap, datain, extractTotals[0] ); + datain.position( src + pixelSizeInBytes ); + extract.extract( isSwap, datain, extractTotals[1] ); + for( cc = 0; cc < components; cc++ ) { + int kk = 0; + // grab 4 pixels to average + totals[cc] = 0.0f; + for( kk = 0; kk < BOX2; kk++ ) { + totals[cc] += extractTotals[kk][cc]; + } + totals[cc] /= BOX2; + } + extract.shove( totals, outIndex, dataout ); + outIndex++; + // skip over to next group of 2 + src += pixelSizeInBytes + pixelSizeInBytes; + } + int padBytes = rowSizeInBytes - ( width * pixelSizeInBytes ); + src += padBytes; + + assert( src == rowSizeInBytes ); + assert( outIndex == halfWidth * halfHeight ); + } else if( width == 1 ) { + int outIndex = 0; + + assert( height != 1 ); + halfWidth = 1; + // one vertical volumn with possible pad bytes per row + // average two at a time + + for( jj = 0; jj < halfHeight; jj++ ) { + float[] totals = new float[4]; + float[][] extractTotals = new float[BOX2][4]; + int cc; + // average two at a time, instead of four + datain.position( src ); + extract.extract( isSwap, datain, extractTotals[0] ); + datain.position( src + rowSizeInBytes ); + extract.extract( isSwap, datain, extractTotals[1] ); + for( cc = 0; cc < components; cc++ ) { + int kk = 0; + // grab 4 pixels to average + totals[cc] = 0.0f; + for( kk = 0; kk < BOX2; kk++ ) { + totals[cc] += extractTotals[kk][cc]; + } + totals[cc] /= BOX2; + } + extract.shove( totals, outIndex, dataout ); + outIndex++; + // skip over to next group of 2 + src += rowSizeInBytes + rowSizeInBytes; + } + assert( src == rowSizeInBytes ); + assert( outIndex == halfWidth * halfHeight ); + } + } + + public static void halveImagePackedPixelSlice( int components, Extract extract, + int width, int height, int depth, ByteBuffer dataIn, + ByteBuffer dataOut, int pixelSizeInBytes, int rowSizeInBytes, + int imageSizeInBytes, boolean isSwap ) { + int ii, jj; + int halfWidth = width / 2; + int halfHeight = height / 2; + int halfDepth = depth / 2; + int src = 0; + int padBytes = rowSizeInBytes - ( width * pixelSizeInBytes ); + int outIndex = 0; + + assert( (width == 1 || height == 1) && depth >= 2 ); + + if( width == height ) { + assert( width == 1 && height == 1 ); + assert( depth >= 2 ); + + for( ii = 0; ii < halfDepth; ii++ ) { + float totals[] = new float[4]; + float extractTotals[][] = new float[BOX2][4]; + int cc; + + dataIn.position( src ); + extract.extract( isSwap, dataIn, extractTotals[0] ); + dataIn.position( src + imageSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[1] ); + + for( cc = 0; cc < components; cc++ ) { + int kk; + + // average only 2 pixels since a column + totals[cc]= 0.0f; + for( kk = 0; kk < BOX2; kk++ ) { + totals[cc] += extractTotals[kk][cc]; + } + totals[cc] /= BOX2; + } // for cc + + extract.shove( totals, outIndex, dataOut ); + outIndex++; + // skip over to next group of 2 + src += imageSizeInBytes + imageSizeInBytes; + } // for ii + } else if( height == 1 ) { + assert( width != 1 ); + + for( ii = 0; ii < halfDepth; ii++ ) { + for( jj = 0; jj < halfWidth; jj++ ) { + float totals[] = new float[4]; + float extractTotals[][] = new float[BOX4][4]; + int cc; + + dataIn.position( src ); + extract.extract( isSwap, dataIn, extractTotals[0] ); + dataIn.position( src + pixelSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[1] ); + dataIn.position( src + imageSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[2] ); + dataIn.position( src + pixelSizeInBytes + imageSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[3] ); + + for( cc = 0; cc < components; cc++ ) { + int kk; + + // grab 4 pixels to average + totals[cc] = 0.0f; + for( kk = 0; kk < BOX4; kk++ ) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (float)BOX4; + } + extract.shove( totals, outIndex, dataOut ); + outIndex++; + // skip over to next horizontal square of 4 + src += imageSizeInBytes + imageSizeInBytes; + } + } + } else if( width == 1 ) { + assert( height != 1 ); + + for( ii = 0; ii < halfDepth; ii++ ) { + for( jj = 0; jj < halfWidth; jj++ ) { + float totals[] = new float[4]; + float extractTotals[][] = new float[BOX4][4]; + int cc; + + dataIn.position( src ); + extract.extract( isSwap, dataIn, extractTotals[0] ); + dataIn.position( src + rowSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[1] ); + dataIn.position( src + imageSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[2] ); + dataIn.position( src + rowSizeInBytes + imageSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[3] ); + + for( cc = 0; cc < components; cc++ ) { + int kk; + + // grab 4 pixels to average + totals[cc] = 0.0f; + for( kk = 0; kk < BOX4; kk++ ) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (float)BOX4; + } + extract.shove( totals, outIndex, dataOut ); + outIndex++; + // skip over to next horizontal square of 4 + src += imageSizeInBytes + imageSizeInBytes; + } + } + } + } + + public static void halveImageSlice( int components, ExtractPrimitive extract, int width, + int height, int depth, ByteBuffer dataIn, ByteBuffer dataOut, + int elementSizeInBytes, int groupSizeInBytes, int rowSizeInBytes, + int imageSizeInBytes, boolean isSwap ) { + int ii, jj; + int halfWidth = width / 2; + int halfHeight = height / 2; + int halfDepth = depth / 2; + int src = 0; + int padBytes = rowSizeInBytes - ( width * groupSizeInBytes ); + int outIndex = 0; + + assert( (width == 1 || height == 1) && depth >= 2 ); + + if( width == height ) { + assert( width == 1 && height == 1 ); + assert( depth >= 2 ); + + for( ii = 0; ii < halfDepth; ii++ ) { + int cc; + for( cc = 0; cc < components; cc++ ) { + double[] totals = new double[4]; + double[][] extractTotals = new double[BOX2][4]; + int kk; + + dataIn.position( src ); + extractTotals[0][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + imageSizeInBytes ); + extractTotals[1][cc] = extract.extract( isSwap, dataIn ); + + // average 2 pixels since only a column + totals[cc] = 0.0f; + // totals[red] = extractTotals[0][red] + extractTotals[1][red]; + // totals[red] = red / 2; + for( kk = 0; kk < BOX2; kk++ ) { + totals[cc] += extractTotals[kk][cc]; + } + totals[cc] /= (double)BOX2; + + extract.shove( totals[cc], outIndex, dataOut ); + outIndex++; + src += elementSizeInBytes; + } // for cc + // skip over next group of 2 + src += rowSizeInBytes; + } // for ii + + assert( src == rowSizeInBytes * height * depth ); + assert( outIndex == halfDepth * components ); + } else if( height == 1 ) { + assert( width != 1 ); + + for( ii = 0; ii < halfDepth; ii++ ) { + for( jj = 0; jj < halfWidth; jj++ ) { + int cc; + for( cc = 0; cc < components; cc++ ) { + int kk; + double totals[] = new double[4]; + double extractTotals[][] = new double[BOX4][4]; + + dataIn.position( src ); + extractTotals[0][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + groupSizeInBytes ); + extractTotals[1][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + imageSizeInBytes ); + extractTotals[2][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + imageSizeInBytes + groupSizeInBytes ); + extractTotals[3][cc] = extract.extract( isSwap, dataIn ); + + // grab 4 pixels to average + totals[cc] = 0.0f; + // totals[red] = extractTotals[0][red] + extractTotals[1][red] + + // extractTotals[2][red] + extractTotals[3][red]; + // totals[red] /= (double)BOX4; + for( kk = 0; kk < BOX4; kk++ ) { + totals[cc] += extractTotals[kk][cc]; + } + totals[cc] /= (double)BOX4; + + extract.shove( totals[cc], outIndex, dataOut ); + outIndex++; + src += elementSizeInBytes; + } // for cc + // skip over to next horizontal square of 4 + src += elementSizeInBytes; + } // for jj + src += padBytes; + src += rowSizeInBytes; + } // for ii + assert( src == rowSizeInBytes * height * depth ); + assert( outIndex == halfWidth * halfDepth * components ); + } else if( width == 1 ) { + assert( height != 1 ); + + for( ii = 0; ii < halfDepth; ii++ ) { + for( jj = 0; jj < halfHeight; jj++ ) { + int cc; + for( cc = 0; cc < components; cc++ ) { + int kk; + double totals[] = new double[4]; + double extractTotals[][] = new double[BOX4][4]; + + dataIn.position( src ); + extractTotals[0][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + rowSizeInBytes ); + extractTotals[1][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + imageSizeInBytes ); + extractTotals[2][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + imageSizeInBytes + groupSizeInBytes ); + extractTotals[3][cc] = extract.extract( isSwap, dataIn ); + + + // grab 4 pixels to average + totals[cc] = 0.0f; + // totals[red] = extractTotals[0][red] + extractTotals[1][red] + + // extractTotals[2][red] + extractTotals[3][red]; + // totals[red] /= (double)BOX4; + for( kk = 0; kk < BOX4; kk++ ) { + totals[cc] += extractTotals[kk][cc]; + } + totals[cc] /= (double)BOX4; + + extract.shove( totals[cc], outIndex, dataOut ); + outIndex++; + src += elementSizeInBytes; + } // for cc + // skip over to next horizontal square of 4 + src += padBytes; + src += rowSizeInBytes; + } // for jj + src += imageSizeInBytes; + } // for ii + assert( src == rowSizeInBytes * height * depth ); + assert( outIndex == halfWidth * halfDepth * components ); + } + } + + public static void halveImage3D( int components, ExtractPrimitive extract, + int width, int height, int depth, ByteBuffer dataIn, ByteBuffer dataOut, + int elementSizeInBytes, int groupSizeInBytes, int rowSizeInBytes, + int imageSizeInBytes, boolean isSwap ) { + assert( depth > 1 ); + + // horizontal/vertical/onecolumn slice viewed from top + if( width == 1 || height == 1 ) { + assert( 1 <= depth ); + + halveImageSlice( components, extract, width, height, depth, dataIn, dataOut, + elementSizeInBytes, groupSizeInBytes, rowSizeInBytes, imageSizeInBytes, + isSwap ); + return; + } + + int ii, jj, dd; + + int halfWidth = width / 2; + int halfHeight = height / 2; + int halfDepth = depth / 2; + int src = 0; + int padBytes = rowSizeInBytes - ( width * groupSizeInBytes ); + int outIndex = 0; + + for( dd = 0; dd < halfDepth; dd++ ) { + for( ii = 0; ii < halfHeight; ii++ ) { + for( jj = 0; jj < halfWidth; jj++ ) { + int cc; + for( cc = 0; cc < components; cc++ ) { + int kk; + double totals[] = new double[4]; + double extractTotals[][] = new double[BOX8][4]; + + dataIn.position( src ); + extractTotals[0][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + groupSizeInBytes ); + extractTotals[1][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + rowSizeInBytes ); + extractTotals[2][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + rowSizeInBytes + groupSizeInBytes ); + extractTotals[3][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + imageSizeInBytes ); + extractTotals[4][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + groupSizeInBytes + imageSizeInBytes ); + extractTotals[5][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + rowSizeInBytes + imageSizeInBytes ); + extractTotals[6][cc] = extract.extract( isSwap, dataIn ); + dataIn.position( src + rowSizeInBytes + imageSizeInBytes + groupSizeInBytes ); + extractTotals[7][cc] = extract.extract( isSwap, dataIn ); + + totals[cc] = 0.0f; + + for( kk = 0; kk < BOX8; kk++ ) { + totals[cc] += extractTotals[kk][cc]; + } + totals[cc] /= (double)BOX8; + + extract.shove( totals[cc], outIndex, dataOut ); + outIndex++; + + src += elementSizeInBytes; + } // for cc + // skip over to next square of 4 + src += groupSizeInBytes; + } // for jj + // skip past pad bytes, if any, to get to next row + src += padBytes; + src += rowSizeInBytes; + } // for ii + src += imageSizeInBytes; + } // for dd + assert( src == rowSizeInBytes * height * depth ); + assert( outIndex == halfWidth * halfHeight * halfDepth * components ); + } + + public static void halveImagePackedPixel3D( int components, Extract extract, + int width, int height, int depth, ByteBuffer dataIn, + ByteBuffer dataOut, int pixelSizeInBytes, int rowSizeInBytes, + int imageSizeInBytes, boolean isSwap ) { + if( depth == 1 ) { + assert( 1 <= width && 1 <= height ); + + halveImagePackedPixel( components, extract, width, height, dataIn, dataOut, + pixelSizeInBytes, rowSizeInBytes, isSwap ); + return; + } else if( width == 1 || height == 1 ) { // a horizontal or vertical slice viewed from top + assert( 1 <= depth ); + + halveImagePackedPixelSlice( components, extract, width, height, depth, dataIn, + dataOut, pixelSizeInBytes, rowSizeInBytes, imageSizeInBytes, isSwap ); + return; + } + int ii, jj, dd; + + int halfWidth = width / 2; + int halfHeight = height / 2; + int halfDepth = depth / 2; + int src = 0; + int padBytes = rowSizeInBytes - ( width * pixelSizeInBytes ); + int outIndex = 0; + + for( dd = 0; dd < halfDepth; dd++ ) { + for( ii = 0; ii < halfHeight; ii++ ) { + for( jj = 0; jj < halfWidth; jj++ ) { + float totals[] = new float[4]; // 4 is max components + float extractTotals[][] = new float[BOX8][4]; + int cc; + + dataIn.position( src ); + extract.extract( isSwap, dataIn, extractTotals[0] ); + dataIn.position( src + pixelSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[1] ); + dataIn.position( src + rowSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[2] ); + dataIn.position( src + rowSizeInBytes + pixelSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[3] ); + dataIn.position( src + imageSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[4] ); + dataIn.position( src + pixelSizeInBytes + imageSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[5] ); + dataIn.position( src + rowSizeInBytes + imageSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[6] ); + dataIn.position( src + rowSizeInBytes + pixelSizeInBytes + imageSizeInBytes ); + extract.extract( isSwap, dataIn, extractTotals[7] ); + + for( cc = 0; cc < components; cc++ ) { + int kk; + // grab 8 pixels to average + totals[cc] = 0.0f; + for( kk = 0; kk < BOX8; kk++ ) { + totals[cc] += extractTotals[kk][cc]; + } + totals[cc] /= (float)BOX8; + } + extract.shove( totals, outIndex, dataOut ); + outIndex++; + // skip over to next square of 4 + src += pixelSizeInBytes + pixelSizeInBytes; + } + // skip past pad bytes, if any, to get to next row + src += padBytes; + src += rowSizeInBytes; + } + src += imageSizeInBytes; + } + assert( src == rowSizeInBytes * height * depth ); + assert( outIndex == halfWidth * halfHeight * halfDepth ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Image.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Image.java new file mode 100644 index 000000000..b610ce86b --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Image.java @@ -0,0 +1,1413 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import java.nio.*; + +/** + * + * @author Administrator + */ +public class Image { + + /** Creates a new instance of Image */ + public Image() { + } + + public static short getShortFromByteArray( byte[] array, int index ) { + short s; + s = (short)(array[index] << 8 ); + s |= (short)(0x00FF & array[index+1]); + return( s ); + } + + public static int getIntFromByteArray( byte[] array, int index ) { + int i; + i = ( array[index] << 24 ) & 0xFF000000; + i |= ( array[index+1] << 16 ) & 0x00FF0000; + i |= ( array[index+2] << 8 ) & 0x0000FF00; + i |= ( array[index+3] ) & 0x000000FF; + return( i ); + } + + public static float getFloatFromByteArray( byte[] array, int index ) { + int i = getIntFromByteArray( array, index ); + return( Float.intBitsToFloat(i) ); + } + + /* + * Extract array from user's data applying all pixel store modes. + * The internal format used is an array of unsigned shorts. + */ + public static void fill_image( PixelStorageModes psm, int width, int height, + int format, int type, boolean index_format, ByteBuffer userdata, + ShortBuffer newimage ) { + int components; + int element_size; + int rowsize; + int padding; + int groups_per_line; + int group_size; + int elements_per_line; + int start; + int iter = 0; + int iter2; + int i, j, k; + boolean myswap_bytes; + + // Create a Extract interface object + Extract extract = null; + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + extract = new Extract332(); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + extract = new Extract233rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + extract = new Extract565(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + extract = new Extract565rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + extract = new Extract4444(); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + extract = new Extract4444rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + extract = new Extract5551(); + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + extract = new Extract1555rev(); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + extract = new Extract8888(); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + extract = new Extract8888rev(); + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + extract = new Extract1010102(); + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + extract = new Extract2101010rev(); + break; + } + + myswap_bytes = psm.getUnpackSwapBytes(); + components = Mipmap.elements_per_group( format, type ); + if( psm.getUnpackRowLength() > 0 ) { + groups_per_line = psm.getUnpackRowLength(); + } else { + groups_per_line = width; + } + + // All formats except GL_BITMAP fall out trivially + if( type == GL2.GL_BITMAP ) { + int bit_offset; + int current_bit; + + rowsize = ( groups_per_line * components + 7 ) / 8; + padding = ( rowsize % psm.getUnpackAlignment() ); + if( padding != 0 ) { + rowsize += psm.getUnpackAlignment() - padding; + } + start = psm.getUnpackSkipRows() * rowsize + ( psm.getUnpackSkipPixels() * components / 8 ); + elements_per_line = width * components; + iter2 = 0; + for( i = 0; i < height; i++ ) { + iter = start; + userdata.position( iter ); // **************************************** + bit_offset = (psm.getUnpackSkipPixels() * components) % 8; + for( j = 0; j < elements_per_line; j++ ) { + // retrieve bit + if( psm.getUnpackLsbFirst() ) { + userdata.position( iter ); + current_bit = ( userdata.get() & 0x000000FF ) & ( 1 << bit_offset );//userdata[iter] & ( 1 << bit_offset ); + } else { + current_bit = ( userdata.get() & 0x000000FF ) & ( 1 << ( 7 - bit_offset ) ); + } + if( current_bit != 0 ) { + if( index_format ) { + newimage.position( iter2 ); + newimage.put( (short)1 ); + } else { + newimage.position( iter2 ); + newimage.put( (short)65535 ); + } + } else { + newimage.position( iter2 ); + newimage.put( (short)0 ); + } + bit_offset++; + if( bit_offset == 8 ) { + bit_offset = 0; + iter++; + } + iter2++; + } + start += rowsize; + } + } else { + element_size = Mipmap.bytes_per_element( type ); + group_size = element_size * components; + if( element_size == 1 ) { + myswap_bytes = false; + } + + rowsize = groups_per_line * group_size; + padding = ( rowsize % psm.getUnpackAlignment() ); + if( padding != 0 ) { + rowsize += psm.getUnpackAlignment() - padding; + } + start = psm.getUnpackSkipRows() * rowsize + psm.getUnpackSkipPixels() * group_size; + elements_per_line = width * components; + + iter2 = 0; + for( i = 0; i < height; i++ ) { + iter = start; + userdata.position( iter ); //*************************************** + for( j = 0; j < elements_per_line; j++ ) { + Type_Widget widget = new Type_Widget(); + float[] extractComponents = new float[4]; + userdata.position( iter ); + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + extract.extract( false, userdata /*userdata[iter]*/, extractComponents ); + for( k = 0; k < 3; k++ ) { + newimage.put( iter2++, (short)(extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + extract.extract( false, userdata /*userdata[iter]*/, extractComponents ); + for( k = 0; k < 3; k++ ) { + newimage.put( iter2++, (short)(extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_BYTE ): + if( index_format ) { + newimage.put( iter2++, (short)( 0x000000FF & userdata.get() ) );//userdata[iter]; + } else { + newimage.put( iter2++, (short)( 0x000000FF & userdata.get()/*userdata[iter]*/ * 257 ) ); + } + break; + case( GL2.GL_BYTE ): + if( index_format ) { + newimage.put( iter2++, userdata.get() ); //userdata[iter]; + } else { + newimage.put( iter2++, (short)(userdata.get()/*userdata[iter]*/ * 516 ) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + extract.extract( myswap_bytes, userdata/*userdata[iter]*/, extractComponents ); + for( k = 0; k < 3; k++ ) { + newimage.put( iter2++, (short)(extractComponents[k] * 65535) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + extract.extract( myswap_bytes, userdata, extractComponents ); + for( k = 0; k < 3; k++ ) { + newimage.put( iter2++, (short)(extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + extract.extract( myswap_bytes, userdata, extractComponents ); + for( k = 0; k < 4; k++ ) { + newimage.put( iter2++, (short)(extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + extract.extract( myswap_bytes, userdata, extractComponents ); + for( k = 0; k < 4; k++ ) { + newimage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + extract.extract( myswap_bytes, userdata, extractComponents ); + for( k = 0; k < 4; k++ ) { + newimage.put( iter2++, (short)(extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + extract.extract( myswap_bytes, userdata, extractComponents ); + for( k = 0; k < 4; k++ ) { + newimage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + if( myswap_bytes ) { + widget.setUB1( userdata.get() ); + widget.setUB0( userdata.get() ); + } else { + widget.setUB0( userdata.get() ); + widget.setUB1( userdata.get() ); + } + if( type == GL2.GL_SHORT ) { + if( index_format ) { + newimage.put( iter2++, widget.getS0() ); + } else { + newimage.put( iter2++, (short)(widget.getS0() * 2) ); + } + } else { + newimage.put( iter2++, widget.getUS0() ); + } + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + extract.extract( myswap_bytes, userdata, extractComponents ); + for( k = 0; k < 4; k++ ) { + newimage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + extract.extract( myswap_bytes, userdata, extractComponents ); + for( k = 0; k < 4; k++ ) { + newimage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + extract.extract( myswap_bytes, userdata, extractComponents ); + for( k = 0; k < 4; k++ ) { + newimage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + extract.extract( myswap_bytes, userdata, extractComponents ); + for( k = 0; k < 4; k++ ) { + newimage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_INT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_FLOAT ): + if( myswap_bytes ) { + widget.setUB3( userdata.get() ); + widget.setUB2( userdata.get() ); + widget.setUB1( userdata.get() ); + widget.setUB0( userdata.get() ); + } else { + widget.setUB0( userdata.get() ); + widget.setUB1( userdata.get() ); + widget.setUB2( userdata.get() ); + widget.setUB3( userdata.get() ); + } + if( type == GL2.GL_FLOAT ) { + if( index_format ) { + newimage.put( iter2++, (short)widget.getF() ); + } else { + newimage.put( iter2++, (short)(widget.getF() * 65535 ) ); + } + } else if( type == GL2.GL_UNSIGNED_INT ) { + if( index_format ) { + newimage.put( iter2++, (short)( widget.getUI() ) ); + } else { + newimage.put( iter2++, (short)( widget.getUI() >> 16 ) ); + } + } else { + if( index_format ) { + newimage.put( iter2++, (short)( widget.getI() ) ); + } else { + newimage.put( iter2++, (short)( widget.getI() >> 15 ) ); + } + } + break; + } + iter += element_size; + } // for j + start += rowsize; + // want iter pointing at start, not within, row for assertion purposes + iter = start; + } // for i + + // iterators should be one byte past end + if( !Mipmap.isTypePackedPixel( type ) ) { + assert( iter2 == ( width * height * components ) ); + } else { + assert( iter2 == ( width * height * Mipmap.elements_per_group( format, 0 ) ) ); + } + assert( iter == ( rowsize * height + psm.getUnpackSkipRows() * rowsize + psm.getUnpackSkipPixels() * group_size ) ); + } + } + + /* + * Insert array into user's data applying all pixel store modes. + * Theinternal format is an array of unsigned shorts. + * empty_image() because it is the opposet of fill_image(). + */ + public static void empty_image( PixelStorageModes psm, int width, int height, + int format, int type, boolean index_format, + ShortBuffer oldimage, ByteBuffer userdata ) { + + int components; + int element_size; + int rowsize; + int padding; + int groups_per_line; + int group_size; + int elements_per_line; + int start; + int iter = 0; + int iter2; + int i, j, k; + boolean myswap_bytes; + + // Create a Extract interface object + Extract extract = null; + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + extract = new Extract332(); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + extract = new Extract233rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + extract = new Extract565(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + extract = new Extract565rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + extract = new Extract4444(); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + extract = new Extract4444rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + extract = new Extract5551(); + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + extract = new Extract1555rev(); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + extract = new Extract8888(); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + extract = new Extract8888rev(); + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + extract = new Extract1010102(); + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + extract = new Extract2101010rev(); + break; + } + + myswap_bytes = psm.getPackSwapBytes(); + components = Mipmap.elements_per_group( format, type ); + if( psm.getPackRowLength() > 0 ) { + groups_per_line = psm.getPackRowLength(); + } else { + groups_per_line = width; + } + + // all formats except GL_BITMAP fall out trivially + if( type == GL2.GL_BITMAP ) { + int bit_offset; + int current_bit; + + rowsize = ( groups_per_line * components + 7 ) / 8; + padding = ( rowsize % psm.getPackAlignment() ); + if( padding != 0 ) { + rowsize += psm.getPackAlignment() - padding; + } + start = psm.getPackSkipRows() * rowsize + psm.getPackSkipPixels() * components / 8; + elements_per_line = width * components; + iter2 = 0; + for( i = 0; i < height; i++ ) { + iter = start; + bit_offset = ( psm.getPackSkipPixels() * components ) % 8; + for( j = 0; j < elements_per_line; j++ ) { + if( index_format ) { + current_bit = oldimage.get( iter2 ) & 1; + } else { + if( oldimage.get( iter2 ) < 0 ) { // must check for negative rather than 32767 + current_bit = 1; + } else { + current_bit = 0; + } + } + + if( current_bit != 0 ) { + if( psm.getPackLsbFirst() ) { + userdata.put( iter, (byte)( ( userdata.get( iter ) | ( 1 << bit_offset ) ) ) ); + } else { + userdata.put( iter, (byte)( ( userdata.get( iter ) | ( 7 - bit_offset ) ) ) ); + } + } else { + if( psm.getPackLsbFirst() ) { + //userdata[iter] &= ~( 1 << bit_offset ); + userdata.put( iter, (byte)( ( userdata.get( iter ) & ~( 1 << bit_offset ) ) ) ); + } else { + //userdata[iter] &= ~( 1 << ( 7 - bit_offset ) ); + userdata.put( iter, (byte)( ( userdata.get( iter ) & ~( 7 - bit_offset ) ) ) ); + } + } + + bit_offset++; + if( bit_offset == 8 ) { + bit_offset = 0; + iter++; + } + iter2++; + } + start += rowsize; + } + } else { + float shoveComponents[] = new float[4]; + + element_size = Mipmap.bytes_per_element( type ); + group_size = element_size * components; + if( element_size == 1 ) { + myswap_bytes = false; + } + + rowsize = groups_per_line * group_size; + padding = ( rowsize % psm.getPackAlignment() ); + if( padding != 0 ) { + rowsize += psm.getPackAlignment() - padding; + } + start = psm.getPackSkipRows() * rowsize + psm.getPackSkipPixels() * group_size; + elements_per_line = width * components; + + iter2 = 0; + for( i = 0; i < height; i++ ) { + iter = start; + for( j = 0; j < elements_per_line; j++ ) { + Type_Widget widget = new Type_Widget(); + + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + for( k = 0; k < 3; k++ ) { + shoveComponents[k] = oldimage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, userdata ); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + for( k = 0; k < 3; k++ ) { + shoveComponents[k] = oldimage.get(iter2++) / 65535.0f; + } + extract.shove( shoveComponents, 0, userdata ); + break; + case( GL2.GL_UNSIGNED_BYTE ): + if( index_format ) { + //userdata[iter] = (byte)oldimage[iter2++]; + userdata.put( iter, (byte)oldimage.get(iter2++) ); + } else { + //userdata[iter] = (byte)( oldimage[iter2++] >> 8 ); + userdata.put( iter, (byte)( oldimage.get(iter2++) ) ); + } + break; + case( GL2.GL_BYTE ): + if( index_format ) { + //userdata[iter] = (byte)oldimage[iter2++]; + userdata.put( iter, (byte)oldimage.get(iter2++) ); + } else { + //userdata[iter] = (byte)( oldimage[iter2++] >> 9 ); + userdata.put( iter, (byte)( oldimage.get(iter2++) ) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + for( k = 0; k < 3; k++ ) { + shoveComponents[k] = oldimage.get(iter2++) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter] = widget.getUB1(); + //userdata[iter+1] = widget.getUB0(); + userdata.put( iter, widget.getUB1() ); + userdata.put( iter + 1,widget.getUB0() ); + } else { + //userdata[iter] = widget.getUB0(); + //userdata[iter+1] = widget.getUB1(); + userdata.put( iter, widget.getUB0() ); + userdata.put( iter + 1, widget.getUB1() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + for( k = 0; k < 3; k++ ) { + shoveComponents[k] = oldimage.get(iter2++) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter] = widget.getUB1(); + //userdata[iter+1] = widget.getUB0(); + userdata.put( iter, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB0() ); + } else { + //userdata[iter] = widget.getUB0(); + //userdata[iter+1] = widget.getUB1(); + userdata.put( iter, widget.getUB0() ); + userdata.put( iter, widget.getUB1() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldimage.get(iter2++) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter] = widget.getUB1(); + //userdata[iter+1] = widget.getUB0(); + userdata.put( iter, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB0() ); + } else { + //userdata[iter] = widget.getUB0(); + //userdata[iter+1] = widget.getUB1(); + userdata.put( iter, widget.getUB0() ); + userdata.put( iter + 1, widget.getUB1() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldimage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter] = widget.getUB1(); + //userdata[iter+1] = widget.getUB0(); + userdata.put( iter, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB0() ); + } else { + //userdata[iter] = widget.getUB0(); + //userdata[iter+1] = widget.getUB1(); + userdata.put( iter, widget.getUB0() ); + userdata.put( iter + 1, widget.getUB1() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldimage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter] = widget.getUB1(); + //userdata[iter+1] = widget.getUB0(); + userdata.put( iter, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB0() ); + } else { + //userdata[iter] = widget.getUB0(); + //userdata[iter+1] = widget.getUB1(); + userdata.put( iter, widget.getUB0() ); + userdata.put( iter + 1, widget.getUB1() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldimage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter] = widget.getUB1(); + //userdata[iter+1] = widget.getUB0(); + userdata.put( iter, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB0() ); + } else { + //userdata[iter] = widget.getUB0(); + //userdata[iter+1] = widget.getUB1(); + userdata.put( iter, widget.getUB0() ); + userdata.put( iter + 1, widget.getUB1() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + if( type == GL2.GL_SHORT ) { + if( index_format ) { + widget.setS0( oldimage.get( iter2++ ) ); + } else { + widget.setS0( (short)(oldimage.get( iter2++ ) >> 1) ); + } + } else { + widget.setUS0( oldimage.get( iter2++ ) ); + } + if( myswap_bytes ) { + //userdata[iter] = widget.getUB1(); + //userdata[iter+1] = widget.getUB0(); + userdata.put( iter, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB0() ); + } else { + //userdata[iter] = widget.getUB0(); + //userdata[iter] = widget.getUB1(); + userdata.put( iter, widget.getUB0() ); + userdata.put( iter + 1, widget.getUB1() ); + } + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldimage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter+3] = widget.getUB0(); + //userdata[iter+2] = widget.getUB1(); + //userdata[iter+1] = widget.getUB2(); + //userdata[iter ] = widget.getUB3(); + userdata.put( iter + 3, widget.getUB0() ); + userdata.put( iter + 2, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB2() ); + userdata.put( iter , widget.getUB3() ); + } else { + userdata.putInt( iter, widget.getUI() ); + } + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldimage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter+3] = widget.getUB0(); + //userdata[iter+2] = widget.getUB1(); + //userdata[iter+1] = widget.getUB2(); + //userdata[iter ] = widget.getUB3(); + userdata.put( iter + 3, widget.getUB0() ); + userdata.put( iter + 2, widget.getUB1() ); + userdata.put( iter + 2, widget.getUB2() ); + userdata.put( iter , widget.getUB3() ); + } else { + userdata.putInt( iter, widget.getUI() ); + } + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldimage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter+3] = widget.getUB0(); + //userdata[iter+2] = widget.getUB1(); + //userdata[iter+1] = widget.getUB2(); + //userdata[iter ] = widget.getUB3(); + userdata.put( iter + 3, widget.getUB0() ); + userdata.put( iter + 2, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB2() ); + userdata.put( iter , widget.getUB3() ); + } else { + userdata.putInt( iter, widget.getUI() ); + } + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldimage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswap_bytes ) { + //userdata[iter+3] = widget.getUB0(); + //userdata[iter+2] = widget.getUB1(); + //userdata[iter+1] = widget.getUB2(); + //userdata[iter ] = widget.getUB3(); + userdata.put( iter + 3, widget.getUB0() ); + userdata.put( iter + 2, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB2() ); + userdata.put( iter , widget.getUB3() ); + } else { + userdata.putInt( iter, widget.getUI() ); + } + break; + case( GL2.GL_INT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_FLOAT ): + if( type == GL2.GL_FLOAT ) { + if( index_format ) { + widget.setF( oldimage.get( iter2++ ) ); + } else { + widget.setF( oldimage.get( iter2++ ) / 65535.0f ); + } + } else if( type == GL2.GL_UNSIGNED_INT ) { + if( index_format ) { + widget.setUI( oldimage.get( iter2++ ) ); + } else { + widget.setUI( oldimage.get( iter2++ ) * 65537 ); + } + } else { + if( index_format ) { + widget.setI( oldimage.get( iter2++ ) ); + } else { + widget.setI( (oldimage.get( iter2++ ) * 65537) / 2 ); + } + } + if( myswap_bytes ) { + userdata.put( iter + 3, widget.getUB0() ); + userdata.put( iter + 2, widget.getUB1() ); + userdata.put( iter + 1, widget.getUB2() ); + userdata.put( iter , widget.getUB3() ); + } else { + userdata.put( iter , widget.getUB0() ); + userdata.put( iter + 1, widget.getUB1() ); + userdata.put( iter + 2, widget.getUB2() ); + userdata.put( iter + 3, widget.getUB3() ); + } + break; + } + iter += element_size; + } // for j + start += rowsize; + // want iter pointing at start, not within, row for assertion purposes + iter = start; + } // for i + // iterators should be one byte past end + if( !Mipmap.isTypePackedPixel( type ) ) { + assert( iter2 == width * height * components ); + } else { + assert( iter2 == width * height * Mipmap.elements_per_group( format, 0 ) ); + } + assert( iter == rowsize * height + psm.getPackSkipRows() * rowsize + psm.getPackSkipPixels() * group_size ); + } + } + + public static void fillImage3D( PixelStorageModes psm, int width, int height, + int depth, int format, int type, boolean indexFormat, ByteBuffer userImage, + ShortBuffer newImage ) { + boolean myswapBytes; + int components; + int groupsPerLine; + int elementSize; + int groupSize; + int rowSize; + int padding; + int elementsPerLine; + int rowsPerImage; + int imageSize; + int start, rowStart; + int iter = 0; + int iter2 = 0; + int ww, hh, dd, k; + Type_Widget widget = new Type_Widget(); + float extractComponents[] = new float[4]; + + // Create a Extract interface object + Extract extract = null; + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + extract = new Extract332(); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + extract = new Extract233rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + extract = new Extract565(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + extract = new Extract565rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + extract = new Extract4444(); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + extract = new Extract4444rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + extract = new Extract5551(); + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + extract = new Extract1555rev(); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + extract = new Extract8888(); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + extract = new Extract8888rev(); + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + extract = new Extract1010102(); + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + extract = new Extract2101010rev(); + break; + } + + myswapBytes = psm.getUnpackSwapBytes(); + components = Mipmap.elements_per_group( format, type ); + if( psm.getUnpackRowLength() > 0 ) { + groupsPerLine = psm.getUnpackRowLength(); + } else { + groupsPerLine = width; + } + elementSize = Mipmap.bytes_per_element( type ); + groupSize = elementSize * components; + if( elementSize == 1 ) { + myswapBytes = false; + } + + // 3dstuff begin + if( psm.getUnpackImageHeight() > 0 ) { + rowsPerImage = psm.getUnpackImageHeight(); + } else { + rowsPerImage = height; + } + // 3dstuff end + + rowSize = groupsPerLine * groupSize; + padding = rowSize % psm.getUnpackAlignment(); + if( padding != 0 ) { + rowSize += psm.getUnpackAlignment() - padding; + } + + imageSize = rowsPerImage * rowSize; // 3dstuff + + start = psm.getUnpackSkipRows() * rowSize + + psm.getUnpackSkipPixels() * groupSize + + psm.getUnpackSkipImages() * imageSize; + elementsPerLine = width * components; + + iter2 = 0; + for( dd = 0; dd < depth; dd++ ) { + rowStart = start; + for( hh = 0; hh < height; hh++ ) { + iter = rowStart; + for( ww = 0; ww < elementsPerLine; ww++ ) { + + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + if( indexFormat ) { + newImage.put( iter2++, (short)(0x000000FF & userImage.get( iter ) ) ); + } else { + newImage.put( iter2++, (short)((0x000000FF & userImage.get( iter ) ) * 257 ) ); + } + break; + case( GL2.GL_BYTE ): + if( indexFormat ) { + newImage.put( iter2++, userImage.get( iter ) ); + } else { + newImage.put( iter2++, (short)(userImage.get( iter ) * 516 ) ); + } + break; + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + userImage.position( iter ); + extract.extract( false, userImage, extractComponents ); + for( k = 0; k < 3; k++ ) { + newImage.put( iter2++, (short)(extractComponents[k] * 65535) ); + } + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + userImage.position( iter ); + extract.extract( false, userImage, extractComponents ); + for( k = 0; k < 3; k++ ) { + newImage.put( iter2++, (short)(extractComponents[k] * 65535) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + userImage.position( iter ); + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)(extractComponents[k] * 65535) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + userImage.position( iter ); + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)(extractComponents[k] * 65535) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + userImage.position( iter ); + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)(extractComponents[k] * 65535) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + userImage.position( iter ); + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)(extractComponents[k] * 65535) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + userImage.position( iter ); + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)(extractComponents[k] * 65535) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + userImage.position( iter ); + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)(extractComponents[k] * 65535) ); + } + break; + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + if( myswapBytes ) { + widget.setUB0( userImage.get( iter + 1 ) ); + widget.setUB1( userImage.get( iter ) ); + } else { + widget.setUB0( userImage.get( iter ) ); + widget.setUB1( userImage.get( iter + 1 ) ); + } + if( type == GL2.GL_SHORT ) { + if( indexFormat ) { + newImage.put( iter2++, widget.getUS0() ); + } else { + newImage.put( iter2++, (short)(widget.getUS0() * 2) ); + } + } else { + newImage.put( iter2++, widget.getUS0() ); + } + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + userImage.position( iter ); + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + userImage.position( iter ); + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + userImage.position( iter ); + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + extract.extract( myswapBytes, userImage, extractComponents ); + for( k = 0; k < 4; k++ ) { + newImage.put( iter2++, (short)( extractComponents[k] * 65535 ) ); + } + break; + case( GL2.GL_INT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_FLOAT ): + if( myswapBytes ) { + widget.setUB0( userImage.get( iter + 3 ) ); + widget.setUB1( userImage.get( iter + 2 ) ); + widget.setUB2( userImage.get( iter + 1 ) ); + widget.setUB3( userImage.get( iter ) ); + } else { + widget.setUB0( userImage.get( iter ) ); + widget.setUB1( userImage.get( iter + 1 ) ); + widget.setUB2( userImage.get( iter + 2 ) ); + widget.setUB3( userImage.get( iter + 3 ) ); + } + if( type == GL2.GL_FLOAT ) { + if( indexFormat ) { + newImage.put( iter2++, (short)widget.getF() ); + } else { + newImage.put( iter2++, (short)( widget.getF() * 65535.0f ) ); + } + } else if( type == GL2.GL_UNSIGNED_INT ) { + if( indexFormat ) { + newImage.put( iter2++, (short)widget.getUI() ); + } else { + newImage.put( iter2++, (short)(widget.getUI() >> 16) ); + } + } else { + if( indexFormat ) { + newImage.put( iter2++, (short)widget.getI() ); + } else { + newImage.put( iter2++, (short)(widget.getI() >> 15) ); + } + } + break; + default: + assert( false ); + } + iter += elementSize; + } // for ww + rowStart += rowSize; + iter = rowStart; // for assert + } // for hh + start += imageSize; + }// for dd + + // iterators should be one byte past end + if( !Mipmap.isTypePackedPixel( type ) ) { + assert( iter2 == width * height * depth * components ); + } else { + assert( iter2 == width * height * depth * Mipmap.elements_per_group( format, 0 ) ); + } + assert( iter == rowSize * height * depth + psm.getUnpackSkipRows() * rowSize + + psm.getUnpackSkipPixels() * groupSize + + psm.getUnpackSkipImages() * imageSize ); + } + + public static void emptyImage3D( PixelStorageModes psm, int width, int height, int depth, + int format, int type, boolean indexFormat, ShortBuffer oldImage, ByteBuffer userImage ) { + boolean myswapBytes; + int components; + int groupsPerLine; + int elementSize; + int groupSize; + int rowSize; + int padding; + int start, rowStart, iter; + int elementsPerLine; + int iter2; + int ii, jj, dd, k; + int rowsPerImage; + int imageSize; + Type_Widget widget = new Type_Widget(); + float[] shoveComponents = new float[4]; + + // Create a Extract interface object + Extract extract = null; + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + extract = new Extract332(); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + extract = new Extract233rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + extract = new Extract565(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + extract = new Extract565rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + extract = new Extract4444(); + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + extract = new Extract4444rev(); + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + extract = new Extract5551(); + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + extract = new Extract1555rev(); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + extract = new Extract8888(); + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + extract = new Extract8888rev(); + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + extract = new Extract1010102(); + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + extract = new Extract2101010rev(); + break; + } + + iter = 0; + + myswapBytes = psm.getPackSwapBytes(); + components = Mipmap.elements_per_group( format, type ); + if( psm.getPackRowLength() > 0 ) { + groupsPerLine = psm.getPackRowLength(); + } else { + groupsPerLine = width; + } + + elementSize = Mipmap.bytes_per_element( type ); + groupSize = elementSize * components; + if( elementSize == 1 ) { + myswapBytes = false; + } + + // 3dstuff begin + if( psm.getPackImageHeight() > 0 ) { + rowsPerImage = psm.getPackImageHeight(); + } else { + rowsPerImage = height; + } + + // 3dstuff end + + rowSize = groupsPerLine * groupSize; + padding = rowSize % psm.getPackAlignment(); + if( padding != 0 ) { + rowSize += psm.getPackAlignment() - padding; + } + + imageSize = rowsPerImage * rowSize; + + start = psm.getPackSkipRows() * rowSize + + psm.getPackSkipPixels() * groupSize + + psm.getPackSkipImages() * imageSize; + elementsPerLine = width * components; + + iter2 = 0; + for( dd = 0; dd < depth; dd++ ) { + rowStart = start; + + for( ii = 0; ii < height; ii++ ) { + iter = rowStart; + + for( jj = 0; jj < elementsPerLine; jj++ ) { + + switch( type ) { + case( GL2.GL_UNSIGNED_BYTE ): + if( indexFormat ) { + userImage.put( iter, (byte)(oldImage.get( iter2++ ) ) ); + } else { + userImage.put( iter, (byte)(oldImage.get( iter2++ ) >> 8 ) ); + } + break; + case( GL2.GL_BYTE ): + if( indexFormat ) { + userImage.put( iter, (byte)(oldImage.get(iter2++) ) ); + } else { + userImage.put( iter, (byte)(oldImage.get(iter2++) >> 9) ); + } + break; + case( GL2.GL_UNSIGNED_BYTE_3_3_2 ): + for( k = 0; k < 3; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, userImage ); + break; + case( GL2.GL_UNSIGNED_BYTE_2_3_3_REV ): + for( k = 0; k < 3; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, userImage ); + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5 ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.putShort( iter, widget.getUB1() ); + userImage.putShort( iter + 1, widget.getUB0() ); + } else { + userImage.putShort( iter, widget.getUS0() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_6_5_REV ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.put( iter, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB0() ); + } else { + userImage.putShort( iter, widget.getUS0() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4 ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.put( iter, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB0() ); + } else { + userImage.putShort( iter, widget.getUS0() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.put( iter, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB0() ); + } else { + userImage.putShort( iter, widget.getUS0() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_5_5_5_1 ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.put( iter, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB0() ); + } else { + userImage.putShort( iter, widget.getUS0() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.put( iter, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB0() ); + } else { + userImage.putShort( iter, widget.getUS0() ); + } + break; + case( GL2.GL_UNSIGNED_SHORT ): + case( GL2.GL_SHORT ): + if( type == GL2.GL_SHORT ) { + if( indexFormat ) { + widget.setS0( (short)oldImage.get( iter2++ ) ); + } else { + widget.setS0( (short)(oldImage.get( iter2++ ) >> 1) ); + } + } else { + widget.setUS0( (short)oldImage.get( iter2++ ) ); + } + if( myswapBytes ) { + userImage.put( iter, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB0() ); + } else { + userImage.put( iter, widget.getUB0() ); + userImage.put( iter + 1, widget.getUB1() ); + } + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8 ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.put( iter + 3, widget.getUB0() ); + userImage.put( iter + 2, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB2() ); + userImage.put( iter , widget.getUB3() ); + } else { + userImage.putInt( iter, widget.getUI() ); + } + break; + case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.put( iter + 3, widget.getUB0() ); + userImage.put( iter + 2, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB2() ); + userImage.put( iter , widget.getUB3() ); + } else { + userImage.putInt( iter, widget.getUI() ); + } + break; + case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.put( iter + 3, widget.getUB0() ); + userImage.put( iter + 2, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB2() ); + userImage.put( iter ,widget.getUB3() ); + } else { + userImage.putInt( iter, widget.getUI() ); + } + break; + case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): + for( k = 0; k < 4; k++ ) { + shoveComponents[k] = oldImage.get( iter2++ ) / 65535.0f; + } + extract.shove( shoveComponents, 0, widget.getBuffer() ); + if( myswapBytes ) { + userImage.put( iter + 3, widget.getUB0() ); + userImage.put( iter + 2, widget.getUB2() ); + userImage.put( iter + 1, widget.getUB1() ); + userImage.put( iter , widget.getUB0() ); + } else { + userImage.putInt( iter, widget.getUI() ); + } + break; + case( GL2.GL_INT ): + case( GL2.GL_UNSIGNED_INT ): + case( GL2.GL_FLOAT ): + if( type == GL2.GL_FLOAT ) { + if( indexFormat ) { + widget.setF( oldImage.get( iter2++ ) ); + } else { + widget.setF( oldImage.get( iter2++ ) / 65535.0f ); + } + } else if( type == GL2.GL_UNSIGNED_INT ) { + if( indexFormat ) { + widget.setUI( oldImage.get( iter2++ ) ); + } else { + widget.setUI( oldImage.get( iter2++ ) * 65537 ); + } + } else { + if( indexFormat ) { + widget.setI( oldImage.get( iter2++ ) ); + } else { + widget.setI( ( oldImage.get( iter2++ ) * 65535 ) / 2 ); + } + } + if( myswapBytes ) { + userImage.put( iter + 3, widget.getUB0() ); + userImage.put( iter + 2, widget.getUB1() ); + userImage.put( iter + 1, widget.getUB2() ); + userImage.put( iter , widget.getUB3() ); + } else { + userImage.put( iter , widget.getUB0() ); + userImage.put( iter + 1, widget.getUB1() ); + userImage.put( iter + 2, widget.getUB2() ); + userImage.put( iter + 3, widget.getUB3() ); + } + break; + default: + assert( false ); + } + + iter += elementSize; + } // for jj + rowStart += rowSize; + } // for ii + start += imageSize; + } // for dd + + if( !Mipmap.isTypePackedPixel( type ) ) { + assert( iter2 == width * height * depth * components ); + } else { + assert( iter2 == width * height * depth * Mipmap.elements_per_group( format, 0 ) ); + } + assert( iter == rowSize * height * depth + + psm.getUnpackSkipRows() * rowSize + + psm.getUnpackSkipPixels() * groupSize + + psm.getUnpackSkipImages() * imageSize ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Mipmap.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Mipmap.java new file mode 100644 index 000000000..f38b62e37 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Mipmap.java @@ -0,0 +1,868 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.GL2GL3; +import javax.media.opengl.glu.GLU; +import javax.media.opengl.GLException; +import java.nio.*; +import com.jogamp.common.nio.Buffers; + +/** + * + * @author Administrator + */ +public class Mipmap { + + /** Creates a new instance of Mipmap */ + public Mipmap() { + } + + public static int computeLog( int value ) { + int i = 0; + // Error + if( value == 0 ) { + return( -1 ); + } + for( ;; ) { + if( (value & 1) >= 1 ) { + if( value != 1 ) { + return( -1 ); + } + return( i ); + } + value = value >> 1; + i++; + } + } + + /* Compute the nearest power of 2 number. This algorithm is a little strange + * but it works quite well. + */ + public static int nearestPower( int value ) { + int i = 1; + // Error! + if( value == 0 ) { + return( -1 ); + } + for( ;; ) { + if( value == 1 ) { + return( i ); + } else if( value == 3 ) { + return( i * 4 ); + } + value = value >> 1; + i *= 2; + } + } + + public static short GLU_SWAP_2_BYTES( short s ) { + byte b = 0; + b = (byte)( s >>> 8 ); + s = (short)( s << 8 ); + s = (short)( s | (0x00FF & b) ); + return( s ); + } + + public static int GLU_SWAP_4_BYTES( int i ) { + int t = i << 24; + t |= 0x00FF0000 & ( i << 8 ); + t |= 0x0000FF00 & ( i >>> 8 ); + t |= 0x000000FF & ( i >>> 24 ); + return( t ); + } + + public static float GLU_SWAP_4_BYTES( float f ) { + int i = Float.floatToRawIntBits( f ); + float temp = Float.intBitsToFloat( i ); + return( temp ); + } + + public static int checkMipmapArgs( int internalFormat, int format, int type ) { + if( !legalFormat( format ) || !legalType( type ) ) { + return( GLU.GLU_INVALID_ENUM ); + } + if( format == GL2GL3.GL_STENCIL_INDEX ) { + return( GLU.GLU_INVALID_ENUM ); + } + if( !isLegalFormatForPackedPixelType( format, type ) ) { + return( GLU.GLU_INVALID_OPERATION ); + } + return( 0 ); + } + + public static boolean legalFormat( int format ) { + switch( format ) { + case( GL2.GL_COLOR_INDEX ): + case( GL2GL3.GL_STENCIL_INDEX ): + case( GL2GL3.GL_DEPTH_COMPONENT ): + case( GL2GL3.GL_RED ): + case( GL2GL3.GL_GREEN ): + case( GL2GL3.GL_BLUE ): + case( GL2GL3.GL_ALPHA ): + case( GL2GL3.GL_RGB ): + case( GL2GL3.GL_RGBA ): + case( GL2GL3.GL_LUMINANCE ): + case( GL2GL3.GL_LUMINANCE_ALPHA ): + case( GL2GL3.GL_BGR ): + case( GL2GL3.GL_BGRA ): + return( true ); + default: + return( false ); + } + } + + public static boolean legalType( int type ) { + switch( type ) { + case( GL2.GL_BITMAP ): + case( GL2GL3.GL_BYTE ): + case( GL2GL3.GL_UNSIGNED_BYTE ): + case( GL2GL3.GL_SHORT ): + case( GL2GL3.GL_UNSIGNED_SHORT ): + case( GL2GL3.GL_INT ): + case( GL2GL3.GL_UNSIGNED_INT ): + case( GL2GL3.GL_FLOAT ): + case( GL2GL3.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + case( GL2GL3.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2GL3.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ): + return( true ); + default: + return( false ); + } + } + + public static boolean isTypePackedPixel( int type ) { + assert( legalType( type ) ); + + if( type == GL2GL3.GL_UNSIGNED_BYTE_3_3_2 || + type == GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5 || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 || + type == GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8 || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL2GL3.GL_UNSIGNED_INT_10_10_10_2 || + type == GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ) { + return( true ); + } + return( false ); + } + + public static boolean isLegalFormatForPackedPixelType( int format, int type ) { + // if not a packed pixel type then return true + if( isTypePackedPixel( type ) ) { + return( true ); + } + + // 3_3_2/2_3_3_REV & 5_6_5/5_6_5_REV are only compatible with RGB + if( (type == GL2GL3.GL_UNSIGNED_BYTE_3_3_2 || type == GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5 || type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV ) + & format != GL2GL3.GL_RGB ) { + return( false ); + } + + // 4_4_4_4/4_4_4_4_REV & 5_5_5_1/1_5_5_5_REV & 8_8_8_8/8_8_8_8_REV & + // 10_10_10_2/2_10_10_10_REV are only campatible with RGBA, BGRA & ARGB_EXT + if( ( type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 || + type == GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8 || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL2GL3.GL_UNSIGNED_INT_10_10_10_2 || + type == GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ) && + (format != GL2GL3.GL_RGBA && format != GL2GL3.GL_BGRA) ) { + return( false ); + } + return( true ); + } + + public static boolean isLegalLevels( int userLevel, int baseLevel, int maxLevel, + int totalLevels ) { + if( (baseLevel < 0) || (baseLevel < userLevel) || (maxLevel < baseLevel) || + (totalLevels < maxLevel) ) { + return( false ); + } + return( true ); + } + + /* Given user requested textures size, determine if it fits. If it doesn't then + * halve both sides and make the determination again until it does fit ( for + * IR only ). + * Note that proxy textures are not implemented in RE* even though they + * advertise the texture extension. + * Note that proxy textures are implemented but not according to spec in IMPACT* + */ + public static void closestFit( GL gl, int target, int width, int height, int internalFormat, + int format, int type, int[] newWidth, int[] newHeight ) { + // Use proxy textures if OpenGL version >= 1.1 + if( Double.parseDouble( gl.glGetString( GL.GL_VERSION ).trim().substring( 0, 3 ) ) >= 1.1 ) { + int widthPowerOf2 = nearestPower( width ); + int heightPowerOf2 = nearestPower( height ); + int[] proxyWidth = new int[1]; + boolean noProxyTextures = false; + + // Some drivers (in particular, ATI's) seem to set a GL error + // when proxy textures are used even though this is in violation + // of the spec. Guard against this and interactions with the + // DebugGL by watching for GLException. + try { + do { + // compute level 1 width & height, clamping each at 1 + int widthAtLevelOne = ( ( width > 1 ) ? (widthPowerOf2 >> 1) : widthPowerOf2 ); + int heightAtLevelOne = ( ( height > 1 ) ? (heightPowerOf2 >> 1) : heightPowerOf2 ); + int proxyTarget; + + assert( widthAtLevelOne > 0 ); + assert( heightAtLevelOne > 0 ); + + // does width x height at level 1 & all their mipmaps fit? + if( target == GL2GL3.GL_TEXTURE_2D || target == GL2GL3.GL_PROXY_TEXTURE_2D ) { + proxyTarget = GL2GL3.GL_PROXY_TEXTURE_2D; + gl.glTexImage2D( proxyTarget, 1, internalFormat, widthAtLevelOne, + heightAtLevelOne, 0, format, type, null ); + } else if( (target == GL2GL3.GL_TEXTURE_CUBE_MAP_POSITIVE_X) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_NEGATIVE_X) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_POSITIVE_Y) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_POSITIVE_Z) || + (target == GL2GL3.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) ) { + proxyTarget = GL2GL3.GL_PROXY_TEXTURE_CUBE_MAP; + gl.glTexImage2D( proxyTarget, 1, internalFormat, widthAtLevelOne, + heightAtLevelOne, 0, format, type, null ); + } else { + assert( target == GL2GL3.GL_TEXTURE_1D || target == GL2GL3.GL_PROXY_TEXTURE_1D ); + proxyTarget = GL2GL3.GL_PROXY_TEXTURE_1D; + gl.getGL2GL3().glTexImage1D( proxyTarget, 1, internalFormat, widthAtLevelOne, + 0, format, type, null ); + } + if(gl.isGL2GL3()) { + gl.getGL2GL3().glGetTexLevelParameteriv( proxyTarget, 1, GL2GL3.GL_TEXTURE_WIDTH, proxyWidth, 0 ); + } else { + proxyWidth[0] = 0; + } + // does it fit? + if( proxyWidth[0] == 0 ) { // nope, so try again with theses sizes + if( widthPowerOf2 == 1 && heightPowerOf2 == 1 ) { + /* A 1x1 texture couldn't fit for some reason so break out. This + * should never happen. But things happen. The disadvantage with + * this if-statement is that we will never be aware of when this + * happens since it will silently branch out. + */ + noProxyTextures = true; + break; + } + widthPowerOf2 = widthAtLevelOne; + heightPowerOf2 = heightAtLevelOne; + } + // else it does fit + } while( proxyWidth[0] == 0 ); + } catch (GLException e) { + noProxyTextures = true; + } + // loop must terminate + // return the width & height at level 0 that fits + if( !noProxyTextures ) { + newWidth[0] = widthPowerOf2; + newHeight[0] = heightPowerOf2; + return; + } + } + int[] maxsize = new int[1]; + gl.glGetIntegerv( GL2GL3.GL_MAX_TEXTURE_SIZE, maxsize , 0); + // clamp user's texture sizes to maximum sizes, if necessary + newWidth[0] = nearestPower( width ); + if( newWidth[0] > maxsize[0] ) { + newWidth[0] = maxsize[0]; + } + newHeight[0] = nearestPower( height ); + if( newHeight[0] > maxsize[0] ) { + newHeight[0] = maxsize[0]; + } + } + + public static void closestFit3D( GL gl, int target, int width, int height, int depth, + int internalFormat, int format, int type, int[] newWidth, int[] newHeight, + int[] newDepth ) { + int widthPowerOf2 = nearestPower( width ); + int heightPowerOf2 = nearestPower( height ); + int depthPowerOf2 = nearestPower( depth ); + int[] proxyWidth = new int[1]; + + do { + // compute level 1 width & height & depth, clamping each at 1 + int widthAtLevelOne = (widthPowerOf2 > 1) ? widthPowerOf2 >> 1 : widthPowerOf2; + int heightAtLevelOne = (heightPowerOf2 > 1) ? heightPowerOf2 >> 1 : heightPowerOf2; + int depthAtLevelOne = (depthPowerOf2 > 1) ? depthPowerOf2 >> 1 : depthPowerOf2; + int proxyTarget = 0; + assert( widthAtLevelOne > 0 ); + assert( heightAtLevelOne > 0 ); + assert( depthAtLevelOne > 0 ); + + // does width x height x depth at level 1 & all their mipmaps fit? + if( target == GL2GL3.GL_TEXTURE_3D || target == GL2GL3.GL_PROXY_TEXTURE_3D ) { + proxyTarget = GL2GL3.GL_PROXY_TEXTURE_3D; + gl.getGL2GL3().glTexImage3D( proxyTarget, 1, internalFormat, widthAtLevelOne, + heightAtLevelOne, depthAtLevelOne, 0, format, type, null ); + } + if(gl.isGL2GL3()) { + gl.getGL2GL3().glGetTexLevelParameteriv( proxyTarget, 1, GL2GL3.GL_TEXTURE_WIDTH, proxyWidth, 0 ); + } else { + proxyWidth[0] = 0; + } + // does it fit + if( proxyWidth[0] == 0 ) { + if( widthPowerOf2 == 1 && heightPowerOf2 == 1 && depthPowerOf2 == 1 ) { + newWidth[0] = newHeight[0] = newDepth[0] = 1; + return; + } + widthPowerOf2 = widthAtLevelOne; + heightPowerOf2 = heightAtLevelOne; + depthPowerOf2 = depthAtLevelOne; + } + } while( proxyWidth[0] == 0 ); + // loop must terminate + + // return the width & height at level 0 that fits + newWidth[0] = widthPowerOf2; + newHeight[0] = heightPowerOf2; + newDepth[0] = depthPowerOf2; + } + + public static int elements_per_group( int format, int type ) { + // Return the number of elements per grtoup of a specified gromat + + // If the type is packedpixels then answer is 1 + if( type == GL2GL3.GL_UNSIGNED_BYTE_3_3_2 || + type == GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5 || + type == GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 || + type == GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV || + type == GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 || + type == GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8 || + type == GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL2GL3.GL_UNSIGNED_INT_10_10_10_2 || + type == GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ) { + return( 1 ); + } + + // Types are not packed pixels so get elements per group + switch( format ) { + case( GL2GL3.GL_RGB ): + case( GL2GL3.GL_BGR ): + return( 3 ); + case( GL2GL3.GL_LUMINANCE_ALPHA ): + return( 2 ); + case( GL2GL3.GL_RGBA ): + case( GL2GL3.GL_BGRA ): + return( 4 ); + default: + return( 1 ); + } + } + + public static int bytes_per_element( int type ) { + // return the number of bytes per element, based on the element type + + switch( type ) { + case( GL2.GL_BITMAP ): + case( GL2GL3.GL_BYTE ): + case( GL2GL3.GL_UNSIGNED_BYTE ): + case( GL2GL3.GL_UNSIGNED_BYTE_3_3_2 ): + case( GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV ): + return( 1 ); + case( GL2GL3.GL_SHORT ): + case( GL2GL3.GL_UNSIGNED_SHORT ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_6_5 ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4 ): + case( GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV ): + case( GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1 ): + case( GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV ): + return( 2 ); + case( GL2GL3.GL_INT ): + case( GL2GL3.GL_UNSIGNED_INT ): + case( GL2GL3.GL_UNSIGNED_INT_8_8_8_8 ): + case( GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV ): + case( GL2GL3.GL_UNSIGNED_INT_10_10_10_2 ): + case( GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV ): + case( GL2GL3.GL_FLOAT ): + return( 4 ); + default: + return( 4 ); + } + } + + public static boolean is_index( int format ) { + return( format == GL2.GL_COLOR_INDEX || format == GL2GL3.GL_STENCIL_INDEX ); + } + + /* Compute memory required for internal packed array of data of given type and format. */ + + public static int image_size( int width, int height, int format, int type ) { + int bytes_per_row; + int components; + + assert( width > 0 ); + assert( height > 0 ); + components = elements_per_group( format, type ); + if( type == GL2.GL_BITMAP ) { + bytes_per_row = (width + 7) / 8; + } else { + bytes_per_row = bytes_per_element( type ) * width; + } + return( bytes_per_row * height * components ); + } + + public static int imageSize3D( int width, int height, int depth, int format, int type ) { + int components = elements_per_group( format, type ); + int bytes_per_row = bytes_per_element( type ) * width; + + assert( width > 0 && height > 0 && depth > 0 ); + assert( type != GL2.GL_BITMAP ); + + return( bytes_per_row * height * depth * components ); + } + + public static void retrieveStoreModes( GL gl, PixelStorageModes psm ) { + int[] a = new int[1]; + gl.glGetIntegerv( GL2GL3.GL_UNPACK_ALIGNMENT, a, 0); + psm.setUnpackAlignment( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_ROW_LENGTH, a, 0); + psm.setUnpackRowLength( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_ROWS, a, 0); + psm.setUnpackSkipRows( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_PIXELS, a, 0); + psm.setUnpackSkipPixels( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_LSB_FIRST, a, 0); + psm.setUnpackLsbFirst( ( a[0] == 1 ) ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SWAP_BYTES, a, 0); + psm.setUnpackSwapBytes( ( a[0] == 1 ) ); + + gl.glGetIntegerv( GL2GL3.GL_PACK_ALIGNMENT, a, 0); + psm.setPackAlignment( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_PACK_ROW_LENGTH, a, 0); + psm.setPackRowLength( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_ROWS, a, 0); + psm.setPackSkipRows( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_PIXELS, a, 0); + psm.setPackSkipPixels( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_PACK_LSB_FIRST, a, 0); + psm.setPackLsbFirst( ( a[0] == 1 ) ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SWAP_BYTES, a, 0); + psm.setPackSwapBytes( ( a[0] == 1 ) ); + } + + public static void retrieveStoreModes3D( GL gl, PixelStorageModes psm ) { + int[] a = new int[1]; + gl.glGetIntegerv( GL2GL3.GL_UNPACK_ALIGNMENT, a, 0); + psm.setUnpackAlignment( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_ROW_LENGTH, a, 0); + psm.setUnpackRowLength( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_ROWS, a, 0); + psm.setUnpackSkipRows( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_PIXELS, a, 0); + psm.setUnpackSkipPixels( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_LSB_FIRST, a, 0); + psm.setUnpackLsbFirst( ( a[0] == 1 ) ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SWAP_BYTES, a, 0); + psm.setUnpackSwapBytes( ( a[0] == 1 ) ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_SKIP_IMAGES, a, 0); + psm.setUnpackSkipImages( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_UNPACK_IMAGE_HEIGHT, a, 0); + psm.setUnpackImageHeight( a[0] ); + + gl.glGetIntegerv( GL2GL3.GL_PACK_ALIGNMENT, a, 0); + psm.setPackAlignment( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_PACK_ROW_LENGTH, a, 0); + psm.setPackRowLength( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_ROWS, a, 0); + psm.setPackSkipRows( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_PIXELS, a, 0 ); + psm.setPackSkipPixels( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_PACK_LSB_FIRST, a, 0 ); + psm.setPackLsbFirst( ( a[0] == 1 ) ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SWAP_BYTES, a, 0 ); + psm.setPackSwapBytes( ( a[0] == 1 ) ); + gl.glGetIntegerv( GL2GL3.GL_PACK_SKIP_IMAGES, a, 0 ); + psm.setPackSkipImages( a[0] ); + gl.glGetIntegerv( GL2GL3.GL_PACK_IMAGE_HEIGHT, a, 0 ); + psm.setPackImageHeight( a[0] ); + } + + public static int gluScaleImage( GL gl, int format, int widthin, int heightin, + int typein, ByteBuffer datain, int widthout, int heightout, + int typeout, ByteBuffer dataout ) { + int datainPos = datain.position(); + int dataoutPos = dataout.position(); + try { + + int components; + ByteBuffer beforeimage; + ByteBuffer afterimage; + PixelStorageModes psm = new PixelStorageModes(); + + if( (widthin == 0) || (heightin == 0) || (widthout == 0) || (heightout == 0) ) { + return( 0 ); + } + if( (widthin < 0) || (heightin < 0) || (widthout < 0) || (heightout < 0) ) { + return( GLU.GLU_INVALID_VALUE ); + } + if( !legalFormat( format ) || !legalType( typein ) || !legalType( typeout ) ) { + return( GLU.GLU_INVALID_ENUM ); + } + if( !isLegalFormatForPackedPixelType( format, typein ) ) { + return( GLU.GLU_INVALID_OPERATION ); + } + if( !isLegalFormatForPackedPixelType( format, typeout ) ) { + return( GLU.GLU_INVALID_OPERATION ); + } + beforeimage = Buffers.newDirectByteBuffer( image_size( widthin, heightin, format, GL2GL3.GL_UNSIGNED_SHORT ) ); + afterimage = Buffers.newDirectByteBuffer( image_size( widthout, heightout, format, GL2GL3.GL_UNSIGNED_SHORT ) ); + if( beforeimage == null || afterimage == null ) { + return( GLU.GLU_OUT_OF_MEMORY ); + } + + retrieveStoreModes( gl, psm ); + Image.fill_image( psm, widthin, heightin, format, typein, is_index( format ), datain, beforeimage.asShortBuffer() ); + components = elements_per_group( format, 0 ); + ScaleInternal.scale_internal( components, widthin, heightin, beforeimage.asShortBuffer(), widthout, heightout, afterimage.asShortBuffer() ); + Image.empty_image( psm, widthout, heightout, format, typeout, is_index( format ), afterimage.asShortBuffer(), dataout ); + + return( 0 ); + } finally { + datain.position(datainPos); + dataout.position(dataoutPos); + } + } + + public static int gluBuild1DMipmapLevels( GL gl, int target, int internalFormat, + int width, int format, int type, int userLevel, int baseLevel, + int maxLevel, ByteBuffer data ) { + int dataPos = data.position(); + try { + + int levels; + + int rc = checkMipmapArgs( internalFormat, format, type ); + if( rc != 0 ) { + return( rc ); + } + + if( width < 1 ) { + return( GLU.GLU_INVALID_VALUE ); + } + + levels = computeLog( width ); + + levels += userLevel; + if( !isLegalLevels( userLevel, baseLevel, maxLevel, levels ) ) { + return( GLU.GLU_INVALID_VALUE ); + } + + return( BuildMipmap.gluBuild1DMipmapLevelsCore( gl, target, internalFormat, width, + width, format, type, userLevel, baseLevel, maxLevel, data ) ); + } finally { + data.position(dataPos); + } + } + + public static int gluBuild1DMipmaps( GL gl, int target, int internalFormat, int width, + int format, int type, ByteBuffer data ) { + int dataPos = data.position(); + + try { + int[] widthPowerOf2 = new int[1]; + int levels; + int[] dummy = new int[1]; + + int rc = checkMipmapArgs( internalFormat, format, type ); + if( rc != 0 ) { + return( rc ); + } + + if( width < 1 ) { + return( GLU.GLU_INVALID_VALUE ); + } + + closestFit( gl, target, width, 1, internalFormat, format, type, widthPowerOf2, dummy ); + levels = computeLog( widthPowerOf2[0] ); + + return( BuildMipmap.gluBuild1DMipmapLevelsCore( gl, target, internalFormat, + width, widthPowerOf2[0], format, type, 0, 0, levels, data ) ); + } finally { + data.position(dataPos); + } + } + + + public static int gluBuild2DMipmapLevels( GL gl, int target, int internalFormat, + int width, int height, int format, int type, int userLevel, + int baseLevel, int maxLevel, Object data ) { + int dataPos = 0; + + int level, levels; + + int rc = checkMipmapArgs( internalFormat, format, type ); + if( rc != 0 ) { + return( rc ); + } + + if( width < 1 || height < 1 ) { + return( GLU.GLU_INVALID_VALUE ); + } + + levels = computeLog( width ); + level = computeLog( height ); + if( level > levels ) { + levels = level; + } + + levels += userLevel; + if( !isLegalLevels( userLevel, baseLevel, maxLevel, levels ) ) { + return( GLU.GLU_INVALID_VALUE ); + } + + //PointerWrapper pointer = PointerWrapperFactory.getPointerWrapper( data ); + ByteBuffer buffer = null; + if( data instanceof ByteBuffer ) { + buffer = (ByteBuffer)data; + dataPos = buffer.position(); + } else if( data instanceof byte[] ) { + byte[] array = (byte[])data; + buffer = ByteBuffer.allocateDirect(array.length); + buffer.put(array); + } else if( data instanceof short[] ) { + short[] array = (short[])data; + buffer = ByteBuffer.allocateDirect( array.length * 2 ); + ShortBuffer sb = buffer.asShortBuffer(); + sb.put( array ); + } else if( data instanceof int[] ) { + int[] array = (int[])data; + buffer = ByteBuffer.allocateDirect( array.length * 4 ); + IntBuffer ib = buffer.asIntBuffer(); + ib.put( array ); + } else if( data instanceof float[] ) { + float[] array = (float[])data; + buffer = ByteBuffer.allocateDirect( array.length * 4 ); + FloatBuffer fb = buffer.asFloatBuffer(); + fb.put( array ); + } + + try { + return( BuildMipmap.gluBuild2DMipmapLevelsCore( gl, target, internalFormat, + width, height, width, height, format, type, userLevel, baseLevel, + maxLevel, buffer ) ); + } finally { + buffer.position(dataPos); + } + } + + + public static int gluBuild2DMipmaps( GL gl, int target, int internalFormat, + int width, int height, int format, int type, Object data ) { + int dataPos = 0; + + int[] widthPowerOf2 = new int[1]; + int[] heightPowerOf2 = new int[1]; + int level, levels; + + int rc = checkMipmapArgs( internalFormat, format, type ); + if( rc != 0 ) { + return( rc ); + } + + if( width < 1 || height < 1 ) { + return( GLU.GLU_INVALID_VALUE ); + } + + closestFit( gl, target, width, height, internalFormat, format, type, + widthPowerOf2, heightPowerOf2 ); + + levels = computeLog( widthPowerOf2[0] ); + level = computeLog( heightPowerOf2[0] ); + if( level > levels ) { + levels = level; + } + + //PointerWrapper pointer = PointerWrapperFactory.getPointerWrapper( data ); + ByteBuffer buffer = null; + if( data instanceof ByteBuffer ) { + buffer = (ByteBuffer)data; + dataPos = buffer.position(); + } else if( data instanceof byte[] ) { + byte[] array = (byte[])data; + buffer = ByteBuffer.allocateDirect(array.length); + buffer.put(array); + } else if( data instanceof short[] ) { + short[] array = (short[])data; + buffer = ByteBuffer.allocateDirect( array.length * 2 ); + ShortBuffer sb = buffer.asShortBuffer(); + sb.put( array ); + } else if( data instanceof int[] ) { + int[] array = (int[])data; + buffer = ByteBuffer.allocateDirect( array.length * 4 ); + IntBuffer ib = buffer.asIntBuffer(); + ib.put( array ); + } else if( data instanceof float[] ) { + float[] array = (float[])data; + buffer = ByteBuffer.allocateDirect( array.length * 4 ); + FloatBuffer fb = buffer.asFloatBuffer(); + fb.put( array ); + } + + try { + return( BuildMipmap.gluBuild2DMipmapLevelsCore( gl, target, internalFormat, + width, height, widthPowerOf2[0], heightPowerOf2[0], format, type, 0, + 0, levels, buffer ) ); + } finally { + buffer.position(dataPos); + } + } + + + public static int gluBuild3DMipmaps( GL gl, int target, int internalFormat, + int width, int height, int depth, int format, int type, ByteBuffer data ) { + int dataPos = data.position(); + try { + + int[] widthPowerOf2 = new int[1]; + int[] heightPowerOf2 = new int[1]; + int[] depthPowerOf2 = new int[1]; + int level, levels; + + int rc = checkMipmapArgs( internalFormat, format, type ); + if( rc != 0 ) { + return( rc ); + } + + if( width < 1 || height < 1 || depth < 1 ) { + return( GLU.GLU_INVALID_VALUE ); + } + + if( type == GL2.GL_BITMAP ) { + return( GLU.GLU_INVALID_ENUM ); + } + + closestFit3D( gl, target, width, height, depth, internalFormat, format, + type, widthPowerOf2, heightPowerOf2, depthPowerOf2 ); + + levels = computeLog( widthPowerOf2[0] ); + level = computeLog( heightPowerOf2[0] ); + if( level > levels ) { + levels = level; + } + level = computeLog( depthPowerOf2[0] ); + if( level > levels ) { + levels = level; + } + + return( BuildMipmap.gluBuild3DMipmapLevelsCore( gl, target, internalFormat, width, + height, depth, widthPowerOf2[0], heightPowerOf2[0], depthPowerOf2[0], + format, type, 0, 0, levels, data ) ); + } finally { + data.position(dataPos); + } + } + + public static int gluBuild3DMipmapLevels( GL gl, int target, int internalFormat, + int width, int height, int depth, int format, int type, int userLevel, + int baseLevel, int maxLevel, ByteBuffer data ) { + int dataPos = data.position(); + try { + int level, levels; + + int rc = checkMipmapArgs( internalFormat, format, type ); + if( rc != 0 ) { + return( rc ); + } + + if( width < 1 || height < 1 || depth < 1 ) { + return( GLU.GLU_INVALID_VALUE ); + } + + if( type == GL2.GL_BITMAP ) { + return( GLU.GLU_INVALID_ENUM ); + } + + levels = computeLog( width ); + level = computeLog( height ); + if( level > levels ) { + levels = level; + } + level = computeLog( depth ); + if( level > levels ) { + levels = level; + } + + levels += userLevel; + if( !isLegalLevels( userLevel, baseLevel, maxLevel, levels ) ) { + return( GLU.GLU_INVALID_VALUE ); + } + + return( BuildMipmap.gluBuild3DMipmapLevelsCore( gl, target, internalFormat, width, + height, depth, width, height, depth, format, type, userLevel, + baseLevel, maxLevel, data ) ); + } finally { + data.position(dataPos); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/PixelStorageModes.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/PixelStorageModes.java new file mode 100644 index 000000000..0b1af8323 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/PixelStorageModes.java @@ -0,0 +1,426 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +/** + * + * @author Administrator + */ +public class PixelStorageModes { + + /** + * Holds value of property packAlignment. + */ + private int packAlignment; + + /** + * Holds value of property packRowLength. + */ + private int packRowLength; + + /** + * Holds value of property packSkipRows. + */ + private int packSkipRows; + + /** + * Holds value of property packSkipPixels. + */ + private int packSkipPixels; + + /** + * Holds value of property packLsbFirst. + */ + private boolean packLsbFirst; + + /** + * Holds value of property packSwapBytes. + */ + private boolean packSwapBytes; + + /** + * Holds value of property packSkipImages. + */ + private int packSkipImages; + + /** + * Holds value of property packImageHeight. + */ + private int packImageHeight; + + /** + * Holds value of property unpackAlignment. + */ + private int unpackAlignment; + + /** + * Holds value of property unpackRowLength. + */ + private int unpackRowLength; + + /** + * Holds value of property unpackSkipRows. + */ + private int unpackSkipRows; + + /** + * Holds value of property unpackSkipPixels. + */ + private int unpackSkipPixels; + + /** + * Holds value of property unpackLsbFirst. + */ + private boolean unpackLsbFirst; + + /** + * Holds value of property unpackSwapBytes. + */ + private boolean unpackSwapBytes; + + /** + * Holds value of property unpackSkipImages. + */ + private int unpackSkipImages; + + /** + * Holds value of property unpackImageHeight. + */ + private int unpackImageHeight; + + /** Creates a new instance of PixelStorageModes */ + public PixelStorageModes() { + } + + /** + * Getter for property packAlignment. + * @return Value of property packAlignment. + */ + public int getPackAlignment() { + + return this.packAlignment; + } + + /** + * Setter for property packAlignment. + * @param packAlignment New value of property packAlignment. + */ + public void setPackAlignment(int packAlignment) { + + this.packAlignment = packAlignment; + } + + /** + * Getter for property packRowLength. + * @return Value of property packRowLength. + */ + public int getPackRowLength() { + + return this.packRowLength; + } + + /** + * Setter for property packRowLength. + * @param packRowLength New value of property packRowLength. + */ + public void setPackRowLength(int packRowLength) { + + this.packRowLength = packRowLength; + } + + /** + * Getter for property packSkipRows. + * @return Value of property packSkipRows. + */ + public int getPackSkipRows() { + + return this.packSkipRows; + } + + /** + * Setter for property packSkipRows. + * @param packSkipRows New value of property packSkipRows. + */ + public void setPackSkipRows(int packSkipRows) { + + this.packSkipRows = packSkipRows; + } + + /** + * Getter for property packSkipPixels. + * @return Value of property packSkipPixels. + */ + public int getPackSkipPixels() { + + return this.packSkipPixels; + } + + /** + * Setter for property packSkipPixels. + * @param packSkipPixels New value of property packSkipPixels. + */ + public void setPackSkipPixels(int packSkipPixels) { + + this.packSkipPixels = packSkipPixels; + } + + /** + * Getter for property packLsbFirst. + * @return Value of property packLsbFirst. + */ + public boolean getPackLsbFirst() { + + return this.packLsbFirst; + } + + /** + * Setter for property packLsbFirst. + * @param packLsbFirst New value of property packLsbFirst. + */ + public void setPackLsbFirst(boolean packLsbFirst) { + + this.packLsbFirst = packLsbFirst; + } + + /** + * Getter for property packSwapBytes. + * @return Value of property packSwapBytes. + */ + public boolean getPackSwapBytes() { + + return this.packSwapBytes; + } + + /** + * Setter for property packSwapBytes. + * @param packSwapBytes New value of property packSwapBytes. + */ + public void setPackSwapBytes(boolean packSwapBytes) { + + this.packSwapBytes = packSwapBytes; + } + + /** + * Getter for property packSkipImages. + * @return Value of property packSkipImages. + */ + public int getPackSkipImages() { + + return this.packSkipImages; + } + + /** + * Setter for property packSkipImages. + * @param packSkipImages New value of property packSkipImages. + */ + public void setPackSkipImages(int packSkipImages) { + + this.packSkipImages = packSkipImages; + } + + /** + * Getter for property packImageHeight. + * @return Value of property packImageHeight. + */ + public int getPackImageHeight() { + + return this.packImageHeight; + } + + /** + * Setter for property packImageHeight. + * @param packImageHeight New value of property packImageHeight. + */ + public void setPackImageHeight(int packImageHeight) { + + this.packImageHeight = packImageHeight; + } + + /** + * Getter for property unpackAlignment. + * @return Value of property unpackAlignment. + */ + public int getUnpackAlignment() { + + return this.unpackAlignment; + } + + /** + * Setter for property unpackAlignment. + * @param unpackAlignment New value of property unpackAlignment. + */ + public void setUnpackAlignment(int unpackAlignment) { + + this.unpackAlignment = unpackAlignment; + } + + /** + * Getter for property unpackRowLength. + * @return Value of property unpackRowLength. + */ + public int getUnpackRowLength() { + + return this.unpackRowLength; + } + + /** + * Setter for property unpackRowLength. + * @param unpackRowLength New value of property unpackRowLength. + */ + public void setUnpackRowLength(int unpackRowLength) { + + this.unpackRowLength = unpackRowLength; + } + + /** + * Getter for property unpackSkipRows. + * @return Value of property unpackSkipRows. + */ + public int getUnpackSkipRows() { + + return this.unpackSkipRows; + } + + /** + * Setter for property unpackSkipRows. + * @param unpackSkipRows New value of property unpackSkipRows. + */ + public void setUnpackSkipRows(int unpackSkipRows) { + + this.unpackSkipRows = unpackSkipRows; + } + + /** + * Getter for property unpackSkipPixels. + * @return Value of property unpackSkipPixels. + */ + public int getUnpackSkipPixels() { + + return this.unpackSkipPixels; + } + + /** + * Setter for property unpackSkipPixels. + * @param unpackSkipPixels New value of property unpackSkipPixels. + */ + public void setUnpackSkipPixels(int unpackSkipPixels) { + + this.unpackSkipPixels = unpackSkipPixels; + } + + /** + * Getter for property unpackLsbFirst. + * @return Value of property unpackLsbFirst. + */ + public boolean getUnpackLsbFirst() { + + return this.unpackLsbFirst; + } + + /** + * Setter for property unpackLsbFirst. + * @param unpackLsbFirst New value of property unpackLsbFirst. + */ + public void setUnpackLsbFirst(boolean unpackLsbFirst) { + + this.unpackLsbFirst = unpackLsbFirst; + } + + /** + * Getter for property unpackSwapBytes. + * @return Value of property unpackSwapBytes. + */ + public boolean getUnpackSwapBytes() { + + return this.unpackSwapBytes; + } + + /** + * Setter for property unpackSwapBytes. + * @param unpackSwapBytes New value of property unpackSwapBytes. + */ + public void setUnpackSwapBytes(boolean unpackSwapBytes) { + + this.unpackSwapBytes = unpackSwapBytes; + } + + /** + * Getter for property unpackSkipImages. + * @return Value of property unpackSkipImages. + */ + public int getUnpackSkipImages() { + + return this.unpackSkipImages; + } + + /** + * Setter for property unpackSkipImages. + * @param unpackSkipImages New value of property unpackSkipImages. + */ + public void setUnpackSkipImages(int unpackSkipImages) { + + this.unpackSkipImages = unpackSkipImages; + } + + /** + * Getter for property unpackImageHeight. + * @return Value of property unpackImageHeight. + */ + public int getUnpackImageHeight() { + + return this.unpackImageHeight; + } + + /** + * Setter for property unpackImageHeight. + * @param unpackImageHeight New value of property unpackImageHeight. + */ + public void setUnpackImageHeight(int unpackImageHeight) { + + this.unpackImageHeight = unpackImageHeight; + } + + +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/ScaleInternal.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/ScaleInternal.java new file mode 100644 index 000000000..5f086ceff --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/ScaleInternal.java @@ -0,0 +1,2447 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.glu.GLU; +import java.nio.*; +import com.jogamp.common.nio.Buffers; + +/** + * + * @author Administrator + */ +public class ScaleInternal { + + public static final float UINT_MAX = (float)(0x00000000FFFFFFFF); + + public static void scale_internal( int components, int widthin, int heightin, + ShortBuffer datain, int widthout, int heightout, ShortBuffer dataout ) { + float x, lowx, highx, convx, halfconvx; + float y, lowy, highy, convy, halfconvy; + float xpercent, ypercent; + float percent; + // Max components in a format is 4, so... + float[] totals = new float[4]; + float area; + int i, j, k, yint, xint, xindex, yindex; + int temp; + + if( (widthin == (widthout * 2)) && (heightin == (heightout * 2)) ) { + HalveImage.halveImage( components, widthin, heightin, datain, dataout ); + return; + } + convy = (float)heightin / heightout; + convx = (float)widthin / widthout; + halfconvx = convx / 2; + halfconvy = convy / 2; + for( i = 0; i < heightout; i++ ) { + y = convy * ( i + 0.5f ); + if( heightin > heightout ) { + highy = y + halfconvy; + lowy = y - halfconvy; + } else { + highy = y + 0.5f; + lowy = y - 0.5f; + } + for( j = 0; j < widthout; j++ ) { + x = convx * ( j + 0.5f ); + if( widthin > widthout ) { + highx = x + halfconvx; + lowx = x - halfconvx; + } else { + highx = x + 0.5f; + lowx = x - 0.5f; + } + // Ok, now apply box filter to box that goes from (lowx, lowy) + // to (highx, highy) on input data into this pixel on output + // data. + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + area = 0.0f; + + y = lowy; + yint = (int)Math.floor( y ); + while( y < highy ) { + yindex = ( yint + heightin ) % heightin; + if( highy < yint + 1 ) { + ypercent = highy - y; + } else { + ypercent = yint + 1 - y; + } + + x = lowx; + xint = (int)Math.floor( x ); + + while( x < highx ) { + xindex = ( xint + widthin ) % widthin; + if( highx < xint + 1 ) { + xpercent = highx -x; + } else { + xpercent = xint + 1 - x; + } + + percent = xpercent * ypercent; + area += percent; + temp = ( xindex + ( yindex * widthin) ) * components; + for( k = 0; k < components; k++ ) { + totals[k] += datain.get( temp + k ) * percent; + } + + xint++; + x = xint; + } + yint++; + y = yint; + } + + temp = ( j + ( i * widthout ) ) * components; + for( k = 0; k < components; k++ ) { + // totals[] should be rounded in the case of enlarging an RGB + // ramp when the type is 332 or 4444 + dataout.put( temp + k, (short)((totals[k] + 0.5f) / area) ); + } + } + } + } + + public static void scale_internal_ubyte( int components, int widthin, int heightin, + ByteBuffer datain, int widthout, int heightout, + ByteBuffer dataout, int element_size, int ysize, int group_size ) { + float x, convx; + float y, convy; + float percent; + // Max components in a format is 4, so... + float[] totals = new float[4]; + float area; + int i, j, k, xindex; + + int temp, temp0; + int temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + int left, right; + + if( (widthin == (widthout * 2)) && (heightin == (heightout * 2)) ) { + HalveImage.halveImage_ubyte( components, widthin, heightin, datain, dataout, + element_size, ysize, group_size ); + return; + } + convy = (float)heightin / heightout; + convx = (float)widthin / widthout; + convy_int = (int)Math.floor( convy ); + convy_float = convy - convy_int; + convx_int = (int)Math.floor( convx ); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0.0f; + highy_int = convy_int; + highy_float = convy_float; + + for( i = 0; i < heightout; i++ ) { + // Clamp here to be sure we don't read beyond input buffer. + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0.0f; + highx_int = convx_int; + highx_float = convx_float; + + for( j = 0; j < widthout; j++ ) { + + // Ok, now apply box filter to box that goes from (lowx, lowy) + // to (highx, highy) on input data into this pixel on output + // data. + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + + // caulate the value for pixels in the 1st row + xindex = lowx_int * group_size; + + if( ( highy_int > lowy_int ) && ( highx_int > lowx_int ) ) { + + y_percent = 1 - lowy_float; + temp = xindex + lowy_int * ysize; + percent = y_percent * ( 1 - lowx_float ); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * percent; + } + left = temp; + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * y_percent; + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * percent; + } + + // calculate the value for pixels in the last row + y_percent = highy_float; + percent = y_percent * ( 1 - lowx_float ); + temp = xindex + highy_int * ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * percent; + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * y_percent; + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * percent; + } + + // calculate the value for the pixels in the 1st and last column + for( m = lowy_int + 1; m < highy_int; m++ ) { + left += ysize; + right += ysize; + for( k = 0; k < components; k++, left += element_size, right += element_size ) { + float f = 0.0f; + datain.position( left ); + f = ( 0x000000FF & datain.get() ) * ( 1.0f - lowx_float ); + datain.position( right ); + f += ( 0x000000FF & datain.get() ) * highx_float; + totals[k] += f; + } + } + } else if( highy_int > lowy_int ) { + x_percent = highx_float - lowx_float; + percent = ( 1 - lowy_float) * x_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * percent; + } + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * x_percent; + } + } + percent = x_percent * highy_float; + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * percent; + } + } else if( highx_int > lowx_int ) { + y_percent = highy_float - lowy_float; + percent = ( 1 - lowx_float ) * y_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * percent; + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * y_percent; + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * percent; + } + } else { + percent = ( highy_float - lowy_float ) * ( highx_float - lowx_float ); + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ) * percent; + } + } + + // this is for the pixels in the body + temp0 = xindex + group_size + ( lowy_int + 1 ) * ysize; + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp = temp0; + for( l = lowx_int + 1; l < highx_int; l++ ) { + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += ( 0x000000FF & datain.get() ); + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = ( j + ( i * widthout ) ) * components; + for( k = 0; k < components; k++ ) { + dataout.position( outindex + k ); + dataout.put( (byte)(totals[k] / area) ); + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if( highx_float > 1.0f ) { + highx_float -= 1.0f; + highx_int++; + } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if( highy_float > 1.0f ) { + highy_float -= 1.0f; + highy_int++; + } + } + } + + public static void scale_internal_byte( int components, int widthin, int heightin, + ByteBuffer datain, int widthout, int heightout, + ByteBuffer dataout, int element_size, int ysize, + int group_size ) { + float x, convx; + float y, convy; + float percent; + // Max components in a format is 4, so... + float[] totals = new float[4]; + float area; + int i, j, k, xindex; + + int temp, temp0; + int temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + int left, right; + + if( (widthin == (widthout * 2)) && (heightin == (heightout * 2)) ) { + HalveImage.halveImage_byte( components, widthin, heightin, datain, dataout, + element_size, ysize, group_size ); + return; + } + convy = (float)heightin / heightout; + convx = (float)widthin / widthout; + convy_int = (int)Math.floor( convy ); + convy_float = convy - convy_int; + convx_int = (int)Math.floor( convx ); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0.0f; + highy_int = convy_int; + highy_float = convy_float; + + for( i = 0; i < heightout; i++ ) { + // Clamp here to be sure we don't read beyond input buffer. + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0.0f; + highx_int = convx_int; + highx_float = convx_float; + + for( j = 0; j < widthout; j++ ) { + + // Ok, now apply box filter to box that goes from (lowx, lowy) + // to (highx, highy) on input data into this pixel on output + // data. + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + + // caulate the value for pixels in the 1st row + xindex = lowx_int * group_size; + if( ( highy_int > lowy_int ) && ( highx_int > lowx_int ) ) { + + y_percent = 1 - lowy_float; + temp = xindex + lowy_int * ysize; + percent = y_percent * ( 1 - lowx_float ); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * percent; + } + left = temp; + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * y_percent; + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * percent; + } + + // calculate the value for pixels in the last row + y_percent = highy_float; + percent = y_percent * ( 1 - lowx_float ); + temp = xindex + highy_int * ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * percent; + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * y_percent; + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * percent; + } + + // calculate the value for the pixels in the 1st and last column + for( m = lowy_int + 1; m < highy_int; m++ ) { + left += ysize; + right += ysize; + for( k = 0; k < components; k++, left += element_size, right += element_size ) { + float f = 0.0f; + datain.position( left ); + f = datain.get() * ( 1 - lowx_float ); + datain.position( right ); + f += datain.get() * highx_float; + totals[k] += f; + } + } + } else if( highy_int > lowy_int ) { + x_percent = highx_float - lowx_float; + percent = ( 1 - lowy_float) * x_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * percent; + } + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * x_percent; + } + } + percent = x_percent * highy_float; + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * percent; + } + } else if( highx_int > lowx_int ) { + y_percent = highy_float - lowy_float; + percent = ( 1 - lowx_float ) * y_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * percent; + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * y_percent; + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * percent; + } + } else { + percent = ( highy_float - lowy_float ) * ( highx_float - lowx_float ); + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get() * percent; + } + } + + // this is for the pixels in the body + temp0 = xindex + group_size + ( lowy_int + 1 ) * ysize; + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp = temp0; + for( l = lowx_int + 1; l < highx_int; l++ ) { + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + totals[k] += datain.get(); + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = ( j + ( i * widthout ) ) * components; + for( k = 0; k < components; k++ ) { + dataout.position( outindex + k ); + dataout.put( (byte)(totals[k] / area) ); + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if( highx_float > 1.0f ) { + highx_float -= 1.0f; + highx_int++; + } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if( highy_float > 1.0f ) { + highy_float -= 1.0f; + highy_int++; + } + } + } + + public static void scale_internal_ushort( int components, int widthin, int heightin, + ByteBuffer datain, int widthout, int heightout, + ShortBuffer dataout, int element_size, int ysize, + int group_size, boolean myswap_bytes ) { + float x, convx; + float y, convy; + float percent; + // Max components in a format is 4, so... + float[] totals = new float[4]; + float area; + int i, j, k, xindex; + + int temp, temp0; + int temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + int left, right; + + if( (widthin == (widthout * 2)) && (heightin == (heightout * 2)) ) { + HalveImage.halveImage_ushort( components, widthin, heightin, datain, dataout, + element_size, ysize, group_size, myswap_bytes ); + return; + } + convy = (float)heightin / heightout; + convx = (float)widthin / widthout; + convy_int = (int)Math.floor( convy ); + convy_float = convy - convy_int; + convx_int = (int)Math.floor( convx ); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0.0f; + highy_int = convy_int; + highy_float = convy_float; + + for( i = 0; i < heightout; i++ ) { + // Clamp here to be sure we don't read beyond input buffer. + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0.0f; + highx_int = convx_int; + highx_float = convx_float; + + for( j = 0; j < widthout; j++ ) { + + // Ok, now apply box filter to box that goes from (lowx, lowy) + // to (highx, highy) on input data into this pixel on output + // data. + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + + // caulate the value for pixels in the 1st row + xindex = lowx_int * group_size; + if( ( highy_int > lowy_int ) && ( highx_int > lowx_int ) ) { + + y_percent = 1 - lowy_float; + temp = xindex + lowy_int * ysize; + percent = y_percent * ( 1 - lowx_float ); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += ( 0x0000FFFF & ((int)Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ))) * percent; + } else { + totals[k] += ( 0x0000FFFF & datain.getShort() ) * percent; + } + } + left = temp; + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += ( 0x0000FFFF & ((int)Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ))) * y_percent; + } else { + totals[k] += ( 0x0000FFFF & datain.getShort()) * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += ( 0x0000FFFF & (Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ))) * percent; + } else { + totals[k] += ( 0x0000FFFF & datain.getShort()) * percent; + } + } + + // calculate the value for pixels in the last row + y_percent = highy_float; + percent = y_percent * ( 1 - lowx_float ); + temp = xindex + highy_int * ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort()) ) * percent; + } else { + totals[k] += ( 0x0000FFFF & datain.getShort() ) * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort()) ) * y_percent; + } else { + totals[k] += ( 0x0000FFFF & datain.getShort()) * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += ( 0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort()) ) * percent; + } else { + totals[k] += ( 0x0000FFFF & datain.getShort()) * percent; + } + } + + // calculate the value for the pixels in the 1st and last column + for( m = lowy_int + 1; m < highy_int; m++ ) { + left += ysize; + right += ysize; + for( k = 0; k < components; k++, left += element_size, right += element_size ) { + if( myswap_bytes ) { + datain.position( left ); + float f = (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES(datain.getShort())) * ( 1 - lowx_float ); + datain.position( right ); + f += ((0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES(datain.getShort())) * highx_float); + totals[k] += f; + } else { + datain.position( left ); + float f = ((0x0000FFFF & datain.getShort()) * ( 1 - lowx_float )); + datain.position( right ); + f += ((0x0000FFFF & datain.getShort()) * highx_float); + totals[k] += f; + } + } + } + } else if( highy_int > lowy_int ) { + x_percent = highx_float - lowx_float; + percent = ( 1 - lowy_float) * x_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() )) * percent; + } else { + totals[k] += (0x0000FFFF & datain.getShort()) * percent; + } + } + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort()) ) * x_percent; + } else { + totals[k] += (0x0000FFFF & datain.getShort()) * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort() )) * percent; + } else { + totals[k] += (0x0000FFFF & datain.getShort()) * percent; + } + } + } else if( highx_int > lowx_int ) { + y_percent = highy_float - lowy_float; + percent = ( 1 - lowx_float ) * y_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort()) ) * percent; + } else { + totals[k] += (0x0000FFFF & datain.getShort()) * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort()) ) * y_percent; + } else { + totals[k] += (0x0000FFFF & datain.getShort()) * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort()) ) * percent; + } else { + totals[k] += (0x0000FFFF & datain.getShort()) * percent; + } + } + } else { + percent = ( highy_float - lowy_float ) * ( highx_float - lowx_float ); + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort()) ) * percent; + } else { + totals[k] += (0x0000FFFF & datain.getShort()) * percent; + } + } + } + + // this is for the pixels in the body + temp0 = xindex + group_size + ( lowy_int + 1 ) * ysize; + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp = temp0; + for( l = lowx_int + 1; l < highx_int; l++ ) { + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x0000FFFF & Mipmap.GLU_SWAP_2_BYTES( datain.getShort())); + } else { + totals[k] += (0x0000FFFF & datain.getShort()); + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = ( j + ( i * widthout ) ) * components; + for( k = 0; k < components; k++ ) { + dataout.position( outindex + k ); + dataout.put( (short)(totals[k] / area) ); + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if( highx_float > 1.0f ) { + highx_float -= 1.0f; + highx_int++; + } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if( highy_float > 1.0f ) { + highy_float -= 1.0f; + highy_int++; + } + } + } + + public static void scale_internal_short( int components, int widthin, int heightin, + ByteBuffer datain, int widthout, int heightout, + ShortBuffer dataout, int element_size, int ysize, + int group_size, boolean myswap_bytes ) { + float x, convx; + float y, convy; + float percent; + // Max components in a format is 4, so... + float[] totals = new float[4]; + float area; + int i, j, k, xindex; + + int temp, temp0; + int temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + int left, right; + + int swapbuf; // unsigned buffer + + if( (widthin == (widthout * 2)) && (heightin == (heightout * 2)) ) { + HalveImage.halveImage_short( components, widthin, heightin, datain, dataout, + element_size, ysize, group_size, myswap_bytes ); + return; + } + convy = (float)heightin / heightout; + convx = (float)widthin / widthout; + convy_int = (int)Math.floor( convy ); + convy_float = convy - convy_int; + convx_int = (int)Math.floor( convx ); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0.0f; + highy_int = convy_int; + highy_float = convy_float; + + for( i = 0; i < heightout; i++ ) { + // Clamp here to be sure we don't read beyond input buffer. + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0.0f; + highx_int = convx_int; + highx_float = convx_float; + + for( j = 0; j < widthout; j++ ) { + + // Ok, now apply box filter to box that goes from (lowx, lowy) + // to (highx, highy) on input data into this pixel on output + // data. + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + + // caulate the value for pixels in the 1st row + xindex = lowx_int * group_size; + if( ( highy_int > lowy_int ) && ( highx_int > lowx_int ) ) { + + y_percent = 1 - lowy_float; + temp = xindex + lowy_int * ysize; + percent = y_percent * ( 1 - lowx_float ); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getShort() * percent; + } + } + left = temp; + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * y_percent; + } else { + totals[k] += datain.getShort() * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getShort() * percent; + } + } + + // calculate the value for pixels in the last row + y_percent = highy_float; + percent = y_percent * ( 1 - lowx_float ); + temp = xindex + highy_int * ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getShort() * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * y_percent; + } else { + totals[k] += datain.getShort() * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getShort() * percent; + } + } + + // calculate the value for the pixels in the 1st and last column + for( m = lowy_int + 1; m < highy_int; m++ ) { + left += ysize; + right += ysize; + for( k = 0; k < components; k++, left += element_size, right += element_size ) { + if( myswap_bytes ) { + datain.position( left ); + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * ( 1 - lowx_float ); + datain.position( right ); + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * highx_float; + } else { + datain.position( left ); + totals[k] += datain.getShort() * ( 1 - lowx_float ); + datain.position( right ); + totals[k] += datain.getShort() * highx_float; + } + } + } + } else if( highy_int > lowy_int ) { + x_percent = highx_float - lowx_float; + percent = ( 1 - lowy_float) * x_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getShort() * percent; + } + } + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort()); + totals[k] += swapbuf * x_percent; + } else { + totals[k] += datain.getShort() * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getShort() * percent; + } + } + } else if( highx_int > lowx_int ) { + y_percent = highy_float - lowy_float; + percent = ( 1 - lowx_float ) * y_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getShort() * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * y_percent; + } else { + totals[k] += datain.getShort() * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getShort() * percent; + } + } + } else { + percent = ( highy_float - lowy_float ) * ( highx_float - lowx_float ); + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getShort() * percent; + } + } + } + + // this is for the pixels in the body + temp0 = xindex + group_size + ( lowy_int + 1 ) * ysize; + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp = temp0; + for( l = lowx_int + 1; l < highx_int; l++ ) { + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_2_BYTES( datain.getShort() ); + totals[k] += swapbuf; + } else { + totals[k] += datain.getShort(); + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = ( j + ( i * widthout ) ) * components; + for( k = 0; k < components; k++ ) { + dataout.position( outindex + k ); + dataout.put( (short)(totals[k] / area) ); + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if( highx_float > 1.0f ) { + highx_float -= 1.0f; + highx_int++; + } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if( highy_float > 1.0f ) { + highy_float -= 1.0f; + highy_int++; + } + } + } + + public static void scale_internal_uint( int components, int widthin, int heightin, + ByteBuffer datain, int widthout, int heightout, + IntBuffer dataout, int element_size, int ysize, + int group_size, boolean myswap_bytes ) { + float x, convx; + float y, convy; + float percent; + // Max components in a format is 4, so... + float[] totals = new float[4]; + float area; + int i, j, k, xindex; + + int temp, temp0; + int temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + int left, right; + + if( (widthin == (widthout * 2)) && (heightin == (heightout * 2)) ) { + HalveImage.halveImage_uint( components, widthin, heightin, datain, dataout, + element_size, ysize, group_size, myswap_bytes ); + return; + } + convy = (float)heightin / heightout; + convx = (float)widthin / widthout; + convy_int = (int)Math.floor( convy ); + convy_float = convy - convy_int; + convx_int = (int)Math.floor( convx ); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0.0f; + highy_int = convy_int; + highy_float = convy_float; + + for( i = 0; i < heightout; i++ ) { + // Clamp here to be sure we don't read beyond input buffer. + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0.0f; + highx_int = convx_int; + highx_float = convx_float; + + for( j = 0; j < widthout; j++ ) { + + // Ok, now apply box filter to box that goes from (lowx, lowy) + // to (highx, highy) on input data into this pixel on output + // data. + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + + // caulate the value for pixels in the 1st row + xindex = lowx_int * group_size; + if( ( highy_int > lowy_int ) && ( highx_int > lowx_int ) ) { + + y_percent = 1 - lowy_float; + temp = xindex + lowy_int * ysize; + percent = y_percent * ( 1 - lowx_float ); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt()) ) * percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * percent; + } + } + left = temp; + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt()) ) * y_percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt()) ) * percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * percent; + } + } + + // calculate the value for pixels in the last row + y_percent = highy_float; + percent = y_percent * ( 1 - lowx_float ); + temp = xindex + highy_int * ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt()) ) * percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt()) ) * y_percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt()) ) * percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * percent; + } + } + + // calculate the value for the pixels in the 1st and last column + for( m = lowy_int + 1; m < highy_int; m++ ) { + left += ysize; + right += ysize; + for( k = 0; k < components; k++, left += element_size, right += element_size ) { + if( myswap_bytes ) { + datain.position( left ); + totals[k] += ((0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES(datain.getInt())) * ( 1 - lowx_float )); + datain.position( right ); + totals[k] += ((0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES(datain.getInt())) * highx_float); + } else { + datain.position( left ); + totals[k] += ((0x00000000FFFFFFFF & datain.getInt()) * ( 1 - lowx_float )); + datain.position( right ); + totals[k] += ((0x00000000FFFFFFFF & datain.getInt()) * highx_float); + } + } + } + } else if( highy_int > lowy_int ) { + x_percent = highx_float - lowx_float; + percent = ( 1 - lowy_float) * x_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt())) * percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * percent; + } + } + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt())) * x_percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt())) * percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * percent; + } + } + } else if( highx_int > lowx_int ) { + y_percent = highy_float - lowy_float; + percent = ( 1 - lowx_float ) * y_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt())) * percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt())) * y_percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt())) * percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * percent; + } + } + } else { + percent = ( highy_float - lowy_float ) * ( highx_float - lowx_float ); + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + long tempInt0 = ( 0xFFFFFFFFL & datain.getInt( temp_index ) ); + datain.position( temp_index ); + long tempInt1 = ( 0xFFFFFFFFL & datain.getInt() ); + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt())) * percent; + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()) * percent; + } + } + } + + // this is for the pixels in the body + temp0 = xindex + group_size + ( lowy_int + 1 ) * ysize; + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp = temp0; + for( l = lowx_int + 1; l < highx_int; l++ ) { + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + totals[k] += (0x00000000FFFFFFFF & Mipmap.GLU_SWAP_4_BYTES( datain.getInt())); + } else { + totals[k] += (0x00000000FFFFFFFF & datain.getInt()); + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = ( j + ( i * widthout ) ) * components; + float value = 0.0f; + for( k = 0; k < components; k++ ) { + value = totals[k] / area; + dataout.position( outindex + k ); + if( value >= UINT_MAX ) { + dataout.put( (int)value ); + } else { + dataout.put( (int)(totals[k] / area) ); + } + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if( highx_float > 1.0f ) { + highx_float -= 1.0f; + highx_int++; + } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if( highy_float > 1.0f ) { + highy_float -= 1.0f; + highy_int++; + } + } + } + + public static void scale_internal_int( int components, int widthin, int heightin, + ByteBuffer datain, int widthout, int heightout, + IntBuffer dataout, int element_size, int ysize, + int group_size, boolean myswap_bytes ) { + float x, convx; + float y, convy; + float percent; + // Max components in a format is 4, so... + float[] totals = new float[4]; + float area; + int i, j, k, xindex; + + int temp, temp0; + int temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + int left, right; + + long swapbuf; // unsigned buffer + + if( (widthin == (widthout * 2)) && (heightin == (heightout * 2)) ) { + HalveImage.halveImage_int( components, widthin, heightin, datain, dataout, + element_size, ysize, group_size, myswap_bytes ); + return; + } + convy = (float)heightin / heightout; + convx = (float)widthin / widthout; + convy_int = (int)Math.floor( convy ); + convy_float = convy - convy_int; + convx_int = (int)Math.floor( convx ); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0.0f; + highy_int = convy_int; + highy_float = convy_float; + + for( i = 0; i < heightout; i++ ) { + // Clamp here to be sure we don't read beyond input buffer. + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0.0f; + highx_int = convx_int; + highx_float = convx_float; + + for( j = 0; j < widthout; j++ ) { + + // Ok, now apply box filter to box that goes from (lowx, lowy) + // to (highx, highy) on input data into this pixel on output + // data. + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + + // caulate the value for pixels in the 1st row + xindex = lowx_int * group_size; + if( ( highy_int > lowy_int ) && ( highx_int > lowx_int ) ) { + + y_percent = 1 - lowy_float; + temp = xindex + lowy_int * ysize; + percent = y_percent * ( 1 - lowx_float ); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getInt() * percent; + } + } + left = temp; + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * y_percent; + } else { + totals[k] += datain.getInt() * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getInt() * percent; + } + } + + // calculate the value for pixels in the last row + y_percent = highy_float; + percent = y_percent * ( 1 - lowx_float ); + temp = xindex + highy_int * ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getInt() * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * y_percent; + } else { + totals[k] += datain.getInt() * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getInt() * percent; + } + } + + // calculate the value for the pixels in the 1st and last column + for( m = lowy_int + 1; m < highy_int; m++ ) { + left += ysize; + right += ysize; + for( k = 0; k < components; k++, left += element_size, right += element_size ) { + if( myswap_bytes ) { + datain.position( left ); + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * ( 1 - lowx_float ); + datain.position( right ); + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * highx_float; + } else { + datain.position( left ); + totals[k] += (datain.getInt() * ( 1 - lowx_float )); + datain.position( right ); + totals[k] += (datain.getInt() * highx_float); + } + } + } + } else if( highy_int > lowy_int ) { + x_percent = highx_float - lowx_float; + percent = ( 1 - lowy_float) * x_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getInt() * percent; + } + } + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * x_percent; + } else { + totals[k] += datain.getInt() * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getInt() * percent; + } + } + } else if( highx_int > lowx_int ) { + y_percent = highy_float - lowy_float; + percent = ( 1 - lowx_float ) * y_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getInt() * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * y_percent; + } else { + totals[k] += datain.getInt() * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getInt() * percent; + } + } + } else { + percent = ( highy_float - lowy_float ) * ( highx_float - lowx_float ); + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getInt() * percent; + } + } + } + + // this is for the pixels in the body + temp0 = xindex + group_size + ( lowy_int + 1 ) * ysize; + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp = temp0; + for( l = lowx_int + 1; l < highx_int; l++ ) { + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getInt() ); + totals[k] += swapbuf; + } else { + totals[k] += datain.getInt(); + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = ( j + ( i * widthout ) ) * components; + for( k = 0; k < components; k++ ) { + dataout.position( outindex + k ); + dataout.put( (int)(totals[k] / area) ); + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if( highx_float > 1.0f ) { + highx_float -= 1.0f; + highx_int++; + } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if( highy_float > 1.0f ) { + highy_float -= 1.0f; + highy_int++; + } + } + } + + public static void scale_internal_float( int components, int widthin, int heightin, + ByteBuffer datain, int widthout, int heightout, + FloatBuffer dataout, int element_size, int ysize, + int group_size, boolean myswap_bytes ) { + float x, convx; + float y, convy; + float percent; + // Max components in a format is 4, so... + float[] totals = new float[4]; + float area; + int i, j, k, xindex; + + int temp, temp0; + int temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + int left, right; + + float swapbuf; // unsigned buffer + + if( (widthin == (widthout * 2)) && (heightin == (heightout * 2)) ) { + HalveImage.halveImage_float( components, widthin, heightin, datain, dataout, + element_size, ysize, group_size, myswap_bytes ); + return; + } + convy = (float)heightin / heightout; + convx = (float)widthin / widthout; + convy_int = (int)Math.floor( convy ); + convy_float = convy - convy_int; + convx_int = (int)Math.floor( convx ); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0.0f; + highy_int = convy_int; + highy_float = convy_float; + + for( i = 0; i < heightout; i++ ) { + // Clamp here to be sure we don't read beyond input buffer. + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0.0f; + highx_int = convx_int; + highx_float = convx_float; + + for( j = 0; j < widthout; j++ ) { + + // Ok, now apply box filter to box that goes from (lowx, lowy) + // to (highx, highy) on input data into this pixel on output + // data. + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + + // caulate the value for pixels in the 1st row + xindex = lowx_int * group_size; + if( ( highy_int > lowy_int ) && ( highx_int > lowx_int ) ) { + + y_percent = 1 - lowy_float; + temp = xindex + lowy_int * ysize; + percent = y_percent * ( 1 - lowx_float ); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getFloat() * percent; + } + } + left = temp; + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * y_percent; + } else { + totals[k] += datain.getFloat() * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getFloat() * percent; + } + } + + // calculate the value for pixels in the last row + y_percent = highy_float; + percent = y_percent * ( 1 - lowx_float ); + temp = xindex + highy_int * ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getFloat() * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * y_percent; + } else { + totals[k] += datain.getFloat() * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getFloat() * percent; + } + } + + // calculate the value for the pixels in the 1st and last column + for( m = lowy_int + 1; m < highy_int; m++ ) { + left += ysize; + right += ysize; + for( k = 0; k < components; k++, left += element_size, right += element_size ) { + if( myswap_bytes ) { + datain.position( left ); + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * ( 1 - lowx_float ); + datain.position( right ); + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * highx_float; + } else { + datain.position( left ); + totals[k] += (datain.getFloat() * ( 1 - lowx_float )); + datain.position( right ); + totals[k] += (datain.getFloat() * highx_float); + } + } + } + } else if( highy_int > lowy_int ) { + x_percent = highx_float - lowx_float; + percent = ( 1 - lowy_float) * x_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getFloat() * percent; + } + } + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * x_percent; + } else { + totals[k] += datain.getFloat() * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getFloat() * percent; + } + } + } else if( highx_int > lowx_int ) { + y_percent = highy_float - lowy_float; + percent = ( 1 - lowx_float ) * y_percent; + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getFloat() * percent; + } + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += group_size; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * y_percent; + } else { + totals[k] += datain.getFloat() * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getFloat() * percent; + } + } + } else { + percent = ( highy_float - lowy_float ) * ( highx_float - lowx_float ); + temp = xindex + (lowy_int * ysize); + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf * percent; + } else { + totals[k] += datain.getFloat() * percent; + } + } + } + + // this is for the pixels in the body + temp0 = xindex + group_size + ( lowy_int + 1 ) * ysize; + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp = temp0; + for( l = lowx_int + 1; l < highx_int; l++ ) { + for( k = 0, temp_index = temp; k < components; k++, temp_index += element_size ) { + datain.position( temp_index ); + if( myswap_bytes ) { + swapbuf = Mipmap.GLU_SWAP_4_BYTES( datain.getFloat() ); + totals[k] += swapbuf; + } else { + totals[k] += datain.getFloat(); + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = ( j + ( i * widthout ) ) * components; + for( k = 0; k < components; k++ ) { + dataout.position( outindex + k ); + dataout.put( (totals[k] / area) ); + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if( highx_float > 1.0f ) { + highx_float -= 1.0f; + highx_int++; + } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if( highy_float > 1.0f ) { + highy_float -= 1.0f; + highy_int++; + } + } + } + + public static void scaleInternalPackedPixel( int components, Extract extract, + int widthIn, int heightIn, ByteBuffer dataIn, int widthOut, + int heightOut, ByteBuffer dataOut, int pixelSizeInBytes, + int rowSizeInBytes, boolean isSwap ) { + float x, convx; + float y, convy; + float percent; + + // max components in a format is 4, so + float[] totals = new float[4]; + float[] extractTotals = new float[4]; + float[] extractMoreTotals = new float[4]; + float[] shoveTotals = new float[4]; + + float area; + int i, j, k, xindex; + + int temp, temp0; + int temp_index; + int outIndex = 0; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + int left, right; + + if( widthIn == widthOut * 2 && heightIn == heightOut * 2 ) { + HalveImage.halveImagePackedPixel( components, extract, widthIn, heightIn, dataIn, dataOut, + pixelSizeInBytes, rowSizeInBytes, isSwap ); + return; + } + convy = (float)heightIn / (float)heightOut; + convx = (float)widthIn / (float)widthOut; + convy_int = (int)Math.floor( convy ); + convy_float = convy - convy_int; + convx_int = (int)Math.floor( convx ); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0.0f; + highy_int = convy_int; + highy_float = convx_float; + + for( i = 0; i < heightOut; i++ ) { + // Clamp here to be sure we don't read beyond input buffer. + if (highy_int >= heightIn) + highy_int = heightIn - 1; + lowx_int = 0; + lowx_float = 0.0f; + highx_int = convx_int; + highx_float = convx_float; + + for( j = 0; j < widthOut; j++ ) { + // ok now apply box filter to box that goes from( lowx, lowy ) + // to ( highx, highy ) on input data into this pixel on output data + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + + // calculate that value for pixels in the 1st row + xindex = lowx_int * pixelSizeInBytes; + if( (highy_int > lowy_int) && (highx_int > lowx_int) ) { + + y_percent = 1 - lowy_float; + temp = xindex + lowy_int * rowSizeInBytes; + percent = y_percent * ( 1 - lowx_float ); + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + left = temp; + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += pixelSizeInBytes; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * y_percent; + } + } + temp += pixelSizeInBytes; + right = temp; + percent = y_percent * highx_float; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + // calculate the value for pixels in the last row + + y_percent = highy_float; + percent = y_percent * ( 1 - lowx_float ); + temp = xindex + highy_int * rowSizeInBytes; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += pixelSizeInBytes; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * y_percent; + } + } + temp += pixelSizeInBytes; + percent = y_percent * highx_float; + dataIn.position( temp ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + + // calculate the value for pixels in the 1st and last column + for( m = lowy_int + 1; m < highy_int; m++ ) { + left += rowSizeInBytes; + right += rowSizeInBytes; + dataIn.position( left ); + extract.extract( isSwap, dataIn, extractTotals ); + dataIn.position( right ); + extract.extract( isSwap, dataIn, extractMoreTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += ( extractTotals[k] * ( 1 - lowx_float ) + extractMoreTotals[k] * highx_float ); + } + } + } else if( highy_int > lowy_int ) { + x_percent = highx_float - lowx_float; + percent = ( 1 - lowy_float ) * x_percent; + temp = xindex + lowy_int * rowSizeInBytes; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp += rowSizeInBytes; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * x_percent; + } + } + percent = x_percent * highy_float; + temp += rowSizeInBytes; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + } else if( highx_int > lowx_int ) { + y_percent = highy_float - lowy_float; + percent = ( 1 - lowx_float ) * y_percent; + temp = xindex + lowy_int * rowSizeInBytes; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + for( l = lowx_int + 1; l < highx_int; l++ ) { + temp += pixelSizeInBytes; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * y_percent; + } + } + temp += pixelSizeInBytes; + percent = y_percent * highx_float; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + } else { + percent = ( highy_float - lowy_float ) * ( highx_float - lowx_float ); + temp = xindex + lowy_int * rowSizeInBytes; + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + } + + // this is for the pixels in the body + temp0 = xindex + pixelSizeInBytes + ( lowy_int + 1 ) * rowSizeInBytes; + for( m = lowy_int + 1; m < highy_int; m++ ) { + temp = temp0; + for( l = lowx_int + 1; l < highx_int; l++ ) { + dataIn.position( temp ); + extract.extract( isSwap, dataIn, extractTotals ); + for( k = 0; k < components; k++ ) { + totals[k] += extractTotals[k] * percent; + } + temp += pixelSizeInBytes; + } + temp0 += rowSizeInBytes; + } + + outIndex = ( j + ( i * widthOut ) ); + for( k = 0; k < components; k++ ) { + shoveTotals[k] = totals[k] / area; + } + extract.shove( shoveTotals, outIndex, dataOut ); + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if( highx_float > 1.0f ) { + highx_float -= 1.0f; + highx_int++; + } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthIn - 1) { + int delta = (highx_int - widthIn + 1); + lowx_int -= delta; + highx_int -= delta; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if( highy_float > 1.0f ) { + highy_float -= 1.0f; + highy_int++; + } + } + assert( outIndex == ( widthOut * heightOut - 1) ); + } + + public static void scaleInternal3D( int components, int widthIn, int heightIn, + int depthIn, ShortBuffer dataIn, int widthOut, int heightOut, + int depthOut, ShortBuffer dataOut ) { + float x, lowx, highx, convx, halfconvx; + float y, lowy, highy, convy, halfconvy; + float z, lowz, highz, convz, halfconvz; + float xpercent, ypercent, zpercent; + float percent; + // max compnents in a format is 4 + float[] totals = new float[4]; + float volume; + int i, j, d, k, zint, yint, xint, xindex, yindex, zindex; + int temp; + + lowy = highy = lowx = highx = 0.0f; + + convz = (float)depthIn / depthOut; + convy = (float)heightIn / heightOut; + convx = (float)widthIn / widthOut; + halfconvz = convz / 2.0f; + halfconvy = convy / 2.0f; + halfconvx = convx / 2.0f; + for( d = 0; d < depthOut; d++ ) { + z = convz * ( d + 0.5f ); + if( depthIn > depthOut ) { + highz = z + halfconvz; + lowz = z - halfconvz; + } else { + highz = z + 0.5f; + lowz = z - 0.5f; + } + for( i = 0; i < heightOut; i++ ) { + y = convy * ( i + 0.5f ); + if( heightIn > heightOut ) { + highz = y + halfconvy; + lowz = y - halfconvy; + } else { + highz = y + 0.5f; + lowz = y - 0.5f; + } + for( j = 0; j < widthOut; j++ ) { + x = convx * ( j + 0.5f ); + if( depthIn > depthOut ) { + highz = x + halfconvx; + lowz = x - halfconvx; + } else { + highz = x + 0.5f; + lowz = x - 0.5f; + } + + // Ok, now apply box filter to box that goes from ( lowx, lowy, lowz ) + // to ( highx, highy, highz ) on input data into this pixel on output data + + totals[0] = totals[1] = totals[2] = totals[3] = 0.0f; + volume = 0.0f; + + z = lowz; + zint = (int)(Math.floor( z ) ); + while( z < highz ) { + zindex = ( zint + depthIn ) % depthIn; + if( highz < zint + 1 ) { + zpercent = highz - z; + } else { + zpercent = zint + 1 - z; + } + + y = lowy; + yint = (int)(Math.floor( y ) ); + while( y < highy ) { + yindex = ( yint + heightIn ) % heightIn; + if( highy < yint + 1 ) { + ypercent = highy - y; + } else { + ypercent = yint + 1 - y; + } + + x = lowx; + xint = (int)(Math.floor( x ) ); + + while( x < highx ) { + xindex = (xint + widthIn ) % widthIn; + if( highx < xint + 1 ) { + xpercent = highx - x; + } else { + xpercent = xint + 1 - x; + } + + percent = xpercent * ypercent * zpercent; + volume += percent; + + temp = (xindex + ( yindex *widthIn) + (zindex * widthIn *heightIn)) * components; + for( k = 0; k < components; k++ ) { + assert( 0 <= (temp+k) && (temp+k) < (widthIn * heightIn * depthIn * components) ); + totals[k] += dataIn.get( temp + k ) * percent; + } + xint++; + x = xint; + } // while x + yint++; + y = yint; + } // while y + zint++; + z = zint; + } // while z + + temp = ( j + ( i * widthOut ) + (d * widthOut * heightOut ) ) * components; + for( k = 0; k < components; k++ ) { + // totals should be rounded in the case of enlarging an rgb ramp when the type is 332 or 4444 + assert( 0 <= ( temp + k ) && ( temp + k ) < (widthOut * heightOut* depthOut * components) ); + dataOut.put( temp + k, (short)((totals[k] + 0.5f) / volume ) ); + } + } + } + } + } + + public static int gluScaleImage3D( GL gl, int format, int widthIn, int heightIn, + int depthIn, int typeIn, ByteBuffer dataIn, int widthOut, int heightOut, + int depthOut, int typeOut, ByteBuffer dataOut ) { + int components; + ShortBuffer beforeImage, afterImage; + PixelStorageModes psm = new PixelStorageModes(); + + if( widthIn == 0 || heightIn == 0 || depthIn == 0 || + widthOut == 0 || heightOut == 0 || depthOut == 0 ) { + return( 0 ); + } + + if( widthIn < 0 || heightIn < 0 || depthIn < 0 || + widthOut < 0 || heightOut < 0 || depthOut < 0 ) { + return( GLU.GLU_INVALID_VALUE ); + } + + if( !Mipmap.legalFormat(format) || !Mipmap.legalType(typeIn) || + !Mipmap.legalType(typeOut) || typeIn == GL2.GL_BITMAP || + typeOut == GL2.GL_BITMAP ) { + return( GLU.GLU_INVALID_ENUM ); + } + + if( !Mipmap.isLegalFormatForPackedPixelType( format, typeIn ) ) { + return( GLU.GLU_INVALID_OPERATION ); + } + + if( !Mipmap.isLegalFormatForPackedPixelType( format, typeOut ) ) { + return( GLU.GLU_INVALID_OPERATION ); + } + + try { + beforeImage = Buffers.newDirectByteBuffer( Mipmap.imageSize3D( widthIn, + heightIn, depthIn, format, GL2.GL_UNSIGNED_SHORT ) ).asShortBuffer(); + afterImage = Buffers.newDirectByteBuffer( Mipmap.imageSize3D( widthIn, + heightIn, depthIn, format, GL2.GL_UNSIGNED_SHORT ) ).asShortBuffer(); + } catch( OutOfMemoryError err ) { + return( GLU.GLU_OUT_OF_MEMORY ); + } + Mipmap.retrieveStoreModes3D( gl, psm ); + + Image.fillImage3D( psm, widthIn, heightIn, depthIn, format, typeIn, + Mipmap.is_index( format ), dataIn, beforeImage ); + components = Mipmap.elements_per_group( format, 0 ); + ScaleInternal.scaleInternal3D( components, widthIn, heightIn, depthIn, + beforeImage, widthOut, heightOut, depthOut, afterImage ); + Image.emptyImage3D( psm, widthOut, heightOut, depthOut, format, typeOut, + Mipmap.is_index( format ), afterImage, dataOut ); + + return( 0 ); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/mipmap/Type_Widget.java b/src/jogl/classes/jogamp/opengl/glu/mipmap/Type_Widget.java new file mode 100644 index 000000000..38113f601 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/mipmap/Type_Widget.java @@ -0,0 +1,226 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.mipmap; + +import java.nio.*; + +/** + * + * @author Administrator + */ +public class Type_Widget { + + ByteBuffer buffer; + + /** Creates a new instance of Type_Widget */ + public Type_Widget() { + // can't make this direct, because JVM doesn't allocate small direct buffers efficiently + // see https://jogamp.org/bugzilla/show_bug.cgi?id=463 for details + buffer = ByteBuffer.allocate( 4 ); + } + + public void setUB0( byte b ) { + buffer.position( 0 ); + buffer.put( b ); + } + + public byte getUB0() { + buffer.position( 0 ); + return( buffer.get() ); + } + + public void setUB1( byte b ) { + buffer.position( 1 ); + buffer.put( b ); + } + + public byte getUB1() { + buffer.position( 1 ); + return( buffer.get() ); + } + + public void setUB2( byte b ) { + buffer.position( 2 ); + buffer.put( b ); + } + + public byte getUB2() { + buffer.position( 2 ); + return( buffer.get() ); + } + + public void setUB3( byte b ) { + buffer.position( 3 ); + buffer.put( b ); + } + + public byte getUB3() { + buffer.position( 3 ); + return( buffer.get() ); + } + + public void setUS0( short s ) { + buffer.position( 0 ); + buffer.putShort( s ); + } + + public short getUS0() { + buffer.position( 0 ); + return( buffer.getShort() ); + } + + public void setUS1( short s ) { + buffer.position( 2 ); + buffer.putShort( s ); + } + + public short getUS1() { + buffer.position( 2 ); + return( buffer.getShort() ); + } + + public void setUI( int i ) { + buffer.position( 0 ); + buffer.putInt( i ); + } + + public int getUI() { + buffer.position( 0 ); + return( buffer.getInt() ); + } + + public void setB0( byte b ) { + buffer.position( 0 ); + buffer.put( b ); + } + + public byte getB0() { + buffer.position( 0 ); + return( buffer.get() ); + } + + public void setB1( byte b ) { + buffer.position( 1 ); + buffer.put( b ); + } + + public byte getB1() { + buffer.position( 1 ); + return( buffer.get() ); + } + + public void setB2( byte b ) { + buffer.position( 2 ); + buffer.put( b ); + } + + public byte getB2() { + buffer.position( 2 ); + return( buffer.get() ); + } + + public void setB3( byte b ) { + buffer.position( 3 ); + buffer.put( b ); + } + + public byte getB3() { + buffer.position( 3 ); + return( buffer.get() ); + } + + public void setS0( short s ) { + buffer.position( 0 ); + buffer.putShort( s ); + } + + public short getS0() { + buffer.position( 0 ); + return( buffer.getShort() ); + } + + public void setS1( short s ) { + buffer.position( 2 ); + buffer.putShort( s ); + } + + public short getS1() { + buffer.position( 2 ); + return( buffer.getShort() ); + } + + public void setI( int i ) { + buffer.position( 0 ); + buffer.putInt( i ); + } + + public int getI() { + buffer.position( 0 ); + return( buffer.getInt() ); + } + + public void setF( float f ) { + buffer.position( 0 ); + buffer.putFloat( f ); + } + + public float getF() { + buffer.position( 0 ); + return( buffer.getFloat() ); + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + return( buffer ); + } + + public static void main( String args[] ) { + Type_Widget t = new Type_Widget(); + t.setI( 1000000 ); + + System.out.println("int: " + Integer.toHexString( t.getI() ) ); + + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Arc.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Arc.java new file mode 100644 index 000000000..422f8d4df --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Arc.java @@ -0,0 +1,258 @@ +package jogamp.opengl.glu.nurbs; + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/** + * Trimming arc + * @author Tomas Hrasky + * + */ +public class Arc { + /** + * Corresponding picewise-linear arc + */ + public PwlArc pwlArc; + + /** + * Arc type + */ + private long type; + + /** + * Arc link in linked list + */ + public Arc link; + + /** + * Previous arc + */ + Arc prev; + + /** + * Next arc + */ + Arc next; + + /** + * Corresponding berizer type arc + */ + private BezierArc bezierArc; + + /** + * Makes new arc at specified side + * + * @param side + * which side doeas this arc form + */ + public Arc(int side) { + bezierArc = null; + pwlArc = null; + type = 0; + setside(side); + // nuid=_nuid + } + + /** + * Sets side the arc is at + * + * @param side + * arc side + */ + private void setside(int side) { + // DONE + clearside(); + type |= side << 8; + } + + /** + * Unsets side + */ + private void clearside() { + // DONE + type &= ~(0x7 << 8); + } + + // this one replaces enum arc_side + /** + * Side not specified + */ + public static final int ARC_NONE = 0; + + /** + * Arc on right + */ + public static final int ARC_RIGHT = 1; + + /** + * Arc on top + */ + public static final int ARC_TOP = 2; + + /** + * Arc on left + */ + public static final int ARC_LEFT = 3; + + /** + * Arc on bottom + */ + public static final int ARC_BOTTOM = 4; + + /** + * Bezier type flag + */ + private static final long BEZIER_TAG = 1 << 13; + + /** + * Arc type flag + */ + private static final long ARC_TAG = 1 << 3; + + /** + * Tail type tag + */ + private static final long TAIL_TAG = 1 << 6; + + /** + * Appends arc to the list + * + * @param jarc + * arc to be append + * @return this + */ + public Arc append(Arc jarc) { + // DONE + if (jarc != null) { + next = jarc.next; + prev = jarc; + next.prev = this; + prev.next = this; + } else { + next = this; + prev = this; + } + + return this; + } + + /** + * Unused + * + * @return true + */ + public boolean check() { + return true; + } + + /** + * Sets bezier type flag + */ + public void setbezier() { + // DONE + type |= BEZIER_TAG; + + } + + /** + * Returns tail of linked list coords + * + * @return tail coords + */ + public float[] tail() { + // DONE + return pwlArc.pts[0].param; + } + + /** + * Returns head of linked list coords + * + * @return head coords + */ + public float[] head() { + // DONE + return next.pwlArc.pts[0].param; + } + + /** + * Returns whether arc is marked with arc_tag + * + * @return is arc marked with arc_tag + */ + public boolean ismarked() { + // DONE + return ((type & ARC_TAG) > 0) ? true : false; + } + + /** + * Cleans arc_tag flag + */ + public void clearmark() { + // DONE + type &= (~ARC_TAG); + } + + /** + * Sets arc_tag flag + */ + public void setmark() { + // DONE + type |= ARC_TAG; + } + + /** + * sets tail tag + */ + public void setitail() { + // DONE + type |= TAIL_TAG; + } + + /** + * Returns whether arc is marked tail + * + * @return is tail + */ + public boolean getitail() { + return false; + } + + /** + * Unsets tail tag + */ + public void clearitail() { + // DONE + type &= (~TAIL_TAG); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcSdirSorter.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcSdirSorter.java new file mode 100644 index 000000000..0d04d4cd6 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcSdirSorter.java @@ -0,0 +1,63 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class for sorting list of Arcs + * @author Tomas Hrasky + * + */ +public class ArcSdirSorter { + + /** + * Makes new ArcSdirSorter with Subdivider + * @param subdivider subdivider + */ + public ArcSdirSorter(Subdivider subdivider) { + //TODO + // System.out.println("TODO arcsdirsorter.constructor"); + } + + /** + * Sorts list of arcs + * @param list arc list to be sorted + * @param count size of list + */ + public void qsort(CArrayOfArcs list, int count) { + // TODO + // System.out.println("TODO arcsdirsorter.qsort"); + } + +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTdirSorter.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTdirSorter.java new file mode 100644 index 000000000..bee98b8c3 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTdirSorter.java @@ -0,0 +1,60 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class for sorting list of Arcs + * @author Tomas Hrasky + * + */ +public class ArcTdirSorter { + /** + * Makes new ArcSdirSorter with Subdivider + * @param subdivider subdivider + */ + public ArcTdirSorter(Subdivider subdivider) { + // TODO Auto-generated constructor stub + // System.out.println("TODO arcTsorter.konstruktor"); + } + /** + * Sorts list of arcs + * @param list arc list to be sorted + * @param count size of list + */ + public void qsort(CArrayOfArcs list, int count) { + // TODO Auto-generated method stub + // System.out.println("TODO arcTsorter.qsort"); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTesselator.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTesselator.java new file mode 100644 index 000000000..2e4d3eb96 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTesselator.java @@ -0,0 +1,90 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class for arc tesselation + * @author Tomas Hrasky + * + */ +public class ArcTesselator { + + /** + * Makes given arc an bezier arc + * @param arc arc to work with + * @param s1 minimum s param + * @param s2 maximum s param + * @param t1 minimum t param + * @param t2 maximum s param + */ + public void bezier(Arc arc, float s1, float s2, float t1, float t2) { + // DONE + TrimVertex[] p = new TrimVertex[2]; + p[0] = new TrimVertex(); + p[1] = new TrimVertex(); + arc.pwlArc = new PwlArc(2, p); + p[0].param[0] = s1; + p[0].param[1] = s2; + p[1].param[0] = t1; + p[1].param[1] = t2; + arc.setbezier(); + } + + /** + * Empty method + * @param newright arc to work with + * @param s first tail + * @param t2 second tail + * @param t1 third tail + * @param f stepsize + */ + public void pwl_right(Arc newright, float s, float t1, float t2, float f) { + // TODO Auto-generated method stub + // System.out.println("TODO arctesselator.pwl_right"); + } + + /** + * Empty method + * @param newright arc to work with + * @param s first tail + * @param t2 second tail + * @param t1 third tail + * @param f stepsize + */ + public void pwl_left(Arc newright, float s, float t2, float t1, float f) { + // TODO Auto-generated method stub + // System.out.println("TODO arctesselator.pwl_left"); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Backend.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Backend.java new file mode 100644 index 000000000..4959f8000 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Backend.java @@ -0,0 +1,217 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class responsible for rendering + * @author Tomas Hrasky + * + */ +public abstract class Backend { + + /** + * Fill surface + */ + public static final int N_MESHFILL = 0; + + /** + * Draw surface as wire model + */ + public static final int N_MESHLINE = 1; + + /** + * Draw surface with points + */ + public static final int N_MESHPOINT = 2; + + /** + * Object rendering curves + */ + protected CurveEvaluator curveEvaluator; + + /** + * Object rendering surfaces + */ + protected SurfaceEvaluator surfaceEvaluator; + + /** + * Makes new backend + */ + public Backend() { + // curveEvaluator = new OpenGLCurveEvaluator(); + // surfaceEvaluator = new OpenGLSurfaceEvaluator(); + } + + /** + * Begin a curve + */ + public void bgncurv() { + // DONE + curveEvaluator.bgnmap1f(); + + } + + /** + * End a curve + */ + public void endcurv() { + // DONE + curveEvaluator.endmap1f(); + + } + + /** + * Make cuve with given parameters + * @param type curve type + * @param ps control points + * @param stride control points coordinates number + * @param order order of curve + * @param ulo smallest u + * @param uhi highest u + */ + public void curvpts(int type, CArrayOfFloats ps, int stride, int order, + float ulo, float uhi) { + // DONE + curveEvaluator.map1f(type, ulo, uhi, stride, order, ps); + curveEvaluator.enable(type); + } + + /** + * Draw curve + * @param u1 smallest u + * @param u2 highest u + * @param nu number of pieces + */ + public void curvgrid(float u1, float u2, int nu) { + // DONE + curveEvaluator.mapgrid1f(nu, u1, u2); + + } + + /** + * Evaluates curve mesh + * @param from low param + * @param n step + */ + public void curvmesh(int from, int n) { + // DONE + curveEvaluator.mapmesh1f(N_MESHFILL, from, from + n); + } + + /** + * Begin surface + * @param wiretris use triangles + * @param wirequads use quads + */ + public void bgnsurf(int wiretris, int wirequads) { + // DONE + surfaceEvaluator.bgnmap2f(); + + if (wiretris > 0) + surfaceEvaluator.polymode(NurbsConsts.N_MESHLINE); + else + surfaceEvaluator.polymode(NurbsConsts.N_MESHFILL); + } + + /** + * End surface + */ + public void endsurf() { + // DONE + surfaceEvaluator.endmap2f(); + } + + /** + * Empty method + * @param ulo low u param + * @param uhi hig u param + * @param vlo low v param + * @param vhi high v param + */ + public void patch(float ulo, float uhi, float vlo, float vhi) { + // DONE + surfaceEvaluator.domain2f(ulo, uhi, vlo, vhi); + } + + /** + * Draw surface + * @param u0 lowest u + * @param u1 highest u + * @param nu number of pieces in u direction + * @param v0 lowest v + * @param v1 highest v + * @param nv number of pieces in v direction + */ + public void surfgrid(float u0, float u1, int nu, float v0, float v1, int nv) { + // DONE + surfaceEvaluator.mapgrid2f(nu, u0, u1, nv, v0, v1); + + } + + /** + * Evaluates surface mesh + * @param u u param + * @param v v param + * @param n step in u direction + * @param m step in v direction + */ + public void surfmesh(int u, int v, int n, int m) { + // System.out.println("TODO backend.surfmesh wireframequads"); + // TODO wireframequads + surfaceEvaluator.mapmesh2f(NurbsConsts.N_MESHFILL, u, u + n, v, v + m); + } + + /** + * Make surface + * @param type surface type + * @param pts control points + * @param ustride control points coordinates in u direction + * @param vstride control points coordinates in v direction + * @param uorder surface order in u direction + * @param vorder surface order in v direction + * @param ulo lowest u + * @param uhi hightest u + * @param vlo lowest v + * @param vhi hightest v + */ + public void surfpts(int type, CArrayOfFloats pts, int ustride, int vstride, + int uorder, int vorder, float ulo, float uhi, float vlo, float vhi) { + // DONE + surfaceEvaluator.map2f(type, ulo, uhi, ustride, uorder, vlo, vhi, + vstride, vorder, pts); + surfaceEvaluator.enable(type); + + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/BezierArc.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/BezierArc.java new file mode 100644 index 000000000..9f7984bb7 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/BezierArc.java @@ -0,0 +1,44 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Empty class + * @author Tomas Hrasky + * + */ +public class BezierArc { + +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Bin.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Bin.java new file mode 100644 index 000000000..df8b16ab5 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Bin.java @@ -0,0 +1,155 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class holding trimming arcs + * @author Tomas Hrasky + * + */ +public class Bin { + + /** + * Head of linked list of arcs + */ + private Arc head; + + /** + * Current arc + */ + private Arc current; + + /** + * Indicates whether there are any Arcs in linked list + * @return true if there are any Arcs in linked list + */ + public boolean isnonempty() { + // DONE + return this.head != null ? true : false; + } + + /** + * Adds and arc to linked list + * @param jarc added arc + */ + public void addarc(Arc jarc) { + // DONE + // if (head == null) + // head = jarc; + // else { + jarc.link = head; + head = jarc; + // } + + } + + /** + * Returns number of arcs in linked list + * @return number of arcs + */ + public int numarcs() { + // DONE + int count = 0; + for (Arc jarc = firstarc(); jarc != null; jarc = nextarc()) + count++; + return count; + } + + /** + * Removes first arc in list + * @return new linked list head + */ + public Arc removearc() { + // DONE + Arc jarc = head; + if (jarc != null) + head = jarc.link; + return jarc; + + } + + /** + * Consolidates linked list + */ + public void adopt() { + // DONE + markall(); + + Arc orphan; + while ((orphan = removearc()) != null) { + for (Arc parent = orphan.next; !parent.equals(orphan); parent = parent.next) { + if (!parent.ismarked()) { + orphan.link = parent.link; + parent.link = orphan; + orphan.clearmark(); + break; + } + } + } + + } + + /** + * Marks all arc in linked list + */ + private void markall() { + // DONE + for (Arc jarc = firstarc(); jarc != null; jarc = nextarc()) + jarc.setmark(); + } + + /** + * Returns first arc in linked list + * @return first arc in linked list + */ + private Arc firstarc() { + // DONE + current = head; + return nextarc(); + } + + /** + * Returns next arc in linked list + * @return next arc + * + */ + private Arc nextarc() { + // DONE + Arc jarc = current; + if (jarc != null) + current = jarc.link; + return jarc; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Breakpt.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Breakpt.java new file mode 100644 index 000000000..f45571dac --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Breakpt.java @@ -0,0 +1,59 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class holding break point parameters + * + * @author Tomas Hrasky + * + */ +public class Breakpt { + + /** + * Breakpoint multiplicity + */ + public int multi; + + /** + * Breakpint value + */ + public float value; + + /** + * Breakpoint deficit (how many times it has to be added) + */ + public int def; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfArcs.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfArcs.java new file mode 100644 index 000000000..aaa8cb5f2 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfArcs.java @@ -0,0 +1,194 @@ +package jogamp.opengl.glu.nurbs; + +/** + * Class replacing C language pointer + * + * @author Tomas Hrasky + * + */ +public class CArrayOfArcs { + /** + * Underlaying array + */ + private Arc[] array; + + /** + * Pointer to array member + */ + private int pointer; + + /** + * Don't check for array borders? + */ + private boolean noCheck = true; + + /** + * Makes new CArray + * + * @param array + * underlaying array + * @param pointer + * pointer (index) to array + */ + public CArrayOfArcs(Arc[] array, int pointer) { + this.array = array; + // this.pointer=pointer; + setPointer(pointer); + } + + /** + * Makes new CArray from other CArray + * + * @param carray + * reference array + */ + public CArrayOfArcs(CArrayOfArcs carray) { + this.array = carray.array; + // this.pointer=carray.pointer; + setPointer(carray.pointer); + } + + /** + * Makes new CArray with pointer set to 0 + * + * @param ctlarray + * underlaying array + */ + public CArrayOfArcs(Arc[] ctlarray) { + this.array = ctlarray; + this.pointer = 0; + } + + /** + * Returns element at pointer + * + * @return element at pointer + */ + public Arc get() { + return array[pointer]; + } + + /** + * Increases pointer by one (++) + */ + public void pp() { + // pointer++; + setPointer(pointer + 1); + } + + /** + * Sets element at pointer + * + * @param f + * desired value + */ + public void set(Arc f) { + array[pointer] = f; + + } + + /** + * Returns array element at specified index + * + * @param i + * array index + * @return element at index + */ + public Arc get(int i) { + return array[i]; + } + + /** + * Returns array element at specified index relatively to pointer + * + * @param i + * relative index + * @return element at relative index + */ + public Arc getRelative(int i) { + return array[pointer + i]; + } + + /** + * Sets value of element at specified index relatively to pointer + * + * @param i + * relative index + * @param value + * value to be set + */ + public void setRelative(int i, Arc value) { + array[pointer + i] = value; + } + + /** + * Lessens pointer by value + * + * @param i + * lessen by + */ + public void lessenPointerBy(int i) { + // pointer-=i; + setPointer(pointer - i); + } + + /** + * Returns pointer value + * + * @return pointer value + */ + public int getPointer() { + return pointer; + } + + /** + * Sets ponter value + * + * @param pointer + * pointer value to be set + */ + public void setPointer(int pointer) { + if (!noCheck && pointer > array.length) + throw new IllegalArgumentException("Pointer " + pointer + + " out of bounds " + array.length); + this.pointer = pointer; + } + + /** + * Raises pointer by value + * + * @param i + * raise by + */ + public void raisePointerBy(int i) { + // pointer+=i; + setPointer(pointer + i); + } + + /** + * Lessens ponter by one (--) + */ + public void mm() { + // pointer--; + setPointer(pointer - 1); + } + + /** + * Returns underlaying array + * + * @return underlaying array + */ + public Arc[] getArray() { + return array; + } + + /** + * Sets underlaying array + * + * @param array + * underlaying array + */ + public void setArray(Arc[] array) { + this.array = array; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfBreakpts.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfBreakpts.java new file mode 100644 index 000000000..5112b07fc --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfBreakpts.java @@ -0,0 +1,130 @@ +package jogamp.opengl.glu.nurbs; + +/** + * Class replacing C language pointer + * + * @author Tomas Hrasky + * + */ +public class CArrayOfBreakpts { + /** + * Underlaying array + */ + private Breakpt[] pole; + + /** + * Pointer to array member + */ + private int pointer; + + /** + * Makes new CArray + * + * @param array + * underlaying array + * @param pointer + * pointer (index) to array + */ + public CArrayOfBreakpts(Breakpt[] array, int pointer) { + this.pole = array; + this.pointer = pointer; + } + + /** + * Makes new CArray from other CArray + * + * @param carray + * reference array + */ + public CArrayOfBreakpts(CArrayOfBreakpts carray) { + this.pole = carray.pole; + this.pointer = carray.pointer; + } + + /** + * Returns element at pointer + * + * @return element at pointer + */ + public Breakpt get() { + return pole[pointer]; + } + + /** + * Increases pointer by one (++) + */ + public void pp() { + pointer++; + } + + /** + * Sets element at pointer + * + * @param f + * desired value + */ + public void set(Breakpt f) { + pole[pointer] = f; + + } + + /** + * Returns array element at specified index + * + * @param i + * array index + * @return element at index + */ + public Breakpt get(int i) { + return pole[i]; + } + + /** + * Lessens pointer by value + * + * @param i + * lessen by + */ + public void lessenPointerBy(int i) { + pointer -= i; + + } + + /** + * Returns pointer value + * + * @return pointer value + */ + public int getPointer() { + return pointer; + } + + /** + * Sets ponter value + * + * @param pointer + * pointer value to be set + */ + public void setPointer(int pointer) { + this.pointer = pointer; + } + + /** + * Raises pointer by value + * + * @param i + * raise by + */ + public void raisePointerBy(int i) { + pointer += i; + + } + + /** + * Lessens ponter by one (--) + */ + public void mm() { + pointer--; + + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfFloats.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfFloats.java new file mode 100644 index 000000000..39ef841ec --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfFloats.java @@ -0,0 +1,195 @@ +package jogamp.opengl.glu.nurbs; + +/** + * Class replacing C language pointer + * + * @author Tomas Hrasky + * + */ +public class CArrayOfFloats { + + /** + * Underlaying array + */ + private float[] array; + + /** + * Pointer to array member + */ + private int pointer; + + /** + * Don't check for array borders? + */ + private boolean noCheck = true; + + /** + * Makes new CArray + * + * @param array + * underlaying array + * @param pointer + * pointer (index) to array + */ + public CArrayOfFloats(float[] array, int pointer) { + this.array = array; + // this.pointer=pointer; + setPointer(pointer); + } + + /** + * Makes new CArray from other CArray + * + * @param carray + * reference array + */ + public CArrayOfFloats(CArrayOfFloats carray) { + this.array = carray.array; + // this.pointer=carray.pointer; + setPointer(carray.pointer); + } + + /** + * Makes new CArray with pointer set to 0 + * + * @param ctlarray + * underlaying array + */ + public CArrayOfFloats(float[] ctlarray) { + this.array = ctlarray; + this.pointer = 0; + } + + /** + * Returns element at pointer + * + * @return element at pointer + */ + public float get() { + return array[pointer]; + } + + /** + * Increases pointer by one (++) + */ + public void pp() { + // pointer++; + setPointer(pointer + 1); + } + + /** + * Sets element at pointer + * + * @param f + * desired value + */ + public void set(float f) { + array[pointer] = f; + + } + + /** + * Returns array element at specified index + * + * @param i + * array index + * @return element at index + */ + public float get(int i) { + return array[i]; + } + + /** + * Returns array element at specified index relatively to pointer + * + * @param i + * relative index + * @return element at relative index + */ + public float getRelative(int i) { + return array[pointer + i]; + } + + /** + * Sets value of element at specified index relatively to pointer + * + * @param i + * relative index + * @param value + * value to be set + */ + public void setRelative(int i, float value) { + array[pointer + i] = value; + } + + /** + * Lessens pointer by value + * + * @param i + * lessen by + */ + public void lessenPointerBy(int i) { + // pointer-=i; + setPointer(pointer - i); + } + + /** + * Returns pointer value + * + * @return pointer value + */ + public int getPointer() { + return pointer; + } + + /** + * Sets ponter value + * + * @param pointer + * pointer value to be set + */ + public void setPointer(int pointer) { + if (!noCheck && pointer > array.length) + throw new IllegalArgumentException("Pointer " + pointer + + " out of bounds " + array.length); + this.pointer = pointer; + } + + /** + * Raises pointer by value + * + * @param i + * raise by + */ + public void raisePointerBy(int i) { + // pointer+=i; + setPointer(pointer + i); + } + + /** + * Lessens ponter by one (--) + */ + public void mm() { + // pointer--; + setPointer(pointer - 1); + } + + /** + * Returns underlaying array + * + * @return underlaying array + */ + public float[] getArray() { + return array; + } + + /** + * Sets underlaying array + * + * @param array + * underlaying array + */ + public void setArray(float[] array) { + this.array = array; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfQuiltspecs.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfQuiltspecs.java new file mode 100644 index 000000000..4b21f2d50 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/CArrayOfQuiltspecs.java @@ -0,0 +1,160 @@ +package jogamp.opengl.glu.nurbs; + +/** + * Class replacing C language pointer + * + * @author Tomas Hrasky + * + */ +public class CArrayOfQuiltspecs { + /** + * Underlaying array + */ + private Quiltspec[] array; + + /** + * Pointer to array member + */ + private int pointer; + + /** + * Makes new CArray + * + * @param array + * underlaying array + * @param pointer + * pointer (index) to array + */ + public CArrayOfQuiltspecs(Quiltspec[] array, int pointer) { + this.array = array; + this.pointer = pointer; + } + + /** + * Makes new CArray from other CArray + * + * @param carray + * reference array + */ + public CArrayOfQuiltspecs(CArrayOfQuiltspecs carray) { + this.array = carray.array; + this.pointer = carray.pointer; + } + + /** + * Makes new CArray with pointer set to 0 + * + * @param array + * underlaying array + */ + public CArrayOfQuiltspecs(Quiltspec[] array) { + this.array = array; + this.pointer = 0; + } + + /** + * Returns element at pointer + * + * @return element at pointer + */ + public Quiltspec get() { + return array[pointer]; + } + + /** + * Increases pointer by one (++) + */ + public void pp() { + pointer++; + } + + /** + * Sets element at pointer + * + * @param f + * desired value + */ + public void set(Quiltspec f) { + array[pointer] = f; + + } + + /** + * Returns array element at specified index + * + * @param i + * array index + * @return element at index + */ + public Quiltspec get(int i) { + return array[i]; + } + + /** + * Lessens pointer by value + * + * @param i + * lessen by + */ + public void lessenPointerBy(int i) { + pointer -= i; + + } + + /** + * Returns pointer value + * + * @return pointer value + */ + public int getPointer() { + return pointer; + } + + /** + * Sets ponter value + * + * @param pointer + * pointer value to be set + */ + public void setPointer(int pointer) { + this.pointer = pointer; + } + + /** + * Raises pointer by value + * + * @param i + * raise by + */ + public void raisePointerBy(int i) { + pointer += i; + + } + + /** + * Lessens ponter by one (--) + */ + public void mm() { + pointer--; + + } + + /** + * Returns underlaying array + * + * @return underlaying array + */ + public Quiltspec[] getArray() { + return array; + } + + /** + * Sets underlaying array + * + * @param array + * underlaying array + */ + public void setArray(Quiltspec[] array) { + this.array = array; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Curve.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Curve.java new file mode 100644 index 000000000..b0ff4e6e5 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Curve.java @@ -0,0 +1,238 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class holding curve definition + * @author Tomáš Hráský + * + */ +public class Curve { + + /** + * Maximum coordinates per control point + */ + private static final int MAXCOORDS = 5; + + /** + * Max curve order + */ + private static final int MAXORDER = 24; + + /** + * Next curve in linked list + */ + public Curve next; + + /** + * OpenGL maps + */ + private Mapdesc mapdesc; + + /** + * Does the curve need sampling + */ + private boolean needsSampling; + + /** + * Culling + */ + private int cullval; + + /** + * Number of coords + */ + private int stride; + + /** + * Curve order + */ + private int order; + + /** + * Holds conversion range borders + */ + private float[] range; + + /** + * Subdivision stepsize + */ + public float stepsize; + + /** + * Minimal subdivision stepsize + */ + private float minstepsize; + + /** + * Sampling points + */ + float[] spts; + + /** + * Makes new Curve + * + * @param geo + * @param pta + * @param ptb + * @param c + * next curve in linked list + */ + public Curve(Quilt geo, float[] pta, float[] ptb, Curve c) { + + spts = new float[MAXORDER * MAXCOORDS]; + + mapdesc = geo.mapdesc; + + next = c; + needsSampling = mapdesc.isRangeSampling() ? true : false; + + cullval = mapdesc.isCulling() ? Subdivider.CULL_ACCEPT + : Subdivider.CULL_TRIVIAL_REJECT; + order = geo.qspec.get(0).order; + stride = MAXCOORDS; + + // CArrayOfFloats ps = geo.cpts; + CArrayOfFloats ps = new CArrayOfFloats(geo.cpts.getArray(), 0); + CArrayOfQuiltspecs qs = geo.qspec; + ps.raisePointerBy(qs.get().offset); + ps.raisePointerBy(qs.get().index * qs.get().order * qs.get().stride); + + if (needsSampling) { + mapdesc.xformSampling(ps, qs.get().order, qs.get().stride, spts, + stride); + } + if (cullval == Subdivider.CULL_ACCEPT) { + // System.out.println("TODO curve.Curve-cullval"); + // mapdesc.xformCulling(ps,qs.get().order,qs.get().stride,cpts,stride); + } + + range = new float[3]; + range[0] = qs.get().breakpoints[qs.get().index]; + range[1] = qs.get().breakpoints[qs.get().index + 1]; + range[2] = range[1] - range[0]; + // TODO it is necessary to solve problem with "this" pointer here + if (range[0] != pta[0]) { + // System.out.println("TODO curve.Curve-range0"); + // Curve lower=new Curve(this,pta,0); + // lower.next=next; + // this=lower; + } + if (range[1] != ptb[0]) { + // System.out.println("TODO curve.Curve-range1"); + // Curve lower=new Curve(this,ptb,0); + } + } + + /** + * Checks culling type + * @return Subdivider.CULL_ACCEPT + */ + public int cullCheck() { + if (cullval == Subdivider.CULL_ACCEPT) { + // System.out.println("TODO curve.cullval"); + // cullval=mapdesc.cullCheck(cpts,order,stride); + } + // TODO compute cullval and return the computed value + // return cullval; + return Subdivider.CULL_ACCEPT; + } + + /** + * Computes subdivision step size + */ + public void getStepSize() { + minstepsize = 0; + if (mapdesc.isConstantSampling()) { + setstepsize(mapdesc.maxrate); + } else if (mapdesc.isDomainSampling()) { + setstepsize(mapdesc.maxrate * range[2]); + } else { + assert (order <= MAXORDER); + + float tmp[][] = new float[MAXORDER][MAXCOORDS]; + + int tstride = (MAXORDER); + + int val = 0; + // mapdesc.project(spts,stride,tmp,tstride,order); + + // System.out.println("TODO curve.getsptepsize mapdesc.project"); + + if (val == 0) { + setstepsize(mapdesc.maxrate); + } else { + float t = mapdesc.getProperty(NurbsConsts.N_PIXEL_TOLERANCE); + if (mapdesc.isParametricDistanceSampling()) { + // System.out.println("TODO curve.getstepsize - parametric"); + } else if (mapdesc.isPathLengthSampling()) { + // System.out.println("TODO curve.getstepsize - pathlength"); + } else { + setstepsize(mapdesc.maxrate); + } + } + + } + + } + + /** + * Sets maximum subdivision step size + * @param max maximum subdivision step size + */ + private void setstepsize(float max) { + // DONE + stepsize = (max >= 1) ? (range[2] / max) : range[2]; + minstepsize = stepsize; + } + + /** + * Clamps the curve + */ + public void clamp() { + // DONE + if (stepsize < minstepsize) + stepsize = mapdesc.clampfactor * minstepsize; + } + + /** + * Tells whether curve needs subdivision + * + * @return curve needs subdivison + */ + public boolean needsSamplingSubdivision() { + return (stepsize < minstepsize); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/CurveEvaluator.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/CurveEvaluator.java new file mode 100644 index 000000000..92dadf648 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/CurveEvaluator.java @@ -0,0 +1,86 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class rendering curves with OpenGL + * @author Tomáš Hráský + * + */ +public interface CurveEvaluator { + /** + * Pushes eval bit + */ + public void bgnmap1f(); + + /** + * Pops all OpenGL attributes + */ + public void endmap1f() ; + + /** + * Initializes opengl evaluator + * @param type curve type + * @param ulo lowest u + * @param uhi highest u + * @param stride control point coords + * @param order curve order + * @param ps control points + */ + public void map1f(int type, float ulo, float uhi, int stride, int order, + CArrayOfFloats ps) ; + + /** + * Calls opengl enable + * @param type what to enable + */ + public void enable(int type) ; + + /** + * Calls glMapGrid1f + * @param nu steps + * @param u1 low u + * @param u2 high u + */ + public void mapgrid1f(int nu, float u1, float u2) ; + + /** + * Evaluates a curve using glEvalMesh1f + * @param style Backend.N_MESHFILL/N_MESHLINE/N_MESHPOINT + * @param from lowest param + * @param to highest param + */ + public void mapmesh1f(int style, int from, int to) ; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Curvelist.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Curvelist.java new file mode 100644 index 000000000..80baf207b --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Curvelist.java @@ -0,0 +1,121 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class for woking with linked list of curves + * @author Tomas Hrasky + * + */ +public class Curvelist { + + /** + * Head of linked list + */ + private Curve curve; + + /** + * Holds conversion range borders + */ + float[] range; + + /** + * Subdivision step size + */ + public float stepsize; + + /** + * Do curves need subdivision? + */ + private boolean needsSubdivision; + + /** + * Makes new instance on top of specified lis of Quilts + * @param qlist underlaying list of quilts + * @param pta range start + * @param ptb range end + */ + public Curvelist(Quilt qlist, float[] pta, float[] ptb) { + // DONE + curve = null; + range = new float[3]; + + for (Quilt q = qlist; q != null; q = q.next) { + curve = new Curve(q, pta, ptb, curve); + } + range[0] = pta[0]; + range[1] = ptb[0]; + range[2] = range[1] - range[0]; + } + + /** + * Compute step size + */ + public void getstepsize() { + // DONE + stepsize = range[2]; + Curve c; + for (c = curve; c != null; c = c.next) { + c.getStepSize(); + c.clamp(); + stepsize = (c.stepsize < stepsize) ? c.stepsize : stepsize; + if (c.needsSamplingSubdivision()) + break; + } + needsSubdivision = (c != null) ? true : false; + + } + + /** + * Indicates whether curves need subdivision + * @return curves need subdivision + */ + public boolean needsSamplingSubdivision() { + // DONE + return needsSubdivision; + } + + /** + * Checks for culling + * @return Subdivider.CULL_TRIVIAL_REJECT or Subdivider.CULL_ACCEPT + */ + public int cullCheck() { + // DONE + for (Curve c = curve; c != null; c = c.next) + if (c.cullCheck() == Subdivider.CULL_TRIVIAL_REJECT) + return Subdivider.CULL_TRIVIAL_REJECT; + return Subdivider.CULL_ACCEPT; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/DisplayList.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/DisplayList.java new file mode 100644 index 000000000..5c80ffd30 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/DisplayList.java @@ -0,0 +1,56 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +import java.lang.reflect.Method; + +/** + * Display list + * @author Tomas Hrasky + * + */ +public class DisplayList { + + /** + * Append action to the display list + * @param src source object to invoke method on + * @param m invoked method + * @param arg method argument + */ + public void append(Object src, Method m, Object arg) { + // TODO Auto-generated method stub + // System.out.println("TODO displaylist append"); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Flist.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Flist.java new file mode 100644 index 000000000..6983691d9 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Flist.java @@ -0,0 +1,130 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +import java.util.Arrays; + +/** + * List of breakpoints + * @author Tomas Hrasky + * + */ +public class Flist { + + /** + * Data elements end index + * + */ + public int end; + + /** + *Data elements start index + */ + public int start; + + /** + * Breakpoint values + */ + public float[] pts; + + /** + * Number of array fields + */ + private int npts; + + /** + * Grows list + * @param maxpts maximum desired size + */ + public void grow(int maxpts) { + // DONE + if (npts < maxpts) { + // npts=2*maxpts; + npts = maxpts; + pts = new float[npts]; + } + start = 0; + end = 0; + } + + /** + * Removes duplicate array elemnts + */ + public void filter() { + // INFO the aim of this method is to remove duplicates from array + + Arrays.sort(pts); + + start = 0; + + int j = 0; + + for (int i = 1; i < end; i++) { + if (pts[i] == pts[i - j - 1]) + j++; + pts[i - j] = pts[i]; + } + + end -= j; + + } + + /** + * Sets start and and to real start and end of array elements + * @param from start from + * @param to end at + */ + public void taper(float from, float to) { + // DONE + + while (pts[start] != from) { + start++; + } + + while (pts[end - 1] != to) { + end--; + } + + } + + /** + * Adds breakpoint value + * @param f value + */ + public void add(float f) { + //DONE + pts[end++] = f; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotspec.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotspec.java new file mode 100644 index 000000000..4f97b1271 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotspec.java @@ -0,0 +1,557 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Knot vector specification + * + * @author Tomas Hrasky + * + */ +public class Knotspec { + + /** + * Begin of input knots + */ + public CArrayOfFloats inkbegin; + + /** + * End of input knots + */ + public CArrayOfFloats inkend; + + /** + * Stride before knot operations + */ + public int prestride; + + /** + * Curve order + */ + public int order; + + /** + * Next knot specification in linked list (used in surfaces) + */ + public Knotspec next; + + /** + * Last knot + */ + public CArrayOfFloats klast; + + /** + * First knot + */ + CArrayOfFloats kfirst; + + /** + * Beginning of breakpoints + */ + CArrayOfBreakpts bbegin; + + /** + * End of breakpoints + */ + CArrayOfBreakpts bend; + + /** + * Considered left end knot + */ + CArrayOfFloats kleft; + + /** + * Considered right end knot + */ + CArrayOfFloats kright; + + /** + * Offset before knot operations + */ + int preoffset; + + /** + * Control points array Length after knot operations + */ + int postwidth; + + /** + * Beginning of coeficients array + */ + private CArrayOfFloats sbegin; + + /** + * Beginning of output knots + */ + private CArrayOfFloats outkbegin; + + /** + * End of output knots + */ + private CArrayOfFloats outkend; + + /** + * Control points aray length before knot operations + */ + int prewidth; + + /** + * Offset after knot operations + */ + int postoffset; + + /** + * Number of control points' coordinates after knot operations + */ + public int poststride; + + /** + * Number of control points' coordinates + */ + public int ncoords; + + /** + * Tell whether knotspec has already benn transformed + */ + public boolean istransformed; + + /** + * Knotspec to be transformed + */ + public Knotspec kspectotrans; + + /** + * Finds knot border of knot insertion and required multiplicities + */ + public void preselect() { + // DONE + float kval; + + klast = new CArrayOfFloats(inkend); + klast.lessenPointerBy(order); + for (kval = klast.get(); klast.getPointer() != inkend.getPointer(); klast + .pp()) { + if (!Knotvector.identical(klast.get(), kval)) + break; + } + + kfirst = new CArrayOfFloats(inkbegin); + kfirst.raisePointerBy(order - 1); + for (kval = kfirst.get(); kfirst.getPointer() != inkend.getPointer(); kfirst + .pp()) { + if (!Knotvector.identical(kfirst.get(), kval)) + break; + } + + CArrayOfFloats k = new CArrayOfFloats(kfirst); + k.mm(); + + for (; k.getPointer() >= inkbegin.getPointer(); k.mm()) + if (!Knotvector.identical(kval, k.get())) + break; + k.pp(); + + Breakpt[] bbeginArray = new Breakpt[(klast.getPointer() - kfirst + .getPointer()) + 1]; + for (int i = 0; i < bbeginArray.length; i++) + bbeginArray[i] = new Breakpt(); + bbegin = new CArrayOfBreakpts(bbeginArray, 0); + bbegin.get().multi = kfirst.getPointer() - k.getPointer(); + bbegin.get().value = kval; + + bend = new CArrayOfBreakpts(bbegin); + kleft = new CArrayOfFloats(kfirst); + kright = new CArrayOfFloats(kfirst); + + } + + /** + * Perpares knotspec for transformation + */ + public void select() { + // DONE + breakpoints(); + knots(); + factors(); + + preoffset = kleft.getPointer() - (inkbegin.getPointer() + order); + postwidth = ((bend.getPointer() - bbegin.getPointer()) * order); + prewidth = (outkend.getPointer() - outkbegin.getPointer()) - order; + postoffset = (bbegin.get().def > 1) ? (bbegin.get().def - 1) : 0; + + } + + /** + * Computes alpha factors for computing new control points + */ + private void factors() { + // DONE + CArrayOfFloats mid = new CArrayOfFloats(outkend.getArray(), (outkend + .getPointer() - 1) + - order + bend.get().multi); + + CArrayOfFloats fptr = null; + if (sbegin != null) + fptr = new CArrayOfFloats(sbegin); + + for (CArrayOfBreakpts bpt = new CArrayOfBreakpts(bend); bpt + .getPointer() >= bbegin.getPointer(); bpt.mm()) { + mid.lessenPointerBy(bpt.get().multi); + int def = bpt.get().def - 1; + if (def < 0) + continue; + float kv = bpt.get().value; + + CArrayOfFloats kf = new CArrayOfFloats(mid.getArray(), (mid + .getPointer() - def) + + (order - 1)); + for (CArrayOfFloats kl = new CArrayOfFloats(kf.getArray(), kf + .getPointer() + + def); kl.getPointer() != kf.getPointer(); kl.mm()) { + CArrayOfFloats kh, kt; + for (kt = new CArrayOfFloats(kl), kh = new CArrayOfFloats(mid); kt + .getPointer() != kf.getPointer(); kh.mm(), kt.mm()) { + fptr.set((kv - kh.get()) / (kt.get() - kh.get())); + fptr.pp(); + } + kl.set(kv); + } + } + + } + + /** + * Makes new knot vector + */ + private void knots() { + // DONE + CArrayOfFloats inkpt = new CArrayOfFloats(kleft.getArray(), kleft + .getPointer() + - order); + CArrayOfFloats inkend = new CArrayOfFloats(kright.getArray(), kright + .getPointer() + + bend.get().def); + + outkbegin = new CArrayOfFloats(new float[inkend.getPointer() + - inkpt.getPointer()], 0); + CArrayOfFloats outkpt; + for (outkpt = new CArrayOfFloats(outkbegin); inkpt.getPointer() != inkend + .getPointer(); inkpt.pp(), outkpt.pp()) { + outkpt.set(inkpt.get()); + } + outkend = new CArrayOfFloats(outkpt); + } + + /** + * Analyzes breakpoints + */ + private void breakpoints() { + // DONE + CArrayOfBreakpts ubpt = new CArrayOfBreakpts(bbegin); + CArrayOfBreakpts ubend = new CArrayOfBreakpts(bend); + int nfactors = 0; + + ubpt.get().value = ubend.get().value; + ubpt.get().multi = ubend.get().multi; + + kleft = new CArrayOfFloats(kright); + + for (; kright.getPointer() != klast.getPointer(); kright.pp()) { + if (Knotvector.identical(kright.get(), ubpt.get().value)) { + ubpt.get().multi++; + } else { + ubpt.get().def = order - ubpt.get().multi; + nfactors += (ubpt.get().def * (ubpt.get().def - 1)) / 2; + ubpt.pp(); + ubpt.get().value = kright.get(); + ubpt.get().multi = 1; + } + } + ubpt.get().def = order - ubpt.get().multi; + nfactors += (ubpt.get().def * (ubpt.get().def - 1)) / 2; + + bend = new CArrayOfBreakpts(ubpt); + + if (nfactors > 0) { + sbegin = new CArrayOfFloats(new float[nfactors], 0); + } else { + sbegin = null; + } + + } + + /** + * Copies control points + * + * @param _inpt + * input control points + * @param _outpt + * output control points + */ + public void copy(CArrayOfFloats _inpt, CArrayOfFloats _outpt) { + CArrayOfFloats inpt = new CArrayOfFloats(_inpt); + CArrayOfFloats outpt = new CArrayOfFloats(_outpt); + + inpt.raisePointerBy(preoffset); + if (next != null) { + for (CArrayOfFloats lpt = new CArrayOfFloats(outpt.getArray(), + outpt.getPointer() + prewidth); outpt.getPointer() != lpt + .getPointer(); outpt.raisePointerBy(poststride)) { + next.copy(inpt, outpt); + inpt.raisePointerBy(prestride); + } + + } else { + for (CArrayOfFloats lpt = new CArrayOfFloats(outpt.getArray(), + outpt.getPointer() + prewidth); outpt.getPointer() != lpt + .getPointer(); outpt.raisePointerBy(poststride)) { + pt_io_copy(outpt, inpt); + inpt.raisePointerBy(prestride); + } + } + + } + + /** + * Copies one control point to other + * + * @param topt + * source control point + * @param frompt + * destination control point + */ + private void pt_io_copy(CArrayOfFloats topt, CArrayOfFloats frompt) { + // DONE + switch (ncoords) { + case 4: + topt.setRelative(3, frompt.getRelative(3)); + case 3: + topt.setRelative(2, frompt.getRelative(2)); + case 2: + topt.setRelative(1, frompt.getRelative(1)); + case 1: + topt.set(frompt.get()); + break; + default: + // TODO break with copying in general case + // System.out.println("TODO knotspec.pt_io_copy"); + break; + } + + } + + /** + * Inserts a knot + * + * @param _p + * inserted knot + */ + public void transform(CArrayOfFloats _p) { + CArrayOfFloats p = new CArrayOfFloats(_p); + // DONE + if (next != null) {//surface code + if (this.equals(kspectotrans)) { + next.transform(p); + } else { + if (istransformed) { + p.raisePointerBy(postoffset); + for (CArrayOfFloats pend = new CArrayOfFloats(p.getArray(), + p.getPointer() + postwidth); p.getPointer() != pend + .getPointer(); p.raisePointerBy(poststride)) + next.transform(p); + + } else { + CArrayOfFloats pend = new CArrayOfFloats(p.getArray(), p + .getPointer() + + prewidth); + for (; p.getPointer() != pend.getPointer(); p + .raisePointerBy(poststride)) + next.transform(p); + } + } + + } else {//code for curve + if (this.equals(kspectotrans)) { + insert(p); + } else { + if (istransformed) { + p.raisePointerBy(postoffset); + for (CArrayOfFloats pend = new CArrayOfFloats(p.getArray(), + p.getPointer() + postwidth); p.getPointer() != pend + .getPointer(); p.raisePointerBy(poststride)) { + kspectotrans.insert(p); + } + } else { + CArrayOfFloats pend = new CArrayOfFloats(p.getArray(), p + .getPointer() + + prewidth); + for (; p.getPointer() != pend.getPointer(); p + .raisePointerBy(poststride)) + kspectotrans.insert(p); + } + } + } + + } + + /** + * Inserts a knot and computes new control points + * + * @param p + * inserted knot + */ + private void insert(CArrayOfFloats p) { + // DONE + CArrayOfFloats fptr = null; + if (sbegin != null) + fptr = new CArrayOfFloats(sbegin); + CArrayOfFloats srcpt = new CArrayOfFloats(p.getArray(), p.getPointer() + + prewidth - poststride); + // CArrayOfFloats srcpt = new CArrayOfFloats(p.getArray(), prewidth - + // poststride); + CArrayOfFloats dstpt = new CArrayOfFloats(p.getArray(), p.getPointer() + + postwidth + postoffset - poststride); + // CArrayOfFloats dstpt = new CArrayOfFloats(p.getArray(), postwidth + + // postoffset - poststride); + CArrayOfBreakpts bpt = new CArrayOfBreakpts(bend); + + for (CArrayOfFloats pend = new CArrayOfFloats(srcpt.getArray(), srcpt + .getPointer() + - poststride * bpt.get().def); srcpt.getPointer() != pend + .getPointer(); pend.raisePointerBy(poststride)) { + CArrayOfFloats p1 = new CArrayOfFloats(srcpt); + for (CArrayOfFloats p2 = new CArrayOfFloats(srcpt.getArray(), srcpt + .getPointer() + - poststride); p2.getPointer() != pend.getPointer(); p1 + .setPointer(p2.getPointer()), p2 + .lessenPointerBy(poststride)) { + pt_oo_sum(p1, p1, p2, fptr.get(), 1.0 - fptr.get()); + fptr.pp(); + } + } + bpt.mm(); + for (; bpt.getPointer() >= bbegin.getPointer(); bpt.mm()) { + + for (int multi = bpt.get().multi; multi > 0; multi--) { + pt_oo_copy(dstpt, srcpt); + dstpt.lessenPointerBy(poststride); + srcpt.lessenPointerBy(poststride); + } + for (CArrayOfFloats pend = new CArrayOfFloats(srcpt.getArray(), + srcpt.getPointer() - poststride * bpt.get().def); srcpt + .getPointer() != pend.getPointer(); pend + .raisePointerBy(poststride), dstpt + .lessenPointerBy(poststride)) { + pt_oo_copy(dstpt, srcpt); + CArrayOfFloats p1 = new CArrayOfFloats(srcpt); + + for (CArrayOfFloats p2 = new CArrayOfFloats(srcpt.getArray(), + srcpt.getPointer() - poststride); p2.getPointer() != pend + .getPointer(); p1.setPointer(p2.getPointer()), p2 + .lessenPointerBy(poststride)) { + pt_oo_sum(p1, p1, p2, fptr.get(), 1.0 - fptr.get()); + fptr.pp(); + } + } + } + } + + /** + * Copies one control point to another + * + * @param topt + * source ctrl point + * @param frompt + * distance ctrl point + */ + private void pt_oo_copy(CArrayOfFloats topt, CArrayOfFloats frompt) { + // DONE + // this is a "trick" with case - "break" is omitted so it comes through all cases + switch (ncoords) { + case 4: + topt.setRelative(3, frompt.getRelative(3)); + case 3: + topt.setRelative(2, frompt.getRelative(2)); + case 2: + topt.setRelative(1, frompt.getRelative(1)); + case 1: + topt.setRelative(0, frompt.getRelative(0)); + break; + default: + // default uses memcpy but it is not needed (we probably won't have more than 4 coords) + // TODO not sure about it + break; + } + + } + + /** + * Computes new control point + * + * @param x + * first point + * @param y + * second point + * @param z + * third pont + * @param a + * alpha + * @param b + * 1 - alpha + */ + private void pt_oo_sum(CArrayOfFloats x, CArrayOfFloats y, + CArrayOfFloats z, float a, double b) { + // DONE + switch (ncoords) { + case 4: + x.setRelative(3, (float) (a * y.getRelative(3) + b + * z.getRelative(3))); + case 3: + x.setRelative(2, (float) (a * y.getRelative(2) + b + * z.getRelative(2))); + case 2: + x.setRelative(1, (float) (a * y.getRelative(1) + b + * z.getRelative(1))); + case 1: + x.setRelative(0, (float) (a * y.getRelative(0) + b + * z.getRelative(0))); + break; + default: + //no need of default - see previous method and its case statement + // System.out.println("TODO pt_oo_sum default"); + break; + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotvector.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotvector.java new file mode 100644 index 000000000..89389dea6 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotvector.java @@ -0,0 +1,179 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Knot vector used in curve specification + * + * @author Tomas Hrasky + * + */ +public class Knotvector { + + /** + * Tolerance used when comparing knots - when difference is smaller, knots + * are considered equal + */ + public static final float TOLERANCE = 1.0e-5f; + + /** + * Maximum curve order + */ + private static final int MAXORDER = 24; + + /** + * Number of knots + */ + int knotcount; + + /** + * Number of control points' coordinates + */ + int stride; + + /** + * Curve order + */ + int order; + + /** + * Knots + */ + float[] knotlist; + + /** + * Makes new knotvector + * + * @param nknots + * number of knots + * @param stride + * number of ctrl points' corrdinates + * @param order + * curve order + * @param knot + * knots + */ + public Knotvector(int nknots, int stride, int order, float[] knot) { + // DONE + init(nknots, stride, order, knot); + } + + /** + * Initializes knotvector + * + * @param nknots + * number of knots + * @param stride + * number of ctrl points' corrdinates + * @param order + * curve order + * @param knot + * knots + */ + public void init(int nknots, int stride, int order, float[] knot) { + // DONE + this.knotcount = nknots; + this.stride = stride; + this.order = order; + this.knotlist = new float[nknots]; + for (int i = 0; i < nknots; i++) { + this.knotlist[i] = knot[i]; + } + + } + + /** + * Validates knot vector parameters + * + * @return knot vector validity + */ + public int validate() { + int kindex = knotcount - 1; + if (order < 1 || order > MAXORDER) { + return 1; + } + if (knotcount < 2 * order) { + return 2; + } + if (identical(knotlist[kindex - (order - 1)], knotlist[order - 1])) { + return 3; + } + for (int i = 0; i < kindex; i++) { + if (knotlist[i] > knotlist[i + 1]) + return 4; + } + int multi = 1; + for (; kindex >= 1; kindex--) { + if (knotlist[kindex] - knotlist[kindex - 1] < TOLERANCE) { + multi++; + continue; + } + if (multi > order) { + return 5; + } + multi = 1; + } + if (multi > order) { + return 5; + } + + return 0; + } + + /** + * Show specified message + * + * @param msg + * message to be shown + */ + public void show(String msg) { + // TODO Auto-generated method stub + // System.out.println("TODO knotvector.show"); + + } + + /** + * Compares two knots for equality + * + * @param a + * first knot + * @param b + * second knot + * @return knots are/are not equal + */ + public static boolean identical(float a, float b) { + return ((a - b) < TOLERANCE) ? true : false; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Mapdesc.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Mapdesc.java new file mode 100644 index 000000000..8fab114ff --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Mapdesc.java @@ -0,0 +1,442 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class holding properties of OpenGL map + * @author Tomas Hrasky + * + */ +public class Mapdesc { + + /** + * Maximum control point coords + */ + private static final int MAXCOORDS = 5; + + /** + * Next description in list + */ + public Mapdesc next; + + /** + * Is map rational + */ + public int isrational; + + /** + * Number of control point coords + */ + public int ncoords; + + /** + * Map type + */ + private int type; + + /** + * Number of homogenous coords + */ + private int hcoords; + + /** + * Number of inhomogenous coords + */ + private int inhcoords; + + /** + * Not used + */ + private int mask; + + /** + * Value of N_PIXEL_TOLERANCE property + */ + private float pixel_tolerance; + + /** + * Value of N_ERROR_TOLERANCE property + */ + private float error_tolerance; + + /** + * Value of N_BBOX_SUBDIVIDING property + */ + private float bbox_subdividing; + + /** + * Value of N_CULLING property + */ + private float culling_method; + + /** + * Value of N_SAMPLINGMETHOD property + */ + private float sampling_method; + + /** + * Value of N_CLAMPFACTOR property + */ + float clampfactor; + + /** + * Value of N_MINSAVINGS property + */ + private float minsavings; + + /** + * Steps in u direction + */ + private float s_steps; + + /** + * Steps in v direction + */ + private float t_steps; + + /** + * Maximal step + */ + float maxrate; + + /** + * Maximal u direction step + */ + private float maxsrate; + + /** + * Maximal v direction step + */ + private float maxtrate; + + /** + * Not used + */ + private float[][] bmat; + + /** + * Sampling matrix + */ + private float[][] smat; + + /** + * Not used + */ + private float[][] cmat; + + /** + * Not used + */ + private float[] bboxsize; + + /** + * Makes new mapdesc + * @param type map type + * @param rational is rational + * @param ncoords number of control points coords + * @param backend backend object + */ + public Mapdesc(int type, int rational, int ncoords, Backend backend) { + // DONE + this.type = type; + this.isrational = rational; + this.ncoords = ncoords; + this.hcoords = ncoords + (isrational > 0 ? 0 : 1); + this.inhcoords = ncoords - (isrational > 0 ? 1 : 0); + this.mask = ((1 << (inhcoords * 2)) - 1); + next = null; + + assert (hcoords <= MAXCOORDS); + assert (inhcoords >= 1); + + pixel_tolerance = 1f; + error_tolerance = 1f; + bbox_subdividing = NurbsConsts.N_NOBBOXSUBDIVISION; + culling_method = NurbsConsts.N_NOCULLING; + sampling_method = NurbsConsts.N_NOSAMPLING; + clampfactor = NurbsConsts.N_NOCLAMPING; + minsavings = NurbsConsts.N_NOSAVINGSSUBDIVISION; + s_steps = 0f; + t_steps = 0f; + + maxrate = (s_steps < 0) ? 0 : s_steps; + maxsrate = (s_steps < 0) ? 0 : s_steps; + maxtrate = (t_steps < 0) ? 0 : t_steps; + bmat = new float[MAXCOORDS][MAXCOORDS]; + cmat = new float[MAXCOORDS][MAXCOORDS]; + smat = new float[MAXCOORDS][MAXCOORDS]; + + identify(bmat); + identify(cmat); + identify(smat); + bboxsize = new float[MAXCOORDS]; + for (int i = 0; i < inhcoords; i++) + bboxsize[i] = 1; + } + + /** + * Make matrix identity matrix + * @param arr matrix + */ + private void identify(float[][] arr) { + // DONE + for (int i = 0; i < MAXCOORDS; i++) + for (int j = 0; j < MAXCOORDS; j++) + arr[i][j] = 0; + for (int i = 0; i < MAXCOORDS; i++) + arr[i][i] = 1; + + } + + /** + * Tells whether tag is property tag + * @param tag property tag + * @return is/is not property + */ + public boolean isProperty(int tag) { + boolean ret; + switch (tag) { + case NurbsConsts.N_PIXEL_TOLERANCE: + case NurbsConsts.N_ERROR_TOLERANCE: + case NurbsConsts.N_CULLING: + case NurbsConsts.N_BBOX_SUBDIVIDING: + case NurbsConsts.N_S_STEPS: + case NurbsConsts.N_T_STEPS: + case NurbsConsts.N_SAMPLINGMETHOD: + case NurbsConsts.N_CLAMPFACTOR: + case NurbsConsts.N_MINSAVINGS: + ret = true; + break; + default: + ret = false; + break; + } + return ret; + } + + /** + * Returns number of control points' coords + * @return number of control points' coords + */ + public int getNCoords() { + return ncoords; + } + + /** + * Returns map type + * @return map type + */ + public int getType() { + return type; + } + + /** + * Tells whether map is range sampling + * @return is map range sampling + */ + public boolean isRangeSampling() { + // DONE + return (isParametricDistanceSampling() || isPathLengthSampling() + || isSurfaceAreaSampling() || isObjectSpaceParaSampling() || isObjectSpacePathSampling()); + } + + /** + * Tells whether map is object space sampling + * @return is map object space sampling + */ + private boolean isObjectSpacePathSampling() { + // DONE + return sampling_method == NurbsConsts.N_OBJECTSPACE_PATH; + } + + /** + * Tells whether map is object space parasampling + * @return is map object space parasampling + */ + private boolean isObjectSpaceParaSampling() { + // DONE + return sampling_method == NurbsConsts.N_OBJECTSPACE_PARA; + } + + /** + * Tells whether map is area sampling surface + * @return is map area sampling surface + */ + private boolean isSurfaceAreaSampling() { + // DONE + return sampling_method == NurbsConsts.N_SURFACEAREA; + } + + /** + * Tells whether map is path length sampling + * @return is map path length sampling + */ + boolean isPathLengthSampling() { + // DONE + return sampling_method == NurbsConsts.N_PATHLENGTH; + } + + /** + * Tells whether map is parametric distance sampling + * @return is map parametric distance sampling + */ + boolean isParametricDistanceSampling() { + // DONE + return sampling_method == NurbsConsts.N_PARAMETRICDISTANCE; + } + + /** + * Tells whether map is culling + * @return is map culling + */ + public boolean isCulling() { + // DONE + return culling_method != NurbsConsts.N_NOCULLING ? true : false; + } + + /** + * Tells whether map is constantly sampling + * @return is map constant sampling + */ + public boolean isConstantSampling() { + return (sampling_method == NurbsConsts.N_FIXEDRATE) ? true : false; + } + + /** + * Tells whether map is domain sampling + * @return is map domain sampling + */ + public boolean isDomainSampling() { + return (sampling_method == NurbsConsts.N_DOMAINDISTANCE) ? true : false; + } + + /** + * Returns property of specified tag value + * @param tag property tag + * @return property value + */ + public float getProperty(int tag) { + // TODO Auto-generated method stub + // System.out.println("TODO mapdesc.getproperty"); + return 0; + } + + /** + * Sets property with given tag + * @param tag property tag + * @param value desired value + */ + public void setProperty(int tag, float value) { + // TODO Auto-generated method stub + switch (tag) { + case NurbsConsts.N_PIXEL_TOLERANCE: + pixel_tolerance = value; + break; + case NurbsConsts.N_ERROR_TOLERANCE: + error_tolerance = value; + break; + case NurbsConsts.N_CULLING: + culling_method = value; + break; + case NurbsConsts.N_BBOX_SUBDIVIDING: + if (value <= 0) + value = NurbsConsts.N_NOBBOXSUBDIVISION; + bbox_subdividing = value; + break; + case NurbsConsts.N_S_STEPS: + if (value < 0) + value = 0; + s_steps = value; + maxrate = value; + maxsrate = value; + break; + case NurbsConsts.N_T_STEPS: + if (value < 0) + value = 0; + t_steps = value; + maxtrate = value; + break; + case NurbsConsts.N_SAMPLINGMETHOD: + sampling_method = value; + break; + case NurbsConsts.N_CLAMPFACTOR: + if (value < 0) + value = 0; + clampfactor = value; + break; + case NurbsConsts.N_MINSAVINGS: + if (value <= 0) + value = NurbsConsts.N_NOSAVINGSSUBDIVISION; + minsavings = value; + break; + } + } + + /** + * Samples curve + * @param pts control points + * @param order curve order + * @param stride number of control points' coordinates + * @param sp breakpoints + * @param outstride output number of control points' coordinates + */ + public void xformSampling(CArrayOfFloats pts, int order, int stride, + float[] sp, int outstride) { + // DONE + xFormMat(smat, pts, order, stride, sp, outstride); + } + + /** + * Empty method + * @param mat sampling matrix + * @param pts ontrol points + * @param order curve order + * @param stride number of control points' coordinates + * @param cp breakpoints + * @param outstride output number of control points' coordinates + */ + private void xFormMat(float[][] mat, CArrayOfFloats pts, int order, + int stride, float[] cp, int outstride) { + // TODO Auto-generated method stub + + // System.out.println("TODO mapdsc.xformmat ; change cp from float[] to carrayoffloats"); + + if (isrational > 0) { + + } else { + + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Maplist.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Maplist.java new file mode 100644 index 000000000..af8024109 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Maplist.java @@ -0,0 +1,122 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class holding list of Mapdescs + * @author Tomáš Hráský + * + */ +public class Maplist { + /** + * Head of linked list + */ + private Mapdesc maps; + + /** + * Backend class + */ + private Backend backend; + + /** + * Makes new Maplist + * @param backend Backend class + */ + public Maplist(Backend backend) { + this.backend = backend; + } + + /** + * Sets linked list beginning to null + */ + public void initialize() { + // TODO mapdespool.clear ? + maps = null; + } + + /** + * Defines new Mapdesc if it is not defined and appends it to linked list + * @param type map type + * @param rational is map rational + * @param ncoords number of coords + */ + public void define(int type, int rational, int ncoords) { + // DONE + Mapdesc m = locate(type); + assert (m == null || (m.isrational == rational && m.ncoords == ncoords)); + add(type, rational, ncoords); + + } + + /** + * Adds new Mapdesc to linked list + * @param type map type + * @param rational is map rational + * @param ncoords number of coords + */ + private void add(int type, int rational, int ncoords) { + // DONE + Mapdesc map = new Mapdesc(type, rational, ncoords, backend); + if (maps == null) { + maps = map; + } else { + map.next = maps; + maps = map; + } + } + + /** + * Tries to find Mapdesc in linked list + * @param type map type + * @return Mapdesc of type or null if there is no such map + */ + public Mapdesc locate(int type) { + // DONE + Mapdesc m = null; + for (m = maps; m != null; m = m.next) + if (m.getType() == type) + break; + return m; + } + + /** + * Alias for locate + * @param type maptype + * @return Mapdesc of type or null if there is no such map + */ + public Mapdesc find(int type) { + return locate(type); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/NurbsConsts.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/NurbsConsts.java new file mode 100644 index 000000000..55a176db8 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/NurbsConsts.java @@ -0,0 +1,184 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class hodling NURBS constants as seen in OpenGL GLU documentation + * @author JOGL project + * + */ +public class NurbsConsts { + /* + * NURBS Properties - one set per map, each takes a single INREAL arg + */ + public static final int N_SAMPLING_TOLERANCE = 1; + + public static final int N_S_RATE = 6; + + public static final int N_T_RATE = 7; + + public static final int N_CLAMPFACTOR = 13; + + public static final float N_NOCLAMPING = 0.0f; + + public static final int N_MINSAVINGS = 14; + + public static final float N_NOSAVINGSSUBDIVISION = 0.0f; + + /* + * NURBS Properties - one set per map, each takes an enumerated value + */ + public static final int N_CULLING = 2; + + public static final float N_NOCULLING = 0.0f; + + public static final float N_CULLINGON = 1.0f; + + public static final int N_SAMPLINGMETHOD = 10; + + public static final float N_NOSAMPLING = 0.0f; + + public static final float N_FIXEDRATE = 3.0f; + + public static final float N_DOMAINDISTANCE = 2.0f; + + public static final float N_PARAMETRICDISTANCE = 5.0f; + + public static final float N_PATHLENGTH = 6.0f; + + public static final float N_SURFACEAREA = 7.0f; + + public static final float N_OBJECTSPACE_PARA = 8.0f; + + public static final float N_OBJECTSPACE_PATH = 9.0f; + + public static final int N_BBOX_SUBDIVIDING = 17; + + public static final float N_NOBBOXSUBDIVISION = 0.0f; + + public static final float N_BBOXTIGHT = 1.0f; + + public static final float N_BBOXROUND = 2.0f; + + /* + * NURBS Rendering Properties - one set per renderer each takes an + * enumerated value + */ + public static final int N_DISPLAY = 3; + + public static final int N_FILL = 1; + + public static final int N_OUTLINE_POLY = 2; + + public static final int N_OUTLINE_TRI = 3; + + public static final int N_OUTLINE_QUAD = 4; + + public static final int N_OUTLINE_PATCH = 5; + + public static final int N_OUTLINE_PARAM = 6; + + public static final int N_OUTLINE_PARAM_S = 7; + + public static final int N_OUTLINE_PARAM_ST = 8; + + public static final int N_OUTLINE_SUBDIV = 9; + + public static final int N_OUTLINE_SUBDIV_S = 10; + + public static final int N_OUTLINE_SUBDIV_ST = 11; + + public static final int N_ISOLINE_S = 12; + + public static final int N_ERRORCHECKING = 4; + + public static final int N_NOMSG = 0; + + public static final int N_MSG = 1; + + /* GL 4.0 propeties not defined above */ + + public static final int N_PIXEL_TOLERANCE = N_SAMPLING_TOLERANCE; + + public static final int N_ERROR_TOLERANCE = 20; + + public static final int N_SUBDIVISIONS = 5; + + public static final int N_TILES = 8; + + public static final int N_TMP1 = 9; + + public static final int N_TMP2 = N_SAMPLINGMETHOD; + + public static final int N_TMP3 = 11; + + public static final int N_TMP4 = 12; + + public static final int N_TMP5 = N_CLAMPFACTOR; + + public static final int N_TMP6 = N_MINSAVINGS; + + public static final int N_S_STEPS = N_S_RATE; + + public static final int N_T_STEPS = N_T_RATE; + + /* + * NURBS Rendering Properties - one set per map, each takes an INREAL matrix + * argument + */ + public static final int N_CULLINGMATRIX = 1; + + public static final int N_SAMPLINGMATRIX = 2; + + public static final int N_BBOXMATRIX = 3; + + /* + * NURBS Rendering Properties - one set per map, each takes an INREAL vector + * argument + */ + public static final int N_BBOXSIZE = 4; + + /* type argument for trimming curves */ + + public static final int N_P2D = 0x8; + + public static final int N_P2DR = 0xd; + + public static final int N_MESHLINE = 1; + + public static final int N_MESHFILL = 0; + + public static final int N_MESHPOINT = 2; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/O_curve.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_curve.java new file mode 100644 index 000000000..d6b565433 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_curve.java @@ -0,0 +1,63 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Struct holding curve links + * @author Tomáš Hráský + * + */ +public class O_curve { + + /** + * Curve type + */ + public int curvetype; + + /** + * Next curve in linked list + */ + public O_curve next; + + /** + * Curve of picewiselinear type + */ + public O_pwlcurve o_pwlcurve; + + /** + * NURBS curve + */ + public O_nurbscurve o_nurbscurve; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/O_nurbscurve.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_nurbscurve.java new file mode 100644 index 000000000..05c89ebcf --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_nurbscurve.java @@ -0,0 +1,80 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * NURBS curve object + * @author Tomáš Hráský + * + */ +public class O_nurbscurve { + + /** + * List of bezier curves + */ + public Quilt bezier_curves; + + /** + * Curve type + */ + public int type; + + /** + * Was curve used ? + */ + public boolean used; + + /** + * Parent curve + */ + public O_curve owner; + + /** + * Next curve in list + */ + public O_nurbscurve next; + + /** + * Makes new O_nurbscurve + * @param realType type of curve + */ + public O_nurbscurve(int realType) { + // DONE + this.type = realType; + this.owner = null; + this.next = null; + this.used = false; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/O_nurbssurface.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_nurbssurface.java new file mode 100644 index 000000000..867f43657 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_nurbssurface.java @@ -0,0 +1,79 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * NURBS surface object + * @author Tomáš Hráský + * + */ +public class O_nurbssurface { + + /** + * List of bezier patches forming NURBS surface + */ + public Quilt bezier_patches; + + /** + * Was surface used + */ + public boolean used; + + /** + * Parent O_surface + */ + public O_surface owner; + + /** + * Next surface in list + */ + public O_nurbssurface next; + + /** + * Surface type + */ + private int type; + + /** + * Makes new O_nurbssurface of type + * @param type surface type + */ + public O_nurbssurface(int type) { + this.type = type; + this.owner = null; + this.next = null; + this.used = false; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/O_pwlcurve.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_pwlcurve.java new file mode 100644 index 000000000..27ca3501d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_pwlcurve.java @@ -0,0 +1,44 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Empty class + * @author Tomáš Hráský + * + */ +public class O_pwlcurve { + +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/O_surface.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_surface.java new file mode 100644 index 000000000..96d455bca --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_surface.java @@ -0,0 +1,52 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Surface object + * @author Tomáš Hráský + * + */ +public class O_surface { + /** + * NURBS surface + */ + public O_nurbssurface o_nurbssurface; + + /** + * Trims + */ + public O_trim o_trim; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/O_trim.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_trim.java new file mode 100644 index 000000000..4cbec01be --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/O_trim.java @@ -0,0 +1,44 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Empty class + * @author Tomáš Hráský + * + */ +public class O_trim { + +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Patch.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Patch.java new file mode 100644 index 000000000..51c43fca7 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Patch.java @@ -0,0 +1,54 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Empty class + * @author Tomas Hrasky + * + */ +public class Patch { + + /** + * Empty constructor + * @param q + * @param pta + * @param ptb + * @param patch + */ + public Patch(Quilt q, float[] pta, float[] ptb, Patch patch) { + // System.out.println("TODO patch.constructor"); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Patchlist.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Patchlist.java new file mode 100644 index 000000000..f60a0cc43 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Patchlist.java @@ -0,0 +1,145 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * List of patches + * @author Tomáš Hráský + * + */ +public class Patchlist { + + /** + * Array of ranges + */ + public Pspec[] pspec; + + /** + * head of list of patches + */ + private Patch patch; + + /** + * Makes new list of patches + * @param quilts list of quilts + * @param pta low border + * @param ptb high border + */ + public Patchlist(Quilt quilts, float[] pta, float[] ptb) { + // DONE + patch = null; + + for (Quilt q = quilts; q != null; q = q.next) + patch = new Patch(q, pta, ptb, patch); + pspec[0] = new Pspec(); + pspec[0].range[0] = pta[0]; + pspec[0].range[1] = ptb[0]; + pspec[0].range[2] = ptb[0] - pta[0]; + pspec[1] = new Pspec(); + pspec[1].range[0] = pta[1]; + pspec[1].range[1] = ptb[1]; + pspec[1].range[2] = ptb[1] - pta[1]; + + } + + /** + * Empty constructor + * @param patchlist + * @param param + * @param mid + */ + public Patchlist(Patchlist patchlist, int param, float mid) { + // TODO Auto-generated constructor stub + // System.out.println("TODO patchlist.konstruktor 2"); + } + + /** + * Empty method + * @return 0 + */ + public int cullCheck() { + // TODO Auto-generated method stub + // System.out.println("TODO patchlist.cullcheck"); + return 0; + } + + /** + * Empty method + */ + public void getstepsize() { + // System.out.println("TODO patchlist.getsptepsize"); + // TODO Auto-generated method stub + + } + + /** + * Empty method + * @return false + */ + public boolean needsSamplingSubdivision() { + // TODO Auto-generated method stub + // System.out.println("patchlist.needsSamplingSubdivision"); + return false; + } + + /** + * Empty method + * @param i + * @return false + */ + public boolean needsSubdivision(int i) { + // TODO Auto-generated method stub + // System.out.println("TODO patchlist.needsSubdivision"); + return false; + } + + /** + * Empty method + * @return false + */ + public boolean needsNonSamplingSubdivision() { + // TODO Auto-generated method stub + // System.out.println("TODO patchlist.needsNonSamplingSubdivision"); + return false; + } + + /** + * Empty method + */ + public void bbox() { + // TODO Auto-generated method stub + // System.out.println("TODO patchlist.bbox"); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Property.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Property.java new file mode 100644 index 000000000..25b4dc441 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Property.java @@ -0,0 +1,75 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class representing property + * + * @author Tomas Hrasky + * + */ +public class Property { + + /** + * Property type + */ + public int type; + + /** + * Property id + */ + public int tag; + + /** + * Property value + */ + public float value; + + /** + * Makes new property with given parameters + * + * @param type + * property type + * @param tag + * property id + * @param value + * property value + */ + public Property(int type, int tag, float value) { + this.type = type; + this.tag = tag; + this.value = value; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Pspec.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Pspec.java new file mode 100644 index 000000000..0289b274c --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Pspec.java @@ -0,0 +1,47 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class holding range + * @author Tomáš Hráský + * + */ +public class Pspec { + /** + * Range + */ + public float[] range; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/PwlArc.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/PwlArc.java new file mode 100644 index 000000000..bcbd20a16 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/PwlArc.java @@ -0,0 +1,71 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Picewiselinar trimming arc + * @author Tomáš Hráský + * + */ +public class PwlArc { + + /** + * Number of points + */ + private int npts; + + /** + * Vertexes + */ + public TrimVertex[] pts; + + /** + * Arc type + */ + private int type; + + /** + * Makes new trimming arc + * @param i num ber of vertexes + * @param p trimming vertexes array + */ + public PwlArc(int i, TrimVertex[] p) { + // DONE + this.npts = i; + this.pts = p; + type = NurbsConsts.N_P2D; + + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Quilt.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Quilt.java new file mode 100644 index 000000000..6d732a44f --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Quilt.java @@ -0,0 +1,282 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class for converting NURBS curves and surfaces to list of bezier arcs or patches repectively + * @author Tomáš Hráský + * + */ +public class Quilt { + /** + * Maximum quilt dimension + */ + private static final int MAXDIM = 2; + + /** + * List of map descriptions + */ + Mapdesc mapdesc; + + /** + * Array of quiltspecs pointer + */ + public CArrayOfQuiltspecs qspec; + + /** + * End array of quilt specs pointer + */ + public CArrayOfQuiltspecs eqspec; + + /** + * Control points + */ + public CArrayOfFloats cpts; + + /** + * Next quilt in list + */ + public Quilt next; + + /** + * Makes new quilt with mapdesc + * @param mapdesc map description + */ + public Quilt(Mapdesc mapdesc) { + // DONE + this.mapdesc = mapdesc; + Quiltspec[] tmpquilts = new Quiltspec[MAXDIM]; + for (int i = 0; i < tmpquilts.length; i++) + tmpquilts[i] = new Quiltspec(); + this.qspec = new CArrayOfQuiltspecs(tmpquilts); + + } + + /** + * Converts NURBS surface to bezier patches + * @param sknotvector knots in u direction + * @param tknotvector knots in v direction + * @param ctrlarr control points + * @param coords control points coords + */ + public void toBezier(Knotvector sknotvector, Knotvector tknotvector, + CArrayOfFloats ctrlarr, int coords) { + Splinespec spline = new Splinespec(2); + spline.kspecinit(sknotvector, tknotvector); + spline.select(); + spline.layout(coords); + spline.setupquilt(this); + spline.copy(ctrlarr); + spline.transform(); + } + + /** + * Converts NURBS curve to list of bezier curves + * @param knots knot vector + * @param ctlarray control points + * @param ncoords number of coordinates + */ + public void toBezier(Knotvector knots, CArrayOfFloats ctlarray, int ncoords) { + // DONE + Splinespec spline = new Splinespec(1); + spline.kspecinit(knots); + spline.select(); + spline.layout(ncoords); + spline.setupquilt(this); + spline.copy(ctlarray); + spline.transform(); + } + + /** + * Walks thru all arcs/patches + * @param pta low border + * @param ptb high border + * @param backend Backend + */ + public void downloadAll(float[] pta, float[] ptb, Backend backend) { + // DONE + for (Quilt m = this; m != null; m = m.next) { + m.select(pta, ptb); + m.download(backend); + } + + } + + /** + * Renders arcs/patches + * @param backend Backend for rendering + */ + private void download(Backend backend) { + // DONE + if (getDimension() == 2) { + + CArrayOfFloats ps = new CArrayOfFloats(cpts); + ps.raisePointerBy(qspec.get(0).offset); + ps.raisePointerBy(qspec.get(1).offset); + ps.raisePointerBy(qspec.get(0).index * qspec.get(0).order + * qspec.get(0).stride); + ps.raisePointerBy(qspec.get(1).index * qspec.get(1).order + * qspec.get(1).stride); + + backend.surfpts(mapdesc.getType(), ps, qspec.get(0).stride, qspec + .get(1).stride, qspec.get(0).order, qspec.get(1).order, + qspec.get(0).breakpoints[qspec.get(0).index], + qspec.get(0).breakpoints[qspec.get(0).index + 1], qspec + .get(1).breakpoints[qspec.get(1).index], qspec + .get(1).breakpoints[qspec.get(1).index + 1]); + + } else {// code for curves + // CArrayOfFloats ps=new CArrayOfFloats(cpts); + CArrayOfFloats ps = new CArrayOfFloats(cpts.getArray(), 0); + ps.raisePointerBy(qspec.get(0).offset); + ps.raisePointerBy(qspec.get(0).index * qspec.get(0).order + * qspec.get(0).stride); + backend.curvpts(mapdesc.getType(), ps, qspec.get(0).stride, qspec + .get(0).order, + qspec.get(0).breakpoints[qspec.get(0).index], + qspec.get(0).breakpoints[qspec.get(0).index + 1]); + } + + } + + /** + * Returns quilt dimension + * @return quilt dimesion + */ + private int getDimension() { + // DONE + return eqspec.getPointer() - qspec.getPointer(); + } + + /** + * Finds Quiltspec.index + * @param pta range + * @param ptb range + */ + private void select(float[] pta, float[] ptb) { + // DONE + int dim = eqspec.getPointer() - qspec.getPointer(); + int i, j; + for (i = 0; i < dim; i++) { + for (j = qspec.get(i).width - 1; j >= 0; j--) + if (qspec.get(i).breakpoints[j] <= pta[i] + && ptb[i] <= qspec.get(i).breakpoints[j + 1]) + break; + assert (j != -1); + qspec.get(i).index = j; + } + } + + /** + * Find range according to breakpoints + * @param from low param + * @param to high param + * @param bpts breakpoints + */ + public void getRange(float[] from, float[] to, Flist bpts) { + // DONE + getRange(from, to, 0, bpts); + + } + + /** + * Find range according to breakpoints + * @param from low param + * @param to high param + * @param i from/to array index + * @param list breakpoints + */ + private void getRange(float[] from, float[] to, int i, Flist list) { + // DONE + Quilt maps = this; + from[i] = maps.qspec.get(i).breakpoints[0]; + to[i] = maps.qspec.get(i).breakpoints[maps.qspec.get(i).width]; + int maxpts = 0; + Quilt m; + for (m = maps; m != null; m = m.next) { + if (m.qspec.get(i).breakpoints[0] > from[i]) + from[i] = m.qspec.get(i).breakpoints[0]; + if (m.qspec.get(i).breakpoints[m.qspec.get(i).width] < to[i]) + to[i] = m.qspec.get(i).breakpoints[m.qspec.get(i).width]; + maxpts += m.qspec.get(i).width + 1; + } + list.grow(maxpts); + for (m = maps; m != null; m = m.next) { + for (int j = 0; j <= m.qspec.get(i).width; j++) { + list.add(m.qspec.get(i).breakpoints[j]); + } + } + list.filter(); + list.taper(from[i], to[i]); + } + + /** + * Is this quilt culled + * @return 0 or Subdivider.CULL_ACCEPT + */ + public int isCulled() { + if (mapdesc.isCulling()) { + // System.out.println("TODO quilt.isculled mapdesc.isculling"); + return 0; + } else { + return Subdivider.CULL_ACCEPT; + } + } + + /** + * Finds range for surface + * @param from low param + * @param to high param + * @param slist u direction breakpoints + * @param tlist v direction breakpoints + */ + public void getRange(float[] from, float[] to, Flist slist, Flist tlist) { + // DONE + getRange(from, to, 0, slist); + getRange(from, to, 1, tlist); + + } + + /** + * Empty method + * @param sbrkpts + * @param tbrkpts + * @param rate + */ + public void findRates(Flist sbrkpts, Flist tbrkpts, float[] rate) { + // TODO Auto-generated method stub + // System.out.println("TODO quilt.findrates"); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Quiltspec.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Quiltspec.java new file mode 100644 index 000000000..eaec1c9a2 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Quiltspec.java @@ -0,0 +1,85 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Quilt definition + * @author Tomas Hrasky + * + */ +public class Quiltspec { + + /** + * Stride between control points + */ + public int stride; + + /** + * Quilt width in breakpoints + */ + public int width; + + /** + * Quilt order + */ + public int order; + + /** + * Start offset + */ + public int offset; + + /** + * Breakpoint index + */ + public int index; + + /** + * Boundary + */ + public int[] bdry; + + /** + * Breakpoints + */ + public float[] breakpoints; + + /** + * Makes new quiltspec + */ + public Quiltspec() { + this.bdry = new int[2]; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/README.txt b/src/jogl/classes/jogamp/opengl/glu/nurbs/README.txt new file mode 100644 index 000000000..89630c71e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/README.txt @@ -0,0 +1,59 @@ +Unimplemented functionality + - tesselation and callbacks + - trimming + - setting NURBS properties (-> sampling etc.) +Differences from C++ source + - no pooling + - pointers to arrays are replaced by CArrayOf... classes and their methods +Unimplemented or incomplete "calltree top" methods (according to glu.def in Mesa 6.5) + gluBeginTrim + gluDeleteNurbsRenderer - won't be needed + gluEndTrim + gluGetNurbsProperty + gluLoadSamplingMatrices + gluNurbsCallback + gluNurbsCallbackData + gluNurbsCallbackDataEXT + gluNurbsCurve - TODO type switch + gluNurbsProperty + gluPwlCurve + gluQuadricCallback - not a NURBS method +As of files + - Arc[ST]dirSorter.java - unimplemented (part of tesselation) + - Backend.java:194 - wireframe quads - part of tesselation/callback + - Curve.java:141-204 - culling + - DisplayList.java:57 - append to DL - not sure whether it will be needed + - GLUnurbs.java :443,484 - error values + :445 - trimming + :512 - error handling (callback) + :530 - loadGLmatrices + :786 - nuid - nurbs object id - won't be needed I think + :803 - end trim + - GLUwNURBS.java:68,176 - NUBRS properties + - Knotspec.java :371 - copying in general case (more than 4 coords) + :517 - copying with more than 4 coords + :556 - pt_oo_sum default + - Knotvector.java:165 - show method (probably debugging) + - Mapdesc.java :354 - get property + :435 - xFormMat - change param cp to CArrayOfFloats; probably sampling functionality + - Maplist.java:68 - clear ? + - OpenGLCurveEvaluator.java :132 - tess./callback code + :168 - mapgrid1f + :190 - tess./callback code (output triangles) + - OpenGLSurfaceEvaluator.java :77 . tess./callback code + :81 - glGetIntegerValue + :114 - tess./callback code + :117 - Level of detail + :144,161,201 - tess./callback code - output triangles + - Patch.java:55 - constructor stuff ? + - Patchlist.java:55 - constructor stuff ? + :97 - cull check + :105 - step size + :115 - need of sampling subdivision + :126 - need of subdivision + :137 - need of non sampling subd. + :146 - bbox (??) + -Quilt.java :254 - culling + :282 - rates + -Subdivider.java - all TODOs - it's stuff about trimming probably + :545 - jumpbuffer - not sure purpose it exactly served in original source diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Renderhints.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Renderhints.java new file mode 100644 index 000000000..4729e2421 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Renderhints.java @@ -0,0 +1,128 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class holding rendering params + * @author Tomas Hrasky + * + */ +public class Renderhints { + + /** + * Check for errors + */ + public int errorchecking; + + /** + * Maximum subdivisions + */ + public int maxsubdivisions; + + /** + * Number of subdivisions + */ + private int subdivisions; + + /** + * Display method + */ + int display_method; + + /** + * Output triangles + */ + int wiretris; + + /** + * Output quads + */ + int wirequads; + + /** + * Makes new Renderinghints + */ + public Renderhints() { + display_method = NurbsConsts.N_FILL; + errorchecking = NurbsConsts.N_MSG; + subdivisions = 6; + // tmp1=0; + } + + /** + * Set property value + * @param prop property + */ + public void setProperty(Property prop) { + switch (prop.type) { + case NurbsConsts.N_DISPLAY: + display_method = (int) prop.value; + break; + case NurbsConsts.N_ERRORCHECKING: + errorchecking = (int) prop.value; + break; + case NurbsConsts.N_SUBDIVISIONS: + subdivisions = (int) prop.value; + break; + default: + // abort - end program + break; + } + } + + /** + * Initialization + */ + public void init() { + // DONE + maxsubdivisions = subdivisions; + if (maxsubdivisions < 0) + maxsubdivisions = 0; + + if (display_method == NurbsConsts.N_FILL) { + wiretris = 0; + wirequads = 0; + } else if (display_method == NurbsConsts.N_OUTLINE_TRI) { + wiretris = 1; + wirequads = 0; + } else if (display_method == NurbsConsts.N_OUTLINE_QUAD) { + wiretris = 0; + wirequads = 1; + } else { + wiretris = 1; + wirequads = 1; + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Splinespec.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Splinespec.java new file mode 100644 index 000000000..f1c779c2f --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Splinespec.java @@ -0,0 +1,204 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * NURBS definition + * @author Tomas Hrasky + * + */ +public class Splinespec { + + /** + * Dimension + */ + private int dim; + + /** + * Knot vector specs + */ + private Knotspec kspec; + + /** + * Control points after conversion + */ + private CArrayOfFloats outcpts; + + /** + * Makes new Splinespec with given dimension + * @param i dimension + */ + public Splinespec(int i) { + // DONE + this.dim = i; + } + + /** + * Initializes knotspec according to knotvector + * @param knotvector basic knotvector + */ + public void kspecinit(Knotvector knotvector) { + // DONE + this.kspec = new Knotspec(); + kspec.inkbegin = new CArrayOfFloats(knotvector.knotlist, 0); + kspec.inkend = new CArrayOfFloats(knotvector.knotlist, + knotvector.knotcount); + kspec.prestride = knotvector.stride; + kspec.order = knotvector.order; + kspec.next = null; + } + + /** + * Initializes knotspec according to knotvector - SURFACE + * @param sknotvector knotvector in u dir + * @param tknotvector knotvector in v dir + */ + public void kspecinit(Knotvector sknotvector, Knotvector tknotvector) { + // DONE + this.kspec = new Knotspec(); + Knotspec tkspec = new Knotspec(); + + kspec.inkbegin = new CArrayOfFloats(sknotvector.knotlist, 0); + kspec.inkend = new CArrayOfFloats(sknotvector.knotlist, + sknotvector.knotcount); + kspec.prestride = sknotvector.stride; + kspec.order = sknotvector.order; + kspec.next = tkspec; + + tkspec.inkbegin = new CArrayOfFloats(tknotvector.knotlist, 0); + tkspec.inkend = new CArrayOfFloats(tknotvector.knotlist, + tknotvector.knotcount); + tkspec.prestride = tknotvector.stride; + tkspec.order = tknotvector.order; + tkspec.next = null; + } + + /** + * Preselect and select knotspecs + */ + public void select() { + // DONE + for (Knotspec knotspec = kspec; knotspec != null; knotspec = knotspec.next) { + knotspec.preselect(); + knotspec.select(); + } + + } + + /** + * Prepares for conversion + * @param ncoords number of coords + */ + public void layout(int ncoords) { + // DONE + int stride = ncoords; + for (Knotspec knotspec = kspec; knotspec != null; knotspec = knotspec.next) { + knotspec.poststride = stride; + stride *= (knotspec.bend.getPointer() - knotspec.bbegin + .getPointer()) + * knotspec.order + knotspec.postoffset; + knotspec.preoffset *= knotspec.prestride; + knotspec.prewidth *= knotspec.poststride; + knotspec.postwidth *= knotspec.poststride; + knotspec.postoffset *= knotspec.poststride; + knotspec.ncoords = ncoords; + } + outcpts = new CArrayOfFloats(new float[stride]); + + } + + /** + * Prepares quilt for conversion + * @param quilt quilt to work with + */ + public void setupquilt(Quilt quilt) { + // DONE + CArrayOfQuiltspecs qspec = new CArrayOfQuiltspecs(quilt.qspec); + quilt.eqspec = new CArrayOfQuiltspecs(qspec.getArray(), dim); + for (Knotspec knotspec = kspec; knotspec != null;) { + qspec.get().stride = knotspec.poststride; + qspec.get().width = knotspec.bend.getPointer() + - knotspec.bbegin.getPointer(); + qspec.get().order = knotspec.order; + qspec.get().offset = knotspec.postoffset; + qspec.get().index = 0; + qspec.get().bdry[0] = (knotspec.kleft.getPointer() == knotspec.kfirst + .getPointer()) ? 1 : 0; + qspec.get().bdry[1] = (knotspec.kright.getPointer() == knotspec.klast + .getPointer()) ? 1 : 0; + qspec.get().breakpoints = new float[qspec.get().width + 1]; + CArrayOfFloats k = new CArrayOfFloats(qspec.get().breakpoints, 0); + for (CArrayOfBreakpts bk = new CArrayOfBreakpts(knotspec.bbegin); bk + .getPointer() <= knotspec.bend.getPointer(); bk.pp()) { + k.set(bk.get().value); + k.pp(); + } + knotspec = knotspec.next; + if (knotspec != null) + qspec.pp(); + } + quilt.cpts = new CArrayOfFloats(outcpts); + quilt.next = null; + } + + /** + * Copies array of control points to output array + * @param ctlarray control points array + */ + public void copy(CArrayOfFloats ctlarray) { + // DONE + kspec.copy(ctlarray, outcpts); + + } + + /** + * Transforms knotspecs - conversion + */ + public void transform() { + // DONE + Knotspec knotspec; + outcpts.setPointer(0); + for (knotspec = kspec; knotspec != null; knotspec = knotspec.next) + knotspec.istransformed = false; + + for (knotspec = kspec; knotspec != null; knotspec = knotspec.next) { + for (Knotspec kspec2 = kspec; kspec2 != null; kspec2 = kspec2.next) + kspec2.kspectotrans = knotspec; + kspec.transform(outcpts); + knotspec.istransformed = true; + } + + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Subdivider.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Subdivider.java new file mode 100644 index 000000000..3378dba8d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Subdivider.java @@ -0,0 +1,1167 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class working with curves and surfaces + * @author Tomas Hrasky + * + */ +public class Subdivider { + /** + * Cull type + */ + public static final int CULL_TRIVIAL_REJECT = 0; + + /** + * Cull type + */ + public static final int CULL_ACCEPT = 1; + + /** + * Maximum trimming arcs + */ + private static final int MAXARCS = 10; + + /** + * Linked list of Quilts + */ + Quilt qlist; + + /** + * Object holding rendering honts information + */ + private Renderhints renderhints; + + /** + * Backend object + */ + private Backend backend; + + /** + * Number of subdivisions + */ + private int subdivisions; + + /** + * U step when using domain distance sampling + */ + private float domain_distance_u_rate; + + /** + * Use domain distance sampling + */ + private int is_domain_distance_sampling; + + /** + * Initial class holding trimming arcs + */ + private Bin initialbin; + + /** + * Not used + */ + private boolean showDegenerate; + + /** + * Is triming arc type bezier arc + */ + private boolean isArcTypeBezier; + + /** + * Breakpoints in v direction + */ + private Flist tpbrkpts; + + /** + * Breakpoints in u direction + */ + private Flist spbrkpts; + + /** + * Unused + */ + private int s_index; + + /** + * Head of linked list of trimming arcs + */ + private Arc pjarc; + + /** + * Class tesselating trimming arcs + */ + private ArcTesselator arctesselator; + + /** + * Unused + */ + private int t_index; + + /** + * Breakpoints + */ + private Flist smbrkpts; + + /** + * Not used + */ + private float[] stepsizes; + + /** + * Domain distance in V direction + */ + private float domain_distance_v_rate; + + /** + * Initializes quilt list + */ + public void beginQuilts(Backend backend) { + // DONE + qlist = null; + renderhints = new Renderhints(); + this.backend = backend; + + initialbin = new Bin(); + arctesselator = new ArcTesselator(); + } + + /** + * Adds quilt to linked list + * @param quilt added quilt + */ + public void addQuilt(Quilt quilt) { + // DONE + if (qlist == null) + qlist = quilt; + else { + quilt.next = qlist; + qlist = quilt; + } + + } + + /** + * Empty method + */ + public void endQuilts() { + // DONE + } + + /** + * Draws a surface + */ + public void drawSurfaces() { + renderhints.init(); + + if (qlist == null) { + // System.out.println("qlist is null"); + return; + } + + for (Quilt q = qlist; q != null; q = q.next) { + if (q.isCulled() == CULL_TRIVIAL_REJECT) { + freejarcs(initialbin); + return; + } + } + + float[] from = new float[2]; + float[] to = new float[2]; + + spbrkpts = new Flist(); + tpbrkpts = new Flist(); + qlist.getRange(from, to, spbrkpts, tpbrkpts); + + boolean optimize = (is_domain_distance_sampling > 0 && (renderhints.display_method != NurbsConsts.N_OUTLINE_PATCH)); + + // TODO decide whether to optimize (when there is gluNurbsProperty implemented) + optimize = true; + + if (!initialbin.isnonempty()) { + if (!optimize) { + makeBorderTrim(from, to); + } + } else { + float[] rate = new float[2]; + qlist.findRates(spbrkpts, tpbrkpts, rate); + // System.out.println("subdivider.drawsurfaces decompose"); + } + + backend.bgnsurf(renderhints.wiretris, renderhints.wirequads); + + // TODO partition test + + if (!initialbin.isnonempty() && optimize) { + + int i, j; + int num_u_steps; + int num_v_steps; + for (i = spbrkpts.start; i < spbrkpts.end - 1; i++) { + for (j = tpbrkpts.start; j < tpbrkpts.end - 1; j++) { + float[] pta = new float[2]; + float[] ptb = new float[2]; + + pta[0] = spbrkpts.pts[i]; + ptb[0] = spbrkpts.pts[i + 1]; + pta[1] = tpbrkpts.pts[j]; + ptb[1] = tpbrkpts.pts[j + 1]; + qlist.downloadAll(pta, ptb, backend); + + num_u_steps = (int) (domain_distance_u_rate * (ptb[0] - pta[0])); + num_v_steps = (int) (domain_distance_v_rate * (ptb[1] - pta[1])); + + if (num_u_steps <= 0) + num_u_steps = 1; + if (num_v_steps <= 0) + num_v_steps = 1; + + backend.surfgrid(pta[0], ptb[0], num_u_steps, ptb[1], + pta[1], num_v_steps); + backend.surfmesh(0, 0, num_u_steps, num_v_steps); + + } + } + + } else + + subdivideInS(initialbin); + + backend.endsurf(); + } + + /** + * Empty method + * @param initialbin2 + */ + private void freejarcs(Bin initialbin2) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.freejarcs"); + } + + /** + * Subdivide in U direction + * @param source Trimming arcs source + */ + private void subdivideInS(Bin source) { + // DONE + if (renderhints.display_method == NurbsConsts.N_OUTLINE_PARAM) { + outline(source); + freejarcs(source); + } else { + setArcTypeBezier(); + setNonDegenerate(); + splitInS(source, spbrkpts.start, spbrkpts.end); + } + + } + + /** + * Split in U direction + * @param source Trimming arcs source + * @param start breakpoints start + * @param end breakpoints end + */ + private void splitInS(Bin source, int start, int end) { + // DONE + if (source.isnonempty()) { + if (start != end) { + int i = start + (end - start) / 2; + Bin left = new Bin(); + Bin right = new Bin(); + + split(source, left, right, 0, spbrkpts.pts[i]); + splitInS(left, start, i); + splitInS(right, i + 1, end); + } else { + if (start == spbrkpts.start || start == spbrkpts.end) { + freejarcs(source); + } else if (renderhints.display_method == NurbsConsts.N_OUTLINE_PARAM_S) { + outline(source); + freejarcs(source); + } else { + setArcTypeBezier(); + setNonDegenerate(); + s_index = start; + splitInT(source, tpbrkpts.start, tpbrkpts.end); + } + } + } else{ + // System.out.println("Source is empty - subdivider.splitins"); + } + } + + /** + * Split in V direction + * @param source + * @param start + * @param end + */ + private void splitInT(Bin source, int start, int end) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.splitint"); + + if (source.isnonempty()) { + if (start != end) { + int i = start + (end - start) / 2; + Bin left = new Bin(); + Bin right = new Bin(); + split(source, left, right, 1, tpbrkpts.pts[i + 1]); + splitInT(left, start, i); + splitInT(right, i + 1, end); + } else { + if (start == tpbrkpts.start || start == tpbrkpts.end) { + freejarcs(source); + } else if (renderhints.display_method == NurbsConsts.N_OUTLINE_PARAM_ST) { + outline(source); + freejarcs(source); + } else { + t_index = start; + setArcTypeBezier(); + setDegenerate(); + + float[] pta = new float[2]; + float[] ptb = new float[2]; + + pta[0] = spbrkpts.pts[s_index - 1]; + pta[1] = tpbrkpts.pts[t_index - 1]; + + ptb[0] = spbrkpts.pts[s_index]; + ptb[1] = tpbrkpts.pts[t_index]; + qlist.downloadAll(pta, ptb, backend); + + Patchlist patchlist = new Patchlist(qlist, pta, ptb); + + samplingSplit(source, patchlist, + renderhints.maxsubdivisions, 0); + setNonDegenerate(); + setArcTypeBezier(); + } + } + } + + } + + /** + * Sample + * @param source + * @param patchlist + * @param subdivisions + * @param param + */ + private void samplingSplit(Bin source, Patchlist patchlist, + int subdivisions, int param) { + // DONE + if (!source.isnonempty()) + return; + if (patchlist.cullCheck() == CULL_TRIVIAL_REJECT) { + freejarcs(source); + return; + } + + patchlist.getstepsize(); + if (renderhints.display_method == NurbsConsts.N_OUTLINE_PATCH) { + tesselation(source, patchlist); + outline(source); + freejarcs(source); + return; + } + + tesselation(source, patchlist); + if (patchlist.needsSamplingSubdivision() && subdivisions > 0) { + if (!patchlist.needsSubdivision(0)) { + param = 1; + } else if (patchlist.needsSubdivision(1)) + param = 0; + else + param = 1 - param; + + Bin left = new Bin(); + Bin right = new Bin(); + + float mid = (float) ((patchlist.pspec[param].range[0] + patchlist.pspec[param].range[1]) * .5); + + split(source, left, right, param, mid); + Patchlist subpatchlist = new Patchlist(patchlist, param, mid); + samplingSplit(left, subpatchlist, subdivisions - 1, param); + samplingSplit(right, subpatchlist, subdivisions - 1, param); + } else { + setArcTypePwl(); + setDegenerate(); + nonSamplingSplit(source, patchlist, subdivisions, param); + setDegenerate(); + setArcTypeBezier(); + } + } + + /** + * Not used + * @param source + * @param patchlist + * @param subdivisions + * @param param + */ + private void nonSamplingSplit(Bin source, Patchlist patchlist, + int subdivisions, int param) { + // DONE + if (patchlist.needsNonSamplingSubdivision() && subdivisions > 0) { + param = 1 - param; + + Bin left = new Bin(); + Bin right = new Bin(); + + float mid = (float) ((patchlist.pspec[param].range[0] + patchlist.pspec[param].range[1]) * .5); + split(source, left, right, param, mid); + Patchlist subpatchlist = new Patchlist(patchlist, param, mid); + if (left.isnonempty()) { + if (subpatchlist.cullCheck() == CULL_TRIVIAL_REJECT) + freejarcs(left); + else + nonSamplingSplit(left, subpatchlist, subdivisions - 1, + param); + } + if (right.isnonempty()) { + if (patchlist.cullCheck() == CULL_TRIVIAL_REJECT) + freejarcs(right); + else + nonSamplingSplit(right, subpatchlist, subdivisions - 1, + param); + } + } else { + patchlist.bbox(); + backend.patch(patchlist.pspec[0].range[0], + patchlist.pspec[0].range[1], patchlist.pspec[1].range[0], + patchlist.pspec[1].range[1]); + if (renderhints.display_method == NurbsConsts.N_OUTLINE_SUBDIV) { + outline(source); + freejarcs(source); + } else { + setArcTypePwl(); + setDegenerate(); + findIrregularS(source); + monosplitInS(source, smbrkpts.start, smbrkpts.end); + } + } + + } + + /** + * Not used + * @param source + * @param start + * @param end + */ + private void monosplitInS(Bin source, int start, int end) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.monosplitins"); + } + + /** + * Not used + * @param source + */ + private void findIrregularS(Bin source) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.findIrregularS"); + } + + /** + * Not used + */ + private void setArcTypePwl() { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.setarctypepwl"); + } + + /** + * Not used + * @param source + * @param patchlist + */ + private void tesselation(Bin source, Patchlist patchlist) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.tesselation"); + } + + /** + * Not used + */ + private void setDegenerate() { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.setdegenerate"); + } + + /** + * Not used + * @param bin + * @param left + * @param right + * @param param + * @param value + */ + private void split(Bin bin, Bin left, Bin right, int param, float value) { + // DONE + Bin intersections = new Bin(); + Bin unknown = new Bin(); + + partition(bin, left, intersections, right, unknown, param, value); + + int count = intersections.numarcs(); + // TODO jumpbuffer ?? + + if (count % 2 == 0) { + + Arc[] arclist = new Arc[MAXARCS]; + CArrayOfArcs list; + if (count >= MAXARCS) { + list = new CArrayOfArcs(new Arc[count]); + } else { + list = new CArrayOfArcs(arclist); + } + + CArrayOfArcs last, lptr; + Arc jarc; + + for (last = new CArrayOfArcs(list); (jarc = intersections + .removearc()) != null; last.pp()) + last.set(jarc); + + if (param == 0) {// sort into incrasing t order + ArcSdirSorter sorter = new ArcSdirSorter(this); + sorter.qsort(list, count); + + for (lptr = new CArrayOfArcs(list); lptr.getPointer() < last + .getPointer(); lptr.raisePointerBy(2)) + check_s(lptr.get(), lptr.getRelative(1)); + for (lptr = new CArrayOfArcs(list); lptr.getPointer() < last + .getPointer(); lptr.raisePointerBy(2)) + join_s(left, right, lptr.get(), lptr.getRelative(1)); + for (lptr = new CArrayOfArcs(list); lptr.getPointer() != last + .getPointer(); lptr.pp()) { + if (lptr.get().head()[0] <= value + && lptr.get().tail()[0] <= value) + left.addarc(lptr.get()); + else + right.addarc(lptr.get()); + } + + } else {// sort into decreasing s order + ArcTdirSorter sorter = new ArcTdirSorter(this); + sorter.qsort(list, count); + + for (lptr = new CArrayOfArcs(list); lptr.getPointer() < last + .getPointer(); lptr.raisePointerBy(2)) + check_t(lptr.get(), lptr.getRelative(1)); + for (lptr = new CArrayOfArcs(list); lptr.getPointer() < last + .getPointer(); lptr.raisePointerBy(2)) + join_t(left, right, lptr.get(), lptr.getRelative(1)); + for (lptr = new CArrayOfArcs(list); lptr.getPointer() != last + .getPointer(); lptr.raisePointerBy(2)) { + if (lptr.get().head()[0] <= value + && lptr.get().tail()[0] <= value) + left.addarc(lptr.get()); + else + right.addarc(lptr.get()); + } + + } + + unknown.adopt(); + } + } + + /** + * Not used + * @param left + * @param right + * @param arc + * @param relative + */ + private void join_t(Bin left, Bin right, Arc arc, Arc relative) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.join_t"); + } + + /** + * Not used + * @param arc + * @param relative + */ + private void check_t(Arc arc, Arc relative) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.check_t"); + } + + /** + * Not used + * @param left + * @param right + * @param jarc1 + * @param jarc2 + */ + private void join_s(Bin left, Bin right, Arc jarc1, Arc jarc2) { + // DONE + if (!jarc1.getitail()) + jarc1 = jarc1.next; + if (!jarc2.getitail()) + jarc2 = jarc2.next; + + float s = jarc1.tail()[0]; + float t1 = jarc1.tail()[1]; + float t2 = jarc2.tail()[1]; + + if (t1 == t2) { + simplelink(jarc1, jarc2); + } else { + Arc newright = new Arc(Arc.ARC_RIGHT); + Arc newleft = new Arc(Arc.ARC_LEFT); + if (isBezierArcType()) { + arctesselator.bezier(newright, s, s, t1, t2); + arctesselator.bezier(newleft, s, s, t2, t1); + } else { + arctesselator.pwl_right(newright, s, t1, t2, stepsizes[0]); + arctesselator.pwl_left(newright, s, t2, t1, stepsizes[2]); + } + link(jarc1, jarc2, newright, newleft); + left.addarc(newright); + right.addarc(newleft); + } + + } + + /** + * Not used + * @param jarc1 + * @param jarc2 + * @param newright + * @param newleft + */ + private void link(Arc jarc1, Arc jarc2, Arc newright, Arc newleft) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.link"); + } + + /** + * Not used + * @return true + */ + private boolean isBezierArcType() { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.isbezierarc"); + return true; + } + + /** + * Not used + * @param jarc1 + * @param jarc2 + */ + private void simplelink(Arc jarc1, Arc jarc2) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.simplelink"); + } + + /** + * Not used + * @param arc + * @param relative + */ + private void check_s(Arc arc, Arc relative) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.check_s"); + + } + + /** + * Not used + * @param bin + * @param left + * @param intersections + * @param right + * @param unknown + * @param param + * @param value + */ + private void partition(Bin bin, Bin left, Bin intersections, Bin right, + Bin unknown, int param, float value) { + + Bin headonleft = new Bin(); + Bin headonright = new Bin(); + Bin tailonleft = new Bin(); + Bin tailonright = new Bin(); + + for (Arc jarc = bin.removearc(); jarc != null; jarc = bin.removearc()) { + float tdiff = jarc.tail()[param] - value; + float hdiff = jarc.head()[param] - value; + + if (tdiff > 0) { + if (hdiff > 0) { + right.addarc(jarc); + } else if (hdiff == 0) { + tailonright.addarc(jarc); + } else { + Arc jtemp; + switch (arc_split(jarc, param, value, 0)) { + case 2: + tailonright.addarc(jarc); + headonleft.addarc(jarc.next); + break; + // TODO rest cases + default: + System.out + .println("TODO subdivider.partition rest cases"); + break; + } + } + } else if (tdiff == 0) { + if (hdiff > 0) { + headonright.addarc(jarc); + } else if (hdiff == 0) { + unknown.addarc(jarc); + } else { + headonright.addarc(jarc); + } + } else { + if (hdiff > 0) { + // TODO rest + // System.out.println("TODO subdivider.partition rest of else"); + } else if (hdiff == 0) { + tailonleft.addarc(jarc); + } else { + left.addarc(jarc); + } + } + + } + if (param == 0) { + classify_headonleft_s(headonleft, intersections, left, value); + classify_tailonleft_s(tailonleft, intersections, left, value); + classify_headonright_s(headonright, intersections, right, value); + classify_tailonright_s(tailonright, intersections, right, value); + } else { + classify_headonleft_t(headonleft, intersections, left, value); + classify_tailonleft_t(tailonleft, intersections, left, value); + classify_headonright_t(headonright, intersections, right, value); + classify_tailonright_t(tailonright, intersections, right, value); + } + } + + /** + * Not used + * @param tailonright + * @param intersections + * @param right + * @param value + */ + private void classify_tailonright_t(Bin tailonright, Bin intersections, + Bin right, float value) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.classify_tailonright_t"); + + } + + /** + * Not used + * @param bin + * @param in + * @param out + * @param val + */ + private void classify_tailonleft_s(Bin bin, Bin in, Bin out, float val) { + + // DONE + Arc j; + while ((j = bin.removearc()) != null) { + j.clearitail(); + + float diff = j.next.head()[0] - val; + if (diff > 0) { + in.addarc(j); + } else if (diff < 0) { + if (ccwTurn_sl(j, j.next)) + out.addarc(j); + else + in.addarc(j); + } else { + if (j.next.tail()[1] > j.next.head()[1]) + in.addarc(j); + else + out.addarc(j); + } + } + + } + + /** + * Not used + * @param bin + * @param in + * @param out + * @param val + */ + private void classify_headonright_s(Bin bin, Bin in, Bin out, float val) { + // DONE + Arc j; + while ((j = bin.removearc()) != null) { + j.setitail(); + + float diff = j.prev.tail()[0] - val; + if (diff > 0) { + if (ccwTurn_sr(j.prev, j)) + out.addarc(j); + else + in.addarc(j); + } else if (diff < 0) { + out.addarc(j); + } else { + if (j.prev.tail()[1] > j.prev.head()[1]) + out.addarc(j); + else + in.addarc(j); + } + } + } + + /** + * Not used + * @param prev + * @param j + * @return false + */ + private boolean ccwTurn_sr(Arc prev, Arc j) { + // TODO Auto-generated method stub + // System.out.println("TODO ccwTurn_sr"); + return false; + } + + /** + * Not used + * @param headonright + * @param intersections + * @param right + * @param value + */ + private void classify_headonright_t(Bin headonright, Bin intersections, + Bin right, float value) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.classify_headonright_t"); + } + + /** + * Not used + * @param tailonleft + * @param intersections + * @param left + * @param value + */ + private void classify_tailonleft_t(Bin tailonleft, Bin intersections, + Bin left, float value) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.classify_tailonleft_t"); + } + + /** + * Not used + * @param bin + * @param in + * @param out + * @param val + */ + private void classify_headonleft_t(Bin bin, Bin in, Bin out, float val) { + // DONE + Arc j; + while ((j = bin.removearc()) != null) { + j.setitail(); + + float diff = j.prev.tail()[1] - val; + if (diff > 0) { + out.addarc(j); + } else if (diff < 0) { + if (ccwTurn_tl(j.prev, j)) + out.addarc(j); + else + in.addarc(j); + } else { + if (j.prev.tail()[0] > j.prev.head()[0]) + out.addarc(j); + else + in.addarc(j); + } + } + } + + /** + * Not used + * @param prev + * @param j + * @return false + */ + private boolean ccwTurn_tl(Arc prev, Arc j) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.ccwTurn_tl"); + return false; + } + + /** + * Not used + * @param bin + * @param in + * @param out + * @param val + */ + private void classify_tailonright_s(Bin bin, Bin in, Bin out, float val) { + // DONE + Arc j; + while ((j = bin.removearc()) != null) { + j.clearitail(); + + float diff = j.next.head()[0] - val; + if (diff > 0) { + if (ccwTurn_sr(j, j.next)) + out.addarc(j); + else + in.addarc(j); + } else if (diff < 0) { + in.addarc(j); + } else { + if (j.next.tail()[1] > j.next.head()[1]) + out.addarc(j); + else + in.addarc(j); + } + } + + } + + /** + * Not used + * @param bin + * @param in + * @param out + * @param val + */ + private void classify_headonleft_s(Bin bin, Bin in, Bin out, float val) { + // DONE + Arc j; + while ((j = bin.removearc()) != null) { + j.setitail(); + + float diff = j.prev.tail()[0] - val; + if (diff > 0) { + out.addarc(j); + } else if (diff < 0) { + if (ccwTurn_sl(j.prev, j)) + out.addarc(j); + else + in.addarc(j); + } else { + if (j.prev.tail()[1] > j.prev.head()[1]) + in.addarc(j); + else + out.addarc(j); + } + } + + } + + /** + * Not used + * @param prev + * @param j + * @return false + */ + private boolean ccwTurn_sl(Arc prev, Arc j) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.ccwTurn_sl"); + return false; + } + + /** + * Not used + * @param jarc + * @param param + * @param value + * @param i + * @return 0 + */ + private int arc_split(Arc jarc, int param, float value, int i) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.arc_split"); + return 0; + } + + /** + * Not used + */ + private void setNonDegenerate() { + // DONE + this.showDegenerate = false; + + } + + /** + * sets trimming arc default type to bezier + */ + private void setArcTypeBezier() { + // DONE + isArcTypeBezier = true; + } + + /** + * Not used + * @param source + */ + private void outline(Bin source) { + // TODO Auto-generated method stub + // System.out.println("TODO subdivider.outline"); + } + + /** + * Makes default trim along surface borders + * @param from range beginnings + * @param to range ends + */ + private void makeBorderTrim(float[] from, float[] to) { + // DONE + float smin = from[0]; + float smax = to[0]; + + float tmin = from[1]; + float tmax = to[1]; + + pjarc = null; + Arc jarc = null; + + jarc = new Arc(Arc.ARC_BOTTOM); + arctesselator.bezier(jarc, smin, smax, tmin, tmin); + initialbin.addarc(jarc); + pjarc = jarc.append(pjarc); + + jarc = new Arc(Arc.ARC_RIGHT); + arctesselator.bezier(jarc, smax, smax, tmin, tmax); + initialbin.addarc(jarc); + pjarc = jarc.append(pjarc); + + jarc = new Arc(Arc.ARC_TOP); + arctesselator.bezier(jarc, smax, smin, tmax, tmax); + initialbin.addarc(jarc); + pjarc = jarc.append(pjarc); + + jarc = new Arc(Arc.ARC_LEFT); + arctesselator.bezier(jarc, smin, smin, tmax, tmin); + initialbin.addarc(jarc); + jarc = jarc.append(pjarc); + + // assert (jarc.check() == true); + } + + /** + * Draws NURBS curve + */ + public void drawCurves() { + // DONE + float[] from = new float[1]; + float[] to = new float[1]; + + Flist bpts = new Flist(); + qlist.getRange(from, to, bpts); + + renderhints.init(); + + backend.bgncurv(); + + for (int i = bpts.start; i < bpts.end - 1; i++) { + float[] pta = new float[1]; + float[] ptb = new float[1]; + pta[0] = bpts.pts[i]; + ptb[0] = bpts.pts[i + 1]; + + qlist.downloadAll(pta, ptb, backend); + Curvelist curvelist = new Curvelist(qlist, pta, ptb); + samplingSplit(curvelist, renderhints.maxsubdivisions); + } + backend.endcurv(); + } + + /** + * Samples a curve in case of need, or sends curve to backend + * @param curvelist list of curves + * @param maxsubdivisions maximum number of subdivisions + */ + private void samplingSplit(Curvelist curvelist, int maxsubdivisions) { + if (curvelist.cullCheck() == CULL_TRIVIAL_REJECT) + return; + + curvelist.getstepsize(); + + if (curvelist.needsSamplingSubdivision() && (subdivisions > 0)) { + // TODO kód + // System.out.println("TODO subdivider-needsSamplingSubdivision"); + } else { + int nu = (int) (1 + curvelist.range[2] / curvelist.stepsize); + backend.curvgrid(curvelist.range[0], curvelist.range[1], nu); + backend.curvmesh(0, nu); + } + + } + + /** + * Sets new domain_distance_u_rate value + * @param d new domain_distance_u_rate value + + */ + public void set_domain_distance_u_rate(double d) { + // DONE + domain_distance_u_rate = (float) d; + } + + /** + * Sets new domain_distance_v_rate value + * @param d new domain_distance_v_rate value + */ + public void set_domain_distance_v_rate(double d) { + // DONE + domain_distance_v_rate = (float) d; + } + + /** + * Sets new is_domain_distance_sampling value + * @param i new is_domain_distance_sampling value + */ + public void set_is_domain_distance_sampling(int i) { + // DONE + this.is_domain_distance_sampling = i; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/SurfaceEvaluator.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/SurfaceEvaluator.java new file mode 100644 index 000000000..35ad1b7e7 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/SurfaceEvaluator.java @@ -0,0 +1,111 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Class rendering surfaces with OpenGL + * @author Tomas Hrasky + * + */ +public interface SurfaceEvaluator { + + /** + * Pushes eval bit + */ + public void bgnmap2f() ; + + /** + * Sets glPolygonMode + * @param style polygon mode (N_MESHFILL/N_MESHLINE/N_MESHPOINT) + */ + public void polymode(int style) ; + + /** + * Pops all attributes + */ + public void endmap2f() ; + + /** + * Empty method + * @param ulo + * @param uhi + * @param vlo + * @param vhi + */ + public void domain2f(float ulo, float uhi, float vlo, float vhi) ; + + /** + * Defines 2D mesh + * @param nu number of steps in u direction + * @param u0 lowest u + * @param u1 highest u + * @param nv number of steps in v direction + * @param v0 lowest v + * @param v1 highest v + */ + public void mapgrid2f(int nu, float u0, float u1, int nv, float v0, float v1) ; + + /** + * Evaluates surface + * @param style surface style + * @param umin minimum U + * @param umax maximum U + * @param vmin minimum V + * @param vmax maximum V + */ + public void mapmesh2f(int style, int umin, int umax, int vmin, int vmax) ; + + /** + * Initializes evaluator + * @param type surface type + * @param ulo lowest u + * @param uhi highest u + * @param ustride number of objects between control points in u direction + * @param uorder surface order in u direction + * @param vlo lowest v + * @param vhi highest v + * @param vstride number of control points' coords + * @param vorder surface order in v direction + * @param pts control points + */ + public void map2f(int type, float ulo, float uhi, int ustride, int uorder, + float vlo, float vhi, int vstride, int vorder, CArrayOfFloats pts) ; + + /** + * Calls opengl enable + * @param type what to enable + */ + public void enable(int type) ; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/TrimVertex.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/TrimVertex.java new file mode 100644 index 000000000..e88d69709 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/TrimVertex.java @@ -0,0 +1,56 @@ +package jogamp.opengl.glu.nurbs; + +/* + ** License Applicability. Except to the extent portions of this file are + ** made subject to an alternative license as permitted in the SGI Free + ** Software License B, Version 2.0 (the "License"), the contents of this + ** file are subject only to the provisions of the License. You may not use + ** this file except in compliance with the License. You may obtain a copy + ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + ** + ** http://oss.sgi.com/projects/FreeB + ** + ** Note that, as provided in the License, the Software is distributed on an + ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + ** + ** Original Code. The Original Code is: OpenGL Sample Implementation, + ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + ** Copyright in any portions created by third parties is as indicated + ** elsewhere herein. All Rights Reserved. + ** + ** Additional Notice Provisions: The application programming interfaces + ** established by SGI in conjunction with the Original Code are The + ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + ** Window System(R) (Version 1.3), released October 19, 1998. This software + ** was created using the OpenGL(R) version 1.2.1 Sample Implementation + ** published by SGI, but has not been independently verified as being + ** compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +/** + * Holds vertex used in trim + * + * @author Tomas Hrasky + * + */ +public class TrimVertex { + + /** + * Trim vertex coords + */ + public float[] param; + + /** + * Makes new empty trim vertex + */ + public TrimVertex() { + param = new float[2]; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/registry/Registry.java b/src/jogl/classes/jogamp/opengl/glu/registry/Registry.java new file mode 100644 index 000000000..3d669d9bb --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/registry/Registry.java @@ -0,0 +1,79 @@ +/* + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 2.0 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * NOTE: The Original Code (as defined below) has been licensed to Sun + * Microsystems, Inc. ("Sun") under the SGI Free Software License B + * (Version 1.1), shown above ("SGI License"). Pursuant to Section + * 3.2(3) of the SGI License, Sun is distributing the Covered Code to + * you under an alternative license ("Alternative License"). This + * Alternative License includes all of the provisions of the SGI License + * except that Section 2.2 and 11 are omitted. Any differences between + * the Alternative License and the SGI License are offered solely by Sun + * and not by SGI. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + */ + +package jogamp.opengl.glu.registry; + +import javax.media.opengl.glu.GLU; + +/** + * + * @author Administrator + */ +public class Registry { + + /** Creates a new instance of Registry */ + public Registry() { + } + + public static String gluGetString(int name) { + if( name == GLU.GLU_VERSION ) { + return( "1.3" ); + } else if( name == GLU.GLU_EXTENSIONS ) { + return( "GLU_EXT_nurbs_tessellator GLU_EXT_object_space_tess " ); + } + return( null ); + } + + public static boolean gluCheckExtension( String extName, String extString ) { + if( extName == null || extString == null ) { + return( false ); + } + if ((extString.indexOf(extName + " ") >= 0) || + extString.endsWith(extName) || + extString.equals(extName)) { + return true; + } + return false; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/ActiveRegion.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/ActiveRegion.java new file mode 100644 index 000000000..13c226a7c --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/ActiveRegion.java @@ -0,0 +1,69 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + + +class ActiveRegion { + GLUhalfEdge eUp; /* upper edge, directed right to left */ + DictNode nodeUp; /* dictionary node corresponding to eUp */ + int windingNumber; /* used to determine which regions are + * inside the polygon */ + boolean inside; /* is this region inside the polygon? */ + boolean sentinel; /* marks fake edges at t = +/-infinity */ + boolean dirty; /* marks regions where the upper or lower + * edge has changed, but we haven't checked + * whether they intersect yet */ + boolean fixUpperEdge; /* marks temporary edges introduced when + * we process a "right vertex" (one without + * any edges leaving to the right) */ +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/CachedVertex.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/CachedVertex.java new file mode 100644 index 000000000..91072e310 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/CachedVertex.java @@ -0,0 +1,58 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class CachedVertex { + public double[] coords = new double[3]; + public Object data; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/Dict.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Dict.java new file mode 100644 index 000000000..3ac9df67a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Dict.java @@ -0,0 +1,140 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class Dict { + DictNode head; + Object frame; + DictLeq leq; + + private Dict() { + } + + static Dict dictNewDict(Object frame, DictLeq leq) { + Dict dict = new Dict(); + dict.head = new DictNode(); + + dict.head.key = null; + dict.head.next = dict.head; + dict.head.prev = dict.head; + + dict.frame = frame; + dict.leq = leq; + + return dict; + } + + static void dictDeleteDict(Dict dict) { + dict.head = null; + dict.frame = null; + dict.leq = null; + } + + static DictNode dictInsert(Dict dict, Object key) { + return dictInsertBefore(dict, dict.head, key); + } + + static DictNode dictInsertBefore(Dict dict, DictNode node, Object key) { + do { + node = node.prev; + } while (node.key != null && !dict.leq.leq(dict.frame, node.key, key)); + + DictNode newNode = new DictNode(); + newNode.key = key; + newNode.next = node.next; + node.next.prev = newNode; + newNode.prev = node; + node.next = newNode; + + return newNode; + } + + static Object dictKey(DictNode aNode) { + return aNode.key; + } + + static DictNode dictSucc(DictNode aNode) { + return aNode.next; + } + + static DictNode dictPred(DictNode aNode) { + return aNode.prev; + } + + static DictNode dictMin(Dict aDict) { + return aDict.head.next; + } + + static DictNode dictMax(Dict aDict) { + return aDict.head.prev; + } + + static void dictDelete(Dict dict, DictNode node) { + node.next.prev = node.prev; + node.prev.next = node.next; + } + + static DictNode dictSearch(Dict dict, Object key) { + DictNode node = dict.head; + + do { + node = node.next; + } while (node.key != null && !(dict.leq.leq(dict.frame, key, node.key))); + + return node; + } + + public interface DictLeq { + boolean leq(Object frame, Object key1, Object key2); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/DictNode.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/DictNode.java new file mode 100644 index 000000000..93cf2314f --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/DictNode.java @@ -0,0 +1,59 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class DictNode { + Object key; + DictNode next; + DictNode prev; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUface.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUface.java new file mode 100644 index 000000000..b15bf7195 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUface.java @@ -0,0 +1,65 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class GLUface { + public GLUface next; /* next face (never NULL) */ + public GLUface prev; /* previous face (never NULL) */ + public GLUhalfEdge anEdge; /* a half edge with this left face */ + public Object data; /* room for client's data */ + + /* Internal data (keep hidden) */ + public GLUface trail; /* "stack" for conversion to strips */ + public boolean marked; /* flag for conversion to strips */ + public boolean inside; /* this face is in the polygon interior */ +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUhalfEdge.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUhalfEdge.java new file mode 100644 index 000000000..385a4384b --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUhalfEdge.java @@ -0,0 +1,71 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class GLUhalfEdge { + public GLUhalfEdge next; /* doubly-linked list (prev==Sym->next) */ + public GLUhalfEdge Sym; /* same edge, opposite direction */ + public GLUhalfEdge Onext; /* next edge CCW around origin */ + public GLUhalfEdge Lnext; /* next edge CCW around left face */ + public GLUvertex Org; /* origin vertex (Overtex too long) */ + public jogamp.opengl.glu.tessellator.GLUface Lface; /* left face */ + + /* Internal data (keep hidden) */ + public jogamp.opengl.glu.tessellator.ActiveRegion activeRegion; /* a region with this upper edge (sweep.c) */ + public int winding; /* change in winding number when crossing */ + public boolean first; + + public GLUhalfEdge(boolean first) { + this.first = first; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUmesh.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUmesh.java new file mode 100644 index 000000000..dfdf5be70 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUmesh.java @@ -0,0 +1,60 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class GLUmesh { + GLUvertex vHead = new GLUvertex(); /* dummy header for vertex list */ + jogamp.opengl.glu.tessellator.GLUface fHead = new GLUface(); /* dummy header for face list */ + jogamp.opengl.glu.tessellator.GLUhalfEdge eHead = new GLUhalfEdge(true); /* dummy header for edge list */ + jogamp.opengl.glu.tessellator.GLUhalfEdge eHeadSym = new GLUhalfEdge(false); /* and its symmetric counterpart */ +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUtessellatorImpl.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUtessellatorImpl.java new file mode 100644 index 000000000..182820bbc --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUtessellatorImpl.java @@ -0,0 +1,646 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +import jogamp.opengl.glu.tessellator.*; +import javax.media.opengl.*; +import javax.media.opengl.glu.*; + +public class GLUtessellatorImpl implements GLUtessellator { + public static final int TESS_MAX_CACHE = 100; + + private int state; /* what begin/end calls have we seen? */ + + private GLUhalfEdge lastEdge; /* lastEdge->Org is the most recent vertex */ + GLUmesh mesh; /* stores the input contours, and eventually + the tessellation itself */ + + /*** state needed for projecting onto the sweep plane ***/ + + double[] normal = new double[3]; /* user-specified normal (if provided) */ + double[] sUnit = new double[3]; /* unit vector in s-direction (debugging) */ + double[] tUnit = new double[3]; /* unit vector in t-direction (debugging) */ + + /*** state needed for the line sweep ***/ + + private double relTolerance; /* tolerance for merging features */ + int windingRule; /* rule for determining polygon interior */ + boolean fatalError; /* fatal error: needed combine callback */ + + Dict dict; /* edge dictionary for sweep line */ + PriorityQ pq; /* priority queue of vertex events */ + GLUvertex event; /* current sweep event being processed */ + + /*** state needed for rendering callbacks (see render.c) ***/ + + boolean flagBoundary; /* mark boundary edges (use EdgeFlag) */ + boolean boundaryOnly; /* Extract contours, not triangles */ + boolean avoidDegenerateTris; /* JOGL-specific hint to try to improve triangulation + by avoiding producing degenerate (zero-area) triangles; + has not been tested exhaustively and is therefore an option */ + + GLUface lonelyTriList; + /* list of triangles which could not be rendered as strips or fans */ + + + + /*** state needed to cache single-contour polygons for renderCache() */ + + private boolean flushCacheOnNextVertex; /* empty cache on next vertex() call */ + int cacheCount; /* number of cached vertices */ + CachedVertex[] cache = new CachedVertex[TESS_MAX_CACHE]; /* the vertex data */ + + /*** rendering callbacks that also pass polygon data ***/ + private Object polygonData; /* client data for current polygon */ + + private GLUtessellatorCallback callBegin; + private GLUtessellatorCallback callEdgeFlag; + private GLUtessellatorCallback callVertex; + private GLUtessellatorCallback callEnd; +// private GLUtessellatorCallback callMesh; + private GLUtessellatorCallback callError; + private GLUtessellatorCallback callCombine; + + private GLUtessellatorCallback callBeginData; + private GLUtessellatorCallback callEdgeFlagData; + private GLUtessellatorCallback callVertexData; + private GLUtessellatorCallback callEndData; +// private GLUtessellatorCallback callMeshData; + private GLUtessellatorCallback callErrorData; + private GLUtessellatorCallback callCombineData; + + private static final double GLU_TESS_DEFAULT_TOLERANCE = 0.0; +// private static final int GLU_TESS_MESH = 100112; /* void (*)(GLUmesh *mesh) */ + private static GLUtessellatorCallback NULL_CB = new GLUtessellatorCallbackAdapter(); + +// #define MAX_FAST_ALLOC (MAX(sizeof(EdgePair), \ +// MAX(sizeof(GLUvertex),sizeof(GLUface)))) + + private GLUtessellatorImpl() { + state = TessState.T_DORMANT; + + normal[0] = 0; + normal[1] = 0; + normal[2] = 0; + + relTolerance = GLU_TESS_DEFAULT_TOLERANCE; + windingRule = GLU.GLU_TESS_WINDING_ODD; + flagBoundary = false; + boundaryOnly = false; + + callBegin = NULL_CB; + callEdgeFlag = NULL_CB; + callVertex = NULL_CB; + callEnd = NULL_CB; + callError = NULL_CB; + callCombine = NULL_CB; +// callMesh = NULL_CB; + + callBeginData = NULL_CB; + callEdgeFlagData = NULL_CB; + callVertexData = NULL_CB; + callEndData = NULL_CB; + callErrorData = NULL_CB; + callCombineData = NULL_CB; + + polygonData = null; + + for (int i = 0; i < cache.length; i++) { + cache[i] = new CachedVertex(); + } + } + + static public GLUtessellator gluNewTess() + { + return new GLUtessellatorImpl(); + } + + + private void makeDormant() { + /* Return the tessellator to its original dormant state. */ + + if (mesh != null) { + Mesh.__gl_meshDeleteMesh(mesh); + } + state = TessState.T_DORMANT; + lastEdge = null; + mesh = null; + } + + private void requireState(int newState) { + if (state != newState) gotoState(newState); + } + + private void gotoState(int newState) { + while (state != newState) { + /* We change the current state one level at a time, to get to + * the desired state. + */ + if (state < newState) { + if (state == TessState.T_DORMANT) { + callErrorOrErrorData(GLU.GLU_TESS_MISSING_BEGIN_POLYGON); + gluTessBeginPolygon(null); + } else if (state == TessState.T_IN_POLYGON) { + callErrorOrErrorData(GLU.GLU_TESS_MISSING_BEGIN_CONTOUR); + gluTessBeginContour(); + } + } else { + if (state == TessState.T_IN_CONTOUR) { + callErrorOrErrorData(GLU.GLU_TESS_MISSING_END_CONTOUR); + gluTessEndContour(); + } else if (state == TessState.T_IN_POLYGON) { + callErrorOrErrorData(GLU.GLU_TESS_MISSING_END_POLYGON); + /* gluTessEndPolygon( tess ) is too much work! */ + makeDormant(); + } + } + } + } + + public void gluDeleteTess() { + requireState(TessState.T_DORMANT); + } + + public void gluTessProperty(int which, double value) { + switch (which) { + case GLU.GLU_TESS_TOLERANCE: + if (value < 0.0 || value > 1.0) break; + relTolerance = value; + return; + + case GLU.GLU_TESS_WINDING_RULE: + int windingRule = (int) value; + if (windingRule != value) break; /* not an integer */ + + switch (windingRule) { + case GLU.GLU_TESS_WINDING_ODD: + case GLU.GLU_TESS_WINDING_NONZERO: + case GLU.GLU_TESS_WINDING_POSITIVE: + case GLU.GLU_TESS_WINDING_NEGATIVE: + case GLU.GLU_TESS_WINDING_ABS_GEQ_TWO: + this.windingRule = windingRule; + return; + default: + break; + } + + case GLU.GLU_TESS_BOUNDARY_ONLY: + boundaryOnly = (value != 0); + return; + + case GLU.GLU_TESS_AVOID_DEGENERATE_TRIANGLES: + avoidDegenerateTris = (value != 0); + return; + + default: + callErrorOrErrorData(GLU.GLU_INVALID_ENUM); + return; + } + callErrorOrErrorData(GLU.GLU_INVALID_VALUE); + } + +/* Returns tessellator property */ + public void gluGetTessProperty(int which, double[] value, int value_offset) { + switch (which) { + case GLU.GLU_TESS_TOLERANCE: +/* tolerance should be in range [0..1] */ + assert (0.0 <= relTolerance && relTolerance <= 1.0); + value[value_offset] = relTolerance; + break; + case GLU.GLU_TESS_WINDING_RULE: + assert (windingRule == GLU.GLU_TESS_WINDING_ODD || + windingRule == GLU.GLU_TESS_WINDING_NONZERO || + windingRule == GLU.GLU_TESS_WINDING_POSITIVE || + windingRule == GLU.GLU_TESS_WINDING_NEGATIVE || + windingRule == GLU.GLU_TESS_WINDING_ABS_GEQ_TWO); + value[value_offset] = windingRule; + break; + case GLU.GLU_TESS_BOUNDARY_ONLY: + assert (boundaryOnly == true || boundaryOnly == false); + value[value_offset] = boundaryOnly ? 1 : 0; + break; + case GLU.GLU_TESS_AVOID_DEGENERATE_TRIANGLES: + value[value_offset] = avoidDegenerateTris ? 1 : 0; + break; + default: + value[value_offset] = 0.0; + callErrorOrErrorData(GLU.GLU_INVALID_ENUM); + break; + } + } /* gluGetTessProperty() */ + + public void gluTessNormal(double x, double y, double z) { + normal[0] = x; + normal[1] = y; + normal[2] = z; + } + + public void gluTessCallback(int which, GLUtessellatorCallback aCallback) { + switch (which) { + case GLU.GLU_TESS_BEGIN: + callBegin = aCallback == null ? NULL_CB : aCallback; + return; + case GLU.GLU_TESS_BEGIN_DATA: + callBeginData = aCallback == null ? NULL_CB : aCallback; + return; + case GLU.GLU_TESS_EDGE_FLAG: + callEdgeFlag = aCallback == null ? NULL_CB : aCallback; +/* If the client wants boundary edges to be flagged, + * we render everything as separate triangles (no strips or fans). + */ + flagBoundary = aCallback != null; + return; + case GLU.GLU_TESS_EDGE_FLAG_DATA: + callEdgeFlagData = callBegin = aCallback == null ? NULL_CB : aCallback; +/* If the client wants boundary edges to be flagged, + * we render everything as separate triangles (no strips or fans). + */ + flagBoundary = (aCallback != null); + return; + case GLU.GLU_TESS_VERTEX: + callVertex = aCallback == null ? NULL_CB : aCallback; + return; + case GLU.GLU_TESS_VERTEX_DATA: + callVertexData = aCallback == null ? NULL_CB : aCallback; + return; + case GLU.GLU_TESS_END: + callEnd = aCallback == null ? NULL_CB : aCallback; + return; + case GLU.GLU_TESS_END_DATA: + callEndData = aCallback == null ? NULL_CB : aCallback; + return; + case GLU.GLU_TESS_ERROR: + callError = aCallback == null ? NULL_CB : aCallback; + return; + case GLU.GLU_TESS_ERROR_DATA: + callErrorData = aCallback == null ? NULL_CB : aCallback; + return; + case GLU.GLU_TESS_COMBINE: + callCombine = aCallback == null ? NULL_CB : aCallback; + return; + case GLU.GLU_TESS_COMBINE_DATA: + callCombineData = aCallback == null ? NULL_CB : aCallback; + return; +// case GLU_TESS_MESH: +// callMesh = aCallback == null ? NULL_CB : aCallback; +// return; + default: + callErrorOrErrorData(GLU.GLU_INVALID_ENUM); + return; + } + } + + private boolean addVertex(double[] coords, Object vertexData) { + GLUhalfEdge e; + + e = lastEdge; + if (e == null) { +/* Make a self-loop (one vertex, one edge). */ + + e = Mesh.__gl_meshMakeEdge(mesh); + if (e == null) return false; + if (!Mesh.__gl_meshSplice(e, e.Sym)) return false; + } else { +/* Create a new vertex and edge which immediately follow e + * in the ordering around the left face. + */ + if (Mesh.__gl_meshSplitEdge(e) == null) return false; + e = e.Lnext; + } + +/* The new vertex is now e.Org. */ + e.Org.data = vertexData; + e.Org.coords[0] = coords[0]; + e.Org.coords[1] = coords[1]; + e.Org.coords[2] = coords[2]; + +/* The winding of an edge says how the winding number changes as we + * cross from the edge''s right face to its left face. We add the + * vertices in such an order that a CCW contour will add +1 to + * the winding number of the region inside the contour. + */ + e.winding = 1; + e.Sym.winding = -1; + + lastEdge = e; + + return true; + } + + private void cacheVertex(double[] coords, Object vertexData) { + if (cache[cacheCount] == null) { + cache[cacheCount] = new CachedVertex(); + } + + CachedVertex v = cache[cacheCount]; + + v.data = vertexData; + v.coords[0] = coords[0]; + v.coords[1] = coords[1]; + v.coords[2] = coords[2]; + ++cacheCount; + } + + + private boolean flushCache() { + CachedVertex[] v = cache; + + mesh = Mesh.__gl_meshNewMesh(); + if (mesh == null) return false; + + for (int i = 0; i < cacheCount; i++) { + CachedVertex vertex = v[i]; + if (!addVertex(vertex.coords, vertex.data)) return false; + } + cacheCount = 0; + flushCacheOnNextVertex = false; + + return true; + } + + public void gluTessVertex(double[] coords, int coords_offset, Object vertexData) { + int i; + boolean tooLarge = false; + double x; + double[] clamped = new double[3]; + + requireState(TessState.T_IN_CONTOUR); + + if (flushCacheOnNextVertex) { + if (!flushCache()) { + callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY); + return; + } + lastEdge = null; + } + for (i = 0; i < 3; ++i) { + x = coords[i+coords_offset]; + if (x < -GLU.GLU_TESS_MAX_COORD) { + x = -GLU.GLU_TESS_MAX_COORD; + tooLarge = true; + } + if (x > GLU.GLU_TESS_MAX_COORD) { + x = GLU.GLU_TESS_MAX_COORD; + tooLarge = true; + } + clamped[i] = x; + } + if (tooLarge) { + callErrorOrErrorData(GLU.GLU_TESS_COORD_TOO_LARGE); + } + + if (mesh == null) { + if (cacheCount < TESS_MAX_CACHE) { + cacheVertex(clamped, vertexData); + return; + } + if (!flushCache()) { + callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY); + return; + } + } + + if (!addVertex(clamped, vertexData)) { + callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY); + } + } + + + public void gluTessBeginPolygon(Object data) { + requireState(TessState.T_DORMANT); + + state = TessState.T_IN_POLYGON; + cacheCount = 0; + flushCacheOnNextVertex = false; + mesh = null; + + polygonData = data; + } + + + public void gluTessBeginContour() { + requireState(TessState.T_IN_POLYGON); + + state = TessState.T_IN_CONTOUR; + lastEdge = null; + if (cacheCount > 0) { +/* Just set a flag so we don't get confused by empty contours + * -- these can be generated accidentally with the obsolete + * NextContour() interface. + */ + flushCacheOnNextVertex = true; + } + } + + + public void gluTessEndContour() { + requireState(TessState.T_IN_CONTOUR); + state = TessState.T_IN_POLYGON; + } + + public void gluTessEndPolygon() { + GLUmesh mesh; + + try { + requireState(TessState.T_IN_POLYGON); + state = TessState.T_DORMANT; + + if (this.mesh == null) { + if (!flagBoundary /*&& callMesh == NULL_CB*/) { + +/* Try some special code to make the easy cases go quickly + * (eg. convex polygons). This code does NOT handle multiple contours, + * intersections, edge flags, and of course it does not generate + * an explicit mesh either. + */ + if (Render.__gl_renderCache(this)) { + polygonData = null; + return; + } + } + if (!flushCache()) throw new RuntimeException(); /* could've used a label*/ + } + +/* Determine the polygon normal and project vertices onto the plane + * of the polygon. + */ + Normal.__gl_projectPolygon(this); + +/* __gl_computeInterior( tess ) computes the planar arrangement specified + * by the given contours, and further subdivides this arrangement + * into regions. Each region is marked "inside" if it belongs + * to the polygon, according to the rule given by windingRule. + * Each interior region is guaranteed be monotone. + */ + if (!Sweep.__gl_computeInterior(this)) { + throw new RuntimeException(); /* could've used a label */ + } + + mesh = this.mesh; + if (!fatalError) { + boolean rc = true; + +/* If the user wants only the boundary contours, we throw away all edges + * except those which separate the interior from the exterior. + * Otherwise we tessellate all the regions marked "inside". + */ + if (boundaryOnly) { + rc = TessMono.__gl_meshSetWindingNumber(mesh, 1, true); + } else { + rc = TessMono.__gl_meshTessellateInterior(mesh, avoidDegenerateTris); + } + if (!rc) throw new RuntimeException(); /* could've used a label */ + + Mesh.__gl_meshCheckMesh(mesh); + + if (callBegin != NULL_CB || callEnd != NULL_CB + || callVertex != NULL_CB || callEdgeFlag != NULL_CB + || callBeginData != NULL_CB + || callEndData != NULL_CB + || callVertexData != NULL_CB + || callEdgeFlagData != NULL_CB) { + if (boundaryOnly) { + Render.__gl_renderBoundary(this, mesh); /* output boundary contours */ + } else { + Render.__gl_renderMesh(this, mesh); /* output strips and fans */ + } + } +// if (callMesh != NULL_CB) { +// +///* Throw away the exterior faces, so that all faces are interior. +// * This way the user doesn't have to check the "inside" flag, +// * and we don't need to even reveal its existence. It also leaves +// * the freedom for an implementation to not generate the exterior +// * faces in the first place. +// */ +// TessMono.__gl_meshDiscardExterior(mesh); +// callMesh.mesh(mesh); /* user wants the mesh itself */ +// mesh = null; +// polygonData = null; +// return; +// } + } + Mesh.__gl_meshDeleteMesh(mesh); + polygonData = null; + mesh = null; + } catch (Exception e) { + e.printStackTrace(); + callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY); + } + } + + /*******************************************************/ + +/* Obsolete calls -- for backward compatibility */ + + public void gluBeginPolygon() { + gluTessBeginPolygon(null); + gluTessBeginContour(); + } + + +/*ARGSUSED*/ + public void gluNextContour(int type) { + gluTessEndContour(); + gluTessBeginContour(); + } + + + public void gluEndPolygon() { + gluTessEndContour(); + gluTessEndPolygon(); + } + + void callBeginOrBeginData(int a) { + if (callBeginData != NULL_CB) + callBeginData.beginData(a, polygonData); + else + callBegin.begin(a); + } + + void callVertexOrVertexData(Object a) { + if (callVertexData != NULL_CB) + callVertexData.vertexData(a, polygonData); + else + callVertex.vertex(a); + } + + void callEdgeFlagOrEdgeFlagData(boolean a) { + if (callEdgeFlagData != NULL_CB) + callEdgeFlagData.edgeFlagData(a, polygonData); + else + callEdgeFlag.edgeFlag(a); + } + + void callEndOrEndData() { + if (callEndData != NULL_CB) + callEndData.endData(polygonData); + else + callEnd.end(); + } + + void callCombineOrCombineData(double[] coords, Object[] vertexData, float[] weights, Object[] outData) { + if (callCombineData != NULL_CB) + callCombineData.combineData(coords, vertexData, weights, outData, polygonData); + else + callCombine.combine(coords, vertexData, weights, outData); + } + + void callErrorOrErrorData(int a) { + if (callErrorData != NULL_CB) + callErrorData.errorData(a, polygonData); + else + callError.error(a); + } + +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUvertex.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUvertex.java new file mode 100644 index 000000000..c30d75946 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUvertex.java @@ -0,0 +1,65 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class GLUvertex { + public GLUvertex next; /* next vertex (never NULL) */ + public GLUvertex prev; /* previous vertex (never NULL) */ + public jogamp.opengl.glu.tessellator.GLUhalfEdge anEdge; /* a half-edge with this origin */ + public Object data; /* client's data */ + + /* Internal data (keep hidden) */ + public double[] coords = new double[3]; /* vertex location in 3D */ + public double s, t; /* projection onto the sweep plane */ + public int pqHandle; /* to allow deletion from priority queue */ +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/Geom.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Geom.java new file mode 100644 index 000000000..3da2d267e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Geom.java @@ -0,0 +1,338 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class Geom { + private Geom() { + } + + /* Given three vertices u,v,w such that VertLeq(u,v) && VertLeq(v,w), + * evaluates the t-coord of the edge uw at the s-coord of the vertex v. + * Returns v->t - (uw)(v->s), ie. the signed distance from uw to v. + * If uw is vertical (and thus passes thru v), the result is zero. + * + * The calculation is extremely accurate and stable, even when v + * is very close to u or w. In particular if we set v->t = 0 and + * let r be the negated result (this evaluates (uw)(v->s)), then + * r is guaranteed to satisfy MIN(u->t,w->t) <= r <= MAX(u->t,w->t). + */ + static double EdgeEval(GLUvertex u, GLUvertex v, GLUvertex w) { + double gapL, gapR; + + assert (VertLeq(u, v) && VertLeq(v, w)); + + gapL = v.s - u.s; + gapR = w.s - v.s; + + if (gapL + gapR > 0) { + if (gapL < gapR) { + return (v.t - u.t) + (u.t - w.t) * (gapL / (gapL + gapR)); + } else { + return (v.t - w.t) + (w.t - u.t) * (gapR / (gapL + gapR)); + } + } + /* vertical line */ + return 0; + } + + static double EdgeSign(GLUvertex u, GLUvertex v, GLUvertex w) { + double gapL, gapR; + + assert (VertLeq(u, v) && VertLeq(v, w)); + + gapL = v.s - u.s; + gapR = w.s - v.s; + + if (gapL + gapR > 0) { + return (v.t - w.t) * gapL + (v.t - u.t) * gapR; + } + /* vertical line */ + return 0; + } + + + /*********************************************************************** + * Define versions of EdgeSign, EdgeEval with s and t transposed. + */ + + static double TransEval(GLUvertex u, GLUvertex v, GLUvertex w) { + /* Given three vertices u,v,w such that TransLeq(u,v) && TransLeq(v,w), + * evaluates the t-coord of the edge uw at the s-coord of the vertex v. + * Returns v->s - (uw)(v->t), ie. the signed distance from uw to v. + * If uw is vertical (and thus passes thru v), the result is zero. + * + * The calculation is extremely accurate and stable, even when v + * is very close to u or w. In particular if we set v->s = 0 and + * let r be the negated result (this evaluates (uw)(v->t)), then + * r is guaranteed to satisfy MIN(u->s,w->s) <= r <= MAX(u->s,w->s). + */ + double gapL, gapR; + + assert (TransLeq(u, v) && TransLeq(v, w)); + + gapL = v.t - u.t; + gapR = w.t - v.t; + + if (gapL + gapR > 0) { + if (gapL < gapR) { + return (v.s - u.s) + (u.s - w.s) * (gapL / (gapL + gapR)); + } else { + return (v.s - w.s) + (w.s - u.s) * (gapR / (gapL + gapR)); + } + } + /* vertical line */ + return 0; + } + + static double TransSign(GLUvertex u, GLUvertex v, GLUvertex w) { + /* Returns a number whose sign matches TransEval(u,v,w) but which + * is cheaper to evaluate. Returns > 0, == 0 , or < 0 + * as v is above, on, or below the edge uw. + */ + double gapL, gapR; + + assert (TransLeq(u, v) && TransLeq(v, w)); + + gapL = v.t - u.t; + gapR = w.t - v.t; + + if (gapL + gapR > 0) { + return (v.s - w.s) * gapL + (v.s - u.s) * gapR; + } + /* vertical line */ + return 0; + } + + + static boolean VertCCW(GLUvertex u, GLUvertex v, GLUvertex w) { + /* For almost-degenerate situations, the results are not reliable. + * Unless the floating-point arithmetic can be performed without + * rounding errors, *any* implementation will give incorrect results + * on some degenerate inputs, so the client must have some way to + * handle this situation. + */ + return (u.s * (v.t - w.t) + v.s * (w.t - u.t) + w.s * (u.t - v.t)) >= 0; + } + +/* Given parameters a,x,b,y returns the value (b*x+a*y)/(a+b), + * or (x+y)/2 if a==b==0. It requires that a,b >= 0, and enforces + * this in the rare case that one argument is slightly negative. + * The implementation is extremely stable numerically. + * In particular it guarantees that the result r satisfies + * MIN(x,y) <= r <= MAX(x,y), and the results are very accurate + * even when a and b differ greatly in magnitude. + */ + static double Interpolate(double a, double x, double b, double y) { + a = (a < 0) ? 0 : a; + b = (b < 0) ? 0 : b; + if (a <= b) { + if (b == 0) { + return (x + y) / 2.0; + } else { + return (x + (y - x) * (a / (a + b))); + } + } else { + return (y + (x - y) * (b / (a + b))); + } + } + + static void EdgeIntersect(GLUvertex o1, GLUvertex d1, + GLUvertex o2, GLUvertex d2, + GLUvertex v) +/* Given edges (o1,d1) and (o2,d2), compute their point of intersection. + * The computed point is guaranteed to lie in the intersection of the + * bounding rectangles defined by each edge. + */ { + double z1, z2; + + /* This is certainly not the most efficient way to find the intersection + * of two line segments, but it is very numerically stable. + * + * Strategy: find the two middle vertices in the VertLeq ordering, + * and interpolate the intersection s-value from these. Then repeat + * using the TransLeq ordering to find the intersection t-value. + */ + + if (!VertLeq(o1, d1)) { + GLUvertex temp = o1; + o1 = d1; + d1 = temp; + } + if (!VertLeq(o2, d2)) { + GLUvertex temp = o2; + o2 = d2; + d2 = temp; + } + if (!VertLeq(o1, o2)) { + GLUvertex temp = o1; + o1 = o2; + o2 = temp; + temp = d1; + d1 = d2; + d2 = temp; + } + + if (!VertLeq(o2, d1)) { + /* Technically, no intersection -- do our best */ + v.s = (o2.s + d1.s) / 2.0; + } else if (VertLeq(d1, d2)) { + /* Interpolate between o2 and d1 */ + z1 = EdgeEval(o1, o2, d1); + z2 = EdgeEval(o2, d1, d2); + if (z1 + z2 < 0) { + z1 = -z1; + z2 = -z2; + } + v.s = Interpolate(z1, o2.s, z2, d1.s); + } else { + /* Interpolate between o2 and d2 */ + z1 = EdgeSign(o1, o2, d1); + z2 = -EdgeSign(o1, d2, d1); + if (z1 + z2 < 0) { + z1 = -z1; + z2 = -z2; + } + v.s = Interpolate(z1, o2.s, z2, d2.s); + } + + /* Now repeat the process for t */ + + if (!TransLeq(o1, d1)) { + GLUvertex temp = o1; + o1 = d1; + d1 = temp; + } + if (!TransLeq(o2, d2)) { + GLUvertex temp = o2; + o2 = d2; + d2 = temp; + } + if (!TransLeq(o1, o2)) { + GLUvertex temp = o2; + o2 = o1; + o1 = temp; + temp = d2; + d2 = d1; + d1 = temp; + } + + if (!TransLeq(o2, d1)) { + /* Technically, no intersection -- do our best */ + v.t = (o2.t + d1.t) / 2.0; + } else if (TransLeq(d1, d2)) { + /* Interpolate between o2 and d1 */ + z1 = TransEval(o1, o2, d1); + z2 = TransEval(o2, d1, d2); + if (z1 + z2 < 0) { + z1 = -z1; + z2 = -z2; + } + v.t = Interpolate(z1, o2.t, z2, d1.t); + } else { + /* Interpolate between o2 and d2 */ + z1 = TransSign(o1, o2, d1); + z2 = -TransSign(o1, d2, d1); + if (z1 + z2 < 0) { + z1 = -z1; + z2 = -z2; + } + v.t = Interpolate(z1, o2.t, z2, d2.t); + } + } + + static boolean VertEq(GLUvertex u, GLUvertex v) { + return u.s == v.s && u.t == v.t; + } + + static boolean VertLeq(GLUvertex u, GLUvertex v) { + return u.s < v.s || (u.s == v.s && u.t <= v.t); + } + +/* Versions of VertLeq, EdgeSign, EdgeEval with s and t transposed. */ + + static boolean TransLeq(GLUvertex u, GLUvertex v) { + return u.t < v.t || (u.t == v.t && u.s <= v.s); + } + + static boolean EdgeGoesLeft(GLUhalfEdge e) { + return VertLeq(e.Sym.Org, e.Org); + } + + static boolean EdgeGoesRight(GLUhalfEdge e) { + return VertLeq(e.Org, e.Sym.Org); + } + + static double VertL1dist(GLUvertex u, GLUvertex v) { + return Math.abs(u.s - v.s) + Math.abs(u.t - v.t); + } + + /***********************************************************************/ + + // Compute the cosine of the angle between the edges between o and + // v1 and between o and v2 + static double EdgeCos(GLUvertex o, GLUvertex v1, GLUvertex v2) { + double ov1s = v1.s - o.s; + double ov1t = v1.t - o.t; + double ov2s = v2.s - o.s; + double ov2t = v2.t - o.t; + double dotp = ov1s * ov2s + ov1t * ov2t; + double len = Math.sqrt(ov1s * ov1s + ov1t * ov1t) * Math.sqrt(ov2s * ov2s + ov2t * ov2t); + if (len > 0.0) { + dotp /= len; + } + return dotp; + } + + static final double EPSILON = 1.0e-5; + static final double ONE_MINUS_EPSILON = 1.0 - EPSILON; +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/Mesh.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Mesh.java new file mode 100644 index 000000000..942dfe8d1 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Mesh.java @@ -0,0 +1,734 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class Mesh { + private Mesh() { + } + + /************************ Utility Routines ************************/ +/* MakeEdge creates a new pair of half-edges which form their own loop. + * No vertex or face structures are allocated, but these must be assigned + * before the current edge operation is completed. + */ + static jogamp.opengl.glu.tessellator.GLUhalfEdge MakeEdge(jogamp.opengl.glu.tessellator.GLUhalfEdge eNext) { + jogamp.opengl.glu.tessellator.GLUhalfEdge e; + jogamp.opengl.glu.tessellator.GLUhalfEdge eSym; + jogamp.opengl.glu.tessellator.GLUhalfEdge ePrev; + +// EdgePair * pair = (EdgePair *) +// memAlloc(sizeof(EdgePair)); +// if (pair == NULL) return NULL; +// +// e = &pair - > e; + e = new jogamp.opengl.glu.tessellator.GLUhalfEdge(true); +// eSym = &pair - > eSym; + eSym = new jogamp.opengl.glu.tessellator.GLUhalfEdge(false); + + + /* Make sure eNext points to the first edge of the edge pair */ + if (!eNext.first) { + eNext = eNext.Sym; + } + + /* Insert in circular doubly-linked list before eNext. + * Note that the prev pointer is stored in Sym->next. + */ + ePrev = eNext.Sym.next; + eSym.next = ePrev; + ePrev.Sym.next = e; + e.next = eNext; + eNext.Sym.next = eSym; + + e.Sym = eSym; + e.Onext = e; + e.Lnext = eSym; + e.Org = null; + e.Lface = null; + e.winding = 0; + e.activeRegion = null; + + eSym.Sym = e; + eSym.Onext = eSym; + eSym.Lnext = e; + eSym.Org = null; + eSym.Lface = null; + eSym.winding = 0; + eSym.activeRegion = null; + + return e; + } + +/* Splice( a, b ) is best described by the Guibas/Stolfi paper or the + * CS348a notes (see mesh.h). Basically it modifies the mesh so that + * a->Onext and b->Onext are exchanged. This can have various effects + * depending on whether a and b belong to different face or vertex rings. + * For more explanation see __gl_meshSplice() below. + */ + static void Splice(jogamp.opengl.glu.tessellator.GLUhalfEdge a, jogamp.opengl.glu.tessellator.GLUhalfEdge b) { + jogamp.opengl.glu.tessellator.GLUhalfEdge aOnext = a.Onext; + jogamp.opengl.glu.tessellator.GLUhalfEdge bOnext = b.Onext; + + aOnext.Sym.Lnext = b; + bOnext.Sym.Lnext = a; + a.Onext = bOnext; + b.Onext = aOnext; + } + +/* MakeVertex( newVertex, eOrig, vNext ) attaches a new vertex and makes it the + * origin of all edges in the vertex loop to which eOrig belongs. "vNext" gives + * a place to insert the new vertex in the global vertex list. We insert + * the new vertex *before* vNext so that algorithms which walk the vertex + * list will not see the newly created vertices. + */ + static void MakeVertex(jogamp.opengl.glu.tessellator.GLUvertex newVertex, + jogamp.opengl.glu.tessellator.GLUhalfEdge eOrig, jogamp.opengl.glu.tessellator.GLUvertex vNext) { + jogamp.opengl.glu.tessellator.GLUhalfEdge e; + jogamp.opengl.glu.tessellator.GLUvertex vPrev; + jogamp.opengl.glu.tessellator.GLUvertex vNew = newVertex; + + assert (vNew != null); + + /* insert in circular doubly-linked list before vNext */ + vPrev = vNext.prev; + vNew.prev = vPrev; + vPrev.next = vNew; + vNew.next = vNext; + vNext.prev = vNew; + + vNew.anEdge = eOrig; + vNew.data = null; + /* leave coords, s, t undefined */ + + /* fix other edges on this vertex loop */ + e = eOrig; + do { + e.Org = vNew; + e = e.Onext; + } while (e != eOrig); + } + +/* MakeFace( newFace, eOrig, fNext ) attaches a new face and makes it the left + * face of all edges in the face loop to which eOrig belongs. "fNext" gives + * a place to insert the new face in the global face list. We insert + * the new face *before* fNext so that algorithms which walk the face + * list will not see the newly created faces. + */ + static void MakeFace(jogamp.opengl.glu.tessellator.GLUface newFace, jogamp.opengl.glu.tessellator.GLUhalfEdge eOrig, jogamp.opengl.glu.tessellator.GLUface fNext) { + jogamp.opengl.glu.tessellator.GLUhalfEdge e; + jogamp.opengl.glu.tessellator.GLUface fPrev; + jogamp.opengl.glu.tessellator.GLUface fNew = newFace; + + assert (fNew != null); + + /* insert in circular doubly-linked list before fNext */ + fPrev = fNext.prev; + fNew.prev = fPrev; + fPrev.next = fNew; + fNew.next = fNext; + fNext.prev = fNew; + + fNew.anEdge = eOrig; + fNew.data = null; + fNew.trail = null; + fNew.marked = false; + + /* The new face is marked "inside" if the old one was. This is a + * convenience for the common case where a face has been split in two. + */ + fNew.inside = fNext.inside; + + /* fix other edges on this face loop */ + e = eOrig; + do { + e.Lface = fNew; + e = e.Lnext; + } while (e != eOrig); + } + +/* KillEdge( eDel ) destroys an edge (the half-edges eDel and eDel->Sym), + * and removes from the global edge list. + */ + static void KillEdge(jogamp.opengl.glu.tessellator.GLUhalfEdge eDel) { + jogamp.opengl.glu.tessellator.GLUhalfEdge ePrev, eNext; + + /* Half-edges are allocated in pairs, see EdgePair above */ + if (!eDel.first) { + eDel = eDel.Sym; + } + + /* delete from circular doubly-linked list */ + eNext = eDel.next; + ePrev = eDel.Sym.next; + eNext.Sym.next = ePrev; + ePrev.Sym.next = eNext; + } + + +/* KillVertex( vDel ) destroys a vertex and removes it from the global + * vertex list. It updates the vertex loop to point to a given new vertex. + */ + static void KillVertex(jogamp.opengl.glu.tessellator.GLUvertex vDel, jogamp.opengl.glu.tessellator.GLUvertex newOrg) { + jogamp.opengl.glu.tessellator.GLUhalfEdge e, eStart = vDel.anEdge; + jogamp.opengl.glu.tessellator.GLUvertex vPrev, vNext; + + /* change the origin of all affected edges */ + e = eStart; + do { + e.Org = newOrg; + e = e.Onext; + } while (e != eStart); + + /* delete from circular doubly-linked list */ + vPrev = vDel.prev; + vNext = vDel.next; + vNext.prev = vPrev; + vPrev.next = vNext; + } + +/* KillFace( fDel ) destroys a face and removes it from the global face + * list. It updates the face loop to point to a given new face. + */ + static void KillFace(jogamp.opengl.glu.tessellator.GLUface fDel, jogamp.opengl.glu.tessellator.GLUface newLface) { + jogamp.opengl.glu.tessellator.GLUhalfEdge e, eStart = fDel.anEdge; + jogamp.opengl.glu.tessellator.GLUface fPrev, fNext; + + /* change the left face of all affected edges */ + e = eStart; + do { + e.Lface = newLface; + e = e.Lnext; + } while (e != eStart); + + /* delete from circular doubly-linked list */ + fPrev = fDel.prev; + fNext = fDel.next; + fNext.prev = fPrev; + fPrev.next = fNext; + } + + + /****************** Basic Edge Operations **********************/ + +/* __gl_meshMakeEdge creates one edge, two vertices, and a loop (face). + * The loop consists of the two new half-edges. + */ + public static jogamp.opengl.glu.tessellator.GLUhalfEdge __gl_meshMakeEdge(jogamp.opengl.glu.tessellator.GLUmesh mesh) { + jogamp.opengl.glu.tessellator.GLUvertex newVertex1 = new jogamp.opengl.glu.tessellator.GLUvertex(); + jogamp.opengl.glu.tessellator.GLUvertex newVertex2 = new jogamp.opengl.glu.tessellator.GLUvertex(); + jogamp.opengl.glu.tessellator.GLUface newFace = new jogamp.opengl.glu.tessellator.GLUface(); + jogamp.opengl.glu.tessellator.GLUhalfEdge e; + + e = MakeEdge(mesh.eHead); + if (e == null) return null; + + MakeVertex(newVertex1, e, mesh.vHead); + MakeVertex(newVertex2, e.Sym, mesh.vHead); + MakeFace(newFace, e, mesh.fHead); + return e; + } + + +/* __gl_meshSplice( eOrg, eDst ) is the basic operation for changing the + * mesh connectivity and topology. It changes the mesh so that + * eOrg->Onext <- OLD( eDst->Onext ) + * eDst->Onext <- OLD( eOrg->Onext ) + * where OLD(...) means the value before the meshSplice operation. + * + * This can have two effects on the vertex structure: + * - if eOrg->Org != eDst->Org, the two vertices are merged together + * - if eOrg->Org == eDst->Org, the origin is split into two vertices + * In both cases, eDst->Org is changed and eOrg->Org is untouched. + * + * Similarly (and independently) for the face structure, + * - if eOrg->Lface == eDst->Lface, one loop is split into two + * - if eOrg->Lface != eDst->Lface, two distinct loops are joined into one + * In both cases, eDst->Lface is changed and eOrg->Lface is unaffected. + * + * Some special cases: + * If eDst == eOrg, the operation has no effect. + * If eDst == eOrg->Lnext, the new face will have a single edge. + * If eDst == eOrg->Lprev, the old face will have a single edge. + * If eDst == eOrg->Onext, the new vertex will have a single edge. + * If eDst == eOrg->Oprev, the old vertex will have a single edge. + */ + public static boolean __gl_meshSplice(jogamp.opengl.glu.tessellator.GLUhalfEdge eOrg, jogamp.opengl.glu.tessellator.GLUhalfEdge eDst) { + boolean joiningLoops = false; + boolean joiningVertices = false; + + if (eOrg == eDst) return true; + + if (eDst.Org != eOrg.Org) { + /* We are merging two disjoint vertices -- destroy eDst->Org */ + joiningVertices = true; + KillVertex(eDst.Org, eOrg.Org); + } + if (eDst.Lface != eOrg.Lface) { + /* We are connecting two disjoint loops -- destroy eDst.Lface */ + joiningLoops = true; + KillFace(eDst.Lface, eOrg.Lface); + } + + /* Change the edge structure */ + Splice(eDst, eOrg); + + if (!joiningVertices) { + jogamp.opengl.glu.tessellator.GLUvertex newVertex = new jogamp.opengl.glu.tessellator.GLUvertex(); + + /* We split one vertex into two -- the new vertex is eDst.Org. + * Make sure the old vertex points to a valid half-edge. + */ + MakeVertex(newVertex, eDst, eOrg.Org); + eOrg.Org.anEdge = eOrg; + } + if (!joiningLoops) { + jogamp.opengl.glu.tessellator.GLUface newFace = new jogamp.opengl.glu.tessellator.GLUface(); + + /* We split one loop into two -- the new loop is eDst.Lface. + * Make sure the old face points to a valid half-edge. + */ + MakeFace(newFace, eDst, eOrg.Lface); + eOrg.Lface.anEdge = eOrg; + } + + return true; + } + + +/* __gl_meshDelete( eDel ) removes the edge eDel. There are several cases: + * if (eDel.Lface != eDel.Rface), we join two loops into one; the loop + * eDel.Lface is deleted. Otherwise, we are splitting one loop into two; + * the newly created loop will contain eDel.Dst. If the deletion of eDel + * would create isolated vertices, those are deleted as well. + * + * This function could be implemented as two calls to __gl_meshSplice + * plus a few calls to memFree, but this would allocate and delete + * unnecessary vertices and faces. + */ + static boolean __gl_meshDelete(jogamp.opengl.glu.tessellator.GLUhalfEdge eDel) { + jogamp.opengl.glu.tessellator.GLUhalfEdge eDelSym = eDel.Sym; + boolean joiningLoops = false; + + /* First step: disconnect the origin vertex eDel.Org. We make all + * changes to get a consistent mesh in this "intermediate" state. + */ + if (eDel.Lface != eDel.Sym.Lface) { + /* We are joining two loops into one -- remove the left face */ + joiningLoops = true; + KillFace(eDel.Lface, eDel.Sym.Lface); + } + + if (eDel.Onext == eDel) { + KillVertex(eDel.Org, null); + } else { + /* Make sure that eDel.Org and eDel.Sym.Lface point to valid half-edges */ + eDel.Sym.Lface.anEdge = eDel.Sym.Lnext; + eDel.Org.anEdge = eDel.Onext; + + Splice(eDel, eDel.Sym.Lnext); + if (!joiningLoops) { + jogamp.opengl.glu.tessellator.GLUface newFace = new jogamp.opengl.glu.tessellator.GLUface(); + + /* We are splitting one loop into two -- create a new loop for eDel. */ + MakeFace(newFace, eDel, eDel.Lface); + } + } + + /* Claim: the mesh is now in a consistent state, except that eDel.Org + * may have been deleted. Now we disconnect eDel.Dst. + */ + if (eDelSym.Onext == eDelSym) { + KillVertex(eDelSym.Org, null); + KillFace(eDelSym.Lface, null); + } else { + /* Make sure that eDel.Dst and eDel.Lface point to valid half-edges */ + eDel.Lface.anEdge = eDelSym.Sym.Lnext; + eDelSym.Org.anEdge = eDelSym.Onext; + Splice(eDelSym, eDelSym.Sym.Lnext); + } + + /* Any isolated vertices or faces have already been freed. */ + KillEdge(eDel); + + return true; + } + + + /******************** Other Edge Operations **********************/ + +/* All these routines can be implemented with the basic edge + * operations above. They are provided for convenience and efficiency. + */ + + +/* __gl_meshAddEdgeVertex( eOrg ) creates a new edge eNew such that + * eNew == eOrg.Lnext, and eNew.Dst is a newly created vertex. + * eOrg and eNew will have the same left face. + */ + static jogamp.opengl.glu.tessellator.GLUhalfEdge __gl_meshAddEdgeVertex(jogamp.opengl.glu.tessellator.GLUhalfEdge eOrg) { + jogamp.opengl.glu.tessellator.GLUhalfEdge eNewSym; + jogamp.opengl.glu.tessellator.GLUhalfEdge eNew = MakeEdge(eOrg); + + eNewSym = eNew.Sym; + + /* Connect the new edge appropriately */ + Splice(eNew, eOrg.Lnext); + + /* Set the vertex and face information */ + eNew.Org = eOrg.Sym.Org; + { + jogamp.opengl.glu.tessellator.GLUvertex newVertex = new jogamp.opengl.glu.tessellator.GLUvertex(); + + MakeVertex(newVertex, eNewSym, eNew.Org); + } + eNew.Lface = eNewSym.Lface = eOrg.Lface; + + return eNew; + } + + +/* __gl_meshSplitEdge( eOrg ) splits eOrg into two edges eOrg and eNew, + * such that eNew == eOrg.Lnext. The new vertex is eOrg.Sym.Org == eNew.Org. + * eOrg and eNew will have the same left face. + */ + public static jogamp.opengl.glu.tessellator.GLUhalfEdge __gl_meshSplitEdge(jogamp.opengl.glu.tessellator.GLUhalfEdge eOrg) { + jogamp.opengl.glu.tessellator.GLUhalfEdge eNew; + jogamp.opengl.glu.tessellator.GLUhalfEdge tempHalfEdge = __gl_meshAddEdgeVertex(eOrg); + + eNew = tempHalfEdge.Sym; + + /* Disconnect eOrg from eOrg.Sym.Org and connect it to eNew.Org */ + Splice(eOrg.Sym, eOrg.Sym.Sym.Lnext); + Splice(eOrg.Sym, eNew); + + /* Set the vertex and face information */ + eOrg.Sym.Org = eNew.Org; + eNew.Sym.Org.anEdge = eNew.Sym; /* may have pointed to eOrg.Sym */ + eNew.Sym.Lface = eOrg.Sym.Lface; + eNew.winding = eOrg.winding; /* copy old winding information */ + eNew.Sym.winding = eOrg.Sym.winding; + + return eNew; + } + + +/* __gl_meshConnect( eOrg, eDst ) creates a new edge from eOrg.Sym.Org + * to eDst.Org, and returns the corresponding half-edge eNew. + * If eOrg.Lface == eDst.Lface, this splits one loop into two, + * and the newly created loop is eNew.Lface. Otherwise, two disjoint + * loops are merged into one, and the loop eDst.Lface is destroyed. + * + * If (eOrg == eDst), the new face will have only two edges. + * If (eOrg.Lnext == eDst), the old face is reduced to a single edge. + * If (eOrg.Lnext.Lnext == eDst), the old face is reduced to two edges. + */ + static jogamp.opengl.glu.tessellator.GLUhalfEdge __gl_meshConnect(jogamp.opengl.glu.tessellator.GLUhalfEdge eOrg, jogamp.opengl.glu.tessellator.GLUhalfEdge eDst) { + jogamp.opengl.glu.tessellator.GLUhalfEdge eNewSym; + boolean joiningLoops = false; + jogamp.opengl.glu.tessellator.GLUhalfEdge eNew = MakeEdge(eOrg); + + eNewSym = eNew.Sym; + + if (eDst.Lface != eOrg.Lface) { + /* We are connecting two disjoint loops -- destroy eDst.Lface */ + joiningLoops = true; + KillFace(eDst.Lface, eOrg.Lface); + } + + /* Connect the new edge appropriately */ + Splice(eNew, eOrg.Lnext); + Splice(eNewSym, eDst); + + /* Set the vertex and face information */ + eNew.Org = eOrg.Sym.Org; + eNewSym.Org = eDst.Org; + eNew.Lface = eNewSym.Lface = eOrg.Lface; + + /* Make sure the old face points to a valid half-edge */ + eOrg.Lface.anEdge = eNewSym; + + if (!joiningLoops) { + jogamp.opengl.glu.tessellator.GLUface newFace = new jogamp.opengl.glu.tessellator.GLUface(); + + /* We split one loop into two -- the new loop is eNew.Lface */ + MakeFace(newFace, eNew, eOrg.Lface); + } + return eNew; + } + + + /******************** Other Operations **********************/ + +/* __gl_meshZapFace( fZap ) destroys a face and removes it from the + * global face list. All edges of fZap will have a null pointer as their + * left face. Any edges which also have a null pointer as their right face + * are deleted entirely (along with any isolated vertices this produces). + * An entire mesh can be deleted by zapping its faces, one at a time, + * in any order. Zapped faces cannot be used in further mesh operations! + */ + static void __gl_meshZapFace(jogamp.opengl.glu.tessellator.GLUface fZap) { + jogamp.opengl.glu.tessellator.GLUhalfEdge eStart = fZap.anEdge; + jogamp.opengl.glu.tessellator.GLUhalfEdge e, eNext, eSym; + jogamp.opengl.glu.tessellator.GLUface fPrev, fNext; + + /* walk around face, deleting edges whose right face is also null */ + eNext = eStart.Lnext; + do { + e = eNext; + eNext = e.Lnext; + + e.Lface = null; + if (e.Sym.Lface == null) { + /* delete the edge -- see __gl_MeshDelete above */ + + if (e.Onext == e) { + KillVertex(e.Org, null); + } else { + /* Make sure that e.Org points to a valid half-edge */ + e.Org.anEdge = e.Onext; + Splice(e, e.Sym.Lnext); + } + eSym = e.Sym; + if (eSym.Onext == eSym) { + KillVertex(eSym.Org, null); + } else { + /* Make sure that eSym.Org points to a valid half-edge */ + eSym.Org.anEdge = eSym.Onext; + Splice(eSym, eSym.Sym.Lnext); + } + KillEdge(e); + } + } while (e != eStart); + + /* delete from circular doubly-linked list */ + fPrev = fZap.prev; + fNext = fZap.next; + fNext.prev = fPrev; + fPrev.next = fNext; + } + + +/* __gl_meshNewMesh() creates a new mesh with no edges, no vertices, + * and no loops (what we usually call a "face"). + */ + public static jogamp.opengl.glu.tessellator.GLUmesh __gl_meshNewMesh() { + jogamp.opengl.glu.tessellator.GLUvertex v; + jogamp.opengl.glu.tessellator.GLUface f; + jogamp.opengl.glu.tessellator.GLUhalfEdge e; + jogamp.opengl.glu.tessellator.GLUhalfEdge eSym; + jogamp.opengl.glu.tessellator.GLUmesh mesh = new jogamp.opengl.glu.tessellator.GLUmesh(); + + v = mesh.vHead; + f = mesh.fHead; + e = mesh.eHead; + eSym = mesh.eHeadSym; + + v.next = v.prev = v; + v.anEdge = null; + v.data = null; + + f.next = f.prev = f; + f.anEdge = null; + f.data = null; + f.trail = null; + f.marked = false; + f.inside = false; + + e.next = e; + e.Sym = eSym; + e.Onext = null; + e.Lnext = null; + e.Org = null; + e.Lface = null; + e.winding = 0; + e.activeRegion = null; + + eSym.next = eSym; + eSym.Sym = e; + eSym.Onext = null; + eSym.Lnext = null; + eSym.Org = null; + eSym.Lface = null; + eSym.winding = 0; + eSym.activeRegion = null; + + return mesh; + } + + +/* __gl_meshUnion( mesh1, mesh2 ) forms the union of all structures in + * both meshes, and returns the new mesh (the old meshes are destroyed). + */ + static jogamp.opengl.glu.tessellator.GLUmesh __gl_meshUnion(jogamp.opengl.glu.tessellator.GLUmesh mesh1, jogamp.opengl.glu.tessellator.GLUmesh mesh2) { + jogamp.opengl.glu.tessellator.GLUface f1 = mesh1.fHead; + jogamp.opengl.glu.tessellator.GLUvertex v1 = mesh1.vHead; + jogamp.opengl.glu.tessellator.GLUhalfEdge e1 = mesh1.eHead; + jogamp.opengl.glu.tessellator.GLUface f2 = mesh2.fHead; + jogamp.opengl.glu.tessellator.GLUvertex v2 = mesh2.vHead; + jogamp.opengl.glu.tessellator.GLUhalfEdge e2 = mesh2.eHead; + + /* Add the faces, vertices, and edges of mesh2 to those of mesh1 */ + if (f2.next != f2) { + f1.prev.next = f2.next; + f2.next.prev = f1.prev; + f2.prev.next = f1; + f1.prev = f2.prev; + } + + if (v2.next != v2) { + v1.prev.next = v2.next; + v2.next.prev = v1.prev; + v2.prev.next = v1; + v1.prev = v2.prev; + } + + if (e2.next != e2) { + e1.Sym.next.Sym.next = e2.next; + e2.next.Sym.next = e1.Sym.next; + e2.Sym.next.Sym.next = e1; + e1.Sym.next = e2.Sym.next; + } + + return mesh1; + } + + +/* __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh. + */ + static void __gl_meshDeleteMeshZap(jogamp.opengl.glu.tessellator.GLUmesh mesh) { + jogamp.opengl.glu.tessellator.GLUface fHead = mesh.fHead; + + while (fHead.next != fHead) { + __gl_meshZapFace(fHead.next); + } + assert (mesh.vHead.next == mesh.vHead); + } + +/* __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh. + */ + public static void __gl_meshDeleteMesh(jogamp.opengl.glu.tessellator.GLUmesh mesh) { + jogamp.opengl.glu.tessellator.GLUface f, fNext; + jogamp.opengl.glu.tessellator.GLUvertex v, vNext; + jogamp.opengl.glu.tessellator.GLUhalfEdge e, eNext; + + for (f = mesh.fHead.next; f != mesh.fHead; f = fNext) { + fNext = f.next; + } + + for (v = mesh.vHead.next; v != mesh.vHead; v = vNext) { + vNext = v.next; + } + + for (e = mesh.eHead.next; e != mesh.eHead; e = eNext) { + /* One call frees both e and e.Sym (see EdgePair above) */ + eNext = e.next; + } + } + +/* __gl_meshCheckMesh( mesh ) checks a mesh for self-consistency. + */ + public static void __gl_meshCheckMesh(jogamp.opengl.glu.tessellator.GLUmesh mesh) { + jogamp.opengl.glu.tessellator.GLUface fHead = mesh.fHead; + jogamp.opengl.glu.tessellator.GLUvertex vHead = mesh.vHead; + jogamp.opengl.glu.tessellator.GLUhalfEdge eHead = mesh.eHead; + jogamp.opengl.glu.tessellator.GLUface f, fPrev; + jogamp.opengl.glu.tessellator.GLUvertex v, vPrev; + jogamp.opengl.glu.tessellator.GLUhalfEdge e, ePrev; + + fPrev = fHead; + for (fPrev = fHead; (f = fPrev.next) != fHead; fPrev = f) { + assert (f.prev == fPrev); + e = f.anEdge; + do { + assert (e.Sym != e); + assert (e.Sym.Sym == e); + assert (e.Lnext.Onext.Sym == e); + assert (e.Onext.Sym.Lnext == e); + assert (e.Lface == f); + e = e.Lnext; + } while (e != f.anEdge); + } + assert (f.prev == fPrev && f.anEdge == null && f.data == null); + + vPrev = vHead; + for (vPrev = vHead; (v = vPrev.next) != vHead; vPrev = v) { + assert (v.prev == vPrev); + e = v.anEdge; + do { + assert (e.Sym != e); + assert (e.Sym.Sym == e); + assert (e.Lnext.Onext.Sym == e); + assert (e.Onext.Sym.Lnext == e); + assert (e.Org == v); + e = e.Onext; + } while (e != v.anEdge); + } + assert (v.prev == vPrev && v.anEdge == null && v.data == null); + + ePrev = eHead; + for (ePrev = eHead; (e = ePrev.next) != eHead; ePrev = e) { + assert (e.Sym.next == ePrev.Sym); + assert (e.Sym != e); + assert (e.Sym.Sym == e); + assert (e.Org != null); + assert (e.Sym.Org != null); + assert (e.Lnext.Onext.Sym == e); + assert (e.Onext.Sym.Lnext == e); + } + assert (e.Sym.next == ePrev.Sym + && e.Sym == mesh.eHeadSym + && e.Sym.Sym == e + && e.Org == null && e.Sym.Org == null + && e.Lface == null && e.Sym.Lface == null); + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/Normal.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Normal.java new file mode 100644 index 000000000..7d5acd9f8 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Normal.java @@ -0,0 +1,288 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; + +class Normal { + private Normal() { + } + + static boolean SLANTED_SWEEP = false; + static double S_UNIT_X; /* Pre-normalized */ + static double S_UNIT_Y; + private static final boolean TRUE_PROJECT = false; + + static { + if (SLANTED_SWEEP) { +/* The "feature merging" is not intended to be complete. There are + * special cases where edges are nearly parallel to the sweep line + * which are not implemented. The algorithm should still behave + * robustly (ie. produce a reasonable tesselation) in the presence + * of such edges, however it may miss features which could have been + * merged. We could minimize this effect by choosing the sweep line + * direction to be something unusual (ie. not parallel to one of the + * coordinate axes). + */ + S_UNIT_X = 0.50941539564955385; /* Pre-normalized */ + S_UNIT_Y = 0.86052074622010633; + } else { + S_UNIT_X = 1.0; + S_UNIT_Y = 0.0; + } + } + + private static double Dot(double[] u, double[] v) { + return (u[0] * v[0] + u[1] * v[1] + u[2] * v[2]); + } + + static void Normalize(double[] v) { + double len = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; + + assert (len > 0); + len = Math.sqrt(len); + v[0] /= len; + v[1] /= len; + v[2] /= len; + } + + static int LongAxis(double[] v) { + int i = 0; + + if (Math.abs(v[1]) > Math.abs(v[0])) { + i = 1; + } + if (Math.abs(v[2]) > Math.abs(v[i])) { + i = 2; + } + return i; + } + + static void ComputeNormal(GLUtessellatorImpl tess, double[] norm) { + jogamp.opengl.glu.tessellator.GLUvertex v, v1, v2; + double c, tLen2, maxLen2; + double[] maxVal, minVal, d1, d2, tNorm; + jogamp.opengl.glu.tessellator.GLUvertex[] maxVert, minVert; + jogamp.opengl.glu.tessellator.GLUvertex vHead = tess.mesh.vHead; + int i; + + maxVal = new double[3]; + minVal = new double[3]; + minVert = new jogamp.opengl.glu.tessellator.GLUvertex[3]; + maxVert = new jogamp.opengl.glu.tessellator.GLUvertex[3]; + d1 = new double[3]; + d2 = new double[3]; + tNorm = new double[3]; + + maxVal[0] = maxVal[1] = maxVal[2] = -2 * GLU.GLU_TESS_MAX_COORD; + minVal[0] = minVal[1] = minVal[2] = 2 * GLU.GLU_TESS_MAX_COORD; + + for (v = vHead.next; v != vHead; v = v.next) { + for (i = 0; i < 3; ++i) { + c = v.coords[i]; + if (c < minVal[i]) { + minVal[i] = c; + minVert[i] = v; + } + if (c > maxVal[i]) { + maxVal[i] = c; + maxVert[i] = v; + } + } + } + +/* Find two vertices separated by at least 1/sqrt(3) of the maximum + * distance between any two vertices + */ + i = 0; + if (maxVal[1] - minVal[1] > maxVal[0] - minVal[0]) { + i = 1; + } + if (maxVal[2] - minVal[2] > maxVal[i] - minVal[i]) { + i = 2; + } + if (minVal[i] >= maxVal[i]) { +/* All vertices are the same -- normal doesn't matter */ + norm[0] = 0; + norm[1] = 0; + norm[2] = 1; + return; + } + +/* Look for a third vertex which forms the triangle with maximum area + * (Length of normal == twice the triangle area) + */ + maxLen2 = 0; + v1 = minVert[i]; + v2 = maxVert[i]; + d1[0] = v1.coords[0] - v2.coords[0]; + d1[1] = v1.coords[1] - v2.coords[1]; + d1[2] = v1.coords[2] - v2.coords[2]; + for (v = vHead.next; v != vHead; v = v.next) { + d2[0] = v.coords[0] - v2.coords[0]; + d2[1] = v.coords[1] - v2.coords[1]; + d2[2] = v.coords[2] - v2.coords[2]; + tNorm[0] = d1[1] * d2[2] - d1[2] * d2[1]; + tNorm[1] = d1[2] * d2[0] - d1[0] * d2[2]; + tNorm[2] = d1[0] * d2[1] - d1[1] * d2[0]; + tLen2 = tNorm[0] * tNorm[0] + tNorm[1] * tNorm[1] + tNorm[2] * tNorm[2]; + if (tLen2 > maxLen2) { + maxLen2 = tLen2; + norm[0] = tNorm[0]; + norm[1] = tNorm[1]; + norm[2] = tNorm[2]; + } + } + + if (maxLen2 <= 0) { +/* All points lie on a single line -- any decent normal will do */ + norm[0] = norm[1] = norm[2] = 0; + norm[LongAxis(d1)] = 1; + } + } + + static void CheckOrientation(GLUtessellatorImpl tess) { + double area; + jogamp.opengl.glu.tessellator.GLUface f, fHead = tess.mesh.fHead; + jogamp.opengl.glu.tessellator.GLUvertex v, vHead = tess.mesh.vHead; + jogamp.opengl.glu.tessellator.GLUhalfEdge e; + +/* When we compute the normal automatically, we choose the orientation + * so that the the sum of the signed areas of all contours is non-negative. + */ + area = 0; + for (f = fHead.next; f != fHead; f = f.next) { + e = f.anEdge; + if (e.winding <= 0) continue; + do { + area += (e.Org.s - e.Sym.Org.s) * (e.Org.t + e.Sym.Org.t); + e = e.Lnext; + } while (e != f.anEdge); + } + if (area < 0) { +/* Reverse the orientation by flipping all the t-coordinates */ + for (v = vHead.next; v != vHead; v = v.next) { + v.t = -v.t; + } + tess.tUnit[0] = -tess.tUnit[0]; + tess.tUnit[1] = -tess.tUnit[1]; + tess.tUnit[2] = -tess.tUnit[2]; + } + } + +/* Determine the polygon normal and project vertices onto the plane + * of the polygon. + */ + public static void __gl_projectPolygon(GLUtessellatorImpl tess) { + jogamp.opengl.glu.tessellator.GLUvertex v, vHead = tess.mesh.vHead; + double w; + double[] norm = new double[3]; + double[] sUnit, tUnit; + int i; + boolean computedNormal = false; + + norm[0] = tess.normal[0]; + norm[1] = tess.normal[1]; + norm[2] = tess.normal[2]; + if (norm[0] == 0 && norm[1] == 0 && norm[2] == 0) { + ComputeNormal(tess, norm); + computedNormal = true; + } + sUnit = tess.sUnit; + tUnit = tess.tUnit; + i = LongAxis(norm); + + if (TRUE_PROJECT) { +/* Choose the initial sUnit vector to be approximately perpendicular + * to the normal. + */ + Normalize(norm); + + sUnit[i] = 0; + sUnit[(i + 1) % 3] = S_UNIT_X; + sUnit[(i + 2) % 3] = S_UNIT_Y; + +/* Now make it exactly perpendicular */ + w = Dot(sUnit, norm); + sUnit[0] -= w * norm[0]; + sUnit[1] -= w * norm[1]; + sUnit[2] -= w * norm[2]; + Normalize(sUnit); + +/* Choose tUnit so that (sUnit,tUnit,norm) form a right-handed frame */ + tUnit[0] = norm[1] * sUnit[2] - norm[2] * sUnit[1]; + tUnit[1] = norm[2] * sUnit[0] - norm[0] * sUnit[2]; + tUnit[2] = norm[0] * sUnit[1] - norm[1] * sUnit[0]; + Normalize(tUnit); + } else { +/* Project perpendicular to a coordinate axis -- better numerically */ + sUnit[i] = 0; + sUnit[(i + 1) % 3] = S_UNIT_X; + sUnit[(i + 2) % 3] = S_UNIT_Y; + + tUnit[i] = 0; + tUnit[(i + 1) % 3] = (norm[i] > 0) ? -S_UNIT_Y : S_UNIT_Y; + tUnit[(i + 2) % 3] = (norm[i] > 0) ? S_UNIT_X : -S_UNIT_X; + } + +/* Project the vertices onto the sweep plane */ + for (v = vHead.next; v != vHead; v = v.next) { + v.s = Dot(v.coords, sUnit); + v.t = Dot(v.coords, tUnit); + } + if (computedNormal) { + CheckOrientation(tess); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQ.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQ.java new file mode 100644 index 000000000..25405ad64 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQ.java @@ -0,0 +1,100 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +abstract class PriorityQ { + public static final int INIT_SIZE = 32; + + public static class PQnode { + int handle; + } + + public static class PQhandleElem { + Object key; + int node; + } + + public static interface Leq { + boolean leq(Object key1, Object key2); + } + + // #ifdef FOR_TRITE_TEST_PROGRAM +// private static boolean LEQ(PriorityQCommon.Leq leq, Object x,Object y) { +// return pq.leq.leq(x,y); +// } +// #else +/* Violates modularity, but a little faster */ +// #include "geom.h" + public static boolean LEQ(Leq leq, Object x, Object y) { + return jogamp.opengl.glu.tessellator.Geom.VertLeq((jogamp.opengl.glu.tessellator.GLUvertex) x, (jogamp.opengl.glu.tessellator.GLUvertex) y); + } + + static PriorityQ pqNewPriorityQ(Leq leq) { + return new PriorityQSort(leq); + } + + abstract void pqDeletePriorityQ(); + + abstract boolean pqInit(); + + abstract int pqInsert(Object keyNew); + + abstract Object pqExtractMin(); + + abstract void pqDelete(int hCurr); + + abstract Object pqMinimum(); + + abstract boolean pqIsEmpty(); +// #endif +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQHeap.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQHeap.java new file mode 100644 index 000000000..899df2e3d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQHeap.java @@ -0,0 +1,262 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class PriorityQHeap extends jogamp.opengl.glu.tessellator.PriorityQ { + jogamp.opengl.glu.tessellator.PriorityQ.PQnode[] nodes; + jogamp.opengl.glu.tessellator.PriorityQ.PQhandleElem[] handles; + int size, max; + int freeList; + boolean initialized; + jogamp.opengl.glu.tessellator.PriorityQ.Leq leq; + +/* really __gl_pqHeapNewPriorityQ */ + public PriorityQHeap(jogamp.opengl.glu.tessellator.PriorityQ.Leq leq) { + size = 0; + max = jogamp.opengl.glu.tessellator.PriorityQ.INIT_SIZE; + nodes = new jogamp.opengl.glu.tessellator.PriorityQ.PQnode[jogamp.opengl.glu.tessellator.PriorityQ.INIT_SIZE + 1]; + for (int i = 0; i < nodes.length; i++) { + nodes[i] = new PQnode(); + } + handles = new jogamp.opengl.glu.tessellator.PriorityQ.PQhandleElem[jogamp.opengl.glu.tessellator.PriorityQ.INIT_SIZE + 1]; + for (int i = 0; i < handles.length; i++) { + handles[i] = new PQhandleElem(); + } + initialized = false; + freeList = 0; + this.leq = leq; + + nodes[1].handle = 1; /* so that Minimum() returns NULL */ + handles[1].key = null; + } + +/* really __gl_pqHeapDeletePriorityQ */ + void pqDeletePriorityQ() { + handles = null; + nodes = null; + } + + void FloatDown(int curr) { + jogamp.opengl.glu.tessellator.PriorityQ.PQnode[] n = nodes; + jogamp.opengl.glu.tessellator.PriorityQ.PQhandleElem[] h = handles; + int hCurr, hChild; + int child; + + hCurr = n[curr].handle; + for (; ;) { + child = curr << 1; + if (child < size && LEQ(leq, h[n[child + 1].handle].key, + h[n[child].handle].key)) { + ++child; + } + + assert (child <= max); + + hChild = n[child].handle; + if (child > size || LEQ(leq, h[hCurr].key, h[hChild].key)) { + n[curr].handle = hCurr; + h[hCurr].node = curr; + break; + } + n[curr].handle = hChild; + h[hChild].node = curr; + curr = child; + } + } + + + void FloatUp(int curr) { + jogamp.opengl.glu.tessellator.PriorityQ.PQnode[] n = nodes; + jogamp.opengl.glu.tessellator.PriorityQ.PQhandleElem[] h = handles; + int hCurr, hParent; + int parent; + + hCurr = n[curr].handle; + for (; ;) { + parent = curr >> 1; + hParent = n[parent].handle; + if (parent == 0 || LEQ(leq, h[hParent].key, h[hCurr].key)) { + n[curr].handle = hCurr; + h[hCurr].node = curr; + break; + } + n[curr].handle = hParent; + h[hParent].node = curr; + curr = parent; + } + } + +/* really __gl_pqHeapInit */ + boolean pqInit() { + int i; + + /* This method of building a heap is O(n), rather than O(n lg n). */ + + for (i = size; i >= 1; --i) { + FloatDown(i); + } + initialized = true; + + return true; + } + +/* really __gl_pqHeapInsert */ +/* returns LONG_MAX iff out of memory */ + int pqInsert(Object keyNew) { + int curr; + int free; + + curr = ++size; + if ((curr * 2) > max) { + jogamp.opengl.glu.tessellator.PriorityQ.PQnode[] saveNodes = nodes; + jogamp.opengl.glu.tessellator.PriorityQ.PQhandleElem[] saveHandles = handles; + + /* If the heap overflows, double its size. */ + max <<= 1; +// pq->nodes = (PQnode *)memRealloc( pq->nodes, (size_t) ((pq->max + 1) * sizeof( pq->nodes[0] ))); + PriorityQ.PQnode[] pqNodes = new PriorityQ.PQnode[max + 1]; + System.arraycopy( nodes, 0, pqNodes, 0, nodes.length ); + for (int i = nodes.length; i < pqNodes.length; i++) { + pqNodes[i] = new PQnode(); + } + nodes = pqNodes; + if (nodes == null) { + nodes = saveNodes; /* restore ptr to free upon return */ + return Integer.MAX_VALUE; + } + +// pq->handles = (PQhandleElem *)memRealloc( pq->handles,(size_t)((pq->max + 1) * sizeof( pq->handles[0] ))); + PriorityQ.PQhandleElem[] pqHandles = new PriorityQ.PQhandleElem[max + 1]; + System.arraycopy( handles, 0, pqHandles, 0, handles.length ); + for (int i = handles.length; i < pqHandles.length; i++) { + pqHandles[i] = new PQhandleElem(); + } + handles = pqHandles; + if (handles == null) { + handles = saveHandles; /* restore ptr to free upon return */ + return Integer.MAX_VALUE; + } + } + + if (freeList == 0) { + free = curr; + } else { + free = freeList; + freeList = handles[free].node; + } + + nodes[curr].handle = free; + handles[free].node = curr; + handles[free].key = keyNew; + + if (initialized) { + FloatUp(curr); + } + assert (free != Integer.MAX_VALUE); + return free; + } + +/* really __gl_pqHeapExtractMin */ + Object pqExtractMin() { + jogamp.opengl.glu.tessellator.PriorityQ.PQnode[] n = nodes; + jogamp.opengl.glu.tessellator.PriorityQ.PQhandleElem[] h = handles; + int hMin = n[1].handle; + Object min = h[hMin].key; + + if (size > 0) { + n[1].handle = n[size].handle; + h[n[1].handle].node = 1; + + h[hMin].key = null; + h[hMin].node = freeList; + freeList = hMin; + + if (--size > 0) { + FloatDown(1); + } + } + return min; + } + +/* really __gl_pqHeapDelete */ + void pqDelete(int hCurr) { + jogamp.opengl.glu.tessellator.PriorityQ.PQnode[] n = nodes; + jogamp.opengl.glu.tessellator.PriorityQ.PQhandleElem[] h = handles; + int curr; + + assert (hCurr >= 1 && hCurr <= max && h[hCurr].key != null); + + curr = h[hCurr].node; + n[curr].handle = n[size].handle; + h[n[curr].handle].node = curr; + + if (curr <= --size) { + if (curr <= 1 || LEQ(leq, h[n[curr >> 1].handle].key, h[n[curr].handle].key)) { + FloatDown(curr); + } else { + FloatUp(curr); + } + } + h[hCurr].key = null; + h[hCurr].node = freeList; + freeList = hCurr; + } + + Object pqMinimum() { + return handles[nodes[1].handle].key; + } + + boolean pqIsEmpty() { + return size == 0; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQSort.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQSort.java new file mode 100644 index 000000000..f37f98ace --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQSort.java @@ -0,0 +1,278 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class PriorityQSort extends jogamp.opengl.glu.tessellator.PriorityQ { + jogamp.opengl.glu.tessellator.PriorityQHeap heap; + Object[] keys; + + // JAVA: 'order' contains indices into the keys array. + // This simulates the indirect pointers used in the original C code + // (from Frank Suykens, Luciad.com). + int[] order; + int size, max; + boolean initialized; + jogamp.opengl.glu.tessellator.PriorityQ.Leq leq; + + public PriorityQSort(jogamp.opengl.glu.tessellator.PriorityQ.Leq leq) { + heap = new jogamp.opengl.glu.tessellator.PriorityQHeap(leq); + + keys = new Object[jogamp.opengl.glu.tessellator.PriorityQ.INIT_SIZE]; + + size = 0; + max = jogamp.opengl.glu.tessellator.PriorityQ.INIT_SIZE; + initialized = false; + this.leq = leq; + } + +/* really __gl_pqSortDeletePriorityQ */ + void pqDeletePriorityQ() { + if (heap != null) heap.pqDeletePriorityQ(); + order = null; + keys = null; + } + + private static boolean LT(jogamp.opengl.glu.tessellator.PriorityQ.Leq leq, Object x, Object y) { + return (!jogamp.opengl.glu.tessellator.PriorityQHeap.LEQ(leq, y, x)); + } + + private static boolean GT(jogamp.opengl.glu.tessellator.PriorityQ.Leq leq, Object x, Object y) { + return (!jogamp.opengl.glu.tessellator.PriorityQHeap.LEQ(leq, x, y)); + } + + private static void Swap(int[] array, int a, int b) { + if (true) { + int tmp = array[a]; + array[a] = array[b]; + array[b] = tmp; + } else { + + } + } + + private static class Stack { + int p, r; + } + +/* really __gl_pqSortInit */ + boolean pqInit() { + int p, r, i, j; + int piv; + Stack[] stack = new Stack[50]; + for (int k = 0; k < stack.length; k++) { + stack[k] = new Stack(); + } + int top = 0; + + int seed = 2016473283; + + /* Create an array of indirect pointers to the keys, so that we + * the handles we have returned are still valid. + */ + order = new int[size + 1]; +/* the previous line is a patch to compensate for the fact that IBM */ +/* machines return a null on a malloc of zero bytes (unlike SGI), */ +/* so we have to put in this defense to guard against a memory */ +/* fault four lines down. from [email protected]. */ + p = 0; + r = size - 1; + for (piv = 0, i = p; i <= r; ++piv, ++i) { + // indirect pointers: keep an index into the keys array, not a direct pointer to its contents + order[i] = piv; + } + + /* Sort the indirect pointers in descending order, + * using randomized Quicksort + */ + stack[top].p = p; + stack[top].r = r; + ++top; + while (--top >= 0) { + p = stack[top].p; + r = stack[top].r; + while (r > p + 10) { + seed = Math.abs( seed * 1539415821 + 1 ); + i = p + seed % (r - p + 1); + piv = order[i]; + order[i] = order[p]; + order[p] = piv; + i = p - 1; + j = r + 1; + do { + do { + ++i; + } while (GT(leq, keys[order[i]], keys[piv])); + do { + --j; + } while (LT(leq, keys[order[j]], keys[piv])); + Swap(order, i, j); + } while (i < j); + Swap(order, i, j); /* Undo last swap */ + if (i - p < r - j) { + stack[top].p = j + 1; + stack[top].r = r; + ++top; + r = i - 1; + } else { + stack[top].p = p; + stack[top].r = i - 1; + ++top; + p = j + 1; + } + } + /* Insertion sort small lists */ + for (i = p + 1; i <= r; ++i) { + piv = order[i]; + for (j = i; j > p && LT(leq, keys[order[j - 1]], keys[piv]); --j) { + order[j] = order[j - 1]; + } + order[j] = piv; + } + } + max = size; + initialized = true; + heap.pqInit(); /* always succeeds */ + +/* #ifndef NDEBUG + p = order; + r = p + size - 1; + for (i = p; i < r; ++i) { + Assertion.doAssert(LEQ( * * (i + 1), **i )); + } + #endif*/ + + return true; + } + +/* really __gl_pqSortInsert */ +/* returns LONG_MAX iff out of memory */ + int pqInsert(Object keyNew) { + int curr; + + if (initialized) { + return heap.pqInsert(keyNew); + } + curr = size; + if (++size >= max) { + Object[] saveKey = keys; + + /* If the heap overflows, double its size. */ + max <<= 1; +// pq->keys = (PQHeapKey *)memRealloc( pq->keys,(size_t)(pq->max * sizeof( pq->keys[0] ))); + Object[] pqKeys = new Object[max]; + System.arraycopy( keys, 0, pqKeys, 0, keys.length ); + keys = pqKeys; + if (keys == null) { + keys = saveKey; /* restore ptr to free upon return */ + return Integer.MAX_VALUE; + } + } + assert curr != Integer.MAX_VALUE; + keys[curr] = keyNew; + + /* Negative handles index the sorted array. */ + return -(curr + 1); + } + +/* really __gl_pqSortExtractMin */ + Object pqExtractMin() { + Object sortMin, heapMin; + + if (size == 0) { + return heap.pqExtractMin(); + } + sortMin = keys[order[size - 1]]; + if (!heap.pqIsEmpty()) { + heapMin = heap.pqMinimum(); + if (LEQ(leq, heapMin, sortMin)) { + return heap.pqExtractMin(); + } + } + do { + --size; + } while (size > 0 && keys[order[size - 1]] == null); + return sortMin; + } + +/* really __gl_pqSortMinimum */ + Object pqMinimum() { + Object sortMin, heapMin; + + if (size == 0) { + return heap.pqMinimum(); + } + sortMin = keys[order[size - 1]]; + if (!heap.pqIsEmpty()) { + heapMin = heap.pqMinimum(); + if (jogamp.opengl.glu.tessellator.PriorityQHeap.LEQ(leq, heapMin, sortMin)) { + return heapMin; + } + } + return sortMin; + } + +/* really __gl_pqSortIsEmpty */ + boolean pqIsEmpty() { + return (size == 0) && heap.pqIsEmpty(); + } + +/* really __gl_pqSortDelete */ + void pqDelete(int curr) { + if (curr >= 0) { + heap.pqDelete(curr); + return; + } + curr = -(curr + 1); + assert curr < max && keys[curr] != null; + + keys[curr] = null; + while (size > 0 && keys[order[size - 1]] == null) { + --size; + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/Render.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Render.java new file mode 100644 index 000000000..34b7ee55b --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Render.java @@ -0,0 +1,557 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; + +class Render { + private static final boolean USE_OPTIMIZED_CODE_PATH = false; + + private Render() { + } + + private static final RenderFan renderFan = new RenderFan(); + private static final RenderStrip renderStrip = new RenderStrip(); + private static final RenderTriangle renderTriangle = new RenderTriangle(); + +/* This structure remembers the information we need about a primitive + * to be able to render it later, once we have determined which + * primitive is able to use the most triangles. + */ + private static class FaceCount { + public FaceCount() { + } + + public FaceCount(long size, jogamp.opengl.glu.tessellator.GLUhalfEdge eStart, renderCallBack render) { + this.size = size; + this.eStart = eStart; + this.render = render; + } + + long size; /* number of triangles used */ + jogamp.opengl.glu.tessellator.GLUhalfEdge eStart; /* edge where this primitive starts */ + renderCallBack render; + }; + + private static interface renderCallBack { + void render(GLUtessellatorImpl tess, jogamp.opengl.glu.tessellator.GLUhalfEdge e, long size); + } + + /************************ Strips and Fans decomposition ******************/ + +/* __gl_renderMesh( tess, mesh ) takes a mesh and breaks it into triangle + * fans, strips, and separate triangles. A substantial effort is made + * to use as few rendering primitives as possible (ie. to make the fans + * and strips as large as possible). + * + * The rendering output is provided as callbacks (see the api). + */ + public static void __gl_renderMesh(GLUtessellatorImpl tess, jogamp.opengl.glu.tessellator.GLUmesh mesh) { + jogamp.opengl.glu.tessellator.GLUface f; + + /* Make a list of separate triangles so we can render them all at once */ + tess.lonelyTriList = null; + + for (f = mesh.fHead.next; f != mesh.fHead; f = f.next) { + f.marked = false; + } + for (f = mesh.fHead.next; f != mesh.fHead; f = f.next) { + + /* We examine all faces in an arbitrary order. Whenever we find + * an unprocessed face F, we output a group of faces including F + * whose size is maximum. + */ + if (f.inside && !f.marked) { + RenderMaximumFaceGroup(tess, f); + assert (f.marked); + } + } + if (tess.lonelyTriList != null) { + RenderLonelyTriangles(tess, tess.lonelyTriList); + tess.lonelyTriList = null; + } + } + + + static void RenderMaximumFaceGroup(GLUtessellatorImpl tess, jogamp.opengl.glu.tessellator.GLUface fOrig) { + /* We want to find the largest triangle fan or strip of unmarked faces + * which includes the given face fOrig. There are 3 possible fans + * passing through fOrig (one centered at each vertex), and 3 possible + * strips (one for each CCW permutation of the vertices). Our strategy + * is to try all of these, and take the primitive which uses the most + * triangles (a greedy approach). + */ + jogamp.opengl.glu.tessellator.GLUhalfEdge e = fOrig.anEdge; + FaceCount max = new FaceCount(); + FaceCount newFace = new FaceCount(); + + max.size = 1; + max.eStart = e; + max.render = renderTriangle; + + if (!tess.flagBoundary) { + newFace = MaximumFan(e); + if (newFace.size > max.size) { + max = newFace; + } + newFace = MaximumFan(e.Lnext); + if (newFace.size > max.size) { + max = newFace; + } + newFace = MaximumFan(e.Onext.Sym); + if (newFace.size > max.size) { + max = newFace; + } + + newFace = MaximumStrip(e); + if (newFace.size > max.size) { + max = newFace; + } + newFace = MaximumStrip(e.Lnext); + if (newFace.size > max.size) { + max = newFace; + } + newFace = MaximumStrip(e.Onext.Sym); + if (newFace.size > max.size) { + max = newFace; + } + } + max.render.render(tess, max.eStart, max.size); + } + + +/* Macros which keep track of faces we have marked temporarily, and allow + * us to backtrack when necessary. With triangle fans, this is not + * really necessary, since the only awkward case is a loop of triangles + * around a single origin vertex. However with strips the situation is + * more complicated, and we need a general tracking method like the + * one here. + */ + private static boolean Marked(jogamp.opengl.glu.tessellator.GLUface f) { + return !f.inside || f.marked; + } + + private static GLUface AddToTrail(jogamp.opengl.glu.tessellator.GLUface f, jogamp.opengl.glu.tessellator.GLUface t) { + f.trail = t; + f.marked = true; + return f; + } + + private static void FreeTrail(jogamp.opengl.glu.tessellator.GLUface t) { + if (true) { + while (t != null) { + t.marked = false; + t = t.trail; + } + } else { + /* absorb trailing semicolon */ + } + } + + static FaceCount MaximumFan(jogamp.opengl.glu.tessellator.GLUhalfEdge eOrig) { + /* eOrig.Lface is the face we want to render. We want to find the size + * of a maximal fan around eOrig.Org. To do this we just walk around + * the origin vertex as far as possible in both directions. + */ + FaceCount newFace = new FaceCount(0, null, renderFan); + jogamp.opengl.glu.tessellator.GLUface trail = null; + jogamp.opengl.glu.tessellator.GLUhalfEdge e; + + for (e = eOrig; !Marked(e.Lface); e = e.Onext) { + trail = AddToTrail(e.Lface, trail); + ++newFace.size; + } + for (e = eOrig; !Marked(e.Sym.Lface); e = e.Sym.Lnext) { + trail = AddToTrail(e.Sym.Lface, trail); + ++newFace.size; + } + newFace.eStart = e; + /*LINTED*/ + FreeTrail(trail); + return newFace; + } + + + private static boolean IsEven(long n) { + return (n & 0x1L) == 0; + } + + static FaceCount MaximumStrip(jogamp.opengl.glu.tessellator.GLUhalfEdge eOrig) { + /* Here we are looking for a maximal strip that contains the vertices + * eOrig.Org, eOrig.Dst, eOrig.Lnext.Dst (in that order or the + * reverse, such that all triangles are oriented CCW). + * + * Again we walk forward and backward as far as possible. However for + * strips there is a twist: to get CCW orientations, there must be + * an *even* number of triangles in the strip on one side of eOrig. + * We walk the strip starting on a side with an even number of triangles; + * if both side have an odd number, we are forced to shorten one side. + */ + FaceCount newFace = new FaceCount(0, null, renderStrip); + long headSize = 0, tailSize = 0; + jogamp.opengl.glu.tessellator.GLUface trail = null; + jogamp.opengl.glu.tessellator.GLUhalfEdge e, eTail, eHead; + + for (e = eOrig; !Marked(e.Lface); ++tailSize, e = e.Onext) { + trail = AddToTrail(e.Lface, trail); + ++tailSize; + e = e.Lnext.Sym; + if (Marked(e.Lface)) break; + trail = AddToTrail(e.Lface, trail); + } + eTail = e; + + for (e = eOrig; !Marked(e.Sym.Lface); ++headSize, e = e.Sym.Onext.Sym) { + trail = AddToTrail(e.Sym.Lface, trail); + ++headSize; + e = e.Sym.Lnext; + if (Marked(e.Sym.Lface)) break; + trail = AddToTrail(e.Sym.Lface, trail); + } + eHead = e; + + newFace.size = tailSize + headSize; + if (IsEven(tailSize)) { + newFace.eStart = eTail.Sym; + } else if (IsEven(headSize)) { + newFace.eStart = eHead; + } else { + /* Both sides have odd length, we must shorten one of them. In fact, + * we must start from eHead to guarantee inclusion of eOrig.Lface. + */ + --newFace.size; + newFace.eStart = eHead.Onext; + } + /*LINTED*/ + FreeTrail(trail); + return newFace; + } + + private static class RenderTriangle implements renderCallBack { + public void render(GLUtessellatorImpl tess, jogamp.opengl.glu.tessellator.GLUhalfEdge e, long size) { + /* Just add the triangle to a triangle list, so we can render all + * the separate triangles at once. + */ + assert (size == 1); + tess.lonelyTriList = AddToTrail(e.Lface, tess.lonelyTriList); + } + } + + + static void RenderLonelyTriangles(GLUtessellatorImpl tess, jogamp.opengl.glu.tessellator.GLUface f) { + /* Now we render all the separate triangles which could not be + * grouped into a triangle fan or strip. + */ + jogamp.opengl.glu.tessellator.GLUhalfEdge e; + int newState; + int edgeState = -1; /* force edge state output for first vertex */ + + tess.callBeginOrBeginData(GL.GL_TRIANGLES); + + for (; f != null; f = f.trail) { + /* Loop once for each edge (there will always be 3 edges) */ + + e = f.anEdge; + do { + if (tess.flagBoundary) { + /* Set the "edge state" to true just before we output the + * first vertex of each edge on the polygon boundary. + */ + newState = (!e.Sym.Lface.inside) ? 1 : 0; + if (edgeState != newState) { + edgeState = newState; + tess.callEdgeFlagOrEdgeFlagData( edgeState != 0); + } + } + tess.callVertexOrVertexData( e.Org.data); + + e = e.Lnext; + } while (e != f.anEdge); + } + tess.callEndOrEndData(); + } + + private static class RenderFan implements renderCallBack { + public void render(GLUtessellatorImpl tess, jogamp.opengl.glu.tessellator.GLUhalfEdge e, long size) { + /* Render as many CCW triangles as possible in a fan starting from + * edge "e". The fan *should* contain exactly "size" triangles + * (otherwise we've goofed up somewhere). + */ + tess.callBeginOrBeginData( GL.GL_TRIANGLE_FAN); + tess.callVertexOrVertexData( e.Org.data); + tess.callVertexOrVertexData( e.Sym.Org.data); + + while (!Marked(e.Lface)) { + e.Lface.marked = true; + --size; + e = e.Onext; + tess.callVertexOrVertexData( e.Sym.Org.data); + } + + assert (size == 0); + tess.callEndOrEndData(); + } + } + + private static class RenderStrip implements renderCallBack { + public void render(GLUtessellatorImpl tess, jogamp.opengl.glu.tessellator.GLUhalfEdge e, long size) { + /* Render as many CCW triangles as possible in a strip starting from + * edge "e". The strip *should* contain exactly "size" triangles + * (otherwise we've goofed up somewhere). + */ + tess.callBeginOrBeginData( GL.GL_TRIANGLE_STRIP); + tess.callVertexOrVertexData( e.Org.data); + tess.callVertexOrVertexData( e.Sym.Org.data); + + while (!Marked(e.Lface)) { + e.Lface.marked = true; + --size; + e = e.Lnext.Sym; + tess.callVertexOrVertexData( e.Org.data); + if (Marked(e.Lface)) break; + + e.Lface.marked = true; + --size; + e = e.Onext; + tess.callVertexOrVertexData( e.Sym.Org.data); + } + + assert (size == 0); + tess.callEndOrEndData(); + } + } + + /************************ Boundary contour decomposition ******************/ + +/* __gl_renderBoundary( tess, mesh ) takes a mesh, and outputs one + * contour for each face marked "inside". The rendering output is + * provided as callbacks (see the api). + */ + public static void __gl_renderBoundary(GLUtessellatorImpl tess, jogamp.opengl.glu.tessellator.GLUmesh mesh) { + jogamp.opengl.glu.tessellator.GLUface f; + jogamp.opengl.glu.tessellator.GLUhalfEdge e; + + for (f = mesh.fHead.next; f != mesh.fHead; f = f.next) { + if (f.inside) { + tess.callBeginOrBeginData( GL.GL_LINE_LOOP); + e = f.anEdge; + do { + tess.callVertexOrVertexData( e.Org.data); + e = e.Lnext; + } while (e != f.anEdge); + tess.callEndOrEndData(); + } + } + } + + + /************************ Quick-and-dirty decomposition ******************/ + + private static final int SIGN_INCONSISTENT = 2; + + static int ComputeNormal(GLUtessellatorImpl tess, double[] norm, boolean check) +/* + * If check==false, we compute the polygon normal and place it in norm[]. + * If check==true, we check that each triangle in the fan from v0 has a + * consistent orientation with respect to norm[]. If triangles are + * consistently oriented CCW, return 1; if CW, return -1; if all triangles + * are degenerate return 0; otherwise (no consistent orientation) return + * SIGN_INCONSISTENT. + */ { + jogamp.opengl.glu.tessellator.CachedVertex[] v = tess.cache; +// CachedVertex vn = v0 + tess.cacheCount; + int vn = tess.cacheCount; +// CachedVertex vc; + int vc; + double dot, xc, yc, zc, xp, yp, zp; + double[] n = new double[3]; + int sign = 0; + + /* Find the polygon normal. It is important to get a reasonable + * normal even when the polygon is self-intersecting (eg. a bowtie). + * Otherwise, the computed normal could be very tiny, but perpendicular + * to the true plane of the polygon due to numerical noise. Then all + * the triangles would appear to be degenerate and we would incorrectly + * decompose the polygon as a fan (or simply not render it at all). + * + * We use a sum-of-triangles normal algorithm rather than the more + * efficient sum-of-trapezoids method (used in CheckOrientation() + * in normal.c). This lets us explicitly reverse the signed area + * of some triangles to get a reasonable normal in the self-intersecting + * case. + */ + if (!check) { + norm[0] = norm[1] = norm[2] = 0.0; + } + + vc = 1; + xc = v[vc].coords[0] - v[0].coords[0]; + yc = v[vc].coords[1] - v[0].coords[1]; + zc = v[vc].coords[2] - v[0].coords[2]; + while (++vc < vn) { + xp = xc; + yp = yc; + zp = zc; + xc = v[vc].coords[0] - v[0].coords[0]; + yc = v[vc].coords[1] - v[0].coords[1]; + zc = v[vc].coords[2] - v[0].coords[2]; + + /* Compute (vp - v0) cross (vc - v0) */ + n[0] = yp * zc - zp * yc; + n[1] = zp * xc - xp * zc; + n[2] = xp * yc - yp * xc; + + dot = n[0] * norm[0] + n[1] * norm[1] + n[2] * norm[2]; + if (!check) { + /* Reverse the contribution of back-facing triangles to get + * a reasonable normal for self-intersecting polygons (see above) + */ + if (dot >= 0) { + norm[0] += n[0]; + norm[1] += n[1]; + norm[2] += n[2]; + } else { + norm[0] -= n[0]; + norm[1] -= n[1]; + norm[2] -= n[2]; + } + } else if (dot != 0) { + /* Check the new orientation for consistency with previous triangles */ + if (dot > 0) { + if (sign < 0) return SIGN_INCONSISTENT; + sign = 1; + } else { + if (sign > 0) return SIGN_INCONSISTENT; + sign = -1; + } + } + } + return sign; + } + +/* __gl_renderCache( tess ) takes a single contour and tries to render it + * as a triangle fan. This handles convex polygons, as well as some + * non-convex polygons if we get lucky. + * + * Returns true if the polygon was successfully rendered. The rendering + * output is provided as callbacks (see the api). + */ + public static boolean __gl_renderCache(GLUtessellatorImpl tess) { + jogamp.opengl.glu.tessellator.CachedVertex[] v = tess.cache; +// CachedVertex vn = v0 + tess.cacheCount; + int vn = tess.cacheCount; +// CachedVertex vc; + int vc; + double[] norm = new double[3]; + int sign; + + if (tess.cacheCount < 3) { + /* Degenerate contour -- no output */ + return true; + } + + norm[0] = tess.normal[0]; + norm[1] = tess.normal[1]; + norm[2] = tess.normal[2]; + if (norm[0] == 0 && norm[1] == 0 && norm[2] == 0) { + ComputeNormal( tess, norm, false); + } + + sign = ComputeNormal( tess, norm, true); + if (sign == SIGN_INCONSISTENT) { + /* Fan triangles did not have a consistent orientation */ + return false; + } + if (sign == 0) { + /* All triangles were degenerate */ + return true; + } + + if ( !USE_OPTIMIZED_CODE_PATH ) { + return false; + } else { + /* Make sure we do the right thing for each winding rule */ + switch (tess.windingRule) { + case GLU.GLU_TESS_WINDING_ODD: + case GLU.GLU_TESS_WINDING_NONZERO: + break; + case GLU.GLU_TESS_WINDING_POSITIVE: + if (sign < 0) return true; + break; + case GLU.GLU_TESS_WINDING_NEGATIVE: + if (sign > 0) return true; + break; + case GLU.GLU_TESS_WINDING_ABS_GEQ_TWO: + return true; + } + + tess.callBeginOrBeginData( tess.boundaryOnly ? GL.GL_LINE_LOOP + : (tess.cacheCount > 3) ? GL.GL_TRIANGLE_FAN + : GL.GL_TRIANGLES); + + tess.callVertexOrVertexData( v[0].data); + if (sign > 0) { + for (vc = 1; vc < vn; ++vc) { + tess.callVertexOrVertexData( v[vc].data); + } + } else { + for (vc = vn - 1; vc > 0; --vc) { + tess.callVertexOrVertexData( v[vc].data); + } + } + tess.callEndOrEndData(); + return true; + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/Sweep.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Sweep.java new file mode 100644 index 000000000..95eb5dda1 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Sweep.java @@ -0,0 +1,1353 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; + +class Sweep { + private Sweep() { + } + +// #ifdef FOR_TRITE_TEST_PROGRAM +// extern void DebugEvent( GLUtessellator *tess ); +// #else + private static void DebugEvent(GLUtessellatorImpl tess) { + + } +// #endif + +/* + * Invariants for the Edge Dictionary. + * - each pair of adjacent edges e2=Succ(e1) satisfies EdgeLeq(e1,e2) + * at any valid location of the sweep event + * - if EdgeLeq(e2,e1) as well (at any valid sweep event), then e1 and e2 + * share a common endpoint + * - for each e, e.Dst has been processed, but not e.Org + * - each edge e satisfies VertLeq(e.Dst,event) && VertLeq(event,e.Org) + * where "event" is the current sweep line event. + * - no edge e has zero length + * + * Invariants for the Mesh (the processed portion). + * - the portion of the mesh left of the sweep line is a planar graph, + * ie. there is *some* way to embed it in the plane + * - no processed edge has zero length + * - no two processed vertices have identical coordinates + * - each "inside" region is monotone, ie. can be broken into two chains + * of monotonically increasing vertices according to VertLeq(v1,v2) + * - a non-invariant: these chains may intersect (very slightly) + * + * Invariants for the Sweep. + * - if none of the edges incident to the event vertex have an activeRegion + * (ie. none of these edges are in the edge dictionary), then the vertex + * has only right-going edges. + * - if an edge is marked "fixUpperEdge" (it is a temporary edge introduced + * by ConnectRightVertex), then it is the only right-going edge from + * its associated vertex. (This says that these edges exist only + * when it is necessary.) + */ + +/* When we merge two edges into one, we need to compute the combined + * winding of the new edge. + */ + private static void AddWinding(GLUhalfEdge eDst, GLUhalfEdge eSrc) { + eDst.winding += eSrc.winding; + eDst.Sym.winding += eSrc.Sym.winding; + } + + + private static ActiveRegion RegionBelow(ActiveRegion r) { + return ((ActiveRegion) Dict.dictKey(Dict.dictPred(r.nodeUp))); + } + + private static ActiveRegion RegionAbove(ActiveRegion r) { + return ((ActiveRegion) Dict.dictKey(Dict.dictSucc(r.nodeUp))); + } + + static boolean EdgeLeq(GLUtessellatorImpl tess, ActiveRegion reg1, ActiveRegion reg2) +/* + * Both edges must be directed from right to left (this is the canonical + * direction for the upper edge of each region). + * + * The strategy is to evaluate a "t" value for each edge at the + * current sweep line position, given by tess.event. The calculations + * are designed to be very stable, but of course they are not perfect. + * + * Special case: if both edge destinations are at the sweep event, + * we sort the edges by slope (they would otherwise compare equally). + */ { + GLUvertex event = tess.event; + GLUhalfEdge e1, e2; + double t1, t2; + + e1 = reg1.eUp; + e2 = reg2.eUp; + + if (e1.Sym.Org == event) { + if (e2.Sym.Org == event) { + /* Two edges right of the sweep line which meet at the sweep event. + * Sort them by slope. + */ + if (Geom.VertLeq(e1.Org, e2.Org)) { + return Geom.EdgeSign(e2.Sym.Org, e1.Org, e2.Org) <= 0; + } + return Geom.EdgeSign(e1.Sym.Org, e2.Org, e1.Org) >= 0; + } + return Geom.EdgeSign(e2.Sym.Org, event, e2.Org) <= 0; + } + if (e2.Sym.Org == event) { + return Geom.EdgeSign(e1.Sym.Org, event, e1.Org) >= 0; + } + + /* General case - compute signed distance *from* e1, e2 to event */ + t1 = Geom.EdgeEval(e1.Sym.Org, event, e1.Org); + t2 = Geom.EdgeEval(e2.Sym.Org, event, e2.Org); + return (t1 >= t2); + } + + + static void DeleteRegion(GLUtessellatorImpl tess, ActiveRegion reg) { + if (reg.fixUpperEdge) { + /* It was created with zero winding number, so it better be + * deleted with zero winding number (ie. it better not get merged + * with a real edge). + */ + assert (reg.eUp.winding == 0); + } + reg.eUp.activeRegion = null; + Dict.dictDelete(tess.dict, reg.nodeUp); /* __gl_dictListDelete */ + } + + + static boolean FixUpperEdge(ActiveRegion reg, GLUhalfEdge newEdge) +/* + * Replace an upper edge which needs fixing (see ConnectRightVertex). + */ { + assert (reg.fixUpperEdge); + if (!Mesh.__gl_meshDelete(reg.eUp)) return false; + reg.fixUpperEdge = false; + reg.eUp = newEdge; + newEdge.activeRegion = reg; + + return true; + } + + static ActiveRegion TopLeftRegion(ActiveRegion reg) { + GLUvertex org = reg.eUp.Org; + GLUhalfEdge e; + + /* Find the region above the uppermost edge with the same origin */ + do { + reg = RegionAbove(reg); + } while (reg.eUp.Org == org); + + /* If the edge above was a temporary edge introduced by ConnectRightVertex, + * now is the time to fix it. + */ + if (reg.fixUpperEdge) { + e = Mesh.__gl_meshConnect(RegionBelow(reg).eUp.Sym, reg.eUp.Lnext); + if (e == null) return null; + if (!FixUpperEdge(reg, e)) return null; + reg = RegionAbove(reg); + } + return reg; + } + + static ActiveRegion TopRightRegion(ActiveRegion reg) { + GLUvertex dst = reg.eUp.Sym.Org; + + /* Find the region above the uppermost edge with the same destination */ + do { + reg = RegionAbove(reg); + } while (reg.eUp.Sym.Org == dst); + return reg; + } + + static ActiveRegion AddRegionBelow(GLUtessellatorImpl tess, + ActiveRegion regAbove, + GLUhalfEdge eNewUp) +/* + * Add a new active region to the sweep line, *somewhere* below "regAbove" + * (according to where the new edge belongs in the sweep-line dictionary). + * The upper edge of the new region will be "eNewUp". + * Winding number and "inside" flag are not updated. + */ { + ActiveRegion regNew = new ActiveRegion(); + if (regNew == null) throw new RuntimeException(); + + regNew.eUp = eNewUp; + /* __gl_dictListInsertBefore */ + regNew.nodeUp = Dict.dictInsertBefore(tess.dict, regAbove.nodeUp, regNew); + if (regNew.nodeUp == null) throw new RuntimeException(); + regNew.fixUpperEdge = false; + regNew.sentinel = false; + regNew.dirty = false; + + eNewUp.activeRegion = regNew; + return regNew; + } + + static boolean IsWindingInside(GLUtessellatorImpl tess, int n) { + switch (tess.windingRule) { + case GLU.GLU_TESS_WINDING_ODD: + return (n & 1) != 0; + case GLU.GLU_TESS_WINDING_NONZERO: + return (n != 0); + case GLU.GLU_TESS_WINDING_POSITIVE: + return (n > 0); + case GLU.GLU_TESS_WINDING_NEGATIVE: + return (n < 0); + case GLU.GLU_TESS_WINDING_ABS_GEQ_TWO: + return (n >= 2) || (n <= -2); + } + /*LINTED*/ +// assert (false); + throw new InternalError(); + /*NOTREACHED*/ + } + + + static void ComputeWinding(GLUtessellatorImpl tess, ActiveRegion reg) { + reg.windingNumber = RegionAbove(reg).windingNumber + reg.eUp.winding; + reg.inside = IsWindingInside(tess, reg.windingNumber); + } + + + static void FinishRegion(GLUtessellatorImpl tess, ActiveRegion reg) +/* + * Delete a region from the sweep line. This happens when the upper + * and lower chains of a region meet (at a vertex on the sweep line). + * The "inside" flag is copied to the appropriate mesh face (we could + * not do this before -- since the structure of the mesh is always + * changing, this face may not have even existed until now). + */ { + GLUhalfEdge e = reg.eUp; + GLUface f = e.Lface; + + f.inside = reg.inside; + f.anEdge = e; /* optimization for __gl_meshTessellateMonoRegion() */ + DeleteRegion(tess, reg); + } + + + static GLUhalfEdge FinishLeftRegions(GLUtessellatorImpl tess, + ActiveRegion regFirst, ActiveRegion regLast) +/* + * We are given a vertex with one or more left-going edges. All affected + * edges should be in the edge dictionary. Starting at regFirst.eUp, + * we walk down deleting all regions where both edges have the same + * origin vOrg. At the same time we copy the "inside" flag from the + * active region to the face, since at this point each face will belong + * to at most one region (this was not necessarily true until this point + * in the sweep). The walk stops at the region above regLast; if regLast + * is null we walk as far as possible. At the same time we relink the + * mesh if necessary, so that the ordering of edges around vOrg is the + * same as in the dictionary. + */ { + ActiveRegion reg, regPrev; + GLUhalfEdge e, ePrev; + + regPrev = regFirst; + ePrev = regFirst.eUp; + while (regPrev != regLast) { + regPrev.fixUpperEdge = false; /* placement was OK */ + reg = RegionBelow(regPrev); + e = reg.eUp; + if (e.Org != ePrev.Org) { + if (!reg.fixUpperEdge) { + /* Remove the last left-going edge. Even though there are no further + * edges in the dictionary with this origin, there may be further + * such edges in the mesh (if we are adding left edges to a vertex + * that has already been processed). Thus it is important to call + * FinishRegion rather than just DeleteRegion. + */ + FinishRegion(tess, regPrev); + break; + } + /* If the edge below was a temporary edge introduced by + * ConnectRightVertex, now is the time to fix it. + */ + e = Mesh.__gl_meshConnect(ePrev.Onext.Sym, e.Sym); + if (e == null) throw new RuntimeException(); + if (!FixUpperEdge(reg, e)) throw new RuntimeException(); + } + + /* Relink edges so that ePrev.Onext == e */ + if (ePrev.Onext != e) { + if (!Mesh.__gl_meshSplice(e.Sym.Lnext, e)) throw new RuntimeException(); + if (!Mesh.__gl_meshSplice(ePrev, e)) throw new RuntimeException(); + } + FinishRegion(tess, regPrev); /* may change reg.eUp */ + ePrev = reg.eUp; + regPrev = reg; + } + return ePrev; + } + + + static void AddRightEdges(GLUtessellatorImpl tess, ActiveRegion regUp, + GLUhalfEdge eFirst, GLUhalfEdge eLast, GLUhalfEdge eTopLeft, + boolean cleanUp) +/* + * Purpose: insert right-going edges into the edge dictionary, and update + * winding numbers and mesh connectivity appropriately. All right-going + * edges share a common origin vOrg. Edges are inserted CCW starting at + * eFirst; the last edge inserted is eLast.Sym.Lnext. If vOrg has any + * left-going edges already processed, then eTopLeft must be the edge + * such that an imaginary upward vertical segment from vOrg would be + * contained between eTopLeft.Sym.Lnext and eTopLeft; otherwise eTopLeft + * should be null. + */ { + ActiveRegion reg, regPrev; + GLUhalfEdge e, ePrev; + boolean firstTime = true; + + /* Insert the new right-going edges in the dictionary */ + e = eFirst; + do { + assert (Geom.VertLeq(e.Org, e.Sym.Org)); + AddRegionBelow(tess, regUp, e.Sym); + e = e.Onext; + } while (e != eLast); + + /* Walk *all* right-going edges from e.Org, in the dictionary order, + * updating the winding numbers of each region, and re-linking the mesh + * edges to match the dictionary ordering (if necessary). + */ + if (eTopLeft == null) { + eTopLeft = RegionBelow(regUp).eUp.Sym.Onext; + } + regPrev = regUp; + ePrev = eTopLeft; + for (; ;) { + reg = RegionBelow(regPrev); + e = reg.eUp.Sym; + if (e.Org != ePrev.Org) break; + + if (e.Onext != ePrev) { + /* Unlink e from its current position, and relink below ePrev */ + if (!Mesh.__gl_meshSplice(e.Sym.Lnext, e)) throw new RuntimeException(); + if (!Mesh.__gl_meshSplice(ePrev.Sym.Lnext, e)) throw new RuntimeException(); + } + /* Compute the winding number and "inside" flag for the new regions */ + reg.windingNumber = regPrev.windingNumber - e.winding; + reg.inside = IsWindingInside(tess, reg.windingNumber); + + /* Check for two outgoing edges with same slope -- process these + * before any intersection tests (see example in __gl_computeInterior). + */ + regPrev.dirty = true; + if (!firstTime && CheckForRightSplice(tess, regPrev)) { + AddWinding(e, ePrev); + DeleteRegion(tess, regPrev); + if (!Mesh.__gl_meshDelete(ePrev)) throw new RuntimeException(); + } + firstTime = false; + regPrev = reg; + ePrev = e; + } + regPrev.dirty = true; + assert (regPrev.windingNumber - e.winding == reg.windingNumber); + + if (cleanUp) { + /* Check for intersections between newly adjacent edges. */ + WalkDirtyRegions(tess, regPrev); + } + } + + + static void CallCombine(GLUtessellatorImpl tess, GLUvertex isect, + Object[] data, float[] weights, boolean needed) { + double[] coords = new double[3]; + + /* Copy coord data in case the callback changes it. */ + coords[0] = isect.coords[0]; + coords[1] = isect.coords[1]; + coords[2] = isect.coords[2]; + + Object[] outData = new Object[1]; + tess.callCombineOrCombineData(coords, data, weights, outData); + isect.data = outData[0]; + if (isect.data == null) { + if (!needed) { + isect.data = data[0]; + } else if (!tess.fatalError) { + /* The only way fatal error is when two edges are found to intersect, + * but the user has not provided the callback necessary to handle + * generated intersection points. + */ + tess.callErrorOrErrorData(GLU.GLU_TESS_NEED_COMBINE_CALLBACK); + tess.fatalError = true; + } + } + } + + static void SpliceMergeVertices(GLUtessellatorImpl tess, GLUhalfEdge e1, + GLUhalfEdge e2) +/* + * Two vertices with idential coordinates are combined into one. + * e1.Org is kept, while e2.Org is discarded. + */ { + Object[] data = new Object[4]; + float[] weights = new float[]{0.5f, 0.5f, 0.0f, 0.0f}; + + data[0] = e1.Org.data; + data[1] = e2.Org.data; + CallCombine(tess, e1.Org, data, weights, false); + if (!Mesh.__gl_meshSplice(e1, e2)) throw new RuntimeException(); + } + + static void VertexWeights(GLUvertex isect, GLUvertex org, GLUvertex dst, + float[] weights) +/* + * Find some weights which describe how the intersection vertex is + * a linear combination of "org" and "dest". Each of the two edges + * which generated "isect" is allocated 50% of the weight; each edge + * splits the weight between its org and dst according to the + * relative distance to "isect". + */ { + double t1 = Geom.VertL1dist(org, isect); + double t2 = Geom.VertL1dist(dst, isect); + + weights[0] = (float) (0.5 * t2 / (t1 + t2)); + weights[1] = (float) (0.5 * t1 / (t1 + t2)); + isect.coords[0] += weights[0] * org.coords[0] + weights[1] * dst.coords[0]; + isect.coords[1] += weights[0] * org.coords[1] + weights[1] * dst.coords[1]; + isect.coords[2] += weights[0] * org.coords[2] + weights[1] * dst.coords[2]; + } + + + static void GetIntersectData(GLUtessellatorImpl tess, GLUvertex isect, + GLUvertex orgUp, GLUvertex dstUp, + GLUvertex orgLo, GLUvertex dstLo) +/* + * We've computed a new intersection point, now we need a "data" pointer + * from the user so that we can refer to this new vertex in the + * rendering callbacks. + */ { + Object[] data = new Object[4]; + float[] weights = new float[4]; + float[] weights1 = new float[2]; + float[] weights2 = new float[2]; + + data[0] = orgUp.data; + data[1] = dstUp.data; + data[2] = orgLo.data; + data[3] = dstLo.data; + + isect.coords[0] = isect.coords[1] = isect.coords[2] = 0; + VertexWeights(isect, orgUp, dstUp, weights1); + VertexWeights(isect, orgLo, dstLo, weights2); + System.arraycopy(weights1, 0, weights, 0, 2); + System.arraycopy(weights2, 0, weights, 2, 2); + + CallCombine(tess, isect, data, weights, true); + } + + static boolean CheckForRightSplice(GLUtessellatorImpl tess, ActiveRegion regUp) +/* + * Check the upper and lower edge of "regUp", to make sure that the + * eUp.Org is above eLo, or eLo.Org is below eUp (depending on which + * origin is leftmost). + * + * The main purpose is to splice right-going edges with the same + * dest vertex and nearly identical slopes (ie. we can't distinguish + * the slopes numerically). However the splicing can also help us + * to recover from numerical errors. For example, suppose at one + * point we checked eUp and eLo, and decided that eUp.Org is barely + * above eLo. Then later, we split eLo into two edges (eg. from + * a splice operation like this one). This can change the result of + * our test so that now eUp.Org is incident to eLo, or barely below it. + * We must correct this condition to maintain the dictionary invariants. + * + * One possibility is to check these edges for intersection again + * (ie. CheckForIntersect). This is what we do if possible. However + * CheckForIntersect requires that tess.event lies between eUp and eLo, + * so that it has something to fall back on when the intersection + * calculation gives us an unusable answer. So, for those cases where + * we can't check for intersection, this routine fixes the problem + * by just splicing the offending vertex into the other edge. + * This is a guaranteed solution, no matter how degenerate things get. + * Basically this is a combinatorial solution to a numerical problem. + */ { + ActiveRegion regLo = RegionBelow(regUp); + GLUhalfEdge eUp = regUp.eUp; + GLUhalfEdge eLo = regLo.eUp; + + if (Geom.VertLeq(eUp.Org, eLo.Org)) { + if (Geom.EdgeSign(eLo.Sym.Org, eUp.Org, eLo.Org) > 0) return false; + + /* eUp.Org appears to be below eLo */ + if (!Geom.VertEq(eUp.Org, eLo.Org)) { + /* Splice eUp.Org into eLo */ + if (Mesh.__gl_meshSplitEdge(eLo.Sym) == null) throw new RuntimeException(); + if (!Mesh.__gl_meshSplice(eUp, eLo.Sym.Lnext)) throw new RuntimeException(); + regUp.dirty = regLo.dirty = true; + + } else if (eUp.Org != eLo.Org) { + /* merge the two vertices, discarding eUp.Org */ + tess.pq.pqDelete(eUp.Org.pqHandle); /* __gl_pqSortDelete */ + SpliceMergeVertices(tess, eLo.Sym.Lnext, eUp); + } + } else { + if (Geom.EdgeSign(eUp.Sym.Org, eLo.Org, eUp.Org) < 0) return false; + + /* eLo.Org appears to be above eUp, so splice eLo.Org into eUp */ + RegionAbove(regUp).dirty = regUp.dirty = true; + if (Mesh.__gl_meshSplitEdge(eUp.Sym) == null) throw new RuntimeException(); + if (!Mesh.__gl_meshSplice(eLo.Sym.Lnext, eUp)) throw new RuntimeException(); + } + return true; + } + + static boolean CheckForLeftSplice(GLUtessellatorImpl tess, ActiveRegion regUp) +/* + * Check the upper and lower edge of "regUp", to make sure that the + * eUp.Sym.Org is above eLo, or eLo.Sym.Org is below eUp (depending on which + * destination is rightmost). + * + * Theoretically, this should always be true. However, splitting an edge + * into two pieces can change the results of previous tests. For example, + * suppose at one point we checked eUp and eLo, and decided that eUp.Sym.Org + * is barely above eLo. Then later, we split eLo into two edges (eg. from + * a splice operation like this one). This can change the result of + * the test so that now eUp.Sym.Org is incident to eLo, or barely below it. + * We must correct this condition to maintain the dictionary invariants + * (otherwise new edges might get inserted in the wrong place in the + * dictionary, and bad stuff will happen). + * + * We fix the problem by just splicing the offending vertex into the + * other edge. + */ { + ActiveRegion regLo = RegionBelow(regUp); + GLUhalfEdge eUp = regUp.eUp; + GLUhalfEdge eLo = regLo.eUp; + GLUhalfEdge e; + + assert (!Geom.VertEq(eUp.Sym.Org, eLo.Sym.Org)); + + if (Geom.VertLeq(eUp.Sym.Org, eLo.Sym.Org)) { + if (Geom.EdgeSign(eUp.Sym.Org, eLo.Sym.Org, eUp.Org) < 0) return false; + + /* eLo.Sym.Org is above eUp, so splice eLo.Sym.Org into eUp */ + RegionAbove(regUp).dirty = regUp.dirty = true; + e = Mesh.__gl_meshSplitEdge(eUp); + if (e == null) throw new RuntimeException(); + if (!Mesh.__gl_meshSplice(eLo.Sym, e)) throw new RuntimeException(); + e.Lface.inside = regUp.inside; + } else { + if (Geom.EdgeSign(eLo.Sym.Org, eUp.Sym.Org, eLo.Org) > 0) return false; + + /* eUp.Sym.Org is below eLo, so splice eUp.Sym.Org into eLo */ + regUp.dirty = regLo.dirty = true; + e = Mesh.__gl_meshSplitEdge(eLo); + if (e == null) throw new RuntimeException(); + if (!Mesh.__gl_meshSplice(eUp.Lnext, eLo.Sym)) throw new RuntimeException(); + e.Sym.Lface.inside = regUp.inside; + } + return true; + } + + + static boolean CheckForIntersect(GLUtessellatorImpl tess, ActiveRegion regUp) +/* + * Check the upper and lower edges of the given region to see if + * they intersect. If so, create the intersection and add it + * to the data structures. + * + * Returns true if adding the new intersection resulted in a recursive + * call to AddRightEdges(); in this case all "dirty" regions have been + * checked for intersections, and possibly regUp has been deleted. + */ { + ActiveRegion regLo = RegionBelow(regUp); + GLUhalfEdge eUp = regUp.eUp; + GLUhalfEdge eLo = regLo.eUp; + GLUvertex orgUp = eUp.Org; + GLUvertex orgLo = eLo.Org; + GLUvertex dstUp = eUp.Sym.Org; + GLUvertex dstLo = eLo.Sym.Org; + double tMinUp, tMaxLo; + GLUvertex isect = new GLUvertex(); + GLUvertex orgMin; + GLUhalfEdge e; + + assert (!Geom.VertEq(dstLo, dstUp)); + assert (Geom.EdgeSign(dstUp, tess.event, orgUp) <= 0); + assert (Geom.EdgeSign(dstLo, tess.event, orgLo) >= 0); + assert (orgUp != tess.event && orgLo != tess.event); + assert (!regUp.fixUpperEdge && !regLo.fixUpperEdge); + + if (orgUp == orgLo) return false; /* right endpoints are the same */ + + tMinUp = Math.min(orgUp.t, dstUp.t); + tMaxLo = Math.max(orgLo.t, dstLo.t); + if (tMinUp > tMaxLo) return false; /* t ranges do not overlap */ + + if (Geom.VertLeq(orgUp, orgLo)) { + if (Geom.EdgeSign(dstLo, orgUp, orgLo) > 0) return false; + } else { + if (Geom.EdgeSign(dstUp, orgLo, orgUp) < 0) return false; + } + + /* At this point the edges intersect, at least marginally */ + DebugEvent(tess); + + Geom.EdgeIntersect(dstUp, orgUp, dstLo, orgLo, isect); + /* The following properties are guaranteed: */ + assert (Math.min(orgUp.t, dstUp.t) <= isect.t); + assert (isect.t <= Math.max(orgLo.t, dstLo.t)); + assert (Math.min(dstLo.s, dstUp.s) <= isect.s); + assert (isect.s <= Math.max(orgLo.s, orgUp.s)); + + if (Geom.VertLeq(isect, tess.event)) { + /* The intersection point lies slightly to the left of the sweep line, + * so move it until it''s slightly to the right of the sweep line. + * (If we had perfect numerical precision, this would never happen + * in the first place). The easiest and safest thing to do is + * replace the intersection by tess.event. + */ + isect.s = tess.event.s; + isect.t = tess.event.t; + } + /* Similarly, if the computed intersection lies to the right of the + * rightmost origin (which should rarely happen), it can cause + * unbelievable inefficiency on sufficiently degenerate inputs. + * (If you have the test program, try running test54.d with the + * "X zoom" option turned on). + */ + orgMin = Geom.VertLeq(orgUp, orgLo) ? orgUp : orgLo; + if (Geom.VertLeq(orgMin, isect)) { + isect.s = orgMin.s; + isect.t = orgMin.t; + } + + if (Geom.VertEq(isect, orgUp) || Geom.VertEq(isect, orgLo)) { + /* Easy case -- intersection at one of the right endpoints */ + CheckForRightSplice(tess, regUp); + return false; + } + + if ((!Geom.VertEq(dstUp, tess.event) + && Geom.EdgeSign(dstUp, tess.event, isect) >= 0) + || (!Geom.VertEq(dstLo, tess.event) + && Geom.EdgeSign(dstLo, tess.event, isect) <= 0)) { + /* Very unusual -- the new upper or lower edge would pass on the + * wrong side of the sweep event, or through it. This can happen + * due to very small numerical errors in the intersection calculation. + */ + if (dstLo == tess.event) { + /* Splice dstLo into eUp, and process the new region(s) */ + if (Mesh.__gl_meshSplitEdge(eUp.Sym) == null) throw new RuntimeException(); + if (!Mesh.__gl_meshSplice(eLo.Sym, eUp)) throw new RuntimeException(); + regUp = TopLeftRegion(regUp); + if (regUp == null) throw new RuntimeException(); + eUp = RegionBelow(regUp).eUp; + FinishLeftRegions(tess, RegionBelow(regUp), regLo); + AddRightEdges(tess, regUp, eUp.Sym.Lnext, eUp, eUp, true); + return true; + } + if (dstUp == tess.event) { + /* Splice dstUp into eLo, and process the new region(s) */ + if (Mesh.__gl_meshSplitEdge(eLo.Sym) == null) throw new RuntimeException(); + if (!Mesh.__gl_meshSplice(eUp.Lnext, eLo.Sym.Lnext)) throw new RuntimeException(); + regLo = regUp; + regUp = TopRightRegion(regUp); + e = RegionBelow(regUp).eUp.Sym.Onext; + regLo.eUp = eLo.Sym.Lnext; + eLo = FinishLeftRegions(tess, regLo, null); + AddRightEdges(tess, regUp, eLo.Onext, eUp.Sym.Onext, e, true); + return true; + } + /* Special case: called from ConnectRightVertex. If either + * edge passes on the wrong side of tess.event, split it + * (and wait for ConnectRightVertex to splice it appropriately). + */ + if (Geom.EdgeSign(dstUp, tess.event, isect) >= 0) { + RegionAbove(regUp).dirty = regUp.dirty = true; + if (Mesh.__gl_meshSplitEdge(eUp.Sym) == null) throw new RuntimeException(); + eUp.Org.s = tess.event.s; + eUp.Org.t = tess.event.t; + } + if (Geom.EdgeSign(dstLo, tess.event, isect) <= 0) { + regUp.dirty = regLo.dirty = true; + if (Mesh.__gl_meshSplitEdge(eLo.Sym) == null) throw new RuntimeException(); + eLo.Org.s = tess.event.s; + eLo.Org.t = tess.event.t; + } + /* leave the rest for ConnectRightVertex */ + return false; + } + + /* General case -- split both edges, splice into new vertex. + * When we do the splice operation, the order of the arguments is + * arbitrary as far as correctness goes. However, when the operation + * creates a new face, the work done is proportional to the size of + * the new face. We expect the faces in the processed part of + * the mesh (ie. eUp.Lface) to be smaller than the faces in the + * unprocessed original contours (which will be eLo.Sym.Lnext.Lface). + */ + if (Mesh.__gl_meshSplitEdge(eUp.Sym) == null) throw new RuntimeException(); + if (Mesh.__gl_meshSplitEdge(eLo.Sym) == null) throw new RuntimeException(); + if (!Mesh.__gl_meshSplice(eLo.Sym.Lnext, eUp)) throw new RuntimeException(); + eUp.Org.s = isect.s; + eUp.Org.t = isect.t; + eUp.Org.pqHandle = tess.pq.pqInsert(eUp.Org); /* __gl_pqSortInsert */ + if (eUp.Org.pqHandle == Long.MAX_VALUE) { + tess.pq.pqDeletePriorityQ(); /* __gl_pqSortDeletePriorityQ */ + tess.pq = null; + throw new RuntimeException(); + } + GetIntersectData(tess, eUp.Org, orgUp, dstUp, orgLo, dstLo); + RegionAbove(regUp).dirty = regUp.dirty = regLo.dirty = true; + return false; + } + + static void WalkDirtyRegions(GLUtessellatorImpl tess, ActiveRegion regUp) +/* + * When the upper or lower edge of any region changes, the region is + * marked "dirty". This routine walks through all the dirty regions + * and makes sure that the dictionary invariants are satisfied + * (see the comments at the beginning of this file). Of course + * new dirty regions can be created as we make changes to restore + * the invariants. + */ { + ActiveRegion regLo = RegionBelow(regUp); + GLUhalfEdge eUp, eLo; + + for (; ;) { + /* Find the lowest dirty region (we walk from the bottom up). */ + while (regLo.dirty) { + regUp = regLo; + regLo = RegionBelow(regLo); + } + if (!regUp.dirty) { + regLo = regUp; + regUp = RegionAbove(regUp); + if (regUp == null || !regUp.dirty) { + /* We've walked all the dirty regions */ + return; + } + } + regUp.dirty = false; + eUp = regUp.eUp; + eLo = regLo.eUp; + + if (eUp.Sym.Org != eLo.Sym.Org) { + /* Check that the edge ordering is obeyed at the Dst vertices. */ + if (CheckForLeftSplice(tess, regUp)) { + + /* If the upper or lower edge was marked fixUpperEdge, then + * we no longer need it (since these edges are needed only for + * vertices which otherwise have no right-going edges). + */ + if (regLo.fixUpperEdge) { + DeleteRegion(tess, regLo); + if (!Mesh.__gl_meshDelete(eLo)) throw new RuntimeException(); + regLo = RegionBelow(regUp); + eLo = regLo.eUp; + } else if (regUp.fixUpperEdge) { + DeleteRegion(tess, regUp); + if (!Mesh.__gl_meshDelete(eUp)) throw new RuntimeException(); + regUp = RegionAbove(regLo); + eUp = regUp.eUp; + } + } + } + if (eUp.Org != eLo.Org) { + if (eUp.Sym.Org != eLo.Sym.Org + && !regUp.fixUpperEdge && !regLo.fixUpperEdge + && (eUp.Sym.Org == tess.event || eLo.Sym.Org == tess.event)) { + /* When all else fails in CheckForIntersect(), it uses tess.event + * as the intersection location. To make this possible, it requires + * that tess.event lie between the upper and lower edges, and also + * that neither of these is marked fixUpperEdge (since in the worst + * case it might splice one of these edges into tess.event, and + * violate the invariant that fixable edges are the only right-going + * edge from their associated vertex). + */ + if (CheckForIntersect(tess, regUp)) { + /* WalkDirtyRegions() was called recursively; we're done */ + return; + } + } else { + /* Even though we can't use CheckForIntersect(), the Org vertices + * may violate the dictionary edge ordering. Check and correct this. + */ + CheckForRightSplice(tess, regUp); + } + } + if (eUp.Org == eLo.Org && eUp.Sym.Org == eLo.Sym.Org) { + /* A degenerate loop consisting of only two edges -- delete it. */ + AddWinding(eLo, eUp); + DeleteRegion(tess, regUp); + if (!Mesh.__gl_meshDelete(eUp)) throw new RuntimeException(); + regUp = RegionAbove(regLo); + } + } + } + + + static void ConnectRightVertex(GLUtessellatorImpl tess, ActiveRegion regUp, + GLUhalfEdge eBottomLeft) +/* + * Purpose: connect a "right" vertex vEvent (one where all edges go left) + * to the unprocessed portion of the mesh. Since there are no right-going + * edges, two regions (one above vEvent and one below) are being merged + * into one. "regUp" is the upper of these two regions. + * + * There are two reasons for doing this (adding a right-going edge): + * - if the two regions being merged are "inside", we must add an edge + * to keep them separated (the combined region would not be monotone). + * - in any case, we must leave some record of vEvent in the dictionary, + * so that we can merge vEvent with features that we have not seen yet. + * For example, maybe there is a vertical edge which passes just to + * the right of vEvent; we would like to splice vEvent into this edge. + * + * However, we don't want to connect vEvent to just any vertex. We don''t + * want the new edge to cross any other edges; otherwise we will create + * intersection vertices even when the input data had no self-intersections. + * (This is a bad thing; if the user's input data has no intersections, + * we don't want to generate any false intersections ourselves.) + * + * Our eventual goal is to connect vEvent to the leftmost unprocessed + * vertex of the combined region (the union of regUp and regLo). + * But because of unseen vertices with all right-going edges, and also + * new vertices which may be created by edge intersections, we don''t + * know where that leftmost unprocessed vertex is. In the meantime, we + * connect vEvent to the closest vertex of either chain, and mark the region + * as "fixUpperEdge". This flag says to delete and reconnect this edge + * to the next processed vertex on the boundary of the combined region. + * Quite possibly the vertex we connected to will turn out to be the + * closest one, in which case we won''t need to make any changes. + */ { + GLUhalfEdge eNew; + GLUhalfEdge eTopLeft = eBottomLeft.Onext; + ActiveRegion regLo = RegionBelow(regUp); + GLUhalfEdge eUp = regUp.eUp; + GLUhalfEdge eLo = regLo.eUp; + boolean degenerate = false; + + if (eUp.Sym.Org != eLo.Sym.Org) { + CheckForIntersect(tess, regUp); + } + + /* Possible new degeneracies: upper or lower edge of regUp may pass + * through vEvent, or may coincide with new intersection vertex + */ + if (Geom.VertEq(eUp.Org, tess.event)) { + if (!Mesh.__gl_meshSplice(eTopLeft.Sym.Lnext, eUp)) throw new RuntimeException(); + regUp = TopLeftRegion(regUp); + if (regUp == null) throw new RuntimeException(); + eTopLeft = RegionBelow(regUp).eUp; + FinishLeftRegions(tess, RegionBelow(regUp), regLo); + degenerate = true; + } + if (Geom.VertEq(eLo.Org, tess.event)) { + if (!Mesh.__gl_meshSplice(eBottomLeft, eLo.Sym.Lnext)) throw new RuntimeException(); + eBottomLeft = FinishLeftRegions(tess, regLo, null); + degenerate = true; + } + if (degenerate) { + AddRightEdges(tess, regUp, eBottomLeft.Onext, eTopLeft, eTopLeft, true); + return; + } + + /* Non-degenerate situation -- need to add a temporary, fixable edge. + * Connect to the closer of eLo.Org, eUp.Org. + */ + if (Geom.VertLeq(eLo.Org, eUp.Org)) { + eNew = eLo.Sym.Lnext; + } else { + eNew = eUp; + } + eNew = Mesh.__gl_meshConnect(eBottomLeft.Onext.Sym, eNew); + if (eNew == null) throw new RuntimeException(); + + /* Prevent cleanup, otherwise eNew might disappear before we've even + * had a chance to mark it as a temporary edge. + */ + AddRightEdges(tess, regUp, eNew, eNew.Onext, eNew.Onext, false); + eNew.Sym.activeRegion.fixUpperEdge = true; + WalkDirtyRegions(tess, regUp); + } + +/* Because vertices at exactly the same location are merged together + * before we process the sweep event, some degenerate cases can't occur. + * However if someone eventually makes the modifications required to + * merge features which are close together, the cases below marked + * TOLERANCE_NONZERO will be useful. They were debugged before the + * code to merge identical vertices in the main loop was added. + */ + private static final boolean TOLERANCE_NONZERO = false; + + static void ConnectLeftDegenerate(GLUtessellatorImpl tess, + ActiveRegion regUp, GLUvertex vEvent) +/* + * The event vertex lies exacty on an already-processed edge or vertex. + * Adding the new vertex involves splicing it into the already-processed + * part of the mesh. + */ { + GLUhalfEdge e, eTopLeft, eTopRight, eLast; + ActiveRegion reg; + + e = regUp.eUp; + if (Geom.VertEq(e.Org, vEvent)) { + /* e.Org is an unprocessed vertex - just combine them, and wait + * for e.Org to be pulled from the queue + */ + assert (TOLERANCE_NONZERO); + SpliceMergeVertices(tess, e, vEvent.anEdge); + return; + } + + if (!Geom.VertEq(e.Sym.Org, vEvent)) { + /* General case -- splice vEvent into edge e which passes through it */ + if (Mesh.__gl_meshSplitEdge(e.Sym) == null) throw new RuntimeException(); + if (regUp.fixUpperEdge) { + /* This edge was fixable -- delete unused portion of original edge */ + if (!Mesh.__gl_meshDelete(e.Onext)) throw new RuntimeException(); + regUp.fixUpperEdge = false; + } + if (!Mesh.__gl_meshSplice(vEvent.anEdge, e)) throw new RuntimeException(); + SweepEvent(tess, vEvent); /* recurse */ + return; + } + + /* vEvent coincides with e.Sym.Org, which has already been processed. + * Splice in the additional right-going edges. + */ + assert (TOLERANCE_NONZERO); + regUp = TopRightRegion(regUp); + reg = RegionBelow(regUp); + eTopRight = reg.eUp.Sym; + eTopLeft = eLast = eTopRight.Onext; + if (reg.fixUpperEdge) { + /* Here e.Sym.Org has only a single fixable edge going right. + * We can delete it since now we have some real right-going edges. + */ + assert (eTopLeft != eTopRight); /* there are some left edges too */ + DeleteRegion(tess, reg); + if (!Mesh.__gl_meshDelete(eTopRight)) throw new RuntimeException(); + eTopRight = eTopLeft.Sym.Lnext; + } + if (!Mesh.__gl_meshSplice(vEvent.anEdge, eTopRight)) throw new RuntimeException(); + if (!Geom.EdgeGoesLeft(eTopLeft)) { + /* e.Sym.Org had no left-going edges -- indicate this to AddRightEdges() */ + eTopLeft = null; + } + AddRightEdges(tess, regUp, eTopRight.Onext, eLast, eTopLeft, true); + } + + + static void ConnectLeftVertex(GLUtessellatorImpl tess, GLUvertex vEvent) +/* + * Purpose: connect a "left" vertex (one where both edges go right) + * to the processed portion of the mesh. Let R be the active region + * containing vEvent, and let U and L be the upper and lower edge + * chains of R. There are two possibilities: + * + * - the normal case: split R into two regions, by connecting vEvent to + * the rightmost vertex of U or L lying to the left of the sweep line + * + * - the degenerate case: if vEvent is close enough to U or L, we + * merge vEvent into that edge chain. The subcases are: + * - merging with the rightmost vertex of U or L + * - merging with the active edge of U or L + * - merging with an already-processed portion of U or L + */ { + ActiveRegion regUp, regLo, reg; + GLUhalfEdge eUp, eLo, eNew; + ActiveRegion tmp = new ActiveRegion(); + + /* assert ( vEvent.anEdge.Onext.Onext == vEvent.anEdge ); */ + + /* Get a pointer to the active region containing vEvent */ + tmp.eUp = vEvent.anEdge.Sym; + /* __GL_DICTLISTKEY */ /* __gl_dictListSearch */ + regUp = (ActiveRegion) Dict.dictKey(Dict.dictSearch(tess.dict, tmp)); + regLo = RegionBelow(regUp); + eUp = regUp.eUp; + eLo = regLo.eUp; + + /* Try merging with U or L first */ + if (Geom.EdgeSign(eUp.Sym.Org, vEvent, eUp.Org) == 0) { + ConnectLeftDegenerate(tess, regUp, vEvent); + return; + } + + /* Connect vEvent to rightmost processed vertex of either chain. + * e.Sym.Org is the vertex that we will connect to vEvent. + */ + reg = Geom.VertLeq(eLo.Sym.Org, eUp.Sym.Org) ? regUp : regLo; + + if (regUp.inside || reg.fixUpperEdge) { + if (reg == regUp) { + eNew = Mesh.__gl_meshConnect(vEvent.anEdge.Sym, eUp.Lnext); + if (eNew == null) throw new RuntimeException(); + } else { + GLUhalfEdge tempHalfEdge = Mesh.__gl_meshConnect(eLo.Sym.Onext.Sym, vEvent.anEdge); + if (tempHalfEdge == null) throw new RuntimeException(); + + eNew = tempHalfEdge.Sym; + } + if (reg.fixUpperEdge) { + if (!FixUpperEdge(reg, eNew)) throw new RuntimeException(); + } else { + ComputeWinding(tess, AddRegionBelow(tess, regUp, eNew)); + } + SweepEvent(tess, vEvent); + } else { + /* The new vertex is in a region which does not belong to the polygon. + * We don''t need to connect this vertex to the rest of the mesh. + */ + AddRightEdges(tess, regUp, vEvent.anEdge, vEvent.anEdge, null, true); + } + } + + + static void SweepEvent(GLUtessellatorImpl tess, GLUvertex vEvent) +/* + * Does everything necessary when the sweep line crosses a vertex. + * Updates the mesh and the edge dictionary. + */ { + ActiveRegion regUp, reg; + GLUhalfEdge e, eTopLeft, eBottomLeft; + + tess.event = vEvent; /* for access in EdgeLeq() */ + DebugEvent(tess); + + /* Check if this vertex is the right endpoint of an edge that is + * already in the dictionary. In this case we don't need to waste + * time searching for the location to insert new edges. + */ + e = vEvent.anEdge; + while (e.activeRegion == null) { + e = e.Onext; + if (e == vEvent.anEdge) { + /* All edges go right -- not incident to any processed edges */ + ConnectLeftVertex(tess, vEvent); + return; + } + } + + /* Processing consists of two phases: first we "finish" all the + * active regions where both the upper and lower edges terminate + * at vEvent (ie. vEvent is closing off these regions). + * We mark these faces "inside" or "outside" the polygon according + * to their winding number, and delete the edges from the dictionary. + * This takes care of all the left-going edges from vEvent. + */ + regUp = TopLeftRegion(e.activeRegion); + if (regUp == null) throw new RuntimeException(); + reg = RegionBelow(regUp); + eTopLeft = reg.eUp; + eBottomLeft = FinishLeftRegions(tess, reg, null); + + /* Next we process all the right-going edges from vEvent. This + * involves adding the edges to the dictionary, and creating the + * associated "active regions" which record information about the + * regions between adjacent dictionary edges. + */ + if (eBottomLeft.Onext == eTopLeft) { + /* No right-going edges -- add a temporary "fixable" edge */ + ConnectRightVertex(tess, regUp, eBottomLeft); + } else { + AddRightEdges(tess, regUp, eBottomLeft.Onext, eTopLeft, eTopLeft, true); + } + } + + +/* Make the sentinel coordinates big enough that they will never be + * merged with real input features. (Even with the largest possible + * input contour and the maximum tolerance of 1.0, no merging will be + * done with coordinates larger than 3 * GLU_TESS_MAX_COORD). + */ + private static final double SENTINEL_COORD = (4.0 * GLU.GLU_TESS_MAX_COORD); + + static void AddSentinel(GLUtessellatorImpl tess, double t) +/* + * We add two sentinel edges above and below all other edges, + * to avoid special cases at the top and bottom. + */ { + GLUhalfEdge e; + ActiveRegion reg = new ActiveRegion(); + if (reg == null) throw new RuntimeException(); + + e = Mesh.__gl_meshMakeEdge(tess.mesh); + if (e == null) throw new RuntimeException(); + + e.Org.s = SENTINEL_COORD; + e.Org.t = t; + e.Sym.Org.s = -SENTINEL_COORD; + e.Sym.Org.t = t; + tess.event = e.Sym.Org; /* initialize it */ + + reg.eUp = e; + reg.windingNumber = 0; + reg.inside = false; + reg.fixUpperEdge = false; + reg.sentinel = true; + reg.dirty = false; + reg.nodeUp = Dict.dictInsert(tess.dict, reg); /* __gl_dictListInsertBefore */ + if (reg.nodeUp == null) throw new RuntimeException(); + } + + + static void InitEdgeDict(final GLUtessellatorImpl tess) +/* + * We maintain an ordering of edge intersections with the sweep line. + * This order is maintained in a dynamic dictionary. + */ { + /* __gl_dictListNewDict */ + tess.dict = Dict.dictNewDict(tess, new Dict.DictLeq() { + public boolean leq(Object frame, Object key1, Object key2) { + return EdgeLeq(tess, (ActiveRegion) key1, (ActiveRegion) key2); + } + }); + if (tess.dict == null) throw new RuntimeException(); + + AddSentinel(tess, -SENTINEL_COORD); + AddSentinel(tess, SENTINEL_COORD); + } + + + static void DoneEdgeDict(GLUtessellatorImpl tess) { + ActiveRegion reg; + int fixedEdges = 0; + + /* __GL_DICTLISTKEY */ /* __GL_DICTLISTMIN */ + while ((reg = (ActiveRegion) Dict.dictKey(Dict.dictMin(tess.dict))) != null) { + /* + * At the end of all processing, the dictionary should contain + * only the two sentinel edges, plus at most one "fixable" edge + * created by ConnectRightVertex(). + */ + if (!reg.sentinel) { + assert (reg.fixUpperEdge); + assert (++fixedEdges == 1); + } + assert (reg.windingNumber == 0); + DeleteRegion(tess, reg); +/* __gl_meshDelete( reg.eUp );*/ + } + Dict.dictDeleteDict(tess.dict); /* __gl_dictListDeleteDict */ + } + + + static void RemoveDegenerateEdges(GLUtessellatorImpl tess) +/* + * Remove zero-length edges, and contours with fewer than 3 vertices. + */ { + GLUhalfEdge e, eNext, eLnext; + GLUhalfEdge eHead = tess.mesh.eHead; + + /*LINTED*/ + for (e = eHead.next; e != eHead; e = eNext) { + eNext = e.next; + eLnext = e.Lnext; + + if (Geom.VertEq(e.Org, e.Sym.Org) && e.Lnext.Lnext != e) { + /* Zero-length edge, contour has at least 3 edges */ + + SpliceMergeVertices(tess, eLnext, e); /* deletes e.Org */ + if (!Mesh.__gl_meshDelete(e)) throw new RuntimeException(); /* e is a self-loop */ + e = eLnext; + eLnext = e.Lnext; + } + if (eLnext.Lnext == e) { + /* Degenerate contour (one or two edges) */ + + if (eLnext != e) { + if (eLnext == eNext || eLnext == eNext.Sym) { + eNext = eNext.next; + } + if (!Mesh.__gl_meshDelete(eLnext)) throw new RuntimeException(); + } + if (e == eNext || e == eNext.Sym) { + eNext = eNext.next; + } + if (!Mesh.__gl_meshDelete(e)) throw new RuntimeException(); + } + } + } + + static boolean InitPriorityQ(GLUtessellatorImpl tess) +/* + * Insert all vertices into the priority queue which determines the + * order in which vertices cross the sweep line. + */ { + PriorityQ pq; + GLUvertex v, vHead; + + /* __gl_pqSortNewPriorityQ */ + pq = tess.pq = PriorityQ.pqNewPriorityQ(new PriorityQ.Leq() { + public boolean leq(Object key1, Object key2) { + return Geom.VertLeq(((GLUvertex) key1), (GLUvertex) key2); + } + }); + if (pq == null) return false; + + vHead = tess.mesh.vHead; + for (v = vHead.next; v != vHead; v = v.next) { + v.pqHandle = pq.pqInsert(v); /* __gl_pqSortInsert */ + if (v.pqHandle == Long.MAX_VALUE) break; + } + if (v != vHead || !pq.pqInit()) { /* __gl_pqSortInit */ + tess.pq.pqDeletePriorityQ(); /* __gl_pqSortDeletePriorityQ */ + tess.pq = null; + return false; + } + + return true; + } + + + static void DonePriorityQ(GLUtessellatorImpl tess) { + tess.pq.pqDeletePriorityQ(); /* __gl_pqSortDeletePriorityQ */ + } + + + static boolean RemoveDegenerateFaces(GLUmesh mesh) +/* + * Delete any degenerate faces with only two edges. WalkDirtyRegions() + * will catch almost all of these, but it won't catch degenerate faces + * produced by splice operations on already-processed edges. + * The two places this can happen are in FinishLeftRegions(), when + * we splice in a "temporary" edge produced by ConnectRightVertex(), + * and in CheckForLeftSplice(), where we splice already-processed + * edges to ensure that our dictionary invariants are not violated + * by numerical errors. + * + * In both these cases it is *very* dangerous to delete the offending + * edge at the time, since one of the routines further up the stack + * will sometimes be keeping a pointer to that edge. + */ { + GLUface f, fNext; + GLUhalfEdge e; + + /*LINTED*/ + for (f = mesh.fHead.next; f != mesh.fHead; f = fNext) { + fNext = f.next; + e = f.anEdge; + assert (e.Lnext != e); + + if (e.Lnext.Lnext == e) { + /* A face with only two edges */ + AddWinding(e.Onext, e); + if (!Mesh.__gl_meshDelete(e)) return false; + } + } + return true; + } + + public static boolean __gl_computeInterior(GLUtessellatorImpl tess) +/* + * __gl_computeInterior( tess ) computes the planar arrangement specified + * by the given contours, and further subdivides this arrangement + * into regions. Each region is marked "inside" if it belongs + * to the polygon, according to the rule given by tess.windingRule. + * Each interior region is guaranteed be monotone. + */ { + GLUvertex v, vNext; + + tess.fatalError = false; + + /* Each vertex defines an event for our sweep line. Start by inserting + * all the vertices in a priority queue. Events are processed in + * lexicographic order, ie. + * + * e1 < e2 iff e1.x < e2.x || (e1.x == e2.x && e1.y < e2.y) + */ + RemoveDegenerateEdges(tess); + if (!InitPriorityQ(tess)) return false; /* if error */ + InitEdgeDict(tess); + + /* __gl_pqSortExtractMin */ + while ((v = (GLUvertex) tess.pq.pqExtractMin()) != null) { + for (; ;) { + vNext = (GLUvertex) tess.pq.pqMinimum(); /* __gl_pqSortMinimum */ + if (vNext == null || !Geom.VertEq(vNext, v)) break; + + /* Merge together all vertices at exactly the same location. + * This is more efficient than processing them one at a time, + * simplifies the code (see ConnectLeftDegenerate), and is also + * important for correct handling of certain degenerate cases. + * For example, suppose there are two identical edges A and B + * that belong to different contours (so without this code they would + * be processed by separate sweep events). Suppose another edge C + * crosses A and B from above. When A is processed, we split it + * at its intersection point with C. However this also splits C, + * so when we insert B we may compute a slightly different + * intersection point. This might leave two edges with a small + * gap between them. This kind of error is especially obvious + * when using boundary extraction (GLU_TESS_BOUNDARY_ONLY). + */ + vNext = (GLUvertex) tess.pq.pqExtractMin(); /* __gl_pqSortExtractMin*/ + SpliceMergeVertices(tess, v.anEdge, vNext.anEdge); + } + SweepEvent(tess, v); + } + + /* Set tess.event for debugging purposes */ + /* __GL_DICTLISTKEY */ /* __GL_DICTLISTMIN */ + tess.event = ((ActiveRegion) Dict.dictKey(Dict.dictMin(tess.dict))).eUp.Org; + DebugEvent(tess); + DoneEdgeDict(tess); + DonePriorityQ(tess); + + if (!RemoveDegenerateFaces(tess.mesh)) return false; + Mesh.__gl_meshCheckMesh(tess.mesh); + + return true; + } +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/TessMono.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/TessMono.java new file mode 100644 index 000000000..5db543c80 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/TessMono.java @@ -0,0 +1,241 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class TessMono { +/* __gl_meshTessellateMonoRegion( face ) tessellates a monotone region + * (what else would it do??) The region must consist of a single + * loop of half-edges (see mesh.h) oriented CCW. "Monotone" in this + * case means that any vertical line intersects the interior of the + * region in a single interval. + * + * Tessellation consists of adding interior edges (actually pairs of + * half-edges), to split the region into non-overlapping triangles. + * + * The basic idea is explained in Preparata and Shamos (which I don''t + * have handy right now), although their implementation is more + * complicated than this one. The are two edge chains, an upper chain + * and a lower chain. We process all vertices from both chains in order, + * from right to left. + * + * The algorithm ensures that the following invariant holds after each + * vertex is processed: the untessellated region consists of two + * chains, where one chain (say the upper) is a single edge, and + * the other chain is concave. The left vertex of the single edge + * is always to the left of all vertices in the concave chain. + * + * Each step consists of adding the rightmost unprocessed vertex to one + * of the two chains, and forming a fan of triangles from the rightmost + * of two chain endpoints. Determining whether we can add each triangle + * to the fan is a simple orientation test. By making the fan as large + * as possible, we restore the invariant (check it yourself). + */ + static boolean __gl_meshTessellateMonoRegion(GLUface face, boolean avoidDegenerateTris) { + GLUhalfEdge up, lo; + + /* All edges are oriented CCW around the boundary of the region. + * First, find the half-edge whose origin vertex is rightmost. + * Since the sweep goes from left to right, face->anEdge should + * be close to the edge we want. + */ + up = face.anEdge; + assert (up.Lnext != up && up.Lnext.Lnext != up); + + for (; Geom.VertLeq(up.Sym.Org, up.Org); up = up.Onext.Sym) + ; + for (; Geom.VertLeq(up.Org, up.Sym.Org); up = up.Lnext) + ; + lo = up.Onext.Sym; + + boolean mustConnect = false; // hack for avoidDegenerateTris + + while (up.Lnext != lo) { + if (avoidDegenerateTris && !mustConnect) { + // Skip over regions where several vertices are collinear, + // to try to avoid producing degenerate (zero-area) triangles + // + // The "mustConnect" flag is a hack to try to avoid + // skipping too large regions and causing incorrect + // triangulations. This entire modification is overall + // not robust and needs more work + if (Geom.EdgeCos(lo.Lnext.Org, lo.Org, lo.Lnext.Lnext.Org) <= -Geom.ONE_MINUS_EPSILON) { + // Lines around lo + do { + lo = lo.Onext.Sym; + mustConnect = true; + } while (up.Lnext != lo && + Geom.EdgeCos(lo.Lnext.Org, lo.Org, lo.Lnext.Lnext.Org) <= -Geom.ONE_MINUS_EPSILON); + } else if (Geom.EdgeCos(up.Onext.Sym.Org, up.Org, up.Onext.Sym.Onext.Sym.Org) <= -Geom.ONE_MINUS_EPSILON) { + // Lines around up + do { + up = up.Lnext; + mustConnect = true; + } while (up.Lnext != lo && + Geom.EdgeCos(up.Onext.Sym.Org, up.Org, up.Onext.Sym.Onext.Sym.Org) <= -Geom.ONE_MINUS_EPSILON); + } + + if (up.Lnext == lo) + break; + } + + if (Geom.VertLeq(up.Sym.Org, lo.Org)) { + /* up.Sym.Org is on the left. It is safe to form triangles from lo.Org. + * The EdgeGoesLeft test guarantees progress even when some triangles + * are CW, given that the upper and lower chains are truly monotone. + */ + while (lo.Lnext != up && (Geom.EdgeGoesLeft(lo.Lnext) + || Geom.EdgeSign(lo.Org, lo.Sym.Org, lo.Lnext.Sym.Org) <= 0)) { + GLUhalfEdge tempHalfEdge = Mesh.__gl_meshConnect(lo.Lnext, lo); + mustConnect = false; + if (tempHalfEdge == null) return false; + lo = tempHalfEdge.Sym; + } + lo = lo.Onext.Sym; + } else { + /* lo.Org is on the left. We can make CCW triangles from up.Sym.Org. */ + while (lo.Lnext != up && (Geom.EdgeGoesRight(up.Onext.Sym) + || Geom.EdgeSign(up.Sym.Org, up.Org, up.Onext.Sym.Org) >= 0)) { + GLUhalfEdge tempHalfEdge = Mesh.__gl_meshConnect(up, up.Onext.Sym); + mustConnect = false; + if (tempHalfEdge == null) return false; + up = tempHalfEdge.Sym; + } + up = up.Lnext; + } + } + + /* Now lo.Org == up.Sym.Org == the leftmost vertex. The remaining region + * can be tessellated in a fan from this leftmost vertex. + */ + assert (lo.Lnext != up); + while (lo.Lnext.Lnext != up) { + GLUhalfEdge tempHalfEdge = Mesh.__gl_meshConnect(lo.Lnext, lo); + if (tempHalfEdge == null) return false; + lo = tempHalfEdge.Sym; + } + + return true; + } + + +/* __gl_meshTessellateInterior( mesh ) tessellates each region of + * the mesh which is marked "inside" the polygon. Each such region + * must be monotone. + */ + public static boolean __gl_meshTessellateInterior(GLUmesh mesh, boolean avoidDegenerateTris) { + GLUface f, next; + + /*LINTED*/ + for (f = mesh.fHead.next; f != mesh.fHead; f = next) { + /* Make sure we don''t try to tessellate the new triangles. */ + next = f.next; + if (f.inside) { + if (!__gl_meshTessellateMonoRegion(f, avoidDegenerateTris)) return false; + } + } + + return true; + } + + +/* __gl_meshDiscardExterior( mesh ) zaps (ie. sets to NULL) all faces + * which are not marked "inside" the polygon. Since further mesh operations + * on NULL faces are not allowed, the main purpose is to clean up the + * mesh so that exterior loops are not represented in the data structure. + */ + public static void __gl_meshDiscardExterior(GLUmesh mesh) { + GLUface f, next; + + /*LINTED*/ + for (f = mesh.fHead.next; f != mesh.fHead; f = next) { + /* Since f will be destroyed, save its next pointer. */ + next = f.next; + if (!f.inside) { + Mesh.__gl_meshZapFace(f); + } + } + } + + private static final int MARKED_FOR_DELETION = 0x7fffffff; + +/* __gl_meshSetWindingNumber( mesh, value, keepOnlyBoundary ) resets the + * winding numbers on all edges so that regions marked "inside" the + * polygon have a winding number of "value", and regions outside + * have a winding number of 0. + * + * If keepOnlyBoundary is TRUE, it also deletes all edges which do not + * separate an interior region from an exterior one. + */ + public static boolean __gl_meshSetWindingNumber(GLUmesh mesh, int value, boolean keepOnlyBoundary) { + GLUhalfEdge e, eNext; + + for (e = mesh.eHead.next; e != mesh.eHead; e = eNext) { + eNext = e.next; + if (e.Sym.Lface.inside != e.Lface.inside) { + + /* This is a boundary edge (one side is interior, one is exterior). */ + e.winding = (e.Lface.inside) ? value : -value; + } else { + + /* Both regions are interior, or both are exterior. */ + if (!keepOnlyBoundary) { + e.winding = 0; + } else { + if (!Mesh.__gl_meshDelete(e)) return false; + } + } + } + return true; + } + +} diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/TessState.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/TessState.java new file mode 100644 index 000000000..c25de2d91 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/TessState.java @@ -0,0 +1,59 @@ +/* +* Portions Copyright (C) 2003-2006 Sun Microsystems, Inc. +* All rights reserved. +*/ + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 2.0 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** Author: Eric Veach, July 1994 +** Java Port: Pepijn Van Eeckhoudt, July 2003 +** Java Port: Nathan Parker Burg, August 2003 +*/ +package jogamp.opengl.glu.tessellator; + +class TessState { + public static final int T_DORMANT = 0; + public static final int T_IN_POLYGON = 1; + public static final int T_IN_CONTOUR = 2; +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java new file mode 100644 index 000000000..085889739 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -0,0 +1,328 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + +import java.nio.*; +import java.util.*; +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import jogamp.opengl.*; +import com.jogamp.gluegen.runtime.ProcAddressTable; +import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver; + +public abstract class MacOSXCGLContext extends GLContextImpl +{ + protected boolean isNSContext; + private CGLExt cglExt; + // Table that holds the addresses of the native C-language entry points for + // CGL extension functions. + private CGLExtProcAddressTable cglExtProcAddressTable; + + protected MacOSXCGLContext(GLDrawableImpl drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + public Object getPlatformGLExtensions() { + return getCGLExt(); + } + + protected boolean isNSContext() { return isNSContext; } + + public CGLExt getCGLExt() { + if (cglExt == null) { + cglExt = new CGLExtImpl(this); + } + return cglExt; + } + + public final ProcAddressTable getPlatformExtProcAddressTable() { + return getCGLExtProcAddressTable(); + } + + public final CGLExtProcAddressTable getCGLExtProcAddressTable() { + return cglExtProcAddressTable; + } + + protected Map/*<String, String>*/ getFunctionNameMap() { return null; } + + protected Map/*<String, String>*/ getExtensionNameMap() { return null; } + + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + return 0; // FIXME + } + + protected void destroyContextARBImpl(long _context) { + // FIXME + } + + public final boolean isGLReadDrawableAvailable() { + return false; + } + + /** + * Creates and initializes an appropriate OpenGl Context (NS). Should only be + * called by {@link makeCurrentImpl()}. + */ + protected boolean create(boolean pbuffer, boolean floatingPoint) { + MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this); + long share = 0; + if (other != null) { + if (!other.isNSContext()) { + throw new GLException("GLContextShareSet is not a NS Context"); + } + share = other.getHandle(); + if (share == 0) { + throw new GLException("GLContextShareSet returned a NULL OpenGL context"); + } + } + MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable capabilitiesRequested = (GLCapabilitiesImmutable) config.getRequestedCapabilities(); + GLProfile glProfile = capabilitiesRequested.getGLProfile(); + if(glProfile.isGL3()) { + throw new GLException("GL3 profile currently not supported on MacOSX, due to the lack of a OpenGL 3.1 implementation"); + } + // HACK .. bring in OnScreen/PBuffer selection to the DrawableFactory !! + GLCapabilities capabilities = (GLCapabilities) capabilitiesRequested.cloneMutable(); + capabilities.setPBuffer(pbuffer); + capabilities.setPbufferFloatingPointBuffers(floatingPoint); + + long pixelFormat = MacOSXCGLGraphicsConfiguration.GLCapabilities2NSPixelFormat(capabilities); + if (pixelFormat == 0) { + throw new GLException("Unable to allocate pixel format with requested GLCapabilities"); + } + config.setChosenPixelFormat(pixelFormat); + try { + int[] viewNotReady = new int[1]; + // Try to allocate a context with this + contextHandle = CGL.createContext(share, + drawable.getHandle(), + pixelFormat, + viewNotReady, 0); + if (contextHandle == 0) { + if (viewNotReady[0] == 1) { + if (DEBUG) { + System.err.println("!!! View not ready for " + getClass().getName()); + } + // View not ready at the window system level -- this is OK + return false; + } + throw new GLException("Error creating NSOpenGLContext with requested pixel format"); + } + + if (!pbuffer && !capabilities.isBackgroundOpaque()) { + // Set the context opacity + CGL.setContextOpacity(contextHandle, 0); + } + + GLCapabilitiesImmutable caps = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(glProfile, pixelFormat); + config.setChosenCapabilities(caps); + } finally { + CGL.deletePixelFormat(pixelFormat); + } + if (!CGL.makeCurrentContext(contextHandle)) { + throw new GLException("Error making Context (NS) current"); + } + isNSContext = true; + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); + GLContextShareSet.contextCreated(this); + return true; + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + if ( isNSContext ) { + if (!CGL.makeCurrentContext(contextHandle)) { + throw new GLException("Error making Context (NS) current"); + } + } else { + if (CGL.kCGLNoError != CGL.CGLSetCurrentContext(contextHandle)) { + throw new GLException("Error making Context (CGL) current"); + } + } + } + + protected void releaseImpl() throws GLException { + if ( isNSContext ) { + if (!CGL.clearCurrentContext(contextHandle)) { + throw new GLException("Error freeing OpenGL Context (NS)"); + } + } else { + CGL.CGLReleaseContext(contextHandle); + } + } + + protected void destroyImpl() throws GLException { + if ( !isNSContext ) { + if (CGL.kCGLNoError != CGL.CGLDestroyContext(contextHandle)) { + throw new GLException("Unable to delete OpenGL Context (CGL)"); + } + if (DEBUG) { + System.err.println("!!! Destroyed OpenGL Context (CGL) " + contextHandle); + } + } else { + if (!CGL.deleteContext(contextHandle)) { + throw new GLException("Unable to delete OpenGL Context (NS)"); + } + if (DEBUG) { + System.err.println("!!! Destroyed OpenGL Context (NS) " + contextHandle); + } + } + } + + protected void copyImpl(GLContext source, int mask) throws GLException { + long dst = getHandle(); + long src = source.getHandle(); + if( !isNSContext() ) { + if ( ((MacOSXCGLContext)source).isNSContext() ) { + throw new GLException("Source OpenGL Context is NS ; Destination Context is CGL."); + } + CGL.CGLCopyContext(src, dst, mask); + } else { + if ( !((MacOSXCGLContext)source).isNSContext() ) { + throw new GLException("Source OpenGL Context is CGL ; Destination Context is NS."); + } + CGL.copyContext(dst, src, mask); + } + } + + protected final void updateGLXProcAddressTable() { + AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); + String key = adevice.getUniqueID(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Initializing CGL extension address table: "+key); + } + CGLExtProcAddressTable table = null; + synchronized(mappedContextTypeObjectLock) { + table = (CGLExtProcAddressTable) mappedGLXProcAddress.get( key ); + } + if(null != table) { + cglExtProcAddressTable = table; + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext CGL ProcAddressTable reusing key("+key+") -> "+table.hashCode()); + } + } else { + if (cglExtProcAddressTable == null) { + // FIXME: cache ProcAddressTables by capability bits so we can + // share them among contexts with the same capabilities + cglExtProcAddressTable = new CGLExtProcAddressTable(new GLProcAddressResolver()); + } + resetProcAddressTable(getCGLExtProcAddressTable()); + synchronized(mappedContextTypeObjectLock) { + mappedGLXProcAddress.put(key, getCGLExtProcAddressTable()); + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext CGL ProcAddressTable mapping key("+key+") -> "+getCGLExtProcAddressTable().hashCode()); + } + } + } + } + + public String getPlatformExtensionsString() + { + return ""; + } + + protected void swapBuffers() { + DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)config.getChosenCapabilities(); + if(caps.isOnscreen()) { + if(isNSContext) { + if (!CGL.flushBuffer(contextHandle)) { + throw new GLException("Error swapping buffers (NS)"); + } + } else { + if (CGL.kCGLNoError != CGL.CGLFlushDrawable(contextHandle)) { + throw new GLException("Error swapping buffers (CGL)"); + } + } + } + } + + protected void setSwapIntervalImpl(int interval) { + if( ! isCreated() ) { + throw new GLException("OpenGL context not created"); + } + if ( isNSContext ) { + CGL.setSwapInterval(contextHandle, interval); + } else { + int[] lval = new int[] { (int) interval } ; + CGL.CGLSetParameter(contextHandle, CGL.kCGLCPSwapInterval, lval, 0); + } + currentSwapInterval = interval ; + } + + public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + // FIXME: apparently the Apple extension doesn't require a custom memory allocator + throw new GLException("Not yet implemented"); + } + + public boolean isExtensionAvailable(String glExtensionName) { + if (glExtensionName.equals("GL_ARB_pbuffer") || + glExtensionName.equals("GL_ARB_pixel_format")) { + return true; + } + return super.isExtensionAvailable(glExtensionName); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + + // Support for "mode switching" as described in MacOSXCGLDrawable + public abstract void setOpenGLMode(int mode); + public abstract int getOpenGLMode(); +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java new file mode 100644 index 000000000..10e061d3a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import jogamp.opengl.*; + +public abstract class MacOSXCGLDrawable extends GLDrawableImpl { + // The Java2D/OpenGL pipeline on OS X uses low-level CGLContextObjs + // to represent the contexts for e.g. the Java2D back buffer. When + // the Java2D/JOGL bridge is active, this means that if we want to + // be able to share textures and display lists with the Java2D + // contexts, we need to use the CGL APIs rather than the NSOpenGL + // APIs on the JOGL side. For example, if we create a pbuffer using + // the NSOpenGL APIs and want to share textures and display lists + // between it and the Java2D back buffer, there is no way to do so, + // because the Java2D context is actually a CGLContextObj and the + // NSOpenGLContext's initWithFormat:shareContext: only accepts an + // NSOpenGLContext as its second argument. Of course there is no way + // to wrap an NSOpenGLContext around an arbitrary CGLContextObj. + // + // The situation we care most about is allowing a GLPbuffer to share + // textures, etc. with a GLJPanel when the Java2D/JOGL bridge is + // active; several of the demos rely on this functionality. We aim + // to get there by allowing a GLPBuffer to switch its implementation + // between using an NSOpenGLPixelBuffer and a CGLPBufferObj. In + // order to track whether this has been done we need to have the + // notion of a "mode" of both the MacOSXCGLDrawable and the + // MacOSXGLContext. Initially the mode is "unspecified", meaning it + // leans toward the default (NSOpenGL). If sharing is requested + // between either a GLJPanel and a GLPbuffer or a GLCanvas and a + // GLPbuffer, the GLPbuffer will be switched into the appropriate + // mode: CGL mode for a GLJPanel and NSOpenGL mode for a GLCanvas. + // To avoid thrashing we support exactly one such switch during the + // lifetime of a given GLPbuffer. This is not a fully general + // solution (for example, you can't share textures among a + // GLPbuffer, a GLJPanel and a GLCanvas simultaneously) but should + // be enough to get things off the ground. + public static final int NSOPENGL_MODE = 1; + public static final int CGL_MODE = 2; + + public MacOSXCGLDrawable(GLDrawableFactory factory, NativeSurface comp, boolean realized) { + super(factory, comp, realized); + } + + protected void setRealizedImpl() { + } + + public GLDynamicLookupHelper getGLDynamicLookupHelper() { + return getFactoryImpl().getGLDynamicLookupHelper(0); + } + + protected static String getThreadName() { + return Thread.currentThread().getName(); + } + + // Support for "mode switching" as per above + public abstract void setOpenGLMode(int mode); + public abstract int getOpenGLMode(); +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java new file mode 100644 index 000000000..6ce793490 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + +import java.nio.*; +import java.util.HashMap; +import java.util.List; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.macosx.MacOSXGraphicsDevice; +import javax.media.opengl.*; + +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; +import java.util.ArrayList; +import jogamp.opengl.*; +import jogamp.nativewindow.WrappedSurface; + +public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { + private static final DesktopGLDynamicLookupHelper macOSXCGLDynamicLookupHelper; + + static { + DesktopGLDynamicLookupHelper tmp = null; + try { + tmp = new DesktopGLDynamicLookupHelper(new MacOSXCGLDynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + macOSXCGLDynamicLookupHelper = tmp; + /** FIXME ?? + if(null!=macOSXCGLDynamicLookupHelper) { + CGL.getCGLProcAddressTable().reset(macOSXCGLDynamicLookupHelper); + } */ + } + + public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { + return macOSXCGLDynamicLookupHelper; + } + + public MacOSXCGLDrawableFactory() { + super(); + + // Register our GraphicsConfigurationFactory implementations + // The act of constructing them causes them to be registered + new MacOSXCGLGraphicsConfigurationFactory(); + if(GLProfile.isAWTAvailable()) { + try { + ReflectionUtil.createInstance("jogamp.opengl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory", + null, getClass().getClassLoader()); + } catch (JogampRuntimeException jre) { /* n/a .. */ } + } + + defaultDevice = new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + } + + static class SharedResource { + private MacOSXCGLDrawable drawable; + private MacOSXCGLContext context; + + SharedResource(MacOSXCGLDrawable draw, MacOSXCGLContext ctx) { + drawable = draw; + context = ctx; + } + } + HashMap/*<connection, SharedResource>*/ sharedMap = new HashMap(); + MacOSXGraphicsDevice defaultDevice; + + public final AbstractGraphicsDevice getDefaultDevice() { + return defaultDevice; + } + + public final boolean getIsDeviceCompatible(AbstractGraphicsDevice device) { + if(device instanceof MacOSXGraphicsDevice) { + return true; + } + return false; + } + + protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { + // FIXME: not implemented .. needs a dummy OSX surface + return null; + } + + protected AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device) { + return device; // nothing to do, no native open device + } + + protected final void shutdownInstance() {} + + protected List/*GLCapabilitiesImmutable*/ getAvailableCapabilitiesImpl(AbstractGraphicsDevice device) { + return new ArrayList(0); + } + + protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + return new MacOSXOnscreenCGLDrawable(this, target); + } + + protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { + AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(!caps.isPBuffer()) { + return new MacOSXOffscreenCGLDrawable(this, target); + } + + // PBuffer GLDrawable Creation + /** + * FIXME: Think about this .. + * should not be necessary ? .. + final List returnList = new ArrayList(); + final GLDrawableFactory factory = this; + Runnable r = new Runnable() { + public void run() { + returnList.add(new MacOSXPbufferCGLDrawable(factory, target)); + } + }; + maybeDoSingleThreadedWorkaround(r); + return (GLDrawableImpl) returnList.get(0); + */ + return new MacOSXPbufferCGLDrawable(this, target); + } + + public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + return true; + } + + protected NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device,GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { + AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_MACOSX); + WrappedSurface ns = new WrappedSurface(MacOSXCGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen, true)); + ns.setSize(width, height); + return ns; + } + + protected ProxySurface createProxySurfaceImpl(AbstractGraphicsDevice device, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser) { + AbstractGraphicsScreen screen = new DefaultGraphicsScreen(device, 0); + WrappedSurface ns = new WrappedSurface(MacOSXCGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsRequested, capsRequested, chooser, screen, true), windowHandle); + return ns; + } + + protected GLContext createExternalGLContextImpl() { + return MacOSXExternalCGLContext.create(this, null); + } + + public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { + return false; + } + + protected GLDrawable createExternalGLDrawableImpl() { + // FIXME + throw new GLException("Not yet implemented"); + } + + public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { + return false; + } + + public GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) + throws GLException { + throw new GLException("not supported in non AWT enviroment"); + } + + //------------------------------------------------------ + // Gamma-related functionality + // + + private static final int GAMMA_RAMP_LENGTH = 256; + + /** Returns the length of the computed gamma ramp for this OS and + hardware. Returns 0 if gamma changes are not supported. */ + protected int getGammaRampLength() { + return GAMMA_RAMP_LENGTH; + } + + protected boolean setGammaRamp(float[] ramp) { + return CGL.setGammaRamp(ramp.length, + ramp, 0, + ramp, 0, + ramp, 0); + } + + protected Buffer getGammaRamp() { + return null; + } + + protected void resetGammaRamp(Buffer originalGammaRamp) { + CGL.resetGammaRamp(); + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDynamicLibraryBundleInfo.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDynamicLibraryBundleInfo.java new file mode 100644 index 000000000..94d790cee --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDynamicLibraryBundleInfo.java @@ -0,0 +1,72 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl.macosx.cgl; + +import jogamp.opengl.*; +import com.jogamp.common.os.DynamicLookupHelper; +import com.jogamp.common.os.NativeLibrary; +import com.jogamp.common.os.Platform; +import java.util.*; +import java.security.*; +import javax.media.opengl.GLException; + +public class MacOSXCGLDynamicLibraryBundleInfo extends DesktopGLDynamicLibraryBundleInfo { + protected MacOSXCGLDynamicLibraryBundleInfo() { + super(); + } + + public List getToolLibNames() { + List/*<List>*/ libNamesList = new ArrayList(); + + List/*<String>*/ glesLibNames = new ArrayList(); + + glesLibNames.add("/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"); + glesLibNames.add("GL"); + + libNamesList.add(glesLibNames); + + return libNamesList; + } + + public final List getToolGetProcAddressFuncNameList() { + return null; + /** OSX manual says: NSImage use is discouraged + List res = new ArrayList(); + res.add("GetProcAddress"); // dummy + return res; */ + } + + public final long toolDynamicLookupFunction(long toolGetProcAddressHandle, String funcName) { + return 0; + /** OSX manual says: NSImage use is discouraged + return CGL.getProcAddress(glFuncName); // manual implementation + */ + } +} + diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java new file mode 100644 index 000000000..0d73b6b9c --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; + +public class MacOSXCGLGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable { + long pixelformat; + + MacOSXCGLGraphicsConfiguration(AbstractGraphicsScreen screen, + GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, + long pixelformat) { + super(screen, capsChosen, capsRequested); + this.pixelformat=pixelformat; + } + + public Object clone() { + return super.clone(); + } + + void setChosenPixelFormat(long pixelformat) { + this.pixelformat=pixelformat; + } + + void setChosenCapabilities(GLCapabilitiesImmutable caps) { + super.setChosenCapabilities(caps); + } + + static final int[] cglInternalAttributeToken = new int[] { + CGL.kCGLPFAColorFloat, + CGL.NSOpenGLPFAPixelBuffer, + CGL.NSOpenGLPFADoubleBuffer, + CGL.NSOpenGLPFAStereo, + CGL.NSOpenGLPFAColorSize, + CGL.NSOpenGLPFAAlphaSize, + CGL.NSOpenGLPFADepthSize, + CGL.NSOpenGLPFAAccumSize, + CGL.NSOpenGLPFAStencilSize, + CGL.NSOpenGLPFASampleBuffers, + CGL.NSOpenGLPFASamples }; + + static int[] GLCapabilities2AttribList(GLCapabilitiesImmutable caps) { + int[] ivalues = new int[cglInternalAttributeToken.length]; + + for (int idx = 0; idx < cglInternalAttributeToken.length; idx++) { + int attr = cglInternalAttributeToken[idx]; + switch (attr) { + case CGL.kCGLPFAColorFloat: + ivalues[idx] = caps.getPbufferFloatingPointBuffers() ? 1 : 0; + break; + + case CGL.NSOpenGLPFAPixelBuffer: + ivalues[idx] = caps.isPBuffer() ? 1 : 0; + break; + + case CGL.NSOpenGLPFADoubleBuffer: + ivalues[idx] = (caps.getDoubleBuffered() ? 1 : 0); + break; + + case CGL.NSOpenGLPFAStereo: + ivalues[idx] = (caps.getStereo() ? 1 : 0); + break; + + case CGL.NSOpenGLPFAColorSize: + ivalues[idx] = (caps.getRedBits() + caps.getGreenBits() + caps.getBlueBits()); + break; + + case CGL.NSOpenGLPFAAlphaSize: + ivalues[idx] = caps.getAlphaBits(); + break; + + case CGL.NSOpenGLPFADepthSize: + ivalues[idx] = caps.getDepthBits(); + break; + + case CGL.NSOpenGLPFAAccumSize: + ivalues[idx] = (caps.getAccumRedBits() + caps.getAccumGreenBits() + caps.getAccumBlueBits() + caps.getAccumAlphaBits()); + break; + + case CGL.NSOpenGLPFAStencilSize: + ivalues[idx] = caps.getStencilBits(); + break; + + case CGL.NSOpenGLPFASampleBuffers: + ivalues[idx] = caps.getSampleBuffers() ? 1 : 0; + break; + + case CGL.NSOpenGLPFASamples: + ivalues[idx] = caps.getSampleBuffers() ? ivalues[idx] = caps.getNumSamples() : 0; + break; + + default: + break; + } + } + return ivalues; + } + + static long GLCapabilities2NSPixelFormat(GLCapabilitiesImmutable caps) { + int[] ivalues = GLCapabilities2AttribList(caps); + return CGL.createPixelFormat(cglInternalAttributeToken, 0, cglInternalAttributeToken.length, ivalues, 0); + } + + static GLCapabilitiesImmutable NSPixelFormat2GLCapabilities(GLProfile glp, long pixelFormat) { + return PixelFormat2GLCapabilities(glp, pixelFormat, true); + } + + static GLCapabilitiesImmutable CGLPixelFormat2GLCapabilities(GLProfile glp, long pixelFormat) { + return PixelFormat2GLCapabilities(glp, pixelFormat, false); + } + + private static GLCapabilitiesImmutable PixelFormat2GLCapabilities(GLProfile glp, long pixelFormat, boolean nsUsage) { + int[] ivalues = new int[cglInternalAttributeToken.length]; + + // On this platform the pixel format is associated with the + // context and not the drawable. However it's a reasonable + // approximation to just store the chosen pixel format up in the + // NativeSurface's AbstractGraphicsConfiguration, + // since the public API doesn't provide for a different GLCapabilities per context. + // Note: These restrictions of the platform's API might be considered as a bug anyways. + + // Figure out what attributes we really got + GLCapabilities caps = new GLCapabilities(glp); + if(nsUsage) { + CGL.queryPixelFormat(pixelFormat, cglInternalAttributeToken, 0, cglInternalAttributeToken.length, ivalues, 0); + } else { + CGL.CGLQueryPixelFormat(pixelFormat, cglInternalAttributeToken, 0, cglInternalAttributeToken.length, ivalues, 0); + } + for (int i = 0; i < cglInternalAttributeToken.length; i++) { + int attr = cglInternalAttributeToken[i]; + switch (attr) { + case CGL.kCGLPFAColorFloat: + caps.setPbufferFloatingPointBuffers(ivalues[i] != 0); + break; + + case CGL.NSOpenGLPFAPixelBuffer: + caps.setPBuffer(ivalues[i] != 0); + break; + + case CGL.NSOpenGLPFADoubleBuffer: + caps.setDoubleBuffered(ivalues[i] != 0); + break; + + case CGL.NSOpenGLPFAStereo: + caps.setStereo(ivalues[i] != 0); + break; + + case CGL.NSOpenGLPFAColorSize: + { + int bitSize = ivalues[i]; + if (bitSize == 32) + bitSize = 24; + bitSize /= 3; + caps.setRedBits(bitSize); + caps.setGreenBits(bitSize); + caps.setBlueBits(bitSize); + } + break; + + case CGL.NSOpenGLPFAAlphaSize: + caps.setAlphaBits(ivalues[i]); + break; + + case CGL.NSOpenGLPFADepthSize: + caps.setDepthBits(ivalues[i]); + break; + + case CGL.NSOpenGLPFAAccumSize: + { + int bitSize = ivalues[i] / 4; + caps.setAccumRedBits(bitSize); + caps.setAccumGreenBits(bitSize); + caps.setAccumBlueBits(bitSize); + caps.setAccumAlphaBits(bitSize); + } + break; + + case CGL.NSOpenGLPFAStencilSize: + caps.setStencilBits(ivalues[i]); + break; + + case CGL.NSOpenGLPFASampleBuffers: + caps.setSampleBuffers(ivalues[i] != 0); + break; + + case CGL.NSOpenGLPFASamples: + caps.setNumSamples(ivalues[i]); + break; + + default: + break; + } + } + + return caps; + } +} + diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java new file mode 100644 index 000000000..d4526f04e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.macosx.cgl; + +import jogamp.opengl.GLGraphicsConfigurationFactory; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; + + +/** Subclass of GraphicsConfigurationFactory used when non-AWT tookits + are used on OSX platforms. Toolkits will likely need to delegate + to this one to change the accepted and returned types of the + GraphicsDevice and GraphicsConfiguration abstractions. */ + +public class MacOSXCGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory { + protected static final boolean DEBUG = jogamp.opengl.Debug.debug("GraphicsConfiguration"); + + MacOSXCGLGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.macosx.MacOSXGraphicsDevice.class, this); + } + + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { + return chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, absScreen, false); + } + + static MacOSXCGLGraphicsConfiguration chooseGraphicsConfigurationStatic(CapabilitiesImmutable capsChosen, + CapabilitiesImmutable capsRequested, + CapabilitiesChooser chooser, + AbstractGraphicsScreen absScreen, boolean usePBuffer) { + if (absScreen == null) { + throw new IllegalArgumentException("AbstractGraphicsScreen is null"); + } + + if (! (capsChosen instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - chosen"); + } + + if (! (capsRequested instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - requested"); + } + + if (chooser != null && + !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilitiesChooser objects"); + } + + return new MacOSXCGLGraphicsConfiguration(absScreen, (GLCapabilitiesImmutable)capsChosen, (GLCapabilitiesImmutable)capsRequested, 0); + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java new file mode 100644 index 000000000..6303f2e43 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + +import javax.media.opengl.*; +import jogamp.opengl.*; + +import javax.media.nativewindow.*; +import jogamp.nativewindow.WrappedSurface; + +public class MacOSXExternalCGLContext extends MacOSXCGLContext { + private GLContext lastContext; + + private MacOSXExternalCGLContext(Drawable drawable, boolean isNSContext, long handle) { + super(drawable, null); + drawable.setExternalCGLContext(this); + this.isNSContext = isNSContext; + this.contextHandle = handle; + GLContextShareSet.contextCreated(this); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); + getGLStateTracker().setEnabled(false); // external context usage can't track state in Java + } + + protected static MacOSXExternalCGLContext create(GLDrawableFactory factory, GLProfile glp) { + long pixelFormat = 0; + long currentDrawable = 0; + long contextHandle = CGL.getCurrentContext(); // Check: MacOSX 10.3 .. + boolean isNSContext = 0 != contextHandle; + if( isNSContext ) { + long ctx = CGL.getCGLContext(contextHandle); + if (ctx == 0) { + throw new GLException("Error: NULL Context (CGL) of Context (NS) 0x" +Long.toHexString(contextHandle)); + } + pixelFormat = CGL.CGLGetPixelFormat(ctx); + currentDrawable = CGL.getNSView(contextHandle); + if(DEBUG) { + System.err.println("MacOSXExternalCGLContext Create Context (NS) 0x"+Long.toHexString(contextHandle)+ + ", Context (CGL) 0x"+Long.toHexString(ctx)+ + ", pixelFormat 0x"+Long.toHexString(pixelFormat)+ + ", drawable 0x"+Long.toHexString(currentDrawable)); + } + } else { + contextHandle = CGL.CGLGetCurrentContext(); + if (contextHandle == 0) { + throw new GLException("Error: current Context (CGL) null, no Context (NS)"); + } + pixelFormat = CGL.CGLGetPixelFormat(contextHandle); + if(DEBUG) { + System.err.println("MacOSXExternalCGLContext Create Context (CGL) 0x"+Long.toHexString(contextHandle)+ + ", pixelFormat 0x"+Long.toHexString(pixelFormat)); + } + } + + if (0 == pixelFormat) { + throw new GLException("Error: current pixelformat of current Context 0x"+Long.toHexString(contextHandle)+" is null"); + } + GLCapabilitiesImmutable caps = MacOSXCGLGraphicsConfiguration.CGLPixelFormat2GLCapabilities(glp, pixelFormat); + if(DEBUG) { + System.err.println("MacOSXExternalCGLContext Create "+caps); + } + + AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_MACOSX); + MacOSXCGLGraphicsConfiguration cfg = new MacOSXCGLGraphicsConfiguration(aScreen, caps, caps, pixelFormat); + + if(0 == currentDrawable) { + // set a fake marker stating a valid drawable + currentDrawable = 1; + } + WrappedSurface ns = new WrappedSurface(cfg); + ns.setSurfaceHandle(currentDrawable); + return new MacOSXExternalCGLContext(new Drawable(factory, ns), isNSContext, contextHandle); + } + + protected boolean createImpl() throws GLException { + return true; + } + + public int makeCurrent() throws GLException { + // Save last context if necessary to allow external GLContexts to + // talk to other GLContexts created by this library + GLContext cur = getCurrent(); + if (cur != null && cur != this) { + lastContext = cur; + setCurrent(null); + } + return super.makeCurrent(); + } + + public void release() throws GLException { + super.release(); + setCurrent(lastContext); + lastContext = null; + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + } + + protected void releaseImpl() throws GLException { + } + + protected void destroyImpl() throws GLException { + } + + public void setOpenGLMode(int mode) { + if (mode != MacOSXCGLDrawable.CGL_MODE) + throw new GLException("OpenGL mode switching not supported for external GLContexts"); + } + + public int getOpenGLMode() { + return MacOSXCGLDrawable.CGL_MODE; + } + + // Need to provide the display connection to extension querying APIs + static class Drawable extends MacOSXCGLDrawable { + MacOSXExternalCGLContext extCtx; + + Drawable(GLDrawableFactory factory, NativeSurface comp) { + super(factory, comp, true); + } + + void setExternalCGLContext(MacOSXExternalCGLContext externalContext) { + extCtx = externalContext; + } + + public GLContext createContext(GLContext shareWith) { + throw new GLException("Should not call this"); + } + + public int getWidth() { + throw new GLException("Should not call this"); + } + + public int getHeight() { + throw new GLException("Should not call this"); + } + + public void setSize(int width, int height) { + throw new GLException("Should not call this"); + } + + protected void swapBuffersImpl() { + if (extCtx != null) { + extCtx.swapBuffers(); + } + } + + public void setOpenGLMode(int mode) { + if (mode != CGL_MODE) + throw new GLException("OpenGL mode switching not supported for external GLContext's drawables"); + } + + public int getOpenGLMode() { + return CGL_MODE; + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java new file mode 100644 index 000000000..6dba11038 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + +import javax.media.opengl.*; +import jogamp.opengl.*; + +public class MacOSXOffscreenCGLContext extends MacOSXPbufferCGLContext +{ + public MacOSXOffscreenCGLContext(MacOSXPbufferCGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + public int getOffscreenContextPixelDataType() { + GL gl = getGL(); + return gl.isGL2GL3()?GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV:GL.GL_UNSIGNED_SHORT_5_5_5_1; + } + + public int getOffscreenContextReadBuffer() { + return GL.GL_FRONT; + } + + public boolean offscreenImageNeedsVerticalFlip() { + return true; + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLDrawable.java new file mode 100644 index 000000000..bec4cf32a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLDrawable.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import jogamp.opengl.*; + +public class MacOSXOffscreenCGLDrawable extends MacOSXPbufferCGLDrawable { + + public MacOSXOffscreenCGLDrawable(GLDrawableFactory factory, + NativeSurface target) { + super(factory, target); + } + + public GLContext createContext(GLContext shareWith) { + return new MacOSXOffscreenCGLContext(this, shareWith); + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLContext.java new file mode 100644 index 000000000..55d3a0853 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLContext.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + + +import javax.media.opengl.*; + +public class MacOSXOnscreenCGLContext extends MacOSXCGLContext { + + public MacOSXOnscreenCGLContext(MacOSXOnscreenCGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + @Override + protected void makeCurrentImpl(boolean newCreated) throws GLException { + super.makeCurrentImpl(newCreated); + CGL.updateContext(contextHandle); + } + + @Override + protected void releaseImpl() throws GLException { + super.releaseImpl(); + } + + @Override + protected void swapBuffers() { + if (!CGL.flushBuffer(contextHandle)) { + throw new GLException("Error swapping buffers"); + } + } + + @Override + protected void update() throws GLException { + if (contextHandle == 0) { + throw new GLException("Context not created"); + } + CGL.updateContext(contextHandle); + } + + protected boolean createImpl() { + return create(false, false); + } + + public void setOpenGLMode(int mode) { + if (mode != MacOSXCGLDrawable.NSOPENGL_MODE) + throw new GLException("OpenGL mode switching not supported for on-screen GLContexts"); + } + + public int getOpenGLMode() { + return MacOSXCGLDrawable.NSOPENGL_MODE; + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java new file mode 100644 index 000000000..513dc3a04 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + +import java.lang.ref.WeakReference; +import java.util.*; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; + +public class MacOSXOnscreenCGLDrawable extends MacOSXCGLDrawable { + private List/*<WeakReference<GLContext>>*/ createdContexts = + new ArrayList(); + + protected MacOSXOnscreenCGLDrawable(GLDrawableFactory factory, NativeSurface component) { + super(factory, component, false); + } + + public GLContext createContext(GLContext shareWith) { + MacOSXOnscreenCGLContext context = + new MacOSXOnscreenCGLContext(this, shareWith); + // NOTE: we need to keep track of the created contexts in order to + // implement swapBuffers() because of how Mac OS X implements its + // OpenGL window interface + synchronized (this) { + List newContexts = new ArrayList(); + newContexts.addAll(createdContexts); + newContexts.add(new WeakReference(context)); + createdContexts = newContexts; + } + return context; + } + + protected void swapBuffersImpl() { + for (Iterator iter = createdContexts.iterator(); iter.hasNext(); ) { + WeakReference ref = (WeakReference) iter.next(); + MacOSXOnscreenCGLContext ctx = (MacOSXOnscreenCGLContext) ref.get(); + // FIXME: clear out unreachable contexts + if (ctx != null) { + ctx.swapBuffers(); + } + } + } + + public void setOpenGLMode(int mode) { + if (mode != NSOPENGL_MODE) + throw new GLException("OpenGL mode switching not supported for on-screen GLDrawables"); + } + + public int getOpenGLMode() { + return NSOPENGL_MODE; + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLContext.java new file mode 100644 index 000000000..6eda3f068 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLContext.java @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.macosx.cgl; + +import com.jogamp.common.nio.PointerBuffer; +import java.security.*; +import java.util.*; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import jogamp.opengl.*; + +public class MacOSXPbufferCGLContext extends MacOSXCGLContext { + + // State for render-to-texture and render-to-texture-rectangle support + private int textureTarget; // e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV + private int texture; // actual texture object + + private static boolean isTigerOrLater; + + static { + String osVersion = Debug.getProperty("os.version", false, AccessController.getContext()); + StringTokenizer tok = new StringTokenizer(osVersion, ". "); + int major = Integer.parseInt(tok.nextToken()); + int minor = Integer.parseInt(tok.nextToken()); + isTigerOrLater = ((major > 10) || (minor > 3)); + } + + public MacOSXPbufferCGLContext(MacOSXPbufferCGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + initOpenGLImpl(); + } + + public void bindPbufferToTexture() { + GL gl = getGL(); + gl.glBindTexture(textureTarget, texture); + // FIXME: not clear whether this is really necessary, but since + // the API docs seem to imply it is and since it doesn't seem to + // impact performance, leaving it in + CGL.setContextTextureImageToPBuffer(contextHandle, drawable.getHandle(), GL.GL_FRONT); + } + + public void releasePbufferFromTexture() { + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + if (getOpenGLMode() != ((MacOSXPbufferCGLDrawable)drawable).getOpenGLMode()) { + setOpenGLMode(((MacOSXPbufferCGLDrawable)drawable).getOpenGLMode()); + } + + if (!impl.makeCurrent(contextHandle)) { + throw new GLException("Error making Context (NS) current"); + } + + if (newCreated) { + // Initialize render-to-texture support if requested + DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable)config.getChosenCapabilities(); + GL gl = getGL(); + boolean rect = gl.isGL2GL3() && capabilities.getPbufferRenderToTextureRectangle(); + if (rect) { + if (!gl.isExtensionAvailable("GL_EXT_texture_rectangle")) { + System.err.println("MacOSXPbufferCGLContext: WARNING: GL_EXT_texture_rectangle extension not " + + "supported; skipping requested render_to_texture_rectangle support for pbuffer"); + rect = false; + } + } + textureTarget = (rect ? GL2.GL_TEXTURE_RECTANGLE : GL.GL_TEXTURE_2D); + int[] tmp = new int[1]; + gl.glGenTextures(1, tmp, 0); + texture = tmp[0]; + gl.glBindTexture(textureTarget, texture); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); + gl.glCopyTexImage2D(textureTarget, 0, GL.GL_RGB, 0, 0, drawable.getWidth(), drawable.getHeight(), 0); + } + } + + protected void releaseImpl() throws GLException { + if (!impl.release(contextHandle)) { + throw new GLException("Error releasing OpenGL Context (NS)"); + } + } + + protected void destroyImpl() throws GLException { + if (!impl.destroy(contextHandle)) { + throw new GLException("Unable to delete OpenGL context"); + } + if (DEBUG) { + System.err.println("!!! Destroyed OpenGL context " + contextHandle); + } + } + + protected void setSwapIntervalImpl(int interval) { + impl.setSwapInterval(contextHandle, interval); + currentSwapInterval = impl.getSwapInterval() ; + } + + public int getFloatingPointMode() { + return GLPbuffer.APPLE_FLOAT; + } + + protected boolean createImpl() throws GLException { + DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable)config.getChosenCapabilities(); + if (capabilities.getPbufferFloatingPointBuffers() && + !isTigerOrLater) { + throw new GLException("Floating-point pbuffers supported only on OS X 10.4 or later"); + } + // Change our OpenGL mode to match that of any share context before we create ourselves + MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this); + if (other != null) { + setOpenGLMode(other.getOpenGLMode()); + } + // Will throw exception upon error + isNSContext = impl.isNSContext(); + contextHandle = impl.create(); + + if (!impl.makeCurrent(contextHandle)) { + throw new GLException("Error making Context (NS:"+isNSContext()+") current"); + } + if(!isNSContext()) { // FIXME: ?? + throw new GLException("Not a NS Context"); + } + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); + return true; + } + + //--------------------------------------------------------------------------- + // OpenGL "mode switching" functionality + // + private boolean haveSetOpenGLMode = false; + // FIXME: should consider switching the default mode based on + // whether the Java2D/JOGL bridge is active -- need to ask ourselves + // whether it's more likely that we will share with a GLCanvas or a + // GLJPanel when the bridge is turned on + private int openGLMode = MacOSXCGLDrawable.NSOPENGL_MODE; + // Implementation object (either NSOpenGL-based or CGL-based) + protected Impl impl; + + public void setOpenGLMode(int mode) { + if (mode == openGLMode) { + return; + } + if (haveSetOpenGLMode) { + throw new GLException("Can't switch between using NSOpenGLPixelBuffer and CGLPBufferObj more than once"); + } + destroyImpl(); + ((MacOSXPbufferCGLDrawable)drawable).setOpenGLMode(mode); + openGLMode = mode; + haveSetOpenGLMode = true; + if (DEBUG) { + System.err.println("Switching PBuffer context mode to " + + ((mode == MacOSXCGLDrawable.NSOPENGL_MODE) ? "NSOPENGL_MODE" : "CGL_MODE")); + } + initOpenGLImpl(); + } + + public int getOpenGLMode() { + return openGLMode; + } + + private void initOpenGLImpl() { + switch (openGLMode) { + case MacOSXCGLDrawable.NSOPENGL_MODE: + impl = new NSOpenGLImpl(); + break; + case MacOSXCGLDrawable.CGL_MODE: + impl = new CGLImpl(); + break; + default: + throw new InternalError("Illegal implementation mode " + openGLMode); + } + } + + // Abstract interface for implementation of this context (either + // NSOpenGL-based or CGL-based) + interface Impl { + public boolean isNSContext(); + public long create(); + public boolean destroy(long ctx); + public boolean makeCurrent(long ctx); + public boolean release(long ctx); + public void setSwapInterval(long ctx, int interval); + public int getSwapInterval(); + } + + // NSOpenGLContext-based implementation + class NSOpenGLImpl implements Impl { + public boolean isNSContext() { return true; } + public long create() { + DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable)config.getChosenCapabilities(); + if (capabilities.getPbufferFloatingPointBuffers() && + !isTigerOrLater) { + throw new GLException("Floating-point pbuffers supported only on OS X 10.4 or later"); + } + if (!MacOSXPbufferCGLContext.this.create(true, capabilities.getPbufferFloatingPointBuffers())) { + throw new GLException("Error creating context for pbuffer"); + } + // Must now associate the pbuffer with our newly-created context + CGL.setContextPBuffer(contextHandle, drawable.getHandle()); + return contextHandle; + } + + public boolean destroy(long ctx) { + return CGL.deleteContext(ctx); + } + + public boolean makeCurrent(long ctx) { + return CGL.makeCurrentContext(ctx); + } + + public boolean release(long ctx) { + return CGL.clearCurrentContext(ctx); + } + + private int currentSwapInterval = 0 ; + + public void setSwapInterval(long ctx, int interval) { + CGL.setSwapInterval(ctx, interval); + currentSwapInterval = interval ; + } + public int getSwapInterval() { + return currentSwapInterval; + } + } + + class CGLImpl implements Impl { + public boolean isNSContext() { return false; } + public long create() { + // Find and configure share context + MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(MacOSXPbufferCGLContext.this); + long share = 0; + if (other != null) { + // Reconfigure pbuffer-based GLContexts + if (other instanceof MacOSXPbufferCGLContext) { + MacOSXPbufferCGLContext ctx = (MacOSXPbufferCGLContext) other; + ctx.setOpenGLMode(MacOSXCGLDrawable.CGL_MODE); + } else { + if (other.isNSContext()) { + throw new GLException("Can't share between NSOpenGLContexts and CGLContextObjs"); + } + } + share = other.getHandle(); + // Note we don't check for a 0 return value, since switching + // the context's mode causes it to be destroyed and not + // re-initialized until the next makeCurrent + } + + // Set up pixel format attributes + // FIXME: shall go into MacOSXCGLGraphicsConfiguration + int[] attrs = new int[256]; + int i = 0; + attrs[i++] = CGL.kCGLPFAPBuffer; + DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable)config.getChosenCapabilities(); + if (capabilities.getPbufferFloatingPointBuffers()) + attrs[i++] = CGL.kCGLPFAColorFloat; + if (capabilities.getDoubleBuffered()) + attrs[i++] = CGL.kCGLPFADoubleBuffer; + if (capabilities.getStereo()) + attrs[i++] = CGL.kCGLPFAStereo; + attrs[i++] = CGL.kCGLPFAColorSize; + attrs[i++] = (capabilities.getRedBits() + + capabilities.getGreenBits() + + capabilities.getBlueBits()); + attrs[i++] = CGL.kCGLPFAAlphaSize; + attrs[i++] = capabilities.getAlphaBits(); + attrs[i++] = CGL.kCGLPFADepthSize; + attrs[i++] = capabilities.getDepthBits(); + // FIXME: should validate stencil size as is done in MacOSXWindowSystemInterface.m + attrs[i++] = CGL.kCGLPFAStencilSize; + attrs[i++] = capabilities.getStencilBits(); + attrs[i++] = CGL.kCGLPFAAccumSize; + attrs[i++] = (capabilities.getAccumRedBits() + + capabilities.getAccumGreenBits() + + capabilities.getAccumBlueBits() + + capabilities.getAccumAlphaBits()); + if (capabilities.getSampleBuffers()) { + attrs[i++] = CGL.kCGLPFASampleBuffers; + attrs[i++] = 1; + attrs[i++] = CGL.kCGLPFASamples; + attrs[i++] = capabilities.getNumSamples(); + } + + // Use attribute array to select pixel format + PointerBuffer fmt = PointerBuffer.allocateDirect(1); + long[] numScreens = new long[1]; + int res = CGL.CGLChoosePixelFormat(attrs, 0, fmt, numScreens, 0); + if (res != CGL.kCGLNoError) { + throw new GLException("Error code " + res + " while choosing pixel format"); + } + + // Create new context + PointerBuffer ctx = PointerBuffer.allocateDirect(1); + if (DEBUG) { + System.err.println("Share context for CGL-based pbuffer context is " + toHexString(share)); + } + res = CGL.CGLCreateContext(fmt.get(0), share, ctx); + CGL.CGLDestroyPixelFormat(fmt.get(0)); + if (res != CGL.kCGLNoError) { + throw new GLException("Error code " + res + " while creating context"); + } + // Attach newly-created context to the pbuffer + res = CGL.CGLSetPBuffer(ctx.get(0), drawable.getHandle(), 0, 0, 0); + if (res != CGL.kCGLNoError) { + throw new GLException("Error code " + res + " while attaching context to pbuffer"); + } + return ctx.get(0); + } + + public boolean destroy(long ctx) { + return (CGL.CGLDestroyContext(ctx) == CGL.kCGLNoError); + } + + public boolean makeCurrent(long ctx) { + return CGL.CGLSetCurrentContext(ctx) == CGL.kCGLNoError; + } + + public boolean release(long ctx) { + return (CGL.CGLSetCurrentContext(0) == CGL.kCGLNoError); + } + + public void setSwapInterval(long ctx, int interval) { + // For now not supported (not really relevant for off-screen contexts anyway) + } + public int getSwapInterval() { + return 0; + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java new file mode 100644 index 000000000..ec9ff8dd2 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl; + +import com.jogamp.common.nio.PointerBuffer; +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import jogamp.opengl.*; + +public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { + private static final boolean DEBUG = Debug.debug("MacOSXPbufferCGLDrawable"); + + // State for render-to-texture and render-to-texture-rectangle support + private int textureTarget; // e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV + private int texture; // actual texture object + + // NSOpenGLPbuffer (for normal mode) + // CGLPbufferObj (for CGL_MODE situation, i.e., when Java2D/JOGL bridge is active) + // Note that we can not store this in the NativeSurface because the + // semantic is that contains an NSView + protected long pBuffer; + + public MacOSXPbufferCGLDrawable(GLDrawableFactory factory, NativeSurface target) { + super(factory, target, true); + + if (DEBUG) { + System.out.println("Pbuffer config: " + getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration()); + } + + initOpenGLImpl(); + createPbuffer(); + + if (DEBUG) { + System.err.println("Created pbuffer " + this); + } + } + + protected void setRealizedImpl() { + if(realized) { + createPbuffer(); + } else { + destroyImpl(); + } + } + + public GLContext createContext(GLContext shareWith) { + return new MacOSXPbufferCGLContext(this, shareWith); + } + + protected void destroyImpl() { + if (this.pBuffer != 0) { + NativeSurface ns = getNativeSurface(); + impl.destroy(pBuffer); + this.pBuffer = 0; + ((SurfaceChangeable)ns).setSurfaceHandle(0); + if (DEBUG) { + System.err.println("Destroyed pbuffer: " + pBuffer); + } + } + } + + public long getHandle() { + return pBuffer; + } + + protected void swapBuffersImpl() { + if(DEBUG) { + System.err.println("unhandled swapBuffersImpl() called for: "+this); + } + } + + private void createPbuffer() { + NativeSurface ns = getNativeSurface(); + DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) ns.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable)config.getChosenCapabilities(); + GLProfile glProfile = capabilities.getGLProfile(); + int renderTarget; + if (glProfile.isGL2GL3() && capabilities.getPbufferRenderToTextureRectangle()) { + renderTarget = GL2.GL_TEXTURE_RECTANGLE; + } else { + int w = getNextPowerOf2(getWidth()); + int h = getNextPowerOf2(getHeight()); + ((SurfaceChangeable)ns).setSize(w, h); + renderTarget = GL.GL_TEXTURE_2D; + } + + int internalFormat = GL.GL_RGBA; + if (capabilities.getPbufferFloatingPointBuffers()) { + // FIXME: want to check availability of GL_APPLE_float_pixels + // extension, but need valid OpenGL context in order to do so -- + // in worst case would need to create dummy window / GLCanvas + // (undesirable) -- could maybe also do this with pbuffers + /* + if (!gl.isExtensionAvailable("GL_APPLE_float_pixels")) { + throw new GLException("Floating-point support (GL_APPLE_float_pixels) not available"); + } + */ + if(glProfile.isGL2GL3()) { + switch (capabilities.getRedBits()) { + case 16: internalFormat = GL2.GL_RGBA_FLOAT16_APPLE; break; + case 32: internalFormat = GL2.GL_RGBA_FLOAT32_APPLE; break; + default: throw new GLException("Invalid floating-point bit depth (only 16 and 32 supported)"); + } + } else { + internalFormat = GL.GL_RGBA; + } + } + + pBuffer = impl.create(renderTarget, internalFormat, getWidth(), getHeight()); + if (pBuffer == 0) { + throw new GLException("pbuffer creation error: CGL.createPBuffer() failed"); + } + + ((SurfaceChangeable)ns).setSurfaceHandle(pBuffer); + + } + + private int getNextPowerOf2(int number) { + if (((number-1) & number) == 0) { + //ex: 8 -> 0b1000; 8-1=7 -> 0b0111; 0b1000&0b0111 == 0 + return number; + } + int power = 0; + while (number > 0) { + number = number>>1; + power++; + } + return (1<<power); + } + + //--------------------------------------------------------------------------- + // OpenGL "mode switching" functionality + // + private boolean haveSetOpenGLMode = false; + // FIXME: should consider switching the default mode based on + // whether the Java2D/JOGL bridge is active -- need to ask ourselves + // whether it's more likely that we will share with a GLCanvas or a + // GLJPanel when the bridge is turned on + private int openGLMode = NSOPENGL_MODE; + // Implementation object (either NSOpenGL-based or CGL-based) + protected Impl impl; + + public void setOpenGLMode(int mode) { + if (mode == openGLMode) { + return; + } + if (haveSetOpenGLMode) { + throw new GLException("Can't switch between using NSOpenGLPixelBuffer and CGLPBufferObj more than once"); + } + destroyImpl(); + openGLMode = mode; + haveSetOpenGLMode = true; + if (DEBUG) { + System.err.println("Switching PBuffer drawable mode to " + + ((mode == MacOSXCGLDrawable.NSOPENGL_MODE) ? "NSOPENGL_MODE" : "CGL_MODE")); + } + initOpenGLImpl(); + createPbuffer(); + } + + public int getOpenGLMode() { + return openGLMode; + } + + private void initOpenGLImpl() { + switch (openGLMode) { + case NSOPENGL_MODE: + impl = new NSOpenGLImpl(); + break; + case CGL_MODE: + impl = new CGLImpl(); + break; + default: + throw new InternalError("Illegal implementation mode " + openGLMode); + } + } + + // Abstract interface for implementation of this drawable (either + // NSOpenGL-based or CGL-based) + interface Impl { + public long create(int renderTarget, int internalFormat, int width, int height); + public void destroy(long pbuffer); + } + + // NSOpenGLPixelBuffer implementation + class NSOpenGLImpl implements Impl { + public long create(int renderTarget, int internalFormat, int width, int height) { + return CGL.createPBuffer(renderTarget, internalFormat, width, height); + } + + public void destroy(long pbuffer) { + CGL.destroyPBuffer(pbuffer); + } + } + + // CGL implementation + class CGLImpl implements Impl { + public long create(int renderTarget, int internalFormat, int width, int height) { + PointerBuffer pbuffer = PointerBuffer.allocateDirect(1); + int res = CGL.CGLCreatePBuffer(width, height, renderTarget, internalFormat, 0, pbuffer); + if (res != CGL.kCGLNoError) { + throw new GLException("Error creating CGL-based pbuffer: error code " + res); + } + return pbuffer.get(0); + } + + public void destroy(long pbuffer) { + int res = CGL.CGLDestroyPBuffer(pbuffer); + if (res != CGL.kCGLNoError) { + throw new GLException("Error destroying CGL-based pbuffer: error code " + res); + } + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXAWTCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXAWTCGLDrawableFactory.java new file mode 100644 index 000000000..fe60710f0 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXAWTCGLDrawableFactory.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl.awt; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import jogamp.opengl.macosx.cgl.*; + +public class MacOSXAWTCGLDrawableFactory extends MacOSXCGLDrawableFactory { + + public MacOSXAWTCGLDrawableFactory() { + super(); + } + + public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { + return true; + } + + public GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) + throws GLException { + return new MacOSXJava2DCGLContext(shareWith); + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java new file mode 100644 index 000000000..68e82dc19 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.macosx.cgl.awt; + +import jogamp.opengl.GLGraphicsConfigurationFactory; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; +import javax.media.nativewindow.macosx.MacOSXGraphicsDevice; + +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLException; + +import jogamp.opengl.macosx.cgl.MacOSXCGLGraphicsConfiguration; + +public class MacOSXAWTCGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory { + protected static final boolean DEBUG = jogamp.opengl.Debug.debug("GraphicsConfiguration"); + + public MacOSXAWTCGLGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, this); + } + + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { + GraphicsDevice device = null; + if (absScreen != null && + !(absScreen instanceof AWTGraphicsScreen)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only AWTGraphicsScreen objects"); + } + + if(null==absScreen) { + absScreen = AWTGraphicsScreen.createScreenDevice(-1, AbstractGraphicsDevice.DEFAULT_UNIT); + } + AWTGraphicsScreen awtScreen = (AWTGraphicsScreen) absScreen; + device = ((AWTGraphicsDevice)awtScreen.getDevice()).getGraphicsDevice(); + + if ( !(capsChosen instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects - chosen"); + } + + if ( !(capsRequested instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects - requested"); + } + + if (chooser != null && + !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilitiesChooser objects"); + } + + if(DEBUG) { + System.err.println("MacOSXAWTCGLGraphicsConfigurationFactory: got "+absScreen); + } + + MacOSXGraphicsDevice macDevice = new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + DefaultGraphicsScreen macScreen = new DefaultGraphicsScreen(macDevice, awtScreen.getIndex()); + if(DEBUG) { + System.err.println("MacOSXAWTCGLGraphicsConfigurationFactory: made "+macScreen); + } + + GraphicsConfiguration gc = device.getDefaultConfiguration(); + MacOSXCGLGraphicsConfiguration macConfig = (MacOSXCGLGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(macDevice).chooseGraphicsConfiguration(capsChosen, + capsRequested, + chooser, macScreen); + + if (macConfig == null) { + throw new GLException("Unable to choose a GraphicsConfiguration: "+capsChosen+",\n\t"+chooser+"\n\t"+macScreen); + } + + // We have nothing to match .. so choose the default + return new AWTGraphicsConfiguration(awtScreen, macConfig.getChosenCapabilities(), macConfig.getRequestedCapabilities(), + gc, macConfig); + } +} diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java new file mode 100644 index 000000000..c5372bb5e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.macosx.cgl.awt; + +import jogamp.opengl.macosx.cgl.*; + +import java.awt.Graphics; +import javax.media.opengl.*; +import jogamp.opengl.*; +import jogamp.opengl.awt.*; +import jogamp.opengl.macosx.cgl.*; + +/** MacOSXCGLContext implementation supporting the Java2D/JOGL bridge + * on Mac OS X. The external GLDrawable mechanism does not work on Mac + * OS X due to how drawables and contexts are operated upon on this + * platform, so it is necessary to supply an alternative means to + * create, make current, and destroy contexts on the Java2D "drawable" + * on the Mac platform. + */ + +public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGLContext { + private Graphics graphics; + + // FIXME: ignoring context sharing for the time being; will need to + // rethink this in particular if using FBOs to implement the + // Java2D/OpenGL pipeline on Mac OS X + + MacOSXJava2DCGLContext(GLContext shareWith) { + super(null, shareWith); + } + + public void setGraphics(Graphics g) { + this.graphics = g; + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + if (!Java2D.makeOGLContextCurrentOnSurface(graphics, contextHandle)) { + throw new GLException("Error making context current"); + } + } + + protected boolean createImpl() { + // Find and configure share context + MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this); + long share = 0; + if (other != null) { + // Reconfigure pbuffer-based GLContexts + if (other instanceof MacOSXPbufferCGLContext) { + MacOSXPbufferCGLContext ctx = (MacOSXPbufferCGLContext) other; + ctx.setOpenGLMode(MacOSXCGLDrawable.CGL_MODE); + } else { + if (other.getOpenGLMode() != MacOSXCGLDrawable.CGL_MODE) { + throw new GLException("Can't share between NSOpenGLContexts and CGLContextObjs"); + } + } + share = other.getHandle(); + // Note we don't check for a 0 return value, since switching + // the context's mode causes it to be destroyed and not + // re-initialized until the next makeCurrent + } + + if (DEBUG) { + System.err.println("!!! Share context is " + toHexString(share) + " for " + getClass().getName()); + } + + long ctx = Java2D.createOGLContextOnSurface(graphics, share); + if (ctx == 0) { + return false; + } + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + // FIXME: think about GLContext sharing + contextHandle = ctx; + isNSContext = true; + return true; + } + + protected void releaseImpl() throws GLException { + // FIXME: would need another primitive in the Java2D class in + // order to implement this; hopefully should not matter for + // correctness + } + + protected void destroyImpl() throws GLException { + Java2D.destroyOGLContext(contextHandle); + if (DEBUG) { + System.err.println("!!! Destroyed OpenGL context " + contextHandle); + } + } + + public void setOpenGLMode(int mode) { + if (mode != MacOSXCGLDrawable.CGL_MODE) + throw new GLException("OpenGL mode switching not supported for Java2D GLContexts"); + } + + public int getOpenGLMode() { + return MacOSXCGLDrawable.CGL_MODE; + } +} diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java new file mode 100644 index 000000000..4e5afc683 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java @@ -0,0 +1,331 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package jogamp.opengl.util.glsl.fixedfunc; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; +import javax.media.opengl.glu.*; +import com.jogamp.common.nio.Buffers; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.glsl.*; +import java.nio.*; + +public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFunc { + public static final int MAX_TEXTURE_UNITS = 8; + + protected FixedFuncPipeline fixedFunction=null; + protected PMVMatrix pmvMatrix=null; + protected GL2ES2 gl=null; + + public FixedFuncHook (GL2ES2 gl) { + this(gl, null); + } + + public FixedFuncHook (GL2ES2 gl, PMVMatrix matrix) { + this.gl = gl; + pmvMatrix = (null!=matrix)?matrix:new PMVMatrix(); + + fixedFunction = new FixedFuncPipeline(gl, pmvMatrix); + } + + public FixedFuncHook(GL2ES2 gl, PMVMatrix matrix, + Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot, + String vertexColorFile, + String vertexColorLightFile, + String fragmentColorFile, + String fragmentColorTextureFile) { + this.gl = gl; + pmvMatrix = matrix; + + fixedFunction = new FixedFuncPipeline(gl, pmvMatrix, + shaderRootClass, shaderSrcRoot, shaderBinRoot, + vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile); + } + + public void destroy() { + fixedFunction.destroy(gl); + fixedFunction = null; + } + + public PMVMatrix getMatrix() { return pmvMatrix; } + + // + // FixedFuncHookIf - hooks + // + public void glDrawArrays(int mode, int first, int count) { + fixedFunction.validate(gl); + gl.glDrawArrays(mode, first, count); + } + public void glDrawElements(int mode, int count, int type, java.nio.Buffer indices) { + fixedFunction.validate(gl); + gl.glDrawElements(mode, count, type, indices); + } + public void glDrawElements(int mode, int count, int type, long indices_buffer_offset) { + fixedFunction.validate(gl); + gl.glDrawElements(mode, count, type, indices_buffer_offset); + } + + public void glActiveTexture(int texture) { + fixedFunction.glActiveTexture(gl, texture); + gl.glActiveTexture(texture); + } + public void glEnable(int cap) { + if(fixedFunction.glEnable(gl, cap, true)) { + gl.glEnable(cap); + } + } + public void glDisable(int cap) { + if(fixedFunction.glEnable(gl, cap, false)) { + gl.glDisable(cap); + } + } + public void glCullFace(int faceName) { + fixedFunction.glCullFace(gl, faceName); + gl.glCullFace(faceName); + } + + public void glGetFloatv(int pname, java.nio.FloatBuffer params) { + if(pmvMatrix.isMatrixGetName(pname)) { + pmvMatrix.glGetFloatv(pname, params); + return; + } + gl.glGetFloatv(pname, params); + } + public void glGetFloatv(int pname, float[] params, int params_offset) { + if(pmvMatrix.isMatrixGetName(pname)) { + pmvMatrix.glGetFloatv(pname, params, params_offset); + return; + } + gl.glGetFloatv(pname, params, params_offset); + } + public void glGetIntegerv(int pname, IntBuffer params) { + if(pmvMatrix.isMatrixGetName(pname)) { + pmvMatrix.glGetIntegerv(pname, params); + return; + } + gl.glGetIntegerv(pname, params); + } + public void glGetIntegerv(int pname, int[] params, int params_offset) { + if(pmvMatrix.isMatrixGetName(pname)) { + pmvMatrix.glGetIntegerv(pname, params, params_offset); + return; + } + gl.glGetIntegerv(pname, params, params_offset); + } + + // + // MatrixIf + // + public int glGetMatrixMode() { + return pmvMatrix.glGetMatrixMode(); + } + public void glMatrixMode(int mode) { + pmvMatrix.glMatrixMode(mode); + } + public void glLoadMatrixf(java.nio.FloatBuffer m) { + pmvMatrix.glLoadMatrixf(m); + } + public void glLoadMatrixf(float[] m, int m_offset) { + glLoadMatrixf(GLBuffers.newDirectFloatBuffer(m, m_offset)); + } + public void glPopMatrix() { + pmvMatrix.glPopMatrix(); + } + public void glPushMatrix() { + pmvMatrix.glPushMatrix(); + } + public void glLoadIdentity() { + pmvMatrix.glLoadIdentity(); + } + public void glMultMatrixf(java.nio.FloatBuffer m) { + pmvMatrix.glMultMatrixf(m); + } + public void glMultMatrixf(float[] m, int m_offset) { + glMultMatrixf(GLBuffers.newDirectFloatBuffer(m, m_offset)); + } + public void glTranslatef(float x, float y, float z) { + pmvMatrix.glTranslatef(x, y, z); + } + public void glRotatef(float angdeg, float x, float y, float z) { + pmvMatrix.glRotatef(angdeg, x, y, z); + } + public void glScalef(float x, float y, float z) { + pmvMatrix.glScalef(x, y, z); + } + public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { + pmvMatrix.glOrthof(left, right, bottom, top, zNear, zFar); + } + public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { + pmvMatrix.glFrustumf(left, right, bottom, top, zNear, zFar); + } + + // + // LightingIf + // + public void glColor4f(float red, float green, float blue, float alpha) { + fixedFunction.glColor4fv(gl, GLBuffers.newDirectFloatBuffer(new float[] { red, green, blue, alpha })); + } + + public void glLightfv(int light, int pname, java.nio.FloatBuffer params) { + fixedFunction.glLightfv(gl, light, pname, params); + } + public void glLightfv(int light, int pname, float[] params, int params_offset) { + glLightfv(light, pname, GLBuffers.newDirectFloatBuffer(params, params_offset)); + } + public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params) { + fixedFunction.glMaterialfv(gl, face, pname, params); + } + public void glMaterialfv(int face, int pname, float[] params, int params_offset) { + glMaterialfv(face, pname, GLBuffers.newDirectFloatBuffer(params, params_offset)); + } + public void glMaterialf(int face, int pname, float param) { + glMaterialfv(face, pname, GLBuffers.newDirectFloatBuffer(new float[] { param })); + } + public void glShadeModel(int mode) { + fixedFunction.glShadeModel(gl, mode); + } + + // + // PointerIf + // + public void glEnableClientState(int glArrayIndex) { + fixedFunction.glEnableClientState(gl, glArrayIndex); + } + public void glDisableClientState(int glArrayIndex) { + fixedFunction.glDisableClientState(gl, glArrayIndex); + } + + public void glVertexPointer(GLArrayData array) { + if(array.isVBO()) { + if(!gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not enabled: "+array); + } + } else { + if(gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not disabled: "+array); + } + Buffers.rangeCheck(array.getBuffer(), 1); + if (!Buffers.isDirect(array.getBuffer())) { + throw new GLException("Argument \"pointer\" was not a direct buffer"); } + } + fixedFunction.glVertexPointer(gl, array); + } + + public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer) { + glVertexPointer(GLArrayDataWrapper.createFixed(gl, GL_VERTEX_ARRAY, size, type, false, stride, pointer, 0, 0)); + } + public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) { + int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glVertexPointer(GLArrayDataWrapper.createFixed(gl, GL_VERTEX_ARRAY, size, type, false, + stride, null, vboName, pointer_buffer_offset)); + } + + public void glColorPointer(GLArrayData array) { + if(array.isVBO()) { + if(!gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not enabled: "+array); + } + } else { + if(gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not disabled: "+array); + } + Buffers.rangeCheck(array.getBuffer(), 1); + if (!Buffers.isDirect(array.getBuffer())) { + throw new GLException("Argument \"pointer\" was not a direct buffer"); } + } + fixedFunction.glColorPointer(gl, array); + } + public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer) { + glColorPointer(GLArrayDataWrapper.createFixed(gl, GL_COLOR_ARRAY, size, type, false, + stride, pointer, 0, 0)); + } + public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) { + int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glColorPointer(GLArrayDataWrapper.createFixed(gl, GL_COLOR_ARRAY, size, type, false, + stride, null, vboName, pointer_buffer_offset)); + } + + public void glNormalPointer(GLArrayData array) { + if(array.getComponentNumber()!=3) { + throw new GLException("Only 3 components per normal allowed"); + } + if(array.isVBO()) { + if(!gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not enabled: "+array); + } + } else { + if(gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not disabled: "+array); + } + Buffers.rangeCheck(array.getBuffer(), 1); + if (!Buffers.isDirect(array.getBuffer())) { + throw new GLException("Argument \"pointer\" was not a direct buffer"); } + } + fixedFunction.glNormalPointer(gl, array); + } + public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) { + glNormalPointer(GLArrayDataWrapper.createFixed(gl, GL_NORMAL_ARRAY, 3, type, false, + stride, pointer, 0, 0)); + } + public void glNormalPointer(int type, int stride, long pointer_buffer_offset) { + int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glNormalPointer(GLArrayDataWrapper.createFixed(gl, GL_NORMAL_ARRAY, 3, type, false, + stride, null, vboName, pointer_buffer_offset)); + } + + public void glTexCoordPointer(GLArrayData array) { + if(array.isVBO()) { + if(!gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not enabled: "+array); + } + } else { + if(gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not disabled: "+array); + } + Buffers.rangeCheck(array.getBuffer(), 1); + if (!Buffers.isDirect(array.getBuffer())) { + throw new GLException("Argument \"pointer\" was not a direct buffer"); } + } + fixedFunction.glTexCoordPointer(gl, array); + } + public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer) { + glTexCoordPointer( + GLArrayDataWrapper.createFixed(gl, GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, 0,0)); + } + public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) { + int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glTexCoordPointer( + GLArrayDataWrapper.createFixed(gl, GL_TEXTURE_COORD_ARRAY, size, type, false, + stride, null, vboName, pointer_buffer_offset) ); + } + + public final String toString() { + StringBuffer buf = new StringBuffer(); + buf.append(getClass().getName()+" ("); + if(null!=pmvMatrix) { + buf.append(", matrixDirty: "+pmvMatrix.isDirty()); + } + buf.append("\n\t, FixedFunction: "+fixedFunction); + buf.append(gl); + buf.append(" )"); + + return buf.toString(); + } + +} + + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java new file mode 100644 index 000000000..b77cf4617 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java @@ -0,0 +1,554 @@ + +package jogamp.opengl.util.glsl.fixedfunc; + +import com.jogamp.common.nio.Buffers; +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.glsl.*; +import java.nio.*; + +public class FixedFuncPipeline { + public static final int MAX_TEXTURE_UNITS = 8; + public static final int MAX_LIGHTS = 8; + + // We can't have any dependencies on the FixedFuncUtil class for build bootstrapping reasons + public static final String mgl_Vertex = "mgl_Vertex"; + public static final String mgl_Normal = "mgl_Normal"; + public static final String mgl_Color = "mgl_Color"; + public static final String mgl_MultiTexCoord = "mgl_MultiTexCoord" ; + + public static String getPredefinedArrayIndexName(int glArrayIndex) { + switch(glArrayIndex) { + case GLPointerFunc.GL_VERTEX_ARRAY: + return mgl_Vertex; + case GLPointerFunc.GL_NORMAL_ARRAY: + return mgl_Normal; + case GLPointerFunc.GL_COLOR_ARRAY: + return mgl_Color; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + return mgl_MultiTexCoord; + } + return null; + } + + public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix) { + init(gl, pmvMatrix, FixedFuncPipeline.class, shaderSrcRootDef, shaderBinRootDef, + vertexColorFileDef, vertexColorLightFileDef, fragmentColorFileDef, fragmentColorTextureFileDef); + } + public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot, + String vertexColorFile, + String vertexColorLightFile, + String fragmentColorFile, + String fragmentColorTextureFile) { + init(gl, pmvMatrix, shaderRootClass, shaderSrcRoot, shaderBinRoot, + vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile); + } + + public boolean verbose() { return verbose; } + + public void setVerbose(boolean v) { verbose=v; } + + public boolean isValid() { + return shaderState.linked(); + } + + public ShaderState getShaderState() { + return shaderState; + } + + public int getActiveTextureUnit() { + return activeTextureUnit; + } + + public String getArrayIndexName(int glArrayIndex) { + String name = getPredefinedArrayIndexName(glArrayIndex); + switch(glArrayIndex) { + case GLPointerFunc.GL_VERTEX_ARRAY: + case GLPointerFunc.GL_NORMAL_ARRAY: + case GLPointerFunc.GL_COLOR_ARRAY: + break; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + name = name + activeTextureUnit; + } + return name; + } + + public void destroy(GL2ES2 gl) { + shaderProgramColor.release(gl, true); + shaderProgramColorLight.release(gl, true); + shaderProgramColorTexture.release(gl, true); + shaderProgramColorTextureLight.release(gl, true); + shaderState.destroy(gl); + } + + public void glEnableClientState(GL2ES2 gl, int glArrayIndex) { + shaderState.glUseProgram(gl, true); + + shaderState.glEnableVertexAttribArray(gl, getArrayIndexName(glArrayIndex)); + // textureCoordsEnabled |= (1 << activeTextureUnit); + if ( textureCoordsEnabled.get(activeTextureUnit) != 1 ) { + textureCoordsEnabled.put(activeTextureUnit, 1); + textureCoordsEnabledDirty = true; + } + } + + public void glDisableClientState(GL2ES2 gl, int glArrayIndex) { + shaderState.glUseProgram(gl, true); + + shaderState.glDisableVertexAttribArray(gl, getArrayIndexName(glArrayIndex)); + // textureCoordsEnabled &= ~(1 << activeTextureUnit); + if ( textureCoordsEnabled.get(activeTextureUnit) != 0 ) { + textureCoordsEnabled.put(activeTextureUnit, 0); + textureCoordsEnabledDirty = true; + } + } + + public void glVertexPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glColorPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glColor4fv(GL2ES2 gl, FloatBuffer data ) { + shaderState.glUseProgram(gl, true); + GLUniformData ud = shaderState.getUniform(mgl_ColorStatic); + if(null!=ud) { + ud.setData(data); + shaderState.glUniform(gl, ud); + } + } + + public void glNormalPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glTexCoordPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + data.setName( getArrayIndexName(data.getIndex()) ); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glLightfv(GL2ES2 gl, int light, int pname, java.nio.FloatBuffer params) { + shaderState.glUseProgram(gl, true); + light -=GLLightingFunc.GL_LIGHT0; + if(0 <= light && light < MAX_LIGHTS) { + GLUniformData ud = null; + switch(pname) { + case GLLightingFunc.GL_AMBIENT: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].ambient"); + break; + case GLLightingFunc.GL_DIFFUSE: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].diffuse"); + break; + case GLLightingFunc.GL_SPECULAR: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].specular"); + break; + case GLLightingFunc.GL_POSITION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].position"); + break; + case GLLightingFunc.GL_SPOT_DIRECTION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotDirection"); + break; + case GLLightingFunc.GL_SPOT_EXPONENT: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotExponent"); + break; + case GLLightingFunc.GL_SPOT_CUTOFF: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotCutoff"); + break; + case GLLightingFunc.GL_CONSTANT_ATTENUATION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].constantAttenuation"); + break; + case GLLightingFunc.GL_LINEAR_ATTENUATION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].linearAttenuation"); + break; + case GLLightingFunc.GL_QUADRATIC_ATTENUATION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].quadraticAttenuation"); + break; + default: + if(verbose) { + System.err.println("glLightfv pname not within [GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_POSITION GL_SPOT_DIRECTION]: "+pname); + } + return; + } + if(null!=ud) { + ud.setData(params); + shaderState.glUniform(gl, ud); + } + } else if(verbose) { + System.err.println("glLightfv light not within [0.."+MAX_LIGHTS+"]: "+light); + } + } + + public void glMaterialfv(GL2ES2 gl, int face, int pname, java.nio.FloatBuffer params) { + shaderState.glUseProgram(gl, true); + + switch (face) { + case GL.GL_FRONT: + case GL.GL_FRONT_AND_BACK: + break; + case GL.GL_BACK: + if(verbose) { + System.err.println("glMaterialfv face GL_BACK currently not supported"); + } + break; + default: + } + + GLUniformData ud = null; + switch(pname) { + case GLLightingFunc.GL_AMBIENT: + ud = shaderState.getUniform(mgl_FrontMaterial+".ambient"); + break; + case GLLightingFunc.GL_AMBIENT_AND_DIFFUSE: + glMaterialfv(gl, face, GLLightingFunc.GL_AMBIENT, params); + // fall through intended .. + case GLLightingFunc.GL_DIFFUSE: + ud = shaderState.getUniform(mgl_FrontMaterial+".diffuse"); + break; + case GLLightingFunc.GL_SPECULAR: + ud = shaderState.getUniform(mgl_FrontMaterial+".specular"); + break; + case GLLightingFunc.GL_EMISSION: + ud = shaderState.getUniform(mgl_FrontMaterial+".emission"); + break; + case GLLightingFunc.GL_SHININESS: + ud = shaderState.getUniform(mgl_FrontMaterial+".shininess"); + break; + default: + if(verbose) { + System.err.println("glMaterialfv pname not within [GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_EMISSION GL_SHININESS]: "+pname); + } + return; + } + if(null!=ud) { + ud.setData(params); + shaderState.glUniform(gl, ud); + } + } + + public void glShadeModel(GL2ES2 gl, int mode) { + shaderState.glUseProgram(gl, true); + GLUniformData ud = shaderState.getUniform(mgl_ShadeModel); + if(null!=ud) { + ud.setData(mode); + shaderState.glUniform(gl, ud); + } + } + + public void glActiveTexture(GL2ES2 gl, int textureUnit) { + textureUnit -= GL.GL_TEXTURE0; + if(0 <= textureUnit && textureUnit<MAX_TEXTURE_UNITS) { + shaderState.glUseProgram(gl, true); + GLUniformData ud; + ud = shaderState.getUniform(mgl_ActiveTexture); + if(null!=ud) { + ud.setData(textureUnit); + shaderState.glUniform(gl, ud); + } + ud = shaderState.getUniform(mgl_ActiveTextureIdx); + if(null!=ud) { + ud.setData(textureUnit); + shaderState.glUniform(gl, ud); + } + activeTextureUnit = textureUnit; + } else { + throw new GLException("glActivateTexture textureUnit not within GL_TEXTURE0 + [0.."+MAX_TEXTURE_UNITS+"]: "+textureUnit); + } + } + + /** + * @return false if digested in regard to GL2ES2 spec, + * eg this call must not be passed to an underlying ES2 implementation. + * true if this call shall be passed to an underlying GL2ES2/ES2 implementation as well. + */ + public boolean glEnable(GL2ES2 gl, int cap, boolean enable) { + switch(cap) { + case GL.GL_TEXTURE_2D: + textureEnabled=enable; + return true; + case GLLightingFunc.GL_LIGHTING: + lightingEnabled=enable; + return false; + case GL.GL_CULL_FACE: + cullFace=Math.abs(cullFace); + if(!enable) { + cullFace*=-1; + } + return true; + } + + int light = cap - GLLightingFunc.GL_LIGHT0; + if(0 <= light && light < MAX_LIGHTS) { + if ( (lightsEnabled.get(light)==1) != enable ) { + lightsEnabled.put(light, enable?1:0); + lightsEnabledDirty = true; + return false; + } + } + return true; // pass it on .. + } + + public void glCullFace(GL2ES2 gl, int faceName) { + switch(faceName) { + case GL.GL_FRONT: + faceName = 1; break; + case GL.GL_BACK: + faceName = 2; break; + case GL.GL_FRONT_AND_BACK: + faceName = 3; break; + } + if(0>cullFace) { + faceName *= -1; + } + cullFace = faceName; + } + + public void validate(GL2ES2 gl) { + shaderState.glUseProgram(gl, true); + GLUniformData ud; + if(pmvMatrix.update()) { + ud = shaderState.getUniform(mgl_PMVMatrix); + if(null!=ud) { + // same data object .. + shaderState.glUniform(gl, ud); + } else { + throw new GLException("Failed to update: mgl_PMVMatrix"); + } + ud = shaderState.getUniform(mgl_NormalMatrix); + if(null!=ud) { + // same data object .. + shaderState.glUniform(gl, ud); + } + } + ud = shaderState.getUniform(mgl_ColorEnabled); + if(null!=ud) { + int ca = (shaderState.isVertexAttribArrayEnabled(mgl_Color)==true)?1:0; + if(ca!=ud.intValue()) { + ud.setData(ca); + shaderState.glUniform(gl, ud); + } + } + ud = shaderState.getUniform(mgl_CullFace); + if(null!=ud) { + if(cullFace!=ud.intValue()) { + ud.setData(cullFace); + shaderState.glUniform(gl, ud); + } + } + + if(lightsEnabledDirty) { + ud = shaderState.getUniform(mgl_LightsEnabled); + if(null!=ud) { + // same data object + shaderState.glUniform(gl, ud); + } + lightsEnabledDirty=false; + } + + if(textureCoordsEnabledDirty) { + ud = shaderState.getUniform(mgl_TexCoordEnabled); + if(null!=ud) { + // same data object + shaderState.glUniform(gl, ud); + } + textureCoordsEnabledDirty=false; + } + + if(textureEnabled) { + if(lightingEnabled) { + shaderState.attachShaderProgram(gl, shaderProgramColorTextureLight); + } else { + shaderState.attachShaderProgram(gl, shaderProgramColorTexture); + } + } else { + if(lightingEnabled) { + shaderState.attachShaderProgram(gl, shaderProgramColorLight); + } else { + shaderState.attachShaderProgram(gl, shaderProgramColor); + } + } + if(DEBUG) { + System.err.println("validate: "+this); + } + } + + public String toString() { + return "FixedFuncPipeline[pmv: "+pmvMatrix+ + ", textureEnabled: "+textureEnabled+ + ", textureCoordsEnabled: "+textureCoordsEnabled+ + ", lightingEnabled: "+lightingEnabled+ + ", lightsEnabled: "+lightsEnabled+ + "\n\t, shaderProgramColor: "+shaderProgramColor+ + "\n\t, shaderProgramColorTexture: "+shaderProgramColorTexture+ + "\n\t, shaderProgramColorLight: "+shaderProgramColorLight+ + "\n\t, shaderProgramColorTextureLight: "+shaderProgramColorTextureLight+ + "\n\t, ShaderState: "+shaderState+ + "]"; + } + + protected void init(GL2ES2 gl, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot, + String vertexColorFile, + String vertexColorLightFile, + String fragmentColorFile, + String fragmentColorTextureFile) + { + if(null==pmvMatrix) { + throw new GLException("PMVMatrix is null"); + } + this.pmvMatrix=pmvMatrix; + this.shaderState=new ShaderState(); + this.shaderState.setVerbose(verbose); + ShaderCode vertexColor, vertexColorLight, fragmentColor, fragmentColorTexture; + + vertexColor = ShaderCode.create( gl, gl.GL_VERTEX_SHADER, 1, shaderRootClass, + shaderSrcRoot, shaderBinRoot, vertexColorFile); + + vertexColorLight = ShaderCode.create( gl, gl.GL_VERTEX_SHADER, 1, shaderRootClass, + shaderSrcRoot, shaderBinRoot, vertexColorLightFile); + + fragmentColor = ShaderCode.create( gl, gl.GL_FRAGMENT_SHADER, 1, shaderRootClass, + shaderSrcRoot, shaderBinRoot, fragmentColorFile); + + fragmentColorTexture = ShaderCode.create( gl, gl.GL_FRAGMENT_SHADER, 1, shaderRootClass, + shaderSrcRoot, shaderBinRoot, fragmentColorTextureFile); + + shaderProgramColor = new ShaderProgram(); + shaderProgramColor.add(vertexColor); + shaderProgramColor.add(fragmentColor); + if(!shaderProgramColor.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColor program: "+shaderProgramColor); + } + + shaderProgramColorTexture = new ShaderProgram(); + shaderProgramColorTexture.add(vertexColor); + shaderProgramColorTexture.add(fragmentColorTexture); + if(!shaderProgramColorTexture.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorTexture program: "+shaderProgramColorTexture); + } + + shaderProgramColorLight = new ShaderProgram(); + shaderProgramColorLight.add(vertexColorLight); + shaderProgramColorLight.add(fragmentColor); + if(!shaderProgramColorLight.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorLight); + } + + shaderProgramColorTextureLight = new ShaderProgram(); + shaderProgramColorTextureLight.add(vertexColorLight); + shaderProgramColorTextureLight.add(fragmentColorTexture); + if(!shaderProgramColorTextureLight.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorTextureLight); + } + + shaderState.attachShaderProgram(gl, shaderProgramColor); + shaderState.glUseProgram(gl, true); + + // mandatory .. + if(!shaderState.glUniform(gl, new GLUniformData(mgl_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMviMatrixf()))) { + throw new GLException("Error setting PMVMatrix in shader: "+this); + } + + // optional parameter .. + shaderState.glUniform(gl, new GLUniformData(mgl_NormalMatrix, 3, 3, pmvMatrix.glGetNormalMatrixf())); + + shaderState.glUniform(gl, new GLUniformData(mgl_ColorEnabled, 0)); + shaderState.glUniform(gl, new GLUniformData(mgl_ColorStatic, 4, zero4f)); + shaderState.glUniform(gl, new GLUniformData(mgl_TexCoordEnabled, 1, textureCoordsEnabled)); + shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTexture, activeTextureUnit)); + shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTextureIdx, activeTextureUnit)); + shaderState.glUniform(gl, new GLUniformData(mgl_ShadeModel, 0)); + shaderState.glUniform(gl, new GLUniformData(mgl_CullFace, cullFace)); + for(int i=0; i<MAX_LIGHTS; i++) { + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].ambient", 4, defAmbient)); + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].diffuse", 4, defDiffuse)); + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].specular", 4, defSpecular)); + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].position", 4, defPosition)); + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotDirection", 3, defSpotDir)); + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotExponent", defSpotExponent)); + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotCutoff", defSpotCutoff)); + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].constantAttenuation", defConstantAtten)); + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].linearAttenuation", defLinearAtten)); + shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].quadraticAttenuation", defQuadraticAtten)); + } + shaderState.glUniform(gl, new GLUniformData(mgl_LightsEnabled, 1, lightsEnabled)); + shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".ambient", 4, defMatAmbient)); + shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".diffuse", 4, defMatDiffuse)); + shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".specular", 4, defMatSpecular)); + shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".emission", 4, defMatEmission)); + shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".shininess", defMatShininess)); + + shaderState.glUseProgram(gl, false); + } + + protected static final boolean DEBUG=false; + protected boolean verbose=false; + + protected boolean textureEnabled=false; + protected IntBuffer textureCoordsEnabled = Buffers.newDirectIntBuffer(new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }); + protected boolean textureCoordsEnabledDirty = false; + protected int activeTextureUnit=0; + + protected int cullFace=-2; // <=0 disabled, 1: front, 2: back (default, but disabled), 3: front & back + + protected boolean lightingEnabled=false; + protected IntBuffer lightsEnabled = Buffers.newDirectIntBuffer(new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }); + protected boolean lightsEnabledDirty = false; + + protected PMVMatrix pmvMatrix; + protected ShaderState shaderState; + protected ShaderProgram shaderProgramColor; + protected ShaderProgram shaderProgramColorTexture; + protected ShaderProgram shaderProgramColorLight; + protected ShaderProgram shaderProgramColorTextureLight; + + // uniforms .. + protected static final String mgl_PMVMatrix = "mgl_PMVMatrix"; // m4fv[3] + protected static final String mgl_NormalMatrix = "mgl_NormalMatrix"; // m4fv + protected static final String mgl_ColorEnabled = "mgl_ColorEnabled"; // 1i + protected static final String mgl_ColorStatic = "mgl_ColorStatic"; // 4fv + + protected static final String mgl_LightSource = "mgl_LightSource"; // struct mgl_LightSourceParameters[MAX_LIGHTS] + protected static final String mgl_FrontMaterial = "mgl_FrontMaterial"; // struct mgl_MaterialParameters + protected static final String mgl_LightsEnabled = "mgl_LightsEnabled"; // int mgl_LightsEnabled[MAX_LIGHTS]; + + protected static final String mgl_ShadeModel = "mgl_ShadeModel"; // 1i + + protected static final String mgl_TexCoordEnabled = "mgl_TexCoordEnabled"; // int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS]; + protected static final String mgl_ActiveTexture = "mgl_ActiveTexture"; // 1i + protected static final String mgl_ActiveTextureIdx = "mgl_ActiveTextureIdx";// 1i + + protected static final String mgl_CullFace = "mgl_CullFace"; // 1i + + protected static final FloatBuffer zero4f = Buffers.newDirectFloatBuffer(new float[] { 0.0f, 0.0f, 0.0f, 0.0f }); + + public static final FloatBuffer defAmbient = Buffers.newDirectFloatBuffer(new float[] { 0f, 0f, 0f, 1f }); + public static final FloatBuffer defDiffuse = zero4f; + public static final FloatBuffer defSpecular= zero4f; + public static final FloatBuffer defPosition= Buffers.newDirectFloatBuffer(new float[] { 0f, 0f, 1f, 0f }); + public static final FloatBuffer defSpotDir = Buffers.newDirectFloatBuffer(new float[] { 0f, 0f, -1f }); + public static final float defSpotExponent = 0f; + public static final float defSpotCutoff = 180f; + public static final float defConstantAtten = 1f; + public static final float defLinearAtten = 0f; + public static final float defQuadraticAtten= 0f; + + public static final FloatBuffer defMatAmbient = Buffers.newDirectFloatBuffer(new float[] { 0.2f, 0.2f, 0.2f, 1.0f }); + public static final FloatBuffer defMatDiffuse = Buffers.newDirectFloatBuffer(new float[] { 0.8f, 0.8f, 0.8f, 1.0f }); + public static final FloatBuffer defMatSpecular= Buffers.newDirectFloatBuffer(new float[] { 0f, 0f, 0f, 1f}); + public static final FloatBuffer defMatEmission= Buffers.newDirectFloatBuffer(new float[] { 0f, 0f, 0f, 1f}); + public static final float defMatShininess = 0f; + + protected static final String vertexColorFileDef = "FixedFuncColor"; + protected static final String vertexColorLightFileDef = "FixedFuncColorLight"; + protected static final String fragmentColorFileDef = "FixedFuncColor"; + protected static final String fragmentColorTextureFileDef = "FixedFuncColorTexture"; + protected static final String shaderSrcRootDef = "shaders" ; + protected static final String shaderBinRootDef = "shaders/bin" ; +} + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp new file mode 100644 index 000000000..408ff7251 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp @@ -0,0 +1,16 @@ +#include es_precision.glsl + +#include mgl_uniform.glsl +#include mgl_varying.glsl + +void main (void) +{ + if( mgl_CullFace > 0 && + ( ( mgl_CullFace == 1 && gl_FrontFacing ) || + ( mgl_CullFace == 2 && !gl_FrontFacing ) || + ( mgl_CullFace == 3 ) ) ) { + discard; + } + gl_FragColor = frontColor; +} + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.vp new file mode 100644 index 000000000..346e40196 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.vp @@ -0,0 +1,22 @@ +#include es_precision.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_attribute.glsl +#include mgl_varying.glsl + +#include mgl_settexcoord.vp + +void main(void) +{ + if(mgl_ColorEnabled>0) { + frontColor=mgl_Color; + } else { + frontColor=mgl_ColorStatic; + } + + gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex; + + setTexCoord(gl_Position); +} + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp new file mode 100644 index 000000000..ce203cfb9 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp @@ -0,0 +1,70 @@ +#include es_precision.glsl +#include mgl_lightdef.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_uniform_light.glsl +#include mgl_attribute.glsl +#include mgl_varying.glsl + +#include mgl_settexcoord.vp + +void main(void) +{ + vec4 position; + vec3 normal, lightDir, cameraDir, halfDir; + vec4 ambient, diffuse, specular; + float NdotL, NdotHV, dist, attenuation; + int i; + + position = mgl_PMVMatrix[1] * mgl_Vertex; // vertex eye position + + normal = normalize(mgl_NormalMatrix * mgl_Normal); + // cameraPosition: (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz + cameraDir = normalize( (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz - mgl_Vertex.xyz ); + + ambient = vec4(0,0,0,0); + diffuse = vec4(0,0,0,0); + specular = vec4(0,0,0,0); + + bool lightEnabled = false; + + for(i=0; i<MAX_LIGHTS; i++) { + if( 0!= mgl_LightsEnabled[i] ) { + lightEnabled = true; + ambient += mgl_LightSource[i].ambient; + lightDir = mgl_LightSource[i].position.xyz - position.xyz; + dist = length(lightDir); + lightDir = normalize(lightDir); + attenuation = 1.0 / ( + mgl_LightSource[i].constantAttenuation+ + mgl_LightSource[i].linearAttenuation * dist + + mgl_LightSource[i].quadraticAttenuation * dist * dist ); + NdotL = max(0.0, dot(normal, lightDir)); + diffuse += mgl_LightSource[i].diffuse * NdotL * attenuation; + if (NdotL != 0.0) { + halfDir = normalize (lightDir + cameraDir); + NdotHV = max(0.0, dot(normal, halfDir)); + specular += mgl_LightSource[i].specular * + pow(NdotHV,mgl_FrontMaterial.shininess) * attenuation; + } + } + } + ambient += mgl_FrontMaterial.ambient; + diffuse *= mgl_FrontMaterial.diffuse; + specular *= mgl_FrontMaterial.specular; + + if(mgl_ColorEnabled>0) { + frontColor=mgl_Color; + } else { + frontColor=mgl_ColorStatic; + } + if( lightEnabled ) { + frontColor *= ambient + diffuse + specular; + } + + gl_Position = mgl_PMVMatrix[0] * position; + + setTexCoord(gl_Position); +} + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp new file mode 100644 index 000000000..86e6ace73 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp @@ -0,0 +1,47 @@ + +#include es_precision.glsl +#include mgl_lightdef.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_varying.glsl + +vec4 getTexColor(in sampler2D tex, in int idx) { + vec4 coord; + if(idx==0) { + coord= mgl_TexCoords[0]; + } else if(idx==1) { + coord= mgl_TexCoords[1]; + } else if(idx==2) { + coord= mgl_TexCoords[2]; + } else if(idx==3) { + coord= mgl_TexCoords[3]; + } else if(idx==4) { + coord= mgl_TexCoords[4]; + } else if(idx==5) { + coord= mgl_TexCoords[5]; + } else if(idx==6) { + coord= mgl_TexCoords[6]; + } else { + coord= mgl_TexCoords[7]; + } + return texture2D(tex, coord.st); +} + +void main (void) +{ + if( mgl_CullFace > 0 && + ( ( mgl_CullFace == 1 && gl_FrontFacing ) || + ( mgl_CullFace == 2 && !gl_FrontFacing ) || + ( mgl_CullFace == 3 ) ) ) { + discard; + } + + vec4 texColor = getTexColor(mgl_ActiveTexture,mgl_ActiveTextureIdx); + + if(length(texColor.rgb)>0.0) { + gl_FragColor = vec4(frontColor.rgb*texColor.rgb, frontColor.a) ; + } else { + gl_FragColor = frontColor; + } +} diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColor.bfp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColor.bfp Binary files differnew file mode 100644 index 000000000..3ebaaee1d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColor.bfp diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColor.bvp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColor.bvp Binary files differnew file mode 100644 index 000000000..279ef72c7 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColor.bvp diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColorLight.bvp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColorLight.bvp Binary files differnew file mode 100644 index 000000000..5a9deea71 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColorLight.bvp diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColorTexture.bfp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColorTexture.bfp Binary files differnew file mode 100644 index 000000000..ce1397fe1 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/bin/nvidia/FixedFuncColorTexture.bfp diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/es_precision.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/es_precision.glsl new file mode 100644 index 000000000..fd6abe54e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/es_precision.glsl @@ -0,0 +1,14 @@ +#ifndef es_precision_glsl +#define es_precision_glsl + +#ifdef GL_ES + #define MEDIUMP mediump + #define HIGHP highp + #define LOWP lowp +#else + #define MEDIUMP + #define HIGHP + #define LOWP +#endif + +#endif // es_precision_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl new file mode 100644 index 000000000..b09bdb05a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl @@ -0,0 +1,19 @@ + +#ifndef mgl_attribute_glsl +#define mgl_attribute_glsl + +#include es_precision.glsl + +attribute HIGHP vec4 mgl_Vertex; +attribute HIGHP vec3 mgl_Normal; +attribute HIGHP vec4 mgl_Color; +attribute HIGHP vec4 mgl_MultiTexCoord0; +attribute HIGHP vec4 mgl_MultiTexCoord1; +attribute HIGHP vec4 mgl_MultiTexCoord2; +attribute HIGHP vec4 mgl_MultiTexCoord3; +attribute HIGHP vec4 mgl_MultiTexCoord4; +attribute HIGHP vec4 mgl_MultiTexCoord5; +attribute HIGHP vec4 mgl_MultiTexCoord6; +attribute HIGHP vec4 mgl_MultiTexCoord7; + +#endif // mgl_attribute_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl new file mode 100644 index 000000000..1a464a1cb --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl @@ -0,0 +1,10 @@ + +#ifndef mgl_const_glsl +#define mgl_const_glsl + +#include es_precision.glsl + +const LOWP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits +const LOWP int MAX_LIGHTS = 8; + +#endif // mgl_const_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl new file mode 100644 index 000000000..98e214139 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl @@ -0,0 +1,26 @@ +#ifndef mgl_lightdef_glsl +#define mgl_lightdef_glsl + +struct mgl_LightSourceParameters { + vec4 ambient; + vec4 diffuse; + vec4 specular; + vec4 position; + // vec4 halfVector; // is computed here + vec3 spotDirection; + float spotExponent; + float spotCutoff; // (range: [0.0,90.0], 180.0) + //float spotCosCutoff; // (range: [1.0,0.0],-1.0) + float constantAttenuation; + float linearAttenuation; + float quadraticAttenuation; +}; +struct mgl_MaterialParameters { + vec4 ambient; + vec4 diffuse; + vec4 specular; + vec4 emission; + float shininess; +}; + +#endif // mgl_lightdef_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_settexcoord.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_settexcoord.vp new file mode 100644 index 000000000..1efe328d0 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_settexcoord.vp @@ -0,0 +1,35 @@ +#ifndef mgl_settexcoord_vp +#define mgl_settexcoord_vp + +#include es_precision.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_attribute.glsl +#include mgl_varying.glsl + +void setTexCoord(in vec4 defpos) { + /** + * bitwise operator not supported on APX 2500 ES 2.0 + * + mgl_TexCoords[0] = ( 0 != (mgl_TexCoordEnabled & 1) ) ? mgl_MultiTexCoord0 : defpos; + mgl_TexCoords[1] = ( 0 != (mgl_TexCoordEnabled & 2) ) ? mgl_MultiTexCoord1 : defpos; + mgl_TexCoords[2] = ( 0 != (mgl_TexCoordEnabled & 4) ) ? mgl_MultiTexCoord2 : defpos; + mgl_TexCoords[3] = ( 0 != (mgl_TexCoordEnabled & 8) ) ? mgl_MultiTexCoord3 : defpos; + mgl_TexCoords[4] = ( 0 != (mgl_TexCoordEnabled & 16) ) ? mgl_MultiTexCoord4 : defpos; + mgl_TexCoords[5] = ( 0 != (mgl_TexCoordEnabled & 32) ) ? mgl_MultiTexCoord5 : defpos; + mgl_TexCoords[6] = ( 0 != (mgl_TexCoordEnabled & 64) ) ? mgl_MultiTexCoord6 : defpos; + mgl_TexCoords[7] = ( 0 != (mgl_TexCoordEnabled & 128) ) ? mgl_MultiTexCoord7 : defpos; + */ + + mgl_TexCoords[0] = ( 0 != mgl_TexCoordEnabled[0] ) ? mgl_MultiTexCoord0 : defpos; + mgl_TexCoords[1] = ( 0 != mgl_TexCoordEnabled[1] ) ? mgl_MultiTexCoord1 : defpos; + mgl_TexCoords[2] = ( 0 != mgl_TexCoordEnabled[2] ) ? mgl_MultiTexCoord2 : defpos; + mgl_TexCoords[3] = ( 0 != mgl_TexCoordEnabled[3] ) ? mgl_MultiTexCoord3 : defpos; + mgl_TexCoords[4] = ( 0 != mgl_TexCoordEnabled[4] ) ? mgl_MultiTexCoord4 : defpos; + mgl_TexCoords[5] = ( 0 != mgl_TexCoordEnabled[5] ) ? mgl_MultiTexCoord5 : defpos; + mgl_TexCoords[6] = ( 0 != mgl_TexCoordEnabled[6] ) ? mgl_MultiTexCoord6 : defpos; + mgl_TexCoords[7] = ( 0 != mgl_TexCoordEnabled[7] ) ? mgl_MultiTexCoord7 : defpos; +} + +#endif // mgl_settexcoord_vp diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl new file mode 100644 index 000000000..d8b3c7f95 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl @@ -0,0 +1,18 @@ + +#ifndef mgl_uniform_glsl +#define mgl_uniform_glsl + +#include es_precision.glsl + +#include mgl_const.glsl + +uniform HIGHP mat4 mgl_PMVMatrix[3]; // P, Mv, and Mvi +uniform HIGHP mat3 mgl_NormalMatrix; // transpose(inverse(ModelView)).3x3 +uniform LOWP int mgl_ColorEnabled; +uniform HIGHP vec4 mgl_ColorStatic; +uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS]; +uniform sampler2D mgl_ActiveTexture; +uniform LOWP int mgl_ActiveTextureIdx; +uniform LOWP int mgl_CullFace; + +#endif // mgl_uniform_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl new file mode 100644 index 000000000..0dedb5d5d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl @@ -0,0 +1,15 @@ + +#ifndef mgl_uniform_light_glsl +#define mgl_uniform_light_glsl + +#include es_precision.glsl + +#include mgl_const.glsl +#include mgl_lightdef.glsl + +uniform LOWP int mgl_LightsEnabled[MAX_LIGHTS]; + +uniform mgl_LightSourceParameters mgl_LightSource[MAX_LIGHTS]; +uniform mgl_MaterialParameters mgl_FrontMaterial; + +#endif // mgl_uniform_light_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_varying.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_varying.glsl new file mode 100644 index 000000000..fc9f735d1 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_varying.glsl @@ -0,0 +1,12 @@ + +#ifndef mgl_varying_glsl +#define mgl_varying_glsl + +#include es_precision.glsl + +#include mgl_const.glsl + +varying vec4 frontColor; +varying vec4 mgl_TexCoords[MAX_TEXTURE_UNITS]; + +#endif // mgl_varying_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/scripts/nvidia-apx/glslc-ff.bat b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/scripts/nvidia-apx/glslc-ff.bat new file mode 100755 index 000000000..8a2114e07 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/scripts/nvidia-apx/glslc-ff.bat @@ -0,0 +1,9 @@ +REM +REM You have to call it from the 'shaders' directory, e.g.: +REM scripts\nvidia-apx\glslc-ff.bat +REM +IF !"%JOGLDIR%"==""! GOTO YESPATH +set JOGLDIR=..\lib +:YESPATH + +java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar com.jogamp.opengl.util.glsl.sdk.CompileShaderNVidia FixedFuncColor.fp FixedFuncColorTexture.fp FixedFuncColorLight.vp FixedFuncColor.vp diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/scripts/nvidia-apx/glslc.bat b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/scripts/nvidia-apx/glslc.bat new file mode 100755 index 000000000..c7ca0a8b7 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/scripts/nvidia-apx/glslc.bat @@ -0,0 +1,9 @@ +REM +REM You have to call it from the 'shaders' directory, e.g.: +REM scripts\nvidia-apx\glslc.bat <FileName> +REM +IF !"%JOGLDIR%"==""! GOTO YESPATH +set JOGLDIR=..\lib +:YESPATH + +java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar com.jogamp.opengl.util.glsl.sdk.CompileShaderNVidia %1 diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WGLGLCapabilities.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WGLGLCapabilities.java new file mode 100644 index 000000000..4b3cd0120 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WGLGLCapabilities.java @@ -0,0 +1,248 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl.windows.wgl; + +import java.util.Comparator; + +import jogamp.nativewindow.windows.GDI; +import jogamp.nativewindow.windows.PIXELFORMATDESCRIPTOR; +import javax.media.opengl.GL; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +public class WGLGLCapabilities extends GLCapabilities { + PIXELFORMATDESCRIPTOR pfd; + int pfdID; + int arb_pixelformat; // -1 PFD, 0 NOP, 1 ARB + + /** Comparing pfd id only */ + public static class PfdIDComparator implements Comparator { + + public int compare(Object o1, Object o2) { + if ( ! ( o1 instanceof WGLGLCapabilities ) ) { + Class c = (null != o1) ? o1.getClass() : null ; + throw new ClassCastException("arg1 not a WGLGLCapabilities object: " + c); + } + if ( ! ( o2 instanceof WGLGLCapabilities ) ) { + Class c = (null != o2) ? o2.getClass() : null ; + throw new ClassCastException("arg2 not a WGLGLCapabilities object: " + c); + } + + final WGLGLCapabilities caps1 = (WGLGLCapabilities) o1; + final long id1 = caps1.getPFDID(); + + final WGLGLCapabilities caps2 = (WGLGLCapabilities) o2; + final long id2 = caps2.getPFDID(); + + if(id1 > id2) { + return 1; + } else if(id1 < id2) { + return -1; + } + return 0; + } + } + + public WGLGLCapabilities(PIXELFORMATDESCRIPTOR pfd, int pfdID, GLProfile glp) { + super(glp); + this.pfd = pfd; + this.pfdID = pfdID; + this.arb_pixelformat = 0; + } + + public boolean setValuesByGDI() { + arb_pixelformat = -1; + + setRedBits(pfd.getCRedBits()); + setGreenBits(pfd.getCGreenBits()); + setBlueBits(pfd.getCBlueBits()); + setAlphaBits(pfd.getCAlphaBits()); + setAccumRedBits(pfd.getCAccumRedBits()); + setAccumGreenBits(pfd.getCAccumGreenBits()); + setAccumBlueBits(pfd.getCAccumBlueBits()); + setAccumAlphaBits(pfd.getCAccumAlphaBits()); + setDepthBits(pfd.getCDepthBits()); + setStencilBits(pfd.getCStencilBits()); + setDoubleBuffered((pfd.getDwFlags() & GDI.PFD_DOUBLEBUFFER) != 0); + setStereo((pfd.getDwFlags() & GDI.PFD_STEREO) != 0); + setHardwareAccelerated((pfd.getDwFlags() & GDI.PFD_GENERIC_FORMAT) == 0 + || (pfd.getDwFlags() & GDI.PFD_GENERIC_ACCELERATED) != 0); + // n/a with non ARB/GDI method: + // multisample + // opaque + // pbuffer + + return true; + } + + public boolean setValuesByARB(final int[] iattribs, final int niattribs, final int[] iresults) { + arb_pixelformat = 1; + + for (int i = 0; i < niattribs; i++) { + int attr = iattribs[i]; + switch (attr) { + case WGLExt.WGL_DRAW_TO_WINDOW_ARB: + case WGLExt.WGL_DRAW_TO_BITMAP_ARB: + case WGLExt.WGL_DRAW_TO_PBUFFER_ARB: + break; + + case WGLExt.WGL_ACCELERATION_ARB: + setHardwareAccelerated(iresults[i] == WGLExt.WGL_FULL_ACCELERATION_ARB); + break; + + case WGLExt.WGL_SUPPORT_OPENGL_ARB: + if (iresults[i] != GL.GL_TRUE) { + return false; + } + break; + + case WGLExt.WGL_DEPTH_BITS_ARB: + setDepthBits(iresults[i]); + break; + + case WGLExt.WGL_STENCIL_BITS_ARB: + setStencilBits(iresults[i]); + break; + + case WGLExt.WGL_DOUBLE_BUFFER_ARB: + setDoubleBuffered(iresults[i] == GL.GL_TRUE); + break; + + case WGLExt.WGL_STEREO_ARB: + setStereo(iresults[i] == GL.GL_TRUE); + break; + + case WGLExt.WGL_PIXEL_TYPE_ARB: + if(iresults[i] == WGLExt.WGL_TYPE_COLORINDEX_ARB) { + return false; // color index not supported + } + + if (iresults[i] == WGLExt.WGL_TYPE_RGBA_FLOAT_ARB) { + setPbufferFloatingPointBuffers(true); + } + + // normal RGBA FB: WGLExt.WGL_TYPE_RGBA_ARB + // ignore unknown results here + break; + + case WGLExt.WGL_FLOAT_COMPONENTS_NV: + if (iresults[i] != 0) { + setPbufferFloatingPointBuffers(true); + } + break; + + case WGLExt.WGL_RED_BITS_ARB: + setRedBits(iresults[i]); + break; + + case WGLExt.WGL_GREEN_BITS_ARB: + setGreenBits(iresults[i]); + break; + + case WGLExt.WGL_BLUE_BITS_ARB: + setBlueBits(iresults[i]); + break; + + case WGLExt.WGL_ALPHA_BITS_ARB: + setAlphaBits(iresults[i]); + break; + + case WGLExt.WGL_ACCUM_RED_BITS_ARB: + setAccumRedBits(iresults[i]); + break; + + case WGLExt.WGL_ACCUM_GREEN_BITS_ARB: + setAccumGreenBits(iresults[i]); + break; + + case WGLExt.WGL_ACCUM_BLUE_BITS_ARB: + setAccumBlueBits(iresults[i]); + break; + + case WGLExt.WGL_ACCUM_ALPHA_BITS_ARB: + setAccumAlphaBits(iresults[i]); + break; + + case WGLExt.WGL_SAMPLE_BUFFERS_ARB: + setSampleBuffers(iresults[i] != 0); + break; + + case WGLExt.WGL_SAMPLES_ARB: + setNumSamples(iresults[i]); + break; + + default: + throw new GLException("Unknown pixel format attribute " + iattribs[i]); + } + } + return true; + } + + public Object cloneMutable() { + return clone(); + } + + public Object clone() { + try { + return super.clone(); + } catch (RuntimeException e) { + throw new GLException(e); + } + } + + final public PIXELFORMATDESCRIPTOR getPFD() { return pfd; } + final public int getPFDID() { return pfdID; } + + final public boolean isSetByARB() { return 0 < arb_pixelformat; } + final public boolean isSetByGDI() { return 0 > arb_pixelformat; } + final public boolean isSet() { return 0 != arb_pixelformat; } + + public StringBuffer toString(StringBuffer sink) { + if(null == sink) { + sink = new StringBuffer(); + } + sink.append(pfdID).append(" "); + switch (arb_pixelformat) { + case -1: + sink.append("gdi"); + break; + case 0: + sink.append("nop"); + break; + case 1: + sink.append("arb"); + break; + default: + throw new InternalError("invalid arb_pixelformat: " + arb_pixelformat); + } + sink.append(": "); + return super.toString(sink); + } +}
\ No newline at end of file diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLContext.java new file mode 100644 index 000000000..68b26b30d --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLContext.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import javax.media.opengl.*; + +public class WindowsBitmapWGLContext extends WindowsWGLContext { + public WindowsBitmapWGLContext(WindowsBitmapWGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + public int getOffscreenContextPixelDataType() { + return GL.GL_UNSIGNED_BYTE; + } + + public int getOffscreenContextReadBuffer() { + // On Windows these contexts are always single-buffered + return GL.GL_FRONT; + } + + public boolean offscreenImageNeedsVerticalFlip() { + // We can take care of this in the DIB creation (see below) + return false; + } +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLDrawable.java new file mode 100644 index 000000000..4df3b7e34 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLDrawable.java @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import com.jogamp.common.nio.PointerBuffer; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.SurfaceChangeable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; + +import jogamp.nativewindow.windows.BITMAPINFO; +import jogamp.nativewindow.windows.BITMAPINFOHEADER; +import jogamp.nativewindow.windows.GDI; +import javax.media.opengl.GLCapabilitiesImmutable; + +public class WindowsBitmapWGLDrawable extends WindowsWGLDrawable { + private long origbitmap; + private long hbitmap; + + protected WindowsBitmapWGLDrawable(GLDrawableFactory factory, NativeSurface target) { + super(factory, target, true); + create(); + } + + protected void setRealizedImpl() { + if(realized) { + create(); + } else { + destroyImpl(); + } + } + + public GLContext createContext(GLContext shareWith) { + return new WindowsBitmapWGLContext(this, shareWith); + } + + private void create() { + int werr; + NativeSurface ns = getNativeSurface(); + if(DEBUG) { + System.err.println("WindowsBitmapWGLDrawable (1): "+ns); + } + WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)ns.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable)config.getRequestedCapabilities(); + int width = getWidth(); + int height = getHeight(); + + // + // 1. Create DIB Section + // + BITMAPINFO info = BITMAPINFO.create(); + BITMAPINFOHEADER header = info.getBmiHeader(); + int bitsPerPixel = (capabilities.getRedBits() + + capabilities.getGreenBits() + + capabilities.getBlueBits() + + capabilities.getAlphaBits()); + header.setBiSize(header.size()); + header.setBiWidth(width); + // NOTE: negating the height causes the DIB to be in top-down row + // order rather than bottom-up; ends up being correct during pixel + // readback + header.setBiHeight(-1 * height); + header.setBiPlanes((short) 1); + header.setBiBitCount((short) bitsPerPixel); + header.setBiXPelsPerMeter(0); + header.setBiYPelsPerMeter(0); + header.setBiClrUsed(0); + header.setBiClrImportant(0); + header.setBiCompression(GDI.BI_RGB); + int byteNum = width * height * ( bitsPerPixel >> 3 ) ; + header.setBiSizeImage(byteNum); + + PointerBuffer pb = PointerBuffer.allocateDirect(1); + hbitmap = GDI.CreateDIBSection(0, info, GDI.DIB_RGB_COLORS, pb, 0, 0); + werr = GDI.GetLastError(); + if(DEBUG) { + long p = ( pb.capacity() > 0 ) ? pb.get(0) : 0; + System.err.println("WindowsBitmapWGLDrawable: pb sz/ptr "+pb.capacity() + ", "+toHexString(p)); + System.err.println("WindowsBitmapWGLDrawable: " + width+"x"+height + + ", bpp " + bitsPerPixel + + ", bytes " + byteNum + + ", header sz " + header.size() + + ", DIB ptr num " + pb.capacity()+ + ", "+capabilities+ + ", werr "+werr); + } + if (hbitmap == 0) { + throw new GLException("Error creating offscreen bitmap of " + ns + ", werr " + werr); + } + + // + // 2. Create memory DC (device context) , and associate it with the DIB. + // + long hdc = GDI.CreateCompatibleDC(0); + werr = GDI.GetLastError(); + if (hdc == 0) { + GDI.DeleteObject(hbitmap); + hbitmap = 0; + throw new GLException("Error creating device context for offscreen OpenGL context, werr "+werr); + } + ((SurfaceChangeable)ns).setSurfaceHandle(hdc); + if(DEBUG) { + System.err.println("WindowsBitmapWGLDrawable (2): "+ns); + } + + if ((origbitmap = GDI.SelectObject(hdc, hbitmap)) == 0) { + GDI.DeleteObject(hbitmap); + hbitmap = 0; + GDI.DeleteDC(hdc); + hdc = 0; + throw new GLException("Error selecting bitmap into new device context"); + } + + config.updateGraphicsConfiguration(getFactory(), ns, null); + } + + protected void destroyImpl() { + NativeSurface ns = getNativeSurface(); + if (ns.getSurfaceHandle() != 0) { + // Must destroy bitmap and device context + GDI.SelectObject(ns.getSurfaceHandle(), origbitmap); + GDI.DeleteObject(hbitmap); + GDI.DeleteDC(ns.getSurfaceHandle()); + origbitmap = 0; + hbitmap = 0; + ((SurfaceChangeable)ns).setSurfaceHandle(0); + } + } + + protected void swapBuffersImpl() { + if(DEBUG) { + System.err.println("unhandled swapBuffersImpl() called for: "+this); + } + } + +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java new file mode 100644 index 000000000..3d0cce725 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLProfile; + +import javax.media.nativewindow.AbstractGraphicsScreen; +import jogamp.nativewindow.windows.GDI; +import javax.media.nativewindow.NativeSurface; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLException; +import jogamp.nativewindow.windows.GDISurface; + +public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { + private long hwnd; + private boolean handleHwndLifecycle; + + private WindowsDummyWGLDrawable(GLDrawableFactory factory, GDISurface ns, boolean handleHwndLifecycle) { + super(factory, ns, true); + this.handleHwndLifecycle = handleHwndLifecycle; + + if(NativeSurface.LOCK_SURFACE_NOT_READY >= ns.lockSurface()) { + throw new GLException("WindowsDummyWGLDrawable: surface not ready (lockSurface)"); + } + try { + WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)ns.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + config.updateGraphicsConfiguration(factory, ns, null); + if (DEBUG) { + System.err.println("!!! WindowsDummyWGLDrawable: "+config); + } + } catch (Throwable t) { + destroyImpl(); + throw new GLException(t); + } finally { + unlockSurface(); + } + } + + public static WindowsDummyWGLDrawable create(GLDrawableFactory factory, GLProfile glp, AbstractGraphicsScreen absScreen, + long windowHandle, int width, int height, boolean handleWindowLifecycle) { + if(0 == windowHandle) { + throw new GLException("Error windowHandle 0, werr: "+GDI.GetLastError()); + } + GLCapabilities caps = new GLCapabilities(glp); + WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(caps, absScreen); + GDISurface ns = new GDISurface(cfg, windowHandle); + ns.setSize(width, height); + return new WindowsDummyWGLDrawable(factory, ns, handleWindowLifecycle); + } + + public GLContext createContext(GLContext shareWith) { + // FIXME: figure out how to hook back in the Java 2D / JOGL bridge + return new WindowsWGLContext(this, shareWith); + } + + protected void destroyImpl() { + if (handleHwndLifecycle && hwnd != 0) { + GDI.ShowWindow(hwnd, GDI.SW_HIDE); + GDI.DestroyDummyWindow(hwnd); + hwnd = 0; + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java new file mode 100644 index 000000000..632b373af --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +import jogamp.nativewindow.WrappedSurface; +import jogamp.nativewindow.windows.GDI; +import jogamp.opengl.GLContextShareSet; + + +public class WindowsExternalWGLContext extends WindowsWGLContext { + private GLContext lastContext; + + private WindowsExternalWGLContext(Drawable drawable, long ctx, WindowsWGLGraphicsConfiguration cfg) { + super(drawable, null); + this.contextHandle = ctx; + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Created external OpenGL context " + toHexString(ctx) + " for " + this); + } + GLContextShareSet.contextCreated(this); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + getGLStateTracker().setEnabled(false); // external context usage can't track state in Java + } + + protected static WindowsExternalWGLContext create(GLDrawableFactory factory, GLProfile glp) { + if(DEBUG) { + System.err.println("WindowsExternalWGLContext 0: werr: " + GDI.GetLastError()); + } + + final long ctx = WGL.wglGetCurrentContext(); + if (0 == ctx) { + throw new GLException("Error: attempted to make an external GLContext without a context current, werr " + GDI.GetLastError()); + } + + final long hdc = WGL.wglGetCurrentDC(); + if (0 == hdc) { + throw new GLException("Error: attempted to make an external GLDrawable without a drawable current, werr " + GDI.GetLastError()); + } + AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); + WindowsWGLGraphicsConfiguration cfg; + final int pfdID = GDI.GetPixelFormat(hdc); + if (0 == pfdID) { + // This could have happened if the HDC was released right after the GL ctx made current (SWT), + // WinXP-32bit will not be able to use this HDC afterwards. + // Workaround: Use a fake default configuration + final int werr = GDI.GetLastError(); + cfg = WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(new GLCapabilities(GLProfile.getDefault()), aScreen); + cfg.markExternal(); + if(DEBUG) { + System.err.println("WindowsExternalWGLContext invalid hdc/pfd werr "+werr+", using default cfg: " + cfg); + } + } else { + cfg = WindowsWGLGraphicsConfiguration.createFromExternal(factory, hdc, pfdID, glp, aScreen, true); + if(DEBUG) { + System.err.println("WindowsExternalWGLContext valid hdc/pfd, retrieved cfg: " + cfg); + } + } + return new WindowsExternalWGLContext(new Drawable(factory, new WrappedSurface(cfg, hdc)), ctx, cfg); + } + + public int makeCurrent() throws GLException { + // Save last context if necessary to allow external GLContexts to + // talk to other GLContexts created by this library + GLContext cur = getCurrent(); + if (cur != null && cur != this) { + lastContext = cur; + setCurrent(null); + } + return super.makeCurrent(); + } + + public void release() throws GLException { + super.release(); + setCurrent(lastContext); + lastContext = null; + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + } + + protected void releaseImpl() throws GLException { + } + + protected void destroyImpl() throws GLException { + } + + // Need to provide the display connection to extension querying APIs + static class Drawable extends WindowsWGLDrawable { + Drawable(GLDrawableFactory factory, NativeSurface comp) { + super(factory, comp, true); + } + + public GLContext createContext(GLContext shareWith) { + throw new GLException("Should not call this"); + } + + public int getWidth() { + throw new GLException("Should not call this"); + } + + public int getHeight() { + throw new GLException("Should not call this"); + } + + public void setSize(int width, int height) { + throw new GLException("Should not call this"); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java new file mode 100644 index 000000000..ede504735 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +import jogamp.nativewindow.WrappedSurface; +import jogamp.nativewindow.windows.GDI; + +public class WindowsExternalWGLDrawable extends WindowsWGLDrawable { + + private WindowsExternalWGLDrawable(GLDrawableFactory factory, NativeSurface component) { + super(factory, component, true); + } + + protected static WindowsExternalWGLDrawable create(GLDrawableFactory factory, GLProfile glp) { + long hdc = WGL.wglGetCurrentDC(); + if (0==hdc) { + throw new GLException("Error: attempted to make an external GLDrawable without a drawable current, werr " + GDI.GetLastError()); + } + int pfdID = GDI.GetPixelFormat(hdc); + if (pfdID == 0) { + throw new GLException("Error: attempted to make an external GLContext without a valid pixelformat, werr " + GDI.GetLastError()); + } + + AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); + WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfiguration.createFromExternal(factory, hdc, pfdID, glp, aScreen, true); + return new WindowsExternalWGLDrawable(factory, new WrappedSurface(cfg, hdc)); + } + + + public GLContext createContext(GLContext shareWith) { + return new WindowsWGLContext(this, shareWith); + } + + public void setSize(int newWidth, int newHeight) { + throw new GLException("Should not call this"); + } + + public int getWidth() { + throw new GLException("Should not call this"); + } + + public int getHeight() { + throw new GLException("Should not call this"); + } +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLContext.java new file mode 100644 index 000000000..a06ab8f0e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLContext.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import java.util.*; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import jogamp.opengl.*; + +public class WindowsOnscreenWGLContext extends WindowsWGLContext { + public WindowsOnscreenWGLContext(WindowsOnscreenWGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + } +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLDrawable.java new file mode 100644 index 000000000..4f34c946a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLDrawable.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import jogamp.opengl.*; + +public class WindowsOnscreenWGLDrawable extends WindowsWGLDrawable { + protected WindowsOnscreenWGLDrawable(GLDrawableFactory factory, NativeSurface component) { + super(factory, component, false); + } + + public GLContext createContext(GLContext shareWith) { + return new WindowsOnscreenWGLContext(this, shareWith); + } + +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLContext.java new file mode 100644 index 000000000..97c63ea52 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLContext.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import javax.media.opengl.*; + +public class WindowsPbufferWGLContext extends WindowsWGLContext { + // State for render-to-texture and render-to-texture-rectangle support + private boolean rtt; // render-to-texture? + private boolean hasRTT; // render-to-texture extension available? + private boolean rect; // render-to-texture-rectangle? + private int textureTarget; // e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV + private int texture; // actual texture object + + protected WindowsPbufferWGLContext(WindowsPbufferWGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + public void bindPbufferToTexture() { + if (!rtt) { + throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + + "specified in its GLCapabilities"); + } + GL gl = getGL(); + WGLExt wglExt = getWGLExt(); + gl.glBindTexture(textureTarget, texture); + if (rtt && hasRTT) { + if (!wglExt.wglBindTexImageARB(((WindowsPbufferWGLDrawable)drawable).getPbufferHandle(), WGLExt.WGL_FRONT_LEFT_ARB)) { + throw new GLException("Binding of pbuffer to texture failed: " + wglGetLastError()); + } + } + // FIXME: comment is wrong now + // Note that if the render-to-texture extension is not supported, + // we perform a glCopyTexImage2D in swapBuffers(). + } + + public void releasePbufferFromTexture() { + if (!rtt) { + throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + + "specified in its GLCapabilities"); + } + if (rtt && hasRTT) { + WGLExt wglExt = getWGLExt(); + if (!wglExt.wglReleaseTexImageARB(((WindowsPbufferWGLDrawable)drawable).getPbufferHandle(), WGLExt.WGL_FRONT_LEFT_ARB)) { + throw new GLException("Releasing of pbuffer from texture failed: " + wglGetLastError()); + } + } + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + super.makeCurrentImpl(newCreated); + if (newCreated) { + GLCapabilitiesImmutable capabilities = drawable.getChosenGLCapabilities(); + + // Initialize render-to-texture support if requested + GL gl = getGL(); + rtt = capabilities.getPbufferRenderToTexture(); + rect = gl.isGL2GL3() && capabilities.getPbufferRenderToTextureRectangle(); + + if (rtt) { + if (DEBUG) { + System.err.println("Initializing render-to-texture support"); + } + + if (!gl.isExtensionAvailable("WGL_ARB_render_texture")) { + System.err.println("WindowsPbufferWGLContext: WARNING: WGL_ARB_render_texture extension not " + + "supported; implementing render_to_texture support using slow texture readback"); + } else { + hasRTT = true; + + if (rect && !gl.isExtensionAvailable("GL_NV_texture_rectangle")) { + System.err.println("WindowsPbufferWGLContext: WARNING: GL_NV_texture_rectangle extension not " + + "supported; skipping requested render_to_texture_rectangle support for pbuffer"); + rect = false; + } + if (rect) { + if (DEBUG) { + System.err.println(" Using render-to-texture-rectangle"); + } + textureTarget = GL2.GL_TEXTURE_RECTANGLE_ARB; + } else { + if (DEBUG) { + System.err.println(" Using vanilla render-to-texture"); + } + textureTarget = GL.GL_TEXTURE_2D; + } + int[] tmp = new int[1]; + gl.glGenTextures(1, tmp, 0); + texture = tmp[0]; + gl.glBindTexture(textureTarget, texture); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); + gl.glCopyTexImage2D(textureTarget, 0, GL.GL_RGB, 0, 0, drawable.getWidth(), drawable.getHeight(), 0); + } + } + } + } + + public int getFloatingPointMode() { + return ((WindowsPbufferWGLDrawable)drawable).getFloatingPointMode(); + } + + private static String wglGetLastError() { + return WindowsWGLDrawableFactory.wglGetLastError(); + } +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java new file mode 100644 index 000000000..83354a7fb --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.SurfaceChangeable; +import javax.media.opengl.GL; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; + +import jogamp.nativewindow.windows.GDI; +import javax.media.opengl.GLCapabilitiesImmutable; + +public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { + private WGLExt cachedWGLExt; // cached WGLExt instance from parent GLCanvas, + // needed to destroy pbuffer + private long buffer; // pbuffer handle + + private int floatMode; + + protected WindowsPbufferWGLDrawable(GLDrawableFactory factory, NativeSurface target, + WindowsWGLDrawableFactory.SharedResource sharedResource) { + super(factory, target, true); + + if (DEBUG) { + System.out.println("Pbuffer config: " + getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration()); + } + + createPbuffer(sharedResource); + + if (DEBUG) { + System.err.println("Created pbuffer " + this); + } + } + + protected void setRealizedImpl() { + if(realized) { + throw new GLException("Recreation via setRealized not supported."); + } else { + destroyImpl(); + } + } + + public GLContext createContext(GLContext shareWith) { + return new WindowsPbufferWGLContext(this, shareWith); + } + + protected void destroyImpl() { + NativeSurface ns = getNativeSurface(); + if(0!=buffer) { + WGLExt wglExt = cachedWGLExt; + if (ns.getSurfaceHandle() != 0) { + // Must release DC and pbuffer + // NOTE that since the context is not current, glGetError() can + // not be called here, so we skip the use of any composable + // pipelines (see WindowsOnscreenWGLContext.makeCurrentImpl) + if (wglExt.wglReleasePbufferDCARB(buffer, ns.getSurfaceHandle()) == 0) { + throw new GLException("Error releasing pbuffer device context: error code " + GDI.GetLastError()); + } + ((SurfaceChangeable)ns).setSurfaceHandle(0); + } + if (!wglExt.wglDestroyPbufferARB(buffer)) { + throw new GLException("Error destroying pbuffer: error code " + GDI.GetLastError()); + } + buffer = 0; + } + } + + public long getPbufferHandle() { + // The actual to-be-used handle for makeCurrent etc, + // is the derived DC, set in the NativeSurface surfaceHandle + // returned by getHandle(). + return buffer; + } + + public int getFloatingPointMode() { + return floatMode; + } + + protected void swapBuffersImpl() { + if(DEBUG) { + System.err.println("unhandled swapBuffersImpl() called for: "+this); + } + } + + private void createPbuffer(WindowsWGLDrawableFactory.SharedResource sharedResource) { + long parentHdc = sharedResource.getDrawable().getNativeSurface().getSurfaceHandle(); + WGLExt wglExt = sharedResource.getContext().getWGLExt(); + + int[] iattributes = new int [2*WindowsWGLGraphicsConfiguration.MAX_ATTRIBS]; + float[] fattributes = new float[1]; + int[] floatModeTmp = new int[1]; + int niattribs = 0; + int width, height; + + WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration) getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable)config.getChosenCapabilities(); + GLProfile glProfile = chosenCaps.getGLProfile(); + + if (DEBUG) { + System.out.println("Pbuffer parentHdc = " + toHexString(parentHdc)); + System.out.println("Pbuffer chosenCaps: " + chosenCaps); + } + + if(!WindowsWGLGraphicsConfiguration.GLCapabilities2AttribList(chosenCaps, + iattributes, sharedResource, -1, floatModeTmp)){ + throw new GLException("Pbuffer-related extensions not supported"); + } + + floatMode = floatModeTmp[0]; + boolean rtt = chosenCaps.getPbufferRenderToTexture(); + boolean rect = chosenCaps.getPbufferRenderToTextureRectangle(); + boolean useFloat = chosenCaps.getPbufferFloatingPointBuffers(); + boolean ati = false; + + if (useFloat) { + ati = (floatMode == GLPbuffer.ATI_FLOAT); + } + + int[] pformats = new int[WindowsWGLGraphicsConfiguration.MAX_PFORMATS]; + int nformats; + int[] nformatsTmp = new int[1]; + if (!wglExt.wglChoosePixelFormatARB(parentHdc, + iattributes, 0, + fattributes, 0, + WindowsWGLGraphicsConfiguration.MAX_PFORMATS, + pformats, 0, + nformatsTmp, 0)) { + throw new GLException("pbuffer creation error: wglChoosePixelFormat() failed"); + } + nformats = nformatsTmp[0]; + if (nformats <= 0) { + throw new GLException("pbuffer creation error: Couldn't find a suitable pixel format"); + } + + if (DEBUG) { + System.err.println("" + nformats + " suitable pixel formats found"); + for (int i = 0; i < nformats; i++) { + WGLGLCapabilities dbgCaps = WindowsWGLGraphicsConfiguration.wglARBPFID2GLCapabilities(sharedResource, parentHdc, pformats[i], glProfile, false, true); + System.err.println("pixel format " + pformats[i] + " (index " + i + "): " + dbgCaps); + } + } + + int pfdid = 0; + long tmpBuffer = 0; + { + int whichFormat; + // Loop is a workaround for bugs in NVidia's recent drivers + for (whichFormat = 0; whichFormat < nformats; whichFormat++) { + int format = pformats[whichFormat]; + + // Create the p-buffer. + niattribs = 0; + + if (rtt) { + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FORMAT_ARB; + if (useFloat) { + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FLOAT_RGB_NV; + } else { + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_RGBA_ARB; + } + + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_TARGET_ARB; + iattributes[niattribs++] = rect ? WGLExt.WGL_TEXTURE_RECTANGLE_NV : WGLExt.WGL_TEXTURE_2D_ARB; + + iattributes[niattribs++] = WGLExt.WGL_MIPMAP_TEXTURE_ARB; + iattributes[niattribs++] = GL.GL_FALSE; + + iattributes[niattribs++] = WGLExt.WGL_PBUFFER_LARGEST_ARB; + iattributes[niattribs++] = GL.GL_FALSE; + } + + iattributes[niattribs++] = 0; + + tmpBuffer = wglExt.wglCreatePbufferARB(parentHdc, format, getWidth(), getHeight(), iattributes, 0); + if (tmpBuffer != 0) { + // Done + break; + } + } + + if (0 == tmpBuffer) { + throw new GLException("pbuffer creation error: wglCreatePbuffer() failed: tried " + nformats + + " pixel formats, last error was: " + wglGetLastError()); + } + pfdid = pformats[whichFormat]; + } + + // Get the device context. + long tmpHdc = wglExt.wglGetPbufferDCARB(tmpBuffer); + if (tmpHdc == 0) { + throw new GLException("pbuffer creation error: wglGetPbufferDC() failed"); + } + + NativeSurface ns = getNativeSurface(); + // Set up instance variables + buffer = tmpBuffer; + ((SurfaceChangeable)ns).setSurfaceHandle(tmpHdc); + cachedWGLExt = wglExt; + + // Re-query chosen pixel format + { + WGLGLCapabilities newCaps = WindowsWGLGraphicsConfiguration.wglARBPFID2GLCapabilities(sharedResource, parentHdc, pfdid, glProfile, false, true); + if(null == newCaps) { + throw new GLException("pbuffer creation error: unable to re-query chosen PFD ID: " + pfdid + ", hdc " + this.toHexString(tmpHdc)); + } + if(newCaps.isOnscreen() || !newCaps.isPBuffer()) { + throw new GLException("Error: Selected Onscreen Caps for PBuffer: "+newCaps); + } + config.setCapsPFD(newCaps); + } + + // Determine the actual width and height we were able to create. + int[] tmp = new int[1]; + wglExt.wglQueryPbufferARB( buffer, WGLExt.WGL_PBUFFER_WIDTH_ARB, tmp, 0 ); + width = tmp[0]; + wglExt.wglQueryPbufferARB( buffer, WGLExt.WGL_PBUFFER_HEIGHT_ARB, tmp, 0 ); + height = tmp[0]; + ((SurfaceChangeable)ns).setSize(width, height); + } + + private static String wglGetLastError() { + return WindowsWGLDrawableFactory.wglGetLastError(); + } +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java new file mode 100644 index 000000000..94017e79a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java @@ -0,0 +1,478 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLException; +import javax.media.opengl.GLCapabilitiesImmutable; + +import com.jogamp.gluegen.runtime.ProcAddressTable; +import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver; +import jogamp.nativewindow.windows.GDI; +import jogamp.opengl.GLContextImpl; +import jogamp.opengl.GLContextShareSet; +import jogamp.opengl.GLDrawableImpl; + +public class WindowsWGLContext extends GLContextImpl { + static final Map/*<String, String>*/ functionNameMap; + static final Map/*<String, String>*/ extensionNameMap; + private boolean wglGetExtensionsStringEXTInitialized; + private boolean wglGetExtensionsStringEXTAvailable; + private boolean wglGLReadDrawableAvailableSet; + private boolean wglGLReadDrawableAvailable; + private WGLExt wglExt; + // Table that holds the addresses of the native C-language entry points for + // WGL extension functions. + private WGLExtProcAddressTable wglExtProcAddressTable; + + static { + functionNameMap = new HashMap(); + functionNameMap.put("glAllocateMemoryNV", "wglAllocateMemoryNV"); + functionNameMap.put("glFreeMemoryNV", "wglFreeMemoryNV"); + + extensionNameMap = new HashMap(); + extensionNameMap.put("GL_ARB_pbuffer", "WGL_ARB_pbuffer"); + extensionNameMap.put("GL_ARB_pixel_format", "WGL_ARB_pixel_format"); + } + + // FIXME: figure out how to hook back in the Java 2D / JOGL bridge + WindowsWGLContext(GLDrawableImpl drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + protected void resetState() { + wglGetExtensionsStringEXTInitialized=false; + wglGetExtensionsStringEXTAvailable=false; + wglGLReadDrawableAvailableSet=false; + wglGLReadDrawableAvailable=false; + // no inner state _wglExt=null; + wglExtProcAddressTable=null; + } + + public Object getPlatformGLExtensions() { + return getWGLExt(); + } + + /* package private */ final WGLExt getWGLExt() { + if( null == getWGLExtProcAddressTable()) { + throw new InternalError("Null WGLExtProcAddressTable"); + } + if (wglExt == null) { + wglExt = new WGLExtImpl(this); + } + return wglExt; + } + + public final boolean isGLReadDrawableAvailable() { + if(!wglGLReadDrawableAvailableSet && null != getWGLExtProcAddressTable()) { + WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); + AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice device = config.getScreen().getDevice(); + switch( factory.isReadDrawableAvailable(device) ) { + case 1: + wglGLReadDrawableAvailable = true; + wglGLReadDrawableAvailableSet=true; + break; + case 0: + wglGLReadDrawableAvailable = false; + wglGLReadDrawableAvailableSet=true; + break; + } + } + return wglGLReadDrawableAvailable; + } + + private final boolean wglMakeContextCurrent(long hDrawDC, long hReadDC, long ctx) { + boolean ok = false; + if(wglGLReadDrawableAvailable) { + // needs initilized WGL ProcAddress table + ok = getWGLExt().wglMakeContextCurrent(hDrawDC, hReadDC, ctx); + } else if ( hDrawDC == hReadDC ) { + ok = WGL.wglMakeCurrent(hDrawDC, ctx); + } else { + // should not happen due to 'isGLReadDrawableAvailable()' query in GLContextImpl + throw new InternalError("Given readDrawable but no driver support"); + } + int werr = ( !ok ) ? GDI.GetLastError() : GDI.ERROR_SUCCESS; + if(DEBUG && !ok) { + Throwable t = new Throwable ("Info: wglMakeContextCurrent draw "+ + this.toHexString(hDrawDC) + ", read " + this.toHexString(hReadDC) + + ", ctx " + this.toHexString(ctx) + ", werr " + werr); + t.printStackTrace(); + } + if(!ok && 0==hDrawDC && 0==hReadDC) { + // Some GPU's falsely fails with a zero error code (success), + // in case this is a release context request we tolerate this + return werr == GDI.ERROR_SUCCESS ; + } + return ok; + } + + public final ProcAddressTable getPlatformExtProcAddressTable() { + return getWGLExtProcAddressTable(); + } + + public final WGLExtProcAddressTable getWGLExtProcAddressTable() { + return wglExtProcAddressTable; + } + + protected Map/*<String, String>*/ getFunctionNameMap() { return functionNameMap; } + + protected Map/*<String, String>*/ getExtensionNameMap() { return extensionNameMap; } + + protected void destroyContextARBImpl(long context) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(context); + } + + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + if( null == getWGLExtProcAddressTable()) { + updateGLXProcAddressTable(); + } + WGLExt _wglExt = getWGLExt(); + if(DEBUG) { + System.err.println(getThreadName()+" - WindowWGLContext.createContextARBImpl: "+getGLVersion(major, minor, ctp, "@creation") + + ", handle "+toHexString(drawable.getHandle()) + ", share "+toHexString(share)+", direct "+direct+ + ", wglCreateContextAttribsARB: "+toHexString(wglExtProcAddressTable._addressof_wglCreateContextAttribsARB)); + Thread.dumpStack(); + } + + boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; + boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ; + boolean ctDebug = 0 != ( CTX_OPTION_DEBUG & ctp ) ; + + long ctx=0; + + final int idx_flags = 4; + final int idx_profile = 6; + + /* WGLExt.WGL_CONTEXT_LAYER_PLANE_ARB, WGLExt.WGL_CONTEXT_LAYER_PLANE_ARB, */ + + int attribs[] = { + /* 0 */ WGLExt.WGL_CONTEXT_MAJOR_VERSION_ARB, major, + /* 2 */ WGLExt.WGL_CONTEXT_MINOR_VERSION_ARB, minor, + /* 4 */ WGLExt.WGL_CONTEXT_FLAGS_ARB, 0, + /* 6 */ 0, 0, + /* 8 */ 0 + }; + + if ( major > 3 || major == 3 && minor >= 2 ) { + // FIXME: Verify with a None drawable binding (default framebuffer) + attribs[idx_profile+0] = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB; + if( ctBwdCompat ) { + attribs[idx_profile+1] = WGLExt.WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; + } else { + attribs[idx_profile+1] = WGLExt.WGL_CONTEXT_CORE_PROFILE_BIT_ARB; + } + } + + if ( major >= 3 ) { + if( !ctBwdCompat && ctFwdCompat ) { + attribs[idx_flags+1] |= WGLExt.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; + } + if( ctDebug) { + attribs[idx_flags+1] |= WGLExt.WGL_CONTEXT_DEBUG_BIT_ARB; + } + } + + try { + ctx = _wglExt.wglCreateContextAttribsARB(drawable.getHandle(), share, attribs, 0); + } catch (RuntimeException re) { + if(DEBUG) { + Throwable t = new Throwable("Info: WindowWGLContext.createContextARBImpl wglCreateContextAttribsARB failed with "+getGLVersion(major, minor, ctp, "@creation"), re); + t.printStackTrace(); + } + } + + if(0!=ctx) { + if (!wglMakeContextCurrent(drawable.getHandle(), drawableRead.getHandle(), ctx)) { + if(DEBUG) { + System.err.println("WindowsWGLContext.createContextARB couldn't make current "+getGLVersion(major, minor, ctp, "@creation")); + } + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(ctx); + ctx = 0; + } else { + if (DEBUG) { + System.err.println(getThreadName() + ": createContextARBImpl: OK "+getGLVersion(major, minor, ctp, "@creation")+", share "+share+", direct "+direct); + } + // the following is issued by the caller 'GLContextImpl.createContextARB()' + // setGLFunctionAvailability(true, major, minor, ctp); + } + } else if (DEBUG) { + System.err.println(getThreadName() + ": createContextARBImpl: NO "+getGLVersion(major, minor, ctp, "@creation")); + } + return ctx; + } + + /** + * Creates and initializes an appropriate OpenGL context. Should only be + * called by {@link #makeCurrentImpl()}. + */ + protected boolean createImpl() { + WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); + AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice device = config.getScreen().getDevice(); + WindowsWGLContext sharedContext = (WindowsWGLContext) factory.getOrCreateSharedContextImpl(device); + GLCapabilitiesImmutable glCaps = drawable.getChosenGLCapabilities(); + + isGLReadDrawableAvailable(); // trigger setup wglGLReadDrawableAvailable + + // Windows can set up sharing of display lists after creation time + WindowsWGLContext other = (WindowsWGLContext) GLContextShareSet.getShareContext(this); + long share = 0; + if (other != null) { + share = other.getHandle(); + if (share == 0) { + throw new GLException("GLContextShareSet returned an invalid OpenGL context"); + } + } + + int minor[] = new int[1]; + int major[] = new int[1]; + int ctp[] = new int[1]; + boolean createContextARBTried = false; + + // utilize the shared context's GLXExt in case it was using the ARB method and it already exists + if( null!=sharedContext && sharedContext.isCreatedWithARBMethod() ) { + contextHandle = createContextARB(share, true, major, minor, ctp); + createContextARBTried = true; + if (DEBUG && 0!=contextHandle) { + System.err.println(getThreadName() + ": createImpl: OK (ARB, using sharedContext) share "+share); + } + } + + long temp_ctx = 0; + if(0==contextHandle) { + // To use WGL_ARB_create_context, we have to make a temp context current, + // so we are able to use GetProcAddress + temp_ctx = WGL.wglCreateContext(drawable.getHandle()); + if (temp_ctx == 0) { + throw new GLException("Unable to create temp OpenGL context for device context " + toHexString(drawable.getHandle())); + } + if (!WGL.wglMakeCurrent(drawable.getHandle(), temp_ctx)) { + throw new GLException("Error making temp context current: 0x" + toHexString(temp_ctx) + ", werr: "+GDI.GetLastError()); + } + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + boolean isCreateContextAttribsARBAvailable = isFunctionAvailable("wglCreateContextAttribsARB"); + WGL.wglMakeCurrent(0, 0); // release temp context + + if( !createContextARBTried) { + if(isCreateContextAttribsARBAvailable && + isExtensionAvailable("WGL_ARB_create_context") ) { + // initial ARB context creation + contextHandle = createContextARB(share, true, major, minor, ctp); + createContextARBTried=true; + if (DEBUG) { + if(0!=contextHandle) { + System.err.println(getThreadName() + ": createContextImpl: OK (ARB, initial) share "+share); + } else { + System.err.println(getThreadName() + ": createContextImpl: NOT OK (ARB, initial) - creation failed - share "+share); + } + } + } else if (DEBUG) { + System.err.println(getThreadName() + ": createContextImpl: NOT OK (ARB, initial) - extension not available - share "+share); + } + } + } + + if(0!=contextHandle) { + share = 0; // mark as shared thx to the ARB create method + if(0!=temp_ctx) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(temp_ctx); + if (!wglMakeContextCurrent(drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { + throw new GLException("Cannot make previous verified context current: 0x" + toHexString(contextHandle) + ", werr: " + GDI.GetLastError()); + } + } + } else { + if(glCaps.getGLProfile().isGL3()) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(temp_ctx); + throw new GLException("WindowsWGLContext.createContext failed, but context > GL2 requested "+getGLVersion(major[0], minor[0], ctp[0], "@creation")+", "); + } + if(DEBUG) { + System.err.println("WindowsWGLContext.createContext failed, fall back to !ARB context "+getGLVersion(major[0], minor[0], ctp[0], "@creation")); + } + + // continue with temp context for GL < 3.0 + contextHandle = temp_ctx; + if (!wglMakeContextCurrent(drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(contextHandle); + throw new GLException("Error making old context current: 0x" + toHexString(contextHandle) + ", werr: " + GDI.GetLastError()); + } + if (DEBUG) { + System.err.println(getThreadName() + ": createImpl: OK (old) share "+share); + } + } + + if(0!=share) { + if (!WGL.wglShareLists(share, contextHandle)) { + throw new GLException("wglShareLists(" + toHexString(share) + + ", " + toHexString(contextHandle) + ") failed: werr " + GDI.GetLastError()); + } + } + return true; + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + if (WGL.wglGetCurrentContext() != contextHandle) { + if (!wglMakeContextCurrent(drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { + throw new GLException("Error making context current: 0x" + toHexString(contextHandle) + ", werr: " + GDI.GetLastError() + ", " + this); + } else { + if (DEBUG && newCreated) { + System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + toHexString(drawable.getHandle()) + + ", contextHandle " + toHexString(contextHandle) + ") succeeded"); + } + } + } + } + + protected void releaseImpl() throws GLException { + if (!wglMakeContextCurrent(0, 0, 0)) { + throw new GLException("Error freeing OpenGL context, werr: " + GDI.GetLastError()); + } + } + + protected void destroyImpl() throws GLException { + WGL.wglMakeCurrent(0, 0); + if (!WGL.wglDeleteContext(contextHandle)) { + throw new GLException("Unable to delete OpenGL context"); + } + } + + protected void copyImpl(GLContext source, int mask) throws GLException { + if (!WGL.wglCopyContext(source.getHandle(), getHandle(), mask)) { + throw new GLException("wglCopyContext failed"); + } + } + + protected final void updateGLXProcAddressTable() { + AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); + String key = adevice.getUniqueID(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Initializing WGL extension address table: "+key); + } + wglGetExtensionsStringEXTInitialized=false; + wglGetExtensionsStringEXTAvailable=false; + wglGLReadDrawableAvailableSet=false; + wglGLReadDrawableAvailable=false; + + WGLExtProcAddressTable table = null; + synchronized(mappedContextTypeObjectLock) { + table = (WGLExtProcAddressTable) mappedGLXProcAddress.get( key ); + } + if(null != table) { + wglExtProcAddressTable = table; + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext WGL ProcAddressTable reusing key("+key+") -> "+table.hashCode()); + } + } else { + if (wglExtProcAddressTable == null) { + // FIXME: cache ProcAddressTables by OpenGL context type bits so we can + // share them among contexts classes (GL4, GL4bc, GL3, GL3bc, ..) + wglExtProcAddressTable = new WGLExtProcAddressTable(new GLProcAddressResolver()); + } + resetProcAddressTable(wglExtProcAddressTable); + synchronized(mappedContextTypeObjectLock) { + mappedGLXProcAddress.put(key, getWGLExtProcAddressTable()); + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext WGL ProcAddressTable mapping key("+key+") -> "+getWGLExtProcAddressTable().hashCode()); + } + } + } + } + + public String getPlatformExtensionsString() { + if (!wglGetExtensionsStringEXTInitialized) { + wglGetExtensionsStringEXTAvailable = (WGL.wglGetProcAddress("wglGetExtensionsStringEXT") != 0); + wglGetExtensionsStringEXTInitialized = true; + } + if (wglGetExtensionsStringEXTAvailable) { + return getWGLExt().wglGetExtensionsStringEXT(); + } else { + return ""; + } + } + + protected void setSwapIntervalImpl(int interval) { + WGLExt wglExt = getWGLExt(); + if (wglExt.isExtensionAvailable("WGL_EXT_swap_control")) { + if ( wglExt.wglSwapIntervalEXT(interval) ) { + currentSwapInterval = interval ; + } + } + } + + public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return getWGLExt().wglAllocateMemoryNV(arg0, arg1, arg2, arg3); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawable.java new file mode 100644 index 000000000..4ed9a00c3 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawable.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import java.security.AccessController; +import javax.media.nativewindow.NativeSurface; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; + +import jogamp.nativewindow.windows.GDI; +import jogamp.opengl.Debug; +import jogamp.opengl.GLDrawableImpl; +import jogamp.opengl.GLDynamicLookupHelper; + + +public abstract class WindowsWGLDrawable extends GLDrawableImpl { + private static final boolean PROFILING = Debug.isPropertyDefined("jogl.debug.GLDrawable.profiling", true, AccessController.getContext()); + private static final int PROFILING_TICKS = 200; + private int profilingSwapBuffersTicks; + private long profilingSwapBuffersTime; + + public WindowsWGLDrawable(GLDrawableFactory factory, NativeSurface comp, boolean realized) { + super(factory, comp, realized); + } + + protected void setRealizedImpl() { + if(!realized) { + return; // nothing todo .. + } + + NativeSurface ns = getNativeSurface(); + WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)ns.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + config.updateGraphicsConfiguration(getFactory(), ns, null); + if (DEBUG) { + System.err.println("!!! WindowsWGLDrawable.setRealized(true): "+config); + } + } + + protected void swapBuffersImpl() { + long startTime = 0; + if (PROFILING) { + startTime = System.currentTimeMillis(); + } + + if (!GDI.SwapBuffers(getHandle()) && (GDI.GetLastError() != GDI.ERROR_SUCCESS)) { + throw new GLException("Error swapping buffers"); + } + + if (PROFILING) { + long endTime = System.currentTimeMillis(); + profilingSwapBuffersTime += (endTime - startTime); + int ticks = PROFILING_TICKS; + if (++profilingSwapBuffersTicks == ticks) { + System.err.println("SwapBuffers calls: " + profilingSwapBuffersTime + " ms / " + ticks + " calls (" + + ((float) profilingSwapBuffersTime / (float) ticks) + " ms/call)"); + profilingSwapBuffersTime = 0; + profilingSwapBuffersTicks = 0; + } + } + } + + public GLDynamicLookupHelper getGLDynamicLookupHelper() { + return getFactoryImpl().getGLDynamicLookupHelper(0); + } + + static String getThreadName() { + return Thread.currentThread().getName(); + } +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java new file mode 100644 index 000000000..248dfa482 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java @@ -0,0 +1,590 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.windows.wgl; + +import java.nio.Buffer; +import java.nio.ShortBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.ProxySurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.windows.WindowsGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.opengl.GL; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.nio.PointerBuffer; +import com.jogamp.common.os.Platform; +import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.common.util.VersionNumber; + +import jogamp.nativewindow.WrappedSurface; +import jogamp.nativewindow.windows.GDI; +import jogamp.nativewindow.windows.GDISurface; +import jogamp.nativewindow.windows.RegisteredClassFactory; +import jogamp.opengl.DesktopGLDynamicLookupHelper; +import jogamp.opengl.GLDrawableFactoryImpl; +import jogamp.opengl.GLDrawableImpl; +import jogamp.opengl.GLDynamicLookupHelper; +import jogamp.opengl.SharedResourceRunner; + +public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { + private static final DesktopGLDynamicLookupHelper windowsWGLDynamicLookupHelper; + + static { + DesktopGLDynamicLookupHelper tmp = null; + try { + tmp = new DesktopGLDynamicLookupHelper(new WindowsWGLDynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + windowsWGLDynamicLookupHelper = tmp; + if(null!=windowsWGLDynamicLookupHelper) { + WGL.getWGLProcAddressTable().reset(windowsWGLDynamicLookupHelper); + } + } + + public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { + return windowsWGLDynamicLookupHelper; + } + + public WindowsWGLDrawableFactory() { + super(); + + // Register our GraphicsConfigurationFactory implementations + // The act of constructing them causes them to be registered + new WindowsWGLGraphicsConfigurationFactory(); + if(GLProfile.isAWTAvailable()) { + try { + ReflectionUtil.createInstance("jogamp.opengl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory", + null, getClass().getClassLoader()); + } catch (JogampRuntimeException jre) { /* n/a .. */ } + } + + defaultDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + + // Init shared resources off thread + // Will be released via ShutdownHook + sharedResourceImpl = new SharedResourceImplementation(); + sharedResourceRunner = new SharedResourceRunner(sharedResourceImpl); + sharedResourceThread = new Thread(sharedResourceRunner, Thread.currentThread().getName()+"-SharedResourceRunner"); + sharedResourceThread.setDaemon(true); // Allow JVM to exit, even if this one is running + sharedResourceThread.start(); + } + + WindowsGraphicsDevice defaultDevice; + SharedResourceImplementation sharedResourceImpl; + SharedResourceRunner sharedResourceRunner; + Thread sharedResourceThread; + HashMap/*<connection, SharedResource>*/ sharedMap = new HashMap(); + + long processAffinityChanges = 0; + PointerBuffer procMask = PointerBuffer.allocateDirect(1); + PointerBuffer sysMask = PointerBuffer.allocateDirect(1); + + protected void enterThreadCriticalZone() { + synchronized (sysMask) { + if( 0 == processAffinityChanges) { + long pid = GDI.GetCurrentProcess(); + if ( GDI.GetProcessAffinityMask(pid, procMask, sysMask) ) { + if(DEBUG) { + System.err.println("WindowsWGLDrawableFactory.enterThreadCriticalZone() - 0x" + Long.toHexString(pid) + " - " + Thread.currentThread().getName()); + Thread.dumpStack(); + } + processAffinityChanges = pid; + GDI.SetProcessAffinityMask(pid, 1); + } + } + } + } + + protected void leaveThreadCriticalZone() { + synchronized (sysMask) { + if( 0 != processAffinityChanges) { + long pid = GDI.GetCurrentProcess(); + if( pid != processAffinityChanges) { + throw new GLException("PID doesn't match: set PID 0x" + Long.toHexString(processAffinityChanges) + + " this PID 0x" + Long.toHexString(pid) ); + } + if(DEBUG) { + System.err.println("WindowsWGLDrawableFactory.leaveThreadCriticalZone() - 0x" + Long.toHexString(pid) + " - " + Thread.currentThread().getName()); + } + GDI.SetProcessAffinityMask(pid, sysMask.get(0)); + } + } + } + + /** + * http://msdn.microsoft.com/en-us/library/ms724832%28v=vs.85%29.aspx + * Windows XP 5.1 + */ + static final VersionNumber winXPVersionNumber = new VersionNumber ( 5, 1, 0); + + static class SharedResource implements SharedResourceRunner.Resource { + private WindowsGraphicsDevice device; + private AbstractGraphicsScreen screen; + private WindowsDummyWGLDrawable drawable; + private WindowsWGLContext context; + private boolean hasARBPixelFormat; + private boolean hasARBMultisample; + private boolean hasARBPBuffer; + private boolean hasARBReadDrawable; + private String vendor; + private boolean isVendorATI; + private boolean isVendorNVIDIA; + private boolean needsCurrenContext4ARBPFDQueries; + + SharedResource(WindowsGraphicsDevice dev, AbstractGraphicsScreen scrn, WindowsDummyWGLDrawable draw, WindowsWGLContext ctx, + boolean arbPixelFormat, boolean arbMultisample, boolean arbPBuffer, boolean arbReadDrawable, String glVendor) { + device = dev; + screen = scrn; + drawable = draw; + context = ctx; + hasARBPixelFormat = arbPixelFormat; + hasARBMultisample = arbMultisample; + hasARBPBuffer = arbPBuffer; + hasARBReadDrawable = arbReadDrawable; + vendor = glVendor; + if(null != vendor) { + isVendorNVIDIA = vendor.startsWith("NVIDIA") ; + isVendorATI = vendor.startsWith("ATI") ; + } + + if ( isVendorATI() ) { + final VersionNumber winVersion = new VersionNumber(Platform.getOSVersion(), "."); + final boolean isWinXPOrLess = winVersion.compareTo(winXPVersionNumber) <= 0; + if(DEBUG) { + System.err.println("needsCurrenContext4ARBPFDQueries: "+winVersion+" <= "+winXPVersionNumber+" = "+isWinXPOrLess+" - "+Platform.getOSVersion()); + } + needsCurrenContext4ARBPFDQueries = isWinXPOrLess; + } else { + if(DEBUG) { + System.err.println("needsCurrenContext4ARBPFDQueries: false"); + } + needsCurrenContext4ARBPFDQueries = false; + } + } + + final public AbstractGraphicsDevice getDevice() { return device; } + final public AbstractGraphicsScreen getScreen() { return screen; } + final public WindowsWGLDrawable getDrawable() { return drawable; } + final public WindowsWGLContext getContext() { return context; } + + final boolean hasARBPixelFormat() { return hasARBPixelFormat; } + final boolean hasARBMultisample() { return hasARBMultisample; } + final boolean hasARBPBuffer() { return hasARBPBuffer; } + final boolean hasReadDrawable() { return hasARBReadDrawable; } + + final String vendor() { return vendor; } + final boolean isVendorATI() { return isVendorATI; } + final boolean isVendorNVIDIA() { return isVendorNVIDIA; } + + /** + * Solves bug #480 + * + * TODO: Validate if bug is actually relates to the 'old' ATI Windows driver for old GPU's like X300 etc + * and unrelated to the actual Windows version ! + * + * @return true if GL_VENDOR is ATI _and_ platform is Windows version XP or less! + */ + final boolean needsCurrentContext4ARBPFDQueries() { return needsCurrenContext4ARBPFDQueries; } + } + + class SharedResourceImplementation implements SharedResourceRunner.Implementation { + public void clear() { + synchronized(sharedMap) { + sharedMap.clear(); + } + } + public SharedResourceRunner.Resource mapPut(String connection, SharedResourceRunner.Resource resource) { + synchronized(sharedMap) { + return (SharedResourceRunner.Resource) sharedMap.put(connection, resource); + } + } + public SharedResourceRunner.Resource mapGet(String connection) { + synchronized(sharedMap) { + return (SharedResourceRunner.Resource) sharedMap.get(connection); + } + } + public Collection/*<Resource>*/ mapValues() { + synchronized(sharedMap) { + return sharedMap.values(); + } + } + + public SharedResourceRunner.Resource createSharedResource(String connection) { + WindowsGraphicsDevice sharedDevice = new WindowsGraphicsDevice(connection, AbstractGraphicsDevice.DEFAULT_UNIT); + sharedDevice.lock(); + try { + AbstractGraphicsScreen absScreen = new DefaultGraphicsScreen(sharedDevice, 0); + if (null == absScreen) { + throw new GLException("Couldn't create shared screen for device: "+sharedDevice+", idx 0"); + } + GLProfile glp = GLProfile.getMinDesktop(sharedDevice); + if (null == glp) { + throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice); + } + final int f_dim = 64; + long hwnd = GDI.CreateDummyWindow(0, 0, f_dim, f_dim); + WindowsDummyWGLDrawable sharedDrawable = WindowsDummyWGLDrawable.create(WindowsWGLDrawableFactory.this, glp, absScreen, hwnd, f_dim, f_dim, true); + if (null == sharedDrawable) { + throw new GLException("Couldn't create shared drawable for screen: "+absScreen+", "+glp); + } + WindowsWGLContext sharedContext = (WindowsWGLContext) sharedDrawable.createContext(null); + if (null == sharedContext) { + throw new GLException("Couldn't create shared context for drawable: "+sharedDrawable); + } + sharedContext.setSynchronized(true); + boolean hasARBPixelFormat; + boolean hasARBMultisample; + boolean hasARBPBuffer; + boolean hasARBReadDrawableAvailable; + String vendor; + sharedContext.makeCurrent(); + try { + hasARBPixelFormat = sharedContext.isExtensionAvailable(WGL_ARB_pixel_format); + hasARBMultisample = sharedContext.isExtensionAvailable(WGL_ARB_multisample); + hasARBPBuffer = sharedContext.isExtensionAvailable(GL_ARB_pbuffer); + hasARBReadDrawableAvailable = sharedContext.isExtensionAvailable(WGL_ARB_make_current_read) && + sharedContext.isFunctionAvailable(wglMakeContextCurrent); + vendor = sharedContext.getGL().glGetString(GL.GL_VENDOR); + } finally { + sharedContext.release(); + } + if (DEBUG) { + System.err.println("!!! SharedDevice: " + sharedDevice); + System.err.println("!!! SharedScreen: " + absScreen); + System.err.println("!!! SharedContext: " + sharedContext); + System.err.println("!!! pixelformat: " + hasARBPixelFormat); + System.err.println("!!! multisample: " + hasARBMultisample); + System.err.println("!!! pbuffer: " + hasARBPBuffer); + System.err.println("!!! readDrawable: " + hasARBReadDrawableAvailable); + System.err.println("!!! vendor: " + vendor); + } + return new SharedResource(sharedDevice, absScreen, sharedDrawable, sharedContext, + hasARBPixelFormat, hasARBMultisample, + hasARBPBuffer, hasARBReadDrawableAvailable, vendor); + } catch (Throwable t) { + throw new GLException("WindowsWGLDrawableFactory - Could not initialize shared resources for "+connection, t); + } finally { + sharedDevice.unlock(); + } + } + + public void releaseSharedResource(SharedResourceRunner.Resource shared) { + SharedResource sr = (SharedResource) shared; + if (DEBUG) { + System.err.println("!!! Shutdown Shared:"); + System.err.println("!!! Device : " + sr.device); + System.err.println("!!! Screen : " + sr.screen); + System.err.println("!!! Drawable: " + sr.drawable); + System.err.println("!!! CTX : " + sr.context); + } + + if (null != sr.context) { + // may cause JVM SIGSEGV: sharedContext.destroy(); + sr.context = null; + } + + if (null != sr.drawable) { + sr.drawable.destroy(); + sr.drawable = null; + } + + if (null != sr.screen) { + sr.screen = null; + } + + if (null != sr.device) { + sr.device.close(); + sr.device = null; + } + } + } + + public final AbstractGraphicsDevice getDefaultDevice() { + return defaultDevice; + } + + public final boolean getIsDeviceCompatible(AbstractGraphicsDevice device) { + if(device instanceof WindowsGraphicsDevice) { + return true; + } + return false; + } + + final static String GL_ARB_pbuffer = "GL_ARB_pbuffer"; + final static String WGL_ARB_pixel_format = "WGL_ARB_pixel_format"; + final static String WGL_ARB_multisample = "WGL_ARB_multisample"; + final static String WGL_NV_float_buffer = "WGL_NV_float_buffer"; + final static String WGL_ARB_make_current_read = "WGL_ARB_make_current_read"; + final static String wglMakeContextCurrent = "wglMakeContextCurrent"; + + protected final GLContext getSharedContextImpl(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getShared(device); + if(null!=sr) { + return sr.getContext(); + } + return null; + } + + protected final boolean hasSharedContextImpl(AbstractGraphicsDevice device) { + return null != getSharedContextImpl(device); + } + + protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.getContext(); + } + return null; + } + + protected AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.getDevice(); + } + return null; + } + + protected WindowsWGLDrawable getOrCreateSharedDrawable(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return (WindowsWGLDrawable) sr.getDrawable(); + } + return null; + } + + SharedResource getOrCreateSharedResource(AbstractGraphicsDevice device) { + return (SharedResource) sharedResourceRunner.getOrCreateShared(device); + } + + protected final void shutdownInstance() { + sharedResourceRunner.releaseAndWait(); + RegisteredClassFactory.shutdownSharedClasses(); + } + + protected List/*GLCapabilitiesImmutable*/ getAvailableCapabilitiesImpl(AbstractGraphicsDevice device) { + return WindowsWGLGraphicsConfigurationFactory.getAvailableCapabilities(this, device); + } + + protected final GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + return new WindowsOnscreenWGLDrawable(this, target); + } + + protected final GLDrawableImpl createOffscreenDrawableImpl(final NativeSurface target) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(!chosenCaps.isPBuffer()) { + return new WindowsBitmapWGLDrawable(this, target); + } + + // PBuffer GLDrawable Creation + final AbstractGraphicsDevice device = config.getScreen().getDevice(); + + final SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); + if(null==sr) { + throw new IllegalArgumentException("No shared resource for "+device); + } + final List returnList = new ArrayList(); + Runnable r = new Runnable() { + public void run() { + GLContext lastContext = GLContext.getCurrent(); + if (lastContext != null) { + lastContext.release(); + } + sr.context.makeCurrent(); + try { + GLDrawableImpl pbufferDrawable = new WindowsPbufferWGLDrawable(WindowsWGLDrawableFactory.this, target, sr); + returnList.add(pbufferDrawable); + } finally { + sr.context.release(); + if (lastContext != null) { + lastContext.makeCurrent(); + } + } + } + }; + maybeDoSingleThreadedWorkaround(r); + return (GLDrawableImpl) returnList.get(0); + } + + /** + * @return 1 if read drawable extension is available, 0 if not + * and -1 if undefined yet, ie no shared device exist at this point. + */ + public final int isReadDrawableAvailable(AbstractGraphicsDevice device) { + SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared((null!=device)?device:defaultDevice); + if(null!=sr) { + return sr.hasReadDrawable() ? 1 : 0 ; + } + return -1; // undefined + } + + public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared((null!=device)?device:defaultDevice); + if(null!=sr) { + return sr.hasARBPBuffer(); + } + return false; + } + + protected final NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { + AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); + WrappedSurface ns = new WrappedSurface(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( + capsChosen, capsRequested, chooser, screen) ); + ns.setSize(width, height); + return ns; + } + + protected final ProxySurface createProxySurfaceImpl(AbstractGraphicsDevice adevice, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser) { + // FIXME device/windowHandle -> screen ?! + WindowsGraphicsDevice device = (WindowsGraphicsDevice) adevice; + AbstractGraphicsScreen screen = new DefaultGraphicsScreen(device, 0); + WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsRequested, capsRequested, chooser, screen); + GDISurface ns = new GDISurface(cfg, windowHandle); + return ns; + } + + protected final GLContext createExternalGLContextImpl() { + return WindowsExternalWGLContext.create(this, null); + } + + public final boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { + return true; + } + + protected final GLDrawable createExternalGLDrawableImpl() { + return WindowsExternalWGLDrawable.create(this, null); + } + + static String wglGetLastError() { + long err = GDI.GetLastError(); + String detail = null; + switch ((int) err) { + case GDI.ERROR_SUCCESS: detail = "ERROR_SUCCESS"; break; + case GDI.ERROR_INVALID_PIXEL_FORMAT: detail = "ERROR_INVALID_PIXEL_FORMAT"; break; + case GDI.ERROR_NO_SYSTEM_RESOURCES: detail = "ERROR_NO_SYSTEM_RESOURCES"; break; + case GDI.ERROR_INVALID_DATA: detail = "ERROR_INVALID_DATA"; break; + case GDI.ERROR_PROC_NOT_FOUND: detail = "ERROR_PROC_NOT_FOUND"; break; + case GDI.ERROR_INVALID_WINDOW_HANDLE:detail = "ERROR_INVALID_WINDOW_HANDLE"; break; + default: detail = "(Unknown error code " + err + ")"; break; + } + return detail; + } + + public final boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { + return false; + } + + public final GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) + throws GLException { + throw new GLException("Unimplemented on this platform"); + } + + //------------------------------------------------------ + // Gamma-related functionality + // + + private static final int GAMMA_RAMP_LENGTH = 256; + + protected final int getGammaRampLength() { + return GAMMA_RAMP_LENGTH; + } + + protected final boolean setGammaRamp(float[] ramp) { + short[] rampData = new short[3 * GAMMA_RAMP_LENGTH]; + for (int i = 0; i < GAMMA_RAMP_LENGTH; i++) { + short scaledValue = (short) (ramp[i] * 65535); + rampData[i] = scaledValue; + rampData[i + GAMMA_RAMP_LENGTH] = scaledValue; + rampData[i + 2 * GAMMA_RAMP_LENGTH] = scaledValue; + } + + long screenDC = GDI.GetDC(0); + boolean res = GDI.SetDeviceGammaRamp(screenDC, ShortBuffer.wrap(rampData)); + GDI.ReleaseDC(0, screenDC); + return res; + } + + protected final Buffer getGammaRamp() { + ShortBuffer rampData = ShortBuffer.wrap(new short[3 * GAMMA_RAMP_LENGTH]); + long screenDC = GDI.GetDC(0); + boolean res = GDI.GetDeviceGammaRamp(screenDC, rampData); + GDI.ReleaseDC(0, screenDC); + if (!res) { + return null; + } + return rampData; + } + + protected final void resetGammaRamp(Buffer originalGammaRamp) { + if (originalGammaRamp == null) { + // getGammaRamp failed earlier + return; + } + long screenDC = GDI.GetDC(0); + GDI.SetDeviceGammaRamp(screenDC, originalGammaRamp); + GDI.ReleaseDC(0, screenDC); + } +} diff --git a/src/jogamp/graph/font/FontInt.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDynamicLibraryBundleInfo.java index 4d9390da2..0fb7f4510 100644 --- a/src/jogamp/graph/font/FontInt.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDynamicLibraryBundleInfo.java @@ -1,16 +1,16 @@ /** - * Copyright 2011 JogAmp Community. All rights reserved. + * 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 @@ -20,31 +20,39 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package jogamp.graph.font; + +package jogamp.opengl.windows.wgl; + +import jogamp.opengl.*; +import java.util.*; -import jogamp.graph.geom.plane.AffineTransform; -import jogamp.graph.geom.plane.Path2D; +public class WindowsWGLDynamicLibraryBundleInfo extends DesktopGLDynamicLibraryBundleInfo { + protected WindowsWGLDynamicLibraryBundleInfo() { + super(); + } -import com.jogamp.graph.font.Font; + public List getToolLibNames() { + List/*<String>*/ libNamesList = new ArrayList(); -public interface FontInt extends Font { + libNamesList.add("OpenGL32"); - public interface Glyph extends Font.Glyph { - // reserved special glyph IDs - // http://scripts.sil.org/cms/scripts/page.php?item_id=IWS-Chapter08#ba57949e - public static final int ID_UNKNOWN = 0; - public static final int ID_CR = 2; - public static final int ID_SPACE = 3; - - public Path2D getPath(); // unscaled path - public Path2D getPath(float pixelSize); + return libNamesList; } - public void getOutline(String string, float pixelSize, - AffineTransform transform, Path2D[] result); + + public final List getToolGetProcAddressFuncNameList() { + List res = new ArrayList(); + res.add("wglGetProcAddress"); + return res; + } + + public final long toolDynamicLookupFunction(long toolGetProcAddressHandle, String funcName) { + return WGL.wglGetProcAddress(toolGetProcAddressHandle, funcName); + } } + diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java new file mode 100644 index 000000000..1899f5212 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java @@ -0,0 +1,741 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.windows.wgl; + +import java.util.ArrayList; +import java.util.List; + +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.DefaultGraphicsConfiguration; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.opengl.GL; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; + +import jogamp.nativewindow.windows.GDI; +import jogamp.nativewindow.windows.PIXELFORMATDESCRIPTOR; +import jogamp.opengl.GLGraphicsConfigurationUtil; + +public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable { + // Keep this under the same debug flag as the drawable factory for convenience + protected static final boolean DEBUG = jogamp.opengl.Debug.debug("GraphicsConfiguration"); + + protected static final int MAX_PFORMATS = 256; + protected static final int MAX_ATTRIBS = 256; + + private GLCapabilitiesChooser chooser; + private boolean isDetermined = false; + private boolean isExternal = false; + + WindowsWGLGraphicsConfiguration(AbstractGraphicsScreen screen, + GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser) { + super(screen, capsChosen, capsRequested); + this.chooser=chooser; + this.isDetermined = false; + } + + WindowsWGLGraphicsConfiguration(AbstractGraphicsScreen screen, + WGLGLCapabilities capsChosen, GLCapabilitiesImmutable capsRequested) { + super(screen, capsChosen, capsRequested); + setCapsPFD(capsChosen); + this.chooser=null; + } + + + static WindowsWGLGraphicsConfiguration createFromExternal(GLDrawableFactory _factory, long hdc, int pfdID, + GLProfile glp, AbstractGraphicsScreen screen, boolean onscreen) + { + if(_factory==null) { + throw new GLException("Null factory"); + } + if(hdc==0) { + throw new GLException("Null HDC"); + } + if(pfdID<=0) { + throw new GLException("Invalid pixelformat id "+pfdID); + } + if(null==glp) { + glp = GLProfile.getDefault(screen.getDevice()); + } + WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory) _factory; + AbstractGraphicsDevice device = screen.getDevice(); + WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResource(device); + boolean hasARB = null != sharedResource && sharedResource.hasARBPixelFormat(); + + WGLGLCapabilities caps = null; + + if(hasARB) { + caps = wglARBPFID2GLCapabilities(sharedResource, hdc, pfdID, glp, onscreen, true /* pbuffer */); + } else { + caps = PFD2GLCapabilities(glp, hdc, pfdID, onscreen); + } + if(null==caps) { + throw new GLException("Couldn't choose Capabilities by: HDC 0x"+Long.toHexString(hdc)+ + ", pfdID "+pfdID+", onscreen "+onscreen+", hasARB "+hasARB); + } + + WindowsWGLGraphicsConfiguration cfg = new WindowsWGLGraphicsConfiguration(screen, caps, caps); + cfg.markExternal(); + return cfg; + } + + public Object clone() { + return super.clone(); + } + + /** + * Updates the graphics configuration in case it has been determined yet.<br> + * Uses the NativeSurface's HDC.<br> + * Ensures that a PIXELFORMAT is set. + * + * @param factory + * @param ns + * @param pfIDs optional pool of preselected PixelFormat IDs, maybe null for unrestricted selection + * + * @see #isDetermined() + * @see #isExternal() + */ + public final void updateGraphicsConfiguration(GLDrawableFactory factory, NativeSurface ns, int[] pfIDs) { + WindowsWGLGraphicsConfigurationFactory.updateGraphicsConfiguration(chooser, factory, ns, pfIDs); + } + + /** + * Preselect the graphics configuration in case it has been determined yet.<br> + * Uses a shared device's HDC and the given pfdIDs to preselect the pfd. + * No PIXELFORMAT is set. + * + * @param factory + * @param pfIDs optional pool of preselected PixelFormat IDs, maybe null for unrestricted selection + * + * @see #isDetermined() + */ + public final void preselectGraphicsConfiguration(GLDrawableFactory factory, int[] pfdIDs) { + AbstractGraphicsDevice device = getNativeGraphicsConfiguration().getScreen().getDevice(); + WindowsWGLGraphicsConfigurationFactory.preselectGraphicsConfiguration(chooser, factory, device, this, pfdIDs); + } + + /** + * Sets the hdc's PixelFormat, this configuration's capabilities and marks it as determined. + */ + final void setPixelFormat(long hdc, WGLGLCapabilities caps) { + if (0 == hdc) { + throw new GLException("Error: HDC is null"); + } + + if (!GDI.SetPixelFormat(hdc, caps.getPFDID(), caps.getPFD())) { + throw new GLException("Unable to set pixel format " + caps + + " for device context " + toHexString(hdc) + + ": error code " + GDI.GetLastError()); + } + if (DEBUG) { + System.err.println("!!! setPixelFormat (ARB): hdc "+toHexString(hdc) +", "+caps); + } + setCapsPFD(caps); + } + + /** + * Only sets this configuration's capabilities and marks it as determined, + * the actual pixelformat is not set. + */ + final void setCapsPFD(WGLGLCapabilities caps) { + setChosenCapabilities(caps); + this.isDetermined = true; + if (DEBUG) { + System.err.println("*** setCapsPFD: "+caps); + } + } + + /** + * External configuration's HDC pixelformat shall not be modified + */ + public final boolean isExternal() { return isExternal; } + + final void markExternal() { + this.isExternal=true; + } + + /** + * Determined configuration states set target capabilties via {@link #setCapsPFD(WGLGLCapabilities)}, + * but does not imply a set pixelformat. + * + * @see #setPixelFormat(long, WGLGLCapabilities) + * @see #setCapsPFD(WGLGLCapabilities) + */ + public final boolean isDetermined() { return isDetermined; } + + public final PIXELFORMATDESCRIPTOR getPixelFormat() { return isDetermined ? ((WGLGLCapabilities)capabilitiesChosen).getPFD() : null; } + public final int getPixelFormatID() { return isDetermined ? ((WGLGLCapabilities)capabilitiesChosen).getPFDID() : 0; } + public final boolean isChoosenByARB() { return isDetermined ? ((WGLGLCapabilities)capabilitiesChosen).isSetByARB() : false; } + + static int fillAttribsForGeneralWGLARBQuery(WindowsWGLDrawableFactory.SharedResource sharedResource, int[] iattributes) { + int niattribs = 0; + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW_ARB; + if(sharedResource.hasARBPBuffer()) { + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_PBUFFER_ARB; + } + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_BITMAP_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCELERATION_ARB; + iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB; + iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB; + iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB; + iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB; + if(sharedResource.hasARBMultisample()) { + iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB; + iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB; + } + + if(sharedResource.hasARBPBuffer()) { + WindowsWGLContext sharedCtx = sharedResource.getContext(); + if(null != sharedCtx && sharedCtx.isExtensionAvailable(WindowsWGLDrawableFactory.WGL_NV_float_buffer)) { + // pbo float buffer + iattributes[niattribs++] = WGLExt.WGL_FLOAT_COMPONENTS_NV; // nvidia + } + } + + return niattribs; + } + + static boolean wglARBPFIDValid(WindowsWGLContext sharedCtx, long hdc, int pfdID) { + int[] in = new int[1]; + int[] out = new int[1]; + in[0] = WGLExt.WGL_COLOR_BITS_ARB; + if (!sharedCtx.getWGLExt().wglGetPixelFormatAttribivARB(hdc, pfdID, 0, 1, in, 0, out, 0)) { + // Some GPU's falsely fails with a zero error code (success) + return GDI.GetLastError() == GDI.ERROR_SUCCESS ; + } + return true; + } + + static int[] wglAllARBPFIDs(WindowsWGLContext sharedCtx, long hdc) { + int[] iattributes = new int[1]; + int[] iresults = new int[1]; + + WGLExt wglExt = sharedCtx.getWGLExt(); + iattributes[0] = WGLExt.WGL_NUMBER_PIXEL_FORMATS_ARB; + if (!wglExt.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, 0, iresults, 0)) { + if(DEBUG) { + System.err.println("GetPixelFormatAttribivARB: Failed - HDC 0x" + Long.toHexString(hdc) + + ", LastError: " + GDI.GetLastError()); + Thread.dumpStack(); + } + return null; + } + int numFormats = iresults[0]; + if(0 == numFormats) { + if(DEBUG) { + System.err.println("GetPixelFormatAttribivARB: No formats - HDC 0x" + Long.toHexString(hdc) + + ", LastError: " + GDI.GetLastError()); + Thread.dumpStack(); + } + return null; + } + int[] pfdIDs = new int[numFormats]; + for (int i = 0; i < numFormats; i++) { + pfdIDs[i] = 1 + i; + } + return pfdIDs; + } + + static WGLGLCapabilities wglARBPFID2GLCapabilities(WindowsWGLDrawableFactory.SharedResource sharedResource, + long hdc, int pfdID, + GLProfile glp, boolean onscreen, boolean usePBuffer) { + if (!sharedResource.hasARBPixelFormat()) { + return null; + } + + int[] iattributes = new int [2*MAX_ATTRIBS]; + int[] iresults = new int [2*MAX_ATTRIBS]; + + int niattribs = fillAttribsForGeneralWGLARBQuery(sharedResource, iattributes); + + if (!sharedResource.getContext().getWGLExt().wglGetPixelFormatAttribivARB(hdc, pfdID, 0, niattribs, iattributes, 0, iresults, 0)) { + throw new GLException("wglARBPFID2GLCapabilities: Error getting pixel format attributes for pixel format " + pfdID + + " of device context " + toHexString(hdc) + ", werr " + GDI.GetLastError()); + } + ArrayList bucket = new ArrayList(1); + final int winattrbits = GLGraphicsConfigurationUtil.getWinAttributeBits(onscreen, usePBuffer); + if(AttribList2GLCapabilities(bucket, glp, hdc, pfdID, iattributes, niattribs, iresults, winattrbits)) { + return (WGLGLCapabilities) bucket.get(0); + } + return null; + } + + static int[] wglChoosePixelFormatARB(long hdc, WindowsWGLDrawableFactory.SharedResource sharedResource, + GLCapabilitiesImmutable capabilities, + int[] iattributes, int accelerationMode, float[] fattributes) + { + + if ( !WindowsWGLGraphicsConfiguration.GLCapabilities2AttribList(capabilities, + iattributes, sharedResource, accelerationMode, null)) + { + if (DEBUG) { + System.err.println("wglChoosePixelFormatARB: GLCapabilities2AttribList failed: " + GDI.GetLastError()); + Thread.dumpStack(); + } + return null; + } + + int[] pformatsTmp = new int[WindowsWGLGraphicsConfiguration.MAX_PFORMATS]; + int[] numFormatsTmp = new int[1]; + if ( !sharedResource.getContext().getWGLExt().wglChoosePixelFormatARB(hdc, iattributes, 0, + fattributes, 0, + WindowsWGLGraphicsConfiguration.MAX_PFORMATS, + pformatsTmp, 0, numFormatsTmp, 0)) + { + if (DEBUG) { + System.err.println("wglChoosePixelFormatARB: wglChoosePixelFormatARB failed: " + GDI.GetLastError()); + Thread.dumpStack(); + } + return null; + } + int numFormats = numFormatsTmp[0]; + int[] pformats = null; + if( 0 < numFormats ) { + pformats = new int[numFormats]; + System.arraycopy(pformatsTmp, 0, pformats, 0, numFormats); + } + if (DEBUG) { + System.err.println("wglChoosePixelFormatARB: NumFormats (wglChoosePixelFormatARB) accelMode 0x" + + Integer.toHexString(accelerationMode) + ": " + numFormats); + for (int i = 0; i < numFormats; i++) { + WGLGLCapabilities dbgCaps0 = WindowsWGLGraphicsConfiguration.wglARBPFID2GLCapabilities( + sharedResource, hdc, pformats[i], + capabilities.getGLProfile(), capabilities.isOnscreen(), capabilities.isPBuffer()); + System.err.println("pixel format " + pformats[i] + " (index " + i + "): " + dbgCaps0); + } + } + return pformats; + } + + static List /*<GLCapabilitiesImmutable>*/ wglARBPFIDs2GLCapabilities(WindowsWGLDrawableFactory.SharedResource sharedResource, + long hdc, int[] pfdIDs, GLProfile glp, boolean onscreen, boolean usePBuffer) { + final int winattrbits = GLGraphicsConfigurationUtil.getWinAttributeBits(onscreen, usePBuffer); + return wglARBPFIDs2GLCapabilitiesImpl(sharedResource, hdc, pfdIDs, glp, winattrbits); + } + + static List /*<GLCapabilitiesImmutable>*/ wglARBPFIDs2AllGLCapabilities(WindowsWGLDrawableFactory.SharedResource sharedResource, + long hdc, int[] pfdIDs, GLProfile glp) { + return wglARBPFIDs2GLCapabilitiesImpl(sharedResource, hdc, pfdIDs, glp, GLGraphicsConfigurationUtil.ALL_BITS); + } + + private static List /*<GLCapabilitiesImmutable>*/ wglARBPFIDs2GLCapabilitiesImpl(WindowsWGLDrawableFactory.SharedResource sharedResource, + long hdc, int[] pfdIDs, GLProfile glp, int winattrbits) { + if (!sharedResource.hasARBPixelFormat()) { + return null; + } + final int numFormats = pfdIDs.length; + + int[] iattributes = new int [2*MAX_ATTRIBS]; + int[] iresults = new int [2*MAX_ATTRIBS]; + int niattribs = fillAttribsForGeneralWGLARBQuery(sharedResource, iattributes); + + ArrayList bucket = new ArrayList(); + + for(int i = 0; i<numFormats; i++) { + if ( pfdIDs[i] >= 1 && + sharedResource.getContext().getWGLExt().wglGetPixelFormatAttribivARB(hdc, pfdIDs[i], 0, niattribs, iattributes, 0, iresults, 0) ) { + AttribList2GLCapabilities(bucket, glp, hdc, pfdIDs[i], iattributes, niattribs, iresults, winattrbits); + } else if (DEBUG) { + System.err.println("wglARBPFIDs2GLCapabilities: Cannot get pixel format attributes for pixel format " + + i + "/" + numFormats + ": " + pfdIDs[i] + ", " + + GLGraphicsConfigurationUtil.winAttributeBits2String(null, winattrbits).toString()); + } + } + return bucket; + } + + static boolean GLCapabilities2AttribList(GLCapabilitiesImmutable caps, + int[] iattributes, + WindowsWGLDrawableFactory.SharedResource sharedResource, + int accelerationValue, + int[] floatMode) throws GLException { + if (!sharedResource.hasARBPixelFormat()) { + return false; + } + + boolean onscreen = caps.isOnscreen(); + boolean pbuffer = caps.isPBuffer(); + + int niattribs = 0; + + iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + if(accelerationValue>0) { + iattributes[niattribs++] = WGLExt.WGL_ACCELERATION_ARB; + iattributes[niattribs++] = accelerationValue; + } + if (onscreen) { + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + } else if (pbuffer && sharedResource.hasARBPBuffer()) { + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_PBUFFER_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_BITMAP_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + } + + iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB; + if (caps.getDoubleBuffered()) { + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = GL.GL_FALSE; + } + + iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB; + if (caps.getStereo()) { + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = GL.GL_FALSE; + } + + iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB; + iattributes[niattribs++] = caps.getDepthBits(); + iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB; + iattributes[niattribs++] = caps.getRedBits(); + iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB; + iattributes[niattribs++] = caps.getGreenBits(); + iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB; + iattributes[niattribs++] = caps.getBlueBits(); + iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB; + iattributes[niattribs++] = caps.getAlphaBits(); + iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB; + iattributes[niattribs++] = caps.getStencilBits(); + if (caps.getAccumRedBits() > 0 || + caps.getAccumGreenBits() > 0 || + caps.getAccumBlueBits() > 0 || + caps.getAccumAlphaBits() > 0) { + iattributes[niattribs++] = WGLExt.WGL_ACCUM_BITS_ARB; + iattributes[niattribs++] = (caps.getAccumRedBits() + + caps.getAccumGreenBits() + + caps.getAccumBlueBits() + + caps.getAccumAlphaBits()); + iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB; + iattributes[niattribs++] = caps.getAccumRedBits(); + iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB; + iattributes[niattribs++] = caps.getAccumGreenBits(); + iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB; + iattributes[niattribs++] = caps.getAccumBlueBits(); + iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB; + iattributes[niattribs++] = caps.getAccumAlphaBits(); + } + + if (caps.getSampleBuffers() && sharedResource.hasARBMultisample()) { + iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB; + iattributes[niattribs++] = caps.getNumSamples(); + } + + boolean rtt = caps.getPbufferRenderToTexture(); + boolean rect = caps.getPbufferRenderToTextureRectangle(); + boolean useFloat = caps.getPbufferFloatingPointBuffers(); + boolean ati = false; + boolean nvidia = false; + if (pbuffer && sharedResource.hasARBPBuffer()) { + // Check some invariants and set up some state + if (rect && !rtt) { + throw new GLException("Render-to-texture-rectangle requires render-to-texture to be specified"); + } + + WindowsWGLContext sharedCtx = sharedResource.getContext(); + if (rect) { + if (!sharedCtx.isExtensionAvailable("GL_NV_texture_rectangle")) { + throw new GLException("Render-to-texture-rectangle requires GL_NV_texture_rectangle extension"); + } + } + + if (useFloat) { + // Prefer NVidia extension over ATI + nvidia = sharedCtx.isExtensionAvailable(WindowsWGLDrawableFactory.WGL_NV_float_buffer); + if(nvidia) { + floatMode[0] = GLPbuffer.NV_FLOAT; + } else { + ati = sharedCtx.isExtensionAvailable("WGL_ATI_pixel_format_float"); + if(ati) { + floatMode[0] = GLPbuffer.ATI_FLOAT; + } else { + throw new GLException("Floating-point pbuffers not supported by this hardware"); + } + } + + if (DEBUG) { + System.err.println("Using " + (ati ? "ATI" : ( nvidia ? "NVidia" : "NONE" ) ) + " floating-point extension"); + } + } + + // See whether we need to change the pixel type to support ATI's + // floating-point pbuffers + if (useFloat && ati) { + if (rtt) { + throw new GLException("Render-to-floating-point-texture not supported on ATI hardware"); + } else { + iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_FLOAT_ARB; + } + } else { + if (!rtt) { + // Currently we don't support non-truecolor visuals in the + // GLCapabilities, so we don't offer the option of making + // color-index pbuffers. + iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_ARB; + } + } + + if (useFloat && nvidia) { + iattributes[niattribs++] = WGLExt.WGL_FLOAT_COMPONENTS_NV; + iattributes[niattribs++] = GL.GL_TRUE; + } + + if (rtt) { + if (useFloat) { + assert(!ati); + assert(nvidia); + if (!rect) { + throw new GLException("Render-to-floating-point-texture only supported on NVidia hardware with render-to-texture-rectangle"); + } + iattributes[niattribs++] = WGLExt.WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV; + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = rect ? WGLExt.WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV : WGLExt.WGL_BIND_TO_TEXTURE_RGB_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + } + } + } else { + iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_ARB; + } + iattributes[niattribs++] = 0; + + return true; + } + + static int AttribList2DrawableTypeBits(final int[] iattribs, final int niattribs, final int[] iresults) { + int val = 0; + + for (int i = 0; i < niattribs; i++) { + int attr = iattribs[i]; + switch (attr) { + case WGLExt.WGL_DRAW_TO_WINDOW_ARB: + if(iresults[i] == GL.GL_TRUE) val |= GLGraphicsConfigurationUtil.WINDOW_BIT; + break; + case WGLExt.WGL_DRAW_TO_BITMAP_ARB: + if(iresults[i] == GL.GL_TRUE) val |= GLGraphicsConfigurationUtil.BITMAP_BIT; + break; + case WGLExt.WGL_DRAW_TO_PBUFFER_ARB: + if(iresults[i] == GL.GL_TRUE) val |= GLGraphicsConfigurationUtil.PBUFFER_BIT; + break; + } + } + return val; + } + + static boolean AttribList2GLCapabilities( ArrayList capsBucket, + final GLProfile glp, final long hdc, final int pfdID, final int[] iattribs, + final int niattribs, + final int[] iresults, final int winattrmask) { + final int allDrawableTypeBits = AttribList2DrawableTypeBits(iattribs, niattribs, iresults); + int drawableTypeBits = winattrmask & allDrawableTypeBits; + + if( 0 == drawableTypeBits ) { + return false; + } + PIXELFORMATDESCRIPTOR pfd = createPixelFormatDescriptor(); + + if (GDI.DescribePixelFormat(hdc, pfdID, pfd.size(), pfd) == 0) { + // remove displayable bits, since pfdID is non displayable + drawableTypeBits = drawableTypeBits & ~(GLGraphicsConfigurationUtil.WINDOW_BIT | GLGraphicsConfigurationUtil.BITMAP_BIT); + if( 0 == drawableTypeBits ) { + return false; + } + // non displayable requested (pbuffer) + } + WGLGLCapabilities res = new WGLGLCapabilities(pfd, pfdID, glp); + res.setValuesByARB(iattribs, niattribs, iresults); + + return GLGraphicsConfigurationUtil.addGLCapabilitiesPermutations(capsBucket, res, drawableTypeBits ); + } + + // + // GDI PIXELFORMAT + // + + static int[] wglAllGDIPFIDs(long hdc) { + int numFormats = GDI.DescribePixelFormat(hdc, 1, 0, null); + if (numFormats == 0) { + throw new GLException("DescribePixelFormat: No formats - HDC 0x" + Long.toHexString(hdc) + + ", LastError: " + GDI.GetLastError()); + } + int[] pfdIDs = new int[numFormats]; + for (int i = 0; i < numFormats; i++) { + pfdIDs[i] = 1 + i; + } + return pfdIDs; + } + + static int PFD2DrawableTypeBits(PIXELFORMATDESCRIPTOR pfd) { + int val = 0; + + int dwFlags = pfd.getDwFlags(); + + if( 0 != (GDI.PFD_DRAW_TO_WINDOW & dwFlags ) ) { + val |= GLGraphicsConfigurationUtil.WINDOW_BIT; + } + if( 0 != (GDI.PFD_DRAW_TO_BITMAP & dwFlags ) ) { + val |= GLGraphicsConfigurationUtil.BITMAP_BIT; + } + return val; + } + + static WGLGLCapabilities PFD2GLCapabilities(GLProfile glp, long hdc, int pfdID, boolean onscreen) { + final int winattrmask = GLGraphicsConfigurationUtil.getWinAttributeBits(onscreen, false); + ArrayList capsBucket = new ArrayList(1); + if( PFD2GLCapabilities(capsBucket, glp, hdc, pfdID, winattrmask) ) { + return (WGLGLCapabilities) capsBucket.get(0); + } + return null; + } + + static boolean PFD2GLCapabilities(ArrayList capsBucket, final GLProfile glp, final long hdc, final int pfdID, final int winattrmask) { + PIXELFORMATDESCRIPTOR pfd = createPixelFormatDescriptor(hdc, pfdID); + if(null == pfd) { + return false; + } + if ((pfd.getDwFlags() & GDI.PFD_SUPPORT_OPENGL) == 0) { + return false; + } + final int allDrawableTypeBits = PFD2DrawableTypeBits(pfd); + final int drawableTypeBits = winattrmask & allDrawableTypeBits; + + if( 0 == drawableTypeBits ) { + return false; + } + + WGLGLCapabilities res = new WGLGLCapabilities(pfd, pfdID, glp); + res.setValuesByGDI(); + + return GLGraphicsConfigurationUtil.addGLCapabilitiesPermutations(capsBucket, res, drawableTypeBits ); + } + + static PIXELFORMATDESCRIPTOR GLCapabilities2PFD(GLCapabilitiesImmutable caps, PIXELFORMATDESCRIPTOR pfd) { + int colorDepth = (caps.getRedBits() + + caps.getGreenBits() + + caps.getBlueBits()); + if (colorDepth < 15) { + throw new GLException("Bit depths < 15 (i.e., non-true-color) not supported"); + } + int pfdFlags = (GDI.PFD_SUPPORT_OPENGL | + GDI.PFD_GENERIC_ACCELERATED); + if (caps.getDoubleBuffered()) { + pfdFlags |= GDI.PFD_DOUBLEBUFFER; + } + if (caps.isOnscreen()) { + pfdFlags |= GDI.PFD_DRAW_TO_WINDOW; + } else { + pfdFlags |= GDI.PFD_DRAW_TO_BITMAP; + } + if (caps.getStereo()) { + pfdFlags |= GDI.PFD_STEREO; + } + pfd.setDwFlags(pfdFlags); + pfd.setIPixelType((byte) GDI.PFD_TYPE_RGBA); + pfd.setCColorBits((byte) colorDepth); + pfd.setCRedBits ((byte) caps.getRedBits()); + pfd.setCGreenBits((byte) caps.getGreenBits()); + pfd.setCBlueBits ((byte) caps.getBlueBits()); + pfd.setCAlphaBits((byte) caps.getAlphaBits()); + int accumDepth = (caps.getAccumRedBits() + + caps.getAccumGreenBits() + + caps.getAccumBlueBits()); + pfd.setCAccumBits ((byte) accumDepth); + pfd.setCAccumRedBits ((byte) caps.getAccumRedBits()); + pfd.setCAccumGreenBits((byte) caps.getAccumGreenBits()); + pfd.setCAccumBlueBits ((byte) caps.getAccumBlueBits()); + pfd.setCAccumAlphaBits((byte) caps.getAccumAlphaBits()); + pfd.setCDepthBits((byte) caps.getDepthBits()); + pfd.setCStencilBits((byte) caps.getStencilBits()); + pfd.setILayerType((byte) GDI.PFD_MAIN_PLANE); + + // n/a with non ARB/GDI method: + // multisample + // opaque + // pbuffer + return pfd; + } + + static PIXELFORMATDESCRIPTOR createPixelFormatDescriptor(long hdc, int pfdID) { + PIXELFORMATDESCRIPTOR pfd = PIXELFORMATDESCRIPTOR.create(); + pfd.setNSize((short) pfd.size()); + pfd.setNVersion((short) 1); + if(0 != hdc && 1 <= pfdID) { + if (GDI.DescribePixelFormat(hdc, pfdID, pfd.size(), pfd) == 0) { + // Accelerated pixel formats that are non displayable + if(DEBUG) { + System.err.println("Info: Non displayable pixel format " + pfdID + " of device context: error code " + GDI.GetLastError()); + } + return null; + } + } + return pfd; + } + + static PIXELFORMATDESCRIPTOR createPixelFormatDescriptor() { + return createPixelFormatDescriptor(0, 0); + } + + public String toString() { + return "WindowsWGLGraphicsConfiguration["+getScreen()+", pfdID " + getPixelFormatID() + ", ARB-Choosen " + isChoosenByARB() + + ",\n\trequested " + getRequestedCapabilities() + + ",\n\tchosen " + getChosenCapabilities() + + "]"; + } +} + diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java new file mode 100644 index 000000000..8c1f5e87c --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -0,0 +1,486 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.windows.wgl; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +import jogamp.nativewindow.windows.GDI; +import jogamp.nativewindow.windows.PIXELFORMATDESCRIPTOR; +import jogamp.opengl.GLGraphicsConfigurationFactory; +import jogamp.opengl.GLGraphicsConfigurationUtil; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** Subclass of GraphicsConfigurationFactory used when non-AWT tookits + are used on Windows platforms. Toolkits will likely need to delegate + to this one to change the accepted and returned types of the + GraphicsDevice and GraphicsConfiguration abstractions. */ + +public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory { + protected static final boolean DEBUG = jogamp.opengl.Debug.debug("GraphicsConfiguration"); + static WGLGLCapabilities.PfdIDComparator PfdIDComparator = new WGLGLCapabilities.PfdIDComparator(); + + WindowsWGLGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.windows.WindowsGraphicsDevice.class, this); + } + + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { + + if (! (capsChosen instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - chosen"); + } + + if (! (capsRequested instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - requested"); + } + + return chooseGraphicsConfigurationStatic((GLCapabilitiesImmutable)capsChosen, (GLCapabilitiesImmutable)capsRequested, chooser, absScreen); + } + + static WindowsWGLGraphicsConfiguration createDefaultGraphicsConfiguration(GLCapabilitiesImmutable caps, + AbstractGraphicsScreen absScreen) { + return chooseGraphicsConfigurationStatic(caps, caps, null, absScreen); + } + + static WindowsWGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilitiesImmutable capsChosen, + GLCapabilitiesImmutable capsReq, + CapabilitiesChooser chooser, + AbstractGraphicsScreen absScreen) { + if(null==absScreen) { + absScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); + } + AbstractGraphicsDevice absDevice = absScreen.getDevice(); + + capsChosen = GLGraphicsConfigurationUtil.fixGLCapabilities( + capsChosen, GLDrawableFactory.getDesktopFactory().canCreateGLPbuffer(absDevice) ); + + return new WindowsWGLGraphicsConfiguration( absScreen, capsChosen, capsReq, (GLCapabilitiesChooser)chooser ); + } + + protected static List/*<WGLGLCapabilities>*/ getAvailableCapabilities(WindowsWGLDrawableFactory factory, AbstractGraphicsDevice device) { + WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResource(device); + if(null == sharedResource) { + throw new GLException("Shared resource for device n/a: "+device); + } + WindowsWGLDrawable sharedDrawable = sharedResource.getDrawable(); + GLCapabilitiesImmutable capsChosen = sharedDrawable.getChosenGLCapabilities(); + WindowsWGLContext sharedContext = sharedResource.getContext(); + List availableCaps = null; + + if ( sharedResource.needsCurrentContext4ARBPFDQueries() ) { + if(GLContext.CONTEXT_NOT_CURRENT == sharedContext.makeCurrent()) { + throw new GLException("Could not make Shared Context current: "+device); + } + } else { + sharedDrawable.lockSurface(); + } + try { + long hdc = sharedDrawable.getHandle(); + if (0 == hdc) { + throw new GLException("Error: HDC is null"); + } + if (sharedResource.hasARBPixelFormat()) { + availableCaps = getAvailableGLCapabilitiesARB(hdc, sharedResource, capsChosen.getGLProfile()); + } + if( null == availableCaps || availableCaps.isEmpty() ) { + availableCaps = getAvailableGLCapabilitiesGDI(hdc, capsChosen.getGLProfile()); + } + } finally { + if ( sharedResource.needsCurrentContext4ARBPFDQueries() ) { + sharedContext.release(); + } else { + sharedDrawable.unlockSurface(); + } + } + + if( null != availableCaps && availableCaps.size() > 1 ) { + Collections.sort(availableCaps, PfdIDComparator); + } + return availableCaps; + } + + static List/*<WGLGLCapabilities>*/ getAvailableGLCapabilitiesARB(long hdc, WindowsWGLDrawableFactory.SharedResource sharedResource, GLProfile glProfile) { + int[] pformats = WindowsWGLGraphicsConfiguration.wglAllARBPFIDs(sharedResource.getContext(), hdc); + return WindowsWGLGraphicsConfiguration.wglARBPFIDs2AllGLCapabilities(sharedResource, hdc, pformats, glProfile); + } + + static List/*<WGLGLCapabilities>*/ getAvailableGLCapabilitiesGDI(long hdc, GLProfile glProfile) { + int[] pformats = WindowsWGLGraphicsConfiguration.wglAllGDIPFIDs(hdc); + int numFormats = pformats.length; + ArrayList bucket = new ArrayList(numFormats); + for (int i = 0; i < numFormats; i++) { + WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(bucket, glProfile, hdc, pformats[i], GLGraphicsConfigurationUtil.ALL_BITS); + } + return bucket; + } + + /** + * + * @param chooser + * @param _factory + * @param ns + * @param pfIDs optional pool of preselected PixelFormat IDs, maybe null for unrestricted selection + */ + static void updateGraphicsConfiguration(CapabilitiesChooser chooser, + GLDrawableFactory factory, NativeSurface ns, int[] pfdIDs) { + if (chooser != null && !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilitiesChooser objects"); + } + if (factory == null) { + throw new IllegalArgumentException("GLDrawableFactory is null"); + } + if (ns == null) { + throw new IllegalArgumentException("NativeSurface is null"); + } + + if(NativeSurface.LOCK_SURFACE_NOT_READY >= ns.lockSurface()) { + throw new GLException("Surface not ready (lockSurface)"); + } + try { + long hdc = ns.getSurfaceHandle(); + if (0 == hdc) { + throw new GLException("Error: HDC is null"); + } + WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration) ns.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + + if( !config.isExternal() ) { + if( !config.isDetermined() ) { + updateGraphicsConfiguration(config, chooser, factory, hdc, false, pfdIDs); + } else { + // set PFD if not set yet + int pfdID = -1; + boolean set = false; + if ( 1 > ( pfdID = GDI.GetPixelFormat(hdc) ) ) { + if (!GDI.SetPixelFormat(hdc, config.getPixelFormatID(), config.getPixelFormat())) { + throw new GLException("Unable to set pixel format " + config.getPixelFormatID() + + " for device context " + toHexString(hdc) + + ": error code " + GDI.GetLastError()); + } + set = true; + } + if (DEBUG) { + System.err.println("!!! setPixelFormat (post): hdc "+toHexString(hdc) +", "+pfdID+" -> "+config.getPixelFormatID()+", set: "+set); + Thread.dumpStack(); + } + } + } + } finally { + ns.unlockSurface(); + } + } + + static void preselectGraphicsConfiguration(CapabilitiesChooser chooser, + GLDrawableFactory _factory, AbstractGraphicsDevice device, + WindowsWGLGraphicsConfiguration config, int[] pfdIDs) { + if (chooser != null && !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilitiesChooser objects"); + } + if (_factory == null) { + throw new IllegalArgumentException("GLDrawableFactory is null"); + } + if (config == null) { + throw new IllegalArgumentException("WindowsWGLGraphicsConfiguration is null"); + } + WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory) _factory; + WindowsWGLDrawable sharedDrawable = factory.getOrCreateSharedDrawable(device); + if(null == sharedDrawable) { + throw new IllegalArgumentException("Shared Drawable is null"); + } + + if(NativeSurface.LOCK_SURFACE_NOT_READY >= sharedDrawable.lockSurface()) { + throw new GLException("Surface not ready (lockSurface)"); + } + try { + long hdc = sharedDrawable.getHandle(); + if (0 == hdc) { + throw new GLException("Error: HDC is null"); + } + updateGraphicsConfiguration(config, chooser, factory, hdc, true, pfdIDs); + } finally { + sharedDrawable.unlockSurface(); + } + } + + private static void updateGraphicsConfiguration(WindowsWGLGraphicsConfiguration config, CapabilitiesChooser chooser, + GLDrawableFactory factory, long hdc, boolean extHDC, int[] pfdIDs) { + if (DEBUG) { + if(extHDC) { + System.err.println("updateGraphicsConfiguration(using shared): hdc "+toHexString(hdc)); + } else { + System.err.println("updateGraphicsConfiguration(using target): hdc "+toHexString(hdc)); + } + System.err.println("!!! user chosen caps " + config.getChosenCapabilities()); + } + AbstractGraphicsDevice device = config.getScreen().getDevice(); + WindowsWGLDrawableFactory.SharedResource sharedResource = ((WindowsWGLDrawableFactory)factory).getOrCreateSharedResource(device); + WindowsWGLContext sharedContext = null; + if (null != sharedResource && sharedResource.needsCurrentContext4ARBPFDQueries()) { + sharedContext = sharedResource.getContext(); + if(GLContext.CONTEXT_NOT_CURRENT == sharedContext.makeCurrent()) { + throw new GLException("Could not make Shared Context current: "+device); + } + } + try { + if( !updateGraphicsConfigurationARB(hdc, extHDC, config, chooser, (WindowsWGLDrawableFactory)factory, pfdIDs) ) { + updateGraphicsConfigurationGDI(hdc, extHDC, config, chooser, pfdIDs); + } + } finally { + if (null != sharedContext) { + sharedContext.release(); + } + } + } + + private static boolean updateGraphicsConfigurationARB(long hdc, boolean extHDC, WindowsWGLGraphicsConfiguration config, + CapabilitiesChooser chooser, WindowsWGLDrawableFactory factory, int[] pformats) { + AbstractGraphicsDevice device = config.getScreen().getDevice(); + WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResource(device); + + if (null == sharedResource) { + if (DEBUG) { + System.err.println("updateGraphicsConfigurationARB: SharedResource is null: "+device); + } + return false; + } + if (!sharedResource.hasARBPixelFormat()) { + if (DEBUG) { + System.err.println("updateGraphicsConfigurationARB: "+WindowsWGLDrawableFactory.WGL_ARB_pixel_format+" not available"); + } + return false; + } + + GLCapabilitiesImmutable capsChosen = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + boolean onscreen = capsChosen.isOnscreen(); + boolean usePBuffer = capsChosen.isPBuffer(); + GLProfile glProfile = capsChosen.getGLProfile(); + + WGLGLCapabilities pixelFormatCaps = null; // chosen or preset PFD ID's caps + boolean pixelFormatSet = false; // indicates a preset PFD ID [caps] + final int presetPFDID = extHDC ? -1 : GDI.GetPixelFormat(hdc) ; + if ( 1 <= presetPFDID ) { + // Pixelformat already set by either + // - a previous preselectGraphicsConfiguration() call on the same HDC, + // - the graphics driver, copying the HDC's pixelformat to the new one, + // - or the Java2D/OpenGL pipeline's configuration + if (DEBUG) { + System.err.println("updateGraphicsConfigurationARB: Pixel format already chosen for HDC: " + toHexString(hdc) + + ", pixelformat " + presetPFDID); + } + pixelFormatSet = true; + pixelFormatCaps = WindowsWGLGraphicsConfiguration.wglARBPFID2GLCapabilities(sharedResource, hdc, presetPFDID, glProfile, onscreen, usePBuffer); + } else { + int recommendedIndex = -1; // recommended index + + if(null == pformats) { + // No given PFD IDs + // + // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as preferred choice + int[] iattributes = new int[2 * WindowsWGLGraphicsConfiguration.MAX_ATTRIBS]; + float[] fattributes = new float[1]; + int accelerationMode = WGLExt.WGL_FULL_ACCELERATION_ARB; + pformats = WindowsWGLGraphicsConfiguration.wglChoosePixelFormatARB(hdc, sharedResource, capsChosen, + iattributes, accelerationMode, fattributes); + if (null == pformats) { + accelerationMode = WGLExt.WGL_GENERIC_ACCELERATION_ARB; + pformats = WindowsWGLGraphicsConfiguration.wglChoosePixelFormatARB(hdc, sharedResource, capsChosen, + iattributes, accelerationMode, fattributes); + } + if (null == pformats) { + accelerationMode = -1; // use what we are offered .. + pformats = WindowsWGLGraphicsConfiguration.wglChoosePixelFormatARB(hdc, sharedResource, capsChosen, + iattributes, accelerationMode, fattributes); + } + if (null != pformats) { + recommendedIndex = 0; + } else { + if(DEBUG) { + System.err.println("updateGraphicsConfigurationARB: wglChoosePixelFormatARB failed with: "+capsChosen); + } + // 2nd choice: get all GLCapabilities available, no preferred recommendedIndex available + pformats = WindowsWGLGraphicsConfiguration.wglAllARBPFIDs(sharedResource.getContext(), hdc); + if (DEBUG) { + final int len = ( null != pformats ) ? pformats.length : 0; + System.err.println("updateGraphicsConfigurationARB: NumFormats (wglAllARBPFIDs) " + len); + } + } + if (null == pformats) { + if (DEBUG) { + Thread.dumpStack(); + } + return false; + } + } + + List /*<WGLGLCapabilities>*/ availableCaps = + WindowsWGLGraphicsConfiguration.wglARBPFIDs2GLCapabilities(sharedResource, hdc, pformats, + glProfile, onscreen, usePBuffer); + if( null == availableCaps || 0 == availableCaps.size() ) { + if (DEBUG) { + System.err.println("updateGraphicsConfigurationARB: wglARBPFIDs2GLCapabilities failed with " + pformats.length + + " pfd ids, onscreen " + onscreen + ", pbuffer " + usePBuffer); + Thread.dumpStack(); + } + return false; + } + + if (DEBUG) { + System.err.println("updateGraphicsConfigurationARB: " + pformats.length + + " pfd ids, onscreen " + onscreen + ", pbuffer " + usePBuffer + ", " + availableCaps.size() + " glcaps"); + if(0 <= recommendedIndex) { + System.err.println("updateGraphicsConfigurationARB: Used wglChoosePixelFormatARB to recommend pixel format " + + pformats[recommendedIndex] + ", idx " + recommendedIndex +", "+availableCaps.get(recommendedIndex)); + } + } + + int chosenIndex = chooseCapabilities(chooser, capsChosen, availableCaps, recommendedIndex); + if ( 0 > chosenIndex ) { + if (DEBUG) { + Thread.dumpStack(); + } + return false; + } + pixelFormatCaps = (WGLGLCapabilities) availableCaps.get(chosenIndex); + if( null == pixelFormatCaps) { + throw new GLException("Null Capabilities with "+ + " chosen pfdID: native recommended "+ (recommendedIndex+1) + + " chosen "+pixelFormatCaps.getPFDID()); + } + if (DEBUG) { + System.err.println("!!! chosen pfdID (ARB): native recommended "+ (recommendedIndex+1) + + " chosen "+pixelFormatCaps); + } + } + + if ( !extHDC && !pixelFormatSet ) { + config.setPixelFormat(hdc, pixelFormatCaps); + } else { + config.setCapsPFD(pixelFormatCaps); + } + return true; + } + + private static boolean updateGraphicsConfigurationGDI(long hdc, boolean extHDC, WindowsWGLGraphicsConfiguration config, + CapabilitiesChooser chooser, int[] pformats) { + GLCapabilitiesImmutable capsChosen = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(capsChosen.isPBuffer()) { + if (DEBUG) { + System.err.println("updateGraphicsConfigurationGDI: no pbuffer supported on GDI: " + capsChosen); + } + return false; + } + boolean onscreen = capsChosen.isOnscreen(); + GLProfile glProfile = capsChosen.getGLProfile(); + + ArrayList<WGLGLCapabilities> availableCaps = new ArrayList<WGLGLCapabilities>(); + int pfdID; // chosen or preset PFD ID + WGLGLCapabilities pixelFormatCaps = null; // chosen or preset PFD ID's caps + boolean pixelFormatSet = false; // indicates a preset PFD ID [caps] + + if ( !extHDC && 1 <= ( pfdID = GDI.GetPixelFormat(hdc) ) ) { + // Pixelformat already set by either + // - a previous preselectGraphicsConfiguration() call on the same HDC, + // - the graphics driver, copying the HDC's pixelformat to the new one, + // - or the Java2D/OpenGL pipeline's configuration + if (DEBUG) { + System.err.println("updateGraphicsConfigurationGDI: NOTE: pixel format already chosen for HDC: " + toHexString(hdc) + + ", pixelformat " + pfdID); + } + pixelFormatSet = true; + pixelFormatCaps = WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(glProfile, hdc, pfdID, onscreen); + } else { + if(null == pformats) { + pformats = WindowsWGLGraphicsConfiguration.wglAllGDIPFIDs(hdc); + } + final int winattrmask = GLGraphicsConfigurationUtil.getWinAttributeBits(onscreen, false); + + for (int i = 0; i < pformats.length; i++) { + WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(availableCaps, glProfile, hdc, pformats[i], winattrmask); + } + + // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as preferred choice + PIXELFORMATDESCRIPTOR pfd = WindowsWGLGraphicsConfiguration.createPixelFormatDescriptor(); + pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(capsChosen, pfd); + pfdID = GDI.ChoosePixelFormat(hdc, pfd); + int recommendedIndex = -1 ; + if( 1 <= pfdID ) { + // seek index .. + for (recommendedIndex = availableCaps.size() - 1 ; + 0 <= recommendedIndex && pfdID != ((WGLGLCapabilities) availableCaps.get(recommendedIndex)).getPFDID(); + recommendedIndex--) + { /* nop */ } + } + // 2nd choice: if no preferred recommendedIndex available + if (DEBUG) { + System.err.println("updateGraphicsConfigurationGDI: ChoosePixelFormat(HDC " + toHexString(hdc) + ") = " + pfdID + ", idx " + recommendedIndex + " (LastError: " + GDI.GetLastError() + ")"); + } + int chosenIndex = chooseCapabilities(chooser, capsChosen, availableCaps, recommendedIndex); + if ( 0 > chosenIndex ) { + if (DEBUG) { + Thread.dumpStack(); + } + return false; + } + pixelFormatCaps = availableCaps.get(chosenIndex); + if (DEBUG) { + System.err.println("!!! chosen pfdID (GDI): native recommended "+ (recommendedIndex+1) + + ", caps " + pixelFormatCaps); + } + } + + if ( !extHDC && !pixelFormatSet ) { + config.setPixelFormat(hdc, pixelFormatCaps); + } else { + config.setCapsPFD(pixelFormatCaps); + } + return true; + } +} + diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java new file mode 100644 index 000000000..1f09180eb --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.windows.wgl.awt; + + +import com.jogamp.common.util.ArrayHashSet; +import jogamp.nativewindow.jawt.windows.Win32SunJDKReflection; +import jogamp.opengl.GLGraphicsConfigurationFactory; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; +import javax.media.nativewindow.windows.WindowsGraphicsDevice; + +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLException; + +import jogamp.opengl.windows.wgl.WindowsWGLGraphicsConfiguration; +import javax.media.opengl.GLDrawableFactory; + +public class WindowsAWTWGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory { + protected static final boolean DEBUG = jogamp.opengl.Debug.debug("GraphicsConfiguration"); + + public WindowsAWTWGLGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, this); + } + + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { + GraphicsDevice device = null; + if (absScreen != null && + !(absScreen instanceof AWTGraphicsScreen)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only AWTGraphicsScreen objects"); + } + + if(null==absScreen) { + absScreen = AWTGraphicsScreen.createScreenDevice(-1, AbstractGraphicsDevice.DEFAULT_UNIT); + if(DEBUG) { + System.err.println("WindowsAWTWGLGraphicsConfigurationFactory: creating default device: "+absScreen); + } + } + AWTGraphicsScreen awtScreen = (AWTGraphicsScreen) absScreen; + device = ((AWTGraphicsDevice)awtScreen.getDevice()).getGraphicsDevice(); + + if ( !(capsChosen instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects - chosen"); + } + + if ( !(capsRequested instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects - requested"); + } + + if (chooser != null && + !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilitiesChooser objects"); + } + + if(DEBUG) { + System.err.println("WindowsAWTWGLGraphicsConfigurationFactory: got "+absScreen); + } + + WindowsGraphicsDevice winDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + DefaultGraphicsScreen winScreen = new DefaultGraphicsScreen(winDevice, awtScreen.getIndex()); + GraphicsConfigurationFactory configFactory = GraphicsConfigurationFactory.getFactory(winDevice); + GLDrawableFactory drawableFactory = GLDrawableFactory.getFactory( ((GLCapabilitiesImmutable)capsChosen).getGLProfile() ); + + WindowsWGLGraphicsConfiguration winConfig = (WindowsWGLGraphicsConfiguration) + configFactory.chooseGraphicsConfiguration(capsChosen, + capsRequested, + chooser, winScreen); + if (winConfig == null) { + throw new GLException("Unable to choose a GraphicsConfiguration: "+capsChosen+",\n\t"+chooser+"\n\t"+winScreen); + } + + GraphicsConfiguration chosenGC = null; + + // 1st Choice: Create an AWT GraphicsConfiguration with the desired PFD + // This gc will probably not be able to support GDI (WGL_SUPPORT_GDI_ARB, PFD_SUPPORT_GDI) + // however on most GPUs this is the current situation for Windows, + // otherwise no hardware accelerated PFD could be achieved. + // - preselect with no constrains + // - try to create dedicated GC + winConfig.preselectGraphicsConfiguration(drawableFactory, null); + if ( 1 <= winConfig.getPixelFormatID() ) { + chosenGC = Win32SunJDKReflection.graphicsConfigurationGet(device, winConfig.getPixelFormatID()); + if(DEBUG) { + System.err.println("WindowsAWTWGLGraphicsConfigurationFactory: Found new AWT PFD ID "+winConfig.getPixelFormatID()+" -> "+winConfig); + } + } + + if( null == chosenGC ) { + // 2nd Choice: Choose and match the GL Visual with AWT: + // - collect all AWT PFDs + // - choose a GL config from the pool of AWT PFDs + // + // The resulting GraphicsConfiguration has to be 'forced' on the AWT native peer, + // ie. returned by GLCanvas's getGraphicsConfiguration() befor call by super.addNotify(). + // + + // collect all available PFD IDs + GraphicsConfiguration[] configs = device.getConfigurations(); + int[] pfdIDs = new int[configs.length]; + ArrayHashSet pfdIDOSet = new ArrayHashSet(); + for (int i = 0; i < configs.length; i++) { + GraphicsConfiguration gc = configs[i]; + pfdIDs[i] = Win32SunJDKReflection.graphicsConfigurationGetPixelFormatID(gc); + pfdIDOSet.add(new Integer(pfdIDs[i])); + if(DEBUG) { + System.err.println("AWT pfd["+i+"] "+pfdIDs[i]); + } + } + if(DEBUG) { + System.err.println("WindowsAWTWGLGraphicsConfigurationFactory: PFD IDs: "+pfdIDs.length+", unique: "+pfdIDOSet.size()); + } + winConfig.preselectGraphicsConfiguration(drawableFactory, pfdIDs); + int gcIdx = pfdIDOSet.indexOf(new Integer(winConfig.getPixelFormatID())); + if( 0 > gcIdx ) { + chosenGC = configs[gcIdx]; + if(DEBUG) { + System.err.println("WindowsAWTWGLGraphicsConfigurationFactory: Found matching AWT PFD ID "+winConfig.getPixelFormatID()+" -> "+winConfig); + } + } + } + + if ( null == chosenGC ) { + throw new GLException("Unable to determine GraphicsConfiguration: "+winConfig); + } + return new AWTGraphicsConfiguration(awtScreen, winConfig.getChosenCapabilities(), winConfig.getRequestedCapabilities(), + chosenGC, winConfig); + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java b/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java new file mode 100644 index 000000000..e95c80205 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.opengl.*; + + +public class GLXUtil { + public static String getExtension(long display) { + return GLX.glXGetClientString(display, GLX.GLX_EXTENSIONS); + } + + public static boolean isMultisampleAvailable(String extensions) { + if (extensions != null) { + return (extensions.indexOf("GLX_ARB_multisample") >= 0); + } + return false; + } + + public static boolean isMultisampleAvailable(long display) { + return isMultisampleAvailable(getExtension(display)); + } + + /** Workaround for apparent issue with ATI's proprietary drivers + where direct contexts still send GLX tokens for GL calls */ + public static String getVendorName(long display) { + return GLX.glXGetClientString(display, GLX.GLX_VENDOR); + } + + public static boolean isVendorNVIDIA(String vendor) { + return vendor != null && vendor.startsWith("NVIDIA") ; + } + + public static boolean isVendorATI(String vendor) { + return vendor != null && vendor.startsWith("ATI") ; + } + + public static boolean isVendorATI(long display) { + return isVendorATI(getVendorName(display)); + } + + public static boolean isVendorNVIDIA(long display) { + return isVendorNVIDIA(getVendorName(display)); + } + + public static void getGLXVersion(long display, int major[], int minor[]) { + if(0 == display) { + throw new GLException("null display handle"); + } + if(major.length<1||minor.length<1) { + throw new GLException("passed int arrays size is not >= 1"); + } + + if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) { + throw new GLException("glXQueryVersion failed"); + } + + // Work around bugs in ATI's Linux drivers where they report they + // only implement GLX version 1.2 on the server side + if (major[0] == 1 && minor[0] == 2) { + String str = GLX.glXGetClientString(display, GLX.GLX_VERSION); + try { + // e.g. "1.3" + major[0] = Integer.valueOf(str.substring(0, 1)).intValue(); + minor[0] = Integer.valueOf(str.substring(2, 3)).intValue(); + } catch (Exception e) { + major[0] = 1; + minor[0] = 2; + } + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java new file mode 100644 index 000000000..68bdb4ab8 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java @@ -0,0 +1,90 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.opengl.*; + +import javax.media.nativewindow.x11.*; +import jogamp.nativewindow.*; +import jogamp.nativewindow.x11.*; + +public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { + private static final int f_dim = 64; + private long dummyWindow = 0; + + /** + * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, + * we cannot switch the Display as we please, + * hence we reuse the target's screen configuration. + */ + public X11DummyGLXDrawable(X11GraphicsScreen screen, GLDrawableFactory factory, GLCapabilitiesImmutable caps) { + super(factory, + new WrappedSurface(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( + caps, caps, null, screen))); + this.realized = true; + + WrappedSurface ns = (WrappedSurface) getNativeSurface(); + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)ns.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + + X11GraphicsDevice device = (X11GraphicsDevice) screen.getDevice(); + long dpy = device.getHandle(); + int scrn = screen.getIndex(); + long visualID = config.getVisualID(); + + dummyWindow = X11Util.CreateDummyWindow(dpy, scrn, visualID, f_dim, f_dim); + ns.setSurfaceHandle( dummyWindow ); + ns.setSize(f_dim, f_dim); + + updateHandle(); + } + + public static X11DummyGLXDrawable create(X11GraphicsScreen screen, GLDrawableFactory factory, GLProfile glp) { + GLCapabilities caps = new GLCapabilities(glp); + return new X11DummyGLXDrawable(screen, factory, caps); + } + + public void setSize(int width, int height) { + } + + public int getWidth() { + return 1; + } + + public int getHeight() { + return 1; + } + + protected void destroyImpl() { + if(0!=dummyWindow) { + destroyHandle(); + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + X11Util.DestroyDummyWindow(config.getScreen().getDevice().getHandle(), dummyWindow); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java new file mode 100644 index 000000000..c488fe5cf --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import javax.media.opengl.*; +import jogamp.opengl.*; +import jogamp.nativewindow.WrappedSurface; + +public class X11ExternalGLXContext extends X11GLXContext { + private GLContext lastContext; + + private X11ExternalGLXContext(Drawable drawable, long ctx) { + super(drawable, null); + this.contextHandle = ctx; + GLContextShareSet.contextCreated(this); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); + getGLStateTracker().setEnabled(false); // external context usage can't track state in Java + } + + protected static X11ExternalGLXContext create(GLDrawableFactory factory, GLProfile glp) { + long ctx = GLX.glXGetCurrentContext(); + if (ctx == 0) { + throw new GLException("Error: current context null"); + } + long display = GLX.glXGetCurrentDisplay(); + if (display == 0) { + throw new GLException("Error: current display null"); + } + long drawable = GLX.glXGetCurrentDrawable(); + if (drawable == 0) { + throw new GLException("Error: attempted to make an external GLDrawable without a drawable/context current"); + } + int[] val = new int[1]; + GLX.glXQueryContext(display, ctx, GLX.GLX_SCREEN, val, 0); + X11GraphicsScreen x11Screen = (X11GraphicsScreen) X11GraphicsScreen.createScreenDevice(display, val[0]); + + GLX.glXQueryContext(display, ctx, GLX.GLX_FBCONFIG_ID, val, 0); + X11GLXGraphicsConfiguration cfg = X11GLXGraphicsConfiguration.create(glp, x11Screen, val[0]); + + WrappedSurface ns = new WrappedSurface(cfg); + ns.setSurfaceHandle(drawable); + return new X11ExternalGLXContext(new Drawable(factory, ns), ctx); + } + + protected boolean createImpl() { + return true; + } + + public int makeCurrent() throws GLException { + // Save last context if necessary to allow external GLContexts to + // talk to other GLContexts created by this library + GLContext cur = getCurrent(); + if (cur != null && cur != this) { + lastContext = cur; + setCurrent(null); + } + return super.makeCurrent(); + } + + public void release() throws GLException { + super.release(); + setCurrent(lastContext); + lastContext = null; + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + } + + protected void releaseImpl() throws GLException { + } + + protected void destroyImpl() throws GLException { + } + + // Need to provide the display connection to extension querying APIs + static class Drawable extends X11GLXDrawable { + Drawable(GLDrawableFactory factory, NativeSurface comp) { + super(factory, comp, true); + } + + public GLContext createContext(GLContext shareWith) { + throw new GLException("Should not call this"); + } + + public int getWidth() { + throw new GLException("Should not call this"); + } + + public int getHeight() { + throw new GLException("Should not call this"); + } + + public void setSize(int width, int height) { + throw new GLException("Should not call this"); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java new file mode 100644 index 000000000..eb286cdf0 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import javax.media.opengl.*; +import jogamp.nativewindow.WrappedSurface; + + +public class X11ExternalGLXDrawable extends X11GLXDrawable { + + private X11ExternalGLXDrawable(GLDrawableFactory factory, NativeSurface surface) { + super(factory, surface, true); + } + + protected static X11ExternalGLXDrawable create(GLDrawableFactory factory, GLProfile glp) { + long context = GLX.glXGetCurrentContext(); + if (context == 0) { + throw new GLException("Error: current context null"); + } + long display = GLX.glXGetCurrentDisplay(); + if (display == 0) { + throw new GLException("Error: current display null"); + } + long drawable = GLX.glXGetCurrentDrawable(); + if (drawable == 0) { + throw new GLException("Error: attempted to make an external GLDrawable without a drawable current"); + } + int[] val = new int[1]; + GLX.glXQueryContext(display, context, GLX.GLX_SCREEN, val, 0); + X11GraphicsScreen x11Screen = (X11GraphicsScreen) X11GraphicsScreen.createScreenDevice(display, val[0]); + + GLX.glXQueryContext(display, context, GLX.GLX_FBCONFIG_ID, val, 0); + X11GLXGraphicsConfiguration cfg = X11GLXGraphicsConfiguration.create(glp, x11Screen, val[0]); + + int w, h; + GLX.glXQueryDrawable(display, drawable, GLX.GLX_WIDTH, val, 0); + w=val[0]; + GLX.glXQueryDrawable(display, drawable, GLX.GLX_HEIGHT, val, 0); + h=val[0]; + + GLX.glXQueryContext(display, context, GLX.GLX_RENDER_TYPE, val, 0); + if ((val[0] & GLX.GLX_RGBA_TYPE) == 0) { + if (DEBUG) { + System.err.println("X11ExternalGLXDrawable: WARNING: forcing GLX_RGBA_TYPE for newly created contexts (current 0x"+Integer.toHexString(val[0])+")"); + } + } + WrappedSurface ns = new WrappedSurface(cfg); + ns.setSurfaceHandle(drawable); + ns.setSize(w, h); + return new X11ExternalGLXDrawable(factory, ns); + } + + public GLContext createContext(GLContext shareWith) { + return new Context(this, shareWith); + } + + public void setSize(int newWidth, int newHeight) { + throw new GLException("Should not call this"); + } + + class Context extends X11GLXContext { + Context(X11GLXDrawable drawable, GLContext shareWith) { + super(drawable, shareWith); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLCapabilities.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLCapabilities.java new file mode 100644 index 000000000..5455976da --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLCapabilities.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 jogamp.opengl.x11.glx; + +import jogamp.nativewindow.x11.XVisualInfo; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; +import java.util.Comparator; + +public class X11GLCapabilities extends GLCapabilities { + XVisualInfo xVisualInfo; // maybe null if !onscreen + long fbcfg; + int fbcfgid; + + /** Comparing xvisual id only */ + public static class XVisualIDComparator implements Comparator { + + public int compare(Object o1, Object o2) { + if ( ! ( o1 instanceof X11GLCapabilities ) ) { + Class c = (null != o1) ? o1.getClass() : null ; + throw new ClassCastException("arg1 not a X11GLCapabilities object: " + c); + } + if ( ! ( o2 instanceof X11GLCapabilities ) ) { + Class c = (null != o2) ? o2.getClass() : null ; + throw new ClassCastException("arg2 not a X11GLCapabilities object: " + c); + } + + final X11GLCapabilities caps1 = (X11GLCapabilities) o1; + final long id1 = caps1.getXVisualID(); + + final X11GLCapabilities caps2 = (X11GLCapabilities) o2; + final long id2 = caps2.getXVisualID(); + + if(id1 > id2) { + return 1; + } else if(id1 < id2) { + return -1; + } + return 0; + } + } + + public X11GLCapabilities(XVisualInfo xVisualInfo, long fbcfg, int fbcfgid, GLProfile glp) { + super(glp); + this.xVisualInfo = xVisualInfo; + this.fbcfg = fbcfg; + this.fbcfgid = fbcfgid; + } + + public X11GLCapabilities(XVisualInfo xVisualInfo, GLProfile glp) { + super(glp); + this.xVisualInfo = xVisualInfo; + this.fbcfg = 0; + this.fbcfgid = -1; + } + + public Object cloneMutable() { + return clone(); + } + + public Object clone() { + try { + return super.clone(); + } catch (RuntimeException e) { + throw new GLException(e); + } + } + + final public XVisualInfo getXVisualInfo() { return xVisualInfo; } + final public long getXVisualID() { return (null!=xVisualInfo) ? xVisualInfo.getVisualid() : 0; } + final public boolean hasXVisualInfo() { return null!=xVisualInfo; } + + final public long getFBConfig() { return fbcfg; } + final public int getFBConfigID() { return fbcfgid; } + final public boolean hasFBConfig() { return 0!=fbcfg && fbcfgid>0; } + + final static String na_str = "----" ; + + public StringBuffer toString(StringBuffer sink) { + if(null == sink) { + sink = new StringBuffer(); + } + if(hasXVisualInfo()) { + sink.append("0x").append(Long.toHexString(xVisualInfo.getVisualid())); + } else { + sink.append(na_str); + } + sink.append(" "); + if(hasFBConfig()) { + sink.append("0x").append(Integer.toHexString(fbcfgid)); + } else { + sink.append(na_str); + } + sink.append(": "); + return super.toString(sink); + } +}
\ No newline at end of file diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java new file mode 100644 index 000000000..7d7614ca2 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java @@ -0,0 +1,587 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.x11.glx; + +import java.nio.*; +import java.util.*; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.X11GraphicsDevice; + +import com.jogamp.common.util.VersionNumber; +import jogamp.opengl.*; +import com.jogamp.gluegen.runtime.ProcAddressTable; +import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver; +import jogamp.nativewindow.x11.X11Util; + +public abstract class X11GLXContext extends GLContextImpl { + protected static final boolean TRACE_CONTEXT_CURRENT = false; // true; + + private static final Map/*<String, String>*/ functionNameMap; + private static final Map/*<String, String>*/ extensionNameMap; + private VersionNumber glXVersion; + private boolean glXVersionOneThreeCapable; + private boolean glXQueryExtensionsStringInitialized; + private boolean glXQueryExtensionsStringAvailable; + private GLXExt glXExt; + // Table that holds the addresses of the native C-language entry points for + // GLX extension functions. + private GLXExtProcAddressTable glXExtProcAddressTable; + private int hasSwapIntervalSGI = 0; + + // This indicates whether the context we have created is indirect + // and therefore requires the toolkit to be locked around all GL + // calls rather than just all GLX calls + protected boolean isDirect; + + static { + functionNameMap = new HashMap(); + functionNameMap.put("glAllocateMemoryNV", "glXAllocateMemoryNV"); + functionNameMap.put("glFreeMemoryNV", "glXFreeMemoryNV"); + + extensionNameMap = new HashMap(); + extensionNameMap.put("GL_ARB_pbuffer", "GLX_SGIX_pbuffer"); + extensionNameMap.put("GL_ARB_pixel_format", "GLX_SGIX_pbuffer"); // good enough + } + + X11GLXContext(GLDrawableImpl drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + protected void resetState() { + glXVersion = null; + glXVersionOneThreeCapable = false; + glXQueryExtensionsStringInitialized=false; + glXQueryExtensionsStringAvailable=false; + // no inner state glXExt=null; + glXExtProcAddressTable = null; + hasSwapIntervalSGI = 0; + isDirect = false; + } + + public final ProcAddressTable getPlatformExtProcAddressTable() { + return getGLXExtProcAddressTable(); + } + + public final GLXExtProcAddressTable getGLXExtProcAddressTable() { + return glXExtProcAddressTable; + } + + public Object getPlatformGLExtensions() { + return getGLXExt(); + } + + public GLXExt getGLXExt() { + if (glXExt == null) { + glXExt = new GLXExtImpl(this); + } + return glXExt; + } + + protected Map/*<String, String>*/ getFunctionNameMap() { return functionNameMap; } + + protected Map/*<String, String>*/ getExtensionNameMap() { return extensionNameMap; } + + public final boolean isGLXVersionGreaterEqualOneThree() { + if(null == glXVersion) { + X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); + + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + X11GraphicsDevice device = (X11GraphicsDevice) config.getScreen().getDevice(); + + glXVersion = factory.getGLXVersion(device); + glXVersionOneThreeCapable = ( null != glXVersion ) ? glXVersion.compareTo(X11GLXDrawableFactory.versionOneThree) >= 0 : false ; + } + return glXVersionOneThreeCapable; + } + + public final boolean isGLReadDrawableAvailable() { + return isGLXVersionGreaterEqualOneThree(); + } + + private final boolean glXMakeContextCurrent(long dpy, long writeDrawable, long readDrawable, long ctx) { + boolean res = false; + + try { + if(TRACE_CONTEXT_CURRENT) { + Throwable t = new Throwable(Thread.currentThread()+" - glXMakeContextCurrent("+toHexString(dpy)+", "+ + toHexString(writeDrawable)+", "+toHexString(readDrawable)+", "+toHexString(ctx)+") - GLX >= 1.3 "+ glXVersionOneThreeCapable); + t.printStackTrace(); + } + if ( glXVersionOneThreeCapable ) { + res = GLX.glXMakeContextCurrent(dpy, writeDrawable, readDrawable, ctx); + } else if ( writeDrawable == readDrawable ) { + res = GLX.glXMakeCurrent(dpy, writeDrawable, ctx); + } else { + // should not happen due to 'isGLReadDrawableAvailable()' query in GLContextImpl + throw new InternalError("Given readDrawable but no driver support"); + } + } catch (RuntimeException re) { + if(DEBUG) { + System.err.println("Warning: X11GLXContext.glXMakeContextCurrent failed: "+re+", with "+ + "dpy "+toHexString(dpy)+ + ", write "+toHexString(writeDrawable)+ + ", read "+toHexString(readDrawable)+ + ", ctx "+toHexString(ctx)); + re.printStackTrace(); + } + } + return res; + } + + protected void destroyContextARBImpl(long ctx) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + long display = config.getScreen().getDevice().getHandle(); + + glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, ctx); + } + + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + updateGLXProcAddressTable(); + GLXExt _glXExt = getGLXExt(); + if(DEBUG) { + System.err.println("X11GLXContext.createContextARBImpl: "+getGLVersion(major, minor, ctp, "@creation") + + ", handle "+toHexString(drawable.getHandle()) + ", share "+toHexString(share)+", direct "+direct+ + ", glXCreateContextAttribsARB: "+toHexString(glXExtProcAddressTable._addressof_glXCreateContextAttribsARB)); + Thread.dumpStack(); + } + + boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; + boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ; + boolean ctDebug = 0 != ( CTX_OPTION_DEBUG & ctp ) ; + + long ctx=0; + + final int idx_flags = 6; + final int idx_profile = 8; + + int attribs[] = { + /* 0 */ GLX.GLX_CONTEXT_MAJOR_VERSION_ARB, major, + /* 2 */ GLX.GLX_CONTEXT_MINOR_VERSION_ARB, minor, + /* 4 */ GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE, // default + /* 6 */ GLX.GLX_CONTEXT_FLAGS_ARB, 0, + /* 8 */ 0, 0, + /* 10 */ 0 + }; + + if ( major > 3 || major == 3 && minor >= 2 ) { + // FIXME: Verify with a None drawable binding (default framebuffer) + attribs[idx_profile+0] = GLX.GLX_CONTEXT_PROFILE_MASK_ARB; + if( ctBwdCompat ) { + attribs[idx_profile+1] = GLX.GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; + } else { + attribs[idx_profile+1] = GLX.GLX_CONTEXT_CORE_PROFILE_BIT_ARB; + } + } + + if ( major >= 3 ) { + if( !ctBwdCompat && ctFwdCompat ) { + attribs[idx_flags+1] |= GLX.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; + } + if( ctDebug) { + attribs[idx_flags+1] |= GLX.GLX_CONTEXT_DEBUG_BIT_ARB; + } + } + + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice device = config.getScreen().getDevice(); + long display = device.getHandle(); + + try { + // critical path, a remote display might not support this command, + // hence we need to catch the X11 Error within this block. + X11Util.XSync(display, false); + ctx = _glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); + X11Util.XSync(display, false); + } catch (RuntimeException re) { + if(DEBUG) { + Throwable t = new Throwable("Info: X11GLXContext.createContextARBImpl glXCreateContextAttribsARB failed with "+getGLVersion(major, minor, ctp, "@creation"), re); + t.printStackTrace(); + } + } + if(0!=ctx) { + if (!glXMakeContextCurrent(display, drawable.getHandle(), drawableRead.getHandle(), ctx)) { + if(DEBUG) { + System.err.println("X11GLXContext.createContextARBImpl couldn't make current "+getGLVersion(major, minor, ctp, "@creation")); + } + // release & destroy + glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, ctx); + ctx = 0; + } else { + if (DEBUG) { + System.err.println(getThreadName() + ": createContextARBImpl: OK "+getGLVersion(major, minor, ctp, "@creation")+", share "+share+", direct "+direct); + } + // the following is issued by the caller 'GLContextImpl.createContextARB()' + // setGLFunctionAvailability(true, major, minor, ctp); + } + } else if (DEBUG) { + System.err.println(getThreadName() + ": createContextARBImpl: NO "+getGLVersion(major, minor, ctp, "@creation")); + } + + return ctx; + } + + protected boolean createImpl() { + // covers the whole context creation loop incl createContextARBImpl and destroyContextARBImpl + X11Util.setX11ErrorHandler(true, true); + try { + return createImplRaw(); + } finally { + X11Util.setX11ErrorHandler(false, false); + } + } + + private boolean createImplRaw() { + boolean direct = true; // try direct always + isDirect = false; // fall back + + X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice device = config.getScreen().getDevice(); + X11GLXContext sharedContext = (X11GLXContext) factory.getOrCreateSharedContextImpl(device); + long display = device.getHandle(); + + isGLReadDrawableAvailable(); // trigger setup glXVersionOneThreeCapable + + X11GLXContext other = (X11GLXContext) GLContextShareSet.getShareContext(this); + long share = 0; + if (other != null) { + share = other.getHandle(); + if (share == 0) { + throw new GLException("GLContextShareSet returned an invalid OpenGL context"); + } + direct = GLX.glXIsDirect(display, share); + } + + GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + GLProfile glp = glCaps.getGLProfile(); + isVendorATI = factory.isGLXVendorATI(device); + + if(config.getFBConfigID()<0) { + // not able to use FBConfig + if(glp.isGL3()) { + throw new GLException("Unable to create OpenGL >= 3.1 context"); + } + contextHandle = GLX.glXCreateContext(display, config.getXVisualInfo(), share, direct); + if (contextHandle == 0) { + throw new GLException("Unable to create context(0)"); + } + if (!glXMakeContextCurrent(display, drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { + throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(contextHandle)+", drawable "+drawable); + } + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + isDirect = GLX.glXIsDirect(display, contextHandle); + if (DEBUG) { + System.err.println(getThreadName() + ": createContextImpl: OK (old-1) share "+share+", direct "+isDirect+"/"+direct); + } + return true; + } + + int minor[] = new int[1]; + int major[] = new int[1]; + int ctp[] = new int[1]; + boolean createContextARBTried = false; + + // utilize the shared context's GLXExt in case it was using the ARB method and it already exists + if(null!=sharedContext && sharedContext.isCreatedWithARBMethod()) { + contextHandle = createContextARB(share, direct, major, minor, ctp); + createContextARBTried = true; + if (DEBUG && 0!=contextHandle) { + System.err.println(getThreadName() + ": createContextImpl: OK (ARB, using sharedContext) share "+share); + } + } + + long temp_ctx = 0; + if(0==contextHandle) { + // To use GLX_ARB_create_context, we have to make a temp context current, + // so we are able to use GetProcAddress + temp_ctx = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct); + if (temp_ctx == 0) { + throw new GLException("Unable to create temp OpenGL context(1)"); + } + if (!glXMakeContextCurrent(display, drawable.getHandle(), drawableRead.getHandle(), temp_ctx)) { + throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(temp_ctx)+", drawable "+drawable); + } + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + boolean isCreateContextAttribsARBAvailable = isFunctionAvailable("glXCreateContextAttribsARB"); + glXMakeContextCurrent(display, 0, 0, 0); // release temp context + + if( !createContextARBTried ) { + if ( isCreateContextAttribsARBAvailable && + isExtensionAvailable("GLX_ARB_create_context") ) { + // initial ARB context creation + contextHandle = createContextARB(share, direct, major, minor, ctp); + createContextARBTried=true; + if (DEBUG) { + if(0!=contextHandle) { + System.err.println(getThreadName() + ": createContextImpl: OK (ARB, initial) share "+share); + } else { + System.err.println(getThreadName() + ": createContextImpl: NOT OK (ARB, initial) - creation failed - share "+share); + } + } + } else if (DEBUG) { + System.err.println(getThreadName() + ": createContextImpl: NOT OK (ARB, initial) - extension not available - share "+share); + } + } + } + + if(0!=contextHandle) { + if(0!=temp_ctx) { + glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_ctx); + if (!glXMakeContextCurrent(display, drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { + throw new GLException("Cannot make previous verified context current"); + } + } + } else { + if(glp.isGL3()) { + glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_ctx); + throw new GLException("X11GLXContext.createContextImpl failed, but context > GL2 requested "+getGLVersion(major[0], minor[0], ctp[0], "@creation")+", "); + } + if(DEBUG) { + System.err.println("X11GLXContext.createContextImpl failed, fall back to !ARB context "+getGLVersion(major[0], minor[0], ctp[0], "@creation")); + } + + // continue with temp context for GL <= 3.0 + contextHandle = temp_ctx; + if (!glXMakeContextCurrent(display, drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { + glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_ctx); + throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(contextHandle)+", drawable "+drawable); + } + if (DEBUG) { + System.err.println(getThreadName() + ": createContextImpl: OK (old-2) share "+share); + } + } + isDirect = GLX.glXIsDirect(display, contextHandle); + if (DEBUG) { + System.err.println(getThreadName() + ": createContextImpl: OK direct "+isDirect+"/"+direct); + } + return true; + } + + protected void makeCurrentImpl(boolean newCreated) throws GLException { + long dpy = drawable.getNativeSurface().getDisplayHandle(); + + if (GLX.glXGetCurrentContext() != contextHandle) { + X11Util.setX11ErrorHandler(true, true); + try { + if (!glXMakeContextCurrent(dpy, drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { + throw new GLException("Error making context current: "+this); + } + } finally { + X11Util.setX11ErrorHandler(false, false); + } + if (DEBUG && newCreated) { + System.err.println(getThreadName() + ": glXMakeCurrent(display " + + toHexString(dpy)+ + ", drawable " + toHexString(drawable.getHandle()) + + ", drawableRead " + toHexString(drawableRead.getHandle()) + + ", context " + toHexString(contextHandle) + ") succeeded"); + } + } + } + + protected void releaseImpl() throws GLException { + long display = drawable.getNativeSurface().getDisplayHandle(); + X11Util.setX11ErrorHandler(true, true); + try { + if (!glXMakeContextCurrent(display, 0, 0, 0)) { + throw new GLException("Error freeing OpenGL context"); + } + } finally { + X11Util.setX11ErrorHandler(false, false); + } + } + + protected void destroyImpl() throws GLException { + long display = drawable.getNativeSurface().getDisplayHandle(); + if (DEBUG) { + System.err.println("glXDestroyContext(dpy " + + toHexString(display)+ + ", ctx " + + toHexString(contextHandle) + ")"); + } + GLX.glXDestroyContext(display, contextHandle); + if (DEBUG) { + System.err.println("!!! Destroyed OpenGL context " + contextHandle); + } + } + + protected void copyImpl(GLContext source, int mask) throws GLException { + long dst = getHandle(); + long src = source.getHandle(); + long display = drawable.getNativeSurface().getDisplayHandle(); + if (0 == display) { + throw new GLException("Connection to X display not yet set up"); + } + GLX.glXCopyContext(display, src, dst, mask); + // Should check for X errors and raise GLException + } + + protected final void updateGLXProcAddressTable() { + AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); + String key = adevice.getUniqueID(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Initializing GLX extension address table: "+key); + } + glXQueryExtensionsStringInitialized = false; + glXQueryExtensionsStringAvailable = false; + + GLXExtProcAddressTable table = null; + synchronized(mappedContextTypeObjectLock) { + table = (GLXExtProcAddressTable) mappedGLXProcAddress.get( key ); + } + if(null != table) { + glXExtProcAddressTable = table; + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext GLX ProcAddressTable reusing key("+key+") -> "+table.hashCode()); + } + } else { + if (glXExtProcAddressTable == null) { + glXExtProcAddressTable = new GLXExtProcAddressTable(new GLProcAddressResolver()); + } + resetProcAddressTable(getGLXExtProcAddressTable()); + synchronized(mappedContextTypeObjectLock) { + mappedGLXProcAddress.put(key, getGLXExtProcAddressTable()); + if(DEBUG) { + System.err.println(getThreadName() + ": !!! GLContext GLX ProcAddressTable mapping key("+key+") -> "+getGLXExtProcAddressTable().hashCode()); + Thread.dumpStack(); + } + } + } + } + + public synchronized String getPlatformExtensionsString() { + if (!glXQueryExtensionsStringInitialized) { + glXQueryExtensionsStringAvailable = + getDrawableImpl().getGLDynamicLookupHelper().dynamicLookupFunction("glXQueryExtensionsString") != 0; + glXQueryExtensionsStringInitialized = true; + } + if (glXQueryExtensionsStringAvailable) { + NativeSurface ns = drawable.getNativeSurface(); + String ret = GLX.glXQueryExtensionsString(ns.getDisplayHandle(), ns.getScreenIndex()); + if (DEBUG) { + System.err.println("!!! GLX extensions: " + ret); + } + return ret; + } else { + return ""; + } + } + + public boolean isExtensionAvailable(String glExtensionName) { + if (glExtensionName.equals("GL_ARB_pbuffer") || + glExtensionName.equals("GL_ARB_pixel_format")) { + return getGLDrawable().getFactory().canCreateGLPbuffer( + drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice() ); + } + return super.isExtensionAvailable(glExtensionName); + } + + protected void setSwapIntervalImpl(int interval) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(!glCaps.isOnscreen()) return; + + GLXExt glXExt = getGLXExt(); + if(0==hasSwapIntervalSGI) { + try { + hasSwapIntervalSGI = glXExt.isExtensionAvailable("GLX_SGI_swap_control")?1:-1; + } catch (Throwable t) { hasSwapIntervalSGI=1; } + } + if (hasSwapIntervalSGI>0) { + try { + if( 0 == glXExt.glXSwapIntervalSGI(interval) ) { + currentSwapInterval = interval; + } + } catch (Throwable t) { hasSwapIntervalSGI=-1; } + } + } + + public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return getGLXExt().glXAllocateMemoryNV(arg0, arg1, arg2, arg3); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(getClass().getName()); + sb.append(" ["); + super.append(sb); + sb.append(", direct "); + sb.append(isDirect); + sb.append("] "); + return sb.toString(); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private boolean isVendorATI = false; + +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawable.java new file mode 100644 index 000000000..d2ce629df --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawable.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import jogamp.opengl.*; + +public abstract class X11GLXDrawable extends GLDrawableImpl { + protected X11GLXDrawable(GLDrawableFactory factory, NativeSurface comp, boolean realized) { + super(factory, comp, realized); + } + + public GLDynamicLookupHelper getGLDynamicLookupHelper() { + return getFactoryImpl().getGLDynamicLookupHelper(0); + } + + protected void setRealizedImpl() { + if(realized) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + config.updateGraphicsConfiguration(); + + if (DEBUG) { + System.err.println("!!! X11GLXDrawable.setRealized(true): "+config); + } + } + } + + protected void swapBuffersImpl() { + GLX.glXSwapBuffers(getNativeSurface().getDisplayHandle(), getHandle()); + } + + //--------------------------------------------------------------------------- + // Internals only below this point + // +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java new file mode 100644 index 000000000..8203a440c --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java @@ -0,0 +1,552 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package jogamp.opengl.x11.glx; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.nio.*; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import javax.media.opengl.*; + +import jogamp.opengl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; +import jogamp.nativewindow.WrappedSurface; +import jogamp.nativewindow.x11.*; + +public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { + + private static final DesktopGLDynamicLookupHelper x11GLXDynamicLookupHelper; + static final VersionNumber versionOneThree = new VersionNumber(1, 3, 0); + + static { + DesktopGLDynamicLookupHelper tmp = null; + try { + tmp = new DesktopGLDynamicLookupHelper(new X11GLXDynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + x11GLXDynamicLookupHelper = tmp; + if(null!=x11GLXDynamicLookupHelper) { + GLX.getGLXProcAddressTable().reset(x11GLXDynamicLookupHelper); + } + } + + public static VersionNumber getGLXVersion(X11GraphicsDevice device) { + int[] major = new int[1]; + int[] minor = new int[1]; + GLXUtil.getGLXVersion(device.getHandle(), major, minor); + return new VersionNumber(major[0], minor[0], 0); + } + + public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { + return x11GLXDynamicLookupHelper; + } + + public X11GLXDrawableFactory() { + super(); + // Register our GraphicsConfigurationFactory implementations + // The act of constructing them causes them to be registered + new X11GLXGraphicsConfigurationFactory(); + if(GLProfile.isAWTAvailable()) { + try { + ReflectionUtil.createInstance("jogamp.opengl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory", + null, getClass().getClassLoader()); + } catch (JogampRuntimeException jre) { /* n/a .. */ } + } + + defaultDevice = new X11GraphicsDevice(X11Util.getNullDisplayName(), AbstractGraphicsDevice.DEFAULT_UNIT); + + // Init shared resources off thread + // Will be released via ShutdownHook + sharedResourceImpl = new SharedResourceImplementation(); + sharedResourceRunner = new SharedResourceRunner(sharedResourceImpl); + sharedResourceThread = new Thread(sharedResourceRunner, Thread.currentThread().getName()+"-SharedResourceRunner"); + sharedResourceThread.setDaemon(true); // Allow JVM to exit, even if this one is running + sharedResourceThread.start(); + } + + X11GraphicsDevice defaultDevice; + SharedResourceImplementation sharedResourceImpl; + SharedResourceRunner sharedResourceRunner; + Thread sharedResourceThread; + HashMap/*<connection, SharedResource>*/ sharedMap = new HashMap(); + + static class SharedResource implements SharedResourceRunner.Resource { + X11GraphicsDevice device; + X11GraphicsScreen screen; + X11DummyGLXDrawable drawable; + X11GLXContext context; + String glXVendorName; + boolean isGLXVendorATI; + boolean isGLXVendorNVIDIA; + VersionNumber glXVersion; + + SharedResource(X11GraphicsDevice dev, X11GraphicsScreen scrn, + X11DummyGLXDrawable draw, X11GLXContext ctx, + VersionNumber glXVer, String glXVendor) { + device = dev; + screen = scrn; + drawable = draw; + context = ctx; + glXVersion = glXVer; + glXVendorName = glXVendor; + isGLXVendorATI = GLXUtil.isVendorATI(glXVendorName); + isGLXVendorNVIDIA = GLXUtil.isVendorNVIDIA(glXVendorName); + } + final public AbstractGraphicsDevice getDevice() { return device; } + final public AbstractGraphicsScreen getScreen() { return screen; } + final public GLDrawableImpl getDrawable() { return drawable; } + final public GLContextImpl getContext() { return context; } + + final String getGLXVendorName() { return glXVendorName; } + final boolean isGLXVendorATI() { return isGLXVendorATI; } + final boolean isGLXVendorNVIDIA() { return isGLXVendorNVIDIA; } + final VersionNumber getGLXVersion() { return glXVersion; } + final boolean isGLXVersionGreaterEqualOneThree() { + return ( null != glXVersion ) ? glXVersion.compareTo(versionOneThree) >= 0 : false ; + } + } + + class SharedResourceImplementation implements SharedResourceRunner.Implementation { + public void clear() { + synchronized(sharedMap) { + sharedMap.clear(); + } + } + public SharedResourceRunner.Resource mapPut(String connection, SharedResourceRunner.Resource resource) { + synchronized(sharedMap) { + return (SharedResourceRunner.Resource) sharedMap.put(connection, resource); + } + } + public SharedResourceRunner.Resource mapGet(String connection) { + synchronized(sharedMap) { + return (SharedResourceRunner.Resource) sharedMap.get(connection); + } + } + public Collection/*<Resource>*/ mapValues() { + synchronized(sharedMap) { + return sharedMap.values(); + } + } + + public SharedResourceRunner.Resource createSharedResource(String connection) { + X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.createDisplay(connection), AbstractGraphicsDevice.DEFAULT_UNIT); + sharedDevice.setCloseDisplay(true); + sharedDevice.lock(); + try { + String glXVendorName = GLXUtil.getVendorName(sharedDevice.getHandle()); + X11GraphicsScreen sharedScreen = new X11GraphicsScreen(sharedDevice, 0); + + if (null == sharedScreen) { + throw new GLException("Couldn't create shared screen for device: "+sharedDevice+", idx 0"); + } + GLProfile glp = GLProfile.getMinDesktop(sharedDevice); + if (null == glp) { + throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice); + } + X11DummyGLXDrawable sharedDrawable = X11DummyGLXDrawable.create(sharedScreen, X11GLXDrawableFactory.this, glp); + if (null == sharedDrawable) { + throw new GLException("Couldn't create shared drawable for screen: "+sharedScreen+", "+glp); + } + X11GLXContext sharedContext = (X11GLXContext) sharedDrawable.createContext(null); + if (null == sharedContext) { + throw new GLException("Couldn't create shared context for drawable: "+sharedDrawable); + } + sharedContext.setSynchronized(true); + VersionNumber glXVersion = getGLXVersion(sharedDevice); + boolean madeCurrent = false; + sharedContext.makeCurrent(); + try { + madeCurrent = sharedContext.isCurrent(); + } finally { + sharedContext.release(); + } + if (DEBUG) { + System.err.println("!!! SharedDevice: " + sharedDevice); + System.err.println("!!! SharedScreen: " + sharedScreen); + System.err.println("!!! SharedContext: " + sharedContext + ", madeCurrent " + madeCurrent); + System.err.println("!!! GLX Vendor: " + glXVendorName); + System.err.println("!!! GLX Version: " + glXVersion + + " >= 1.3: " + (glXVersion.compareTo(versionOneThree) >= 0)); + } + return new SharedResource(sharedDevice, sharedScreen, sharedDrawable, sharedContext, glXVersion, glXVendorName); + } catch (Throwable t) { + throw new GLException("WindowsWGLDrawableFactory - Could not initialize shared resources for "+connection, t); + } finally { + sharedDevice.unlock(); + } + } + + public void releaseSharedResource(SharedResourceRunner.Resource shared) { + SharedResource sr = (SharedResource) shared; + if (DEBUG) { + System.err.println("!!! Shutdown Shared:"); + System.err.println("!!! Device : " + sr.device); + System.err.println("!!! Screen : " + sr.screen); + System.err.println("!!! Drawable: " + sr.drawable); + System.err.println("!!! CTX : " + sr.context); + } + + if (null != sr.context) { + // may cause JVM SIGSEGV: sharedContext.destroy(); + sr.context = null; + } + + if (null != sr.drawable) { + // may cause JVM SIGSEGV: sharedDrawable.destroy(); + sr.drawable = null; + } + + if (null != sr.screen) { + sr.screen = null; + } + + if (null != sr.device) { + sr.device.close(); + sr.device = null; + } + } + } + + public final AbstractGraphicsDevice getDefaultDevice() { + return defaultDevice; + } + + public final boolean getIsDeviceCompatible(AbstractGraphicsDevice device) { + if(device instanceof X11GraphicsDevice) { + return true; + } + return false; + } + + protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.getContext(); + } + return null; + } + + protected AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.getDevice(); + } + return null; + } + + protected final long getOrCreateSharedDpy(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.getDevice().getHandle(); + } + return 0; + } + + SharedResource getOrCreateSharedResource(AbstractGraphicsDevice device) { + return (SharedResource) sharedResourceRunner.getOrCreateShared(device); + } + + public final String getGLXVendorName(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return ((SharedResource)sr).getGLXVendorName(); + } + return GLXUtil.getVendorName(device.getHandle()); + } + + public final boolean isGLXVendorATI(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return ((SharedResource)sr).isGLXVendorATI(); + } + return GLXUtil.isVendorATI(device.getHandle()); + } + + public final boolean isGLXVendorNVIDIA(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return ((SharedResource)sr).isGLXVendorNVIDIA(); + } + return GLXUtil.isVendorNVIDIA(device.getHandle()); + } + + protected final void shutdownInstance() { + sharedResourceRunner.releaseAndWait(); + + // Don't really close pending Display connections, + // since this may trigger a JVM exception + X11Util.shutdown( false, DEBUG ); + } + + protected List/*GLCapabilitiesImmutable*/ getAvailableCapabilitiesImpl(AbstractGraphicsDevice device) { + return X11GLXGraphicsConfigurationFactory.getAvailableCapabilities(this, device); + } + + protected final GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + return new X11OnscreenGLXDrawable(this, target); + } + + protected final GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(!caps.isPBuffer()) { + return new X11PixmapGLXDrawable(this, target); + } + + // PBuffer GLDrawable Creation + GLDrawableImpl pbufferDrawable; + AbstractGraphicsDevice device = config.getScreen().getDevice(); + + /** + * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, + * we need to have a context current on the same Display to create a PBuffer. + * The dummy context shall also use the same Display, + * since switching Display in this regard is another ATI bug. + */ + SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); + if( null!=sr && sr.isGLXVendorATI() && null == GLContext.getCurrent() ) { + sr.getContext().makeCurrent(); + try { + pbufferDrawable = new X11PbufferGLXDrawable(this, target); + } finally { + sr.getContext().release(); + } + } else { + pbufferDrawable = new X11PbufferGLXDrawable(this, target); + } + return pbufferDrawable; + } + + public final boolean isGLXVersionGreaterEqualOneThree(AbstractGraphicsDevice device) { + SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + return sr.isGLXVersionGreaterEqualOneThree(); + } + if( device instanceof X11GraphicsDevice ) { + VersionNumber v = getGLXVersion( (X11GraphicsDevice) device); + return ( null != v ) ? v.compareTo(versionOneThree) >= 0 : false ; + } + return false; + } + + public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + if(null == device) { + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(defaultDevice); + if(null!=sr) { + device = sr.getDevice(); + } + } + return isGLXVersionGreaterEqualOneThree(device); + } + + protected final NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, + GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser, + int width, int height) { + X11GraphicsScreen screen = null; + SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + if(null!=sr) { + screen = (X11GraphicsScreen) sr.getScreen(); + } + if(null==screen) { + return null; + } + + WrappedSurface ns = new WrappedSurface( + X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen) ); + if(ns != null) { + ns.setSize(width, height); + } + return ns; + } + + protected final ProxySurface createProxySurfaceImpl(AbstractGraphicsDevice adevice, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser) { + // FIXME device/windowHandle -> screen ?! + X11GraphicsDevice device = (X11GraphicsDevice) adevice; + X11GraphicsScreen screen = new X11GraphicsScreen(device, 0); + X11GLXGraphicsConfiguration cfg = X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsRequested, capsRequested, chooser, screen); + WrappedSurface ns = new WrappedSurface(cfg, windowHandle); + return ns; + } + + protected final GLContext createExternalGLContextImpl() { + return X11ExternalGLXContext.create(this, null); + } + + public final boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { + return canCreateGLPbuffer(device); + } + + protected final GLDrawable createExternalGLDrawableImpl() { + return X11ExternalGLXDrawable.create(this, null); + } + + public final boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { + return false; + } + + public final GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) + throws GLException { + throw new GLException("Unimplemented on this platform"); + } + + //---------------------------------------------------------------------- + // Gamma-related functionality + // + + private boolean gotGammaRampLength; + private int gammaRampLength; + protected final synchronized int getGammaRampLength() { + if (gotGammaRampLength) { + return gammaRampLength; + } + + long display = getOrCreateSharedDpy(defaultDevice); + if(0 == display) { + return 0; + } + + int[] size = new int[1]; + boolean res = X11Util.XF86VidModeGetGammaRampSize(display, + X11Util.DefaultScreen(display), + size, 0); + if (!res) { + return 0; + } + gotGammaRampLength = true; + gammaRampLength = size[0]; + return gammaRampLength; + } + + protected final boolean setGammaRamp(float[] ramp) { + long display = getOrCreateSharedDpy(defaultDevice); + if(0 == display) { + return false; + } + + int len = ramp.length; + short[] rampData = new short[len]; + for (int i = 0; i < len; i++) { + rampData[i] = (short) (ramp[i] * 65535); + } + + boolean res = X11Util.XF86VidModeSetGammaRamp(display, + X11Util.DefaultScreen(display), + rampData.length, + rampData, 0, + rampData, 0, + rampData, 0); + return res; + } + + protected final Buffer getGammaRamp() { + long display = getOrCreateSharedDpy(defaultDevice); + if(0 == display) { + return null; + } + + int size = getGammaRampLength(); + ShortBuffer rampData = ShortBuffer.wrap(new short[3 * size]); + rampData.position(0); + rampData.limit(size); + ShortBuffer redRampData = rampData.slice(); + rampData.position(size); + rampData.limit(2 * size); + ShortBuffer greenRampData = rampData.slice(); + rampData.position(2 * size); + rampData.limit(3 * size); + ShortBuffer blueRampData = rampData.slice(); + + boolean res = X11Util.XF86VidModeGetGammaRamp(display, + X11Util.DefaultScreen(display), + size, + redRampData, + greenRampData, + blueRampData); + if (!res) { + return null; + } + return rampData; + } + + protected final void resetGammaRamp(Buffer originalGammaRamp) { + if (originalGammaRamp == null) { + return; // getGammaRamp failed originally + } + long display = getOrCreateSharedDpy(defaultDevice); + if(0 == display) { + return; + } + + ShortBuffer rampData = (ShortBuffer) originalGammaRamp; + int capacity = rampData.capacity(); + if ((capacity % 3) != 0) { + throw new IllegalArgumentException("Must not be the original gamma ramp"); + } + int size = capacity / 3; + rampData.position(0); + rampData.limit(size); + ShortBuffer redRampData = rampData.slice(); + rampData.position(size); + rampData.limit(2 * size); + ShortBuffer greenRampData = rampData.slice(); + rampData.position(2 * size); + rampData.limit(3 * size); + ShortBuffer blueRampData = rampData.slice(); + + X11Util.XF86VidModeSetGammaRamp(display, + X11Util.DefaultScreen(display), + size, + redRampData, + greenRampData, + blueRampData); + } +} diff --git a/src/com/jogamp/graph/font/Font.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDynamicLibraryBundleInfo.java index a4ab527e2..51b6144c5 100644 --- a/src/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDynamicLibraryBundleInfo.java @@ -3,14 +3,14 @@ * * 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 @@ -20,63 +20,65 @@ * 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.graph.font; + +package jogamp.opengl.x11.glx; -import com.jogamp.graph.geom.AABBox; +import jogamp.opengl.*; +import java.util.*; -/** - * Interface wrapper for font implementation. - * - * TrueType Font Specification: - * http://developer.apple.com/fonts/ttrefman/rm06/Chap6.html - * - * TrueType Font Table Introduction: - * http://scripts.sil.org/cms/scripts/page.php?item_id=IWS-Chapter08 - */ +public class X11GLXDynamicLibraryBundleInfo extends DesktopGLDynamicLibraryBundleInfo { + protected X11GLXDynamicLibraryBundleInfo() { + super(); + } + + public List getToolLibNames() { + List/*<List>*/ libNamesList = new ArrayList(); + + List/*<String>*/ glesLibNames = new ArrayList(); + + // Be aware that on DRI systems, eg ATI fglrx, etc, + // you have to set LIBGL_DRIVERS_PATH env variable. + // Eg on Ubuntu 64bit systems this is: + // export LIBGL_DRIVERS_PATH=/usr/lib/fglrx/dri:/usr/lib32/fglrx/dri + // + + // this is the default GL lib name, according to the spec + glesLibNames.add("libGL.so.1"); + + // try this one as well, if spec fails + glesLibNames.add("libGL.so"); + + // last but not least .. the generic one + glesLibNames.add("GL"); + + libNamesList.add(glesLibNames); + + return libNamesList; + } -public interface Font { + /** + * This respects old DRI requirements:<br> + * <pre> + * http://dri.sourceforge.net/doc/DRIuserguide.html + * </pre> + */ + public boolean shallLinkGlobal() { return true; } - /** - * Metrics for font - * - * Depending on the font's direction, horizontal or vertical, - * the following tables shall be used: - * - * Vertical http://developer.apple.com/fonts/TTRefMan/RM06/Chap6vhea.html - * Horizontal http://developer.apple.com/fonts/TTRefMan/RM06/Chap6hhea.html - */ - public interface Metrics { - float getAscent(float pixelSize); - float getDescent(float pixelSize); - float getLineGap(float pixelSize); - float getMaxExtend(float pixelSize); - float getScale(float pixelSize); - AABBox getBBox(float pixelSize); + public final List getToolGetProcAddressFuncNameList() { + List res = new ArrayList(); + res.add("glXGetProcAddressARB"); + res.add("glXGetProcAddress"); + return res; } - /** - * Glyph for font - */ - public interface Glyph { - public Font getFont(); - public char getSymbol(); - public AABBox getBBox(float pixelSize); - public float getAdvance(float pixelSize, boolean useFrationalMetrics); + public final long toolDynamicLookupFunction(long toolGetProcAddressHandle, String funcName) { + return GLX.glXGetProcAddress(toolGetProcAddressHandle, funcName); } +} - public String getName(); - - public Metrics getMetrics(); - public Glyph getGlyph(char symbol); - public int getNumGlyphs(); - - public float getStringWidth(String string, float pixelSize); - public float getStringHeight(String string, float pixelSize); - public AABBox getStringBounds(CharSequence string, float pixelSize); -}
\ No newline at end of file diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java new file mode 100644 index 000000000..109311123 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java @@ -0,0 +1,450 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.x11.glx; + +import java.util.ArrayList; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import javax.media.opengl.*; + +import com.jogamp.common.nio.PointerBuffer; +import jogamp.opengl.*; +import jogamp.nativewindow.x11.*; + +public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implements Cloneable { + protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); + + public static final int MAX_ATTRIBS = 128; + private GLCapabilitiesChooser chooser; + + X11GLXGraphicsConfiguration(X11GraphicsScreen screen, + X11GLCapabilities capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser) { + super(screen, capsChosen, capsRequested, capsChosen.getXVisualInfo()); + this.chooser=chooser; + } + + static X11GLXGraphicsConfiguration create(GLProfile glp, X11GraphicsScreen x11Screen, int fbcfgID) { + long display = x11Screen.getDevice().getHandle(); + if(0==display) { + throw new GLException("Display null of "+x11Screen); + } + int screen = x11Screen.getIndex(); + long fbcfg = glXFBConfigID2FBConfig(display, screen, fbcfgID); + if(0==fbcfg) { + throw new GLException("FBConfig null of "+toHexString(fbcfgID)); + } + if(null==glp) { + glp = GLProfile.getDefault(x11Screen.getDevice()); + } + X11GLCapabilities caps = GLXFBConfig2GLCapabilities(glp, display, fbcfg, true, true, true, GLXUtil.isMultisampleAvailable(display)); + if(null==caps) { + throw new GLException("GLCapabilities null of "+toHexString(fbcfg)); + } + return new X11GLXGraphicsConfiguration(x11Screen, caps, caps, new DefaultGLCapabilitiesChooser()); + } + + public Object clone() { + return super.clone(); + } + + public final long getFBConfig() { + return ((X11GLCapabilities)capabilitiesChosen).getFBConfig(); + } + public final int getFBConfigID() { + return ((X11GLCapabilities)capabilitiesChosen).getFBConfigID(); + } + + void updateGraphicsConfiguration() { + X11GLXGraphicsConfiguration newConfig = (X11GLXGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(getScreen().getDevice()).chooseGraphicsConfiguration( + getChosenCapabilities(), getRequestedCapabilities(), chooser, getScreen()); + if(null!=newConfig) { + // FIXME: setScreen( ... ); + setXVisualInfo(newConfig.getXVisualInfo()); + setChosenCapabilities(newConfig.getChosenCapabilities()); + if(DEBUG) { + System.err.println("!!! updateGraphicsConfiguration: "+this); + } + } + } + + private static int nonZeroOrDontCare(int value) { + return value != 0 ? value : (int)GLX.GLX_DONT_CARE ; + } + + static int[] GLCapabilities2AttribList(GLCapabilitiesImmutable caps, + boolean forFBAttr, + boolean isMultisampleAvailable, + long display, + int screen) + { + int colorDepth = (caps.getRedBits() + + caps.getGreenBits() + + caps.getBlueBits()); + if (colorDepth < 15) { + throw new GLException("Bit depths < 15 (i.e., non-true-color) not supported"); + } + int[] res = new int[MAX_ATTRIBS]; + int idx = 0; + + if (forFBAttr) { + res[idx++] = GLX.GLX_DRAWABLE_TYPE; + res[idx++] = caps.isOnscreen() ? ( GLX.GLX_WINDOW_BIT ) : ( caps.isPBuffer() ? GLX.GLX_PBUFFER_BIT : GLX.GLX_PIXMAP_BIT ) ; + } + + if (forFBAttr) { + res[idx++] = GLX.GLX_RENDER_TYPE; + res[idx++] = GLX.GLX_RGBA_BIT; + } else { + res[idx++] = GLX.GLX_RGBA; + } + + // FIXME: Still a bug is Mesa: PBUFFER && GLX_STEREO==GL_FALSE ? + if (forFBAttr) { + res[idx++] = GLX.GLX_DOUBLEBUFFER; + res[idx++] = caps.getDoubleBuffered()?GL.GL_TRUE:GL.GL_FALSE; + res[idx++] = GLX.GLX_STEREO; + res[idx++] = caps.getStereo()?GL.GL_TRUE:GL.GL_FALSE; + res[idx++] = GLX.GLX_TRANSPARENT_TYPE; + res[idx++] = caps.isBackgroundOpaque()?GLX.GLX_NONE:GLX.GLX_TRANSPARENT_RGB; + if(!caps.isBackgroundOpaque()) { + res[idx++] = GLX.GLX_TRANSPARENT_RED_VALUE; + res[idx++] = caps.getTransparentRedValue()>=0?caps.getTransparentRedValue():(int)GLX.GLX_DONT_CARE; + res[idx++] = GLX.GLX_TRANSPARENT_GREEN_VALUE; + res[idx++] = caps.getTransparentGreenValue()>=0?caps.getTransparentGreenValue():(int)GLX.GLX_DONT_CARE; + res[idx++] = GLX.GLX_TRANSPARENT_BLUE_VALUE; + res[idx++] = caps.getTransparentBlueValue()>=0?caps.getTransparentBlueValue():(int)GLX.GLX_DONT_CARE; + res[idx++] = GLX.GLX_TRANSPARENT_ALPHA_VALUE; + res[idx++] = caps.getTransparentAlphaValue()>=0?caps.getTransparentAlphaValue():(int)GLX.GLX_DONT_CARE; + } + } else { + if (caps.getDoubleBuffered()) { + res[idx++] = GLX.GLX_DOUBLEBUFFER; + } + if (caps.getStereo()) { + res[idx++] = GLX.GLX_STEREO; + } + } + + res[idx++] = GLX.GLX_RED_SIZE; + res[idx++] = caps.getRedBits(); + res[idx++] = GLX.GLX_GREEN_SIZE; + res[idx++] = caps.getGreenBits(); + res[idx++] = GLX.GLX_BLUE_SIZE; + res[idx++] = caps.getBlueBits(); + res[idx++] = GLX.GLX_ALPHA_SIZE; + res[idx++] = caps.getAlphaBits(); + res[idx++] = GLX.GLX_DEPTH_SIZE; + res[idx++] = caps.getDepthBits(); + if (caps.getStencilBits() > 0) { + res[idx++] = GLX.GLX_STENCIL_SIZE; + res[idx++] = caps.getStencilBits(); + } + if (caps.getAccumRedBits() > 0 || + caps.getAccumGreenBits() > 0 || + caps.getAccumBlueBits() > 0 || + caps.getAccumAlphaBits() > 0) { + res[idx++] = GLX.GLX_ACCUM_RED_SIZE; + res[idx++] = caps.getAccumRedBits(); + res[idx++] = GLX.GLX_ACCUM_GREEN_SIZE; + res[idx++] = caps.getAccumGreenBits(); + res[idx++] = GLX.GLX_ACCUM_BLUE_SIZE; + res[idx++] = caps.getAccumBlueBits(); + res[idx++] = GLX.GLX_ACCUM_ALPHA_SIZE; + res[idx++] = caps.getAccumAlphaBits(); + } + if (isMultisampleAvailable && caps.getSampleBuffers()) { + res[idx++] = GLX.GLX_SAMPLE_BUFFERS; + res[idx++] = GL.GL_TRUE; + res[idx++] = GLX.GLX_SAMPLES; + res[idx++] = caps.getNumSamples(); + } + if (caps.isPBuffer()) { + if (caps.getPbufferFloatingPointBuffers()) { + String glXExtensions = GLX.glXQueryExtensionsString(display, screen); + if (glXExtensions == null || + glXExtensions.indexOf("GLX_NV_float_buffer") < 0) { + throw new GLException("Floating-point pbuffers on X11 currently require NVidia hardware: "+glXExtensions); + } + res[idx++] = GLXExt.GLX_FLOAT_COMPONENTS_NV; + res[idx++] = GL.GL_TRUE; + } + } + res[idx++] = 0; + return res; + } + + // FBConfig + + static boolean GLXFBConfigValid(long display, long fbcfg) { + int[] tmp = new int[1]; + if(GLX.GLX_BAD_ATTRIBUTE == GLX.glXGetFBConfigAttrib(display, fbcfg, GLX.GLX_RENDER_TYPE, tmp, 0)) { + return false; + } + return true; + } + + static int FBCfgDrawableTypeBits(final long display, final long fbcfg) { + int val = 0; + + int[] tmp = new int[1]; + int fbtype = glXGetFBConfig(display, fbcfg, GLX.GLX_DRAWABLE_TYPE, tmp, 0); + + if ( 0 != ( fbtype & GLX.GLX_WINDOW_BIT ) ) { + val |= GLGraphicsConfigurationUtil.WINDOW_BIT; + } + if ( 0 != ( fbtype & GLX.GLX_PIXMAP_BIT ) ) { + val |= GLGraphicsConfigurationUtil.BITMAP_BIT; + } + if ( 0 != ( fbtype & GLX.GLX_PBUFFER_BIT ) ) { + val |= GLGraphicsConfigurationUtil.PBUFFER_BIT; + } + return val; + } + + static X11GLCapabilities GLXFBConfig2GLCapabilities(GLProfile glp, long display, long fbcfg, + boolean relaxed, boolean onscreen, boolean usePBuffer, + boolean isMultisampleAvailable) { + ArrayList bucket = new ArrayList(); + final int winattrmask = GLGraphicsConfigurationUtil.getWinAttributeBits(onscreen, usePBuffer); + if( GLXFBConfig2GLCapabilities(bucket, glp, display, fbcfg, winattrmask, isMultisampleAvailable) ) { + return (X11GLCapabilities) bucket.get(0); + } else if ( relaxed && GLXFBConfig2GLCapabilities(bucket, glp, display, fbcfg, GLGraphicsConfigurationUtil.ALL_BITS, isMultisampleAvailable) ) { + return (X11GLCapabilities) bucket.get(0); + } + return null; + } + + static boolean GLXFBConfig2GLCapabilities(ArrayList capsBucket, + GLProfile glp, long display, long fbcfg, + int winattrmask, boolean isMultisampleAvailable) { + final int allDrawableTypeBits = FBCfgDrawableTypeBits(display, fbcfg); + int drawableTypeBits = winattrmask & allDrawableTypeBits; + + int fbcfgid = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfg); + XVisualInfo visualInfo = GLX.glXGetVisualFromFBConfig(display, fbcfg); + if(null == visualInfo) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities: Null XVisualInfo for FBConfigID 0x" + Integer.toHexString(fbcfgid)); + } + // onscreen must have an XVisualInfo + drawableTypeBits = drawableTypeBits & ~GLGraphicsConfigurationUtil.WINDOW_BIT; + } + + if( 0 == drawableTypeBits ) { + return false; + } + + int[] tmp = new int[1]; + if(GLX.GLX_BAD_ATTRIBUTE == GLX.glXGetFBConfigAttrib(display, fbcfg, GLX.GLX_RENDER_TYPE, tmp, 0)) { + return false; + } + if( 0 == ( GLX.GLX_RGBA_BIT & tmp[0] ) ) { + return false; // no RGBA -> color index not supported + } + + GLCapabilities res = new X11GLCapabilities(visualInfo, fbcfg, fbcfgid, glp); + res.setDoubleBuffered(glXGetFBConfig(display, fbcfg, GLX.GLX_DOUBLEBUFFER, tmp, 0) != 0); + res.setStereo (glXGetFBConfig(display, fbcfg, GLX.GLX_STEREO, tmp, 0) != 0); + res.setHardwareAccelerated(glXGetFBConfig(display, fbcfg, GLX.GLX_CONFIG_CAVEAT, tmp, 0) != GLX.GLX_SLOW_CONFIG); + res.setDepthBits (glXGetFBConfig(display, fbcfg, GLX.GLX_DEPTH_SIZE, tmp, 0)); + res.setStencilBits (glXGetFBConfig(display, fbcfg, GLX.GLX_STENCIL_SIZE, tmp, 0)); + res.setRedBits (glXGetFBConfig(display, fbcfg, GLX.GLX_RED_SIZE, tmp, 0)); + res.setGreenBits (glXGetFBConfig(display, fbcfg, GLX.GLX_GREEN_SIZE, tmp, 0)); + res.setBlueBits (glXGetFBConfig(display, fbcfg, GLX.GLX_BLUE_SIZE, tmp, 0)); + res.setAlphaBits (glXGetFBConfig(display, fbcfg, GLX.GLX_ALPHA_SIZE, tmp, 0)); + res.setAccumRedBits (glXGetFBConfig(display, fbcfg, GLX.GLX_ACCUM_RED_SIZE, tmp, 0)); + res.setAccumGreenBits(glXGetFBConfig(display, fbcfg, GLX.GLX_ACCUM_GREEN_SIZE, tmp, 0)); + res.setAccumBlueBits (glXGetFBConfig(display, fbcfg, GLX.GLX_ACCUM_BLUE_SIZE, tmp, 0)); + res.setAccumAlphaBits(glXGetFBConfig(display, fbcfg, GLX.GLX_ACCUM_ALPHA_SIZE, tmp, 0)); + if (isMultisampleAvailable) { + res.setSampleBuffers(glXGetFBConfig(display, fbcfg, GLX.GLX_SAMPLE_BUFFERS, tmp, 0) != 0); + res.setNumSamples (glXGetFBConfig(display, fbcfg, GLX.GLX_SAMPLES, tmp, 0)); + } + res.setBackgroundOpaque(glXGetFBConfig(display, fbcfg, GLX.GLX_TRANSPARENT_TYPE, tmp, 0) == GLX.GLX_NONE); + if(!res.isBackgroundOpaque()) { + glXGetFBConfig(display, fbcfg, GLX.GLX_TRANSPARENT_RED_VALUE, tmp, 0); + res.setTransparentRedValue(tmp[0]==GLX.GLX_DONT_CARE?-1:tmp[0]); + + glXGetFBConfig(display, fbcfg, GLX.GLX_TRANSPARENT_GREEN_VALUE, tmp, 0); + res.setTransparentGreenValue(tmp[0]==GLX.GLX_DONT_CARE?-1:tmp[0]); + + glXGetFBConfig(display, fbcfg, GLX.GLX_TRANSPARENT_BLUE_VALUE, tmp, 0); + res.setTransparentBlueValue(tmp[0]==GLX.GLX_DONT_CARE?-1:tmp[0]); + + glXGetFBConfig(display, fbcfg, GLX.GLX_TRANSPARENT_ALPHA_VALUE, tmp, 0); + res.setTransparentAlphaValue(tmp[0]==GLX.GLX_DONT_CARE?-1:tmp[0]); + } + try { + res.setPbufferFloatingPointBuffers(glXGetFBConfig(display, fbcfg, GLXExt.GLX_FLOAT_COMPONENTS_NV, tmp, 0) != GL.GL_FALSE); + } catch (Exception e) {} + + return GLGraphicsConfigurationUtil.addGLCapabilitiesPermutations(capsBucket, res, drawableTypeBits ); + } + + private static String glXGetFBConfigErrorCode(int err) { + switch (err) { + case GLX.GLX_NO_EXTENSION: return "GLX_NO_EXTENSION"; + case GLX.GLX_BAD_ATTRIBUTE: return "GLX_BAD_ATTRIBUTE"; + default: return "Unknown error code " + err; + } + } + + static int glXGetFBConfig(long display, long cfg, int attrib, int[] tmp, int tmp_offset) { + if (display == 0) { + throw new GLException("No display connection"); + } + int res = GLX.glXGetFBConfigAttrib(display, cfg, attrib, tmp, tmp_offset); + if (res != 0) { + throw new GLException("glXGetFBConfig("+toHexString(attrib)+") failed: error code " + glXGetFBConfigErrorCode(res)); + } + return tmp[tmp_offset]; + } + + static int glXFBConfig2FBConfigID(long display, long cfg) { + int[] tmpID = new int[1]; + return glXGetFBConfig(display, cfg, GLX.GLX_FBCONFIG_ID, tmpID, 0); + } + + static long glXFBConfigID2FBConfig(long display, int screen, int id) { + int[] attribs = new int[] { GLX.GLX_FBCONFIG_ID, id, 0 }; + int[] count = { -1 }; + PointerBuffer fbcfgsL = GLX.glXChooseFBConfig(display, screen, attribs, 0, count, 0); + if (fbcfgsL == null || fbcfgsL.limit()<1) { + return 0; + } + return fbcfgsL.get(0); + } + + // Visual Info + + static XVisualInfo XVisualID2XVisualInfo(long display, long visualID) { + int[] count = new int[1]; + XVisualInfo template = XVisualInfo.create(); + template.setVisualid(visualID); + XVisualInfo[] infos = X11Util.XGetVisualInfo(display, X11Lib.VisualIDMask, template, count, 0); + if (infos == null || infos.length == 0) { + return null; + } + XVisualInfo res = XVisualInfo.create(infos[0]); + if (DEBUG) { + System.err.println("!!! Fetched XVisualInfo for visual ID " + toHexString(visualID)); + System.err.println("!!! Resulting XVisualInfo: visualid = " + toHexString(res.getVisualid())); + } + return res; + } + + static boolean XVisualInfo2GLCapabilities(ArrayList capsBucket, + GLProfile glp, long display, XVisualInfo info, + final int winattrmask, boolean isMultisampleEnabled) { + final int allDrawableTypeBits = GLGraphicsConfigurationUtil.WINDOW_BIT | GLGraphicsConfigurationUtil.BITMAP_BIT ; + final int drawableTypeBits = winattrmask & allDrawableTypeBits; + + if( 0 == drawableTypeBits ) { + return false; + } + + int[] tmp = new int[1]; + int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp, 0); + if (val == 0) { + if(DEBUG) { + System.err.println("Visual ("+toHexString(info.getVisualid())+") does not support OpenGL"); + } + return false; + } + val = glXGetConfig(display, info, GLX.GLX_RGBA, tmp, 0); + if (val == 0) { + if(DEBUG) { + System.err.println("Visual ("+toHexString(info.getVisualid())+") does not support RGBA"); + } + return false; + } + + GLCapabilities res = new X11GLCapabilities(info, glp); + + res.setDoubleBuffered(glXGetConfig(display, info, GLX.GLX_DOUBLEBUFFER, tmp, 0) != 0); + res.setStereo (glXGetConfig(display, info, GLX.GLX_STEREO, tmp, 0) != 0); + // Note: use of hardware acceleration is determined by + // glXCreateContext, not by the XVisualInfo. Optimistically claim + // that all GLCapabilities have the capability to be hardware + // accelerated. + res.setHardwareAccelerated(true); + res.setDepthBits (glXGetConfig(display, info, GLX.GLX_DEPTH_SIZE, tmp, 0)); + res.setStencilBits (glXGetConfig(display, info, GLX.GLX_STENCIL_SIZE, tmp, 0)); + res.setRedBits (glXGetConfig(display, info, GLX.GLX_RED_SIZE, tmp, 0)); + res.setGreenBits (glXGetConfig(display, info, GLX.GLX_GREEN_SIZE, tmp, 0)); + res.setBlueBits (glXGetConfig(display, info, GLX.GLX_BLUE_SIZE, tmp, 0)); + res.setAlphaBits (glXGetConfig(display, info, GLX.GLX_ALPHA_SIZE, tmp, 0)); + res.setAccumRedBits (glXGetConfig(display, info, GLX.GLX_ACCUM_RED_SIZE, tmp, 0)); + res.setAccumGreenBits(glXGetConfig(display, info, GLX.GLX_ACCUM_GREEN_SIZE, tmp, 0)); + res.setAccumBlueBits (glXGetConfig(display, info, GLX.GLX_ACCUM_BLUE_SIZE, tmp, 0)); + res.setAccumAlphaBits(glXGetConfig(display, info, GLX.GLX_ACCUM_ALPHA_SIZE, tmp, 0)); + if (isMultisampleEnabled) { + res.setSampleBuffers(glXGetConfig(display, info, GLX.GLX_SAMPLE_BUFFERS, tmp, 0) != 0); + res.setNumSamples (glXGetConfig(display, info, GLX.GLX_SAMPLES, tmp, 0)); + } + + return GLGraphicsConfigurationUtil.addGLCapabilitiesPermutations(capsBucket, res, drawableTypeBits); + } + + private static String glXGetConfigErrorCode(int err) { + switch (err) { + case GLX.GLX_NO_EXTENSION: return "GLX_NO_EXTENSION"; + case GLX.GLX_BAD_SCREEN: return "GLX_BAD_SCREEN"; + case GLX.GLX_BAD_ATTRIBUTE: return "GLX_BAD_ATTRIBUTE"; + case GLX.GLX_BAD_VISUAL: return "GLX_BAD_VISUAL"; + default: return "Unknown error code " + err; + } + } + + static int glXGetConfig(long display, XVisualInfo info, int attrib, int[] tmp, int tmp_offset) { + if (display == 0) { + throw new GLException("No display connection"); + } + int res = GLX.glXGetConfig(display, info, attrib, tmp, tmp_offset); + if (res != 0) { + throw new GLException("glXGetConfig("+toHexString(attrib)+") failed: error code " + glXGetConfigErrorCode(res)); + } + return tmp[tmp_offset]; + } + + public String toString() { + return "X11GLXGraphicsConfiguration["+getScreen()+", visualID " + toHexString(getVisualID()) + ", fbConfigID " + toHexString(getFBConfigID()) + + ",\n\trequested " + getRequestedCapabilities()+ + ",\n\tchosen " + getChosenCapabilities()+ + "]"; + } +} + diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java new file mode 100644 index 000000000..b984f1633 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.x11.X11GraphicsScreen; +import javax.media.nativewindow.x11.X11GraphicsDevice; +import javax.media.opengl.DefaultGLCapabilitiesChooser; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +import com.jogamp.common.nio.PointerBuffer; +import jogamp.nativewindow.x11.X11Lib; +import jogamp.nativewindow.x11.X11Util; +import jogamp.nativewindow.x11.XVisualInfo; +import jogamp.opengl.Debug; +import jogamp.opengl.GLGraphicsConfigurationFactory; +import jogamp.opengl.GLGraphicsConfigurationUtil; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +/** Subclass of GraphicsConfigurationFactory used when non-AWT toolkits + are used on X11 platforms. Toolkits will likely need to delegate + to this one to change the accepted and returned types of the + GraphicsDevice and GraphicsConfiguration abstractions. */ + +public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory { + protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); + static X11GLCapabilities.XVisualIDComparator XVisualIDComparator = new X11GLCapabilities.XVisualIDComparator(); + + X11GLXGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, this); + } + + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { + if (!(absScreen instanceof X11GraphicsScreen)) { + throw new IllegalArgumentException("Only X11GraphicsScreen are allowed here"); + } + + if ( !(capsChosen instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - chosen"); + } + + if ( !(capsRequested instanceof GLCapabilitiesImmutable)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - requested"); + } + + if (chooser != null && !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilitiesChooser objects"); + } + return chooseGraphicsConfigurationStatic((GLCapabilitiesImmutable)capsChosen, (GLCapabilitiesImmutable)capsRequested, + (GLCapabilitiesChooser)chooser, (X11GraphicsScreen)absScreen); + } + + protected static List/*<X11GLCapabilities>*/ getAvailableCapabilities(X11GLXDrawableFactory factory, AbstractGraphicsDevice device) { + X11GLXDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResource(device); + if(null == sharedResource) { + throw new GLException("Shared resource for device n/a: "+device); + } + X11GraphicsScreen sharedScreen = (X11GraphicsScreen) sharedResource.getScreen(); + X11GLXDrawable sharedDrawable = (X11GLXDrawable) sharedResource.getDrawable(); + GLCapabilitiesImmutable capsChosen = sharedDrawable.getChosenGLCapabilities(); + GLProfile glp = capsChosen.getGLProfile(); + + List/*GLCapabilitiesImmutable*/ availableCaps = null; + + if( sharedResource.isGLXVersionGreaterEqualOneThree() ) { + availableCaps = getAvailableGLCapabilitiesFBConfig(sharedScreen, glp); + } + if( null == availableCaps || availableCaps.isEmpty() ) { + availableCaps = getAvailableGLCapabilitiesXVisual(sharedScreen, glp); + } + if( null != availableCaps && availableCaps.size() > 1 ) { + Collections.sort(availableCaps, XVisualIDComparator); + } + return availableCaps; + } + + static List/*<X11GLCapabilities>*/ getAvailableGLCapabilitiesFBConfig(X11GraphicsScreen x11Screen, GLProfile glProfile) { + PointerBuffer fbcfgsL = null; + + // Utilizing FBConfig + // + AbstractGraphicsDevice absDevice = x11Screen.getDevice(); + long display = absDevice.getHandle(); + + int screen = x11Screen.getIndex(); + boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); + int[] count = { -1 }; + ArrayList availableCaps = new ArrayList(); + + fbcfgsL = GLX.glXChooseFBConfig(display, screen, null, 0, count, 0); + if (fbcfgsL == null || fbcfgsL.limit()<=0) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.getAvailableGLCapabilitiesFBConfig: Failed glXChooseFBConfig ("+x11Screen+"): "+fbcfgsL+", "+count[0]); + } + return null; + } + for (int i = 0; i < fbcfgsL.limit(); i++) { + if( !X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(availableCaps, glProfile, display, fbcfgsL.get(i), GLGraphicsConfigurationUtil.ALL_BITS, isMultisampleAvailable) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.getAvailableGLCapabilitiesFBConfig: FBConfig invalid (2): ("+x11Screen+"): fbcfg: "+toHexString(fbcfgsL.get(i))); + } + } + } + return availableCaps; + } + + static List/*<X11GLCapabilities>*/ getAvailableGLCapabilitiesXVisual(X11GraphicsScreen x11Screen, GLProfile glProfile) { + AbstractGraphicsDevice absDevice = x11Screen.getDevice(); + long display = absDevice.getHandle(); + + int screen = x11Screen.getIndex(); + boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); + + int[] count = new int[1]; + XVisualInfo template = XVisualInfo.create(); + template.setScreen(screen); + XVisualInfo[] infos = X11Util.XGetVisualInfo(display, X11Lib.VisualScreenMask, template, count, 0); + if (infos == null || infos.length<1) { + throw new GLException("Error while enumerating available XVisualInfos"); + } + ArrayList availableCaps = new ArrayList(); + for (int i = 0; i < infos.length; i++) { + if( !X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(availableCaps, glProfile, display, infos[i], GLGraphicsConfigurationUtil.ALL_BITS, isMultisampleAvailable) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.getAvailableGLCapabilitiesXVisual: XVisual invalid: ("+x11Screen+"): fbcfg: "+toHexString(infos[i].getVisualid())); + } + } + } + return availableCaps; + } + + + static X11GLXGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilitiesImmutable capsChosen, + GLCapabilitiesImmutable capsReq, + GLCapabilitiesChooser chooser, + X11GraphicsScreen x11Screen) { + if (x11Screen == null) { + throw new IllegalArgumentException("AbstractGraphicsScreen is null"); + } + + if (capsChosen == null) { + capsChosen = new GLCapabilities(null); + } + X11GraphicsDevice x11Device = (X11GraphicsDevice) x11Screen.getDevice(); + X11GLXDrawableFactory factory = (X11GLXDrawableFactory) GLDrawableFactory.getDesktopFactory(); + + capsChosen = GLGraphicsConfigurationUtil.fixGLCapabilities( capsChosen, factory.canCreateGLPbuffer(x11Device) ); + boolean usePBuffer = capsChosen.isPBuffer(); + + X11GLXGraphicsConfiguration res = null; + if( factory.isGLXVersionGreaterEqualOneThree(x11Device) ) { + res = chooseGraphicsConfigurationFBConfig(capsChosen, capsReq, chooser, x11Screen); + } + if(null==res) { + if(usePBuffer) { + throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig for "+capsChosen); + } + res = chooseGraphicsConfigurationXVisual(capsChosen, capsReq, chooser, x11Screen); + } + if(null==res) { + throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig and XVisual for "+capsChosen); + } + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationStatic("+x11Screen+","+capsChosen+"): "+res); + } + return res; + } + + static X11GLXGraphicsConfiguration fetchGraphicsConfigurationFBConfig(X11GraphicsScreen x11Screen, int fbID, GLProfile glp) { + AbstractGraphicsDevice absDevice = x11Screen.getDevice(); + long display = absDevice.getHandle(); + int screen = x11Screen.getIndex(); + + long fbcfg = X11GLXGraphicsConfiguration.glXFBConfigID2FBConfig(display, screen, fbID); + if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfg ) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("+x11Screen+","+toHexString(fbID)+"): fbcfg: "+toHexString(fbcfg)); + } + return null; + } + X11GLCapabilities caps = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(glp, display, fbcfg, true, true, true, GLXUtil.isMultisampleAvailable(display)); + return new X11GLXGraphicsConfiguration(x11Screen, caps, caps, new DefaultGLCapabilitiesChooser()); + } + + private static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig(GLCapabilitiesImmutable capsChosen, + GLCapabilitiesImmutable capsReq, + GLCapabilitiesChooser chooser, + X11GraphicsScreen x11Screen) { + long recommendedFBConfig = -1; + int recommendedIndex = -1; + PointerBuffer fbcfgsL = null; + GLProfile glProfile = capsChosen.getGLProfile(); + boolean onscreen = capsChosen.isOnscreen(); + boolean usePBuffer = capsChosen.isPBuffer(); + + // Utilizing FBConfig + // + AbstractGraphicsDevice absDevice = x11Screen.getDevice(); + long display = absDevice.getHandle(); + + int screen = x11Screen.getIndex(); + boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); + int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capsChosen, true, isMultisampleAvailable, display, screen); + int[] count = { -1 }; + ArrayList/*<X11GLCapabilities>*/ availableCaps = new ArrayList(); + final int winattrmask = GLGraphicsConfigurationUtil.getWinAttributeBits(onscreen, usePBuffer); + + // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as preferred choice + fbcfgsL = GLX.glXChooseFBConfig(display, screen, attribs, 0, count, 0); + if (fbcfgsL != null && fbcfgsL.limit()>0) { + for (int i = 0; i < fbcfgsL.limit(); i++) { + if( !X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(availableCaps, glProfile, display, fbcfgsL.get(i), winattrmask, isMultisampleAvailable) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: FBConfig invalid (1): ("+x11Screen+","+capsChosen+"): fbcfg: "+toHexString(fbcfgsL.get(i))); + } + } + } + if(availableCaps.size() > 0) { + recommendedFBConfig = fbcfgsL.get(0); + recommendedIndex=0; + if (DEBUG) { + System.err.println("!!! glXChooseFBConfig recommended fbcfg " + toHexString(recommendedFBConfig) + ", idx " + recommendedIndex); + System.err.println("!!! user caps " + capsChosen); + System.err.println("!!! fbcfg caps " + availableCaps.get(recommendedIndex)); + } + } else if (DEBUG) { + System.err.println("!!! glXChooseFBConfig no caps for recommended fbcfg " + toHexString(fbcfgsL.get(0))); + System.err.println("!!! user caps " + capsChosen); + } + } + + // 2nd choice: get all GLCapabilities available, no preferred recommendedIndex available + if( 0 == availableCaps.size() ) { + // reset .. + recommendedFBConfig = -1; + recommendedIndex = -1; + + fbcfgsL = GLX.glXChooseFBConfig(display, screen, null, 0, count, 0); + if (fbcfgsL == null || fbcfgsL.limit()<=0) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig ("+x11Screen+","+capsChosen+"): "+fbcfgsL+", "+count[0]); + } + return null; + } + + for (int i = 0; i < fbcfgsL.limit(); i++) { + if( !X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(availableCaps, glProfile, display, fbcfgsL.get(i), winattrmask, isMultisampleAvailable) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: FBConfig invalid (2): ("+x11Screen+"): fbcfg: "+toHexString(fbcfgsL.get(i))); + } + } + } + } + int chosenIndex = chooseCapabilities(chooser, capsChosen, availableCaps, recommendedIndex); + if ( 0 > chosenIndex ) { + if (DEBUG) { + Thread.dumpStack(); + } + return null; + } + X11GLCapabilities chosenCaps = (X11GLCapabilities) availableCaps.get(chosenIndex); + + return new X11GLXGraphicsConfiguration(x11Screen, chosenCaps, capsReq, chooser); + } + + private static X11GLXGraphicsConfiguration chooseGraphicsConfigurationXVisual(GLCapabilitiesImmutable capsChosen, + GLCapabilitiesImmutable capsReq, + GLCapabilitiesChooser chooser, + X11GraphicsScreen x11Screen) { + if (chooser == null) { + chooser = new DefaultGLCapabilitiesChooser(); + } + + GLProfile glProfile = capsChosen.getGLProfile(); + final int winattrmask = GLGraphicsConfigurationUtil.getWinAttributeBits(capsChosen.isOnscreen(), false /* pbuffer */); + ArrayList availableCaps = new ArrayList(); + int recommendedIndex = -1; + + AbstractGraphicsDevice absDevice = x11Screen.getDevice(); + long display = absDevice.getHandle(); + + int screen = x11Screen.getIndex(); + boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); + int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capsChosen, false, isMultisampleAvailable, display, screen); + + // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as preferred choice + XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0); + if (DEBUG) { + System.err.print("!!! glXChooseVisual recommended "); + if (recommendedVis == null) { + System.err.println("null visual"); + } else { + System.err.println("visual id " + toHexString(recommendedVis.getVisualid())); + } + } + + // 2nd choice: get all GLCapabilities available, preferred recommendedIndex might be available if 1st choice was successful + int[] count = new int[1]; + XVisualInfo template = XVisualInfo.create(); + template.setScreen(screen); + XVisualInfo[] infos = X11Util.XGetVisualInfo(display, X11Lib.VisualScreenMask, template, count, 0); + if (infos == null || infos.length<1) { + throw new GLException("Error while enumerating available XVisualInfos"); + } + + for (int i = 0; i < infos.length; i++) { + if( !X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(availableCaps, glProfile, display, infos[i], winattrmask, isMultisampleAvailable) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.getAvailableGLCapabilitiesXVisual: XVisual invalid: ("+x11Screen+"): fbcfg: "+toHexString(infos[i].getVisualid())); + } + } else { + // Attempt to find the visual chosenIndex by glXChooseVisual + if (recommendedVis != null && recommendedVis.getVisualid() == infos[i].getVisualid()) { + recommendedIndex = availableCaps.size() - 1; + } + } + } + + int chosenIndex = chooseCapabilities(chooser, capsChosen, availableCaps, recommendedIndex); + if ( 0 > chosenIndex ) { + if (DEBUG) { + Thread.dumpStack(); + } + return null; + } + X11GLCapabilities chosenCaps = (X11GLCapabilities) availableCaps.get(chosenIndex); + + return new X11GLXGraphicsConfiguration(x11Screen, chosenCaps, capsReq, chooser); + } + +} + diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11OnscreenGLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11OnscreenGLXContext.java new file mode 100644 index 000000000..ce5d466d4 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11OnscreenGLXContext.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package jogamp.opengl.x11.glx; + +import javax.media.opengl.*; + +public class X11OnscreenGLXContext extends X11GLXContext { + + public X11OnscreenGLXContext(X11OnscreenGLXDrawable drawable, GLContext shareWith) { + super(drawable, shareWith); + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11OnscreenGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11OnscreenGLXDrawable.java new file mode 100644 index 000000000..9e6ef911e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11OnscreenGLXDrawable.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; + +public class X11OnscreenGLXDrawable extends X11GLXDrawable { + /** GLXWindow can't be made current on AWT with NVidia driver, hence disabled for now */ + public static final boolean USE_GLXWINDOW = false; + long glXWindow; // GLXWindow, a GLXDrawable representation + boolean useGLXWindow; + + protected X11OnscreenGLXDrawable(GLDrawableFactory factory, NativeSurface component) { + super(factory, component, false); + glXWindow=0; + useGLXWindow=false; + } + + public long getHandle() { + if(useGLXWindow) { + return glXWindow; + } + return getNativeSurface().getSurfaceHandle(); + } + + protected void destroyHandle() { + if(0!=glXWindow) { + GLX.glXDestroyWindow(getNativeSurface().getDisplayHandle(), glXWindow); + glXWindow = 0; + useGLXWindow=false; + } + } + + /** must be locked already */ + protected void updateHandle() { + if(USE_GLXWINDOW) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + if(config.getFBConfig()>=0) { + useGLXWindow=true; + long dpy = getNativeSurface().getDisplayHandle(); + if(0!=glXWindow) { + GLX.glXDestroyWindow(dpy, glXWindow); + } + glXWindow = GLX.glXCreateWindow(dpy, config.getFBConfig(), getNativeSurface().getSurfaceHandle(), null, 0); + if (DEBUG) { + System.err.println("!!! X11OnscreenGLXDrawable.setRealized(true): glXWindow: "+toHexString(getNativeSurface().getSurfaceHandle())+" -> "+toHexString(glXWindow)); + } + if(0==glXWindow) { + throw new GLException("X11OnscreenGLXDrawable.setRealized(true): GLX.glXCreateWindow() failed: "+this); + } + } + } + } + + public GLContext createContext(GLContext shareWith) { + return new X11OnscreenGLXContext(this, shareWith); + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11PbufferGLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11PbufferGLXContext.java new file mode 100644 index 000000000..765a8207a --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11PbufferGLXContext.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.opengl.*; + +public class X11PbufferGLXContext extends X11GLXContext { + + public X11PbufferGLXContext(X11PbufferGLXDrawable drawable, GLContext shareWith) { + super(drawable, shareWith); + } + + public void bindPbufferToTexture() { + // FIXME: figure out how to implement this + throw new GLException("Not yet implemented"); + } + + public void releasePbufferFromTexture() { + // FIXME: figure out how to implement this + throw new GLException("Not yet implemented"); + } + + + public int getFloatingPointMode() { + return ((X11PbufferGLXDrawable)drawable).getFloatingPointMode(); + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11PbufferGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11PbufferGLXDrawable.java new file mode 100644 index 000000000..8ea989267 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11PbufferGLXDrawable.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +public class X11PbufferGLXDrawable extends X11GLXDrawable { + protected X11PbufferGLXDrawable(GLDrawableFactory factory, NativeSurface target) { + /* GLCapabilities caps, + GLCapabilitiesChooser chooser, + int width, int height */ + super(factory, target, true); + + if (DEBUG) { + System.out.println("Pbuffer config: " + getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration()); + } + + createPbuffer(); + + if (DEBUG) { + System.err.println("Created pbuffer " + this); + } + } + + protected void setRealizedImpl() { + if(realized) { + createPbuffer(); + } else { + destroyImpl(); + } + } + + public GLContext createContext(GLContext shareWith) { + return new X11PbufferGLXContext(this, shareWith); + } + + protected void destroyImpl() { + NativeSurface ns = getNativeSurface(); + if (ns.getSurfaceHandle() != 0) { + GLX.glXDestroyPbuffer(ns.getDisplayHandle(), ns.getSurfaceHandle()); + } + ((SurfaceChangeable)ns).setSurfaceHandle(0); + } + + private void createPbuffer() { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration) getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsScreen aScreen = config.getScreen(); + AbstractGraphicsDevice aDevice = aScreen.getDevice(); + long display = aDevice.getHandle(); + int screen = aScreen.getIndex(); + + if (display==0) { + throw new GLException("Null display"); + } + + NativeSurface ns = getNativeSurface(); + + GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable)config.getChosenCapabilities(); + + if (chosenCaps.getPbufferRenderToTexture()) { + throw new GLException("Render-to-texture pbuffers not supported yet on X11"); + } + + if (chosenCaps.getPbufferRenderToTextureRectangle()) { + throw new GLException("Render-to-texture-rectangle pbuffers not supported yet on X11"); + } + + // Create the p-buffer. + int niattribs = 0; + int[] iattributes = new int[5]; + + iattributes[niattribs++] = GLX.GLX_PBUFFER_WIDTH; + iattributes[niattribs++] = ns.getWidth(); + iattributes[niattribs++] = GLX.GLX_PBUFFER_HEIGHT; + iattributes[niattribs++] = ns.getHeight(); + iattributes[niattribs++] = 0; + + long pbuffer = GLX.glXCreatePbuffer(display, config.getFBConfig(), iattributes, 0); + if (pbuffer == 0) { + // FIXME: query X error code for detail error message + throw new GLException("pbuffer creation error: glXCreatePbuffer() failed"); + } + + // Set up instance variables + ((SurfaceChangeable)ns).setSurfaceHandle(pbuffer); + + // Determine the actual width and height we were able to create. + int[] tmp = new int[1]; + GLX.glXQueryDrawable(display, pbuffer, GLX.GLX_WIDTH, tmp, 0); + int width = tmp[0]; + GLX.glXQueryDrawable(display, pbuffer, GLX.GLX_HEIGHT, tmp, 0); + int height = tmp[0]; + ((SurfaceChangeable)ns).setSize(width, height); + } + + public int getFloatingPointMode() { + // Floating-point pbuffers currently require NVidia hardware on X11 + return GLPbuffer.NV_FLOAT; + } + + protected void swapBuffersImpl() { + if(DEBUG) { + System.err.println("unhandled swapBuffersImpl() called for: "+this); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXContext.java new file mode 100644 index 000000000..ef8007de4 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXContext.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.opengl.*; + +public class X11PixmapGLXContext extends X11GLXContext { + + public X11PixmapGLXContext(X11PixmapGLXDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + public int getOffscreenContextPixelDataType() { + GL gl = getGL(); + return gl.isGL2GL3()?GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV:GL.GL_UNSIGNED_SHORT_5_5_5_1; + } + + public int getOffscreenContextReadBuffer() { + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + if (caps.getDoubleBuffered()) { + return GL.GL_BACK; + } + return GL.GL_FRONT; + } + + public boolean offscreenImageNeedsVerticalFlip() { + // There doesn't seem to be a way to do this in the construction + // of the Pixmap or GLXPixmap + return true; + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXDrawable.java new file mode 100644 index 000000000..f5d321561 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXDrawable.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.opengl.x11.glx; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import jogamp.nativewindow.x11.*; + +public class X11PixmapGLXDrawable extends X11GLXDrawable { + private long pixmap; + + protected X11PixmapGLXDrawable(GLDrawableFactory factory, NativeSurface target) { + super(factory, target, true); + create(); + } + + protected void setRealizedImpl() { + if(realized) { + create(); + } else { + destroyImpl(); + } + } + + public GLContext createContext(GLContext shareWith) { + return new X11PixmapGLXContext(this, shareWith); + } + + private void create() { + NativeSurface ns = getNativeSurface(); + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration) ns.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + XVisualInfo vis = config.getXVisualInfo(); + int bitsPerPixel = vis.getDepth(); + AbstractGraphicsScreen aScreen = config.getScreen(); + AbstractGraphicsDevice aDevice = aScreen.getDevice(); + long dpy = aDevice.getHandle(); + int screen = aScreen.getIndex(); + + pixmap = X11Util.XCreatePixmap(dpy, X11Util.RootWindow(dpy, screen), + surface.getWidth(), surface.getHeight(), bitsPerPixel); + if (pixmap == 0) { + throw new GLException("XCreatePixmap failed"); + } + long drawable = GLX.glXCreateGLXPixmap(dpy, vis, pixmap); + if (drawable == 0) { + X11Util.XFreePixmap(dpy, pixmap); + pixmap = 0; + throw new GLException("glXCreateGLXPixmap failed"); + } + ((SurfaceChangeable)ns).setSurfaceHandle(drawable); + if (DEBUG) { + System.err.println("Created pixmap " + toHexString(pixmap) + + ", GLXPixmap " + toHexString(drawable) + + ", display " + toHexString(dpy)); + } + } + + protected void destroyImpl() { + if (pixmap == 0) return; + + NativeSurface ns = getNativeSurface(); + long display = ns.getDisplayHandle(); + + long drawable = ns.getSurfaceHandle(); + if (DEBUG) { + System.err.println("Destroying pixmap " + toHexString(pixmap) + + ", GLXPixmap " + toHexString(drawable) + + ", display " + toHexString(display)); + } + + // Must destroy pixmap and GLXPixmap + + if (DEBUG) { + long cur = GLX.glXGetCurrentContext(); + if (cur != 0) { + System.err.println("WARNING: found context " + toHexString(cur) + " current during pixmap destruction"); + } + } + + // FIXME: workaround for crashes on NVidia hardware when + // destroying pixmap (no context is current at the point of the + // crash, at least from the point of view of + // glXGetCurrentContext) + GLX.glXMakeCurrent(display, 0, 0); + + GLX.glXDestroyGLXPixmap(display, drawable); + X11Util.XFreePixmap(display, pixmap); + drawable = 0; + pixmap = 0; + ((SurfaceChangeable)ns).setSurfaceHandle(0); + display = 0; + } + + protected void swapBuffersImpl() { + if(DEBUG) { + System.err.println("unhandled swapBuffersImpl() called for: "+this); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java new file mode 100644 index 000000000..ee7dd280e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.opengl.x11.glx.awt; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import javax.media.nativewindow.awt.*; +import javax.media.opengl.*; + +import jogamp.opengl.*; +import jogamp.nativewindow.jawt.x11.*; +import jogamp.nativewindow.x11.*; + +public class X11AWTGLXGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory { + protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); + + public X11AWTGLXGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, this); + } + + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { + GraphicsDevice device = null; + if (absScreen != null && + !(absScreen instanceof AWTGraphicsScreen)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only AWTGraphicsScreen objects"); + } + + if(null==absScreen) { + absScreen = AWTGraphicsScreen.createScreenDevice(-1, AbstractGraphicsDevice.DEFAULT_UNIT); + } + AWTGraphicsScreen awtScreen = (AWTGraphicsScreen) absScreen; + device = ((AWTGraphicsDevice)awtScreen.getDevice()).getGraphicsDevice(); + + if ( !(capsChosen instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects - chosen"); + } + + if ( !(capsRequested instanceof GLCapabilitiesImmutable) ) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects - requested"); + } + + if (chooser != null && + !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilitiesChooser objects"); + } + + if(DEBUG) { + System.err.println("X11AWTGLXGraphicsConfigurationFactory: got "+absScreen); + } + + long displayHandle = X11SunJDKReflection.graphicsDeviceGetDisplay(device); + boolean owner = false; + if(0==displayHandle) { + displayHandle = X11Util.createDisplay(null); + owner = true; + if(DEBUG) { + System.err.println(Thread.currentThread().getName() + " - X11AWTGLXGraphicsConfigurationFactory: using a thread local X11 display"); + } + } else { + if(DEBUG) { + System.err.println(Thread.currentThread().getName() + " - X11AWTGLXGraphicsConfigurationFactory: using AWT X11 display 0x"+Long.toHexString(displayHandle)); + } + /** + * Using the AWT display handle works fine with NVidia and AMD drivers today 2011-02-22, + * hence no need for our own display instance anymore. + String name = X11Util.XDisplayString(displayHandle); + displayHandle = X11Util.createDisplay(name); + owner = true; + */ + } + ((AWTGraphicsDevice)awtScreen.getDevice()).setSubType(NativeWindowFactory.TYPE_X11, displayHandle); + X11GraphicsDevice x11Device = new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT); + x11Device.setCloseDisplay(owner); + X11GraphicsScreen x11Screen = new X11GraphicsScreen(x11Device, awtScreen.getIndex()); + if(DEBUG) { + System.err.println("X11AWTGLXGraphicsConfigurationFactory: made "+x11Screen); + } + GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(x11Device); + GraphicsConfiguration[] configs = device.getConfigurations(); + + // + // Match the X11/GL Visual with AWT: + // - choose a config AWT agnostic and then + // - try to find the visual within the GraphicsConfiguration + // + // The resulting GraphicsConfiguration has to be 'forced' on the AWT native peer, + // ie. returned by GLCanvas's getGraphicsConfiguration() befor call by super.addNotify(). + // + X11GraphicsConfiguration x11Config = (X11GraphicsConfiguration) factory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, x11Screen); + if (x11Config == null) { + throw new GLException("Unable to choose a GraphicsConfiguration (1): "+capsChosen+",\n\t"+chooser+"\n\t"+x11Screen); + } + long visualID = x11Config.getVisualID(); + for (int i = 0; i < configs.length; i++) { + GraphicsConfiguration gc = configs[i]; + if (gc != null) { + if (X11SunJDKReflection.graphicsConfigurationGetVisualID(gc) == visualID) { + if(DEBUG) { + System.err.println("Found matching AWT visual: 0x"+Long.toHexString(visualID) +" -> "+x11Config); + } + return new AWTGraphicsConfiguration(awtScreen, + x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(), + gc, x11Config); + } + } + } + + // try again using an AWT Colormodel compatible configuration + GraphicsConfiguration gc = device.getDefaultConfiguration(); + capsChosen = AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsChosen, gc); + x11Config = (X11GraphicsConfiguration) factory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, x11Screen); + if (x11Config == null) { + throw new GLException("Unable to choose a GraphicsConfiguration (2): "+capsChosen+",\n\t"+chooser+"\n\t"+x11Screen); + } + visualID = x11Config.getVisualID(); + for (int i = 0; i < configs.length; i++) { + gc = configs[i]; + if (X11SunJDKReflection.graphicsConfigurationGetVisualID(gc) == visualID) { + if(DEBUG) { + System.err.println("Found matching default AWT visual: 0x"+Long.toHexString(visualID) +" -> "+x11Config); + } + return new AWTGraphicsConfiguration(awtScreen, + x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(), + gc, x11Config); + } + } + + // Either we weren't able to reflectively introspect on the + // X11GraphicsConfig or something went wrong in the steps above; + // Let's take the default configuration as used on Windows and MacOSX then .. + if(DEBUG) { + System.err.println("!!! Using default configuration"); + } + + gc = device.getDefaultConfiguration(); + return new AWTGraphicsConfiguration(awtScreen, x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(), gc, x11Config); + } +} diff --git a/src/jogl/native/GLXGetProcAddressARB.c b/src/jogl/native/GLXGetProcAddressARB.c new file mode 100644 index 000000000..6e9f6c3c2 --- /dev/null +++ b/src/jogl/native/GLXGetProcAddressARB.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2003-2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +#if defined(__sun) || defined(_HPUX) +#include <dlfcn.h> + +/* HP-UX doesn't define RTLD_DEFAULT. */ +#if defined(_HPUX) && !defined(RTLD_DEFAULT) +#define RTLD_DEFAULT NULL +#endif + +/* Sun's GLX implementation doesn't have glXGetProcAddressARB (or + glXGetProcAddress) so we implement it here */ +void (*glXGetProcAddressARB(const char *procname))() { + return (void (*)()) dlsym(RTLD_DEFAULT, procname); +} +#endif /* __ sun || _HPUX */ diff --git a/src/jogl/native/audio/Mixer.cpp b/src/jogl/native/audio/Mixer.cpp new file mode 100644 index 000000000..9fa5b61bc --- /dev/null +++ b/src/jogl/native/audio/Mixer.cpp @@ -0,0 +1,199 @@ +#include <windows.h> +#include <stdlib.h> +#include <mmsystem.h> +#include <mmreg.h> +#include "com_jogamp_audio_windows_waveout_Mixer.h" + +static HANDLE event = NULL; +static HWAVEOUT output = NULL; +// We use only two buffers to keep latency down +#define NUM_BUFFERS 2 +//#define NUM_BUFFERS 4 +// This is about 20 ms of data for WAVE_FORMAT_PCM: +// (44100 samples / sec) * (20 ms / 1000 ms) * (2 bytes / sample) * (2 channels) +//#define BUFFER_SIZE 3528 + +// This is about 50 ms of data for WAVE_FORMAT_PCM: +// (44100 samples / sec) * (50 ms / 1000 ms) * (2 bytes / sample) * (1 channel) +//#define BUFFER_SIZE 4410 + +// This is about 200 ms of data for WAVE_FORMAT_PCM: +// (44100 samples / sec) * (200 ms / 1000 ms) * (2 bytes / sample) * (1 channel) +//#define BUFFER_SIZE 17640 + +// This is about 200 ms of data for WAVE_FORMAT_PCM: +// (44100 samples / sec) * (200 ms / 1000 ms) * (2 bytes / sample) * (2 channel) +//#define BUFFER_SIZE 35280 + +// This is about 1000 ms of data for WAVE_FORMAT_PCM: +// (44100 samples / sec) * (1000 ms / 1000 ms) * (2 bytes / sample) * (1 channel) +//#define BUFFER_SIZE 88200 + +// This is about 50 ms of data for WAVE_FORMAT_PCM: +// (44100 samples / sec) * (50 ms / 1000 ms) * (2 bytes / sample) * (2 channels) +//#define BUFFER_SIZE 8820 + +// This is about 50 ms of data for WAVE_FORMAT_IEEE_FLOAT: +// (44100 samples / sec) * (50 ms / 1000 ms) * (4 bytes / sample) * (2 channels) +//#define BUFFER_SIZE 17640 + +// This is about 200 ms of data for WAVE_FORMAT_PCM: +// (11025 samples / sec) * (200 ms / 1000 ms) * (2 bytes / sample) * (2 channel) +#define BUFFER_SIZE 8820 + +//#define BUFFER_SIZE 8192 +static WAVEHDR** buffers = NULL; + +void CALLBACK playbackCallback(HWAVEOUT output, + UINT msg, + DWORD_PTR userData, + DWORD_PTR param1, + DWORD_PTR param2) +{ + if (msg == WOM_DONE) { + WAVEHDR* hdr = (WAVEHDR*) param1; + hdr->dwFlags |= WHDR_DONE; + SetEvent(event); + } +} + +JNIEXPORT jboolean JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_initializeWaveOut + (JNIEnv *env, jclass unused, jlong eventObject) +{ + event = (HANDLE) eventObject; + + // Note the hard requirements on the RawSoundConverter's output format + WAVEFORMATEX format; + format.wFormatTag = WAVE_FORMAT_PCM; + // format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; + format.nChannels = 2; + // format.nChannels = 1; + // format.nSamplesPerSec = 44100; + format.nSamplesPerSec = 11025; + format.wBitsPerSample = 16; + // format.wBitsPerSample = 32; + format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8; + format.nAvgBytesPerSec = format.nBlockAlign * format.nSamplesPerSec; + format.cbSize = 0; + MMRESULT res = waveOutOpen(&output, + WAVE_MAPPER, + &format, + /* NULL, */ (DWORD_PTR) &playbackCallback, + NULL, // No user data right now + /* CALLBACK_NULL */ CALLBACK_FUNCTION); + if (res != MMSYSERR_NOERROR) { + return JNI_FALSE; + } + + buffers = (WAVEHDR**) calloc(NUM_BUFFERS, sizeof(WAVEHDR)); + for (int i = 0; i < NUM_BUFFERS; i++) { + char* data = (char*) calloc(BUFFER_SIZE, 1); + WAVEHDR* hdr = (WAVEHDR*) calloc(1, sizeof(WAVEHDR)); + hdr->lpData = data; + hdr->dwBufferLength = BUFFER_SIZE; + hdr->dwFlags |= WHDR_DONE; + buffers[i] = hdr; + } + + return JNI_TRUE; +} + +JNIEXPORT void JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_shutdownWaveOut + (JNIEnv *env, jclass unused) +{ + // writeString("Pausing\n"); + waveOutPause(output); + // writeString("Resetting\n"); + waveOutReset(output); + // writeString("Closing output\n"); + waveOutClose(output); +} + +JNIEXPORT jlong JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_getNextMixerBuffer + (JNIEnv *env, jclass unused) +{ + WAVEHDR* hdr = NULL; + for (int i = 0; i < NUM_BUFFERS; i++) { + if (buffers[i] != NULL && ((buffers[i]->dwFlags & WHDR_DONE) != 0)) { + hdr = buffers[i]; + hdr->dwFlags &= ~WHDR_DONE; + break; + } + } + return (jlong) hdr; +} + +JNIEXPORT jobject JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_getMixerBufferData + (JNIEnv *env, jclass unused, jlong mixerBuffer) +{ + WAVEHDR* hdr = (WAVEHDR*) mixerBuffer; + return env->NewDirectByteBuffer(hdr->lpData, hdr->dwBufferLength); +} + +JNIEXPORT jlong JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_getMixerBufferDataAddress + (JNIEnv *env, jclass unused, jlong mixerBuffer) +{ + WAVEHDR* hdr = (WAVEHDR*) mixerBuffer; + return (jlong) hdr->lpData; +} + +JNIEXPORT jint JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_getMixerBufferDataCapacity + (JNIEnv *env, jclass unused, jlong mixerBuffer) +{ + WAVEHDR* hdr = (WAVEHDR*) mixerBuffer; + return (jint) hdr->dwBufferLength; +} + +JNIEXPORT jboolean JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_prepareMixerBuffer + (JNIEnv *env, jclass unused, jlong mixerBuffer) +{ + MMRESULT res = waveOutPrepareHeader(output, + (WAVEHDR*) mixerBuffer, + sizeof(WAVEHDR)); + if (res == MMSYSERR_NOERROR) { + return JNI_TRUE; + } + return JNI_FALSE; +} + +JNIEXPORT jboolean JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_writeMixerBuffer + (JNIEnv *env, jclass unused, jlong mixerBuffer) +{ + MMRESULT res = waveOutWrite(output, + (WAVEHDR*) mixerBuffer, + sizeof(WAVEHDR)); + if (res == MMSYSERR_NOERROR) { + waveOutRestart(output); + + return JNI_TRUE; + } + return JNI_FALSE; +} + +JNIEXPORT jlong JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_CreateEvent + (JNIEnv *env, jclass unused) +{ + return (jlong) CreateEvent(NULL, FALSE, TRUE, NULL); +} + +JNIEXPORT jboolean JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_WaitForSingleObject + (JNIEnv *env, jclass unused, jlong eventObject) +{ + DWORD res = WaitForSingleObject((HANDLE) eventObject, INFINITE); + if (res == WAIT_OBJECT_0) { + return JNI_TRUE; + } + return JNI_FALSE; +} + +JNIEXPORT void JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_SetEvent + (JNIEnv *env, jclass unused, jlong eventObject) +{ + SetEvent((HANDLE) eventObject); +} + +JNIEXPORT void JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_CloseHandle + (JNIEnv *env, jclass unused, jlong eventObject) +{ + CloseHandle((HANDLE) eventObject); +} diff --git a/src/jogl/native/macosx/ContextUpdater.h b/src/jogl/native/macosx/ContextUpdater.h new file mode 100644 index 000000000..e8b757fac --- /dev/null +++ b/src/jogl/native/macosx/ContextUpdater.h @@ -0,0 +1,40 @@ +/* + +Listens to NSViewGlobalFrameDidChangeNotification + +This notification is sent whenever an NSView that has an attached NSSurface changes size or changes screens (thus potentially changing graphics hardware drivers.) + +*/ + +#import <Cocoa/Cocoa.h> +#import <Foundation/Foundation.h> +#import <AppKit/NSView.h> +#import <OpenGL/OpenGL.h> +#import <OpenGL/gl.h> + +//#define DEBUG_GL_LOCKS + +#ifdef DEBUG_GL_LOCKS + #define LOCK_GL(func, line) [ContextUpdater lockInFunction:func atLine:line]; + #define UNLOCK_GL(func, line) [ContextUpdater unlockInFunction:func atLine:line]; +#else + #define LOCK_GL(func, line) [ContextUpdater lock]; + #define UNLOCK_GL(func, line) [ContextUpdater unlock]; +#endif + +// gznote: OpenGL NOT thread safe - need to sync on update and paints + +@interface ContextUpdater : NSObject +{ +} + ++ (void) lock; ++ (void) lockInFunction:(char *)func atLine:(int)line; ++ (void) unlock; ++ (void) unlockInFunction:(char *)func atLine:(int)line; + +- (void) registerFor:(NSOpenGLContext *)context with: (NSView *)window; + +- (void) update:(NSNotification *)notification; + +@end diff --git a/src/jogl/native/macosx/ContextUpdater.m b/src/jogl/native/macosx/ContextUpdater.m new file mode 100644 index 000000000..587782c98 --- /dev/null +++ b/src/jogl/native/macosx/ContextUpdater.m @@ -0,0 +1,83 @@ +#import "ContextUpdater.h" +#import <pthread.h> + +@implementation ContextUpdater +{ +} + +static NSOpenGLContext *theContext; +static pthread_mutex_t resourceLock = PTHREAD_MUTEX_INITIALIZER; + +static void printLockDebugInfo(char *message, char *func, int line) +{ + fprintf(stderr, "%s in function: \"%s\" at line: %d\n", message, func, line); + fflush(stderr); +} + ++ (void) lock +{ + if (theContext != NULL) + { + pthread_mutex_lock(&resourceLock); + } +} + ++ (void) lockInFunction:(char *)func atLine:(int)line +{ + if (theContext != NULL) + { + printLockDebugInfo("locked ", func, line); + [self lock]; + } +} + ++ (void) unlock +{ + if (theContext != NULL) + { + pthread_mutex_unlock(&resourceLock); + } +} + ++ (void) unlockInFunction:(char *)func atLine:(int)line +{ + if (theContext != NULL) + { + printLockDebugInfo("unlocked", func, line); + [self unlock]; + } +} + +- (void) registerFor:(NSOpenGLContext *)context with: (NSView *)view +{ + if (view != NULL) + { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:NSViewGlobalFrameDidChangeNotification object: view]; + theContext = context; + } +} + +- (void) update:(NSNotification *)notification +{ + [ContextUpdater lock]; + + [theContext update]; + + [ContextUpdater unlock]; +} + +- (id) init +{ + theContext = NULL; + + return [super init]; +} + +- (void) dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + [super dealloc]; +} + +@end
\ No newline at end of file diff --git a/src/jogl/native/macosx/MacOSXCustomCGLCode.c b/src/jogl/native/macosx/MacOSXCustomCGLCode.c new file mode 100644 index 000000000..c29be889d --- /dev/null +++ b/src/jogl/native/macosx/MacOSXCustomCGLCode.c @@ -0,0 +1,24 @@ +#include <stdlib.h> + +#include <assert.h> + +#include </usr/include/machine/types.h> +#include "macosx-window-system.h" + +void CGLQueryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalues) { + CGLPixelFormatObj pix = (CGLPixelFormatObj) pixelFormat; + // FIXME: think about how specifying this might affect the API + int virtualScreen = 0; + + int i; + GLint value; + for (i = 0; i < niattrs && iattrs[i]>0; i++) { + CGLPixelFormatAttribute attr = (CGLPixelFormatAttribute) iattrs[i]; + if ( kCGLNoError == CGLDescribePixelFormat(pix, virtualScreen, attr, &value) ) { + ivalues[i] = value; + } else { + ivalues[i] = 0; + } + } +} + diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m new file mode 100644 index 000000000..cbfea6d71 --- /dev/null +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m @@ -0,0 +1,740 @@ +/* Note: usage of AvailabilityMacros.h to detect whether we're + building on OS X 10.3 does not work because the header #defines + MAC_OS_X_VERSION_10_4 even though the machine is a 10.3 machine + +#include <AvailabilityMacros.h> + +#ifndef MAC_OS_X_VERSION_10_3 + #error building JOGL requires Mac OS X 10.3 or greater +#endif + +#ifndef MAC_OS_X_VERSION_10_4 + #define NSOpenGLPFAColorFloat kCGLPFAColorFloat + #define kCGLNoError 0 +#endif +*/ + +#import <Cocoa/Cocoa.h> +#import <OpenGL/gl.h> +#import <OpenGL/CGLTypes.h> +#import <jni.h> +#import "ContextUpdater.h" + +#import "macosx-window-system.h" + +// see MacOSXPbufferGLContext.java createPbuffer +#define USE_GL_TEXTURE_RECTANGLE_EXT + +#ifdef USE_GL_TEXTURE_RECTANGLE_EXT + #ifndef GL_TEXTURE_RECTANGLE_EXT + #define GL_TEXTURE_RECTANGLE_EXT 0x84F5 + #endif +#endif + +// Workarounds for compiling on 10.3 +#ifndef kCGLRGBA16161616Bit +#define kCGLRGBA16161616Bit 0x00800000 /* 64 argb bit/pixel, R=63:48, G=47:32, B=31:16, A=15:0 */ +#define kCGLRGBFloat64Bit 0x01000000 /* 64 rgb bit/pixel, half float */ +#define kCGLRGBAFloat64Bit 0x02000000 /* 64 argb bit/pixel, half float */ +#define kCGLRGBFloat128Bit 0x04000000 /* 128 rgb bit/pixel, ieee float */ +#define kCGLRGBAFloat128Bit 0x08000000 /* 128 argb bit/pixel, ieee float */ +#define kCGLRGBFloat256Bit 0x10000000 /* 256 rgb bit/pixel, ieee double */ +#define kCGLRGBAFloat256Bit 0x20000000 /* 256 argb bit/pixel, ieee double */ +#endif + +struct _RendererInfo +{ + long id; // kCGLRPRendererID + long displayMask; // kCGLRPDisplayMask + + long accelerated; // kCGLRPAccelerated + + long window; // kCGLRPWindow + long fullscreen; // kCGLRPFullScreen + long multiscreen; // kCGLRPMultiScreen + long offscreen; // kCGLRPOffScreen + long floatPixels; // see kCGLRPColorModes + long stereo; // kCGLRPBufferModes + + long auxBuffers; // kCGLRPMaxAuxBuffers + long sampleBuffers; // kCGLRPMaxSampleBuffers + long samples; // kCGLRPMaxSamples + long samplesModes; // kCGLRPSampleModes + long multiSample; // see kCGLRPSampleModes + long superSample; // see kCGLRPSampleModes + long alphaSample; // kCGLRPSampleAlpha + + long colorModes; // kCGLRPColorModes + long colorRGBSizeMAX; + long colorASizeMAX; + long colorFloatRGBSizeMAX; + long colorFloatASizeMAX; + long colorFloatRGBSizeMIN; + long colorFloatASizeMIN; + long colorModesCount; + long colorFloatModesCount; + long depthModes; // kCGLRPDepthModes + long depthSizeMAX; + long depthModesCount; + long stencilModes; // kCGLRPStencilModes + long stencilSizeMAX; + long stencilModesCount; + long accumModes; // kCGLRPAccumModes + long accumRGBSizeMAX; + long accumASizeMAX; + long accumModesCount; +} +typedef RendererInfo; + +RendererInfo *gRenderers = NULL; +long gRenderersCount = 0; + +long depthModes[] = { + kCGL0Bit, + kCGL1Bit, + kCGL2Bit, + kCGL3Bit, + kCGL4Bit, + kCGL5Bit, + kCGL6Bit, + kCGL8Bit, + kCGL10Bit, + kCGL12Bit, + kCGL16Bit, + kCGL24Bit, + kCGL32Bit, + kCGL48Bit, + kCGL64Bit, + kCGL96Bit, + kCGL128Bit, + 0 + }; +long depthModesBits[] = {0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 24, 32, 48, 64, 96, 128}; +long colorModes[] = { + kCGLRGB444Bit, + kCGLARGB4444Bit, + kCGLRGB444A8Bit, + kCGLRGB555Bit, + kCGLARGB1555Bit, + kCGLRGB555A8Bit, + kCGLRGB565Bit, + kCGLRGB565A8Bit, + kCGLRGB888Bit, + kCGLARGB8888Bit, + kCGLRGB888A8Bit, + kCGLRGB101010Bit, + kCGLARGB2101010Bit, + kCGLRGB101010_A8Bit, + kCGLRGB121212Bit, + kCGLARGB12121212Bit, + kCGLRGB161616Bit, + kCGLRGBA16161616Bit, + kCGLRGBFloat64Bit, + kCGLRGBAFloat64Bit, + kCGLRGBFloat128Bit, + kCGLRGBAFloat128Bit, + kCGLRGBFloat256Bit, + kCGLRGBAFloat256Bit, + 0 + }; +long colorModesBitsRGB[] = {4, 4, 4, 5, 5, 5, 5, 5, 8, 8, 8, 10, 10, 10, 12, 12, 16, 16, 16, 16, 32, 32, 64, 64}; +long colorModesBitsA[] = {0, 4, 8, 0, 1, 8, 0, 8, 0, 8, 8, 0, 2, 8, 0, 12, 0, 16, 0, 16, 0, 32, 0, 64}; + +void getRendererInfo() +{ + if (gRenderersCount == 0) + { + CGLRendererInfoObj info; + CGLError err = CGLQueryRendererInfo(CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay), &info, &gRenderersCount); + if (err == 0 /* kCGLNoError */) + { + // how many renderers are available? + CGLDescribeRenderer(info, 0, kCGLRPRendererCount, &gRenderersCount); + + // allocate our global renderers info + gRenderers = (RendererInfo*)malloc(gRenderersCount*sizeof(RendererInfo)); + memset(gRenderers, 0x00, gRenderersCount*sizeof(RendererInfo)); + + // iterate through the renderers checking for their features + long j; + for (j=0; j<gRenderersCount; j++) + { + RendererInfo *renderer = &gRenderers[j]; + int i; + + CGLDescribeRenderer(info, j, kCGLRPRendererID, &(renderer->id)); + CGLDescribeRenderer(info, j, kCGLRPDisplayMask, &(renderer->displayMask)); + + CGLDescribeRenderer(info, j, kCGLRPAccelerated, &(renderer->accelerated)); + + CGLDescribeRenderer(info, j, kCGLRPWindow, &(renderer->window)); + CGLDescribeRenderer(info, j, kCGLRPFullScreen, &(renderer->fullscreen)); + CGLDescribeRenderer(info, j, kCGLRPMultiScreen, &(renderer->multiscreen)); + CGLDescribeRenderer(info, j, kCGLRPOffScreen, &(renderer->offscreen)); + CGLDescribeRenderer(info, j, kCGLRPColorModes, &(renderer->floatPixels)); + if ((renderer->floatPixels >= kCGLRGBFloat64Bit) != 0) + { + renderer->floatPixels = 1; + } + else + { + renderer->floatPixels = 0; + } + CGLDescribeRenderer(info, j, kCGLRPBufferModes, &(renderer->stereo)); + if ((renderer->stereo & kCGLStereoscopicBit) != 0) + { + renderer->stereo = 1; + } + else + { + renderer->stereo = 0; + } + + CGLDescribeRenderer(info, j, kCGLRPMaxAuxBuffers, &(renderer->auxBuffers)); + CGLDescribeRenderer(info, j, kCGLRPMaxSampleBuffers, &(renderer->sampleBuffers)); + CGLDescribeRenderer(info, j, kCGLRPMaxSamples, &(renderer->samples)); + // The following queries are only legal on 10.4 + // FIXME: should figure out a way to enable them dynamically +#ifdef kCGLRPSampleModes + CGLDescribeRenderer(info, j, kCGLRPSampleModes, &(renderer->samplesModes)); + if ((renderer->samplesModes & kCGLSupersampleBit) != 0) + { + renderer->multiSample = 1; + } + if ((renderer->samplesModes & kCGLMultisampleBit) != 0) + { + renderer->superSample = 1; + } + CGLDescribeRenderer(info, j, kCGLRPSampleAlpha, &(renderer->alphaSample)); +#endif + CGLDescribeRenderer(info, j, kCGLRPColorModes, &(renderer->colorModes)); + i=0; + int floatPixelFormatInitialized = 0; + while (colorModes[i] != 0) + { + if ((renderer->colorModes & colorModes[i]) != 0) + { + // non-float color model + if (colorModes[i] < kCGLRGBFloat64Bit) + { + // look for max color and alpha values - prefer color models that have alpha + if ((colorModesBitsRGB[i] >= renderer->colorRGBSizeMAX) && (colorModesBitsA[i] >= renderer->colorASizeMAX)) + { + renderer->colorRGBSizeMAX = colorModesBitsRGB[i]; + renderer->colorASizeMAX = colorModesBitsA[i]; + } + renderer->colorModesCount++; + } + // float-color model + if (colorModes[i] >= kCGLRGBFloat64Bit) + { + if (floatPixelFormatInitialized == 0) + { + floatPixelFormatInitialized = 1; + + renderer->colorFloatASizeMAX = colorModesBitsA[i]; + renderer->colorFloatRGBSizeMAX = colorModesBitsRGB[i]; + renderer->colorFloatASizeMIN = colorModesBitsA[i]; + renderer->colorFloatRGBSizeMIN = colorModesBitsRGB[i]; + } + // look for max color and alpha values - prefer color models that have alpha + if ((colorModesBitsRGB[i] >= renderer->colorFloatRGBSizeMAX) && (colorModesBitsA[i] >= renderer->colorFloatASizeMAX)) + { + renderer->colorFloatRGBSizeMAX = colorModesBitsRGB[i]; + renderer->colorFloatASizeMAX = colorModesBitsA[i]; + } + // find min color + if (colorModesBitsA[i] < renderer->colorFloatASizeMIN) + { + renderer->colorFloatASizeMIN = colorModesBitsA[i]; + } + // find min alpha color + if (colorModesBitsA[i] < renderer->colorFloatRGBSizeMIN) + { + renderer->colorFloatRGBSizeMIN = colorModesBitsRGB[i]; + } + renderer->colorFloatModesCount++; + } + } + i++; + } + CGLDescribeRenderer(info, j, kCGLRPDepthModes, &(renderer->depthModes)); + i=0; + while (depthModes[i] != 0) + { + if ((renderer->depthModes & depthModes[i]) != 0) + { + renderer->depthSizeMAX = depthModesBits[i]; + renderer->depthModesCount++; + } + i++; + } + CGLDescribeRenderer(info, j, kCGLRPStencilModes, &(renderer->stencilModes)); + i=0; + while (depthModes[i] != 0) + { + if ((renderer->stencilModes & depthModes[i]) != 0) + { + renderer->stencilSizeMAX = depthModesBits[i]; + renderer->stencilModesCount++; + } + i++; + } + CGLDescribeRenderer(info, j, kCGLRPAccumModes, &(renderer->accumModes)); + i=0; + while (colorModes[i] != 0) + { + if ((renderer->accumModes & colorModes[i]) != 0) + { + if ((colorModesBitsRGB[i] >= renderer->accumRGBSizeMAX) && (colorModesBitsA[i] >= renderer->accumASizeMAX)) + { + renderer->accumRGBSizeMAX = colorModesBitsRGB[i]; + renderer->accumASizeMAX = colorModesBitsA[i]; + } + renderer->accumModesCount++; + } + i++; + } + } + } + CGLDestroyRendererInfo (info); + } + +#if 0 + fprintf(stderr, "gRenderersCount=%ld\n", gRenderersCount); + int j; + for (j=0; j<gRenderersCount; j++) + { + RendererInfo *renderer = &gRenderers[j]; + fprintf(stderr, " id=%ld\n", renderer->id); + fprintf(stderr, " displayMask=%ld\n", renderer->displayMask); + + fprintf(stderr, " accelerated=%ld\n", renderer->accelerated); + + fprintf(stderr, " window=%ld\n", renderer->window); + fprintf(stderr, " fullscreen=%ld\n", renderer->fullscreen); + fprintf(stderr, " multiscreen=%ld\n", renderer->multiscreen); + fprintf(stderr, " offscreen=%ld\n", renderer->offscreen); + fprintf(stderr, " floatPixels=%ld\n", renderer->floatPixels); + fprintf(stderr, " stereo=%ld\n", renderer->stereo); + + fprintf(stderr, " auxBuffers=%ld\n", renderer->auxBuffers); + fprintf(stderr, " sampleBuffers=%ld\n", renderer->sampleBuffers); + fprintf(stderr, " samples=%ld\n", renderer->samples); + fprintf(stderr, " samplesModes=%ld\n", renderer->samplesModes); + fprintf(stderr, " multiSample=%ld\n", renderer->superSample); + fprintf(stderr, " superSample=%ld\n", renderer->superSample); + fprintf(stderr, " alphaSample=%ld\n", renderer->alphaSample); + + fprintf(stderr, " colorModes=%ld\n", renderer->colorModes); + fprintf(stderr, " colorRGBSizeMAX=%ld\n", renderer->colorRGBSizeMAX); + fprintf(stderr, " colorASizeMAX=%ld\n", renderer->colorASizeMAX); + fprintf(stderr, " colorFloatRGBSizeMAX=%ld\n", renderer->colorFloatRGBSizeMAX); + fprintf(stderr, " colorFloatASizeMAX=%ld\n", renderer->colorFloatASizeMAX); + fprintf(stderr, " colorFloatRGBSizeMIN=%ld\n", renderer->colorFloatRGBSizeMIN); + fprintf(stderr, " colorFloatASizeMIN=%ld\n", renderer->colorFloatASizeMIN); + fprintf(stderr, " colorModesCount=%ld\n", renderer->colorModesCount); + fprintf(stderr, " colorFloatModesCount=%ld\n", renderer->colorFloatModesCount); + fprintf(stderr, " depthModes=%ld\n", renderer->depthModes); + fprintf(stderr, " depthSizeMAX=%ld\n", renderer->depthSizeMAX); + fprintf(stderr, " depthModesCount=%ld\n", renderer->depthModesCount); + fprintf(stderr, " stencilModes=%ld\n", renderer->stencilModes); + fprintf(stderr, " stencilSizeMAX=%ld\n", renderer->stencilSizeMAX); + fprintf(stderr, " stencilModesCount=%ld\n", renderer->stencilModesCount); + fprintf(stderr, " accumModes=%ld\n", renderer->accumModes); + fprintf(stderr, " accumRGBSizeMAX=%ld\n", renderer->accumRGBSizeMAX); + fprintf(stderr, " accumASizeMAX=%ld\n", renderer->accumASizeMAX); + fprintf(stderr, " accumModesCount=%ld\n", renderer->accumModesCount); + fprintf(stderr, "\n"); + } +#endif +} + +long validateParameter(NSOpenGLPixelFormatAttribute attribute, long value) +{ + int i; + for (i=0; i<gRenderersCount; i++) { + RendererInfo* renderer = &gRenderers[i]; + if (renderer->accelerated != 0) { + switch (attribute) { + case NSOpenGLPFAStereo: + return renderer->stereo; + + case NSOpenGLPFAStencilSize: + return MIN(value, renderer->stencilSizeMAX); + + default: + break; + } + } + } + + return value; +} + +void* createPixelFormat(int* iattrs, int niattrs, int* ivalues) { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + getRendererInfo(); + + // http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSOpenGLPixelFormat.html + NSOpenGLPixelFormatAttribute attribs[256]; + + int idx = 0; + int i; + for (i = 0; i < niattrs && iattrs[i]>0; i++) { + int attr = iattrs[i]; + switch (attr) { + case NSOpenGLPFAPixelBuffer: + if (ivalues[i] != 0) { + attribs[idx++] = NSOpenGLPFAPixelBuffer; + } + break; + + case kCGLPFAColorFloat: + if (ivalues[i] != 0) { + attribs[idx++] = kCGLPFAColorFloat; + } + break; + + case NSOpenGLPFADoubleBuffer: + if (ivalues[i] != 0) { + attribs[idx++] = NSOpenGLPFADoubleBuffer; + } + break; + + case NSOpenGLPFAStereo: + if (ivalues[i] != 0 && (validateParameter(NSOpenGLPFAStereo, 0 /* dummy */) != 0)) { + attribs[idx++] = NSOpenGLPFAStereo; + } + break; + + case NSOpenGLPFAColorSize: + case NSOpenGLPFAAlphaSize: + case NSOpenGLPFADepthSize: + case NSOpenGLPFAAccumSize: + case NSOpenGLPFASampleBuffers: + case NSOpenGLPFASamples: + attribs[idx++] = attr; + attribs[idx++] = ivalues[i]; + break; + + case NSOpenGLPFAStencilSize: + attribs[idx++] = attr; + attribs[idx++] = validateParameter(NSOpenGLPFAStencilSize, ivalues[i]); + break; + + default: + // Need better way to signal to caller + return nil; + } + } + + // Zero-terminate + attribs[idx++] = 0; + + NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; + if (fmt == nil) { + // should we fallback to defaults or not? + fmt = [NSOpenGLView defaultPixelFormat]; + } + + [pool release]; + return fmt; +} + +void queryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalues) { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSOpenGLPixelFormat* fmt = (NSOpenGLPixelFormat*) pixelFormat; + long tmp; + // FIXME: think about how specifying this might affect the API + int virtualScreen = 0; + + int i; + for (i = 0; i < niattrs && iattrs[i]>0; i++) { + [fmt getValues: &tmp + forAttribute: (NSOpenGLPixelFormatAttribute) iattrs[i] + forVirtualScreen: virtualScreen]; + ivalues[i] = (int) tmp; + } + [pool release]; +} + +void deletePixelFormat(void* pixelFormat) { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSOpenGLPixelFormat* fmt = (NSOpenGLPixelFormat*) pixelFormat; + [fmt release]; + [pool release]; +} + +void* createContext(void* shareContext, + void* view, + void* pixelFormat, + int* viewNotReady) +{ + getRendererInfo(); + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + NSView *nsView = NULL; + NSObject *nsObj = (NSObject*) view; + + if( nsObj != NULL && [nsObj isKindOfClass:[NSView class]] ) { + nsView = (NSView*)nsObj; + } + + if (nsView != NULL) + { + Bool viewReady = true; + + if ([nsView lockFocusIfCanDraw] == NO) + { + viewReady = false; + } + else + { + NSRect frame = [nsView frame]; + if ((frame.size.width == 0) || (frame.size.height == 0)) + { + [nsView unlockFocus]; + viewReady = false; + } + } + + if (!viewReady) + { + if (viewNotReady != NULL) + { + *viewNotReady = 1; + } + + // the view is not ready yet + [pool release]; + return NULL; + } + } + + NSOpenGLContext* nsContext = [[NSOpenGLContext alloc] + initWithFormat: (NSOpenGLPixelFormat*) pixelFormat + shareContext: (NSOpenGLContext*) shareContext]; + + if (nsContext != nil) { + if (nsView != nil) { + [nsContext setView:nsView]; + [nsView unlockFocus]; + } + } + + [pool release]; + return nsContext; +} + +void * getCurrentContext() { + NSOpenGLContext *nsContext = NULL; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + nsContext = [NSOpenGLContext currentContext]; + [pool release]; + return nsContext;; +} + +void * getCGLContext(void* nsJContext) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + void * cglContext = NULL; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + cglContext = [nsContext CGLContextObj]; + [pool release]; + return cglContext; +} + +void * getNSView(void* nsJContext) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + void * view = NULL; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + view = [nsContext view]; + [pool release]; + return view; +} + +Bool makeCurrentContext(void* nsJContext) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [nsContext makeCurrentContext]; + [pool release]; + return true; +} + +Bool clearCurrentContext(void* nsJContext) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSOpenGLContext *currentNSContext = [NSOpenGLContext currentContext]; + if( currentNSContext != nsContext ) { + [nsContext makeCurrentContext]; + } + [NSOpenGLContext clearCurrentContext]; + [pool release]; + return true; +} + +Bool deleteContext(void* nsJContext) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [nsContext clearDrawable]; + [nsContext release]; + [pool release]; + return true; +} + +Bool flushBuffer(void* nsJContext) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [nsContext flushBuffer]; + [pool release]; + return true; +} + +void setContextOpacity(void* nsJContext, int opacity) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + + [nsContext setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity]; +} + +void updateContext(void* nsJContext) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [nsContext update]; + [pool release]; +} + +void copyContext(void* destContext, void* srcContext, int mask) { + NSOpenGLContext *src = (NSOpenGLContext*) srcContext; + NSOpenGLContext *dst = (NSOpenGLContext*) destContext; + [dst copyAttributesFromContext: src withMask: mask]; +} + +void* updateContextRegister(void* nsJContext, void* view) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + NSView *nsView = (NSView*)view; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + ContextUpdater *contextUpdater = [[ContextUpdater alloc] init]; + [contextUpdater registerFor:nsContext with:nsView]; + [pool release]; + return NULL; +} + +void updateContextUnregister(void* updater) { + ContextUpdater *contextUpdater = (ContextUpdater *)updater; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [contextUpdater release]; + [pool release]; +} + +void* createPBuffer(int renderTarget, int internalFormat, int width, int height) { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSOpenGLPixelBuffer* pBuffer = [[NSOpenGLPixelBuffer alloc] + initWithTextureTarget:renderTarget + textureInternalFormat:internalFormat + textureMaxMipMapLevel:0 + pixelsWide:width + pixelsHigh:height]; + [pool release]; + return pBuffer; +} + +Bool destroyPBuffer(void* buffer) { + /* FIXME: not clear whether we need to perform the clearDrawable below */ + NSOpenGLPixelBuffer *pBuffer = (NSOpenGLPixelBuffer*)buffer; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + /* + if (nsContext != NULL) { + [nsContext clearDrawable]; + } + */ + [pBuffer release]; + [pool release]; + + return true; +} + +void setContextPBuffer(void* nsJContext, void* buffer) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + NSOpenGLPixelBuffer *pBuffer = (NSOpenGLPixelBuffer*)buffer; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [nsContext setPixelBuffer: pBuffer + cubeMapFace: 0 + mipMapLevel: 0 + currentVirtualScreen: [nsContext currentVirtualScreen]]; + [pool release]; +} + +void setContextTextureImageToPBuffer(void* nsJContext, void* buffer, int colorBuffer) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + NSOpenGLPixelBuffer *pBuffer = (NSOpenGLPixelBuffer*)buffer; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + [nsContext setTextureImageToPixelBuffer: pBuffer + colorBuffer: (unsigned long) colorBuffer]; + [pool release]; +} + +#include <mach-o/dyld.h> +Bool imagesInitialized = false; +static char libGLStr[] = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"; +static char libGLUStr[] = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib"; +static const struct mach_header *libGLImage; +static const struct mach_header *libGLUImage; +void* getProcAddress(const char *procname) { + if (imagesInitialized == false) { + imagesInitialized = true; + unsigned long options = NSADDIMAGE_OPTION_RETURN_ON_ERROR; + libGLImage = NSAddImage(libGLStr, options); + libGLUImage = NSAddImage(libGLUStr, options); + } + + unsigned long options = NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR; + char underscoreName[512] = "_"; + strcat(underscoreName, procname); + + if (NSIsSymbolNameDefinedInImage(libGLImage, underscoreName) == YES) { + NSSymbol sym = NSLookupSymbolInImage(libGLImage, underscoreName, options); + return NSAddressOfSymbol(sym); + } + + if (NSIsSymbolNameDefinedInImage(libGLUImage, underscoreName) == YES) { + NSSymbol sym = NSLookupSymbolInImage(libGLUImage, underscoreName, options); + return NSAddressOfSymbol(sym); + } + + if (NSIsSymbolNameDefinedWithHint(underscoreName, "GL")) { + NSSymbol sym = NSLookupAndBindSymbol(underscoreName); + return NSAddressOfSymbol(sym); + } + + return NULL; +} + +void setSwapInterval(void* nsJContext, int interval) { + NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; + long swapInterval = interval; + [nsContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval]; +} + +Bool setGammaRamp(int tableSize, float* redRamp, float* greenRamp, float* blueRamp) { + CGDisplayErr err = CGSetDisplayTransferByTable(kCGDirectMainDisplay, tableSize, redRamp, greenRamp, blueRamp); + return (err == CGDisplayNoErr); +} + +void resetGammaRamp() { + CGDisplayRestoreColorSyncSettings(); +} diff --git a/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c b/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c new file mode 100644 index 000000000..5317c2abc --- /dev/null +++ b/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c @@ -0,0 +1,255 @@ +/* + * media_video_Movie.c + * JFXFramework + * + * Created by sun on 17/02/08. + * Copyright 2007 __MyCompanyName__. All rights reserved. + * + */ + +// http://developer.apple.com/technotes/tn2005/tn2140.html +// http://developer.apple.com/qa/qa2005/qa1443.html +// http://developer.apple.com/documentation/QuickTime/Conceptual/QT7UpdateGuide/Chapter03/chapter_3_section_1.html#//apple_ref/doc/c_ref/NewMovieFromProperties +// http://developer.apple.com/qa/qa2001/qa1149.html +// http://developer.apple.com/qa/qa2001/qa1262.html + +#include "com_jogamp_openmax_OMXInstance.h" +#include "omx_tool.h" +#include <stdarg.h> + +static const char * const ClazzNameRuntimeException = + "java/lang/RuntimeException"; +static jclass runtimeExceptionClz=NULL; +#ifdef _WIN32_WCE + #define STDOUT_FILE "\\Storage Card\\demos\\stdout.txt" + #define STDERR_FILE "\\Storage Card\\demos\\stderr.txt" +#endif + +static void _initStatics(JNIEnv *env) +{ + jclass c; +#ifdef _WIN32_WCE + _wfreopen(TEXT(STDOUT_FILE),L"w",stdout); + _wfreopen(TEXT(STDERR_FILE),L"w",stderr); +#endif + fprintf(stdout, "_initstatics ..\n"); fflush(stdout); // JAU + if (runtimeExceptionClz != NULL) { + return; + } + + c = (*env)->FindClass(env, ClazzNameRuntimeException); + if(NULL==c) { + fprintf(stdout, "FatalError: can't find %s\n", ClazzNameRuntimeException); + (*env)->FatalError(env, ClazzNameRuntimeException); + } + runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c); + if(NULL==runtimeExceptionClz) { + fprintf(stdout, "FatalError: can't use %s\n", ClazzNameRuntimeException); + (*env)->FatalError(env, ClazzNameRuntimeException); + } +} + +void java_throwNewRuntimeException(intptr_t jni_env, const char* format, ...) +{ + va_list ap; + char buffer[255]; + va_start(ap, format); + #ifdef _WIN32 + _vsnprintf(buffer, sizeof(buffer)-1, format, ap); + #else + vsnprintf(buffer, sizeof(buffer)-1, format, ap); + #endif + va_end(ap); + buffer[sizeof(buffer)-1]=0; + fprintf(stderr, "RuntimeException: %s\n", buffer); fflush(stderr); + if(jni_env!=0) { + (*((JNIEnv *)jni_env))->ThrowNew((JNIEnv *)jni_env, runtimeExceptionClz, buffer); + } +} + +void OMXInstance_SaveJavaAttributes(OMXToolBasicAV_t *pOMXAV, KDboolean issueJavaCallback) +{ + if(NULL==pOMXAV || 0==pOMXAV->jni_env || 0==pOMXAV->jni_instance) { + fprintf(stderr, "OMXInstance_SaveJavaAttributes failed"); + return; + } else if(issueJavaCallback==KD_TRUE) { + JNIEnv * env = (JNIEnv *)pOMXAV->jni_env; + jobject instance = (jobject)pOMXAV->jni_instance; + (*env)->CallVoidMethod(env, instance, (jmethodID)pOMXAV->jni_mid_saveAttributes); + } +} + +void OMXInstance_UpdateJavaAttributes(OMXToolBasicAV_t *pOMXAV, KDboolean issueJavaCallback) +{ + if(NULL==pOMXAV || 0==pOMXAV->jni_env || 0==pOMXAV->jni_instance) { + fprintf(stderr, "OMXInstance_UpdateJavaAttributes failed"); + return; + } else { + JNIEnv * env = (JNIEnv *)pOMXAV->jni_env; + jobject instance = (jobject)pOMXAV->jni_instance; + (*env)->SetIntField(env, instance, (jfieldID)pOMXAV->jni_fid_width, (jint)pOMXAV->width); + (*env)->SetIntField(env, instance, (jfieldID)pOMXAV->jni_fid_height, (jint)pOMXAV->height); + (*env)->SetIntField(env, instance, (jfieldID)pOMXAV->jni_fid_fps, (jint)pOMXAV->framerate); + (*env)->SetLongField(env, instance, (jfieldID)pOMXAV->jni_fid_bps, (jlong)pOMXAV->bitrate); + (*env)->SetLongField(env, instance, (jfieldID)pOMXAV->jni_fid_totalFrames, (jlong)(pOMXAV->length*pOMXAV->framerate)); + if(issueJavaCallback==KD_TRUE) { + (*env)->CallVoidMethod(env, instance, (jmethodID)pOMXAV->jni_mid_attributesUpdated); + } else { + if(strlen(pOMXAV->videoCodec)>0) { + (*env)->SetObjectField(env, instance, (jfieldID)pOMXAV->jni_fid_vcodec, (*env)->NewStringUTF(env, pOMXAV->videoCodec)); + } + if(strlen(pOMXAV->audioCodec)>0) { + (*env)->SetObjectField(env, instance, (jfieldID)pOMXAV->jni_fid_acodec, (*env)->NewStringUTF(env, pOMXAV->audioCodec)); + } + } + } +} + +JNIEXPORT jlong JNICALL Java_com_jogamp_openmax_OMXInstance__1createInstance + (JNIEnv *env, jobject instance) +{ + OMXToolBasicAV_t * pOMXAV; + + _initStatics(env); + + pOMXAV->jni_env=(intptr_t)env; + pOMXAV->jni_instance=(intptr_t)instance; + + pOMXAV = OMXToolBasicAV_CreateInstance((intptr_t)env, (intptr_t)instance); + if(NULL!=pOMXAV) { + jclass cls = (*env)->GetObjectClass(env, instance); + pOMXAV->jni_mid_saveAttributes = (intptr_t) (*env)->GetMethodID(env, cls, "saveAttributes", "()V"); + pOMXAV->jni_mid_attributesUpdated = (intptr_t) (*env)->GetMethodID(env, cls, "attributesUpdated", "()V"); + pOMXAV->jni_fid_width = (intptr_t) (*env)->GetFieldID(env, cls, "width", "I"); + pOMXAV->jni_fid_height = (intptr_t) (*env)->GetFieldID(env, cls, "height", "I"); + pOMXAV->jni_fid_fps = (intptr_t) (*env)->GetFieldID(env, cls, "fps", "I"); + pOMXAV->jni_fid_bps = (intptr_t) (*env)->GetFieldID(env, cls, "bps", "J"); + pOMXAV->jni_fid_totalFrames = (intptr_t) (*env)->GetFieldID(env, cls, "totalFrames", "J"); + pOMXAV->jni_fid_acodec = (intptr_t) (*env)->GetFieldID(env, cls, "acodec", "Ljava/lang/String;"); + pOMXAV->jni_fid_vcodec = (intptr_t) (*env)->GetFieldID(env, cls, "vcodec", "Ljava/lang/String;"); + } + + return (jlong) (intptr_t) (void *)pOMXAV; +} + +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1setStream + (JNIEnv *env, jobject instance, jlong ptr, jint vBufferNum, jstring jpath) +{ + jboolean iscopy; + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + + fprintf(stdout, "setStream 1 ..\n"); fflush(stdout); // JAU + if (pOMXAV != NULL) { + const char *filePath = (*env)->GetStringUTFChars(env, jpath, &iscopy); + fprintf(stdout, "setStream 2 %s..\n", filePath); fflush(stdout); // JAU + pOMXAV->jni_env=(intptr_t)env; + pOMXAV->jni_instance=(intptr_t)instance; + OMXToolBasicAV_SetStream(pOMXAV, vBufferNum, filePath); + (*env)->ReleaseStringChars(env, jpath, (const jchar *)filePath); + } + fprintf(stdout, "setStream 3 ..\n"); fflush(stdout); // JAU +} + +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1setStreamEGLImageTexture2D + (JNIEnv *env, jobject instance, jlong ptr, jint i, jint tex, jlong image, jlong sync) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + if (pOMXAV != NULL) { + OMXToolBasicAV_SetStreamEGLImageTexture2D( pOMXAV, i, (GLuint) tex, + (EGLImageKHR)(intptr_t)image, + (EGLSyncKHR)(intptr_t)sync); + } +} + +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1activateStream + (JNIEnv *env, jobject instance, jlong ptr) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + + if (pOMXAV != NULL) { + OMXToolBasicAV_ActivateStream(pOMXAV); + } +} + +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1attachVideoRenderer + (JNIEnv *env, jobject instance, jlong ptr) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + OMXToolBasicAV_AttachVideoRenderer(pOMXAV); +} + +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1detachVideoRenderer + (JNIEnv *env, jobject instance, jlong ptr) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + OMXToolBasicAV_DetachVideoRenderer(pOMXAV); +} + +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1setPlaySpeed + (JNIEnv *env, jobject instance, jlong ptr, jfloat scale) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + OMXToolBasicAV_SetPlaySpeed(pOMXAV, scale); +} + +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1play + (JNIEnv *env, jobject instance, jlong ptr) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + OMXToolBasicAV_PlayStart(pOMXAV); + return OMXToolBasicAV_GetCurrentPosition(pOMXAV); +} + +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1pause + (JNIEnv *env, jobject instance, jlong ptr) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + OMXToolBasicAV_PlayPause(pOMXAV); + return OMXToolBasicAV_GetCurrentPosition(pOMXAV); +} + +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1stop + (JNIEnv *env, jobject instance, jlong ptr) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + OMXToolBasicAV_PlayStop(pOMXAV); + return OMXToolBasicAV_GetCurrentPosition(pOMXAV); +} + +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1seek + (JNIEnv *env, jobject instance, jlong ptr, jfloat pos) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + OMXToolBasicAV_PlaySeek(pOMXAV, pos); + return OMXToolBasicAV_GetCurrentPosition(pOMXAV); +} + +JNIEXPORT jint JNICALL Java_com_jogamp_openmax_OMXInstance__1getNextTextureID + (JNIEnv *env, jobject instance, jlong ptr) +{ + jint textureID = 0xffffffff; + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + if (pOMXAV != NULL) { + textureID = OMXToolBasicAV_GetNextTextureID(pOMXAV); + } + return textureID; +} + +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1getCurrentPosition + (JNIEnv *env, jobject instance, jlong ptr) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + return OMXToolBasicAV_GetCurrentPosition(pOMXAV); +} + + +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1destroyInstance + (JNIEnv *env, jobject instance, jlong ptr) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); + if (pOMXAV != NULL) { + OMXToolBasicAV_DestroyInstance(pOMXAV); + } +} + + diff --git a/src/jogl/native/openmax/omx_tool.c b/src/jogl/native/openmax/omx_tool.c new file mode 100644 index 000000000..c6b6494e2 --- /dev/null +++ b/src/jogl/native/openmax/omx_tool.c @@ -0,0 +1,1729 @@ + +#include "omx_tool.h" + +#define VERBOSE_ON 1 +#define VERBOSE2_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(...) fprintf(stdout, __VA_ARGS__) +#else + #define DBG_PRINT(...) +#endif + +#if defined(VERBOSE_ON) && defined(VERBOSE2_ON) + #define DBG_PRINT2(...) fprintf(stdout, __VA_ARGS__) +#else + #define DBG_PRINT2(...) +#endif + +#ifdef VERBOSE_ON + #ifdef _WIN32_WCE + #define STDOUT_FILE "\\Storage Card\\stdout.txt" + #define STDERR_FILE "\\Storage Card\\stderr.txt" + #endif +#endif + +#define NOTSET_U8 ((OMX_U8)0xDE) +#define NOTSET_U16 ((OMX_U16)0xDEDE) +#define NOTSET_U32 ((OMX_U32)0xDEDEDEDE) +#define INIT_PARAM(_X_) (memset(&(_X_), NOTSET_U8, sizeof(_X_)), ((_X_).nSize = sizeof (_X_)), (_X_).nVersion = vOMX) + +void OMXInstance_SaveJavaAttributes(OMXToolBasicAV_t *pOMXAV, KDboolean issueJavaCallback); +void OMXInstance_UpdateJavaAttributes(OMXToolBasicAV_t *pOMXAV, KDboolean issueJavaCallback); + +#if !defined(SELF_TEST) +void java_throwNewRuntimeException(intptr_t jni_env, const char* format, ...); +#else +#include <stdarg.h> +void java_throwNewRuntimeException(intptr_t jni_env, const char* format, ...) { + va_list ap; + char buffer[255]; + va_start(ap, format); + #ifdef _WIN32 + _vsnprintf(buffer, sizeof(buffer)-1, format, ap); + #else + vsnprintf(buffer, sizeof(buffer)-1, format, ap); + #endif + va_end(ap); + buffer[sizeof(buffer)-1]=0; + DBG_PRINT( "RuntimeException: %s\n", buffer); + exit(1); +} +#endif +static void DestroyInstanceUnlock(OMXToolBasicAV_t * pOMXAV); + +#define OMXSAFEVOID(x) \ +do { \ + OMX_ERRORTYPE err = (x); \ + if (err != OMX_ErrorNone) { \ + java_throwNewRuntimeException((NULL!=pOMXAV)?pOMXAV->jni_env:0, "FAILED at %s:%d, Error: 0x%x\n", __FILE__, __LINE__, err); \ + if(NULL!=pOMXAV) { \ + DestroyInstanceUnlock(pOMXAV); \ + } \ + return; \ + } \ +} while (0); + +#define OMXSAFE(x) \ +do { \ + OMX_ERRORTYPE err = (x); \ + if (err != OMX_ErrorNone) { \ + java_throwNewRuntimeException((NULL!=pOMXAV)?pOMXAV->jni_env:0, "FAILED at %s:%d, Error: 0x%x\n", __FILE__, __LINE__, err); \ + if(NULL!=pOMXAV) { \ + DestroyInstanceUnlock(pOMXAV); \ + } \ + return -1; \ + } \ +} while (0); + +#define OMXSAFEERR(x) \ +do { \ + OMX_ERRORTYPE err = (x); \ + if (err != OMX_ErrorNone) { \ + java_throwNewRuntimeException((NULL!=pOMXAV)?pOMXAV->jni_env:0, "FAILED at %s:%d, Error: 0x%x\n", __FILE__, __LINE__, err); \ + if(NULL!=pOMXAV) { \ + DestroyInstanceUnlock(pOMXAV); \ + } \ + return err; \ + } \ +} while (0); + +static PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; +static PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR; +static PFNEGLGETSYNCATTRIBKHRPROC eglGetSyncAttribKHR; +static PFNEGLSIGNALSYNCKHRPROC eglSignalSyncKHR; +static int _hasEGLSync = 0; + +#define GETEXTENSION(type, ext) \ +do \ +{ \ + ext = (type) eglGetProcAddress(#ext); \ + if (!ext) \ + { \ + fprintf(stderr, "ERROR getting proc addr of " #ext "\n"); \ + } \ +} while (0); + +int USE_OPENGL = 1; +int USE_HWAUDIOOUT = 1; +int USE_AUDIOBUFFERING = 0; +const int PORT_VRENDERER = 6; + +static OMX_VERSIONTYPE vOMX; + +static int _initialized = 0; +static void InitStatic() +{ + if(_initialized) return; + +#ifdef VERBOSE_ON + #ifdef _WIN32_WCE + _wfreopen(TEXT(STDOUT_FILE),L"w",stdout); + _wfreopen(TEXT(STDERR_FILE),L"w",stderr); + #endif +#endif + + _initialized = 1; + + vOMX.s.nVersionMajor = 1; + vOMX.s.nVersionMinor = 1; + vOMX.s.nRevision = 0; + vOMX.s.nStep = 0; + + GETEXTENSION(PFNEGLCREATEIMAGEKHRPROC, eglCreateImageKHR); + GETEXTENSION(PFNEGLCREATESYNCKHRPROC, eglCreateSyncKHR); + GETEXTENSION(PFNEGLGETSYNCATTRIBKHRPROC, eglGetSyncAttribKHR); + GETEXTENSION(PFNEGLSIGNALSYNCKHRPROC, eglSignalSyncKHR); + if(NULL==eglGetSyncAttribKHR||NULL==eglSignalSyncKHR) { + _hasEGLSync = 0; + } else { + _hasEGLSync = 1; + } + + OMX_Init(); +} + +static void Invalidate(OMXToolBasicAV_t * pOMXAV) +{ + DBG_PRINT("INVALIDATE\n"); + pOMXAV->status=OMXAV_INVALID; +} + +static void GetComponentName(OMX_HANDLETYPE hComponent, KDchar *pName, int nameMaxLen) +{ + OMX_VERSIONTYPE v1, v2; + OMX_UUIDTYPE uuid; + + OMX_GetComponentVersion(hComponent, pName, &v1, &v2, &uuid); +} + +static OMX_ERRORTYPE UpdateStreamInfo(OMXToolBasicAV_t * pOMXAV, KDboolean issueCallback); + +static OMX_ERRORTYPE EventHandler( + OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_PTR pAppData, + OMX_IN OMX_EVENTTYPE eEvent, + OMX_IN OMX_U32 nData1, + OMX_IN OMX_U32 nData2, + OMX_IN OMX_PTR pEventData) +{ + OMXToolBasicAV_t * pOMXAV = (OMXToolBasicAV_t *) pAppData; + KDchar name[128]; + + GetComponentName(hComponent, name, 128); + + switch (eEvent) + { + case OMX_EventCmdComplete: + { + DBG_PRINT("event complete: cmd 0x%X, s:0x%X, component: %p - %s\n", (unsigned)nData1, (unsigned)nData2, hComponent, name); + if (nData1 == OMX_CommandStateSet && pOMXAV->status == OMXAV_INVALID) + { + if (nData2 > OMX_StateLoaded) { + DBG_PRINT("\t state -> StateLoaded\n"); + // Transition the component down to StateLoaded + OMX_SendCommand(hComponent, OMX_CommandStateSet, OMX_StateLoaded, 0); + } + } + else if (nData1 == OMX_CommandFlush && nData2 == OMX_ALL) + { + DBG_PRINT("\t flush\n"); + kdThreadSemPost(pOMXAV->flushSem); + } + break; + } + case OMX_EventBufferFlag: + if (nData2 & OMX_BUFFERFLAG_EOS) + { + DBG_PRINT("event buffer EOS: component: %p - %s\n", hComponent, name); + if (pOMXAV->endComponent == hComponent) + { + DBG_PRINT("\t end component - FIN\n"); + pOMXAV->status = OMXAV_FIN; + } + } + break; + case OMX_EventError: + { + if (nData1 == OMX_ErrorIncorrectStateTransition) + { + DBG_PRINT("event error: 0x%X IncorrectTransition, component: %p - %s\n", (unsigned int) nData1, hComponent, name); + // We are shutting down, just continue with that process + OMX_SendCommand(hComponent, OMX_CommandStateSet, OMX_StateIdle, 0); + } + else if(nData1 == OMX_ErrorSameState) + { + DBG_PRINT("event error: Same State 0x%X, component: %p - %s\n", (unsigned int) nData2, hComponent, name); + } + else + { + DBG_PRINT("event error: 0x%X, component: %p - %s\n", (unsigned int) nData1, hComponent, name); + Invalidate(pOMXAV); + } + } + break; + case OMX_EventPortSettingsChanged: + { + (void) UpdateStreamInfo(pOMXAV, (pOMXAV->status>OMXAV_INIT)?KD_TRUE:KD_FALSE); + } + break; + default: + break; + } + + return OMX_ErrorNone; +} + + +static OMX_ERRORTYPE EmptyBufferDone( + OMX_OUT OMX_HANDLETYPE hComponent, + OMX_OUT OMX_PTR pAppData, + OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) +{ + return OMX_ErrorNone; +} + +static OMX_ERRORTYPE FillBufferDone( + OMX_OUT OMX_HANDLETYPE hComponent, + OMX_OUT OMX_PTR pAppData, + OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) +{ + OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *) pAppData; + + if (pBuffer->nFlags & OMX_BUFFERFLAG_EOS) + { + pOMXAV->status = OMXAV_FIN; + } + pOMXAV->available++; + DBG_PRINT("FillBufferDone avail %d\n", pOMXAV->available); + + return OMX_ErrorNone; +} + +#define STATE_SLEEP 10 // ms +#define STATE_TIMEOUT 1000 // ms +#define STATE_TIMEOUT_LOOP (STATE_TIMEOUT/STATE_SLEEP) + +static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE hComponent, + OMX_STATETYPE eTestState, + OMX_STATETYPE eTestState2, + OMX_STATETYPE *currentState) +{ + OMX_ERRORTYPE eError = OMX_ErrorNone; + OMX_STATETYPE eState; + int loop=STATE_TIMEOUT_LOOP; + + DBG_PRINT( "WaitForState p1 c:%p s1:0x%X s2:0x%X\n", hComponent, eTestState, eTestState2); + eError = OMX_GetState(hComponent, &eState); + DBG_PRINT( "WaitForState p2 s:0x%X e:0x%X\n", eState, eError); + + while (loop>0 && + OMX_ErrorNone == eError && + eState != eTestState && + eState != eTestState2) + { + usleep(STATE_SLEEP*1000); + loop--; + + eError = OMX_GetState(hComponent, &eState); + DBG_PRINT( "WaitForState p3 s:0x%X e:0x%X\n", eState, eError); + } + + if(NULL!=currentState) *currentState=eState; + + return eError; +} + +static KDint SyncOnState(OMX_HANDLETYPE hComponent, OMX_STATETYPE state) +{ + OMX_STATETYPE currentState; + OMX_ERRORTYPE eError = WaitForState(hComponent, state, OMX_StateInvalid, ¤tState); + return ( OMX_ErrorNone != eError ) ? -1 : ( currentState!=state ) ? -2 : 0 ; +} + +static KDint CheckState(OMX_HANDLETYPE hComponent, OMX_STATETYPE state) +{ + OMX_ERRORTYPE eError = OMX_ErrorNone; + OMX_STATETYPE eState; + + eError = OMX_GetState(hComponent, &eState); + + return ( OMX_ErrorNone != eError ) ? -1 : ( eState!=state ) ? -2 : 0 ; +} + +KDint OMXToolBasicAV_IsFileValid(const KDchar * file) +{ + #ifdef _WIN32 + KDchar cvtdPath[_MAX_PATH]; + + if(NULL==file) return -1; + + kdStrcpy_s(cvtdPath, _MAX_PATH, file); + while(kdStrchr(cvtdPath,'/')) + *kdStrchr(cvtdPath,'/')='\\'; + + { + #ifdef UNICODE + wchar_t properfilename[_MAX_PATH]; + mbstowcs( properfilename, cvtdPath, _MAX_PATH ); + #else + char *properfilename = cvtdPath; + #endif + + if (INVALID_FILE_ATTRIBUTES==GetFileAttributes(properfilename)) + { + fprintf(stderr, "!>Input file (%s) does not exist! EXITING.", file); + return -2; + } + } + #else + if(NULL==file) return -1; + #endif + + return 0; +} + +KDint OMXToolBasicAV_CheckState(OMXToolBasicAV_t * pOMXAV, OMX_STATETYPE state) +{ + KDint i, res; + if(NULL==pOMXAV) return -1; + + for(i=0; i<OMXAV_H_NUMBER; i++) { + if(0!=pOMXAV->comp[i]) { + if( 0!=(res=CheckState(pOMXAV->comp[i], state)) ) { + return res-(i*10); + } + } + } + return 0; +} + +KDint OMXToolBasicAV_WaitForState(OMXToolBasicAV_t * pOMXAV, OMX_STATETYPE state) +{ + KDint res, i; + DBG_PRINT( "OMXToolBasicAV_WaitForState %p s:%d\n", pOMXAV, state); + if(NULL==pOMXAV) { + DBG_PRINT( "OMXToolBasicAV_WaitForState p1\n"); + return -1; + } + + for(i=0; i<OMXAV_H_NUMBER; i++) { + if(0!=pOMXAV->comp[i]) { + DBG_PRINT( "OMXToolBasicAV_WaitForState p4 %d c:%p\n", i, pOMXAV->comp[i]); + if( 0!=(res=SyncOnState(pOMXAV->comp[i], state)) ) { + KDchar name[128]; + GetComponentName(pOMXAV->comp[i], name, 128); + DBG_PRINT( "OMXToolBasicAV_WaitForState Failed (Wait) %d c:%p - %s, s:0x%X\n", + i, pOMXAV->comp[i], name, state); + return res-(i*10); + } + } + } + + return 0; +} + +static OMX_ERRORTYPE RequestState(OMX_HANDLETYPE hComponent, OMX_STATETYPE state, KDboolean wait) +{ + OMX_ERRORTYPE eError = OMX_ErrorNone; + OMX_STATETYPE eState; + eError = OMX_GetState(hComponent, &eState); + DBG_PRINT( "RequestState p2 c:%p, e:0x%X, s:0x%X\n", + hComponent, eError, eState); + // Skip StateSet in case the state is already reached .. + if(OMX_ErrorNone != eError || eState!=state) { + eError = OMX_SendCommand(hComponent, OMX_CommandStateSet, state, 0); + DBG_PRINT( "RequestState p3 c:%p e:0x%X s: 0x%X -> 0x%X\n", + hComponent, eError, eState, state); + if(wait) { + OMX_STATETYPE currentState; + eError = WaitForState(hComponent, state, OMX_StateInvalid, ¤tState); + if ( OMX_ErrorNone==eError && currentState!=state ) eError=OMX_StateInvalid; + } + } + return eError; +} + +KDint OMXToolBasicAV_RequestState(OMXToolBasicAV_t * pOMXAV, OMX_STATETYPE state, KDboolean wait) +{ + KDint i; + DBG_PRINT( "OMXToolBasicAV_RequestState %p s:%d, w:%d\n", pOMXAV, state, wait); + if(NULL==pOMXAV) { + DBG_PRINT( "OMXToolBasicAV_RequestState p1\n"); + return -1; + } + + for(i=0; i<OMXAV_H_NUMBER; i++) { + if(0!=pOMXAV->comp[i]) { + OMXSAFE(RequestState(pOMXAV->comp[i], state, KD_FALSE)); + } + } + + if (wait) + { + return OMXToolBasicAV_WaitForState(pOMXAV, state); + } + + return 0; +} + +static KDint SendCommand(OMXToolBasicAV_t * pOMXAV, OMX_COMMANDTYPE cmd, OMX_U32 nParam1, OMX_PTR pCmdData) +{ + KDint i; + if(NULL==pOMXAV) return -1; + + for(i=0; i<OMXAV_H_NUMBER; i++) { + if(0!=pOMXAV->comp[i]) { + if(OMX_ErrorNone!=OMX_SendCommand(pOMXAV->comp[i], cmd, nParam1, pCmdData)) { + return -1; + } + if(OMX_CommandFlush==cmd) { + kdThreadSemWait(pOMXAV->flushSem); + } + } + } + return 0; +} + +static KDint PlayStop(OMXToolBasicAV_t * pOMXAV); +static int DetachVideoRenderer(OMXToolBasicAV_t * pOMXAV); + +static void DestroyInstanceUnlock(OMXToolBasicAV_t * pOMXAV) +{ + // 0: Stop + // 1: X -> idle + // 2: Disable all ports + // 3: DetachVideoRenderer + // 3: X -> loaded + // 4: Free Handle + // 5: Free mutex/semaphores/struct + int i, res1=0, res2=0; + if(NULL==pOMXAV) return; + + DBG_PRINT( "Destroy p1\n"); + PlayStop(pOMXAV); + + DBG_PRINT( "Destroy p2\n"); + if(0!=(res1=OMXToolBasicAV_RequestState(pOMXAV, OMX_StateIdle, KD_TRUE))) + { + java_throwNewRuntimeException(pOMXAV->jni_env, "Destroy - Wait for Idle Failed (%d)", res1); + } + + DBG_PRINT( "Destroy p3\n"); + SendCommand(pOMXAV, OMX_CommandPortDisable, OMX_ALL, 0); // Ignore error .. + + DBG_PRINT( "Destroy p3\n"); + DetachVideoRenderer(pOMXAV); + + DBG_PRINT( "Destroy p4\n"); + if(0!=(res2=OMXToolBasicAV_RequestState(pOMXAV, OMX_StateLoaded, KD_TRUE))) + { + if(!res1) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Destroy - Wait for Loaded Failed (%d)", res2); + } + } + + DBG_PRINT( "Destroy p5\n"); + for(i=0; i<OMXAV_H_NUMBER; i++) { + if(0!=pOMXAV->comp[i]) { + OMX_FreeHandle(pOMXAV->comp[i]); + pOMXAV->comp[i]=0; + } + } + + if(0!=pOMXAV->flushSem) { + DBG_PRINT( "Destroy p6\n"); + kdThreadSemFree(pOMXAV->flushSem); + pOMXAV->flushSem=0; + } + if(0!=pOMXAV->mutex) { + DBG_PRINT( "Destroy p7\n"); + kdThreadMutexUnlock(pOMXAV->mutex); + DBG_PRINT( "Destroy p8\n"); + kdThreadMutexFree(pOMXAV->mutex); + pOMXAV->mutex=0; + } + + DBG_PRINT( "Destroy DONE\n"); + + free(pOMXAV); +} + +static OMX_ERRORTYPE AddFile(OMXToolBasicAV_t * pOMXAV, const KDchar* filename) +{ +// FIXME: Non NV case .. +#if 0 + OMX_ERRORTYPE eError; + NVX_PARAM_FILENAME oFilenameParam; + OMX_INDEXTYPE eIndexParamFilename; + + eError = OMX_GetExtensionIndex(pOMXAV->comp[OMXAV_H_READER], NVX_INDEX_PARAM_FILENAME, + &eIndexParamFilename); + if (eError != OMX_ErrorNone) + return eError; + + INIT_PARAM(oFilenameParam); + oFilenameParam.pFilename = (char*) filename; + + eError = OMX_SetParameter(pOMXAV->comp[OMXAV_H_READER], eIndexParamFilename, &oFilenameParam); + if (eError != OMX_ErrorNone) + return eError; + + return OMX_ErrorNone; +#else + return OMX_ErrorNotImplemented; +#endif +} + +static OMX_ERRORTYPE ProbePort(OMXToolBasicAV_t * pOMXAV, int port, KDchar *codec, KDchar* component) +{ +// FIXME: Non NV case .. +#if 0 + OMX_U32 roles = 1; + OMX_ERRORTYPE err = OMX_ErrorNone; + OMX_INDEXTYPE eParam; + NVX_PARAM_STREAMTYPE oStreamType; + OMX_PARAM_PORTDEFINITIONTYPE oPortDef; + + INIT_PARAM(oStreamType); + INIT_PARAM(oPortDef); + OMXSAFEERR(OMX_GetExtensionIndex(pOMXAV->comp[OMXAV_H_READER], NVX_INDEX_PARAM_STREAMTYPE, &eParam)); + + oPortDef.nPortIndex = port; + OMXSAFEERR(OMX_GetParameter(pOMXAV->comp[OMXAV_H_READER], OMX_IndexParamPortDefinition, &oPortDef)); + + oStreamType.nPort = port; + OMXSAFEERR(OMX_GetParameter(pOMXAV->comp[OMXAV_H_READER], eParam, &oStreamType)); + + if (oPortDef.eDomain != OMX_PortDomainVideo && + oPortDef.eDomain != OMX_PortDomainAudio) { + return OMX_ErrorNotImplemented; + } + + switch (oStreamType.eStreamType) + { +#define CODEC(a, b) case a: kdStrncat_s(codec, 128, b, kdStrlen(b)); break + CODEC(NvxStreamType_MPEG4, "mpeg4"); + CODEC(NvxStreamType_H264, "avc"); + CODEC(NvxStreamType_H263, "mpeg4"); + CODEC(NvxStreamType_WMV, "vc1"); + CODEC(NvxStreamType_MP3, "mp3"); + CODEC(NvxStreamType_AAC, "aac"); + CODEC(NvxStreamType_AACSBR, "eaacplus"); + CODEC(NvxStreamType_BSAC, "bsac"); + CODEC(NvxStreamType_WMA, "wma"); + CODEC(NvxStreamType_WMAPro, "wmapro"); + CODEC(NvxStreamType_WMALossless, "wmalossless"); + CODEC(NvxStreamType_AMRWB, "amrwb"); + CODEC(NvxStreamType_AMRNB, "amrnb"); + CODEC(NvxStreamType_VORBIS, "vorbis"); +#undef CODEC + default: + return OMX_ErrorNotImplemented; + } + + { + KDchar ocodec[256]; + OMX_U8 *tmp = (OMX_U8*) kdMalloc(OMX_MAX_STRINGNAME_SIZE + 1); + kdMemset(tmp, 0, sizeof(OMX_U8) * (OMX_MAX_STRINGNAME_SIZE + 1)); + + if (oPortDef.eDomain == OMX_PortDomainVideo) + kdStrcpy_s(ocodec, 128, "video_decoder."); + else if (oPortDef.eDomain == OMX_PortDomainAudio) + kdStrcpy_s(ocodec, 128, "audio_decoder."); + kdStrncat_s(ocodec, 128, codec, kdStrlen(codec)); + + err = OMX_GetComponentsOfRole(codec, &roles, &tmp); + kdStrcpy_s(component, 256, (KDchar*) tmp); + kdFree(tmp); + printf("%s(%s) -> %s\n", ocodec, codec, component); + } + + return err != OMX_ErrorNone ? err : roles ? OMX_ErrorNone : OMX_ErrorComponentNotFound; +#else + return OMX_ErrorNotImplemented; +#endif +} + +static int StartClock(OMXToolBasicAV_t * pOMXAV, KDboolean start, KDfloat32 time) { + OMX_TIME_CONFIG_CLOCKSTATETYPE oClockState; + OMX_ERRORTYPE eError = OMX_ErrorNone; + int loop=STATE_TIMEOUT_LOOP; + INIT_PARAM(oClockState); + oClockState.nOffset = 0; + oClockState.nStartTime = (KD_TRUE==start)? (OMX_TICKS) (time * 1000.0 * 1000.0) : 0; + oClockState.nWaitMask = 0; + oClockState.eState = (KD_TRUE==start)?OMX_TIME_ClockStateRunning:OMX_TIME_ClockStateStopped; + + eError = OMX_SetConfig(pOMXAV->comp[OMXAV_H_CLOCK], OMX_IndexConfigTimeClockState, &oClockState); + while (loop>0 && OMX_ErrorNotReady == eError) + { + DBG_PRINT( "Play 3.2\n"); + usleep(STATE_SLEEP*1000); + loop--; + eError = OMX_SetConfig(pOMXAV->comp[OMXAV_H_CLOCK], OMX_IndexConfigTimeClockState, + &oClockState); + } + return (OMX_ErrorNotReady == eError)?-1:0; +} + +static KDfloat32 GetClockPosition(OMXToolBasicAV_t * pOMXAV) +{ + OMX_TIME_CONFIG_TIMESTAMPTYPE stamp; + INIT_PARAM(stamp); + stamp.nPortIndex = 0; + + OMX_GetConfig(pOMXAV->comp[OMXAV_H_CLOCK], OMX_IndexConfigTimeCurrentMediaTime, &stamp); + return (KDfloat32) (stamp.nTimestamp * (1.0f/(1000.0f*1000.0f))); +} + +static KDfloat32 GetClockScale(OMXToolBasicAV_t * pOMXAV) +{ + OMX_TIME_CONFIG_SCALETYPE pScale; + INIT_PARAM(pScale); + + OMX_GetConfig(pOMXAV->comp[OMXAV_H_CLOCK], OMX_IndexConfigTimeScale, &pScale); + return (pScale.xScale / 65536.0f); +} + +static KDint SetClockScale(OMXToolBasicAV_t * pOMXAV, KDfloat32 scale) +{ + OMX_TIME_CONFIG_SCALETYPE pScale; + INIT_PARAM(pScale); + pScale.xScale = (int) (scale * (1<<16)); + + OMX_SetConfig(pOMXAV->comp[OMXAV_H_CLOCK], OMX_IndexConfigTimeScale, &pScale); + return 0; +} + +static int SetMediaPosition(OMXToolBasicAV_t * pOMXAV, KDfloat32 time) { + OMX_ERRORTYPE eError = OMX_ErrorNone; + OMX_TIME_CONFIG_TIMESTAMPTYPE timestamp; + int loop=STATE_TIMEOUT_LOOP; + INIT_PARAM(timestamp); + timestamp.nPortIndex = 0; + timestamp.nTimestamp = (OMX_TICKS) (time * 1000.0 * 1000.0); + + eError = OMX_SetConfig(pOMXAV->comp[OMXAV_H_READER], OMX_IndexConfigTimePosition, ×tamp); + while (loop>0 && OMX_ErrorNotReady == eError) + { + usleep(STATE_SLEEP*1000); + loop--; + eError = OMX_SetConfig(pOMXAV->comp[OMXAV_H_READER], OMX_IndexConfigTimePosition, ×tamp); + } + return (OMX_ErrorNotReady == eError)?-1:0; +} + +static KDfloat32 GetMediaLength(OMXToolBasicAV_t * pOMXAV) +{ +// FIXME: Non NV case .. +#if 0 + NVX_PARAM_DURATION oDuration; + OMX_INDEXTYPE eParam; + + if (OMX_ErrorNone != OMX_GetExtensionIndex(pOMXAV->comp[OMXAV_H_READER], NVX_INDEX_PARAM_DURATION, &eParam)) + return -1.0f; + + if (OMX_ErrorNone != OMX_GetParameter(pOMXAV->comp[OMXAV_H_READER], eParam, &oDuration)) + return -1.0f; + + return (KDfloat32) (oDuration.nDuration * (1.0f/(1000.0f*1000.0f))); +#else + return -1.0f; +#endif +} + +static OMX_ERRORTYPE UpdateStreamInfo(OMXToolBasicAV_t * pOMXAV, KDboolean issueCallback) +{ + OMX_ERRORTYPE err = OMX_ErrorNone; + OMX_PARAM_PORTDEFINITIONTYPE oPortDef; + + DBG_PRINT( "Update StreamInfo p0\n" ); + + kdMemset(&oPortDef, 0, sizeof(oPortDef)); + oPortDef.nSize = sizeof(oPortDef); + oPortDef.nVersion.s.nVersionMajor = 1; + oPortDef.nVersion.s.nVersionMinor = 1; + oPortDef.nPortIndex = 0; + err = OMX_GetParameter(pOMXAV->comp[OMXAV_H_READER], OMX_IndexParamPortDefinition, &oPortDef); + if(OMX_ErrorNone!=err) { + fprintf(stderr, "UpdateStreamInfo failed - p1 0x%X", err); + return err; + } + + if (oPortDef.eDomain != OMX_PortDomainVideo) + { + kdMemset(&oPortDef, 0, sizeof(oPortDef)); + oPortDef.nSize = sizeof(oPortDef); + oPortDef.nVersion.s.nVersionMajor = 1; + oPortDef.nVersion.s.nVersionMinor = 1; + oPortDef.nPortIndex = 1; + err = OMX_GetParameter(pOMXAV->comp[OMXAV_H_READER], OMX_IndexParamPortDefinition, &oPortDef); + if(OMX_ErrorNone!=err) { + fprintf(stderr, "UpdateStreamInfo failed - p2 0x%X", err); + return err; + } + } + + DBG_PRINT( "Update StreamInfo p1\n" ); + OMXInstance_SaveJavaAttributes(pOMXAV, issueCallback); + + pOMXAV->width = oPortDef.format.video.nFrameWidth; + pOMXAV->height = oPortDef.format.video.nFrameHeight; + /* pOMXAV->stride = oPortDef.format.video.nStride; + pOMXAV->sliceHeight = oPortDef.format.video.nSliceHeight; */ + pOMXAV->framerate = oPortDef.format.video.xFramerate; + pOMXAV->bitrate = oPortDef.format.video.nBitrate; + DBG_PRINT( "Update StreamInfo p2 %dx%d, fps %d, bps %d\n", pOMXAV->width, pOMXAV->height, pOMXAV->framerate, pOMXAV->bitrate ); + pOMXAV->length = GetMediaLength(pOMXAV); + pOMXAV->speed = GetClockScale(pOMXAV); + + OMXInstance_UpdateJavaAttributes(pOMXAV, issueCallback); + + return err; +} + +static int AttachAudioRenderer(OMXToolBasicAV_t * pOMXAV) +{ +// FIXME: Non NV case .. +#if 0 + int res=0; + // Configure audio port + + if (USE_AUDIOBUFFERING) + { + // FIXME: proper audio buffering .. + OMXSAFE(OMX_GetHandle(&pOMXAV->comp[OMXAV_H_ABUFFERING], "OMX.Nvidia.audio.visualization", pOMXAV, &pOMXAV->callbacks)); + if(0!=(res=SyncOnState(pOMXAV->comp[OMXAV_H_ABUFFERING], OMX_StateLoaded))) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Loading AudioBuffering Failed (%d)", res); + return res; + } + /** + if (m_settings.m_avsync) + { + // Tweak the avsync parameter + NVX_CONFIG_VISU conf; + INIT_PARAM(conf); + conf.nAVSyncOffset = m_settings.m_avsync; + + OMX_INDEXTYPE idx; + OMX_GetExtensionIndex(pOMXAV->comp[OMXAV_H_ABUFFERING], NVX_INDEX_PARAM_VISUDATA, &idx); + OMX_SetConfig(pOMXAV->comp[OMXAV_H_ABUFFERING], idx, &conf); + }*/ + } + + OMXSAFE(OMX_GetHandle(&pOMXAV->comp[OMXAV_H_ARENDERER], "OMX.Nvidia.audio.render",pOMXAV, &pOMXAV->callbacks)); + pOMXAV->endComponent = pOMXAV->comp[OMXAV_H_ARENDERER]; + + // mandatory before SetupTunnel + if(0!=(res=SyncOnState(pOMXAV->comp[OMXAV_H_ARENDERER], OMX_StateLoaded))) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Loading AudioRenderer Failed (%d)", res); + return res; + } + + { + OMX_INDEXTYPE eIndexConfigOutputType; + NVX_CONFIG_AUDIOOUTPUT ao; + OMX_ERRORTYPE eError; + + INIT_PARAM(ao); + + eError = OMX_GetExtensionIndex(pOMXAV->comp[OMXAV_H_ARENDERER], NVX_INDEX_CONFIG_AUDIO_OUTPUT, + &eIndexConfigOutputType); + if (eError != OMX_ErrorNoMore) + { + /** FIXME: HDMI configuration .. + // for now, only put audio out hdmi if the settings say to, regardless of the hdmi-video flag. + // if (// m_settings.m_hdmiVideo || // m_settings.m_hdmiAudio) + // ao.eOutputType = NVX_AUDIO_OutputHdmi; + else */ + ao.eOutputType = NVX_AUDIO_OutputI2S; + + OMX_SetConfig(pOMXAV->comp[OMXAV_H_ARENDERER], eIndexConfigOutputType, &ao); + } + } + + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_CLOCK], OMX_CommandPortEnable, pOMXAV->audioPort, 0)); + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_ARENDERER], OMX_CommandPortEnable, 1, 0)); + + if (USE_AUDIOBUFFERING) + { + OMXSAFE(OMX_SetupTunnel(pOMXAV->comp[OMXAV_H_ADECODER], 1, pOMXAV->comp[OMXAV_H_ABUFFERING], 0)); + OMXSAFE(OMX_SetupTunnel(pOMXAV->comp[OMXAV_H_ABUFFERING], 1, pOMXAV->comp[OMXAV_H_ARENDERER], 0)); + } + else + { + OMXSAFE(OMX_SetupTunnel(pOMXAV->comp[OMXAV_H_ADECODER], 1, pOMXAV->comp[OMXAV_H_ARENDERER], 0)); + } + + OMXSAFE(OMX_SetupTunnel(pOMXAV->comp[OMXAV_H_CLOCK], pOMXAV->audioPort, pOMXAV->comp[OMXAV_H_ARENDERER], 1)); + + return OMX_ErrorNone; +#else + return OMX_ErrorNotImplemented; +#endif +} + +static int AttachVideoRenderer(OMXToolBasicAV_t * pOMXAV) +{ + int i, res=0; + if(KD_NULL!=pOMXAV->comp[OMXAV_H_VSCHEDULER]) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Detach Video first"); + return -1; + } + OMXSAFE(OMX_GetHandle(&pOMXAV->comp[OMXAV_H_VSCHEDULER], "OMX.Nvidia.video.scheduler", pOMXAV, &pOMXAV->callbacks)); + pOMXAV->endComponent = pOMXAV->comp[OMXAV_H_VSCHEDULER]; + + // mandatory before SetupTunnel + if(0!=(res=SyncOnState(pOMXAV->comp[OMXAV_H_VSCHEDULER], OMX_StateLoaded))) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Loading VideoScheduler Failed (%d)", res); + return res; + } + // mandatory before EGLUseImage + OMXSAFE(RequestState(pOMXAV->comp[OMXAV_H_VSCHEDULER], OMX_StateIdle, KD_FALSE)); + + DBG_PRINT( "Attach VR %p c:%p\n", pOMXAV, pOMXAV->comp[OMXAV_H_VSCHEDULER]); + OMXSAFE(UpdateStreamInfo(pOMXAV, KD_FALSE)); + + DBG_PRINT( "UseEGLImg port enable/tunneling %p\n", pOMXAV); + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_CLOCK], OMX_CommandPortEnable, PORT_VRENDERER, 0)); + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_VDECODER], OMX_CommandPortEnable, 1, 0)); + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_VSCHEDULER], OMX_CommandPortEnable, 0, 0)); + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_VSCHEDULER], OMX_CommandPortEnable, 2, 0)); + OMXSAFE(OMX_SetupTunnel(pOMXAV->comp[OMXAV_H_VDECODER], 1, pOMXAV->comp[OMXAV_H_VSCHEDULER], 0)); + OMXSAFE(OMX_SetupTunnel(pOMXAV->comp[OMXAV_H_CLOCK], PORT_VRENDERER, pOMXAV->comp[OMXAV_H_VSCHEDULER], 2)); + + for (i = 0; i < pOMXAV->vBufferNum; i++) { + OMXToolImageBuffer_t *pBuf = &pOMXAV->buffers[i]; + // The Texture, EGLImage and EGLSync was created by the Java client, + // and registered using the OMXToolBasicAV_SetStreamEGLImageTexture2D command. + + DBG_PRINT( "UseEGLImg %p #%d t:%d i:%p s:%p p1\n", pOMXAV, i, pBuf->tex, pBuf->image, pBuf->sync); + + if(NULL==pBuf->image) { + java_throwNewRuntimeException(pOMXAV->jni_env, "AttachVideoRenderer: User didn't set buffer %d/%d\n", i, pOMXAV->vBufferNum); + return -1; + } else { + // tell decoder output port that it will be using EGLImage + OMXSAFE(OMX_UseEGLImage( + pOMXAV->comp[OMXAV_H_VSCHEDULER], + &pBuf->omxBufferHeader, + 1, // The port to use the EGLImage for + pOMXAV, // app private data + pBuf->image)); + } + DBG_PRINT( "UseEGLImg %p #%d t:%d i:%p s:%p b:%p - p2\n", + pOMXAV, i, pBuf->tex, pBuf->image, pBuf->sync, pBuf->omxBufferHeader); + } + + DBG_PRINT( "UseEGLImg %p #%d DONE\n", pOMXAV, i); + return 0; +} + +static int DetachVideoRenderer(OMXToolBasicAV_t * pOMXAV) +{ + int i; + if(NULL==pOMXAV) return -1; + + if(KD_NULL==pOMXAV->comp[OMXAV_H_VSCHEDULER]) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Attach Video first"); + return -1; + } + DBG_PRINT( "DetachVideoRenderer p0\n"); + if(0==CheckState(pOMXAV->comp[OMXAV_H_VSCHEDULER], OMX_StateLoaded)) { + DBG_PRINT( "DetachVideoRenderer DONE (already state loaded)\n"); + return 0; + } + OMXSAFE(RequestState(pOMXAV->comp[OMXAV_H_VSCHEDULER], OMX_StateIdle, KD_TRUE)); + + DBG_PRINT( "DetachVideoRenderer p1\n"); + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_CLOCK], OMX_CommandPortDisable, PORT_VRENDERER, 0)); + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_VDECODER], OMX_CommandPortDisable, 1, 0)); + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_VSCHEDULER], OMX_CommandPortDisable, 0, 0)); + OMXSAFE(OMX_SendCommand(pOMXAV->comp[OMXAV_H_VSCHEDULER], OMX_CommandPortDisable, 2, 0)); + DBG_PRINT( "DetachVideoRenderer p2\n"); + + for (i = 0; i < pOMXAV->vBufferNum; i++) { + OMXToolImageBuffer_t *pBuf = &pOMXAV->buffers[i]; + + // tell decoder output port to stop using EGLImage + if (NULL!=pBuf->omxBufferHeader) { + OMX_FreeBuffer( + pOMXAV->comp[OMXAV_H_VSCHEDULER], + 1, + pBuf->omxBufferHeader); + pBuf->omxBufferHeader=NULL; + } + } + + OMXSAFE(RequestState(pOMXAV->comp[OMXAV_H_VSCHEDULER], OMX_StateLoaded, KD_TRUE)); + DBG_PRINT( "DetachVideoRenderer p3\n"); + + OMX_FreeHandle(pOMXAV->comp[OMXAV_H_VSCHEDULER]); + pOMXAV->comp[OMXAV_H_VSCHEDULER]=NULL; + DBG_PRINT( "DetachVideoRenderer DONE\n"); + return 0; +} + +OMXToolBasicAV_t * OMXToolBasicAV_CreateInstance(EGLDisplay dpy) +{ + int i; + OMXToolBasicAV_t * pOMXAV = NULL; + InitStatic(); + + pOMXAV = malloc(sizeof(OMXToolBasicAV_t)); + if(NULL==pOMXAV) { + DBG_PRINT( "Init struct failed!\n"); + return NULL; + } + memset(pOMXAV, 0, sizeof(OMXToolBasicAV_t)); + + pOMXAV->dpy = dpy; + + pOMXAV->audioPort=-1; + pOMXAV->videoPort=-1; + + for(i=0; i<OMXAV_H_NUMBER; i++) { + pOMXAV->comp[i] = KD_NULL; + } + + pOMXAV->callbacks.EventHandler = EventHandler; + pOMXAV->callbacks.EmptyBufferDone = EmptyBufferDone; + pOMXAV->callbacks.FillBufferDone = FillBufferDone; + + pOMXAV->mutex = kdThreadMutexCreate(KD_NULL); + pOMXAV->flushSem = kdThreadSemCreate(0); + + pOMXAV->play_speed = 1.0f; + pOMXAV->status=OMXAV_INIT; + + return pOMXAV; +} + +void OMXToolBasicAV_SetStream(OMXToolBasicAV_t * pOMXAV, int vBufferNum, const KDchar * stream) +{ + OMX_ERRORTYPE eError = OMX_ErrorNone; + + DBG_PRINT( "SetStream 1 %s ..\n", stream); + + // FIXME: verify player state .. ie stop ! + if(pOMXAV->status!=OMXAV_INIT) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Player instance in use\n"); + return; + } + if(vBufferNum>EGLIMAGE_MAX_BUFFERS) { + java_throwNewRuntimeException(pOMXAV->jni_env, "buffer number %d > MAX(%d)\n", vBufferNum, EGLIMAGE_MAX_BUFFERS); + return; + } + + kdThreadMutexLock(pOMXAV->mutex); + + DBG_PRINT( "SetStream 3\n"); + + pOMXAV->vBufferNum = vBufferNum; + + // Use the "super parser" :) FIXME: Non NV case .. + eError = OMX_GetHandle(&pOMXAV->comp[OMXAV_H_READER], "OMX.Nvidia.reader", pOMXAV, &pOMXAV->callbacks); + + eError = AddFile(pOMXAV, stream); + if(eError!=OMX_ErrorNone) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Couldn't open or handle stream: %s\n", stream); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + + DBG_PRINT( "SetStream 4\n"); + + // Auto detect codecs + { + OMX_PARAM_PORTDEFINITIONTYPE oPortDef; + INIT_PARAM(oPortDef); + oPortDef.nPortIndex = 0; + pOMXAV->videoPort = -1; + pOMXAV->audioPort = -1; + OMXSAFEVOID(OMX_GetParameter(pOMXAV->comp[OMXAV_H_READER], OMX_IndexParamPortDefinition, &oPortDef)); + + if (oPortDef.eDomain == OMX_PortDomainAudio) + pOMXAV->audioPort = oPortDef.nPortIndex; + else if (oPortDef.eDomain == OMX_PortDomainVideo) + pOMXAV->videoPort = oPortDef.nPortIndex; + else + OMXSAFEVOID(OMX_ErrorNotImplemented); + + INIT_PARAM(oPortDef); + oPortDef.nPortIndex = 1; + if (OMX_GetParameter(pOMXAV->comp[OMXAV_H_READER], OMX_IndexParamPortDefinition, &oPortDef) == OMX_ErrorNone) + { + if (oPortDef.eDomain == OMX_PortDomainAudio) + pOMXAV->audioPort = oPortDef.nPortIndex; + else if (oPortDef.eDomain == OMX_PortDomainVideo) + pOMXAV->videoPort = oPortDef.nPortIndex; + else + OMXSAFEVOID(OMX_ErrorNotImplemented); + } + if (pOMXAV->audioPort != -1) + { + if (ProbePort(pOMXAV, pOMXAV->audioPort, pOMXAV->audioCodec, pOMXAV->audioCodecComponent) != OMX_ErrorNone) + { + printf("disabling audio port\n"); + OMXSAFEVOID(OMX_SendCommand(pOMXAV->comp[OMXAV_H_READER], OMX_CommandPortDisable, pOMXAV->audioPort, 0)); + pOMXAV->audioPort = -1; + } + } + if (pOMXAV->videoPort != -1) + if (ProbePort(pOMXAV, pOMXAV->videoPort, pOMXAV->videoCodec, pOMXAV->videoCodecComponent) != OMX_ErrorNone) + { + printf("disabling video port\n"); + OMXSAFEVOID(OMX_SendCommand(pOMXAV->comp[OMXAV_H_READER], OMX_CommandPortDisable, pOMXAV->videoPort, 0)); + pOMXAV->videoPort = -1; + } + + if (pOMXAV->audioPort == -1 && pOMXAV->videoPort == -1) + { + java_throwNewRuntimeException(pOMXAV->jni_env, "Neither audioport or videoport could be played back!\n"); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + } + DBG_PRINT( "SetStream 5 ; audioPort %d, videoPort %d\n", pOMXAV->audioPort, pOMXAV->videoPort); + + OMXSAFEVOID(OMX_GetHandle(&pOMXAV->comp[OMXAV_H_CLOCK], "OMX.Nvidia.clock.component", pOMXAV, &pOMXAV->callbacks)); + + DBG_PRINT( "Configuring comp[OMXAV_H_CLOCK]\n"); + { + + OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE oActiveClockType; + INIT_PARAM(oActiveClockType); + oActiveClockType.eClock = (pOMXAV->audioPort != -1) ? + OMX_TIME_RefClockAudio : OMX_TIME_RefClockVideo; + OMXSAFEVOID(OMX_SetConfig(pOMXAV->comp[OMXAV_H_CLOCK], OMX_IndexConfigTimeActiveRefClock, + &oActiveClockType)); + } + OMXSAFEVOID(OMX_SendCommand(pOMXAV->comp[OMXAV_H_CLOCK], OMX_CommandPortDisable, (OMX_U32) -1, 0)); + + OMXSAFEVOID(UpdateStreamInfo(pOMXAV, KD_FALSE)); + + kdThreadMutexUnlock(pOMXAV->mutex); + + DBG_PRINT( "SetStream X\n"); +} + +void OMXToolBasicAV_SetStreamEGLImageTexture2D(OMXToolBasicAV_t * pOMXAV, KDint i, GLuint tex, EGLImageKHR image, EGLSyncKHR sync) +{ + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return; + } + DBG_PRINT( "SetStreamEGLImg %p #%d/%d t:%d i:%p s:%p..\n", pOMXAV, i, pOMXAV->vBufferNum, tex, image, sync); + if(i<0||i>=pOMXAV->vBufferNum) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Buffer index out of range: %d\n", i); + return; + } + + kdThreadMutexLock(pOMXAV->mutex); + { + OMXToolImageBuffer_t *pBuf = &pOMXAV->buffers[i]; + pBuf->tex=tex; + pBuf->image=image; + pBuf->sync=sync; + + } + kdThreadMutexUnlock(pOMXAV->mutex); +} + +void OMXToolBasicAV_ActivateStream(OMXToolBasicAV_t * pOMXAV) { + int res; + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return; + } + DBG_PRINT( "ActivateStream 1\n"); + + kdThreadMutexLock(pOMXAV->mutex); + + if (pOMXAV->audioPort != -1) + { + OMXSAFEVOID(OMX_GetHandle(&pOMXAV->comp[OMXAV_H_ADECODER], pOMXAV->audioCodecComponent, pOMXAV, &pOMXAV->callbacks)); + } + + if (pOMXAV->videoPort != -1) + { + OMXSAFEVOID(OMX_GetHandle(&pOMXAV->comp[OMXAV_H_VDECODER], pOMXAV->videoCodecComponent, pOMXAV, &pOMXAV->callbacks)); + } + + // + // mandatory: before SetupTunnel (->Activate), wait until all devices are ready .. + // arender/vrender must wait as well .. + if(0!=(res=OMXToolBasicAV_WaitForState(pOMXAV, OMX_StateLoaded))) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Loaded Failed (%d)", res); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + + if (pOMXAV->audioPort != -1) + { + if(0!=(res=AttachAudioRenderer(pOMXAV))) { + kdThreadMutexUnlock(pOMXAV->mutex); + return; // exception thrown + } + } + + if (pOMXAV->videoPort != -1) + { + if(0!=(res=AttachVideoRenderer(pOMXAV))) { + kdThreadMutexUnlock(pOMXAV->mutex); + return; // exception thrown + } + } + + DBG_PRINT( "Setup tunneling\n"); + { + // do tunneling + if (pOMXAV->audioPort != -1) + { + DBG_PRINT( "Setup tunneling audio\n"); + OMXSAFEVOID(OMX_SetupTunnel(pOMXAV->comp[OMXAV_H_READER], pOMXAV->audioPort, pOMXAV->comp[OMXAV_H_ADECODER], 0)); + // The rest of the audio port is configured in AttachAudioRenderer + } + + if (pOMXAV->videoPort != -1) + { + DBG_PRINT( "Setup tunneling video\n"); + OMXSAFEVOID(OMX_SetupTunnel(pOMXAV->comp[OMXAV_H_READER], pOMXAV->videoPort, pOMXAV->comp[OMXAV_H_VDECODER], 0)); + // The rest of the video port is configured in AttachVideoRenderer + } + } + DBG_PRINT( "ActivateStream .. %p\n", pOMXAV); + + // + // mandatory: wait until all devices are idle + // failure means not all necessary ports/buffer are set. + // + if(0!=(res=OMXToolBasicAV_RequestState(pOMXAV, OMX_StateIdle, KD_TRUE))) + { + java_throwNewRuntimeException(pOMXAV->jni_env, "Wait for Idle Failed (%d)", res); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + pOMXAV->status=OMXAV_STOPPED; + kdThreadMutexUnlock(pOMXAV->mutex); + DBG_PRINT( "ActivateStream done %p\n", pOMXAV); +} + +void OMXToolBasicAV_DetachVideoRenderer(OMXToolBasicAV_t * pOMXAV) { + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return; + } + if(pOMXAV->status<=OMXAV_INIT) { + java_throwNewRuntimeException(pOMXAV->jni_env, "OMX invalid status: %d <= INIT\n", pOMXAV->status); + return; + } + kdThreadMutexLock(pOMXAV->mutex); + + (void) DetachVideoRenderer(pOMXAV); + + kdThreadMutexUnlock(pOMXAV->mutex); +} + +void OMXToolBasicAV_AttachVideoRenderer(OMXToolBasicAV_t * pOMXAV) { + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return; + } + if(pOMXAV->status<=OMXAV_INIT) { + java_throwNewRuntimeException(pOMXAV->jni_env, "OMX invalid status: %d <= INIT\n", pOMXAV->status); + return; + } + kdThreadMutexLock(pOMXAV->mutex); + + (void) AttachVideoRenderer(pOMXAV); + + kdThreadMutexUnlock(pOMXAV->mutex); +} + +void OMXToolBasicAV_SetPlaySpeed(OMXToolBasicAV_t * pOMXAV, KDfloat32 scale) +{ + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return; + } + if(pOMXAV->status<=OMXAV_INIT) { + java_throwNewRuntimeException(pOMXAV->jni_env, "OMX invalid status: %d <= INIT\n", pOMXAV->status); + return; + } + kdThreadMutexLock(pOMXAV->mutex); + + if(!SetClockScale(pOMXAV, scale)) { + pOMXAV->play_speed=scale; + } + + kdThreadMutexUnlock(pOMXAV->mutex); +} + + +void OMXToolBasicAV_PlayStart(OMXToolBasicAV_t * pOMXAV) +{ + int res; + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return; + } + if(pOMXAV->status<=OMXAV_INIT) { + java_throwNewRuntimeException(pOMXAV->jni_env, "OMX invalid status: %d <= INIT\n", pOMXAV->status); + return; + } + if(pOMXAV->status==OMXAV_PLAYING) { + return; + } + + kdThreadMutexLock(pOMXAV->mutex); + DBG_PRINT( "Play 2\n"); + + SetClockScale(pOMXAV, pOMXAV->play_speed); + + DBG_PRINT( "Play 3.1\n"); + if(0!=(res=OMXToolBasicAV_RequestState(pOMXAV, OMX_StateExecuting, KD_TRUE))) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Play Execute Failed (%d)", res); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + if(pOMXAV->status==OMXAV_STOPPED || pOMXAV->status==OMXAV_FIN) { + DBG_PRINT( "Play 3.2\n"); + if(StartClock(pOMXAV, KD_TRUE, 0.0)) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Play StartClock Failed"); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + } + DBG_PRINT( "Play 4.0\n"); + + kdThreadMutexUnlock(pOMXAV->mutex); + pOMXAV->status=OMXAV_PLAYING; + DBG_PRINT( "Play DONE\n"); +} + +static int PlayStop(OMXToolBasicAV_t * pOMXAV) +{ + int res; + if(NULL==pOMXAV || pOMXAV->status<=OMXAV_INIT) { + return -1; + } + if( pOMXAV->status!=OMXAV_PLAYING && pOMXAV->status!=OMXAV_PAUSED ) { + return -1; + } + + if(OMXToolBasicAV_CheckState(pOMXAV, OMX_StateLoaded)) { + if(StartClock(pOMXAV, KD_FALSE, 0.0)) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Stop StopClock Failed"); + kdThreadMutexUnlock(pOMXAV->mutex); + return -1; + } + if(OMXToolBasicAV_CheckState(pOMXAV, OMX_StateIdle)) { + if(0!=(res=OMXToolBasicAV_RequestState(pOMXAV, OMX_StateIdle, KD_TRUE))) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Stop Idle Failed (%d)", res); + kdThreadMutexUnlock(pOMXAV->mutex); + return res; + } + } + } + pOMXAV->status=OMXAV_STOPPED; + return 0; +} + +void OMXToolBasicAV_PlayStop(OMXToolBasicAV_t * pOMXAV) +{ + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return; + } + if(pOMXAV->status<=OMXAV_INIT) { + java_throwNewRuntimeException(pOMXAV->jni_env, "OMX invalid status: %d <= INIT\n", pOMXAV->status); + return; + } + kdThreadMutexLock(pOMXAV->mutex); + + (void) PlayStop(pOMXAV); + + kdThreadMutexUnlock(pOMXAV->mutex); +} + +void OMXToolBasicAV_PlayPause(OMXToolBasicAV_t * pOMXAV) +{ + int res; + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return; + } + if(pOMXAV->status<=OMXAV_INIT) { + java_throwNewRuntimeException(pOMXAV->jni_env, "OMX invalid status: %d <= INIT\n", pOMXAV->status); + return; + } + if(pOMXAV->status==OMXAV_PAUSED || pOMXAV->status!=OMXAV_PLAYING) { + return; + } + + kdThreadMutexLock(pOMXAV->mutex); + SetClockScale(pOMXAV, 0); + if(0!=(res=OMXToolBasicAV_RequestState(pOMXAV, OMX_StatePause, KD_TRUE))) { + fprintf(stderr, "Err: Pause Pause Failed (%d)", res); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + pOMXAV->status=OMXAV_PAUSED; + kdThreadMutexUnlock(pOMXAV->mutex); +} + +void OMXToolBasicAV_PlaySeek(OMXToolBasicAV_t * pOMXAV, KDfloat32 time) +{ + int res; + + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return; + } + if(pOMXAV->status<=OMXAV_INIT) { + java_throwNewRuntimeException(pOMXAV->jni_env, "OMX invalid status: %d <= INIT\n", pOMXAV->status); + return; + } + kdThreadMutexLock(pOMXAV->mutex); + + pOMXAV->length = GetMediaLength(pOMXAV); + if(pOMXAV->length<=time) { + (void) PlayStop(pOMXAV); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + + // 1. Pause the component through the use of OMX_SendCommand requesting a + // state transition to OMX_StatePause. + if(pOMXAV->status!=OMXAV_PAUSED) { + if(0!=(res=OMXToolBasicAV_RequestState(pOMXAV, OMX_StatePause, KD_TRUE))) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Seek Pause Failed (%d)", res); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + } + + // 2. Stop the comp[OMXAV_H_CLOCK] componentÂ’s media comp[OMXAV_H_CLOCK] through the use of OMX_SetConfig + // on OMX_TIME_CONFIG_CLOCKSTATETYPE requesting a transition to + // OMX_TIME_ClockStateStopped. + if(StartClock(pOMXAV, KD_FALSE, 0.0)) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Seek StopClock Failed"); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + + // 3. Seek to the desired location through the use of OMX_SetConfig on + // OMX_IndexConfigTimePosition requesting the desired timestamp. + if(SetMediaPosition(pOMXAV, time)) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Seek position Failed"); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + + // 4. Flush all components. + if(SendCommand(pOMXAV, OMX_CommandFlush, OMX_ALL, 0)) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Seek Flush Failed"); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + + // 5. Start the comp[OMXAV_H_CLOCK] componentÂ’s media comp[OMXAV_H_CLOCK] through the use of OMX_SetConfig + // on OMX_TIME_CONFIG_CLOCKSTATETYPE requesting a transition to either + // OMX_TIME_ClockStateRunning or + // OMX_TIME_ClockStateWaitingForStartTime. + if(StartClock(pOMXAV, KD_TRUE, time)) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Seek StartClock Failed"); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + + // 6. Un-pause the component through the use of OMX_SendCommand requesting a + // state transition to OMX_StateExecuting. + if(pOMXAV->status==OMXAV_PLAYING) { + if(0!=(res=OMXToolBasicAV_RequestState(pOMXAV, OMX_StateExecuting, KD_TRUE))) { + java_throwNewRuntimeException(pOMXAV->jni_env, "Seek Execute Failed (%d)", res); + kdThreadMutexUnlock(pOMXAV->mutex); + return; + } + } + kdThreadMutexUnlock(pOMXAV->mutex); +} + +GLuint OMXToolBasicAV_GetNextTextureID(OMXToolBasicAV_t * pOMXAV) { + GLuint texID = 0; + int ret = pOMXAV->glPos; + kdThreadMutexLock(pOMXAV->mutex); + + if(pOMXAV->status==OMXAV_PLAYING) { + int next = (pOMXAV->omxPos + 1) % pOMXAV->vBufferNum; + + DBG_PRINT2("GetNextTexture A avail %d, filled %d, pos o:%d g:%d\n", + pOMXAV->available, pOMXAV->filled, pOMXAV->omxPos, pOMXAV->glPos); + + while (pOMXAV->filled < pOMXAV->vBufferNum) + { + int attr; + if ( !_hasEGLSync || ( + eglGetSyncAttribKHR(pOMXAV->dpy, pOMXAV->buffers[pOMXAV->omxPos].sync, EGL_SYNC_STATUS_KHR, &attr) && + attr == EGL_SIGNALED_KHR ) + ) + { + DBG_PRINT2( "GetNextTexture p2.1 attr 0x%X\n", attr); + // OpenGL has finished rendering with this texture, so we are free + // to make OpenMAX IL fill it with new data. + OMX_FillThisBuffer(pOMXAV->comp[OMXAV_H_VSCHEDULER], pOMXAV->buffers[pOMXAV->omxPos].omxBufferHeader); + DBG_PRINT2( "GetNextTexture p2.2\n"); + pOMXAV->omxPos = next; + next = (pOMXAV->omxPos + 1) % pOMXAV->vBufferNum; + pOMXAV->filled++; + } + else + { + DBG_PRINT2( "GetNextTexture p2.3\n"); + break; + } + } + } + if (pOMXAV->available > 1) + { + DBG_PRINT2("GetNextTexture p3.1\n"); + // We want to make sure that the previous eglImage + // has finished, so insert a fence command into the + // command stream to make sure that any rendering using + // the previous eglImage has finished. + // + // Only move on to rendering the next image if the insertion + // was successfull. + if (!_hasEGLSync || eglSignalSyncKHR(pOMXAV->dpy, pOMXAV->buffers[pOMXAV->glPos].sync, EGL_UNSIGNALED_KHR)) + { + DBG_PRINT2( "GetNextTexture p3.2\n"); + pOMXAV->available--; + pOMXAV->filled--; + pOMXAV->glPos = (pOMXAV->glPos + 1) % pOMXAV->vBufferNum; + ret = pOMXAV->glPos; + } + } + + texID = pOMXAV->available ? pOMXAV->buffers[ret].tex : 0; + DBG_PRINT2( "GetNextTexture B avail %d, filled %d, pos o:%d g:%d t:%d\n", + pOMXAV->available, pOMXAV->filled, pOMXAV->omxPos, pOMXAV->glPos, texID); + + kdThreadMutexUnlock(pOMXAV->mutex); + return texID; +} + +KDfloat32 OMXToolBasicAV_GetCurrentPosition(OMXToolBasicAV_t * pOMXAV) { + KDfloat32 res = -1.0f; + if(NULL==pOMXAV) { + java_throwNewRuntimeException(0, "OMX instance null\n"); + return res; + } + if(pOMXAV->status<=OMXAV_INIT) { + java_throwNewRuntimeException(pOMXAV->jni_env, "OMX invalid status: %d <= INIT\n", pOMXAV->status); + return res; + } + kdThreadMutexLock(pOMXAV->mutex); + + res = GetClockPosition(pOMXAV); + + kdThreadMutexUnlock(pOMXAV->mutex); + + return res; +} + +void OMXToolBasicAV_DestroyInstance(OMXToolBasicAV_t * pOMXAV) +{ + if(NULL==pOMXAV) return; + + kdThreadMutexLock(pOMXAV->mutex); + DestroyInstanceUnlock(pOMXAV); +} + +#if defined(SELF_TEST) + +#include <KD/NV_extwindowprops.h> + +static PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; + +int ModuleTest() +{ + int i; + OMXToolBasicAV_t * pOMXAV = NULL; + GLuint tex; EGLImageKHR image; EGLSyncKHR sync; + KDchar file[512]; + EGLint attrib = EGL_NONE; + +#if 0 + const EGLint s_configAttribs[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_ALPHA_SIZE, EGL_DONT_CARE, + EGL_DEPTH_SIZE, 1, + EGL_STENCIL_SIZE, EGL_DONT_CARE, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE + }; +#else + const EGLint s_configAttribs[] = { + EGL_RED_SIZE, 5, + EGL_GREEN_SIZE, 6, + EGL_BLUE_SIZE, 5, + EGL_ALPHA_SIZE, EGL_DONT_CARE, + EGL_DEPTH_SIZE, 16, + EGL_STENCIL_SIZE, EGL_DONT_CARE, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE + }; +#endif + + const EGLint contextAttrs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + + EGLint numConfigs; + EGLint majorVersion; + EGLint minorVersion; + + EGLint sWidth, sHeight; + + EGLDisplay eglDisplay; + EGLConfig eglConfig; + EGLContext eglContext; + EGLSurface eglWindowSurface; + KDWindow *kdWindow; + NativeWindowType ntWindow; + +// KDint wSize[2]; + + /* + * EGL initialisation. + */ + + eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(eglDisplay, &majorVersion, &minorVersion); + eglChooseConfig(eglDisplay, s_configAttribs, &eglConfig, 1, &numConfigs); + kdWindow = kdCreateWindow(eglDisplay, eglConfig, KD_NULL); + + { + /* Set fullscreen mode */ + KDboolean fullscreen = KD_TRUE; + kdSetWindowPropertybv(kdWindow, + KD_WINDOWPROPERTY_FULLSCREEN_NV, &fullscreen); + } + + kdRealizeWindow(kdWindow, &ntWindow); + + eglContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, contextAttrs); + + eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglConfig, ntWindow, KD_NULL); + eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, eglContext); + + printf("EGL Extensions : %s\n",eglQueryString(eglDisplay, EGL_EXTENSIONS)); + printf("EGL CLIENT APIs: %s\n",eglQueryString(eglDisplay, EGL_CLIENT_APIS)); + + eglQuerySurface(eglDisplay, eglWindowSurface, EGL_WIDTH , &sWidth); + eglQuerySurface(eglDisplay, eglWindowSurface, EGL_HEIGHT , &sHeight); + + /* Set up the viewport and perspective. */ + printf("screen dim %dx%d\n", sWidth, sHeight); + glViewport(0, 0, sWidth, sHeight); + + /* + if (argc == 2) + kdStrcpy_s(file, 512, argv[1]); + else */ + kdStrcpy_s(file, 512, "/Storage Card/resources/videoplayer/Luna_800x480_1_5M_H264.mp4"); + + if( OMXToolBasicAV_IsFileValid(file) ) { + fprintf(stderr, "File is invalid"); + return -1; + } + + GETEXTENSION(PFNEGLDESTROYIMAGEKHRPROC, eglDestroyImageKHR); + + pOMXAV = OMXToolBasicAV_CreateInstance(eglDisplay); + if(OMXToolBasicAV_SetStream(pOMXAV, file)) { + return -1; + } + printf("movie dim %dx%d\n", pOMXAV->width, pOMXAV->height); + + glActiveTexture(GL_TEXTURE0); + printf("i1: 0x%X\n", glGetError()); + glEnable(GL_TEXTURE_2D); + printf("i2: 0x%X\n", glGetError()); + + for (i = 0; i < 3; i++) + { + printf("0: 0x%X\n", glGetError()); + glGenTextures(1, &tex); + printf("1: tex: %d, e 0x%X\n", tex, glGetError()); + glBindTexture(GL_TEXTURE_2D, tex); + printf("2: 0x%X\n", glGetError()); + + // create space for buffer with a texture + glTexImage2D( + GL_TEXTURE_2D, // target + 0, // level + GL_RGBA, // internal format + pOMXAV->width, // width + pOMXAV->height, // height + 0, // border + GL_RGBA, // format + GL_UNSIGNED_BYTE, // type + NULL); // pixels -- will be provided later + printf("3: 0x%X\n", glGetError()); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + printf("4: 0x%X\n", glGetError()); + + // create EGLImage from texture + image = eglCreateImageKHR( + eglDisplay, + eglContext, + EGL_GL_TEXTURE_2D_KHR, + (EGLClientBuffer)(tex), + &attrib); + if (!image) + { + printf("eglGetError: 0x%x\n", eglGetError()); + printf("ERROR creating EglImage\n"); + return -1; + } + printf("5 eglGetError: 0x%x\n", eglGetError()); + + sync = eglCreateSyncKHR( + eglDisplay, EGL_SYNC_FENCE_KHR, &attrib); + + printf("6 eglGetError: 0x%x\n", eglGetError()); + + if(OMXToolBasicAV_SetStreamEGLImageTexture2D(pOMXAV, i, tex, image, sync)) { + return -1; + } + } + + printf("7\n"); + if( OMXToolBasicAV_ActivateStream(eglDisplay, pOMXAV) ) { + return -1; + } + + printf("8\n"); + if( OMXToolBasicAV_PlayStart(eglDisplay, pOMXAV) ) { + return -1; + } + + printf("8.2\n"); + + i = 0; + while (i++ < 10) { + glClear(GL_COLOR_BUFFER_BIT); + // set uniforms + // set attributes + // draw arrays .. + eglSwapBuffers(eglDisplay, eglWindowSurface); + printf("Sleep %d\n", i); + usleep(1000); + } + + printf("9\n"); + if( OMXToolBasicAV_PlayStop(eglDisplay, pOMXAV) ) { + fprintf(stderr, "Err: Stop"); + return -1; + } + printf("A1\n"); + OMXToolBasicAV_DetachVideoRenderer(eglDisplay, pOMXAV); // Stop before .. + + printf("A2\n"); + OMXToolBasicAV_AttachVideoRenderer(eglDisplay, pOMXAV); // DetachVideoRenderer before .. + + printf("B\n"); + OMXToolBasicAV_DestroyInstance(eglDisplay, pOMXAV); + + printf("C\n"); + eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroySurface(eglDisplay, eglWindowSurface); + eglDestroyContext(eglDisplay, eglContext); + + printf("D\n"); + kdDestroyWindow(kdWindow); + + printf("E\n"); + eglTerminate(eglDisplay); + printf("F\n"); + eglReleaseThread(); + + return 0; +} + +KDint kdMain(KDint argc, const KDchar *const *argv) +// int main(int argc, const char *const *argv) +{ + return ModuleTest(); +} +#endif + diff --git a/src/jogl/native/openmax/omx_tool.h b/src/jogl/native/openmax/omx_tool.h new file mode 100644 index 000000000..dbc375dd7 --- /dev/null +++ b/src/jogl/native/openmax/omx_tool.h @@ -0,0 +1,168 @@ +/** + * Uses the EGL Extensions: EGL_KHR_reusable_sync and EGL_KHR_fence_sync + */ + +#ifndef _OMX_TOOL_H +#define _OMX_TOOL_H + +#ifdef _WIN32 + #include <windows.h> + // __declspec(dllimport) void __stdcall Sleep(unsigned long dwMilliseconds); + + #define usleep(t) Sleep((t) / 1000) + + #ifdef _MSC_VER + /* This typedef is apparently needed for Microsoft compilers before VC8, + and on Windows CE */ + #if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1400 ) + #ifdef _WIN64 + typedef long long intptr_t; + #else + typedef int intptr_t; + #endif + #endif + #else + #include <inttypes.h> + #endif +#else + #include <unistd.h> + #include <inttypes.h> +#endif + +#include <OMX_Core.h> +#include <OMX_Component.h> +#include <OMX_Index.h> + +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> +#include <EGL/egl.h> +#include <EGL/eglext.h> +#include <KD/kd.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define EGLIMAGE_MAX_BUFFERS 4 + +extern int USE_OPENGL; +extern int USE_HWAUDIOOUT; +extern int USE_AUDIOBUFFERING; +extern const int PORT_VRENDERER; + +typedef struct { + EGLSyncKHR sync; + EGLImageKHR image; + GLuint tex; + OMX_BUFFERHEADERTYPE *omxBufferHeader; +} OMXToolImageBuffer_t; + +typedef enum +{ + OMXAV_INVALID=0, + OMXAV_INIT, + OMXAV_STOPPED, + OMXAV_PLAYING, + OMXAV_PAUSED, + OMXAV_FIN, +} OMXToolStatus; + +typedef enum +{ + OMXAV_H_READER=0, + OMXAV_H_CLOCK, + OMXAV_H_ADECODER, + OMXAV_H_ABUFFERING, + OMXAV_H_ARENDERER, + OMXAV_H_VDECODER, + OMXAV_H_VRENDERER, + OMXAV_H_VSCHEDULER, + OMXAV_H_NUMBER, +} OMXToolHandleIdx; + + +typedef struct { + EGLDisplay dpy; + OMX_VERSIONTYPE version; + OMX_HANDLETYPE comp[OMXAV_H_NUMBER]; + OMX_HANDLETYPE endComponent; + OMX_CALLBACKTYPE callbacks; + + KDchar audioCodec[256]; + KDchar audioCodecComponent[256]; + KDchar videoCodec[256]; + KDchar videoCodecComponent[256]; + int audioPort; + int videoPort; + KDuint32 width; + KDuint32 height; + KDuint32 bitrate; // per seconds + KDuint32 framerate; // per seconds + KDfloat32 length; // seconds + KDfloat32 speed; // current clock scale + KDfloat32 play_speed; // current play clock scale + + KDThreadMutex * mutex; + KDThreadSem * flushSem; + + OMXToolImageBuffer_t buffers[EGLIMAGE_MAX_BUFFERS]; + int vBufferNum; + int glPos; + int omxPos; + int filled; + int available; + + int status; + + intptr_t jni_env; + intptr_t jni_instance; + intptr_t jni_mid_saveAttributes; + intptr_t jni_mid_attributesUpdated; + intptr_t jni_fid_width; + intptr_t jni_fid_height; + intptr_t jni_fid_fps; + intptr_t jni_fid_bps; + intptr_t jni_fid_totalFrames; + intptr_t jni_fid_acodec; + intptr_t jni_fid_vcodec; +} OMXToolBasicAV_t ; + +// +// more internal stuff .. +// +KDint OMXToolBasicAV_IsFileValid(const KDchar * file); + +// +// OMX state control .. +// +KDint OMXToolBasicAV_CheckState(OMXToolBasicAV_t * pOMXAV, OMX_STATETYPE state); +KDint OMXToolBasicAV_SetState(OMXToolBasicAV_t * pOMXAV, OMX_STATETYPE state, KDboolean wait); + +// +// User related functionality, mutex managed +// +OMXToolBasicAV_t * OMXToolBasicAV_CreateInstance(EGLDisplay dpy); // #1 +void OMXToolBasicAV_SetStream(OMXToolBasicAV_t * pOMXAV, int vBufferNum, const KDchar * stream); // #2 +void OMXToolBasicAV_SetStreamEGLImageTexture2D(OMXToolBasicAV_t * pOMXAV, KDint i, GLuint tex, EGLImageKHR image, EGLSyncKHR sync); // #3 +void OMXToolBasicAV_ActivateStream(OMXToolBasicAV_t * pOMXAV); // #4 + +void OMXToolBasicAV_AttachVideoRenderer(OMXToolBasicAV_t * pOMXAV); // Stop, DetachVideoRenderer, SetEGLImageTexture2D .. before .. +void OMXToolBasicAV_DetachVideoRenderer(OMXToolBasicAV_t * pOMXAV); // Stop before .. + +void OMXToolBasicAV_SetPlaySpeed(OMXToolBasicAV_t * pOMXAV, KDfloat32 scale); +void OMXToolBasicAV_PlayStart(OMXToolBasicAV_t * pOMXAV); // #5 +void OMXToolBasicAV_PlayPause(OMXToolBasicAV_t * pOMXAV); +void OMXToolBasicAV_PlayStop(OMXToolBasicAV_t * pOMXAV); +void OMXToolBasicAV_PlaySeek(OMXToolBasicAV_t * pOMXAV, KDfloat32 time); +GLuint OMXToolBasicAV_GetNextTextureID(OMXToolBasicAV_t * pOMXAV); + +KDfloat32 OMXToolBasicAV_GetCurrentPosition(OMXToolBasicAV_t * pOMXAV); + +void OMXToolBasicAV_DestroyInstance(OMXToolBasicAV_t * pOMXAV); + +#if defined(SELF_TEST) + int ModuleTest(); +#endif + +#endif /* _OMX_TOOL_H */ + diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowVersion.java b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowVersion.java new file mode 100644 index 000000000..38bd70a90 --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowVersion.java @@ -0,0 +1,62 @@ +/** + * 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.nativewindow; + +import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.util.JogampVersion; +import com.jogamp.common.util.VersionUtil; +import java.util.jar.Manifest; + +public class NativeWindowVersion extends JogampVersion { + + protected static volatile NativeWindowVersion jogampCommonVersionInfo; + + protected NativeWindowVersion(String packageName, Manifest mf) { + super(packageName, mf); + } + + public static NativeWindowVersion getInstance() { + if(null == jogampCommonVersionInfo) { // volatile: ok + synchronized(NativeWindowVersion.class) { + if( null == jogampCommonVersionInfo ) { + final String packageName = "javax.media.nativewindow"; + final Manifest mf = VersionUtil.getManifest(NativeWindowVersion.class.getClassLoader(), packageName); + jogampCommonVersionInfo = new NativeWindowVersion(packageName, mf); + } + } + } + return jogampCommonVersionInfo; + } + + public static void main(String args[]) { + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(GlueGenVersion.getInstance()); + System.err.println(NativeWindowVersion.getInstance()); + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java new file mode 100644 index 000000000..784343c5a --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +/** A marker interface describing a graphics configuration, visual, or + pixel format in a toolkit-independent manner. */ + +public interface AbstractGraphicsConfiguration extends Cloneable { + /** + * Return the screen this graphics configuration is valid for + */ + public AbstractGraphicsScreen getScreen(); + + /** + * Return the capabilities reflecting this graphics configuration, + * which may differ from the capabilites used to choose this configuration. + * + * @return An immutable instance of the Capabilities to avoid mutation by + * the user. + */ + public CapabilitiesImmutable getChosenCapabilities(); + + /** + * Return the capabilities used to choose this graphics configuration. + * + * These may be used to reconfigure the NativeWindow in case + * the device changes in a multi screen environment. + * + * @return An immutable instance of the Capabilities to avoid mutation by + * the user. + */ + public CapabilitiesImmutable getRequestedCapabilities(); + + /** + * In case this instance already reflects a native configuration, + * return this one. + * Otherwise return the encapsuled native configuration, + * as it shall be included e.g. in the AWT case. + */ + public AbstractGraphicsConfiguration getNativeGraphicsConfiguration(); +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java new file mode 100644 index 000000000..83b437612 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +/** A interface describing a graphics device in a + toolkit-independent manner. + */ + +public interface AbstractGraphicsDevice extends Cloneable { + /** Dummy connection value for a default connection where no native support for multiple devices is available */ + public static String DEFAULT_CONNECTION = "decon"; + + /** Dummy connection value for an external connection where no native support for multiple devices is available */ + public static String EXTERNAL_CONNECTION = "excon"; + + /** Default unit id for the 1st device: 0 */ + public static int DEFAULT_UNIT = 0; + + /** + * Returns the type of the underlying subsystem, ie + * NativeWindowFactory.TYPE_KD, NativeWindowFactory.TYPE_X11, .. + */ + public String getType(); + + /** + * Returns the semantic GraphicsDevice connection.<br> + * On platforms supporting remote devices, eg via tcp/ip network, + * the implementation shall return a unique name for each remote address.<br> + * On X11 for example, the connection string should be as the following example.<br> + * <ul> + * <li><code>:0.0</code> for a local connection</li> + * <li><code>remote.host.net:0.0</code> for a remote connection</li> + * </ul> + * + * To support multiple local device, see {@link #getUnitID()}. + */ + public String getConnection(); + + /** + * Returns the graphics device <code>unit ID</code>.<br> + * The <code>unit ID</code> support multiple graphics device configurations + * on a local machine.<br> + * To support remote device, see {@link #getConnection()}. + * @return + */ + public int getUnitID(); + + /** + * Returns a unique ID String of this device using {@link #getType() type}, + * {@link #getConnection() connection} and {@link #getUnitID() unitID}.<br> + * The unique ID does not reflect the instance of the device, hence the handle is not included.<br> + * The unique ID may be used as a key for semantic device mapping. + */ + public String getUniqueID(); + + /** + * Returns the native handle of the underlying native device, + * if such thing exist. + */ + public long getHandle(); + + /** + * Optionally locking the device, utilizing eg {@link javax.media.nativewindow.ToolkitLock}. + * The lock implementation must be recursive. + */ + public void lock(); + + /** + * Optionally unlocking the device, utilizing eg {@link javax.media.nativewindow.ToolkitLock}. + * The lock implementation must be recursive. + */ + public void unlock(); + + /** + * Optionally closing the device.<br> + * The default implementation is a NOP operation, returning false.<br> + * The specific implementing, ie {@link javax.media.nativewindow.x11.X11GraphicsDevice}, + * shall have a enable/disable like {@link javax.media.nativewindow.x11.X11GraphicsDevice#setCloseDisplay(boolean, boolean)},<br> + * which shall be invoked at creation time to determine ownership/role of freeing the resource.<br> + * + * @return true if a specialized closing operation was successfully issued, otherwise false, + * ie no native closing operation was issued, which doesn't imply an error at all. + */ + public boolean close(); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java new file mode 100644 index 000000000..eb2cc9120 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +/** A interface describing a graphics screen in a + toolkit-independent manner. + */ + +public interface AbstractGraphicsScreen extends Cloneable { + /** + * Return the device this graphics configuration is valid for + */ + public AbstractGraphicsDevice getDevice(); + + /** Returns the screen index this graphics screen is valid for + */ + public int getIndex(); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java new file mode 100644 index 000000000..79d69c703 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java @@ -0,0 +1,328 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +/** Specifies a set of capabilities that a window's rendering context + must support, such as color depth per channel. It currently + contains the minimal number of routines which allow configuration + on all supported window systems. */ +public class Capabilities implements CapabilitiesImmutable, Cloneable, Comparable { + private int redBits = 8; + private int greenBits = 8; + private int blueBits = 8; + private int alphaBits = 0; + + // Support for transparent windows containing OpenGL content + private boolean backgroundOpaque = true; + private int transparentValueRed = -1; + private int transparentValueGreen = -1; + private int transparentValueBlue = -1; + private int transparentValueAlpha = -1; + + // Switch for on- or offscreen + private boolean onscreen = true; + + /** Creates a Capabilities object. All attributes are in a default + state. + */ + public Capabilities() {} + + public Object cloneMutable() { + return clone(); + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new NativeWindowException(e); + } + } + + public int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + this.redBits; + hash = ((hash << 5) - hash) + this.greenBits; + hash = ((hash << 5) - hash) + this.blueBits; + hash = ((hash << 5) - hash) + this.alphaBits; + hash = ((hash << 5) - hash) + ( this.backgroundOpaque ? 1 : 0 ); + hash = ((hash << 5) - hash) + this.transparentValueRed; + hash = ((hash << 5) - hash) + this.transparentValueGreen; + hash = ((hash << 5) - hash) + this.transparentValueBlue; + hash = ((hash << 5) - hash) + this.transparentValueAlpha; + hash = ((hash << 5) - hash) + ( this.onscreen ? 1 : 0 ); + return hash; + } + + public boolean equals(Object obj) { + if(this == obj) { return true; } + if(!(obj instanceof CapabilitiesImmutable)) { + return false; + } + CapabilitiesImmutable other = (CapabilitiesImmutable)obj; + boolean res = other.getRedBits()==redBits && + other.getGreenBits()==greenBits && + other.getBlueBits()==blueBits && + other.getAlphaBits()==alphaBits && + other.isBackgroundOpaque()==backgroundOpaque && + other.isOnscreen()==onscreen; + if(!backgroundOpaque) { + res = res && other.getTransparentRedValue()==transparentValueRed && + other.getTransparentGreenValue()==transparentValueGreen && + other.getTransparentBlueValue()==transparentValueBlue && + other.getTransparentAlphaValue()==transparentValueAlpha; + } + + return res; + } + + /** comparing RGBA values only */ + public int compareTo(Object o) { + if ( ! ( o instanceof Capabilities ) ) { + Class c = (null != o) ? o.getClass() : null ; + throw new ClassCastException("Not a Capabilities object: " + c); + } + + final Capabilities caps = (Capabilities) o; + + final int a = ( alphaBits > 0 ) ? alphaBits : 1; + final int rgba = redBits * greenBits * blueBits * a; + + final int xa = ( caps.alphaBits ) > 0 ? caps.alphaBits : 1; + final int xrgba = caps.redBits * caps.greenBits * caps.blueBits * xa; + + if(rgba > xrgba) { + return 1; + } else if(rgba < xrgba) { + return -1; + } + + return 0; // they are equal: RGBA + } + + /** Returns the number of bits requested for the color buffer's red + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public int getRedBits() { + return redBits; + } + + /** Sets the number of bits requested for the color buffer's red + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public void setRedBits(int redBits) { + this.redBits = redBits; + } + + /** Returns the number of bits requested for the color buffer's + green component. On some systems only the color depth, which is + the sum of the red, green, and blue bits, is considered. */ + public int getGreenBits() { + return greenBits; + } + + /** Sets the number of bits requested for the color buffer's green + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public void setGreenBits(int greenBits) { + this.greenBits = greenBits; + } + + /** Returns the number of bits requested for the color buffer's blue + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public int getBlueBits() { + return blueBits; + } + + /** Sets the number of bits requested for the color buffer's blue + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public void setBlueBits(int blueBits) { + this.blueBits = blueBits; + } + + /** Returns the number of bits requested for the color buffer's + alpha component. On some systems only the color depth, which is + the sum of the red, green, and blue bits, is considered. */ + public int getAlphaBits() { + return alphaBits; + } + + /** Sets the number of bits requested for the color buffer's alpha + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public void setAlphaBits(int alphaBits) { + this.alphaBits = alphaBits; + } + + /** For on-screen OpenGL contexts on some platforms, sets whether + the background of the context should be considered opaque. On + supported platforms, setting this to false, in conjunction with + the transparency values, may allow + hardware-accelerated OpenGL content inside of windows of + arbitrary shape. To achieve this effect it is necessary to use + an OpenGL clear color with an alpha less than 1.0. The default + value for this flag is <code>true</code>; setting it to false + may incur a certain performance penalty, so it is not + recommended to arbitrarily set it to false.<br> + If not set already, the transparency values for red, green, blue and alpha + are set to their default value, which is half of the value range + of the framebuffer's corresponding component, + ie <code> redValue = ( 1 << ( redBits - 1 ) ) -1 </code>. + */ + public void setBackgroundOpaque(boolean opaque) { + backgroundOpaque = opaque; + if(!opaque) { + if(transparentValueRed<0) + transparentValueRed = ( 1 << ( getRedBits() - 1 ) ) - 1 ; + if(transparentValueGreen<0) + transparentValueGreen = ( 1 << ( getGreenBits() - 1 ) ) - 1 ; + if(transparentValueBlue<0) + transparentValueBlue = ( 1 << ( getBlueBits() - 1 ) ) - 1 ; + if(transparentValueAlpha<0) + transparentValueAlpha = ( 1 << ( getAlphaBits() - 1 ) ) - 1 ; + } + } + + /** Indicates whether the background of this OpenGL context should + be considered opaque. Defaults to true. + + @see #setBackgroundOpaque + */ + public boolean isBackgroundOpaque() { + return backgroundOpaque; + } + + /** Sets whether the drawable surface supports onscreen. + Defaults to true. + */ + public void setOnscreen(boolean onscreen) { + this.onscreen=onscreen; + } + + /** Indicates whether the drawable surface is onscreen. + Defaults to true. + */ + public boolean isOnscreen() { + return onscreen; + } + + /** Gets the transparent red value for the frame buffer configuration. + * This value is undefined if {@link #isBackgroundOpaque()} equals true. + * @see #setTransparentRedValue + */ + public int getTransparentRedValue() { return transparentValueRed; } + + /** Gets the transparent green value for the frame buffer configuration. + * This value is undefined if {@link #isBackgroundOpaque()} equals true. + * @see #setTransparentGreenValue + */ + public int getTransparentGreenValue() { return transparentValueGreen; } + + /** Gets the transparent blue value for the frame buffer configuration. + * This value is undefined if {@link #isBackgroundOpaque()} equals true. + * @see #setTransparentBlueValue + */ + public int getTransparentBlueValue() { return transparentValueBlue; } + + /** Gets the transparent alpha value for the frame buffer configuration. + * This value is undefined if {@link #isBackgroundOpaque()} equals true. + * @see #setTransparentAlphaValue + */ + public int getTransparentAlphaValue() { return transparentValueAlpha; } + + /** Sets the transparent red value for the frame buffer configuration, + ranging from 0 to the maximum frame buffer value for red. + This value is ignored if {@link #isBackgroundOpaque()} equals true.<br> + It defaults to half of the frambuffer value for red. <br> + A value of -1 is interpreted as any value. */ + public void setTransparentRedValue(int transValueRed) { transparentValueRed=transValueRed; } + + /** Sets the transparent green value for the frame buffer configuration, + ranging from 0 to the maximum frame buffer value for green. + This value is ignored if {@link #isBackgroundOpaque()} equals true.<br> + It defaults to half of the frambuffer value for green.<br> + A value of -1 is interpreted as any value. */ + public void setTransparentGreenValue(int transValueGreen) { transparentValueGreen=transValueGreen; } + + /** Sets the transparent blue value for the frame buffer configuration, + ranging from 0 to the maximum frame buffer value for blue. + This value is ignored if {@link #isBackgroundOpaque()} equals true.<br> + It defaults to half of the frambuffer value for blue.<br> + A value of -1 is interpreted as any value. */ + public void setTransparentBlueValue(int transValueBlue) { transparentValueBlue=transValueBlue; } + + /** Sets the transparent alpha value for the frame buffer configuration, + ranging from 0 to the maximum frame buffer value for alpha. + This value is ignored if {@link #isBackgroundOpaque()} equals true.<br> + It defaults to half of the frambuffer value for alpha.<br> + A value of -1 is interpreted as any value. */ + public void setTransparentAlphaValue(int transValueAlpha) { transparentValueAlpha=transValueAlpha; } + + public StringBuffer toString(StringBuffer sink) { + if(null == sink) { + sink = new StringBuffer(); + } + if(onscreen) { + sink.append("on-scr"); + } else { + sink.append("offscr"); + } + sink.append(", rgba ").append(redBits).append("/").append(greenBits).append("/").append(blueBits).append("/").append(alphaBits); + if(backgroundOpaque) { + sink.append(", opaque"); + } else { + sink.append(", trans-rgba 0x").append(Integer.toHexString(transparentValueRed)).append("/").append(Integer.toHexString(transparentValueGreen)).append("/").append(Integer.toHexString(transparentValueBlue)).append("/").append(Integer.toHexString(transparentValueAlpha)); + } + return sink; + } + + /** Returns a textual representation of this Capabilities + object. */ + public String toString() { + StringBuffer msg = new StringBuffer(); + msg.append("Caps["); + toString(msg); + msg.append("]"); + return msg.toString(); + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java new file mode 100644 index 000000000..a306363dc --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +import java.util.List; + +/** Provides a mechanism by which applications can customize the + window type selection for a given {@link Capabilities}. + Developers can implement this interface and pass an instance into + the method {@link GraphicsConfigurationFactory#chooseGraphicsConfiguration}; the chooser + will be called at window creation time. */ + +public interface CapabilitiesChooser { + /** Chooses the index (0..available.length - 1) of the {@link + Capabilities} most closely matching the desired one from the + list of all supported. Some of the entries in the + <code>available</code> array may be null; the chooser must + ignore these. The <em>windowSystemRecommendedChoice</em> + parameter may be provided to the chooser by the underlying + window system; if this index is valid, it is recommended, but + not necessarily required, that the chooser select that entry. + + <P> <em>Note:</em> this method is called automatically by the + {@link GraphicsConfigurationFactory#chooseGraphicsConfiguration} method + when an instance of this class is passed in to it. + It should generally not be + invoked by users directly, unless it is desired to delegate the + choice to some other CapabilitiesChooser object. + */ + public int chooseCapabilities(CapabilitiesImmutable desired, + List /*<CapabilitiesImmutable>*/ available, + int windowSystemRecommendedChoice); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java new file mode 100644 index 000000000..8fb704bad --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.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 javax.media.nativewindow; + +import com.jogamp.common.type.WriteCloneable; + +/** + * Specifies an immutable set of capabilities that a window's rendering context + * must support, such as color depth per channel. + * + * @see javax.media.nativewindow.Capabilities + */ +public interface CapabilitiesImmutable extends WriteCloneable { + + /** + * Returns the number of bits requested for the color buffer's red + * component. On some systems only the color depth, which is the sum of the + * red, green, and blue bits, is considered. + */ + int getRedBits(); + + /** + * Returns the number of bits requested for the color buffer's green + * component. On some systems only the color depth, which is the sum of the + * red, green, and blue bits, is considered. + */ + int getGreenBits(); + + /** + * Returns the number of bits requested for the color buffer's blue + * component. On some systems only the color depth, which is the sum of the + * red, green, and blue bits, is considered. + */ + int getBlueBits(); + + /** + * Returns the number of bits requested for the color buffer's alpha + * component. On some systems only the color depth, which is the sum of the + * red, green, and blue bits, is considered. + */ + int getAlphaBits(); + + /** + * Indicates whether the background of this OpenGL context should be + * considered opaque. Defaults to true. + */ + boolean isBackgroundOpaque(); + + /** + * Indicates whether the drawable surface is onscreen. Defaults to true. + */ + boolean isOnscreen(); + + /** + * Gets the transparent red value for the frame buffer configuration. This + * value is undefined if; equals true. + */ + int getTransparentRedValue(); + + /** + * Gets the transparent green value for the frame buffer configuration. This + * value is undefined if; equals true. + */ + int getTransparentGreenValue(); + + /** + * Gets the transparent blue value for the frame buffer configuration. This + * value is undefined if; equals true. + */ + int getTransparentBlueValue(); + + /** + * Gets the transparent alpha value for the frame buffer configuration. This + * value is undefined if; equals true. + */ + int getTransparentAlphaValue(); + + Object cloneMutable(); + + /** Equality over the immutable attributes of both objects */ + @Override + boolean equals(Object obj); + + /** hash code over the immutable attributes of both objects */ + @Override + int hashCode(); + + /** Return a textual representation of this object. Use the given StringBuffer [optional]. */ + StringBuffer toString(StringBuffer sink); + + /** Returns a textual representation of this object. */ + @Override + String toString(); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java new file mode 100644 index 000000000..b43db8292 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +import java.util.List; + +/** <P> The default implementation of the {@link + CapabilitiesChooser} interface, which provides consistent visual + selection behavior across platforms. The precise algorithm is + deliberately left loosely specified. Some properties are: </P> + + <LI> Attempts to match as closely as possible the given + Capabilities, but will select one with fewer capabilities (i.e., + lower color depth) if necessary. + + <LI> If there is no exact match, prefers a more-capable visual to + a less-capable one. + + <LI> If there is more than one exact match, chooses an arbitrary + one. + + <LI> If a valid windowSystemRecommendedChoice parameter is + supplied, chooses that instead of using the cross-platform code. + + </UL> +*/ + +public class DefaultCapabilitiesChooser implements CapabilitiesChooser { + private static final boolean DEBUG = false; // FIXME: Debug.debug("DefaultCapabilitiesChooser"); + + public int chooseCapabilities(final CapabilitiesImmutable desired, + final List /*<CapabilitiesImmutable>*/ available, + final int windowSystemRecommendedChoice) { + if (DEBUG) { + System.err.println("Desired: " + desired); + for (int i = 0; i < available.size(); i++) { + System.err.println("Available " + i + ": " + available.get(i)); + } + System.err.println("Window system's recommended choice: " + windowSystemRecommendedChoice); + } + final int availnum = available.size(); + + if (windowSystemRecommendedChoice >= 0 && + windowSystemRecommendedChoice < availnum && + null != available.get(windowSystemRecommendedChoice)) { + if (DEBUG) { + System.err.println("Choosing window system's recommended choice of " + windowSystemRecommendedChoice); + System.err.println(available.get(windowSystemRecommendedChoice)); + } + return windowSystemRecommendedChoice; + } + + // Create score array + int[] scores = new int[availnum]; + int NO_SCORE = -9999999; + int COLOR_MISMATCH_PENALTY_SCALE = 36; + for (int i = 0; i < availnum; i++) { + scores[i] = NO_SCORE; + } + // Compute score for each + for (int i = 0; i < availnum; i++) { + CapabilitiesImmutable cur = (CapabilitiesImmutable) available.get(i); + if (cur == null) { + continue; + } + int score = 0; + // Compute difference in color depth + score += (COLOR_MISMATCH_PENALTY_SCALE * + ((cur.getRedBits() + cur.getGreenBits() + cur.getBlueBits() + cur.getAlphaBits()) - + (desired.getRedBits() + desired.getGreenBits() + desired.getBlueBits() + desired.getAlphaBits()))); + scores[i] = score; + } + + if (DEBUG) { + System.err.print("Scores: ["); + for (int i = 0; i < availnum; i++) { + if (i > 0) { + System.err.print(","); + } + System.err.print(" " + scores[i]); + } + System.err.println(" ]"); + } + + // Ready to select. Choose score closest to 0. + int scoreClosestToZero = NO_SCORE; + int chosenIndex = -1; + for (int i = 0; i < availnum; i++) { + int score = scores[i]; + if (score == NO_SCORE) { + continue; + } + // Don't substitute a positive score for a smaller negative score + if ((scoreClosestToZero == NO_SCORE) || + (Math.abs(score) < Math.abs(scoreClosestToZero) && + ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) { + scoreClosestToZero = score; + chosenIndex = i; + } + } + if (chosenIndex < 0) { + throw new NativeWindowException("Unable to select one of the provided Capabilities"); + } + if (DEBUG) { + System.err.println("Chosen index: " + chosenIndex); + System.err.println("Chosen capabilities:"); + System.err.println(available.get(chosenIndex)); + } + + return chosenIndex; + } + + private static int sign(int score) { + if (score < 0) { + return -1; + } + return 1; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java new file mode 100644 index 000000000..ffa8bfae6 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow; + +public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphicsConfiguration { + private AbstractGraphicsScreen screen; + protected CapabilitiesImmutable capabilitiesChosen; + protected CapabilitiesImmutable capabilitiesRequested; + + public DefaultGraphicsConfiguration(AbstractGraphicsScreen screen, + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) { + if(null == screen) { + throw new NativeWindowException("Null screen"); + } + if(null == capsChosen) { + throw new NativeWindowException("Null chosen caps"); + } + if(null == capsRequested) { + throw new NativeWindowException("Null requested caps"); + } + this.screen = screen; + this.capabilitiesChosen = capsChosen; + this.capabilitiesRequested = capsRequested; + } + + @Override + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new NativeWindowException(e); + } + } + + public AbstractGraphicsScreen getScreen() { + return screen; + } + + public CapabilitiesImmutable getChosenCapabilities() { + return capabilitiesChosen; + } + + public CapabilitiesImmutable getRequestedCapabilities() { + return capabilitiesRequested; + } + + public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() { + return this; + } + + /** + * Set the capabilities to a new value. + * + * The use case for setting the Capabilities at a later time is + * a change of the graphics device in a multi-screen environment.<br> + * + * The objects reference is being used. + * + * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + */ + protected void setChosenCapabilities(CapabilitiesImmutable capsChosen) { + capabilitiesChosen = capsChosen; + } + + /** + * Set a new screen. + * + * the use case for setting a new screen at a later time is + * a change of the graphics device in a multi-screen environment.<br> + * + * A copy of the passed object is being used. + */ + protected void setScreen(DefaultGraphicsScreen screen) { + this.screen = (AbstractGraphicsScreen) screen.clone(); + } + + @Override + public String toString() { + return getClass().getSimpleName()+"[" + screen + + ",\n\tchosen " + capabilitiesChosen+ + ",\n\trequested " + capabilitiesRequested+ + "]"; + } + + public static String toHexString(int val) { + return "0x"+Integer.toHexString(val); + } + + public static String toHexString(long val) { + return "0x"+Long.toHexString(val); + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java new file mode 100644 index 000000000..c2aa6fae9 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow; + +import jogamp.nativewindow.NativeWindowFactoryImpl; + +public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice { + private static final String separator = "_"; + private String type; + protected String connection; + protected int unitID; + protected String uniqueID; + protected long handle; + protected ToolkitLock toolkitLock; + + /** + * Create an instance with the system default {@link ToolkitLock}, + * gathered via {@link NativeWindowFactory#createDefaultToolkitLock()}. + * @param type + */ + public DefaultGraphicsDevice(String type, String connection, int unitID) { + this.type = type; + this.connection = connection; + this.unitID = unitID; + this.uniqueID = getUniqueID(type, connection, unitID); + this.handle = 0; + setToolkitLock( NativeWindowFactory.getDefaultToolkitLock(type) ); + } + + /** + * Create an instance with the system default {@link ToolkitLock}. + * gathered via {@link NativeWindowFactory#createDefaultToolkitLock()}. + * @param type + * @param handle + */ + public DefaultGraphicsDevice(String type, String connection, int unitID, long handle) { + this.type = type; + this.connection = connection; + this.unitID = unitID; + this.uniqueID = getUniqueID(type, connection, unitID); + this.handle = handle; + setToolkitLock( NativeWindowFactory.createDefaultToolkitLock(type, handle) ); + } + + /** + * Create an instance with the given {@link ToolkitLock} instance. + * @param type + * @param handle + * @param locker + */ + public DefaultGraphicsDevice(String type, String connection, int unitID, long handle, ToolkitLock locker) { + this.type = type; + this.connection = connection; + this.unitID = unitID; + this.uniqueID = getUniqueID(type, connection, unitID); + this.handle = handle; + setToolkitLock( locker ); + } + + @Override + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new NativeWindowException(e); + } + } + + public final String getType() { + return type; + } + + public final String getConnection() { + return connection; + } + + public final int getUnitID() { + return unitID; + } + + public final String getUniqueID() { + return uniqueID; + } + + public final long getHandle() { + return handle; + } + + /** + * No lock is performed on the graphics device per default, + * instead the aggregated recursive {@link ToolkitLock#lock()} is invoked. + * + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long) + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long, javax.media.nativewindow.ToolkitLock) + */ + public final void lock() { + toolkitLock.lock(); + } + + /** + * No lock is performed on the graphics device per default, + * instead the aggregated recursive {@link ToolkitLock#unlock()} is invoked. + * + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long) + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long, javax.media.nativewindow.ToolkitLock) + */ + public final void unlock() { + toolkitLock.unlock(); + } + + public boolean close() { + return false; + } + + @Override + public String toString() { + return getClass().getSimpleName()+"[type "+getType()+", connection "+getConnection()+", unitID "+getUnitID()+", handle 0x"+Long.toHexString(getHandle())+"]"; + } + + /** + * Set the internal ToolkitLock, which is used within the + * {@link #lock()} and {@link #unlock()} implementation. + * + * @param locker the ToolkitLock, if null, {@link jogamp.nativewindow.NullToolkitLock} is being used + */ + protected void setToolkitLock(ToolkitLock locker) { + this.toolkitLock = ( null == locker ) ? NativeWindowFactoryImpl.getNullToolkitLock() : locker ; + } + + /** + * @return the used ToolkitLock + * + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long) + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long, javax.media.nativewindow.ToolkitLock) + */ + public final ToolkitLock getToolkitLock() { + return toolkitLock; + } + + protected static String getUniqueID(String type, String connection, int unitID) { + return (type + separator + connection + separator + unitID).intern(); + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java new file mode 100644 index 000000000..f50bd0e14 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow; + +public class DefaultGraphicsScreen implements Cloneable, AbstractGraphicsScreen { + AbstractGraphicsDevice device; + private int idx; + + public DefaultGraphicsScreen(AbstractGraphicsDevice device, int idx) { + this.device = device; + this.idx = idx; + } + + public static AbstractGraphicsScreen createDefault(String type) { + return new DefaultGraphicsScreen(new DefaultGraphicsDevice(type, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT), 0); + } + + @Override + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new NativeWindowException(e); + } + } + + public AbstractGraphicsDevice getDevice() { + return device; + } + + public int getIndex() { + return idx; + } + + @Override + public String toString() { + return getClass().getSimpleName()+"["+device+", idx "+idx+"]"; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java new file mode 100644 index 000000000..fa3923dcf --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2008-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow; + +import com.jogamp.common.util.ReflectionUtil; +import jogamp.nativewindow.Debug; +import jogamp.nativewindow.DefaultGraphicsConfigurationFactoryImpl; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + + +/** + * Provides the mechanism by which the graphics configuration for a + * window can be chosen before the window is created. The graphics + * configuration decides parameters related to hardware accelerated rendering such + * as the OpenGL pixel format. <br> + * On some window systems (EGL/OpenKODE and X11 in particular) it is necessary to + * choose the graphics configuration early at window creation time. <br> + * Note that the selection of the graphics configuration is an algorithm which does not have + * strong dependencies on the particular Java window toolkit in use + * (e.g., AWT) and therefore it is strongly desirable to factor this + * functionality out of the core {@link NativeWindowFactory} so that + * new window toolkits can replace just the {@link + * NativeWindowFactory} and reuse the graphics configuration selection + * algorithm provided by, for example, an OpenGL binding. + */ + +public abstract class GraphicsConfigurationFactory { + protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); + + private static Map/*<Class, NativeWindowFactory>*/ registeredFactories = + Collections.synchronizedMap(new HashMap()); + private static Class abstractGraphicsDeviceClass; + + static { + initialize(); + } + + protected static String getThreadName() { + return Thread.currentThread().getName(); + } + + protected static String toHexString(int val) { + return "0x" + Integer.toHexString(val); + } + + protected static String toHexString(long val) { + return "0x" + Long.toHexString(val); + } + + /** Creates a new NativeWindowFactory instance. End users do not + need to call this method. */ + protected GraphicsConfigurationFactory() { + } + + private static void initialize() { + abstractGraphicsDeviceClass = javax.media.nativewindow.AbstractGraphicsDevice.class; + + if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { + try { + GraphicsConfigurationFactory factory = (GraphicsConfigurationFactory) + ReflectionUtil.createInstance("jogamp.nativewindow.x11.X11GraphicsConfigurationFactory", null, + GraphicsConfigurationFactory.class.getClassLoader()); + registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, factory); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + // Register the default no-op factory for arbitrary + // AbstractGraphicsDevice implementations, including + // AWTGraphicsDevice instances -- the OpenGL binding will take + // care of handling AWTGraphicsDevices on X11 platforms (as + // well as X11GraphicsDevices in non-AWT situations) + registerFactory(abstractGraphicsDeviceClass, new DefaultGraphicsConfigurationFactoryImpl()); + } + + /** Returns the factory for use with the given type of + AbstractGraphicsDevice. */ + public static GraphicsConfigurationFactory getFactory(AbstractGraphicsDevice device) { + if (device == null) { + return getFactory(AbstractGraphicsDevice.class); + } + return getFactory(device.getClass()); + } + + /** + * Returns the graphics configuration factory for use with the + * given class, which must implement the {@link + * AbstractGraphicsDevice} interface. + * + * @throws IllegalArgumentException if the given class does not implement AbstractGraphicsDevice + */ + public static GraphicsConfigurationFactory getFactory(Class abstractGraphicsDeviceImplementor) + throws IllegalArgumentException, NativeWindowException + { + if (!(abstractGraphicsDeviceClass.isAssignableFrom(abstractGraphicsDeviceImplementor))) { + throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice"); + } + + GraphicsConfigurationFactory factory = null; + Class clazz = abstractGraphicsDeviceImplementor; + while (clazz != null) { + factory = + (GraphicsConfigurationFactory) registeredFactories.get(clazz); + if (factory != null) { + if(DEBUG) { + System.err.println("GraphicsConfigurationFactory.getFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory); + } + return factory; + } + clazz = clazz.getSuperclass(); + } + // Return the default + factory = (GraphicsConfigurationFactory)registeredFactories.get(abstractGraphicsDeviceClass); + if(DEBUG) { + System.err.println("GraphicsConfigurationFactory.getFactory() DEFAULT "+abstractGraphicsDeviceClass+" -> "+factory); + } + return factory; + } + + /** Registers a GraphicsConfigurationFactory handling graphics + * device objects of the given class. This does not need to be + * called by end users, only implementors of new + * GraphicsConfigurationFactory subclasses. + * + * @throws IllegalArgumentException if the given class does not implement AbstractGraphicsDevice + */ + protected static void registerFactory(Class abstractGraphicsDeviceImplementor, GraphicsConfigurationFactory factory) + throws IllegalArgumentException + { + if (!(abstractGraphicsDeviceClass.isAssignableFrom(abstractGraphicsDeviceImplementor))) { + throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice"); + } + if(DEBUG) { + System.err.println("GraphicsConfigurationFactory.registerFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory); + } + registeredFactories.put(abstractGraphicsDeviceImplementor, factory); + } + + /** + * <P> Selects a graphics configuration on the specified graphics + * device compatible with the supplied {@link Capabilities}. Some + * platforms (e.g.: X11, EGL, KD) require the graphics configuration + * to be specified when the native window is created. + * These architectures have seperated their device, screen, window and drawable + * context and hence are capable of quering the capabilities for each screen. + * A fully established window is not required.</P> + * + * <P>Other platforms (e.g. Windows, MacOSX) don't offer the mentioned seperation + * and hence need a fully established window and it's drawable. + * Here the validation of the capabilities is performed later. + * In this case, the AbstractGraphicsConfiguration implementation + * must allow an overwrite of the Capabilites, for example + * {@link DefaultGraphicsConfiguration#setChosenCapabilities DefaultGraphicsConfiguration.setChosenCapabilities(..)}. + * </P> + * + * <P> + * This method is mainly intended to be both used and implemented by the + * OpenGL binding.</P> + * + * <P> The concrete data type of the passed graphics device and + * returned graphics configuration must be specified in the + * documentation binding this particular API to the underlying + * window toolkit. The Reference Implementation accepts {@link + * javax.media.nativewindow.awt.AWTGraphicsDevice AWTGraphicsDevice} objects and returns {@link + * javax.media.nativewindow.awt.AWTGraphicsConfiguration AWTGraphicsConfiguration} objects. On + * X11 platforms where the AWT is not in use, it also accepts + * {@link javax.media.nativewindow.x11.X11GraphicsDevice + * X11GraphicsDevice} objects and returns {@link + * javax.media.nativewindow.x11.X11GraphicsConfiguration + * X11GraphicsConfiguration} objects.</P> + * + * @param capsChosen the intermediate chosen capabilities to be refined by this implementation, may be equal to capsRequested + * @param capsRequested the original requested capabilities + * @param chooser the choosing implementation + * @param screen the referring Screen + * @return the complete GraphicsConfiguration + * + * @throws IllegalArgumentException if the data type of the passed + * AbstractGraphicsDevice is not supported by this + * NativeWindowFactory. + * @throws NativeWindowException if any window system-specific errors caused + * the selection of the graphics configuration to fail. + * + * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + * @see javax.media.nativewindow.DefaultGraphicsConfiguration#setChosenCapabilities(Capabilities caps) + */ + public final AbstractGraphicsConfiguration + chooseGraphicsConfiguration(CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + CapabilitiesChooser chooser, + AbstractGraphicsScreen screen) + throws IllegalArgumentException, NativeWindowException { + if(null==capsChosen) { + throw new NativeWindowException("Chosen Capabilities are null"); + } + if(null==capsRequested) { + throw new NativeWindowException("Requested Capabilities are null"); + } + if(null==screen) { + throw new NativeWindowException("Screen is null"); + } + AbstractGraphicsDevice device = screen.getDevice(); + if(null==device) { + throw new NativeWindowException("Screen's Device is null"); + } + device.lock(); + try { + return chooseGraphicsConfigurationImpl(capsChosen, capsRequested, chooser, screen); + } finally { + device.unlock(); + } + } + + protected abstract AbstractGraphicsConfiguration + chooseGraphicsConfigurationImpl(CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + CapabilitiesChooser chooser, AbstractGraphicsScreen screen) + throws IllegalArgumentException, NativeWindowException; + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java new file mode 100644 index 000000000..a5b71fbf8 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java @@ -0,0 +1,163 @@ +/** + * 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 javax.media.nativewindow; + +/** Provides low-level information required for + hardware-accelerated rendering using a surface in a platform-independent manner.<P> + + A NativeSurface created for a particular on- or offscreen component is + expected to have the same lifetime as that component. As long as + the component is alive and realized/visible, NativeSurface must be able + provide information such as the surface handle while it is locked.<P> +*/ +public interface NativeSurface extends SurfaceUpdatedListener { + /** Unlocked state */ + public static final int LOCK_SURFACE_UNLOCKED = 0; + + /** Returned by {@link #lockSurface()} if the surface is not ready to be locked. */ + public static final int LOCK_SURFACE_NOT_READY = 1; + + /** Returned by {@link #lockSurface()} if the surface is locked, but has changed. */ + public static final int LOCK_SURFACE_CHANGED = 2; + + /** Returned by {@link #lockSurface()} if the surface is locked, and is unchanged. */ + public static final int LOCK_SUCCESS = 3; + + /** + * Lock the surface of this native window<P> + * + * The surface handle, see {@link #lockSurface()}, <br> + * shall be valid after a successfull call, + * ie return a value other than {@link #LOCK_SURFACE_NOT_READY}.<P> + * + * This call is blocking until the surface has been locked + * or a timeout is reached. The latter will throw a runtime exception. <P> + * + * This call allows recursion from the same thread.<P> + * + * The implementation may want to aquire the + * application level {@link com.jogamp.common.util.locks.RecursiveLock} + * first before proceeding with a native surface lock. <P> + * + * The implementation shall also invoke {@link AbstractGraphicsDevice#lock()} + * for the initial lock (recursive count zero).<P> + * + * @return {@link #LOCK_SUCCESS}, {@link #LOCK_SURFACE_CHANGED} or {@link #LOCK_SURFACE_NOT_READY}. + * + * @throws RuntimeException after timeout when waiting for the surface lock + * + * @see com.jogamp.common.util.locks.RecursiveLock + */ + public int lockSurface(); + + /** + * Unlock the surface of this native window + * + * Shall not modify the surface handle, see {@link #lockSurface()} <P> + * + * The implementation shall also invoke {@link AbstractGraphicsDevice#unlock()} + * for the final unlock (recursive count zero).<P> + * + * @throws RuntimeException if surface is not locked + * + * @see #lockSurface + * @see com.jogamp.common.util.locks.RecursiveLock + */ + public void unlockSurface() throws NativeWindowException ; + + /** + * Return if surface is locked by another thread, ie not the current one + */ + public boolean isSurfaceLockedByOtherThread(); + + /** + * Return if surface is locked + */ + public boolean isSurfaceLocked(); + + /** + * Return the locking owner's Thread, or null if not locked. + */ + public Thread getSurfaceLockOwner(); + + /** + * Provide a mechanism to utilize custom (pre-) swap surface + * code. This method is called before the render toolkit (e.g. JOGL) + * swaps the buffer/surface. The implementation may itself apply the swapping, + * in which case true shall be returned. + * + * @return true if this method completed swapping the surface, + * otherwise false, in which case eg the GLDrawable + * implementation has to swap the code. + */ + public boolean surfaceSwap(); + + /** + * Returns the handle to the surface for this NativeSurface. <P> + * + * The surface handle should be set/update by {@link #lockSurface()}, + * where {@link #unlockSurface()} is not allowed to modify it. + * After {@link #unlockSurface()} it is no more guaranteed + * that the surface handle is still valid. + * + * The surface handle shall reflect the platform one + * for all drawable surface operations, e.g. opengl, swap-buffer. <P> + * + * On X11 this returns an entity of type Window, + * since there is no differentiation of surface and window there. <BR> + * On Microsoft Windows this returns an entity of type HDC. + */ + public long getSurfaceHandle(); + + /** Returns the current width of this surface. */ + public int getWidth(); + + /** Returns the current height of this surface. */ + public int getHeight(); + + /** + * Returns the graphics configuration corresponding to this window. + * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + */ + public AbstractGraphicsConfiguration getGraphicsConfiguration(); + + /** + * Convenience: Get display handle from + * AbstractGraphicsConfiguration . AbstractGraphicsScreen . AbstractGraphicsDevice + */ + public long getDisplayHandle(); + + /** + * Convenience: Get display handle from + * AbstractGraphicsConfiguration . AbstractGraphicsScreen + */ + public int getScreenIndex(); + +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java new file mode 100644 index 000000000..d65cc8c18 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +import javax.media.nativewindow.util.Point; + +/** Extend the {@link NativeSurface} interface with windowing + information such as window handle and position.<P> + + A window toolkit such as the AWT may either implement this interface + directly with one of its components, or provide and register an + implementation of {@link NativeWindowFactory NativeWindowFactory} + which can create NativeWindow objects for its components. <P> +*/ +public interface NativeWindow extends NativeSurface { + + /** + * destroys the window and releases + * windowing related resources. + */ + public void destroy(); + + /** + * @return The parent NativeWindow, or null if this NativeWindow is top level. + */ + public NativeWindow getParent(); + + /** + * Returns the window handle for this NativeWindow. <P> + * + * The window handle shall reflect the platform one + * for all window related operations, e.g. open, close, resize. <P> + * + * On X11 this returns an entity of type Window. <BR> + * On Microsoft Windows this returns an entity of type HWND. + */ + public long getWindowHandle(); + + /** Returns the current x position of this window, relative to it's parent. */ + public int getX(); + + /** Returns the current y position of this window, relative to it's parent. */ + public int getY(); + + /** + * Returns the current absolute location of this window. + * @param point if not null, + * {@link javax.media.nativewindow.util.Point#translate(javax.media.nativewindow.util.Point)} + * the passed {@link javax.media.nativewindow.util.Point} by this location on the screen and return it. + * @return either the passed non null translated point by the screen location of this NativeWindow, + * or a new instance with the screen location of this NativeWindow. + */ + public Point getLocationOnScreen(Point point); + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java new file mode 100644 index 000000000..593c1e7d6 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +/** A generic exception for OpenGL errors used throughout the binding + as a substitute for {@link RuntimeException}. */ + +public class NativeWindowException extends RuntimeException { + /** Constructs a NativeWindowException object. */ + public NativeWindowException() { + super(); + } + + /** Constructs a NativeWindowException object with the specified detail + message. */ + public NativeWindowException(String message) { + super(message); + } + + /** Constructs a NativeWindowException object with the specified detail + message and root cause. */ + public NativeWindowException(String message, Throwable cause) { + super(message, cause); + } + + /** Constructs a NativeWindowException object with the specified root + cause. */ + public NativeWindowException(Throwable cause) { + super(cause); + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java new file mode 100644 index 000000000..b0f5cb3f9 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -0,0 +1,486 @@ +/* + * Copyright (c) 2008-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow; + +import java.security.*; +import java.util.*; + +import com.jogamp.common.util.*; +import com.jogamp.common.jvm.JVMUtil; +import jogamp.nativewindow.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +/** Provides a pluggable mechanism for arbitrary window toolkits to + adapt their components to the {@link NativeWindow} interface, + which provides a platform-independent mechanism of accessing the + information required to perform operations like + hardware-accelerated rendering using the OpenGL API. */ + +public abstract class NativeWindowFactory { + protected static final boolean DEBUG; + + /** OpenKODE/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}*/ + public static final String TYPE_EGL = "EGL"; + + /** Microsoft Windows type, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_WINDOWS = "Windows"; + + /** X11 type, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_X11 = "X11"; + + /** Mac OS X type, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_MACOSX = "MacOSX"; + + /** Generic AWT type, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_AWT = "AWT"; + + /** Generic DEFAULT type, where platform implementation don't care, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_DEFAULT = "default"; + + private static NativeWindowFactory defaultFactory; + private static Map/*<Class, NativeWindowFactory>*/ registeredFactories; + private static Class nativeWindowClass; + private static String nativeWindowingTypePure; + private static String nativeOSNamePure; + private static String nativeWindowingTypeCustom; + private static String nativeOSNameCustom; + private static boolean isAWTAvailable; + public static final String AWTComponentClassName = "java.awt.Component" ; + public static final String JAWTUtilClassName = "jogamp.nativewindow.jawt.JAWTUtil" ; + public static final String X11UtilClassName = "jogamp.nativewindow.x11.X11Util"; + public static final String GDIClassName = "jogamp.nativewindow.windows.GDI"; + public static final String X11JAWTToolkitLockClassName = "jogamp.nativewindow.jawt.x11.X11JAWTToolkitLock" ; + public static final String X11ToolkitLockClassName = "jogamp.nativewindow.x11.X11ToolkitLock" ; + private static Class jawtUtilClass; + private static Method jawtUtilGetJAWTToolkitMethod; + private static Method jawtUtilInitMethod; + private static Class x11JAWTToolkitLockClass; + private static Constructor x11JAWTToolkitLockConstructor; + private static Class x11ToolkitLockClass; + private static Constructor x11ToolkitLockConstructor; + private static boolean isFirstUIActionOnProcess; + + /** Creates a new NativeWindowFactory instance. End users do not + need to call this method. */ + protected NativeWindowFactory() { + } + + private static String _getNativeWindowingType(String osNameLowerCase) { + if (osNameLowerCase.startsWith("kd")) { + return TYPE_EGL; + } else if (osNameLowerCase.startsWith("wind")) { + return TYPE_WINDOWS; + } else if (osNameLowerCase.startsWith("mac os x") || + osNameLowerCase.startsWith("darwin")) { + return TYPE_MACOSX; + } else if (osNameLowerCase.equals("awt")) { + return TYPE_AWT; + } else { + return TYPE_X11; + } + } + + static { + JVMUtil.initSingleton(); + DEBUG = Debug.debug("NativeWindow"); + if(DEBUG) { + Throwable td = new Throwable(Thread.currentThread().getName()+" - Info: NativeWindowFactory.<init>"); + td.printStackTrace(); + } + } + + static boolean initialized = false; + + private static void initNativeImpl(final boolean firstUIActionOnProcess, final ClassLoader cl) { + String clazzName = null; + if( TYPE_X11.equals(nativeWindowingTypePure) ) { + clazzName = X11UtilClassName; + } else if( TYPE_WINDOWS.equals(nativeWindowingTypePure) ) { + clazzName = GDIClassName; + } + if( null != clazzName ) { + ReflectionUtil.callStaticMethod(clazzName, "initSingleton", + new Class[] { boolean.class }, + new Object[] { new Boolean(firstUIActionOnProcess) }, cl ); + } + } + + /** + * Static one time initialization of this factory.<br> + * This initialization method <b>must be called</b> once by the program or utilizing modules! + * <p> + * The parameter <code>firstUIActionOnProcess</code> has an impact on concurrent locking: + * <ul> + * <li> {@link #getDefaultToolkitLock() getDefaultToolkitLock() }</li> + * <li> {@link #getDefaultToolkitLock(java.lang.String) getDefaultToolkitLock(type) }</li> + * <li> {@link #createDefaultToolkitLock(java.lang.String, long) createDefaultToolkitLock(type, dpyHandle) }</li> + * <li> {@link #createDefaultToolkitLockNoAWT(java.lang.String, long) createDefaultToolkitLockNoAWT(type, dpyHandle) }</li> + * </ul> + * </p> + * @param firstUIActionOnProcess Should be <code>true</code> if called before the first UI action of the running program, + * otherwise <code>false</code>. + */ + public static synchronized void initSingleton(final boolean firstUIActionOnProcess) { + if(!initialized) { + initialized = true; + + if(DEBUG) { + System.err.println(Thread.currentThread().getName()+" - NativeWindowFactory.initSingleton("+firstUIActionOnProcess+")"); + } + + // Gather the windowing OS first + AccessControlContext acc = AccessController.getContext(); + nativeOSNamePure = Debug.getProperty("os.name", false, acc); + nativeWindowingTypePure = _getNativeWindowingType(nativeOSNamePure.toLowerCase()); + nativeOSNameCustom = Debug.getProperty("nativewindow.ws.name", true, acc); + if(null==nativeOSNameCustom||nativeOSNameCustom.length()==0) { + nativeOSNameCustom = nativeOSNamePure; + nativeWindowingTypeCustom = nativeWindowingTypePure; + } else { + nativeWindowingTypeCustom = nativeOSNameCustom; + } + + final ClassLoader cl = NativeWindowFactory.class.getClassLoader(); + + if(firstUIActionOnProcess) { + // X11 initialization before possible AWT initialization + initNativeImpl(firstUIActionOnProcess, cl); + } + isFirstUIActionOnProcess = firstUIActionOnProcess; + isAWTAvailable = false; // may be set to true below + + if( !Debug.getBooleanProperty("java.awt.headless", true, acc) && + ReflectionUtil.isClassAvailable(AWTComponentClassName, cl) && + ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice", cl) ) { + + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + jawtUtilClass = Class.forName(JAWTUtilClassName, false, NativeWindowFactory.class.getClassLoader()); + jawtUtilInitMethod = jawtUtilClass.getDeclaredMethod("initSingleton", (Class[])null); + jawtUtilInitMethod.setAccessible(true); + jawtUtilGetJAWTToolkitMethod = jawtUtilClass.getDeclaredMethod("getJAWTToolkitLock", new Class[]{}); + jawtUtilGetJAWTToolkitMethod.setAccessible(true); + } catch (Exception e) { + // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5 + } + return null; + } + }); + if(null != jawtUtilClass && null != jawtUtilGetJAWTToolkitMethod && null != jawtUtilInitMethod) { + ReflectionUtil.callMethod(null, jawtUtilInitMethod, null); + + Object resO = ReflectionUtil.callStaticMethod(JAWTUtilClassName, "isHeadlessMode", null, null, cl ); + if(resO instanceof Boolean) { + // AWT is only available in case all above classes are available + // and AWT is not int headless mode + isAWTAvailable = ((Boolean)resO).equals(Boolean.FALSE); + } + } + } + if(!firstUIActionOnProcess) { + // X11 initialization after possible AWT initialization + initNativeImpl(firstUIActionOnProcess, cl); + } + registeredFactories = Collections.synchronizedMap(new HashMap()); + + // register our default factory -> NativeWindow + NativeWindowFactory factory = new NativeWindowFactoryImpl(); + nativeWindowClass = javax.media.nativewindow.NativeWindow.class; + registerFactory(nativeWindowClass, factory); + defaultFactory = factory; + + if ( isAWTAvailable ) { + // register either our default factory or (if exist) the X11/AWT one -> AWT Component + registerFactory(ReflectionUtil.getClass(AWTComponentClassName, false, cl), factory); + } + + if( TYPE_X11 == nativeWindowingTypePure ) { + // passing through RuntimeException if not exists intended + x11ToolkitLockClass = ReflectionUtil.getClass(X11ToolkitLockClassName, false, cl); + x11ToolkitLockConstructor = ReflectionUtil.getConstructor(x11ToolkitLockClass, new Class[] { long.class } ); + if( isAWTAvailable() ) { + x11JAWTToolkitLockClass = ReflectionUtil.getClass(X11JAWTToolkitLockClassName, false, cl); + x11JAWTToolkitLockConstructor = ReflectionUtil.getConstructor(x11JAWTToolkitLockClass, new Class[] { long.class } ); + } + } + + if(DEBUG) { + System.err.println("NativeWindowFactory firstUIActionOnProcess "+firstUIActionOnProcess); + System.err.println("NativeWindowFactory isAWTAvailable "+isAWTAvailable+", defaultFactory "+factory); + } + } + } + + /** @return true if initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, + otherwise false. */ + public static boolean isFirstUIActionOnProcess() { + return isFirstUIActionOnProcess; + } + + /** @return true if not headless, AWT Component and NativeWindow's AWT part available */ + public static boolean isAWTAvailable() { return isAWTAvailable; } + + /** + * @param useCustom if false return the native value, if true return a custom value if set, otherwise fallback to the native value. + * @return the native OS name + */ + public static String getNativeOSName(boolean useCustom) { + return useCustom?nativeOSNameCustom:nativeOSNamePure; + } + + /** + * @param useCustom if false return the native value, if true return a custom value if set, otherwise fallback to the native value. + * @return a define native window type, like {@link #TYPE_X11}, .. + */ + public static String getNativeWindowType(boolean useCustom) { + return useCustom?nativeWindowingTypeCustom:nativeWindowingTypePure; + } + + /** Don't know if we shall add this factory here .. + public static AbstractGraphicsDevice createGraphicsDevice(String type, String connection, int unitID, long handle, ToolkitLock locker) { + if(type.equals(TYPE_EGL)) { + return new + } else if(type.equals(TYPE_X11)) { + } else if(type.equals(TYPE_WINDOWS)) { + } else if(type.equals(TYPE_MACOSX)) { + } else if(type.equals(TYPE_AWT)) { + } else if(type.equals(TYPE_DEFAULT)) { + } + } */ + + /** Sets the default NativeWindowFactory. */ + public static void setDefaultFactory(NativeWindowFactory factory) { + defaultFactory = factory; + } + + /** Gets the default NativeWindowFactory. */ + public static NativeWindowFactory getDefaultFactory() { + return defaultFactory; + } + + /** + * Provides the system default {@link ToolkitLock}, a singleton instance. + * <br> + * @see #getDefaultToolkitLock(java.lang.String) + */ + public static ToolkitLock getDefaultToolkitLock() { + return getDefaultToolkitLock(getNativeWindowType(false)); + } + + /** + * Provides the default {@link ToolkitLock} for <code>type</code>, a singleton instance. + * <br> + * <ul> + * <li> If {@link #initSingleton(boolean) initSingleton( <b>firstUIActionOnProcess := false</b> )} </li> + * <ul> + * <li>If native <b>X11 type</b> with or w/o AWT</li> + * <ul> + * <li> If <b>AWT available</b> </li> + * <ul> + * <li> return {@link jogamp.nativewindow.jawt.JAWTToolkitLock} </li> + * </ul> + * </ul> + * </ul> + * <li> Otherwise return {@link jogamp.nativewindow.NullToolkitLock} </li> + * </ul> + */ + public static ToolkitLock getDefaultToolkitLock(String type) { + if( !isFirstUIActionOnProcess() ) { + if( TYPE_X11 == type || TYPE_AWT == type && TYPE_X11 == getNativeWindowType(false) ) { + if( isAWTAvailable() ) { + return getAWTToolkitLock(); + } + } + } + return NativeWindowFactoryImpl.getNullToolkitLock(); + } + + protected static ToolkitLock getAWTToolkitLock() { + Object resO = ReflectionUtil.callMethod(null, jawtUtilGetJAWTToolkitMethod, null); + + if(resO instanceof ToolkitLock) { + return (ToolkitLock) resO; + } else { + throw new RuntimeException("JAWTUtil.getJAWTToolkitLock() didn't return a ToolkitLock"); + } + } + + public static ToolkitLock getNullToolkitLock() { + return NativeWindowFactoryImpl.getNullToolkitLock(); + } + + /** + * Creates the default {@link ToolkitLock} for <code>type</code> and <code>deviceHandle</code>. + * <br> + * <ul> + * <li> If {@link #initSingleton(boolean) initSingleton( <b>firstUIActionOnProcess := false</b> )} </li> + * <ul> + * <li>If <b>X11 type</b> </li> + * <ul> + * <li> If <b>AWT available</b> </li> + * <ul> + * <li> return {@link jogamp.nativewindow.jawt.x11.X11JAWTToolkitLock} </li> + * </ul> + * <li> If <b>AWT not available</b> </li> + * <ul> + * <li> return {@link jogamp.nativewindow.x11.X11ToolkitLock} </li> + * </ul> + * </ul> + * </ul> + * <li> Otherwise return {@link jogamp.nativewindow.NullToolkitLock} </li> + * </ul> + */ + public static ToolkitLock createDefaultToolkitLock(String type, long deviceHandle) { + if( !isFirstUIActionOnProcess() ) { + if( TYPE_X11 == type ) { + if( 0== deviceHandle ) { + throw new RuntimeException("JAWTUtil.createDefaultToolkitLock() called with NULL device but on X11"); + } + if( isAWTAvailable() ) { + return createX11AWTToolkitLock(deviceHandle); + } + return createX11ToolkitLock(deviceHandle); + } + } + return NativeWindowFactoryImpl.getNullToolkitLock(); + } + + /** + * Creates the default {@link ToolkitLock} for <code>type</code> and <code>deviceHandle</code>. + * <br> + * <ul> + * <li> If {@link #initSingleton(boolean) initSingleton( <b>firstUIActionOnProcess := false</b> )} </li> + * <ul> + * <li>If <b>X11 type</b> </li> + * <ul> + * <li> return {@link jogamp.nativewindow.x11.X11ToolkitLock} </li> + * </ul> + * </ul> + * <li> Otherwise return {@link jogamp.nativewindow.NullToolkitLock} </li> + * </ul> + */ + public static ToolkitLock createDefaultToolkitLockNoAWT(String type, long deviceHandle) { + if( !isFirstUIActionOnProcess() ) { + if( TYPE_X11 == type ) { + if( 0== deviceHandle ) { + throw new RuntimeException("JAWTUtil.createDefaultToolkitLockNoAWT() called with NULL device but on X11"); + } + return createX11ToolkitLock(deviceHandle); + } + } + return NativeWindowFactoryImpl.getNullToolkitLock(); + } + + protected static ToolkitLock createX11AWTToolkitLock(long deviceHandle) { + try { + return (ToolkitLock) x11JAWTToolkitLockConstructor.newInstance(new Object[]{new Long(deviceHandle)}); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + protected static ToolkitLock createX11ToolkitLock(long deviceHandle) { + try { + return (ToolkitLock) x11ToolkitLockConstructor.newInstance(new Object[]{new Long(deviceHandle)}); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + + /** Returns the appropriate NativeWindowFactory to handle window + objects of the given type. The windowClass might be {@link + NativeWindow NativeWindow}, in which case the client has + already assumed the responsibility of creating a compatible + NativeWindow implementation, or it might be that of a toolkit + class like {@link java.awt.Component Component}. */ + public static NativeWindowFactory getFactory(Class windowClass) throws IllegalArgumentException { + if (nativeWindowClass.isAssignableFrom(windowClass)) { + return (NativeWindowFactory) registeredFactories.get(nativeWindowClass); + } + Class clazz = windowClass; + while (clazz != null) { + NativeWindowFactory factory = (NativeWindowFactory) registeredFactories.get(clazz); + if (factory != null) { + return factory; + } + clazz = clazz.getSuperclass(); + } + throw new IllegalArgumentException("No registered NativeWindowFactory for class " + windowClass.getName()); + } + + /** Registers a NativeWindowFactory handling window objects of the + given class. This does not need to be called by end users, + only implementors of new NativeWindowFactory subclasses. */ + protected static void registerFactory(Class windowClass, NativeWindowFactory factory) { + if(DEBUG) { + System.err.println("NativeWindowFactory.registerFactory() "+windowClass+" -> "+factory); + } + registeredFactories.put(windowClass, factory); + } + + /** Converts the given window object and it's + {@link AbstractGraphicsConfiguration AbstractGraphicsConfiguration} into a + {@link NativeWindow NativeWindow} which can be operated upon by a custom + toolkit, e.g. {@link javax.media.opengl.GLDrawableFactory javax.media.opengl.GLDrawableFactory}.<br> + The object may be a component for a particular window toolkit, such as an AWT + Canvas. It may also be a NativeWindow object itself.<br> + You shall utilize {@link javax.media.nativewindow.GraphicsConfigurationFactory GraphicsConfigurationFactory} + to construct a proper {@link AbstractGraphicsConfiguration AbstractGraphicsConfiguration}.<br> + The particular implementation of the + NativeWindowFactory is responsible for handling objects from a + particular window toolkit. The built-in NativeWindowFactory + handles NativeWindow instances as well as AWT Components.<br> + + @throws IllegalArgumentException if the given window object + could not be handled by any of the registered + NativeWindowFactory instances + + @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + */ + public static NativeWindow getNativeWindow(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException, NativeWindowException { + if (winObj == null) { + throw new IllegalArgumentException("Null window object"); + } + + return getFactory(winObj.getClass()).getNativeWindowImpl(winObj, config); + } + + /** Performs the conversion from a toolkit's window object to a + NativeWindow. Implementors of concrete NativeWindowFactory + subclasses should override this method. */ + protected abstract NativeWindow getNativeWindowImpl(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException; +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java new file mode 100644 index 000000000..038580ce0 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java @@ -0,0 +1,150 @@ +/** + * 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 javax.media.nativewindow; + +import com.jogamp.common.util.locks.RecursiveLock; + +public abstract class ProxySurface implements NativeSurface { + protected RecursiveLock surfaceLock = new RecursiveLock(); + protected AbstractGraphicsConfiguration config; + protected long displayHandle; + protected int height; + protected int scrnIndex; + protected int width; + + public ProxySurface(AbstractGraphicsConfiguration cfg) { + invalidate(); + config = cfg; + displayHandle=cfg.getScreen().getDevice().getHandle(); + } + + void invalidate() { + displayHandle = 0; + invalidateImpl(); + } + protected abstract void invalidateImpl(); + + public final long getDisplayHandle() { + return displayHandle; + } + + public final AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + public final int getScreenIndex() { + return config.getScreen().getIndex(); + } + + public abstract long getSurfaceHandle(); + + public final int getWidth() { + return width; + } + + public final int getHeight() { + return height; + } + + public void setSize(int width, int height) { + this.width = width; + this.height = height; + } + + public boolean surfaceSwap() { + return false; + } + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { + } + + public int lockSurface() throws NativeWindowException { + surfaceLock.lock(); + int res = surfaceLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; + + if ( LOCK_SURFACE_NOT_READY == res ) { + try { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + adevice.lock(); + try { + res = lockSurfaceImpl(); + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + adevice.unlock(); + } + } + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + surfaceLock.unlock(); + } + } + } + return res; + } + + public final void unlockSurface() { + surfaceLock.validateLocked(); + + if (surfaceLock.getRecursionCount() == 0) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + try { + unlockSurfaceImpl(); + } finally { + adevice.unlock(); + } + } + surfaceLock.unlock(); + } + + protected abstract int lockSurfaceImpl(); + + protected abstract void unlockSurfaceImpl() ; + + public final void validateSurfaceLocked() { + surfaceLock.validateLocked(); + } + + public final boolean isSurfaceLocked() { + return surfaceLock.isLocked(); + } + + public final boolean isSurfaceLockedByOtherThread() { + return surfaceLock.isLockedByOtherThread(); + } + + public final Thread getSurfaceLockOwner() { + return surfaceLock.getOwner(); + } + + public final int getSurfaceRecursionCount() { + return surfaceLock.getRecursionCount(); + } + + public abstract String toString(); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/SurfaceChangeable.java b/src/nativewindow/classes/javax/media/nativewindow/SurfaceChangeable.java new file mode 100644 index 000000000..fc32b57b3 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/SurfaceChangeable.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +public interface SurfaceChangeable { + + public void setSurfaceHandle(long surfaceHandle); + public void setSize(int width, int height); + +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java b/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java new file mode 100644 index 000000000..88e805d14 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package javax.media.nativewindow; + +public interface SurfaceUpdatedListener { + /** Notification of a surface update event. + * + * @param updater is the caller object who updated the surface, + * e.g. a JOGL GLDrawable. + * @param ns the updated NativeSurface + * @param when the time in ms, when the surface was updated + */ + public void surfaceUpdated(Object updater, NativeSurface ns, long when) ; +} + diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java b/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java index eab5fc8eb..982ce469b 100644 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java +++ b/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java @@ -25,28 +25,21 @@ * 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 com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.geom.Vertex; +package javax.media.nativewindow; + +import jogamp.nativewindow.Debug; +import java.security.AccessController; /** - * - * Action Keys: - * - 1/2: zoom in/out - * - 3/4: font +/- - * - 6/7: 2nd pass texture size - * - 0/9: rotate - * - s: toogle draw 'font set' - * - f: toggle draw fps - * - v: toggle v-sync - * - space: toggle font (ubuntu/java) + * Marker for a singleton global recursive blocking lock implementation, + * optionally locking a native windowing toolkit as well. + * <br> + * One use case is the AWT locking on X11, see {@link jogamp.nativewindow.jawt.JAWTToolkitLock}. */ -public abstract class GPURegionRendererListenerBase01 extends GPURendererListenerBase01 { - OutlineShape outlineShape = null; +public interface ToolkitLock { + public static final boolean TRACE_LOCK = Debug.isPropertyDefined("nativewindow.debug.ToolkitLock.TraceLock", true, AccessController.getContext()); - public GPURegionRendererListenerBase01(Vertex.Factory<? extends Vertex> factory, int mode, boolean debug, boolean trace) { - super(RegionRenderer.create(factory, mode), debug, trace); - } -}
\ No newline at end of file + public void lock(); + public void unlock(); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java b/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java new file mode 100644 index 000000000..949aee79c --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java @@ -0,0 +1,66 @@ +/** + * 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 javax.media.nativewindow; + +/** + * Protocol for handling window closing events. + * <p> + * The implementation shall obey either the user value set by this interface,<br> + * an underlying toolkit set user value or it's default, eg. {@link #DO_NOTHING_ON_CLOSE DO_NOTHING_ON_CLOSE} within an AWT environment.<br> + * If none of the above determines the operation, + * this protocol default behavior {@link #DISPOSE_ON_CLOSE DISPOSE_ON_CLOSE} shall be used.</p> + */ +public interface WindowClosingProtocol { + /** + * Dispose resources on native window close operation.<br> + * This is the default behavior in case no underlying toolkit defines otherwise. + */ + int DISPOSE_ON_CLOSE = 1; + + /** + * Do nothing on native window close operation.<br> + * This is the default behavior within an AWT environment. + */ + int DO_NOTHING_ON_CLOSE = 0; + + /** + * @return the current close operation value + * @see #DISPOSE_ON_CLOSE + * @see #DO_NOTHING_ON_CLOSE + */ + int getDefaultCloseOperation(); + + /** + * @param op the new close operation value + * @return the previous close operation value + * @see #DISPOSE_ON_CLOSE + * @see #DO_NOTHING_ON_CLOSE + */ + int setDefaultCloseOperation(int op); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java new file mode 100644 index 000000000..d83a92a5b --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow.awt; + +import javax.media.nativewindow.*; +import java.awt.Component; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.image.ColorModel; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import jogamp.nativewindow.Debug; + +/** A wrapper for an AWT GraphicsConfiguration allowing it to be + handled in a toolkit-independent manner. */ + +public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable { + private GraphicsConfiguration config; + AbstractGraphicsConfiguration encapsulated; + + public AWTGraphicsConfiguration(AWTGraphicsScreen screen, + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + GraphicsConfiguration config, AbstractGraphicsConfiguration encapsulated) { + super(screen, capsChosen, capsRequested); + this.config = config; + this.encapsulated=encapsulated; + } + + public AWTGraphicsConfiguration(AWTGraphicsScreen screen, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + GraphicsConfiguration config) { + super(screen, capsChosen, capsRequested); + this.config = config; + this.encapsulated=null; + } + + /** + * @param capsChosen if null, <code>capsRequested</code> is copied and aligned + * with the graphics capabilties of the AWT Component to produce the chosen Capabilties. + * Otherwise the <code>capsChosen</code> is used. + */ + public static AWTGraphicsConfiguration create(Component awtComp, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) + { + AWTGraphicsScreen awtScreen = null; + AWTGraphicsDevice awtDevice = null; + GraphicsDevice awtGraphicsDevice = null; + GraphicsConfiguration awtGfxConfig = awtComp.getGraphicsConfiguration(); + if(null!=awtGfxConfig) { + awtGraphicsDevice = awtGfxConfig.getDevice(); + if(null!=awtGraphicsDevice) { + // Create Device/Screen + awtDevice = new AWTGraphicsDevice(awtGraphicsDevice, AbstractGraphicsDevice.DEFAULT_UNIT); + awtScreen = new AWTGraphicsScreen(awtDevice); + } + } + if(null==awtScreen) { + // use defaults since no native peer is available yet + awtScreen = (AWTGraphicsScreen) AWTGraphicsScreen.createScreenDevice(-1, AbstractGraphicsDevice.DEFAULT_UNIT); + awtDevice = (AWTGraphicsDevice) awtScreen.getDevice(); + awtGraphicsDevice = awtDevice.getGraphicsDevice(); + } + + if(null==capsChosen) { + GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration(); + capsChosen = setupCapabilitiesRGBABits(capsChosen, gc); + } + return new AWTGraphicsConfiguration(awtScreen, capsChosen, capsRequested, awtGfxConfig); + } + + @Override + public Object clone() { + return super.clone(); + } + + public GraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + @Override + public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() { + return (null!=encapsulated)?encapsulated:this; + } + + /** + * Sets up the Capabilities' RGBA size based on the given GraphicsConfiguration's ColorModel. + * + * @param capabilities the Capabilities object whose red, green, blue, and alpha bits will be set + * @param gc the GraphicsConfiguration from which to derive the RGBA bit depths + * @return the passed Capabilities + */ + public static CapabilitiesImmutable setupCapabilitiesRGBABits(CapabilitiesImmutable capabilitiesIn, GraphicsConfiguration gc) { + Capabilities capabilities = (Capabilities) capabilitiesIn.cloneMutable(); + + ColorModel cm = gc.getColorModel(); + if(null==cm) { + throw new NativeWindowException("Could not determine AWT ColorModel"); + } + int cmBitsPerPixel = cm.getPixelSize(); + int bitsPerPixel = 0; + int[] bitesPerComponent = cm.getComponentSize(); + if(bitesPerComponent.length>=3) { + capabilities.setRedBits(bitesPerComponent[0]); + bitsPerPixel += bitesPerComponent[0]; + capabilities.setGreenBits(bitesPerComponent[1]); + bitsPerPixel += bitesPerComponent[1]; + capabilities.setBlueBits(bitesPerComponent[2]); + bitsPerPixel += bitesPerComponent[2]; + } + if(bitesPerComponent.length>=4) { + capabilities.setAlphaBits(bitesPerComponent[3]); + bitsPerPixel += bitesPerComponent[3]; + } else { + capabilities.setAlphaBits(0); + } + if(Debug.debugAll()) { + if(cmBitsPerPixel!=bitsPerPixel) { + System.err.println("AWT Colormodel bits per components/pixel mismatch: "+bitsPerPixel+" != "+cmBitsPerPixel); + } + } + return capabilities; + } + + @Override + public String toString() { + return getClass().getSimpleName()+"[" + getScreen() + + ",\n\tchosen " + capabilitiesChosen+ + ",\n\trequested " + capabilitiesRequested+ + ",\n\t" + config + + ",\n\tencapsulated "+encapsulated+"]"; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java new file mode 100644 index 000000000..66a63bfcd --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow.awt; + +import javax.media.nativewindow.*; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import javax.media.nativewindow.AbstractGraphicsDevice; + +/** A wrapper for an AWT GraphicsDevice allowing it to be + handled in a toolkit-independent manner. */ + +public class AWTGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + private GraphicsDevice device; + private String subType; + + protected AWTGraphicsDevice(GraphicsDevice device, int unitID) { + super(NativeWindowFactory.TYPE_AWT, device.getIDstring(), unitID); + this.device = device; + this.subType = null; + } + + public static AbstractGraphicsDevice createDevice(GraphicsDevice awtDevice, int unitID) { + if(null==awtDevice) { + awtDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + unitID = AbstractGraphicsDevice.DEFAULT_UNIT; + } + return new AWTGraphicsDevice(awtDevice, unitID); + } + + @Override + public Object clone() { + return super.clone(); + } + + public GraphicsDevice getGraphicsDevice() { + return device; + } + + /** + * In case the native handle was specified, e.g. using X11, + * we shall be able to mark it.<br> + * This will also set the subType, queried with {@link #getSubType()} + * and reset the ToolkitLock type with {@link NativeWindowFactory#createDefaultToolkitLock(java.lang.String, long)} + * and {@link #setToolkitLock(javax.media.nativewindow.ToolkitLock)}. + */ + public void setSubType(String subType, long handle) { + this.handle = handle; + this.subType = subType; + setToolkitLock( NativeWindowFactory.createDefaultToolkitLock(subType, handle) ); + } + + public String getSubType() { + return subType; + } + + @Override + public String toString() { + return getClass().getSimpleName()+"[type "+getType()+"[subType "+getSubType()+"], connection "+getConnection()+", unitID "+getUnitID()+", awtDevice "+device+", handle 0x"+Long.toHexString(getHandle())+"]"; + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java new file mode 100644 index 000000000..383dcae80 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow.awt; + +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import javax.media.nativewindow.*; +import javax.media.nativewindow.AbstractGraphicsDevice; + +/** A wrapper for an AWT GraphicsDevice (screen) allowing it to be + handled in a toolkit-independent manner. */ + +public class AWTGraphicsScreen extends DefaultGraphicsScreen implements Cloneable { + + public AWTGraphicsScreen(AWTGraphicsDevice device) { + super(device, findScreenIndex(device.getGraphicsDevice())); + } + + public static GraphicsDevice getScreenDevice(int index) { + if(index<0) return null; + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + if(index<gs.length) { + return gs[index]; + } + return null; + } + + public static int findScreenIndex(GraphicsDevice awtDevice) { + if(null==awtDevice) return -1; + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + for (int j = 0; j < gs.length; j++) { + if(gs[j] == awtDevice) return j; + } + return -1; + } + + public static AbstractGraphicsScreen createScreenDevice(GraphicsDevice awtDevice, int unitID) { + AWTGraphicsDevice device = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(awtDevice, unitID); + return new AWTGraphicsScreen(device); + } + + public static AbstractGraphicsScreen createScreenDevice(int index, int unitID) { + GraphicsDevice awtDevice = getScreenDevice(index); + return createScreenDevice(awtDevice, unitID); + } + + public static AbstractGraphicsScreen createDefault() { + return createScreenDevice(-1, AbstractGraphicsDevice.DEFAULT_UNIT); + } + + public Object clone() { + return super.clone(); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTWindowClosingProtocol.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTWindowClosingProtocol.java new file mode 100644 index 000000000..e7db942e4 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTWindowClosingProtocol.java @@ -0,0 +1,139 @@ +/** + * 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 javax.media.nativewindow.awt; + +import java.awt.Component; +import java.awt.Window; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import javax.media.nativewindow.WindowClosingProtocol; +import jogamp.nativewindow.awt.AWTMisc; + +public class AWTWindowClosingProtocol implements WindowClosingProtocol { + + private Component comp; + private Runnable closingOperation; + private volatile boolean closingListenerSet = false; + private Object closingListenerLock = new Object(); + private int defaultCloseOperation = DISPOSE_ON_CLOSE; + private boolean defaultCloseOperationSetByUser = false; + + public AWTWindowClosingProtocol(Component comp, Runnable closingOperation) { + this.comp = comp; + this.closingOperation = closingOperation; + } + + class WindowClosingAdapter extends WindowAdapter { + @Override + public void windowClosing(WindowEvent e) { + int op = AWTWindowClosingProtocol.this.getDefaultCloseOperation(); + + if( DISPOSE_ON_CLOSE == op ) { + // we have to issue this call right away, + // otherwise the window gets destroyed + closingOperation.run(); + } + } + } + WindowListener windowClosingAdapter = new WindowClosingAdapter(); + + final boolean addClosingListenerImpl() { + Window w = AWTMisc.getWindow(comp); + if(null!=w) { + w.addWindowListener(windowClosingAdapter); + return true; + } + return false; + } + + /** + * Adds this closing listener to the components Window if exist and only one time.<br> + * Hence you may call this method every time to ensure it has been set, + * ie in case the Window parent is not available yet. + * + * @return + */ + public final boolean addClosingListenerOneShot() { + if(!closingListenerSet) { // volatile: ok + synchronized(closingListenerLock) { + if(!closingListenerSet) { + closingListenerSet=addClosingListenerImpl(); + return closingListenerSet; + } + } + } + return false; + } + + public final boolean removeClosingListener() { + if(closingListenerSet) { // volatile: ok + synchronized(closingListenerLock) { + if(closingListenerSet) { + Window w = AWTMisc.getWindow(comp); + if(null!=w) { + w.removeWindowListener(windowClosingAdapter); + closingListenerSet = false; + return true; + } + } + } + } + return false; + } + + /** + * + * @return the user set close operation if set by {@link #setDefaultCloseOperation(int) setDefaultCloseOperation(int)}, + * otherwise return the AWT/Swing close operation value translated to + * a {@link WindowClosingProtocol} value . + */ + public final int getDefaultCloseOperation() { + int op = -1; + synchronized(closingListenerLock) { + if(defaultCloseOperationSetByUser) { + op = defaultCloseOperation; + } + } + if(0 <= op) { + return op; + } + // User didn't determine the behavior, use underlying AWT behavior + return AWTMisc.getNWClosingOperation(comp); + } + + public final int setDefaultCloseOperation(int op) { + synchronized(closingListenerLock) { + int _op = defaultCloseOperation; + defaultCloseOperation = op; + defaultCloseOperationSetByUser = true; + return _op; + } + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java new file mode 100644 index 000000000..2dfd9f0ee --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow.egl; + +import javax.media.nativewindow.*; + +/** Encapsulates a graphics device on EGL platforms. + */ + +public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + boolean closeDisplay = false; + + /** + * Note that this is not an open connection, ie no native display handle exist. + * This constructor exist to setup a default device connection/unit.<br> + */ + public EGLGraphicsDevice(String connection, int unitID) { + super(NativeWindowFactory.TYPE_EGL, connection, unitID); + } + + /** Constructs a new EGLGraphicsDevice corresponding to the given EGL display handle. */ + public EGLGraphicsDevice(long eglDisplay, String connection, int unitID) { + super(NativeWindowFactory.TYPE_EGL, connection, unitID, eglDisplay); + } + + public Object clone() { + return super.clone(); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java new file mode 100644 index 000000000..02c63758f --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow.macosx; + +import javax.media.nativewindow.*; + +/** Encapsulates a graphics device on MacOSX platforms. + */ + +public class MacOSXGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + /** Constructs a new MacOSXGraphicsDevice */ + public MacOSXGraphicsDevice(int unitID) { + super(NativeWindowFactory.TYPE_MACOSX, AbstractGraphicsDevice.DEFAULT_CONNECTION, unitID); + } + + public Object clone() { + return super.clone(); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/package.html b/src/nativewindow/classes/javax/media/nativewindow/package.html new file mode 100644 index 000000000..14730a548 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/package.html @@ -0,0 +1,117 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> + <title>NativeWindow Protocol Draft Public Review Specification</title> +</head> + <body> + +<h2><i>NativeWindow Protocol</i> Specification Overview</h2> + +<h3>Preface</h3> + This specification, an optional set of packages, describing a <i>protocol</i> for a + <i>native windowing interface</i> binding to Java(TM).<br> + Currently specified <i>native windowing systems</i> are:<br><br> + <ul> + <li> EGL/OpenKODE Windowing System</li> + <li> X11 Windowing System</li> + <li> Microsoft Windows</li> + <li> Apple MacOSX</li> + <li> Java's AWT</li> + </ul> + <br> + However, any other native windowing system may be added to the implementation, + using a generic string identifier and an optional specialisation of:<br><br> + <ul> + <li>{@link javax.media.nativewindow.AbstractGraphicsDevice AbstractGraphicsDevice},<br> + <br> + Shall return the new string identifier with {@link javax.media.nativewindow.AbstractGraphicsDevice#getType() getType()}</li> + <li>{@link javax.media.nativewindow.AbstractGraphicsScreen AbstractGraphicsScreen}</li> + <li>{@link javax.media.nativewindow.AbstractGraphicsConfiguration AbstractGraphicsConfiguration}</li> + </ul> + <br> + The implementor has to provide the following:<br><br> + <ul> + <li> The specialisation of the abstract class {@link javax.media.nativewindow.NativeWindowFactory NativeWindowFactory}<br> + <br> + shall be registered with {@link javax.media.nativewindow.NativeWindowFactory#registerFactory NativeWindowFactory.registerFactory(..)}.</li> + + <li> The specialisation of the abstract class {@link javax.media.nativewindow.GraphicsConfigurationFactory GraphicsConfigurationFactory}<br> + <br> + shall be registered with {@link javax.media.nativewindow.GraphicsConfigurationFactory#registerFactory GraphicsConfigurationFactory.registerFactory(..)}.</li> + </ul><br> + This protocol <i>does not</i> describe how to <i>create</i> native windows, but how to <i>bind</i> a native surface to an implementation of + and window to an implementation of {@link javax.media.nativewindow.NativeSurface NativeSurface}.<br> + {@link javax.media.nativewindow.NativeWindow NativeWindow} specializes the NativeSurface.<br> + However, an implementation of this protocol (e.g. {@link com.jogamp.newt}) may support the creation.<br> + +<h3>Dependencies</h3> + This binding has dependencies to the following: + <ul> + <li> Either of the following Java implementations:<br/> + <ul> + <li> <a href="http://java.sun.com/j2se/1.5.0/docs/api/">Java SE 1.5 or later</a> </li> + <li> A mobile JavaVM with language 1.5 support, ie: + <ul> + <li> <a href="http://developer.android.com/reference/packages.html">Dalvik API Level 7</a> </li> + <li> <a href="http://jamvm.sourceforge.net/">JamVM</a> </li> + </ul> + with + <ul> + <li> <a href="http://java.sun.com/products/foundation/">Foundation Profile 1.1.2 (JSR 219)</a> </li> + <li> <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/nio/package-summary.html"> Java 1.4 <i>java.nio</i> implementation</a> </li> + </ul></li> + </ul></li> + </ul> + <br> + +<h3>Package Structure</h3> + The packages defined by this specification include:<br/><br/> +<ul> + <li>The <b>javax.media.nativewindow</b> package<br> + <br> + This package contains Java bindings for a native windowing system.<br> + Subsequent packages contain marker type classes, containing native characteristics of the windowing system. + + <ul> + <li>The <b>javax.media.nativewindow.awt</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the AWT windowing system.</li> + + <li>The <b>javax.media.nativewindow.x11</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the X11 windowing system.</li> + + <li>The <b>javax.media.nativewindow.windows</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the Windows windowing system.</li> + + <li>The <b>javax.media.nativewindow.macosx</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the MacOSX windowing system.</li> + + <li>The <b>javax.media.nativewindow.egl</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the EGL/OpenKODE windowing system.</li> + </ul></li> +</ul> + +<h3>Factory Model</h3> +Running on a platform with a supported windowing system, the factory model shall be used +to instantiate a native window, see {@link javax.media.nativewindow.NativeWindowFactory NativeWindowFactory}.<br> +The implementor has to specialize +All supported +Regardless of the knowledge of the underly +<br> + +<h3>Revision History<br> + </h3> + +<ul> +<li> Early Draft Review, June 2009</li> +<li> 2.0.0 Maintenance Release, February 2011</li> +</ul> + <br> + <br> + <br> +</body> +</html> diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java new file mode 100644 index 000000000..4151c1537 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java @@ -0,0 +1,96 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright (c) 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 javax.media.nativewindow.util; + +public class Dimension implements Cloneable, DimensionReadOnly { + int width; + int height; + + public Dimension() { + this(0, 0); + } + + public Dimension(int width, int height) { + if(width<0 || height<0) { + throw new IllegalArgumentException("width and height must be within: ["+0+".."+Integer.MAX_VALUE+"]"); + } + this.width=width; + this.height=height; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public int getWidth() { return width; } + public int getHeight() { return height; } + + public void setWidth(int width) { + this.width = width; + } + public void setHeight(int height) { + this.height = height; + } + public Dimension scale(int s) { + width *= s; + height *= s; + return this; + } + public Dimension add(Dimension pd) { + width += pd.width ; + height += pd.height ; + return this; + } + + public String toString() { + return new String(width+" x "+height); + } + + public boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof Dimension) { + Dimension p = (Dimension)obj; + return height == p.height && + width == p.width ; + } + return false; + } + + public int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + width; + return ((hash << 5) - hash) + height; + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/DimensionReadOnly.java b/src/nativewindow/classes/javax/media/nativewindow/util/DimensionReadOnly.java new file mode 100644 index 000000000..442afd4ba --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/DimensionReadOnly.java @@ -0,0 +1,55 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright (c) 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 javax.media.nativewindow.util; + +/** Immutable Dimension Interface, consisting of it's read only components:<br> + * <ul> + * <li><code>width</code></li> + * <li><code>height</code></li> + * </ul> + */ +public interface DimensionReadOnly extends Cloneable { + + int getHeight(); + + int getWidth(); + + /** + * Checks whether two dimensions objects are equal. Two instances + * of <code>DimensionReadOnly</code> are equal if two components + * <code>height</code> and <code>width</code> are equal. + * @return <code>true</code> if the two dimensions are equal; + * otherwise <code>false</code>. + */ + boolean equals(Object obj); + + int hashCode(); + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java new file mode 100644 index 000000000..96a45b7b1 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ +package javax.media.nativewindow.util; + +/** + * Simple class representing insets. + * + * @author tdv + */ +public class Insets implements Cloneable { + public int top; + public int left; + public int bottom; + public int right; + public int hash; + + /** + * Creates and initializes a new <code>Insets</code> object with the + * specified top, left, bottom, and right insets. + * @param top the inset from the top. + * @param left the inset from the left. + * @param bottom the inset from the bottom. + * @param right the inset from the right. + */ + public Insets(int top, int left, int bottom, int right) { + this.top = top; + this.left = left; + this.bottom = bottom; + this.right = right; + this.hash = computeHashCode(); + } + + /** + * Checks whether two insets objects are equal. Two instances + * of <code>Insets</code> are equal if the four integer values + * of the fields <code>top</code>, <code>left</code>, + * <code>bottom</code>, and <code>right</code> are all equal. + * @return <code>true</code> if the two insets are equal; + * otherwise <code>false</code>. + */ + public boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof Insets) { + Insets insets = (Insets)obj; + return ((top == insets.top) && (left == insets.left) && + (bottom == insets.bottom) && (right == insets.right)); + } + return false; + } + + /** + * Returns the hash code for this Insets. + * + * @return a hash code for this Insets. + */ + public int hashCode() { + return hash; + } + + public String toString() { + return getClass().getName() + "[top=" + top + ",left=" + left + + ",bottom=" + bottom + ",right=" + right + "]"; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + protected int computeHashCode() { + int sum1 = left + bottom; + int sum2 = right + top; + int val1 = sum1 * (sum1 + 1)/2 + left; + int val2 = sum2 * (sum2 + 1)/2 + top; + int sum3 = val1 + val2; + return sum3 * (sum3 + 1)/2 + val2; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Point.java b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java new file mode 100644 index 000000000..6db0ecfe2 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java @@ -0,0 +1,96 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright (c) 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 javax.media.nativewindow.util; + +public class Point implements Cloneable, PointReadOnly { + int x; + int y; + + public Point(int x, int y) { + this.x=x; + this.y=y; + } + + public Point() { + this(0, 0); + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof Point) { + Point p = (Point)obj; + return y == p.y && x == p.x; + } + return false; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + x; + hash = ((hash << 5) - hash) + y; + return hash; + } + + public String toString() { + return new String( x + " / " + y ); + } + + public void setX(int x) { this.x = x; } + public void setY(int y) { this.y = y; } + + public Point translate(Point pd) { + x += pd.x ; + y += pd.y ; + return this; + } + + public Point translate(int dx, int dy) { + x += dx ; + y += dy ; + return this; + } + +} diff --git a/src/jogamp/graph/math/MathFloat.java b/src/nativewindow/classes/javax/media/nativewindow/util/PointReadOnly.java index 0b8d69eba..9caaf7fee 100644 --- a/src/jogamp/graph/math/MathFloat.java +++ b/src/nativewindow/classes/javax/media/nativewindow/util/PointReadOnly.java @@ -1,45 +1,50 @@ -/**
- * Copyright 2011 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package jogamp.graph.math;
-
-public class MathFloat {
-
- public static final float E = 2.7182818284590452354f;
-
- public static final float PI = 3.14159265358979323846f;
-
- public static float abs(float a) { return (float) java.lang.Math.abs(a); }
- public static float pow(float a, float b) { return (float) java.lang.Math.pow(a, b); }
-
- public static float sin(float a) { return (float) java.lang.Math.sin(a); }
- public static float cos(float a) { return (float) java.lang.Math.cos(a); }
- public static float acos(float a) { return (float) java.lang.Math.acos(a); }
-
- public static float sqrt(float a) { return (float) java.lang.Math.sqrt(a); }
-
-}
+/** + * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright (c) 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 javax.media.nativewindow.util; + +/** Immutable Point interface */ +public interface PointReadOnly extends Cloneable { + + int getX(); + + int getY(); + + /** + * Checks whether two points objects are equal. Two instances + * of <code>PointReadOnly</code> are equal if the two components + * <code>y</code> and <code>x</code> are equal. + * @return <code>true</code> if the two points are equal; + * otherwise <code>false</code>. + */ + public boolean equals(Object obj); + + public int hashCode(); + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java b/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java new file mode 100644 index 000000000..ba24bc64e --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java @@ -0,0 +1,88 @@ +/** + * 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 javax.media.nativewindow.util; + +public class Rectangle implements Cloneable, RectangleReadOnly { + int x; + int y; + int width; + int height; + + public Rectangle() { + this(0, 0, 0, 0); + } + + public Rectangle(int x, int y, int width, int height) { + this.x=x; + this.y=y; + this.width=width; + this.height=height; + } + + protected Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public int getX() { return x; } + public int getY() { return y; } + public int getWidth() { return width; } + public int getHeight() { return height; } + public void setX(int x) { this.x = x; } + public void setY(int y) { this.y = y; } + public void setWidth(int width) { this.width = width; } + public void setHeight(int height) { this.height = height; } + + public boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof Rectangle) { + Rectangle rect = (Rectangle)obj; + return (y == rect.y) && (x == rect.x) && + (height == rect.height) && (width == rect.width); + } + return false; + } + + public int hashCode() { + int sum1 = x + height; + int sum2 = width + y; + int val1 = sum1 * (sum1 + 1)/2 + x; + int val2 = sum2 * (sum2 + 1)/2 + y; + int sum3 = val1 + val2; + return sum3 * (sum3 + 1)/2 + val2; + } + + public String toString() { + return new String("[ "+x+" / "+y+" "+width+" x "+height+" ]"); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/RectangleReadOnly.java b/src/nativewindow/classes/javax/media/nativewindow/util/RectangleReadOnly.java new file mode 100644 index 000000000..81a5a9f86 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/RectangleReadOnly.java @@ -0,0 +1,54 @@ +/** + * 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 javax.media.nativewindow.util; + +/** Immutable Rectangle interface */ +public interface RectangleReadOnly extends Cloneable { + + int getHeight(); + + int getWidth(); + + int getX(); + + int getY(); + + /** + * Checks whether two rect objects are equal. Two instances + * of <code>Rectangle</code> are equal if the four integer values + * of the fields <code>y</code>, <code>x</code>, + * <code>height</code>, and <code>width</code> are all equal. + * @return <code>true</code> if the two rectangles are equal; + * otherwise <code>false</code>. + */ + boolean equals(Object obj); + + int hashCode(); + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java b/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java new file mode 100644 index 000000000..ea098b967 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java @@ -0,0 +1,95 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright (c) 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 javax.media.nativewindow.util; + +/** Immutable SurfaceSize Class, consisting of it's read only components:<br> + * <ul> + * <li>{@link javax.media.nativewindow.util.DimensionReadOnly} size in pixels</li> + * <li><code>bits per pixel</code></li> + * </ul> + */ +public class SurfaceSize implements Cloneable { + DimensionReadOnly resolution; + int bitsPerPixel; + + public SurfaceSize(DimensionReadOnly resolution, int bitsPerPixel) { + if(null==resolution || bitsPerPixel<=0) { + throw new IllegalArgumentException("resolution must be set and bitsPerPixel greater 0"); + } + this.resolution=resolution; + this.bitsPerPixel=bitsPerPixel; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public final DimensionReadOnly getResolution() { + return resolution; + } + + public final int getBitsPerPixel() { + return bitsPerPixel; + } + + public final String toString() { + return new String("[ "+resolution+" x "+bitsPerPixel+" bpp ]"); + } + + /** + * Checks whether two size objects are equal. Two instances + * of <code>SurfaceSize</code> are equal if the two components + * <code>resolution</code> and <code>bitsPerPixel</code> + * are equal. + * @return <code>true</code> if the two dimensions are equal; + * otherwise <code>false</code>. + */ + public final boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof SurfaceSize) { + SurfaceSize p = (SurfaceSize)obj; + return getResolution().equals(p.getResolution()) && + getBitsPerPixel() == p.getBitsPerPixel(); + } + return false; + } + + public final int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + getResolution().hashCode(); + hash = ((hash << 5) - hash) + getBitsPerPixel(); + return hash; + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java new file mode 100644 index 000000000..5d0129e0d --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow.windows; + +import javax.media.nativewindow.*; + +/** + * Encapsulates a graphics device on Windows platforms.<br> + */ +public class WindowsGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + /** Constructs a new WindowsGraphicsDevice */ + public WindowsGraphicsDevice(int unitID) { + this(AbstractGraphicsDevice.DEFAULT_CONNECTION, unitID); + } + + public WindowsGraphicsDevice(String connection, int unitID) { + super(NativeWindowFactory.TYPE_WINDOWS, connection, unitID); + } + + public Object clone() { + return super.clone(); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java new file mode 100644 index 000000000..100b6b839 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow.x11; + +import javax.media.nativewindow.*; + +import jogamp.nativewindow.x11.XVisualInfo; + +/** Encapsulates a graphics configuration, or OpenGL pixel format, on + X11 platforms. Objects of this type are returned from {@link + javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration + GraphicsConfigurationFactory.chooseGraphicsConfiguration()} on X11 + platforms when toolkits other than the AWT are being used. */ + +public class X11GraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable { + private XVisualInfo info; + + public X11GraphicsConfiguration(X11GraphicsScreen screen, + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, + XVisualInfo info) { + super(screen, capsChosen, capsRequested); + this.info = info; + } + + @Override + public Object clone() { + return super.clone(); + } + + public XVisualInfo getXVisualInfo() { + return info; + } + + protected void setXVisualInfo(XVisualInfo info) { + this.info = info; + } + + public long getVisualID() { + return (null!=info)?info.getVisualid():0; + } + + @Override + public String toString() { + return getClass().getSimpleName()+"["+getScreen()+", visualID 0x" + Long.toHexString(getVisualID()) + + ",\n\tchosen " + capabilitiesChosen+ + ",\n\trequested " + capabilitiesRequested+ + "]"; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java new file mode 100644 index 000000000..48fd63e3c --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow.x11; + +import jogamp.nativewindow.Debug; +import jogamp.nativewindow.x11.X11Util; +import javax.media.nativewindow.DefaultGraphicsDevice; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.ToolkitLock; + +/** Encapsulates a graphics device on X11 platforms. + */ + +public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + public static final boolean DEBUG = Debug.debug("GraphicsDevice"); + boolean closeDisplay = false; + + /** Constructs a new X11GraphicsDevice corresponding to the given connection and default + * {@link javax.media.nativewindow.ToolkitLock} via {@link NativeWindowFactory#createDefaultToolkitLock(java.lang.String, long)}.<br> + * Note that this is not an open connection, ie no native display handle exist. + * This constructor exist to setup a default device connection. + */ + public X11GraphicsDevice(String connection, int unitID) { + super(NativeWindowFactory.TYPE_X11, connection, unitID); + } + + /** Constructs a new X11GraphicsDevice corresponding to the given native display handle and default + * {@link javax.media.nativewindow.ToolkitLock} via {@link NativeWindowFactory#createDefaultToolkitLock(java.lang.String, long)}. + */ + public X11GraphicsDevice(long display, int unitID) { + // FIXME: derive unitID from connection could be buggy, one DISPLAY for all screens for example.. + super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), unitID, display); + if(0==display) { + throw new NativeWindowException("null display"); + } + } + + /** + * @param display the Display connection + * @param locker custom {@link javax.media.nativewindow.ToolkitLock}, eg to force null locking in NEWT + */ + public X11GraphicsDevice(long display, int unitID, ToolkitLock locker) { + super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), unitID, display, locker); + if(0==display) { + throw new NativeWindowException("null display"); + } + } + + public Object clone() { + return super.clone(); + } + + public void setCloseDisplay(boolean close) { + closeDisplay = close; + if(DEBUG && close) { + System.err.println(Thread.currentThread().getName() + " - X11GraphicsDevice.setCloseDisplay(true): "+this); + } + } + public boolean close() { + // FIXME: shall we respect the unitID ? + if(closeDisplay && 0 != handle) { + if(DEBUG) { + System.err.println(Thread.currentThread().getName() + " - X11GraphicsDevice.close(): "+this); + } + X11Util.closeDisplay(handle); + handle = 0; + return true; + } + return false; + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java new file mode 100644 index 000000000..ffe84cb6d --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package javax.media.nativewindow.x11; + +import javax.media.nativewindow.*; +import jogamp.nativewindow.x11.X11Util; + +/** Encapsulates a screen index on X11 + platforms. Objects of this type are passed to {@link + javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration + GraphicsConfigurationFactory.chooseGraphicsConfiguration()} on X11 + platforms when toolkits other than the AWT are being used. */ + +public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneable { + + /** Constructs a new X11GraphicsScreen corresponding to the given native screen index. */ + public X11GraphicsScreen(X11GraphicsDevice device, int screen) { + super(device, fetchScreen(device, screen)); + } + + public static AbstractGraphicsScreen createScreenDevice(long display, int screenIdx) { + if(0==display) throw new NativeWindowException("display is null"); + return new X11GraphicsScreen(new X11GraphicsDevice(display, AbstractGraphicsDevice.DEFAULT_UNIT), screenIdx); + } + + public long getDefaultVisualID() { + // It still could be an AWT hold handle .. + long display = getDevice().getHandle(); + int scrnIdx = X11Util.DefaultScreen(display); + return X11Util.DefaultVisualID(display, scrnIdx); + } + + private static int fetchScreen(X11GraphicsDevice device, int screen) { + // It still could be an AWT hold handle .. + long display = device.getHandle(); + if(X11Util.XineramaEnabled(display)) { + screen = 0; // Xinerama -> 1 screen + } + return screen; + } + + public Object clone() { + return super.clone(); + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/Debug.java b/src/nativewindow/classes/jogamp/nativewindow/Debug.java new file mode 100644 index 000000000..f1cd209dc --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/Debug.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.nativewindow; + +import java.security.*; + +/** Helper routines for logging and debugging. */ + +public class Debug { + // Some common properties + private static boolean verbose; + private static boolean debugAll; + private static AccessControlContext localACC; + + static { + localACC=AccessController.getContext(); + verbose = isPropertyDefined("nativewindow.verbose", true); + debugAll = isPropertyDefined("nativewindow.debug", true); + if (verbose) { + Package p = Package.getPackage("javax.media.nativewindow"); + System.err.println("NativeWindow specification version " + p.getSpecificationVersion()); + System.err.println("NativeWindow implementation version " + p.getImplementationVersion()); + System.err.println("NativeWindow implementation vendor " + p.getImplementationVendor()); + } + } + + static int getIntProperty(final String property, final boolean jnlpAlias) { + return getIntProperty(property, jnlpAlias, localACC); + } + + public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + int i=0; + try { + Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + i = iv.intValue(); + } catch (NumberFormatException nfe) {} + return i; + } + + static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { + return getBooleanProperty(property, jnlpAlias, localACC); + } + + public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + return b.booleanValue(); + } + + static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { + return isPropertyDefined(property, jnlpAlias, localACC); + } + + public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; + } + + static String getProperty(final String property, final boolean jnlpAlias) { + return getProperty(property, jnlpAlias, localACC); + } + + public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + String s=null; + if(null!=acc && acc.equals(localACC)) { + s = (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val=null; + try { + val = System.getProperty(property); + } catch (Exception e) {} + if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + val = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + return val; + } + }); + } else { + try { + s = System.getProperty(property); + } catch (Exception e) {} + if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + s = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + } + return s; + } + public static final String jnlp_prefix = "jnlp." ; + + public static boolean verbose() { + return verbose; + } + + public static boolean debugAll() { + return debugAll; + } + + public static boolean debug(String subcomponent) { + return debugAll() || isPropertyDefined("nativewindow.debug." + subcomponent, true); + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/DefaultGraphicsConfigurationFactoryImpl.java b/src/nativewindow/classes/jogamp/nativewindow/DefaultGraphicsConfigurationFactoryImpl.java new file mode 100644 index 000000000..f34b740d4 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/DefaultGraphicsConfigurationFactoryImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.nativewindow; + +import javax.media.nativewindow.*; + +public class DefaultGraphicsConfigurationFactoryImpl extends GraphicsConfigurationFactory { + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, CapabilitiesChooser chooser, AbstractGraphicsScreen screen) { + return new DefaultGraphicsConfiguration(screen, capsChosen, capsRequested); + } +} diff --git a/src/jogamp/graph/font/typecast/TypecastFontConstructor.java b/src/nativewindow/classes/jogamp/nativewindow/NWJNILibLoader.java index 5fb9d32f7..33e2905a0 100644 --- a/src/jogamp/graph/font/typecast/TypecastFontConstructor.java +++ b/src/nativewindow/classes/jogamp/nativewindow/NWJNILibLoader.java @@ -1,16 +1,16 @@ /** - * Copyright 2011 JogAmp Community. All rights reserved. + * 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 @@ -20,34 +20,28 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package jogamp.graph.font.typecast; - -import java.io.File; -import java.io.IOException; + -import jogamp.graph.font.FontConstructor; +package jogamp.nativewindow; -import net.java.dev.typecast.ot.OTFontCollection; +import java.security.AccessController; +import java.security.PrivilegedAction; +import com.jogamp.common.jvm.JNILibLoaderBase; -import com.jogamp.graph.font.Font; - - -public class TypecastFontConstructor implements FontConstructor { - - public Font create(String path) { - OTFontCollection fontset; - try { - fontset = OTFontCollection.create(new File(path)); - return new TypecastFont(fontset); - } catch (IOException e) { - e.printStackTrace(); - } +public class NWJNILibLoader extends JNILibLoaderBase { + + public static void loadNativeWindow(final String ossuffix) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("nativewindow_"+ossuffix, null, false); return null; - } - -}
\ No newline at end of file + } + }); + } + +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java new file mode 100644 index 000000000..3db8f32d2 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.nativewindow; + +import com.jogamp.common.util.*; +import java.lang.reflect.*; + +import javax.media.nativewindow.*; + +public class NativeWindowFactoryImpl extends NativeWindowFactory { + private static final ToolkitLock nullToolkitLock = new NullToolkitLock(); + + public static ToolkitLock getNullToolkitLock() { + return nullToolkitLock; + } + + // This subclass of NativeWindowFactory handles the case of + // NativeWindows being passed in + protected NativeWindow getNativeWindowImpl(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException { + if (null == winObj) { + throw new IllegalArgumentException("winObj is null"); + } + if (winObj instanceof NativeWindow) { + // Use the NativeWindow directly + return (NativeWindow) winObj; + } + + if (null == config) { + throw new IllegalArgumentException("AbstractGraphicsConfiguration is null with a non NativeWindow object"); + } + + if (NativeWindowFactory.isAWTAvailable() && ReflectionUtil.instanceOf(winObj, AWTComponentClassName)) { + return getAWTNativeWindow(winObj, config); + } + + throw new IllegalArgumentException("Target window object type " + + winObj.getClass().getName() + " is unsupported; expected " + + "javax.media.nativewindow.NativeWindow or "+AWTComponentClassName); + } + + private Constructor nativeWindowConstructor = null; + + private NativeWindow getAWTNativeWindow(Object winObj, AbstractGraphicsConfiguration config) { + if (nativeWindowConstructor == null) { + try { + String osType = getNativeWindowType(true); + String windowClassName = null; + + // We break compile-time dependencies on the AWT here to + // make it easier to run this code on mobile devices + + if (osType.equals(TYPE_WINDOWS)) { + windowClassName = "jogamp.nativewindow.jawt.windows.WindowsJAWTWindow"; + } else if (osType.equals(TYPE_MACOSX)) { + windowClassName = "jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow"; + } else if (osType.equals(TYPE_X11)) { + // Assume Linux, Solaris, etc. Should probably test for these explicitly. + windowClassName = "jogamp.nativewindow.jawt.x11.X11JAWTWindow"; + } else { + throw new IllegalArgumentException("OS " + getNativeOSName(false) + " not yet supported"); + } + + nativeWindowConstructor = ReflectionUtil.getConstructor( + windowClassName, new Class[] { Object.class, AbstractGraphicsConfiguration.class }, + getClass().getClassLoader()); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + try { + return (NativeWindow) nativeWindowConstructor.newInstance(new Object[] { winObj, config }); + } catch (Exception ie) { + throw new IllegalArgumentException(ie); + } + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/NullToolkitLock.java b/src/nativewindow/classes/jogamp/nativewindow/NullToolkitLock.java new file mode 100644 index 000000000..2056d205e --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/NullToolkitLock.java @@ -0,0 +1,55 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.nativewindow; + +import javax.media.nativewindow.ToolkitLock; + +/** + * Implementing a singleton global recursive {@link javax.media.nativewindow.ToolkitLock} + * without any locking. Since there is no locking it all, + * it is intrinsically recursive. + */ +public class NullToolkitLock implements ToolkitLock { + + /** Singleton via {@link NativeWindowFactoryImpl#getNullToolkitLock()} */ + protected NullToolkitLock() { } + + public final void lock() { + if(TRACE_LOCK) { + String msg = "NullToolkitLock.lock()"; + System.err.println(msg); + // Throwable t = new Throwable(msg); + // t.printStackTrace(); + } + } + + public final void unlock() { + if(TRACE_LOCK) { System.err.println("NullToolkitLock.unlock()"); } + } +} diff --git a/src/com/jogamp/graph/geom/Triangle.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java index d13e8ddb1..4c2b1c875 100644 --- a/src/com/jogamp/graph/geom/Triangle.java +++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java @@ -25,55 +25,46 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package com.jogamp.graph.geom; -public class Triangle { - private int id = Integer.MAX_VALUE; - final private Vertex[] vertices; - private boolean[] boundaryEdges = new boolean[3]; - private boolean[] boundaryVertices = null; +package jogamp.nativewindow; - public Triangle(Vertex ... v123){ - vertices = v123; - } +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.ProxySurface; +import javax.media.nativewindow.SurfaceChangeable; - public int getId() { - return id; - } - public void setId(int id) { - this.id = id; - } +public class WrappedSurface extends ProxySurface implements SurfaceChangeable { + protected long surfaceHandle; - public Vertex[] getVertices() { - return vertices; - } - - public boolean isEdgesBoundary() { - return boundaryEdges[0] || boundaryEdges[1] || boundaryEdges[2]; - } - - public boolean isVerticesBoundary() { - return boundaryVertices[0] || boundaryVertices[1] || boundaryVertices[2]; - } + public WrappedSurface(AbstractGraphicsConfiguration cfg) { + this(cfg, 0); + } - public void setEdgesBoundary(boolean[] boundary) { - this.boundaryEdges = boundary; - } - - public boolean[] getEdgeBoundary() { - return boundaryEdges; - } - - public boolean[] getVerticesBoundary() { - return boundaryVertices; - } + public WrappedSurface(AbstractGraphicsConfiguration cfg, long handle) { + super(cfg); + surfaceHandle=handle; + } + + protected final void invalidateImpl() { + surfaceHandle = 0; + } - public void setVerticesBoundary(boolean[] boundaryVertices) { - this.boundaryVertices = boundaryVertices; - } - - public String toString() { - return "Tri ID: " + id + "\n" + vertices[0] + "\n" + vertices[1] + "\n" + vertices[2]; - } + public long getSurfaceHandle() { + return surfaceHandle; + } + + public void setSurfaceHandle(long surfaceHandle) { + this.surfaceHandle=surfaceHandle; + } + + protected int lockSurfaceImpl() { + return LOCK_SUCCESS; + } + + protected void unlockSurfaceImpl() { + } + + public String toString() { + return "WrappedSurface[config " + config + ", displayHandle 0x" + Long.toHexString(getDisplayHandle()) + ", surfaceHandle 0x" + Long.toHexString(getSurfaceHandle()) + ", size " + getWidth() + "x" + getHeight() + "]"; + } } diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java new file mode 100644 index 000000000..834d8a703 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java @@ -0,0 +1,96 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.nativewindow.awt; + +import java.awt.Window; +import java.awt.Component; +import java.awt.Container; +import java.awt.Frame; +import javax.swing.JFrame; +import javax.swing.WindowConstants; + +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.WindowClosingProtocol; +import javax.swing.MenuSelectionManager; + +public class AWTMisc { + + public static JFrame getJFrame(Component c) { + while (c != null && !(c instanceof JFrame)) { + c = c.getParent(); + } + return (JFrame) c; + } + + public static Frame getFrame(Component c) { + while (c != null && !(c instanceof Frame)) { + c = c.getParent(); + } + return (Frame) c; + } + + public static Window getWindow(Component c) { + while (c != null && !(c instanceof Window)) { + c = c.getParent(); + } + return (Window) c; + } + + public static Container getContainer(Component c) { + while (c != null && !(c instanceof Container)) { + c = c.getParent(); + } + return (Container) c; + } + + /** + * Issue this when your non AWT toolkit gains focus to clear AWT menu path + */ + public static void clearAWTMenus() { + MenuSelectionManager.defaultManager().clearSelectedPath(); + } + + public static int AWT2NWClosingOperation(int awtClosingOperation) { + switch (awtClosingOperation) { + case WindowConstants.DISPOSE_ON_CLOSE: + case WindowConstants.EXIT_ON_CLOSE: + return WindowClosingProtocol.DISPOSE_ON_CLOSE; + case WindowConstants.DO_NOTHING_ON_CLOSE: + case WindowConstants.HIDE_ON_CLOSE: + return WindowClosingProtocol.DO_NOTHING_ON_CLOSE; + default: + throw new NativeWindowException("Unhandled AWT Closing Operation: " + awtClosingOperation); + } + } + + public static int getNWClosingOperation(Component c) { + JFrame jf = getJFrame(c); + int op = (null != jf) ? jf.getDefaultCloseOperation() : WindowConstants.DO_NOTHING_ON_CLOSE ; + return AWT2NWClosingOperation(op); + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java new file mode 100644 index 000000000..1ac9e1709 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.nativewindow.jawt; + +import javax.media.nativewindow.NativeWindowFactory; +import jogamp.nativewindow.NWJNILibLoader; + +import java.awt.Toolkit; +import java.security.AccessController; +import java.security.PrivilegedAction; + +public class JAWTJNILibLoader extends NWJNILibLoader { + public static void loadAWTImpl() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + // Make sure that awt.dll is loaded before loading jawt.dll. Otherwise + // a Dialog with "awt.dll not found" might pop up. + // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4481947. + Toolkit.getDefaultToolkit(); + + // Must pre-load JAWT on all non-Mac platforms to + // ensure references from jogl_awt shared object + // will succeed since JAWT shared object isn't in + // default library path + if ( ! NativeWindowFactory.TYPE_MACOSX.equals( NativeWindowFactory.getNativeWindowType(false) ) ) { + try { + loadLibrary("jawt", null, true); + } catch (Throwable t) { + // It might be ok .. if it's already loaded + if(DEBUG) { + t.printStackTrace(); + } + } + } + return null; + } + }); + } +} diff --git a/src/com/jogamp/graph/curve/RegionFactory.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTToolkitLock.java index d3b978b8a..37e34c01c 100755..100644 --- a/src/com/jogamp/graph/curve/RegionFactory.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTToolkitLock.java @@ -1,62 +1,54 @@ -/**
- * 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.graph.curve;
-
-import javax.media.opengl.GLContext;
-import javax.media.opengl.GLException;
-
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-import jogamp.graph.curve.opengl.VBORegionSPES2;
-import jogamp.graph.curve.opengl.VBORegion2PES2;
-
-
-/** RegionFactory to create a Context specific Region implementation.
- *
- * @see Region
- */
-public class RegionFactory {
-
- /**Create a Region based on the GLContext attached
- * @param context the current {@link GLContext}
- * @param st the {@link ShaderState} object
- * @param type can be one of Region.SINGLE_PASS or Region.TWO_PASS
- * @return region
- */
- public static Region create(GLContext context, ShaderState st, int type){
- if( !context.isGL2ES2() ) {
- throw new GLException("At least a GL2ES2 GL context is required. Given: " + context);
- }
- if( Region.TWO_PASS == type ){
- return new VBORegion2PES2(context, st);
- }
- else{
- return new VBORegionSPES2(context);
- }
- }
-}
+/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.nativewindow.jawt; + +import javax.media.nativewindow.ToolkitLock; + +/** + * Implementing a singleton global recursive {@link javax.media.nativewindow.ToolkitLock} + * utilizing JAWT's AWT lock via {@link JAWTUtil#lockToolkit()}. + * <br> + * This strategy should only be used if AWT is using the underlying native windowing toolkit + * in a not intrinsic thread safe manner, e.g. under X11 where no XInitThreads() call + * is issued before any other X11 usage. This is the current situation for e.g. Webstart or Applets. + */ +public class JAWTToolkitLock implements ToolkitLock { + + /** Singleton via {@link JAWTUtil#getJAWTToolkitLock()} */ + protected JAWTToolkitLock() {} + + public final void lock() { + if(TRACE_LOCK) { System.err.println("JAWTToolkitLock.lock()"); } + JAWTUtil.lockToolkit(); + } + + public final void unlock() { + if(TRACE_LOCK) { System.err.println("JAWTToolkitLock.unlock()"); } + JAWTUtil.unlockToolkit(); + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java new file mode 100644 index 000000000..c1c97eece --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package jogamp.nativewindow.jawt; + +import jogamp.nativewindow.*; +import java.awt.EventQueue; + +import javax.media.nativewindow.*; + + +import java.awt.GraphicsEnvironment; +import java.awt.Toolkit; +import java.lang.reflect.*; +import java.security.*; +import java.util.ArrayList; +import java.util.Map; + +public class JAWTUtil { + protected static final boolean DEBUG = Debug.debug("JAWT"); + + // See whether we're running in headless mode + private static final boolean headlessMode; + + // Java2D magic .. + private static final Method isQueueFlusherThread; + private static final boolean j2dExist; + + private static final Method sunToolkitAWTLockMethod; + private static final Method sunToolkitAWTUnlockMethod; + private static final boolean hasSunToolkitAWTLock; + + private static final JAWTToolkitLock jawtToolkitLock; + + private static class PrivilegedDataBlob1 { + PrivilegedDataBlob1() { + ok = false; + } + Method sunToolkitAWTLockMethod; + Method sunToolkitAWTUnlockMethod; + boolean ok; + } + + static { + JAWTJNILibLoader.loadAWTImpl(); + JAWTJNILibLoader.loadNativeWindow("awt"); + + headlessMode = GraphicsEnvironment.isHeadless(); + + boolean ok = false; + Class jC = null; + Method m = null; + if (!headlessMode) { + try { + jC = Class.forName("jogamp.opengl.awt.Java2D"); + m = jC.getMethod("isQueueFlusherThread", (Class[])null); + ok = true; + } catch (Exception e) { + } + } + isQueueFlusherThread = m; + j2dExist = ok; + + PrivilegedDataBlob1 pdb1 = (PrivilegedDataBlob1) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + PrivilegedDataBlob1 d = new PrivilegedDataBlob1(); + try { + final Class sunToolkitClass = Class.forName("sun.awt.SunToolkit"); + d.sunToolkitAWTLockMethod = sunToolkitClass.getDeclaredMethod("awtLock", new Class[]{}); + d.sunToolkitAWTLockMethod.setAccessible(true); + d.sunToolkitAWTUnlockMethod = sunToolkitClass.getDeclaredMethod("awtUnlock", new Class[]{}); + d.sunToolkitAWTUnlockMethod.setAccessible(true); + d.ok=true; + } catch (Exception e) { + // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5 + } + return d; + } + }); + sunToolkitAWTLockMethod = pdb1.sunToolkitAWTLockMethod; + sunToolkitAWTUnlockMethod = pdb1.sunToolkitAWTUnlockMethod; + + boolean _hasSunToolkitAWTLock = false; + if ( pdb1.ok ) { + try { + sunToolkitAWTLockMethod.invoke(null, (Object[])null); + sunToolkitAWTUnlockMethod.invoke(null, (Object[])null); + _hasSunToolkitAWTLock = true; + } catch (Exception e) { + } + } + hasSunToolkitAWTLock = _hasSunToolkitAWTLock; + // hasSunToolkitAWTLock = false; + + jawtToolkitLock = new JAWTToolkitLock(); + + // trigger native AWT toolkit / properties initialization + Map desktophints = null; + try { + if(EventQueue.isDispatchThread()) { + desktophints = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); + } else { + final ArrayList desktophintsBucket = new ArrayList(1); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + Map _desktophints = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); + if(null!=_desktophints) { + desktophintsBucket.add(_desktophints); + } + } + }); + desktophints = ( desktophintsBucket.size() > 0 ) ? (Map)desktophintsBucket.get(0) : null ; + } + } catch (InterruptedException ex) { + ex.printStackTrace(); + } catch (InvocationTargetException ex) { + ex.printStackTrace(); + } + + if (DEBUG) { + System.err.println("JAWTUtil: Has sun.awt.SunToolkit.awtLock/awtUnlock " + hasSunToolkitAWTLock); + System.err.println("JAWTUtil: Has Java2D " + j2dExist); + System.err.println("JAWTUtil: Is headless " + headlessMode); + int hints = ( null != desktophints ) ? desktophints.size() : 0 ; + System.err.println("JAWTUtil: AWT Desktop hints " + hints); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public static boolean hasJava2D() { + return j2dExist; + } + + public static boolean isJava2DQueueFlusherThread() { + boolean b = false; + if(j2dExist) { + try { + b = ((Boolean)isQueueFlusherThread.invoke(null, (Object[])null)).booleanValue(); + } catch (Exception e) {} + } + return b; + } + + public static boolean isHeadlessMode() { + return headlessMode; + } + + /** + * Locks the AWT's global ReentrantLock.<br> + * + * JAWT's native Lock() function calls SunToolkit.awtLock(), + * which just uses AWT's global ReentrantLock.<br> + */ + public static void awtLock() { + if(hasSunToolkitAWTLock) { + try { + sunToolkitAWTLockMethod.invoke(null, (Object[])null); + } catch (Exception e) { + throw new NativeWindowException("SunToolkit.awtLock failed", e); + } + } else { + JAWT.getJAWT().Lock(); + } + } + + /** + * Unlocks the AWT's global ReentrantLock.<br> + * + * JAWT's native Unlock() function calls SunToolkit.awtUnlock(), + * which just uses AWT's global ReentrantLock.<br> + */ + public static void awtUnlock() { + if(hasSunToolkitAWTLock) { + try { + sunToolkitAWTUnlockMethod.invoke(null, (Object[])null); + } catch (Exception e) { + throw new NativeWindowException("SunToolkit.awtUnlock failed", e); + } + } else { + JAWT.getJAWT().Unlock(); + } + } + + public static void lockToolkit() throws NativeWindowException { + if(!headlessMode && !isJava2DQueueFlusherThread()) { + awtLock(); + } + } + + public static void unlockToolkit() { + if(!headlessMode && !isJava2DQueueFlusherThread()) { + awtUnlock(); + } + } + + public static JAWTToolkitLock getJAWTToolkitLock() { + return jawtToolkitLock; + } +} + diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java new file mode 100644 index 000000000..67f6fe4b8 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package jogamp.nativewindow.jawt; + +import com.jogamp.common.util.locks.RecursiveLock; + +import java.awt.Component; +import java.awt.Window; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Point; +import javax.media.nativewindow.util.Rectangle; + +public abstract class JAWTWindow implements NativeWindow { + protected static final boolean DEBUG = JAWTUtil.DEBUG; + + // lifetime: forever + protected Component component; + protected AbstractGraphicsConfiguration config; + + // lifetime: valid after lock, forever until invalidate + protected long drawable; + protected Rectangle bounds; + + public JAWTWindow(Object comp, AbstractGraphicsConfiguration config) { + if (config == null) { + throw new NativeWindowException("Error: AbstractGraphicsConfiguration is null"); + } + this.config = config; + init((Component)comp); + } + + private void init(Component windowObject) throws NativeWindowException { + invalidate(); + this.component = windowObject; + validateNative(); + } + protected abstract void validateNative() throws NativeWindowException; + + protected synchronized void invalidate() { + component = null; + drawable= 0; + bounds = new Rectangle(); + } + + protected final void updateBounds(JAWT_Rectangle jawtBounds) { + bounds.setX(jawtBounds.getX()); + bounds.setY(jawtBounds.getY()); + bounds.setWidth(jawtBounds.getWidth()); + bounds.setHeight(jawtBounds.getHeight()); + } + + /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */ + public final Rectangle getBounds() { return bounds; } + + public final Component getAWTComponent() { + return component; + } + + // + // SurfaceUpdateListener + // + + public final void surfaceUpdated(Object updater, NativeSurface ns, long when) { + // nop + } + + // + // NativeSurface + // + + private RecursiveLock surfaceLock = new RecursiveLock(); + + protected abstract int lockSurfaceImpl() throws NativeWindowException; + + public final int lockSurface() throws NativeWindowException { + surfaceLock.lock(); + int res = surfaceLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; + + if ( LOCK_SURFACE_NOT_READY == res ) { + try { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + adevice.lock(); + try { + res = lockSurfaceImpl(); + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + adevice.unlock(); + } + } + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + surfaceLock.unlock(); + } + } + } + return res; + } + + protected abstract void unlockSurfaceImpl() throws NativeWindowException; + + public final void unlockSurface() { + surfaceLock.validateLocked(); + + if (surfaceLock.getRecursionCount() == 0) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + try { + unlockSurfaceImpl(); + } finally { + adevice.unlock(); + } + } + surfaceLock.unlock(); + } + + public final boolean isSurfaceLockedByOtherThread() { + return surfaceLock.isLockedByOtherThread(); + } + + public final boolean isSurfaceLocked() { + return surfaceLock.isLocked(); + } + + public final Thread getSurfaceLockOwner() { + return surfaceLock.getOwner(); + } + + public final boolean surfaceSwap() { + return false; + } + + public final void surfaceUpdated(Object updater, NativeWindow window, long when) { } + + public final long getSurfaceHandle() { + return drawable; + } + public final AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + public final long getDisplayHandle() { + return config.getScreen().getDevice().getHandle(); + } + + public final int getScreenIndex() { + return config.getScreen().getIndex(); + } + + public final void setSize(int width, int height) { + component.setSize(width, height); + } + + public final int getWidth() { + return component.getWidth(); + } + + public final int getHeight() { + return component.getHeight(); + } + + // + // NativeWindow + // + + public synchronized void destroy() { + if(null!=component) { + if(component instanceof Window) { + ((Window)component).dispose(); + } + } + invalidate(); + } + + public final NativeWindow getParent() { + return null; + } + + public long getWindowHandle() { + return drawable; + } + + public final int getX() { + return component.getX(); + } + + public final int getY() { + return component.getY(); + } + + public Point getLocationOnScreen(Point storage) { + if( 0 != getWindowHandle() ) { + Point d; + // windowLock.lock(); + try { + d = getLocationOnScreenImpl(0, 0); + } finally { + // windowLock.unlock(); + } + if(null!=d) { + if(null!=storage) { + storage.translate(d.getX(),d.getY()); + return storage; + } + return d; + } + // fall through intended .. + } + + if(!Thread.holdsLock(component.getTreeLock())) { + return null; // avoid deadlock .. + } + java.awt.Point awtLOS = component.getLocationOnScreen(); + int dx = (int) ( awtLOS.getX() + .5 ) ; + int dy = (int) ( awtLOS.getY() + .5 ) ; + if(null!=storage) { + return storage.translate(dx, dy); + } + return new Point(dx, dy); + } + protected abstract Point getLocationOnScreenImpl(int x, int y); + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("JAWT-Window["+ + "windowHandle 0x"+Long.toHexString(getWindowHandle())+ + ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ + ", bounds "+bounds); + if(null!=component) { + sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + ", visible "+component.isVisible()); + } else { + sb.append(", component NULL"); + } + sb.append(", lockedExt "+isSurfaceLockedByOtherThread()+ + ",\n\tconfig "+config+ + ",\n\tawtComponent "+getAWTComponent()+"]"); + + return sb.toString(); + } + +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWT_PlatformInfo.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWT_PlatformInfo.java new file mode 100644 index 000000000..40d7b8032 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWT_PlatformInfo.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.nativewindow.jawt; + +/** Marker class for all window system-specific JAWT data structures. */ + +public interface JAWT_PlatformInfo { +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java new file mode 100644 index 000000000..9c29bbd52 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.nativewindow.jawt.macosx; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Point; + +import jogamp.nativewindow.jawt.JAWT; +import jogamp.nativewindow.jawt.JAWTFactory; +import jogamp.nativewindow.jawt.JAWTWindow; +import jogamp.nativewindow.jawt.JAWT_DrawingSurface; +import jogamp.nativewindow.jawt.JAWT_DrawingSurfaceInfo; + +public class MacOSXJAWTWindow extends JAWTWindow { + + public MacOSXJAWTWindow(Object comp, AbstractGraphicsConfiguration config) { + super(comp, config); + } + + protected void validateNative() throws NativeWindowException { + } + + protected int lockSurfaceImpl() throws NativeWindowException { + int ret = NativeWindow.LOCK_SUCCESS; + ds = JAWT.getJAWT().GetDrawingSurface(component); + if (ds == null) { + // Widget not yet realized + unlockSurfaceImpl(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + int res = ds.Lock(); + dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ; + if (!dsLocked) { + unlockSurfaceImpl(); + throw new NativeWindowException("Unable to lock surface"); + } + // See whether the surface changed and if so destroy the old + // OpenGL context so it will be recreated (NOTE: removeNotify + // should handle this case, but it may be possible that race + // conditions can cause this code to be triggered -- should test + // more) + if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { + ret = NativeWindow.LOCK_SURFACE_CHANGED; + } + if (firstLock) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + dsi = ds.GetDrawingSurfaceInfo(); + return null; + } + }); + } else { + dsi = ds.GetDrawingSurfaceInfo(); + } + if (dsi == null) { + unlockSurfaceImpl(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + firstLock = false; + macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo(); + if (macosxdsi == null) { + unlockSurfaceImpl(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + drawable = macosxdsi.getCocoaViewRef(); + + if (drawable == 0) { + unlockSurfaceImpl(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } else { + updateBounds(dsi.getBounds()); + } + return ret; + } + + protected void unlockSurfaceImpl() throws NativeWindowException { + if(null!=ds) { + if (null!=dsi) { + ds.FreeDrawingSurfaceInfo(dsi); + } + if (dsLocked) { + ds.Unlock(); + } + JAWT.getJAWT().FreeDrawingSurface(ds); + } + ds = null; + dsi = null; + macosxdsi = null; + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return null; // FIXME + } + + // Variables for lockSurface/unlockSurface + private JAWT_DrawingSurface ds; + private boolean dsLocked; + private JAWT_DrawingSurfaceInfo dsi; + private JAWT_MacOSXDrawingSurfaceInfo macosxdsi; + + // Workaround for instance of 4796548 + private boolean firstLock = true; + +} + diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/Win32SunJDKReflection.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/Win32SunJDKReflection.java new file mode 100644 index 000000000..5ad22807f --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/Win32SunJDKReflection.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.nativewindow.jawt.windows; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; + +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; + +/** This class encapsulates the reflection routines necessary to peek + inside a few data structures in the AWT implementation on X11 for + the purposes of correctly enumerating the available visuals. */ + +public class Win32SunJDKReflection { + private static Class win32GraphicsDeviceClass; + private static Class win32GraphicsConfigClass; + private static Method win32GraphicsConfigGetConfigMethod; + private static Method win32GraphicsConfigGetVisualMethod; + private static boolean initted; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + win32GraphicsDeviceClass = Class.forName("sun.awt.Win32GraphicsDevice"); + win32GraphicsConfigClass = Class.forName("sun.awt.Win32GraphicsConfig"); + win32GraphicsConfigGetConfigMethod = win32GraphicsConfigClass.getDeclaredMethod("getConfig", new Class[] { win32GraphicsDeviceClass, int.class }); + win32GraphicsConfigGetConfigMethod.setAccessible(true); + win32GraphicsConfigGetVisualMethod = win32GraphicsConfigClass.getDeclaredMethod("getVisual", new Class[] {}); + win32GraphicsConfigGetVisualMethod.setAccessible(true); + initted = true; + } catch (Exception e) { + // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5 + } + return null; + } + }); + } + + public static GraphicsConfiguration graphicsConfigurationGet(GraphicsDevice device, int pfdID) { + if (!initted) { + return null; + } + + try { + return (GraphicsConfiguration) win32GraphicsConfigGetConfigMethod.invoke(null, new Object[] { device, new Integer(pfdID) }); + } catch (Exception e) { + return null; + } + } + + public static int graphicsConfigurationGetPixelFormatID(AbstractGraphicsConfiguration config) { + try { + if (config instanceof AWTGraphicsConfiguration) { + return graphicsConfigurationGetPixelFormatID(((AWTGraphicsConfiguration) config).getGraphicsConfiguration()); + } + return 0; + } catch (Exception e) { + return 0; + } + } + + public static int graphicsConfigurationGetPixelFormatID(GraphicsConfiguration config) { + if (!initted) { + return 0; + } + + try { + return ((Integer) win32GraphicsConfigGetVisualMethod.invoke(config, (Object[])null)).intValue(); + } catch (Exception e) { + return 0; + } + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java new file mode 100644 index 000000000..982b94888 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.nativewindow.jawt.windows; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Point; + +import jogamp.nativewindow.jawt.JAWT; +import jogamp.nativewindow.jawt.JAWTFactory; +import jogamp.nativewindow.jawt.JAWTWindow; +import jogamp.nativewindow.jawt.JAWT_DrawingSurface; +import jogamp.nativewindow.jawt.JAWT_DrawingSurfaceInfo; +import jogamp.nativewindow.windows.GDI; + +public class WindowsJAWTWindow extends JAWTWindow { + + public WindowsJAWTWindow(Object comp, AbstractGraphicsConfiguration config) { + super(comp, config); + } + + protected void validateNative() throws NativeWindowException { + } + + @Override + protected synchronized void invalidate() { + super.invalidate(); + windowHandle = 0; + } + + protected int lockSurfaceImpl() throws NativeWindowException { + int ret = NativeWindow.LOCK_SUCCESS; + ds = JAWT.getJAWT().GetDrawingSurface(component); + if (ds == null) { + // Widget not yet realized + unlockSurfaceImpl(); + return LOCK_SURFACE_NOT_READY; + } + int res = ds.Lock(); + dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ; + if (!dsLocked) { + unlockSurfaceImpl(); + throw new NativeWindowException("Unable to lock surface"); + } + // See whether the surface changed and if so destroy the old + // OpenGL context so it will be recreated (NOTE: removeNotify + // should handle this case, but it may be possible that race + // conditions can cause this code to be triggered -- should test + // more) + if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { + ret = LOCK_SURFACE_CHANGED; + } + dsi = ds.GetDrawingSurfaceInfo(); + if (dsi == null) { + unlockSurfaceImpl(); + return LOCK_SURFACE_NOT_READY; + } + win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo(); + if (win32dsi == null) { + unlockSurfaceImpl(); + return LOCK_SURFACE_NOT_READY; + } + windowHandle = win32dsi.getHandle(); + drawable = win32dsi.getHdc(); + if (windowHandle == 0 || drawable == 0) { + unlockSurfaceImpl(); + return LOCK_SURFACE_NOT_READY; + } else { + updateBounds(dsi.getBounds()); + } + return ret; + } + + protected void unlockSurfaceImpl() throws NativeWindowException { + long startTime = 0; + if(null!=ds) { + if (null!=dsi) { + ds.FreeDrawingSurfaceInfo(dsi); + } + if (dsLocked) { + ds.Unlock(); + } + JAWT.getJAWT().FreeDrawingSurface(ds); + } + ds = null; + dsi = null; + win32dsi = null; + } + + @Override + public long getWindowHandle() { + return windowHandle; + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return GDI.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y); + } + + // Variables for lockSurface/unlockSurface + private JAWT_DrawingSurface ds; + private boolean dsLocked; + private JAWT_DrawingSurfaceInfo dsi; + private JAWT_Win32DrawingSurfaceInfo win32dsi; + + // lifetime: valid after lock, forever until invalidate + protected long windowHandle; +} + diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTToolkitLock.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTToolkitLock.java new file mode 100644 index 000000000..5d4fa0dad --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTToolkitLock.java @@ -0,0 +1,60 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.nativewindow.jawt.x11; + +import jogamp.nativewindow.jawt.*; +import jogamp.nativewindow.x11.X11Util; +import javax.media.nativewindow.ToolkitLock; + +/** + * Implementing a recursive {@link javax.media.nativewindow.ToolkitLock} + * utilizing JAWT's AWT lock via {@link JAWTUtil#lockToolkit()} and {@link X11Util#XLockDisplay(long)}. + * <br> + * This strategy should only be used if AWT is using the underlying native windowing toolkit + * in a not intrinsic thread safe manner, e.g. under X11 where no XInitThreads() call + * is issued before any other X11 usage. This is the current situation for e.g. Webstart or Applets. + */ +public class X11JAWTToolkitLock implements ToolkitLock { + long displayHandle; + + public X11JAWTToolkitLock(long displayHandle) { + this.displayHandle = displayHandle; + } + + public final void lock() { + if(TRACE_LOCK) { System.err.println("X11JAWTToolkitLock.lock()"); } + JAWTUtil.lockToolkit(); + X11Util.XLockDisplay(displayHandle); + } + + public final void unlock() { + if(TRACE_LOCK) { System.err.println("X11JAWTToolkitLock.unlock()"); } + X11Util.XUnlockDisplay(displayHandle); + JAWTUtil.unlockToolkit(); + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java new file mode 100644 index 000000000..2319d6269 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package jogamp.nativewindow.jawt.x11; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.util.Point; + +import jogamp.nativewindow.jawt.JAWT; +import jogamp.nativewindow.jawt.JAWTFactory; +import jogamp.nativewindow.jawt.JAWTWindow; +import jogamp.nativewindow.jawt.JAWT_DrawingSurface; +import jogamp.nativewindow.jawt.JAWT_DrawingSurfaceInfo; +import jogamp.nativewindow.x11.X11Util; + +public class X11JAWTWindow extends JAWTWindow { + + public X11JAWTWindow(Object comp, AbstractGraphicsConfiguration config) { + super(comp, config); + } + + protected void validateNative() throws NativeWindowException { + AWTGraphicsDevice awtDevice = (AWTGraphicsDevice) config.getScreen().getDevice(); + + if(awtDevice.getHandle() != 0) { + // subtype and handle set already, done + return; + } + + long displayHandle = 0; + + // first try a pre-existing attached native configuration, ie native X11GraphicsDevice + AbstractGraphicsConfiguration aconfig = (null!=config) ? config.getNativeGraphicsConfiguration() : null; + AbstractGraphicsScreen ascreen = (null!=aconfig) ? aconfig.getScreen() : null; + AbstractGraphicsDevice adevice = (null!=ascreen) ? ascreen.getDevice() : null; // X11GraphicsDevice + if(null!=adevice) { + displayHandle = adevice.getHandle(); + } + + if(0 == displayHandle) { + displayHandle = X11SunJDKReflection.graphicsDeviceGetDisplay(awtDevice.getGraphicsDevice()); + } + if(0==displayHandle) { + throw new InternalError("X11JAWTWindow: No X11 Display handle available"); + } + awtDevice.setSubType(NativeWindowFactory.TYPE_X11, displayHandle); + } + + protected int lockSurfaceImpl() throws NativeWindowException { + int ret = NativeWindow.LOCK_SUCCESS; + ds = JAWT.getJAWT().GetDrawingSurface(component); + if (ds == null) { + // Widget not yet realized + unlockSurfaceImpl(); + return LOCK_SURFACE_NOT_READY; + } + int res = ds.Lock(); + dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ; + if (!dsLocked) { + unlockSurfaceImpl(); + throw new NativeWindowException("Unable to lock surface"); + } + // See whether the surface changed and if so destroy the old + // OpenGL context so it will be recreated (NOTE: removeNotify + // should handle this case, but it may be possible that race + // conditions can cause this code to be triggered -- should test + // more) + if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { + ret = LOCK_SURFACE_CHANGED; + } + dsi = ds.GetDrawingSurfaceInfo(); + if (dsi == null) { + unlockSurfaceImpl(); + return LOCK_SURFACE_NOT_READY; + } + x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo(); + if (x11dsi == null) { + unlockSurfaceImpl(); + return LOCK_SURFACE_NOT_READY; + } + drawable = x11dsi.getDrawable(); + if (drawable == 0) { + unlockSurfaceImpl(); + return LOCK_SURFACE_NOT_READY; + } else { + updateBounds(dsi.getBounds()); + } + return ret; + } + + protected void unlockSurfaceImpl() throws NativeWindowException { + if(null!=ds) { + if (null!=dsi) { + ds.FreeDrawingSurfaceInfo(dsi); + } + if (dsLocked) { + ds.Unlock(); + } + JAWT.getJAWT().FreeDrawingSurface(ds); + } + ds = null; + dsi = null; + x11dsi = null; + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return X11Util.GetRelativeLocation( getDisplayHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y); + } + + // Variables for lockSurface/unlockSurface + private JAWT_DrawingSurface ds; + private boolean dsLocked; + private JAWT_DrawingSurfaceInfo dsi; + private JAWT_X11DrawingSurfaceInfo x11dsi; + +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11SunJDKReflection.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11SunJDKReflection.java new file mode 100644 index 000000000..b576b0c6b --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11SunJDKReflection.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.nativewindow.jawt.x11; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; + +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; + +/** This class encapsulates the reflection routines necessary to peek + inside a few data structures in the AWT implementation on X11 for + the purposes of correctly enumerating the available visuals. */ + +public class X11SunJDKReflection { + private static Class x11GraphicsDeviceClass; + private static Method x11GraphicsDeviceGetDisplayMethod; + private static Class x11GraphicsConfigClass; + private static Method x11GraphicsConfigGetVisualMethod; + private static boolean initted; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + x11GraphicsDeviceClass = Class.forName("sun.awt.X11GraphicsDevice"); + x11GraphicsDeviceGetDisplayMethod = x11GraphicsDeviceClass.getDeclaredMethod("getDisplay", new Class[] {}); + x11GraphicsDeviceGetDisplayMethod.setAccessible(true); + + x11GraphicsConfigClass = Class.forName("sun.awt.X11GraphicsConfig"); + x11GraphicsConfigGetVisualMethod = x11GraphicsConfigClass.getDeclaredMethod("getVisual", new Class[] {}); + x11GraphicsConfigGetVisualMethod.setAccessible(true); + initted = true; + } catch (Exception e) { + // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5 + } + return null; + } + }); + } + + public static long graphicsDeviceGetDisplay(GraphicsDevice device) { + if (!initted) { + return 0; + } + + try { + return ((Long) x11GraphicsDeviceGetDisplayMethod.invoke(device, (Object[])null)).longValue(); + } catch (Exception e) { + return 0; + } + } + + public static int graphicsConfigurationGetVisualID(AbstractGraphicsConfiguration config) { + try { + if (config instanceof AWTGraphicsConfiguration) { + return graphicsConfigurationGetVisualID(((AWTGraphicsConfiguration) config).getGraphicsConfiguration()); + } + return 0; + } catch (Exception e) { + return 0; + } + } + + public static int graphicsConfigurationGetVisualID(GraphicsConfiguration config) { + if (!initted) { + return 0; + } + + try { + return ((Integer) x11GraphicsConfigGetVisualMethod.invoke(config, (Object[])null)).intValue(); + } catch (Exception e) { + return 0; + } + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java new file mode 100644 index 000000000..d1f5efc88 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java @@ -0,0 +1,240 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.nativewindow.swt; + +import com.jogamp.common.os.Platform; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.eclipse.swt.graphics.GCData; +import org.eclipse.swt.widgets.Control; + +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.windows.WindowsGraphicsDevice; +import javax.media.nativewindow.x11.X11GraphicsDevice; +import com.jogamp.common.util.ReflectionUtil; +import javax.media.nativewindow.macosx.MacOSXGraphicsDevice; + +public class SWTAccessor { + static final Field swt_control_handle; + static final boolean swt_uses_long_handles; + + // X11/GTK, Windows/GDI, .. + static final String str_handle = "handle"; + + // OSX/Cocoa + static final String str_view = "view"; // OSX + static final String str_id = "id"; // OSX + // static final String str_NSView = "org.eclipse.swt.internal.cocoa.NSView"; + + static final Method swt_control_internal_new_GC; + static final Method swt_control_internal_dispose_GC; + static final String str_internal_new_GC = "internal_new_GC"; + static final String str_internal_dispose_GC = "internal_dispose_GC"; + + static final String str_OS_gtk_class = "org.eclipse.swt.internal.gtk.OS"; + static final Class OS_gtk_class; + static final Method OS_gtk_widget_realize; + static final Method OS_gtk_widget_unrealize; + static final Method OS_GTK_WIDGET_WINDOW; + static final Method OS_gdk_x11_drawable_get_xdisplay; + static final Method OS_gdk_x11_drawable_get_xid; + static final String str_gtk_widget_realize = "gtk_widget_realize"; + static final String str_gtk_widget_unrealize = "gtk_widget_unrealize"; + static final String str_GTK_WIDGET_WINDOW = "GTK_WIDGET_WINDOW"; + static final String str_gdk_x11_drawable_get_xdisplay = "gdk_x11_drawable_get_xdisplay"; + static final String str_gdk_x11_drawable_get_xid = "gdk_x11_drawable_get_xid"; + + static { + Field f = null; + + if(NativeWindowFactory.TYPE_MACOSX != NativeWindowFactory.getNativeWindowType(false) ) { + try { + f = Control.class.getField(str_handle); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + } + swt_control_handle = f; // maybe null ! + + boolean ulh; + if (null != swt_control_handle) { + ulh = swt_control_handle.getGenericType().toString().equals(long.class.toString()); + } else { + ulh = Platform.is64Bit(); + } + swt_uses_long_handles = ulh; + // System.err.println("SWT long handles: " + swt_uses_long_handles); + // System.err.println("Platform 64bit: "+Platform.is64Bit()); + + Method m=null; + try { + m = ReflectionUtil.getMethod(Control.class, str_internal_new_GC, new Class[] { GCData.class }); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + swt_control_internal_new_GC = m; + + try { + if(swt_uses_long_handles) { + m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { long.class, GCData.class }); + } else { + m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { int.class, GCData.class }); + } + } catch (NoSuchMethodException ex) { + throw new NativeWindowException(ex); + } + swt_control_internal_dispose_GC = m; + + Class c=null; + Method m1=null, m2=null, m3=null, m4=null, m5=null; + Class handleType = swt_uses_long_handles ? long.class : int.class ; + if( NativeWindowFactory.TYPE_X11 == NativeWindowFactory.getNativeWindowType(false) ) { + try { + c = ReflectionUtil.getClass(str_OS_gtk_class, false, SWTAccessor.class.getClassLoader()); + m1 = c.getDeclaredMethod(str_gtk_widget_realize, handleType); + m2 = c.getDeclaredMethod(str_gtk_widget_unrealize, handleType); + m3 = c.getDeclaredMethod(str_GTK_WIDGET_WINDOW, handleType); + m4 = c.getDeclaredMethod(str_gdk_x11_drawable_get_xdisplay, handleType); + m5 = c.getDeclaredMethod(str_gdk_x11_drawable_get_xid, handleType); + } catch (Exception ex) { throw new NativeWindowException(ex); } + } + OS_gtk_class = c; + OS_gtk_widget_realize = m1; + OS_gtk_widget_unrealize = m2; + OS_GTK_WIDGET_WINDOW = m3; + OS_gdk_x11_drawable_get_xdisplay = m4; + OS_gdk_x11_drawable_get_xid = m5; + } + + static Object getIntOrLong(long arg) { + if(swt_uses_long_handles) { + return new Long(arg); + } + return new Integer((int) arg); + } + + static void callStaticMethodL2V(Method m, long arg) { + ReflectionUtil.callMethod(null, m, new Object[] { getIntOrLong(arg) }); + } + + static long callStaticMethodL2L(Method m, long arg) { + Object o = ReflectionUtil.callMethod(null, m, new Object[] { getIntOrLong(arg) }); + if(o instanceof Number) { + return ((Number)o).longValue(); + } else { + throw new InternalError("SWT method "+m.getName()+" didn't return int or long but "+o.getClass()); + } + } + + public static boolean isUsingLongHandles() { + return swt_uses_long_handles; + } + + public static long getHandle(Control swtControl) { + long h = 0; + if(NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) { + try { + Field fView = Control.class.getField(str_view); + Object view = fView.get(swtControl); + Field fId = view.getClass().getField(str_id); + return fId.getLong(view); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + } + + try { + h = swt_control_handle.getLong(swtControl); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + return h; + } + + public static void setRealized(Control swtControl, boolean realize) { + long handle = getHandle(swtControl); + + if(null != OS_gtk_class) { + if(realize) { + callStaticMethodL2V(OS_gtk_widget_realize, handle); + } else { + callStaticMethodL2V(OS_gtk_widget_unrealize, handle); + } + } + } + + public static AbstractGraphicsDevice getDevice(Control swtControl) { + long handle = getHandle(swtControl); + if( null != OS_gtk_class ) { + long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle); + long displayHandle = callStaticMethodL2L(OS_gdk_x11_drawable_get_xdisplay, widgedHandle); + return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT); + } + if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) ) { + return new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); + } + if( NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) { + return new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + } + throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false)); + } + + public static long getWindowHandle(Control swtControl) { + long handle = getHandle(swtControl); + if( null != OS_gtk_class ) { + long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle); + return callStaticMethodL2L(OS_gdk_x11_drawable_get_xid, widgedHandle); + } + if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) || + NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) { + return handle; + } + throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false)); + } + + public static long newGC(Control swtControl, GCData gcData) { + Object o = ReflectionUtil.callMethod(swtControl, swt_control_internal_new_GC, new Object[] { gcData }); + if(o instanceof Number) { + return ((Number)o).longValue(); + } else { + throw new InternalError("SWT internal_new_GC did not return int or long but "+o.getClass()); + } + } + + public static void disposeGC(Control swtControl, long gc, GCData gcData) { + if(swt_uses_long_handles) { + ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Long(gc), gcData }); + } else { + ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Integer((int)gc), gcData }); + } + } + +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java new file mode 100644 index 000000000..68cf8af45 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java @@ -0,0 +1,87 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.nativewindow.windows; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindowException; + +import javax.media.nativewindow.ProxySurface; + +/** + * GDI Surface implementation which wraps an existing window handle + * allowing the use of HDC via lockSurface()/unlockSurface() protocol. + * The latter will get and release the HDC. + * The size via getWidth()/getHeight() is invalid. + */ +public class GDISurface extends ProxySurface { + protected long windowHandle; + protected long surfaceHandle; + + public GDISurface(AbstractGraphicsConfiguration cfg, long windowHandle) { + super(cfg); + if(0 == windowHandle) { + throw new NativeWindowException("Error hwnd 0, werr: "+GDI.GetLastError()); + } + this.windowHandle=windowHandle; + } + + protected final void invalidateImpl() { + windowHandle=0; + surfaceHandle=0; + } + + protected int lockSurfaceImpl() { + if (0 != surfaceHandle) { + throw new InternalError("surface not released"); + } + surfaceHandle = GDI.GetDC(windowHandle); + return (0 != surfaceHandle) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY; + } + + protected void unlockSurfaceImpl() { + if (0 == surfaceHandle) { + throw new InternalError("surface not acquired"); + } + GDI.ReleaseDC(windowHandle, surfaceHandle); + surfaceHandle=0; + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + public String toString() { + return "GDISurface[config "+config+ + ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+ + ", windowHandle 0x"+Long.toHexString(windowHandle)+ + ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ + ", size "+getWidth()+"x"+getHeight()+"]"; + } + +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClass.java b/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClass.java new file mode 100644 index 000000000..afb3daf7c --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClass.java @@ -0,0 +1,45 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.nativewindow.windows; + +public class RegisteredClass { + long hInstance; + String className; + + RegisteredClass(long hInst, String name) { + hInstance = hInst; + className = name; + } + + public final long getHandle() { return hInstance; } + public final String getName() { return className; } + + @Override + public final String toString() { return "RegisteredClass[handle 0x"+Long.toHexString(hInstance)+", "+className+"]"; } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClassFactory.java b/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClassFactory.java new file mode 100644 index 000000000..15e0a67cb --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClassFactory.java @@ -0,0 +1,133 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.nativewindow.windows; + +import jogamp.nativewindow.Debug; +import java.util.ArrayList; +import javax.media.nativewindow.NativeWindowException; + +public class RegisteredClassFactory { + static final boolean DEBUG = Debug.debug("RegisteredClass"); + private static ArrayList sharedClasses = new ArrayList(); + private String classBaseName; + long wndProc; + + private RegisteredClass sharedClass = null; + private int classIter = 0; + private int sharedRefCount = 0; + private Object sync = new Object(); + + /** + * Intended for a JVM shutdown hook, hence little synchronization + */ + public static void shutdownSharedClasses() { + synchronized(sharedClasses) { + for(int i=0; i<sharedClasses.size(); i++) { + RegisteredClass sc = (RegisteredClass) sharedClasses.get(i); + GDI.DestroyWindowClass(sc.getHandle(), sc.getName()); + if(DEBUG) { + System.err.println("RegisteredClassFactory shutdownSharedClasses "+i+"/"+sharedClasses.size()+": "+sc); + } + } + sharedClasses.clear(); + } + } + + public RegisteredClassFactory(String classBaseName, long wndProc) { + this.classBaseName = classBaseName; + this.wndProc = wndProc; + } + + public RegisteredClass getSharedClass() throws NativeWindowException { + synchronized(sync) { + if( 0 == sharedRefCount ) { + if( null != sharedClass ) { + throw new InternalError("Error ("+sharedRefCount+"): SharedClass not null: "+sharedClass); + } + long hInstance = GDI.GetApplicationHandle(); + if( 0 == hInstance ) { + throw new NativeWindowException("Error: Null ModuleHandle for Application"); + } + String clazzName = null; + boolean registered = false; + while ( !registered && Integer.MAX_VALUE >= classIter ) { + // Retry with next clazz name, this could happen if more than one JVM is running + clazzName = classBaseName + classIter; + classIter++; + registered = GDI.CreateWindowClass(hInstance, clazzName, wndProc); + } + if( !registered ) { + throw new NativeWindowException("Error: Could not create WindowClass: "+clazzName); + } + sharedClass = new RegisteredClass(hInstance, clazzName); + synchronized(sharedClasses) { + sharedClasses.add(sharedClass); + } + if(DEBUG) { + System.err.println("RegisteredClassFactory getSharedClass ("+sharedRefCount+") initialized: "+sharedClass); + } + } else if ( null == sharedClass ) { + throw new InternalError("Error ("+sharedRefCount+"): SharedClass is null"); + } + sharedRefCount++; + } + return sharedClass; + } + + public void releaseSharedClass() { + synchronized(sync) { + if( 0 == sharedRefCount ) { + if( null != sharedClass ) { + throw new InternalError("Error ("+sharedRefCount+"): SharedClass not null: "+sharedClass); + } + return; + } + sharedRefCount--; + if( null == sharedClass ) { + throw new InternalError("Error ("+sharedRefCount+"): SharedClass is null"); + } + if( 0 == sharedRefCount ) { + GDI.DestroyWindowClass(sharedClass.getHandle(), sharedClass.getName()); + synchronized(sharedClasses) { + sharedClasses.remove(sharedClass); + } + if(DEBUG) { + System.err.println("RegisteredClassFactory releaseSharedClass ("+sharedRefCount+") released: "+sharedClass); + } + sharedClass = null; + sharedRefCount = 0; + classIter = 0; + } + } + } + + public int getSharedRefCount() { + return sharedRefCount; + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java new file mode 100644 index 000000000..b669bce75 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.nativewindow.x11; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; + +public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactory { + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, CapabilitiesChooser chooser, AbstractGraphicsScreen screen) + throws IllegalArgumentException, NativeWindowException { + + if(!(screen instanceof X11GraphicsScreen)) { + throw new NativeWindowException("Only valid X11GraphicsScreen are allowed"); + } + return new X11GraphicsConfiguration((X11GraphicsScreen)screen, capsChosen, capsRequested, getXVisualInfo(screen, capsChosen)); + } + + public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, long visualID) + { + XVisualInfo xvi_temp = XVisualInfo.create(); + xvi_temp.setVisualid(visualID); + xvi_temp.setScreen(screen.getIndex()); + int num[] = { -1 }; + long display = screen.getDevice().getHandle(); + + XVisualInfo[] xvis = X11Util.XGetVisualInfo(display, X11Lib.VisualIDMask|X11Lib.VisualScreenMask, xvi_temp, num, 0); + + if(xvis==null || num[0]<1) { + return null; + } + + return XVisualInfo.create(xvis[0]); + } + + public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, CapabilitiesImmutable capabilities) + { + XVisualInfo xv = getXVisualInfoImpl(screen, capabilities, 4 /* TrueColor */); + if(null!=xv) return xv; + return getXVisualInfoImpl(screen, capabilities, 5 /* DirectColor */); + } + + private static XVisualInfo getXVisualInfoImpl(AbstractGraphicsScreen screen, CapabilitiesImmutable capabilities, int c_class) + { + XVisualInfo ret = null; + int[] num = { -1 }; + + XVisualInfo vinfo_template = XVisualInfo.create(); + vinfo_template.setScreen(screen.getIndex()); + vinfo_template.setC_class(c_class); + long display = screen.getDevice().getHandle(); + + XVisualInfo[] vinfos = X11Util.XGetVisualInfo(display, X11Lib.VisualScreenMask, vinfo_template, num, 0); + XVisualInfo best=null; + int rdepth = capabilities.getRedBits() + capabilities.getGreenBits() + capabilities.getBlueBits() + capabilities.getAlphaBits(); + for (int i = 0; vinfos!=null && i < num[0]; i++) { + if ( best == null || + best.getDepth() < vinfos[i].getDepth() ) + { + best = vinfos[i]; + if(rdepth <= best.getDepth()) + break; + } + } + if ( null!=best && ( rdepth <= best.getDepth() || 24 == best.getDepth()) ) { + ret = XVisualInfo.create(best); + } + best = null; + + return ret; + } +} + diff --git a/src/com/jogamp/graph/geom/Vertex.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11ToolkitLock.java index 0e4e5e8df..fb0aff10d 100644 --- a/src/com/jogamp/graph/geom/Vertex.java +++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11ToolkitLock.java @@ -1,5 +1,5 @@ /** - * Copyright 2011 JogAmp Community. All rights reserved. + * 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: @@ -25,56 +25,31 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package com.jogamp.graph.geom; +package jogamp.nativewindow.x11; + +import javax.media.nativewindow.ToolkitLock; /** - * A Vertex with custom memory layout using custom factory. + * Implementing a recursive {@link javax.media.nativewindow.ToolkitLock} + * utilizing {@link X11Util#XLockDisplay(long)}. + * <br> + * This strategy should not be used in case XInitThreads() is being used, + * or a higher level toolkit lock is required, ie AWT lock. */ -public interface Vertex extends Comparable<Vertex>, Cloneable { - - public static interface Factory <T extends Vertex> { - T create(); - - T create(float x, float y); - - T create(float x, float y, float z); - - T create(float[] coordsBuffer, int offset, int length); - } - - void setCoord(float x, float y); - - void setCoord(float x, float y, float z); - - void setCoord(float[] coordsBuffer, int offset, int length); - - float[] getCoord(); - - void setX(float x); - - void setY(float y); - - void setZ(float z); - - float getX(); - - float getY(); - - float getZ(); - - boolean isOnCurve(); - - void setOnCurve(boolean onCurve); - - int getId(); - - void setId(int id); - - int compareTo(Vertex p); - - float[] getTexCoord(); - - void setTexCoord(float s, float t); - - Vertex clone(); +public class X11ToolkitLock implements ToolkitLock { + long displayHandle; + + public X11ToolkitLock(long displayHandle) { + this.displayHandle = displayHandle; + } + + public final void lock() { + if(TRACE_LOCK) { System.err.println("X11ToolkitLock.lock()"); } + X11Util.XLockDisplay(displayHandle); + } + + public final void unlock() { + if(TRACE_LOCK) { System.err.println("X11ToolkitLock.unlock()"); } + X11Util.XUnlockDisplay(displayHandle); + } } diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java new file mode 100644 index 000000000..26da46319 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java @@ -0,0 +1,612 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package jogamp.nativewindow.x11; + +import com.jogamp.common.util.LongObjectHashMap; +import jogamp.nativewindow.Debug; +import jogamp.nativewindow.NWJNILibLoader; + +import javax.media.nativewindow.*; + +import java.nio.Buffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; +import java.security.AccessController; +import java.util.ArrayList; +import java.util.List; +import javax.media.nativewindow.util.Point; + +/** + * Contains a thread safe X11 utility to retrieve display connections. + */ +public class X11Util { + private static final boolean DEBUG = Debug.debug("X11Util"); + private static final boolean TRACE_DISPLAY_LIFECYCLE = Debug.getBooleanProperty("nativewindow.debug.X11Util.TraceDisplayLifecycle", true, AccessController.getContext()); + + private static volatile String nullDisplayName = null; + private static boolean isFirstX11ActionOnProcess = false; + private static boolean isInit = false; + + private static int setX11ErrorHandlerRecCount = 0; + private static Object setX11ErrorHandlerLock = new Object(); + + public static synchronized void initSingleton(boolean firstX11ActionOnProcess) { + if(!isInit) { + NWJNILibLoader.loadNativeWindow("x11"); + + /** + * Always issue XInitThreads() since we have independent + * off-thread created Display connections able to utilize multithreading, ie NEWT */ + initialize0( true ); + // initialize0( firstX11ActionOnProcess ); + isFirstX11ActionOnProcess = firstX11ActionOnProcess; + + if(DEBUG) { + System.out.println("X11Util.isFirstX11ActionOnProcess: "+isFirstX11ActionOnProcess); + } + isInit = true; + } + } + + public static void setX11ErrorHandler(boolean onoff, boolean quiet) { + synchronized(setX11ErrorHandlerLock) { + if(onoff) { + if(0==setX11ErrorHandlerRecCount) { + setX11ErrorHandler0(true, quiet); + } + setX11ErrorHandlerRecCount++; + } else { + if(0 >= setX11ErrorHandlerRecCount) { + throw new InternalError(); + } + setX11ErrorHandlerRecCount--; + if(0==setX11ErrorHandlerRecCount) { + setX11ErrorHandler0(false, false); + } + } + } + } + + public static boolean isFirstX11ActionOnProcess() { + return isFirstX11ActionOnProcess; + } + + public static void lockDefaultToolkit(long dpyHandle) { + NativeWindowFactory.getDefaultToolkitLock().lock(); + if(!isFirstX11ActionOnProcess) { + X11Util.XLockDisplay(dpyHandle); + } + } + + public static void unlockDefaultToolkit(long dpyHandle) { + if(!isFirstX11ActionOnProcess) { + X11Util.XUnlockDisplay(dpyHandle); + } + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } + + public static String getNullDisplayName() { + if(null==nullDisplayName) { // volatile: ok + synchronized(X11Util.class) { + if(null==nullDisplayName) { + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + long dpy = X11Lib.XOpenDisplay(null); + nullDisplayName = X11Lib.XDisplayString(dpy); + X11Lib.XCloseDisplay(dpy); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } + if(DEBUG) { + System.out.println("X11 Display(NULL) <"+nullDisplayName+">"); + } + } + } + } + return nullDisplayName; + } + + private X11Util() {} + + // not exactly thread safe, but good enough for our purpose, + // which is to tag a NamedDisplay uncloseable after creation. + private static Object globalLock = new Object(); + private static LongObjectHashMap globalNamedDisplayMap = new LongObjectHashMap(); + private static List openDisplayList = new ArrayList(); + private static List pendingDisplayList = new ArrayList(); + + public static class NamedDisplay { + String name; + long handle; + int refCount; + boolean unCloseable; + Throwable creationStack; + + protected NamedDisplay(String name, long handle) { + this.name=name; + this.handle=handle; + this.refCount=1; + this.unCloseable=false; + if(DEBUG) { + this.creationStack=new Throwable("NamedDisplay Created at:"); + } else { + this.creationStack=null; + } + } + + public final String getName() { return name; } + public final long getHandle() { return handle; } + public final int getRefCount() { return refCount; } + + public final void setUncloseable(boolean v) { unCloseable = v; } + public final boolean isUncloseable() { return unCloseable; } + + public final Throwable getCreationStack() { return creationStack; } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + @Override + public String toString() { + return "NamedX11Display["+name+", 0x"+Long.toHexString(handle)+", refCount "+refCount+", unCloseable "+unCloseable+"]"; + } + } + + /** Returns the number of unclosed X11 Displays. + * @param realXCloseOpenAndPendingDisplays if true, {@link #closePendingDisplayConnections()} is called. + */ + public static int shutdown(boolean realXCloseOpenAndPendingDisplays, boolean verbose) { + int num=0; + if(DEBUG||verbose||pendingDisplayList.size() > 0) { + String msg = "X11Util.Display: Shutdown (close open / pending Displays: "+realXCloseOpenAndPendingDisplays+ + ", open (no close attempt): "+globalNamedDisplayMap.size()+"/"+openDisplayList.size()+ + ", open (no close attempt and uncloseable): "+pendingDisplayList.size()+")" ; + if(DEBUG) { + Exception e = new Exception(msg); + e.printStackTrace(); + } else { + System.err.println(msg); + } + if( openDisplayList.size() > 0) { + X11Util.dumpOpenDisplayConnections(); + } + if( pendingDisplayList.size() > 0 ) { + X11Util.dumpPendingDisplayConnections(); + } + } + + synchronized(globalLock) { + if(realXCloseOpenAndPendingDisplays) { + closePendingDisplayConnections(); + } + openDisplayList.clear(); + pendingDisplayList.clear(); + globalNamedDisplayMap.clear(); + } + return num; + } + + /** + * Closing pending Display connections in reverse order. + * + * @return number of closed Display connections + */ + public static int closePendingDisplayConnections() { + int num=0; + synchronized(globalLock) { + if(DEBUG) { + System.err.println("X11Util: Closing Pending X11 Display Connections: "+pendingDisplayList.size()); + } + for(int i=pendingDisplayList.size()-1; i>=0; i--) { + NamedDisplay ndpy = (NamedDisplay) pendingDisplayList.get(i); + if(DEBUG) { + System.err.println("X11Util.closePendingDisplayConnections(): Closing ["+i+"]: "+ndpy); + } + XCloseDisplay(ndpy.getHandle()); + num++; + } + } + return num; + } + + public static int getOpenDisplayConnectionNumber() { + synchronized(globalLock) { + return openDisplayList.size(); + } + } + + public static void dumpOpenDisplayConnections() { + synchronized(globalLock) { + System.err.println("X11Util: Open X11 Display Connections: "+openDisplayList.size()); + for(int i=0; i<pendingDisplayList.size(); i++) { + NamedDisplay ndpy = (NamedDisplay) openDisplayList.get(i); + System.err.println("X11Util: ["+i+"]: "+ndpy); + if(null!=ndpy) { + Throwable t = ndpy.getCreationStack(); + if(null!=t) { + t.printStackTrace(); + } + } + } + } + } + + public static int getPendingDisplayConnectionNumber() { + synchronized(globalLock) { + return pendingDisplayList.size(); + } + } + + public static void dumpPendingDisplayConnections() { + synchronized(globalLock) { + System.err.println("X11Util: Pending X11 Display Connections: "+pendingDisplayList.size()); + for(int i=0; i<pendingDisplayList.size(); i++) { + NamedDisplay ndpy = (NamedDisplay) pendingDisplayList.get(i); + System.err.println("X11Util: ["+i+"]: "+ndpy); + if(null!=ndpy) { + Throwable t = ndpy.getCreationStack(); + if(null!=t) { + t.printStackTrace(); + } + } + } + } + } + + public static boolean markDisplayUncloseable(long handle) { + NamedDisplay ndpy; + synchronized(globalLock) { + ndpy = (NamedDisplay) globalNamedDisplayMap.get(handle); + } + if( null != ndpy ) { + ndpy.setUncloseable(true); + return true; + } + return false; + } + + /** Returns this created named display. */ + public static long createDisplay(String name) { + name = validateDisplayName(name); + long dpy = XOpenDisplay(name); + if(0==dpy) { + throw new NativeWindowException("X11Util.Display: Unable to create a display("+name+") connection. Thread "+Thread.currentThread().getName()); + } + // if you like to debug and synchronize X11 commands .. + // setSynchronizeDisplay(dpy, true); + NamedDisplay namedDpy = new NamedDisplay(name, dpy); + synchronized(globalLock) { + globalNamedDisplayMap.put(dpy, namedDpy); + openDisplayList.add(namedDpy); + pendingDisplayList.add(namedDpy); + } + if(DEBUG) { + Exception e = new Exception("X11Util.Display: Created new "+namedDpy+". Thread "+Thread.currentThread().getName()); + e.printStackTrace(); + } + return namedDpy.getHandle(); + } + + public static void closeDisplay(long handle) { + NamedDisplay namedDpy; + + synchronized(globalLock) { + namedDpy = (NamedDisplay) globalNamedDisplayMap.remove(handle); + if(namedDpy!=null) { + if(!openDisplayList.remove(namedDpy)) { throw new RuntimeException("Internal: "+namedDpy); } + } + } + if(null==namedDpy) { + X11Util.dumpPendingDisplayConnections(); + throw new RuntimeException("X11Util.Display: Display(0x"+Long.toHexString(handle)+") with given handle is not mapped. Thread "+Thread.currentThread().getName()); + } + if(namedDpy.getHandle()!=handle) { + X11Util.dumpPendingDisplayConnections(); + throw new RuntimeException("X11Util.Display: Display(0x"+Long.toHexString(handle)+") Mapping error: "+namedDpy+". Thread "+Thread.currentThread().getName()); + } + + if(DEBUG) { + Exception e = new Exception("X11Util.Display: Closing new "+namedDpy+". Thread "+Thread.currentThread().getName()); + e.printStackTrace(); + } + + if(!namedDpy.isUncloseable()) { + synchronized(globalLock) { + if(!pendingDisplayList.remove(namedDpy)) { throw new RuntimeException("Internal: "+namedDpy); } + } + XCloseDisplay(namedDpy.getHandle()); + } + } + + public static NamedDisplay getNamedDisplay(long handle) { + synchronized(globalLock) { + return (NamedDisplay) globalNamedDisplayMap.get(handle); + } + } + + /** + * @return If name is null, it returns the previous queried NULL display name, + * otherwise the name. */ + public static String validateDisplayName(String name) { + return ( null == name || AbstractGraphicsDevice.DEFAULT_CONNECTION.equals(name) ) ? getNullDisplayName() : name ; + } + + public static String validateDisplayName(String name, long handle) { + if( ( null==name || AbstractGraphicsDevice.DEFAULT_CONNECTION.equals(name) ) && 0!=handle) { + name = XDisplayString(handle); + } + return validateDisplayName(name); + } + + /******************************* + ** + ** Locked X11Lib wrapped functions + ** + *******************************/ + + public static long XOpenDisplay(String arg0) { + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + long handle = X11Lib.XOpenDisplay(arg0); + if(TRACE_DISPLAY_LIFECYCLE) { + Throwable t = new Throwable(Thread.currentThread()+" - X11Util.XOpenDisplay("+arg0+") 0x"+Long.toHexString(handle)); + t.printStackTrace(); + } + return handle; + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } + } + + public static int XCloseDisplay(long display) { + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + if(TRACE_DISPLAY_LIFECYCLE) { + Throwable t = new Throwable(Thread.currentThread()+" - X11Util.XCloseDisplay() 0x"+Long.toHexString(display)); + t.printStackTrace(); + } + return X11Lib.XCloseDisplay(display); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } + } + + public static int XFree(Buffer arg0) { + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + return X11Lib.XFree(arg0); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } + } + + public static int XSync(long display, boolean discard) { + lockDefaultToolkit(display); + try { + return X11Lib.XSync(display, discard); + } finally { + unlockDefaultToolkit(display); + } + } + + public static void XSynchronize(long display, boolean onoff) { + lockDefaultToolkit(display); + try { + X11Lib.XSynchronize(display, onoff); + } finally { + unlockDefaultToolkit(display); + } + } + + public static boolean XineramaEnabled(long display) { + lockDefaultToolkit(display); + try { + return X11Lib.XineramaEnabled(display); + } finally { + unlockDefaultToolkit(display); + } + } + + public static int DefaultScreen(long display) { + lockDefaultToolkit(display); + try { + return X11Lib.DefaultScreen(display); + } finally { + unlockDefaultToolkit(display); + } + } + + public static long RootWindow(long display, int screen_number) { + lockDefaultToolkit(display); + try { + return X11Lib.RootWindow(display, screen_number); + } finally { + unlockDefaultToolkit(display); + } + } + + public static long XCreatePixmap(long display, long arg1, int arg2, int arg3, int arg4) { + lockDefaultToolkit(display); + try { + return X11Lib.XCreatePixmap(display, arg1, arg2, arg3, arg4); + } finally { + unlockDefaultToolkit(display); + } + } + + public static String XDisplayString(long display) { + lockDefaultToolkit(display); + try { + return X11Lib.XDisplayString(display); + } finally { + unlockDefaultToolkit(display); + } + } + + public static int XFlush(long display) { + lockDefaultToolkit(display); + try { + return X11Lib.XFlush(display); + } finally { + unlockDefaultToolkit(display); + } + } + + public static int XFreePixmap(long display, long arg1) { + lockDefaultToolkit(display); + try { + return X11Lib.XFreePixmap(display, arg1); + } finally { + unlockDefaultToolkit(display); + } + } + + public static long DefaultVisualID(long display, int screen) { + lockDefaultToolkit(display); + try { + return X11Lib.DefaultVisualID(display, screen); + } finally { + unlockDefaultToolkit(display); + } + } + + public static long CreateDummyWindow(long display, int screen_index, long visualID, int width, int height) { + lockDefaultToolkit(display); + try { + return X11Lib.CreateDummyWindow(display, screen_index, visualID, width, height); + } finally { + unlockDefaultToolkit(display); + } + } + + public static void DestroyDummyWindow(long display, long window) { + lockDefaultToolkit(display); + try { + X11Lib.DestroyDummyWindow(display, window); + } finally { + unlockDefaultToolkit(display); + } + } + + public static Point GetRelativeLocation(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y) { + lockDefaultToolkit(display); + try { + return X11Lib.GetRelativeLocation(display, screen_index, src_win, dest_win, src_x, src_y); + } finally { + unlockDefaultToolkit(display); + } + } + + public static XVisualInfo[] XGetVisualInfo(long display, long arg1, XVisualInfo arg2, int[] arg3, int arg3_offset) { + lockDefaultToolkit(display); + try { + return X11Lib.XGetVisualInfo(display, arg1, arg2, arg3, arg3_offset); + } finally { + unlockDefaultToolkit(display); + } + } + + public static boolean XF86VidModeGetGammaRamp(long display, int screen, int size, ShortBuffer red_array, ShortBuffer green_array, ShortBuffer blue_array) { + lockDefaultToolkit(display); + try { + return X11Lib.XF86VidModeGetGammaRamp(display, screen, size, red_array, green_array, blue_array); + } finally { + unlockDefaultToolkit(display); + } + } + + public static boolean XF86VidModeGetGammaRamp(long display, int screen, int size, short[] red_array, int red_array_offset, short[] green_array, int green_array_offset, short[] blue_array, int blue_array_offset) { + lockDefaultToolkit(display); + try { + return X11Lib.XF86VidModeGetGammaRamp(display, screen, size, red_array, red_array_offset, green_array, green_array_offset, blue_array, blue_array_offset); + } finally { + unlockDefaultToolkit(display); + } + } + + public static boolean XF86VidModeGetGammaRampSize(long display, int screen, IntBuffer size) { + lockDefaultToolkit(display); + try { + return X11Lib.XF86VidModeGetGammaRampSize(display, screen, size); + } finally { + unlockDefaultToolkit(display); + } + } + + public static boolean XF86VidModeGetGammaRampSize(long display, int screen, int[] size, int size_offset) { + lockDefaultToolkit(display); + try { + return X11Lib.XF86VidModeGetGammaRampSize(display, screen, size, size_offset); + } finally { + unlockDefaultToolkit(display); + } + } + + public static boolean XF86VidModeSetGammaRamp(long display, int screen, int size, ShortBuffer red_array, ShortBuffer green_array, ShortBuffer blue_array) { + lockDefaultToolkit(display); + try { + return X11Lib.XF86VidModeSetGammaRamp(display, screen, size, red_array, green_array, blue_array); + } finally { + unlockDefaultToolkit(display); + } + } + + public static boolean XF86VidModeSetGammaRamp(long display, int screen, int size, short[] red_array, int red_array_offset, short[] green_array, int green_array_offset, short[] blue_array, int blue_array_offset) { + lockDefaultToolkit(display); + try { + return X11Lib.XF86VidModeSetGammaRamp(display, screen, size, red_array, red_array_offset, green_array, green_array_offset, blue_array, blue_array_offset); + } finally { + unlockDefaultToolkit(display); + } + } + + public static void XLockDisplay(long handle) { + if(ToolkitLock.TRACE_LOCK) { + System.out.println("+++ X11 Display Lock get 0x"+Long.toHexString(handle)); + } + X11Lib.XLockDisplay(handle); + } + + public static void XUnlockDisplay(long handle) { + if(ToolkitLock.TRACE_LOCK) { + System.out.println("--- X11 Display Lock rel 0x"+Long.toHexString(handle)); + } + X11Lib.XUnlockDisplay(handle); + } + + private static native void initialize0(boolean firstUIActionOnProcess); + private static native void setX11ErrorHandler0(boolean onoff, boolean quiet); +} diff --git a/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c new file mode 100644 index 000000000..470f03a49 --- /dev/null +++ b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +#include <jawt_md.h> + +#ifdef WIN32 + #define PLATFORM_DSI_SIZE sizeof(JAWT_Win32DrawingSurfaceInfo) +#elif defined(linux) || defined(__sun) || defined(__FreeBSD__) || defined(_HPUX) + #define PLATFORM_DSI_SIZE sizeof(JAWT_X11DrawingSurfaceInfo) +#elif defined(macosx) + #define PLATFORM_DSI_SIZE sizeof(JAWT_MacOSXDrawingSurfaceInfo) +#else + ERROR: port JAWT_DrawingSurfaceInfo.c to your platform +#endif + +JNIEXPORT jobject JNICALL +Java_jogamp_nativewindow_jawt_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) { + JAWT_DrawingSurfaceInfo* dsi; + dsi = (*env)->GetDirectBufferAddress(env, jthis0); + if (dsi == NULL) { + (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"), + "Argument \"jthis0\" was not a direct buffer"); + return NULL; + } + if (dsi->platformInfo == NULL) { + return NULL; + } + return (*env)->NewDirectByteBuffer(env, dsi->platformInfo, PLATFORM_DSI_SIZE); +} diff --git a/src/nativewindow/native/NativewindowCommon.c b/src/nativewindow/native/NativewindowCommon.c new file mode 100644 index 000000000..e357045d6 --- /dev/null +++ b/src/nativewindow/native/NativewindowCommon.c @@ -0,0 +1,57 @@ + +#include "NativewindowCommon.h" + +static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException"; +static jclass runtimeExceptionClz=NULL; + +void NativewindowCommon_FatalError(JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + fprintf(stderr, "%s\n", buffer); + (*env)->FatalError(env, buffer); +} + +void NativewindowCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + (*env)->ThrowNew(env, runtimeExceptionClz, buffer); +} + +int NativewindowCommon_init(JNIEnv *env) { + if(NULL==runtimeExceptionClz) { + jclass c = (*env)->FindClass(env, ClazzNameRuntimeException); + if(NULL==c) { + NativewindowCommon_FatalError(env, "Nativewindow: can't find %s", ClazzNameRuntimeException); + } + runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==runtimeExceptionClz) { + NativewindowCommon_FatalError(env, "Nativewindow: can't use %s", ClazzNameRuntimeException); + } + return 1; + } + return 0; +} + +jchar* NativewindowCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str) +{ + jchar* strChars = NULL; + strChars = calloc((*env)->GetStringLength(env, str) + 1, sizeof(jchar)); + if (strChars != NULL) { + (*env)->GetStringRegion(env, str, 0, (*env)->GetStringLength(env, str), strChars); + } + return strChars; +} + diff --git a/src/nativewindow/native/NativewindowCommon.h b/src/nativewindow/native/NativewindowCommon.h new file mode 100644 index 000000000..5dc5debef --- /dev/null +++ b/src/nativewindow/native/NativewindowCommon.h @@ -0,0 +1,15 @@ + +#ifndef NATIVEWINDOW_COMMON_H +#define NATIVEWINDOW_COMMON_H 1 + +#include <jni.h> +#include <stdlib.h> + +int NativewindowCommon_init(JNIEnv *env); + +jchar* NativewindowCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str); + +void NativewindowCommon_FatalError(JNIEnv *env, const char* msg, ...); +void NativewindowCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...); + +#endif diff --git a/src/nativewindow/native/windows/GDImisc.c b/src/nativewindow/native/windows/GDImisc.c new file mode 100644 index 000000000..9bead17ec --- /dev/null +++ b/src/nativewindow/native/windows/GDImisc.c @@ -0,0 +1,242 @@ +#include <jni.h> +#include <stdlib.h> +#include <assert.h> + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#undef WIN32_LEAN_AND_MEAN + +#include <wingdi.h> +#include <stddef.h> + +#ifdef _WIN32 + #ifdef _MSC_VER + /* This typedef is apparently needed for Microsoft compilers before VC8, + and on Windows CE */ + #if (_MSC_VER < 1400) || defined(UNDER_CE) + #ifdef _WIN64 + typedef long long intptr_t; + #else + typedef int intptr_t; + #endif + #endif + #else + #include <inttypes.h> + #endif +#else + #include <inttypes.h> +#endif + +#include <stdio.h> + +#include "NativewindowCommon.h" +#include "jogamp_nativewindow_windows_GDI.h" + +// #define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(args...) fprintf(stderr, args); +#else + #define DBG_PRINT(args...) +#endif + +static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point"; +static const char * const ClazzAnyCstrName = "<init>"; +static const char * const ClazzNamePointCstrSignature = "(II)V"; + +static jclass pointClz = NULL; +static jmethodID pointCstr = NULL; + +HINSTANCE GetApplicationHandle() { + return GetModuleHandle(NULL); +} + +/* Java->C glue code: + * Java package: jogamp.nativewindow.windows.GDI + * Java method: boolean CreateWindowClass(long hInstance, java.lang.String clazzName, long wndProc) + * C function: BOOL CreateWindowClass(HANDLE hInstance, LPCSTR clazzName, HANDLE wndProc); + */ +JNIEXPORT jboolean JNICALL +Java_jogamp_nativewindow_windows_GDI_CreateWindowClass + (JNIEnv *env, jclass _unused, jlong jHInstance, jstring jClazzName, jlong wndProc) +{ + HINSTANCE hInstance = (HINSTANCE) (intptr_t) jHInstance; + const TCHAR* clazzName = NULL; + WNDCLASS wc; + jboolean res; + +#ifdef UNICODE + clazzName = NewtCommon_GetNullTerminatedStringChars(env, jClazzName); +#else + clazzName = (*env)->GetStringUTFChars(env, jClazzName, NULL); +#endif + + ZeroMemory( &wc, sizeof( wc ) ); + if( GetClassInfo( hInstance, clazzName, &wc ) ) { + // registered already + res = JNI_TRUE; + } else { + // register now + ZeroMemory( &wc, sizeof( wc ) ); + wc.style = CS_HREDRAW | CS_VREDRAW ; + wc.lpfnWndProc = (WNDPROC) (intptr_t) wndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = NULL; + wc.hCursor = LoadCursor( NULL, IDC_ARROW); + wc.hbrBackground = NULL; // no background paint - GetStockObject(BLACK_BRUSH); + wc.lpszMenuName = NULL; + wc.lpszClassName = clazzName; + res = ( 0 != RegisterClass( &wc ) ) ? JNI_TRUE : JNI_FALSE ; + } + +#ifdef UNICODE + free((void*) clazzName); +#else + (*env)->ReleaseStringUTFChars(env, jClazzName, clazzName); +#endif + + return res; +} + +/* Java->C glue code: + * Java package: jogamp.nativewindow.windows.GDI + * Java method: boolean DestroyWindowClass(long hInstance, java.lang.String className) + * C function: BOOL DestroyWindowClass(HANDLE hInstance, LPCSTR className); + */ +JNIEXPORT jboolean JNICALL +Java_jogamp_nativewindow_windows_GDI_DestroyWindowClass + (JNIEnv *env, jclass _unused, jlong jHInstance, jstring jClazzName) +{ + HINSTANCE hInstance = (HINSTANCE) (intptr_t) jHInstance; + const TCHAR* clazzName = NULL; + jboolean res; + +#ifdef UNICODE + clazzName = NewtCommon_GetNullTerminatedStringChars(env, jClazzName); +#else + clazzName = (*env)->GetStringUTFChars(env, jClazzName, NULL); +#endif + + res = ( 0 != UnregisterClass( clazzName, hInstance ) ) ? JNI_TRUE : JNI_FALSE ; + +#ifdef UNICODE + free((void*) clazzName); +#else + (*env)->ReleaseStringUTFChars(env, jClazzName, clazzName); +#endif + + return res; +} + + +/* Java->C glue code: + * Java package: jogamp.nativewindow.windows.GDI + * Java method: long CreateDummyWindow0(long hInstance, java.lang.String className, java.lang.String windowName, int x, int y, int width, int height) + * C function: HANDLE CreateDummyWindow0(HANDLE hInstance, LPCSTR className, LPCSTR windowName, int x, int y, int width, int height); + */ +JNIEXPORT jlong JNICALL +Java_jogamp_nativewindow_windows_GDI_CreateDummyWindow0 + (JNIEnv *env, jclass _unused, jlong jHInstance, jstring jWndClassName, jstring jWndName, jint x, jint y, jint width, jint height) +{ + HINSTANCE hInstance = (HINSTANCE) (intptr_t) jHInstance; + const TCHAR* wndClassName = NULL; + const TCHAR* wndName = NULL; + DWORD dwExStyle; + DWORD dwStyle; + HWND hWnd; + +#ifdef UNICODE + wndClassName = NewtCommon_GetNullTerminatedStringChars(env, jWndClassName); + wndName = NewtCommon_GetNullTerminatedStringChars(env, jWndName); +#else + wndClassName = (*env)->GetStringUTFChars(env, jWndClassName, NULL); + wndName = (*env)->GetStringUTFChars(env, jWndName, NULL); +#endif + + dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + dwStyle = WS_OVERLAPPEDWINDOW; + + hWnd = CreateWindowEx( dwExStyle, + wndClassName, + wndName, + dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + x, y, width, height, + NULL, NULL, hInstance, NULL ); + +#ifdef UNICODE + free((void*) wndClassName); + free((void*) wndName); +#else + (*env)->ReleaseStringUTFChars(env, jWndClassName, wndClassName); + (*env)->ReleaseStringUTFChars(env, jWndName, wndName); +#endif + + return (jlong) (intptr_t) hWnd; +} + + +/* + * Class: jogamp_nativewindow_windows_GDI + * Method: initIDs0 + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_nativewindow_windows_GDI_initIDs0 + (JNIEnv *env, jclass clazz) +{ + if(NativewindowCommon_init(env)) { + jclass c = (*env)->FindClass(env, ClazzNamePoint); + if(NULL==c) { + NativewindowCommon_FatalError(env, "FatalError jogamp_nativewindow_windows_GDI: can't find %s", ClazzNamePoint); + } + pointClz = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==pointClz) { + NativewindowCommon_FatalError(env, "FatalError jogamp_nativewindow_windows_GDI: can't use %s", ClazzNamePoint); + } + pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature); + if(NULL==pointCstr) { + NativewindowCommon_FatalError(env, "FatalError jogamp_nativewindow_windows_GDI: can't fetch %s.%s %s", + ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature); + } + } + return JNI_TRUE; +} + +LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + return DefWindowProc(hWnd,uMsg,wParam,lParam); +} + +/* + * Class: jogamp_nativewindow_windows_GDI + * Method: getDummyWndProc0 + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_windows_GDI_getDummyWndProc0 + (JNIEnv *env, jclass clazz) +{ + return (jlong) (intptr_t) DummyWndProc; +} + +/* + * Class: jogamp_nativewindow_windows_GDI + * Method: GetRelativeLocation0 + * Signature: (JJII)Ljavax/media/nativewindow/util/Point; + */ +JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_windows_GDI_GetRelativeLocation0 + (JNIEnv *env, jclass unused, jlong jsrc_win, jlong jdest_win, jint src_x, jint src_y) +{ + HWND src_win = (HWND) (intptr_t) jsrc_win; + HWND dest_win = (HWND) (intptr_t) jdest_win; + POINT dest = { src_x, src_y } ; + int res; + + res = MapWindowPoints(src_win, dest_win, &dest, 1); + + DBG_PRINT("*** WindowsWindow: getRelativeLocation0: %p %d/%d -> %p %d/%d - ok: %d\n", + (void*)src_win, src_x, src_y, (void*)dest_win, (int)dest.x, (int)dest.y, res); + + return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest.x, (jint)dest.y); +} + diff --git a/src/nativewindow/native/x11/XineramaHelper.c b/src/nativewindow/native/x11/XineramaHelper.c new file mode 100644 index 000000000..899bbba55 --- /dev/null +++ b/src/nativewindow/native/x11/XineramaHelper.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +/* This file contains a helper routine to be called by Java code to + determine whether the Xinerama extension is in use and therefore to + treat the multiple AWT screens as one large screen. */ + +#include <inttypes.h> +#include <X11/Xlib.h> + +#ifdef __sun + +typedef Status XineramaGetInfoFunc(Display* display, int screen_number, + XRectangle* framebuffer_rects, unsigned char* framebuffer_hints, + int* num_framebuffers); +typedef Status XineramaGetCenterHintFunc(Display* display, int screen_number, + int* x, int* y); + +XineramaGetCenterHintFunc* XineramaSolarisCenterFunc = NULL; +#include <dlfcn.h> + +#else + +#include <X11/extensions/Xinerama.h> + +#endif + +Bool XineramaEnabled(Display* display) { +#ifdef __sun + +#define MAXFRAMEBUFFERS 16 + char* XinExtName = "XINERAMA"; + int32_t major_opcode, first_event, first_error; + Bool gotXinExt = False; + void* libHandle = 0; + unsigned char fbhints[MAXFRAMEBUFFERS]; + XRectangle fbrects[MAXFRAMEBUFFERS]; + int locNumScr = 0; + Bool usingXinerama = False; + + char* XineramaLibName= "libXext.so"; + char* XineramaGetInfoName = "XineramaGetInfo"; + char* XineramaGetCenterHintName = "XineramaGetCenterHint"; + XineramaGetInfoFunc* XineramaSolarisFunc = NULL; + + gotXinExt = XQueryExtension(display, XinExtName, &major_opcode, + &first_event, &first_error); + + if (gotXinExt) { + /* load library, load and run XineramaGetInfo */ + libHandle = dlopen(XineramaLibName, RTLD_LAZY | RTLD_GLOBAL); + if (libHandle != 0) { + XineramaSolarisFunc = (XineramaGetInfoFunc*)dlsym(libHandle, XineramaGetInfoName); + XineramaSolarisCenterFunc = + (XineramaGetCenterHintFunc*)dlsym(libHandle, + XineramaGetCenterHintName); + if (XineramaSolarisFunc != NULL) { + if ((*XineramaSolarisFunc)(display, 0, &fbrects[0], + &fbhints[0], &locNumScr) != 0) { + + usingXinerama = True; + } + } + dlclose(libHandle); + } + } + return usingXinerama; + +#else + + char* XinExtName = "XINERAMA"; + int32_t major_opcode, first_event, first_error; + Bool gotXinExt = False; + int32_t locNumScr = 0; + + XineramaScreenInfo *xinInfo; + + gotXinExt = XQueryExtension(display, XinExtName, &major_opcode, + &first_event, &first_error); + + if (gotXinExt) { + xinInfo = XineramaQueryScreens(display, &locNumScr); + if (xinInfo != NULL) { + return True; + } + } + return False; + +#endif +} + diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c new file mode 100644 index 000000000..1ced0fff4 --- /dev/null +++ b/src/nativewindow/native/x11/Xmisc.c @@ -0,0 +1,521 @@ +/** + * 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. + */ + + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <stdarg.h> +#include <unistd.h> +#include <errno.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +/* Linux headers don't work properly */ +#define __USE_GNU +#include <dlfcn.h> +#undef __USE_GNU + +/* Current versions of Solaris don't expose the XF86 extensions, + although with the recent transition to Xorg this will probably + happen in an upcoming release */ +#if !defined(__sun) && !defined(_HPUX) +#include <X11/extensions/xf86vmode.h> +#else +/* Need to provide stubs for these */ +Bool XF86VidModeGetGammaRampSize( + Display *display, + int screen, + int* size) +{ + return False; +} + +Bool XF86VidModeGetGammaRamp( + Display *display, + int screen, + int size, + unsigned short *red_array, + unsigned short *green_array, + unsigned short *blue_array) { + return False; +} +Bool XF86VidModeSetGammaRamp( + Display *display, + int screen, + int size, + unsigned short *red_array, + unsigned short *green_array, + unsigned short *blue_array) { + return False; +} +#endif /* defined(__sun) || defined(_HPUX) */ + +/* HP-UX doesn't define RTLD_DEFAULT. */ +#if defined(_HPUX) && !defined(RTLD_DEFAULT) +#define RTLD_DEFAULT NULL +#endif + +#include "NativewindowCommon.h" +#include "jogamp_nativewindow_x11_X11Lib.h" + +// #define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(args...) fprintf(stderr, args); +#else + #define DBG_PRINT(args...) +#endif + +/* Need to pull this in as we don't have a stub header for it */ +extern Bool XineramaEnabled(Display* display); + +static const char * const ClazzNameBuffers = "com/jogamp/common/nio/Buffers"; +static const char * const ClazzNameBuffersStaticCstrName = "copyByteBuffer"; +static const char * const ClazzNameBuffersStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;"; +static const char * const ClazzNameByteBuffer = "java/nio/ByteBuffer"; +static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point"; +static const char * const ClazzAnyCstrName = "<init>"; +static const char * const ClazzNamePointCstrSignature = "(II)V"; +static jclass clazzBuffers = NULL; +static jmethodID cstrBuffers = NULL; +static jclass clazzByteBuffer = NULL; +static jclass pointClz = NULL; +static jmethodID pointCstr = NULL; + +static void _initClazzAccess(JNIEnv *env) { + jclass c; + + if(!NativewindowCommon_init(env)) return; + + c = (*env)->FindClass(env, ClazzNameBuffers); + if(NULL==c) { + NativewindowCommon_FatalError(env, "FatalError Java_jogamp_nativewindow_x11_X11Lib: can't find %s", ClazzNameBuffers); + } + clazzBuffers = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==clazzBuffers) { + NativewindowCommon_FatalError(env, "FatalError Java_jogamp_nativewindow_x11_X11Lib: can't use %s", ClazzNameBuffers); + } + c = (*env)->FindClass(env, ClazzNameByteBuffer); + if(NULL==c) { + NativewindowCommon_FatalError(env, "FatalError Java_jogamp_nativewindow_x11_X11Lib: can't find %s", ClazzNameByteBuffer); + } + clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==c) { + NativewindowCommon_FatalError(env, "FatalError Java_jogamp_nativewindow_x11_X11Lib: can't use %s", ClazzNameByteBuffer); + } + + cstrBuffers = (*env)->GetStaticMethodID(env, clazzBuffers, + ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature); + if(NULL==cstrBuffers) { + NativewindowCommon_FatalError(env, "FatalError Java_jogamp_nativewindow_x11_X11Lib: can't create %s.%s %s", + ClazzNameBuffers, ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature); + } + + c = (*env)->FindClass(env, ClazzNamePoint); + if(NULL==c) { + NativewindowCommon_FatalError(env, "FatalError Java_jogamp_nativewindow_x11_X11Lib: can't find %s", ClazzNamePoint); + } + pointClz = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==pointClz) { + NativewindowCommon_FatalError(env, "FatalError Java_jogamp_nativewindow_x11_X11Lib: can't use %s", ClazzNamePoint); + } + pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature); + if(NULL==pointCstr) { + NativewindowCommon_FatalError(env, "FatalError Java_jogamp_nativewindow_x11_X11Lib: can't fetch %s.%s %s", + ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature); + } +} + +static JNIEnv * x11ErrorHandlerJNIEnv = NULL; +static XErrorHandler origErrorHandler = NULL ; +static int errorHandlerBlocked = 0 ; +static int errorHandlerQuiet = 0 ; + +static int x11ErrorHandler(Display *dpy, XErrorEvent *e) +{ + if(!errorHandlerQuiet) { + fprintf(stderr, "Info: Nativewindow X11 Error: Display %p, Code 0x%X, errno %s\n", dpy, e->error_code, strerror(errno)); + } +#if 0 + // Since the X11 Error may happen anytime, a exception could mess up the JVM completely. + // Experienced this for remote displays issuing non supported commands, eg. glXCreateContextAttribsARB(..) + // + NativewindowCommon_throwNewRuntimeException(x11ErrorHandlerJNIEnv, "Info: Nativewindow X11 Error: Display %p, Code 0x%X, errno %s", + dpy, e->error_code, strerror(errno)); +#endif + +#if 0 + if(NULL!=origErrorHandler) { + origErrorHandler(dpy, e); + } +#endif + + return 0; +} + +static void x11ErrorHandlerEnable(Display *dpy, int onoff, JNIEnv * env) { + if(errorHandlerBlocked) return; + + if(onoff) { + if(NULL==origErrorHandler) { + x11ErrorHandlerJNIEnv = env; + if(NULL!=dpy) { + XSync(dpy, False); + } + origErrorHandler = XSetErrorHandler(x11ErrorHandler); + } + } else { + if(NULL!=origErrorHandler) { + if(NULL!=dpy) { + XSync(dpy, False); + } + XSetErrorHandler(origErrorHandler); + origErrorHandler = NULL; + } + } +} + +static void x11ErrorHandlerEnableBlocking(JNIEnv * env, int onoff, int quiet) { + errorHandlerBlocked = 0 ; + x11ErrorHandlerEnable(NULL, onoff, env); + errorHandlerBlocked = onoff ; + errorHandlerQuiet = quiet; +} + + +static XIOErrorHandler origIOErrorHandler = NULL; + +static int x11IOErrorHandler(Display *dpy) +{ + fprintf(stderr, "Nativewindow X11 IOError: Display %p (%s): %s\n", dpy, XDisplayName(NULL), strerror(errno)); + // NativewindowCommon_FatalError(x11ErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p (%s): %s", dpy, XDisplayName(NULL), strerror(errno)); + if(NULL!=origIOErrorHandler) { + origIOErrorHandler(dpy); + } + return 0; +} + +static void x11IOErrorHandlerEnable(int onoff, JNIEnv * env) { + if(onoff) { + if(NULL==origIOErrorHandler) { + x11ErrorHandlerJNIEnv = env; + origIOErrorHandler = XSetIOErrorHandler(x11IOErrorHandler); + } + } else { + XSetIOErrorHandler(origIOErrorHandler); + origIOErrorHandler = NULL; + } +} + +static int _initialized=0; + +JNIEXPORT void JNICALL +Java_jogamp_nativewindow_x11_X11Util_initialize0(JNIEnv *env, jclass _unused, jboolean firstUIActionOnProcess) { + if(0==_initialized) { + if( JNI_TRUE == firstUIActionOnProcess ) { + if( 0 == XInitThreads() ) { + fprintf(stderr, "Warning: XInitThreads() failed\n"); + } else { + fprintf(stderr, "Info: XInitThreads() called for concurrent Thread support\n"); + } + } else { + fprintf(stderr, "Info: XInitThreads() _not_ called for concurrent Thread support\n"); + } + + _initClazzAccess(env); + x11IOErrorHandlerEnable(1, env); + _initialized=1; + } +} + +JNIEXPORT void JNICALL +Java_jogamp_nativewindow_x11_X11Util_setX11ErrorHandler0(JNIEnv *env, jclass _unused, jboolean onoff, jboolean quiet) { + x11ErrorHandlerEnableBlocking(env, ( JNI_TRUE == onoff ) ? 1 : 0, ( JNI_TRUE == quiet ) ? 1 : 0); +} + +/* Java->C glue code: + * Java package: jogamp.nativewindow.x11.X11Lib + * Java method: XVisualInfo XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, java.nio.IntBuffer arg3) + * C function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); + */ +JNIEXPORT jobject JNICALL +Java_jogamp_nativewindow_x11_X11Lib_XGetVisualInfo1__JJLjava_nio_ByteBuffer_2Ljava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong arg0, jlong arg1, jobject arg2, jobject arg3, jint arg3_byte_offset) { + XVisualInfo * _ptr2 = NULL; + int * _ptr3 = NULL; + XVisualInfo * _res; + int count; + jobject jbyteSource; + jobject jbyteCopy; + if(0==arg0) { + NativewindowCommon_FatalError(env, "invalid display connection.."); + } + if (arg2 != NULL) { + _ptr2 = (XVisualInfo *) (((char*) (*env)->GetDirectBufferAddress(env, arg2)) + 0); + } + if (arg3 != NULL) { + _ptr3 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) + arg3_byte_offset); + } + x11ErrorHandlerEnable((Display *) (intptr_t) arg0, 1, env); + _res = XGetVisualInfo((Display *) (intptr_t) arg0, (long) arg1, (XVisualInfo *) _ptr2, (int *) _ptr3); + x11ErrorHandlerEnable((Display *) (intptr_t) arg0, 0, env); + count = _ptr3[0]; + if (arg3 != NULL) { + (*env)->ReleasePrimitiveArrayCritical(env, arg3, _ptr3, 0); + } + if (_res == NULL) return NULL; + + jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(XVisualInfo)); + jbyteCopy = (*env)->CallStaticObjectMethod(env, clazzBuffers, cstrBuffers, jbyteSource); + + XFree(_res); + + return jbyteCopy; +} + +JNIEXPORT jlong JNICALL +Java_jogamp_nativewindow_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) { + jlong r; + if(0==display) { + NativewindowCommon_FatalError(env, "invalid display connection.."); + } + x11ErrorHandlerEnable((Display *) (intptr_t) display, 1, env); + r = (jlong) XVisualIDFromVisual( DefaultVisual( (Display*) (intptr_t) display, screen ) ); + x11ErrorHandlerEnable((Display *) (intptr_t) display, 0, env); + return r; +} + +/* Java->C glue code: + * Java package: jogamp.nativewindow.x11.X11Lib + * Java method: void XLockDisplay(long display) + * C function: void XLockDisplay(Display * display); + */ +JNIEXPORT void JNICALL +Java_jogamp_nativewindow_x11_X11Lib_XLockDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + if(0==display) { + NativewindowCommon_FatalError(env, "invalid display connection.."); + } + XLockDisplay((Display *) (intptr_t) display); +} + +/* Java->C glue code: + * Java package: jogamp.nativewindow.x11.X11Lib + * Java method: void XUnlockDisplay(long display) + * C function: void XUnlockDisplay(Display * display); + */ +JNIEXPORT void JNICALL +Java_jogamp_nativewindow_x11_X11Lib_XUnlockDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + if(0==display) { + NativewindowCommon_FatalError(env, "invalid display connection.."); + } + XUnlockDisplay((Display *) (intptr_t) display); +} + +/* Java->C glue code: + * Java package: jogamp.nativewindow.x11.X11Lib + * Java method: int XCloseDisplay(long display) + * C function: int XCloseDisplay(Display * display); + */ +JNIEXPORT jint JNICALL +Java_jogamp_nativewindow_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + int _res; + if(0==display) { + NativewindowCommon_FatalError(env, "invalid display connection.."); + } + x11ErrorHandlerEnable((Display *) (intptr_t) display, 1, env); + _res = XCloseDisplay((Display *) (intptr_t) display); + x11ErrorHandlerEnable(NULL, 0, env); + return _res; +} + +/* + * Class: jogamp_nativewindow_x11_X11Lib + * Method: CreateDummyWindow + * Signature: (JIJII)J + */ +JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_x11_X11Lib_CreateDummyWindow + (JNIEnv *env, jclass unused, jlong display, jint screen_index, jlong visualID, jint width, jint height) +{ + Display * dpy = (Display *)(intptr_t)display; + int scrn_idx = (int)screen_index; + Window windowParent = 0; + Window window = 0; + + XVisualInfo visualTemplate; + XVisualInfo *pVisualQuery = NULL; + Visual *visual = NULL; + int depth; + + XSetWindowAttributes xswa; + unsigned long attrMask; + int n; + + Screen* scrn; + + if(NULL==dpy) { + NativewindowCommon_FatalError(env, "invalid display connection.."); + return 0; + } + + if(visualID<0) { + NativewindowCommon_throwNewRuntimeException(env, "invalid VisualID .."); + return 0; + } + + x11ErrorHandlerEnable(dpy, 1, env); + + scrn = ScreenOfDisplay(dpy, scrn_idx); + + // try given VisualID on screen + memset(&visualTemplate, 0, sizeof(XVisualInfo)); + visualTemplate.screen = scrn_idx; + visualTemplate.visualid = (VisualID)visualID; + pVisualQuery = XGetVisualInfo(dpy, VisualIDMask|VisualScreenMask, &visualTemplate,&n); + if(pVisualQuery!=NULL) { + visual = pVisualQuery->visual; + depth = pVisualQuery->depth; + visualID = (jlong)pVisualQuery->visualid; + XFree(pVisualQuery); + pVisualQuery=NULL; + } + DBG_PRINT( "X11: [CreateWindow] trying given (dpy %p, screen %d, visualID: %d, parent %p) found: %p\n", dpy, scrn_idx, (int)visualID, windowParent, visual); + + if (visual==NULL) + { + x11ErrorHandlerEnable(dpy, 0, env); + NativewindowCommon_throwNewRuntimeException(env, "could not query Visual by given VisualID, bail out!"); + return 0; + } + + if(pVisualQuery!=NULL) { + XFree(pVisualQuery); + pVisualQuery=NULL; + } + + if(0==windowParent) { + windowParent = XRootWindowOfScreen(scrn); + } + + attrMask = ( CWBackingStore | CWBackingPlanes | CWBackingPixel | CWBackPixmap | + CWBorderPixel | CWColormap | CWOverrideRedirect ) ; + + memset(&xswa, 0, sizeof(xswa)); + xswa.override_redirect = False; // use the window manager, always + xswa.border_pixel = 0; + xswa.background_pixmap = None; + xswa.backing_store=NotUseful; /* NotUseful, WhenMapped, Always */ + xswa.backing_planes=0; /* planes to be preserved if possible */ + xswa.backing_pixel=0; /* value to use in restoring planes */ + + xswa.colormap = XCreateColormap(dpy, + XRootWindow(dpy, scrn_idx), + visual, + AllocNone); + + window = XCreateWindow(dpy, + windowParent, + 0, 0, + width, height, + 0, // border width + depth, + InputOutput, + visual, + attrMask, + &xswa); + + XSync(dpy, False); + + XSelectInput(dpy, window, 0); // no events + XSync(dpy, False); + + x11ErrorHandlerEnable(dpy, 0, env); + + DBG_PRINT( "X11: [CreateWindow] created window %p on display %p\n", window, dpy); + + return (jlong) window; +} + + +/* + * Class: jogamp_nativewindow_x11_X11Lib + * Method: DestroyDummyWindow + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_jogamp_nativewindow_x11_X11Lib_DestroyDummyWindow + (JNIEnv *env, jclass unused, jlong display, jlong window) +{ + Display * dpy = (Display *)(intptr_t)display; + Window w = (Window) window; + + if(NULL==dpy) { + NativewindowCommon_throwNewRuntimeException(env, "invalid display connection.."); + return; + } + + x11ErrorHandlerEnable(dpy, 1, env); + XUnmapWindow(dpy, w); + XSync(dpy, False); + XDestroyWindow(dpy, w); + x11ErrorHandlerEnable(dpy, 0, env); +} + +/* + * Class: jogamp_nativewindow_x11_X11Lib + * Method: GetRelativeLocation + * Signature: (JIJJII)Ljavax/media/nativewindow/util/Point; + */ +JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_x11_X11Lib_GetRelativeLocation0 + (JNIEnv *env, jclass unused, jlong jdisplay, jint screen_index, jlong jsrc_win, jlong jdest_win, jint src_x, jint src_y) +{ + Display * dpy = (Display *) (intptr_t) jdisplay; + Screen * scrn = ScreenOfDisplay(dpy, (int)screen_index); + Window root = XRootWindowOfScreen(scrn); + Window src_win = (Window)jsrc_win; + Window dest_win = (Window)jdest_win; + int dest_x=-1; + int dest_y=-1; + Window child; + Bool res; + + if( 0 == jdest_win ) { dest_win = root; } + if( 0 == jsrc_win ) { src_win = root; } + + x11ErrorHandlerEnable(dpy, 1, env); + + res = XTranslateCoordinates(dpy, src_win, dest_win, src_x, src_y, &dest_x, &dest_y, &child); + + x11ErrorHandlerEnable(dpy, 0, env); + + DBG_PRINT( "X11: GetRelativeLocation0: %p %d/%d -> %p %d/%d - ok: %d\n", + (void*)src_win, src_x, src_y, (void*)dest_win, dest_x, dest_y, (int)res); + + return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest_x, (jint)dest_y); +} + diff --git a/src/net/java/dev/typecast/ot/Disassembler.java b/src/net/java/dev/typecast/ot/Disassembler.java deleted file mode 100644 index 73e75cc39..000000000 --- a/src/net/java/dev/typecast/ot/Disassembler.java +++ /dev/null @@ -1,109 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot; - -/** - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Disassembler.java,v 1.1.1.1 2004-12-05 23:14:25 davidsch Exp $ - */ -public class Disassembler { - - /** - * Advance the instruction pointer to the next executable opcode. - * This will be the next byte, unless the current opcode is a push - * instruction, in which case it will be the byte immediately beyond - * the last data byte. - * @param ip The current instruction pointer - * @return The new instruction pointer - */ - public static int advanceIP(short[] instructions, int ip) { - - // The high word specifies font, cvt, or glyph program - int i = ip & 0xffff; - int dataCount; - ip++; - if (Mnemonic.NPUSHB == instructions[i]) { - // Next byte is the data byte count - dataCount = instructions[++i]; - ip += dataCount + 1; - } else if (Mnemonic.NPUSHW == instructions[i]) { - // Next byte is the data word count - dataCount = instructions[++i]; - ip += dataCount*2 + 1; - } else if (Mnemonic.PUSHB == (instructions[i] & 0xf8)) { - dataCount = (short)((instructions[i] & 0x07) + 1); - ip += dataCount; - } else if (Mnemonic.PUSHW == (instructions[i] & 0xf8)) { - dataCount = (short)((instructions[i] & 0x07) + 1); - ip += dataCount*2; - } - return ip; - } - - public static short getPushCount(short[] instructions, int ip) { - short instr = instructions[ip & 0xffff]; - if ((Mnemonic.NPUSHB == instr) || (Mnemonic.NPUSHW == instr)) { - return instructions[(ip & 0xffff) + 1]; - } else if ((Mnemonic.PUSHB == (instr & 0xf8)) || (Mnemonic.PUSHW == (instr & 0xf8))) { - return (short)((instr & 0x07) + 1); - } - return 0; - } - - public static int[] getPushData(short[] instructions, int ip) { - int count = getPushCount(instructions, ip); - int[] data = new int[count]; - int i = ip & 0xffff; - short instr = instructions[i]; - if (Mnemonic.NPUSHB == instr) { - for (int j = 0; j < count; j++) { - data[j] = instructions[i + j + 2]; - } - } else if (Mnemonic.PUSHB == (instr & 0xf8)) { - for (int j = 0; j < count; j++) { - data[j] = instructions[i + j + 1]; - } - } else if (Mnemonic.NPUSHW == instr) { - for (int j = 0; j < count; j++) { - data[j] = (instructions[i + j*2 + 2] << 8) | instructions[i + j*2 + 3]; - } - } else if (Mnemonic.PUSHW == (instr & 0xf8)) { - for (int j = 0; j < count; j++) { - data[j] = (instructions[i + j*2 + 1] << 8) | instructions[i + j*2 + 2]; - } - } - return data; - } - - public static String disassemble(short[] instructions, int leadingSpaces) { - StringBuffer sb = new StringBuffer(); - int ip = 0; - while (ip < instructions.length) { - for (int i = 0; i < leadingSpaces; i++) { - sb.append(" "); - } - sb.append(ip).append(": "); - sb.append(Mnemonic.getMnemonic(instructions[ip])); - if (getPushCount(instructions, ip) > 0) { - int[] data = getPushData(instructions, ip); - for(int j = 0; j < data.length; j++) { - if ((instructions[ip] == Mnemonic.PUSHW) || - (instructions[ip] == Mnemonic.NPUSHW)) { - sb.append(" ").append((short) data[j]); - } else { - sb.append(" ").append(data[j]); - } - } - } - sb.append("\n"); - ip = advanceIP(instructions, ip); - } - return sb.toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/Fixed.java b/src/net/java/dev/typecast/ot/Fixed.java deleted file mode 100644 index 6f83e922c..000000000 --- a/src/net/java/dev/typecast/ot/Fixed.java +++ /dev/null @@ -1,852 +0,0 @@ -/* - * $Id: Fixed.java,v 1.1.1.1 2004-12-05 23:14:26 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot; - -/** - * Functions for working with signed 16.16 fixed values - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Fixed.java,v 1.1.1.1 2004-12-05 23:14:26 davidsch Exp $ - */ -public class Fixed { - - // Tangent LUT - static private int[] t = { - 0x0, - 0x1, - 0x3, - 0x4, - 0x6, - 0x7, - 0x9, - 0xb, - 0xc, - 0xe, - 0xf, - 0x11, - 0x12, - 0x14, - 0x16, - 0x17, - 0x19, - 0x1a, - 0x1c, - 0x1d, - 0x1f, - 0x21, - 0x22, - 0x24, - 0x25, - 0x27, - 0x29, - 0x2a, - 0x2c, - 0x2e, - 0x2f, - 0x31, - 0x32, - 0x34, - 0x36, - 0x37, - 0x39, - 0x3b, - 0x3c, - 0x3e, - 0x40, - 0x41, - 0x43, - 0x45, - 0x46, - 0x48, - 0x4a, - 0x4b, - 0x4d, - 0x4f, - 0x51, - 0x52, - 0x54, - 0x56, - 0x58, - 0x59, - 0x5b, - 0x5d, - 0x5f, - 0x60, - 0x62, - 0x64, - 0x66, - 0x68, - 0x6a, - 0x6b, - 0x6d, - 0x6f, - 0x71, - 0x73, - 0x75, - 0x77, - 0x79, - 0x7b, - 0x7c, - 0x7e, - 0x80, - 0x82, - 0x84, - 0x86, - 0x88, - 0x8a, - 0x8c, - 0x8e, - 0x91, - 0x93, - 0x95, - 0x97, - 0x99, - 0x9b, - 0x9d, - 0x9f, - 0xa2, - 0xa4, - 0xa6, - 0xa8, - 0xab, - 0xad, - 0xaf, - 0xb1, - 0xb4, - 0xb6, - 0xb9, - 0xbb, - 0xbd, - 0xc0, - 0xc2, - 0xc5, - 0xc7, - 0xca, - 0xcc, - 0xcf, - 0xd2, - 0xd4, - 0xd7, - 0xda, - 0xdc, - 0xdf, - 0xe2, - 0xe5, - 0xe8, - 0xea, - 0xed, - 0xf0, - 0xf3, - 0xf6, - 0xf9, - 0xfc, - 0x100, - 0x103, - 0x106, - 0x109, - 0x10c, - 0x110, - 0x113, - 0x116, - 0x11a, - 0x11d, - 0x121, - 0x125, - 0x128, - 0x12c, - 0x130, - 0x134, - 0x137, - 0x13b, - 0x13f, - 0x143, - 0x148, - 0x14c, - 0x150, - 0x154, - 0x159, - 0x15d, - 0x162, - 0x166, - 0x16b, - 0x170, - 0x175, - 0x17a, - 0x17f, - 0x184, - 0x189, - 0x18e, - 0x194, - 0x199, - 0x19f, - 0x1a5, - 0x1ab, - 0x1b1, - 0x1b7, - 0x1bd, - 0x1c3, - 0x1ca, - 0x1d1, - 0x1d7, - 0x1de, - 0x1e6, - 0x1ed, - 0x1f4, - 0x1fc, - 0x204, - 0x20c, - 0x214, - 0x21d, - 0x225, - 0x22e, - 0x238, - 0x241, - 0x24b, - 0x255, - 0x25f, - 0x26a, - 0x274, - 0x280, - 0x28b, - 0x297, - 0x2a3, - 0x2b0, - 0x2bd, - 0x2cb, - 0x2d9, - 0x2e8, - 0x2f7, - 0x306, - 0x317, - 0x328, - 0x339, - 0x34b, - 0x35e, - 0x372, - 0x387, - 0x39d, - 0x3b3, - 0x3cb, - 0x3e4, - 0x3fe, - 0x419, - 0x435, - 0x454, - 0x474, - 0x495, - 0x4b9, - 0x4de, - 0x506, - 0x531, - 0x55e, - 0x58f, - 0x5c3, - 0x5fb, - 0x637, - 0x677, - 0x6bd, - 0x709, - 0x75c, - 0x7b7, - 0x81b, - 0x889, - 0x904, - 0x98d, - 0xa27, - 0xad5, - 0xb9c, - 0xc82, - 0xd8e, - 0xecb, - 0x1046, - 0x1217, - 0x145a, - 0x1744, - 0x1b26, - 0x2095, - 0x28bc, - 0x3651, - 0x517b, - 0xa2f8 - }; - - // Sine LUT - static private int[] s = { - 0x0, - 0x1, - 0x3, - 0x4, - 0x6, - 0x7, - 0x9, - 0xa, - 0xc, - 0xe, - 0xf, - 0x11, - 0x12, - 0x14, - 0x15, - 0x17, - 0x19, - 0x1a, - 0x1c, - 0x1d, - 0x1f, - 0x20, - 0x22, - 0x24, - 0x25, - 0x27, - 0x28, - 0x2a, - 0x2b, - 0x2d, - 0x2e, - 0x30, - 0x31, - 0x33, - 0x35, - 0x36, - 0x38, - 0x39, - 0x3b, - 0x3c, - 0x3e, - 0x3f, - 0x41, - 0x42, - 0x44, - 0x45, - 0x47, - 0x48, - 0x4a, - 0x4b, - 0x4d, - 0x4e, - 0x50, - 0x51, - 0x53, - 0x54, - 0x56, - 0x57, - 0x59, - 0x5a, - 0x5c, - 0x5d, - 0x5f, - 0x60, - 0x61, - 0x63, - 0x64, - 0x66, - 0x67, - 0x69, - 0x6a, - 0x6c, - 0x6d, - 0x6e, - 0x70, - 0x71, - 0x73, - 0x74, - 0x75, - 0x77, - 0x78, - 0x7a, - 0x7b, - 0x7c, - 0x7e, - 0x7f, - 0x80, - 0x82, - 0x83, - 0x84, - 0x86, - 0x87, - 0x88, - 0x8a, - 0x8b, - 0x8c, - 0x8e, - 0x8f, - 0x90, - 0x92, - 0x93, - 0x94, - 0x95, - 0x97, - 0x98, - 0x99, - 0x9b, - 0x9c, - 0x9d, - 0x9e, - 0x9f, - 0xa1, - 0xa2, - 0xa3, - 0xa4, - 0xa6, - 0xa7, - 0xa8, - 0xa9, - 0xaa, - 0xab, - 0xad, - 0xae, - 0xaf, - 0xb0, - 0xb1, - 0xb2, - 0xb3, - 0xb5, - 0xb6, - 0xb7, - 0xb8, - 0xb9, - 0xba, - 0xbb, - 0xbc, - 0xbd, - 0xbe, - 0xbf, - 0xc0, - 0xc1, - 0xc2, - 0xc3, - 0xc4, - 0xc5, - 0xc6, - 0xc7, - 0xc8, - 0xc9, - 0xca, - 0xcb, - 0xcc, - 0xcd, - 0xce, - 0xcf, - 0xd0, - 0xd1, - 0xd2, - 0xd3, - 0xd3, - 0xd4, - 0xd5, - 0xd6, - 0xd7, - 0xd8, - 0xd9, - 0xd9, - 0xda, - 0xdb, - 0xdc, - 0xdd, - 0xdd, - 0xde, - 0xdf, - 0xe0, - 0xe1, - 0xe1, - 0xe2, - 0xe3, - 0xe3, - 0xe4, - 0xe5, - 0xe6, - 0xe6, - 0xe7, - 0xe8, - 0xe8, - 0xe9, - 0xea, - 0xea, - 0xeb, - 0xeb, - 0xec, - 0xed, - 0xed, - 0xee, - 0xee, - 0xef, - 0xef, - 0xf0, - 0xf1, - 0xf1, - 0xf2, - 0xf2, - 0xf3, - 0xf3, - 0xf4, - 0xf4, - 0xf4, - 0xf5, - 0xf5, - 0xf6, - 0xf6, - 0xf7, - 0xf7, - 0xf7, - 0xf8, - 0xf8, - 0xf9, - 0xf9, - 0xf9, - 0xfa, - 0xfa, - 0xfa, - 0xfb, - 0xfb, - 0xfb, - 0xfb, - 0xfc, - 0xfc, - 0xfc, - 0xfc, - 0xfd, - 0xfd, - 0xfd, - 0xfd, - 0xfe, - 0xfe, - 0xfe, - 0xfe, - 0xfe, - 0xfe, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff - }; - - // Cosine LUT - static private int[] c = { - 0x100, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xfe, - 0xfe, - 0xfe, - 0xfe, - 0xfe, - 0xfe, - 0xfd, - 0xfd, - 0xfd, - 0xfd, - 0xfc, - 0xfc, - 0xfc, - 0xfc, - 0xfb, - 0xfb, - 0xfb, - 0xfb, - 0xfa, - 0xfa, - 0xfa, - 0xf9, - 0xf9, - 0xf9, - 0xf8, - 0xf8, - 0xf7, - 0xf7, - 0xf7, - 0xf6, - 0xf6, - 0xf5, - 0xf5, - 0xf4, - 0xf4, - 0xf4, - 0xf3, - 0xf3, - 0xf2, - 0xf2, - 0xf1, - 0xf1, - 0xf0, - 0xef, - 0xef, - 0xee, - 0xee, - 0xed, - 0xed, - 0xec, - 0xeb, - 0xeb, - 0xea, - 0xea, - 0xe9, - 0xe8, - 0xe8, - 0xe7, - 0xe6, - 0xe6, - 0xe5, - 0xe4, - 0xe3, - 0xe3, - 0xe2, - 0xe1, - 0xe1, - 0xe0, - 0xdf, - 0xde, - 0xdd, - 0xdd, - 0xdc, - 0xdb, - 0xda, - 0xd9, - 0xd9, - 0xd8, - 0xd7, - 0xd6, - 0xd5, - 0xd4, - 0xd3, - 0xd3, - 0xd2, - 0xd1, - 0xd0, - 0xcf, - 0xce, - 0xcd, - 0xcc, - 0xcb, - 0xca, - 0xc9, - 0xc8, - 0xc7, - 0xc6, - 0xc5, - 0xc4, - 0xc3, - 0xc2, - 0xc1, - 0xc0, - 0xbf, - 0xbe, - 0xbd, - 0xbc, - 0xbb, - 0xba, - 0xb9, - 0xb8, - 0xb7, - 0xb6, - 0xb5, - 0xb3, - 0xb2, - 0xb1, - 0xb0, - 0xaf, - 0xae, - 0xad, - 0xab, - 0xaa, - 0xa9, - 0xa8, - 0xa7, - 0xa6, - 0xa4, - 0xa3, - 0xa2, - 0xa1, - 0x9f, - 0x9e, - 0x9d, - 0x9c, - 0x9b, - 0x99, - 0x98, - 0x97, - 0x95, - 0x94, - 0x93, - 0x92, - 0x90, - 0x8f, - 0x8e, - 0x8c, - 0x8b, - 0x8a, - 0x88, - 0x87, - 0x86, - 0x84, - 0x83, - 0x82, - 0x80, - 0x7f, - 0x7e, - 0x7c, - 0x7b, - 0x7a, - 0x78, - 0x77, - 0x75, - 0x74, - 0x73, - 0x71, - 0x70, - 0x6e, - 0x6d, - 0x6c, - 0x6a, - 0x69, - 0x67, - 0x66, - 0x64, - 0x63, - 0x61, - 0x60, - 0x5f, - 0x5d, - 0x5c, - 0x5a, - 0x59, - 0x57, - 0x56, - 0x54, - 0x53, - 0x51, - 0x50, - 0x4e, - 0x4d, - 0x4b, - 0x4a, - 0x48, - 0x47, - 0x45, - 0x44, - 0x42, - 0x41, - 0x3f, - 0x3e, - 0x3c, - 0x3b, - 0x39, - 0x38, - 0x36, - 0x35, - 0x33, - 0x31, - 0x30, - 0x2e, - 0x2d, - 0x2b, - 0x2a, - 0x28, - 0x27, - 0x25, - 0x24, - 0x22, - 0x20, - 0x1f, - 0x1d, - 0x1c, - 0x1a, - 0x19, - 0x17, - 0x15, - 0x14, - 0x12, - 0x11, - 0xf, - 0xe, - 0xc, - 0xa, - 0x9, - 0x7, - 0x6, - 0x4, - 0x3, - 0x1 - }; - - /** - * Yet to be implemented. - * @param num Input - * @return Output - */ - public static int arctan( int num ) { - return 0; - } - - /** - * 26.6 fixed number square root function. - * Simple (brain-dead) divide & conqure algorithm. - * @param num The 26.6 fixed number in question - * @return The resulting square root - */ - public static int squareRoot(int num) { - int n = num; - int divisor = num; - int nSquared; - - while (divisor != 0) { - divisor /= 2; - nSquared = (n * n) >> 6; - if (nSquared == num) { - break; - } else if (nSquared > num) { - n -= divisor; - } else { - n += divisor; - } - } - return n; - } - - public static float floatValue(long fixed) { - return (fixed >> 16) + (float)(fixed & 0xffff) / 0x10000; - } - - public static float roundedFloatValue(long fixed, int decimalPlaces) { - int factor = 10 * decimalPlaces; - return (float)((int)(floatValue(fixed) * factor)) / factor; - } -} diff --git a/src/net/java/dev/typecast/ot/Mnemonic.java b/src/net/java/dev/typecast/ot/Mnemonic.java deleted file mode 100644 index 5655c1e86..000000000 --- a/src/net/java/dev/typecast/ot/Mnemonic.java +++ /dev/null @@ -1,397 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot; - -/** - * The Mnemonic representations of the TrueType instruction set. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Mnemonic.java,v 1.1.1.1 2004-12-05 23:14:30 davidsch Exp $ - */ -public class Mnemonic { - - public static final short SVTCA = 0x00; // [a] - public static final short SPVTCA = 0x02; // [a] - public static final short SFVTCA = 0x04; // [a] - public static final short SPVTL = 0x06; // [a] - public static final short SFVTL = 0x08; // [a] - public static final short SPVFS = 0x0A; - public static final short SFVFS = 0x0B; - public static final short GPV = 0x0C; - public static final short GFV = 0x0D; - public static final short SFVTPV = 0x0E; - public static final short ISECT = 0x0F; - public static final short SRP0 = 0x10; - public static final short SRP1 = 0x11; - public static final short SRP2 = 0x12; - public static final short SZP0 = 0x13; - public static final short SZP1 = 0x14; - public static final short SZP2 = 0x15; - public static final short SZPS = 0x16; - public static final short SLOOP = 0x17; - public static final short RTG = 0x18; - public static final short RTHG = 0x19; - public static final short SMD = 0x1A; - public static final short ELSE = 0x1B; - public static final short JMPR = 0x1C; - public static final short SCVTCI = 0x1D; - public static final short SSWCI = 0x1E; - public static final short SSW = 0x1F; - public static final short DUP = 0x20; - public static final short POP = 0x21; - public static final short CLEAR = 0x22; - public static final short SWAP = 0x23; - public static final short DEPTH = 0x24; - public static final short CINDEX = 0x25; - public static final short MINDEX = 0x26; - public static final short ALIGNPTS = 0x27; - public static final short UTP = 0x29; - public static final short LOOPCALL = 0x2A; - public static final short CALL = 0x2B; - public static final short FDEF = 0x2C; - public static final short ENDF = 0x2D; - public static final short MDAP = 0x2E; // [a] - public static final short IUP = 0x30; // [a] - public static final short SHP = 0x32; - public static final short SHC = 0x34; // [a] - public static final short SHZ = 0x36; // [a] - public static final short SHPIX = 0x38; - public static final short IP = 0x39; - public static final short MSIRP = 0x3A; // [a] - public static final short ALIGNRP = 0x3C; - public static final short RTDG = 0x3D; - public static final short MIAP = 0x3E; // [a] - public static final short NPUSHB = 0x40; - public static final short NPUSHW = 0x41; - public static final short WS = 0x42; - public static final short RS = 0x43; - public static final short WCVTP = 0x44; - public static final short RCVT = 0x45; - public static final short GC = 0x46; // [a] - public static final short SCFS = 0x48; - public static final short MD = 0x49; // [a] - public static final short MPPEM = 0x4B; - public static final short MPS = 0x4C; - public static final short FLIPON = 0x4D; - public static final short FLIPOFF = 0x4E; - public static final short DEBUG = 0x4F; - public static final short LT = 0x50; - public static final short LTEQ = 0x51; - public static final short GT = 0x52; - public static final short GTEQ = 0x53; - public static final short EQ = 0x54; - public static final short NEQ = 0x55; - public static final short ODD = 0x56; - public static final short EVEN = 0x57; - public static final short IF = 0x58; - public static final short EIF = 0x59; - public static final short AND = 0x5A; - public static final short OR = 0x5B; - public static final short NOT = 0x5C; - public static final short DELTAP1 = 0x5D; - public static final short SDB = 0x5E; - public static final short SDS = 0x5F; - public static final short ADD = 0x60; - public static final short SUB = 0x61; - public static final short DIV = 0x62; - public static final short MUL = 0x63; - public static final short ABS = 0x64; - public static final short NEG = 0x65; - public static final short FLOOR = 0x66; - public static final short CEILING = 0x67; - public static final short ROUND = 0x68; // [ab] - public static final short NROUND = 0x6C; // [ab] - public static final short WCVTF = 0x70; - public static final short DELTAP2 = 0x71; - public static final short DELTAP3 = 0x72; - public static final short DELTAC1 = 0x73; - public static final short DELTAC2 = 0x74; - public static final short DELTAC3 = 0x75; - public static final short SROUND = 0x76; - public static final short S45ROUND = 0x77; - public static final short JROT = 0x78; - public static final short JROF = 0x79; - public static final short ROFF = 0x7A; - public static final short RUTG = 0x7C; - public static final short RDTG = 0x7D; - public static final short SANGW = 0x7E; - public static final short AA = 0x7F; - public static final short FLIPPT = 0x80; - public static final short FLIPRGON = 0x81; - public static final short FLIPRGOFF = 0x82; - public static final short SCANCTRL = 0x85; - public static final short SDPVTL = 0x86; // [a] - public static final short GETINFO = 0x88; - public static final short IDEF = 0x89; - public static final short ROLL = 0x8A; - public static final short MAX = 0x8B; - public static final short MIN = 0x8C; - public static final short SCANTYPE = 0x8D; - public static final short INSTCTRL = 0x8E; - public static final short PUSHB = 0xB0; // [abc] - public static final short PUSHW = 0xB8; // [abc] - public static final short MDRP = 0xC0; // [abcde] - public static final short MIRP = 0xE0; // [abcde] - - /** - * Gets the mnemonic text for the specified opcode - * @param opcode The opcode for which the mnemonic is required - * @return The mnemonic, with a description - */ - public static String getMnemonic(short opcode) { - if (opcode >= MIRP) return "MIRP["+((opcode&16)==0?"nrp0,":"srp0,")+((opcode&8)==0?"nmd,":"md,")+((opcode&4)==0?"nrd,":"rd,")+(opcode&3)+"]"; - else if (opcode >= MDRP) return "MDRP["+((opcode&16)==0?"nrp0,":"srp0,")+((opcode&8)==0?"nmd,":"md,")+((opcode&4)==0?"nrd,":"rd,")+(opcode&3)+"]"; - else if (opcode >= PUSHW) return "PUSHW["+((opcode&7)+1)+"]"; - else if (opcode >= PUSHB) return "PUSHB["+((opcode&7)+1)+"]"; - else if (opcode >= INSTCTRL) return "INSTCTRL"; - else if (opcode >= SCANTYPE) return "SCANTYPE"; - else if (opcode >= MIN) return "MIN"; - else if (opcode >= MAX) return "MAX"; - else if (opcode >= ROLL) return "ROLL"; - else if (opcode >= IDEF) return "IDEF"; - else if (opcode >= GETINFO) return "GETINFO"; - else if (opcode >= SDPVTL) return "SDPVTL["+(opcode&1)+"]"; - else if (opcode >= SCANCTRL) return "SCANCTRL"; - else if (opcode >= FLIPRGOFF) return "FLIPRGOFF"; - else if (opcode >= FLIPRGON) return "FLIPRGON"; - else if (opcode >= FLIPPT) return "FLIPPT"; - else if (opcode >= AA) return "AA"; - else if (opcode >= SANGW) return "SANGW"; - else if (opcode >= RDTG) return "RDTG"; - else if (opcode >= RUTG) return "RUTG"; - else if (opcode >= ROFF) return "ROFF"; - else if (opcode >= JROF) return "JROF"; - else if (opcode >= JROT) return "JROT"; - else if (opcode >= S45ROUND) return "S45ROUND"; - else if (opcode >= SROUND) return "SROUND"; - else if (opcode >= DELTAC3) return "DELTAC3"; - else if (opcode >= DELTAC2) return "DELTAC2"; - else if (opcode >= DELTAC1) return "DELTAC1"; - else if (opcode >= DELTAP3) return "DELTAP3"; - else if (opcode >= DELTAP2) return "DELTAP2"; - else if (opcode >= WCVTF) return "WCVTF"; - else if (opcode >= NROUND) return "NROUND["+(opcode&3)+"]"; - else if (opcode >= ROUND) return "ROUND["+(opcode&3)+"]"; - else if (opcode >= CEILING) return "CEILING"; - else if (opcode >= FLOOR) return "FLOOR"; - else if (opcode >= NEG) return "NEG"; - else if (opcode >= ABS) return "ABS"; - else if (opcode >= MUL) return "MUL"; - else if (opcode >= DIV) return "DIV"; - else if (opcode >= SUB) return "SUB"; - else if (opcode >= ADD) return "ADD"; - else if (opcode >= SDS) return "SDS"; - else if (opcode >= SDB) return "SDB"; - else if (opcode >= DELTAP1) return "DELTAP1"; - else if (opcode >= NOT) return "NOT"; - else if (opcode >= OR) return "OR"; - else if (opcode >= AND) return "AND"; - else if (opcode >= EIF) return "EIF"; - else if (opcode >= IF) return "IF"; - else if (opcode >= EVEN) return "EVEN"; - else if (opcode >= ODD) return "ODD"; - else if (opcode >= NEQ) return "NEQ"; - else if (opcode >= EQ) return "EQ"; - else if (opcode >= GTEQ) return "GTEQ"; - else if (opcode >= GT) return "GT"; - else if (opcode >= LTEQ) return "LTEQ"; - else if (opcode >= LT) return "LT"; - else if (opcode >= DEBUG) return "DEBUG"; - else if (opcode >= FLIPOFF) return "FLIPOFF"; - else if (opcode >= FLIPON) return "FLIPON"; - else if (opcode >= MPS) return "MPS"; - else if (opcode >= MPPEM) return "MPPEM"; - else if (opcode >= MD) return "MD["+(opcode&1)+"]"; - else if (opcode >= SCFS) return "SCFS"; - else if (opcode >= GC) return "GC["+(opcode&1)+"]"; - else if (opcode >= RCVT) return "RCVT"; - else if (opcode >= WCVTP) return "WCVTP"; - else if (opcode >= RS) return "RS"; - else if (opcode >= WS) return "WS"; - else if (opcode >= NPUSHW) return "NPUSHW"; - else if (opcode >= NPUSHB) return "NPUSHB"; - else if (opcode >= MIAP) return "MIAP["+((opcode&1)==0?"nrd+nci":"rd+ci")+"]"; - else if (opcode >= RTDG) return "RTDG"; - else if (opcode >= ALIGNRP) return "ALIGNRP"; - else if (opcode >= MSIRP) return "MSIRP["+(opcode&1)+"]"; - else if (opcode >= IP) return "IP"; - else if (opcode >= SHPIX) return "SHPIX"; - else if (opcode >= SHZ) return "SHZ["+(opcode&1)+"]"; - else if (opcode >= SHC) return "SHC["+(opcode&1)+"]"; - else if (opcode >= SHP) return "SHP"; - else if (opcode >= IUP) return "IUP["+((opcode&1)==0?"y":"x")+"]"; - else if (opcode >= MDAP) return "MDAP["+((opcode&1)==0?"nrd":"rd")+"]"; - else if (opcode >= ENDF) return "ENDF"; - else if (opcode >= FDEF) return "FDEF"; - else if (opcode >= CALL) return "CALL"; - else if (opcode >= LOOPCALL) return "LOOPCALL"; - else if (opcode >= UTP) return "UTP"; - else if (opcode >= ALIGNPTS) return "ALIGNPTS"; - else if (opcode >= MINDEX) return "MINDEX"; - else if (opcode >= CINDEX) return "CINDEX"; - else if (opcode >= DEPTH) return "DEPTH"; - else if (opcode >= SWAP) return "SWAP"; - else if (opcode >= CLEAR) return "CLEAR"; - else if (opcode >= POP) return "POP"; - else if (opcode >= DUP) return "DUP"; - else if (opcode >= SSW) return "SSW"; - else if (opcode >= SSWCI) return "SSWCI"; - else if (opcode >= SCVTCI) return "SCVTCI"; - else if (opcode >= JMPR) return "JMPR"; - else if (opcode >= ELSE) return "ELSE"; - else if (opcode >= SMD) return "SMD"; - else if (opcode >= RTHG) return "RTHG"; - else if (opcode >= RTG) return "RTG"; - else if (opcode >= SLOOP) return "SLOOP"; - else if (opcode >= SZPS) return "SZPS"; - else if (opcode >= SZP2) return "SZP2"; - else if (opcode >= SZP1) return "SZP1"; - else if (opcode >= SZP0) return "SZP0"; - else if (opcode >= SRP2) return "SRP2"; - else if (opcode >= SRP1) return "SRP1"; - else if (opcode >= SRP0) return "SRP0"; - else if (opcode >= ISECT) return "ISECT"; - else if (opcode >= SFVTPV) return "SFVTPV"; - else if (opcode >= GFV) return "GFV"; - else if (opcode >= GPV) return "GPV"; - else if (opcode >= SFVFS) return "SFVFS"; - else if (opcode >= SPVFS) return "SPVFS"; - else if (opcode >= SFVTL) return "SFVTL["+((opcode&1)==0?"y-axis":"x-axis")+"]"; - else if (opcode >= SPVTL) return "SPVTL["+((opcode&1)==0?"y-axis":"x-axis")+"]"; - else if (opcode >= SFVTCA) return "SFVTCA["+((opcode&1)==0?"y-axis":"x-axis")+"]"; - else if (opcode >= SPVTCA) return "SPVTCA["+((opcode&1)==0?"y-axis":"x-axis")+"]"; - else if (opcode >= SVTCA) return "SVTCA["+((opcode&1)==0?"y-axis":"x-axis")+"]"; - else return "????"; - } - - public static String getComment(short opcode) { - if (opcode >= MIRP) return "MIRP["+((opcode&16)==0?"nrp0,":"srp0,")+((opcode&8)==0?"nmd,":"md,")+((opcode&4)==0?"nrd,":"rd,")+(opcode&3)+"]\t\tMove Indirect Relative Point"; - else if (opcode >= MDRP) return "MDRP["+((opcode&16)==0?"nrp0,":"srp0,")+((opcode&8)==0?"nmd,":"md,")+((opcode&4)==0?"nrd,":"rd,")+(opcode&3)+"]\t\tMove Direct Relative Point"; - else if (opcode >= PUSHW) return "PUSHW["+((opcode&7)+1)+"]"; - else if (opcode >= PUSHB) return "PUSHB["+((opcode&7)+1)+"]"; - else if (opcode >= INSTCTRL) return "INSTCTRL\tINSTruction Execution ConTRol"; - else if (opcode >= SCANTYPE) return "SCANTYPE\tSCANTYPE"; - else if (opcode >= MIN) return "MIN\t\tMINimum of top two stack elements"; - else if (opcode >= MAX) return "MAX\t\tMAXimum of top two stack elements"; - else if (opcode >= ROLL) return "ROLL\t\tROLL the top three stack elements"; - else if (opcode >= IDEF) return "IDEF\t\tInstruction DEFinition"; - else if (opcode >= GETINFO) return "GETINFO\tGET INFOrmation"; - else if (opcode >= SDPVTL) return "SDPVTL["+(opcode&1)+"]\tSet Dual Projection_Vector To Line"; - else if (opcode >= SCANCTRL) return "SCANCTRL\tSCAN conversion ConTRoL"; - else if (opcode >= FLIPRGOFF) return "FLIPRGOFF\tFLIP RanGe OFF"; - else if (opcode >= FLIPRGON) return "FLIPRGON\tFLIP RanGe ON"; - else if (opcode >= FLIPPT) return "FLIPPT\tFLIP PoinT"; - else if (opcode >= AA) return "AA"; - else if (opcode >= SANGW) return "SANGW\t\tSet Angle _Weight"; - else if (opcode >= RDTG) return "RDTG\t\tRound Down To Grid"; - else if (opcode >= RUTG) return "RUTG\t\tRound Up To Grid"; - else if (opcode >= ROFF) return "ROFF\t\tRound OFF"; - else if (opcode >= JROF) return "JROF\t\tJump Relative On False"; - else if (opcode >= JROT) return "JROT\t\tJump Relative On True"; - else if (opcode >= S45ROUND) return "S45ROUND\tSuper ROUND 45 degrees"; - else if (opcode >= SROUND) return "SROUND\tSuper ROUND"; - else if (opcode >= DELTAC3) return "DELTAC3\tDELTA exception C3"; - else if (opcode >= DELTAC2) return "DELTAC2\tDELTA exception C2"; - else if (opcode >= DELTAC1) return "DELTAC1\tDELTA exception C1"; - else if (opcode >= DELTAP3) return "DELTAP3\tDELTA exception P3"; - else if (opcode >= DELTAP2) return "DELTAP2\tDELTA exception P2"; - else if (opcode >= WCVTF) return "WCVTF\t\tWrite Control Value Table in FUnits"; - else if (opcode >= NROUND) return "NROUND["+(opcode&3)+"]"; - else if (opcode >= ROUND) return "ROUND["+(opcode&3)+"]"; - else if (opcode >= CEILING) return "CEILING\tCEILING"; - else if (opcode >= FLOOR) return "FLOOR\t\tFLOOR"; - else if (opcode >= NEG) return "NEG\t\tNEGate"; - else if (opcode >= ABS) return "ABS\t\tABSolute value"; - else if (opcode >= MUL) return "MUL\t\tMULtiply"; - else if (opcode >= DIV) return "DIV\t\tDIVide"; - else if (opcode >= SUB) return "SUB\t\tSUBtract"; - else if (opcode >= ADD) return "ADD\t\tADD"; - else if (opcode >= SDS) return "SDS\t\tSet Delta_Shift in the graphics state"; - else if (opcode >= SDB) return "SDB\t\tSet Delta_Base in the graphics state"; - else if (opcode >= DELTAP1) return "DELTAP1\tDELTA exception P1"; - else if (opcode >= NOT) return "NOT\t\tlogical NOT"; - else if (opcode >= OR) return "OR\t\t\tlogical OR"; - else if (opcode >= AND) return "AND\t\tlogical AND"; - else if (opcode >= EIF) return "EIF\t\tEnd IF"; - else if (opcode >= IF) return "IF\t\t\tIF test"; - else if (opcode >= EVEN) return "EVEN"; - else if (opcode >= ODD) return "ODD"; - else if (opcode >= NEQ) return "NEQ\t\tNot EQual"; - else if (opcode >= EQ) return "EQ\t\t\tEQual"; - else if (opcode >= GTEQ) return "GTEQ\t\tGreater Than or Equal"; - else if (opcode >= GT) return "GT\t\t\tGreater Than"; - else if (opcode >= LTEQ) return "LTEQ\t\tLess Than or Equal"; - else if (opcode >= LT) return "LT\t\t\tLess Than"; - else if (opcode >= DEBUG) return "DEBUG"; - else if (opcode >= FLIPOFF) return "FLIPOFF\tSet the auto_flip Boolean to OFF"; - else if (opcode >= FLIPON) return "FLIPON\tSet the auto_flip Boolean to ON"; - else if (opcode >= MPS) return "MPS\t\tMeasure Point Size"; - else if (opcode >= MPPEM) return "MPPEM\t\tMeasure Pixels Per EM"; - else if (opcode >= MD) return "MD["+(opcode&1)+"]\t\t\tMeasure Distance"; - else if (opcode >= SCFS) return "SCFS\t\tSets Coordinate From the Stack using projection_vector and freedom_vector"; - else if (opcode >= GC) return "GC["+(opcode&1)+"]\t\t\tGet Coordinate projected onto the projection_vector"; - else if (opcode >= RCVT) return "RCVT\t\tRead Control Value Table"; - else if (opcode >= WCVTP) return "WCVTP\t\tWrite Control Value Table in Pixel units"; - else if (opcode >= RS) return "RS\t\t\tRead Store"; - else if (opcode >= WS) return "WS\t\t\tWrite Store"; - else if (opcode >= NPUSHW) return "NPUSHW"; - else if (opcode >= NPUSHB) return "NPUSHB"; - else if (opcode >= MIAP) return "MIAP["+((opcode&1)==0?"nrd+nci":"rd+ci")+"]\t\tMove Indirect Absolute Point"; - else if (opcode >= RTDG) return "RTDG\t\tRound To Double Grid"; - else if (opcode >= ALIGNRP) return "ALIGNRP\tALIGN Relative Point"; - else if (opcode >= MSIRP) return "MSIRP["+(opcode&1)+"]\t\tMove Stack Indirect Relative Point"; - else if (opcode >= IP) return "IP\t\t\tInterpolate Point by the last relative stretch"; - else if (opcode >= SHPIX) return "SHPIX\t\tSHift point by a PIXel amount"; - else if (opcode >= SHZ) return "SHZ["+(opcode&1)+"]\t\tSHift Zone by the last pt"; - else if (opcode >= SHC) return "SHC["+(opcode&1)+"]\t\tSHift Contour by the last point"; - else if (opcode >= SHP) return "SHP\t\tSHift Point by the last point"; - else if (opcode >= IUP) return "IUP["+((opcode&1)==0?"y":"x")+"]\t\tInterpolate Untouched Points through the outline"; - else if (opcode >= MDAP) return "MDAP["+((opcode&1)==0?"nrd":"rd")+"]\t\tMove Direct Absolute Point"; - else if (opcode >= ENDF) return "ENDF\t\tEND Function definition"; - else if (opcode >= FDEF) return "FDEF\t\tFunction DEFinition "; - else if (opcode >= CALL) return "CALL\t\tCALL function"; - else if (opcode >= LOOPCALL) return "LOOPCALL\tLOOP and CALL function"; - else if (opcode >= UTP) return "UTP\t\tUnTouch Point"; - else if (opcode >= ALIGNPTS) return "ALIGNPTS\tALIGN Points"; - else if (opcode >= MINDEX) return "MINDEX\tMove the INDEXed element to the top of the stack"; - else if (opcode >= CINDEX) return "CINDEX\tCopy the INDEXed element to the top of the stack"; - else if (opcode >= DEPTH) return "DEPTH\t\tReturns the DEPTH of the stack"; - else if (opcode >= SWAP) return "SWAP\t\tSWAP the top two elements on the stack"; - else if (opcode >= CLEAR) return "CLEAR\t\tClear the entire stack"; - else if (opcode >= POP) return "POP\t\tPOP top stack element"; - else if (opcode >= DUP) return "DUP\t\tDuplicate top stack element"; - else if (opcode >= SSW) return "SSW\t\tSet Single-width"; - else if (opcode >= SSWCI) return "SSWCI\t\tSet Single_Width_Cut_In"; - else if (opcode >= SCVTCI) return "SCVTCI\tSet Control Value Table Cut In"; - else if (opcode >= JMPR) return "JMPR\t\tJuMP"; - else if (opcode >= ELSE) return "ELSE"; - else if (opcode >= SMD) return "SMD\t\tSet Minimum_ Distance"; - else if (opcode >= RTHG) return "RTHG\t\tRound To Half Grid"; - else if (opcode >= RTG) return "RTG\t\tRound To Grid"; - else if (opcode >= SLOOP) return "SLOOP\t\tSet LOOP variable"; - else if (opcode >= SZPS) return "SZPS\t\tSet Zone PointerS"; - else if (opcode >= SZP2) return "SZP2\t\tSet Zone Pointer 2"; - else if (opcode >= SZP1) return "SZP1\t\tSet Zone Pointer 1"; - else if (opcode >= SZP0) return "SZP0\t\tSet Zone Pointer 0"; - else if (opcode >= SRP2) return "SRP2\t\tSet Reference Point 2"; - else if (opcode >= SRP1) return "SRP1\t\tSet Reference Point 1"; - else if (opcode >= SRP0) return "SRP0\t\tSet Reference Point 0"; - else if (opcode >= ISECT) return "ISECT\t\tmoves point p to the InterSECTion of two lines"; - else if (opcode >= SFVTPV) return "SFVTPV\tSet Freedom_Vector To Projection Vector"; - else if (opcode >= GFV) return "GFV\t\tGet Freedom_Vector"; - else if (opcode >= GPV) return "GPV\t\tGet Projection_Vector"; - else if (opcode >= SFVFS) return "SFVFS\t\tSet Freedom_Vector From Stack"; - else if (opcode >= SPVFS) return "SPVFS\t\tSet Projection_Vector From Stack"; - else if (opcode >= SFVTL) return "SFVTL["+((opcode&1)==0?"y-axis":"x-axis")+"]\t\tSet Freedom_Vector To Line"; - else if (opcode >= SPVTL) return "SPVTL["+((opcode&1)==0?"y-axis":"x-axis")+"]\t\tSet Projection_Vector To Line"; - else if (opcode >= SFVTCA) return "SFVTCA["+((opcode&1)==0?"y-axis":"x-axis")+"]\tSet Freedom_Vector to Coordinate Axis"; - else if (opcode >= SPVTCA) return "SPVTCA["+((opcode&1)==0?"y-axis":"x-axis")+"]\tSet Projection_Vector To Coordinate Axis"; - else if (opcode >= SVTCA) return "SVTCA["+((opcode&1)==0?"y-axis":"x-axis")+"]\t\tSet freedom and projection Vectors To Coordinate Axis"; - else return "????"; - } -} diff --git a/src/net/java/dev/typecast/ot/OTFont.java b/src/net/java/dev/typecast/ot/OTFont.java deleted file mode 100644 index e58fc3794..000000000 --- a/src/net/java/dev/typecast/ot/OTFont.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot; - -import java.io.DataInputStream; -import java.io.IOException; - -import net.java.dev.typecast.ot.table.DirectoryEntry; -import net.java.dev.typecast.ot.table.GlyfDescript; -import net.java.dev.typecast.ot.table.HdmxTable; -import net.java.dev.typecast.ot.table.TableDirectory; -import net.java.dev.typecast.ot.table.Table; -import net.java.dev.typecast.ot.table.Os2Table; -import net.java.dev.typecast.ot.table.CmapTable; -import net.java.dev.typecast.ot.table.GlyfTable; -import net.java.dev.typecast.ot.table.HeadTable; -import net.java.dev.typecast.ot.table.HheaTable; -import net.java.dev.typecast.ot.table.HmtxTable; -import net.java.dev.typecast.ot.table.LocaTable; -import net.java.dev.typecast.ot.table.MaxpTable; -import net.java.dev.typecast.ot.table.NameTable; -import net.java.dev.typecast.ot.table.PostTable; -import net.java.dev.typecast.ot.table.VheaTable; -import net.java.dev.typecast.ot.table.TableFactory; - -/** - * The TrueType font. - * @version $Id: OTFont.java,v 1.6 2007-01-31 01:49:18 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a>, Sven Gothel - */ -public class OTFont { - - private OTFontCollection _fc; - private TableDirectory _tableDirectory = null; - private Table[] _tables; - private Os2Table _os2; - private CmapTable _cmap; - private GlyfTable _glyf; - private HeadTable _head; - private HheaTable _hhea; - private HdmxTable _hdmx; - private HmtxTable _hmtx; - private LocaTable _loca; - private MaxpTable _maxp; - private NameTable _name; - private PostTable _post; - private VheaTable _vhea; - - /** - * Constructor - */ - public OTFont(OTFontCollection fc) { - _fc = fc; - } - - public Table getTable(int tableType) { - for (int i = 0; i < _tables.length; i++) { - if ((_tables[i] != null) && (_tables[i].getType() == tableType)) { - return _tables[i]; - } - } - return null; - } - - public Os2Table getOS2Table() { - return _os2; - } - - public CmapTable getCmapTable() { - return _cmap; - } - - public HeadTable getHeadTable() { - return _head; - } - - public HheaTable getHheaTable() { - return _hhea; - } - - public HdmxTable getHdmxTable() { - return _hdmx; - } - - public HmtxTable getHmtxTable() { - return _hmtx; - } - - public LocaTable getLocaTable() { - return _loca; - } - - public MaxpTable getMaxpTable() { - return _maxp; - } - - public NameTable getNameTable() { - return _name; - } - - public PostTable getPostTable() { - return _post; - } - - public VheaTable getVheaTable() { - return _vhea; - } - - public int getAscent() { - return _hhea.getAscender(); - } - - public int getDescent() { - return _hhea.getDescender(); - } - - public int getNumGlyphs() { - return _maxp.getNumGlyphs(); - } - - public OTGlyph getGlyph(int i) { - - final GlyfDescript _glyfDescr = _glyf.getDescription(i); - return (null != _glyfDescr) - ? new OTGlyph( - _glyfDescr, - _hmtx.getLeftSideBearing(i), - _hmtx.getAdvanceWidth(i)) - : null; - } - - public TableDirectory getTableDirectory() { - return _tableDirectory; - } - - private Table readTable( - DataInputStream dis, - int tablesOrigin, - int tag) throws IOException { - dis.reset(); - DirectoryEntry entry = _tableDirectory.getEntryByTag(tag); - if (entry == null) { - return null; - } - dis.skip(tablesOrigin + entry.getOffset()); - return TableFactory.create(_fc, this, entry, dis); - } - - /** - * @param dis OpenType/TrueType font file data. - * @param directoryOffset The Table Directory offset within the file. For a - * regular TTF/OTF file this will be zero, but for a TTC (Font Collection) - * the offset is retrieved from the TTC header. For a Mac font resource, - * offset is retrieved from the resource headers. - * @param tablesOrigin The point the table offsets are calculated from. - * Once again, in a regular TTF file, this will be zero. In a TTC is is - * also zero, but within a Mac resource, it is the beggining of the - * individual font resource data. - */ - protected void read( - DataInputStream dis, - int directoryOffset, - int tablesOrigin) throws IOException { - - // Load the table directory - dis.reset(); - dis.skip(directoryOffset); - _tableDirectory = new TableDirectory(dis); - _tables = new Table[_tableDirectory.getNumTables()]; - - // Load some prerequisite tables - _head = (HeadTable) readTable(dis, tablesOrigin, Table.head); - _hhea = (HheaTable) readTable(dis, tablesOrigin, Table.hhea); - _maxp = (MaxpTable) readTable(dis, tablesOrigin, Table.maxp); - _loca = (LocaTable) readTable(dis, tablesOrigin, Table.loca); - _vhea = (VheaTable) readTable(dis, tablesOrigin, Table.vhea); - - int index = 0; - _tables[index++] = _head; - _tables[index++] = _hhea; - _tables[index++] = _maxp; - if (_loca != null) { - _tables[index++] = _loca; - } - if (_vhea != null) { - _tables[index++] = _vhea; - } - - // Load all other tables - for (int i = 0; i < _tableDirectory.getNumTables(); i++) { - DirectoryEntry entry = _tableDirectory.getEntry(i); - if (entry.getTag() == Table.head - || entry.getTag() == Table.hhea - || entry.getTag() == Table.maxp - || entry.getTag() == Table.loca - || entry.getTag() == Table.vhea) { - continue; - } - dis.reset(); - dis.skip(tablesOrigin + entry.getOffset()); - _tables[index] = TableFactory.create(_fc, this, entry, dis); - ++index; - } - - // Get references to commonly used tables (these happen to be all the - // required tables) - _cmap = (CmapTable) getTable(Table.cmap); - _hdmx = (HdmxTable) getTable(Table.hdmx); - _hmtx = (HmtxTable) getTable(Table.hmtx); - _name = (NameTable) getTable(Table.name); - _os2 = (Os2Table) getTable(Table.OS_2); - _post = (PostTable) getTable(Table.post); - - // If this is a TrueType outline, then we'll have at least the - // 'glyf' table (along with the 'loca' table) - _glyf = (GlyfTable) getTable(Table.glyf); - } - - public String toString() { - if (_tableDirectory != null) { - return _tableDirectory.toString(); - } else { - return "Empty font"; - } - } -} diff --git a/src/net/java/dev/typecast/ot/OTFontCollection.java b/src/net/java/dev/typecast/ot/OTFontCollection.java deleted file mode 100644 index 6f8754f59..000000000 --- a/src/net/java/dev/typecast/ot/OTFontCollection.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * $Id: OTFontCollection.java,v 1.6 2010-08-10 11:38:11 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot; - -import java.io.File; -import java.io.BufferedInputStream; -import java.io.DataInputStream; -import java.io.FileInputStream; -import java.io.IOException; - -import java.util.ArrayList; - -import net.java.dev.typecast.ot.mac.ResourceHeader; -import net.java.dev.typecast.ot.mac.ResourceMap; -import net.java.dev.typecast.ot.mac.ResourceReference; -import net.java.dev.typecast.ot.mac.ResourceType; -import net.java.dev.typecast.ot.table.DirectoryEntry; -import net.java.dev.typecast.ot.table.Table; -import net.java.dev.typecast.ot.table.TTCHeader; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: OTFontCollection.java,v 1.6 2010-08-10 11:38:11 davidsch Exp $ - */ -public class OTFontCollection { - - private String _pathName; - private String _fileName; - private TTCHeader _ttcHeader; - private OTFont[] _fonts; - private ArrayList<Table> _tables = new ArrayList<Table>(); - private boolean _resourceFork = false; - - /** Creates new FontCollection */ - protected OTFontCollection() { - } - - /** - * @param file The OpenType font file - */ - public static OTFontCollection create(File file) throws IOException { - OTFontCollection fc = new OTFontCollection(); - fc.read(file); - return fc; - } - - public String getPathName() { - return _pathName; - } - - public String getFileName() { - return _fileName; - } - - public OTFont getFont(int i) { - return _fonts[i]; - } - - public int getFontCount() { - return _fonts.length; - } - - public TTCHeader getTtcHeader() { - return _ttcHeader; - } - - public Table getTable(DirectoryEntry de) { - for (int i = 0; i < _tables.size(); i++) { - Table table = _tables.get(i); - if ((table.getDirectoryEntry().getTag() == de.getTag()) && - (table.getDirectoryEntry().getOffset() == de.getOffset())) { - return table; - } - } - return null; - } - - public void addTable(Table table) { - _tables.add(table); - } - - /** - * @param file The OpenType font file - */ - protected void read(File file) throws IOException { - _pathName = file.getPath(); - _fileName = file.getName(); - - if (!file.exists()) { - throw new IOException(); - } - - // Do we need to modify the path name to deal with font resources - // in a Mac resource fork? - if (file.length() == 0) { - file = new File(file, "..namedfork/rsrc"); - if (!file.exists()) { - throw new IOException(); - } - _resourceFork = true; - } - - DataInputStream dis = new DataInputStream( - new BufferedInputStream( - new FileInputStream(file), (int) file.length())); - dis.mark((int) file.length()); - - if (_resourceFork || _pathName.endsWith(".dfont")) { - - // This is a Macintosh font suitcase resource - ResourceHeader resourceHeader = new ResourceHeader(dis); - - // Seek to the map offset and read the map - dis.reset(); - dis.skip(resourceHeader.getMapOffset()); - ResourceMap map = new ResourceMap(dis); - - // Get the 'sfnt' resources - ResourceType resourceType = map.getResourceType("sfnt"); - - // Load the font data - _fonts = new OTFont[resourceType.getCount()]; - for (int i = 0; i < resourceType.getCount(); i++) { - ResourceReference resourceReference = resourceType.getReference(i); - _fonts[i] = new OTFont(this); - int offset = resourceHeader.getDataOffset() + - resourceReference.getDataOffset() + 4; - _fonts[i].read(dis, offset, offset); - } - - } else if (TTCHeader.isTTC(dis)) { - - // This is a TrueType font collection - dis.reset(); - _ttcHeader = new TTCHeader(dis); - _fonts = new OTFont[_ttcHeader.getDirectoryCount()]; - for (int i = 0; i < _ttcHeader.getDirectoryCount(); i++) { - _fonts[i] = new OTFont(this); - _fonts[i].read(dis, _ttcHeader.getTableDirectory(i), 0); - } - } else { - - // This is a standalone font file - _fonts = new OTFont[1]; - _fonts[0] = new OTFont(this); - _fonts[0].read(dis, 0, 0); - } - dis.close(); - } -} diff --git a/src/net/java/dev/typecast/ot/OTGlyph.java b/src/net/java/dev/typecast/ot/OTGlyph.java deleted file mode 100644 index 958dd2280..000000000 --- a/src/net/java/dev/typecast/ot/OTGlyph.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot; - -import com.jogamp.graph.geom.AABBox; - -import net.java.dev.typecast.ot.table.GlyphDescription; -import net.java.dev.typecast.ot.table.GlyfDescript; -import net.java.dev.typecast.ot.table.Charstring; -import net.java.dev.typecast.ot.table.CharstringType2; - -import net.java.dev.typecast.t2.T2Interpreter; - -/** - * An individual glyph within a font. - * @version $Id: Glyph.java,v 1.3 2007-02-21 12:23:54 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a>, Sven Gothel - */ -public class OTGlyph { - - protected short _leftSideBearing; - protected int _advanceWidth; - private Point[] _points; - AABBox _bbox; - - /** - * Construct a Glyph from a TrueType outline described by - * a GlyphDescription. - * @param cs The Charstring describing the glyph. - * @param lsb The Left Side Bearing. - * @param advance The advance width. - */ - public OTGlyph(GlyphDescription gd, short lsb, int advance) { - _leftSideBearing = lsb; - _advanceWidth = advance; - describe(gd); - } - - /** - * Construct a Glyph from a PostScript outline described by a Charstring. - * @param cs The Charstring describing the glyph. - * @param lsb The Left Side Bearing. - * @param advance The advance width. - */ - public OTGlyph(Charstring cs, short lsb, int advance) { - _leftSideBearing = lsb; - _advanceWidth = advance; - if (cs instanceof CharstringType2) { - T2Interpreter t2i = new T2Interpreter(); - _points = t2i.execute((CharstringType2) cs); - } else { - //throw unsupported charstring type - } - } - - public AABBox getBBox() { - return _bbox; - } - - public int getAdvanceWidth() { - return _advanceWidth; - } - - public short getLeftSideBearing() { - return _leftSideBearing; - } - - public Point getPoint(int i) { - return _points[i]; - } - - public int getPointCount() { - return _points.length; - } - - /** - * Resets the glyph to the TrueType table settings - */ - public void reset() { - } - - /** - * @param factor a 16.16 fixed value - */ - public void scale(int factor) { - for (int i = 0; i < _points.length; i++) { - //points[i].x = ( points[i].x * factor ) >> 6; - //points[i].y = ( points[i].y * factor ) >> 6; - _points[i].x = ((_points[i].x<<10) * factor) >> 26; - _points[i].y = ((_points[i].y<<10) * factor) >> 26; - } - _leftSideBearing = (short)(( _leftSideBearing * factor) >> 6); - _advanceWidth = (_advanceWidth * factor) >> 6; - } - - /** - * Set the points of a glyph from the GlyphDescription - */ - private void describe(GlyphDescription gd) { - int endPtIndex = 0; - _points = new Point[gd.getPointCount() /* + 2 */ ]; - for (int i = 0; i < gd.getPointCount(); i++) { - boolean endPt = gd.getEndPtOfContours(endPtIndex) == i; - if (endPt) { - endPtIndex++; - } - _points[i] = new Point( - gd.getXCoordinate(i), - gd.getYCoordinate(i), - (gd.getFlags(i) & GlyfDescript.onCurve) != 0, - endPt); - } - - // Append the origin and advanceWidth points (n & n+1) - // _points[gd.getPointCount()] = new Point(0, 0, true, true); - // _points[gd.getPointCount()+1] = new Point(_advanceWidth, 0, true, true); - - _bbox = new AABBox(gd.getXMinimum(), gd.getYMinimum(), 0, gd.getXMaximum(), gd.getYMaximum(), 0); - } -} diff --git a/src/net/java/dev/typecast/ot/Point.java b/src/net/java/dev/typecast/ot/Point.java deleted file mode 100644 index fae13b098..000000000 --- a/src/net/java/dev/typecast/ot/Point.java +++ /dev/null @@ -1,29 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot; - -/** - * @version $Id: Point.java,v 1.1.1.1 2004-12-05 23:14:31 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class Point { - - public int x = 0; - public int y = 0; - public boolean onCurve = true; - public boolean endOfContour = false; - public boolean touched = false; - - public Point(int x, int y, boolean onCurve, boolean endOfContour) { - this.x = x; - this.y = y; - this.onCurve = onCurve; - this.endOfContour = endOfContour; - } -} diff --git a/src/net/java/dev/typecast/ot/mac/ResourceData.java b/src/net/java/dev/typecast/ot/mac/ResourceData.java deleted file mode 100644 index a1c12ffc0..000000000 --- a/src/net/java/dev/typecast/ot/mac/ResourceData.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * $Id: ResourceData.java,v 1.1.1.1 2004-12-05 23:14:31 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.mac; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceData.java,v 1.1.1.1 2004-12-05 23:14:31 davidsch Exp $ - */ -public class ResourceData { - - private byte[] data; - - /** Creates new ResourceData */ - public ResourceData(DataInput di) throws IOException { - int dataLen = di.readInt(); - data = new byte[dataLen]; - di.readFully(data); - } - - public byte[] getData() { - return data; - } -} diff --git a/src/net/java/dev/typecast/ot/mac/ResourceFile.java b/src/net/java/dev/typecast/ot/mac/ResourceFile.java deleted file mode 100644 index e9499d9e8..000000000 --- a/src/net/java/dev/typecast/ot/mac/ResourceFile.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * $Id: ResourceFile.java,v 1.2 2007-01-29 04:01:53 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.mac; - -import java.io.IOException; -import java.io.RandomAccessFile; - -/** - * Mac resource loading test. - * TODO: incorporate this into the test suite. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceFile.java,v 1.2 2007-01-29 04:01:53 davidsch Exp $ - */ -public class ResourceFile { - - private ResourceHeader header; - private ResourceMap map; - - /** Creates new Resource */ - public ResourceFile(RandomAccessFile raf) throws IOException { - - // Read header at the beginning of the file - raf.seek(0); - header = new ResourceHeader(raf); - - // Seek to the map offset and read the map - raf.seek(header.getMapOffset()); - map = new ResourceMap(raf); - } - - public ResourceMap getResourceMap() { - return map; - } - - public static void main(String[] args) { - try { - //RandomAccessFile raf = new RandomAccessFile("/Library/Fonts/GillSans.dfont", "r"); - - // Tests loading a font from a resource fork on Mac OS X - RandomAccessFile raf = new RandomAccessFile("/Library/Fonts/Georgia/..namedfork/rsrc", "r"); - ResourceFile resource = new ResourceFile(raf); - for (int i = 0; i < resource.getResourceMap().getResourceTypeCount(); i++) { - System.out.println(resource.getResourceMap().getResourceType(i).getTypeAsString()); - } - - // Get the first 'sfnt' resource - ResourceType type = resource.getResourceMap().getResourceType("sfnt"); - ResourceReference reference = type.getReference(0); - - type = resource.getResourceMap().getResourceType("FOND"); - for (int i = 0; i < type.getCount(); ++i) { - reference = type.getReference(i); - System.out.println(reference.getName()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/src/net/java/dev/typecast/ot/mac/ResourceHeader.java b/src/net/java/dev/typecast/ot/mac/ResourceHeader.java deleted file mode 100644 index bdfe15a72..000000000 --- a/src/net/java/dev/typecast/ot/mac/ResourceHeader.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * $Id: ResourceHeader.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.mac; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceHeader.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ - */ -public class ResourceHeader { - - private int dataOffset; - private int mapOffset; - private int dataLen; - private int mapLen; - - /** Creates new ResourceHeader */ - public ResourceHeader(DataInput di) throws IOException { - dataOffset = di.readInt(); - mapOffset = di.readInt(); - dataLen = di.readInt(); - mapLen = di.readInt(); - } - - public int getDataOffset() { - return dataOffset; - } - - public int getMapOffset() { - return mapOffset; - } - - public int getDataLength() { - return dataLen; - } - - public int getMapLength() { - return mapLen; - } -} diff --git a/src/net/java/dev/typecast/ot/mac/ResourceMap.java b/src/net/java/dev/typecast/ot/mac/ResourceMap.java deleted file mode 100644 index ee98fd8eb..000000000 --- a/src/net/java/dev/typecast/ot/mac/ResourceMap.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * $Id: ResourceMap.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.mac; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceMap.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ - */ -public class ResourceMap { - - private byte[] headerCopy = new byte[16]; - private int nextResourceMap; - private int fileReferenceNumber; - private int attributes; - private ResourceType[] types; - - /** Creates new ResourceMap */ - public ResourceMap(DataInput di) throws IOException { - di.readFully(headerCopy); - nextResourceMap = di.readInt(); - fileReferenceNumber = di.readUnsignedShort(); - attributes = di.readUnsignedShort(); - int typeOffset = di.readUnsignedShort(); - int nameOffset = di.readUnsignedShort(); - int typeCount = di.readUnsignedShort() + 1; - - // Read types - types = new ResourceType[typeCount]; - for (int i = 0; i < typeCount; i++) { - types[i] = new ResourceType(di); - } - - // Read the references - for (int i = 0; i < typeCount; i++) { - types[i].readRefs(di); - } - - // Read the names - for (int i = 0; i < typeCount; i++) { - types[i].readNames(di); - } - } - - public ResourceType getResourceType(String typeName) { - for (int i = 0; i < types.length; i++) { - String s = types[i].getTypeAsString(); - if (types[i].getTypeAsString().equals(typeName)) { - return types[i]; - } - } - return null; - } - - public ResourceType getResourceType(int i) { - return types[i]; - } - - public int getResourceTypeCount() { - return types.length; - } -} diff --git a/src/net/java/dev/typecast/ot/mac/ResourceReference.java b/src/net/java/dev/typecast/ot/mac/ResourceReference.java deleted file mode 100644 index f7f6e0fdf..000000000 --- a/src/net/java/dev/typecast/ot/mac/ResourceReference.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * $Id: ResourceReference.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.mac; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceReference.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ - */ -public class ResourceReference { - - private int id; - private short nameOffset; - private short attributes; - private int dataOffset; - private int handle; - private String name; - - /** Creates new ResourceReference */ - protected ResourceReference(DataInput di) throws IOException { - id = di.readUnsignedShort(); - nameOffset = di.readShort(); - attributes = (short) di.readUnsignedByte(); - dataOffset = (di.readUnsignedByte()<<16) | di.readUnsignedShort(); - handle = di.readInt(); - } - - protected void readName(DataInput di) throws IOException { - if (nameOffset > -1) { - int len = di.readUnsignedByte(); - byte[] buf = new byte[len]; - di.readFully(buf); - name = new String(buf); - } - } - - public int getId() { - return id; - } - - public short getNameOffset() { - return nameOffset; - } - - public short getAttributes() { - return attributes; - } - - public int getDataOffset() { - return dataOffset; - } - - public int getHandle() { - return handle; - } - - public String getName() { - return name; - } -} diff --git a/src/net/java/dev/typecast/ot/mac/ResourceType.java b/src/net/java/dev/typecast/ot/mac/ResourceType.java deleted file mode 100644 index 2c21e7a27..000000000 --- a/src/net/java/dev/typecast/ot/mac/ResourceType.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * $Id: ResourceType.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.mac; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceType.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ - */ -public class ResourceType { - - private int type; - private int count; - private int offset; - private ResourceReference[] references; - - /** Creates new ResourceType */ - protected ResourceType(DataInput di) throws IOException { - type = di.readInt(); - count = di.readUnsignedShort() + 1; - offset = di.readUnsignedShort(); - references = new ResourceReference[count]; - } - - protected void readRefs(DataInput di) throws IOException { - for (int i = 0; i < count; i++) { - references[i] = new ResourceReference(di); - } - } - - protected void readNames(DataInput di) throws IOException { - for (int i = 0; i < count; i++) { - references[i].readName(di); - } - } - - public int getType() { - return type; - } - - public String getTypeAsString() { - return new StringBuffer() - .append((char)((type>>24)&0xff)) - .append((char)((type>>16)&0xff)) - .append((char)((type>>8)&0xff)) - .append((char)((type)&0xff)) - .toString(); - } - - public int getCount() { - return count; - } - - public int getOffset() { - return offset; - } - - public ResourceReference getReference(int i) { - return references[i]; - } -} diff --git a/src/net/java/dev/typecast/ot/table/BaseTable.java b/src/net/java/dev/typecast/ot/table/BaseTable.java deleted file mode 100644 index f92de718f..000000000 --- a/src/net/java/dev/typecast/ot/table/BaseTable.java +++ /dev/null @@ -1,435 +0,0 @@ -/* - * $Id: BaseTable.java,v 1.3 2007-02-08 04:31:31 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -import java.io.ByteArrayInputStream; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.IOException; - -/** - * Baseline Table - * @version $Id: BaseTable.java,v 1.3 2007-02-08 04:31:31 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class BaseTable implements Table { - - private abstract class BaseCoord { - - public abstract int getBaseCoordFormat(); - - public abstract short getCoordinate(); - } - - private class BaseCoordFormat1 extends BaseCoord { - - private short _coordinate; - - protected BaseCoordFormat1(DataInput di) throws IOException { - _coordinate = di.readShort(); - } - - public int getBaseCoordFormat() { - return 1; - } - - public short getCoordinate() { - return _coordinate; - } - - } - - private class BaseCoordFormat2 extends BaseCoord { - - private short _coordinate; - private int _referenceGlyph; - private int _baseCoordPoint; - - protected BaseCoordFormat2(DataInput di) throws IOException { - _coordinate = di.readShort(); - _referenceGlyph = di.readUnsignedShort(); - _baseCoordPoint = di.readUnsignedShort(); - } - - public int getBaseCoordFormat() { - return 2; - } - - public short getCoordinate() { - return _coordinate; - } - - } - - private class BaseCoordFormat3 extends BaseCoord { - - private short _coordinate; - private int _deviceTableOffset; - - protected BaseCoordFormat3(DataInput di) throws IOException { - _coordinate = di.readShort(); - _deviceTableOffset = di.readUnsignedShort(); - } - - public int getBaseCoordFormat() { - return 2; - } - - public short getCoordinate() { - return _coordinate; - } - - } - - private class FeatMinMaxRecord { - - private int _tag; - private int _minCoordOffset; - private int _maxCoordOffset; - - protected FeatMinMaxRecord(DataInput di) throws IOException { - _tag = di.readInt(); - _minCoordOffset = di.readUnsignedShort(); - _maxCoordOffset = di.readUnsignedShort(); - } - } - - private class MinMax { - - private int _minCoordOffset; - private int _maxCoordOffset; - private int _featMinMaxCount; - private FeatMinMaxRecord[] _featMinMaxRecord; - - protected MinMax(int minMaxOffset) throws IOException { - DataInput di = getDataInputForOffset(minMaxOffset); - _minCoordOffset = di.readUnsignedShort(); - _maxCoordOffset = di.readUnsignedShort(); - _featMinMaxCount = di.readUnsignedShort(); - _featMinMaxRecord = new FeatMinMaxRecord[_featMinMaxCount]; - for (int i = 0; i < _featMinMaxCount; ++i) { - _featMinMaxRecord[i] = new FeatMinMaxRecord(di); - } - } - } - - private class BaseValues { - - private int _defaultIndex; - private int _baseCoordCount; - private int[] _baseCoordOffset; - private BaseCoord[] _baseCoords; - - protected BaseValues(int baseValuesOffset) throws IOException { - DataInput di = getDataInputForOffset(baseValuesOffset); - _defaultIndex = di.readUnsignedShort(); - _baseCoordCount = di.readUnsignedShort(); - _baseCoordOffset = new int[_baseCoordCount]; - for (int i = 0; i < _baseCoordCount; ++i) { - _baseCoordOffset[i] = di.readUnsignedShort(); - } - _baseCoords = new BaseCoord[_baseCoordCount]; - for (int i = 0; i < _baseCoordCount; ++i) { - int format = di.readUnsignedShort(); - switch (format) { - case 1: - _baseCoords[i] = new BaseCoordFormat1(di); - break; - case 2: - _baseCoords[i] = new BaseCoordFormat2(di); - break; - case 3: - _baseCoords[i] = new BaseCoordFormat3(di); - break; - } - } - } - } - - private class BaseLangSysRecord { - - private int _baseLangSysTag; - private int _minMaxOffset; - - protected BaseLangSysRecord(DataInput di) throws IOException { - _baseLangSysTag = di.readInt(); - _minMaxOffset = di.readUnsignedShort(); - } - - public int getBaseLangSysTag() { - return _baseLangSysTag; - } - - public int getMinMaxOffset() { - return _minMaxOffset; - } - } - - private class BaseScript { - - private int _thisOffset; - private int _baseValuesOffset; - private int _defaultMinMaxOffset; - private int _baseLangSysCount; - private BaseLangSysRecord[] _baseLangSysRecord; - private BaseValues _baseValues; - private MinMax[] _minMax; - - protected BaseScript(int baseScriptOffset) throws IOException { - _thisOffset = baseScriptOffset; - DataInput di = getDataInputForOffset(baseScriptOffset); - _baseValuesOffset = di.readUnsignedShort(); - _defaultMinMaxOffset = di.readUnsignedShort(); - _baseLangSysCount = di.readUnsignedShort(); - _baseLangSysRecord = new BaseLangSysRecord[_baseLangSysCount]; - for (int i = 0; i < _baseLangSysCount; ++i) { - _baseLangSysRecord[i] = new BaseLangSysRecord(di); - } - if (_baseValuesOffset > 0) { - _baseValues = new BaseValues(baseScriptOffset + _baseValuesOffset); - } - for (int i = 0; i < _baseLangSysCount; ++i) { - _minMax[i] = new MinMax(baseScriptOffset + _baseLangSysRecord[i].getMinMaxOffset()); - } - } - - public String toString() { - StringBuffer sb = new StringBuffer() - .append("\nBaseScript BaseScriptT").append(Integer.toHexString(_thisOffset)) - .append("\nBaseValuesT").append(Integer.toHexString(_thisOffset + _baseValuesOffset)) - .append("\nMinMaxT").append(Integer.toHexString(_thisOffset + _defaultMinMaxOffset)) - .append("\n").append(Integer.toHexString(_baseLangSysCount)); -// for (int i = 0; i < _baseLangSysCount; ++i) { -// sb.append("\n ; BaseScriptRecord[").append(i); -// sb.append("]\n'").append(tagAsString(_baseScriptRecord[i].getBaseScriptTag())).append("'"); -// sb.append("\nBaseScriptT").append(Integer.toHexString(_thisOffset + _baseScriptRecord[i].getBaseScriptOffset())); -// } -// for (int i = 0; i < _baseScriptCount; ++i) { -// sb.append("\n").append(_baseScripts[i].toString()); -// } - if (_baseValues != null) { - sb.append("\n").append(_baseValues.toString()); - } - return sb.toString(); - } - } - - private class BaseScriptRecord { - - private int _baseScriptTag; - private int _baseScriptOffset; - - protected BaseScriptRecord(DataInput di) throws IOException { - _baseScriptTag = di.readInt(); - _baseScriptOffset = di.readUnsignedShort(); - } - - public int getBaseScriptTag() { - return _baseScriptTag; - } - - public int getBaseScriptOffset() { - return _baseScriptOffset; - } - } - - private class BaseScriptList { - - private int _thisOffset; - private int _baseScriptCount; - private BaseScriptRecord[] _baseScriptRecord; - private BaseScript[] _baseScripts; - - protected BaseScriptList(int baseScriptListOffset) throws IOException { - _thisOffset = baseScriptListOffset; - DataInput di = getDataInputForOffset(baseScriptListOffset); - _baseScriptCount = di.readUnsignedShort(); - _baseScriptRecord = new BaseScriptRecord[_baseScriptCount]; - for (int i = 0; i < _baseScriptCount; ++i) { - _baseScriptRecord[i] = new BaseScriptRecord(di); - } - _baseScripts = new BaseScript[_baseScriptCount]; - for (int i = 0; i < _baseScriptCount; ++i) { - _baseScripts[i] = new BaseScript( - baseScriptListOffset + _baseScriptRecord[i].getBaseScriptOffset()); - } - } - - public String toString() { - StringBuffer sb = new StringBuffer() - .append("\nBaseScriptList BaseScriptListT").append(Integer.toHexString(_thisOffset)) - .append("\n").append(Integer.toHexString(_baseScriptCount)); - for (int i = 0; i < _baseScriptCount; ++i) { - sb.append("\n ; BaseScriptRecord[").append(i); - sb.append("]\n'").append(tagAsString(_baseScriptRecord[i].getBaseScriptTag())).append("'"); - sb.append("\nBaseScriptT").append(Integer.toHexString(_thisOffset + _baseScriptRecord[i].getBaseScriptOffset())); - } - for (int i = 0; i < _baseScriptCount; ++i) { - sb.append("\n").append(_baseScripts[i].toString()); - } - return sb.toString(); - } - } - - private class BaseTagList { - - private int _thisOffset; - private int _baseTagCount; - private int[] _baselineTag; - - protected BaseTagList(int baseTagListOffset) throws IOException { - _thisOffset = baseTagListOffset; - DataInput di = getDataInputForOffset(baseTagListOffset); - _baseTagCount = di.readUnsignedShort(); - _baselineTag = new int[_baseTagCount]; - for (int i = 0; i < _baseTagCount; ++i) { - _baselineTag[i] = di.readInt(); - } - } - - public String toString() { - StringBuffer sb = new StringBuffer() - .append("\nBaseTagList BaseTagListT").append(Integer.toHexString(_thisOffset)) - .append("\n").append(Integer.toHexString(_baseTagCount)); - for (int i = 0; i < _baseTagCount; ++i) { - sb.append("\n'").append(tagAsString(_baselineTag[i])).append("'"); - } - return sb.toString(); - } - } - - private class Axis { - - private int _thisOffset; - private int _baseTagListOffset; - private int _baseScriptListOffset; - private BaseTagList _baseTagList; - private BaseScriptList _baseScriptList; - - protected Axis(int axisOffset) throws IOException { - _thisOffset = axisOffset; - DataInput di = getDataInputForOffset(axisOffset); - _baseTagListOffset = di.readUnsignedShort(); - _baseScriptListOffset = di.readUnsignedShort(); - if (_baseTagListOffset != 0) { - _baseTagList = new BaseTagList(axisOffset + _baseTagListOffset); - } - if (_baseScriptListOffset != 0) { - _baseScriptList = new BaseScriptList( - axisOffset + _baseScriptListOffset); - } - } - - public String toString() { - return new StringBuffer() - .append("\nAxis AxisT").append(Integer.toHexString(_thisOffset)) - .append("\nBaseTagListT").append(Integer.toHexString(_thisOffset + _baseTagListOffset)) - .append("\nBaseScriptListT").append(Integer.toHexString(_thisOffset + _baseScriptListOffset)) - .append("\n").append(_baseTagList) - .append("\n").append(_baseScriptList) - .toString(); - } - } - - private DirectoryEntry _de; - private int _version; - private int _horizAxisOffset; - private int _vertAxisOffset; - private Axis _horizAxis; - private Axis _vertAxis; - private byte[] _buf; - - /** Creates a new instance of BaseTable */ - protected BaseTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); - - // Load entire table into a buffer, and create another input stream - _buf = new byte[de.getLength()]; - di.readFully(_buf); - DataInput di2 = getDataInputForOffset(0); - - _version = di2.readInt(); - _horizAxisOffset = di2.readUnsignedShort(); - _vertAxisOffset = di2.readUnsignedShort(); - if (_horizAxisOffset != 0) { - _horizAxis = new Axis(_horizAxisOffset); - } - if (_vertAxisOffset != 0) { - _vertAxis = new Axis(_vertAxisOffset); - } - - // Let go of the buffer - _buf = null; - } - - private DataInput getDataInputForOffset(int offset) { - return new DataInputStream(new ByteArrayInputStream( - _buf, offset, - _de.getLength() - offset)); - } - -// private String valueAsShortHex(int value) { -// return String.format("%1$4x", value); -// } -// -// private String valueAsLongHex(int value) { -// return String.format("%1$8x", value); -// } - - static protected String tagAsString(int tag) { - char[] c = new char[4]; - c[0] = (char)((tag >> 24) & 0xff); - c[1] = (char)((tag >> 16) & 0xff); - c[2] = (char)((tag >> 8) & 0xff); - c[3] = (char)(tag & 0xff); - return String.valueOf(c); - } - - public int getType() { - return BASE; - } - - public String toString() { - StringBuffer sb = new StringBuffer() - .append("; 'BASE' Table - Baseline\n;-------------------------------------\n\n") - .append("BASEHeader BASEHeaderT").append(Integer.toHexString(0)) - .append("\n").append(Integer.toHexString(_version)) - .append("\nAxisT").append(Integer.toHexString(_horizAxisOffset)) - .append("\nAxisT").append(Integer.toHexString(_vertAxisOffset)); - if (_horizAxis != null) { - sb.append("\n").append(_horizAxis.toString()); - } - if (_vertAxis != null) { - sb.append("\n").append(_vertAxis.toString()); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/CffStandardStrings.java b/src/net/java/dev/typecast/ot/table/CffStandardStrings.java deleted file mode 100644 index 987ea886c..000000000 --- a/src/net/java/dev/typecast/ot/table/CffStandardStrings.java +++ /dev/null @@ -1,424 +0,0 @@ -/* - * $Id: CffStandardStrings.java,v 1.1 2007-02-05 12:41:52 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -/** - * Compact Font Format Standard Strings. As per Appendix A of the Adobe - * CFF specification. - * @version $Id: CffStandardStrings.java,v 1.1 2007-02-05 12:41:52 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CffStandardStrings { - - public static final String[] standardStrings = { - ".notdef", - "space", - "exclam", - "quotedbl", - "numbersign", - "dollar", - "percent", - "ampersand", - "quoteright", - "parenleft", - "parenright", - "asterisk", - "plus", - "comma", - "hyphen", - "period", - "slash", - "zero", - "one", - "two", - "three", - "four", - "five", - "six", - "seven", - "eight", - "nine", - "colon", - "semicolon", - "less", - "equal", - "greater", - "question", - "at", - "A", - "B", - "C", - "D", - "E", - "F", - "G", - "H", - "I", - "J", - "K", - "L", - "M", - "N", - "O", - "P", - "Q", - "R", - "S", - "T", - "U", - "V", - "W", - "X", - "Y", - "Z", - "bracketleft", - "backslash", - "bracketright", - "asciicircum", - "underscore", - "quoteleft", - "a", - "b", - "c", - "d", - "e", - "f", - "g", - "h", - "i", - "j", - "k", - "l", - "m", - "n", - "o", - "p", - "q", - "r", - "s", - "t", - "u", - "v", - "w", - "x", - "y", - "z", - "braceleft", - "bar", - "braceright", - "asciitilde", - "exclamdown", - "cent", - "sterling", - "fraction", - "yen", - "florin", - "section", - "currency", - "quotesingle", - "quotedblleft", - "guillemotleft", - "guilsinglleft", - "guilsinglright", - "fi", - "fl", - "endash", - "dagger", - "daggerdbl", - "periodcentered", - "paragraph", - "bullet", - "quotesinglbase", - "quotedblbase", - "quotedblright", - "guillemotright", - "ellipsis", - "perthousand", - "questiondown", - "grave", - "acute", - "circumflex", - "tilde", - "macron", - "breve", - "dotaccent", - "dieresis", - "ring", - "cedilla", - "hungarumlaut", - "ogonek", - "caron", - "emdash", - "AE", - "ordfeminine", - "Lslash", - "Oslash", - "OE", - "ordmasculine", - "ae", - "dotlessi", - "lslash", - "oslash", - "oe", - "germandbls", - "onesuperior", - "logicalnot", - "mu", - "trademark", - "Eth", - "onehalf", - "plusminus", - "Thorn", - "onequarter", - "divide", - "brokenbar", - "degree", - "thorn", - "threequarters", - "twosuperior", - "registered", - "minus", - "eth", - "multiply", - "threesuperior", - "copyright", - "Aacute", - "Acircumflex", - "Adieresis", - "Agrave", - "Aring", - "Atilde", - "Ccedilla", - "Eacute", - "Ecircumflex", - "Edieresis", - "Egrave", - "Iacute", - "Icircumflex", - "Idieresis", - "Igrave", - "Ntilde", - "Oacute", - "Ocircumflex", - "Odieresis", - "Ograve", - "Otilde", - "Scaron", - "Uacute", - "Ucircumflex", - "Udieresis", - "Ugrave", - "Yacute", - "Ydieresis", - "Zcaron", - "aacute", - "acircumflex", - "adieresis", - "agrave", - "aring", - "atilde", - "ccedilla", - "eacute", - "ecircumflex", - "edieresis", - "egrave", - "iacute", - "icircumflex", - "idieresis", - "igrave", - "ntilde", - "oacute", - "ocircumflex", - "odieresis", - "ograve", - "otilde", - "scaron", - "uacute", - "ucircumflex", - "udieresis", - "ugrave", - "yacute", - "ydieresis", - "zcaron", - "exclamsmall", - "Hungarumlautsmall", - "dollaroldstyle", - "dollarsuperior", - "ampersandsmall", - "Acutesmall", - "parenleftsuperior", - "parenrightsuperior", - "twodotenleader", - "onedotenleader", - "zerooldstyle", - "oneoldstyle", - "twooldstyle", - "threeoldstyle", - "fouroldstyle", - "fiveoldstyle", - "sixoldstyle", - "sevenoldstyle", - "eightoldstyle", - "nineoldstyle", - "commasuperior", - "threequartersemdash", - "periodsuperior", - "questionsmall", - "asuperior", - "bsuperior", - "centsuperior", - "dsuperior", - "esuperior", - "isuperior", - "lsuperior", - "msuperior", - "nsuperior", - "osuperior", - "rsuperior", - "ssuperior", - "tsuperior", - "ff", - "ffi", - "ffl", - "parenleftinferior", - "parenrightinferior", - "Circumflexsmall", - "hyphensuperior", - "Gravesmall", - "Asmall", - "Bsmall", - "Csmall", - "Dsmall", - "Esmall", - "Fsmall", - "Gsmall", - "Hsmall", - "Ismall", - "Jsmall", - "Ksmall", - "Lsmall", - "Msmall", - "Nsmall", - "Osmall", - "Psmall", - "Qsmall", - "Rsmall", - "Ssmall", - "Tsmall", - "Usmall", - "Vsmall", - "Wsmall", - "Xsmall", - "Ysmall", - "Zsmall", - "colonmonetary", - "onefitted", - "rupiah", - "Tildesmall", - "exclamdownsmall", - "centoldstyle", - "Lslashsmall", - "Scaronsmall", - "Zcaronsmall", - "Dieresissmall", - "Brevesmall", - "Caronsmall", - "Dotaccentsmall", - "Macronsmall", - "figuredash", - "hypheninferior", - "Ogoneksmall", - "Ringsmall", - "Cedillasmall", - "questiondownsmall", - "oneeighth", - "threeeighths", - "fiveeighths", - "seveneighths", - "onethird", - "twothirds", - "zerosuperior", - "foursuperior", - "fivesuperior", - "sixsuperior", - "sevensuperior", - "eightsuperior", - "ninesuperior", - "zeroinferior", - "oneinferior", - "twoinferior", - "threeinferior", - "fourinferior", - "fiveinferior", - "sixinferior", - "seveninferior", - "eightinferior", - "nineinferior", - "centinferior", - "dollarinferior", - "periodinferior", - "commainferior", - "Agravesmall", - "Aacutesmall", - "Acircumflexsmall", - "Atildesmall", - "Adieresissmall", - "Aringsmall", - "AEsmall", - "Ccedillasmall", - "Egravesmall", - "Eacutesmall", - "Ecircumflexsmall", - "Edieresissmall", - "Igravesmall", - "Iacutesmall", - "Icircumflexsmall", - "Idieresissmall", - "Ethsmall", - "Ntildesmall", - "Ogravesmall", - "Oacutesmall", - "Ocircumflexsmall", - "Otildesmall", - "Odieresissmall", - "OEsmall", - "Oslashsmall", - "Ugravesmall", - "Uacutesmall", - "Ucircumflexsmall", - "Udieresissmall", - "Yacutesmall", - "Thornsmall", - "Ydieresissmall", - "001.000", - "001.001", - "001.002", - "001.003", - "Black", - "Bold", - "Book", - "Light", - "Medium", - "Regular", - "Roman", - "Semibold" - }; -} diff --git a/src/net/java/dev/typecast/ot/table/CffTable.java b/src/net/java/dev/typecast/ot/table/CffTable.java deleted file mode 100644 index 2bd0cec63..000000000 --- a/src/net/java/dev/typecast/ot/table/CffTable.java +++ /dev/null @@ -1,620 +0,0 @@ -/* - * $Id: CffTable.java,v 1.4 2007-07-26 11:15:06 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -import java.io.ByteArrayInputStream; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.IOException; - -import java.util.ArrayList; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Hashtable; - -/** - * Compact Font Format Table - * @version $Id: CffTable.java,v 1.4 2007-07-26 11:15:06 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CffTable implements Table { - - public class Dict { - - private Dictionary<Integer, Object> _entries = new Hashtable<Integer, Object>(); - private int[] _data; - private int _index; - - protected Dict(int[] data, int offset, int length) { - _data = data; - _index = offset; - while (_index < offset + length) { - addKeyAndValueEntry(); - } - } - - public Object getValue(int key) { - return _entries.get(key); - } - - private boolean addKeyAndValueEntry() { - ArrayList<Object> operands = new ArrayList<Object>(); - Object operand = null; - while (isOperandAtIndex()) { - operand = nextOperand(); - operands.add(operand); - } - int operator = _data[_index++]; - if (operator == 12) { - operator <<= 8; - operator |= _data[_index++]; - } - if (operands.size() == 1) { - _entries.put(operator, operand); - } else { - _entries.put(operator, operands); - } - return true; - } - - private boolean isOperandAtIndex() { - int b0 = _data[_index]; - if ((32 <= b0 && b0 <= 254) - || b0 == 28 - || b0 == 29 - || b0 == 30) { - return true; - } - return false; - } - - private boolean isOperatorAtIndex() { - int b0 = _data[_index]; - if (0 <= b0 && b0 <= 21) { - return true; - } - return false; - } - - private Object nextOperand() { - int b0 = _data[_index]; - if (32 <= b0 && b0 <= 246) { - - // 1 byte integer - ++_index; - return new Integer(b0 - 139); - } else if (247 <= b0 && b0 <= 250) { - - // 2 byte integer - int b1 = _data[_index + 1]; - _index += 2; - return new Integer((b0 - 247) * 256 + b1 + 108); - } else if (251 <= b0 && b0 <= 254) { - - // 2 byte integer - int b1 = _data[_index + 1]; - _index += 2; - return new Integer(-(b0 - 251) * 256 - b1 - 108); - } else if (b0 == 28) { - - // 3 byte integer - int b1 = _data[_index + 1]; - int b2 = _data[_index + 2]; - _index += 3; - return new Integer(b1 << 8 | b2); - } else if (b0 == 29) { - - // 5 byte integer - int b1 = _data[_index + 1]; - int b2 = _data[_index + 2]; - int b3 = _data[_index + 3]; - int b4 = _data[_index + 4]; - _index += 5; - return new Integer(b1 << 24 | b2 << 16 | b3 << 8 | b4); - } else if (b0 == 30) { - - // Real number - StringBuffer fString = new StringBuffer(); - int nibble1 = 0; - int nibble2 = 0; - ++_index; - while ((nibble1 != 0xf) && (nibble2 != 0xf)) { - nibble1 = _data[_index] >> 4; - nibble2 = _data[_index] & 0xf; - ++_index; - fString.append(decodeRealNibble(nibble1)); - fString.append(decodeRealNibble(nibble2)); - } - return new Float(fString.toString()); - } else { - return null; - } - } - - private String decodeRealNibble(int nibble) { - if (nibble < 0xa) { - return Integer.toString(nibble); - } else if (nibble == 0xa) { - return "."; - } else if (nibble == 0xb) { - return "E"; - } else if (nibble == 0xc) { - return "E-"; - } else if (nibble == 0xe) { - return "-"; - } - return ""; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - Enumeration<Integer> keys = _entries.keys(); - while (keys.hasMoreElements()) { - Integer key = keys.nextElement(); - if ((key.intValue() & 0xc00) == 0xc00) { - sb.append("12 ").append(key.intValue() & 0xff).append(": "); - } else { - sb.append(key.toString()).append(": "); - } - sb.append(_entries.get(key).toString()).append("\n"); - } - return sb.toString(); - } - } - - public class Index { - - private int _count; - private int _offSize; - private int[] _offset; - private int[] _data; - - protected Index(DataInput di) throws IOException { - _count = di.readUnsignedShort(); - _offset = new int[_count + 1]; - _offSize = di.readUnsignedByte(); - for (int i = 0; i < _count + 1; ++i) { - int thisOffset = 0; - for (int j = 0; j < _offSize; ++j) { - thisOffset |= di.readUnsignedByte() << ((_offSize - j - 1) * 8); - } - _offset[i] = thisOffset; - } - _data = new int[getDataLength()]; - for (int i = 0; i < getDataLength(); ++i) { - _data[i] = di.readUnsignedByte(); - } - } - - public int getCount() { - return _count; - } - - public int getOffset(int index) { - return _offset[index]; - } - - public int getDataLength() { - return _offset[_offset.length - 1] - 1; - } - - public int[] getData() { - return _data; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("DICT\n"); - sb.append("count: ").append(_count).append("\n"); - sb.append("offSize: ").append(_offSize).append("\n"); - for (int i = 0; i < _count + 1; ++i) { - sb.append("offset[").append(i).append("]: ").append(_offset[i]).append("\n"); - } - sb.append("data:"); - for (int i = 0; i < _data.length; ++i) { - if (i % 8 == 0) { - sb.append("\n"); - } else { - sb.append(" "); - } - sb.append(_data[i]); - } - sb.append("\n"); - return sb.toString(); - } - } - - public class TopDictIndex extends Index { - - protected TopDictIndex(DataInput di) throws IOException { - super(di); - } - - public Dict getTopDict(int index) { - int offset = getOffset(index) - 1; - int len = getOffset(index + 1) - offset - 1; - return new Dict(getData(), offset, len); - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < getCount(); ++i) { - sb.append(getTopDict(i).toString()).append("\n"); - } - return sb.toString(); - } - } - - public class NameIndex extends Index { - - protected NameIndex(DataInput di) throws IOException { - super(di); - } - - public String getName(int index) { - String name = null; - int offset = getOffset(index) - 1; - int len = getOffset(index + 1) - offset - 1; - - // Ensure the name hasn't been deleted - if (getData()[offset] != 0) { - StringBuffer sb = new StringBuffer(); - for (int i = offset; i < offset + len; ++i) { - sb.append((char) getData()[i]); - } - name = sb.toString(); - } else { - name = "DELETED NAME"; - } - return name; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < getCount(); ++i) { - sb.append(getName(i)).append("\n"); - } - return sb.toString(); - } - } - - public class StringIndex extends Index { - - protected StringIndex(DataInput di) throws IOException { - super(di); - } - - public String getString(int index) { - if (index < CffStandardStrings.standardStrings.length) { - return CffStandardStrings.standardStrings[index]; - } else { - index -= CffStandardStrings.standardStrings.length; - if (index >= getCount()) { - return null; - } - int offset = getOffset(index) - 1; - int len = getOffset(index + 1) - offset - 1; - - StringBuffer sb = new StringBuffer(); - for (int i = offset; i < offset + len; ++i) { - sb.append((char) getData()[i]); - } - return sb.toString(); - } - } - - public String toString() { - int nonStandardBase = CffStandardStrings.standardStrings.length; - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < getCount(); ++i) { - sb.append(nonStandardBase + i).append(": "); - sb.append(getString(nonStandardBase + i)).append("\n"); - } - return sb.toString(); - } - } - - private class CharsetRange { - - private int _first; - private int _left; - - public int getFirst() { - return _first; - } - - protected void setFirst(int first) { - _first = first; - } - - public int getLeft() { - return _left; - } - - protected void setLeft(int left) { - _left = left; - } - } - - private class CharsetRange1 extends CharsetRange { - - protected CharsetRange1(DataInput di) throws IOException { - setFirst(di.readUnsignedShort()); - setLeft(di.readUnsignedByte()); - } - } - - private class CharsetRange2 extends CharsetRange { - - protected CharsetRange2(DataInput di) throws IOException { - setFirst(di.readUnsignedShort()); - setLeft(di.readUnsignedShort()); - } - } - - private abstract class Charset { - - public abstract int getFormat(); - - public abstract int getSID(int gid); - } - - private class CharsetFormat0 extends Charset { - - private int[] _glyph; - - protected CharsetFormat0(DataInput di, int glyphCount) throws IOException { - _glyph = new int[glyphCount - 1]; // minus 1 because .notdef is omitted - for (int i = 0; i < glyphCount - 1; ++i) { - _glyph[i] = di.readUnsignedShort(); - } - } - - public int getFormat() { - return 0; - } - - public int getSID(int gid) { - if (gid == 0) { - return 0; - } - return _glyph[gid - 1]; - } - } - - private class CharsetFormat1 extends Charset { - - private ArrayList<CharsetRange> _charsetRanges = new ArrayList<CharsetRange>(); - - protected CharsetFormat1(DataInput di, int glyphCount) throws IOException { - int glyphsCovered = glyphCount - 1; // minus 1 because .notdef is omitted - while (glyphsCovered > 0) { - CharsetRange range = new CharsetRange1(di); - _charsetRanges.add(range); - glyphsCovered -= range.getLeft() + 1; - } - } - - public int getFormat() { - return 1; - } - - public int getSID(int gid) { - if (gid == 0) { - return 0; - } - - // Count through the ranges to find the one of interest - int count = 0; - for (CharsetRange range : _charsetRanges) { - count += range.getLeft(); - if (gid < count) { - int sid = gid - count + range.getFirst(); - return sid; - } - } - return 0; - } - } - - private class CharsetFormat2 extends Charset { - - private ArrayList<CharsetRange> _charsetRanges = new ArrayList<CharsetRange>(); - - protected CharsetFormat2(DataInput di, int glyphCount) throws IOException { - int glyphsCovered = glyphCount - 1; // minus 1 because .notdef is omitted - while (glyphsCovered > 0) { - CharsetRange range = new CharsetRange2(di); - _charsetRanges.add(range); - glyphsCovered -= range.getLeft() + 1; - } - } - - public int getFormat() { - return 2; - } - - public int getSID(int gid) { - if (gid == 0) { - return 0; - } - - // Count through the ranges to find the one of interest - int count = 0; - for (CharsetRange range : _charsetRanges) { - if (gid < range.getLeft() + count) { - int sid = gid - count + range.getFirst() - 1; - return sid; - } - count += range.getLeft(); - } - return 0; - } - } - - private DirectoryEntry _de; - private int _major; - private int _minor; - private int _hdrSize; - private int _offSize; - private NameIndex _nameIndex; - private TopDictIndex _topDictIndex; - private StringIndex _stringIndex; - private Index _globalSubrIndex; - private Index _charStringsIndexArray[]; - private Charset[] _charsets; - private Charstring[][] _charstringsArray; - - private byte[] _buf; - - /** Creates a new instance of CffTable */ - protected CffTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); - - // Load entire table into a buffer, and create another input stream - _buf = new byte[de.getLength()]; - di.readFully(_buf); - DataInput di2 = getDataInputForOffset(0); - - // Header - _major = di2.readUnsignedByte(); - _minor = di2.readUnsignedByte(); - _hdrSize = di2.readUnsignedByte(); - _offSize = di2.readUnsignedByte(); - - // Name INDEX - di2 = getDataInputForOffset(_hdrSize); - _nameIndex = new NameIndex(di2); - - // Top DICT INDEX - _topDictIndex = new TopDictIndex(di2); - - // String INDEX - _stringIndex = new StringIndex(di2); - - // Global Subr INDEX - _globalSubrIndex = new Index(di2); - - // Encodings go here -- but since this is an OpenType font will this - // not always be a CIDFont? In which case there are no encodings - // within the CFF data. - - // Load each of the fonts - _charStringsIndexArray = new Index[_topDictIndex.getCount()]; - _charsets = new Charset[_topDictIndex.getCount()]; - _charstringsArray = new Charstring[_topDictIndex.getCount()][]; - for (int i = 0; i < _topDictIndex.getCount(); ++i) { - - // Charstrings INDEX - // We load this before Charsets because we may need to know the number - // of glyphs - Integer charStringsOffset = (Integer) _topDictIndex.getTopDict(i).getValue(17); - di2 = getDataInputForOffset(charStringsOffset); - _charStringsIndexArray[i] = new Index(di2); - int glyphCount = _charStringsIndexArray[i].getCount(); - - // Charsets - Integer charsetOffset = (Integer) _topDictIndex.getTopDict(i).getValue(15); - di2 = getDataInputForOffset(charsetOffset); - int format = di2.readUnsignedByte(); - switch (format) { - case 0: - _charsets[i] = new CharsetFormat0(di2, glyphCount); - break; - case 1: - _charsets[i] = new CharsetFormat1(di2, glyphCount); - break; - case 2: - _charsets[i] = new CharsetFormat2(di2, glyphCount); - break; - } - - // Create the charstrings - _charstringsArray[i] = new Charstring[glyphCount]; - for (int j = 0; j < glyphCount; ++j) { - int offset = _charStringsIndexArray[i].getOffset(j) - 1; - int len = _charStringsIndexArray[i].getOffset(j + 1) - offset - 1; - _charstringsArray[i][j] = new CharstringType2( - i, - _stringIndex.getString(_charsets[i].getSID(j)), - _charStringsIndexArray[i].getData(), - offset, - len, - null, - null); - } - } - } - - private DataInput getDataInputForOffset(int offset) { - return new DataInputStream(new ByteArrayInputStream( - _buf, offset, - _de.getLength() - offset)); - } - - public NameIndex getNameIndex() { - return _nameIndex; - } - - public Charset getCharset(int fontIndex) { - return _charsets[fontIndex]; - } - - public Charstring getCharstring(int fontIndex, int gid) { - return _charstringsArray[fontIndex][gid]; - } - - public int getCharstringCount(int fontIndex) { - return _charstringsArray[fontIndex].length; - } - - public int getType() { - return CFF; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'CFF' Table - Compact Font Format\n---------------------------------\n"); - sb.append("\nName INDEX\n"); - sb.append(_nameIndex.toString()); - sb.append("\nTop DICT INDEX\n"); - sb.append(_topDictIndex.toString()); - sb.append("\nString INDEX\n"); - sb.append(_stringIndex.toString()); - sb.append("\nGlobal Subr INDEX\n"); - sb.append(_globalSubrIndex.toString()); - for (int i = 0; i < _charStringsIndexArray.length; ++i) { - sb.append("\nCharStrings INDEX ").append(i).append("\n"); - sb.append(_charStringsIndexArray[i].toString()); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/Charstring.java b/src/net/java/dev/typecast/ot/table/Charstring.java deleted file mode 100644 index 2439d6bc5..000000000 --- a/src/net/java/dev/typecast/ot/table/Charstring.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * $Id: Charstring.java,v 1.2 2007-02-21 12:25:19 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -/** - * CFF Charstring - * @version $Id: Charstring.java,v 1.2 2007-02-21 12:25:19 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public abstract class Charstring { - - public abstract int getIndex(); - - public abstract String getName(); -} diff --git a/src/net/java/dev/typecast/ot/table/CharstringType2.java b/src/net/java/dev/typecast/ot/table/CharstringType2.java deleted file mode 100644 index e47825cf3..000000000 --- a/src/net/java/dev/typecast/ot/table/CharstringType2.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * $Id: CharstringType2.java,v 1.4 2007-07-26 11:13:44 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -import net.java.dev.typecast.ot.table.CffTable; - -/** - * CFF Type 2 Charstring - * @version $Id: CharstringType2.java,v 1.4 2007-07-26 11:13:44 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CharstringType2 extends Charstring { - - private static final String[] _oneByteOperators = { - "-Reserved-", - "hstem", - "-Reserved-", - "vstem", - "vmoveto", - "rlineto", - "hlineto", - "vlineto", - "rrcurveto", - "-Reserved-", - "callsubr", - "return", - "escape", - "-Reserved-", - "endchar", - "-Reserved-", - "-Reserved-", - "-Reserved-", - "hstemhm", - "hintmask", - "cntrmask", - "rmoveto", - "hmoveto", - "vstemhm", - "rcurveline", - "rlinecurve", - "vvcurveto", - "hhcurveto", - "shortint", - "callgsubr", - "vhcurveto", - "hvcurveto" - }; - - private static final String[] _twoByteOperators = { - "-Reserved- (dotsection)", - "-Reserved-", - "-Reserved-", - "and", - "or", - "not", - "-Reserved-", - "-Reserved-", - "-Reserved-", - "abs", - "add", - "sub", - "div", - "-Reserved-", - "neg", - "eq", - "-Reserved-", - "-Reserved-", - "drop", - "-Reserved-", - "put", - "get", - "ifelse", - "random", - "mul", - "-Reserved-", - "sqrt", - "dup", - "exch", - "index", - "roll", - "-Reserved-", - "-Reserved-", - "-Reserved-", - "hflex", - "flex", - "hflex1", - "flex1", - "-Reserved-" - }; - - private int _index; - private String _name; - private int[] _data; - private int _offset; - private int _length; - private CffTable.Index _localSubrIndex; - private CffTable.Index _globalSubrIndex; - private int _ip; - - /** Creates a new instance of CharstringType2 */ - protected CharstringType2( - int index, - String name, - int[] data, - int offset, - int length, - CffTable.Index localSubrIndex, - CffTable.Index globalSubrIndex) { - _index = index; - _name = name; - _data = data; - _offset = offset; - _length = length; - _localSubrIndex = localSubrIndex; - _globalSubrIndex = globalSubrIndex; - } - - public int getIndex() { - return _index; - } - - public String getName() { - return _name; - } - - private void disassemble(StringBuffer sb) { - Number operand = null; - while (isOperandAtIndex()) { - operand = nextOperand(); - sb.append(operand).append(" "); - } - int operator = nextByte(); - String mnemonic; - if (operator == 12) { - operator = nextByte(); - - // Check we're not exceeding the upper limit of our mnemonics - if (operator > 38) { - operator = 38; - } - mnemonic = _twoByteOperators[operator]; - } else { - mnemonic = _oneByteOperators[operator]; - } - sb.append(mnemonic); - } - - public void resetIP() { - _ip = _offset; - } - - public boolean isOperandAtIndex() { - int b0 = _data[_ip]; - if ((32 <= b0 && b0 <= 255) || b0 == 28) { - return true; - } - return false; - } - - public Number nextOperand() { - int b0 = _data[_ip]; - if (32 <= b0 && b0 <= 246) { - - // 1 byte integer - ++_ip; - return new Integer(b0 - 139); - } else if (247 <= b0 && b0 <= 250) { - - // 2 byte integer - int b1 = _data[_ip + 1]; - _ip += 2; - return new Integer((b0 - 247) * 256 + b1 + 108); - } else if (251 <= b0 && b0 <= 254) { - - // 2 byte integer - int b1 = _data[_ip + 1]; - _ip += 2; - return new Integer(-(b0 - 251) * 256 - b1 - 108); - } else if (b0 == 28) { - - // 3 byte integer - int b1 = _data[_ip + 1]; - int b2 = _data[_ip + 2]; - _ip += 3; - return new Integer(b1 << 8 | b2); - } else if (b0 == 255) { - - // 16-bit signed integer with 16 bits of fraction - int b1 = (byte) _data[_ip + 1]; - int b2 = _data[_ip + 2]; - int b3 = _data[_ip + 3]; - int b4 = _data[_ip + 4]; - _ip += 5; - return new Float((b1 << 8 | b2) + ((b3 << 8 | b4) / 65536.0)); - } else { - return null; - } - } - - public int nextByte() { - return _data[_ip++]; - } - - public boolean moreBytes() { - return _ip < _offset + _length; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - resetIP(); - while (moreBytes()) { - disassemble(sb); - sb.append("\n"); - } - return sb.toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/ClassDef.java b/src/net/java/dev/typecast/ot/table/ClassDef.java deleted file mode 100644 index 9fa45c3c6..000000000 --- a/src/net/java/dev/typecast/ot/table/ClassDef.java +++ /dev/null @@ -1,33 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.IOException; -import java.io.RandomAccessFile; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ClassDef.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ - */ -public abstract class ClassDef { - - public abstract int getFormat(); - - protected static ClassDef read(RandomAccessFile raf) throws IOException { - ClassDef c = null; - int format = raf.readUnsignedShort(); - if (format == 1) { - c = new ClassDefFormat1(raf); - } else if (format == 2) { - c = new ClassDefFormat2(raf); - } - return c; - } -} diff --git a/src/net/java/dev/typecast/ot/table/ClassDefFormat1.java b/src/net/java/dev/typecast/ot/table/ClassDefFormat1.java deleted file mode 100644 index 07b85ddf9..000000000 --- a/src/net/java/dev/typecast/ot/table/ClassDefFormat1.java +++ /dev/null @@ -1,39 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.IOException; -import java.io.RandomAccessFile; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ClassDefFormat1.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ - */ -public class ClassDefFormat1 extends ClassDef { - - private int startGlyph; - private int glyphCount; - private int[] classValues; - - /** Creates new ClassDefFormat1 */ - public ClassDefFormat1(RandomAccessFile raf) throws IOException { - startGlyph = raf.readUnsignedShort(); - glyphCount = raf.readUnsignedShort(); - classValues = new int[glyphCount]; - for (int i = 0; i < glyphCount; i++) { - classValues[i] = raf.readUnsignedShort(); - } - } - - public int getFormat() { - return 1; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/ClassDefFormat2.java b/src/net/java/dev/typecast/ot/table/ClassDefFormat2.java deleted file mode 100644 index f8b883c41..000000000 --- a/src/net/java/dev/typecast/ot/table/ClassDefFormat2.java +++ /dev/null @@ -1,37 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.IOException; -import java.io.RandomAccessFile; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ClassDefFormat2.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ - */ -public class ClassDefFormat2 extends ClassDef { - - private int classRangeCount; - private RangeRecord[] classRangeRecords; - - /** Creates new ClassDefFormat2 */ - public ClassDefFormat2(RandomAccessFile raf) throws IOException { - classRangeCount = raf.readUnsignedShort(); - classRangeRecords = new RangeRecord[classRangeCount]; - for (int i = 0; i < classRangeCount; i++) { - classRangeRecords[i] = new RangeRecord(raf); - } - } - - public int getFormat() { - return 2; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat.java b/src/net/java/dev/typecast/ot/table/CmapFormat.java deleted file mode 100644 index be88af1e6..000000000 --- a/src/net/java/dev/typecast/ot/table/CmapFormat.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: CmapFormat.java,v 1.3 2004-12-21 16:56:35 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public abstract class CmapFormat { - - public class Range { - - private int _startCode; - private int _endCode; - - protected Range(int startCode, int endCode) { - _startCode = startCode; - _endCode = endCode; - } - - public int getStartCode() { - return _startCode; - } - - public int getEndCode() { - return _endCode; - } - } - - protected int _format; - protected int _length; - protected int _language; - - protected CmapFormat(DataInput di) throws IOException { - _length = di.readUnsignedShort(); - _language = di.readUnsignedShort(); - } - - protected static CmapFormat create(int format, DataInput di) - throws IOException { - switch(format) { - case 0: - return new CmapFormat0(di); - case 2: - return new CmapFormat2(di); - case 4: - return new CmapFormat4(di); - case 6: - return new CmapFormat6(di); - default: - return new CmapFormatUnknown(format, di); - } - } - - public int getFormat() { - return _format; - } - - public int getLength() { - return _length; - } - - public int getLanguage() { - return _language; - } - - public abstract int getRangeCount(); - - public abstract Range getRange(int index) - throws ArrayIndexOutOfBoundsException; - - public abstract int mapCharCode(int charCode); - - public String toString() { - return new StringBuffer() - .append("format: ") - .append(_format) - .append(", length: ") - .append(_length) - .append(", language: ") - .append(_language).toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat0.java b/src/net/java/dev/typecast/ot/table/CmapFormat0.java deleted file mode 100644 index 80f42b227..000000000 --- a/src/net/java/dev/typecast/ot/table/CmapFormat0.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * Simple Macintosh cmap table, mapping only the ASCII character set to glyphs. - * - * @version $Id: CmapFormat0.java,v 1.2 2004-12-21 10:22:55 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CmapFormat0 extends CmapFormat { - - private int[] _glyphIdArray = new int[256]; - - protected CmapFormat0(DataInput di) throws IOException { - super(di); - _format = 0; - for (int i = 0; i < 256; i++) { - _glyphIdArray[i] = di.readUnsignedByte(); - } - } - - public int getRangeCount() { - return 1; - } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { - if (index != 0) { - throw new ArrayIndexOutOfBoundsException(); - } - return new Range(0, 255); - } - - public int mapCharCode(int charCode) { - if (0 <= charCode && charCode < 256) { - return _glyphIdArray[charCode]; - } else { - return 0; - } - } -} diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat2.java b/src/net/java/dev/typecast/ot/table/CmapFormat2.java deleted file mode 100644 index 4eeaf420a..000000000 --- a/src/net/java/dev/typecast/ot/table/CmapFormat2.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * High-byte mapping through table cmap format. - * @version $Id: CmapFormat2.java,v 1.3 2004-12-21 16:56:54 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CmapFormat2 extends CmapFormat { - - private class SubHeader { - int _firstCode; - int _entryCount; - short _idDelta; - int _idRangeOffset; - int _arrayIndex; - } - - private int[] _subHeaderKeys = new int[256]; - private SubHeader[] _subHeaders; - private int[] _glyphIndexArray; - - protected CmapFormat2(DataInput di) throws IOException { - super(di); - _format = 2; - - int pos = 6; - - // Read the subheader keys, noting the highest value, as this will - // determine the number of subheaders to read. - int highest = 0; - for (int i = 0; i < 256; ++i) { - _subHeaderKeys[i] = di.readUnsignedShort(); - highest = Math.max(highest, _subHeaderKeys[i]); - pos += 2; - } - int subHeaderCount = highest / 8 + 1; - _subHeaders = new SubHeader[subHeaderCount]; - - // Read the subheaders, once again noting the highest glyphIndexArray - // index range. - int indexArrayOffset = 8 * subHeaderCount + 518; - highest = 0; - for (int i = 0; i < _subHeaders.length; ++i) { - SubHeader sh = new SubHeader(); - sh._firstCode = di.readUnsignedShort(); - sh._entryCount = di.readUnsignedShort(); - sh._idDelta = di.readShort(); - sh._idRangeOffset = di.readUnsignedShort(); - - // Calculate the offset into the _glyphIndexArray - pos += 8; - sh._arrayIndex = - (pos - 2 + sh._idRangeOffset - indexArrayOffset) / 2; - - // What is the highest range within the glyphIndexArray? - highest = Math.max(highest, sh._arrayIndex + sh._entryCount); - - _subHeaders[i] = sh; - } - - // Read the glyphIndexArray - _glyphIndexArray = new int[highest]; - for (int i = 0; i < _glyphIndexArray.length; ++i) { - _glyphIndexArray[i] = di.readUnsignedShort(); - } - } - - public int getRangeCount() { - return _subHeaders.length; - } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { - if (index < 0 || index >= _subHeaders.length) { - throw new ArrayIndexOutOfBoundsException(); - } - - // Find the high-byte (if any) - int highByte = 0; - if (index != 0) { - for (int i = 0; i < 256; ++i) { - if (_subHeaderKeys[i] / 8 == index) { - highByte = i << 8; - break; - } - } - } - - return new Range( - highByte | _subHeaders[index]._firstCode, - highByte | (_subHeaders[index]._firstCode + - _subHeaders[index]._entryCount - 1)); - } - - public int mapCharCode(int charCode) { - - // Get the appropriate subheader - int index = 0; - int highByte = charCode >> 8; - if (highByte != 0) { - index = _subHeaderKeys[highByte] / 8; - } - SubHeader sh = _subHeaders[index]; - - // Is the charCode out-of-range? - int lowByte = charCode & 0xff; - if (lowByte < sh._firstCode || - lowByte >= (sh._firstCode + sh._entryCount)) { - return 0; - } - - // Now calculate the glyph index - int glyphIndex = - _glyphIndexArray[sh._arrayIndex + (lowByte - sh._firstCode)]; - if (glyphIndex != 0) { - glyphIndex += sh._idDelta; - glyphIndex %= 65536; - } - return glyphIndex; - } -} diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat4.java b/src/net/java/dev/typecast/ot/table/CmapFormat4.java deleted file mode 100644 index 3748a8f84..000000000 --- a/src/net/java/dev/typecast/ot/table/CmapFormat4.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: CmapFormat4.java,v 1.3 2004-12-21 16:57:23 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CmapFormat4 extends CmapFormat { - - private int _segCountX2; - private int _searchRange; - private int _entrySelector; - private int _rangeShift; - private int[] _endCode; - private int[] _startCode; - private int[] _idDelta; - private int[] _idRangeOffset; - private int[] _glyphIdArray; - private int _segCount; - - protected CmapFormat4(DataInput di) throws IOException { - super(di); // 6 - _format = 4; - _segCountX2 = di.readUnsignedShort(); // +2 (8) - _segCount = _segCountX2 / 2; - _endCode = new int[_segCount]; - _startCode = new int[_segCount]; - _idDelta = new int[_segCount]; - _idRangeOffset = new int[_segCount]; - _searchRange = di.readUnsignedShort(); // +2 (10) - _entrySelector = di.readUnsignedShort(); // +2 (12) - _rangeShift = di.readUnsignedShort(); // +2 (14) - for (int i = 0; i < _segCount; i++) { - _endCode[i] = di.readUnsignedShort(); - } // + 2*segCount (2*segCount + 14) - di.readUnsignedShort(); // reservePad +2 (2*segCount + 16) - for (int i = 0; i < _segCount; i++) { - _startCode[i] = di.readUnsignedShort(); - } // + 2*segCount (4*segCount + 16) - for (int i = 0; i < _segCount; i++) { - _idDelta[i] = di.readUnsignedShort(); - } // + 2*segCount (6*segCount + 16) - for (int i = 0; i < _segCount; i++) { - _idRangeOffset[i] = di.readUnsignedShort(); - } // + 2*segCount (8*segCount + 16) - - // Whatever remains of this header belongs in glyphIdArray - int count = (_length - (8*_segCount + 16)) / 2; - _glyphIdArray = new int[count]; - for (int i = 0; i < count; i++) { - _glyphIdArray[i] = di.readUnsignedShort(); - } // + 2*count (8*segCount + 2*count + 18) - - // Are there any padding bytes we need to consume? -// int leftover = length - (8*segCount + 2*count + 18); -// if (leftover > 0) { -// di.skipBytes(leftover); -// } - } - - public int getRangeCount() { - return _segCount; - } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { - if (index < 0 || index >= _segCount) { - throw new ArrayIndexOutOfBoundsException(); - } - return new Range(_startCode[index], _endCode[index]); - } - - public int mapCharCode(int charCode) { - try { - for (int i = 0; i < _segCount; i++) { - if (_endCode[i] >= charCode) { - if (_startCode[i] <= charCode) { - if (_idRangeOffset[i] > 0) { - return _glyphIdArray[_idRangeOffset[i]/2 + (charCode - _startCode[i]) - (_segCount - i)]; - } else { - return (_idDelta[i] + charCode) % 65536; - } - } else { - break; - } - } - } - } catch (ArrayIndexOutOfBoundsException e) { - System.err.println("error: Array out of bounds - " + e.getMessage()); - } - return 0; - } - - public String toString() { - return new StringBuffer() - .append(super.toString()) - .append(", segCountX2: ") - .append(_segCountX2) - .append(", searchRange: ") - .append(_searchRange) - .append(", entrySelector: ") - .append(_entrySelector) - .append(", rangeShift: ") - .append(_rangeShift) - .append(", endCode: ") - .append(_endCode) - .append(", startCode: ") - .append(_endCode) - .append(", idDelta: ") - .append(_idDelta) - .append(", idRangeOffset: ") - .append(_idRangeOffset).toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat6.java b/src/net/java/dev/typecast/ot/table/CmapFormat6.java deleted file mode 100644 index f9b398aab..000000000 --- a/src/net/java/dev/typecast/ot/table/CmapFormat6.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * TODO: To be implemented - * @version $Id: CmapFormat6.java,v 1.2 2004-12-21 10:22:56 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CmapFormat6 extends CmapFormat { - - private short _firstCode; - private short _entryCount; - private short[] _glyphIdArray; - - protected CmapFormat6(DataInput di) throws IOException { - super(di); - _format = 6; - - // HACK: As this is not yet implemented, we need to skip over the bytes - // we should be consuming - //di.skipBytes(_length - 4); - } - - public int getRangeCount() { - return 0; - } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { - throw new ArrayIndexOutOfBoundsException(); - } - - public int mapCharCode(int charCode) { - return 0; - } -} diff --git a/src/net/java/dev/typecast/ot/table/CmapFormatUnknown.java b/src/net/java/dev/typecast/ot/table/CmapFormatUnknown.java deleted file mode 100644 index 01ca600f1..000000000 --- a/src/net/java/dev/typecast/ot/table/CmapFormatUnknown.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * $Id: CmapFormatUnknown.java,v 1.1 2004-12-21 10:21:23 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * When we encounter a cmap format we don't understand, we can use this class - * to hold the bare minimum information about it. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: CmapFormatUnknown.java,v 1.1 2004-12-21 10:21:23 davidsch Exp $ - */ -public class CmapFormatUnknown extends CmapFormat { - - /** Creates a new instance of CmapFormatUnknown */ - protected CmapFormatUnknown(int format, DataInput di) throws IOException { - super(di); - _format = format; - - // We don't know how to handle this data, so we'll just skip over it - di.skipBytes(_length - 4); - } - - public int getRangeCount() { - return 0; - } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { - throw new ArrayIndexOutOfBoundsException(); - } - - public int mapCharCode(int charCode) { - return 0; - } -} diff --git a/src/net/java/dev/typecast/ot/table/CmapIndexEntry.java b/src/net/java/dev/typecast/ot/table/CmapIndexEntry.java deleted file mode 100644 index c82e270fb..000000000 --- a/src/net/java/dev/typecast/ot/table/CmapIndexEntry.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: CmapIndexEntry.java,v 1.2 2004-12-21 10:22:56 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CmapIndexEntry implements Comparable { - - private int _platformId; - private int _encodingId; - private int _offset; - private CmapFormat _format; - - protected CmapIndexEntry(DataInput di) throws IOException { - _platformId = di.readUnsignedShort(); - _encodingId = di.readUnsignedShort(); - _offset = di.readInt(); - } - - public int getPlatformId() { - return _platformId; - } - - public int getEncodingId() { - return _encodingId; - } - - public int getOffset() { - return _offset; - } - - public CmapFormat getFormat() { - return _format; - } - - public void setFormat(CmapFormat format) { - _format = format; - } - - public String toString() { - return new StringBuffer() - .append("platform id: ") - .append(_platformId) - .append(" (") - .append(ID.getPlatformName((short) _platformId)) - .append("), encoding id: ") - .append(_encodingId) - .append(" (") - .append(ID.getEncodingName((short) _platformId, (short) _encodingId)) - .append("), offset: ") - .append(_offset).toString(); - } - - public int compareTo(java.lang.Object obj) { - CmapIndexEntry entry = (CmapIndexEntry) obj; - if (getOffset() < entry.getOffset()) { - return -1; - } else if (getOffset() > entry.getOffset()) { - return 1; - } else { - return 0; - } - } -} diff --git a/src/net/java/dev/typecast/ot/table/CmapTable.java b/src/net/java/dev/typecast/ot/table/CmapTable.java deleted file mode 100644 index de69cc1f0..000000000 --- a/src/net/java/dev/typecast/ot/table/CmapTable.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -import java.util.Arrays; - -/** - * @version $Id: CmapTable.java,v 1.3 2004-12-21 10:22:56 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CmapTable implements Table { - - private DirectoryEntry _de; - private int _version; - private int _numTables; - private CmapIndexEntry[] _entries; - - protected CmapTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); - _version = di.readUnsignedShort(); - _numTables = di.readUnsignedShort(); - long bytesRead = 4; - _entries = new CmapIndexEntry[_numTables]; - - // Get each of the index entries - for (int i = 0; i < _numTables; i++) { - _entries[i] = new CmapIndexEntry(di); - bytesRead += 8; - } - - // Sort into their order of offset - Arrays.sort(_entries); - - // Get each of the tables - int lastOffset = 0; - CmapFormat lastFormat = null; - for (int i = 0; i < _numTables; i++) { - if (_entries[i].getOffset() == lastOffset) { - - // This is a multiple entry - _entries[i].setFormat(lastFormat); - continue; - } else if (_entries[i].getOffset() > bytesRead) { - di.skipBytes(_entries[i].getOffset() - (int) bytesRead); - } else if (_entries[i].getOffset() != bytesRead) { - - // Something is amiss - throw new IOException(); - } - int formatType = di.readUnsignedShort(); - lastFormat = CmapFormat.create(formatType, di); - lastOffset = _entries[i].getOffset(); - _entries[i].setFormat(lastFormat); - bytesRead += lastFormat.getLength(); - } - } - - public int getVersion() { - return _version; - } - - public int getNumTables() { - return _numTables; - } - - public CmapIndexEntry getCmapIndexEntry(int i) { - return _entries[i]; - } - - public CmapFormat getCmapFormat(short platformId, short encodingId) { - - // Find the requested format - for (int i = 0; i < _numTables; i++) { - if (_entries[i].getPlatformId() == platformId - && _entries[i].getEncodingId() == encodingId) { - return _entries[i].getFormat(); - } - } - return null; - } - - public int getType() { - return cmap; - } - - public String toString() { - StringBuffer sb = new StringBuffer().append("cmap\n"); - - // Get each of the index entries - for (int i = 0; i < _numTables; i++) { - sb.append("\t").append(_entries[i].toString()).append("\n"); - } - - // Get each of the tables -// for (int i = 0; i < numTables; i++) { -// sb.append("\t").append(formats[i].toString()).append("\n"); -// } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/Coverage.java b/src/net/java/dev/typecast/ot/table/Coverage.java deleted file mode 100644 index 3c6cf0409..000000000 --- a/src/net/java/dev/typecast/ot/table/Coverage.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Coverage.java,v 1.3 2007-01-24 09:43:30 davidsch Exp $ - */ -public abstract class Coverage { - - public abstract int getFormat(); - - /** - * @param glyphId The ID of the glyph to find. - * @return The index of the glyph within the coverage, or -1 if the glyph - * can't be found. - */ - public abstract int findGlyph(int glyphId); - - protected static Coverage read(DataInput di) throws IOException { - Coverage c = null; - int format = di.readUnsignedShort(); - if (format == 1) { - c = new CoverageFormat1(di); - } else if (format == 2) { - c = new CoverageFormat2(di); - } - return c; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/CoverageFormat1.java b/src/net/java/dev/typecast/ot/table/CoverageFormat1.java deleted file mode 100644 index a81eb0f1e..000000000 --- a/src/net/java/dev/typecast/ot/table/CoverageFormat1.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: CoverageFormat1.java,v 1.2 2007-01-24 09:43:30 davidsch Exp $ - */ -public class CoverageFormat1 extends Coverage { - - private int _glyphCount; - private int[] _glyphIds; - - /** Creates new CoverageFormat1 */ - protected CoverageFormat1(DataInput di) throws IOException { - _glyphCount = di.readUnsignedShort(); - _glyphIds = new int[_glyphCount]; - for (int i = 0; i < _glyphCount; i++) { - _glyphIds[i] = di.readUnsignedShort(); - } - } - - public int getFormat() { - return 1; - } - - public int findGlyph(int glyphId) { - for (int i = 0; i < _glyphCount; i++) { - if (_glyphIds[i] == glyphId) { - return i; - } - } - return -1; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/CoverageFormat2.java b/src/net/java/dev/typecast/ot/table/CoverageFormat2.java deleted file mode 100644 index a30489647..000000000 --- a/src/net/java/dev/typecast/ot/table/CoverageFormat2.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: CoverageFormat2.java,v 1.2 2007-01-24 09:43:30 davidsch Exp $ - */ -public class CoverageFormat2 extends Coverage { - - private int _rangeCount; - private RangeRecord[] _rangeRecords; - - /** Creates new CoverageFormat2 */ - protected CoverageFormat2(DataInput di) throws IOException { - _rangeCount = di.readUnsignedShort(); - _rangeRecords = new RangeRecord[_rangeCount]; - for (int i = 0; i < _rangeCount; i++) { - _rangeRecords[i] = new RangeRecord(di); - } - } - - public int getFormat() { - return 2; - } - - public int findGlyph(int glyphId) { - for (int i = 0; i < _rangeCount; i++) { - int n = _rangeRecords[i].getCoverageIndex(glyphId); - if (n > -1) { - return n; - } - } - return -1; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/CvtTable.java b/src/net/java/dev/typecast/ot/table/CvtTable.java deleted file mode 100644 index 44dc0af41..000000000 --- a/src/net/java/dev/typecast/ot/table/CvtTable.java +++ /dev/null @@ -1,61 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: CvtTable.java,v 1.1.1.1 2004-12-05 23:14:36 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class CvtTable implements Table { - - private DirectoryEntry de; - private short[] values; - - protected CvtTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - int len = de.getLength() / 2; - values = new short[len]; - for (int i = 0; i < len; i++) { - values[i] = di.readShort(); - } - } - - public int getType() { - return cvt; - } - - public short[] getValues() { - return values; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'cvt ' Table - Control Value Table\n----------------------------------\n"); - sb.append("Size = ").append(0).append(" bytes, ").append(values.length).append(" entries\n"); - sb.append(" Values\n ------\n"); - for (int i = 0; i < values.length; i++) { - sb.append(" ").append(i).append(": ").append(values[i]).append("\n"); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/Device.java b/src/net/java/dev/typecast/ot/table/Device.java deleted file mode 100644 index 75c302acd..000000000 --- a/src/net/java/dev/typecast/ot/table/Device.java +++ /dev/null @@ -1,50 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.IOException; -import java.io.RandomAccessFile; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Device.java,v 1.1.1.1 2004-12-05 23:14:37 davidsch Exp $ - */ -public class Device extends Object { - - private int startSize; - private int endSize; - private int deltaFormat; - private int[] deltaValues; - - /** Creates new Device */ - public Device(RandomAccessFile raf) throws IOException { - startSize = raf.readUnsignedShort(); - endSize = raf.readUnsignedShort(); - deltaFormat = raf.readUnsignedShort(); - int size = startSize - endSize; - switch (deltaFormat) { - case 1: - size = (size % 8 == 0) ? size / 8 : size / 8 + 1; - break; - case 2: - size = (size % 4 == 0) ? size / 4 : size / 4 + 1; - break; - case 3: - size = (size % 2 == 0) ? size / 2 : size / 2 + 1; - break; - } - deltaValues = new int[size]; - for (int i = 0; i < size; i++) { - deltaValues[i] = raf.readUnsignedShort(); - } - } - - -} diff --git a/src/net/java/dev/typecast/ot/table/DirectoryEntry.java b/src/net/java/dev/typecast/ot/table/DirectoryEntry.java deleted file mode 100644 index c0f2f9bc1..000000000 --- a/src/net/java/dev/typecast/ot/table/DirectoryEntry.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: DirectoryEntry.java,v 1.2 2004-12-09 23:46:21 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class DirectoryEntry implements Cloneable { - - private int _tag; - private int _checksum; - private int _offset; - private int _length; - - protected DirectoryEntry(DataInput di) throws IOException { - _tag = di.readInt(); - _checksum = di.readInt(); - _offset = di.readInt(); - _length = di.readInt(); - } - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - return null; - } - } - - public int getChecksum() { - return _checksum; - } - - public int getLength() { - return _length; - } - - public int getOffset() { - return _offset; - } - - public int getTag() { - return _tag; - } - - public String getTagAsString() { - return new StringBuffer() - .append((char)((_tag>>24)&0xff)) - .append((char)((_tag>>16)&0xff)) - .append((char)((_tag>>8)&0xff)) - .append((char)((_tag)&0xff)) - .toString(); - } - - public String toString() { - return new StringBuffer() - .append("'").append(getTagAsString()) - .append("' - chksm = 0x").append(Integer.toHexString(_checksum)) - .append(", off = 0x").append(Integer.toHexString(_offset)) - .append(", len = ").append(_length) - .toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/DsigEntry.java b/src/net/java/dev/typecast/ot/table/DsigEntry.java deleted file mode 100644 index 6ce41ec48..000000000 --- a/src/net/java/dev/typecast/ot/table/DsigEntry.java +++ /dev/null @@ -1,43 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.IOException; -import java.io.DataInput; - -/** - * - * @version $Id: DsigEntry.java,v 1.1.1.1 2004-12-05 23:14:37 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class DsigEntry { - - private int format; - private int length; - private int offset; - - /** Creates new DsigEntry */ - protected DsigEntry(DataInput di) throws IOException { - format = di.readInt(); - length = di.readInt(); - offset = di.readInt(); - } - - public int getFormat() { - return format; - } - - public int getLength() { - return length; - } - - public int getOffset() { - return offset; - } -} diff --git a/src/net/java/dev/typecast/ot/table/DsigTable.java b/src/net/java/dev/typecast/ot/table/DsigTable.java deleted file mode 100644 index 8d63800d4..000000000 --- a/src/net/java/dev/typecast/ot/table/DsigTable.java +++ /dev/null @@ -1,69 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.IOException; -import java.io.DataInput; - -/** - * - * @version $Id: DsigTable.java,v 1.1.1.1 2004-12-05 23:14:37 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class DsigTable implements Table { - - private DirectoryEntry de; - private int version; - private int numSigs; - private int flag; - private DsigEntry[] dsigEntry; - private SignatureBlock[] sigBlocks; - - /** Creates new DsigTable */ - protected DsigTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - version = di.readInt(); - numSigs = di.readUnsignedShort(); - flag = di.readUnsignedShort(); - dsigEntry = new DsigEntry[numSigs]; - sigBlocks = new SignatureBlock[numSigs]; - for (int i = 0; i < numSigs; i++) { - dsigEntry[i] = new DsigEntry(di); - } - for (int i = 0; i < numSigs; i++) { - sigBlocks[i] = new SignatureBlock(di); - } - } - - /** - * Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return DSIG; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - - public String toString() { - StringBuffer sb = new StringBuffer().append("DSIG\n"); - for (int i = 0; i < numSigs; i++) { - sb.append(sigBlocks[i].toString()); - } - return sb.toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/Feature.java b/src/net/java/dev/typecast/ot/table/Feature.java deleted file mode 100644 index 34adf4662..000000000 --- a/src/net/java/dev/typecast/ot/table/Feature.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Feature.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ - */ -public class Feature { - - private int _featureParams; - private int _lookupCount; - private int[] _lookupListIndex; - - /** Creates new Feature */ - protected Feature(DataInput di) throws IOException { - _featureParams = di.readUnsignedShort(); - _lookupCount = di.readUnsignedShort(); - _lookupListIndex = new int[_lookupCount]; - for (int i = 0; i < _lookupCount; i++) { - _lookupListIndex[i] = di.readUnsignedShort(); - } - } - - public int getLookupCount() { - return _lookupCount; - } - - public int getLookupListIndex(int i) { - return _lookupListIndex[i]; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/FeatureList.java b/src/net/java/dev/typecast/ot/table/FeatureList.java deleted file mode 100644 index 8f17c461f..000000000 --- a/src/net/java/dev/typecast/ot/table/FeatureList.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: FeatureList.java,v 1.3 2007-01-24 09:54:44 davidsch Exp $ - */ -public class FeatureList { - - private int _featureCount; - private FeatureRecord[] _featureRecords; - private Feature[] _features; - - /** Creates new FeatureList */ - public FeatureList(DataInputStream dis, int offset) throws IOException { - - // Ensure we're in the right place - dis.reset(); - dis.skipBytes(offset); - - // Start reading - _featureCount = dis.readUnsignedShort(); - _featureRecords = new FeatureRecord[_featureCount]; - _features = new Feature[_featureCount]; - for (int i = 0; i < _featureCount; i++) { - _featureRecords[i] = new FeatureRecord(dis); - } - for (int i = 0; i < _featureCount; i++) { - dis.reset(); - dis.skipBytes(offset + _featureRecords[i].getOffset()); - _features[i] = new Feature(dis); - } - } - - public int getFeatureCount() { - return _featureCount; - } - - public FeatureRecord getFeatureRecord(int i) { - return _featureRecords[i]; - } - - public Feature getFeature(int i) { - return _features[i]; - } - - public Feature findFeature(LangSys langSys, String tag) { - if (tag.length() != 4) { - return null; - } - int tagVal = ((tag.charAt(0)<<24) - | (tag.charAt(1)<<16) - | (tag.charAt(2)<<8) - | tag.charAt(3)); - for (int i = 0; i < _featureCount; i++) { - if (_featureRecords[i].getTag() == tagVal) { - if (langSys.isFeatureIndexed(i)) { - return _features[i]; - } - } - } - return null; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/FeatureRecord.java b/src/net/java/dev/typecast/ot/table/FeatureRecord.java deleted file mode 100644 index 7c2788892..000000000 --- a/src/net/java/dev/typecast/ot/table/FeatureRecord.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: FeatureRecord.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ - */ -public class FeatureRecord { - - private int _tag; - private int _offset; - - /** Creates new FeatureRecord */ - protected FeatureRecord(DataInput di) throws IOException { - _tag = di.readInt(); - _offset = di.readUnsignedShort(); - } - - public int getTag() { - return _tag; - } - - public int getOffset() { - return _offset; - } - - public String getTagAsString() { - return new StringBuffer() - .append((char)((_tag>>24)&0xff)) - .append((char)((_tag>>16)&0xff)) - .append((char)((_tag>>8)&0xff)) - .append((char)((_tag)&0xff)) - .toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/FeatureTags.java b/src/net/java/dev/typecast/ot/table/FeatureTags.java deleted file mode 100644 index 8d573d0c6..000000000 --- a/src/net/java/dev/typecast/ot/table/FeatureTags.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -/** - * Definition of Feature tags - * - * @version $Id: FeatureTags.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ - * @author <a href="mailto:[email protected]">Vincent Hardy</a> - */ -public interface FeatureTags { - public static final String FEATURE_TAG_INIT = "init"; - public static final String FEATURE_TAG_MEDI = "medi"; - public static final String FEATURE_TAG_FINA = "fina"; -} diff --git a/src/net/java/dev/typecast/ot/table/FpgmTable.java b/src/net/java/dev/typecast/ot/table/FpgmTable.java deleted file mode 100644 index 37a2ae045..000000000 --- a/src/net/java/dev/typecast/ot/table/FpgmTable.java +++ /dev/null @@ -1,46 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; -import net.java.dev.typecast.ot.Disassembler; - -/** - * @version $Id: FpgmTable.java,v 1.1.1.1 2004-12-05 23:14:38 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class FpgmTable extends Program implements Table { - - private DirectoryEntry de; - - protected FpgmTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - readInstructions(di, de.getLength()); - } - - public int getType() { - return fpgm; - } - - public String toString() { - return Disassembler.disassemble(getInstructions(), 0); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/GaspRange.java b/src/net/java/dev/typecast/ot/table/GaspRange.java deleted file mode 100644 index 9f343e942..000000000 --- a/src/net/java/dev/typecast/ot/table/GaspRange.java +++ /dev/null @@ -1,45 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GaspRange.java,v 1.1.1.1 2004-12-05 23:14:38 davidsch Exp $ - */ -public class GaspRange { - - public static final int GASP_GRIDFIT = 1; - public static final int GASP_DOGRAY = 2; - - private int rangeMaxPPEM; - private int rangeGaspBehavior; - - /** Creates new GaspRange */ - protected GaspRange(DataInput di) throws IOException { - rangeMaxPPEM = di.readUnsignedShort(); - rangeGaspBehavior = di.readUnsignedShort(); - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(" rangeMaxPPEM: ").append(rangeMaxPPEM) - .append("\n rangeGaspBehavior: 0x").append(rangeGaspBehavior); - if ((rangeGaspBehavior & GASP_GRIDFIT) != 0) { - sb.append("- GASP_GRIDFIT "); - } - if ((rangeGaspBehavior & GASP_DOGRAY) != 0) { - sb.append("- GASP_DOGRAY"); - } - return sb.toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/GaspTable.java b/src/net/java/dev/typecast/ot/table/GaspTable.java deleted file mode 100644 index 50a1bcd93..000000000 --- a/src/net/java/dev/typecast/ot/table/GaspTable.java +++ /dev/null @@ -1,63 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GaspTable.java,v 1.1.1.1 2004-12-05 23:14:39 davidsch Exp $ - */ -public class GaspTable implements Table { - - private DirectoryEntry de; - private int version; - private int numRanges; - private GaspRange[] gaspRange; - - /** Creates new GaspTable */ - protected GaspTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - version = di.readUnsignedShort(); - numRanges = di.readUnsignedShort(); - gaspRange = new GaspRange[numRanges]; - for (int i = 0; i < numRanges; i++) { - gaspRange[i] = new GaspRange(di); - } - } - - public int getType() { - return gasp; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'gasp' Table - Grid-fitting And Scan-conversion Procedure\n---------------------------------------------------------"); - sb.append("\n 'gasp' version: ").append(version); - sb.append("\n numRanges: ").append(numRanges); - for (int i = 0; i < numRanges; i++) { - sb.append("\n\n gasp Range ").append(i).append("\n"); - sb.append(gaspRange[i].toString()); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/GlyfCompositeComp.java b/src/net/java/dev/typecast/ot/table/GlyfCompositeComp.java deleted file mode 100644 index 0a3f91a2a..000000000 --- a/src/net/java/dev/typecast/ot/table/GlyfCompositeComp.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: GlyfCompositeComp.java,v 1.3 2010-08-10 11:41:55 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class GlyfCompositeComp { - - public static final short ARG_1_AND_2_ARE_WORDS = 0x0001; - public static final short ARGS_ARE_XY_VALUES = 0x0002; - public static final short ROUND_XY_TO_GRID = 0x0004; - public static final short WE_HAVE_A_SCALE = 0x0008; - public static final short MORE_COMPONENTS = 0x0020; - public static final short WE_HAVE_AN_X_AND_Y_SCALE = 0x0040; - public static final short WE_HAVE_A_TWO_BY_TWO = 0x0080; - public static final short WE_HAVE_INSTRUCTIONS = 0x0100; - public static final short USE_MY_METRICS = 0x0200; - - private int _firstIndex; - private int _firstContour; - private short _argument1; - private short _argument2; - private int _flags; - private int _glyphIndex; - private double _xscale = 1.0; - private double _yscale = 1.0; - private double _scale01 = 0.0; - private double _scale10 = 0.0; - private int _xtranslate = 0; - private int _ytranslate = 0; - private int _point1 = 0; - private int _point2 = 0; - - protected GlyfCompositeComp(int firstIndex, int firstContour, DataInput di) - throws IOException { - _firstIndex = firstIndex; - _firstContour = firstContour; - _flags = di.readUnsignedShort(); - _glyphIndex = di.readUnsignedShort(); - - // Get the arguments as just their raw values - if ((_flags & ARG_1_AND_2_ARE_WORDS) != 0) { - _argument1 = di.readShort(); - _argument2 = di.readShort(); - } else { - _argument1 = (short) di.readByte(); - _argument2 = (short) di.readByte(); - } - - // Assign the arguments according to the flags - if ((_flags & ARGS_ARE_XY_VALUES) != 0) { - _xtranslate = _argument1; - _ytranslate = _argument2; - } else { - _point1 = _argument1; - _point2 = _argument2; - } - - // Get the scale values (if any) - if ((_flags & WE_HAVE_A_SCALE) != 0) { - int i = di.readShort(); - _xscale = _yscale = (double) i / (double) 0x4000; - } else if ((_flags & WE_HAVE_AN_X_AND_Y_SCALE) != 0) { - short i = di.readShort(); - _xscale = (double) i / (double) 0x4000; - i = di.readShort(); - _yscale = (double) i / (double) 0x4000; - } else if ((_flags & WE_HAVE_A_TWO_BY_TWO) != 0) { - int i = di.readShort(); - _xscale = (double) i / (double) 0x4000; - i = di.readShort(); - _scale01 = (double) i / (double) 0x4000; - i = di.readShort(); - _scale10 = (double) i / (double) 0x4000; - i = di.readShort(); - _yscale = (double) i / (double) 0x4000; - } - } - - public int getFirstIndex() { - return _firstIndex; - } - - public int getFirstContour() { - return _firstContour; - } - - public short getArgument1() { - return _argument1; - } - - public short getArgument2() { - return _argument2; - } - - public int getFlags() { - return _flags; - } - - public int getGlyphIndex() { - return _glyphIndex; - } - - public double getScale01() { - return _scale01; - } - - public double getScale10() { - return _scale10; - } - - public double getXScale() { - return _xscale; - } - - public double getYScale() { - return _yscale; - } - - public int getXTranslate() { - return _xtranslate; - } - - public int getYTranslate() { - return _ytranslate; - } - - /** - * Transforms an x-coordinate of a point for this component. - * @param x The x-coordinate of the point to transform - * @param y The y-coordinate of the point to transform - * @return The transformed x-coordinate - */ - public int scaleX(int x, int y) { - return (int)((double) x * _xscale + (double) y * _scale10); - } - - /** - * Transforms a y-coordinate of a point for this component. - * @param x The x-coordinate of the point to transform - * @param y The y-coordinate of the point to transform - * @return The transformed y-coordinate - */ - public int scaleY(int x, int y) { - return (int)((double) x * _scale01 + (double) y * _yscale); - } -} diff --git a/src/net/java/dev/typecast/ot/table/GlyfCompositeDescript.java b/src/net/java/dev/typecast/ot/table/GlyfCompositeDescript.java deleted file mode 100644 index 97c0b0f79..000000000 --- a/src/net/java/dev/typecast/ot/table/GlyfCompositeDescript.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -import java.util.ArrayList; - -/** - * Glyph description for composite glyphs. Composite glyphs are made up of one - * or more simple glyphs, usually with some sort of transformation applied to - * each. - * - * @version $Id: GlyfCompositeDescript.java,v 1.5 2007-01-25 08:43:18 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class GlyfCompositeDescript extends GlyfDescript { - - private ArrayList<GlyfCompositeComp> _components = - new ArrayList<GlyfCompositeComp>(); - - public GlyfCompositeDescript( - GlyfTable parentTable, - int glyphIndex, - DataInput di) throws IOException { - super(parentTable, glyphIndex, (short) -1, di); - - // Get all of the composite components - GlyfCompositeComp comp; - int firstIndex = 0; - int firstContour = 0; - try { - do { - _components.add(comp = new GlyfCompositeComp(firstIndex, firstContour, di)); - GlyfDescript desc = parentTable.getDescription(comp.getGlyphIndex()); - if (desc != null) { - firstIndex += desc.getPointCount(); - firstContour += desc.getContourCount(); - } - } while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0); - - // Are there hinting intructions to read? - if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0) { - readInstructions(di, di.readShort()); - } - } catch (IOException e) { - throw e; -// } catch (Exception e) { -// int foo = 0; - } - } - - public int getEndPtOfContours(int i) { - GlyfCompositeComp c = getCompositeCompEndPt(i); - if (c != null) { - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); - return gd.getEndPtOfContours(i - c.getFirstContour()) + c.getFirstIndex(); - } - return 0; - } - - public byte getFlags(int i) { - GlyfCompositeComp c = getCompositeComp(i); - if (c != null) { - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); - return gd.getFlags(i - c.getFirstIndex()); - } - return 0; - } - - public short getXCoordinate(int i) { - GlyfCompositeComp c = getCompositeComp(i); - if (c != null) { - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); - int n = i - c.getFirstIndex(); - int x = gd.getXCoordinate(n); - int y = gd.getYCoordinate(n); - short x1 = (short) c.scaleX(x, y); - x1 += c.getXTranslate(); - return x1; - } - return 0; - } - - public short getYCoordinate(int i) { - GlyfCompositeComp c = getCompositeComp(i); - if (c != null) { - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); - int n = i - c.getFirstIndex(); - int x = gd.getXCoordinate(n); - int y = gd.getYCoordinate(n); - short y1 = (short) c.scaleY(x, y); - y1 += c.getYTranslate(); - return y1; - } - return 0; - } - - public boolean isComposite() { - return true; - } - - public int getPointCount() { - GlyfCompositeComp c = _components.get(_components.size()-1); - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); - if (gd != null) { - return c.getFirstIndex() + gd.getPointCount(); - } else { - return 0; - } - } - - public int getContourCount() { - GlyfCompositeComp c = _components.get(_components.size()-1); - return c.getFirstContour() + _parentTable.getDescription(c.getGlyphIndex()).getContourCount(); - } - - public int getComponentIndex(int i) { - return _components.get(i).getFirstIndex(); - } - - public int getComponentCount() { - return _components.size(); - } - - public GlyfCompositeComp getComponent(int i) { - return _components.get(i); - } - - protected GlyfCompositeComp getCompositeComp(int i) { - GlyfCompositeComp c; - for (int n = 0; n < _components.size(); n++) { - c = _components.get(n); - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); - if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount())) { - return c; - } - } - return null; - } - - protected GlyfCompositeComp getCompositeCompEndPt(int i) { - GlyfCompositeComp c; - for (int j = 0; j < _components.size(); j++) { - c = _components.get(j); - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); - if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount())) { - return c; - } - } - return null; - } -} diff --git a/src/net/java/dev/typecast/ot/table/GlyfDescript.java b/src/net/java/dev/typecast/ot/table/GlyfDescript.java deleted file mode 100644 index 49ae5b494..000000000 --- a/src/net/java/dev/typecast/ot/table/GlyfDescript.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: GlyfDescript.java,v 1.3 2007-01-24 09:47:48 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public abstract class GlyfDescript extends Program implements GlyphDescription { - - // flags - public static final byte onCurve = 0x01; - public static final byte xShortVector = 0x02; - public static final byte yShortVector = 0x04; - public static final byte repeat = 0x08; - public static final byte xDual = 0x10; - public static final byte yDual = 0x20; - - protected GlyfTable _parentTable; - private int _glyphIndex; - private int _numberOfContours; - private short _xMin; - private short _yMin; - private short _xMax; - private short _yMax; - - protected GlyfDescript( - GlyfTable parentTable, - int glyphIndex, - short numberOfContours, - DataInput di) throws IOException { - _parentTable = parentTable; - _numberOfContours = numberOfContours; - _xMin = di.readShort(); - _yMin = di.readShort(); - _xMax = di.readShort(); - _yMax = di.readShort(); - } - - public int getNumberOfContours() { - return _numberOfContours; - } - - public int getGlyphIndex() { - return _glyphIndex; - } - - public short getXMaximum() { - return _xMax; - } - - public short getXMinimum() { - return _xMin; - } - - public short getYMaximum() { - return _yMax; - } - - public short getYMinimum() { - return _yMin; - } - - public String toString() { - return new StringBuffer() - .append(" numberOfContours: ").append(_numberOfContours) - .append("\n xMin: ").append(_xMin) - .append("\n yMin: ").append(_yMin) - .append("\n xMax: ").append(_xMax) - .append("\n yMax: ").append(_yMax) - .toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/GlyfSimpleDescript.java b/src/net/java/dev/typecast/ot/table/GlyfSimpleDescript.java deleted file mode 100644 index e2c3a2c84..000000000 --- a/src/net/java/dev/typecast/ot/table/GlyfSimpleDescript.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; -import net.java.dev.typecast.ot.Disassembler; - -/** - * @version $Id: GlyfSimpleDescript.java,v 1.3 2007-01-24 09:47:47 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class GlyfSimpleDescript extends GlyfDescript { - - private int[] _endPtsOfContours; - private byte[] _flags; - private short[] _xCoordinates; - private short[] _yCoordinates; - private int _count; - - public GlyfSimpleDescript( - GlyfTable parentTable, - int glyphIndex, - short numberOfContours, - DataInput di) throws IOException { - super(parentTable, glyphIndex, numberOfContours, di); - - // Simple glyph description - _endPtsOfContours = new int[numberOfContours]; - for (int i = 0; i < numberOfContours; i++) { - _endPtsOfContours[i] = di.readShort(); - } - - // The last end point index reveals the total number of points - _count = _endPtsOfContours[numberOfContours-1] + 1; - _flags = new byte[_count]; - _xCoordinates = new short[_count]; - _yCoordinates = new short[_count]; - - int instructionCount = di.readShort(); - readInstructions(di, instructionCount); - readFlags(_count, di); - readCoords(_count, di); - } - - public int getEndPtOfContours(int i) { - return _endPtsOfContours[i]; - } - - public byte getFlags(int i) { - return _flags[i]; - } - - public short getXCoordinate(int i) { - return _xCoordinates[i]; - } - - public short getYCoordinate(int i) { - return _yCoordinates[i]; - } - - public boolean isComposite() { - return false; - } - - public int getPointCount() { - return _count; - } - - public int getContourCount() { - return getNumberOfContours(); - } - /* - public int getComponentIndex(int c) { - return 0; - } - - public int getComponentCount() { - return 1; - } - */ - /** - * The table is stored as relative values, but we'll store them as absolutes - */ - private void readCoords(int count, DataInput di) throws IOException { - short x = 0; - short y = 0; - for (int i = 0; i < count; i++) { - if ((_flags[i] & xDual) != 0) { - if ((_flags[i] & xShortVector) != 0) { - x += (short) di.readUnsignedByte(); - } - } else { - if ((_flags[i] & xShortVector) != 0) { - x += (short) -((short) di.readUnsignedByte()); - } else { - x += di.readShort(); - } - } - _xCoordinates[i] = x; - } - - for (int i = 0; i < count; i++) { - if ((_flags[i] & yDual) != 0) { - if ((_flags[i] & yShortVector) != 0) { - y += (short) di.readUnsignedByte(); - } - } else { - if ((_flags[i] & yShortVector) != 0) { - y += (short) -((short) di.readUnsignedByte()); - } else { - y += di.readShort(); - } - } - _yCoordinates[i] = y; - } - } - - /** - * The flags are run-length encoded - */ - private void readFlags(int flagCount, DataInput di) throws IOException { - try { - for (int index = 0; index < flagCount; index++) { - _flags[index] = di.readByte(); - if ((_flags[index] & repeat) != 0) { - int repeats = di.readByte(); - for (int i = 1; i <= repeats; i++) { - _flags[index + i] = _flags[index]; - } - index += repeats; - } - } - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("error: array index out of bounds"); - } - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(super.toString()); - sb.append("\n\n EndPoints\n ---------"); - for (int i = 0; i < _endPtsOfContours.length; i++) { - sb.append("\n ").append(i).append(": ").append(_endPtsOfContours[i]); - } - sb.append("\n\n Length of Instructions: "); - sb.append(getInstructions().length).append("\n"); - sb.append(Disassembler.disassemble(getInstructions(), 8)); - sb.append("\n Flags\n -----"); - for (int i = 0; i < _flags.length; i++) { - sb.append("\n ").append(i).append(": "); - if ((_flags[i] & 0x20) != 0) { - sb.append("YDual "); - } else { - sb.append(" "); - } - if ((_flags[i] & 0x10) != 0) { - sb.append("XDual "); - } else { - sb.append(" "); - } - if ((_flags[i] & 0x08) != 0) { - sb.append("Repeat "); - } else { - sb.append(" "); - } - if ((_flags[i] & 0x04) != 0) { - sb.append("Y-Short "); - } else { - sb.append(" "); - } - if ((_flags[i] & 0x02) != 0) { - sb.append("X-Short "); - } else { - sb.append(" "); - } - if ((_flags[i] & 0x01) != 0) { - sb.append("On"); - } else { - sb.append(" "); - } - } - sb.append("\n\n Coordinates\n -----------"); - short oldX = 0; - short oldY = 0; - for (int i = 0; i < _xCoordinates.length; i++) { - sb.append("\n ").append(i) - .append(": Rel (").append(_xCoordinates[i] - oldX) - .append(", ").append(_yCoordinates[i] - oldY) - .append(") -> Abs (").append(_xCoordinates[i]) - .append(", ").append(_yCoordinates[i]).append(")"); - oldX = _xCoordinates[i]; - oldY = _yCoordinates[i]; - } - return sb.toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/GlyfTable.java b/src/net/java/dev/typecast/ot/table/GlyfTable.java deleted file mode 100644 index 03f519db2..000000000 --- a/src/net/java/dev/typecast/ot/table/GlyfTable.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.ByteArrayInputStream; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.IOException; - -/** - * @version $Id: GlyfTable.java,v 1.6 2010-08-10 11:46:30 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class GlyfTable implements Table { - - private DirectoryEntry _de; - private GlyfDescript[] _descript; - - protected GlyfTable( - DirectoryEntry de, - DataInput di, - MaxpTable maxp, - LocaTable loca) throws IOException { - _de = (DirectoryEntry) de.clone(); - _descript = new GlyfDescript[maxp.getNumGlyphs()]; - - // Buffer the whole table so we can randomly access it - byte[] buf = new byte[de.getLength()]; - di.readFully(buf); - ByteArrayInputStream bais = new ByteArrayInputStream(buf); - - // Process all the simple glyphs - for (int i = 0; i < maxp.getNumGlyphs(); i++) { - int len = loca.getOffset(i + 1) - loca.getOffset(i); - if (len > 0) { - bais.reset(); - bais.skip(loca.getOffset(i)); - DataInputStream dis = new DataInputStream(bais); - short numberOfContours = dis.readShort(); - if (numberOfContours >= 0) { - _descript[i] = new GlyfSimpleDescript(this, i, numberOfContours, dis); - } - } else { - _descript[i] = null; - } - } - - // Now do all the composite glyphs - for (int i = 0; i < maxp.getNumGlyphs(); i++) { - int len = loca.getOffset(i + 1) - loca.getOffset(i); - if (len > 0) { - bais.reset(); - bais.skip(loca.getOffset(i)); - DataInputStream dis = new DataInputStream(bais); - short numberOfContours = dis.readShort(); - if (numberOfContours < 0) { - _descript[i] = new GlyfCompositeDescript(this, i, dis); - } - } - } - } - - public GlyfDescript getDescription(int i) { - if (i < _descript.length) { - return _descript[i]; - } else { - return null; - } - } - - public int getType() { - return glyf; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/GlyphDescription.java b/src/net/java/dev/typecast/ot/table/GlyphDescription.java deleted file mode 100644 index b23f31364..000000000 --- a/src/net/java/dev/typecast/ot/table/GlyphDescription.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -/** - * Specifies access to glyph description classes, simple and composite. - * @version $Id: GlyphDescription.java,v 1.3 2007-01-24 09:47:45 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public interface GlyphDescription { - - public int getGlyphIndex(); - - public int getEndPtOfContours(int i); - - public byte getFlags(int i); - - public short getXCoordinate(int i); - - public short getYCoordinate(int i); - - public short getXMaximum(); - - public short getXMinimum(); - - public short getYMaximum(); - - public short getYMinimum(); - - public boolean isComposite(); - - public int getPointCount(); - - public int getContourCount(); - - // public int getComponentIndex(int c); - // public int getComponentCount(); -} diff --git a/src/net/java/dev/typecast/ot/table/GposTable.java b/src/net/java/dev/typecast/ot/table/GposTable.java deleted file mode 100644 index 3efeeaa03..000000000 --- a/src/net/java/dev/typecast/ot/table/GposTable.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * $Id: GposTable.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * TODO: To be implemented - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GposTable.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ - */ -public class GposTable implements Table { - - private DirectoryEntry _de; - - protected GposTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); - - // GPOS Header - int version = di.readInt(); - int scriptList = di.readInt(); - int featureList = di.readInt(); - int lookupList = di.readInt(); - } - - /** Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return GPOS; - } - - public String toString() { - return "GPOS"; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/GsubTable.java b/src/net/java/dev/typecast/ot/table/GsubTable.java deleted file mode 100644 index d7f9c355f..000000000 --- a/src/net/java/dev/typecast/ot/table/GsubTable.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.ByteArrayInputStream; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GsubTable.java,v 1.3 2007-01-24 09:47:46 davidsch Exp $ - */ -public class GsubTable implements Table, LookupSubtableFactory { - - private DirectoryEntry _de; - private ScriptList _scriptList; - private FeatureList _featureList; - private LookupList _lookupList; - - protected GsubTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); - - // Load into a temporary buffer, and create another input stream - byte[] buf = new byte[de.getLength()]; - di.readFully(buf); - DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); - - // GSUB Header - int version = dis.readInt(); - int scriptListOffset = dis.readUnsignedShort(); - int featureListOffset = dis.readUnsignedShort(); - int lookupListOffset = dis.readUnsignedShort(); - - // Script List - _scriptList = new ScriptList(dis, scriptListOffset); - - // Feature List - _featureList = new FeatureList(dis, featureListOffset); - - // Lookup List - _lookupList = new LookupList(dis, lookupListOffset, this); - } - - /** - * 1 - Single - Replace one glyph with one glyph - * 2 - Multiple - Replace one glyph with more than one glyph - * 3 - Alternate - Replace one glyph with one of many glyphs - * 4 - Ligature - Replace multiple glyphs with one glyph - * 5 - Context - Replace one or more glyphs in context - * 6 - Chaining - Context Replace one or more glyphs in chained context - */ - public LookupSubtable read( - int type, - DataInputStream dis, - int offset) throws IOException { - LookupSubtable s = null; - switch (type) { - case 1: - s = SingleSubst.read(dis, offset); - break; - case 2: -// s = MultipleSubst.read(dis, offset); - break; - case 3: -// s = AlternateSubst.read(dis, offset); - break; - case 4: - s = LigatureSubst.read(dis, offset); - break; - case 5: -// s = ContextSubst.read(dis, offset); - break; - case 6: -// s = ChainingSubst.read(dis, offset); - break; - } - return s; - } - - /** Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return GSUB; - } - - public ScriptList getScriptList() { - return _scriptList; - } - - public FeatureList getFeatureList() { - return _featureList; - } - - public LookupList getLookupList() { - return _lookupList; - } - - public String toString() { - return "GSUB"; - } - - public static String lookupTypeAsString(int type) { - switch (type) { - case 1: - return "Single"; - case 2: - return "Multiple"; - case 3: - return "Alternate"; - case 4: - return "Ligature"; - case 5: - return "Context"; - case 6: - return "Chaining"; - } - return "Unknown"; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/HdmxTable.java b/src/net/java/dev/typecast/ot/table/HdmxTable.java deleted file mode 100644 index 68a03c590..000000000 --- a/src/net/java/dev/typecast/ot/table/HdmxTable.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * $Id: HdmxTable.java,v 1.2 2007-07-26 11:12:30 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * The Horizontal Device Metrics table for TrueType outlines. This stores - * integer advance widths scaled to specific pixel sizes. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: HdmxTable.java,v 1.2 2007-07-26 11:12:30 davidsch Exp $ - */ -public class HdmxTable implements Table { - - public class DeviceRecord { - - private short _pixelSize; - private short _maxWidth; - private short[] _widths; - - protected DeviceRecord(int numGlyphs, DataInput di) throws IOException { - _pixelSize = di.readByte(); - _maxWidth = di.readByte(); - _widths = new short[numGlyphs]; - for (int i = 0; i < numGlyphs; ++i) { - _widths[i] = di.readByte(); - } - } - - public short getPixelSize() { - return _pixelSize; - } - - public short getMaxWidth() { - return _maxWidth; - } - - public short[] getWidths() { - return _widths; - } - - public short getWidth(int glyphidx) { - return _widths[glyphidx]; - } - - } - - private DirectoryEntry _de; - private int _version; - private short _numRecords; - private int _sizeDeviceRecords; - private DeviceRecord[] _records; - - /** Creates a new instance of HdmxTable */ - protected HdmxTable(DirectoryEntry de, DataInput di, MaxpTable maxp) - throws IOException { - _de = (DirectoryEntry) de.clone(); - _version = di.readUnsignedShort(); - _numRecords = di.readShort(); - _sizeDeviceRecords = di.readInt(); - _records = new DeviceRecord[_numRecords]; - - // Read the device records - for (int i = 0; i < _numRecords; ++i) { - _records[i] = new DeviceRecord(maxp.getNumGlyphs(), di); - } - } - - public int getNumberOfRecords() { - return _numRecords; - } - - public DeviceRecord getRecord(int i) { - return _records[i]; - } - - public int getType() { - return hdmx; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'hdmx' Table - Horizontal Device Metrics\n----------------------------------------\n"); - sb.append("Size = ").append(_de.getLength()).append(" bytes\n") - .append("\t'hdmx' version: ").append(_version).append("\n") - .append("\t# device records: ").append(_numRecords).append("\n") - .append("\tRecord length: ").append(_sizeDeviceRecords).append("\n"); - for (int i = 0; i < _numRecords; ++i) { - sb.append("\tDevRec ").append(i) - .append(": ppem = ").append(_records[i].getPixelSize()) - .append(", maxWid = ").append(_records[i].getMaxWidth()) - .append("\n"); - for (int j = 0; j < _records[i].getWidths().length; ++j) { - sb.append(" ").append(j).append(". ") - .append(_records[i].getWidths()[j]).append("\n"); - } - sb.append("\n\n"); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/HeadTable.java b/src/net/java/dev/typecast/ot/table/HeadTable.java deleted file mode 100644 index c99ae768d..000000000 --- a/src/net/java/dev/typecast/ot/table/HeadTable.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -import net.java.dev.typecast.ot.Fixed; - -/** - * @version $Id: HeadTable.java,v 1.2 2004-12-21 10:23:20 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class HeadTable implements Table { - - private DirectoryEntry _de; - private int _versionNumber; - private int _fontRevision; - private int _checkSumAdjustment; - private int _magicNumber; - private short _flags; - private short _unitsPerEm; - private long _created; - private long _modified; - private short _xMin; - private short _yMin; - private short _xMax; - private short _yMax; - private short _macStyle; - private short _lowestRecPPEM; - private short _fontDirectionHint; - private short _indexToLocFormat; - private short _glyphDataFormat; - - protected HeadTable(DirectoryEntry de, DataInput di) throws IOException { - this._de = (DirectoryEntry) de.clone(); - _versionNumber = di.readInt(); - _fontRevision = di.readInt(); - _checkSumAdjustment = di.readInt(); - _magicNumber = di.readInt(); - _flags = di.readShort(); - _unitsPerEm = di.readShort(); - _created = di.readLong(); - _modified = di.readLong(); - _xMin = di.readShort(); - _yMin = di.readShort(); - _xMax = di.readShort(); - _yMax = di.readShort(); - _macStyle = di.readShort(); - _lowestRecPPEM = di.readShort(); - _fontDirectionHint = di.readShort(); - _indexToLocFormat = di.readShort(); - _glyphDataFormat = di.readShort(); - } - - public int getCheckSumAdjustment() { - return _checkSumAdjustment; - } - - public long getCreated() { - return _created; - } - - public short getFlags() { - return _flags; - } - - public short getFontDirectionHint() { - return _fontDirectionHint; - } - - public int getFontRevision(){ - return _fontRevision; - } - - public short getGlyphDataFormat() { - return _glyphDataFormat; - } - - public short getIndexToLocFormat() { - return _indexToLocFormat; - } - - public short getLowestRecPPEM() { - return _lowestRecPPEM; - } - - public short getMacStyle() { - return _macStyle; - } - - public long getModified() { - return _modified; - } - - public int getType() { - return head; - } - - public short getUnitsPerEm() { - return _unitsPerEm; - } - - public int getVersionNumber() { - return _versionNumber; - } - - public short getXMax() { - return _xMax; - } - - public short getXMin() { - return _xMin; - } - - public short getYMax() { - return _yMax; - } - - public short getYMin() { - return _yMin; - } - - public String toString() { - return new StringBuffer() - .append("'head' Table - Font Header\n--------------------------") - .append("\n 'head' version: ").append(Fixed.floatValue(_versionNumber)) - .append("\n fontRevision: ").append(Fixed.roundedFloatValue(_fontRevision, 8)) - .append("\n checkSumAdjustment: 0x").append(Integer.toHexString(_checkSumAdjustment).toUpperCase()) - .append("\n magicNumber: 0x").append(Integer.toHexString(_magicNumber).toUpperCase()) - .append("\n flags: 0x").append(Integer.toHexString(_flags).toUpperCase()) - .append("\n unitsPerEm: ").append(_unitsPerEm) - .append("\n created: ").append(_created) - .append("\n modified: ").append(_modified) - .append("\n xMin: ").append(_xMin) - .append("\n yMin: ").append(_yMin) - .append("\n xMax: ").append(_xMax) - .append("\n yMax: ").append(_yMax) - .append("\n macStyle bits: ").append(Integer.toHexString(_macStyle).toUpperCase()) - .append("\n lowestRecPPEM: ").append(_lowestRecPPEM) - .append("\n fontDirectionHint: ").append(_fontDirectionHint) - .append("\n indexToLocFormat: ").append(_indexToLocFormat) - .append("\n glyphDataFormat: ").append(_glyphDataFormat) - .toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/HheaTable.java b/src/net/java/dev/typecast/ot/table/HheaTable.java deleted file mode 100644 index 4b49f41be..000000000 --- a/src/net/java/dev/typecast/ot/table/HheaTable.java +++ /dev/null @@ -1,135 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; -import net.java.dev.typecast.ot.Fixed; - -/** - * @version $Id: HheaTable.java,v 1.2 2010-08-10 11:44:02 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class HheaTable implements Table { - - private DirectoryEntry de; - private int version; - private short ascender; - private short descender; - private short lineGap; - private short advanceWidthMax; - private short minLeftSideBearing; - private short minRightSideBearing; - private short xMaxExtent; - private short caretSlopeRise; - private short caretSlopeRun; - private short metricDataFormat; - private int numberOfHMetrics; - - protected HheaTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - version = di.readInt(); - ascender = di.readShort(); - descender = di.readShort(); - lineGap = di.readShort(); - advanceWidthMax = di.readShort(); - minLeftSideBearing = di.readShort(); - minRightSideBearing = di.readShort(); - xMaxExtent = di.readShort(); - caretSlopeRise = di.readShort(); - caretSlopeRun = di.readShort(); - for (int i = 0; i < 5; i++) { - di.readShort(); - } - metricDataFormat = di.readShort(); - numberOfHMetrics = di.readUnsignedShort(); - } - - public short getAdvanceWidthMax() { - return advanceWidthMax; - } - - public short getAscender() { - return ascender; - } - - public short getCaretSlopeRise() { - return caretSlopeRise; - } - - public short getCaretSlopeRun() { - return caretSlopeRun; - } - - public short getDescender() { - return descender; - } - - public short getLineGap() { - return lineGap; - } - - public short getMetricDataFormat() { - return metricDataFormat; - } - - public short getMinLeftSideBearing() { - return minLeftSideBearing; - } - - public short getMinRightSideBearing() { - return minRightSideBearing; - } - - public int getNumberOfHMetrics() { - return numberOfHMetrics; - } - - public int getType() { - return hhea; - } - - public short getXMaxExtent() { - return xMaxExtent; - } - - public String toString() { - return new StringBuffer() - .append("'hhea' Table - Horizontal Header\n--------------------------------") - .append("\n 'hhea' version: ").append(Fixed.floatValue(version)) - .append("\n yAscender: ").append(ascender) - .append("\n yDescender: ").append(descender) - .append("\n yLineGap: ").append(lineGap) - .append("\n advanceWidthMax: ").append(advanceWidthMax) - .append("\n minLeftSideBearing: ").append(minLeftSideBearing) - .append("\n minRightSideBearing: ").append(minRightSideBearing) - .append("\n xMaxExtent: ").append(xMaxExtent) - .append("\n horizCaretSlopeNum: ").append(caretSlopeRise) - .append("\n horizCaretSlopeDenom: ").append(caretSlopeRun) - .append("\n reserved0: 0") - .append("\n reserved1: 0") - .append("\n reserved2: 0") - .append("\n reserved3: 0") - .append("\n reserved4: 0") - .append("\n metricDataFormat: ").append(metricDataFormat) - .append("\n numOf_LongHorMetrics: ").append(numberOfHMetrics) - .toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/HmtxTable.java b/src/net/java/dev/typecast/ot/table/HmtxTable.java deleted file mode 100644 index 7b4cbae40..000000000 --- a/src/net/java/dev/typecast/ot/table/HmtxTable.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: HmtxTable.java,v 1.5 2007-07-26 11:11:48 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class HmtxTable implements Table { - - private DirectoryEntry _de; - private int[] _hMetrics = null; - private short[] _leftSideBearing = null; - - protected HmtxTable( - DirectoryEntry de, - DataInput di, - HheaTable hhea, - MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); - _hMetrics = new int[hhea.getNumberOfHMetrics()]; - for (int i = 0; i < hhea.getNumberOfHMetrics(); ++i) { - _hMetrics[i] = - di.readUnsignedByte()<<24 - | di.readUnsignedByte()<<16 - | di.readUnsignedByte()<<8 - | di.readUnsignedByte(); - } - int lsbCount = maxp.getNumGlyphs() - hhea.getNumberOfHMetrics(); - _leftSideBearing = new short[lsbCount]; - for (int i = 0; i < lsbCount; ++i) { - _leftSideBearing[i] = di.readShort(); - } - } - - public int getAdvanceWidth(int i) { - if (_hMetrics == null) { - return 0; - } - if (i < _hMetrics.length) { - return _hMetrics[i] >> 16; - } else { - return _hMetrics[_hMetrics.length - 1] >> 16; - } - } - - public short getLeftSideBearing(int i) { - if (_hMetrics == null) { - return 0; - } - if (i < _hMetrics.length) { - return (short)(_hMetrics[i] & 0xffff); - } else { - return _leftSideBearing[i - _hMetrics.length]; - } - } - - public int getType() { - return hmtx; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'hmtx' Table - Horizontal Metrics\n---------------------------------\n"); - sb.append("Size = ").append(_de.getLength()).append(" bytes, ") - .append(_hMetrics.length).append(" entries\n"); - for (int i = 0; i < _hMetrics.length; i++) { - sb.append(" ").append(i) - .append(". advWid: ").append(getAdvanceWidth(i)) - .append(", LSdBear: ").append(getLeftSideBearing(i)) - .append("\n"); - } - for (int i = 0; i < _leftSideBearing.length; i++) { - sb.append(" LSdBear ").append(i + _hMetrics.length) - .append(": ").append(_leftSideBearing[i]) - .append("\n"); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/ID.java b/src/net/java/dev/typecast/ot/table/ID.java deleted file mode 100644 index 5dc79d766..000000000 --- a/src/net/java/dev/typecast/ot/table/ID.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * $Id: ID.java,v 1.1.1.1 2004-12-05 23:14:47 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ID.java,v 1.1.1.1 2004-12-05 23:14:47 davidsch Exp $ - */ -public abstract class ID { - - // Platform IDs - public static final short platformUnicode = 0; - public static final short platformMacintosh = 1; - public static final short platformISO = 2; - public static final short platformMicrosoft = 3; - - // Unicode Encoding IDs - public static final short encodingUnicode10Semantics = 0; - public static final short encodingUnicode11Semantics = 1; - public static final short encodingISO10646Semantics = 2; - public static final short encodingUnicode20Semantics = 3; - - // Microsoft Encoding IDs -// public static final short encodingUndefined = 0; -// public static final short encodingUGL = 1; - public static final short encodingSymbol = 0; - public static final short encodingUnicode = 1; - public static final short encodingShiftJIS = 2; - public static final short encodingPRC = 3; - public static final short encodingBig5 = 4; - public static final short encodingWansung = 5; - public static final short encodingJohab = 6; - public static final short encodingUCS4 = 10; - - // Macintosh Encoding IDs - public static final short encodingRoman = 0; - public static final short encodingJapanese = 1; - public static final short encodingChinese = 2; - public static final short encodingKorean = 3; - public static final short encodingArabic = 4; - public static final short encodingHebrew = 5; - public static final short encodingGreek = 6; - public static final short encodingRussian = 7; - public static final short encodingRSymbol = 8; - public static final short encodingDevanagari = 9; - public static final short encodingGurmukhi = 10; - public static final short encodingGujarati = 11; - public static final short encodingOriya = 12; - public static final short encodingBengali = 13; - public static final short encodingTamil = 14; - public static final short encodingTelugu = 15; - public static final short encodingKannada = 16; - public static final short encodingMalayalam = 17; - public static final short encodingSinhalese = 18; - public static final short encodingBurmese = 19; - public static final short encodingKhmer = 20; - public static final short encodingThai = 21; - public static final short encodingLaotian = 22; - public static final short encodingGeorgian = 23; - public static final short encodingArmenian = 24; - public static final short encodingMaldivian = 25; - public static final short encodingTibetan = 26; - public static final short encodingMongolian = 27; - public static final short encodingGeez = 28; - public static final short encodingSlavic = 29; - public static final short encodingVietnamese = 30; - public static final short encodingSindhi = 31; - public static final short encodingUninterp = 32; - - // ISO Encoding IDs - public static final short encodingASCII = 0; - public static final short encodingISO10646 = 1; - public static final short encodingISO8859_1 = 2; - - // Microsoft Language IDs - public static final short languageSQI = 0x041c; - public static final short languageEUQ = 0x042d; - public static final short languageBEL = 0x0423; - public static final short languageBGR = 0x0402; - public static final short languageCAT = 0x0403; - public static final short languageSHL = 0x041a; - public static final short languageCSY = 0x0405; - public static final short languageDAN = 0x0406; - public static final short languageNLD = 0x0413; - public static final short languageNLB = 0x0813; - public static final short languageENU = 0x0409; - public static final short languageENG = 0x0809; - public static final short languageENA = 0x0c09; - public static final short languageENC = 0x1009; - public static final short languageENZ = 0x1409; - public static final short languageENI = 0x1809; - public static final short languageETI = 0x0425; - public static final short languageFIN = 0x040b; - public static final short languageFRA = 0x040c; - public static final short languageFRB = 0x080c; - public static final short languageFRC = 0x0c0c; - public static final short languageFRS = 0x100c; - public static final short languageFRL = 0x140c; - public static final short languageDEU = 0x0407; - public static final short languageDES = 0x0807; - public static final short languageDEA = 0x0c07; - public static final short languageDEL = 0x1007; - public static final short languageDEC = 0x1407; - public static final short languageELL = 0x0408; - public static final short languageHUN = 0x040e; - public static final short languageISL = 0x040f; - public static final short languageITA = 0x0410; - public static final short languageITS = 0x0810; - public static final short languageLVI = 0x0426; - public static final short languageLTH = 0x0427; - public static final short languageNOR = 0x0414; - public static final short languageNON = 0x0814; - public static final short languagePLK = 0x0415; - public static final short languagePTB = 0x0416; - public static final short languagePTG = 0x0816; - public static final short languageROM = 0x0418; - public static final short languageRUS = 0x0419; - public static final short languageSKY = 0x041b; - public static final short languageSLV = 0x0424; - public static final short languageESP = 0x040a; - public static final short languageESM = 0x080a; - public static final short languageESN = 0x0c0a; - public static final short languageSVE = 0x041d; - public static final short languageTRK = 0x041f; - public static final short languageUKR = 0x0422; - - // Macintosh Language IDs - public static final short languageEnglish = 0; - public static final short languageFrench = 1; - public static final short languageGerman = 2; - public static final short languageItalian = 3; - public static final short languageDutch = 4; - public static final short languageSwedish = 5; - public static final short languageSpanish = 6; - public static final short languageDanish = 7; - public static final short languagePortuguese = 8; - public static final short languageNorwegian = 9; - public static final short languageHebrew = 10; - public static final short languageJapanese = 11; - public static final short languageArabic = 12; - public static final short languageFinnish = 13; - public static final short languageGreek = 14; - public static final short languageIcelandic = 15; - public static final short languageMaltese = 16; - public static final short languageTurkish = 17; - public static final short languageYugoslavian = 18; - public static final short languageChinese = 19; - public static final short languageUrdu = 20; - public static final short languageHindi = 21; - public static final short languageThai = 22; - - // Name IDs - public static final short nameCopyrightNotice = 0; - public static final short nameFontFamilyName = 1; - public static final short nameFontSubfamilyName = 2; - public static final short nameUniqueFontIdentifier = 3; - public static final short nameFullFontName = 4; - public static final short nameVersionString = 5; - public static final short namePostscriptName = 6; - public static final short nameTrademark = 7; - public static final short nameManufacturerName = 8; - public static final short nameDesigner = 9; - public static final short nameDescription = 10; - public static final short nameURLVendor = 11; - public static final short nameURLDesigner = 12; - public static final short nameLicenseDescription = 13; - public static final short nameLicenseInfoURL = 14; - public static final short namePreferredFamily = 16; - public static final short namePreferredSubfamily = 17; - public static final short nameCompatibleFull = 18; - public static final short nameSampleText = 19; - public static final short namePostScriptCIDFindfontName = 20; - - public static String getPlatformName(short platformId) { - switch (platformId) { - case platformUnicode: return "Unicode"; - case platformMacintosh: return "Macintosh"; - case platformISO: return "ISO"; - case platformMicrosoft: return "Microsoft"; - default: return "Custom"; - } - } - - public static String getEncodingName(short platformId, short encodingId) { - - if (platformId == platformUnicode) { - - // Unicode specific encodings - switch (encodingId) { - case encodingUnicode10Semantics: return "Unicode 1.0 semantics"; - case encodingUnicode11Semantics: return "Unicode 1.1 semantics"; - case encodingISO10646Semantics: return "ISO 10646:1993 semantics"; - case encodingUnicode20Semantics: return "Unicode 2.0 and onwards semantics"; - default: return ""; - } - - } else if (platformId == platformMacintosh) { - - // Macintosh specific encodings - switch (encodingId) { - case encodingRoman: return "Roman"; - case encodingJapanese: return "Japanese"; - case encodingChinese: return "Chinese"; - case encodingKorean: return "Korean"; - case encodingArabic: return "Arabi"; - case encodingHebrew: return "Hebrew"; - case encodingGreek: return "Greek"; - case encodingRussian: return "Russian"; - case encodingRSymbol: return "RSymbol"; - case encodingDevanagari: return "Devanagari"; - case encodingGurmukhi: return "Gurmukhi"; - case encodingGujarati: return "Gujarati"; - case encodingOriya: return "Oriya"; - case encodingBengali: return "Bengali"; - case encodingTamil: return "Tamil"; - case encodingTelugu: return "Telugu"; - case encodingKannada: return "Kannada"; - case encodingMalayalam: return "Malayalam"; - case encodingSinhalese: return "Sinhalese"; - case encodingBurmese: return "Burmese"; - case encodingKhmer: return "Khmer"; - case encodingThai: return "Thai"; - case encodingLaotian: return "Laotian"; - case encodingGeorgian: return "Georgian"; - case encodingArmenian: return "Armenian"; - case encodingMaldivian: return "Maldivian"; - case encodingTibetan: return "Tibetan"; - case encodingMongolian: return "Mongolian"; - case encodingGeez: return "Geez"; - case encodingSlavic: return "Slavic"; - case encodingVietnamese: return "Vietnamese"; - case encodingSindhi: return "Sindhi"; - case encodingUninterp: return "Uninterpreted"; - default: return ""; - } - - } else if (platformId == platformISO) { - - // ISO specific encodings - switch (encodingId) { - case encodingASCII: return "7-bit ASCII"; - case encodingISO10646: return "ISO 10646"; - case encodingISO8859_1: return "ISO 8859-1"; - default: return ""; - } - - } else if (platformId == platformMicrosoft) { - - // Windows specific encodings - switch (encodingId) { - case encodingSymbol: return "Symbol"; - case encodingUnicode: return "Unicode"; - case encodingShiftJIS: return "ShiftJIS"; - case encodingPRC: return "PRC"; - case encodingBig5: return "Big5"; - case encodingWansung: return "Wansung"; - case encodingJohab: return "Johab"; - case 7: return "Reserved"; - case 8: return "Reserved"; - case 9: return "Reserved"; - case encodingUCS4: return "UCS-4"; - default: return ""; - } - } - return ""; - } - - public static String getLanguageName(short platformId, short languageId) { - - if (platformId == platformMacintosh) { - switch (languageId) { - case languageEnglish: return "English"; - case languageFrench: return "French"; - case languageGerman: return "German"; - case languageItalian: return "Italian"; - case languageDutch: return "Dutch"; - case languageSwedish: return "Swedish"; - case languageSpanish: return "Spanish"; - case languageDanish: return "Danish"; - case languagePortuguese: return "Portuguese"; - case languageNorwegian: return "Norwegian"; - case languageHebrew: return "Hebrew"; - case languageJapanese: return "Japanese"; - case languageArabic: return "Arabic"; - case languageFinnish: return "Finnish"; - case languageGreek: return "Greek"; - case languageIcelandic: return "Icelandic"; - case languageMaltese: return "Maltese"; - case languageTurkish: return "Turkish"; - case languageYugoslavian: return "Yugoslavian"; - case languageChinese: return "Chinese"; - case languageUrdu: return "Urdu"; - case languageHindi: return "Hindi"; - case languageThai: return "Thai"; - default: return ""; - } - } else if (platformId == platformMicrosoft) { - switch (languageId) { - case languageSQI: return "Albanian (Albania)"; - case languageEUQ: return "Basque (Basque)"; - case languageBEL: return "Byelorussian (Byelorussia)"; - case languageBGR: return "Bulgarian (Bulgaria)"; - case languageCAT: return "Catalan (Catalan)"; - case languageSHL: return "Croatian (Croatian)"; - case languageCSY: return "Czech (Czech)"; - case languageDAN: return "Danish (Danish)"; - case languageNLD: return "Dutch (Dutch (Standard))"; - case languageNLB: return "Dutch (Belgian (Flemish))"; - case languageENU: return "English (American)"; - case languageENG: return "English (British)"; - case languageENA: return "English (Australian)"; - case languageENC: return "English (Canadian)"; - case languageENZ: return "English (New Zealand)"; - case languageENI: return "English (Ireland)"; - case languageETI: return "Estonian (Estonia)"; - case languageFIN: return "Finnish (Finnish)"; - case languageFRA: return "French (French (Standard))"; - case languageFRB: return "French (Belgian)"; - case languageFRC: return "French (Canadian)"; - case languageFRS: return "French (Swiss)"; - case languageFRL: return "French (Luxembourg)"; - case languageDEU: return "German (German (Standard))"; - case languageDES: return "German (Swiss)"; - case languageDEA: return "German (Austrian)"; - case languageDEL: return "German (Luxembourg)"; - case languageDEC: return "German (Liechtenstein)"; - case languageELL: return "Greek (Greek)"; - case languageHUN: return "Hungarian (Hungarian)"; - case languageISL: return "Icelandic (Icelandic)"; - case languageITA: return "Italian (Italian (Standard))"; - case languageITS: return "Italian (Swiss)"; - case languageLVI: return "Latvian (Latvia)"; - case languageLTH: return "Lithuanian (Lithuania)"; - case languageNOR: return "Norwegian (Norwegian (Bokmal))"; - case languageNON: return "Norwegian (Norwegian (Nynorsk))"; - case languagePLK: return "Polish (Polish)"; - case languagePTB: return "Portuguese (Portuguese (Brazilian))"; - case languagePTG: return "Portuguese (Portuguese (Standard))"; - case languageROM: return "Romanian (Romania)"; - case languageRUS: return "Russian (Russian)"; - case languageSKY: return "Slovak (Slovak)"; - case languageSLV: return "Slovenian (Slovenia)"; - case languageESP: return "Spanish (Spanish (Traditional Sort))"; - case languageESM: return "Spanish (Mexican)"; - case languageESN: return "Spanish (Spanish (Modern Sort))"; - case languageSVE: return "Swedish (Swedish)"; - case languageTRK: return "Turkish (Turkish)"; - case languageUKR: return "Ukrainian (Ukraine)"; - default: return ""; - } - } - return ""; - } - - public static String getNameName(short nameId) { - switch (nameId) { - case nameCopyrightNotice: return "Copyright notice"; - case nameFontFamilyName: return "Font Family name"; - case nameFontSubfamilyName: return "Font Subfamily name"; - case nameUniqueFontIdentifier: return "Unique font identifier"; - case nameFullFontName: return "Full font name"; - case nameVersionString: return "Version string"; - case namePostscriptName: return "Postscript name"; - case nameTrademark: return "Trademark"; - case nameManufacturerName: return "Manufacturer Name"; - case nameDesigner: return "Designer"; - case nameDescription: return "Description"; - case nameURLVendor: return "URL Vendor"; - case nameURLDesigner: return "URL Designer"; - case nameLicenseDescription: return "License Description"; - case nameLicenseInfoURL: return "License Info URL"; - case namePreferredFamily: return "Preferred Family"; - case namePreferredSubfamily: return "Preferred Subfamily"; - case nameCompatibleFull: return "Compatible Full"; - case nameSampleText: return "Sample text"; - case namePostScriptCIDFindfontName: return "PostScript CID findfont name"; - default: return ""; - } - } -} diff --git a/src/net/java/dev/typecast/ot/table/KernSubtable.java b/src/net/java/dev/typecast/ot/table/KernSubtable.java deleted file mode 100644 index f55fa04fb..000000000 --- a/src/net/java/dev/typecast/ot/table/KernSubtable.java +++ /dev/null @@ -1,49 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KernSubtable.java,v 1.1.1.1 2004-12-05 23:14:47 davidsch Exp $ - */ -public abstract class KernSubtable { - - /** Creates new KernSubtable */ - protected KernSubtable() { - } - - public abstract int getKerningPairCount(); - - public abstract KerningPair getKerningPair(int i); - - public static KernSubtable read(DataInput di) throws IOException { - KernSubtable table = null; - int version = di.readUnsignedShort(); - int length = di.readUnsignedShort(); - int coverage = di.readUnsignedShort(); - int format = coverage >> 8; - - switch (format) { - case 0: - table = new KernSubtableFormat0(di); - break; - case 2: - table = new KernSubtableFormat2(di); - break; - default: - break; - } - return table; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/KernSubtableFormat0.java b/src/net/java/dev/typecast/ot/table/KernSubtableFormat0.java deleted file mode 100644 index e3b1c9cf9..000000000 --- a/src/net/java/dev/typecast/ot/table/KernSubtableFormat0.java +++ /dev/null @@ -1,47 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KernSubtableFormat0.java,v 1.1.1.1 2004-12-05 23:14:48 davidsch Exp $ - */ -public class KernSubtableFormat0 extends KernSubtable { - - private int nPairs; - private int searchRange; - private int entrySelector; - private int rangeShift; - private KerningPair[] kerningPairs; - - /** Creates new KernSubtableFormat0 */ - protected KernSubtableFormat0(DataInput di) throws IOException { - nPairs = di.readUnsignedShort(); - searchRange = di.readUnsignedShort(); - entrySelector = di.readUnsignedShort(); - rangeShift = di.readUnsignedShort(); - kerningPairs = new KerningPair[nPairs]; - for (int i = 0; i < nPairs; i++) { - kerningPairs[i] = new KerningPair(di); - } - } - - public int getKerningPairCount() { - return nPairs; - } - - public KerningPair getKerningPair(int i) { - return kerningPairs[i]; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/KernSubtableFormat2.java b/src/net/java/dev/typecast/ot/table/KernSubtableFormat2.java deleted file mode 100644 index 5ff37c291..000000000 --- a/src/net/java/dev/typecast/ot/table/KernSubtableFormat2.java +++ /dev/null @@ -1,42 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KernSubtableFormat2.java,v 1.1.1.1 2004-12-05 23:14:48 davidsch Exp $ - */ -public class KernSubtableFormat2 extends KernSubtable { - - private int rowWidth; - private int leftClassTable; - private int rightClassTable; - private int array; - - /** Creates new KernSubtableFormat2 */ - protected KernSubtableFormat2(DataInput di) throws IOException { - rowWidth = di.readUnsignedShort(); - leftClassTable = di.readUnsignedShort(); - rightClassTable = di.readUnsignedShort(); - array = di.readUnsignedShort(); - } - - public int getKerningPairCount() { - return 0; - } - - public KerningPair getKerningPair(int i) { - return null; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/KernTable.java b/src/net/java/dev/typecast/ot/table/KernTable.java deleted file mode 100644 index 81c4a998f..000000000 --- a/src/net/java/dev/typecast/ot/table/KernTable.java +++ /dev/null @@ -1,62 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KernTable.java,v 1.1.1.1 2004-12-05 23:14:48 davidsch Exp $ - */ -public class KernTable implements Table { - - private DirectoryEntry de; - private int version; - private int nTables; - private KernSubtable[] tables; - - /** Creates new KernTable */ - protected KernTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - version = di.readUnsignedShort(); - nTables = di.readUnsignedShort(); - tables = new KernSubtable[nTables]; - for (int i = 0; i < nTables; i++) { - tables[i] = KernSubtable.read(di); - } - } - - public int getSubtableCount() { - return nTables; - } - - public KernSubtable getSubtable(int i) { - return tables[i]; - } - - /** Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return kern; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/KerningPair.java b/src/net/java/dev/typecast/ot/table/KerningPair.java deleted file mode 100644 index de614235f..000000000 --- a/src/net/java/dev/typecast/ot/table/KerningPair.java +++ /dev/null @@ -1,44 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KerningPair.java,v 1.1.1.1 2004-12-05 23:14:47 davidsch Exp $ - */ -public class KerningPair { - - private int left; - private int right; - private short value; - - /** Creates new KerningPair */ - protected KerningPair(DataInput di) throws IOException { - left = di.readUnsignedShort(); - right = di.readUnsignedShort(); - value = di.readShort(); - } - - public int getLeft() { - return left; - } - - public int getRight() { - return right; - } - - public short getValue() { - return value; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/LangSys.java b/src/net/java/dev/typecast/ot/table/LangSys.java deleted file mode 100644 index 9963bf6af..000000000 --- a/src/net/java/dev/typecast/ot/table/LangSys.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LangSys.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ - */ -public class LangSys { - - private int _lookupOrder; - private int _reqFeatureIndex; - private int _featureCount; - private int[] _featureIndex; - - /** Creates new LangSys */ - protected LangSys(DataInput di) throws IOException { - _lookupOrder = di.readUnsignedShort(); - _reqFeatureIndex = di.readUnsignedShort(); - _featureCount = di.readUnsignedShort(); - _featureIndex = new int[_featureCount]; - for (int i = 0; i < _featureCount; i++) { - _featureIndex[i] = di.readUnsignedShort(); - } - } - - public int getLookupOrder() { - return _lookupOrder; - } - - public int getReqFeatureIndex() { - return _reqFeatureIndex; - } - - public int getFeatureCount() { - return _featureCount; - } - - public int getFeatureIndex(int i) { - return _featureIndex[i]; - } - - protected boolean isFeatureIndexed(int n) { - for (int i = 0; i < _featureCount; i++) { - if (_featureIndex[i] == n) { - return true; - } - } - return false; - } - -} - diff --git a/src/net/java/dev/typecast/ot/table/LangSysRecord.java b/src/net/java/dev/typecast/ot/table/LangSysRecord.java deleted file mode 100644 index a69c12a44..000000000 --- a/src/net/java/dev/typecast/ot/table/LangSysRecord.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LangSysRecord.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ - */ -public class LangSysRecord { - - private int _tag; - private int _offset; - - /** Creates new LangSysRecord */ - public LangSysRecord(DataInput di) throws IOException { - _tag = di.readInt(); - _offset = di.readUnsignedShort(); - } - - public int getTag() { - return _tag; - } - - public int getOffset() { - return _offset; - } - - public String getTagAsString() { - return new StringBuffer() - .append((char)((_tag>>24)&0xff)) - .append((char)((_tag>>16)&0xff)) - .append((char)((_tag>>8)&0xff)) - .append((char)((_tag)&0xff)) - .toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/Ligature.java b/src/net/java/dev/typecast/ot/table/Ligature.java deleted file mode 100644 index 36969ba7a..000000000 --- a/src/net/java/dev/typecast/ot/table/Ligature.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Ligature.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ - */ -public class Ligature { - - private int _ligGlyph; - private int _compCount; - private int[] _components; - - /** Creates new Ligature */ - public Ligature(DataInput di) throws IOException { - _ligGlyph = di.readUnsignedShort(); - _compCount = di.readUnsignedShort(); - _components = new int[_compCount - 1]; - for (int i = 0; i < _compCount - 1; i++) { - _components[i] = di.readUnsignedShort(); - } - } - - public int getGlyphCount() { - return _compCount; - } - - public int getGlyphId(int i) { - return (i == 0) ? _ligGlyph : _components[i-1]; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/LigatureSet.java b/src/net/java/dev/typecast/ot/table/LigatureSet.java deleted file mode 100644 index fe6db0445..000000000 --- a/src/net/java/dev/typecast/ot/table/LigatureSet.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LigatureSet.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ - */ -public class LigatureSet { - - private int _ligatureCount; - private int[] _ligatureOffsets; - private Ligature[] _ligatures; - - /** Creates new LigatureSet */ - public LigatureSet(DataInputStream dis, int offset) throws IOException { - dis.reset(); - dis.skipBytes(offset); - _ligatureCount = dis.readUnsignedShort(); - _ligatureOffsets = new int[_ligatureCount]; - _ligatures = new Ligature[_ligatureCount]; - for (int i = 0; i < _ligatureCount; i++) { - _ligatureOffsets[i] = dis.readUnsignedShort(); - } - for (int i = 0; i < _ligatureCount; i++) { - dis.reset(); - dis.skipBytes(offset + _ligatureOffsets[i]); - _ligatures[i] = new Ligature(dis); - } - } - -} - diff --git a/src/net/java/dev/typecast/ot/table/LigatureSubst.java b/src/net/java/dev/typecast/ot/table/LigatureSubst.java deleted file mode 100644 index 73a8b9d36..000000000 --- a/src/net/java/dev/typecast/ot/table/LigatureSubst.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LigatureSubst.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ - */ -public abstract class LigatureSubst extends LookupSubtable { - - public static LigatureSubst read(DataInputStream dis, int offset) throws IOException { - dis.reset(); - dis.skipBytes(offset); - int format = dis.readUnsignedShort(); - if (format == 1) { - return new LigatureSubstFormat1(dis, offset); - } - return null; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/LigatureSubstFormat1.java b/src/net/java/dev/typecast/ot/table/LigatureSubstFormat1.java deleted file mode 100644 index b19b07111..000000000 --- a/src/net/java/dev/typecast/ot/table/LigatureSubstFormat1.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LigatureSubstFormat1.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ - */ -public class LigatureSubstFormat1 extends LigatureSubst { - - private int _coverageOffset; - private int _ligSetCount; - private int[] _ligatureSetOffsets; - private Coverage _coverage; - private LigatureSet[] _ligatureSets; - - /** Creates new LigatureSubstFormat1 */ - protected LigatureSubstFormat1( - DataInputStream dis, - int offset) throws IOException { - _coverageOffset = dis.readUnsignedShort(); - _ligSetCount = dis.readUnsignedShort(); - _ligatureSetOffsets = new int[_ligSetCount]; - _ligatureSets = new LigatureSet[_ligSetCount]; - for (int i = 0; i < _ligSetCount; i++) { - _ligatureSetOffsets[i] = dis.readUnsignedShort(); - } - dis.reset(); - dis.skipBytes(offset + _coverageOffset); - _coverage = Coverage.read(dis); - for (int i = 0; i < _ligSetCount; i++) { - _ligatureSets[i] = new LigatureSet(dis, offset + _ligatureSetOffsets[i]); - } - } - - public int getFormat() { - return 1; - } - - public String getTypeAsString() { - return "LigatureSubstFormat1"; - } -} diff --git a/src/net/java/dev/typecast/ot/table/LocaTable.java b/src/net/java/dev/typecast/ot/table/LocaTable.java deleted file mode 100644 index 5f62940df..000000000 --- a/src/net/java/dev/typecast/ot/table/LocaTable.java +++ /dev/null @@ -1,77 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: LocaTable.java,v 1.4 2010-08-10 11:45:43 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class LocaTable implements Table { - - private DirectoryEntry _de; - private int[] _offsets = null; - private short _factor = 0; - - protected LocaTable( - DirectoryEntry de, - DataInput di, - HeadTable head, - MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); - _offsets = new int[maxp.getNumGlyphs() + 1]; - boolean shortEntries = head.getIndexToLocFormat() == 0; - if (shortEntries) { - _factor = 2; - for (int i = 0; i <= maxp.getNumGlyphs(); i++) { - _offsets[i] = di.readUnsignedShort(); - } - } else { - _factor = 1; - for (int i = 0; i <= maxp.getNumGlyphs(); i++) { - _offsets[i] = di.readInt(); - } - } - } - - public int getOffset(int i) { - if (_offsets == null) { - return 0; - } - return _offsets[i] * _factor; - } - - public int getType() { - return loca; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'loca' Table - Index To Location Table\n--------------------------------------\n") - .append("Size = ").append(_de.getLength()).append(" bytes, ") - .append(_offsets.length).append(" entries\n"); - for (int i = 0; i < _offsets.length; i++) { - sb.append(" Idx ").append(i) - .append(" -> glyfOff 0x").append(getOffset(i)).append("\n"); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/Lookup.java b/src/net/java/dev/typecast/ot/table/Lookup.java deleted file mode 100644 index d6e46cd91..000000000 --- a/src/net/java/dev/typecast/ot/table/Lookup.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Lookup.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ - */ -public class Lookup { - - // LookupFlag bit enumeration - public static final int IGNORE_BASE_GLYPHS = 0x0002; - public static final int IGNORE_BASE_LIGATURES = 0x0004; - public static final int IGNORE_BASE_MARKS = 0x0008; - public static final int MARK_ATTACHMENT_TYPE = 0xFF00; - - private int _type; - private int _flag; - private int _subTableCount; - private int[] _subTableOffsets; - private LookupSubtable[] _subTables; - - /** Creates new Lookup */ - public Lookup(LookupSubtableFactory factory, DataInputStream dis, int offset) - throws IOException { - - // Ensure we're in the right place - dis.reset(); - dis.skipBytes(offset); - - // Start reading - _type = dis.readUnsignedShort(); - _flag = dis.readUnsignedShort(); - _subTableCount = dis.readUnsignedShort(); - _subTableOffsets = new int[_subTableCount]; - _subTables = new LookupSubtable[_subTableCount]; - for (int i = 0; i < _subTableCount; i++) { - _subTableOffsets[i] = dis.readUnsignedShort(); - } - for (int i = 0; i < _subTableCount; i++) { - _subTables[i] = factory.read(_type, dis, offset + _subTableOffsets[i]); - } - } - - public int getType() { - return _type; - } - - public int getSubtableCount() { - return _subTableCount; - } - - public LookupSubtable getSubtable(int i) { - return _subTables[i]; - } - -} - diff --git a/src/net/java/dev/typecast/ot/table/LookupList.java b/src/net/java/dev/typecast/ot/table/LookupList.java deleted file mode 100644 index 9ac76aba5..000000000 --- a/src/net/java/dev/typecast/ot/table/LookupList.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LookupList.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ - */ -public class LookupList { - - private int _lookupCount; - private int[] _lookupOffsets; - private Lookup[] _lookups; - - /** Creates new LookupList */ - public LookupList(DataInputStream dis, int offset, LookupSubtableFactory factory) - throws IOException { - - // Ensure we're in the right place - dis.reset(); - dis.skipBytes(offset); - - // Start reading - _lookupCount = dis.readUnsignedShort(); - _lookupOffsets = new int[_lookupCount]; - _lookups = new Lookup[_lookupCount]; - for (int i = 0; i < _lookupCount; i++) { - _lookupOffsets[i] = dis.readUnsignedShort(); - } - for (int i = 0; i < _lookupCount; i++) { - _lookups[i] = new Lookup(factory, dis, offset + _lookupOffsets[i]); - } - } - - public int getLookupCount() { - return _lookupCount; - } - - public int getLookupOffset(int i) { - return _lookupOffsets[i]; - } - - public Lookup getLookup(int i) { - return _lookups[i]; - } - - public Lookup getLookup(Feature feature, int index) { - if (feature.getLookupCount() > index) { - int i = feature.getLookupListIndex(index); - return _lookups[i]; - } - return null; - } - -} - diff --git a/src/net/java/dev/typecast/ot/table/LookupSubtable.java b/src/net/java/dev/typecast/ot/table/LookupSubtable.java deleted file mode 100644 index 4d8dbb180..000000000 --- a/src/net/java/dev/typecast/ot/table/LookupSubtable.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LookupSubtable.java,v 1.2 2007-01-24 09:47:45 davidsch Exp $ - */ -public abstract class LookupSubtable { - public abstract String getTypeAsString(); -} diff --git a/src/net/java/dev/typecast/ot/table/LookupSubtableFactory.java b/src/net/java/dev/typecast/ot/table/LookupSubtableFactory.java deleted file mode 100644 index 2081e2ea6..000000000 --- a/src/net/java/dev/typecast/ot/table/LookupSubtableFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LookupSubtableFactory.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ - */ -public interface LookupSubtableFactory { - public LookupSubtable read(int type, DataInputStream dis, int offset) - throws IOException; -} diff --git a/src/net/java/dev/typecast/ot/table/LtshTable.java b/src/net/java/dev/typecast/ot/table/LtshTable.java deleted file mode 100644 index 12dca01f4..000000000 --- a/src/net/java/dev/typecast/ot/table/LtshTable.java +++ /dev/null @@ -1,68 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @version $Id: LtshTable.java,v 1.1.1.1 2004-12-05 23:14:51 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class LtshTable implements Table { - - private DirectoryEntry de; - private int version; - private int numGlyphs; - private int[] yPels; - - /** Creates new LtshTable */ - protected LtshTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - version = di.readUnsignedShort(); - numGlyphs = di.readUnsignedShort(); - yPels = new int[numGlyphs]; - for (int i = 0; i < numGlyphs; i++) { - yPels[i] = di.readUnsignedByte(); - } - } - - /** - * Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return LTSH; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'LTSH' Table - Linear Threshold Table\n-------------------------------------") - .append("\n 'LTSH' Version: ").append(version) - .append("\n Number of Glyphs: ").append(numGlyphs) - .append("\n\n Glyph # Threshold\n ------- ---------\n"); - for (int i = 0; i < numGlyphs; i++) { - sb.append(" ").append(i).append(". ").append(yPels[i]) - .append("\n"); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/MaxpTable.java b/src/net/java/dev/typecast/ot/table/MaxpTable.java deleted file mode 100644 index 571d3ebfd..000000000 --- a/src/net/java/dev/typecast/ot/table/MaxpTable.java +++ /dev/null @@ -1,162 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; -import net.java.dev.typecast.ot.Fixed; - -/** - * @version $Id: MaxpTable.java,v 1.1.1.1 2004-12-05 23:14:52 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class MaxpTable implements Table { - - private DirectoryEntry de; - private int versionNumber; - private int numGlyphs; - private int maxPoints; - private int maxContours; - private int maxCompositePoints; - private int maxCompositeContours; - private int maxZones; - private int maxTwilightPoints; - private int maxStorage; - private int maxFunctionDefs; - private int maxInstructionDefs; - private int maxStackElements; - private int maxSizeOfInstructions; - private int maxComponentElements; - private int maxComponentDepth; - - protected MaxpTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - versionNumber = di.readInt(); - - // CFF fonts use version 0.5, TrueType fonts use version 1.0 - if (versionNumber == 0x00005000) { - numGlyphs = di.readUnsignedShort(); - } else if (versionNumber == 0x00010000) { - numGlyphs = di.readUnsignedShort(); - maxPoints = di.readUnsignedShort(); - maxContours = di.readUnsignedShort(); - maxCompositePoints = di.readUnsignedShort(); - maxCompositeContours = di.readUnsignedShort(); - maxZones = di.readUnsignedShort(); - maxTwilightPoints = di.readUnsignedShort(); - maxStorage = di.readUnsignedShort(); - maxFunctionDefs = di.readUnsignedShort(); - maxInstructionDefs = di.readUnsignedShort(); - maxStackElements = di.readUnsignedShort(); - maxSizeOfInstructions = di.readUnsignedShort(); - maxComponentElements = di.readUnsignedShort(); - maxComponentDepth = di.readUnsignedShort(); - } - } - - public int getVersionNumber() { - return versionNumber; - } - - public int getMaxComponentDepth() { - return maxComponentDepth; - } - - public int getMaxComponentElements() { - return maxComponentElements; - } - - public int getMaxCompositeContours() { - return maxCompositeContours; - } - - public int getMaxCompositePoints() { - return maxCompositePoints; - } - - public int getMaxContours() { - return maxContours; - } - - public int getMaxFunctionDefs() { - return maxFunctionDefs; - } - - public int getMaxInstructionDefs() { - return maxInstructionDefs; - } - - public int getMaxPoints() { - return maxPoints; - } - - public int getMaxSizeOfInstructions() { - return maxSizeOfInstructions; - } - - public int getMaxStackElements() { - return maxStackElements; - } - - public int getMaxStorage() { - return maxStorage; - } - - public int getMaxTwilightPoints() { - return maxTwilightPoints; - } - - public int getMaxZones() { - return maxZones; - } - - public int getNumGlyphs() { - return numGlyphs; - } - - public int getType() { - return maxp; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'maxp' Table - Maximum Profile\n------------------------------") - .append("\n 'maxp' version: ").append(Fixed.floatValue(versionNumber)) - .append("\n numGlyphs: ").append(numGlyphs); - if (versionNumber == 0x00010000) { - sb.append("\n maxPoints: ").append(maxPoints) - .append("\n maxContours: ").append(maxContours) - .append("\n maxCompositePoints: ").append(maxCompositePoints) - .append("\n maxCompositeContours: ").append(maxCompositeContours) - .append("\n maxZones: ").append(maxZones) - .append("\n maxTwilightPoints: ").append(maxTwilightPoints) - .append("\n maxStorage: ").append(maxStorage) - .append("\n maxFunctionDefs: ").append(maxFunctionDefs) - .append("\n maxInstructionDefs: ").append(maxInstructionDefs) - .append("\n maxStackElements: ").append(maxStackElements) - .append("\n maxSizeOfInstructions: ").append(maxSizeOfInstructions) - .append("\n maxComponentElements: ").append(maxComponentElements) - .append("\n maxComponentDepth: ").append(maxComponentDepth); - } else { - sb.append("\n"); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/NameRecord.java b/src/net/java/dev/typecast/ot/table/NameRecord.java deleted file mode 100644 index cdba03ef9..000000000 --- a/src/net/java/dev/typecast/ot/table/NameRecord.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: NameRecord.java,v 1.2 2004-12-09 23:47:23 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class NameRecord { - - private short _platformId; - private short _encodingId; - private short _languageId; - private short _nameId; - private short _stringLength; - private short _stringOffset; - private String _record; - - protected NameRecord(DataInput di) throws IOException { - _platformId = di.readShort(); - _encodingId = di.readShort(); - _languageId = di.readShort(); - _nameId = di.readShort(); - _stringLength = di.readShort(); - _stringOffset = di.readShort(); - } - - public short getEncodingId() { - return _encodingId; - } - - public short getLanguageId() { - return _languageId; - } - - public short getNameId() { - return _nameId; - } - - public short getPlatformId() { - return _platformId; - } - - public String getRecordString() { - return _record; - } - - protected void loadString(DataInput di) throws IOException { - StringBuffer sb = new StringBuffer(); - di.skipBytes(_stringOffset); - if (_platformId == ID.platformUnicode) { - - // Unicode (big-endian) - for (int i = 0; i < _stringLength/2; i++) { - sb.append(di.readChar()); - } - } else if (_platformId == ID.platformMacintosh) { - - // Macintosh encoding, ASCII - for (int i = 0; i < _stringLength; i++) { - sb.append((char) di.readByte()); - } - } else if (_platformId == ID.platformISO) { - - // ISO encoding, ASCII - for (int i = 0; i < _stringLength; i++) { - sb.append((char) di.readByte()); - } - } else if (_platformId == ID.platformMicrosoft) { - - // Microsoft encoding, Unicode - char c; - for (int i = 0; i < _stringLength/2; i++) { - c = di.readChar(); - sb.append(c); - } - } - _record = sb.toString(); - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - - sb.append(" Platform ID: ").append(_platformId) - .append("\n Specific ID: ").append(_encodingId) - .append("\n Language ID: ").append(_languageId) - .append("\n Name ID: ").append(_nameId) - .append("\n Length: ").append(_stringLength) - .append("\n Offset: ").append(_stringOffset) - .append("\n\n").append(_record); - - return sb.toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/NameTable.java b/src/net/java/dev/typecast/ot/table/NameTable.java deleted file mode 100644 index 05f823427..000000000 --- a/src/net/java/dev/typecast/ot/table/NameTable.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.ByteArrayInputStream; -import java.io.IOException; - -/** - * The naming table allows multilingual strings to be associated with the - * OpenType font file. These strings can represent copyright notices, font - * names, family names, style names, and so on. - * @version $Id: NameTable.java,v 1.2 2004-12-09 23:47:23 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class NameTable implements Table { - - private DirectoryEntry _de; - private short _formatSelector; - private short _numberOfNameRecords; - private short _stringStorageOffset; - private NameRecord[] _records; - - protected NameTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); - _formatSelector = di.readShort(); - _numberOfNameRecords = di.readShort(); - _stringStorageOffset = di.readShort(); - _records = new NameRecord[_numberOfNameRecords]; - - // Load the records, which contain the encoding information and string - // offsets - for (int i = 0; i < _numberOfNameRecords; i++) { - _records[i] = new NameRecord(di); - } - - // Load the string data into a buffer so the records can copy out the - // bits they are interested in - byte[] buffer = new byte[_de.getLength() - _stringStorageOffset]; - di.readFully(buffer); - - // Now let the records get their hands on them - for (int i = 0; i < _numberOfNameRecords; i++) { - _records[i].loadString( - new DataInputStream(new ByteArrayInputStream(buffer))); - } - } - - public short getNumberOfNameRecords() { - return _numberOfNameRecords; - } - - public NameRecord getRecord(int i) { - return _records[i]; - } - - public String getRecordString(short nameId) { - - // Search for the first instance of this name ID - for (int i = 0; i < _numberOfNameRecords; i++) { - if (_records[i].getNameId() == nameId) { - return _records[i].getRecordString(); - } - } - return ""; - } - - public int getType() { - return name; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/Os2Table.java b/src/net/java/dev/typecast/ot/table/Os2Table.java deleted file mode 100644 index 9ec599724..000000000 --- a/src/net/java/dev/typecast/ot/table/Os2Table.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: Os2Table.java,v 1.2 2004-12-09 23:46:21 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class Os2Table implements Table { - - private DirectoryEntry _de; - private int _version; - private short _xAvgCharWidth; - private int _usWeightClass; - private int _usWidthClass; - private short _fsType; - private short _ySubscriptXSize; - private short _ySubscriptYSize; - private short _ySubscriptXOffset; - private short _ySubscriptYOffset; - private short _ySuperscriptXSize; - private short _ySuperscriptYSize; - private short _ySuperscriptXOffset; - private short _ySuperscriptYOffset; - private short _yStrikeoutSize; - private short _yStrikeoutPosition; - private short _sFamilyClass; - private Panose _panose; - private int _ulUnicodeRange1; - private int _ulUnicodeRange2; - private int _ulUnicodeRange3; - private int _ulUnicodeRange4; - private int _achVendorID; - private short _fsSelection; - private int _usFirstCharIndex; - private int _usLastCharIndex; - private short _sTypoAscender; - private short _sTypoDescender; - private short _sTypoLineGap; - private int _usWinAscent; - private int _usWinDescent; - private int _ulCodePageRange1; - private int _ulCodePageRange2; - private short _sxHeight; - private short _sCapHeight; - private int _usDefaultChar; - private int _usBreakChar; - private int _usMaxContext; - - protected Os2Table(DirectoryEntry de, DataInput di) throws IOException { - this._de = (DirectoryEntry) de.clone(); - _version = di.readUnsignedShort(); - _xAvgCharWidth = di.readShort(); - _usWeightClass = di.readUnsignedShort(); - _usWidthClass = di.readUnsignedShort(); - _fsType = di.readShort(); - _ySubscriptXSize = di.readShort(); - _ySubscriptYSize = di.readShort(); - _ySubscriptXOffset = di.readShort(); - _ySubscriptYOffset = di.readShort(); - _ySuperscriptXSize = di.readShort(); - _ySuperscriptYSize = di.readShort(); - _ySuperscriptXOffset = di.readShort(); - _ySuperscriptYOffset = di.readShort(); - _yStrikeoutSize = di.readShort(); - _yStrikeoutPosition = di.readShort(); - _sFamilyClass = di.readShort(); - byte[] buf = new byte[10]; - di.readFully(buf); - _panose = new Panose(buf); - _ulUnicodeRange1 = di.readInt(); - _ulUnicodeRange2 = di.readInt(); - _ulUnicodeRange3 = di.readInt(); - _ulUnicodeRange4 = di.readInt(); - _achVendorID = di.readInt(); - _fsSelection = di.readShort(); - _usFirstCharIndex = di.readUnsignedShort(); - _usLastCharIndex = di.readUnsignedShort(); - _sTypoAscender = di.readShort(); - _sTypoDescender = di.readShort(); - _sTypoLineGap = di.readShort(); - _usWinAscent = di.readUnsignedShort(); - _usWinDescent = di.readUnsignedShort(); - _ulCodePageRange1 = di.readInt(); - _ulCodePageRange2 = di.readInt(); - - // OpenType 1.3 - if (_version == 2) { - _sxHeight = di.readShort(); - _sCapHeight = di.readShort(); - _usDefaultChar = di.readUnsignedShort(); - _usBreakChar = di.readUnsignedShort(); - _usMaxContext = di.readUnsignedShort(); - } - } - - public int getVersion() { - return _version; - } - - public short getAvgCharWidth() { - return _xAvgCharWidth; - } - - public int getWeightClass() { - return _usWeightClass; - } - - public int getWidthClass() { - return _usWidthClass; - } - - public short getLicenseType() { - return _fsType; - } - - public short getSubscriptXSize() { - return _ySubscriptXSize; - } - - public short getSubscriptYSize() { - return _ySubscriptYSize; - } - - public short getSubscriptXOffset() { - return _ySubscriptXOffset; - } - - public short getSubscriptYOffset() { - return _ySubscriptYOffset; - } - - public short getSuperscriptXSize() { - return _ySuperscriptXSize; - } - - public short getSuperscriptYSize() { - return _ySuperscriptYSize; - } - - public short getSuperscriptXOffset() { - return _ySuperscriptXOffset; - } - - public short getSuperscriptYOffset() { - return _ySuperscriptYOffset; - } - - public short getStrikeoutSize() { - return _yStrikeoutSize; - } - - public short getStrikeoutPosition() { - return _yStrikeoutPosition; - } - - public short getFamilyClass() { - return _sFamilyClass; - } - - public Panose getPanose() { - return _panose; - } - - public int getUnicodeRange1() { - return _ulUnicodeRange1; - } - - public int getUnicodeRange2() { - return _ulUnicodeRange2; - } - - public int getUnicodeRange3() { - return _ulUnicodeRange3; - } - - public int getUnicodeRange4() { - return _ulUnicodeRange4; - } - - public int getVendorID() { - return _achVendorID; - } - - public short getSelection() { - return _fsSelection; - } - - public int getFirstCharIndex() { - return _usFirstCharIndex; - } - - public int getLastCharIndex() { - return _usLastCharIndex; - } - - public short getTypoAscender() { - return _sTypoAscender; - } - - public short getTypoDescender() { - return _sTypoDescender; - } - - public short getTypoLineGap() { - return _sTypoLineGap; - } - - public int getWinAscent() { - return _usWinAscent; - } - - public int getWinDescent() { - return _usWinDescent; - } - - public int getCodePageRange1() { - return _ulCodePageRange1; - } - - public int getCodePageRange2() { - return _ulCodePageRange2; - } - - public short getXHeight() { - return _sxHeight; - } - - public short getCapHeight() { - return _sCapHeight; - } - - public int getDefaultChar() { - return _usDefaultChar; - } - - public int getBreakChar() { - return _usBreakChar; - } - - public int getMaxContext() { - return _usMaxContext; - } - - public int getType() { - return OS_2; - } - - public String toString() { - return new StringBuffer() - .append("'OS/2' Table - OS/2 and Windows Metrics\n---------------------------------------") - .append("\n 'OS/2' version: ").append(_version) - .append("\n xAvgCharWidth: ").append(_xAvgCharWidth) - .append("\n usWeightClass: ").append(_usWeightClass) - .append("\n usWidthClass: ").append(_usWidthClass) - .append("\n fsType: 0x").append(Integer.toHexString(_fsType).toUpperCase()) - .append("\n ySubscriptXSize: ").append(_ySubscriptXSize) - .append("\n ySubscriptYSize: ").append(_ySubscriptYSize) - .append("\n ySubscriptXOffset: ").append(_ySubscriptXOffset) - .append("\n ySubscriptYOffset: ").append(_ySubscriptYOffset) - .append("\n ySuperscriptXSize: ").append(_ySuperscriptXSize) - .append("\n ySuperscriptYSize: ").append(_ySuperscriptYSize) - .append("\n ySuperscriptXOffset: ").append(_ySuperscriptXOffset) - .append("\n ySuperscriptYOffset: ").append(_ySuperscriptYOffset) - .append("\n yStrikeoutSize: ").append(_yStrikeoutSize) - .append("\n yStrikeoutPosition: ").append(_yStrikeoutPosition) - .append("\n sFamilyClass: ").append(_sFamilyClass>>8) - .append(" subclass = ").append(_sFamilyClass&0xff) - .append("\n PANOSE: ").append(_panose.toString()) - .append("\n Unicode Range 1( Bits 0 - 31 ): ").append(Integer.toHexString(_ulUnicodeRange1).toUpperCase()) - .append("\n Unicode Range 2( Bits 32- 63 ): ").append(Integer.toHexString(_ulUnicodeRange2).toUpperCase()) - .append("\n Unicode Range 3( Bits 64- 95 ): ").append(Integer.toHexString(_ulUnicodeRange3).toUpperCase()) - .append("\n Unicode Range 4( Bits 96-127 ): ").append(Integer.toHexString(_ulUnicodeRange4).toUpperCase()) - .append("\n achVendID: '").append(getVendorIDAsString()) - .append("'\n fsSelection: 0x").append(Integer.toHexString(_fsSelection).toUpperCase()) - .append("\n usFirstCharIndex: 0x").append(Integer.toHexString(_usFirstCharIndex).toUpperCase()) - .append("\n usLastCharIndex: 0x").append(Integer.toHexString(_usLastCharIndex).toUpperCase()) - .append("\n sTypoAscender: ").append(_sTypoAscender) - .append("\n sTypoDescender: ").append(_sTypoDescender) - .append("\n sTypoLineGap: ").append(_sTypoLineGap) - .append("\n usWinAscent: ").append(_usWinAscent) - .append("\n usWinDescent: ").append(_usWinDescent) - .append("\n CodePage Range 1( Bits 0 - 31 ): ").append(Integer.toHexString(_ulCodePageRange1).toUpperCase()) - .append("\n CodePage Range 2( Bits 32- 63 ): ").append(Integer.toHexString(_ulCodePageRange2).toUpperCase()) - .toString(); - } - - private String getVendorIDAsString() { - return new StringBuffer() - .append((char)((_achVendorID>>24)&0xff)) - .append((char)((_achVendorID>>16)&0xff)) - .append((char)((_achVendorID>>8)&0xff)) - .append((char)((_achVendorID)&0xff)) - .toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/Panose.java b/src/net/java/dev/typecast/ot/table/Panose.java deleted file mode 100644 index fe0a357d2..000000000 --- a/src/net/java/dev/typecast/ot/table/Panose.java +++ /dev/null @@ -1,96 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -/** - * @version $Id: Panose.java,v 1.1.1.1 2004-12-05 23:14:54 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class Panose { - - byte bFamilyType = 0; - byte bSerifStyle = 0; - byte bWeight = 0; - byte bProportion = 0; - byte bContrast = 0; - byte bStrokeVariation = 0; - byte bArmStyle = 0; - byte bLetterform = 0; - byte bMidline = 0; - byte bXHeight = 0; - - /** Creates new Panose */ - public Panose(byte[] panose) { - bFamilyType = panose[0]; - bSerifStyle = panose[1]; - bWeight = panose[2]; - bProportion = panose[3]; - bContrast = panose[4]; - bStrokeVariation = panose[5]; - bArmStyle = panose[6]; - bLetterform = panose[7]; - bMidline = panose[8]; - bXHeight = panose[9]; - } - - public byte getFamilyType() { - return bFamilyType; - } - - public byte getSerifStyle() { - return bSerifStyle; - } - - public byte getWeight() { - return bWeight; - } - - public byte getProportion() { - return bProportion; - } - - public byte getContrast() { - return bContrast; - } - - public byte getStrokeVariation() { - return bStrokeVariation; - } - - public byte getArmStyle() { - return bArmStyle; - } - - public byte getLetterForm() { - return bLetterform; - } - - public byte getMidline() { - return bMidline; - } - - public byte getXHeight() { - return bXHeight; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(String.valueOf(bFamilyType)).append(" ") - .append(String.valueOf(bSerifStyle)).append(" ") - .append(String.valueOf(bWeight)).append(" ") - .append(String.valueOf(bProportion)).append(" ") - .append(String.valueOf(bContrast)).append(" ") - .append(String.valueOf(bStrokeVariation)).append(" ") - .append(String.valueOf(bArmStyle)).append(" ") - .append(String.valueOf(bLetterform)).append(" ") - .append(String.valueOf(bMidline)).append(" ") - .append(String.valueOf(bXHeight)); - return sb.toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/PcltTable.java b/src/net/java/dev/typecast/ot/table/PcltTable.java deleted file mode 100644 index 457aec2e1..000000000 --- a/src/net/java/dev/typecast/ot/table/PcltTable.java +++ /dev/null @@ -1,105 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @version $Id: PcltTable.java,v 1.1.1.1 2004-12-05 23:14:54 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class PcltTable implements Table { - - private DirectoryEntry de; - private int version; - private long fontNumber; - private int pitch; - private int xHeight; - private int style; - private int typeFamily; - private int capHeight; - private int symbolSet; - private char[] typeface = new char[16]; - private short[] characterComplement = new short[8]; - private char[] fileName = new char[6]; - private short strokeWeight; - private short widthType; - private byte serifStyle; - private byte reserved; - - /** Creates new PcltTable */ - protected PcltTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - version = di.readInt(); - fontNumber = di.readInt(); - pitch = di.readUnsignedShort(); - xHeight = di.readUnsignedShort(); - style = di.readUnsignedShort(); - typeFamily = di.readUnsignedShort(); - capHeight = di.readUnsignedShort(); - symbolSet = di.readUnsignedShort(); - for (int i = 0; i < 16; i++) { - typeface[i] = (char) di.readUnsignedByte(); - } - for (int i = 0; i < 8; i++) { - characterComplement[i] = (short) di.readUnsignedByte(); - } - for (int i = 0; i < 6; i++) { - fileName[i] = (char) di.readUnsignedByte(); - } - strokeWeight = (short) di.readUnsignedByte(); - widthType = (short) di.readUnsignedByte(); - serifStyle = di.readByte(); - reserved = di.readByte(); - } - - /** - * Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return PCLT; - } - - public String toString() { - return new StringBuffer() - .append("'PCLT' Table - Printer Command Language Table\n---------------------------------------------") - .append("\n version: 0x").append(Integer.toHexString(version).toUpperCase()) - .append("\n fontNumber: ").append(fontNumber).append(" (0x").append(Long.toHexString(fontNumber).toUpperCase()) - .append(")\n pitch: ").append(pitch) - .append("\n xHeight: ").append(xHeight) - .append("\n style: 0x").append(style) - .append("\n typeFamily: 0x").append(typeFamily>>12) - .append(" ").append(typeFamily & 0xfff) - .append("\n capHeight: ").append(capHeight) - .append("\n symbolSet: ").append(symbolSet) - .append("\n typeFace: ").append(new String(typeface)) - .append("\n characterComplement 0x") - .append(Integer.toHexString(characterComplement[0]).toUpperCase()) - .append("\n fileName: ").append(new String(fileName)) - .append("\n strokeWeight: ").append(strokeWeight) - .append("\n widthType: ").append(widthType) - .append("\n serifStyle: ").append(serifStyle) - .append("\n reserved: ").append(reserved) - .toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/PostTable.java b/src/net/java/dev/typecast/ot/table/PostTable.java deleted file mode 100644 index 4a1b0650b..000000000 --- a/src/net/java/dev/typecast/ot/table/PostTable.java +++ /dev/null @@ -1,422 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; -import net.java.dev.typecast.ot.Fixed; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: PostTable.java,v 1.1.1.1 2004-12-05 23:14:56 davidsch Exp $ - */ -public class PostTable implements Table { - - /** - * TODO: Mac Glyph names for 210 & 257 - */ - private static final String[] macGlyphName = { - ".notdef", // 0 - "null", // 1 - "CR", // 2 - "space", // 3 - "exclam", // 4 - "quotedbl", // 5 - "numbersign", // 6 - "dollar", // 7 - "percent", // 8 - "ampersand", // 9 - "quotesingle", // 10 - "parenleft", // 11 - "parenright", // 12 - "asterisk", // 13 - "plus", // 14 - "comma", // 15 - "hyphen", // 16 - "period", // 17 - "slash", // 18 - "zero", // 19 - "one", // 20 - "two", // 21 - "three", // 22 - "four", // 23 - "five", // 24 - "six", // 25 - "seven", // 26 - "eight", // 27 - "nine", // 28 - "colon", // 29 - "semicolon", // 30 - "less", // 31 - "equal", // 32 - "greater", // 33 - "question", // 34 - "at", // 35 - "A", // 36 - "B", // 37 - "C", // 38 - "D", // 39 - "E", // 40 - "F", // 41 - "G", // 42 - "H", // 43 - "I", // 44 - "J", // 45 - "K", // 46 - "L", // 47 - "M", // 48 - "N", // 49 - "O", // 50 - "P", // 51 - "Q", // 52 - "R", // 53 - "S", // 54 - "T", // 55 - "U", // 56 - "V", // 57 - "W", // 58 - "X", // 59 - "Y", // 60 - "Z", // 61 - "bracketleft", // 62 - "backslash", // 63 - "bracketright", // 64 - "asciicircum", // 65 - "underscore", // 66 - "grave", // 67 - "a", // 68 - "b", // 69 - "c", // 70 - "d", // 71 - "e", // 72 - "f", // 73 - "g", // 74 - "h", // 75 - "i", // 76 - "j", // 77 - "k", // 78 - "l", // 79 - "m", // 80 - "n", // 81 - "o", // 82 - "p", // 83 - "q", // 84 - "r", // 85 - "s", // 86 - "t", // 87 - "u", // 88 - "v", // 89 - "w", // 90 - "x", // 91 - "y", // 92 - "z", // 93 - "braceleft", // 94 - "bar", // 95 - "braceright", // 96 - "asciitilde", // 97 - "Adieresis", // 98 - "Aring", // 99 - "Ccedilla", // 100 - "Eacute", // 101 - "Ntilde", // 102 - "Odieresis", // 103 - "Udieresis", // 104 - "aacute", // 105 - "agrave", // 106 - "acircumflex", // 107 - "adieresis", // 108 - "atilde", // 109 - "aring", // 110 - "ccedilla", // 111 - "eacute", // 112 - "egrave", // 113 - "ecircumflex", // 114 - "edieresis", // 115 - "iacute", // 116 - "igrave", // 117 - "icircumflex", // 118 - "idieresis", // 119 - "ntilde", // 120 - "oacute", // 121 - "ograve", // 122 - "ocircumflex", // 123 - "odieresis", // 124 - "otilde", // 125 - "uacute", // 126 - "ugrave", // 127 - "ucircumflex", // 128 - "udieresis", // 129 - "dagger", // 130 - "degree", // 131 - "cent", // 132 - "sterling", // 133 - "section", // 134 - "bullet", // 135 - "paragraph", // 136 - "germandbls", // 137 - "registered", // 138 - "copyright", // 139 - "trademark", // 140 - "acute", // 141 - "dieresis", // 142 - "notequal", // 143 - "AE", // 144 - "Oslash", // 145 - "infinity", // 146 - "plusminus", // 147 - "lessequal", // 148 - "greaterequal", // 149 - "yen", // 150 - "mu", // 151 - "partialdiff", // 152 - "summation", // 153 - "product", // 154 - "pi", // 155 - "integral'", // 156 - "ordfeminine", // 157 - "ordmasculine", // 158 - "Omega", // 159 - "ae", // 160 - "oslash", // 161 - "questiondown", // 162 - "exclamdown", // 163 - "logicalnot", // 164 - "radical", // 165 - "florin", // 166 - "approxequal", // 167 - "increment", // 168 - "guillemotleft",// 169 - "guillemotright",//170 - "ellipsis", // 171 - "nbspace", // 172 - "Agrave", // 173 - "Atilde", // 174 - "Otilde", // 175 - "OE", // 176 - "oe", // 177 - "endash", // 178 - "emdash", // 179 - "quotedblleft", // 180 - "quotedblright",// 181 - "quoteleft", // 182 - "quoteright", // 183 - "divide", // 184 - "lozenge", // 185 - "ydieresis", // 186 - "Ydieresis", // 187 - "fraction", // 188 - "currency", // 189 - "guilsinglleft",// 190 - "guilsinglright",//191 - "fi", // 192 - "fl", // 193 - "daggerdbl", // 194 - "middot", // 195 - "quotesinglbase",//196 - "quotedblbase", // 197 - "perthousand", // 198 - "Acircumflex", // 199 - "Ecircumflex", // 200 - "Aacute", // 201 - "Edieresis", // 202 - "Egrave", // 203 - "Iacute", // 204 - "Icircumflex", // 205 - "Idieresis", // 206 - "Igrave", // 207 - "Oacute", // 208 - "Ocircumflex", // 209 - "", // 210 - "Ograve", // 211 - "Uacute", // 212 - "Ucircumflex", // 213 - "Ugrave", // 214 - "dotlessi", // 215 - "circumflex", // 216 - "tilde", // 217 - "overscore", // 218 - "breve", // 219 - "dotaccent", // 220 - "ring", // 221 - "cedilla", // 222 - "hungarumlaut", // 223 - "ogonek", // 224 - "caron", // 225 - "Lslash", // 226 - "lslash", // 227 - "Scaron", // 228 - "scaron", // 229 - "Zcaron", // 230 - "zcaron", // 231 - "brokenbar", // 232 - "Eth", // 233 - "eth", // 234 - "Yacute", // 235 - "yacute", // 236 - "Thorn", // 237 - "thorn", // 238 - "minus", // 239 - "multiply", // 240 - "onesuperior", // 241 - "twosuperior", // 242 - "threesuperior",// 243 - "onehalf", // 244 - "onequarter", // 245 - "threequarters",// 246 - "franc", // 247 - "Gbreve", // 248 - "gbreve", // 249 - "Idot", // 250 - "Scedilla", // 251 - "scedilla", // 252 - "Cacute", // 253 - "cacute", // 254 - "Ccaron", // 255 - "ccaron", // 256 - "" // 257 - }; - - private DirectoryEntry de; - private int version; - private int italicAngle; - private short underlinePosition; - private short underlineThickness; - private int isFixedPitch; - private int minMemType42; - private int maxMemType42; - private int minMemType1; - private int maxMemType1; - - // v2 - private int numGlyphs; - private int[] glyphNameIndex; - private String[] psGlyphName; - - /** Creates new PostTable */ - protected PostTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - version = di.readInt(); - italicAngle = di.readInt(); - underlinePosition = di.readShort(); - underlineThickness = di.readShort(); - isFixedPitch = di.readInt(); - minMemType42 = di.readInt(); - maxMemType42 = di.readInt(); - minMemType1 = di.readInt(); - maxMemType1 = di.readInt(); - - if (version == 0x00020000) { - numGlyphs = di.readUnsignedShort(); - glyphNameIndex = new int[numGlyphs]; - for (int i = 0; i < numGlyphs; i++) { - glyphNameIndex[i] = di.readUnsignedShort(); - } - int h = highestGlyphNameIndex(); - if (h > 257) { - h -= 257; - psGlyphName = new String[h]; - for (int i = 0; i < h; i++) { - int len = di.readUnsignedByte(); - byte[] buf = new byte[len]; - di.readFully(buf); - psGlyphName[i] = new String(buf); - } - } - } else if (version == 0x00025000) { - } else if (version == 0x00030000) { - } - } - - public int getVersion() { - return version; - } - - private int highestGlyphNameIndex() { - int high = 0; - for (int i = 0; i < numGlyphs; i++) { - if (high < glyphNameIndex[i]) { - high = glyphNameIndex[i]; - } - } - return high; - } - - public String getGlyphName(int i) { - if (version == 0x00020000) { - return (glyphNameIndex[i] > 257) - ? psGlyphName[glyphNameIndex[i] - 258] - : macGlyphName[glyphNameIndex[i]]; - } else { - return null; - } - } - - private boolean isMacGlyphName(int i) { - if (version == 0x00020000) { - return glyphNameIndex[i] <= 257; - } else { - return false; - } - } - - /** Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return post; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'post' Table - PostScript Metrics\n---------------------------------\n") - .append("\n 'post' version: ").append(Fixed.floatValue(version)) - .append("\n italicAngle: ").append(Fixed.floatValue(italicAngle)) - .append("\n underlinePosition: ").append(underlinePosition) - .append("\n underlineThickness: ").append(underlineThickness) - .append("\n isFixedPitch: ").append(isFixedPitch) - .append("\n minMemType42: ").append(minMemType42) - .append("\n maxMemType42: ").append(maxMemType42) - .append("\n minMemType1: ").append(minMemType1) - .append("\n maxMemType1: ").append(maxMemType1); - - if (version == 0x00020000) { - sb.append("\n\n Format 2.0: Non-Standard (for PostScript) TrueType Glyph Set.\n"); - sb.append(" numGlyphs: ").append(numGlyphs).append("\n"); - for (int i = 0; i < numGlyphs; i++) { - sb.append(" Glyf ").append(i).append(" -> "); - if (isMacGlyphName(i)) { - sb.append("Mac Glyph # ").append(glyphNameIndex[i]) - .append(", '").append(macGlyphName[glyphNameIndex[i]]).append("'\n"); - } else { - sb.append("PSGlyf Name # ").append(glyphNameIndex[i] - 257) - .append(", name= '").append(psGlyphName[glyphNameIndex[i] - 258]).append("'\n"); - } - } - sb.append("\n Full List of PSGlyf Names\n ------------------------\n"); - for (int i = 0; i < psGlyphName.length; i++) { - sb.append(" PSGlyf Name # ").append(i + 1) - .append(": ").append(psGlyphName[i]) - .append("\n"); - } - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/PrepTable.java b/src/net/java/dev/typecast/ot/table/PrepTable.java deleted file mode 100644 index 938b9b840..000000000 --- a/src/net/java/dev/typecast/ot/table/PrepTable.java +++ /dev/null @@ -1,46 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; -import net.java.dev.typecast.ot.Disassembler; - -/** - * @version $Id: PrepTable.java,v 1.1.1.1 2004-12-05 23:14:57 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class PrepTable extends Program implements Table { - - private DirectoryEntry de; - - public PrepTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - readInstructions(di, de.getLength()); - } - - public int getType() { - return prep; - } - - public String toString() { - return Disassembler.disassemble(getInstructions(), 0); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - -} diff --git a/src/net/java/dev/typecast/ot/table/Program.java b/src/net/java/dev/typecast/ot/table/Program.java deleted file mode 100644 index d4dd094e2..000000000 --- a/src/net/java/dev/typecast/ot/table/Program.java +++ /dev/null @@ -1,40 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: Program.java,v 1.1.1.1 2004-12-05 23:14:57 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public abstract class Program { - - private short[] instructions; - - public short[] getInstructions() { - return instructions; - } - - protected void readInstructions(DataInput di, int count) throws IOException { - instructions = new short[count]; - for (int i = 0; i < count; i++) { - instructions[i] = (short) di.readUnsignedByte(); - } - } -/* - protected void readInstructions(ByteArrayInputStream bais, int count) { - instructions = new short[count]; - for (int i = 0; i < count; i++) { - instructions[i] = (short) bais.read(); - } - } -*/ -} diff --git a/src/net/java/dev/typecast/ot/table/RangeRecord.java b/src/net/java/dev/typecast/ot/table/RangeRecord.java deleted file mode 100644 index 3bcb9ccb5..000000000 --- a/src/net/java/dev/typecast/ot/table/RangeRecord.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * Coverage Index (GlyphID) = StartCoverageIndex + GlyphID - Start GlyphID - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: RangeRecord.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ - */ -public class RangeRecord { - - private int _start; - private int _end; - private int _startCoverageIndex; - - /** Creates new RangeRecord */ - public RangeRecord(DataInput di) throws IOException { - _start = di.readUnsignedShort(); - _end = di.readUnsignedShort(); - _startCoverageIndex = di.readUnsignedShort(); - } - - public boolean isInRange(int glyphId) { - return (_start <= glyphId && glyphId <= _end); - } - - public int getCoverageIndex(int glyphId) { - if (isInRange(glyphId)) { - return _startCoverageIndex + glyphId - _start; - } - return -1; - } - -} - diff --git a/src/net/java/dev/typecast/ot/table/Script.java b/src/net/java/dev/typecast/ot/table/Script.java deleted file mode 100644 index e3022c116..000000000 --- a/src/net/java/dev/typecast/ot/table/Script.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Script.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ - */ -public class Script { - - private int _defaultLangSysOffset; - private int _langSysCount; - private LangSysRecord[] _langSysRecords; - private LangSys _defaultLangSys; - private LangSys[] _langSys; - - /** Creates new ScriptTable */ - protected Script(DataInputStream dis, int offset) throws IOException { - - // Ensure we're in the right place - dis.reset(); - dis.skipBytes(offset); - - // Start reading - _defaultLangSysOffset = dis.readUnsignedShort(); - _langSysCount = dis.readUnsignedShort(); - if (_langSysCount > 0) { - _langSysRecords = new LangSysRecord[_langSysCount]; - for (int i = 0; i < _langSysCount; i++) { - _langSysRecords[i] = new LangSysRecord(dis); - } - } - - // Read the LangSys tables - if (_langSysCount > 0) { - _langSys = new LangSys[_langSysCount]; - for (int i = 0; i < _langSysCount; i++) { - dis.reset(); - dis.skipBytes(offset + _langSysRecords[i].getOffset()); - _langSys[i] = new LangSys(dis); - } - } - if (_defaultLangSysOffset > 0) { - dis.reset(); - dis.skipBytes(offset + _defaultLangSysOffset); - _defaultLangSys = new LangSys(dis); - } - } - - public int getLangSysCount() { - return _langSysCount; - } - - public LangSysRecord getLangSysRecord(int i) { - return _langSysRecords[i]; - } - - public LangSys getDefaultLangSys() { - return _defaultLangSys; - } - - public LangSys getLangSys(int i) { - return _langSys[i]; - } -} - diff --git a/src/net/java/dev/typecast/ot/table/ScriptList.java b/src/net/java/dev/typecast/ot/table/ScriptList.java deleted file mode 100644 index bd82a052f..000000000 --- a/src/net/java/dev/typecast/ot/table/ScriptList.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ScriptList.java,v 1.3 2007-01-24 09:54:44 davidsch Exp $ - */ -public class ScriptList { - - private int _scriptCount = 0; - private ScriptRecord[] _scriptRecords; - private Script[] _scripts; - - /** Creates new ScriptList */ - protected ScriptList(DataInputStream dis, int offset) throws IOException { - - // Ensure we're in the right place - dis.reset(); - dis.skipBytes(offset); - - // Start reading - _scriptCount = dis.readUnsignedShort(); - _scriptRecords = new ScriptRecord[_scriptCount]; - _scripts = new Script[_scriptCount]; - for (int i = 0; i < _scriptCount; i++) { - _scriptRecords[i] = new ScriptRecord(dis); - } - for (int i = 0; i < _scriptCount; i++) { - _scripts[i] = new Script(dis, offset + _scriptRecords[i].getOffset()); - } - } - - public int getScriptCount() { - return _scriptCount; - } - - public ScriptRecord getScriptRecord(int i) { - return _scriptRecords[i]; - } - - public Script getScript(int i) { - return _scripts[i]; - } - - public Script findScript(String tag) { - if (tag.length() != 4) { - return null; - } - int tagVal = ((tag.charAt(0)<<24) - | (tag.charAt(1)<<16) - | (tag.charAt(2)<<8) - | tag.charAt(3)); - for (int i = 0; i < _scriptCount; i++) { - if (_scriptRecords[i].getTag() == tagVal) { - return _scripts[i]; - } - } - return null; - } - -} - diff --git a/src/net/java/dev/typecast/ot/table/ScriptRecord.java b/src/net/java/dev/typecast/ot/table/ScriptRecord.java deleted file mode 100644 index aea0bf0df..000000000 --- a/src/net/java/dev/typecast/ot/table/ScriptRecord.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ScriptRecord.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ - */ -public class ScriptRecord { - - private int _tag; - private int _offset; - - /** Creates new ScriptRecord */ - protected ScriptRecord(DataInput di) throws IOException { - _tag = di.readInt(); - _offset = di.readUnsignedShort(); - } - - public int getTag() { - return _tag; - } - - public int getOffset() { - return _offset; - } - - public String getTagAsString() { - return new StringBuffer() - .append((char)((_tag>>24)&0xff)) - .append((char)((_tag>>16)&0xff)) - .append((char)((_tag>>8)&0xff)) - .append((char)((_tag)&0xff)) - .toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/ScriptTags.java b/src/net/java/dev/typecast/ot/table/ScriptTags.java deleted file mode 100644 index eeb4f8e25..000000000 --- a/src/net/java/dev/typecast/ot/table/ScriptTags.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -/** - * Definition of Script tags - * - * @version $Id: ScriptTags.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ - * @author <a href="mailto:[email protected]">Vincent Hardy</a> - */ -public interface ScriptTags { - public static final String SCRIPT_TAG_ARAB = "arab"; -} diff --git a/src/net/java/dev/typecast/ot/table/SignatureBlock.java b/src/net/java/dev/typecast/ot/table/SignatureBlock.java deleted file mode 100644 index 2e4acf525..000000000 --- a/src/net/java/dev/typecast/ot/table/SignatureBlock.java +++ /dev/null @@ -1,46 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.IOException; -import java.io.DataInput; - -/** - * - * @version $Id: SignatureBlock.java,v 1.1.1.1 2004-12-05 23:14:58 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class SignatureBlock { - - private int reserved1; - private int reserved2; - private int signatureLen; - private byte[] signature; - - /** Creates new SignatureBlock */ - protected SignatureBlock(DataInput di) throws IOException { - reserved1 = di.readUnsignedShort(); - reserved2 = di.readUnsignedShort(); - signatureLen = di.readInt(); - signature = new byte[signatureLen]; - di.readFully(signature); - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < signatureLen; i += 16) { - if (signatureLen - i >= 16) { - sb.append(new String(signature, i, 16)).append("\n"); - } else { - sb.append(new String(signature, i, signatureLen - i)).append("\n"); - } - } - return sb.toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/SingleSubst.java b/src/net/java/dev/typecast/ot/table/SingleSubst.java deleted file mode 100644 index 91c985883..000000000 --- a/src/net/java/dev/typecast/ot/table/SingleSubst.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: SingleSubst.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ - */ -public abstract class SingleSubst extends LookupSubtable { - - public abstract int getFormat(); - - public abstract int substitute(int glyphId); - - public static SingleSubst read(DataInputStream dis, int offset) throws IOException { - SingleSubst s = null; - dis.reset(); - dis.skipBytes(offset); - int format = dis.readUnsignedShort(); - if (format == 1) { - s = new SingleSubstFormat1(dis, offset); - } else if (format == 2) { - s = new SingleSubstFormat2(dis, offset); - } - return s; - } - -} - diff --git a/src/net/java/dev/typecast/ot/table/SingleSubstFormat1.java b/src/net/java/dev/typecast/ot/table/SingleSubstFormat1.java deleted file mode 100644 index 538c57f6d..000000000 --- a/src/net/java/dev/typecast/ot/table/SingleSubstFormat1.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: SingleSubstFormat1.java,v 1.2 2007-01-24 09:47:45 davidsch Exp $ - */ -public class SingleSubstFormat1 extends SingleSubst { - - private int _coverageOffset; - private short _deltaGlyphID; - private Coverage _coverage; - - /** Creates new SingleSubstFormat1 */ - protected SingleSubstFormat1(DataInputStream dis, int offset) throws IOException { - _coverageOffset = dis.readUnsignedShort(); - _deltaGlyphID = dis.readShort(); - dis.reset(); - dis.skipBytes(offset + _coverageOffset); - _coverage = Coverage.read(dis); - } - - public int getFormat() { - return 1; - } - - public int substitute(int glyphId) { - int i = _coverage.findGlyph(glyphId); - if (i > -1) { - return glyphId + _deltaGlyphID; - } - return glyphId; - } - - public String getTypeAsString() { - return "SingleSubstFormat1"; - } -} - diff --git a/src/net/java/dev/typecast/ot/table/SingleSubstFormat2.java b/src/net/java/dev/typecast/ot/table/SingleSubstFormat2.java deleted file mode 100644 index 74c68f71f..000000000 --- a/src/net/java/dev/typecast/ot/table/SingleSubstFormat2.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: SingleSubstFormat2.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ - */ -public class SingleSubstFormat2 extends SingleSubst { - - private int _coverageOffset; - private int _glyphCount; - private int[] _substitutes; - private Coverage _coverage; - - /** Creates new SingleSubstFormat2 */ - protected SingleSubstFormat2(DataInputStream dis, int offset) throws IOException { - _coverageOffset = dis.readUnsignedShort(); - _glyphCount = dis.readUnsignedShort(); - _substitutes = new int[_glyphCount]; - for (int i = 0; i < _glyphCount; i++) { - _substitutes[i] = dis.readUnsignedShort(); - } - dis.reset(); - dis.skipBytes(offset + _coverageOffset); - _coverage = Coverage.read(dis); - } - - public int getFormat() { - return 2; - } - - public int substitute(int glyphId) { - int i = _coverage.findGlyph(glyphId); - if (i > -1) { - return _substitutes[i]; - } - return glyphId; - } - - public String getTypeAsString() { - return "SingleSubstFormat2"; - } -} - diff --git a/src/net/java/dev/typecast/ot/table/TTCHeader.java b/src/net/java/dev/typecast/ot/table/TTCHeader.java deleted file mode 100644 index 2f38d33f4..000000000 --- a/src/net/java/dev/typecast/ot/table/TTCHeader.java +++ /dev/null @@ -1,59 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * - * @version $Id: TTCHeader.java,v 1.1.1.1 2004-12-05 23:15:01 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class TTCHeader { - - public static final int ttcf = 0x74746366; - - private int ttcTag; - private int version; - private int directoryCount; - private int[] tableDirectory; - private int dsigTag; - private int dsigLength; - private int dsigOffset; - - /** Creates new TTCHeader */ - public TTCHeader(DataInput di) throws IOException { - ttcTag = di.readInt(); - version = di.readInt(); - directoryCount = di.readInt(); - tableDirectory = new int[directoryCount]; - for (int i = 0; i < directoryCount; i++) { - tableDirectory[i] = di.readInt(); - } - if (version == 0x00010000) { - dsigTag = di.readInt(); - } - dsigLength = di.readInt(); - dsigOffset = di.readInt(); - } - - public int getDirectoryCount() { - return directoryCount; - } - - public int getTableDirectory(int i) { - return tableDirectory[i]; - } - - public static boolean isTTC(DataInput di) throws IOException { - int ttcTag = di.readInt(); - return ttcTag == ttcf; - } -} diff --git a/src/net/java/dev/typecast/ot/table/Table.java b/src/net/java/dev/typecast/ot/table/Table.java deleted file mode 100644 index ddbdc49e2..000000000 --- a/src/net/java/dev/typecast/ot/table/Table.java +++ /dev/null @@ -1,67 +0,0 @@ -/***************************************************************************** - * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * - *****************************************************************************/ - -package net.java.dev.typecast.ot.table; - -/** - * @version $Id: Table.java,v 1.1.1.1 2004-12-05 23:14:59 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public interface Table { - - // Table constants - public static final int BASE = 0x42415345; // Baseline data [OpenType] - public static final int CFF = 0x43464620; // PostScript font program (compact font format) [PostScript] - public static final int DSIG = 0x44534947; // Digital signature - public static final int EBDT = 0x45424454; // Embedded bitmap data - public static final int EBLC = 0x45424c43; // Embedded bitmap location data - public static final int EBSC = 0x45425343; // Embedded bitmap scaling data - public static final int GDEF = 0x47444546; // Glyph definition data [OpenType] - public static final int GPOS = 0x47504f53; // Glyph positioning data [OpenType] - public static final int GSUB = 0x47535542; // Glyph substitution data [OpenType] - public static final int JSTF = 0x4a535446; // Justification data [OpenType] - public static final int LTSH = 0x4c545348; // Linear threshold table - public static final int MMFX = 0x4d4d4658; // Multiple master font metrics [PostScript] - public static final int MMSD = 0x4d4d5344; // Multiple master supplementary data [PostScript] - public static final int OS_2 = 0x4f532f32; // OS/2 and Windows specific metrics [r] - public static final int PCLT = 0x50434c54; // PCL5 - public static final int VDMX = 0x56444d58; // Vertical Device Metrics table - public static final int cmap = 0x636d6170; // character to glyph mapping [r] - public static final int cvt = 0x63767420; // Control Value Table - public static final int fpgm = 0x6670676d; // font program - public static final int fvar = 0x66766172; // Apple's font variations table [PostScript] - public static final int gasp = 0x67617370; // grid-fitting and scan conversion procedure (grayscale) - public static final int glyf = 0x676c7966; // glyph data [r] - public static final int hdmx = 0x68646d78; // horizontal device metrics - public static final int head = 0x68656164; // font header [r] - public static final int hhea = 0x68686561; // horizontal header [r] - public static final int hmtx = 0x686d7478; // horizontal metrics [r] - public static final int kern = 0x6b65726e; // kerning - public static final int loca = 0x6c6f6361; // index to location [r] - public static final int maxp = 0x6d617870; // maximum profile [r] - public static final int name = 0x6e616d65; // naming table [r] - public static final int prep = 0x70726570; // CVT Program - public static final int post = 0x706f7374; // PostScript information [r] - public static final int vhea = 0x76686561; // Vertical Metrics header - public static final int vmtx = 0x766d7478; // Vertical Metrics - - /** - * Get the table type, as a table directory value. - * @return The table type - */ - public int getType(); - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry(); - -} diff --git a/src/net/java/dev/typecast/ot/table/TableDirectory.java b/src/net/java/dev/typecast/ot/table/TableDirectory.java deleted file mode 100644 index 2eff53dd9..000000000 --- a/src/net/java/dev/typecast/ot/table/TableDirectory.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; -import net.java.dev.typecast.ot.Fixed; - -/** - * @version $Id: TableDirectory.java,v 1.2 2004-12-09 23:46:21 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class TableDirectory { - - private int _version = 0; - private short _numTables = 0; - private short _searchRange = 0; - private short _entrySelector = 0; - private short _rangeShift = 0; - private DirectoryEntry[] _entries; - - public TableDirectory(DataInput di) throws IOException { - _version = di.readInt(); - _numTables = di.readShort(); - _searchRange = di.readShort(); - _entrySelector = di.readShort(); - _rangeShift = di.readShort(); - _entries = new DirectoryEntry[_numTables]; - for (int i = 0; i < _numTables; i++) { - _entries[i] = new DirectoryEntry(di); - } - } - - public DirectoryEntry getEntry(int index) { - return _entries[index]; - } - - public DirectoryEntry getEntryByTag(int tag) { - for (int i = 0; i < _numTables; i++) { - if (_entries[i].getTag() == tag) { - return _entries[i]; - } - } - return null; - } - - public short getEntrySelector() { - return _entrySelector; - } - - public short getNumTables() { - return _numTables; - } - - public short getRangeShift() { - return _rangeShift; - } - - public short getSearchRange() { - return _searchRange; - } - - public int getVersion() { - return _version; - } - - public String toString() { - StringBuffer sb = new StringBuffer() - .append("Offset Table\n------ -----") - .append("\n sfnt version: ").append(Fixed.floatValue(_version)) - .append("\n numTables = ").append(_numTables) - .append("\n searchRange = ").append(_searchRange) - .append("\n entrySelector = ").append(_entrySelector) - .append("\n rangeShift = ").append(_rangeShift) - .append("\n\n"); - for (int i = 0; i < _numTables; i++) { - sb.append(i).append(". ").append(_entries[i].toString()).append("\n"); - } - return sb.toString(); - } -} diff --git a/src/net/java/dev/typecast/ot/table/TableException.java b/src/net/java/dev/typecast/ot/table/TableException.java deleted file mode 100644 index 02bc49eb5..000000000 --- a/src/net/java/dev/typecast/ot/table/TableException.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * $Id: TableException.java,v 1.1.1.1 2004-12-05 23:15:00 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: TableException.java,v 1.1.1.1 2004-12-05 23:15:00 davidsch Exp $ - */ -public class TableException extends java.lang.Exception { - - private static final long serialVersionUID = 1L; - - /** - * Creates a new instance of <code>TableException</code> without detail message. - */ - public TableException() { - } - - - /** - * Constructs an instance of <code>TableException</code> with the specified detail message. - * @param msg the detail message. - */ - public TableException(String msg) { - super(msg); - } -} diff --git a/src/net/java/dev/typecast/ot/table/TableFactory.java b/src/net/java/dev/typecast/ot/table/TableFactory.java deleted file mode 100644 index 28a7a4a97..000000000 --- a/src/net/java/dev/typecast/ot/table/TableFactory.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see <http://www.apache.org/>. - -*/ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; -import net.java.dev.typecast.ot.OTFont; -import net.java.dev.typecast.ot.OTFontCollection; - -/** - * - * @version $Id: TableFactory.java,v 1.7 2007-02-05 12:39:51 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class TableFactory { - - public static Table create( - OTFontCollection fc, - OTFont font, - DirectoryEntry de, - DataInputStream dis) throws IOException { - Table t = null; - - // First, if we have a font collection, look for the table there - if (fc != null) { - t = fc.getTable(de); - if (t != null) { - return t; - } - } - - // Create the table - switch (de.getTag()) { - case Table.BASE: - t = new BaseTable(de, dis); - break; - case Table.CFF: - t = new CffTable(de, dis); - break; - case Table.DSIG: - t = new DsigTable(de, dis); - break; - case Table.EBDT: - break; - case Table.EBLC: - break; - case Table.EBSC: - break; - case Table.GDEF: - break; - case Table.GPOS: - t = new GposTable(de, dis); - break; - case Table.GSUB: - t = new GsubTable(de, dis); - break; - case Table.JSTF: - break; - case Table.LTSH: - t = new LtshTable(de, dis); - break; - case Table.MMFX: - break; - case Table.MMSD: - break; - case Table.OS_2: - t = new Os2Table(de, dis); - break; - case Table.PCLT: - t = new PcltTable(de, dis); - break; - case Table.VDMX: - t = new VdmxTable(de, dis); - break; - case Table.cmap: - t = new CmapTable(de, dis); - break; - case Table.cvt: - t = new CvtTable(de, dis); - break; - case Table.fpgm: - t = new FpgmTable(de, dis); - break; - case Table.fvar: - break; - case Table.gasp: - t = new GaspTable(de, dis); - break; - case Table.glyf: - t = new GlyfTable(de, dis, font.getMaxpTable(), font.getLocaTable()); - break; - case Table.hdmx: - t = new HdmxTable(de, dis, font.getMaxpTable()); - break; - case Table.head: - t = new HeadTable(de, dis); - break; - case Table.hhea: - t = new HheaTable(de, dis); - break; - case Table.hmtx: - t = new HmtxTable(de, dis, font.getHheaTable(), font.getMaxpTable()); - break; - case Table.kern: - t = new KernTable(de, dis); - break; - case Table.loca: - t = new LocaTable(de, dis, font.getHeadTable(), font.getMaxpTable()); - break; - case Table.maxp: - t = new MaxpTable(de, dis); - break; - case Table.name: - t = new NameTable(de, dis); - break; - case Table.prep: - t = new PrepTable(de, dis); - break; - case Table.post: - t = new PostTable(de, dis); - break; - case Table.vhea: - t = new VheaTable(de, dis); - break; - case Table.vmtx: - t = new VmtxTable(de, dis, font.getVheaTable(), font.getMaxpTable()); - break; - } - - // If we have a font collection, add this table to it - if ((fc != null) && (t != null)) { - fc.addTable(t); - } - return t; - } -} diff --git a/src/net/java/dev/typecast/ot/table/VdmxTable.java b/src/net/java/dev/typecast/ot/table/VdmxTable.java deleted file mode 100644 index 907133b6d..000000000 --- a/src/net/java/dev/typecast/ot/table/VdmxTable.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * $Id: VdmxTable.java,v 1.1 2007-01-30 05:25:35 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * The Vertical Device Metrics table for TrueType outlines. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: VdmxTable.java,v 1.1 2007-01-30 05:25:35 davidsch Exp $ - */ -public class VdmxTable implements Table { - - private class Ratio { - - private byte _bCharSet; - private byte _xRatio; - private byte _yStartRatio; - private byte _yEndRatio; - - protected Ratio(DataInput di) throws IOException { - _bCharSet = di.readByte(); - _xRatio = di.readByte(); - _yStartRatio = di.readByte(); - _yEndRatio = di.readByte(); - } - - public byte getBCharSet() { - return _bCharSet; - } - - public byte getXRatio() { - return _xRatio; - } - - public byte getYStartRatio() { - return _yStartRatio; - } - - public byte getYEndRatio() { - return _yEndRatio; - } - } - - private class VTableRecord { - - private int _yPelHeight; - private short _yMax; - private short _yMin; - - protected VTableRecord(DataInput di) throws IOException { - _yPelHeight = di.readUnsignedShort(); - _yMax = di.readShort(); - _yMin = di.readShort(); - } - - public int getYPelHeight() { - return _yPelHeight; - } - - public short getYMax() { - return _yMax; - } - - public short getYMin() { - return _yMin; - } - } - - private class Group { - - private int _recs; - private int _startsz; - private int _endsz; - private VTableRecord[] _entry; - - protected Group(DataInput di) throws IOException { - _recs = di.readUnsignedShort(); - _startsz = di.readUnsignedByte(); - _endsz = di.readUnsignedByte(); - _entry = new VTableRecord[_recs]; - for (int i = 0; i < _recs; ++i) { - _entry[i] = new VTableRecord(di); - } - } - - public int getRecs() { - return _recs; - } - - public int getStartSZ() { - return _startsz; - } - - public int getEndSZ() { - return _endsz; - } - - public VTableRecord[] getEntry() { - return _entry; - } - } - - private DirectoryEntry _de; - private int _version; - private int _numRecs; - private int _numRatios; - private Ratio[] _ratRange; - private int _offset[]; - private Group[] _groups; - - /** Creates a new instance of VdmxTable */ - protected VdmxTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); - _version = di.readUnsignedShort(); - _numRecs = di.readUnsignedShort(); - _numRatios = di.readUnsignedShort(); - _ratRange = new Ratio[_numRatios]; - for (int i = 0; i < _numRatios; ++i) { - _ratRange[i] = new Ratio(di); - } - _offset = new int[_numRatios]; - for (int i = 0; i < _numRatios; ++i) { - _offset[i] = di.readUnsignedShort(); - } - _groups = new Group[_numRecs]; - for (int i = 0; i < _numRecs; ++i) { - _groups[i] = new Group(di); - } - } - - public int getType() { - return VDMX; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'VDMX' Table - Precomputed Vertical Device Metrics\n") - .append("--------------------------------------------------\n") - .append(" Version: ").append(_version).append("\n") - .append(" Number of Hgt Records: ").append(_numRecs).append("\n") - .append(" Number of Ratio Records: ").append(_numRatios).append("\n"); - for (int i = 0; i < _numRatios; ++i) { - sb.append("\n Ratio Record #").append(i + 1).append("\n") - .append("\tCharSetId ").append(_ratRange[i].getBCharSet()).append("\n") - .append("\txRatio ").append(_ratRange[i].getXRatio()).append("\n") - .append("\tyStartRatio ").append(_ratRange[i].getYStartRatio()).append("\n") - .append("\tyEndRatio ").append(_ratRange[i].getYEndRatio()).append("\n") - .append("\tRecord Offset ").append(_offset[i]).append("\n"); - } - sb.append("\n VDMX Height Record Groups\n") - .append(" -------------------------\n"); - for (int i = 0; i < _numRecs; ++i) { - Group group = _groups[i]; - sb.append(" ").append(i + 1) - .append(". Number of Hgt Records ").append(group.getRecs()).append("\n") - .append(" Starting Y Pel Height ").append(group.getStartSZ()).append("\n") - .append(" Ending Y Pel Height ").append(group.getEndSZ()).append("\n"); - for (int j = 0; j < group.getRecs(); ++j) { - sb.append("\n ").append(j + 1) - .append(". Pel Height= ").append(group.getEntry()[j].getYPelHeight()).append("\n") - .append(" yMax= ").append(group.getEntry()[j].getYMax()).append("\n") - .append(" yMin= ").append(group.getEntry()[j].getYMin()).append("\n"); - } - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/VheaTable.java b/src/net/java/dev/typecast/ot/table/VheaTable.java deleted file mode 100644 index 3863080cf..000000000 --- a/src/net/java/dev/typecast/ot/table/VheaTable.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * $Id: VheaTable.java,v 1.1 2007-01-31 01:17:40 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; -import net.java.dev.typecast.ot.Fixed; - -/** - * Vertical Header Table - * @version $Id: VheaTable.java,v 1.1 2007-01-31 01:17:40 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class VheaTable implements Table { - - private DirectoryEntry _de; - private int _version; - private short _ascent; - private short _descent; - private short _lineGap; - private short _advanceHeightMax; - private short _minTopSideBearing; - private short _minBottomSideBearing; - private short _yMaxExtent; - private short _caretSlopeRise; - private short _caretSlopeRun; - private short _metricDataFormat; - private int _numberOfLongVerMetrics; - - protected VheaTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); - _version = di.readInt(); - _ascent = di.readShort(); - _descent = di.readShort(); - _lineGap = di.readShort(); - _advanceHeightMax = di.readShort(); - _minTopSideBearing = di.readShort(); - _minBottomSideBearing = di.readShort(); - _yMaxExtent = di.readShort(); - _caretSlopeRise = di.readShort(); - _caretSlopeRun = di.readShort(); - for (int i = 0; i < 5; ++i) { - di.readShort(); - } - _metricDataFormat = di.readShort(); - _numberOfLongVerMetrics = di.readUnsignedShort(); - } - - public short getAdvanceHeightMax() { - return _advanceHeightMax; - } - - public short getAscent() { - return _ascent; - } - - public short getCaretSlopeRise() { - return _caretSlopeRise; - } - - public short getCaretSlopeRun() { - return _caretSlopeRun; - } - - public short getDescent() { - return _descent; - } - - public short getLineGap() { - return _lineGap; - } - - public short getMetricDataFormat() { - return _metricDataFormat; - } - - public short getMinTopSideBearing() { - return _minTopSideBearing; - } - - public short getMinBottomSideBearing() { - return _minBottomSideBearing; - } - - public int getNumberOfLongVerMetrics() { - return _numberOfLongVerMetrics; - } - - public int getType() { - return vhea; - } - - public short getYMaxExtent() { - return _yMaxExtent; - } - - public String toString() { - return new StringBuffer() - .append("'vhea' Table - Vertical Header\n------------------------------") - .append("\n 'vhea' version: ").append(Fixed.floatValue(_version)) - .append("\n xAscender: ").append(_ascent) - .append("\n xDescender: ").append(_descent) - .append("\n xLineGap: ").append(_lineGap) - .append("\n advanceHeightMax: ").append(_advanceHeightMax) - .append("\n minTopSideBearing: ").append(_minTopSideBearing) - .append("\n minBottomSideBearing: ").append(_minBottomSideBearing) - .append("\n yMaxExtent: ").append(_yMaxExtent) - .append("\n horizCaretSlopeNum: ").append(_caretSlopeRise) - .append("\n horizCaretSlopeDenom: ").append(_caretSlopeRun) - .append("\n reserved0: 0") - .append("\n reserved1: 0") - .append("\n reserved2: 0") - .append("\n reserved3: 0") - .append("\n reserved4: 0") - .append("\n metricDataFormat: ").append(_metricDataFormat) - .append("\n numOf_LongVerMetrics: ").append(_numberOfLongVerMetrics) - .toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/ot/table/VmtxTable.java b/src/net/java/dev/typecast/ot/table/VmtxTable.java deleted file mode 100644 index b2d9a3c3e..000000000 --- a/src/net/java/dev/typecast/ot/table/VmtxTable.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * $Id: VmtxTable.java,v 1.1 2007-01-31 01:18:04 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * Vertical Metrics Table - * @version $Id: VmtxTable.java,v 1.1 2007-01-31 01:18:04 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class VmtxTable implements Table { - - private DirectoryEntry _de; - private int[] _vMetrics = null; - private short[] _topSideBearing = null; - - protected VmtxTable( - DirectoryEntry de, - DataInput di, - VheaTable vhea, - MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); - _vMetrics = new int[vhea.getNumberOfLongVerMetrics()]; - for (int i = 0; i < vhea.getNumberOfLongVerMetrics(); ++i) { - _vMetrics[i] = - di.readUnsignedByte()<<24 - | di.readUnsignedByte()<<16 - | di.readUnsignedByte()<<8 - | di.readUnsignedByte(); - } - int tsbCount = maxp.getNumGlyphs() - vhea.getNumberOfLongVerMetrics(); - _topSideBearing = new short[tsbCount]; - for (int i = 0; i < tsbCount; ++i) { - _topSideBearing[i] = di.readShort(); - } - } - - public int getAdvanceHeight(int i) { - if (_vMetrics == null) { - return 0; - } - if (i < _vMetrics.length) { - return _vMetrics[i] >> 16; - } else { - return _vMetrics[_vMetrics.length - 1] >> 16; - } - } - - public short getTopSideBearing(int i) { - if (_vMetrics == null) { - return 0; - } - if (i < _vMetrics.length) { - return (short)(_vMetrics[i] & 0xffff); - } else { - return _topSideBearing[i - _vMetrics.length]; - } - } - - public int getType() { - return vmtx; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("'vmtx' Table - Vertical Metrics\n-------------------------------\n"); - sb.append("Size = ").append(_de.getLength()).append(" bytes, ") - .append(_vMetrics.length).append(" entries\n"); - for (int i = 0; i < _vMetrics.length; i++) { - sb.append(" ").append(i) - .append(". advHeight: ").append(getAdvanceHeight(i)) - .append(", TSdBear: ").append(getTopSideBearing(i)) - .append("\n"); - } - for (int i = 0; i < _topSideBearing.length; i++) { - sb.append(" TSdBear ").append(i + _vMetrics.length) - .append(": ").append(_topSideBearing[i]) - .append("\n"); - } - return sb.toString(); - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } -} diff --git a/src/net/java/dev/typecast/t2/T2Interpreter.java b/src/net/java/dev/typecast/t2/T2Interpreter.java deleted file mode 100644 index 6ae59cf8d..000000000 --- a/src/net/java/dev/typecast/t2/T2Interpreter.java +++ /dev/null @@ -1,1043 +0,0 @@ -/* - * $Id: T2Interpreter.java,v 1.2 2007-07-26 11:10:18 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.t2; - -import java.util.ArrayList; - -import net.java.dev.typecast.ot.Point; - -import net.java.dev.typecast.ot.table.CharstringType2; - -/** - * Type 2 Charstring Interpreter. Operator descriptions are quoted from - * Adobe's Type 2 Charstring Format document -- 5117.Type2.pdf. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: T2Interpreter.java,v 1.2 2007-07-26 11:10:18 davidsch Exp $ - */ -public class T2Interpreter { - - private static final int ARGUMENT_STACK_LIMIT = 48; - private static final int SUBR_STACK_LIMIT = 10; - private static final int TRANSIENT_ARRAY_ELEMENT_COUNT = 32; - - private Number[] _argStack = new Number[ARGUMENT_STACK_LIMIT]; - private int _argStackIndex = 0; - private int[] _subrStack = new int[SUBR_STACK_LIMIT]; - private int _subrStackIndex = 0; - private Number[] _transientArray = new Number[TRANSIENT_ARRAY_ELEMENT_COUNT]; - - private ArrayList<Point> _points; - - /** Creates a new instance of T2Interpreter */ - public T2Interpreter() { - } - - /** - * Moves the current point to a position at the relative coordinates - * (dx1, dy1). - */ - private void _rmoveto() { - int dy1 = popArg().intValue(); - int dx1 = popArg().intValue(); - clearArg(); - Point lastPoint = getLastPoint(); - moveTo(lastPoint.x + dx1, lastPoint.y + dy1); - } - - /** - * Moves the current point dx1 units in the horizontal direction. - */ - private void _hmoveto() { - int dx1 = popArg().intValue(); - clearArg(); - Point lastPoint = getLastPoint(); - moveTo(lastPoint.x + dx1, lastPoint.y); - } - - /** - * Moves the current point dy1 units in the vertical direction. - */ - private void _vmoveto() { - int dy1 = popArg().intValue(); - clearArg(); - Point lastPoint = getLastPoint(); - moveTo(lastPoint.x, lastPoint.y + dy1); - } - - /** - * Appends a line from the current point to a position at the - * relative coordinates dxa, dya. Additional rlineto operations are - * performed for all subsequent argument pairs. The number of - * lines is determined from the number of arguments on the stack. - */ - private void _rlineto() { - int count = getArgCount() / 2; - int[] dx = new int[count]; - int[] dy = new int[count]; - for (int i = 0; i < count; ++i) { - dy[count - i - 1] = popArg().intValue(); - dx[count - i - 1] = popArg().intValue(); - } - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - lineTo(lastPoint.x + dx[i], lastPoint.y + dy[i]); - } - clearArg(); - } - - /** - * Appends a horizontal line of length dx1 to the current point. - * With an odd number of arguments, subsequent argument pairs - * are interpreted as alternating values of dy and dx, for which - * additional lineto operators draw alternating vertical and - * horizontal lines. With an even number of arguments, the - * arguments are interpreted as alternating horizontal and - * vertical lines. The number of lines is determined from the - * number of arguments on the stack. - */ - private void _hlineto() { - int count = getArgCount(); - Number[] nums = new Number[count]; - for (int i = 0; i < count; ++i) { - nums[count - i - 1] = popArg(); - } - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - if (i % 2 == 0) { - lineTo(lastPoint.x + nums[i].intValue(), lastPoint.y); - } else { - lineTo(lastPoint.x, lastPoint.y + nums[i].intValue()); - } - } - clearArg(); - } - - /** - * Appends a vertical line of length dy1 to the current point. With - * an odd number of arguments, subsequent argument pairs are - * interpreted as alternating values of dx and dy, for which - * additional lineto operators draw alternating horizontal and - * vertical lines. With an even number of arguments, the - * arguments are interpreted as alternating vertical and - * horizontal lines. The number of lines is determined from the - * number of arguments on the stack. - */ - private void _vlineto() { - int count = getArgCount(); - Number[] nums = new Number[count]; - for (int i = 0; i < count; ++i) { - nums[count - i - 1] = popArg(); - } - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - if (i % 2 == 0) { - lineTo(lastPoint.x, lastPoint.y + nums[i].intValue()); - } else { - lineTo(lastPoint.x + nums[i].intValue(), lastPoint.y); - } - } - clearArg(); - } - - /** - * Appends a Bezier curve, defined by dxa...dyc, to the current - * point. For each subsequent set of six arguments, an additional - * curve is appended to the current point. The number of curve - * segments is determined from the number of arguments on the - * number stack and is limited only by the size of the number - * stack. - */ - private void _rrcurveto() { - int count = getArgCount() / 6; - int[] dxa = new int[count]; - int[] dya = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; - int[] dyc = new int[count]; - for (int i = 0; i < count; ++i) { - dyc[count - i - 1] = popArg().intValue(); - dxc[count - i - 1] = popArg().intValue(); - dyb[count - i - 1] = popArg().intValue(); - dxb[count - i - 1] = popArg().intValue(); - dya[count - i - 1] = popArg().intValue(); - dxa[count - i - 1] = popArg().intValue(); - } - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x + dxa[i]; - int ya = lastPoint.y + dya[i]; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb + dxc[i]; - int yc = yb + dyc[i]; - curveTo(xa, ya, xb, yb, xc, yc); - } - clearArg(); - } - - /** - * Appends one or more Bezier curves, as described by the - * dxa...dxc set of arguments, to the current point. For each curve, - * if there are 4 arguments, the curve starts and ends horizontal. - * The first curve need not start horizontal (the odd argument - * case). Note the argument order for the odd argument case. - */ - private void _hhcurveto() { - int count = getArgCount() / 4; - int dy1 = 0; - int[] dxa = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; - for (int i = 0; i < count; ++i) { - dxc[count - i - 1] = popArg().intValue(); - dyb[count - i - 1] = popArg().intValue(); - dxb[count - i - 1] = popArg().intValue(); - dxa[count - i - 1] = popArg().intValue(); - } - if (getArgCount() == 1) { - dy1 = popArg().intValue(); - } - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x + dxa[i]; - int ya = lastPoint.y + (i == 0 ? dy1 : 0); - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb + dxc[i]; - int yc = yb; - curveTo(xa, ya, xb, yb, xc, yc); - } - clearArg(); - } - - /** - * Appends one or more Bezier curves to the current point. The - * tangent for the first Bezier must be horizontal, and the second - * must be vertical (except as noted below). - * If there is a multiple of four arguments, the curve starts - * horizontal and ends vertical. Note that the curves alternate - * between start horizontal, end vertical, and start vertical, and - * end horizontal. The last curve (the odd argument case) need not - * end horizontal/vertical. - */ - private void _hvcurveto() { - if (getArgCount() % 8 <= 1) { - int count = getArgCount() / 8; - int[] dxa = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dyc = new int[count]; - int[] dyd = new int[count]; - int[] dxe = new int[count]; - int[] dye = new int[count]; - int[] dxf = new int[count]; - int dyf = 0; - if (getArgCount() % 8 == 1) { - dyf = popArg().intValue(); - } - for (int i = 0; i < count; ++i) { - dxf[count - i - 1] = popArg().intValue(); - dye[count - i - 1] = popArg().intValue(); - dxe[count - i - 1] = popArg().intValue(); - dyd[count - i - 1] = popArg().intValue(); - dyc[count - i - 1] = popArg().intValue(); - dyb[count - i - 1] = popArg().intValue(); - dxb[count - i - 1] = popArg().intValue(); - dxa[count - i - 1] = popArg().intValue(); - } - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x + dxa[i]; - int ya = lastPoint.y; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb; - int yc = yb + dyc[i]; - int xd = xc; - int yd = yc + dyd[i]; - int xe = xd + dxe[i]; - int ye = yd + dye[i]; - int xf = xe + dxf[i]; - int yf = ye + dyf; - curveTo(xa, ya, xb, yb, xc, yc); - curveTo(xd, yd, xe, ye, xf, yf); - } - } else { - int count = getArgCount() / 8; - int[] dya = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; - int[] dxd = new int[count]; - int[] dxe = new int[count]; - int[] dye = new int[count]; - int[] dyf = new int[count]; - int dxf = 0; - if (getArgCount() % 8 == 1) { - dxf = popArg().intValue(); - } - for (int i = 0; i < count; ++i) { - dyf[count - i - 1] = popArg().intValue(); - dye[count - i - 1] = popArg().intValue(); - dxe[count - i - 1] = popArg().intValue(); - dxd[count - i - 1] = popArg().intValue(); - dxc[count - i - 1] = popArg().intValue(); - dyb[count - i - 1] = popArg().intValue(); - dxb[count - i - 1] = popArg().intValue(); - dya[count - i - 1] = popArg().intValue(); - } - int dy3 = popArg().intValue(); - int dy2 = popArg().intValue(); - int dx2 = popArg().intValue(); - int dx1 = popArg().intValue(); - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x; - int ya = lastPoint.y + dya[i]; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb + dxc[i]; - int yc = yb; - int xd = xc + dxd[i]; - int yd = yc; - int xe = xd + dxe[i]; - int ye = yd + dye[i]; - int xf = xe + dxf; - int yf = ye + dyf[i]; - curveTo(xa, ya, xb, yb, xc, yc); - curveTo(xd, yd, xe, ye, xf, yf); - - // What on earth do we do with dx1, dx2, dy2 and dy3? - } - } - clearArg(); - } - - /** - * Is equivalent to one rrcurveto for each set of six arguments - * dxa...dyc, followed by exactly one rlineto using the dxd, dyd - * arguments. The number of curves is determined from the count - * on the argument stack. - */ - private void _rcurveline() { - int count = (getArgCount() - 2) / 6; - int[] dxa = new int[count]; - int[] dya = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; - int[] dyc = new int[count]; - int dyd = popArg().intValue(); - int dxd = popArg().intValue(); - for (int i = 0; i < count; ++i) { - dyc[count - i - 1] = popArg().intValue(); - dxc[count - i - 1] = popArg().intValue(); - dyb[count - i - 1] = popArg().intValue(); - dxb[count - i - 1] = popArg().intValue(); - dya[count - i - 1] = popArg().intValue(); - dxa[count - i - 1] = popArg().intValue(); - } - int xc = 0; - int yc = 0; - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x + dxa[i]; - int ya = lastPoint.y + dya[i]; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - xc = xb + dxc[i]; - yc = yb + dyc[i]; - curveTo(xa, ya, xb, yb, xc, yc); - } - lineTo(xc + dxd, yc + dyd); - clearArg(); - } - - /** - * Is equivalent to one rlineto for each pair of arguments beyond - * the six arguments dxb...dyd needed for the one rrcurveto - * command. The number of lines is determined from the count of - * items on the argument stack. - */ - private void _rlinecurve() { - int count = (getArgCount() - 6) / 2; - int[] dxa = new int[count]; - int[] dya = new int[count]; - int dyd = popArg().intValue(); - int dxd = popArg().intValue(); - int dyc = popArg().intValue(); - int dxc = popArg().intValue(); - int dyb = popArg().intValue(); - int dxb = popArg().intValue(); - for (int i = 0; i < count; ++i) { - dya[count - i - 1] = popArg().intValue(); - dxa[count - i - 1] = popArg().intValue(); - } - int xa = 0; - int ya = 0; - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - xa = lastPoint.x + dxa[i]; - ya = lastPoint.y + dya[i]; - lineTo(xa, ya); - } - int xb = xa + dxb; - int yb = ya + dyb; - int xc = xb + dxc; - int yc = yb + dyc; - int xd = xc + dxd; - int yd = yc + dyd; - curveTo(xb, yb, xc, yc, xd, yd); - clearArg(); - } - - /** - * Appends one or more Bezier curves to the current point, where - * the first tangent is vertical and the second tangent is horizontal. - * This command is the complement of hvcurveto; see the - * description of hvcurveto for more information. - */ - private void _vhcurveto() { - if (getArgCount() % 8 <= 1) { - int count = getArgCount() / 8; - int[] dya = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; - int[] dxd = new int[count]; - int[] dxe = new int[count]; - int[] dye = new int[count]; - int[] dyf = new int[count]; - int dxf = 0; - if (getArgCount() % 8 == 1) { - dxf = popArg().intValue(); - } - for (int i = 0; i < count; ++i) { - dyf[count - i - 1] = popArg().intValue(); - dye[count - i - 1] = popArg().intValue(); - dxe[count - i - 1] = popArg().intValue(); - dxd[count - i - 1] = popArg().intValue(); - dxc[count - i - 1] = popArg().intValue(); - dyb[count - i - 1] = popArg().intValue(); - dxb[count - i - 1] = popArg().intValue(); - dya[count - i - 1] = popArg().intValue(); - } - for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x; - int ya = lastPoint.y + dya[i]; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb + dxc[i]; - int yc = yb; - int xd = xc + dxd[i]; - int yd = yc; - int xe = xd + dxe[i]; - int ye = yd + dye[i]; - int xf = xe + dxf; - int yf = ye + dyf[i]; - curveTo(xa, ya, xb, yb, xc, yc); - curveTo(xd, yd, xe, ye, xf, yf); - } - } else { - int foo = 0; - } - clearArg(); - } - - /** - * Appends one or more curves to the current point. If the argument - * count is a multiple of four, the curve starts and ends vertical. If - * the argument count is odd, the first curve does not begin with a - * vertical tangent. - */ - private void _vvcurveto() { - - clearArg(); - } - - /** - * Causes two B�zier curves, as described by the arguments (as - * shown in Figure 2 below), to be rendered as a straight line when - * the flex depth is less than fd /100 device pixels, and as curved lines - * when the flex depth is greater than or equal to fd/100 device - * pixels. - */ - private void _flex() { - - clearArg(); - } - - /** - * Causes the two curves described by the arguments dx1...dx6 to - * be rendered as a straight line when the flex depth is less than - * 0.5 (that is, fd is 50) device pixels, and as curved lines when the - * flex depth is greater than or equal to 0.5 device pixels. - */ - private void _hflex() { - - clearArg(); - } - - /** - * Causes the two curves described by the arguments to be - * rendered as a straight line when the flex depth is less than 0.5 - * device pixels, and as curved lines when the flex depth is greater - * than or equal to 0.5 device pixels. - */ - private void _hflex1() { - - clearArg(); - } - - /** - * Causes the two curves described by the arguments to be - * rendered as a straight line when the flex depth is less than 0.5 - * device pixels, and as curved lines when the flex depth is greater - * than or equal to 0.5 device pixels. - */ - private void _flex1() { - - clearArg(); - } - - /** - * Finishes a charstring outline definition, and must be the - * last operator in a character�s outline. - */ - private void _endchar() { - endContour(); - clearArg(); - } - - private void _hstem() { - - clearArg(); - } - - private void _vstem() { - - clearArg(); - } - - private void _hstemhm() { - - clearArg(); - } - - private void _vstemhm() { - - clearArg(); - } - - private void _hintmask() { - - clearArg(); - } - - private void _cntrmask() { - - clearArg(); - } - - /** - * Returns the absolute value of num. - */ - private void _abs() { - double num = popArg().doubleValue(); - pushArg(Math.abs(num)); - } - - /** - * Returns the sum of the two numbers num1 and num2. - */ - private void _add() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); - pushArg(num1 + num2); - } - - /** - * Returns the result of subtracting num2 from num1. - */ - private void _sub() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); - pushArg(num1 - num2); - } - - /** - * Returns the quotient of num1 divided by num2. The result is - * undefined if overflow occurs and is zero for underflow. - */ - private void _div() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); - pushArg(num1 / num2); - } - - /** - * Returns the negative of num. - */ - private void _neg() { - double num = popArg().doubleValue(); - pushArg(-num); - } - - /** - * Returns a pseudo random number num2 in the range (0,1], that - * is, greater than zero and less than or equal to one. - */ - private void _random() { - pushArg(1.0 - Math.random()); - } - - /** - * Returns the product of num1 and num2. If overflow occurs, the - * result is undefined, and zero is returned for underflow. - */ - private void _mul() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); - pushArg(num1 * num2); - } - - /** - * Returns the square root of num. If num is negative, the result is - * undefined. - */ - private void _sqrt() { - double num = popArg().doubleValue(); - pushArg(Math.sqrt(num)); - } - - /** - * Removes the top element num from the Type 2 argument stack. - */ - private void _drop() { - popArg(); - } - - /** - * Exchanges the top two elements on the argument stack. - */ - private void _exch() { - Number num2 = popArg(); - Number num1 = popArg(); - pushArg(num2); - pushArg(num1); - } - - /** - * Retrieves the element i from the top of the argument stack and - * pushes a copy of that element onto that stack. If i is negative, - * the top element is copied. If i is greater than X, the operation is - * undefined. - */ - private void _index() { - int i = popArg().intValue(); - Number[] nums = new Number[i]; - for (int j = 0; j < i; ++j) { - nums[j] = popArg(); - } - for (int j = i - 1; j >= 0; --j) { - pushArg(nums[j]); - } - pushArg(nums[i]); - } - - /** - * Performs a circular shift of the elements num(N�1) ... num0 on - * the argument stack by the amount J. Positive J indicates upward - * motion of the stack; negative J indicates downward motion. - * The value N must be a non-negative integer, otherwise the - * operation is undefined. - */ - private void _roll() { - int j = popArg().intValue(); - int n = popArg().intValue(); - Number[] nums = new Number[n]; - for (int i = 0; i < n; ++i) { - nums[i] = popArg(); - } - for (int i = n - 1; i >= 0; --i) { - pushArg(nums[(n + i + j) % n]); - } - } - - /** - * Duplicates the top element on the argument stack. - */ - private void _dup() { - Number any = popArg(); - pushArg(any); - pushArg(any); - } - - /** - * Stores val into the transient array at the location given by i. - */ - private void _put() { - int i = popArg().intValue(); - Number val = popArg(); - _transientArray[i] = val; - } - - /** - * Retrieves the value stored in the transient array at the location - * given by i and pushes the value onto the argument stack. If get - * is executed prior to put for i during execution of the current - * charstring, the value returned is undefined. - */ - private void _get() { - int i = popArg().intValue(); - pushArg(_transientArray[i]); - } - - /** - * Puts a 1 on the stack if num1 and num2 are both non-zero, and - * puts a 0 on the stack if either argument is zero. - */ - private void _and() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); - pushArg((num1!=0.0) && (num2!=0.0) ? 1 : 0); - } - - /** - * Puts a 1 on the stack if either num1 or num2 are non-zero, and - * puts a 0 on the stack if both arguments are zero. - */ - private void _or() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); - pushArg((num1!=0.0) || (num2!=0.0) ? 1 : 0); - } - - /** - * Returns a 0 if num1 is non-zero; returns a 1 if num1 is zero. - */ - private void _not() { - double num1 = popArg().doubleValue(); - pushArg((num1!=0.0) ? 0 : 1); - } - - /** - * Puts a 1 on the stack if num1 equals num2, otherwise a 0 (zero) - * is put on the stack. - */ - private void _eq() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); - pushArg(num1 == num2 ? 1 : 0); - } - - /** - * Leaves the value s1 on the stack if v1 ? v2, or leaves s2 on the - * stack if v1 > v2. The value of s1 and s2 is usually the biased - * number of a subroutine. - */ - private void _ifelse() { - double v2 = popArg().doubleValue(); - double v1 = popArg().doubleValue(); - Number s2 = popArg(); - Number s1 = popArg(); - pushArg(v1 <= v2 ? s1 : s2); - } - - /** - * Calls a charstring subroutine with index subr# (actually the subr - * number plus the subroutine bias number, as described in section - * 2.3) in the Subrs array. Each element of the Subrs array is a - * charstring encoded like any other charstring. Arguments - * pushed on the Type 2 argument stack prior to calling the - * subroutine, and results pushed on this stack by the subroutine, - * act according to the manner in which the subroutine is coded. - * Calling an undefined subr (gsubr) has undefined results. - */ - private void _callsubr() { - - } - - /** - * Operates in the same manner as callsubr except that it calls a - * global subroutine. - */ - private void _callgsubr() { - - } - - /** - * Returns from either a local or global charstring subroutine, and - * continues execution after the corresponding call(g)subr. - */ - private void _return() { - - } - - public Point[] execute(CharstringType2 cs) { - _points = new ArrayList<Point>(); - cs.resetIP(); - while (cs.moreBytes()) { - while (cs.isOperandAtIndex()) { - pushArg(cs.nextOperand()); - } - int operator = cs.nextByte(); - if (operator == 12) { - operator = cs.nextByte(); - - // Two-byte operators - switch (operator) { - case T2Mnemonic.AND: - _and(); - break; - case T2Mnemonic.OR: - _or(); - break; - case T2Mnemonic.NOT: - _not(); - break; - case T2Mnemonic.ABS: - _abs(); - break; - case T2Mnemonic.ADD: - _add(); - break; - case T2Mnemonic.SUB: - _sub(); - break; - case T2Mnemonic.DIV: - _div(); - break; - case T2Mnemonic.NEG: - _neg(); - break; - case T2Mnemonic.EQ: - _eq(); - break; - case T2Mnemonic.DROP: - _drop(); - break; - case T2Mnemonic.PUT: - _put(); - break; - case T2Mnemonic.GET: - _get(); - break; - case T2Mnemonic.IFELSE: - _ifelse(); - break; - case T2Mnemonic.RANDOM: - _random(); - break; - case T2Mnemonic.MUL: - _mul(); - break; - case T2Mnemonic.SQRT: - _sqrt(); - break; - case T2Mnemonic.DUP: - _dup(); - break; - case T2Mnemonic.EXCH: - _exch(); - break; - case T2Mnemonic.INDEX: - _index(); - break; - case T2Mnemonic.ROLL: - _roll(); - break; - case T2Mnemonic.HFLEX: - _hflex(); - break; - case T2Mnemonic.FLEX: - _flex(); - break; - case T2Mnemonic.HFLEX1: - _hflex1(); - break; - case T2Mnemonic.FLEX1: - _flex1(); - break; - default: - //throw new Exception(); - return null; - } - } else { - - // One-byte operators - switch (operator) { - case T2Mnemonic.HSTEM: - _hstem(); - break; - case T2Mnemonic.VSTEM: - _vstem(); - break; - case T2Mnemonic.VMOVETO: - _vmoveto(); - break; - case T2Mnemonic.RLINETO: - _rlineto(); - break; - case T2Mnemonic.HLINETO: - _hlineto(); - break; - case T2Mnemonic.VLINETO: - _vlineto(); - break; - case T2Mnemonic.RRCURVETO: - _rrcurveto(); - break; - case T2Mnemonic.CALLSUBR: - _callsubr(); - break; - case T2Mnemonic.RETURN: - _return(); - break; - case T2Mnemonic.ENDCHAR: - _endchar(); - break; - case T2Mnemonic.HSTEMHM: - _hstemhm(); - break; - case T2Mnemonic.HINTMASK: - _hintmask(); - break; - case T2Mnemonic.CNTRMASK: - _cntrmask(); - break; - case T2Mnemonic.RMOVETO: - _rmoveto(); - break; - case T2Mnemonic.HMOVETO: - _hmoveto(); - break; - case T2Mnemonic.VSTEMHM: - _vstemhm(); - break; - case T2Mnemonic.RCURVELINE: - _rcurveline(); - break; - case T2Mnemonic.RLINECURVE: - _rlinecurve(); - break; - case T2Mnemonic.VVCURVETO: - _vvcurveto(); - break; - case T2Mnemonic.HHCURVETO: - _hhcurveto(); - break; - case T2Mnemonic.CALLGSUBR: - _callgsubr(); - break; - case T2Mnemonic.VHCURVETO: - _vhcurveto(); - break; - case T2Mnemonic.HVCURVETO: - _hvcurveto(); - break; - default: - //throw new Exception(); - return null; - } - } - } - Point[] pointArray = new Point[_points.size()]; - _points.toArray(pointArray); - return pointArray; - } - - /** - * The number of arguments on the argument stack - */ - private int getArgCount() { - return _argStackIndex; - } - - /** - * Pop a value off the argument stack - */ - private Number popArg() { - return _argStack[--_argStackIndex]; - } - - /** - * Push a value on to the argument stack - */ - private void pushArg(Number n) { - _argStack[_argStackIndex++] = n; - } - - /** - * Pop a value off the subroutine stack - */ - private int popSubr() { - return _subrStack[--_subrStackIndex]; - } - - /** - * Push a value on to the subroutine stack - */ - private void pushSubr(int n) { - _subrStack[_subrStackIndex++] = n; - } - - /** - * Clear the argument stack - */ - private void clearArg() { - _argStackIndex = 0; - } - - private Point getLastPoint() { - int size = _points.size(); - if (size > 0) { - return _points.get(size - 1); - } else { - return new Point(0, 0, true, false); - } - } - - private void moveTo(int x, int y) { - endContour(); - _points.add(new Point(x, y, true, false)); - } - - private void lineTo(int x, int y) { - _points.add(new Point(x, y, true, false)); - } - - private void curveTo(int cx1, int cy1, int cx2, int cy2, int x, int y) { - _points.add(new Point(cx1, cy1, false, false)); - _points.add(new Point(cx2, cy2, false, false)); - _points.add(new Point(x, y, true, false)); - } - - private void endContour() { - Point lastPoint = getLastPoint(); - if (lastPoint != null) { - lastPoint.endOfContour = true; - } - } -} diff --git a/src/net/java/dev/typecast/t2/T2Mnemonic.java b/src/net/java/dev/typecast/t2/T2Mnemonic.java deleted file mode 100644 index 810aea159..000000000 --- a/src/net/java/dev/typecast/t2/T2Mnemonic.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * $Id: T2Mnemonic.java,v 1.1 2007-02-21 12:30:48 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2007 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.t2; - -/** - * The Mnemonic representations of the Type 2 charstring instruction set. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: T2Mnemonic.java,v 1.1 2007-02-21 12:30:48 davidsch Exp $ - */ -public class T2Mnemonic { - - /** - * One byte operators - */ - public static final short HSTEM = 0x01; - public static final short VSTEM = 0x03; - public static final short VMOVETO = 0x04; - public static final short RLINETO = 0x05; - public static final short HLINETO = 0x06; - public static final short VLINETO = 0x07; - public static final short RRCURVETO = 0x08; - public static final short CALLSUBR = 0x0a; - public static final short RETURN = 0x0b; - public static final short ESCAPE = 0x0c; - public static final short ENDCHAR = 0x0e; - public static final short HSTEMHM = 0x12; - public static final short HINTMASK = 0x13; - public static final short CNTRMASK = 0x14; - public static final short RMOVETO = 0x15; - public static final short HMOVETO = 0x16; - public static final short VSTEMHM = 0x17; - public static final short RCURVELINE = 0x18; - public static final short RLINECURVE = 0x19; - public static final short VVCURVETO = 0x1a; - public static final short HHCURVETO = 0x1b; - public static final short CALLGSUBR = 0x1d; - public static final short VHCURVETO = 0x1e; - public static final short HVCURVETO = 0x1f; - - /** - * Two byte operators - */ - public static final short DOTSECTION = 0x00; - public static final short AND = 0x03; - public static final short OR = 0x04; - public static final short NOT = 0x05; - public static final short ABS = 0x09; - public static final short ADD = 0x0a; - public static final short SUB = 0x0b; - public static final short DIV = 0x0c; - public static final short NEG = 0x0e; - public static final short EQ = 0x0f; - public static final short DROP = 0x12; - public static final short PUT = 0x14; - public static final short GET = 0x15; - public static final short IFELSE = 0x16; - public static final short RANDOM = 0x17; - public static final short MUL = 0x18; - public static final short SQRT = 0x1a; - public static final short DUP = 0x1b; - public static final short EXCH = 0x1c; - public static final short INDEX = 0x1d; - public static final short ROLL = 0x1e; - public static final short HFLEX = 0x22; - public static final short FLEX = 0x23; - public static final short HFLEX1 = 0x24; - public static final short FLEX1 = 0x25; -} diff --git a/src/net/java/dev/typecast/tt/engine/GraphicsState.java b/src/net/java/dev/typecast/tt/engine/GraphicsState.java deleted file mode 100644 index 1c36bd3de..000000000 --- a/src/net/java/dev/typecast/tt/engine/GraphicsState.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * $Id: GraphicsState.java,v 1.1.1.1 2004-12-05 23:15:01 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.tt.engine; - -/** - * Maintains the graphics state whilst interpreting hinting instructions. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GraphicsState.java,v 1.1.1.1 2004-12-05 23:15:01 davidsch Exp $ - */ -class GraphicsState { - - public boolean auto_flip = true; - public int control_value_cut_in = 0; - public int delta_base = 9; - public int delta_shift = 3; - public int dual_projection_vectors; - public int[] freedom_vector = new int[2]; - public int zp0 = 1; - public int zp1 = 1; - public int zp2 = 1; - public int instruction_control = 0; - public int loop = 1; - public int minimum_distance = 1; - public int[] projection_vector = new int[2]; - public int round_state = 1; - public int rp0 = 0; - public int rp1 = 0; - public int rp2 = 0; - public int scan_control = 0; - public int single_width_cut_in = 0; - public int single_width_value = 0; -} diff --git a/src/net/java/dev/typecast/tt/engine/Interpreter.java b/src/net/java/dev/typecast/tt/engine/Interpreter.java deleted file mode 100644 index 6f436d764..000000000 --- a/src/net/java/dev/typecast/tt/engine/Interpreter.java +++ /dev/null @@ -1,1357 +0,0 @@ -/* - * $Id: Interpreter.java,v 1.1.1.1 2004-12-05 23:15:05 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.tt.engine; - -import net.java.dev.typecast.ot.Mnemonic; -import net.java.dev.typecast.ot.Point; - -/** - * The interpreter shall remain ignorant of the table structure - the table - * data will be extracted by supporting classes, whether it be the Parser - * or some other. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Interpreter.java,v 1.1.1.1 2004-12-05 23:15:05 davidsch Exp $ - */ -public class Interpreter { - - private Parser parser = null; - private GraphicsState gs = new GraphicsState(); - private Point[][] zone = new Point[2][]; - private int[] stack = null; - private int[] store = null; - private int[] cvt = new int[256]; - private int[] functionMap = null; - private int stackIndex = 0; - private boolean inFuncDef = false; - - public Interpreter(int stackMax, int storeMax, int funcMax) { - zone[0] = new Point[256]; - zone[1] = new Point[256]; - stack = new int[stackMax]; - store = new int[storeMax]; - functionMap = new int[funcMax]; - } - - /** - * ABSolute value - */ - private void _abs() { - int n = pop(); - if (n >= 0) { - push(n); - } else { - push(-n); - } - } - - /** - * ADD - */ - private void _add() { - int n1 = pop(); - int n2 = pop(); - push(n2 + n1); - } - - private void _alignpts() { - pop(); - pop(); - } - - /** - * - * - * USES: loop - */ - private void _alignrp() { - while (gs.loop-- > 0) { - pop(); - } - gs.loop = 1; - } - - /** - * logical AND - */ - private void _and() { - int e2 = pop(); - int e1 = pop(); - push(((e1 != 0) && (e2 != 0)) ? 1 : 0); - } - - /** - * CALL function - */ - private void _call() { - execute(functionMap[pop()]); - } - - /** - * CEILING - */ - private void _ceiling() { - int n = pop(); - if (n >= 0) { - push((n & 0xffc0) + (((n & 0x3f) != 0) ? 0x40 : 0)); - } else { - push(n & 0xffc0); - } - } - - /** - * Copy the INDEXed element to the top of the stack - */ - private void _cindex() { - push(stack[stackIndex - pop()]); - } - - /** - * CLEAR the entire stack - */ - private void _clear() { - stackIndex = 0; - } - - private void _debug() { - pop(); - } - - /** - * DELTA exception C1 - */ - private void _deltac1() { - int n = pop(); - for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn - } - } - - /** - * DELTA exception C2 - */ - private void _deltac2() { - int n = pop(); - for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn - } - } - - /** - * DELTA exception C3 - */ - private void _deltac3() { - int n = pop(); - for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn - } - } - - /** - * DELTA exception P1 - */ - private void _deltap1() { - int n = pop(); - for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn - } - } - - /** - * DELTA exception P2 - */ - private void _deltap2() { - int n = pop(); - for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn - } - } - - /** - * DELTA exception P3 - */ - private void _deltap3() { - int n = pop(); - for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn - } - } - - /** - * Returns the DEPTH of the stack - */ - private void _depth() { - push(stackIndex); - } - - /** - * DIVide - */ - private void _div() { - int n1 = pop(); - int n2 = pop(); - push((n2 / n1) >> 6); - } - - /** - * DUPlicate top stack element - */ - private void _dup() { - int n = pop(); - push(n); - push(n); - } - - /** - * ELSE - */ - private int _else(int instructionIndex) { - return parser.handleElse(instructionIndex); - } - - /** - * EQual - */ - private void _eq() { - int e2 = pop(); - int e1 = pop(); - push((e1 == e2) ? 1 : 0); - } - - private void _even() { - pop(); - push(0); - } - - /** - * Function DEFinition - */ - private void _fdef(int instructionIndex) { - functionMap[pop()] = instructionIndex; - inFuncDef = true; - } - - /** - * Set the auto_FLIP boolean to OFF - */ - private void _flipoff() { - gs.auto_flip = false; - } - - /** - * Set the auto_FLIP boolean to ON - */ - private void _flipon() { - gs.auto_flip = true; - } - - /** - * FLIP PoinT - * - * USES: loop - */ - private void _flippt() { - while(gs.loop-- > 0) { - int index = pop(); - zone[gs.zp0][index].onCurve = !zone[gs.zp0][index].onCurve; - } - gs.loop = 1; - } - - /** - * FLIP RanGe OFF - */ - private void _fliprgoff() { - int end = pop(); - int start = pop(); - for (int i = start; i <= end; i++) { - zone[1][i].onCurve = false; - } - } - - /** - * FLIP RanGe ON - */ - private void _fliprgon() { - int end = pop(); - int start = pop(); - for (int i = start; i <= end; i++) { - zone[1][i].onCurve = true; - } - } - - /** - * FLOOR - */ - private void _floor() { - int n = pop(); - if (n >= 0) { - push(n & 0xffc0); - } else { - push((n & 0xffc0) - (((n & 0x3f) != 0) ? 0x40 : 0)); - } - } - - private void _gc(short param) { - pop(); - push(0); - } - - private void _getinfo() { - pop(); - push(0); - } - - /** - * Get Freedom_Vector - */ - private void _gfv() { - push(gs.freedom_vector[0]); - push(gs.freedom_vector[1]); - } - - /** - * Get Projection_Vector - */ - private void _gpv() { - push(gs.projection_vector[0]); - push(gs.projection_vector[1]); - } - - /** - * Greater Than - */ - private void _gt() { - int e2 = pop(); - int e1 = pop(); - push((e1 > e2) ? 1 : 0); - } - - /** - * Greater Than or EQual - */ - private void _gteq() { - int e2 = pop(); - int e1 = pop(); - push((e1 >= e2) ? 1 : 0); - } - - /** - * Instruction DEFinition - */ - private void _idef() { - pop(); - inFuncDef = true; - } - - /** - * IF test - */ - private int _if(int instructionIndex) { - return parser.handleIf(pop() != 0, instructionIndex); - } - - /** - * INSTruction Execution ConTRol - * - * INSTCTRL[] - * - * Code Range - * 0x8E - * - * Pops - * s: selector flag (int32) - * value: USHORT (padded to 32 bits) used to set value of instruction_control. - * - * Pushes - * - - * - * Sets - * instruction_control - * - * Sets the instruction control state variable making it possible to turn on or off - * the execution of instructions and to regulate use of parameters set in the CVT - * program. INSTCTRL[ ] can only be executed in the CVT program. - * - * This instruction clears and sets various control flags in the rasterizer. The - * selector flag determines valid values for the value argument. The value determines - * the new setting of the raterizer control flag. In version 1.0 there are only two - * flags in use: - * - * Selector flag 1 is used to inhibit grid-fitting. If s=1, valid values for the - * value argument are 0 (FALSE) and 1 (TRUE). If the value argument is set to TRUE - * (v=1), any instructions associated with glyphs will not be executed. For example, - * to inhibit grid-fitting when a glyph is being rotated or stretched, use the - * following sequence on the preprogram: - * - * PUSHB[000] 6 ; ask GETINFO to check for stretching or rotation - * GETINFO[] ; will push TRUE if glyph is stretched or rotated - * IF[] ; tests value at top of stack - * PUSHB[000] 1 ; value for INSTCTRL - * PUSHB[000] 1 ; selector for INSTCTRL - * INSTRCTRL[] ; based on selector and value will turn grid-fitting off - * EIF[] - * - * Selector flag 2 is used to establish that any parameters set in the CVT program - * should be ignored when instructions associated with glyphs are executed. These - * include, for example, the values for scantype and the CVT cut-in. If s=1, valid - * values for the value argument are 0 (FALSE) and 2 (TRUE). If the value argument is - * set to TRUE (v=2), the default values of those parameters will be used regardless - * of any changes that may have been made in those values by the preprogram. If the - * value argument is set to FALSE (v=0), parameter values changed by the CVT program - * will be used in glyph instructions. - */ - private void _instctrl() { - int s = pop(); - int v = pop(); - if (s == 1) { - gs.instruction_control |= v; - } else if (s == 2) { - gs.instruction_control |= v; - } - } - - private void _ip() { - pop(); - } - - private void _isect() { - pop(); - pop(); - pop(); - pop(); - pop(); - } - - private void _iup(short param) { - } - - /** - * JuMP Relative - */ - private int _jmpr(int instructionIndex) { - return instructionIndex += pop() - 1; - } - - /** - * Jump Relative On False - */ - private int _jrof(int instructionIndex) { - boolean test = pop() != 0; - int offset = pop(); - if (!test) { - instructionIndex += offset - 1; - } - return instructionIndex; - } - - /** - * Jump Relative On True - */ - private int _jrot(int instructionIndex) { - boolean test = pop() != 0; - int offset = pop(); - if (test) { - instructionIndex += offset - 1; - } - return instructionIndex; - } - - /** - * LOOP and CALL function - */ - private void _loopcall() { - int index = pop(); - int count = pop(); - for (int i = 0; i < count; i++) { - execute(functionMap[i]); - } - } - - /** - * Less Than - */ - private void _lt() { - int e2 = pop(); - int e1 = pop(); - push((e1 < e2) ? 1 : 0); - } - - /** - * Less Than or EQual - */ - private void _lteq() { - int e2 = pop(); - int e1 = pop(); - push((e1 <= e2) ? 1 : 0); - } - - /** - * MAXimum of top two stack elements - */ - private void _max() { - int n1 = pop(); - int n2 = pop(); - push((n1 > n2) ? n1 : n2); - } - - private void _md(short param) { - pop(); - pop(); - push(0); - } - - private void _mdap(short param) { - pop(); - } - - private void _mdrp(short param) { - pop(); - } - - private void _miap(short param) { - pop(); - pop(); - } - /** - * MINimum of top two stack elements - */ - private void _min() { - int n1 = pop(); - int n2 = pop(); - push((n1 < n2) ? n1 : n2); - } - - /** - * Move the INDEXed element to the top of the stack - */ - private void _mindex() { - // Move the indexed element to stackIndex, and shift the others down - int k = pop(); - int e = stack[stackIndex - k]; - for (int i = stackIndex - k; i < stackIndex - 1; i++) { - stack[i] = stack[i+1]; - } - stack[stackIndex - 1] = e; - } - - private void _mirp(short param) { - pop(); - pop(); - } - - private void _mppem() { - push(0); - } - - private void _mps() { - push(0); - } - - private void _msirp(short param) { - pop(); - pop(); - } - - /** - * MULtiply - */ - private void _mul() { - int n1 = pop(); - int n2 = pop(); - push((n1 * n2) >> 6); - } - - /** - * NEGate - */ - private void _neg() { - push(-pop()); - } - - /** - * Not EQual - */ - private void _neq() { - int e2 = pop(); - int e1 = pop(); - push((e1 != e2) ? 1 : 0); - } - - /** - * logical NOT - */ - private void _not() { - push((pop() != 0) ? 0 : 1); - } - - private void _nround(short param) { - pop(); - push(0); - } - - private void _odd() { - pop(); - push(0); - } - - /** - * logical OR - */ - private void _or() { - int e2 = pop(); - int e1 = pop(); - push(((e1 != 0) || (e2 != 0)) ? 1 : 0); - } - - /** - * PUSH N Bytes - * PUSH N Words - * PUSH Bytes - * PUSH Words - */ - private void _push(int[] data) { - for (int j = 0; j < data.length; j++) { - push(data[j]); - } - } - - /** - * Read Control Value Table - */ - private void _rcvt() { - push(cvt[pop()]); - } - - /** - * Round Down To Grid - */ - private void _rdtg() { - gs.round_state = 3; - } - - /** - * Round OFF - */ - private void _roff() { - gs.round_state = 5; - } - - /** - * ROLL the top three stack elements - */ - private void _roll() { - int a = pop(); - int b = pop(); - int c = pop(); - push(b); - push(a); - push(c); - } - - private void _round(short param) { - pop(); - push(0); - } - - /** - * Read Store - */ - private void _rs() { - push(store[pop()]); - } - - /** - * Round To Double Grid - */ - private void _rtdg() { - gs.round_state = 2; - } - - /** - * Round To Grid - */ - private void _rtg() { - gs.round_state = 1; - } - - /** - * Round To Half Grid - */ - private void _rthg() { - gs.round_state = 0; - } - - /** - * Round Up To Grid - */ - private void _rutg() { - gs.round_state = 4; - } - - private void _s45round() { - pop(); - } - - /** - * SCAN conversion ConTRoL - * - * SCANCTRL[ ] - * - * Code Range - * 0x85 - * - * Pops - * n: flags indicating when to turn on dropout control mode (16 bit word padded - * to 32 bits) - * - * Pushes - * - - * - * Sets - * scan_control - * - * SCANCTRL is used to set the value of the Graphics State variable scan_control - * which in turn determines whether the scan converter will activate dropout - * control for this glyph. Use of the dropout control mode is determined by three - * conditions: - * - * Is the glyph rotated? - * - * Is the glyph stretched? - * - * Is the current setting for ppem less than a specified threshold? - * - * The interpreter pops a word from the stack and looks at the lower 16 bits. - * - * Bits 0-7 represent the threshold value for ppem. A value of FF in bits 0-7 - * means invoke dropout_control for all sizes. A value of 0 in bits 0-7 means - * never invoke dropout_control. - * - * Bits 8-13 are used to turn on dropout_control in cases where the specified - * conditions are met. Bits 8, 9 and 10 are used to turn on the dropout_control - * mode (assuming other conditions do not block it). Bits 11, 12, and 13 are - * used to turn off the dropout mode unless other conditions force it. Bits 14 - * and 15 are reserved for future use. - * - * Bit Meaning if set - * --- -------------- - * 8 Set dropout_control to TRUE if other conditions do not block and ppem - * is less than or equal to the threshold value. - * - * 9 Set dropout_control to TRUE if other conditions do not block and the - * glyph is rotated. - * - * 10 Set dropout_control to TRUE if other conditions do not block and the - * glyph is stretched. - * - * 11 Set dropout_control to FALSE unless ppem is less than or equal to the - * threshold value. - * - * 12 Set dropout_control to FALSE unless the glyph is rotated. - * - * 13 Set dropout_control to FALSE unless the glyph is stretched. - * - * 14 Reserved for future use. - * - * 15 Reserved for future use. - * - * For example - * 0x0000 No dropout control is invoked - * 0x01FF Always do dropout control - * 0x0A10 Do dropout control if the glyph is rotated and has less than 16 - * pixels per-em - * - * The scan converter can operate in either a "normal" mode or in a "fix dropout" - * mode depending on the value of a set of enabling and disabling flags. - */ - private void _scanctrl() { - gs.scan_control = pop(); - } - - /** - * SCANTYPE - * - * SCANTYPE[] - * - * Code Range - * 0x8D - * - * Pops - * n: 16 bit integer - * - * Pushes - * - - * - * Sets - * scan_control - * - * Pops a 16-bit integer whose value is used to determine which rules the scan - * converter will use. If the value of the argument is 0, the fast scan converter - * will be used. If the value of the integer is 1 or 2, simple dropout control will - * be used. If the value of the integer is 4 or 5, smart dropout control will be - * used. More specifically, - * - * if n=0 rules 1, 2, and 3 are invoked (simple dropout control scan conversion - * including stubs) - * - * if n=1 rules 1, 2, and 4 are invoked (simple dropout control scan conversion - * excluding stubs) - * - * if n=2 rules 1 and 2 only are invoked (fast scan conversion; dropout control - * turned off) - * - * if n=3 same as n = 2 - * - * if n = 4 rules 1, 2, and 5 are invoked (smart dropout control scan conversion - * including stubs) - * - * if n = 5 rules 1, 2, and 6 are invoked (smart dropout control scan conversion - * excluding stubs) - * - * if n = 6 same as n = 2 - * - * if n = 7 same as n = 2 - * - * The scan conversion rules are shown here: - * - * Rule 1 - * If a pixel's center falls within the glyph outline, that pixel is turned on. - * - * Rule 2 - * If a contour falls exactly on a pixel's center, that pixel is turned on. - * - * Rule 3 - * If a scan line between two adjacent pixel centers (either vertical or - * horizontal) is intersected by both an on-Transition contour and an off-Transition - * contour and neither of the pixels was already turned on by rules 1 and 2, turn on - * the left-most pixel (horizontal scan line) or the bottom-most pixel (vertical scan - * line). This is "Simple" dropout control. - * - * Rule 4 - * Apply Rule 3 only if the two contours continue to intersect other scan lines in - * both directions. That is, do not turn on pixels for 'stubs.' The scanline segments - * that form a square with the intersected scan line segment are examined to verify - * that they are intersected by two contours. It is possible that these could be - * different contours than the ones intersecting the dropout scan line segment. This - * is very unlikely but may have to be controlled with grid-fitting in some exotic - * glyphs. - * - * Rule 5 - * If a scan line between two adjacent pixel centers (either vertical or horizontal) - * is intersected by both an on-Transition contour and an off-Transition contour and - * neither of the pixels was already turned on by rules 1 and 2, turn on the pixel - * which is closer to the midpoint between the on-Transition contour and off- - * Transition contour. This is "Smart" dropout control. - * - * Rule 6 - * Apply Rule 5 only if the two contours continue to intersect other scan lines in - * both directions. That is, do not turn on pixels for 'stubs.' - * - * New fonts wishing to use the new modes of the ScanType instruction, but still - * wishing to work correctly on old rasterizers that don't recognize the new modes - * should: - * - * First execute a ScanType instruction using an old mode which will give the best - * approximation to the desired new mode (e.g. Simple Stubs for Smart Stubs), and - * then - * - * Immediately execute another ScanType instruction with the desired new mode. - */ - private void _scantype() { - pop(); - } - - private void _scfs() { - pop(); - pop(); - } - - /** - * Set Control Value Table Cut In - */ - private void _scvtci() { - gs.control_value_cut_in = pop(); - } - - /** - * Set Delta_Base in the graphics state - */ - private void _sdb() { - gs.delta_base = pop(); - } - - /** - * Set Dual Projection_Vector To Line - */ - private void _sdpvtl(short param) { - pop(); - pop(); - } - - /** - * Set Delta_Shift in the graphics state - */ - private void _sds() { - gs.delta_shift = pop(); - } - - /** - * Set Freedom_Vector From Stack - */ - private void _sfvfs() { - gs.freedom_vector[1] = pop(); // y - gs.freedom_vector[0] = pop(); // x - } - - /* - * Set Freedom_Vector to Coordinate Axis - */ - private void _sfvtca(short param) { - if (param == 1) { - gs.freedom_vector[0] = 0x4000; - gs.freedom_vector[1] = 0x0000; - } else { - gs.freedom_vector[0] = 0x0000; - gs.freedom_vector[1] = 0x4000; - } - } - - /* - * Set Freedom_Vector To Line - */ - private void _sfvtl(short param) { - pop(); - pop(); - if (param == 1) { - gs.freedom_vector[0] = 0x0000; - gs.freedom_vector[1] = 0x0000; - } else { - gs.freedom_vector[0] = 0x0000; - gs.freedom_vector[1] = 0x0000; - } - } - - /** - * Set Freedom_Vector To Projection Vector - */ - private void _sfvtpv() { - gs.freedom_vector[0] = gs.projection_vector[0]; - gs.freedom_vector[1] = gs.projection_vector[1]; - } - - private void _shc(short param) { - pop(); - } - - /** - * SHift Point by the last point - * - * USES: loop - */ - private void _shp(short param) { - while(gs.loop-- > 0) { - pop(); - if(param == 0) { - } else { - } - } - gs.loop = 1; - } - - /** - * SHift Point by a PIXel amount - * - * USES: loop - */ - private void _shpix() { - pop(); // amount - while (gs.loop-- > 0) { - pop(); // p - } - gs.loop = 1; - } - - private void _shz(short param) { - pop(); - } - - /** - * Set LOOP variable - */ - private void _sloop() { - gs.loop = pop(); - } - - /** - * Set Minimum_Distance - */ - private void _smd() { - gs.minimum_distance = pop(); - } - - /** - * Set Projection_Vector From Stack - */ - private void _spvfs() { - gs.projection_vector[1] = pop(); // y - gs.projection_vector[0] = pop(); // x - } - - /* - * Set Projection_Vector To Coordinate Axis - */ - private void _spvtca(short param) { - if (param == 1) { - gs.projection_vector[0] = 0x4000; - gs.projection_vector[1] = 0x0000; - } else { - gs.projection_vector[0] = 0x0000; - gs.projection_vector[1] = 0x4000; - } - } - - /** - * Set Projection_Vector To Line - */ - private void _spvtl(short param) { - - // We'll get a copy of the line and normalize it - - // divide the x- and y-coords by the vector's dot product. - Point p1 = zone[gs.zp2][pop()]; - Point p2 = zone[gs.zp1][pop()]; - int x = p2.x - p1.x; - int y = p2.y - p1.y; - if(param == 1) { - gs.projection_vector[0] = 0x0000; - gs.projection_vector[1] = 0x0000; - } else { - gs.projection_vector[0] = 0x0000; - gs.projection_vector[1] = 0x0000; - } - } - - private void _sround() { - pop(); - } - - /** - * Set Reference Point 0 - */ - private void _srp0() { - gs.rp0 = pop(); - } - - /** - * Set Reference Point 1 - */ - private void _srp1() { - gs.rp1 = pop(); - } - - /** - * Set Reference Point 2 - */ - private void _srp2() { - gs.rp2 = pop(); - } - - /** - * Set Single-Width - */ - private void _ssw() { - gs.single_width_value = pop(); - } - - /** - * Set Single_Width_Cut_In - */ - private void _sswci() { - gs.single_width_cut_in = pop(); - } - - /** - * SUBtract - */ - private void _sub() { - int n1 = pop(); - int n2 = pop(); - push(n2 - n1); - } - - /** - * Set freedom and projection Vectors To Coordinate Axis - */ - private void _svtca(short param) { - if (param == 1) { - gs.projection_vector[0] = 0x4000; - gs.projection_vector[1] = 0x0000; - gs.freedom_vector[0] = 0x4000; - gs.freedom_vector[1] = 0x0000; - } else { - gs.projection_vector[0] = 0x0000; - gs.projection_vector[1] = 0x4000; - gs.freedom_vector[0] = 0x0000; - gs.freedom_vector[1] = 0x4000; - } - } - - /** - * SWAP the top two elements on the stack - */ - private void _swap() { - int n1 = pop(); - int n2 = pop(); - push(n1); - push(n2); - } - - /** - * Set Zone Pointer 0 - */ - private void _szp0() { - gs.zp0 = pop(); - } - - /** - * Set Zone Pointer 1 - */ - private void _szp1() { - gs.zp1 = pop(); - } - - /** - * Set Zone Pointer 2 - */ - private void _szp2() { - gs.zp2 = pop(); - } - - /** - * Set Zone PointerS - */ - private void _szps() { - gs.zp0 = gs.zp1 = gs.zp2 = pop(); - } - - private void _utp() { - pop(); - } - - /** - * Write Control Value Table in FUnits - */ - private void _wcvtf() { - int value = pop(); - // Conversion of value goes here - cvt[pop()] = value; - } - - /** - * Write Control Value Table in Pixel units - */ - private void _wcvtp() { - int value = pop(); - // Conversion of value goes here - cvt[pop()] = value; - } - - /** - * Write Store - */ - private void _ws() { - store[pop()] = pop(); - } - - public void execute(int ip) { - while (ip < ((ip & 0xffff0000) | parser.getISLength(ip >> 16))) { - short opcode = parser.getOpcode(ip); - if (inFuncDef) { - - // We're within a function definition, so don't execute the code - if (opcode == Mnemonic.ENDF) { - inFuncDef = false; - } - ip = parser.advanceIP(ip); - continue; - } - if (opcode >= Mnemonic.MIRP) _mirp((short)(opcode & 31)); - else if (opcode >= Mnemonic.MDRP) _mdrp((short)(opcode & 31)); - else if (opcode >= Mnemonic.PUSHW) _push(parser.getPushData(ip)); - else if (opcode >= Mnemonic.PUSHB) _push(parser.getPushData(ip)); - else if (opcode >= Mnemonic.INSTCTRL) _instctrl(); - else if (opcode >= Mnemonic.SCANTYPE) _scantype(); - else if (opcode >= Mnemonic.MIN) _min(); - else if (opcode >= Mnemonic.MAX) _max(); - else if (opcode >= Mnemonic.ROLL) _roll(); - else if (opcode >= Mnemonic.IDEF) _idef(); - else if (opcode >= Mnemonic.GETINFO) _getinfo(); - else if (opcode >= Mnemonic.SDPVTL) _sdpvtl((short)(opcode & 1)); - else if (opcode >= Mnemonic.SCANCTRL) _scanctrl(); - else if (opcode >= Mnemonic.FLIPRGOFF) _fliprgoff(); - else if (opcode >= Mnemonic.FLIPRGON) _fliprgon(); - else if (opcode >= Mnemonic.FLIPPT) _flippt(); - else if (opcode >= Mnemonic.AA); // AA (ignored) - else if (opcode >= Mnemonic.SANGW); // SANGW (ignored) - else if (opcode >= Mnemonic.RDTG) _rdtg(); - else if (opcode >= Mnemonic.RUTG) _rutg(); - else if (opcode >= Mnemonic.ROFF) _roff(); - else if (opcode >= Mnemonic.JROF) ip = _jrof(ip); - else if (opcode >= Mnemonic.JROT) ip = _jrot(ip); - else if (opcode >= Mnemonic.S45ROUND) _s45round(); - else if (opcode >= Mnemonic.SROUND) _sround(); - else if (opcode >= Mnemonic.DELTAC3) _deltac3(); - else if (opcode >= Mnemonic.DELTAC2) _deltac2(); - else if (opcode >= Mnemonic.DELTAC1) _deltac1(); - else if (opcode >= Mnemonic.DELTAP3) _deltap3(); - else if (opcode >= Mnemonic.DELTAP2) _deltap2(); - else if (opcode >= Mnemonic.WCVTF) _wcvtf(); - else if (opcode >= Mnemonic.NROUND) _nround((short)(opcode & 3)); - else if (opcode >= Mnemonic.ROUND) _round((short)(opcode & 3)); - else if (opcode >= Mnemonic.CEILING) _ceiling(); - else if (opcode >= Mnemonic.FLOOR) _floor(); - else if (opcode >= Mnemonic.NEG) _neg(); - else if (opcode >= Mnemonic.ABS) _abs(); - else if (opcode >= Mnemonic.MUL) _mul(); - else if (opcode >= Mnemonic.DIV) _div(); - else if (opcode >= Mnemonic.SUB) _sub(); - else if (opcode >= Mnemonic.ADD) _add(); - else if (opcode >= Mnemonic.SDS) _sds(); - else if (opcode >= Mnemonic.SDB) _sdb(); - else if (opcode >= Mnemonic.DELTAP1) _deltap1(); - else if (opcode >= Mnemonic.NOT) _not(); - else if (opcode >= Mnemonic.OR) _or(); - else if (opcode >= Mnemonic.AND) _and(); - else if (opcode >= Mnemonic.EIF); // EIF - else if (opcode >= Mnemonic.IF) ip = _if(ip); - else if (opcode >= Mnemonic.EVEN) _even(); - else if (opcode >= Mnemonic.ODD) _odd(); - else if (opcode >= Mnemonic.NEQ) _neq(); - else if (opcode >= Mnemonic.EQ) _eq(); - else if (opcode >= Mnemonic.GTEQ) _gteq(); - else if (opcode >= Mnemonic.GT) _gt(); - else if (opcode >= Mnemonic.LTEQ) _lteq(); - else if (opcode >= Mnemonic.LT) _lt(); - else if (opcode >= Mnemonic.DEBUG) _debug(); - else if (opcode >= Mnemonic.FLIPOFF) _flipoff(); - else if (opcode >= Mnemonic.FLIPON) _flipon(); - else if (opcode >= Mnemonic.MPS) _mps(); - else if (opcode >= Mnemonic.MPPEM) _mppem(); - else if (opcode >= Mnemonic.MD) _md((short)(opcode & 1)); - else if (opcode >= Mnemonic.SCFS) _scfs(); - else if (opcode >= Mnemonic.GC) _gc((short)(opcode & 1)); - else if (opcode >= Mnemonic.RCVT) _rcvt(); - else if (opcode >= Mnemonic.WCVTP) _wcvtp(); - else if (opcode >= Mnemonic.RS) _rs(); - else if (opcode >= Mnemonic.WS) _ws(); - else if (opcode >= Mnemonic.NPUSHW) _push(parser.getPushData(ip)); - else if (opcode >= Mnemonic.NPUSHB) _push(parser.getPushData(ip)); - else if (opcode >= Mnemonic.MIAP) _miap((short)(opcode & 1)); - else if (opcode >= Mnemonic.RTDG) _rtdg(); - else if (opcode >= Mnemonic.ALIGNRP) _alignrp(); - else if (opcode >= Mnemonic.IP) _ip(); - else if (opcode >= Mnemonic.MSIRP) _msirp((short)(opcode & 1)); - else if (opcode >= Mnemonic.SHPIX) _shpix(); - else if (opcode >= Mnemonic.SHZ) _shz((short)(opcode & 1)); - else if (opcode >= Mnemonic.SHC) _shc((short)(opcode & 1)); - else if (opcode >= Mnemonic.SHP) _shp((short)(opcode & 1)); - else if (opcode >= Mnemonic.IUP) _iup((short)(opcode & 1)); - else if (opcode >= Mnemonic.MDAP) _mdap((short)(opcode & 1)); - else if (opcode >= Mnemonic.ENDF) return; - else if (opcode >= Mnemonic.FDEF) _fdef(ip + 1); - else if (opcode >= Mnemonic.CALL) _call(); - else if (opcode >= Mnemonic.LOOPCALL) _loopcall(); - else if (opcode >= Mnemonic.UTP) _utp(); - else if (opcode >= Mnemonic.ALIGNPTS) _alignpts(); - else if (opcode >= Mnemonic.MINDEX) _mindex(); - else if (opcode >= Mnemonic.CINDEX) _cindex(); - else if (opcode >= Mnemonic.DEPTH) _depth(); - else if (opcode >= Mnemonic.SWAP) _swap(); - else if (opcode >= Mnemonic.CLEAR) _clear(); - else if (opcode >= Mnemonic.POP) pop(); - else if (opcode >= Mnemonic.DUP) _dup(); - else if (opcode >= Mnemonic.SSW) _ssw(); - else if (opcode >= Mnemonic.SSWCI) _sswci(); - else if (opcode >= Mnemonic.SCVTCI) _scvtci(); - else if (opcode >= Mnemonic.JMPR) ip = _jmpr(ip); - else if (opcode >= Mnemonic.ELSE) ip = _else(ip); - else if (opcode >= Mnemonic.SMD) _smd(); - else if (opcode >= Mnemonic.RTHG) _rthg(); - else if (opcode >= Mnemonic.RTG) _rtg(); - else if (opcode >= Mnemonic.SLOOP) _sloop(); - else if (opcode >= Mnemonic.SZPS) _szps(); - else if (opcode >= Mnemonic.SZP2) _szp2(); - else if (opcode >= Mnemonic.SZP1) _szp1(); - else if (opcode >= Mnemonic.SZP0) _szp0(); - else if (opcode >= Mnemonic.SRP2) _srp2(); - else if (opcode >= Mnemonic.SRP1) _srp1(); - else if (opcode >= Mnemonic.SRP0) _srp0(); - else if (opcode >= Mnemonic.ISECT) _isect(); - else if (opcode >= Mnemonic.SFVTPV) _sfvtpv(); - else if (opcode >= Mnemonic.GFV) _gfv(); - else if (opcode >= Mnemonic.GPV) _gpv(); - else if (opcode >= Mnemonic.SFVFS) _sfvfs(); - else if (opcode >= Mnemonic.SPVFS) _spvfs(); - else if (opcode >= Mnemonic.SFVTL) _sfvtl((short)(opcode & 1)); - else if (opcode >= Mnemonic.SPVTL) _spvtl((short)(opcode & 1)); - else if (opcode >= Mnemonic.SFVTCA) _sfvtca((short)(opcode & 1)); - else if (opcode >= Mnemonic.SPVTCA) _spvtca((short)(opcode & 1)); - else if (opcode >= Mnemonic.SVTCA) _svtca((short)(opcode & 1)); - ip = parser.advanceIP(ip); - } - } - - public Point[][] getZones() { - return zone; - } - - private int pop() { - return stack[--stackIndex]; - } - - private void push(int i) { - stack[stackIndex++] = i; - } - - public void runCvtProgram() { - execute(0x00010000); - } - - public void runFontProgram() { - execute(0); - } - - public void runGlyphProgram() { - // instruction_control can be set to stop glyphs grid-fitting - if ((gs.instruction_control & 1) == 0) { - execute(0x00020000); - } - } - - public void setParser(Parser p) { - parser = p; - } -} diff --git a/src/net/java/dev/typecast/tt/engine/Parser.java b/src/net/java/dev/typecast/tt/engine/Parser.java deleted file mode 100644 index bfae53197..000000000 --- a/src/net/java/dev/typecast/tt/engine/Parser.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * $Id: Parser.java,v 1.1.1.1 2004-12-05 23:15:06 davidsch Exp $ - * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.java.dev.typecast.tt.engine; - -import net.java.dev.typecast.ot.Mnemonic; - -/** - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Parser.java,v 1.1.1.1 2004-12-05 23:15:06 davidsch Exp $ - */ -public class Parser { - - private short[][] instructions = new short[3][]; - - /** - * Advance the instruction pointer to the next executable opcode. - * This will be the next byte, unless the current opcode is a push - * instruction, in which case it will be the byte immediately beyond - * the last data byte. - * @param ip The current instruction pointer - * @return The new instruction pointer - */ - public int advanceIP(int ip) { - - // The high word specifies font, cvt, or glyph program - int prog = ip >> 16; - int i = ip & 0xffff; - int dataCount; - ip++; - if (Mnemonic.NPUSHB == instructions[prog][i]) { - // Next byte is the data byte count - dataCount = instructions[prog][++i]; - ip += dataCount + 1; - } else if (Mnemonic.NPUSHW == instructions[prog][i]) { - // Next byte is the data word count - dataCount = instructions[prog][++i]; - ip += dataCount*2 + 1; - } else if (Mnemonic.PUSHB == (instructions[prog][i] & 0xf8)) { - dataCount = (short)((instructions[prog][i] & 0x07) + 1); - ip += dataCount; - } else if (Mnemonic.PUSHW == (instructions[prog][i] & 0xf8)) { - dataCount = (short)((instructions[prog][i] & 0x07) + 1); - ip += dataCount*2; - } - return ip; - } - - public int getISLength(int prog) { - return instructions[prog].length; - } - - public short getOpcode(int ip) { - return instructions[ip >> 16][ip & 0xffff]; - } - - public short getPushCount(int ip) { - short instr = instructions[ip >> 16][ip & 0xffff]; - if ((Mnemonic.NPUSHB == instr) || (Mnemonic.NPUSHW == instr)) { - return instructions[ip >> 16][(ip & 0xffff) + 1]; - } else if ((Mnemonic.PUSHB == (instr & 0xf8)) || (Mnemonic.PUSHW == (instr & 0xf8))) { - return (short)((instr & 0x07) + 1); - } - return 0; - } - - public int[] getPushData(int ip) { - int count = getPushCount(ip); - int[] data = new int[count]; - int prog = ip >> 16; - int i = ip & 0xffff; - short instr = instructions[prog][i]; - if (Mnemonic.NPUSHB == instr) { - for (int j = 0; j < count; j++) { - data[j] = instructions[prog][i + j + 2]; - } - } else if (Mnemonic.PUSHB == (instr & 0xf8)) { - for (int j = 0; j < count; j++) { - data[j] = instructions[prog][i + j + 1]; - } - } else if (Mnemonic.NPUSHW == instr) { - for (int j = 0; j < count; j++) { - data[j] = (instructions[prog][i + j*2 + 2] << 8) | instructions[prog][i + j*2 + 3]; - } - } else if (Mnemonic.PUSHW == (instr & 0xf8)) { - for (int j = 0; j < count; j++) { - data[j] = (instructions[prog][i + j*2 + 1] << 8) | instructions[prog][i + j*2 + 2]; - } - } - return data; - } - - public int handleElse(int ip) { - while (instructions[ip >> 16][ip & 0xffff] != Mnemonic.EIF) { - ip = advanceIP(ip); - } - return ip; - } - - public int handleIf(boolean test, int ip) { - if (test == false) { - // The TrueType spec says that we merely jump to the *next* ELSE or EIF - // instruction in the instruction stream. So therefore no nesting! - // Looking at actual code, IF-ELSE-EIF can be nested! - while ((instructions[ip >> 16][ip & 0xffff] != Mnemonic.ELSE) - && (instructions[ip >> 16][ip & 0xffff] != Mnemonic.EIF)) { - ip = advanceIP(ip); - } - } - return ip; - } - - /** - * This program is run everytime we scale the font - */ - public void setCvtProgram(short[] program) { - instructions[1] = program; - } - - /** - * This program is only run once - */ - public void setFontProgram(short[] program) { - instructions[0] = program; - } - - /** - * This program is run everytime we scale the glyph - */ - public void setGlyphProgram(short[] program) { - instructions[2] = program; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - int ip = 0; - while (ip < instructions[0].length) { - sb.append(Mnemonic.getMnemonic(getOpcode(ip))); - if (getPushCount(ip) > 0) { - int[] data = getPushData(ip); - for(int j = 0; j < data.length; j++) - sb.append(" ").append(data[j]); - } - sb.append("\n"); - ip = advanceIP(ip); - } - sb.append("\n"); - ip = 0x10000; - while (ip < (0x10000 | instructions[1].length)) { - sb.append(Mnemonic.getMnemonic(getOpcode(ip))); - if(getPushCount(ip) > 0) { - int[] data = getPushData(ip); - for (int j = 0; j < data.length; j++) { - sb.append(" ").append(data[j]); - } - } - sb.append("\n"); - ip = advanceIP(ip); - } - sb.append("\n"); - ip = 0x20000; - while (ip < (0x20000 | instructions[2].length)) { - sb.append(Mnemonic.getMnemonic(getOpcode(ip))); - if (getPushCount(ip) > 0) { - int[] data = getPushData(ip); - for (int j = 0; j < data.length; j++) { - sb.append(" ").append(data[j]); - } - } - sb.append("\n"); - ip = advanceIP(ip); - } - return sb.toString(); - } -} diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java new file mode 100644 index 000000000..f879449b9 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/Display.java @@ -0,0 +1,230 @@ +/** + * 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.newt; + +import com.jogamp.newt.util.EDTUtil; +import jogamp.newt.Debug; +import jogamp.newt.DisplayImpl; + +import java.util.*; + +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowException; + +public abstract class Display { + public static final boolean DEBUG = Debug.debug("Display"); + + /** return precomputed hashCode from FQN {@link #getFQName()} */ + public abstract int hashCode(); + + /** return true if obj is of type Display and both FQN {@link #getFQName()} equals */ + public boolean equals(Object obj) { + if (this == obj) { return true; } + if (obj instanceof Display) { + Display d = (Display)obj; + return d.getFQName().equals(getFQName()); + } + return false; + } + + /** + * Manual trigger the native creation, if it is not done yet.<br> + * This is useful to be able to request the {@link javax.media.nativewindow.AbstractGraphicsDevice}, via + * {@link #getGraphicsDevice()}.<br> + * Otherwise the abstract device won't be available before the dependent components (Screen and Window) are realized. + * <p> + * This method is usually invoke by {@link #addReference()} + * </p> + * @throws NativeWindowException if the native creation failed. + */ + public abstract void createNative() throws NativeWindowException; + + /** + * Manually trigger the destruction, incl. native destruction.<br> + * <p> + * This method is usually invoke by {@link #removeReference()} + * </p> + */ + public abstract void destroy(); + + /** + * Validate EDT running state.<br> + * Stop the running EDT in case this display is destroyed already.<br> + * @return true if EDT has been stopped (destroyed but running), otherwise false. + */ + public abstract boolean validateEDT(); + + /** + * @return true if the native display handle is valid and ready to operate, + * otherwise false. + * + * @see #destroy() + */ + public abstract boolean isNativeValid(); + + /** + * @return number of references by Screen + */ + public abstract int getReferenceCount(); + + /** + * The 1st call will initiate native creation, + * since we follow the lazy creation pattern. + * + * @return number of references after adding one + * @throws NativeWindowException if the native creation failed. + * @see #removeReference() + */ + public abstract int addReference() throws NativeWindowException ; + + /** + * The last call may destroy this instance, + * if {@link #getDestroyWhenUnused()} returns <code>true</code>. + * + * @return number of references after removing one + * @see #addReference() + * @see #getDestroyWhenUnused() + * @see #setDestroyWhenUnused(boolean) + */ + public abstract int removeReference(); + + public abstract AbstractGraphicsDevice getGraphicsDevice(); + + /** + * @return the fully qualified Display name, + * which is a key of {@link #getType()} + {@link #getName()} + {@link #getId()} + */ + public abstract String getFQName(); + + public abstract long getHandle(); + + /** + * @return this display internal serial id + */ + public abstract int getId(); + + /** + * @return this display instance name as defined at creation time + */ + public abstract String getName(); + + /** + * @return the native display type, ie {@link javax.media.nativewindow.NativeWindowFactory#getNativeWindowType(boolean)} + */ + public abstract String getType(); + + public abstract EDTUtil getEDTUtil(); + + public abstract boolean isEDTRunning(); + + public abstract void dispatchMessages(); + + // Global Displays + protected static ArrayList displayList = new ArrayList(); + protected static int displaysActive = 0; + + public static void dumpDisplayList(String prefix) { + synchronized(displayList) { + Iterator i = displayList.iterator(); + System.err.println(prefix+" DisplayList[] entries: "+displayList.size()+" - "+getThreadName()); + for(int j=0; i.hasNext(); j++) { + DisplayImpl d = (DisplayImpl) i.next(); + System.err.println(" ["+j+"] : "+d); + } + } + } + + /** + * + * @param type + * @param name + * @param fromIndex start index, then increasing until found or end of list * + * @return + */ + public static Display getFirstDisplayOf(String type, String name, int fromIndex) { + return getDisplayOfImpl(type, name, fromIndex, 1); + } + + /** + * + * @param type + * @param name + * @param fromIndex start index, then decreasing until found or end of list. -1 is interpreted as size - 1. + * @return + */ + public static Display getLastDisplayOf(String type, String name, int fromIndex) { + return getDisplayOfImpl(type, name, fromIndex, -1); + } + + private static Display getDisplayOfImpl(String type, String name, int fromIndex, int incr) { + synchronized(displayList) { + int i = fromIndex >= 0 ? fromIndex : displayList.size() - 1 ; + while( ( incr > 0 ) ? i < displayList.size() : i >= 0 ) { + Display display = (Display) displayList.get(i); + if( display.getType().equals(type) && + display.getName().equals(name) ) { + return display; + } + i+=incr; + } + } + return null; + } + + /** Returns the global display collection */ + public static Collection getAllDisplays() { + ArrayList list; + synchronized(displayList) { + list = (ArrayList) displayList.clone(); + } + return list; + } + + public static int getActiveDisplayNumber() { + synchronized(displayList) { + return displaysActive; + } + } + + public static String getThreadName() { + return Thread.currentThread().getName(); + } + + public static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + public static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + + public static int hashCodeNullSafe(Object o) { + return ( null != o ) ? o.hashCode() : 0; + } +} diff --git a/src/newt/classes/com/jogamp/newt/NewtFactory.java b/src/newt/classes/com/jogamp/newt/NewtFactory.java new file mode 100644 index 000000000..4b7eedca2 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/NewtFactory.java @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt; + +import javax.media.nativewindow.*; +import com.jogamp.common.jvm.JVMUtil; +import com.jogamp.newt.event.WindowEvent; +import jogamp.newt.DisplayImpl; +import jogamp.newt.ScreenImpl; +import jogamp.newt.WindowImpl; +import jogamp.newt.Debug; + +public class NewtFactory { + public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); + + // Work-around for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod + static { + JVMUtil.initSingleton(); + NativeWindowFactory.initSingleton(false); // last resort .. + WindowImpl.init(NativeWindowFactory.getNativeWindowType(true)); + } + + public static Class getCustomClass(String packageName, String classBaseName) { + Class clazz = null; + if(packageName!=null || classBaseName!=null) { + String clazzName = packageName + "." + classBaseName ; + try { + clazz = Class.forName(clazzName); + } catch (Throwable t) {} + } + return clazz; + } + + private static boolean useEDT = true; + + /** + * Toggles the usage of an EventDispatchThread while creating a Display.<br> + * The default is enabled.<br> + * The EventDispatchThread is thread local to the Display instance.<br> + */ + public static synchronized void setUseEDT(boolean onoff) { + useEDT = onoff; + } + + /** @see #setUseEDT(boolean) */ + public static boolean useEDT() { return useEDT; } + + /** + * Create a Display entity, incl native creation + */ + public static Display createDisplay(String name) { + return createDisplay(name, true); + } + + public static Display createDisplay(String name, boolean reuse) { + return DisplayImpl.create(NativeWindowFactory.getNativeWindowType(true), name, 0, reuse); + } + + /** + * Create a Display entity using the given implementation type, incl native creation + */ + public static Display createDisplay(String type, String name) { + return createDisplay(type, name, true); + } + + public static Display createDisplay(String type, String name, boolean reuse) { + return DisplayImpl.create(type, name, 0, reuse); + } + + /** + * Create a Screen entity, incl native creation + */ + public static Screen createScreen(Display display, int index) { + return ScreenImpl.create(display, index); + } + + /** + * Create a top level Window entity, incl native creation.<br> + * The Display/Screen is created and owned, ie destructed atomatically.<br> + * A new Display is only created if no preexisting one could be found via {@link Display#getLastDisplayOf(java.lang.String, java.lang.String, int)}. + */ + public static Window createWindow(CapabilitiesImmutable caps) { + return createWindowImpl(NativeWindowFactory.getNativeWindowType(true), caps); + } + + /** + * Create a top level Window entity, incl native creation + */ + public static Window createWindow(Screen screen, CapabilitiesImmutable caps) { + return createWindowImpl(screen, caps); + } + + /** + * Create a child Window entity attached to the given parent, incl native creation.<br> + * The Screen and Display information is regenerated utilizing the parents information.<br> + * <p> + * In case <code>parentWindowObject</code> is a {@link com.jogamp.newt.Window} instance,<br> + * the new window is added to it's list of children.<br> + * This assures proper handling of visibility, creation and destruction.<br> + * {@link com.jogamp.newt.event.WindowEvent#EVENT_WINDOW_RESIZED} is not propagated to the child window for layout<br>, + * you have to add an appropriate {@link com.jogamp.newt.event.WindowListener} for this use case.<br> + * The parents visibility is passed to the new Window<br></p> + * <p> + * In case <code>parentWindowObject</code> is a different {@link javax.media.nativewindow.NativeWindow} implementation,<br> + * you have to handle all events appropriate.<br></p> + * <p> + * + * @param parentWindowObject either a NativeWindow instance + */ + public static Window createWindow(NativeWindow nParentWindow, CapabilitiesImmutable caps) { + final String type = NativeWindowFactory.getNativeWindowType(true); + + Screen screen = null; + Window parentWindow = null; + + if ( nParentWindow instanceof Window ) { + // use parent NEWT Windows Display/Screen + parentWindow = (Window) nParentWindow ; + screen = parentWindow.getScreen(); + } else { + // create a Display/Screen compatible to the NativeWindow + AbstractGraphicsConfiguration nParentConfig = nParentWindow.getGraphicsConfiguration(); + if(null!=nParentConfig) { + AbstractGraphicsScreen nParentScreen = nParentConfig.getScreen(); + AbstractGraphicsDevice nParentDevice = nParentScreen.getDevice(); + Display display = NewtFactory.createDisplay(type, nParentDevice.getHandle(), true); + screen = NewtFactory.createScreen(display, nParentScreen.getIndex()); + } else { + Display display = NewtFactory.createDisplay(type, null, true); // local display + screen = NewtFactory.createScreen(display, 0); // screen 0 + } + } + final Window win = createWindowImpl(nParentWindow, screen, caps); + + win.setSize(nParentWindow.getWidth(), nParentWindow.getHeight()); + if ( null != parentWindow ) { + parentWindow.addChild(win); + win.setVisible(parentWindow.isVisible()); + } + return win; + } + + protected static Window createWindowImpl(NativeWindow parentNativeWindow, Screen screen, CapabilitiesImmutable caps) { + return WindowImpl.create(parentNativeWindow, 0, screen, caps); + } + + protected static Window createWindowImpl(long parentWindowHandle, Screen screen, CapabilitiesImmutable caps) { + return WindowImpl.create(null, parentWindowHandle, screen, caps); + } + + protected static Window createWindowImpl(Screen screen, CapabilitiesImmutable caps) { + return WindowImpl.create(null, 0, screen, caps); + } + + protected static Window createWindowImpl(String type, CapabilitiesImmutable caps) { + Display display = NewtFactory.createDisplay(type, null, true); // local display + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + return WindowImpl.create(null, 0, screen, caps); + } + + /** + * Create a child Window entity attached to the given parent, incl native creation<br> + * + * @param parentWindowObject the native parent window handle + * @param undecorated only impacts if the window is in top-level state, while attached to a parent window it's rendered undecorated always + */ + public static Window createWindow(long parentWindowHandle, Screen screen, CapabilitiesImmutable caps) { + return createWindowImpl(parentWindowHandle, screen, caps); + } + + /** + * Ability to try a Window type with a constructor argument, if supported ..<p> + * Currently only valid is <code> AWTWindow(Frame frame) </code>, + * to support an external created AWT Frame, ie the browsers embedded frame. + * + * @param undecorated only impacts if the window is in top-level state, while attached to a parent window it's rendered undecorated always + */ + public static Window createWindow(Object[] cstrArguments, Screen screen, CapabilitiesImmutable caps) { + return WindowImpl.create(cstrArguments, screen, caps); + } + + /** + * Instantiate a Display entity using the native handle. + */ + public static Display createDisplay(String type, long handle, boolean reuse) { + return DisplayImpl.create(type, null, handle, false); + } + + private static boolean instanceOf(Object obj, String clazzName) { + Class clazz = obj.getClass(); + do { + if(clazz.getName().equals(clazzName)) { + return true; + } + clazz = clazz.getSuperclass(); + } while (clazz!=null); + return false; + } + + public static boolean isScreenCompatible(NativeWindow parent, Screen childScreen) { + // Get parent's NativeWindow details + AbstractGraphicsConfiguration parentConfig = (AbstractGraphicsConfiguration) parent.getGraphicsConfiguration(); + AbstractGraphicsScreen parentScreen = (AbstractGraphicsScreen) parentConfig.getScreen(); + AbstractGraphicsDevice parentDevice = (AbstractGraphicsDevice) parentScreen.getDevice(); + + DisplayImpl childDisplay = (DisplayImpl) childScreen.getDisplay(); + String parentDisplayName = childDisplay.validateDisplayName(null, parentDevice.getHandle()); + String childDisplayName = childDisplay.getName(); + if( ! parentDisplayName.equals( childDisplayName ) ) { + return false; + } + + if( parentScreen.getIndex() != childScreen.getIndex() ) { + return false; + } + return true; + } + + public static Screen createCompatibleScreen(NativeWindow parent) { + return createCompatibleScreen(parent, null); + } + + public static Screen createCompatibleScreen(NativeWindow parent, Screen childScreen) { + // Get parent's NativeWindow details + AbstractGraphicsConfiguration parentConfig = (AbstractGraphicsConfiguration) parent.getGraphicsConfiguration(); + AbstractGraphicsScreen parentScreen = (AbstractGraphicsScreen) parentConfig.getScreen(); + AbstractGraphicsDevice parentDevice = (AbstractGraphicsDevice) parentScreen.getDevice(); + + if(null != childScreen) { + // check if child Display/Screen is compatible already + DisplayImpl childDisplay = (DisplayImpl) childScreen.getDisplay(); + String parentDisplayName = childDisplay.validateDisplayName(null, parentDevice.getHandle()); + String childDisplayName = childDisplay.getName(); + boolean displayEqual = parentDisplayName.equals( childDisplayName ); + boolean screenEqual = parentScreen.getIndex() == childScreen.getIndex(); + if(DEBUG_IMPLEMENTATION) { + System.err.println("NewtFactory.createCompatibleScreen: Display: "+ + parentDisplayName+" =? "+childDisplayName+" : "+displayEqual+"; Screen: "+ + parentScreen.getIndex()+" =? "+childScreen.getIndex()+" : "+screenEqual); + } + if( displayEqual && screenEqual ) { + // match: display/screen + return childScreen; + } + } + + // Prep NEWT's Display and Screen according to the parent + final String type = NativeWindowFactory.getNativeWindowType(true); + Display display = NewtFactory.createDisplay(type, parentDevice.getHandle(), true); + return NewtFactory.createScreen(display, parentScreen.getIndex()); + } +} + diff --git a/src/newt/classes/com/jogamp/newt/NewtVersion.java b/src/newt/classes/com/jogamp/newt/NewtVersion.java new file mode 100644 index 000000000..961ffdf6a --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/NewtVersion.java @@ -0,0 +1,64 @@ +/** + * 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.newt; + +import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.util.JogampVersion; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.nativewindow.NativeWindowVersion; +import java.util.jar.Manifest; + +public class NewtVersion extends JogampVersion { + + protected static volatile NewtVersion jogampCommonVersionInfo; + + protected NewtVersion(String packageName, Manifest mf) { + super(packageName, mf); + } + + public static NewtVersion getInstance() { + if(null == jogampCommonVersionInfo) { // volatile: ok + synchronized(NewtVersion.class) { + if( null == jogampCommonVersionInfo ) { + final String packageName = "com.jogamp.newt"; + final Manifest mf = VersionUtil.getManifest(NewtVersion.class.getClassLoader(), packageName); + jogampCommonVersionInfo = new NewtVersion(packageName, mf); + } + } + } + return jogampCommonVersionInfo; + } + + public static void main(String args[]) { + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(GlueGenVersion.getInstance()); + System.err.println(NativeWindowVersion.getInstance()); + System.err.println(NewtVersion.getInstance()); + } +} diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java new file mode 100644 index 000000000..fec3613a2 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/Screen.java @@ -0,0 +1,236 @@ +/** + * 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.newt; + +import com.jogamp.newt.event.ScreenModeListener; +import jogamp.newt.Debug; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.NativeWindowException; + +public abstract class Screen { + + /** + * A 10s timeout for screen mode change. It is observed, that some platforms + * need a notable amount of time for this task, especially in case of rotation change. + */ + public static final int SCREEN_MODE_CHANGE_TIMEOUT = 10000; + + public static final boolean DEBUG = Debug.debug("Screen"); + + /** return precomputed hashCode from FQN {@link #getFQName()} */ + public abstract int hashCode(); + + /** return true if obj is of type Display and both FQN {@link #getFQName()} equals */ + public boolean equals(Object obj) { + if (this == obj) { return true; } + if (obj instanceof Screen) { + Screen s = (Screen)obj; + return s.getFQName().equals(getFQName()); + } + return false; + } + + /** + * Manual trigger the native creation, if it is not done yet..<br> + * This is useful to be able to request the {@link javax.media.nativewindow.AbstractGraphicsScreen}, via + * {@link #getGraphicsScreen()}.<br> + * Otherwise the abstract device won't be available before the dependent component (Window) is realized. + * <p> + * This method is usually invoke by {@link #addReference()} + * </p> + * <p> + * This method invokes {@link Display#addReference()} after creating the native peer,<br> + * which will issue {@link Display#createNative()} if the reference count was 0. + * </p> + * @throws NativeWindowException if the native creation failed. + */ + public abstract void createNative() throws NativeWindowException; + + /** + * Manually trigger the destruction, incl. native destruction.<br> + * <p> + * This method is usually invoke by {@link #removeReference()} + * </p> + * <p> + * This method invokes {@link Display#removeReference()} after it's own destruction,<br> + * which will issue {@link Display#destroy()} if the reference count becomes 0. + * </p> + */ + public abstract void destroy(); + + public abstract boolean isNativeValid(); + + /** + * @return number of references by Window + */ + public abstract int getReferenceCount(); + + /** + * See {@link Display#addReference()} + * + * @throws NativeWindowException if the native creation failed. + * @see #removeReference() + * @see #setDestroyWhenUnused(boolean) + * @see #getDestroyWhenUnused() + */ + public abstract int addReference() throws NativeWindowException; + + /** + * See {@link Display#removeReference()} + * + * @see #addReference() + * @see #setDestroyWhenUnused(boolean) + * @see #getDestroyWhenUnused() + */ + public abstract int removeReference(); + + public abstract AbstractGraphicsScreen getGraphicsScreen(); + + /** + * @return this Screen index of all Screens of {@link #getDisplay()}. + */ + public abstract int getIndex(); + + /** + * @return the current screen width + */ + public abstract int getWidth(); + + /** + * @return the current screen height + */ + public abstract int getHeight(); + + /** + * @return the associated Display + */ + public abstract Display getDisplay(); + + /** + * @return the screen fully qualified Screen name, + * which is a key of {@link com.jogamp.newt.Display#getFQName()} + {@link #getIndex()}. + */ + public abstract String getFQName(); + + /** + * @param sml ScreenModeListener to be added for ScreenMode change events + */ + public abstract void addScreenModeListener(ScreenModeListener sml); + + /** + * @param sml ScreenModeListener to be removed from ScreenMode change events + */ + public abstract void removeScreenModeListener(ScreenModeListener sml); + + /** + * Return a list of available {@link com.jogamp.newt.ScreenMode}s. + * @return a shallow copy of the internal immutable {@link com.jogamp.newt.ScreenMode}s, + * or null if not implemented for this native type {@link com.jogamp.newt.Display#getType()}. + */ + public abstract List/*<ScreenMode>*/ getScreenModes(); + + /** + * Return the original {@link com.jogamp.newt.ScreenMode}, as used at NEWT initialization. + * @return null if functionality not implemented, + * otherwise the original ScreenMode which is element of the list {@link #getScreenModes()}. + * + */ + public abstract ScreenMode getOriginalScreenMode(); + + /** + * Return the current {@link com.jogamp.newt.ScreenMode}. + * @return null if functionality not implemented, + * otherwise the current ScreenMode which is element of the list {@link #getScreenModes()}. + */ + public abstract ScreenMode getCurrentScreenMode(); + + /** + * Set the current {@link com.jogamp.newt.ScreenMode}. + * @param screenMode to be made current, must be element of the list {@link #getScreenModes()}. + * @return true if successful, otherwise false + */ + public abstract boolean setCurrentScreenMode(ScreenMode screenMode); + + // Global Screens + protected static ArrayList screenList = new ArrayList(); + protected static int screensActive = 0; + + /** + * + * @param type + * @param name + * @param fromIndex start index, then increasing until found or end of list * + * @return + */ + public static Screen getFirstScreenOf(Display display, int idx, int fromIndex) { + return getScreenOfImpl(display, idx, fromIndex, 1); + } + + /** + * + * @param type + * @param name + * @param fromIndex start index, then decreasing until found or end of list. -1 is interpreted as size - 1. + * @return + */ + public static Screen getLastScreenOf(Display display, int idx, int fromIndex) { + return getScreenOfImpl(display, idx, fromIndex, -1); + } + + private static Screen getScreenOfImpl(Display display, int idx, int fromIndex, int incr) { + synchronized(screenList) { + int i = fromIndex >= 0 ? fromIndex : screenList.size() - 1 ; + while( ( incr > 0 ) ? i < screenList.size() : i >= 0 ) { + Screen screen = (Screen) screenList.get(i); + if( screen.getDisplay().equals(display) && + screen.getIndex() == idx ) { + return screen; + } + i+=incr; + } + } + return null; + } + /** Returns the global display collection */ + public static Collection getAllScreens() { + ArrayList list; + synchronized(screenList) { + list = (ArrayList) screenList.clone(); + } + return list; + } + + public static int getActiveScreenNumber() { + synchronized(screenList) { + return screensActive; + } + } +} diff --git a/src/newt/classes/com/jogamp/newt/ScreenMode.java b/src/newt/classes/com/jogamp/newt/ScreenMode.java new file mode 100644 index 000000000..81ce70249 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/ScreenMode.java @@ -0,0 +1,189 @@ +/** + * 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.newt; + +import com.jogamp.newt.util.MonitorMode; + +/** Immutable ScreenMode Class, consisting of it's read only components:<br> + * <ul> + * <li>{@link com.jogamp.newt.util.MonitorMode}, non rotated values</li> + * <li><code>rotation</code>, measured counter clockwise (CCW)</li> + * </ul> + * + * <i>Aquire and filter ScreenModes</i><br> + * <ul> + * <li>A List of read only ScreenMode's is being returned by {@link com.jogamp.newt.Screen#getScreenModes()}.</li> + * <li>You may utilize {@link com.jogamp.newt.util.ScreenModeUtil} to filter and select a desired ScreenMode.</li> + * <li>The current ScreenMode can be obtained via {@link com.jogamp.newt.Screen#getCurrentScreenMode()}.</li> + * <li>The initial original ScreenMode (at startup) can be obtained via {@link com.jogamp.newt.Screen#getOriginalScreenMode()}.</li> + * </ul> + * <br> + * + * <i>Changing ScreenModes</i><br> + * <ul> + * <li> Use {@link com.jogamp.newt.Screen#setCurrentScreenMode(com.jogamp.newt.ScreenMode)}</li> + * to change the current ScreenMode of all Screen's referenced via the full qualified name (FQN) + * {@link com.jogamp.newt.Screen#getFQName()}.</li> + * <li> When the last FQN referenced Screen closes, the original ScreenMode ({@link com.jogamp.newt.Screen#getOriginalScreenMode()}) + * is restored.</li> + * </ul> + * <br> + * Example for changing the ScreenMode: + * <pre> + // determine target refresh rate + ScreenMode orig = screen.getOriginalScreenMode(); + int freq = orig.getMonitorMode().getRefreshRate(); + + // target resolution + Dimension res = new Dimension(800, 600); + + // target rotation + int rot = 0; + + // filter available ScreenModes + List screenModes = screen.getScreenModes(); + screenModes = ScreenModeUtil.filterByRate(screenModes, freq); // get the nearest ones + screenModes = ScreenModeUtil.filterByRotation(screenModes, rot); + screenModes = ScreenModeUtil.filterByResolution(screenModes, res); // get the nearest ones + screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); + + // pick 1st one .. + screen.setCurrentScreenMode((ScreenMode) screenModes.get(0)); + * </pre> + * + * X11 / AMD just works<br> + * <br> + * X11 / NVidia difficulties + * <pre> + NVidia RANDR RefreshRate Bug + If NVidia's 'DynamicTwinView' is enabled, all refresh rates are + unique, ie consequent numbers starting with the default refresh, ie 50, 51, .. + The only way to workaround it is to disable 'DynamicTwinView'. + Read: http://us.download.nvidia.com/XFree86/Linux-x86/260.19.12/README/configtwinview.html + + Check to see if 'DynamicTwinView' is enable: + nvidia-settings -q :0/DynamicTwinview + + To disable it (workaround), add the following option to your xorg.conf device section: + Option "DynamicTwinView" "False" + + NVidia RANDR Rotation: + To enable it, add the following option to your xorg.conf device section: + Option "RandRRotation" "on" + * </pre> + * + */ +public class ScreenMode implements Cloneable { + /** zero rotation, compared to normal settings */ + public static final int ROTATE_0 = 0; + + /** 90 degrees CCW rotation */ + public static final int ROTATE_90 = 90; + + /** 180 degrees CCW rotation */ + public static final int ROTATE_180 = 180; + + /** 270 degrees CCW rotation */ + public static final int ROTATE_270 = 270; + + MonitorMode monitorMode; + int rotation; + + public static boolean isRotationValid(int rotation) { + return rotation == ScreenMode.ROTATE_0 || rotation == ScreenMode.ROTATE_90 || + rotation == ScreenMode.ROTATE_180 || rotation == ScreenMode.ROTATE_270 ; + } + + /** + * @param monitorMode the monitor mode + * @param rotation the screen rotation, measured counter clockwise (CCW) + */ + public ScreenMode(MonitorMode monitorMode, int rotation) { + if ( !isRotationValid(rotation) ) { + throw new RuntimeException("invalid rotation: "+rotation); + } + this.monitorMode = monitorMode; + this.rotation = rotation; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + /** Returns the unrotated <code>MonitorMode</code> */ + public final MonitorMode getMonitorMode() { + return monitorMode; + } + + /** Returns the CCW rotation of this mode */ + public final int getRotation() { + return rotation; + } + + public final String toString() { + return "[ " + getMonitorMode() + ", " + rotation + " degr ]"; + } + + /** + * Tests equality of two <code>ScreenMode</code> objects + * by evaluating equality of it's components:<br> + * <ul> + * <li><code>monitorMode</code></li> + * <li><code>rotation</code></li> + * </ul> + * <br> + */ + public final boolean equals(Object obj) { + if (this == obj) { return true; } + if (obj instanceof ScreenMode) { + ScreenMode sm = (ScreenMode)obj; + return sm.getMonitorMode().equals(getMonitorMode()) && + sm.getRotation() == this.getRotation() ; + } + return false; + } + + /** + * Returns a combined hash code of it's elements:<br> + * <ul> + * <li><code>monitorMode</code></li> + * <li><code>rotation</code></li> + * </ul> + */ + public final int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + getMonitorMode().hashCode(); + hash = ((hash << 5) - hash) + getRotation(); + return hash; + } +} diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java new file mode 100644 index 000000000..b78f7a9e8 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -0,0 +1,422 @@ +/** + * 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.newt; + +import com.jogamp.newt.event.WindowListener; +import com.jogamp.newt.event.KeyListener; +import com.jogamp.newt.event.MouseListener; +import jogamp.newt.Debug; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.SurfaceUpdatedListener; +import javax.media.nativewindow.WindowClosingProtocol; +import javax.media.nativewindow.util.Insets; + +/** + * Specifying the public Window functionality for the + * using a Window and for shadowing one like {@link com.jogamp.newt.opengl.GLWindow}. + */ +public interface Window extends NativeWindow, WindowClosingProtocol { + public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent"); + public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent"); + public static final boolean DEBUG_WINDOW_EVENT = Debug.debug("Window.WindowEvent"); + public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); + + /** A 1s timeout while waiting for a native action response, ie {@link #setVisible(boolean)}. */ + public static final long TIMEOUT_NATIVEWINDOW = 1000; + + // + // Lifecycle + // + + /** + * @return True if native window is valid, can be created or recovered. + * Otherwise false, ie this window is unrecoverable due to a <code>destroy(true)</code> call. + * + * @see #destroy(boolean) + * @see #setVisible(boolean) + */ + boolean isValid(); + + /** + * @return true if the native window handle is valid and ready to operate, ie + * if the native window has been created, otherwise false. + * + * @see #setVisible(boolean) + * @see #destroy(boolean) + */ + boolean isNativeValid(); + + /** + * @return The associated Screen + */ + Screen getScreen(); + + /** + * Set the CapabilitiesChooser to help determine the native visual type. + * + * @param chooser the new CapabilitiesChooser + * @return the previous CapabilitiesChooser + */ + CapabilitiesChooser setCapabilitiesChooser(CapabilitiesChooser chooser); + + /** + * Gets an immutable set of requested capabilities. + * + * @return the requested capabilities + */ + CapabilitiesImmutable getRequestedCapabilities(); + + /** + * Gets an immutable set of chosen capabilities. + * + * @return the chosen capabilities + */ + CapabilitiesImmutable getChosenCapabilities(); + + /** + * Destroy the Window and it's children, incl. native destruction.<br> + * The Window can be recreate via {@link #setVisible(boolean) setVisible(true)}. + * <p> + * This method invokes {@link Screen#removeReference()} after it's own destruction,<br> + * which will issue {@link Screen#destroy()} if the reference count becomes 0.<br> + * This destruction sequence shall end up in {@link Display#destroy()}, if all reference counts become 0. + * </p> + * @see #invalidate() + * @see #setVisible(boolean) + */ + void destroy(); + + /** + * Destroys the Window via {@link #destroy()} and clears all Object references, + * eg. all states, size, position, parent handles, list of child Windows and reference to it's Screen.<br> + * This Window cannot be recreated after calling this method anymore.<br> + */ + void invalidate(); + + /** + * <p> + * <code>setVisible</code> makes the window and children visible if <code>visible</code> is true, + * otherwise the window and children becomes invisible.<br></p> + * <p> + * The <code>setVisible(true)</code> is responsible to actual create the native window.<br></p> + * <p> + * Zero size semantics are respected, see {@link #setSize(int,int)}:<br> + * <pre> + * if ( 0 == windowHandle && visible ) { + * this.visible = visible; + * if( 0<width*height ) { + * createNative(); + * } + * } else if ( this.visible != visible ) { + * this.visible = visible; + * setNativeSizeImpl(); + * } + * </pre></p> + * <p> + * In case this window is a child window and a parent {@link javax.media.nativewindow.NativeWindow} is being used,<br> + * the parent's {@link javax.media.nativewindow.NativeWindow} handle is retrieved via {@link javax.media.nativewindow.NativeWindow#getWindowHandle()}.<br> + * If this action fails, ie if the parent {@link javax.media.nativewindow.NativeWindow} is not valid yet,<br> + * no native window is created yet and <code>setVisible(true)</code> shall be repeated when it is.<br></p> + */ + void setVisible(boolean visible); + + boolean isVisible(); + + // + // Child Window Management + // + + void addChild(NativeWindow win); + + void removeChild(NativeWindow win); + + // + // Modes / States + // + + /** + * Sets the size of the client area of the window, excluding decorations + * Total size of the window will be + * {@code width+insets.left+insets.right, height+insets.top+insets.bottom}<br> + * <p> + * Zero size semantics are respected, see {@link #setVisible(boolean)}:<br> + * <pre> + * if ( 0 != windowHandle && 0>=width*height && visible ) { + * setVisible(false); + * } else if ( 0 == windowHandle && 0<width*height && visible ) { + * setVisible(true); + * } else { + * // as expected .. + * } + * </pre></p> + * <p> + * This call is ignored if in fullscreen mode.<br></p> + * + * @param width of the client area of the window + * @param height of the client area of the window + */ + void setSize(int width, int height); + + /** + * Returns the width of the client area of this window + * @return width of the client area + */ + int getWidth(); + + /** + * Returns the height of the client area of this window + * @return height of the client area + */ + int getHeight(); + + /** Defining ids for the reparenting strategy */ + public interface ReparentAction { + /** No native reparenting valid */ + static final int ACTION_INVALID = -1; + + /** No native reparenting action required, no change*/ + static final int ACTION_UNCHANGED = 0; + + /** Native reparenting incl. Window tree */ + static final int ACTION_NATIVE_REPARENTING = 1; + + /** Native window creation after tree change - instead of reparenting. */ + static final int ACTION_NATIVE_CREATION = 2; + + /** Change Window tree only, native creation is pending */ + static final int ACTION_NATIVE_CREATION_PENDING = 3; + } + + /** + * Change this window's parent window.<br> + * <P> + * In case the old parent is not null and a Window, + * this window is removed from it's list of children.<br> + * In case the new parent is not null and a Window, + * this window is added to it's list of children.<br></P> + * + * @param newParent The new parent NativeWindow. If null, this Window becomes a top level window. + * + * @return The issued reparent action type (strategy) as defined in Window.ReparentAction + */ + int reparentWindow(NativeWindow newParent); + + int reparentWindow(NativeWindow newParent, boolean forceDestroyCreate); + + boolean setFullscreen(boolean fullscreen); + + boolean isFullscreen(); + + /** + * Sets the location of the top left corner of the window, including + * decorations (so the client area will be placed at + * {@code x+insets.left,y+insets.top}.<br> + * + * This call is ignored if in fullscreen mode.<br> + * + * @param x coord of the top left corner + * @param y coord of the top left corner + */ + void setPosition(int x, int y); + + int getX(); + + int getY(); + + /** + * Returns the insets for this native window (the difference between the + * size of the toplevel window with the decorations and the client area). + * + * @return insets for this platform window + */ + Insets getInsets(); + + void setUndecorated(boolean value); + + boolean isUndecorated(); + + void setTitle(String title); + + String getTitle(); + + static interface FocusRunnable { + /** + * @return false if NEWT shall proceed requesting the focus, + * true if NEWT shall not request the focus. + */ + public boolean run(); + } + + /** + * May set to a {@link FocusRunnable}, {@link FocusRunnable#run()} before Newt requests the native focus. + * This allows notifying a covered window toolkit like AWT that the focus is requested, + * hence focus traversal can be made transparent. + */ + void setFocusAction(FocusRunnable focusAction); + + void requestFocus(); + + boolean hasFocus(); + + void windowRepaint(int x, int y, int width, int height); + + void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event); + + void runOnEDTIfAvail(boolean wait, final Runnable task); + + + // + // SurfaceUpdateListener + // + + /** + * Appends the given {@link com.jogamp.newt.event.SurfaceUpdatedListener} to the end of + * the list. + */ + void addSurfaceUpdatedListener(SurfaceUpdatedListener l); + + /** + * + * Inserts the given {@link com.jogamp.newt.event.SurfaceUpdatedListener} at the + * specified position in the list.<br> + * + * @param index Position where the listener will be inserted. + * Should be within (0 <= index && index <= size()). + * An index value of -1 is interpreted as the end of the list, size(). + * @param l The listener object to be inserted + * @throws IndexOutOfBoundsException If the index is not within (0 <= index && index <= size()), or -1 + */ + void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) throws IndexOutOfBoundsException; + + void removeAllSurfaceUpdatedListener(); + + void removeSurfaceUpdatedListener(SurfaceUpdatedListener l); + + SurfaceUpdatedListener getSurfaceUpdatedListener(int index); + + SurfaceUpdatedListener[] getSurfaceUpdatedListeners(); + + + // + // WindowListener + // + + public void sendWindowEvent(int eventType); + + /** + * + * Appends the given {@link com.jogamp.newt.event.WindowListener} to the end of + * the list. + */ + void addWindowListener(WindowListener l); + + /** + * + * Inserts the given {@link com.jogamp.newt.event.WindowListener} at the + * specified position in the list.<br> + * + * @param index Position where the listener will be inserted. + * Should be within (0 <= index && index <= size()). + * An index value of -1 is interpreted as the end of the list, size(). + * @param l The listener object to be inserted + * @throws IndexOutOfBoundsException If the index is not within (0 <= index && index <= size()), or -1 + */ + void addWindowListener(int index, WindowListener l) throws IndexOutOfBoundsException; + + void removeWindowListener(WindowListener l); + + WindowListener getWindowListener(int index); + + WindowListener[] getWindowListeners(); + + // + // KeyListener + // + + + /** + * + * Appends the given {@link com.jogamp.newt.event.KeyListener} to the end of + * the list. + */ + void addKeyListener(KeyListener l); + + /** + * + * Inserts the given {@link com.jogamp.newt.event.KeyListener} at the + * specified position in the list.<br> + * + * @param index Position where the listener will be inserted. + * Should be within (0 <= index && index <= size()). + * An index value of -1 is interpreted as the end of the list, size(). + * @param l The listener object to be inserted + * @throws IndexOutOfBoundsException If the index is not within (0 <= index && index <= size()), or -1 + */ + void addKeyListener(int index, KeyListener l); + + void removeKeyListener(KeyListener l); + + KeyListener getKeyListener(int index); + + KeyListener[] getKeyListeners(); + + + // + // MouseListener + // + + /** + * + * Appends the given {@link com.jogamp.newt.event.MouseListener} to the end of + * the list. + */ + void addMouseListener(MouseListener l); + + /** + * + * Inserts the given {@link com.jogamp.newt.event.MouseListener} at the + * specified position in the list.<br> + * + * @param index Position where the listener will be inserted. + * Should be within (0 <= index && index <= size()). + * An index value of -1 is interpreted as the end of the list, size(). + * @param l The listener object to be inserted + * @throws IndexOutOfBoundsException If the index is not within (0 <= index && index <= size()), or -1 + */ + void addMouseListener(int index, MouseListener l); + + void removeMouseListener(MouseListener l); + + MouseListener getMouseListener(int index); + + MouseListener[] getMouseListeners(); + +} diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java new file mode 100644 index 000000000..0eda5c2a3 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -0,0 +1,378 @@ +/** + * 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.newt.awt; + +import com.jogamp.newt.Display; +import java.lang.reflect.*; +import java.security.*; + +import java.awt.Canvas; +import java.awt.EventQueue; +import java.awt.Graphics; +import java.awt.KeyboardFocusManager; + +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.WindowClosingProtocol; +import javax.media.nativewindow.awt.AWTWindowClosingProtocol; +import jogamp.nativewindow.awt.AWTMisc; + +import com.jogamp.newt.event.awt.AWTAdapter; +import com.jogamp.newt.event.awt.AWTParentWindowAdapter; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.Window; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowListener; +import jogamp.newt.Debug; +import javax.swing.MenuSelectionManager; + +public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProtocol { + public static final boolean DEBUG = Debug.debug("Window"); + + NativeWindow nativeWindow = null; + Window newtChild = null; + int newtChildCloseOp; + AWTAdapter awtAdapter = null; + + private AWTWindowClosingProtocol awtWindowClosingProtocol = + new AWTWindowClosingProtocol(this, new Runnable() { + public void run() { + NewtCanvasAWT.this.destroy(); + } + }); + + /** + * Instantiates a NewtCanvas without a NEWT child.<br> + */ + public NewtCanvasAWT() { + super(); + } + + /** + * Instantiates a NewtCanvas with a NEWT child. + */ + public NewtCanvasAWT(Window child) { + super(); + setNEWTChild(child); + } + + class FocusAction implements Window.FocusRunnable { + public boolean run() { + if ( EventQueue.isDispatchThread() ) { + focusActionImpl.run(); + } else { + try { + EventQueue.invokeAndWait(focusActionImpl); + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + return focusActionImpl.result; + } + + class FocusActionImpl implements Runnable { + public final boolean result = false; // NEWT shall always proceed requesting the native focus + public void run() { + if(DEBUG) { + System.err.println("FocusActionImpl.run() "+Display.getThreadName()); + } + NewtCanvasAWT.this.requestFocusAWTParent(); + KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + kfm.clearGlobalFocusOwner(); + } + } + FocusActionImpl focusActionImpl = new FocusActionImpl(); + } + FocusAction focusAction = new FocusAction(); + + WindowListener clearAWTMenusOnNewtFocus = new WindowAdapter() { + @Override + public void windowGainedFocus(WindowEvent arg0) { + MenuSelectionManager.defaultManager().clearSelectedPath(); + } + }; + + /** sets a new NEWT child, provoking reparenting on the NEWT level. */ + public NewtCanvasAWT setNEWTChild(Window child) { + if(newtChild!=child) { + newtChild = child; + if(null!=nativeWindow) { + java.awt.Container cont = AWTMisc.getContainer(this); + // reparent right away, addNotify has been called already + reparentWindow( (null!=newtChild) ? true : false, cont ); + } + } + return this; + } + + /** @return the current NEWT child */ + public Window getNEWTChild() { + return newtChild; + } + + /** @return this AWT Canvas NativeWindow representation, may be null in case {@link #removeNotify()} has been called, + * or {@link #addNotify()} hasn't been called yet.*/ + public NativeWindow getNativeWindow() { return nativeWindow; } + + public int getDefaultCloseOperation() { + return awtWindowClosingProtocol.getDefaultCloseOperation(); + } + + public int setDefaultCloseOperation(int op) { + return awtWindowClosingProtocol.setDefaultCloseOperation(op); + } + + void configureNewtChild(boolean attach) { + if(null!=awtAdapter) { + awtAdapter.removeFrom(this); + awtAdapter=null; + } + if( null != newtChild ) { + if(attach) { + awtAdapter = new AWTParentWindowAdapter(newtChild).addTo(this); + if(newtChild.isValid()) { + newtChild.addWindowListener(clearAWTMenusOnNewtFocus); + } + newtChild.setFocusAction(focusAction); // enable AWT focus traversal + newtChildCloseOp = newtChild.setDefaultCloseOperation(WindowClosingProtocol.DO_NOTHING_ON_CLOSE); + awtWindowClosingProtocol.addClosingListenerOneShot(); + } else { + if(newtChild.isValid()) { + newtChild.removeWindowListener(clearAWTMenusOnNewtFocus); + } + newtChild.setFocusAction(null); + newtChild.setDefaultCloseOperation(newtChildCloseOp); + awtWindowClosingProtocol.removeClosingListener(); + } + } + } + + @Override + public void addNotify() { + + // before native peer is valid: X11 + disableBackgroundErase(); + + // creates the native peer + super.addNotify(); + + // after native peer is valid: Windows + disableBackgroundErase(); + + java.awt.Container cont = AWTMisc.getContainer(this); + if(DEBUG) { + // if ( isShowing() == false ) -> Container was not visible yet. + // if ( isShowing() == true ) -> Container is already visible. + System.err.println("NewtCanvasAWT.addNotify: "+newtChild+", "+this+", visible "+isVisible()+", showing "+isShowing()+ + ", displayable "+isDisplayable()+" -> "+cont); + } + reparentWindow(true, cont); + } + + @Override + public void removeNotify() { + java.awt.Container cont = AWTMisc.getContainer(this); + if(DEBUG) { + System.err.println("NewtCanvasAWT.removeNotify: "+newtChild+", from "+cont); + } + reparentWindow(false, cont); + super.removeNotify(); + } + + void reparentWindow(boolean add, java.awt.Container cont) { + if(null==newtChild) { + return; // nop + } + + newtChild.setFocusAction(null); // no AWT focus traversal .. + if(add) { + nativeWindow = NewtFactoryAWT.getNativeWindow(this, newtChild.getRequestedCapabilities()); + if(null!=nativeWindow) { + if(DEBUG) { + System.err.println("NewtCanvasAWT.reparentWindow: "+newtChild); + } + final int w = cont.getWidth(); + final int h = cont.getHeight(); + setSize(w, h); + newtChild.setSize(w, h); + newtChild.reparentWindow(nativeWindow); + newtChild.setVisible(true); + configureNewtChild(true); + newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener + newtChild.windowRepaint(0, 0, w, h); + } + } else { + configureNewtChild(false); + nativeWindow = null; + newtChild.setVisible(false); + newtChild.reparentWindow(null); + } + } + + /** + * Destroys this resource: + * <ul> + * <li> Make the NEWT Child invisible </li> + * <li> Disconnects the NEWT Child from this Canvas NativeWindow, reparent to NULL </li> + * <li> Issues <code>destroy()</code> on the NEWT Child</li> + * <li> Remove reference to the NEWT Child</li> + * <li> Remove this Canvas from it's parent.</li> + * </ul> + * @see Window#destroy() + */ + public final void destroy() { + if(null!=newtChild) { + java.awt.Container cont = AWTMisc.getContainer(this); + if(DEBUG) { + System.err.println("NewtCanvasAWT.destroy(): "+newtChild+", from "+cont); + } + configureNewtChild(false); + nativeWindow = null; + newtChild.setVisible(false); + newtChild.reparentWindow(null); + newtChild.destroy(); + newtChild=null; + if(null!=cont) { + cont.remove(this); + } + } + } + + @Override + public void paint(Graphics g) { + awtWindowClosingProtocol.addClosingListenerOneShot(); + if(null!=newtChild) { + newtChild.windowRepaint(0, 0, getWidth(), getHeight()); + } + } + @Override + public void update(Graphics g) { + awtWindowClosingProtocol.addClosingListenerOneShot(); + if(null!=newtChild) { + newtChild.windowRepaint(0, 0, getWidth(), getHeight()); + } + } + + final void requestFocusAWTParent() { + super.requestFocus(); + } + + final void requestFocusNEWTChild() { + if(null!=newtChild) { + newtChild.setFocusAction(null); + newtChild.requestFocus(); + newtChild.setFocusAction(focusAction); + } + } + + @Override + public void requestFocus() { + requestFocusAWTParent(); + requestFocusNEWTChild(); + } + + @Override + public boolean requestFocus(boolean temporary) { + boolean res = super.requestFocus(temporary); + if(res) { + requestFocusNEWTChild(); + } + return res; + } + + @Override + public boolean requestFocusInWindow() { + boolean res = super.requestFocusInWindow(); + if(res) { + requestFocusNEWTChild(); + } + return res; + } + + @Override + public boolean requestFocusInWindow(boolean temporary) { + boolean res = super.requestFocusInWindow(temporary); + if(res) { + requestFocusNEWTChild(); + } + return res; + } + + // Disables the AWT's erasing of this Canvas's background on Windows + // in Java SE 6. This internal API is not available in previous + // releases, but the system property + // -Dsun.awt.noerasebackground=true can be specified to get similar + // results globally in previous releases. + private static boolean disableBackgroundEraseInitialized; + private static Method disableBackgroundEraseMethod; + private void disableBackgroundErase() { + if (!disableBackgroundEraseInitialized) { + try { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + Class clazz = getToolkit().getClass(); + while (clazz != null && disableBackgroundEraseMethod == null) { + try { + disableBackgroundEraseMethod = + clazz.getDeclaredMethod("disableBackgroundErase", + new Class[] { Canvas.class }); + disableBackgroundEraseMethod.setAccessible(true); + } catch (Exception e) { + clazz = clazz.getSuperclass(); + } + } + } catch (Exception e) { + } + return null; + } + }); + } catch (Exception e) { + } + disableBackgroundEraseInitialized = true; + if(DEBUG) { + System.err.println("NewtCanvasAWT: TK disableBackgroundErase method found: "+ + (null!=disableBackgroundEraseMethod)); + } + } + if (disableBackgroundEraseMethod != null) { + Throwable t=null; + try { + disableBackgroundEraseMethod.invoke(getToolkit(), new Object[] { this }); + } catch (Exception e) { + t = e; + } + if(DEBUG) { + System.err.println("NewtCanvasAWT: TK disableBackgroundErase error: "+t); + } + } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java new file mode 100644 index 000000000..e1370f05e --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java @@ -0,0 +1,73 @@ +/** + * 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.newt.awt; + + +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; + +import com.jogamp.newt.NewtFactory; +import jogamp.newt.Debug; + +public class NewtFactoryAWT extends NewtFactory { + public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); + + /** + * Wraps an AWT component into a {@link javax.media.nativewindow.NativeWindow} utilizing the {@link javax.media.nativewindow.NativeWindowFactory},<br> + * using a configuration agnostic dummy {@link javax.media.nativewindow.DefaultGraphicsConfiguration}.<br> + * <p> + * The actual wrapping implementation is {@link jogamp.nativewindow.jawt.JAWTWindow}.<br></p> + * <p> + * Purpose of this wrapping is to access the AWT window handle,<br> + * not to actually render into it.<br> + * Hence the dummy configuration only.</p> + * + * @param awtCompObject must be of type java.awt.Component + */ + public static NativeWindow getNativeWindow(Object awtCompObject, CapabilitiesImmutable capsRequested) { + if(null==awtCompObject) { + throw new NativeWindowException("Null AWT Component"); + } + if( ! (awtCompObject instanceof java.awt.Component) ) { + throw new NativeWindowException("AWT Component not a java.awt.Component"); + } + return getNativeWindow( (java.awt.Component) awtCompObject, capsRequested ); + } + + public static NativeWindow getNativeWindow(java.awt.Component awtComp, CapabilitiesImmutable capsRequested) { + DefaultGraphicsConfiguration config = AWTGraphicsConfiguration.create(awtComp, capsRequested, capsRequested); + NativeWindow awtNative = NativeWindowFactory.getNativeWindow(awtComp, config); // a JAWTWindow + if(DEBUG_IMPLEMENTATION) { + System.err.println("NewtFactoryAWT.getNativeWindow: "+awtComp+" -> "+awtNative); + } + return awtNative; + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java new file mode 100644 index 000000000..148787845 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +public abstract class InputEvent extends NEWTEvent +{ + public static final int SHIFT_MASK = 1 << 0; + public static final int CTRL_MASK = 1 << 1; + public static final int META_MASK = 1 << 2; + public static final int ALT_MASK = 1 << 3; + public static final int ALT_GRAPH_MASK = 1 << 5; + public static final int BUTTON1_MASK = 1 << 6; + public static final int BUTTON2_MASK = 1 << 7; + public static final int BUTTON3_MASK = 1 << 8; + + protected InputEvent(int eventType, Object source, long when, int modifiers) { + super(eventType, source, when); + this.modifiers=modifiers; + } + + public int getModifiers() { + return modifiers; + } + public boolean isAltDown() { + return (modifiers&ALT_MASK)!=0; + } + public boolean isAltGraphDown() { + return (modifiers&ALT_GRAPH_MASK)!=0; + } + public boolean isControlDown() { + return (modifiers&CTRL_MASK)!=0; + } + public boolean isMetaDown() { + return (modifiers&META_MASK)!=0; + } + public boolean isShiftDown() { + return (modifiers&SHIFT_MASK)!=0; + } + + public boolean isButton1Down() { + return (modifiers&BUTTON1_MASK)!=0; + } + + public boolean isButton2Down() { + return (modifiers&BUTTON2_MASK)!=0; + } + + public boolean isButton3Down() { + return (modifiers&BUTTON3_MASK)!=0; + } + + public String toString() { + return "InputEvent[modifiers:"+modifiers+", "+super.toString()+"]"; + } + + private int modifiers; +} diff --git a/src/newt/classes/com/jogamp/newt/event/KeyAdapter.java b/src/newt/classes/com/jogamp/newt/event/KeyAdapter.java new file mode 100644 index 000000000..93c8409b1 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/KeyAdapter.java @@ -0,0 +1,41 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright (c) 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.newt.event; + +public abstract class KeyAdapter implements KeyListener +{ + public void keyPressed(KeyEvent e) { + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java new file mode 100644 index 000000000..2c3fd9cb2 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java @@ -0,0 +1,736 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +public class KeyEvent extends InputEvent +{ + public KeyEvent(int eventType, Object source, long when, int modifiers, int keyCode, char keyChar) { + super(eventType, source, when, modifiers); + this.keyCode=keyCode; + this.keyChar=keyChar; + } + + public char getKeyChar() { + return keyChar; + } + public int getKeyCode() { + return keyCode; + } + + public String toString() { + return "KeyEvent["+getEventTypeString(getEventType())+ + ", code "+keyCode+"("+toHexString(keyCode)+"), char '"+keyChar+"' ("+toHexString((int)keyChar)+"), isActionKey "+isActionKey()+", "+super.toString()+"]"; + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED"; + case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED"; + case EVENT_KEY_TYPED: return "EVENT_KEY_TYPED"; + default: return "unknown (" + type + ")"; + } + } + + public boolean isActionKey() { + switch (keyCode) { + case VK_HOME: + case VK_END: + case VK_PAGE_UP: + case VK_PAGE_DOWN: + case VK_UP: + case VK_DOWN: + case VK_LEFT: + case VK_RIGHT: + + case VK_F1: + case VK_F2: + case VK_F3: + case VK_F4: + case VK_F5: + case VK_F6: + case VK_F7: + case VK_F8: + case VK_F9: + case VK_F10: + case VK_F11: + case VK_F12: + case VK_F13: + case VK_F14: + case VK_F15: + case VK_F16: + case VK_F17: + case VK_F18: + case VK_F19: + case VK_F20: + case VK_F21: + case VK_F22: + case VK_F23: + case VK_F24: + case VK_PRINTSCREEN: + case VK_CAPS_LOCK: + case VK_PAUSE: + case VK_INSERT: + + case VK_HELP: + case VK_WINDOWS: + return true; + } + return false; + } + + private int keyCode; + private char keyChar; + + public static final int EVENT_KEY_PRESSED = 300; + public static final int EVENT_KEY_RELEASED= 301; + public static final int EVENT_KEY_TYPED = 302; + + /* Virtual key codes. */ + + public static final int VK_ENTER = '\n'; + public static final int VK_BACK_SPACE = '\b'; + public static final int VK_TAB = '\t'; + public static final int VK_CANCEL = 0x03; + public static final int VK_CLEAR = 0x0C; + public static final int VK_SHIFT = 0x10; + public static final int VK_CONTROL = 0x11; + public static final int VK_ALT = 0x12; + public static final int VK_PAUSE = 0x13; + public static final int VK_CAPS_LOCK = 0x14; + public static final int VK_ESCAPE = 0x1B; + public static final int VK_SPACE = 0x20; + public static final int VK_PAGE_UP = 0x21; + public static final int VK_PAGE_DOWN = 0x22; + public static final int VK_END = 0x23; + public static final int VK_HOME = 0x24; + + /** + * Constant for the non-numpad <b>left</b> arrow key. + * @see #VK_KP_LEFT + */ + public static final int VK_LEFT = 0x25; + + /** + * Constant for the non-numpad <b>up</b> arrow key. + * @see #VK_KP_UP + */ + public static final int VK_UP = 0x26; + + /** + * Constant for the non-numpad <b>right</b> arrow key. + * @see #VK_KP_RIGHT + */ + public static final int VK_RIGHT = 0x27; + + /** + * Constant for the non-numpad <b>down</b> arrow key. + * @see #VK_KP_DOWN + */ + public static final int VK_DOWN = 0x28; + + /** + * Constant for the comma key, "," + */ + public static final int VK_COMMA = 0x2C; + + /** + * Constant for the minus key, "-" + * @since 1.2 + */ + public static final int VK_MINUS = 0x2D; + + /** + * Constant for the period key, "." + */ + public static final int VK_PERIOD = 0x2E; + + /** + * Constant for the forward slash key, "/" + */ + public static final int VK_SLASH = 0x2F; + + /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ + public static final int VK_0 = 0x30; + public static final int VK_1 = 0x31; + public static final int VK_2 = 0x32; + public static final int VK_3 = 0x33; + public static final int VK_4 = 0x34; + public static final int VK_5 = 0x35; + public static final int VK_6 = 0x36; + public static final int VK_7 = 0x37; + public static final int VK_8 = 0x38; + public static final int VK_9 = 0x39; + + /** + * Constant for the semicolon key, ";" + */ + public static final int VK_SEMICOLON = 0x3B; + + /** + * Constant for the equals key, "=" + */ + public static final int VK_EQUALS = 0x3D; + + /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ + public static final int VK_A = 0x41; + public static final int VK_B = 0x42; + public static final int VK_C = 0x43; + public static final int VK_D = 0x44; + public static final int VK_E = 0x45; + public static final int VK_F = 0x46; + public static final int VK_G = 0x47; + public static final int VK_H = 0x48; + public static final int VK_I = 0x49; + public static final int VK_J = 0x4A; + public static final int VK_K = 0x4B; + public static final int VK_L = 0x4C; + public static final int VK_M = 0x4D; + public static final int VK_N = 0x4E; + public static final int VK_O = 0x4F; + public static final int VK_P = 0x50; + public static final int VK_Q = 0x51; + public static final int VK_R = 0x52; + public static final int VK_S = 0x53; + public static final int VK_T = 0x54; + public static final int VK_U = 0x55; + public static final int VK_V = 0x56; + public static final int VK_W = 0x57; + public static final int VK_X = 0x58; + public static final int VK_Y = 0x59; + public static final int VK_Z = 0x5A; + + /** + * Constant for the open bracket key, "[" + */ + public static final int VK_OPEN_BRACKET = 0x5B; + + /** + * Constant for the back slash key, "\" + */ + public static final int VK_BACK_SLASH = 0x5C; + + /** + * Constant for the close bracket key, "]" + */ + public static final int VK_CLOSE_BRACKET = 0x5D; + + public static final int VK_NUMPAD0 = 0x60; + public static final int VK_NUMPAD1 = 0x61; + public static final int VK_NUMPAD2 = 0x62; + public static final int VK_NUMPAD3 = 0x63; + public static final int VK_NUMPAD4 = 0x64; + public static final int VK_NUMPAD5 = 0x65; + public static final int VK_NUMPAD6 = 0x66; + public static final int VK_NUMPAD7 = 0x67; + public static final int VK_NUMPAD8 = 0x68; + public static final int VK_NUMPAD9 = 0x69; + public static final int VK_MULTIPLY = 0x6A; + public static final int VK_ADD = 0x6B; + + /** + * This constant is obsolete, and is included only for backwards + * compatibility. + * @see #VK_SEPARATOR + */ + public static final int VK_SEPARATER = 0x6C; + + /** + * Constant for the Numpad Separator key. + * @since 1.4 + */ + public static final int VK_SEPARATOR = VK_SEPARATER; + + public static final int VK_SUBTRACT = 0x6D; + public static final int VK_DECIMAL = 0x6E; + public static final int VK_DIVIDE = 0x6F; + public static final int VK_DELETE = 0x7F; /* ASCII DEL */ + public static final int VK_NUM_LOCK = 0x90; + public static final int VK_SCROLL_LOCK = 0x91; + + /** Constant for the F1 function key. */ + public static final int VK_F1 = 0x70; + + /** Constant for the F2 function key. */ + public static final int VK_F2 = 0x71; + + /** Constant for the F3 function key. */ + public static final int VK_F3 = 0x72; + + /** Constant for the F4 function key. */ + public static final int VK_F4 = 0x73; + + /** Constant for the F5 function key. */ + public static final int VK_F5 = 0x74; + + /** Constant for the F6 function key. */ + public static final int VK_F6 = 0x75; + + /** Constant for the F7 function key. */ + public static final int VK_F7 = 0x76; + + /** Constant for the F8 function key. */ + public static final int VK_F8 = 0x77; + + /** Constant for the F9 function key. */ + public static final int VK_F9 = 0x78; + + /** Constant for the F10 function key. */ + public static final int VK_F10 = 0x79; + + /** Constant for the F11 function key. */ + public static final int VK_F11 = 0x7A; + + /** Constant for the F12 function key. */ + public static final int VK_F12 = 0x7B; + + /** + * Constant for the F13 function key. + * @since 1.2 + */ + /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */ + public static final int VK_F13 = 0xF000; + + /** + * Constant for the F14 function key. + * @since 1.2 + */ + public static final int VK_F14 = 0xF001; + + /** + * Constant for the F15 function key. + * @since 1.2 + */ + public static final int VK_F15 = 0xF002; + + /** + * Constant for the F16 function key. + * @since 1.2 + */ + public static final int VK_F16 = 0xF003; + + /** + * Constant for the F17 function key. + * @since 1.2 + */ + public static final int VK_F17 = 0xF004; + + /** + * Constant for the F18 function key. + * @since 1.2 + */ + public static final int VK_F18 = 0xF005; + + /** + * Constant for the F19 function key. + * @since 1.2 + */ + public static final int VK_F19 = 0xF006; + + /** + * Constant for the F20 function key. + * @since 1.2 + */ + public static final int VK_F20 = 0xF007; + + /** + * Constant for the F21 function key. + * @since 1.2 + */ + public static final int VK_F21 = 0xF008; + + /** + * Constant for the F22 function key. + * @since 1.2 + */ + public static final int VK_F22 = 0xF009; + + /** + * Constant for the F23 function key. + * @since 1.2 + */ + public static final int VK_F23 = 0xF00A; + + /** + * Constant for the F24 function key. + * @since 1.2 + */ + public static final int VK_F24 = 0xF00B; + + public static final int VK_PRINTSCREEN = 0x9A; + public static final int VK_INSERT = 0x9B; + public static final int VK_HELP = 0x9C; + public static final int VK_META = 0x9D; + + public static final int VK_BACK_QUOTE = 0xC0; + public static final int VK_QUOTE = 0xDE; + + /** + * Constant for the numeric keypad <b>up</b> arrow key. + * @see #VK_UP + * @since 1.2 + */ + public static final int VK_KP_UP = 0xE0; + + /** + * Constant for the numeric keypad <b>down</b> arrow key. + * @see #VK_DOWN + * @since 1.2 + */ + public static final int VK_KP_DOWN = 0xE1; + + /** + * Constant for the numeric keypad <b>left</b> arrow key. + * @see #VK_LEFT + * @since 1.2 + */ + public static final int VK_KP_LEFT = 0xE2; + + /** + * Constant for the numeric keypad <b>right</b> arrow key. + * @see #VK_RIGHT + * @since 1.2 + */ + public static final int VK_KP_RIGHT = 0xE3; + + /* For European keyboards */ + /** @since 1.2 */ + public static final int VK_DEAD_GRAVE = 0x80; + /** @since 1.2 */ + public static final int VK_DEAD_ACUTE = 0x81; + /** @since 1.2 */ + public static final int VK_DEAD_CIRCUMFLEX = 0x82; + /** @since 1.2 */ + public static final int VK_DEAD_TILDE = 0x83; + /** @since 1.2 */ + public static final int VK_DEAD_MACRON = 0x84; + /** @since 1.2 */ + public static final int VK_DEAD_BREVE = 0x85; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVEDOT = 0x86; + /** @since 1.2 */ + public static final int VK_DEAD_DIAERESIS = 0x87; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVERING = 0x88; + /** @since 1.2 */ + public static final int VK_DEAD_DOUBLEACUTE = 0x89; + /** @since 1.2 */ + public static final int VK_DEAD_CARON = 0x8a; + /** @since 1.2 */ + public static final int VK_DEAD_CEDILLA = 0x8b; + /** @since 1.2 */ + public static final int VK_DEAD_OGONEK = 0x8c; + /** @since 1.2 */ + public static final int VK_DEAD_IOTA = 0x8d; + /** @since 1.2 */ + public static final int VK_DEAD_VOICED_SOUND = 0x8e; + /** @since 1.2 */ + public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f; + + /** @since 1.2 */ + public static final int VK_AMPERSAND = 0x96; + /** @since 1.2 */ + public static final int VK_ASTERISK = 0x97; + /** @since 1.2 */ + public static final int VK_QUOTEDBL = 0x98; + /** @since 1.2 */ + public static final int VK_LESS = 0x99; + + /** @since 1.2 */ + public static final int VK_GREATER = 0xa0; + /** @since 1.2 */ + public static final int VK_BRACELEFT = 0xa1; + /** @since 1.2 */ + public static final int VK_BRACERIGHT = 0xa2; + + /** + * Constant for the "@" key. + * @since 1.2 + */ + public static final int VK_AT = 0x0200; + + /** + * Constant for the ":" key. + * @since 1.2 + */ + public static final int VK_COLON = 0x0201; + + /** + * Constant for the "^" key. + * @since 1.2 + */ + public static final int VK_CIRCUMFLEX = 0x0202; + + /** + * Constant for the "$" key. + * @since 1.2 + */ + public static final int VK_DOLLAR = 0x0203; + + /** + * Constant for the Euro currency sign key. + * @since 1.2 + */ + public static final int VK_EURO_SIGN = 0x0204; + + /** + * Constant for the "!" key. + * @since 1.2 + */ + public static final int VK_EXCLAMATION_MARK = 0x0205; + + /** + * Constant for the inverted exclamation mark key. + * @since 1.2 + */ + public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; + + /** + * Constant for the "(" key. + * @since 1.2 + */ + public static final int VK_LEFT_PARENTHESIS = 0x0207; + + /** + * Constant for the "#" key. + * @since 1.2 + */ + public static final int VK_NUMBER_SIGN = 0x0208; + + /** + * Constant for the "+" key. + * @since 1.2 + */ + public static final int VK_PLUS = 0x0209; + + /** + * Constant for the ")" key. + * @since 1.2 + */ + public static final int VK_RIGHT_PARENTHESIS = 0x020A; + + /** + * Constant for the "_" key. + * @since 1.2 + */ + public static final int VK_UNDERSCORE = 0x020B; + + /** + * Constant for the Microsoft Windows "Windows" key. + * It is used for both the left and right version of the key. + * @see #getKeyLocation() + * @since 1.5 + */ + public static final int VK_WINDOWS = 0x020C; + + /** + * Constant for the Microsoft Windows Context Menu key. + * @since 1.5 + */ + public static final int VK_CONTEXT_MENU = 0x020D; + + /* for input method support on Asian Keyboards */ + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_FINAL = 0x0018; + + /** Constant for the Convert function key. */ + /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */ + public static final int VK_CONVERT = 0x001C; + + /** Constant for the Don't Convert function key. */ + /* Japanese PC 106 keyboard: muhenkan */ + public static final int VK_NONCONVERT = 0x001D; + + /** Constant for the Accept or Commit function key. */ + /* Japanese Solaris keyboard: kakutei */ + public static final int VK_ACCEPT = 0x001E; + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_MODECHANGE = 0x001F; + + /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris; + might still be used on other platforms */ + public static final int VK_KANA = 0x0015; + + /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris; + might still be used for other platforms */ + public static final int VK_KANJI = 0x0019; + + /** + * Constant for the Alphanumeric function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: eisuu */ + public static final int VK_ALPHANUMERIC = 0x00F0; + + /** + * Constant for the Katakana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: katakana */ + public static final int VK_KATAKANA = 0x00F1; + + /** + * Constant for the Hiragana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hiragana */ + public static final int VK_HIRAGANA = 0x00F2; + + /** + * Constant for the Full-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: zenkaku */ + public static final int VK_FULL_WIDTH = 0x00F3; + + /** + * Constant for the Half-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hankaku */ + public static final int VK_HALF_WIDTH = 0x00F4; + + /** + * Constant for the Roman Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: roumaji */ + public static final int VK_ROMAN_CHARACTERS = 0x00F5; + + /** + * Constant for the All Candidates function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */ + public static final int VK_ALL_CANDIDATES = 0x0100; + + /** + * Constant for the Previous Candidate function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */ + public static final int VK_PREVIOUS_CANDIDATE = 0x0101; + + /** + * Constant for the Code Input function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */ + public static final int VK_CODE_INPUT = 0x0102; + + /** + * Constant for the Japanese-Katakana function key. + * This key switches to a Japanese input method and selects its Katakana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */ + public static final int VK_JAPANESE_KATAKANA = 0x0103; + + /** + * Constant for the Japanese-Hiragana function key. + * This key switches to a Japanese input method and selects its Hiragana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_HIRAGANA = 0x0104; + + /** + * Constant for the Japanese-Roman function key. + * This key switches to a Japanese input method and selects its Roman-Direct input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_ROMAN = 0x0105; + + /** + * Constant for the locking Kana function key. + * This key locks the keyboard into a Kana layout. + * @since 1.3 + */ + /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */ + public static final int VK_KANA_LOCK = 0x0106; + + /** + * Constant for the input method on/off key. + * @since 1.3 + */ + /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */ + public static final int VK_INPUT_METHOD_ON_OFF = 0x0107; + + /* for Sun keyboards */ + /** @since 1.2 */ + public static final int VK_CUT = 0xFFD1; + /** @since 1.2 */ + public static final int VK_COPY = 0xFFCD; + /** @since 1.2 */ + public static final int VK_PASTE = 0xFFCF; + /** @since 1.2 */ + public static final int VK_UNDO = 0xFFCB; + /** @since 1.2 */ + public static final int VK_AGAIN = 0xFFC9; + /** @since 1.2 */ + public static final int VK_FIND = 0xFFD0; + /** @since 1.2 */ + public static final int VK_PROPS = 0xFFCA; + /** @since 1.2 */ + public static final int VK_STOP = 0xFFC8; + + /** + * Constant for the Compose function key. + * @since 1.2 + */ + public static final int VK_COMPOSE = 0xFF20; + + /** + * Constant for the AltGraph function key. + * @since 1.2 + */ + public static final int VK_ALT_GRAPH = 0xFF7E; + + /** + * Constant for the Begin key. + * @since 1.5 + */ + public static final int VK_BEGIN = 0xFF58; + + /** + * This value is used to indicate that the keyCode is unknown. + * KEY_TYPED events do not have a keyCode value; this value + * is used instead. + */ + public static final int VK_UNDEFINED = 0x0; +} + diff --git a/src/newt/classes/com/jogamp/newt/event/KeyListener.java b/src/newt/classes/com/jogamp/newt/event/KeyListener.java new file mode 100644 index 000000000..dae343d80 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/KeyListener.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +public interface KeyListener extends NEWTEventListener +{ + public void keyPressed(KeyEvent e); + public void keyReleased(KeyEvent e); + public void keyTyped(KeyEvent e) ; +} + diff --git a/src/newt/classes/com/jogamp/newt/event/MouseAdapter.java b/src/newt/classes/com/jogamp/newt/event/MouseAdapter.java new file mode 100644 index 000000000..3607ae634 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/MouseAdapter.java @@ -0,0 +1,50 @@ +/** + * 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.newt.event; + +public abstract class MouseAdapter implements MouseListener +{ + public void mouseClicked(MouseEvent e) { + } + public void mouseEntered(MouseEvent e) { + } + public void mouseExited(MouseEvent e) { + } + public void mousePressed(MouseEvent e) { + } + public void mouseReleased(MouseEvent e) { + } + public void mouseMoved(MouseEvent e) { + } + public void mouseDragged(MouseEvent e) { + } + public void mouseWheelMoved(MouseEvent e) { + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java new file mode 100644 index 000000000..fbe32d41d --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +public class MouseEvent extends InputEvent +{ + public static final int BUTTON1 = 1; + public static final int BUTTON2 = 2; + public static final int BUTTON3 = 3; + public static final int BUTTON4 = 4; + public static final int BUTTON5 = 5; + public static final int BUTTON6 = 6; + public static final int BUTTON_NUMBER = 6; + + public static final int getClickTimeout() { + return 300; + } + + public MouseEvent(int eventType, Object source, long when, + int modifiers, int x, int y, int clickCount, int button, + int rotation) + { + super(eventType, source, when, modifiers); + this.x=x; + this.y=y; + this.clickCount=clickCount; + this.button=button; + this.wheelRotation = rotation; + } + + public int getButton() { + return button; + } + public int getClickCount() { + return clickCount; + } + public int getX() { + return x; + } + public int getY() { + return y; + } + public int getWheelRotation() { + return wheelRotation; + } + + public String toString() { + return "MouseEvent["+getEventTypeString(getEventType())+ + ", "+x+"/"+y+", button "+button+", count "+clickCount+ + ", wheel rotation "+wheelRotation+ + ", "+super.toString()+"]"; + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED"; + case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED"; + case EVENT_MOUSE_EXITED: return "EVENT_MOUSE_EXITED"; + case EVENT_MOUSE_PRESSED: return "EVENT_MOUSE_PRESSED"; + case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED"; + case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED"; + case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED"; + case EVENT_MOUSE_WHEEL_MOVED: return "EVENT_MOUSE_WHEEL_MOVED"; + default: return "unknown (" + type + ")"; + } + } + + private int x, y, clickCount, button, wheelRotation; + + public static final int EVENT_MOUSE_CLICKED = 200; + public static final int EVENT_MOUSE_ENTERED = 201; + public static final int EVENT_MOUSE_EXITED = 202; + public static final int EVENT_MOUSE_PRESSED = 203; + public static final int EVENT_MOUSE_RELEASED = 204; + public static final int EVENT_MOUSE_MOVED = 205; + public static final int EVENT_MOUSE_DRAGGED = 206; + public static final int EVENT_MOUSE_WHEEL_MOVED = 207; +} diff --git a/src/newt/classes/com/jogamp/newt/event/MouseListener.java b/src/newt/classes/com/jogamp/newt/event/MouseListener.java new file mode 100644 index 000000000..5ec086b94 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/MouseListener.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +public interface MouseListener extends NEWTEventListener +{ + public void mouseClicked(MouseEvent e); + public void mouseEntered(MouseEvent e); + public void mouseExited(MouseEvent e); + public void mousePressed(MouseEvent e); + public void mouseReleased(MouseEvent e); + public void mouseMoved(MouseEvent e); + public void mouseDragged(MouseEvent e); + public void mouseWheelMoved(MouseEvent e); +} + diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java new file mode 100644 index 000000000..10673be3d --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +/** + * NEWT events are provided for notification purposes ONLY;<br> + * The NEWT will automatically handle the event semantics internally, regardless of whether a program is receiving these events or not.<br> + * The actual event semantic is processed before the event is send.<br> + * + * Event type registry:<br> + * <ul> + * <li> WindowEvent <code>100..10x</code></li> + * <li> MouseEvent <code>200..20x</code></li> + * <li> KeyEvent <code>300..30x</code></li> + * </ul><br> + */ +public class NEWTEvent extends java.util.EventObject { + private boolean isSystemEvent; + private int eventType; + private long when; + private Object attachment; + + static final boolean DEBUG = false; + + // 0: NEWTEvent.java + // 1: InputEvent.java + // 2: KeyEvent.java + // 3: com.jogamp.newt.Window + // 3: com.jogamp.newt.event.awt.AWTNewtEventFactory + // 2: MouseEvent.java + // 3: com.jogamp.newt.Window + // 3: com.jogamp.newt.event.awt.AWTNewtEventFactory + // 1: WindowEvent.java + // 2: com.jogamp.newt.Window + // 2: com.jogamp.newt.event.awt.AWTNewtEventFactory + // + // FIXME: verify the isSystemEvent evaluation + // + static final String WindowClazzName = "com.jogamp.newt.Window" ; + static final String AWTNewtEventFactoryClazzName = "com.jogamp.newt.event.awt.AWTNewtEventFactory" ; + + /** + static final boolean evaluateIsSystemEvent(NEWTEvent event, Throwable t) { + StackTraceElement[] stack = t.getStackTrace(); + if(stack.length==0 || null==stack[0]) { + return false; + } + if(DEBUG) { + for (int i = 0; i < stack.length && i<5; i++) { + System.err.println(i+": " + stack[i].getClassName()+ "." + stack[i].getMethodName()); + } + } + + String clazzName = null; + + if( event instanceof com.jogamp.newt.event.WindowEvent ) { + if ( stack.length > 2 ) { + clazzName = stack[2].getClassName(); + } + } else if( (event instanceof com.jogamp.newt.event.MouseEvent) || + (event instanceof com.jogamp.newt.event.KeyEvent) ) { + if ( stack.length > 3 ) { + clazzName = stack[3].getClassName(); + } + } + + boolean res = null!=clazzName && ( + clazzName.equals(WindowClazzName) || + clazzName.equals(AWTNewtEventFactoryClazzName) ) ; + if(DEBUG) { + System.err.println("system: "+res); + } + return res; + } */ + + protected NEWTEvent(int eventType, Object source, long when) { + super(source); + // this.isSystemEvent = evaluateIsSystemEvent(this, new Throwable()); + this.isSystemEvent = false; // FIXME: Need a more efficient way to determine system events + this.eventType = eventType; + this.when = when; + this.attachment=null; + } + + /** Indicates whether this event was produced by the system or + generated by user code. */ + public final boolean isSystemEvent() { + return isSystemEvent; + } + + /** Returns the event type of this event. */ + public final int getEventType() { + return eventType; + } + + /** Returns the timestamp, in milliseconds, of this event. */ + public final long getWhen() { + return when; + } + + /** + * Attach the passed object to this event.<br> + * If an object was previously attached, it will be replaced.<br> + * Attachments to NEWT events allow users to pass on information + * from one custom listener to another, ie custom listener to listener + * communication. + * @param attachment User application specific object + */ + public final void setAttachment(Object attachment) { + this.attachment=attachment; + } + + /** + * @return The user application specific attachment, or null + */ + public final Object getAttachment() { + return attachment; + } + + public String toString() { + return "NEWTEvent[sys:"+isSystemEvent()+", source:"+getSource().getClass().getName()+", when:"+getWhen()+" d "+(System.currentTimeMillis()-getWhen())+"ms]"; + } + + public static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + public static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + +} diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java b/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java new file mode 100644 index 000000000..6aa19e5f8 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java @@ -0,0 +1,40 @@ +/** + * 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.newt.event; + +public interface NEWTEventConsumer { + + /** + * Consume the event + * + * @return true if the event has been consumed, + * otherwise it returns false for later propagation. + */ + public boolean consumeEvent(NEWTEvent event); +} diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEventFiFo.java b/src/newt/classes/com/jogamp/newt/event/NEWTEventFiFo.java new file mode 100644 index 000000000..fe224bba6 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEventFiFo.java @@ -0,0 +1,62 @@ +/** + * 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.newt.event; + +import java.util.LinkedList; + +public class NEWTEventFiFo +{ + private LinkedList/*<NEWTEvent>*/ events = new LinkedList/*<NEWTEvent>*/(); + + /** Add NEWTEvent to tail */ + public synchronized void put(NEWTEvent event) { + events.addLast(event); + notifyAll(); + } + + /** Remove NEWTEvent from head */ + public synchronized NEWTEvent get() { + if (0 == events.size()) { + return null; + } + + return (NEWTEvent) events.removeFirst(); + } + + /** Get NEWTEvents in queue */ + public synchronized int size() { + return events.size(); + } + + /** Clear all NEWTEvents from queue */ + public synchronized void clear() { + events.clear(); + } + +} diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java b/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java new file mode 100644 index 000000000..677136573 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +public interface NEWTEventListener extends java.util.EventListener +{ +} + diff --git a/src/newt/classes/com/jogamp/newt/event/ScreenModeListener.java b/src/newt/classes/com/jogamp/newt/event/ScreenModeListener.java new file mode 100644 index 000000000..7bca23cfe --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/ScreenModeListener.java @@ -0,0 +1,39 @@ +/** + * 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.newt.event; + +import com.jogamp.newt.ScreenMode; + +public interface ScreenModeListener { + /** called before the screen mode will be changed */ + void screenModeChangeNotify(ScreenMode sm); + + /** called after the screen mode has been changed */ + void screenModeChanged(ScreenMode sm, boolean success); +} diff --git a/src/newt/classes/com/jogamp/newt/event/TraceKeyAdapter.java b/src/newt/classes/com/jogamp/newt/event/TraceKeyAdapter.java new file mode 100644 index 000000000..98ba5a24d --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/TraceKeyAdapter.java @@ -0,0 +1,56 @@ +/** + * 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.newt.event; + +public class TraceKeyAdapter implements KeyListener { + + KeyListener downstream; + + public TraceKeyAdapter() { + this.downstream = null; + } + + public TraceKeyAdapter(KeyListener downstream) { + this.downstream = downstream; + } + + public void keyPressed(KeyEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.keyPressed(e); } + } + public void keyReleased(KeyEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.keyReleased(e); } + } + public void keyTyped(KeyEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.keyTyped(e); } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/TraceMouseAdapter.java b/src/newt/classes/com/jogamp/newt/event/TraceMouseAdapter.java new file mode 100644 index 000000000..14ee633a0 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/TraceMouseAdapter.java @@ -0,0 +1,76 @@ +/** + * 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.newt.event; + +public class TraceMouseAdapter implements MouseListener { + + MouseListener downstream; + + public TraceMouseAdapter() { + this.downstream = null; + } + + public TraceMouseAdapter(MouseListener downstream) { + this.downstream = downstream; + } + + public void mouseClicked(MouseEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.mouseClicked(e); } + } + public void mouseEntered(MouseEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.mouseEntered(e); } + } + public void mouseExited(MouseEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.mouseExited(e); } + } + public void mousePressed(MouseEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.mousePressed(e); } + } + public void mouseReleased(MouseEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.mouseReleased(e); } + } + public void mouseMoved(MouseEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.mouseMoved(e); } + } + public void mouseDragged(MouseEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.mouseDragged(e); } + } + public void mouseWheelMoved(MouseEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.mouseWheelMoved(e); } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java new file mode 100644 index 000000000..8542820c4 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java @@ -0,0 +1,71 @@ +/** + * 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.newt.event; + +public class TraceWindowAdapter implements WindowListener { + + WindowListener downstream; + + public TraceWindowAdapter() { + this.downstream = null; + } + + public TraceWindowAdapter(WindowListener downstream) { + this.downstream = downstream; + } + + public void windowResized(WindowEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.windowResized(e); } + } + public void windowMoved(WindowEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.windowMoved(e); } + } + public void windowDestroyNotify(WindowEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.windowDestroyNotify(e); } + } + public void windowDestroyed(WindowEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.windowDestroyed(e); } + } + public void windowGainedFocus(WindowEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.windowGainedFocus(e); } + } + public void windowLostFocus(WindowEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.windowLostFocus(e); } + } + public void windowRepaint(WindowUpdateEvent e) { + System.err.println(e); + if(null!=downstream) { downstream.windowRepaint(e); } + } +} diff --git a/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java new file mode 100644 index 000000000..b9e487e9b --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java @@ -0,0 +1,47 @@ +/** + * 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.newt.event; + +public abstract class WindowAdapter implements WindowListener +{ + public void windowResized(WindowEvent e) { + } + public void windowMoved(WindowEvent e) { + } + public void windowDestroyNotify(WindowEvent e) { + } + public void windowDestroyed(WindowEvent e) { + } + public void windowGainedFocus(WindowEvent e) { + } + public void windowLostFocus(WindowEvent e) { + } + public void windowRepaint(WindowUpdateEvent e) { + } +} diff --git a/src/newt/classes/com/jogamp/newt/event/WindowEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java new file mode 100644 index 000000000..f3d62d8c6 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +/** + * NEWT Window events are provided for notification purposes ONLY.<br> + * NEWT will automatically handle component moves and resizes internally, regardless of whether a program is receiving these events or not. <br> + * The actual event semantic, here move and resize, is processed before the event is send.<br> + */ +public class WindowEvent extends NEWTEvent { + public static final int EVENT_WINDOW_RESIZED = 100; + public static final int EVENT_WINDOW_MOVED = 101; + public static final int EVENT_WINDOW_DESTROY_NOTIFY = 102; + public static final int EVENT_WINDOW_GAINED_FOCUS = 103; + public static final int EVENT_WINDOW_LOST_FOCUS = 104; + public static final int EVENT_WINDOW_REPAINT = 105; + public static final int EVENT_WINDOW_DESTROYED = 106; + + public WindowEvent(int eventType, Object source, long when) { + super(eventType, source, when); + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_WINDOW_RESIZED: return "WINDOW_RESIZED"; + case EVENT_WINDOW_MOVED: return "WINDOW_MOVED"; + case EVENT_WINDOW_DESTROY_NOTIFY: return "EVENT_WINDOW_DESTROY_NOTIFY"; + case EVENT_WINDOW_GAINED_FOCUS: return "EVENT_WINDOW_GAINED_FOCUS"; + case EVENT_WINDOW_LOST_FOCUS: return "EVENT_WINDOW_LOST_FOCUS"; + case EVENT_WINDOW_REPAINT: return "EVENT_WINDOW_REPAINT"; + case EVENT_WINDOW_DESTROYED: return "EVENT_WINDOW_DESTROYED"; + default: return "unknown (" + type + ")"; + } + } + public String toString() { + return "WindowEvent["+getEventTypeString(getEventType()) + + ", " + super.toString() + "]"; + } +} diff --git a/src/newt/classes/com/jogamp/newt/event/WindowListener.java b/src/newt/classes/com/jogamp/newt/event/WindowListener.java new file mode 100644 index 000000000..e841a06cf --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/WindowListener.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.event; + +public interface WindowListener extends NEWTEventListener { + /** Window is resized, your application shall respect the new window dimension. A repaint is recommended. */ + public void windowResized(WindowEvent e); + + /** Window has been moved. */ + public void windowMoved(WindowEvent e); + + /** Window will be destroyed. Release of resources is recommended. */ + public void windowDestroyNotify(WindowEvent e); + + /** Window has been destroyed.*/ + public void windowDestroyed(WindowEvent e); + + /** Window gained focus. */ + public void windowGainedFocus(WindowEvent e); + + /** Window lost focus. */ + public void windowLostFocus(WindowEvent e); + + /** Window area shall be repainted. */ + public void windowRepaint(WindowUpdateEvent e); +} diff --git a/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java new file mode 100644 index 000000000..7cd6ee370 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java @@ -0,0 +1,49 @@ +/** + * 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.newt.event; + +import javax.media.nativewindow.util.Rectangle; + +public class WindowUpdateEvent extends WindowEvent { + Rectangle bounds; + + public WindowUpdateEvent(int eventType, Object source, long when, Rectangle bounds) + { + super(eventType, source, when); + this.bounds = bounds; + } + + public Rectangle getBounds() { + return bounds; + } + + public String toString() { + return "WindowUpdateEvent["+super.toString()+", "+bounds+"]"; + } +} diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java new file mode 100644 index 000000000..e24002659 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java @@ -0,0 +1,180 @@ +/** + * 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.newt.event.awt; + +import jogamp.newt.Debug; + +/** + * Convenient adapter forwarding AWT events to NEWT via the event listener model.<br> + * <p> + * You may attach an instance of this adapter to an AWT Component. When an event happens, + * it is converted to a NEWT event and the given NEWT listener is being called.<br></p> + * <p> + * This adapter fullfills three use cases. First as a plain utility to write code AWT agnostic, + * ie write an {@link javax.media.opengl.GLEvenListener} and some appropriate NEWT {@link com.jogamp.newt.event.NEWTEventListener}.<br></p> + * <p> + * Attach the {@link javax.media.opengl.GLEvenListener} to a NEWT {@link javax.media.opengl.GLAutoDrawable}, e.g. {@link com.jogamp.newt.opengl.GLWindow},<br> + * or to an AWT {@link javax.media.opengl.GLAutoDrawable}, e.g. {@link javax.media.opengl.awt.GLCanvas}.<br> + * <br> + * Attach the NEWT {@link com.jogamp.newt.event.NEWTEventListener} to a NEWT component, e.g. {@link com.jogamp.newt.Window},<br> + * or to an AWT component, e.g. {@link java.awt.Component}.<br></p> + * <p> + * Common:<br> + * <pre> + // your demo/render code + javax.media.opengl.GLEvenListener demo1 = new javax.media.opengl.GLEvenListener() { ... } ; + + // your AWT agnostic NEWT mouse listener code + com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ; + * </pre> </p> + * <p> + * Default NEWT use case, without using the AWTAdapter:<br> + * <pre> + // the NEWT GLAutoDrawable and Window + GLWindow glWindow = GLWindow.create(); + + // attach the renderer demo1 + glWindow.addGLEventListener(demo1); + + // attach the NEWT mouse event listener to glWindow + glWindow.addMouseListener(mouseListener); + * </pre> </p> + * <p> + * AWT use case, AWTAdapter used as an AWT event translator and forwarder to your NEWT listener:<br> + * <pre> + // the AWT GLAutoDrawable and Canvas + GLCanvas glCanvas = new GLCanvas(); + + // attach the renderer demo1 + glCanvas.addGLEventListener(demo1); + + // attach the AWTMouseAdapter to glCanvas, which translates and forwards events to the NEWT mouseListener + new AWTMouseAdapter(mouseListener).addTo(glCanvas); + * </pre> </p> + * <p> + * Previous code in detail:<br> + * <pre> + AWTMouseAdapter mouseAdapter = new AWTMouseAdapter(mouseListener); + glCanvas.addMouseListener(mouseAdapter); + glCanvas.addMouseMotionListener(mouseAdapter); + * </pre> </p> + * + * <p> + * Second use case is just a litte variation of the previous use case, where we pass a NEWT Window <br> + * to be used as the source of the event.<br></p> + * <p> + * <pre> + com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ;<br> + Component comp = ... ; // the AWT component<br> + GLWindow glWindow = GLWindow.create(); // the NEWT component<br> + <br> + new AWTMouseAdapter(mouseListener, glWindow).addTo(comp);<br> + * </pre> </p> + * + * Last but not least, the AWTAdapter maybe used as a general AWT event forwarder to NEWT.<br> + * + * <p> + * <pre> + com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ;<br> + Component comp = ... ; // the AWT component<br> + GLWindow glWindow = GLWindow.create(); // the NEWT component<br> + glWindow.addMouseListener(mouseListener); // add the custom EventListener to the NEWT component<br> + <br> + new AWTMouseAdapter(glWindow).addTo(comp); // forward all AWT events to glWindow, as NEWT events<br> + * </pre> </p> + * + * @see #attachTo + */ +public abstract class AWTAdapter implements java.util.EventListener +{ + public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); + + com.jogamp.newt.event.NEWTEventListener newtListener; + com.jogamp.newt.Window newtWindow; + + /** + * Simply wrap aroung a NEWT EventListener, exposed as an AWT EventListener.<br> + * The NEWT EventListener will be called when an event happens.<br> + */ + public AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener) { + if(null==newtListener) { + throw new RuntimeException("Argument newtListener is null"); + } + this.newtListener = newtListener; + this.newtWindow = null; + } + + /** + * Wrap aroung a NEWT EventListener, exposed as an AWT EventListener,<br> + * where the given NEWT Window impersonates as the event's source. + * The NEWT EventListener will be called when an event happens.<br> + */ + public AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener, com.jogamp.newt.Window newtProxy) { + if(null==newtListener) { + throw new RuntimeException("Argument newtListener is null"); + } + if(null==newtProxy) { + throw new RuntimeException("Argument newtProxy is null"); + } + this.newtListener = newtListener; + this.newtWindow = newtProxy; + } + + /** + * Create a pipeline adapter, AWT EventListener.<br> + * Once attached to an AWT component, it sends the converted AWT events to the NEWT downstream window.<br> + * This is only supported with EDT enabled! + */ + public AWTAdapter(com.jogamp.newt.Window downstream) { + if(null==downstream) { + throw new RuntimeException("Argument downstream is null"); + } + this.newtListener = null; + this.newtWindow = downstream; + if( null == newtWindow.getScreen().getDisplay().getEDTUtil() ) { + throw new RuntimeException("EDT not enabled"); + } + } + + /** + * Due to the fact that some NEWT {@link com.jogamp.newt.event.NEWTEventListener} + * are mapped to more than one {@link java.util.EventListener}, + * this method is for your convenience to use this Adapter as a listener for all types.<br> + * E.g. {@link com.jogamp.newt.event.MouseListener} is mapped to {@link java.awt.event.MouseListener} and {@link java.awt.event.MouseMotionListener}. + */ + public abstract AWTAdapter addTo(java.awt.Component awtComponent); + + /** @see #addTo(java.awt.Component) */ + public abstract AWTAdapter removeFrom(java.awt.Component awtComponent); + + void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) { + newtWindow.enqueueEvent(wait, event); + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java new file mode 100644 index 000000000..8fe6ff63a --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java @@ -0,0 +1,82 @@ +/** + * 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.newt.event.awt; + +public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListener +{ + public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener) { + super(newtListener); + } + + public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener, com.jogamp.newt.Window newtProxy) { + super(newtListener, newtProxy); + } + + public AWTKeyAdapter(com.jogamp.newt.Window downstream) { + super(downstream); + } + + public AWTAdapter addTo(java.awt.Component awtComponent) { + awtComponent.addKeyListener(this); + return this; + } + + public AWTAdapter removeFrom(java.awt.Component awtComponent) { + awtComponent.removeKeyListener(this); + return this; + } + + public void keyPressed(java.awt.event.KeyEvent e) { + com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.KeyListener)newtListener).keyPressed(event); + } else { + enqueueEvent(false, event); + } + } + + public void keyReleased(java.awt.event.KeyEvent e) { + com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.KeyListener)newtListener).keyReleased(event); + } else { + enqueueEvent(false, event); + } + } + + public void keyTyped(java.awt.event.KeyEvent e) { + com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.KeyListener)newtListener).keyTyped(event); + } else { + enqueueEvent(false, event); + } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java new file mode 100644 index 000000000..bd421073a --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.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.newt.event.awt; + +public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener +{ + public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener) { + super(newtListener); + } + + public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener, com.jogamp.newt.Window newtProxy) { + super(newtListener, newtProxy); + } + + public AWTMouseAdapter(com.jogamp.newt.Window downstream) { + super(downstream); + } + + public AWTAdapter addTo(java.awt.Component awtComponent) { + awtComponent.addMouseListener(this); + awtComponent.addMouseMotionListener(this); + return this; + } + + public AWTAdapter removeFrom(java.awt.Component awtComponent) { + awtComponent.removeMouseListener(this); + awtComponent.removeMouseMotionListener(this); + return this; + } + + public void mouseClicked(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseClicked(event); + } else { + enqueueEvent(false, event); + } + } + + public void mouseEntered(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseEntered(event); + } else { + enqueueEvent(false, event); + } + } + + public void mouseExited(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseExited(event); + } else { + enqueueEvent(false, event); + } + } + + public void mousePressed(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mousePressed(event); + } else { + enqueueEvent(false, event); + } + } + + public void mouseReleased(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseReleased(event); + } else { + enqueueEvent(false, event); + } + } + + public void mouseDragged(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseDragged(event); + } else { + enqueueEvent(false, event); + } + } + + public void mouseMoved(java.awt.event.MouseEvent e) { + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.MouseListener)newtListener).mouseMoved(event); + } else { + enqueueEvent(false, event); + } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java new file mode 100644 index 000000000..20c0d15d1 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java @@ -0,0 +1,146 @@ +/** + * 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.newt.event.awt; + +import com.jogamp.common.util.IntIntHashMap; + +class AWTNewtEventFactory { + + protected static final IntIntHashMap eventTypeAWT2NEWT; + + static { + IntIntHashMap map = new IntIntHashMap(); + map.setKeyNotFoundValue(-1); + // n/a map.put(java.awt.event.WindowEvent.WINDOW_OPENED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_OPENED); + map.put(java.awt.event.WindowEvent.WINDOW_CLOSING, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); + map.put(java.awt.event.WindowEvent.WINDOW_CLOSED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DESTROYED); + // n/a map.put(java.awt.event.WindowEvent.WINDOW_ICONIFIED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_ICONIFIED); + // n/a map.put(java.awt.event.WindowEvent.WINDOW_DEICONIFIED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DEICONIFIED); + map.put(java.awt.event.WindowEvent.WINDOW_ACTIVATED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + map.put(java.awt.event.WindowEvent.WINDOW_GAINED_FOCUS, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + map.put(java.awt.event.FocusEvent.FOCUS_GAINED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + map.put(java.awt.event.WindowEvent.WINDOW_DEACTIVATED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS); + map.put(java.awt.event.WindowEvent.WINDOW_LOST_FOCUS, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS); + map.put(java.awt.event.FocusEvent.FOCUS_LOST, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS); + // n/a map.put(java.awt.event.WindowEvent.WINDOW_STATE_CHANGED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_STATE_CHANGED); + + map.put(java.awt.event.ComponentEvent.COMPONENT_MOVED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_MOVED); + map.put(java.awt.event.ComponentEvent.COMPONENT_RESIZED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_RESIZED); + // n/a map.put(java.awt.event.ComponentEvent.COMPONENT_SHOWN, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_SHOWN); + // n/a map.put(java.awt.event.ComponentEvent.COMPONENT_HIDDEN, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_HIDDEN); + + map.put(java.awt.event.MouseEvent.MOUSE_CLICKED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED); + map.put(java.awt.event.MouseEvent.MOUSE_PRESSED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED); + map.put(java.awt.event.MouseEvent.MOUSE_RELEASED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED); + map.put(java.awt.event.MouseEvent.MOUSE_MOVED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED); + map.put(java.awt.event.MouseEvent.MOUSE_ENTERED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_ENTERED); + map.put(java.awt.event.MouseEvent.MOUSE_EXITED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_EXITED); + map.put(java.awt.event.MouseEvent.MOUSE_DRAGGED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED); + map.put(java.awt.event.MouseEvent.MOUSE_WHEEL, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED); + + map.put(java.awt.event.KeyEvent.KEY_PRESSED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED); + map.put(java.awt.event.KeyEvent.KEY_RELEASED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED); + map.put(java.awt.event.KeyEvent.KEY_TYPED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_TYPED); + + eventTypeAWT2NEWT = map; + } + + public static final int awtModifiers2Newt(int awtMods, boolean mouseHint) { + int newtMods = 0; + if ((awtMods & java.awt.event.InputEvent.SHIFT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.SHIFT_MASK; + if ((awtMods & java.awt.event.InputEvent.CTRL_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.CTRL_MASK; + if ((awtMods & java.awt.event.InputEvent.META_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.META_MASK; + if ((awtMods & java.awt.event.InputEvent.ALT_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_MASK; + if ((awtMods & java.awt.event.InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_GRAPH_MASK; + return newtMods; + } + + public static final int awtButton2Newt(int awtButton) { + switch (awtButton) { + case java.awt.event.MouseEvent.BUTTON1: return com.jogamp.newt.event.MouseEvent.BUTTON1; + case java.awt.event.MouseEvent.BUTTON2: return com.jogamp.newt.event.MouseEvent.BUTTON2; + case java.awt.event.MouseEvent.BUTTON3: return com.jogamp.newt.event.MouseEvent.BUTTON3; + } + return 0; + } + + static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.WindowEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeAWT2NEWT.get(event.getID()); + if(-1 < type) { + return new com.jogamp.newt.event.WindowEvent(type, ((null==newtSource)?(Object)event.getComponent():(Object)newtSource), System.currentTimeMillis()); + } + return null; // no mapping .. + } + + static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.ComponentEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeAWT2NEWT.get(event.getID()); + if(-1 < type) { + return new com.jogamp.newt.event.WindowEvent(type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis()); + } + return null; // no mapping .. + } + + static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.FocusEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeAWT2NEWT.get(event.getID()); + if(-1 < type) { + return new com.jogamp.newt.event.WindowEvent(type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis()); + } + return null; // no mapping .. + } + + static final com.jogamp.newt.event.MouseEvent createMouseEvent(java.awt.event.MouseEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeAWT2NEWT.get(event.getID()); + if(-1 < type) { + int rotation = 0; + if (event instanceof java.awt.event.MouseWheelEvent) { + rotation = ((java.awt.event.MouseWheelEvent)event).getWheelRotation(); + } + + return new com.jogamp.newt.event.MouseEvent( + type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), + awtModifiers2Newt(event.getModifiers(), true), + event.getX(), event.getY(), event.getClickCount(), + awtButton2Newt(event.getButton()), rotation); + } + return null; // no mapping .. + } + + static final com.jogamp.newt.event.KeyEvent createKeyEvent(java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeAWT2NEWT.get(event.getID()); + if(-1 < type) { + return new com.jogamp.newt.event.KeyEvent( + type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), + awtModifiers2Newt(event.getModifiers(), false), + event.getKeyCode(), event.getKeyChar()); + } + return null; // no mapping .. + } + +} + diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java new file mode 100644 index 000000000..68f2b3e0f --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java @@ -0,0 +1,130 @@ +/** + * 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.newt.event.awt; + +/** + * Specialized parent/client adapter, + * where the NEWT child window really gets resized, + * and the parent move window event gets discarded. */ +public class AWTParentWindowAdapter + extends AWTWindowAdapter + implements java.awt.event.HierarchyListener +{ + public AWTParentWindowAdapter(com.jogamp.newt.Window downstream) { + super(downstream); + } + + public AWTAdapter addTo(java.awt.Component awtComponent) { + awtComponent.addHierarchyListener(this); + return super.addTo(awtComponent); + } + + public AWTAdapter removeFrom(java.awt.Component awtComponent) { + awtComponent.removeHierarchyListener(this); + return super.removeFrom(awtComponent); + } + + public void focusGained(java.awt.event.FocusEvent e) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("AWT: focusGained: "+ e); + } + } + + public void focusLost(java.awt.event.FocusEvent e) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("AWT: focusLost: "+ e); + } + } + + public void componentResized(java.awt.event.ComponentEvent e) { + // Need to resize the NEWT child window + // the resized event will be send via the native window feedback. + final java.awt.Component comp = e.getComponent(); + if(DEBUG_IMPLEMENTATION) { + System.err.println("AWT: componentResized: "+comp); + } + if(newtWindow.isValid()) { + newtWindow.runOnEDTIfAvail(false, new Runnable() { + public void run() { + int cw = comp.getWidth(); + int ch = comp.getHeight(); + if( 0 < cw * ch ) { + if( newtWindow.getWidth() != cw || newtWindow.getHeight() != ch ) { + newtWindow.setSize(cw, ch); + if(comp.isVisible() != newtWindow.isVisible()) { + newtWindow.setVisible(comp.isVisible()); + } + } + } else if(newtWindow.isVisible()) { + newtWindow.setVisible(false); + } + }}); + } + } + + public void componentMoved(java.awt.event.ComponentEvent e) { + // no propagation to NEWT child window + } + + public void windowActivated(java.awt.event.WindowEvent e) { + // no propagation to NEWT child window + } + + public void windowDeactivated(java.awt.event.WindowEvent e) { + // no propagation to NEWT child window + } + + public void hierarchyChanged(java.awt.event.HierarchyEvent e) { + if( null == newtListener ) { + long bits = e.getChangeFlags(); + final java.awt.Component changed = e.getChanged(); + if( 0 != ( java.awt.event.HierarchyEvent.SHOWING_CHANGED & bits ) ) { + final boolean showing = changed.isShowing(); + if(DEBUG_IMPLEMENTATION) { + System.err.println("AWT: hierarchyChanged SHOWING_CHANGED: showing "+showing+", "+changed); + } + if(newtWindow.isValid()) { + newtWindow.runOnEDTIfAvail(false, new Runnable() { + public void run() { + if(newtWindow.isVisible() != showing) { + newtWindow.setVisible(showing); + } + }}); + } + } + if(DEBUG_IMPLEMENTATION) { + if( 0 != ( java.awt.event.HierarchyEvent.DISPLAYABILITY_CHANGED & bits ) ) { + final boolean displayability = changed.isDisplayable(); + System.err.println("AWT: hierarchyChanged DISPLAYABILITY_CHANGED: displayability "+displayability+", "+changed); + } + } + } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java new file mode 100644 index 000000000..85fe5407b --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java @@ -0,0 +1,204 @@ +/** + * 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.newt.event.awt; + +public class AWTWindowAdapter + extends AWTAdapter + implements java.awt.event.ComponentListener, java.awt.event.WindowListener, java.awt.event.FocusListener +{ + WindowClosingListener windowClosingListener; + + public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener) { + super(newtListener); + } + + public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener, com.jogamp.newt.Window newtProxy) { + super(newtListener, newtProxy); + } + + public AWTWindowAdapter(com.jogamp.newt.Window downstream) { + super(downstream); + } + + public AWTAdapter addTo(java.awt.Component awtComponent) { + java.awt.Window win = getWindow(awtComponent); + awtComponent.addComponentListener(this); + awtComponent.addFocusListener(this); + if( null == windowClosingListener ) { + windowClosingListener = new WindowClosingListener(); + } + if( null != win ) { + win.addWindowListener(windowClosingListener); + } + if(awtComponent instanceof java.awt.Window) { + ((java.awt.Window)awtComponent).addWindowListener(this); + } + return this; + } + + public AWTAdapter removeFrom(java.awt.Component awtComponent) { + awtComponent.removeFocusListener(this); + awtComponent.removeComponentListener(this); + java.awt.Window win = getWindow(awtComponent); + if( null != win && null != windowClosingListener ) { + win.removeWindowListener(windowClosingListener); + } + if(awtComponent instanceof java.awt.Window) { + ((java.awt.Window)awtComponent).removeWindowListener(this); + } + return this; + } + + static java.awt.Window getWindow(java.awt.Component comp) { + while( null != comp && !(comp instanceof java.awt.Window) ) { + comp = comp.getParent(); + } + if(comp instanceof java.awt.Window) { + return (java.awt.Window) comp; + } + return null; + } + + public void focusGained(java.awt.event.FocusEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event); + } else { + enqueueEvent(false, event); + } + } + + public void focusLost(java.awt.event.FocusEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event); + } else { + enqueueEvent(false, event); + } + } + + public void componentResized(java.awt.event.ComponentEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowResized(event); + } else { + enqueueEvent(false, event); + } + } + + public void componentMoved(java.awt.event.ComponentEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowMoved(event); + } else { + enqueueEvent(false, event); + } + } + + public void componentShown(java.awt.event.ComponentEvent e) { + final java.awt.Component comp = e.getComponent(); + if(DEBUG_IMPLEMENTATION) { + System.err.println("AWT: componentShown: "+comp); + } + /** + if(null==newtListener) { + if(newtWindow.isValid()) { + newtWindow.runOnEDTIfAvail(false, new Runnable() { + public void run() { + newtWindow.setVisible(true); + } + }); + } + }*/ + } + + public void componentHidden(java.awt.event.ComponentEvent e) { + final java.awt.Component comp = e.getComponent(); + if(DEBUG_IMPLEMENTATION) { + System.err.println("AWT: componentHidden: "+comp); + } + /** + if(null==newtListener) { + if(newtWindow.isValid()) { + newtWindow.runOnEDTIfAvail(false, new Runnable() { + public void run() { + newtWindow.setVisible(false); + } + }); + } + }*/ + } + + public void windowActivated(java.awt.event.WindowEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event); + } else { + enqueueEvent(false, event); + } + } + + public void windowClosed(java.awt.event.WindowEvent e) { } + + public void windowClosing(java.awt.event.WindowEvent e) { } + + public void windowDeactivated(java.awt.event.WindowEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event); + } else { + enqueueEvent(false, event); + } + } + + public void windowDeiconified(java.awt.event.WindowEvent e) { } + + public void windowIconified(java.awt.event.WindowEvent e) { } + + public void windowOpened(java.awt.event.WindowEvent e) { } + + class WindowClosingListener implements java.awt.event.WindowListener { + public void windowClosing(java.awt.event.WindowEvent e) { + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + if(null!=newtListener) { + ((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyNotify(event); + } else { + enqueueEvent(true, event); + } + } + + public void windowActivated(java.awt.event.WindowEvent e) { } + public void windowClosed(java.awt.event.WindowEvent e) { } + public void windowDeactivated(java.awt.event.WindowEvent e) { } + public void windowDeiconified(java.awt.event.WindowEvent e) { } + public void windowIconified(java.awt.event.WindowEvent e) { } + public void windowOpened(java.awt.event.WindowEvent e) { } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java new file mode 100644 index 000000000..efbd9594b --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -0,0 +1,938 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.jogamp.newt.opengl; + +import java.util.List; + +import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.nativewindow.NativeWindowVersion; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import jogamp.newt.WindowImpl; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Point; +import javax.media.nativewindow.util.Insets; +import javax.media.opengl.*; + +import jogamp.opengl.GLDrawableHelper; +import com.jogamp.opengl.JoglVersion; + +/** + * An implementation of {@link javax.media.opengl.GLAutoDrawable} interface, + * using an aggregation of a {@link com.jogamp.newt.Window} implementation. + * <P> + * This implementation does not make the OpenGL context current<br> + * before calling the various input EventListener callbacks, ie {@link com.jogamp.newt.event.MouseListener} etc.<br> + * This design decision is made in favor of a more performant and simplified + * implementation. Also the event dispatcher shall be implemented OpenGL agnostic.<br> + * To be able to use OpenGL commands from within such input {@link com.jogamp.newt.event.NEWTEventListener},<br> + * you can inject {@link javax.media.opengl.GLRunnable} objects + * via {@link #invoke(boolean, javax.media.opengl.GLRunnable)} to the OpenGL command stream.<br> + * <p> + */ +public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { + private WindowImpl window; + + /** + * Constructor. Do not call this directly -- use {@link #create()} instead. + */ + protected GLWindow(Window window) { + resetCounter(); + this.window = (WindowImpl) window; + ((WindowImpl)this.window).setHandleDestroyNotify(false); + window.addWindowListener(new WindowAdapter() { + @Override + public void windowRepaint(WindowUpdateEvent e) { + if( !GLWindow.this.window.isWindowLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { + display(); + } + } + + @Override + public void windowResized(WindowEvent e) { + sendReshape = true; + if( !GLWindow.this.window.isWindowLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { + display(); + } + } + + @Override + public void windowDestroyNotify(WindowEvent e) { + if( DISPOSE_ON_CLOSE == GLWindow.this.getDefaultCloseOperation() ) { + // Is an animator thread perform rendering? + if (GLWindow.this.helper.isExternalAnimatorRunning()) { + // Pause animations before initiating safe destroy. + GLAnimatorControl ctrl = GLWindow.this.helper.getAnimator(); + boolean isPaused = ctrl.pause(); + destroy(); + if(isPaused) { + ctrl.resume(); + } + } else if (GLWindow.this.window.isWindowLockedByOtherThread()) { + // Window is locked by another thread + // Flag that destroy should be performed on the next + // attempt to display. + sendDestroy = true; + } else { + // Without an external thread animating or locking the + // surface, we are safe. + destroy (); + } + } + } + }); + this.window.setLifecycleHook(new GLLifecycleHook()); + } + + /** + * Creates a new GLWindow attaching a new Window referencing a new Screen + * with the given GLCapabilities. + * <P> + * The resulting GLWindow owns the Window, Screen and Device, ie it will be destructed. + */ + public static GLWindow create(GLCapabilitiesImmutable caps) { + return new GLWindow(NewtFactory.createWindow(caps)); + } + + /** + * Creates a new GLWindow attaching a new Window referencing the given Screen + * with the given GLCapabilities. + * <P> + * The resulting GLWindow owns the Window, ie it will be destructed. + */ + public static GLWindow create(Screen screen, GLCapabilitiesImmutable caps) { + return new GLWindow(NewtFactory.createWindow(screen, caps)); + } + + /** + * Creates a new GLWindow attaching the given window. + * <P> + * The resulting GLWindow does not own the given Window, ie it will not be destructed. + */ + public static GLWindow create(Window window) { + return new GLWindow(window); + } + + /** + * Creates a new GLWindow attaching a new child Window + * of the given <code>parentNativeWindow</code> with the given GLCapabilities. + * <P> + * The Display/Screen will be compatible with the <code>parentNativeWindow</code>, + * or even identical in case it's a Newt Window. + * <P> + * The resulting GLWindow owns the Window, ie it will be destructed. + */ + public static GLWindow create(NativeWindow parentNativeWindow, GLCapabilitiesImmutable caps) { + return new GLWindow(NewtFactory.createWindow(parentNativeWindow, caps)); + } + + //---------------------------------------------------------------------- + // WindowClosingProtocol implementation + // + public int getDefaultCloseOperation() { + return window.getDefaultCloseOperation(); + } + + public int setDefaultCloseOperation(int op) { + return window.setDefaultCloseOperation(op); + } + + //---------------------------------------------------------------------- + // Window Access + // + + public CapabilitiesChooser setCapabilitiesChooser(CapabilitiesChooser chooser) { + return window.setCapabilitiesChooser(chooser); + } + + public final CapabilitiesImmutable getChosenCapabilities() { + if (drawable == null) { + return window.getChosenCapabilities(); + } + + return drawable.getChosenGLCapabilities(); + } + + public final CapabilitiesImmutable getRequestedCapabilities() { + return window.getRequestedCapabilities(); + } + + public final Window getWindow() { + return window; + } + + public final NativeWindow getParent() { + return window.getParent(); + } + + public final Screen getScreen() { + return window.getScreen(); + } + + public final void setTitle(String title) { + window.setTitle(title); + } + + public final String getTitle() { + return window.getTitle(); + } + + public final void setUndecorated(boolean value) { + window.setUndecorated(value); + } + + public final boolean isUndecorated() { + return window.isUndecorated(); + } + + public final void setFocusAction(FocusRunnable focusAction) { + window.setFocusAction(focusAction); + } + + public final void requestFocus() { + window.requestFocus(); + } + + public boolean hasFocus() { + return window.hasFocus(); + } + + public final Insets getInsets() { + return window.getInsets(); + } + + public final void setPosition(int x, int y) { + window.setPosition(x, y); + } + + public final boolean setFullscreen(boolean fullscreen) { + return window.setFullscreen(fullscreen); + } + + public final boolean isFullscreen() { + return window.isFullscreen(); + } + + public final boolean isVisible() { + return window.isVisible(); + } + + @Override + public final String toString() { + return "NEWT-GLWindow[ \n\tHelper: " + helper + ", \n\tDrawable: " + drawable + + ", \n\tContext: " + context + /** ", \n\tWindow: "+window+", \n\tFactory: "+factory+ */ "]"; + } + + public final int reparentWindow(NativeWindow newParent) { + return window.reparentWindow(newParent); + } + + public final int reparentWindow(NativeWindow newParent, boolean forceDestroyCreate) { + return window.reparentWindow(newParent, forceDestroyCreate); + } + + public final void removeChild(NativeWindow win) { + window.removeChild(win); + } + + public final void addChild(NativeWindow win) { + window.addChild(win); + } + + //---------------------------------------------------------------------- + // Window.LifecycleHook Implementation + // + + public final void destroy() { + window.destroy(); + } + + public final void setVisible(boolean visible) { + window.setVisible(visible); + } + + public final void setSize(int width, int height) { + window.setSize(width, height); + } + + public final boolean isValid() { + return window.isValid(); + } + + public final boolean isNativeValid() { + return window.isNativeValid(); + } + + public Point getLocationOnScreen(Point storage) { + return window.getLocationOnScreen(storage); + } + + // Hide methods here .. + protected class GLLifecycleHook implements WindowImpl.LifecycleHook { + + private class DisposeAction implements Runnable { + public final void run() { + // Lock: Covered by DestroyAction .. + helper.dispose(GLWindow.this); + } + } + DisposeAction disposeAction = new DisposeAction(); + + public synchronized void destroyActionPreLock() { + // nop + } + + public synchronized void destroyActionInLock() { + if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { + String msg = "GLWindow.destroy() "+Thread.currentThread()+", start"; + System.err.println(msg); + //Exception e1 = new Exception(msg); + //e1.printStackTrace(); + } + + if( window.isNativeValid() && null != drawable && drawable.isRealized() ) { + if( null != context && context.isCreated() ) { + // Catch dispose GLExceptions by GLEventListener, just 'print' them + // so we can continue with the destruction. + try { + helper.invokeGL(drawable, context, disposeAction, null); + } catch (GLException gle) { + gle.printStackTrace(); + } + context.destroy(); + } + drawable.setRealized(false); + } + context = null; + drawable = null; + + if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { + System.err.println("GLWindow.destroy() "+Thread.currentThread()+", fin"); + } + } + + public synchronized void invalidate(boolean unrecoverable) { + if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { + String msg = "GLWindow.invalidate("+unrecoverable+") "+Thread.currentThread()+", start"; + System.err.println(msg); + //Exception e1 = new Exception(msg); + //e1.printStackTrace(); + } + if(unrecoverable) { + GLAnimatorControl ctrl = GLWindow.this.getAnimator(); + if ( null!=ctrl ) { + ctrl.remove(GLWindow.this); + } + helper=null; + } + } + + public synchronized void resetCounter() { + if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { + System.err.println("GLWindow.resetCounter() "+Thread.currentThread()); + } + GLWindow.this.resetCounter(); + } + + public synchronized void setVisibleActionPost(boolean visible, boolean nativeWindowCreated) { + if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { + String msg = "GLWindow.setVisibleActionPost("+visible+", "+nativeWindowCreated+") "+Thread.currentThread()+", start"; + System.err.println(msg); + // Exception e1 = new Exception(msg); + // e1.printStackTrace(); + } + + /* if (nativeWindowCreated && null != context) { + throw new GLException("InternalError: Native Windows has been just created, but context wasn't destroyed (is not null)"); + } */ + if (null == context && visible && 0 != window.getWindowHandle() && 0<getWidth()*getHeight()) { + NativeWindow nw; + if (window.getWrappedWindow() != null) { + nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); + } else { + nw = window; + } + GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) nw.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + if(null==factory) { + factory = GLDrawableFactory.getFactory(glCaps.getGLProfile()); + } + if(null==drawable) { + drawable = factory.createGLDrawable(nw); + } + drawable.setRealized(true); + context = drawable.createContext(sharedContext); + } + if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { + String msg = "GLWindow.setVisibleActionPost("+visible+", "+nativeWindowCreated+") "+Thread.currentThread()+", fin"; + System.err.println(msg); + //Exception e1 = new Exception(msg); + //e1.printStackTrace(); + } + } + + public synchronized boolean pauseRenderingAction() { + boolean animatorPaused = false; + GLAnimatorControl ctrl = GLWindow.this.getAnimator(); + if ( null!=ctrl ) { + animatorPaused = ctrl.pause(); + } + return animatorPaused; + } + + public synchronized void resumeRenderingAction() { + GLAnimatorControl ctrl = GLWindow.this.getAnimator(); + if ( null!=ctrl && ctrl.isPaused() ) { + ctrl.resume(); + } + } + } + + //---------------------------------------------------------------------- + // OpenGL-related methods and state + // + + private GLContext sharedContext = null; + private GLDrawableFactory factory; + private GLDrawable drawable; + private GLContext context; + private GLDrawableHelper helper = new GLDrawableHelper(); + // To make reshape events be sent immediately before a display event + private boolean sendReshape=false; + private boolean sendDestroy=false; + private boolean perfLog = false; + private long startTime, curTime, lastCheck; + private int totalFrames, lastFrames; + + public GLDrawableFactory getFactory() { + return factory; + } + + /** + * Specifies an {@link javax.media.opengl.GLContext OpenGL context} to share with.<br> + * At native creation, {@link #setVisible(boolean) setVisible(true)}, + * a {@link javax.media.opengl.GLDrawable drawable} and {@link javax.media.opengl.GLContext context} is created besides the native Window itself,<br> + * hence you shall set the shared context before. + * + * @param sharedContext The OpenGL context shared by this GLWindow's one + */ + public void setSharedContext(GLContext sharedContext) { + this.sharedContext = sharedContext; + } + + public void setContext(GLContext newCtx) { + context = newCtx; + } + + public GLContext getContext() { + return context; + } + + public GL getGL() { + if (context == null) { + return null; + } + return context.getGL(); + } + + public GL setGL(GL gl) { + if (context != null) { + context.setGL(gl); + return gl; + } + return null; + } + + public void addGLEventListener(GLEventListener listener) { + if(null!=helper) { + helper.addGLEventListener(listener); + } + } + + public void addGLEventListener(int index, GLEventListener listener) { + if(null!=helper) { + helper.addGLEventListener(index, listener); + } + } + + public void removeGLEventListener(GLEventListener listener) { + if(null!=helper) { + helper.removeGLEventListener(listener); + } + } + + public void setAnimator(GLAnimatorControl animatorControl) { + if(null!=helper) { + helper.setAnimator(animatorControl); + } + } + + public GLAnimatorControl getAnimator() { + if(null!=helper) { + return helper.getAnimator(); + } + return null; + } + + public boolean getPerfLogEnabled() { return perfLog; } + + public void enablePerfLog(boolean v) { + perfLog = v; + } + + public void invoke(boolean wait, GLRunnable glRunnable) { + if(null!=helper) { + helper.invoke(this, wait, glRunnable); + } + } + + public void display() { + display(false); + } + + public void display(boolean forceReshape) { + if( null == window ) { return; } + + if(sendDestroy || ( null!=window && window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) ) { + sendDestroy=false; + destroy(); + return; + } + + if( null == context && isVisible() && 0<getWidth()*getHeight() ) { + // retry native window and drawable/context creation + setVisible(true); + } + + if(forceReshape) { + sendReshape = true; + } + + if( isVisible() && null != context ) { + if( NativeSurface.LOCK_SURFACE_NOT_READY < lockSurface() ) { + try { + helper.invokeGL(drawable, context, displayAction, initAction); + } finally { + unlockSurface(); + } + } + } + } + + /** This implementation uses a static value */ + public void setAutoSwapBufferMode(boolean onOrOff) { + if(null!=helper) { + helper.setAutoSwapBufferMode(onOrOff); + } + } + + /** This implementation uses a static value */ + public boolean getAutoSwapBufferMode() { + if(null!=helper) { + return helper.getAutoSwapBufferMode(); + } + return false; + } + + public void swapBuffers() { + if(drawable!=null && context != null) { + // Lock: Locked Surface/Window by MakeCurrent/Release + if (context != GLContext.getCurrent()) { + // Assume we should try to make the context current before swapping the buffers + helper.invokeGL(drawable, context, swapBuffersAction, initAction); + } else { + drawable.swapBuffers(); + } + } + } + + private class InitAction implements Runnable { + public final void run() { + // Lock: Locked Surface/Window by MakeCurrent/Release + helper.init(GLWindow.this); + resetCounter(); + } + } + private InitAction initAction = new InitAction(); + + private class DisplayAction implements Runnable { + public final void run() { + // Lock: Locked Surface/Window by display _and_ MakeCurrent/Release + if (sendReshape) { + helper.reshape(GLWindow.this, 0, 0, getWidth(), getHeight()); + sendReshape = false; + } + + helper.display(GLWindow.this); + + curTime = System.currentTimeMillis(); + totalFrames++; + + if(perfLog) { + long dt0, dt1; + lastFrames++; + dt0 = curTime-lastCheck; + if ( dt0 > 5000 ) { + dt1 = curTime-startTime; + System.err.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+ + "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f"); + lastCheck=curTime; + lastFrames=0; + } + } + } + } + private DisplayAction displayAction = new DisplayAction(); + + /** + * @return Time of the first display call in milliseconds. + * This value is reset if becoming visible again or reparenting. + */ + public final long getStartTime() { + return startTime; + } + + /** + * @return Time of the last display call in milliseconds. + * This value is reset if becoming visible again or reparenting. + */ + public final long getCurrentTime() { + return curTime; + } + + /** + * @return Duration <code>getCurrentTime() - getStartTime()</code>. + * + * @see #getStartTime() + * @see #getCurrentTime() + */ + public final long getDuration() { + return getCurrentTime()-getStartTime(); + } + + /** + * @return Number of frames displayed since the first display call, ie <code>getStartTime()</code>. + * This value is reset if becoming visible again or reparenting. + */ + public final int getTotalFrames() { + return totalFrames; + } + + /** Reset all counter (startTime, currentTime, frame number) */ + public final synchronized void resetCounter() { + startTime = System.currentTimeMillis(); // overwrite startTime to real init one + curTime = startTime; + lastCheck = startTime; + totalFrames = 0; lastFrames = 0; + } + + private class SwapBuffersAction implements Runnable { + public final void run() { + drawable.swapBuffers(); + } + } + private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); + + //---------------------------------------------------------------------- + // GLDrawable methods + // + + public final NativeSurface getNativeSurface() { + return null!=drawable ? drawable.getNativeSurface() : null; + } + + public final long getHandle() { + return null!=drawable ? drawable.getHandle() : 0; + } + + public final int getX() { + return window.getX(); + } + + public final int getY() { + return window.getY(); + } + + public final int getWidth() { + return window.getWidth(); + } + + public final int getHeight() { + return window.getHeight(); + } + + //---------------------------------------------------------------------- + // GLDrawable methods that are not really needed + // + + public final GLContext createContext(GLContext shareWith) { + return drawable.createContext(shareWith); + } + + public final void setRealized(boolean realized) { + } + + public final boolean isRealized() { + return ( null != drawable ) ? drawable.isRealized() : false; + } + + public final GLCapabilitiesImmutable getChosenGLCapabilities() { + if (drawable == null) { + throw new GLException("No drawable yet"); + } + + return drawable.getChosenGLCapabilities(); + } + + public final GLProfile getGLProfile() { + if (drawable == null) { + throw new GLException("No drawable yet"); + } + + return drawable.getGLProfile(); + } + + //---------------------------------------------------------------------- + // NEWTEventConsumer + // + public boolean consumeEvent(NEWTEvent event) { + return window.consumeEvent(event); + } + + //---------------------------------------------------------------------- + // Window completion + // + public final void windowRepaint(int x, int y, int width, int height) { + window.windowRepaint(x, y, width, height); + } + + public final void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) { + window.enqueueEvent(wait, event); + } + + public final void runOnEDTIfAvail(boolean wait, final Runnable task) { + window.runOnEDTIfAvail(wait, task); + } + + public final SurfaceUpdatedListener getSurfaceUpdatedListener(int index) { + return window.getSurfaceUpdatedListener(index); + } + + public final SurfaceUpdatedListener[] getSurfaceUpdatedListeners() { + return window.getSurfaceUpdatedListeners(); + } + + public final void removeAllSurfaceUpdatedListener() { + window.removeAllSurfaceUpdatedListener(); + } + + public final void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { + window.removeSurfaceUpdatedListener(l); + } + + public final void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { + window.addSurfaceUpdatedListener(l); + } + + public final void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) throws IndexOutOfBoundsException { + window.addSurfaceUpdatedListener(index, l); + } + + public void sendWindowEvent(int eventType) { + window.sendWindowEvent(eventType); + } + + public final WindowListener getWindowListener(int index) { + return window.getWindowListener(index); + } + + public final WindowListener[] getWindowListeners() { + return window.getWindowListeners(); + } + + public final void removeWindowListener(WindowListener l) { + window.removeWindowListener(l); + } + + public final void addWindowListener(WindowListener l) { + window.addWindowListener(l); + } + + public final void addWindowListener(int index, WindowListener l) throws IndexOutOfBoundsException { + window.addWindowListener(index, l); + } + + public final void addKeyListener(KeyListener l) { + window.addKeyListener(l); + } + + public final void addKeyListener(int index, KeyListener l) { + window.addKeyListener(index, l); + } + + public final void removeKeyListener(KeyListener l) { + window.removeKeyListener(l); + } + + public final KeyListener getKeyListener(int index) { + return window.getKeyListener(index); + } + + public final KeyListener[] getKeyListeners() { + return window.getKeyListeners(); + } + + public final void addMouseListener(MouseListener l) { + window.addMouseListener(l); + } + + public final void addMouseListener(int index, MouseListener l) { + window.addMouseListener(index, l); + } + + public final void removeMouseListener(MouseListener l) { + window.removeMouseListener(l); + } + + public final MouseListener getMouseListener(int index) { + return window.getMouseListener(index); + } + + public final MouseListener[] getMouseListeners() { + return window.getMouseListeners(); + } + + //---------------------------------------------------------------------- + // NativeWindow completion + // + + public final int lockSurface() { + return window.lockSurface(); + } + + public final void unlockSurface() throws NativeWindowException { + window.unlockSurface(); + } + + public final boolean isSurfaceLockedByOtherThread() { + return window.isSurfaceLockedByOtherThread(); + } + + public final boolean isSurfaceLocked() { + return window.isSurfaceLocked(); + } + + public final Thread getSurfaceLockOwner() { + return window.getSurfaceLockOwner(); + + } + + public final boolean surfaceSwap() { + return window.surfaceSwap(); + } + + public final void invalidate() { + window.invalidate(); + } + + public final long getWindowHandle() { + return window.getWindowHandle(); + + } + + public final long getSurfaceHandle() { + return window.getSurfaceHandle(); + + } + + public final AbstractGraphicsConfiguration getGraphicsConfiguration() { + return window.getGraphicsConfiguration(); + } + + public final long getDisplayHandle() { + return window.getDisplayHandle(); + } + + public final int getScreenIndex() { + return window.getScreenIndex(); + } + + public final void surfaceUpdated(Object updater, NativeSurface ns, long when) { + window.surfaceUpdated(updater, ns, when); + } + + /** + * A most simple JOGL AWT test entry + */ + public static void main(String args[]) { + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(GlueGenVersion.getInstance()); + System.err.println(NativeWindowVersion.getInstance()); + System.err.println(JoglVersion.getInstance()); + System.err.println(NewtVersion.getInstance()); + + GLProfile glp = GLProfile.getDefault(); + GLDrawableFactory factory = GLDrawableFactory.getFactory(glp); + List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null); + for(int i=0; i<availCaps.size(); i++) { + System.err.println(availCaps.get(i)); + } + GLCapabilitiesImmutable caps = new GLCapabilities( glp ); + + GLWindow glWindow = GLWindow.create(caps); + glWindow.setSize(128, 128); + + glWindow.addGLEventListener(new GLEventListener() { + public void init(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + System.err.println(JoglVersion.getGLInfo(gl, null)); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void display(GLAutoDrawable drawable) { + } + + public void dispose(GLAutoDrawable drawable) { + } + }); + + glWindow.setVisible(true); + glWindow.invalidate(); + } + +} diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java new file mode 100644 index 000000000..d1a11a788 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java @@ -0,0 +1,115 @@ +/** + * 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.newt.util; + +/** + * EDT stands for Event Dispatch Thread. + * <p> + * EDTUtil comprises the functionality of: + * <ul> + * <li> Periodically issuing an event dispatch command on the EDT.</li> + * <li> Ability to enqueue tasks, executed on the EDT.</li> + * <li> Controlling the EDT, ie start and stop in a sane manner.</li> + * </ul> + * The EDT pattern is a common tool to comply with todays windowing toolkits, + * where the common denominator in regards to multithreading is to: + * <ul> + * <li> Create a Window on one thread </li> + * <li> Modify the Window within the same thread </li> + * <li> Handle incoming events from within the same thread </li> + * </ul> + * Note: This is not true on MacOSX, where all these actions have to be + * performed by a unique, so called main thread.<br> + */ +public interface EDTUtil { + + public static final long defaultEDTPollGranularity = 10; // 10ms, 1/100s + + /** + * Create a new EDT. One should invoke <code>reset()</code><br> + * after <code>invokeStop(..)</code> in case another <code>start()</code> or <code>invoke(..)</code> + * is expected. + * + * @see #start() + * @see #invoke(boolean, java.lang.Runnable) + * @see #invokeStop(java.lang.Runnable) + */ + public void reset(); + + /** + * Start the EDT + */ + public void start(); + + /** + * @return True if the current thread is the EDT thread + */ + public boolean isCurrentThreadEDT(); + + /** + * @return True if EDT is running + */ + public boolean isRunning(); + + /** + * Append the final task to the EDT task queue, + * signals EDT to stop and wait until stopped.<br> + * Due to the nature of this method: + * <ul> + * <li>All previous queued tasks will be finished.</li> + * <li>No new tasks are allowed, an Exception is thrown.</li> + * <li>Can be issued from within EDT, ie from within an enqueued task.</li> + * <li>{@link #reset()} may follow immediately, ie creating a new EDT</li> + * </ul> + */ + public void invokeStop(Runnable finalTask); + + /** + * Append task to the EDT task queue.<br> + * Wait until execution is finished if <code>wait == true</code>.<br> + * Shall start the thread if not running.<br> + * Can be issued from within EDT, ie from within an enqueued task.<br> + * + * @throws RuntimeException in case EDT is stopped and not {@link #reset()} + */ + public void invoke(boolean wait, Runnable task); + + /** + * Wait until the EDT task queue is empty.<br> + * The last task may still be in execution when this method returns. + */ + public void waitUntilIdle(); + + /** + * Wait until EDT task is stopped.<br> + * No <code>stop</code> action is performed, {@link #invokeStop(java.lang.Runnable)} should be used before. + */ + public void waitUntilStopped(); +} + diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java new file mode 100644 index 000000000..8bb725b99 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -0,0 +1,406 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.jogamp.newt.util; + +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; + +import javax.media.nativewindow.NativeWindowFactory; + +import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.common.util.RunnableTask; +import com.jogamp.newt.Display; +import jogamp.newt.Debug; +import jogamp.newt.NEWTJNILibLoader; +import jogamp.newt.awt.AWTEDTUtil; + +/** + * NEWT Utility class MainThread<P> + * + * This class provides a startup singleton <i>main thread</i>, + * from which a new thread with the users main class is launched.<br> + * + * Such behavior is necessary for native windowing toolkits, + * where the windowing management must happen on the so called + * <i>main thread</i> e.g. for Mac OS X !<br> + * + * Utilizing this class as a launchpad, now you are able to + * use a NEWT multithreaded application with window handling within the different threads, + * even on these restricted platforms.<br> + * + * To support your NEWT Window platform, + * you have to pass your <i>main thread</i> actions to {@link #invoke invoke(..)}, + * have a look at the {@link com.jogamp.newt.macosx.MacWindow MacWindow} implementation.<br> + * <i>TODO</i>: Some hardcoded dependencies exist in this implementation, + * where you have to patch this code or factor it out. <P> + * + * If your platform is not Mac OS X, but you want to test your code without modifying + * this class, you have to set the system property <code>newt.MainThread.force</code> to <code>true</code>.<P> + * + * The code is compatible with all other platform, which support multithreaded windowing handling. + * Since those platforms won't trigger the <i>main thread</i> serialization, the main method + * will be simply executed, in case you haven't set <code>newt.MainThread.force</code> to <code>true</code>.<P> + * + * Test case on Mac OS X (or any other platform): + <PRE> + java -XstartOnFirstThread com.jogamp.newt.util.MainThread demos.es1.RedSquare -GL2 -GL2 -GL2 -GL2 + </PRE> + * Which starts 4 threads, each with a window and OpenGL rendering.<br> + */ +public class MainThread implements EDTUtil { + private static final AccessControlContext localACC = AccessController.getContext(); + public static final boolean MAIN_THREAD_CRITERIA = ( !NativeWindowFactory.isAWTAvailable() && + NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false)) + ) || Debug.getBooleanProperty("newt.MainThread.force", true, localACC); + + protected static final boolean DEBUG = Debug.debug("MainThread"); + + private static final MainThread singletonMainThread = new MainThread(); // one singleton MainThread + + private static boolean isExit=false; + private static volatile boolean isRunning=false; + private static final Object taskWorkerLock=new Object(); + private static boolean shouldStop; + private static ArrayList tasks; + private static Thread mainThread; + + private static Timer pumpMessagesTimer=null; + private static TimerTask pumpMessagesTimerTask=null; + private static final Map/*<Display, Runnable>*/ pumpMessageDisplayMap = new HashMap(); + + private static boolean useMainThread = false; + + static class MainAction extends Thread { + private String mainClassName; + private String[] mainClassArgs; + + private Method mainClassMain; + + public MainAction(String mainClassName, String[] mainClassArgs) { + this.mainClassName=mainClassName; + this.mainClassArgs=mainClassArgs; + } + + @Override + public void run() { + if ( useMainThread ) { + // we have to start first to provide the service .. + singletonMainThread.waitUntilRunning(); + } + + // start user app .. + try { + Class mainClass = ReflectionUtil.getClass(mainClassName, true, getClass().getClassLoader()); + if(null==mainClass) { + throw new RuntimeException(new ClassNotFoundException("MainThread couldn't find main class "+mainClassName)); + } + try { + mainClassMain = mainClass.getDeclaredMethod("main", new Class[] { String[].class }); + mainClassMain.setAccessible(true); + } catch (Throwable t) { + throw new RuntimeException(t); + } + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" invoke "+mainClassName); + mainClassMain.invoke(null, new Object[] { mainClassArgs } ); + } catch (InvocationTargetException ite) { + ite.getTargetException().printStackTrace(); + } catch (Throwable t) { + t.printStackTrace(); + } + + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" user app fin"); + + if ( useMainThread ) { + singletonMainThread.invokeStop(new Runnable() { + public void run() { + // nop + }}); + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" MainThread fin - stop"); + System.exit(0); + } + } + } + private static MainAction mainAction; + + /** Your new java application main entry, which pipelines your application */ + public static void main(String[] args) { + useMainThread = MAIN_THREAD_CRITERIA; + + if(DEBUG) System.err.println("MainThread.main(): "+Thread.currentThread().getName()+" useMainThread "+ useMainThread ); + + if(args.length==0) { + return; + } + + String mainClassName=args[0]; + String[] mainClassArgs=new String[args.length-1]; + if(args.length>1) { + System.arraycopy(args, 1, mainClassArgs, 0, args.length-1); + } + + NEWTJNILibLoader.loadNEWT(); + + mainAction = new MainAction(mainClassName, mainClassArgs); + + if(NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false))) { + ReflectionUtil.callStaticMethod("jogamp.newt.macosx.MacDisplay", "initSingleton", + null, null, MainThread.class.getClassLoader()); + } + + if ( useMainThread ) { + shouldStop = false; + tasks = new ArrayList(); + mainThread = Thread.currentThread(); + + // dispatch user's main thread .. + mainAction.start(); + + // do our main thread task scheduling + singletonMainThread.run(); + } else { + // run user's main in this thread + mainAction.run(); + } + } + + public static MainThread getSingleton() { + return singletonMainThread; + } + + public static Runnable removePumpMessage(Display dpy) { + synchronized(pumpMessageDisplayMap) { + return (Runnable) pumpMessageDisplayMap.remove(dpy); + } + } + + public static void addPumpMessage(Display dpy, Runnable pumpMessage) { + if ( useMainThread ) { + return; // error ? + } + synchronized (pumpMessageDisplayMap) { + if(null == pumpMessagesTimer) { + pumpMessagesTimer = new Timer(); + pumpMessagesTimerTask = new TimerTask() { + public void run() { + synchronized(pumpMessageDisplayMap) { + for(Iterator i = pumpMessageDisplayMap.values().iterator(); i.hasNext(); ) { + ((Runnable) i.next()).run(); + } + } + } + }; + pumpMessagesTimer.scheduleAtFixedRate(pumpMessagesTimerTask, 0, defaultEDTPollGranularity); + } + pumpMessageDisplayMap.put(dpy, pumpMessage); + } + } + + final public void reset() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().reset(); + } + // nop + } + + final public void start() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().start(); + } + // nop + } + + final public boolean isCurrentThreadEDT() { + if(NativeWindowFactory.isAWTAvailable()) { + return AWTEDTUtil.getSingleton().isCurrentThreadEDT(); + } + return isRunning() && mainThread == Thread.currentThread() ; + } + + final public boolean isRunning() { + if( useMainThread ) { + synchronized(taskWorkerLock) { + return isRunning; + } + } + return true; // AWT is always running + } + + private void invokeLater(Runnable task) { + synchronized(taskWorkerLock) { + if(isRunning() && mainThread != Thread.currentThread()) { + tasks.add(task); + taskWorkerLock.notifyAll(); + } else { + // if !running or isEDTThread, do it right away + task.run(); + } + } + } + + final public void invokeStop(Runnable r) { + invokeImpl(true, r, true); + } + + final public void invoke(boolean wait, Runnable r) { + invokeImpl(wait, r, false); + } + + private void invokeImpl(boolean wait, Runnable r, boolean stop) { + if(r == null) { + return; + } + + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().invokeImpl(wait, r, stop); + return; + } + + // if this main thread is not being used or + // if this is already the main thread .. just execute. + // FIXME: start if not started .. sync logic with DefaultEDTUtil!!! + if( !isRunning() || mainThread == Thread.currentThread() ) { + r.run(); + return; + } + + boolean doWait = wait && isRunning() && mainThread != Thread.currentThread(); + Object lock = new Object(); + RunnableTask rTask = new RunnableTask(r, doWait?lock:null, true); + Throwable throwable = null; + synchronized(lock) { + invokeLater(rTask); + // FIXME .. + synchronized(taskWorkerLock) { + if(isRunning) { + shouldStop = true; + if(DEBUG) System.err.println("MainThread.stop(): "+Thread.currentThread().getName()+" start"); + } + taskWorkerLock.notifyAll(); + } + if( doWait ) { + try { + lock.wait(); + } catch (InterruptedException ie) { + throwable = ie; + } + } + } + if(null==throwable) { + throwable = rTask.getThrowable(); + } + if(null!=throwable) { + throw new RuntimeException(throwable); + } + } + + final public void waitUntilIdle() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().waitUntilIdle(); + } + } + + final public void waitUntilStopped() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().waitUntilStopped(); + } + } + + private void waitUntilRunning() { + synchronized(taskWorkerLock) { + if(isExit) return; + + while(!isRunning) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + public void run() { + if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()); + synchronized(taskWorkerLock) { + isRunning = true; + taskWorkerLock.notifyAll(); + } + while(!shouldStop) { + try { + // wait for something todo .. + synchronized(taskWorkerLock) { + while(!shouldStop && tasks.size()==0) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + // take over the tasks .. + if(!shouldStop && tasks.size()>0) { + Runnable task = (Runnable) tasks.remove(0); + task.run(); // FIXME: could be run outside of lock + } + taskWorkerLock.notifyAll(); + } + } catch (Throwable t) { + // handle errors .. + t.printStackTrace(); + } finally { + // epilog - unlock locked stuff + } + } + if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()+" fin"); + synchronized(taskWorkerLock) { + isRunning = false; + isExit = true; + taskWorkerLock.notifyAll(); + } + } +} + + diff --git a/src/newt/classes/com/jogamp/newt/util/MonitorMode.java b/src/newt/classes/com/jogamp/newt/util/MonitorMode.java new file mode 100644 index 000000000..fb2d0ceb5 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/util/MonitorMode.java @@ -0,0 +1,109 @@ +/** + * 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.newt.util; + +import javax.media.nativewindow.util.*; + +/** Immutable MonitorMode Class, consisting of it's read only components:<br> + * <ul> + * <li>{@link javax.media.nativewindow.util.SurfaceSize} surface memory size</li> + * <li>{@link javax.media.nativewindow.util.DimensionReadOnly} size in [mm]</li> + * <li><code>refresh rate</code></li> + * </ul> + */ +public class MonitorMode implements Cloneable { + SurfaceSize surfaceSize; + DimensionReadOnly screenSizeMM; // in [mm] + int refreshRate; + + public MonitorMode(SurfaceSize surfaceSize, DimensionReadOnly screenSizeMM, int refreshRate) { + if(null==surfaceSize || refreshRate<=0) { + throw new IllegalArgumentException("surfaceSize must be set and refreshRate greater 0"); + } + this.surfaceSize=surfaceSize; + this.screenSizeMM=screenSizeMM; + this.refreshRate=refreshRate; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public final SurfaceSize getSurfaceSize() { + return surfaceSize; + } + + public final DimensionReadOnly getScreenSizeMM() { + return screenSizeMM; + } + + public final int getRefreshRate() { + return refreshRate; + } + + public final String toString() { + return new String("[ "+surfaceSize+" x "+refreshRate+" Hz, "+screenSizeMM+" mm ]"); + } + + /** + * Checks whether two size objects are equal. Two instances + * of <code>MonitorMode</code> are equal if the three components + * <code>surfaceSize</code> and <code>refreshRate</code> + * are equal. <code>screenSizeMM</code> is kept out intentional to reduce the requirements for finding the current mode. + * @return <code>true</code> if the two dimensions are equal; + * otherwise <code>false</code>. + */ + public final boolean equals(Object obj) { + if (this == obj) { return true; } + if (obj instanceof MonitorMode) { + MonitorMode p = (MonitorMode)obj; + return getSurfaceSize().equals(p.getSurfaceSize()) && + /* getScreenSizeMM().equals(p.getScreenSizeMM()) && */ + getRefreshRate() == p.getRefreshRate() ; + } + return false; + } + + /** + * returns a hash code over <code>surfaceSize</code> and <code>refreshRate</code>. + * <code>screenSizeMM</code> is kept out intentional to reduce the requirements for finding the current mode. + */ + public final int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + getSurfaceSize().hashCode(); + /* hash = ((hash << 5) - hash) + getScreenSizeMM().hashCode(); */ + hash = ((hash << 5) - hash) + getRefreshRate(); + return hash; + } +} + diff --git a/src/newt/classes/com/jogamp/newt/util/ScreenModeUtil.java b/src/newt/classes/com/jogamp/newt/util/ScreenModeUtil.java new file mode 100644 index 000000000..3e0e3dac5 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/util/ScreenModeUtil.java @@ -0,0 +1,340 @@ +/** + * 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.newt.util; + +import com.jogamp.common.util.ArrayHashSet; +import com.jogamp.newt.ScreenMode; +import java.util.ArrayList; +import java.util.List; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionReadOnly; +import javax.media.nativewindow.util.SurfaceSize; + +/** + * Convenient {@link com.jogamp.newt.ScreenMode} utility methods, + * filters etc. + */ +public class ScreenModeUtil { + /** WARNING: must be synchronized with ScreenMode.h, native implementation + * 2: width and height + */ + public static final int NUM_RESOLUTION_PROPERTIES = 2; + + /** WARNING: must be synchronized with ScreenMode.h, native implementation + * 1: bpp + */ + public static final int NUM_SURFACE_SIZE_PROPERTIES = 1; + + /** WARNING: must be synchronized with ScreenMode.h, native implementation + * 3: ScreenSizeMM[width, height], refresh-rate + */ + public static final int NUM_MONITOR_MODE_PROPERTIES = 3; + + /** WARNING: must be synchronized with ScreenMode.h, native implementation + * 1: rotation, native_mode_id + */ + public static final int NUM_SCREEN_MODE_PROPERTIES = 1; + + /** WARNING: must be synchronized with ScreenMode.h, native implementation + * count + all the above + */ + public static final int NUM_SCREEN_MODE_PROPERTIES_ALL = 8; + + public static int getIndex(List/*<ScreenMode>*/ screenModes, ScreenMode search) { + return screenModes.indexOf(search); + } + + public static int getIndexByHashCode(List/*<ScreenMode>*/ screenModes, ScreenMode search) { + for (int i=0; null!=screenModes && i<screenModes.size(); i++) { + if ( search.hashCode() == ((ScreenMode)screenModes.get(i)).hashCode() ) { + return i; + } + } + return -1; + } + + /** + * @param screenModes + * @param resolution + * @return modes with nearest resolution, or matching ones + */ + public static List/*<ScreenMode>*/ filterByResolution(List/*<ScreenMode>*/ screenModes, DimensionReadOnly resolution) { + if(null==screenModes || screenModes.size()==0) { + return null; + } + List out = new ArrayList(); + int resolution_sq = resolution.getHeight()*resolution.getWidth(); + int sm_dsq=resolution_sq, sm_dsq_idx=0; + + for (int i=0; null!=screenModes && i<screenModes.size(); i++) { + ScreenMode sm = (ScreenMode)screenModes.get(i); + DimensionReadOnly res = sm.getMonitorMode().getSurfaceSize().getResolution(); + int dsq = Math.abs(resolution_sq - res.getHeight()*res.getWidth()); + if(dsq<sm_dsq) { + sm_dsq = dsq; + sm_dsq_idx = i; + } + if(res.equals(resolution)) { + out.add(sm); + } + } + if(out.size()>0) { + return out; + } + // nearest .. + resolution = ((ScreenMode)screenModes.get(sm_dsq_idx)).getMonitorMode().getSurfaceSize().getResolution(); + return filterByResolution(screenModes, resolution); + } + + public static List/*<ScreenMode>*/ filterBySurfaceSize(List/*<ScreenMode>*/ screenModes, SurfaceSize surfaceSize) { + if(null==screenModes || screenModes.size()==0) { + return null; + } + List out = new ArrayList(); + for (int i=0; null!=screenModes && i<screenModes.size(); i++) { + ScreenMode sm = (ScreenMode)screenModes.get(i); + if(sm.getMonitorMode().getSurfaceSize().equals(surfaceSize)) { + out.add(sm); + } + } + return out.size()>0 ? out : null; + } + + public static List/*<ScreenMode>*/ filterByRotation(List/*<ScreenMode>*/ screenModes, int rotation) { + if(null==screenModes || screenModes.size()==0) { + return null; + } + List out = new ArrayList(); + for (int i=0; null!=screenModes && i<screenModes.size(); i++) { + ScreenMode sm = (ScreenMode)screenModes.get(i); + if(sm.getRotation() == rotation) { + out.add(sm); + } + } + return out.size()>0 ? out : null; + } + + public static List/*<ScreenMode>*/ filterByBpp(List/*<ScreenMode>*/ screenModes, int bitsPerPixel) { + if(null==screenModes || screenModes.size()==0) { + return null; + } + List out = new ArrayList(); + for (int i=0; null!=screenModes && i<screenModes.size(); i++) { + ScreenMode sm = (ScreenMode)screenModes.get(i); + if(sm.getMonitorMode().getSurfaceSize().getBitsPerPixel() == bitsPerPixel) { + out.add(sm); + } + } + return out.size()>0 ? out : null; + } + + /** + * + * @param screenModes + * @param refreshRate + * @return modes with nearest refreshRate, or matching ones + */ + public static List/*<ScreenMode>*/ filterByRate(List/*<ScreenMode>*/ screenModes, int refreshRate) { + if(null==screenModes || screenModes.size()==0) { + return null; + } + int sm_dr = refreshRate; + int sm_dr_idx = -1; + List out = new ArrayList(); + for (int i=0; null!=screenModes && i<screenModes.size(); i++) { + ScreenMode sm = (ScreenMode)screenModes.get(i); + int dr = Math.abs(refreshRate - sm.getMonitorMode().getRefreshRate()); + if(dr<sm_dr) { + sm_dr = dr; + sm_dr_idx = i; + } + if(0 == dr) { + out.add(sm); + } + } + if(out.size()>0) { + return out; + } + refreshRate = ((ScreenMode)screenModes.get(sm_dr_idx)).getMonitorMode().getRefreshRate(); + return filterByRate(screenModes, refreshRate); + } + + public static List/*<ScreenMode>*/ getHighestAvailableBpp(List/*<ScreenMode>*/ screenModes) { + if(null==screenModes || screenModes.size()==0) { + return null; + } + int highest = -1; + for (int i=0; null!=screenModes && i < screenModes.size(); i++) { + ScreenMode sm = (ScreenMode)screenModes.get(i); + int bpp = sm.getMonitorMode().getSurfaceSize().getBitsPerPixel(); + if (bpp > highest) { + highest = bpp; + } + } + return filterByBpp(screenModes, highest); + } + + public static List/*<ScreenMode>*/ getHighestAvailableRate(List/*<ScreenMode>*/ screenModes) { + if(null==screenModes || screenModes.size()==0) { + return null; + } + int highest = -1; + for (int i=0; null!=screenModes && i < screenModes.size(); i++) { + ScreenMode sm = (ScreenMode)screenModes.get(i); + int rate = sm.getMonitorMode().getRefreshRate(); + if (rate > highest) { + highest = rate; + } + } + return filterByRate(screenModes, highest); + } + + /** WARNING: must be synchronized with ScreenMode.h, native implementation */ + public static DimensionReadOnly streamInResolution(int[] resolutionProperties, int offset) { + Dimension resolution = new Dimension(resolutionProperties[offset++], resolutionProperties[offset++]); + return resolution; + } + + /** WARNING: must be synchronized with ScreenMode.h, native implementation */ + public static SurfaceSize streamInSurfaceSize(DimensionReadOnly resolution, int[] sizeProperties, int offset) { + SurfaceSize surfaceSize = new SurfaceSize(resolution, sizeProperties[offset++]); + return surfaceSize; + } + + /** WARNING: must be synchronized with ScreenMode.h, native implementation */ + public static MonitorMode streamInMonitorMode(SurfaceSize surfaceSize, DimensionReadOnly screenSizeMM, int[] monitorProperties, int offset) { + int refreshRate = monitorProperties[offset++]; + return new MonitorMode(surfaceSize, screenSizeMM, refreshRate); + } + + /** WARNING: must be synchronized with ScreenMode.h, native implementation */ + public static ScreenMode streamInScreenMode(MonitorMode monitorMode, int[] modeProperties, int offset) { + int rotation = modeProperties[offset++]; + return new ScreenMode(monitorMode, rotation); + } + + /** + * WARNING: must be synchronized with ScreenMode.h, native implementation + * + * @param modeProperties the input data + * @param offset the offset to the input data + * @return index of the identical (old or new) ScreenMode element in <code>screenModePool</code>, + * matching the input <code>modeProperties</code>, or -1 if input could not be processed. + */ + public static ScreenMode streamIn(int[] modeProperties, int offset) { + return streamInImpl(null, null, null, null, null, modeProperties, offset); + } + + /** + * WARNING: must be synchronized with ScreenMode.h, native implementation + * + * @param resolutionPool hash array of unique DimensionReadOnly resolutions, no duplicates + * @param surfaceSizePool hash array of unique SurfaceSize, no duplicates + * @param monitorModePool hash array of unique MonitorMode, no duplicates + * @param screenModePool hash array of unique ScreenMode, no duplicates + * @param modeProperties the input data + * @param offset the offset to the input data + * @return index of the identical (old or new) ScreenMode element in <code>screenModePool</code>, + * matching the input <code>modeProperties</code>, or -1 if input could not be processed. + */ + public static int streamIn(ArrayHashSet resolutionPool, + ArrayHashSet surfaceSizePool, + ArrayHashSet screenSizeMMPool, + ArrayHashSet monitorModePool, + ArrayHashSet screenModePool, + int[] modeProperties, int offset) { + ScreenMode screenMode = streamInImpl(resolutionPool, surfaceSizePool, screenSizeMMPool, monitorModePool, screenModePool, + modeProperties, offset); + return screenModePool.indexOf(screenMode); + } + + private static ScreenMode streamInImpl(ArrayHashSet resolutionPool, + ArrayHashSet surfaceSizePool, + ArrayHashSet screenSizeMMPool, + ArrayHashSet monitorModePool, + ArrayHashSet screenModePool, + int[] modeProperties, int offset) { + int count = modeProperties[offset]; + if(NUM_SCREEN_MODE_PROPERTIES_ALL != count) { + throw new RuntimeException("NUM_SCREEN_MODE_PROPERTIES should be "+NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+count+", len "+(modeProperties.length-offset)); + } + if(NUM_SCREEN_MODE_PROPERTIES_ALL > modeProperties.length-offset) { + throw new RuntimeException("properties array too short, should be >= "+NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+(modeProperties.length-offset)); + } + offset++; + DimensionReadOnly resolution = ScreenModeUtil.streamInResolution(modeProperties, offset); + offset += ScreenModeUtil.NUM_RESOLUTION_PROPERTIES; + if(null!=resolutionPool) { + resolution = (DimensionReadOnly) resolutionPool.getOrAdd(resolution); + } + + SurfaceSize surfaceSize = ScreenModeUtil.streamInSurfaceSize(resolution, modeProperties, offset); + offset += ScreenModeUtil.NUM_SURFACE_SIZE_PROPERTIES; + if(null!=surfaceSizePool) { + surfaceSize = (SurfaceSize) surfaceSizePool.getOrAdd(surfaceSize); + } + + DimensionReadOnly screenSizeMM = ScreenModeUtil.streamInResolution(modeProperties, offset); + offset += ScreenModeUtil.NUM_RESOLUTION_PROPERTIES; + if(null!=screenSizeMMPool) { + screenSizeMM = (DimensionReadOnly) screenSizeMMPool.getOrAdd(screenSizeMM); + } + + MonitorMode monitorMode = ScreenModeUtil.streamInMonitorMode(surfaceSize, screenSizeMM, modeProperties, offset); + offset += ScreenModeUtil.NUM_MONITOR_MODE_PROPERTIES - ScreenModeUtil.NUM_RESOLUTION_PROPERTIES; + if(null!=monitorModePool) { + monitorMode = (MonitorMode) monitorModePool.getOrAdd(monitorMode); + } + + ScreenMode screenMode = ScreenModeUtil.streamInScreenMode(monitorMode, modeProperties, offset); + if(null!=screenModePool) { + screenMode = (ScreenMode) screenModePool.getOrAdd(screenMode); + } + return screenMode; + } + + /** WARNING: must be synchronized with ScreenMode.h, native implementation */ + public static int[] streamOut (ScreenMode screenMode) { + int[] data = new int[NUM_SCREEN_MODE_PROPERTIES_ALL]; + int idx=0; + data[idx++] = NUM_SCREEN_MODE_PROPERTIES_ALL; + data[idx++] = screenMode.getMonitorMode().getSurfaceSize().getResolution().getWidth(); + data[idx++] = screenMode.getMonitorMode().getSurfaceSize().getResolution().getHeight(); + data[idx++] = screenMode.getMonitorMode().getSurfaceSize().getBitsPerPixel(); + data[idx++] = screenMode.getMonitorMode().getScreenSizeMM().getWidth(); + data[idx++] = screenMode.getMonitorMode().getScreenSizeMM().getHeight(); + data[idx++] = screenMode.getMonitorMode().getRefreshRate(); + data[idx++] = screenMode.getRotation(); + if(NUM_SCREEN_MODE_PROPERTIES_ALL != idx) { + throw new InternalError("wrong number of attributes: got "+idx+" != should "+NUM_SCREEN_MODE_PROPERTIES_ALL); + } + return data; + } + +} diff --git a/src/newt/classes/jogamp/newt/Debug.java b/src/newt/classes/jogamp/newt/Debug.java new file mode 100644 index 000000000..85fbbe764 --- /dev/null +++ b/src/newt/classes/jogamp/newt/Debug.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.newt; + +import java.security.*; + +/** Helper routines for logging and debugging. */ + +public class Debug { + // Some common properties + private static boolean verbose; + private static boolean debugAll; + private static AccessControlContext localACC; + + static { + localACC=AccessController.getContext(); + verbose = isPropertyDefined("newt.verbose", true); + debugAll = isPropertyDefined("newt.debug", true); + if (verbose) { + Package p = Package.getPackage("com.jogamp.newt"); + System.err.println("NEWT specification version " + p.getSpecificationVersion()); + System.err.println("NEWT implementation version " + p.getImplementationVersion()); + System.err.println("NEWT implementation vendor " + p.getImplementationVendor()); + } + } + + static int getIntProperty(final String property, final boolean jnlpAlias) { + return getIntProperty(property, jnlpAlias, localACC); + } + + public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + int i=0; + try { + Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + i = iv.intValue(); + } catch (NumberFormatException nfe) {} + return i; + } + + static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { + return getBooleanProperty(property, jnlpAlias, localACC); + } + + public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + return b.booleanValue(); + } + + static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { + return isPropertyDefined(property, jnlpAlias, localACC); + } + + public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; + } + + static String getProperty(final String property, final boolean jnlpAlias) { + return getProperty(property, jnlpAlias, localACC); + } + + public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + String s=null; + if(null!=acc && acc.equals(localACC)) { + s = (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val=null; + try { + val = System.getProperty(property); + } catch (Exception e) {} + if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + val = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + return val; + } + }); + } else { + try { + s = System.getProperty(property); + } catch (Exception e) {} + if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + s = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + } + return s; + } + public static final String jnlp_prefix = "jnlp." ; + + public static boolean verbose() { + return verbose; + } + + public static boolean debugAll() { + return debugAll; + } + + public static boolean debug(String subcomponent) { + return debugAll() || isPropertyDefined("newt.debug." + subcomponent, true); + } +} diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java new file mode 100644 index 000000000..3b14f30fc --- /dev/null +++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java @@ -0,0 +1,335 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package jogamp.newt; + +import java.util.ArrayList; +import javax.media.nativewindow.NativeWindowException; +import com.jogamp.common.util.RunnableTask; +import com.jogamp.newt.util.EDTUtil; + +public class DefaultEDTUtil implements EDTUtil { + public static final boolean DEBUG = Debug.debug("EDT"); + + private ThreadGroup threadGroup; + private EventDispatchThread edt = null; + private Object edtLock = new Object(); // locking the EDT start/stop state + private String name; + int start_iter=0; + private Runnable dispatchMessages; + + public DefaultEDTUtil(ThreadGroup tg, String name, Runnable dispatchMessages) { + this.threadGroup = tg; + this.name=Thread.currentThread().getName()+"-"+name+"-EDT-"; + this.dispatchMessages=dispatchMessages; + this.edt = new EventDispatchThread(threadGroup, name); + this.edt.setDaemon(true); // don't stop JVM from shutdown .. + } + + public final void reset() { + synchronized(edtLock) { + waitUntilStopped(); + if(DEBUG) { + if(edt.tasks.size()>0) { + String msg = Thread.currentThread()+": EDT reset, remaining tasks: "+edt.tasks.size()+" - "+edt; + System.err.println(msg); + // Throwable t = new Throwable(msg); + // t.printStackTrace(); + } + System.err.println(Thread.currentThread()+": EDT reset - edt: "+edt); + } + this.edt = new EventDispatchThread(threadGroup, name); + this.edt.setDaemon(true); // don't stop JVM from shutdown .. + } + } + + public final void start() { + synchronized(edtLock) { + if(!edt.isRunning() && !edt.shouldStop) { + if(edt.isAlive()) { + throw new RuntimeException("EDT Thread.isAlive(): true, isRunning: "+edt.isRunning()+", edt: "+edt+", tasks: "+edt.tasks.size()); + } + start_iter++; + edt.setName(name+start_iter); + edt.shouldStop = false; + if(DEBUG) { + String msg = Thread.currentThread()+": EDT START - edt: "+edt; + System.err.println(msg); + // Throwable t = new Throwable(msg); + // t.printStackTrace(); + } + edt.start(); + } + } + } + + public final boolean isCurrentThreadEDT() { + return edt == Thread.currentThread(); + } + + public final boolean isRunning() { + return edt.isRunning() ; + } + + public final void invokeStop(Runnable task) { + invokeImpl(true, task, true); + } + + public final void invoke(boolean wait, Runnable task) { + invokeImpl(wait, task, false); + } + + private void invokeImpl(boolean wait, Runnable task, boolean stop) { + if(task == null) { + throw new RuntimeException("Null Runnable"); + } + Throwable throwable = null; + RunnableTask rTask = null; + Object rTaskLock = new Object(); + synchronized(rTaskLock) { // lock the optional task execution + synchronized(edtLock) { // lock the EDT status + if( edt.shouldStop ) { + // drop task .. + if(DEBUG) { + Throwable t = new Throwable("Warning: EDT about (1) to stop, won't enqueue new task: "+edt); + t.printStackTrace(); + } + return; + } + // Exception ee = new Exception("XXX stop: "+stop+", tasks: "+edt.tasks.size()+", task: "+task); + // ee.printStackTrace(); + if(stop) { + edt.shouldStop = true; + if(DEBUG) { + String msg = Thread.currentThread()+": EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - edt: "+edt; + System.err.println(msg); + // Throwable t = new Throwable(msg); + // t.printStackTrace(); + } + } + if( isCurrentThreadEDT() ) { + task.run(); + wait = false; // running in same thread (EDT) -> no wait + if(stop && edt.tasks.size()>0) { + String msg = "Warning: EDT about (2) to stop, having remaining tasks: "+edt.tasks.size()+" - "+edt; + if(DEBUG) { + Throwable t = new Throwable(msg); + t.printStackTrace(); + } else { + System.err.println(msg); + } + } + } else { + synchronized(edt.tasks) { + start(); // start if not started yet and !shouldStop + wait = wait && edt.isRunning(); + rTask = new RunnableTask(task, + wait ? rTaskLock : null, + true /* always catch and report Exceptions, don't disturb EDT */); + if(stop) { + rTask.setAttachment(new Boolean(true)); // mark final task + } + // append task .. + edt.tasks.add(rTask); + edt.tasks.notifyAll(); + } + } + } + if( wait ) { + try { + rTaskLock.wait(); // free lock, allow execution of rTask + } catch (InterruptedException ie) { + throwable = ie; + } + if(null==throwable) { + throwable = rTask.getThrowable(); + } + if(null!=throwable) { + if(throwable instanceof NativeWindowException) { + throw (NativeWindowException)throwable; + } + throw new RuntimeException(throwable); + } + } + } + if(DEBUG && stop) { + System.err.println(Thread.currentThread()+": EDT signal STOP X edt: "+edt); + } + } + + final public void waitUntilIdle() { + final EventDispatchThread _edt; + synchronized(edtLock) { + _edt = edt; + } + if(!_edt.isRunning() || _edt == Thread.currentThread()) { + return; + } + synchronized(_edt.tasks) { + while(_edt.isRunning() && _edt.tasks.size()>0) { + try { + _edt.tasks.notifyAll(); + _edt.tasks.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + final public void waitUntilStopped() { + synchronized(edtLock) { + if(edt.isRunning() && edt != Thread.currentThread() ) { + while(edt.isRunning()) { + try { + edtLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + } + + class EventDispatchThread extends Thread { + volatile boolean shouldStop = false; + volatile boolean isRunning = false; + ArrayList tasks = new ArrayList(); // one shot tasks + + public EventDispatchThread(ThreadGroup tg, String name) { + super(tg, name); + } + + final public boolean isRunning() { + return isRunning; + } + + @Override + final public void start() throws IllegalThreadStateException { + isRunning = true; + super.start(); + } + + /** + * Utilizing locking only on tasks and its execution, + * not for event dispatching. + */ + @Override + final public void run() { + if(DEBUG) { + System.err.println(getName()+": EDT run() START "+ getName()); + } + RuntimeException error = null; + try { + do { + // event dispatch + if(!shouldStop) { + dispatchMessages.run(); + } + // wait and work on tasks + RunnableTask task = null; + synchronized(tasks) { + // wait for tasks + if(!shouldStop && tasks.size()==0) { + try { + tasks.wait(defaultEDTPollGranularity); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + // execute one task, if available + if(tasks.size()>0) { + task = (RunnableTask) tasks.remove(0); + tasks.notifyAll(); + } + } + if(null!=task) { + // Exceptions are always catched, see RunnableTask creation above + task.run(); + } + } while(!shouldStop) ; + } catch (Throwable t) { + // handle errors .. + shouldStop = true; + if(t instanceof RuntimeException) { + error = (RuntimeException) t; + } else { + error = new RuntimeException("Within EDT", t); + } + } finally { + if(DEBUG) { + RunnableTask rt = ( tasks.size() > 0 ) ? (RunnableTask) tasks.get(0) : null ; + System.err.println(getName()+": EDT run() END "+ getName()+", tasks: "+tasks.size()+", "+rt+", "+error); + } + synchronized(edtLock) { + if(null==error) { + synchronized(tasks) { + // drain remaining tasks (stop not on EDT), + // while having tasks and no previous-task, or previous-task is non final + RunnableTask task = null; + while ( ( null == task || task.getAttachment() == null ) && tasks.size() > 0 ) { + task = ( RunnableTask ) tasks.remove(0); + task.run(); + tasks.notifyAll(); + } + if(DEBUG) { + if(null!=task && task.getAttachment()==null) { + Throwable t = new Throwable("Warning: EDT exit: Last task Not Final: "+tasks.size()+", "+task+" - "+edt); + t.printStackTrace(); + } else if(tasks.size()>0) { + Throwable t = new Throwable("Warning: EDT exit: Remaining tasks Post Final: "+tasks.size()); + t.printStackTrace(); + } + } + } + } + isRunning = !shouldStop; + if(!isRunning) { + edtLock.notifyAll(); + } + } + if(DEBUG) { + System.err.println(getName()+": EDT run() EXIT "+ getName()+", "+error); + } + if(null!=error) { + throw error; + } + } + } + } +} + diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java new file mode 100644 index 000000000..299f4fb54 --- /dev/null +++ b/src/newt/classes/jogamp/newt/DisplayImpl.java @@ -0,0 +1,452 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt; + +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.event.NEWTEvent; +import com.jogamp.newt.event.NEWTEventConsumer; +import jogamp.newt.event.NEWTEventTask; +import com.jogamp.newt.util.EDTUtil; +import com.jogamp.newt.util.MainThread; +import java.util.ArrayList; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.NativeWindowFactory; + +public abstract class DisplayImpl extends Display { + public static final boolean DEBUG_TEST_EDT_MAINTHREAD = Debug.isPropertyDefined("newt.test.EDTMainThread", true); // JAU EDT Test .. + + private static int serialno = 1; + + private static Class getDisplayClass(String type) + throws ClassNotFoundException + { + Class displayClass = NewtFactory.getCustomClass(type, "Display"); + if(null==displayClass) { + if (NativeWindowFactory.TYPE_EGL.equals(type)) { + displayClass = Class.forName("jogamp.newt.opengl.kd.KDDisplay"); + } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { + displayClass = Class.forName("jogamp.newt.windows.WindowsDisplay"); + } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + displayClass = Class.forName("jogamp.newt.macosx.MacDisplay"); + } else if (NativeWindowFactory.TYPE_X11.equals(type)) { + displayClass = Class.forName("jogamp.newt.x11.X11Display"); + } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { + displayClass = Class.forName("jogamp.newt.awt.AWTDisplay"); + } else { + throw new RuntimeException("Unknown display type \"" + type + "\""); + } + } + return displayClass; + } + + /** Make sure to reuse a Display with the same name */ + public static Display create(String type, String name, final long handle, boolean reuse) { + try { + Class displayClass = getDisplayClass(type); + DisplayImpl display = (DisplayImpl) displayClass.newInstance(); + name = display.validateDisplayName(name, handle); + synchronized(displayList) { + if(reuse) { + Display display0 = Display.getLastDisplayOf(type, name, -1); + if(null != display0) { + if(DEBUG) { + System.err.println("Display.create() REUSE: "+display0+" "+getThreadName()); + } + return display0; + } + } + display.name = name; + display.type=type; + display.destroyWhenUnused=false; + display.refCount=0; + display.id = serialno++; + display.fqname = getFQName(display.type, display.name, display.id); + display.hashCode = display.fqname.hashCode(); + displayList.add(display); + } + display.createEDTUtil(); + if(DEBUG) { + System.err.println("Display.create() NEW: "+display+" "+getThreadName()); + } + return display; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final DisplayImpl other = (DisplayImpl) obj; + if (this.id != other.id) { + return false; + } + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) { + return false; + } + return true; + } + + public int hashCode() { + return hashCode; + } + + public synchronized final void createNative() + throws NativeWindowException + { + if(null==aDevice) { + if(DEBUG) { + System.err.println("Display.createNative() START ("+getThreadName()+", "+this+")"); + } + final DisplayImpl f_dpy = this; + try { + runOnEDTIfAvail(true, new Runnable() { + public void run() { + f_dpy.createNativeImpl(); + }}); + } catch (Throwable t) { + throw new NativeWindowException(t); + } + if(null==aDevice) { + throw new NativeWindowException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); + } + if(DEBUG) { + System.err.println("Display.createNative() END ("+getThreadName()+", "+this+")"); + } + synchronized(displayList) { + displaysActive++; + } + } + } + + protected boolean shallRunOnEDT() { + return true; + } + + protected void createEDTUtil() { + if(NewtFactory.useEDT()) { + if ( ! DEBUG_TEST_EDT_MAINTHREAD ) { + Thread current = Thread.currentThread(); + edtUtil = new DefaultEDTUtil(current.getThreadGroup(), "Display-"+getFQName(), dispatchMessagesRunnable); + } else { + // Begin JAU EDT Test .. + MainThread.addPumpMessage(this, dispatchMessagesRunnable); + edtUtil = MainThread.getSingleton(); + // End JAU EDT Test .. + } + if(DEBUG) { + System.err.println("Display.createNative("+getFQName()+") Create EDTUtil: "+edtUtil.getClass().getName()); + } + } + } + + public final EDTUtil getEDTUtil() { + return edtUtil; + } + + private void stopEDT(final Runnable task) { + if( shallRunOnEDT() && null!=edtUtil ) { + edtUtil.invokeStop(task); + } else { + task.run(); + } + } + + public void runOnEDTIfAvail(boolean wait, final Runnable task) { + if( shallRunOnEDT() && null!=edtUtil && !edtUtil.isCurrentThreadEDT()) { + edtUtil.invoke(wait, task); + } else { + task.run(); + } + } + + public boolean validateEDT() { + if(0==refCount && null==aDevice && null != edtUtil && edtUtil.isRunning()) { + stopEDT( new Runnable() { + public void run() { + // nop + } + } ); + edtUtil.waitUntilStopped(); + edtUtil.reset(); + return true; + } + return false; + } + + public synchronized final void destroy() { + if(DEBUG) { + dumpDisplayList("Display.destroy("+getFQName()+") BEGIN"); + } + synchronized(displayList) { + displayList.remove(this); + if(0 < displaysActive) { + displaysActive--; + } + } + if(DEBUG) { + System.err.println("Display.destroy(): "+this+" "+getThreadName()); + } + final AbstractGraphicsDevice f_aDevice = aDevice; + final DisplayImpl f_dpy = this; + stopEDT( new Runnable() { + public void run() { + if ( null != f_aDevice ) { + f_dpy.closeNativeImpl(); + } + } + } ); + if(null!=edtUtil) { + if ( DEBUG_TEST_EDT_MAINTHREAD ) { + MainThread.removePumpMessage(this); // JAU EDT Test .. + } + edtUtil.waitUntilStopped(); + edtUtil.reset(); + } + aDevice = null; + refCount=0; + if(DEBUG) { + dumpDisplayList("Display.destroy("+getFQName()+") END"); + } + } + + public synchronized final int addReference() { + if(DEBUG) { + System.err.println("Display.addReference() ("+DisplayImpl.getThreadName()+"): "+refCount+" -> "+(refCount+1)); + } + if ( 0 == refCount ) { + createNative(); + } + if(null == aDevice) { + throw new NativeWindowException ("Display.addReference() (refCount "+refCount+") null AbstractGraphicsDevice"); + } + return refCount++; + } + + + public synchronized final int removeReference() { + if(DEBUG) { + System.err.println("Display.removeReference() ("+DisplayImpl.getThreadName()+"): "+refCount+" -> "+(refCount-1)); + } + refCount--; // could become < 0, in case of manual destruction without actual creation/addReference + if(0>=refCount) { + destroy(); + refCount=0; // fix < 0 + } + return refCount; + } + + public synchronized final int getReferenceCount() { + return refCount; + } + + protected abstract void createNativeImpl(); + protected abstract void closeNativeImpl(); + + public final int getId() { + return id; + } + + public final String getType() { + return type; + } + + public final String getName() { + return name; + } + + public final String getFQName() { + return fqname; + } + + public static final String nilString = "nil" ; + + public String validateDisplayName(String name, long handle) { + if(null==name && 0!=handle) { + name="wrapping-"+toHexString(handle); + } + return ( null == name ) ? nilString : name ; + } + + private static String getFQName(String type, String name, int id) { + if(null==type) type=nilString; + if(null==name) name=nilString; + StringBuilder sb = new StringBuilder(); + sb.append(type); + sb.append("_"); + sb.append(name); + sb.append("-"); + sb.append(id); + return sb.toString().intern(); + } + + public final long getHandle() { + if(null!=aDevice) { + return aDevice.getHandle(); + } + return 0; + } + + public final AbstractGraphicsDevice getGraphicsDevice() { + return aDevice; + } + + public final boolean isNativeValid() { + return null != aDevice; + } + + public boolean isEDTRunning() { + if(null!=edtUtil) { + return edtUtil.isRunning(); + } + return false; + } + + @Override + public String toString() { + return "NEWT-Display["+getFQName()+", refCount "+refCount+", hasEDT "+(null!=edtUtil)+", edtRunning "+isEDTRunning()+", "+aDevice+"]"; + } + + protected abstract void dispatchMessagesNative(); + + private Object eventsLock = new Object(); + private ArrayList/*<NEWTEvent>*/ events = new ArrayList(); + private volatile boolean haveEvents = false; + + class DispatchMessagesRunnable implements Runnable { + public void run() { + DisplayImpl.this.dispatchMessages(); + } + } + DispatchMessagesRunnable dispatchMessagesRunnable = new DispatchMessagesRunnable(); + + final void dispatchMessage(final NEWTEventTask eventTask) { + NEWTEvent event = eventTask.get(); + Object source = event.getSource(); + if(source instanceof NEWTEventConsumer) { + NEWTEventConsumer consumer = (NEWTEventConsumer) source ; + if(!consumer.consumeEvent(event)) { + // enqueue for later execution + enqueueEvent(false, event); + } + } else { + throw new RuntimeException("Event source not NEWT: "+source.getClass().getName()+", "+source); + } + eventTask.notifyIssuer(); + } + + public void dispatchMessages() { + // System.err.println("Display.dispatchMessages() 0 "+this+" "+getThreadName()); + if(0==refCount) return; // no screens + if(null==getGraphicsDevice()) return; // no native device + + ArrayList/*<NEWTEvent>*/ _events = null; + + if(haveEvents) { // volatile: ok + synchronized(eventsLock) { + if(haveEvents) { + // swap events list to free ASAP + _events = events; + events = new ArrayList(); + haveEvents = false; + } + eventsLock.notifyAll(); + } + if( null != _events ) { + for (int i=0; i < _events.size(); i++) { + dispatchMessage((NEWTEventTask) _events.get(i)); + } + } + } + + // System.err.println("Display.dispatchMessages() NATIVE "+this+" "+getThreadName()); + dispatchMessagesNative(); + } + + public void enqueueEvent(boolean wait, NEWTEvent e) { + if(!isEDTRunning()) { + // oops .. we are already dead + if(DEBUG) { + Throwable t = new Throwable("Warning: EDT already stopped: wait:="+wait+", "+e); + t.printStackTrace(); + } + return; + } + + // can't wait if we are on EDT -> consume right away + if(wait && edtUtil.isCurrentThreadEDT()) { + dispatchMessage(new NEWTEventTask(e, null)); + return; + } + + Object lock = new Object(); + NEWTEventTask eTask = new NEWTEventTask(e, wait?lock:null); + synchronized(lock) { + synchronized(eventsLock) { + events.add(eTask); + haveEvents = true; + eventsLock.notifyAll(); + } + if( wait ) { + try { + lock.wait(); + } catch (InterruptedException ie) { + throw new RuntimeException(ie); + } + } + } + } + + protected EDTUtil edtUtil = null; + protected int id; + protected String name; + protected String type; + protected String fqname; + protected int hashCode; + protected int refCount; // number of Display references by Screen + protected boolean destroyWhenUnused; + protected AbstractGraphicsDevice aDevice; +} + diff --git a/src/newt/classes/jogamp/newt/NEWTJNILibLoader.java b/src/newt/classes/jogamp/newt/NEWTJNILibLoader.java new file mode 100644 index 000000000..7b89398db --- /dev/null +++ b/src/newt/classes/jogamp/newt/NEWTJNILibLoader.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package jogamp.newt; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.jogamp.common.jvm.JNILibLoaderBase; + +public class NEWTJNILibLoader extends JNILibLoaderBase { + + public static void loadNEWT() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("newt", null, true); + return null; + } + }); + } + +} diff --git a/src/newt/classes/jogamp/newt/OffscreenWindow.java b/src/newt/classes/jogamp/newt/OffscreenWindow.java new file mode 100644 index 000000000..a79b1a5a1 --- /dev/null +++ b/src/newt/classes/jogamp/newt/OffscreenWindow.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Point; + +public class OffscreenWindow extends WindowImpl implements SurfaceChangeable { + + long surfaceHandle = 0; + + public OffscreenWindow() { + } + + static long nextWindowHandle = 0x100; // start here - a marker + + protected void createNativeImpl() { + if(0!=getParentWindowHandle()) { + throw new NativeWindowException("OffscreenWindow does not support window parenting"); + } + if(capsRequested.isOnscreen()) { + throw new NativeWindowException("Capabilities is onscreen"); + } + AbstractGraphicsScreen aScreen = getScreen().getGraphicsScreen(); + config = GraphicsConfigurationFactory.getFactory(aScreen.getDevice()).chooseGraphicsConfiguration( + capsRequested, capsRequested, capabilitiesChooser, aScreen); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + synchronized(OffscreenWindow.class) { + setWindowHandle(nextWindowHandle++); + } + } + + protected void closeNativeImpl() { + // nop + } + + @Override + protected void invalidate(boolean unrecoverable) { + super.invalidate(unrecoverable); + surfaceHandle = 0; + } + + @Override + public synchronized void destroy() { + super.destroy(); + surfaceHandle = 0; + } + + public void setSurfaceHandle(long handle) { + surfaceHandle = handle ; + } + + @Override + public long getSurfaceHandle() { + return surfaceHandle; + } + + protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) { + sizeChanged(width, height, false); + visibleChanged(visible); + } + + protected void requestFocusImpl(boolean reparented) { + } + + @Override + public void setSize(int width, int height) { + if(!visible) { + sizeChanged(width, height, false); + } + } + @Override + public void setPosition(int x, int y) { + // nop + } + @Override + public boolean setFullscreen(boolean fullscreen) { + // nop + return false; + } + protected boolean reconfigureWindowImpl(int x, int y, int width, int height, boolean parentChange, int fullScreenChange, int decorationChange) { + shouldNotCallThis(); + return false; + } + + @Override + public Point getLocationOnScreen(Point storage) { + if(null!=storage) { + storage.setX(0); + storage.setY(0); + return storage; + } + return new Point(0,0); + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return new Point(x,y); + } +} + diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java new file mode 100644 index 000000000..065cd88eb --- /dev/null +++ b/src/newt/classes/jogamp/newt/ScreenImpl.java @@ -0,0 +1,524 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt; + +import com.jogamp.common.util.ArrayHashSet; +import com.jogamp.common.util.IntIntHashMap; +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.event.ScreenModeListener; +import com.jogamp.newt.util.ScreenModeUtil; + +import javax.media.nativewindow.*; + +import java.security.*; +import java.util.ArrayList; +import java.util.List; + +public abstract class ScreenImpl extends Screen implements ScreenModeListener { + protected static final boolean DEBUG_TEST_SCREENMODE_DISABLED = Debug.isPropertyDefined("newt.test.Screen.disableScreenMode", true); + + protected DisplayImpl display; + protected int screen_idx; + protected String fqname; + protected int hashCode; + protected AbstractGraphicsScreen aScreen; + protected int refCount; // number of Screen references by Window + protected int width=-1, height=-1; // detected values: set using setScreenSize + protected static int usrWidth=-1, usrHeight=-1; // property values: newt.ws.swidth and newt.ws.sheight + private static AccessControlContext localACC = AccessController.getContext(); + private List/*<ScreenModeListener>*/ referencedScreenModeListener = new ArrayList(); + long t0; // creationTime + + private static Class getScreenClass(String type) + throws ClassNotFoundException + { + Class screenClass = NewtFactory.getCustomClass(type, "Screen"); + if(null==screenClass) { + if (NativeWindowFactory.TYPE_EGL.equals(type)) { + screenClass = Class.forName("jogamp.newt.opengl.kd.KDScreen"); + } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { + screenClass = Class.forName("jogamp.newt.windows.WindowsScreen"); + } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + screenClass = Class.forName("jogamp.newt.macosx.MacScreen"); + } else if (NativeWindowFactory.TYPE_X11.equals(type)) { + screenClass = Class.forName("jogamp.newt.x11.X11Screen"); + } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { + screenClass = Class.forName("jogamp.newt.awt.AWTScreen"); + } else { + throw new RuntimeException("Unknown window type \"" + type + "\""); + } + } + return screenClass; + } + + public static Screen create(Display display, final int idx) { + try { + if(usrWidth<0 || usrHeight<0) { + synchronized (Screen.class) { + if(usrWidth<0 || usrHeight<0) { + usrWidth = Debug.getIntProperty("newt.ws.swidth", true, localACC); + usrHeight = Debug.getIntProperty("newt.ws.sheight", true, localACC); + if(usrWidth>0 || usrHeight>0) { + System.err.println("User screen size "+usrWidth+"x"+usrHeight); + } + } + } + } + synchronized(screenList) { + { + Screen screen0 = ScreenImpl.getLastScreenOf(display, idx, -1); + if(null != screen0) { + if(DEBUG) { + System.err.println("Screen.create() REUSE: "+screen0+" "+Display.getThreadName()); + } + return screen0; + } + } + Class screenClass = getScreenClass(display.getType()); + ScreenImpl screen = (ScreenImpl) screenClass.newInstance(); + screen.display = (DisplayImpl) display; + screen.screen_idx = idx; + screen.fqname = (display.getFQName()+idx).intern(); + screen.hashCode = screen.fqname.hashCode(); + screenList.add(screen); + if(DEBUG) { + System.err.println("Screen.create() NEW: "+screen+" "+Display.getThreadName()); + } + return screen; + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ScreenImpl other = (ScreenImpl) obj; + if (this.display != other.display && (this.display == null || !this.display.equals(other.display))) { + return false; + } + if (this.screen_idx != other.screen_idx) { + return false; + } + return true; + } + + public int hashCode() { + return hashCode; + } + + public synchronized final void createNative() + throws NativeWindowException + { + if(null == aScreen) { + if(DEBUG) { + System.err.println("Screen.createNative() START ("+DisplayImpl.getThreadName()+", "+this+")"); + } + t0 = System.currentTimeMillis(); + display.addReference(); + createNativeImpl(); + if(null == aScreen) { + throw new NativeWindowException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); + } + if(DEBUG) { + System.err.println("Screen.createNative() END ("+DisplayImpl.getThreadName()+", "+this+")"); + } + synchronized(screenList) { + screensActive++; + } + } + initScreenModeStatus(); + } + + public synchronized final void destroy() { + releaseScreenModeStatus(); + + synchronized(screenList) { + screenList.remove(this); + if(0 < screensActive) { + screensActive--; + } + } + + if ( null != aScreen ) { + closeNativeImpl(); + aScreen = null; + } + refCount = 0; + display.removeReference(); + } + + public synchronized final int addReference() throws NativeWindowException { + if(DEBUG) { + System.err.println("Screen.addReference() ("+DisplayImpl.getThreadName()+"): "+refCount+" -> "+(refCount+1)); + } + if ( 0 == refCount ) { + createNative(); + } + if(null == aScreen) { + throw new NativeWindowException("Screen.addReference() (refCount "+refCount+") null AbstractGraphicsScreen"); + } + return ++refCount; + } + + public synchronized final int removeReference() { + if(DEBUG) { + String msg = "Screen.removeReference() ("+DisplayImpl.getThreadName()+"): "+refCount+" -> "+(refCount-1); + // Throwable t = new Throwable(msg); + // t.printStackTrace(); + System.err.println(msg); + } + refCount--; // could become < 0, in case of manual destruction without actual creation/addReference + if(0>=refCount) { + destroy(); + refCount=0; // fix < 0 + } + return refCount; + } + + public synchronized final int getReferenceCount() { + return refCount; + } + + protected abstract void createNativeImpl(); + protected abstract void closeNativeImpl(); + + public final String getFQName() { + return fqname; + } + + protected void setScreenSize(int w, int h) { + System.err.println("Detected screen size "+w+"x"+h); + width=w; height=h; + } + + public final Display getDisplay() { + return display; + } + + public final int getIndex() { + return screen_idx; + } + + public final AbstractGraphicsScreen getGraphicsScreen() { + return aScreen; + } + + public final boolean isNativeValid() { + return null != aScreen; + } + + public final int getWidth() { + return (usrWidth>0) ? usrWidth : (width>0) ? width : 480; + } + + public final int getHeight() { + return (usrHeight>0) ? usrHeight : (height>0) ? height : 480; + } + + @Override + public String toString() { + return "NEWT-Screen["+getFQName()+", idx "+screen_idx+", refCount "+refCount+", "+getWidth()+"x"+getHeight()+", "+aScreen+", "+display+"]"; + } + + public final List/*<ScreenMode>*/ getScreenModes() { + ArrayHashSet screenModes = getScreenModesOrig(); + if(null != screenModes && 0 < screenModes.size()) { + return screenModes.toArrayList(); + } + return null; + } + + public ScreenMode getOriginalScreenMode() { + ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); + return ( null != sms ) ? sms.getOriginalScreenMode() : null ; + } + + public ScreenMode getCurrentScreenMode() { + ScreenMode smU = null; + ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); + if(null != sms) { + ScreenMode sm0 = ( DEBUG_TEST_SCREENMODE_DISABLED ) ? null : getCurrentScreenModeImpl(); + if(null == sm0) { + return null; + } + sms.lock(); + try { + smU = (ScreenMode) sms.getScreenModes().get(sm0); // unify via value hash + if(null == smU) { + throw new RuntimeException(sm0+" could not be hashed from ScreenMode list"); + } + + // if mode has changed somehow, update it .. + if( sms.getCurrentScreenMode().hashCode() != smU.hashCode() ) { + sms.fireScreenModeChanged(smU, true); + } + } finally { + sms.unlock(); + } + } + return smU; + } + + public boolean setCurrentScreenMode(ScreenMode screenMode) { + ScreenMode smU = (ScreenMode) getScreenModesOrig().get(screenMode); // unify via value hash + ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); + if(null!=sms) { + sms.lock(); + try { + if(DEBUG) { + System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): 0.0 "+screenMode); + } + + sms.fireScreenModeChangeNotify(smU); + + if(DEBUG) { + System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): 0.1 "+screenMode); + } + + boolean success = setCurrentScreenModeImpl(smU); + if(success) { + setScreenSize(screenMode.getMonitorMode().getSurfaceSize().getResolution().getWidth(), + screenMode.getMonitorMode().getSurfaceSize().getResolution().getHeight()); + } + + if(DEBUG) { + System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): X.0 "+screenMode+", success: "+success); + } + + sms.fireScreenModeChanged(smU, success); + + if(DEBUG) { + System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): X.X "+screenMode+", success: "+success); + } + + return success; + } finally { + sms.unlock(); + } + } + return false; + } + + public void screenModeChangeNotify(ScreenMode sm) { + for(int i=0; i<referencedScreenModeListener.size(); i++) { + ((ScreenModeListener)referencedScreenModeListener.get(i)).screenModeChangeNotify(sm); + } + } + + public void screenModeChanged(ScreenMode sm, boolean success) { + for(int i=0; i<referencedScreenModeListener.size(); i++) { + ((ScreenModeListener)referencedScreenModeListener.get(i)).screenModeChanged(sm, success); + } + } + + public synchronized final void addScreenModeListener(ScreenModeListener sml) { + referencedScreenModeListener.add(sml); + } + + public synchronized final void removeScreenModeListener(ScreenModeListener sml) { + referencedScreenModeListener.remove(sml); + } + + /** ScreenModeStatus bridge to native implementation */ + protected final ArrayHashSet getScreenModesOrig() { + ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); + if(null!=sms) { + return sms.getScreenModes(); + } + return null; + } + + /** ScreenModeStatus bridge to native implementation */ + protected final IntIntHashMap getScreenModesIdx2NativeIdx() { + ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); + if(null!=sms) { + return sms.getScreenModesIdx2NativeIdx(); + } + return null; + } + + /** + * To be implemented by the native specification.<br> + * Is called within a thread safe environment.<br> + * Is called only to collect the ScreenModes, usually at startup setting up modes.<br> + * <br> + * <b>WARNING</b>: must be synchronized with {@link com.jogamp.newt.util.ScreenModeUtil#NUM_SCREEN_MODE_PROPERTIES}, + * ie {@link com.jogamp.newt.util.ScreenModeUtil#streamIn(com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, int[], int)}<br> + * <br> + * <b>Note</b>: Additional 1st element is native mode id. + */ + protected int[] getScreenModeFirstImpl() { + return null; + } + + /** + * To be implemented by the native specification.<br> + * Is called within a thread safe environment.<br> + * Is called only to collect the ScreenModes, usually at startup setting up modes.<br> + * <br> + * <b>WARNING</b>: must be synchronized with {@link com.jogamp.newt.util.ScreenModeUtil#NUM_SCREEN_MODE_PROPERTIES}, + * ie {@link com.jogamp.newt.util.ScreenModeUtil#streamIn(com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, int[], int)}<br> + * <br> + * <b>Note</b>: Additional 1st element is native mode id. + */ + protected int[] getScreenModeNextImpl() { + return null; + } + + /** + * To be implemented by the native specification.<br> + * Is called within a thread safe environment.<br> + */ + protected ScreenMode getCurrentScreenModeImpl() { + return null; + } + + /** + * To be implemented by the native specification.<br> + * Is called within a thread safe environment.<br> + */ + protected boolean setCurrentScreenModeImpl(ScreenMode screenMode) { + return false; + } + + private void initScreenModeStatus() { + ScreenModeStatus sms; + ScreenModeStatus.lockScreenModeStatus(); + try { + sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); + if(null==sms) { + IntIntHashMap screenModesIdx2NativeIdx = new IntIntHashMap(); + + ArrayHashSet screenModes = collectNativeScreenModes(screenModesIdx2NativeIdx); + sms = new ScreenModeStatus(screenModes, screenModesIdx2NativeIdx); + if(null!=screenModes && screenModes.size()>0) { + ScreenMode originalScreenMode = ( DEBUG_TEST_SCREENMODE_DISABLED ) ? null : getCurrentScreenModeImpl(); + if(null != originalScreenMode) { + ScreenMode originalScreenMode0 = (ScreenMode) screenModes.get(originalScreenMode); // unify via value hash + if(null == originalScreenMode0) { + throw new RuntimeException(originalScreenMode+" could not be hashed from ScreenMode list"); + } + sms.setOriginalScreenMode(originalScreenMode0); + } + } + ScreenModeStatus.mapScreenModeStatus(this.getFQName(), sms); + } + sms.addListener(this); + } finally { + ScreenModeStatus.unlockScreenModeStatus(); + } + } + + /** ignores bpp < 15 */ + private ArrayHashSet collectNativeScreenModes(IntIntHashMap screenModesIdx2NativeId) { + ArrayHashSet resolutionPool = new ArrayHashSet(); + ArrayHashSet surfaceSizePool = new ArrayHashSet(); + ArrayHashSet screenSizeMMPool = new ArrayHashSet(); + ArrayHashSet monitorModePool = new ArrayHashSet(); + ArrayHashSet screenModePool = null; + + screenModePool = new ArrayHashSet(); + + int[] smProps = null; + int num = 0; + final int idxBpp = 1 // native mode + + 1 // count + + ScreenModeUtil.NUM_RESOLUTION_PROPERTIES + + ScreenModeUtil.NUM_SURFACE_SIZE_PROPERTIES + - 1 ; // index 0 based + do { + if(DEBUG_TEST_SCREENMODE_DISABLED) { + smProps = null; + } else if(0 == num) { + smProps = getScreenModeFirstImpl(); + } else { + smProps = getScreenModeNextImpl(); + } + if(null != smProps && 0 < smProps.length && smProps[idxBpp] >= 15) { + int nativeId = smProps[0]; + int screenModeIdx = ScreenModeUtil.streamIn(resolutionPool, surfaceSizePool, screenSizeMMPool, + monitorModePool, screenModePool, smProps, 1); + if(screenModeIdx >= 0) { + screenModesIdx2NativeId.put(screenModeIdx, nativeId); + } + } + num++; + } while ( null != smProps && 0 < smProps.length ); + + if(DEBUG) { + System.err.println("ScreenImpl.collectNativeScreenModes: ScreenMode number : "+screenModePool.size()); + System.err.println("ScreenImpl.collectNativeScreenModes: MonitorMode number : "+monitorModePool.size()); + System.err.println("ScreenImpl.collectNativeScreenModes: ScreenSizeMM number: "+screenSizeMMPool.size()); + System.err.println("ScreenImpl.collectNativeScreenModes: SurfaceSize number : "+surfaceSizePool.size()); + System.err.println("ScreenImpl.collectNativeScreenModes: Resolution number : "+resolutionPool.size()); + } + + return screenModePool; + } + + private void releaseScreenModeStatus() { + ScreenModeStatus sms; + ScreenModeStatus.lockScreenModeStatus(); + try { + sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); + if(null != sms) { + sms.lock(); + try { + if(0 == sms.removeListener(this)) { + if(!sms.isOriginalMode()) { + setCurrentScreenMode(sms.getOriginalScreenMode()); + } + ScreenModeStatus.unmapScreenModeStatus(this.getFQName()); + } + } finally { + sms.unlock(); + } + } + } finally { + ScreenModeStatus.unlockScreenModeStatus(); + } + } +} + diff --git a/src/newt/classes/jogamp/newt/ScreenModeStatus.java b/src/newt/classes/jogamp/newt/ScreenModeStatus.java new file mode 100644 index 000000000..4d8b8b5f6 --- /dev/null +++ b/src/newt/classes/jogamp/newt/ScreenModeStatus.java @@ -0,0 +1,207 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.newt; + +import com.jogamp.common.util.ArrayHashSet; +import com.jogamp.common.util.IntIntHashMap; +import com.jogamp.common.util.locks.RecursiveLock; +import com.jogamp.newt.Screen; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.event.ScreenModeListener; +import java.util.ArrayList; +import java.util.HashMap; + +public class ScreenModeStatus { + private static boolean DEBUG = Screen.DEBUG; + + private RecursiveLock lock = new RecursiveLock(); + private ArrayHashSet/*<ScreenMode>*/ screenModes; + private IntIntHashMap screenModesIdx2NativeIdx; + private ScreenMode currentScreenMode; + private ScreenMode originalScreenMode; + private ArrayList/*<ScreenModeChangeListener>*/ listener = new ArrayList(); + + private static HashMap screenFQN2ScreenModeStatus = new HashMap(); + private static RecursiveLock screen2ScreenModeStatusLock = new RecursiveLock(); + + protected static void mapScreenModeStatus(String screenFQN, ScreenModeStatus sms) { + screen2ScreenModeStatusLock.lock(); + try { + ScreenModeStatus _sms = (ScreenModeStatus) screenFQN2ScreenModeStatus.get(screenFQN); + if( null != _sms ) { + throw new RuntimeException("ScreenModeStatus "+_sms+" already mapped to "+screenFQN); + } + screenFQN2ScreenModeStatus.put(screenFQN, sms); + if(DEBUG) { + System.err.println("ScreenModeStatus.map "+screenFQN+" -> "+sms); + } + } finally { + screen2ScreenModeStatusLock.unlock(); + } + } + + /** + * @param screen the prev user + * @return true if mapping is empty, ie no more usage of the mapped ScreenModeStatus + */ + protected static void unmapScreenModeStatus(String screenFQN) { + screen2ScreenModeStatusLock.lock(); + try { + ScreenModeStatus sms = (ScreenModeStatus) screenFQN2ScreenModeStatus.remove(screenFQN); + if(DEBUG) { + System.err.println("ScreenModeStatus.unmap "+screenFQN+" -> "+sms); + } + } finally { + screen2ScreenModeStatusLock.unlock(); + } + } + + protected static ScreenModeStatus getScreenModeStatus(String screenFQN) { + screen2ScreenModeStatusLock.lock(); + try { + return (ScreenModeStatus) screenFQN2ScreenModeStatus.get(screenFQN); + } finally { + screen2ScreenModeStatusLock.unlock(); + } + } + + protected static void lockScreenModeStatus() { + screen2ScreenModeStatusLock.lock(); + } + + protected static void unlockScreenModeStatus() { + screen2ScreenModeStatusLock.unlock(); + } + + public ScreenModeStatus(ArrayHashSet/*<ScreenMode>*/ screenModes, + IntIntHashMap screenModesIdx2NativeIdx) { + this.screenModes = screenModes; + this.screenModesIdx2NativeIdx = screenModesIdx2NativeIdx; + } + + protected final void setOriginalScreenMode(ScreenMode originalScreenMode) { + this.originalScreenMode = originalScreenMode; + this.currentScreenMode = originalScreenMode; + } + + public final ScreenMode getOriginalScreenMode() { + return originalScreenMode; + } + + public final ScreenMode getCurrentScreenMode() { + lock(); + try { + return currentScreenMode; + } finally { + unlock(); + } + } + + public final boolean isOriginalMode() { + lock(); + try { + if(null != currentScreenMode && null != originalScreenMode) { + return currentScreenMode.hashCode() == originalScreenMode.hashCode(); + } + return true; + } finally { + unlock(); + } + } + + protected final ArrayHashSet/*<ScreenMode>*/ getScreenModes() { + return screenModes; + } + + protected final IntIntHashMap getScreenModesIdx2NativeIdx() { + return screenModesIdx2NativeIdx; + } + + protected final int addListener(ScreenModeListener l) { + lock(); + try { + listener.add(l); + if(DEBUG) { + System.err.println("ScreenModeStatus.addListener (size: "+listener.size()+"): "+l); + } + return listener.size(); + } finally { + unlock(); + } + } + + protected final int removeListener(ScreenModeListener l) { + lock(); + try { + if(!listener.remove(l)) { + throw new RuntimeException("ScreenModeListener "+l+" not contained"); + } + if(DEBUG) { + System.err.println("ScreenModeStatus.removeListener (size: "+listener.size()+"): "+l); + } + return listener.size(); + } finally { + unlock(); + } + } + + protected final void fireScreenModeChangeNotify(ScreenMode desiredScreenMode) { + lock(); + try { + for(int i=0; i<listener.size(); i++) { + ((ScreenModeListener)listener.get(i)).screenModeChangeNotify(desiredScreenMode); + } + } finally { + unlock(); + } + } + + protected void fireScreenModeChanged(ScreenMode currentScreenMode, boolean success) { + lock(); + try { + if(success) { + this.currentScreenMode = currentScreenMode; + } + for(int i=0; i<listener.size(); i++) { + ((ScreenModeListener)listener.get(i)).screenModeChanged(currentScreenMode, success); + } + } finally { + unlock(); + } + } + + protected final void lock() throws RuntimeException { + lock.lock(); + } + + protected final void unlock() throws RuntimeException { + lock.unlock(); + } + +} diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java new file mode 100644 index 000000000..cb1c0eda2 --- /dev/null +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -0,0 +1,2239 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt; + +import java.util.ArrayList; +import java.lang.reflect.Method; + +import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Display; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.common.util.locks.RecursiveLock; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.event.KeyListener; +import com.jogamp.newt.event.MouseEvent; +import com.jogamp.newt.event.MouseListener; +import com.jogamp.newt.event.NEWTEvent; +import com.jogamp.newt.event.NEWTEventConsumer; +import com.jogamp.newt.event.ScreenModeListener; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.event.WindowListener; +import com.jogamp.newt.event.WindowUpdateEvent; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.SurfaceUpdatedListener; +import javax.media.nativewindow.util.DimensionReadOnly; +import javax.media.nativewindow.util.Insets; +import javax.media.nativewindow.util.Point; +import javax.media.nativewindow.util.Rectangle; + +public abstract class WindowImpl implements Window, NEWTEventConsumer +{ + public static final boolean DEBUG_TEST_REPARENT_INCOMPATIBLE = Debug.isPropertyDefined("newt.test.Window.reparent.incompatible", true); + + private RecursiveLock windowLock = new RecursiveLock(); // Window instance wide lock + private RecursiveLock surfaceLock = new RecursiveLock(); // Surface only lock + private long windowHandle; + private ScreenImpl screen; + private boolean screenReferenceAdded = false; + private NativeWindow parentWindow; + private long parentWindowHandle; + protected AbstractGraphicsConfiguration config; + protected CapabilitiesImmutable capsRequested; + protected CapabilitiesChooser capabilitiesChooser = null; // default null -> default + protected boolean fullscreen, visible, hasFocus; + protected int width, height, x, y; + protected int nfs_width, nfs_height, nfs_x, nfs_y; // non fullscreen dimensions .. + protected String title = "Newt Window"; + protected boolean undecorated = false; + private LifecycleHook lifecycleHook = null; + + private DestroyAction destroyAction = new DestroyAction(); + private boolean handleDestroyNotify = true; + + private ReparentActionRecreate reparentActionRecreate = new ReparentActionRecreate(); + + private RequestFocusAction requestFocusAction = new RequestFocusAction(); + private FocusRunnable focusAction = null; + + private Object surfaceUpdatedListenersLock = new Object(); + private ArrayList surfaceUpdatedListeners; + + private Object childWindowsLock = new Object(); + private ArrayList childWindows; + + private ArrayList mouseListeners; + private int mouseButtonPressed; // current pressed mouse button number + private long lastMousePressed; // last time when a mouse button was pressed + private int lastMouseClickCount; // last mouse button click count + + private ArrayList keyListeners; + + private ArrayList windowListeners; + private boolean repaintQueued = false; + + ScreenModeListenerImpl screenModeListenerImpl = new ScreenModeListenerImpl(); + + private void initializeStates() { + invalidate(true); + + childWindows = new ArrayList(); + surfaceUpdatedListeners = new ArrayList(); + windowListeners = new ArrayList(); + mouseListeners = new ArrayList(); + + mouseButtonPressed = 0; // current pressed mouse button number + lastMousePressed = 0; // last time when a mouse button was pressed + lastMouseClickCount = 0; // last mouse button click count + keyListeners = new ArrayList(); + } + + // Workaround for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod -- if Fmod is + // initialized first then the connection to the window server + // breaks, leading to errors from deep within the AppKit + public static void init(String type) { + if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + try { + getWindowClass(type); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + // + // Construction Methods + // + + private static Class getWindowClass(String type) + throws ClassNotFoundException + { + Class windowClass = NewtFactory.getCustomClass(type, "Window"); + if(null==windowClass) { + if (NativeWindowFactory.TYPE_EGL.equals(type)) { + windowClass = Class.forName("jogamp.newt.opengl.kd.KDWindow"); + } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { + windowClass = Class.forName("jogamp.newt.windows.WindowsWindow"); + } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + windowClass = Class.forName("jogamp.newt.macosx.MacWindow"); + } else if (NativeWindowFactory.TYPE_X11.equals(type)) { + windowClass = Class.forName("jogamp.newt.x11.X11Window"); + } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { + windowClass = Class.forName("jogamp.newt.awt.AWTWindow"); + } else { + throw new NativeWindowException("Unknown window type \"" + type + "\""); + } + } + return windowClass; + } + + public static WindowImpl create(NativeWindow parentWindow, long parentWindowHandle, Screen screen, CapabilitiesImmutable caps) { + try { + Class windowClass; + if(caps.isOnscreen()) { + windowClass = getWindowClass(screen.getDisplay().getType()); + } else { + windowClass = OffscreenWindow.class; + } + WindowImpl window = (WindowImpl) windowClass.newInstance(); + window.initializeStates(); + window.parentWindow = parentWindow; + window.parentWindowHandle = parentWindowHandle; + window.screen = (ScreenImpl) screen; + window.capsRequested = (CapabilitiesImmutable) caps.cloneMutable(); + window.setUndecorated(0!=parentWindowHandle); + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new NativeWindowException(t); + } + } + + public static WindowImpl create(Object[] cstrArguments, Screen screen, CapabilitiesImmutable caps) { + try { + Class windowClass = getWindowClass(screen.getDisplay().getType()); + Class[] cstrArgumentTypes = getCustomConstructorArgumentTypes(windowClass); + if(null==cstrArgumentTypes) { + throw new NativeWindowException("WindowClass "+windowClass+" doesn't support custom arguments in constructor"); + } + int argsChecked = verifyConstructorArgumentTypes(cstrArgumentTypes, cstrArguments); + if ( argsChecked < cstrArguments.length ) { + throw new NativeWindowException("WindowClass "+windowClass+" constructor mismatch at argument #"+argsChecked+"; Constructor: "+getTypeStrList(cstrArgumentTypes)+", arguments: "+getArgsStrList(cstrArguments)); + } + WindowImpl window = (WindowImpl) ReflectionUtil.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; + window.initializeStates(); + window.screen = (ScreenImpl) screen; + window.capsRequested = (CapabilitiesImmutable) caps.cloneMutable(); + return window; + } catch (Throwable t) { + throw new NativeWindowException(t); + } + } + + public static interface LifecycleHook { + /** + * Reset of internal state counter, ie totalFrames, etc. + * Called from EDT while window is locked. + */ + public abstract void resetCounter(); + + /** + * Invoked after Window setVisible, + * allows allocating resources depending on the native Window. + * Called from EDT while window is locked. + */ + void setVisibleActionPost(boolean visible, boolean nativeWindowCreated); + + /** + * Invoked before Window destroy action, + * allows releasing of resources depending on the native Window.<br> + * Surface not locked yet.<br> + * Called not necessarily from EDT. + */ + void destroyActionPreLock(); + + /** + * Invoked before Window destroy action, + * allows releasing of resources depending on the native Window.<br> + * Surface locked.<br> + * Called from EDT while window is locked. + */ + void destroyActionInLock(); + + /** + * Invoked after destruction from Window's invalidate method.<br> + * Called while window is locked. + * @param unrecoverable + */ + void invalidate(boolean unrecoverable); + + /** + * Invoked for expensive modifications, ie while reparenting and ScreenMode change.<br> + * No lock is hold when invoked.<br> + * + * @return true is paused, otherwise false. If true {@link #resumeRenderingAction()} shall be issued. + * + * @see #resumeRenderingAction() + */ + boolean pauseRenderingAction(); + + /** + * Invoked for expensive modifications, ie while reparenting and ScreenMode change. + * No lock is hold when invoked.<br> + * + * @see #pauseRenderingAction() + */ + void resumeRenderingAction(); + } + + private boolean createNative() { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.createNative() START ("+getThreadName()+", "+this+")"); + } + if( null != parentWindow && + NativeSurface.LOCK_SURFACE_NOT_READY >= parentWindow.lockSurface() ) { + throw new NativeWindowException("Parent surface lock: not ready: "+parentWindow); + } + try { + if(validateParentWindowHandle()) { + if(screenReferenceAdded) { + throw new InternalError("XXX"); + } + screen.addReference(); + screenReferenceAdded = true; + createNativeImpl(); + setVisibleImpl(true, x, y, width, height); + screen.addScreenModeListener(screenModeListenerImpl); + setTitleImpl(title); + } + } finally { + if(null!=parentWindow) { + parentWindow.unlockSurface(); + } + } + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.createNative() END ("+getThreadName()+", "+this+")"); + } + return 0 != windowHandle ; + } + + private void removeScreenReference() { + if(screenReferenceAdded) { + // be nice, probably already called recursive via + // closeAndInvalidate() -> closeNativeIml() -> .. -> windowDestroyed() -> closeAndInvalidate() ! + // or via reparentWindow .. etc + screenReferenceAdded = false; + screen.removeReference(); + } + } + + private void closeAndInvalidate() { + windowLock.lock(); + try { + if( null != screen ) { + if( 0 != windowHandle ) { + screen.removeScreenModeListener(screenModeListenerImpl); + closeNativeImpl(); + removeScreenReference(); + } + Display dpy = screen.getDisplay(); + if(null != dpy) { + dpy.validateEDT(); + } + } + invalidate(false); + } finally { + windowLock.unlock(); + } + } + + private boolean validateParentWindowHandle() { + if(null!=parentWindow) { + parentWindowHandle = getNativeWindowHandle(parentWindow); + return 0 != parentWindowHandle ; + } + return true; + } + + private static long getNativeWindowHandle(NativeWindow nativeWindow) { + long handle = 0; + if(null!=nativeWindow) { + boolean wasLocked = false; + if( NativeSurface.LOCK_SURFACE_NOT_READY < nativeWindow.lockSurface() ) { + wasLocked = true; + try { + handle = nativeWindow.getWindowHandle(); + if(0==handle) { + throw new NativeWindowException("Parent native window handle is NULL, after succesful locking: "+nativeWindow); + } + } catch (NativeWindowException nwe) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.getNativeWindowHandle: not successful yet: "+nwe); + } + } finally { + nativeWindow.unlockSurface(); + } + } + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.getNativeWindowHandle: locked "+wasLocked+", "+nativeWindow); + } + } + return handle; + } + + + //---------------------------------------------------------------------- + // NativeSurface: Native implementation + // + + protected int lockSurfaceImpl() { return LOCK_SUCCESS; } + + protected void unlockSurfaceImpl() { } + + //---------------------------------------------------------------------- + // WindowClosingProtocol implementation + // + private Object closingListenerLock = new Object(); + private int defaultCloseOperation = DISPOSE_ON_CLOSE; + + public int getDefaultCloseOperation() { + synchronized (closingListenerLock) { + return defaultCloseOperation; + } + } + + public int setDefaultCloseOperation(int op) { + synchronized (closingListenerLock) { + int _op = defaultCloseOperation; + defaultCloseOperation = op; + return _op; + } + } + + //---------------------------------------------------------------------- + // Window: Native implementation + // + + /** + * The native implementation must set the native windowHandle.<br> + * + * The implementation should invoke the referenced java state callbacks + * to notify this Java object of state changes. + * + * @see #windowDestroyNotify() + * @see #focusChanged(boolean) + * @see #visibleChanged(boolean) + * @see #sizeChanged(int,int) + * @see #positionChanged(int,int) + * @see #windowDestroyNotify() + */ + protected abstract void createNativeImpl(); + + protected abstract void closeNativeImpl(); + + /** + * The native implementation must invoke {@link #focusChanged(boolean)} + * to change the focus state, if <code>force == false</code>. + * This may happen asynchronous within {@link #TIMEOUT_NATIVEWINDOW}. + * + * @param force if true, bypass {@link #focusChanged(boolean)} and force focus request + */ + protected abstract void requestFocusImpl(boolean force); + + /** + * The native implementation must invoke {@link #visibleChanged(boolean)} + * to change the visibility state. This may happen asynchronous within + * {@link #TIMEOUT_NATIVEWINDOW}. + */ + protected abstract void setVisibleImpl(boolean visible, int x, int y, int width, int height); + + /** + * The native implementation should invoke the referenced java state callbacks + * to notify this Java object of state changes. + * + * @param x -1 if no position change requested, otherwise greater than zero + * @param y -1 if no position change requested, otherwise greater than zero + * @param width -1 if no size change requested, otherwise greater than zero + * @param height -1 if no size change requested, otherwise greater than zero + * @param parentChange true if reparenting requested, otherwise false + * @param fullScreenChange 0 if unchanged, -1 fullscreen off, 1 fullscreen on + * @param decorationChange 0 if unchanged, -1 undecorated, 1 decorated + * + * @see #sizeChanged(int,int) + * @see #positionChanged(int,int) + */ + protected abstract boolean reconfigureWindowImpl(int x, int y, int width, int height, + boolean parentChange, int fullScreenChange, int decorationChange); + + protected void setTitleImpl(String title) {} + + /** + * Return screen coordinates of the given coordinates + * or null, in which case a NativeWindow traversal shall being used + * as demonstrated in {@link #getLocationOnScreen(javax.media.nativewindow.util.Point)}. + * + * @return if not null, the screen location of the given coordinates + */ + protected abstract Point getLocationOnScreenImpl(int x, int y); + + //---------------------------------------------------------------------- + // NativeSurface + // + + public final int lockSurface() { + windowLock.lock(); + surfaceLock.lock(); + int res = surfaceLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; + + if ( LOCK_SURFACE_NOT_READY == res ) { + try { + if( isNativeValid() ) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + adevice.lock(); + try { + res = lockSurfaceImpl(); + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + adevice.unlock(); + } + } + } + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + surfaceLock.unlock(); + windowLock.unlock(); + } + } + } + return res; + } + + public final void unlockSurface() { + surfaceLock.validateLocked(); + windowLock.validateLocked(); + + if (surfaceLock.getRecursionCount() == 0) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + try { + unlockSurfaceImpl(); + } finally { + adevice.unlock(); + } + } + surfaceLock.unlock(); + windowLock.unlock(); + } + + public final boolean isWindowLockedByOtherThread() { + return windowLock.isLockedByOtherThread(); + } + + public final boolean isWindowLocked() { + return windowLock.isLocked(); + } + + public final Thread getWindowLockOwner() { + return windowLock.getOwner(); + } + + public final boolean isSurfaceLockedByOtherThread() { + return surfaceLock.isLockedByOtherThread(); + } + + public final boolean isSurfaceLocked() { + return surfaceLock.isLocked(); + } + + public final Thread getSurfaceLockOwner() { + return surfaceLock.getOwner(); + } + + public long getSurfaceHandle() { + return windowHandle; // default: return window handle + } + + public boolean surfaceSwap() { + return false; + } + + public AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + public final long getDisplayHandle() { + return getScreen().getDisplay().getHandle(); + } + + public final int getScreenIndex() { + return getScreen().getIndex(); + } + + //---------------------------------------------------------------------- + // NativeWindow + // + + // public final void destroy() - see below + + public final NativeWindow getParent() { + return parentWindow; + } + + public final long getWindowHandle() { + return windowHandle; + } + + public Point getLocationOnScreen(Point storage) { + if(isNativeValid()) { + Point d; + windowLock.lock(); + try { + d = getLocationOnScreenImpl(0, 0); + } finally { + windowLock.unlock(); + } + if(null!=d) { + if(null!=storage) { + storage.translate(d.getX(),d.getY()); + return storage; + } + return d; + } + // fall through intended .. + } + + if(null!=storage) { + storage.translate(getX(),getY()); + } else { + storage = new Point(getX(),getY()); + } + if(null!=parentWindow) { + // traverse through parent list .. + parentWindow.getLocationOnScreen(storage); + } + return storage; + } + + //---------------------------------------------------------------------- + // Window + // + + public final boolean isNativeValid() { + return null != getScreen() && 0 != getWindowHandle() ; + } + + public final boolean isValid() { + return null != getScreen() ; + } + + public final Screen getScreen() { + return screen; + } + + final void setVisibleActionImpl(boolean visible) { + boolean nativeWindowCreated = false; + boolean madeVisible = false; + + windowLock.lock(); + try { + if(null!=lifecycleHook) { + lifecycleHook.resetCounter(); + } + + if(!visible && null!=childWindows && childWindows.size()>0) { + synchronized(childWindowsLock) { + for(int i = 0; i < childWindows.size(); i++ ) { + NativeWindow nw = (NativeWindow) childWindows.get(i); + if(nw instanceof WindowImpl) { + ((WindowImpl)nw).setVisible(false); + } + } + } + } + if(0==windowHandle && visible) { + if( 0<width*height ) { + nativeWindowCreated = createNative(); + WindowImpl.this.waitForVisible(visible, true); + madeVisible = visible; + } + } else if(WindowImpl.this.visible != visible) { + if(0 != windowHandle) { + setVisibleImpl(visible, x, y, width, height); + WindowImpl.this.waitForVisible(visible, true); + madeVisible = visible; + } + } + + if(null!=lifecycleHook) { + lifecycleHook.setVisibleActionPost(visible, nativeWindowCreated); + } + + if(0!=windowHandle && visible && null!=childWindows && childWindows.size()>0) { + synchronized(childWindowsLock) { + for(int i = 0; i < childWindows.size(); i++ ) { + NativeWindow nw = (NativeWindow) childWindows.get(i); + if(nw instanceof WindowImpl) { + ((WindowImpl)nw).setVisible(true); + } + } + } + } + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window setVisible: END ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+WindowImpl.this.visible+", nativeWindowCreated: "+nativeWindowCreated+", madeVisible: "+madeVisible); + } + } finally { + windowLock.unlock(); + } + if( nativeWindowCreated || madeVisible ) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener + } + } + + private class VisibleAction implements Runnable { + boolean visible; + + private VisibleAction (boolean visible) { + this.visible = visible; + } + + public final void run() { + setVisibleActionImpl(visible); + } + } + + public void setVisible(boolean visible) { + if(isValid()) { + if( 0==windowHandle && visible && 0>=width*height ) { + // fast-path: not realized yet, make visible, but zero size + return; + } + + if(DEBUG_IMPLEMENTATION) { + String msg = "Window setVisible: START ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+this.visible+" -> "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+(null!=parentWindow); + System.err.println(msg); + Thread.dumpStack(); + } + runOnEDTIfAvail(true, new VisibleAction(visible)); + } + } + + private class SetSizeActionImpl implements Runnable { + int width, height; + + private SetSizeActionImpl(int w, int h) { + width = w; + height = h; + } + public final void run() { + windowLock.lock(); + try { + int visibleAction = 0; // 1 invisible, 2 visible (create) + if ( !fullscreen && ( width != WindowImpl.this.width || WindowImpl.this.height != height ) ) { + if(DEBUG_IMPLEMENTATION) { + String msg = "Window setSize: START "+WindowImpl.this.width+"x"+WindowImpl.this.height+" -> "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible "+visible; + System.err.println(msg); + } + if ( 0 != windowHandle && 0>=width*height && visible ) { + visibleAction=1; // invisible + WindowImpl.this.width = 0; + WindowImpl.this.height = 0; + } else if ( 0 == windowHandle && 0<width*height && visible ) { + visibleAction = 2; // visible (create) + WindowImpl.this.width = width; + WindowImpl.this.height = height; + } else if ( 0 != windowHandle ) { + // this width/height will be set by windowChanged, called by the native implementation + reconfigureWindowImpl(x, y, width, height, false, 0, 0); + } else { + WindowImpl.this.width = width; + WindowImpl.this.height = height; + } + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window setSize: END "+WindowImpl.this.width+"x"+WindowImpl.this.height+", visibleAction "+visibleAction); + } + switch(visibleAction) { + case 1: setVisibleActionImpl(false); break; + case 2: setVisibleActionImpl(true); break; + } + } + } finally { + windowLock.unlock(); + } + } + } + + public void setSize(int width, int height) { + if(isValid()) { + runOnEDTIfAvail(true, new SetSizeActionImpl(width, height)); + } + } + + private class DestroyAction implements Runnable { + public final void run() { + boolean animatorPaused = false; + if(null!=lifecycleHook) { + animatorPaused = lifecycleHook.pauseRenderingAction(); + } + if(null!=lifecycleHook) { + lifecycleHook.destroyActionPreLock(); + } + windowLock.lock(); + try { + if( !isValid() ) { + return; // nop + } + + // Childs first .. + synchronized(childWindowsLock) { + if(childWindows.size()>0) { + // avoid ConcurrentModificationException: parent -> child -> parent.removeChild(this) + ArrayList clonedChildWindows = (ArrayList) childWindows.clone(); + while( clonedChildWindows.size() > 0 ) { + NativeWindow nw = (NativeWindow) clonedChildWindows.remove(0); + if(nw instanceof WindowImpl) { + ((WindowImpl)nw).sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); + ((WindowImpl)nw).destroy(); + } else { + nw.destroy(); + } + } + } + } + + if(null!=lifecycleHook) { + // send synced destroy notification for proper cleanup, eg GLWindow/OpenGL + lifecycleHook.destroyActionInLock(); + } + + closeAndInvalidate(); + + // send synced destroyed notification + sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROYED); + + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.destroy() END "+getThreadName()/*+", "+WindowImpl.this*/); + } + } finally { + windowLock.unlock(); + } + if(animatorPaused) { + lifecycleHook.resumeRenderingAction(); + } + } + } + + public void destroy() { + if( isValid() ) { + if(DEBUG_IMPLEMENTATION) { + String msg = "Window.destroy() START "+getThreadName(); + System.err.println(msg); + //Exception ee = new Exception(msg); + //ee.printStackTrace(); + } + runOnEDTIfAvail(true, destroyAction); + } + } + + public final void invalidate() { + destroy(); + invalidate(true); + } + + /** + * @param unrecoverable If true, all states, size, position, parent handles, + * reference to it's Screen are reset. + * Otherwise you can recreate the window, via <code>setVisible(true)</code>. + * @see #invalidate() + * @see #destroy() + * @see #destroy(boolean) + */ + protected void invalidate(boolean unrecoverable) { + windowLock.lock(); + try { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + String msg = "!!! Window Invalidate(unrecoverable: "+unrecoverable+") "+getThreadName(); + System.err.println(msg); + // Throwable t = new Throwable(msg); + // t.printStackTrace(); + } + + // Childs first .. + synchronized(childWindowsLock) { + // avoid ConcurrentModificationException: parent -> child -> parent.removeChild(this) + if(null!=childWindows && childWindows.size()>0) { + ArrayList clonedChildWindows = (ArrayList) childWindows.clone(); + while( clonedChildWindows.size() > 0 ) { + NativeWindow nw = (NativeWindow) clonedChildWindows.remove(0); + if(nw instanceof WindowImpl) { + ((WindowImpl)nw).invalidate(unrecoverable); + } + } + } + } + + if(null!=lifecycleHook) { + lifecycleHook.invalidate(unrecoverable); + } + + windowHandle = 0; + visible = false; + fullscreen = false; + hasFocus = false; + + if(unrecoverable) { + if(null!=parentWindow && parentWindow instanceof Window) { + ((Window)parentWindow).removeChild(WindowImpl.this); + } + screen = null; + + synchronized(childWindowsLock) { + childWindows = null; + } + synchronized(surfaceUpdatedListenersLock) { + surfaceUpdatedListeners = null; + } + windowListeners = null; + mouseListeners = null; + keyListeners = null; + + parentWindowHandle = 0; + parentWindow = null; + capsRequested = null; + lifecycleHook = null; + + // Default position and dimension will be re-set immediately by user + width = 128; + height = 128; + x=0; + y=0; + } + } finally { + windowLock.unlock(); + } + } + + private class ReparentActionImpl implements Runnable, ReparentAction { + NativeWindow newParentWindow; + boolean forceDestroyCreate; + int reparentAction; + + private ReparentActionImpl(NativeWindow newParentWindow, boolean forceDestroyCreate) { + this.newParentWindow = newParentWindow; + this.forceDestroyCreate = forceDestroyCreate; + this.reparentAction = -1; // ensure it's set + } + + private int getStrategy() { + return reparentAction; + } + + private void setScreen(ScreenImpl newScreen) { + WindowImpl.this.removeScreenReference(); + screen = newScreen; + } + + public final void run() { + boolean animatorPaused = false; + if(null!=lifecycleHook) { + animatorPaused = lifecycleHook.pauseRenderingAction(); + } + reparent(); + if(animatorPaused) { + lifecycleHook.resumeRenderingAction(); + } + } + + private void reparent() { + // mirror pos/size so native change notification can get overwritten + int x = WindowImpl.this.x; + int y = WindowImpl.this.y; + int width = WindowImpl.this.width; + int height = WindowImpl.this.height; + boolean wasVisible; + + windowLock.lock(); + try { + wasVisible = isVisible(); + + Window newParentWindowNEWT = null; + if(newParentWindow instanceof Window) { + newParentWindowNEWT = (Window) newParentWindow; + } + + long newParentWindowHandle = 0 ; + + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.reparent: START ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+", visible "+wasVisible+", old parentWindow: "+Display.hashCodeNullSafe(parentWindow)+", new parentWindow: "+Display.hashCodeNullSafe(newParentWindow)+", forceDestroyCreate "+forceDestroyCreate+", DEBUG_TEST_REPARENT_INCOMPATIBLE "+DEBUG_TEST_REPARENT_INCOMPATIBLE+" "+x+"/"+y+" "+width+"x"+height); + } + + if(null!=lifecycleHook) { + lifecycleHook.resetCounter(); + } + + if(null!=newParentWindow) { + // reset position to 0/0 within parent space + x = 0; + y = 0; + + // refit if size is bigger than parent + if( width > newParentWindow.getWidth() ) { + width = newParentWindow.getWidth(); + } + if( height > newParentWindow.getHeight() ) { + height = newParentWindow.getHeight(); + } + + // Case: Child Window + newParentWindowHandle = getNativeWindowHandle(newParentWindow); + if(0 == newParentWindowHandle) { + // Case: Parent's native window not realized yet + if(null==newParentWindowNEWT) { + throw new NativeWindowException("Reparenting with non NEWT Window type only available after it's realized: "+newParentWindow); + } + // Destroy this window and use parent's Screen. + // It may be created properly when the parent is made visible. + destroy(); + setScreen( (ScreenImpl) newParentWindowNEWT.getScreen() ); + reparentAction = ACTION_NATIVE_CREATION_PENDING; + } else if(newParentWindow != getParent()) { + // Case: Parent's native window realized and changed + if( !isNativeValid() ) { + // May create a new compatible Screen/Display and + // mark it for creation. + if(null!=newParentWindowNEWT) { + setScreen( (ScreenImpl) newParentWindowNEWT.getScreen() ); + } else { + Screen newScreen = NewtFactory.createCompatibleScreen(newParentWindow, getScreen()); + if( getScreen() != newScreen ) { + // auto destroy on-the-fly created Screen/Display + setScreen( (ScreenImpl) newScreen ); + } + } + if( 0<width*height ) { + reparentAction = ACTION_NATIVE_CREATION; + } else { + reparentAction = ACTION_NATIVE_CREATION_PENDING; + } + } else if ( DEBUG_TEST_REPARENT_INCOMPATIBLE || forceDestroyCreate || + !NewtFactory.isScreenCompatible(newParentWindow, getScreen()) ) { + // Destroy this window, may create a new compatible Screen/Display, + // and mark it for creation. + destroy(); + if(null!=newParentWindowNEWT) { + setScreen( (ScreenImpl) newParentWindowNEWT.getScreen() ); + } else { + setScreen( (ScreenImpl) NewtFactory.createCompatibleScreen(newParentWindow, getScreen()) ); + } + reparentAction = ACTION_NATIVE_CREATION; + } else { + // Mark it for native reparenting + reparentAction = ACTION_NATIVE_REPARENTING; + } + } else { + // Case: Parent's native window realized and not changed + reparentAction = ACTION_UNCHANGED; + } + } else { + if( null != parentWindow ) { + // child -> top + // put client to current parent+child position + Point p = getLocationOnScreen(null); + x = p.getX(); + y = p.getY(); + } + + // Case: Top Window + if( 0 == getParentWindowHandle() ) { + // Already Top Window + reparentAction = ACTION_UNCHANGED; + } else if( !isNativeValid() || DEBUG_TEST_REPARENT_INCOMPATIBLE || forceDestroyCreate ) { + // Destroy this window and mark it for [pending] creation. + destroy(); + if( 0<width*height ) { + reparentAction = ACTION_NATIVE_CREATION; + } else { + reparentAction = ACTION_NATIVE_CREATION_PENDING; + } + } else { + // Mark it for native reparenting + reparentAction = ACTION_NATIVE_REPARENTING; + } + } + parentWindowHandle = newParentWindowHandle; + + if ( ACTION_UNCHANGED > reparentAction ) { + throw new NativeWindowException("Internal Error: reparentAction not set"); + } + + if( ACTION_UNCHANGED == reparentAction ) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.reparent: NO CHANGE ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" new parentWindowHandle "+toHexString(newParentWindowHandle)+", visible "+wasVisible); + } + return; + } + + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.reparent: ACTION ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" new parentWindowHandle "+toHexString(newParentWindowHandle)+", reparentAction "+reparentAction+", visible "+wasVisible); + } + + // rearrange window tree + if(null!=parentWindow && parentWindow instanceof Window) { + ((Window)parentWindow).removeChild(WindowImpl.this); + } + parentWindow = newParentWindow; + if(parentWindow instanceof Window) { + ((Window)parentWindow).addChild(WindowImpl.this); + } + + if( ACTION_NATIVE_CREATION_PENDING == reparentAction ) { + return; + } + + if( ACTION_NATIVE_REPARENTING == reparentAction ) { + DisplayImpl display = (DisplayImpl) screen.getDisplay(); + display.dispatchMessagesNative(); // status up2date + if(wasVisible) { + setVisibleImpl(false, x, y, width, height); + WindowImpl.this.waitForVisible(false, true); + } + + // Lock parentWindow only during reparenting (attempt) + NativeWindow parentWindowLocked = null; + if( null != parentWindow ) { + parentWindowLocked = parentWindow; + if( NativeSurface.LOCK_SURFACE_NOT_READY >= parentWindowLocked.lockSurface() ) { + throw new NativeWindowException("Parent surface lock: not ready: "+parentWindow); + } + } + boolean ok = false; + try { + // write back mirrored values, to be able to detect satisfaction + WindowImpl.this.x = x; + WindowImpl.this.y = y; + WindowImpl.this.width = width; + WindowImpl.this.height = height; + ok = reconfigureWindowImpl(x, y, width, height, true, 0, isUndecorated()?-1:1); + } finally { + if(null!=parentWindowLocked) { + parentWindowLocked.unlockSurface(); + } + } + + // set visible again, and revalidate 'ok', + // since it has been experience that in some cases the reparented window gets hidden + if(ok) { + display.dispatchMessagesNative(); // status up2date + if(wasVisible) { + setVisibleImpl(true, x, y, width, height); + ok = WindowImpl.this.waitForVisible(true, false); + display.dispatchMessagesNative(); // status up2date + if( ok && + ( WindowImpl.this.x != x || + WindowImpl.this.y != y || + WindowImpl.this.width != width || + WindowImpl.this.height != height ) ) + { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.reparent (reconfig)"); + } + // reset pos/size .. due to some native impl flakyness + reconfigureWindowImpl(x, y, width, height, false, 0, 0); + display.dispatchMessagesNative(); // status up2date + WindowImpl.this.waitForVisible(true, false); + display.dispatchMessagesNative(); // status up2date + } + } + } + + if(ok) { + if(wasVisible) { + requestFocusImpl(true); + display.dispatchMessagesNative(); // status up2date + } + } else { + // native reparent failed -> try creation + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.reparent: native reparenting failed ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+" -> "+toHexString(newParentWindowHandle)+" - Trying recreation"); + } + destroy(); + reparentAction = ACTION_NATIVE_CREATION ; + } + } + + // write back mirrored values, ensuring persitence + // and not relying on native messaging + WindowImpl.this.x = x; + WindowImpl.this.y = y; + WindowImpl.this.width = width; + WindowImpl.this.height = height; + + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.reparentWindow: END ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+", visible: "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+ Display.hashCodeNullSafe(parentWindow)+" "+x+"/"+y+" "+width+"x"+height); + } + } finally { + windowLock.unlock(); + } + + if(wasVisible) { + switch (reparentAction) { + case ACTION_NATIVE_REPARENTING: + // trigger a resize/relayout and repaint to listener + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + break; + + case ACTION_NATIVE_CREATION: + // This may run on the new Display/Screen connection, hence a new EDT task + runOnEDTIfAvail(true, reparentActionRecreate); + break; + } + } + } + } + + private class ReparentActionRecreate implements Runnable { + public final void run() { + windowLock.lock(); + try { + visible = true; + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.reparentWindow: ReparentActionRecreate ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+", visible: "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+Display.hashCodeNullSafe(parentWindow)); + } + setVisible(true); // native creation + } finally { + windowLock.unlock(); + } + } + } + + public final int reparentWindow(NativeWindow newParent) { + return reparentWindow(newParent, false); + } + + public int reparentWindow(NativeWindow newParent, boolean forceDestroyCreate) { + int reparentActionStrategy = ReparentAction.ACTION_INVALID; + if(isValid()) { + ReparentActionImpl reparentAction = new ReparentActionImpl(newParent, forceDestroyCreate); + runOnEDTIfAvail(true, reparentAction); + reparentActionStrategy = reparentAction.getStrategy(); + } + return reparentActionStrategy; + } + + public CapabilitiesChooser setCapabilitiesChooser(CapabilitiesChooser chooser) { + CapabilitiesChooser old = this.capabilitiesChooser; + this.capabilitiesChooser = chooser; + return old; + } + + public final CapabilitiesImmutable getChosenCapabilities() { + return config.getNativeGraphicsConfiguration().getChosenCapabilities(); + } + + public final CapabilitiesImmutable getRequestedCapabilities() { + return capsRequested; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + if (title == null) { + title = ""; + } + this.title = title; + if(0 != getWindowHandle()) { + setTitleImpl(title); + } + } + + private class DecorationActionImpl implements Runnable { + boolean undecorated; + + private DecorationActionImpl(boolean undecorated) { + this.undecorated = undecorated; + } + + public final void run() { + windowLock.lock(); + try { + if(!fullscreen && isNativeValid() && WindowImpl.this.undecorated != undecorated) { + WindowImpl.this.undecorated = undecorated; + // mirror pos/size so native change notification can get overwritten + int x = WindowImpl.this.x; + int y = WindowImpl.this.y; + int width = WindowImpl.this.width; + int height = WindowImpl.this.height; + + if( 0 != windowHandle ) { + DisplayImpl display = (DisplayImpl) screen.getDisplay(); + display.dispatchMessagesNative(); // status up2date + boolean wasVisible = isVisible(); + setVisibleImpl(false, x, y, width, height); + WindowImpl.this.waitForVisible(false, true); + display.dispatchMessagesNative(); // status up2date + reconfigureWindowImpl(x, y, width, height, false, 0, undecorated?-1:1); + display.dispatchMessagesNative(); // status up2date + if(wasVisible) { + setVisibleImpl(true, x, y, width, height); + WindowImpl.this.waitForVisible(true, true); + display.dispatchMessagesNative(); // status up2date + if( WindowImpl.this.x != x || + WindowImpl.this.y != y || + WindowImpl.this.width != width || + WindowImpl.this.height != height ) + { + // reset pos/size .. due to some native impl flakyness + reconfigureWindowImpl(x, y, width, height, false, 0, 0); + display.dispatchMessagesNative(); // status up2date + } + requestFocusImpl(true); + display.dispatchMessagesNative(); // status up2date + } + } + } + } finally { + windowLock.unlock(); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener + } + } + + public void setUndecorated(boolean value) { + if(isValid()) { + runOnEDTIfAvail(true, new DecorationActionImpl(value)); + } + } + + public boolean isUndecorated() { + return 0 != parentWindowHandle || undecorated || fullscreen ; + } + + public void requestFocus() { + enqueueRequestFocus(true); + } + + public boolean hasFocus() { + return hasFocus; + } + + public Insets getInsets() { + return new Insets(0,0,0,0); + } + + public final int getWidth() { + return width; + } + + public final int getHeight() { + return height; + } + + public final int getX() { + return x; + } + + public final int getY() { + return y; + } + + public final boolean isVisible() { + return visible; + } + + public final boolean isFullscreen() { + return fullscreen; + } + + + //---------------------------------------------------------------------- + // Window + // + + /** + * If the implementation is capable of detecting a device change + * return true and clear the status/reason of the change. + */ + public boolean hasDeviceChanged() { + return false; + } + + public LifecycleHook getLifecycleHook() { + return lifecycleHook; + } + + public LifecycleHook setLifecycleHook(LifecycleHook hook) { + LifecycleHook old = lifecycleHook; + lifecycleHook = hook; + return old; + } + + /** If this Window actually wraps one from another toolkit such as + the AWT, this will return a non-null value. */ + public Object getWrappedWindow() { + return null; + } + + /** + * If set to true, the default value, this NEWT Window implementation will + * handle the destruction (ie {@link #destroy()} call) within {@link #windowDestroyNotify()} implementation.<br> + * If set to false, it's up to the caller/owner to handle destruction within {@link #windowDestroyNotify()}. + */ + public void setHandleDestroyNotify(boolean b) { + handleDestroyNotify = b; + } + + //---------------------------------------------------------------------- + // WindowImpl + // + + protected final long getParentWindowHandle() { + return parentWindowHandle; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append(getClass().getName()+"[Config "+config+ + "\n, "+screen+ + "\n, ParentWindow "+parentWindow+ + "\n, ParentWindowHandle "+toHexString(parentWindowHandle)+ + "\n, WindowHandle "+toHexString(getWindowHandle())+ + "\n, SurfaceHandle "+toHexString(getSurfaceHandle())+ " (lockedExt window "+isWindowLockedByOtherThread()+", surface "+isSurfaceLockedByOtherThread()+")"+ + "\n, Pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + "\n, Visible "+isVisible()+ + "\n, Undecorated "+undecorated+ + "\n, Fullscreen "+fullscreen+ + "\n, WrappedWindow "+getWrappedWindow()+ + "\n, ChildWindows "+childWindows.size()); + + sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedListeners.size()+" ["); + for (int i = 0; i < surfaceUpdatedListeners.size(); i++ ) { + sb.append(surfaceUpdatedListeners.get(i)+", "); + } + sb.append("], WindowListeners num "+windowListeners.size()+" ["); + for (int i = 0; i < windowListeners.size(); i++ ) { + sb.append(windowListeners.get(i)+", "); + } + sb.append("], MouseListeners num "+mouseListeners.size()+" ["); + for (int i = 0; i < mouseListeners.size(); i++ ) { + sb.append(mouseListeners.get(i)+", "); + } + sb.append("], KeyListeners num "+keyListeners.size()+" ["); + for (int i = 0; i < keyListeners.size(); i++ ) { + sb.append(keyListeners.get(i)+", "); + } + sb.append("] ]"); + return sb.toString(); + } + + protected final void setWindowHandle(long handle) { + windowHandle = handle; + } + + public void runOnEDTIfAvail(boolean wait, final Runnable task) { + Screen scrn = getScreen(); + if(null==scrn) { + throw new RuntimeException("Null screen of inner class: "+this); + } + DisplayImpl d = (DisplayImpl) scrn.getDisplay(); + d.runOnEDTIfAvail(wait, task); + } + + private class RequestFocusAction implements Runnable { + public final void run() { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.RequestFocusAction: ("+getThreadName()+"): "+hasFocus+" -> true - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); + } + WindowImpl.this.requestFocusImpl(false); + } + } + + protected void enqueueRequestFocus(boolean wait) { + runOnEDTIfAvail(wait, requestFocusAction); + } + + /** + * May set to a {@link FocusRunnable}, {@link FocusRunnable#run()} before Newt requests the native focus. + * This allows notifying a covered window toolkit like AWT that the focus is requested, + * hence focus traversal can be made transparent. + */ + public void setFocusAction(FocusRunnable focusAction) { + this.focusAction = focusAction; + } + protected boolean focusAction() { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.focusAction() START - "+getThreadName()+", focusAction: "+focusAction+" - windowHandle "+toHexString(getWindowHandle())); + } + boolean res; + if(null!=focusAction) { + res = focusAction.run(); + } else { + res = false; + } + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.focusAction() END - "+getThreadName()+", focusAction: "+focusAction+" - windowHandle "+toHexString(getWindowHandle())+", res: "+res); + } + return res; + } + + private class SetPositionActionImpl implements Runnable { + int x, y; + + private SetPositionActionImpl(int x, int y) { + this.x = x; + this.y = y; + } + public final void run() { + windowLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window setPosition: "+WindowImpl.this.x+"/"+WindowImpl.this.y+" -> "+x+"/"+y+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)); + } + if ( WindowImpl.this.x != x || WindowImpl.this.y != y ) { + if(!fullscreen) { + if(0!=windowHandle) { + // this.x/this.y will be set by windowChanged, called by the native implementation + reconfigureWindowImpl(x, y, -1, -1, false, 0, 0); + } else { + WindowImpl.this.x = x; + WindowImpl.this.y = y; + } + } + } + } finally { + windowLock.unlock(); + } + } + } + + public void setPosition(int x, int y) { + if(isValid()) { + runOnEDTIfAvail(true, new SetPositionActionImpl(x, y)); + } + } + + private class FullScreenActionImpl implements Runnable { + boolean fullscreen; + + private FullScreenActionImpl (boolean fullscreen) { + this.fullscreen = fullscreen; + } + + public final void run() { + windowLock.lock(); + try { + if(isNativeValid() && WindowImpl.this.fullscreen != fullscreen) { + int x,y,w,h; + WindowImpl.this.fullscreen = fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + nfs_width = width; + nfs_height = height; + nfs_x = x; + nfs_y = y; + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()+", "+screen); + } + + DisplayImpl display = (DisplayImpl) screen.getDisplay(); + display.dispatchMessagesNative(); // status up2date + boolean wasVisible = isVisible(); + setVisibleImpl(false, x, y, width, height); + WindowImpl.this.waitForVisible(false, true); + display.dispatchMessagesNative(); // status up2date + + // write back mirrored values, to be able to detect satisfaction + WindowImpl.this.x = x; + WindowImpl.this.y = y; + WindowImpl.this.width = w; + WindowImpl.this.height = h; + reconfigureWindowImpl(x, y, w, h, getParentWindowHandle()!=0, fullscreen?1:-1, isUndecorated()?-1:1); + display.dispatchMessagesNative(); // status up2date + + if(wasVisible) { + setVisibleImpl(true, x, y, width, height); + boolean ok = WindowImpl.this.waitForVisible(true, true, Screen.SCREEN_MODE_CHANGE_TIMEOUT); + display.dispatchMessagesNative(); // status up2date + if( ok && + ( WindowImpl.this.x != x || + WindowImpl.this.y != y || + WindowImpl.this.width != w || + WindowImpl.this.height != h ) ) + { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("Window fs (reconfig): "+x+"/"+y+" "+w+"x"+h+", "+screen); + } + // reset pos/size .. due to some native impl flakyness + reconfigureWindowImpl(x, y, width, height, false, 0, 0); + display.dispatchMessagesNative(); // status up2date + } + requestFocusImpl(true); + display.dispatchMessagesNative(); // status up2date + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("Window fs done"); + } + } + } + } finally { + windowLock.unlock(); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(isValid()) { + runOnEDTIfAvail(true, new FullScreenActionImpl(fullscreen)); + } + return this.fullscreen; + } + + private class ScreenModeListenerImpl implements ScreenModeListener { + boolean animatorPaused = false; + + public void screenModeChangeNotify(ScreenMode sm) { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("Window.screenModeChangeNotify: "+sm); + } + + if(null!=lifecycleHook) { + animatorPaused = lifecycleHook.pauseRenderingAction(); + } + } + + public void screenModeChanged(ScreenMode sm, boolean success) { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("Window.screenModeChanged: "+sm+", success: "+success); + } + + if(success) { + DimensionReadOnly screenSize = sm.getMonitorMode().getSurfaceSize().getResolution(); + if ( getHeight() > screenSize.getHeight() || + getWidth() > screenSize.getWidth() ) { + setSize(screenSize.getWidth(), screenSize.getHeight()); + } + } + + if(animatorPaused) { + lifecycleHook.resumeRenderingAction(); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener + } + } + + //---------------------------------------------------------------------- + // Child Window Management + // + + public final void removeChild(NativeWindow win) { + synchronized(childWindowsLock) { + childWindows.remove(win); + } + } + + public final void addChild(NativeWindow win) { + if (win == null) { + return; + } + synchronized(childWindowsLock) { + childWindows.add(win); + } + } + + //---------------------------------------------------------------------- + // Generic Event Support + // + private void doEvent(boolean enqueue, boolean wait, com.jogamp.newt.event.NEWTEvent event) { + boolean done = false; + + if(!enqueue) { + done = consumeEvent(event); + wait = done; // don't wait if event can't be consumed now + } + + if(!done) { + enqueueEvent(wait, event); + } + } + + public void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) { + if(isValid()) { + ((DisplayImpl)getScreen().getDisplay()).enqueueEvent(wait, event); + } + } + + public boolean consumeEvent(NEWTEvent e) { + switch(e.getEventType()) { + // special repaint treatment + case WindowEvent.EVENT_WINDOW_REPAINT: + // queue repaint event in case window is locked, ie in operation + if( isWindowLocked() ) { + // make sure only one repaint event is queued + if(!repaintQueued) { + repaintQueued=true; + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.consumeEvent: queued "+e); + // Exception ee = new Exception("Window.windowRepaint: "+e); + // ee.printStackTrace(); + } + return false; + } + return true; + } + repaintQueued=false; // no repaint event queued + break; + + // common treatment + case WindowEvent.EVENT_WINDOW_RESIZED: + // queue event in case window is locked, ie in operation + if( isWindowLocked() ) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.consumeEvent: queued "+e); + // Exception ee = new Exception("Window.windowRepaint: "+e); + // ee.printStackTrace(); + } + return false; + } + break; + default: + break; + } + if(e instanceof WindowEvent) { + consumeWindowEvent((WindowEvent)e); + } else if(e instanceof KeyEvent) { + consumeKeyEvent((KeyEvent)e); + } else if(e instanceof MouseEvent) { + consumeMouseEvent((MouseEvent)e); + } else { + throw new NativeWindowException("Unexpected NEWTEvent type " + e); + } + return true; + } + + // + // SurfaceUpdatedListener Support + // + + public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { + addSurfaceUpdatedListener(-1, l); + } + + public void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) + throws IndexOutOfBoundsException + { + if(l == null) { + return; + } + synchronized(surfaceUpdatedListenersLock) { + if(0>index) { + index = surfaceUpdatedListeners.size(); + } + surfaceUpdatedListeners.add(index, l); + } + } + + public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { + if (l == null) { + return; + } + synchronized(surfaceUpdatedListenersLock) { + surfaceUpdatedListeners.remove(l); + } + } + + public void removeAllSurfaceUpdatedListener() { + synchronized(surfaceUpdatedListenersLock) { + surfaceUpdatedListeners = new ArrayList(); + } + } + + public SurfaceUpdatedListener getSurfaceUpdatedListener(int index) { + synchronized(surfaceUpdatedListenersLock) { + if(0>index) { + index = surfaceUpdatedListeners.size()-1; + } + return (SurfaceUpdatedListener) surfaceUpdatedListeners.get(index); + } + } + + public SurfaceUpdatedListener[] getSurfaceUpdatedListeners() { + synchronized(surfaceUpdatedListenersLock) { + return (SurfaceUpdatedListener[]) surfaceUpdatedListeners.toArray(); + } + } + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { + synchronized(surfaceUpdatedListenersLock) { + for(int i = 0; i < surfaceUpdatedListeners.size(); i++ ) { + SurfaceUpdatedListener l = (SurfaceUpdatedListener) surfaceUpdatedListeners.get(i); + l.surfaceUpdated(updater, ns, when); + } + } + } + + // + // MouseListener/Event Support + // + public void sendMouseEvent(int eventType, int modifiers, + int x, int y, int button, int rotation) { + doMouseEvent(false, false, eventType, modifiers, x, y, button, rotation); + } + public void enqueueMouseEvent(boolean wait, int eventType, int modifiers, + int x, int y, int button, int rotation) { + doMouseEvent(true, wait, eventType, modifiers, x, y, button, rotation); + } + private void doMouseEvent(boolean enqueue, boolean wait, int eventType, int modifiers, + int x, int y, int button, int rotation) { + if(x<0||y<0||x>=width||y>=height) { + return; // .. invalid .. + } + if(DEBUG_MOUSE_EVENT) { + System.err.println("doMouseEvent: enqueue"+enqueue+", wait "+wait+", "+MouseEvent.getEventTypeString(eventType)+ + ", mod "+modifiers+", pos "+x+"/"+y+", button "+button); + } + if(button<0||button>MouseEvent.BUTTON_NUMBER) { + throw new NativeWindowException("Invalid mouse button number" + button); + } + long when = System.currentTimeMillis(); + MouseEvent eClicked = null; + MouseEvent e = null; + + if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) { + if(when-lastMousePressed<MouseEvent.getClickTimeout()) { + lastMouseClickCount++; + } else { + lastMouseClickCount=1; + } + lastMousePressed=when; + mouseButtonPressed=button; + e = new MouseEvent(eventType, this, when, + modifiers, x, y, lastMouseClickCount, button, 0); + } else if(MouseEvent.EVENT_MOUSE_RELEASED==eventType) { + e = new MouseEvent(eventType, this, when, + modifiers, x, y, lastMouseClickCount, button, 0); + if(when-lastMousePressed<MouseEvent.getClickTimeout()) { + eClicked = new MouseEvent(MouseEvent.EVENT_MOUSE_CLICKED, this, when, + modifiers, x, y, lastMouseClickCount, button, 0); + } else { + lastMouseClickCount=0; + lastMousePressed=0; + } + mouseButtonPressed=0; + } else if(MouseEvent.EVENT_MOUSE_MOVED==eventType) { + if (mouseButtonPressed>0) { + e = new MouseEvent(MouseEvent.EVENT_MOUSE_DRAGGED, this, when, + modifiers, x, y, 1, mouseButtonPressed, 0); + } else { + e = new MouseEvent(eventType, this, when, + modifiers, x, y, 0, button, 0); + } + } else if(MouseEvent.EVENT_MOUSE_WHEEL_MOVED==eventType) { + e = new MouseEvent(eventType, this, when, modifiers, x, y, 0, button, rotation); + } else { + e = new MouseEvent(eventType, this, when, modifiers, x, y, 0, button, 0); + } + doEvent(enqueue, wait, e); + if(null!=eClicked) { + if(DEBUG_MOUSE_EVENT) { + System.err.println("doMouseEvent: synthesized MOUSE_CLICKED event"); + } + doEvent(enqueue, wait, eClicked); + } + } + + + public void addMouseListener(MouseListener l) { + addMouseListener(-1, l); + } + + public void addMouseListener(int index, MouseListener l) { + if(l == null) { + return; + } + ArrayList clonedListeners = (ArrayList) mouseListeners.clone(); + if(0>index) { + index = clonedListeners.size(); + } + clonedListeners.add(index, l); + mouseListeners = clonedListeners; + } + + public void removeMouseListener(MouseListener l) { + if (l == null) { + return; + } + ArrayList clonedListeners = (ArrayList) mouseListeners.clone(); + clonedListeners.remove(l); + mouseListeners = clonedListeners; + } + + public MouseListener getMouseListener(int index) { + ArrayList clonedListeners = (ArrayList) mouseListeners.clone(); + if(0>index) { + index = clonedListeners.size()-1; + } + return (MouseListener) clonedListeners.get(index); + } + + public MouseListener[] getMouseListeners() { + return (MouseListener[]) mouseListeners.toArray(); + } + + protected void consumeMouseEvent(MouseEvent e) { + if(DEBUG_MOUSE_EVENT) { + System.err.println("consumeMouseEvent: event: "+e); + } + + for(int i = 0; i < mouseListeners.size(); i++ ) { + MouseListener l = (MouseListener) mouseListeners.get(i); + switch(e.getEventType()) { + case MouseEvent.EVENT_MOUSE_CLICKED: + l.mouseClicked(e); + break; + case MouseEvent.EVENT_MOUSE_ENTERED: + l.mouseEntered(e); + break; + case MouseEvent.EVENT_MOUSE_EXITED: + l.mouseExited(e); + break; + case MouseEvent.EVENT_MOUSE_PRESSED: + l.mousePressed(e); + break; + case MouseEvent.EVENT_MOUSE_RELEASED: + l.mouseReleased(e); + break; + case MouseEvent.EVENT_MOUSE_MOVED: + l.mouseMoved(e); + break; + case MouseEvent.EVENT_MOUSE_DRAGGED: + l.mouseDragged(e); + break; + case MouseEvent.EVENT_MOUSE_WHEEL_MOVED: + l.mouseWheelMoved(e); + break; + default: + throw new NativeWindowException("Unexpected mouse event type " + e.getEventType()); + } + } + } + + // + // KeyListener/Event Support + // + + public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + consumeKeyEvent(new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers, keyCode, keyChar) ); + } + + public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) { + enqueueEvent(wait, new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers, keyCode, keyChar) ); + } + + public void addKeyListener(KeyListener l) { + addKeyListener(-1, l); + } + + public void addKeyListener(int index, KeyListener l) { + if(l == null) { + return; + } + ArrayList clonedListeners = (ArrayList) keyListeners.clone(); + if(0>index) { + index = clonedListeners.size(); + } + clonedListeners.add(index, l); + keyListeners = clonedListeners; + } + + public void removeKeyListener(KeyListener l) { + if (l == null) { + return; + } + ArrayList clonedListeners = (ArrayList) keyListeners.clone(); + clonedListeners.remove(l); + keyListeners = clonedListeners; + } + + public KeyListener getKeyListener(int index) { + ArrayList clonedListeners = (ArrayList) keyListeners.clone(); + if(0>index) { + index = clonedListeners.size()-1; + } + return (KeyListener) clonedListeners.get(index); + } + + public KeyListener[] getKeyListeners() { + return (KeyListener[]) keyListeners.toArray(); + } + + protected void consumeKeyEvent(KeyEvent e) { + if(DEBUG_KEY_EVENT) { + System.err.println("consumeKeyEvent: "+e); + } + for(int i = 0; i < keyListeners.size(); i++ ) { + KeyListener l = (KeyListener) keyListeners.get(i); + switch(e.getEventType()) { + case KeyEvent.EVENT_KEY_PRESSED: + l.keyPressed(e); + break; + case KeyEvent.EVENT_KEY_RELEASED: + l.keyReleased(e); + break; + case KeyEvent.EVENT_KEY_TYPED: + l.keyTyped(e); + break; + default: + throw new NativeWindowException("Unexpected key event type " + e.getEventType()); + } + } + } + + // + // WindowListener/Event Support + // + public void sendWindowEvent(int eventType) { + consumeWindowEvent( new WindowEvent(eventType, this, System.currentTimeMillis()) ); + } + + public void enqueueWindowEvent(boolean wait, int eventType) { + enqueueEvent( wait, new WindowEvent(eventType, this, System.currentTimeMillis()) ); + } + + public void addWindowListener(WindowListener l) { + addWindowListener(-1, l); + } + + public void addWindowListener(int index, WindowListener l) + throws IndexOutOfBoundsException + { + if(l == null) { + return; + } + ArrayList clonedListeners = (ArrayList) windowListeners.clone(); + if(0>index) { + index = clonedListeners.size(); + } + clonedListeners.add(index, l); + windowListeners = clonedListeners; + } + + public final void removeWindowListener(WindowListener l) { + if (l == null) { + return; + } + ArrayList clonedListeners = (ArrayList) windowListeners.clone(); + clonedListeners.remove(l); + windowListeners = clonedListeners; + } + + public WindowListener getWindowListener(int index) { + ArrayList clonedListeners = (ArrayList) windowListeners.clone(); + if(0>index) { + index = clonedListeners.size()-1; + } + return (WindowListener) clonedListeners.get(index); + } + + public WindowListener[] getWindowListeners() { + return (WindowListener[]) windowListeners.toArray(); + } + + protected void consumeWindowEvent(WindowEvent e) { + if(DEBUG_WINDOW_EVENT) { + System.err.println("consumeWindowEvent: "+e+", visible "+isVisible()+" "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight()); + } + for(int i = 0; i < windowListeners.size(); i++ ) { + WindowListener l = (WindowListener) windowListeners.get(i); + switch(e.getEventType()) { + case WindowEvent.EVENT_WINDOW_RESIZED: + l.windowResized(e); + break; + case WindowEvent.EVENT_WINDOW_MOVED: + l.windowMoved(e); + break; + case WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY: + l.windowDestroyNotify(e); + break; + case WindowEvent.EVENT_WINDOW_DESTROYED: + l.windowDestroyed(e); + break; + case WindowEvent.EVENT_WINDOW_GAINED_FOCUS: + l.windowGainedFocus(e); + break; + case WindowEvent.EVENT_WINDOW_LOST_FOCUS: + l.windowLostFocus(e); + break; + case WindowEvent.EVENT_WINDOW_REPAINT: + l.windowRepaint((WindowUpdateEvent)e); + break; + default: + throw + new NativeWindowException("Unexpected window event type " + + e.getEventType()); + } + } + } + + /** + * @param focusGained + */ + protected void focusChanged(boolean focusGained) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.focusChanged: ("+getThreadName()+"): "+this.hasFocus+" -> "+focusGained+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); + } + hasFocus = focusGained; + if (focusGained) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } else { + sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); + } + } + + protected void visibleChanged(boolean visible) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.visibleChanged ("+getThreadName()+"): "+this.visible+" -> "+visible+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); + } + this.visible = visible ; + } + + private boolean waitForVisible(boolean visible, boolean failFast) { + return waitForVisible(visible, failFast, TIMEOUT_NATIVEWINDOW); + } + + private boolean waitForVisible(boolean visible, boolean failFast, long timeOut) { + DisplayImpl display = (DisplayImpl) screen.getDisplay(); + for(long sleep = timeOut; 0<sleep && this.visible != visible; sleep-=10 ) { + display.dispatchMessagesNative(); // status up2date + try { + Thread.sleep(10); + } catch (InterruptedException ie) {} + sleep -=10; + } + if(this.visible != visible) { + if(failFast) { + throw new NativeWindowException("Visibility not reached as requested within "+timeOut+"ms : requested "+visible+", is "+this.visible); + } else if (DEBUG_IMPLEMENTATION) { + System.err.println("******* Visibility not reached as requested within "+timeOut+"ms : requested "+visible+", is "+this.visible); + } + } + return this.visible == visible; + } + + protected void sizeChanged(int newWidth, int newHeight, boolean force) { + if(force || width != newWidth || height != newHeight) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.sizeChanged: ("+getThreadName()+"): force "+force+", "+width+"x"+height+" -> "+newWidth+"x"+newHeight+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); + } + width = newWidth; + height = newHeight; + if(isNativeValid()) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + } + } + + protected void positionChanged(int newX, int newY) { + if( 0==parentWindowHandle && ( x != newX || y != newY ) ) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.positionChanged: ("+getThreadName()+"): "+x+"/"+y+" -> "+newX+"/"+newY+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); + } + x = newX; + y = newY; + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + } + + protected void windowDestroyNotify() { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.windowDestroyNotify START "+getThreadName()); + } + + // send synced destroy notifications + enqueueWindowEvent(true, WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); + + if(handleDestroyNotify && DISPOSE_ON_CLOSE == defaultCloseOperation && isValid()) { + destroy(); + } + + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.windowDestroyeNotify END "+getThreadName()); + } + } + + public void windowRepaint(int x, int y, int width, int height) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.windowRepaint "+getThreadName()+" - "+x+"/"+y+" "+width+"x"+height); + // Exception ee = new Exception("Window.windowRepaint: "+" - "+x+"/"+y+" "+width+"x"+height); + // ee.printStackTrace(); + } + + if(isNativeValid()) { + if(0>width) { + width=this.width; + } + if(0>height) { + height=this.height; + } + + NEWTEvent e = new WindowUpdateEvent(WindowEvent.EVENT_WINDOW_REPAINT, this, System.currentTimeMillis(), + new Rectangle(x, y, width, height)); + doEvent(false, false, e); + } + } + + // + // Reflection helper .. + // + + private static Class[] getCustomConstructorArgumentTypes(Class windowClass) { + Class[] argTypes = null; + try { + Method m = windowClass.getDeclaredMethod("getCustomConstructorArgumentTypes", new Class[] {}); + argTypes = (Class[]) m.invoke(null, (Object[])null); + } catch (Throwable t) {} + return argTypes; + } + + private static int verifyConstructorArgumentTypes(Class[] types, Object[] args) { + if(types.length != args.length) { + return -1; + } + for(int i=0; i<args.length; i++) { + if(!types[i].isInstance(args[i])) { + return i; + } + } + return args.length; + } + + private static String getArgsStrList(Object[] args) { + StringBuilder sb = new StringBuilder(); + for(int i=0; i<args.length; i++) { + sb.append(args[i].getClass()); + if(i<args.length) { + sb.append(", "); + } + } + return sb.toString(); + } + + private static String getTypeStrList(Class[] types) { + StringBuilder sb = new StringBuilder(); + for(int i=0; i<types.length; i++) { + sb.append(types[i]); + if(i<types.length) { + sb.append(", "); + } + } + return sb.toString(); + } + + protected final void shouldNotCallThis() { + throw new NativeWindowException("Should not call this"); + } + + public static String getThreadName() { + return Display.getThreadName(); + } + + public static String toHexString(int hex) { + return Display.toHexString(hex); + } + + public static String toHexString(long hex) { + return Display.toHexString(hex); + } +} + diff --git a/src/newt/classes/jogamp/newt/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/awt/AWTCanvas.java new file mode 100644 index 000000000..01e813449 --- /dev/null +++ b/src/newt/classes/jogamp/newt/awt/AWTCanvas.java @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.awt; + +import java.awt.Canvas; +import java.awt.GraphicsDevice; +import java.awt.GraphicsConfiguration; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; +import com.jogamp.newt.Window; + +public class AWTCanvas extends Canvas { + private GraphicsDevice device; + private GraphicsConfiguration chosen; + private AWTGraphicsConfiguration awtConfig; + + private CapabilitiesChooser chooser=null; + private CapabilitiesImmutable capabilities; + + private boolean displayConfigChanged=false; + + public AWTCanvas(CapabilitiesImmutable capabilities, CapabilitiesChooser chooser) { + super(); + + if(null==capabilities) { + throw new NativeWindowException("Capabilities null"); + } + this.capabilities=capabilities; + this.chooser=chooser; + } + + public AWTGraphicsConfiguration getAWTGraphicsConfiguration() { + return awtConfig; + } + + public boolean hasDeviceChanged() { + boolean res = displayConfigChanged; + displayConfigChanged=false; + return res; + } + + public void addNotify() { + + /** + * 'super.addNotify()' determines the GraphicsConfiguration, + * while calling this class's overriden 'getGraphicsConfiguration()' method + * after which it creates the native peer. + * Hence we have to set the 'awtConfig' before since it's GraphicsConfiguration + * is being used in getGraphicsConfiguration(). + * This code order also allows recreation, ie re-adding the GLCanvas. + */ + awtConfig = chooseGraphicsConfiguration(capabilities, capabilities, chooser, device); + if(Window.DEBUG_IMPLEMENTATION) { + Exception e = new Exception("Info: Created Config: "+awtConfig); + e.printStackTrace(); + } + if(null==awtConfig) { + throw new NativeWindowException("Error: NULL AWTGraphicsConfiguration"); + } + chosen = awtConfig.getGraphicsConfiguration(); + + // before native peer is valid: X11 + disableBackgroundErase(); + + // issues getGraphicsConfiguration() and creates the native peer + super.addNotify(); + + // after native peer is valid: Windows + disableBackgroundErase(); + + GraphicsConfiguration gc = super.getGraphicsConfiguration(); + if(null!=gc) { + device = gc.getDevice(); + } + } + + public void removeNotify() { + try { + dispose(); + } finally { + super.removeNotify(); + } + } + + private void dispose() { + if(null != awtConfig) { + AbstractGraphicsDevice adevice = awtConfig.getNativeGraphicsConfiguration().getScreen().getDevice(); + String adeviceMsg=null; + if(Window.DEBUG_IMPLEMENTATION) { + adeviceMsg = adevice.toString(); + } + boolean closed = adevice.close(); + if(Window.DEBUG_IMPLEMENTATION) { + System.err.println("AWTCanvas.dispose(): closed GraphicsDevice: "+adeviceMsg+", result: "+closed); + } + } + } + + /** + * Overridden to choose a GraphicsConfiguration on a parent container's + * GraphicsDevice because both devices + */ + public GraphicsConfiguration getGraphicsConfiguration() { + /* + * Workaround for problems with Xinerama and java.awt.Component.checkGD + * when adding to a container on a different graphics device than the + * one that this Canvas is associated with. + * + * GC will be null unless: + * - A native peer has assigned it. This means we have a native + * peer, and are already comitted to a graphics configuration. + * - This canvas has been added to a component hierarchy and has + * an ancestor with a non-null GC, but the native peer has not + * yet been created. This means we can still choose the GC on + * all platforms since the peer hasn't been created. + */ + final GraphicsConfiguration gc = super.getGraphicsConfiguration(); + /* + * chosen is only non-null on platforms where the GLDrawableFactory + * returns a non-null GraphicsConfiguration (in the GLCanvas + * constructor). + * + * if gc is from this Canvas' native peer then it should equal chosen, + * otherwise it is from an ancestor component that this Canvas is being + * added to, and we go into this block. + */ + if (gc != null && chosen != null && !chosen.equals(gc)) { + /* + * Check for compatibility with gc. If they differ by only the + * device then return a new GCconfig with the super-class' GDevice + * (and presumably the same visual ID in Xinerama). + * + */ + if (!chosen.getDevice().getIDstring().equals(gc.getDevice().getIDstring())) { + /* + * Here we select a GraphicsConfiguration on the alternate + * device that is presumably identical to the chosen + * configuration, but on the other device. + * + * Should really check to ensure that we select a configuration + * with the same X visual ID for Xinerama screens, otherwise the + * GLDrawable may have the wrong visual ID (I don't think this + * ever gets updated). May need to add a method to + * X11GLDrawableFactory to do this in a platform specific + * manner. + * + * However, on platforms where we can actually get into this + * block, both devices should have the same visual list, and the + * same configuration should be selected here. + */ + AWTGraphicsConfiguration config = chooseGraphicsConfiguration( + awtConfig.getChosenCapabilities(), awtConfig.getRequestedCapabilities(), chooser, gc.getDevice()); + final GraphicsConfiguration compatible = (null!=config)?config.getGraphicsConfiguration():null; + if(Window.DEBUG_IMPLEMENTATION) { + Exception e = new Exception("Info: Call Stack: "+Thread.currentThread().getName()); + e.printStackTrace(); + System.err.println("!!! Created Config (n): HAVE GC "+chosen); + System.err.println("!!! Created Config (n): THIS GC "+gc); + System.err.println("!!! Created Config (n): Choosen GC "+compatible); + System.err.println("!!! Created Config (n): HAVE CF "+awtConfig); + System.err.println("!!! Created Config (n): Choosen CF "+config); + System.err.println("!!! Created Config (n): EQUALS CAPS "+config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities())); + } + + if (compatible != null) { + /* + * Save the new GC for equals test above, and to return to + * any outside callers of this method. + */ + chosen = compatible; + if( !config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities())) { + displayConfigChanged=true; + } + awtConfig = config; + } + } + + /* + * If a compatible GC was not found in the block above, this will + * return the GC that was selected in the constructor (and might + * cause an exception in Component.checkGD when adding to a + * container, but in this case that would be the desired behavior). + * + */ + return chosen; + } else if (gc == null) { + /* + * The GC is null, which means we have no native peer, and are not + * part of a (realized) component hierarchy. So we return the + * desired visual that was selected in the constructor (possibly + * null). + */ + return chosen; + } + + /* + * Otherwise we have not explicitly selected a GC in the constructor, so + * just return what Canvas would have. + */ + return gc; + } + + private static AWTGraphicsConfiguration chooseGraphicsConfiguration(CapabilitiesImmutable capsChosen, + CapabilitiesImmutable capsRequested, + CapabilitiesChooser chooser, + GraphicsDevice device) { + AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(device, AbstractGraphicsDevice.DEFAULT_UNIT); + AWTGraphicsConfiguration config = (AWTGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capsChosen, + capsRequested, + chooser, aScreen); + if (config == null) { + throw new NativeWindowException("Error: Couldn't fetch AWTGraphicsConfiguration"); + } + + return config; + } + + // Disables the AWT's erasing of this Canvas's background on Windows + // in Java SE 6. This internal API is not available in previous + // releases, but the system property + // -Dsun.awt.noerasebackground=true can be specified to get similar + // results globally in previous releases. + private static boolean disableBackgroundEraseInitialized; + private static Method disableBackgroundEraseMethod; + private void disableBackgroundErase() { + if (!disableBackgroundEraseInitialized) { + try { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + Class clazz = getToolkit().getClass(); + while (clazz != null && disableBackgroundEraseMethod == null) { + try { + disableBackgroundEraseMethod = + clazz.getDeclaredMethod("disableBackgroundErase", + new Class[] { Canvas.class }); + disableBackgroundEraseMethod.setAccessible(true); + } catch (Exception e) { + clazz = clazz.getSuperclass(); + } + } + } catch (Exception e) { + } + return null; + } + }); + } catch (Exception e) { + } + disableBackgroundEraseInitialized = true; + if(Window.DEBUG_IMPLEMENTATION) { + System.err.println("AWTCanvas: TK disableBackgroundErase method found: "+ + (null!=disableBackgroundEraseMethod)); + } + } + if (disableBackgroundEraseMethod != null) { + Throwable t=null; + try { + disableBackgroundEraseMethod.invoke(getToolkit(), new Object[] { this }); + } catch (Exception e) { + // FIXME: workaround for 6504460 (incorrect backport of 6333613 in 5.0u10) + // throw new GLException(e); + t = e; + } + if(Window.DEBUG_IMPLEMENTATION) { + System.err.println("AWTCanvas: TK disableBackgroundErase error: "+t); + } + } + } +} diff --git a/src/newt/classes/jogamp/newt/awt/AWTDisplay.java b/src/newt/classes/jogamp/newt/awt/AWTDisplay.java new file mode 100644 index 000000000..4c864c111 --- /dev/null +++ b/src/newt/classes/jogamp/newt/awt/AWTDisplay.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.awt; + +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import com.jogamp.newt.NewtFactory; +import jogamp.newt.DisplayImpl; + +public class AWTDisplay extends DisplayImpl { + public AWTDisplay() { + } + + protected void createNativeImpl() { + aDevice = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(null, AbstractGraphicsDevice.DEFAULT_UNIT); // default + } + + protected void setAWTGraphicsDevice(AWTGraphicsDevice d) { + aDevice = d; + } + + protected void closeNativeImpl() { } + + @Override + protected void createEDTUtil() { + if(NewtFactory.useEDT()) { + edtUtil = AWTEDTUtil.getSingleton(); + if(DEBUG) { + System.err.println("AWTDisplay.createNative("+getFQName()+") Create EDTUtil: "+edtUtil.getClass().getName()); + } + } + } + + protected void dispatchMessagesNative() { /* nop */ } +} + diff --git a/src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java new file mode 100644 index 000000000..7b638af31 --- /dev/null +++ b/src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java @@ -0,0 +1,108 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.newt.awt; + +import java.awt.EventQueue; +import javax.media.nativewindow.NativeWindowException; +import com.jogamp.newt.util.EDTUtil; +import jogamp.newt.Debug; + +public class AWTEDTUtil implements EDTUtil { + public static final boolean DEBUG = Debug.debug("EDT"); + + private static AWTEDTUtil singletonMainThread = new AWTEDTUtil(); // one singleton MainThread + + public static AWTEDTUtil getSingleton() { + return singletonMainThread; + } + + AWTEDTUtil() { + // package private access .. + } + + final public void reset() { + // nop + } + + final public void start() { + // nop + } + + final public boolean isCurrentThreadEDT() { + return EventQueue.isDispatchThread(); + } + + final public boolean isRunning() { + return true; // AWT is always running + } + + final public void invokeStop(Runnable r) { + invokeImpl(true, r, true); + } + + final public void invoke(boolean wait, Runnable r) { + invokeImpl(wait, r, false); + } + + /** + * Public access to provide simple dispatching from other EDTUtil implementations + * @param wait true if invokeLater + * @param r the Runnable action + * @param stop true if EDT shall stop (ignored with AWT) + */ + final public void invokeImpl(boolean wait, Runnable r, boolean stop) { + if(r == null) { + return; + } + + // handover to AWT MainThread .. + try { + if ( isCurrentThreadEDT() ) { + r.run(); + return; + } + if(wait) { + EventQueue.invokeAndWait(r); + } else { + EventQueue.invokeLater(r); + } + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + + final public void waitUntilIdle() { + } + + final public void waitUntilStopped() { + } + +} + + diff --git a/src/newt/classes/jogamp/newt/awt/AWTScreen.java b/src/newt/classes/jogamp/newt/awt/AWTScreen.java new file mode 100644 index 000000000..d05933321 --- /dev/null +++ b/src/newt/classes/jogamp/newt/awt/AWTScreen.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.awt; + +import java.awt.DisplayMode; + +import jogamp.newt.ScreenImpl; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; + +public class AWTScreen extends ScreenImpl { + public AWTScreen() { + } + + protected void createNativeImpl() { + aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); + + final DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); + if(null != mode) { + setScreenSize(mode.getWidth(), mode.getHeight()); + } + } + + protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { + aScreen = s; + } + + // done by AWTWindow .. + protected void setScreenSize(int w, int h) { + super.setScreenSize(w, h); + } + + protected void closeNativeImpl() { } +} diff --git a/src/newt/classes/jogamp/newt/awt/AWTWindow.java b/src/newt/classes/jogamp/newt/awt/AWTWindow.java new file mode 100644 index 000000000..b07a9e313 --- /dev/null +++ b/src/newt/classes/jogamp/newt/awt/AWTWindow.java @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.awt; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.DisplayMode; +import java.awt.Frame; +import java.awt.Insets; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; +import javax.media.nativewindow.util.Point; +import jogamp.newt.WindowImpl; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTMouseAdapter; +import com.jogamp.newt.event.awt.AWTWindowAdapter; + +/** An implementation of the Newt Window class built using the + AWT. This is provided for convenience of porting to platforms + supporting Java SE. */ + +public class AWTWindow extends WindowImpl { + + public AWTWindow() { + this(null); + } + + public static Class[] getCustomConstructorArgumentTypes() { + return new Class[] { Container.class } ; + } + + public AWTWindow(Container container) { + super(); + title = "AWT NewtWindow"; + this.container = container; + if(container instanceof Frame) { + frame = (Frame) container; + } + } + + private boolean owningFrame; + private Container container = null; + private Frame frame = null; // same instance as container, just for impl. convenience + private AWTCanvas canvas; + + protected void requestFocusImpl(boolean reparented) { + container.requestFocus(); + } + + @Override + protected void setTitleImpl(final String title) { + if (frame != null) { + frame.setTitle(title); + } + } + + protected void createNativeImpl() { + if(0!=getParentWindowHandle()) { + throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); + } + + if(null==container) { + frame = new Frame(); + container = frame; + owningFrame=true; + } else { + owningFrame=false; + width = container.getWidth(); + height = container.getHeight(); + x = container.getX(); + y = container.getY(); + } + if(null!=frame) { + frame.setTitle(getTitle()); + } + container.setLayout(new BorderLayout()); + canvas = new AWTCanvas(capsRequested, AWTWindow.this.capabilitiesChooser); + + addWindowListener(new LocalWindowListener()); + + new AWTMouseAdapter(this).addTo(canvas); // fwd all AWT Mouse events to here + new AWTKeyAdapter(this).addTo(canvas); // fwd all AWT Key events to here + + // canvas.addComponentListener(listener); + container.add(canvas, BorderLayout.CENTER); + container.setSize(width, height); + container.setLocation(x, y); + new AWTWindowAdapter(this).addTo(container); // fwd all AWT Window events to here + + if(null!=frame) { + frame.setUndecorated(undecorated||fullscreen); + } + + setWindowHandle(1); // just a marker .. + } + + protected void closeNativeImpl() { + setWindowHandle(0); // just a marker .. + if(null!=container) { + container.setVisible(false); + container.remove(canvas); + container.setEnabled(false); + canvas.setEnabled(false); + } + if(owningFrame && null!=frame) { + frame.dispose(); + owningFrame=false; + frame = null; + } + } + + @Override + public boolean hasDeviceChanged() { + boolean res = canvas.hasDeviceChanged(); + if(res) { + config = canvas.getAWTGraphicsConfiguration(); + if (config == null) { + throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this); + } + updateDeviceData(); + } + return res; + } + + protected void setVisibleImpl(final boolean visible, int x, int y, int width, int height) { + container.setVisible(visible); + + reconfigureWindowImpl(x, y, width, height, false, 0, 0); + config = canvas.getAWTGraphicsConfiguration(); + + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + updateDeviceData(); + visibleChanged(visible); + } + + private void updateDeviceData() { + // propagate new info .. + ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)config.getScreen()); + ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)config.getScreen().getDevice()); + + final DisplayMode mode = ((AWTGraphicsDevice)config.getScreen().getDevice()).getGraphicsDevice().getDisplayMode(); + if(null != mode) { + ((AWTScreen)getScreen()).setScreenSize(mode.getWidth(), mode.getHeight()); + } + + } + + @Override + public javax.media.nativewindow.util.Insets getInsets() { + final int insets[] = new int[] { 0, 0, 0, 0 }; + Insets contInsets = container.getInsets(); + insets[0] = contInsets.top; + insets[1] = contInsets.left; + insets[2] = contInsets.bottom; + insets[3] = contInsets.right; + return new javax.media.nativewindow.util.Insets(insets[0],insets[1],insets[2],insets[3]); + } + + protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, final boolean parentChange, final int fullScreenChange, final int decorationChange) { + if(decorationChange!=0 && null!=frame) { + if(!container.isDisplayable()) { + frame.setUndecorated(isUndecorated()); + } else { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("AWTWindow can't undecorate already created frame"); + } + } + } + int _x=(x>=0)?x:AWTWindow.this.x; + int _y=(x>=0)?y:AWTWindow.this.y; + int _w=(width>0)?width:AWTWindow.this.width; + int _h=(height>0)?height:AWTWindow.this.height; + + container.setLocation(_x, _y); + Insets insets = container.getInsets(); + container.setSize(_w + insets.left + insets.right, + _h + insets.top + insets.bottom); + return true; + } + + protected Point getLocationOnScreenImpl(int x, int y) { + java.awt.Point ap = canvas.getLocationOnScreen(); + ap.translate(x, y); + return new Point((int)(ap.getX()+0.5),(int)(ap.getY()+0.5)); + } + + @Override + public Object getWrappedWindow() { + return canvas; + } + + class LocalWindowListener extends com.jogamp.newt.event.WindowAdapter { + @Override + public void windowMoved(com.jogamp.newt.event.WindowEvent e) { + if(null!=container) { + x = container.getX(); + y = container.getY(); + } + } + @Override + public void windowResized(com.jogamp.newt.event.WindowEvent e) { + if(null!=canvas) { + width = canvas.getWidth(); + height = canvas.getHeight(); + } + } + } +} diff --git a/src/newt/classes/jogamp/newt/awt/opengl/VersionApplet.java b/src/newt/classes/jogamp/newt/awt/opengl/VersionApplet.java new file mode 100644 index 000000000..18524d0ba --- /dev/null +++ b/src/newt/classes/jogamp/newt/awt/opengl/VersionApplet.java @@ -0,0 +1,174 @@ +package jogamp.newt.awt.opengl; + +import java.applet.Applet; +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.TextArea; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import java.util.List; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import javax.media.opengl.GL; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLEventListener; + +import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.os.Platform; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.nativewindow.NativeWindowVersion; +import com.jogamp.newt.NewtVersion; +import com.jogamp.opengl.JoglVersion; + +public class VersionApplet extends Applet { + static { + GLProfile.initSingleton(false); + } + TextArea tareaVersion; + TextArea tareaCaps; + GLCanvas canvas; + + public static void main(String[] args) { + Frame frame = new Frame("JOGL Version Applet"); + frame.setSize(800, 600); + frame.setLayout(new BorderLayout()); + + VersionApplet va = new VersionApplet(); + frame.addWindowListener(new ClosingWindowAdapter(frame, va)); + + va.init(); + frame.add(va, BorderLayout.CENTER); + frame.validate(); + + frame.setVisible(true); + va.start(); + } + + static class ClosingWindowAdapter extends WindowAdapter { + Frame f; + VersionApplet va; + public ClosingWindowAdapter(Frame f, VersionApplet va) { + this.f = f; + this.va = va; + } + public void windowClosing(WindowEvent ev) { + f.setVisible(false); + va.stop(); + va.destroy(); + f.remove(va); + f.dispose(); + System.exit(0); + } + } + + private synchronized void my_init() { + if(null != canvas) { return; } + + GLProfile glp = GLProfile.getDefault(); + GLCapabilities glcaps = new GLCapabilities(glp); + + setLayout(new BorderLayout()); + String s; + + tareaVersion = new TextArea(120, 60); + s = VersionUtil.getPlatformInfo().toString(); + System.err.println(s); + tareaVersion.append(s); + + s = GlueGenVersion.getInstance().toString(); + System.err.println(s); + tareaVersion.append(s); + + s = NativeWindowVersion.getInstance().toString(); + System.err.println(s); + tareaVersion.append(NativeWindowVersion.getInstance().toString()); + + s = JoglVersion.getInstance().toString(); + System.err.println(s); + tareaVersion.append(s); + + s = NewtVersion.getInstance().toString(); + System.err.println(s); + tareaVersion.append(s); + + tareaCaps = new TextArea(120, 20); + GLDrawableFactory factory = GLDrawableFactory.getFactory(glp); + List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null); + for(int i=0; i<availCaps.size(); i++) { + s = ((GLCapabilitiesImmutable) availCaps.get(i)).toString(); + System.err.println(s); + tareaCaps.append(s); + tareaCaps.append(Platform.getNewline()); + } + + Container grid = new Container(); + grid.setLayout(new GridLayout(2, 1)); + grid.add(tareaVersion); + grid.add(tareaCaps); + add(grid, BorderLayout.CENTER); + + canvas = new GLCanvas(glcaps); + canvas.addGLEventListener(new GLInfo()); + canvas.setSize(10, 10); + add(canvas, BorderLayout.SOUTH); + validate(); + } + + private synchronized void my_release() { + if(null!=canvas) { + remove(canvas); + canvas.destroy(); + canvas = null; + remove(tareaVersion); + tareaVersion=null; + } + } + + public void init() { + System.err.println("VersionApplet: init() - begin"); + my_init(); + System.err.println("VersionApplet: init() - end"); + } + + public void start() { + System.err.println("VersionApplet: start() - begin"); + System.err.println("VersionApplet: start() - end"); + } + + public void stop() { + System.err.println("VersionApplet: stop() - begin"); + System.err.println("VersionApplet: stop() - end"); + } + + public void destroy() { + System.err.println("VersionApplet: destroy() - start"); + my_release(); + System.err.println("VersionApplet: destroy() - end"); + } + + class GLInfo implements GLEventListener { + public void init(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + String s = JoglVersion.getGLInfo(gl, null).toString(); + System.err.println(s); + tareaVersion.append(s); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void display(GLAutoDrawable drawable) { + } + + public void dispose(GLAutoDrawable drawable) { + } + } + +} diff --git a/src/newt/classes/jogamp/newt/event/NEWTEventTask.java b/src/newt/classes/jogamp/newt/event/NEWTEventTask.java new file mode 100644 index 000000000..fae6560b4 --- /dev/null +++ b/src/newt/classes/jogamp/newt/event/NEWTEventTask.java @@ -0,0 +1,56 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.newt.event; + +import com.jogamp.newt.event.NEWTEvent; + +/** + * Helper class to provide a NEWTEvent queue implementation with a NEWTEvent wrapper + * which notifies after sending the event for the <code>invokeAndWait()</code> semantics. + */ +public class NEWTEventTask { + NEWTEvent event; + Object notifyObject; + + public NEWTEventTask(NEWTEvent event, Object notifyObject) { + this.event = event ; + this.notifyObject = notifyObject ; + } + + public NEWTEvent get() { return event; } + + public void notifyIssuer() { + if(null != notifyObject) { + synchronized (notifyObject) { + notifyObject.notifyAll(); + } + } + } +} + diff --git a/src/newt/classes/jogamp/newt/intel/gdl/Display.java b/src/newt/classes/jogamp/newt/intel/gdl/Display.java new file mode 100644 index 000000000..b1afdb55e --- /dev/null +++ b/src/newt/classes/jogamp/newt/intel/gdl/Display.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.intel.gdl; + +import jogamp.newt.*; +import javax.media.nativewindow.*; + +public class Display extends jogamp.newt.DisplayImpl { + static int initCounter = 0; + + static { + NEWTJNILibLoader.loadNEWT(); + + if (!Screen.initIDs()) { + throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs"); + } + if (!Window.initIDs()) { + throw new NativeWindowException("Failed to initialize GDL Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public Display() { + } + + protected void createNativeImpl() { + synchronized(Display.class) { + if(0==initCounter) { + displayHandle = CreateDisplay(); + if(0==displayHandle) { + throw new NativeWindowException("Couldn't initialize GDL Display"); + } + } + initCounter++; + } + aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT, displayHandle); + } + + protected void closeNativeImpl() { + if(0==displayHandle) { + throw new NativeWindowException("displayHandle null; initCnt "+initCounter); + } + synchronized(Display.class) { + if(initCounter>0) { + initCounter--; + if(0==initCounter) { + DestroyDisplay(displayHandle); + } + } + } + } + + protected void dispatchMessagesNative() { + if(0!=displayHandle) { + DispatchMessages(displayHandle, focusedWindow); + } + } + + protected void setFocus(Window focus) { + focusedWindow = focus; + } + + private long displayHandle = 0; + private Window focusedWindow = null; + private native long CreateDisplay(); + private native void DestroyDisplay(long displayHandle); + private native void DispatchMessages(long displayHandle, Window focusedWindow); +} + diff --git a/src/newt/classes/jogamp/newt/intel/gdl/Screen.java b/src/newt/classes/jogamp/newt/intel/gdl/Screen.java new file mode 100644 index 000000000..b351fe6a9 --- /dev/null +++ b/src/newt/classes/jogamp/newt/intel/gdl/Screen.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.intel.gdl; + +import jogamp.newt.*; +import javax.media.nativewindow.*; + +public class Screen extends jogamp.newt.ScreenImpl { + + static { + Display.initSingleton(); + } + + public Screen() { + } + + protected void createNativeImpl() { + AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice(); + GetScreenInfo(adevice.getHandle(), screen_idx); + aScreen = new DefaultGraphicsScreen(adevice, screen_idx); + } + + protected void closeNativeImpl() { } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native void GetScreenInfo(long displayHandle, int screen_idx); + + // called by GetScreenInfo() .. + private void screenCreated(int width, int height) { + setScreenSize(width, height); + } +} + diff --git a/src/newt/classes/jogamp/newt/intel/gdl/Window.java b/src/newt/classes/jogamp/newt/intel/gdl/Window.java new file mode 100644 index 000000000..d6003beae --- /dev/null +++ b/src/newt/classes/jogamp/newt/intel/gdl/Window.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.intel.gdl; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Point; + +public class Window extends jogamp.newt.WindowImpl { + static { + Display.initSingleton(); + } + + public Window() { + } + + static long nextWindowHandle = 1; + + protected void createNativeImpl() { + if(0!=getParentWindowHandle()) { + throw new NativeWindowException("GDL Window does not support window parenting"); + } + AbstractGraphicsScreen aScreen = getScreen().getGraphicsScreen(); + AbstractGraphicsDevice aDevice = getScreen().getDisplay().getGraphicsDevice(); + + config = GraphicsConfigurationFactory.getFactory(aDevice).chooseGraphicsConfiguration( + capsRequested, capsRequested, capabilitiesChooser, aScreen); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + synchronized(Window.class) { + setWindowHandle(nextWindowHandle++); // just a marker + + surfaceHandle = CreateSurface(aDevice.getHandle(), getScreen().getWidth(), getScreen().getHeight(), x, y, width, height); + if (surfaceHandle == 0) { + throw new NativeWindowException("Error creating window"); + } + } + } + + protected void closeNativeImpl() { + if(0!=surfaceHandle) { + synchronized(Window.class) { + CloseSurface(getDisplayHandle(), surfaceHandle); + } + surfaceHandle = 0; + ((Display)getScreen().getDisplay()).setFocus(null); + } + } + + protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) { + reconfigureWindowImpl(x, y, width, height, false, 0, 0); + if(visible) { + ((Display)getScreen().getDisplay()).setFocus(this); + } + this.visibleChanged(visible); + } + + protected boolean reconfigureWindowImpl(int x, int y, int width, int height, boolean parentChange, int fullScreenChange, int decorationChange) { + Screen screen = (Screen) getScreen(); + + int _x=(x>=0)?x:this.x; + int _y=(x>=0)?y:this.y; + int _w=(width>0)?width:this.width; + int _h=(height>0)?height:this.height; + + if(_w>screen.getWidth()) { + _w=screen.getWidth(); + } + if(_h>screen.getHeight()) { + _h=screen.getHeight(); + } + if((_x+_w)>screen.getWidth()) { + _x=screen.getWidth()-_w; + } + if((_y+_h)>screen.getHeight()) { + _y=screen.getHeight()-_h; + } + + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, getScreen().getWidth(), getScreen().getHeight(), _x, _y, _w, _h); + } + + return true; + } + + protected void requestFocusImpl(boolean reparented) { + ((Display)getScreen().getDisplay()).setFocus(this); + } + + @Override + public final long getSurfaceHandle() { + return surfaceHandle; + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return new Point(x,y); + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateSurface(long displayHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); + private native void CloseSurface(long displayHandle, long surfaceHandle); + private native void SetBounds0(long surfaceHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); + + private void updateBounds(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + private long surfaceHandle; +} diff --git a/src/newt/classes/jogamp/newt/macosx/MacDisplay.java b/src/newt/classes/jogamp/newt/macosx/MacDisplay.java new file mode 100644 index 000000000..49f2ff5d8 --- /dev/null +++ b/src/newt/classes/jogamp/newt/macosx/MacDisplay.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.macosx; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.macosx.*; +import com.jogamp.newt.*; +import jogamp.newt.*; +import com.jogamp.newt.util.MainThread; + +public class MacDisplay extends DisplayImpl { + static { + NEWTJNILibLoader.loadNEWT(); + + if(!initNSApplication0()) { + throw new NativeWindowException("Failed to initialize native Application hook"); + } + if(!MacWindow.initIDs0()) { + throw new NativeWindowException("Failed to initialize jmethodIDs"); + } + if(DEBUG) { + System.err.println("MacDisplay.init App and IDs OK "+Thread.currentThread().getName()); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + public MacDisplay() { + } + + protected void dispatchMessagesNative() { + dispatchMessages0(); + } + + protected void createNativeImpl() { + aDevice = new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + } + + protected void closeNativeImpl() { } + + @Override + protected void createEDTUtil() { + if(NewtFactory.useEDT()) { + final Display f_dpy = this; + MainThread.addPumpMessage(this, + new Runnable() { + public void run() { + if(null!=f_dpy.getGraphicsDevice()) { + f_dpy.dispatchMessages(); + } } } ); + edtUtil = MainThread.getSingleton(); + edtUtil.start(); + } + } + + protected void releaseEDTUtil() { + if(null!=edtUtil) { + MainThread.removePumpMessage(this); + edtUtil.waitUntilStopped(); + edtUtil=null; + } + } + + private static native boolean initNSApplication0(); + protected native void dispatchMessages0(); +} + diff --git a/src/newt/classes/jogamp/newt/macosx/MacScreen.java b/src/newt/classes/jogamp/newt/macosx/MacScreen.java new file mode 100644 index 000000000..30028602c --- /dev/null +++ b/src/newt/classes/jogamp/newt/macosx/MacScreen.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.macosx; + +import com.jogamp.newt.*; +import jogamp.newt.ScreenImpl; +import javax.media.nativewindow.*; + +public class MacScreen extends ScreenImpl { + static { + MacDisplay.initSingleton(); + } + + public MacScreen() { + } + + protected void createNativeImpl() { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx); + setScreenSize(getWidthImpl0(screen_idx), getHeightImpl0(screen_idx)); + } + + protected void closeNativeImpl() { } + + private static native int getWidthImpl0(int scrn_idx); + private static native int getHeightImpl0(int scrn_idx); +} diff --git a/src/newt/classes/jogamp/newt/macosx/MacWindow.java b/src/newt/classes/jogamp/newt/macosx/MacWindow.java new file mode 100644 index 000000000..a27f04797 --- /dev/null +++ b/src/newt/classes/jogamp/newt/macosx/MacWindow.java @@ -0,0 +1,439 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.macosx; + +import javax.media.nativewindow.*; +import com.jogamp.common.util.locks.RecursiveLock; + +import com.jogamp.newt.event.*; +import jogamp.newt.*; +import javax.media.nativewindow.util.Insets; +import javax.media.nativewindow.util.Point; + +public class MacWindow extends WindowImpl { + + // Window styles + private static final int NSBorderlessWindowMask = 0; + private static final int NSTitledWindowMask = 1 << 0; + private static final int NSClosableWindowMask = 1 << 1; + private static final int NSMiniaturizableWindowMask = 1 << 2; + private static final int NSResizableWindowMask = 1 << 3; + + // Window backing store types + private static final int NSBackingStoreRetained = 0; + private static final int NSBackingStoreNonretained = 1; + private static final int NSBackingStoreBuffered = 2; + + // Key constants handled differently on Mac OS X than other platforms + private static final int NSUpArrowFunctionKey = 0xF700; + private static final int NSDownArrowFunctionKey = 0xF701; + private static final int NSLeftArrowFunctionKey = 0xF702; + private static final int NSRightArrowFunctionKey = 0xF703; + private static final int NSF1FunctionKey = 0xF704; + private static final int NSF2FunctionKey = 0xF705; + private static final int NSF3FunctionKey = 0xF706; + private static final int NSF4FunctionKey = 0xF707; + private static final int NSF5FunctionKey = 0xF708; + private static final int NSF6FunctionKey = 0xF709; + private static final int NSF7FunctionKey = 0xF70A; + private static final int NSF8FunctionKey = 0xF70B; + private static final int NSF9FunctionKey = 0xF70C; + private static final int NSF10FunctionKey = 0xF70D; + private static final int NSF11FunctionKey = 0xF70E; + private static final int NSF12FunctionKey = 0xF70F; + private static final int NSF13FunctionKey = 0xF710; + private static final int NSF14FunctionKey = 0xF711; + private static final int NSF15FunctionKey = 0xF712; + private static final int NSF16FunctionKey = 0xF713; + private static final int NSF17FunctionKey = 0xF714; + private static final int NSF18FunctionKey = 0xF715; + private static final int NSF19FunctionKey = 0xF716; + private static final int NSF20FunctionKey = 0xF717; + private static final int NSF21FunctionKey = 0xF718; + private static final int NSF22FunctionKey = 0xF719; + private static final int NSF23FunctionKey = 0xF71A; + private static final int NSF24FunctionKey = 0xF71B; + private static final int NSF25FunctionKey = 0xF71C; + private static final int NSF26FunctionKey = 0xF71D; + private static final int NSF27FunctionKey = 0xF71E; + private static final int NSF28FunctionKey = 0xF71F; + private static final int NSF29FunctionKey = 0xF720; + private static final int NSF30FunctionKey = 0xF721; + private static final int NSF31FunctionKey = 0xF722; + private static final int NSF32FunctionKey = 0xF723; + private static final int NSF33FunctionKey = 0xF724; + private static final int NSF34FunctionKey = 0xF725; + private static final int NSF35FunctionKey = 0xF726; + private static final int NSInsertFunctionKey = 0xF727; + private static final int NSDeleteFunctionKey = 0xF728; + private static final int NSHomeFunctionKey = 0xF729; + private static final int NSBeginFunctionKey = 0xF72A; + private static final int NSEndFunctionKey = 0xF72B; + private static final int NSPageUpFunctionKey = 0xF72C; + private static final int NSPageDownFunctionKey = 0xF72D; + private static final int NSPrintScreenFunctionKey = 0xF72E; + private static final int NSScrollLockFunctionKey = 0xF72F; + private static final int NSPauseFunctionKey = 0xF730; + private static final int NSSysReqFunctionKey = 0xF731; + private static final int NSBreakFunctionKey = 0xF732; + private static final int NSResetFunctionKey = 0xF733; + private static final int NSStopFunctionKey = 0xF734; + private static final int NSMenuFunctionKey = 0xF735; + private static final int NSUserFunctionKey = 0xF736; + private static final int NSSystemFunctionKey = 0xF737; + private static final int NSPrintFunctionKey = 0xF738; + private static final int NSClearLineFunctionKey = 0xF739; + private static final int NSClearDisplayFunctionKey = 0xF73A; + private static final int NSInsertLineFunctionKey = 0xF73B; + private static final int NSDeleteLineFunctionKey = 0xF73C; + private static final int NSInsertCharFunctionKey = 0xF73D; + private static final int NSDeleteCharFunctionKey = 0xF73E; + private static final int NSPrevFunctionKey = 0xF73F; + private static final int NSNextFunctionKey = 0xF740; + private static final int NSSelectFunctionKey = 0xF741; + private static final int NSExecuteFunctionKey = 0xF742; + private static final int NSUndoFunctionKey = 0xF743; + private static final int NSRedoFunctionKey = 0xF744; + private static final int NSFindFunctionKey = 0xF745; + private static final int NSHelpFunctionKey = 0xF746; + private static final int NSModeSwitchFunctionKey = 0xF747; + + private volatile long surfaceHandle; + + // non fullscreen dimensions .. + private final Insets insets = new Insets(0,0,0,0); + + static { + MacDisplay.initSingleton(); + } + + public MacWindow() { + } + + protected void createNativeImpl() { + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration( + capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + } + + protected void closeNativeImpl() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) { System.err.println("MacWindow.CloseAction "+Thread.currentThread().getName()); } + if (getWindowHandle() != 0) { + close0(getWindowHandle()); + } + } catch (Throwable t) { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("Warning: closeNative failed - "+Thread.currentThread().getName(), t); + e.printStackTrace(); + } + } finally { + setWindowHandle(0); + nsViewLock.unlock(); + } + } + + @Override + public final long getSurfaceHandle() { + return surfaceHandle; + } + + @Override + public Insets getInsets() { + // in order to properly calculate insets we need the window to be + // created + nsViewLock.lock(); + try { + createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); + return (Insets) insets.clone(); + } finally { + nsViewLock.unlock(); + } + } + + private RecursiveLock nsViewLock = new RecursiveLock(); + + @Override + protected int lockSurfaceImpl() { + nsViewLock.lock(); + return LOCK_SUCCESS; + } + + @Override + protected void unlockSurfaceImpl() { + nsViewLock.unlock(); + } + + protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) { + nsViewLock.lock(); + try { + if (visible) { + createWindow(false, x, y, width, height, isFullscreen()); + if (getWindowHandle() != 0) { + makeKeyAndOrderFront0(getWindowHandle()); + } + } else { + if (getWindowHandle() != 0) { + orderOut0(getWindowHandle()); + } + } + visibleChanged(visible); + } finally { + nsViewLock.unlock(); + } + } + + @Override + protected void setTitleImpl(final String title) { + // FIXME: move nsViewLock up to window lock + nsViewLock.lock(); + try { + setTitle0(getWindowHandle(), title); + } finally { + nsViewLock.unlock(); + } + } + + protected void requestFocusImpl(boolean reparented) { + // FIXME: move nsViewLock up to window lock + nsViewLock.lock(); + try { + makeKey0(getWindowHandle()); + } finally { + nsViewLock.unlock(); + } + } + + protected boolean reconfigureWindowImpl(int x, int y, int width, int height, boolean parentChange, int fullScreenChange, int decorationChange) { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("MacWindow reconfig: parentChange "+parentChange+", fullScreenChange "+fullScreenChange+", decorationChange "+decorationChange+" "+x+"/"+y+" "+width+"x"+height); + } + int _x=(x>=0)?x:this.x; + int _y=(x>=0)?y:this.y; + int _w=(width>0)?width:this.width; + int _h=(height>0)?height:this.height; + + if(decorationChange!=0 || parentChange || fullScreenChange!=0) { + createWindow(true, _x, _y, _w, _h, fullScreenChange>0); + if (getWindowHandle() != 0) { + makeKeyAndOrderFront0(getWindowHandle()); + } + } else { + if(x>=0 || y>=0) { + setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), _x, _y); + } + if(width>0 || height>0) { + setContentSize0(getWindowHandle(), _w, _h); + } + } + } finally { + nsViewLock.unlock(); + } + return true; + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return null; + } + + private void insetsChanged(int left, int top, int right, int bottom) { + if (DEBUG_IMPLEMENTATION) { + System.err.println(Thread.currentThread().getName()+ + " Insets changed to " + left + ", " + top + ", " + right + ", " + bottom); + } + if (left != -1 && top != -1 && right != -1 && bottom != -1) { + insets.left = left; + insets.top = top; + insets.right = right; + insets.bottom = bottom; + } + } + + private char convertKeyChar(char keyChar) { + if (keyChar == '\r') { + // Turn these into \n + return '\n'; + } + + if (keyChar >= NSUpArrowFunctionKey && keyChar <= NSModeSwitchFunctionKey) { + switch (keyChar) { + case NSUpArrowFunctionKey: return KeyEvent.VK_UP; + case NSDownArrowFunctionKey: return KeyEvent.VK_DOWN; + case NSLeftArrowFunctionKey: return KeyEvent.VK_LEFT; + case NSRightArrowFunctionKey: return KeyEvent.VK_RIGHT; + case NSF1FunctionKey: return KeyEvent.VK_F1; + case NSF2FunctionKey: return KeyEvent.VK_F2; + case NSF3FunctionKey: return KeyEvent.VK_F3; + case NSF4FunctionKey: return KeyEvent.VK_F4; + case NSF5FunctionKey: return KeyEvent.VK_F5; + case NSF6FunctionKey: return KeyEvent.VK_F6; + case NSF7FunctionKey: return KeyEvent.VK_F7; + case NSF8FunctionKey: return KeyEvent.VK_F8; + case NSF9FunctionKey: return KeyEvent.VK_F9; + case NSF10FunctionKey: return KeyEvent.VK_F10; + case NSF11FunctionKey: return KeyEvent.VK_F11; + case NSF12FunctionKey: return KeyEvent.VK_F12; + case NSF13FunctionKey: return KeyEvent.VK_F13; + case NSF14FunctionKey: return KeyEvent.VK_F14; + case NSF15FunctionKey: return KeyEvent.VK_F15; + case NSF16FunctionKey: return KeyEvent.VK_F16; + case NSF17FunctionKey: return KeyEvent.VK_F17; + case NSF18FunctionKey: return KeyEvent.VK_F18; + case NSF19FunctionKey: return KeyEvent.VK_F19; + case NSF20FunctionKey: return KeyEvent.VK_F20; + case NSF21FunctionKey: return KeyEvent.VK_F21; + case NSF22FunctionKey: return KeyEvent.VK_F22; + case NSF23FunctionKey: return KeyEvent.VK_F23; + case NSF24FunctionKey: return KeyEvent.VK_F24; + case NSInsertFunctionKey: return KeyEvent.VK_INSERT; + case NSDeleteFunctionKey: return KeyEvent.VK_DELETE; + case NSHomeFunctionKey: return KeyEvent.VK_HOME; + case NSBeginFunctionKey: return KeyEvent.VK_BEGIN; + case NSEndFunctionKey: return KeyEvent.VK_END; + case NSPageUpFunctionKey: return KeyEvent.VK_PAGE_UP; + case NSPageDownFunctionKey: return KeyEvent.VK_PAGE_DOWN; + case NSPrintScreenFunctionKey: return KeyEvent.VK_PRINTSCREEN; + case NSScrollLockFunctionKey: return KeyEvent.VK_SCROLL_LOCK; + case NSPauseFunctionKey: return KeyEvent.VK_PAUSE; + // Not handled: + // NSSysReqFunctionKey + // NSBreakFunctionKey + // NSResetFunctionKey + case NSStopFunctionKey: return KeyEvent.VK_STOP; + // Not handled: + // NSMenuFunctionKey + // NSUserFunctionKey + // NSSystemFunctionKey + // NSPrintFunctionKey + // NSClearLineFunctionKey + // NSClearDisplayFunctionKey + // NSInsertLineFunctionKey + // NSDeleteLineFunctionKey + // NSInsertCharFunctionKey + // NSDeleteCharFunctionKey + // NSPrevFunctionKey + // NSNextFunctionKey + // NSSelectFunctionKey + // NSExecuteFunctionKey + // NSUndoFunctionKey + // NSRedoFunctionKey + // NSFindFunctionKey + // NSHelpFunctionKey + // NSModeSwitchFunctionKey + default: break; + } + } + + // NSEvent's charactersIgnoringModifiers doesn't ignore the shift key + if (keyChar >= 'a' && keyChar <= 'z') { + return Character.toUpperCase(keyChar); + } + + return keyChar; + } + + @Override + public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) { + int key = convertKeyChar(keyChar); + if(DEBUG_IMPLEMENTATION) System.err.println("MacWindow.enqueueKeyEvent "+Thread.currentThread().getName()); + // Note that we send the key char for the key code on this + // platform -- we do not get any useful key codes out of the system + super.enqueueKeyEvent(wait, eventType, modifiers, key, keyChar); + } + + private void createWindow(final boolean recreate, final int x, final int y, final int width, final int height, final boolean fullscreen) { + + if(0!=getWindowHandle() && !recreate) { + return; + } + + try { + //runOnEDTIfAvail(true, new Runnable() { + // public void run() { + if(0!=getWindowHandle()) { + // save the view .. close the window + surfaceHandle = changeContentView0(getParentWindowHandle(), getWindowHandle(), 0); + if(recreate && 0==surfaceHandle) { + throw new NativeWindowException("Internal Error - recreate, window but no view"); + } + close0(getWindowHandle()); + setWindowHandle(0); + } else { + surfaceHandle = 0; + } + setWindowHandle(createWindow0(getParentWindowHandle(), + x, y, width, height, fullscreen, + (isUndecorated() ? + NSBorderlessWindowMask : + NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), + NSBackingStoreBuffered, + getScreen().getIndex(), surfaceHandle)); + if (getWindowHandle() == 0) { + throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); + } + surfaceHandle = contentView0(getWindowHandle()); + setTitle0(getWindowHandle(), getTitle()); + // don't make the window visible on window creation + // makeKeyAndOrderFront0(windowHandle); + // } } ); + } catch (Exception ie) { + ie.printStackTrace(); + } + + enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_MOVED); + enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_RESIZED); + enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } + + protected static native boolean initIDs0(); + private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h, + boolean fullscreen, int windowStyle, + int backingStoreType, + int screen_idx, long view); + private native void makeKeyAndOrderFront0(long window); + private native void makeKey0(long window); + private native void orderOut0(long window); + private native void close0(long window); + private native void setTitle0(long window, String title); + private native long contentView0(long window); + private native long changeContentView0(long parentWindowHandle, long window, long view); + private native void setContentSize0(long window, int w, int h); + private native void setFrameTopLeftPoint0(long parentWindowHandle, long window, int x, int y); +} diff --git a/src/newt/classes/jogamp/newt/opengl/broadcom/egl/Display.java b/src/newt/classes/jogamp/newt/opengl/broadcom/egl/Display.java new file mode 100644 index 000000000..494908a81 --- /dev/null +++ b/src/newt/classes/jogamp/newt/opengl/broadcom/egl/Display.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.opengl.broadcom.egl; + +import jogamp.newt.*; +import jogamp.opengl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; + +public class Display extends jogamp.newt.DisplayImpl { + + static { + NEWTJNILibLoader.loadNEWT(); + + if (!Window.initIDs()) { + throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public Display() { + } + + protected void createNativeImpl() { + long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight); + if (handle == EGL.EGL_NO_DISPLAY) { + throw new NativeWindowException("BC EGL CreateDisplay failed"); + } + aDevice = new EGLGraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); + } + + protected void closeNativeImpl() { + if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { + DestroyDisplay(aDevice.getHandle()); + } + } + + protected void dispatchMessagesNative() { + // n/a .. DispatchMessages(); + } + + private native long CreateDisplay(int width, int height); + private native void DestroyDisplay(long dpy); + private native void DispatchMessages(); +} + diff --git a/src/newt/classes/jogamp/newt/opengl/broadcom/egl/Screen.java b/src/newt/classes/jogamp/newt/opengl/broadcom/egl/Screen.java new file mode 100644 index 000000000..2224f7860 --- /dev/null +++ b/src/newt/classes/jogamp/newt/opengl/broadcom/egl/Screen.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.opengl.broadcom.egl; + +import javax.media.nativewindow.*; + +public class Screen extends jogamp.newt.ScreenImpl { + + static { + Display.initSingleton(); + } + + + public Screen() { + } + + protected void createNativeImpl() { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx); + setScreenSize(fixedWidth, fixedHeight); + } + + protected void closeNativeImpl() { } + + //---------------------------------------------------------------------- + // Internals only + // + + static final int fixedWidth = 1920; + static final int fixedHeight = 1080; +} + diff --git a/src/newt/classes/jogamp/newt/opengl/broadcom/egl/Window.java b/src/newt/classes/jogamp/newt/opengl/broadcom/egl/Window.java new file mode 100644 index 000000000..9532178f3 --- /dev/null +++ b/src/newt/classes/jogamp/newt/opengl/broadcom/egl/Window.java @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.opengl.broadcom.egl; + +import jogamp.opengl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Point; +import javax.media.opengl.GLCapabilitiesImmutable; + +public class Window extends jogamp.newt.WindowImpl { + static { + Display.initSingleton(); + } + + public Window() { + } + + protected void createNativeImpl() { + if(0!=getParentWindowHandle()) { + throw new RuntimeException("Window parenting not supported (yet)"); + } + // query a good configuration .. even thought we drop this one + // and reuse the EGLUtil choosen one later. + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration( + capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + setSizeImpl(getScreen().getWidth(), getScreen().getHeight()); + + setWindowHandle(realizeWindow(true, width, height)); + if (0 == getWindowHandle()) { + throw new NativeWindowException("Error native Window Handle is null"); + } + } + + protected void closeNativeImpl() { + if(0!=windowHandleClose) { + CloseWindow(getDisplayHandle(), windowHandleClose); + } + } + + protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) { + reconfigureWindowImpl(x, y, width, height, false, 0, 0); + visibleChanged(visible); + } + + protected void requestFocusImpl(boolean reparented) { } + + protected void setSizeImpl(int width, int height) { + if(0!=getWindowHandle()) { + // n/a in BroadcomEGL + System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window"); + } else { + this.width = width; + this.height = height; + } + } + + protected boolean reconfigureWindowImpl(int x, int y, int width, int height, + boolean parentChange, int fullScreenChange, int decorationChange) { + if(0!=getWindowHandle()) { + if(0!=fullScreenChange) { + if( fullScreenChange > 0 ) { + // n/a in BroadcomEGL + System.err.println("setFullscreen n/a in BroadcomEGL"); + return false; + } + } + } + if(width>0 || height>0) { + if(0!=getWindowHandle()) { + // n/a in BroadcomEGL + System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window"); + } else { + this.width=(width>0)?width:this.width; + this.height=(height>0)?height:this.height; + } + } + if(x>=0 || y>=0) { + System.err.println("BCEGL Window.setPositionImpl n/a in BroadcomEGL"); + } + return true; + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return new Point(x,y); + } + + + @Override + public boolean surfaceSwap() { + SwapWindow(getDisplayHandle(), getWindowHandle()); + return true; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height); + private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle); + private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle); + + + private long realizeWindow(boolean chromaKey, int width, int height) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config); + } + long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height); + if (0 == handle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + windowHandleClose = handle; + return handle; + } + + private void windowCreated(int cfgID, int width, int height) { + this.width = width; + this.height = height; + GLCapabilitiesImmutable capsReq = (GLCapabilitiesImmutable) config.getRequestedCapabilities(); + config = EGLGraphicsConfiguration.create(capsReq, getScreen().getGraphicsScreen(), cfgID); + if (config == null) { + throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this); + } + if(DEBUG_IMPLEMENTATION) { + System.err.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+config); + } + } + + private long windowHandleClose; +} diff --git a/src/newt/classes/jogamp/newt/opengl/kd/KDDisplay.java b/src/newt/classes/jogamp/newt/opengl/kd/KDDisplay.java new file mode 100644 index 000000000..c9d83a750 --- /dev/null +++ b/src/newt/classes/jogamp/newt/opengl/kd/KDDisplay.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.opengl.kd; + +import com.jogamp.newt.*; +import jogamp.newt.*; +import jogamp.opengl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; + +public class KDDisplay extends DisplayImpl { + + static { + NEWTJNILibLoader.loadNEWT(); + + if (!KDWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize KDWindow jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public KDDisplay() { + } + + protected void createNativeImpl() { + // FIXME: map name to EGL_*_DISPLAY + long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); + if (handle == EGL.EGL_NO_DISPLAY) { + throw new NativeWindowException("eglGetDisplay failed"); + } + if (!EGL.eglInitialize(handle, null, null)) { + throw new NativeWindowException("eglInitialize failed"); + } + aDevice = new EGLGraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); + } + + protected void closeNativeImpl() { + if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { + EGL.eglTerminate(aDevice.getHandle()); + } + } + + protected void dispatchMessagesNative() { + DispatchMessages(); + } + + private native void DispatchMessages(); +} + diff --git a/src/newt/classes/jogamp/newt/opengl/kd/KDScreen.java b/src/newt/classes/jogamp/newt/opengl/kd/KDScreen.java new file mode 100644 index 000000000..2996fb194 --- /dev/null +++ b/src/newt/classes/jogamp/newt/opengl/kd/KDScreen.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.opengl.kd; + +import com.jogamp.newt.*; +import jogamp.newt.ScreenImpl; +import javax.media.nativewindow.*; + +public class KDScreen extends ScreenImpl { + static { + KDDisplay.initSingleton(); + } + + public KDScreen() { + } + + protected void createNativeImpl() { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx); + } + + protected void closeNativeImpl() { } + + // elevate access to this package .. + protected void setScreenSize(int w, int h) { + super.setScreenSize(w, h); + } +} diff --git a/src/newt/classes/jogamp/newt/opengl/kd/KDWindow.java b/src/newt/classes/jogamp/newt/opengl/kd/KDWindow.java new file mode 100644 index 000000000..9cfa13cd9 --- /dev/null +++ b/src/newt/classes/jogamp/newt/opengl/kd/KDWindow.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.opengl.kd; + +import jogamp.newt.*; +import jogamp.opengl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Point; +import javax.media.opengl.GLCapabilitiesImmutable; + +public class KDWindow extends WindowImpl { + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + + static { + KDDisplay.initSingleton(); + } + + public KDWindow() { + } + + protected void createNativeImpl() { + if(0!=getParentWindowHandle()) { + throw new RuntimeException("Window parenting not supported (yet)"); + } + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration( + capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + GLCapabilitiesImmutable eglCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps); + + eglWindowHandle = CreateWindow(getDisplayHandle(), eglAttribs); + if (eglWindowHandle == 0) { + throw new NativeWindowException("Error creating egl window: "+config); + } + setVisible0(eglWindowHandle, false); + setWindowHandle(RealizeWindow(eglWindowHandle)); + if (0 == getWindowHandle()) { + throw new NativeWindowException("Error native Window Handle is null"); + } + windowHandleClose = eglWindowHandle; + } + + protected void closeNativeImpl() { + if(0!=windowHandleClose) { + CloseWindow(windowHandleClose, windowUserData); + windowUserData=0; + } + } + + protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) { + setVisible0(eglWindowHandle, visible); + reconfigureWindowImpl(x, y, width, height, false, 0, 0); + visibleChanged(visible); + } + + protected void requestFocusImpl(boolean reparented) { } + + protected boolean reconfigureWindowImpl(int x, int y, int width, int height, + boolean parentChange, int fullScreenChange, int decorationChange) { + if(0!=eglWindowHandle) { + if(0!=fullScreenChange) { + boolean fs = fullScreenChange > 0; + setFullScreen0(eglWindowHandle, fs); + if(fs) { + return true; + } + } + // int _x=(x>=0)?x:this.x; + // int _y=(x>=0)?y:this.y; + int _w=(width>0)?width:this.width; + int _h=(height>0)?height:this.height; + if(width>0 || height>0) { + setSize0(eglWindowHandle, _w, _h); + } + if(x>=0 || y>=0) { + System.err.println("setPosition n/a in KD"); + } + } + return true; + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return new Point(x,y); + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long displayHandle, int[] attributes); + private native long RealizeWindow(long eglWindowHandle); + private native int CloseWindow(long eglWindowHandle, long userData); + private native void setVisible0(long eglWindowHandle, boolean visible); + private native void setSize0(long eglWindowHandle, int width, int height); + private native void setFullScreen0(long eglWindowHandle, boolean fullscreen); + + private void windowCreated(long userData) { + windowUserData=userData; + } + + @Override + protected void sizeChanged(int newWidth, int newHeight, boolean force) { + if(fullscreen) { + ((KDScreen)getScreen()).setScreenSize(width, height); + } + super.sizeChanged(newWidth, newHeight, force); + } + + private long eglWindowHandle; + private long windowHandleClose; + private long windowUserData; +} diff --git a/src/newt/classes/jogamp/newt/windows/WindowsDisplay.java b/src/newt/classes/jogamp/newt/windows/WindowsDisplay.java new file mode 100644 index 000000000..750c38092 --- /dev/null +++ b/src/newt/classes/jogamp/newt/windows/WindowsDisplay.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.windows; + +import jogamp.nativewindow.windows.RegisteredClass; +import jogamp.nativewindow.windows.RegisteredClassFactory; +import jogamp.newt.DisplayImpl; +import jogamp.newt.NEWTJNILibLoader; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.windows.WindowsGraphicsDevice; + +public class WindowsDisplay extends DisplayImpl { + + private static final String newtClassBaseName = "_newt_clazz" ; + private static RegisteredClassFactory sharedClassFactory; + + static { + NEWTJNILibLoader.loadNEWT(); + + if (!WindowsWindow.initIDs0()) { + throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); + } + sharedClassFactory = new RegisteredClassFactory(newtClassBaseName, WindowsWindow.getNewtWndProc0()); + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + private RegisteredClass sharedClass; + + public WindowsDisplay() { + } + + protected void createNativeImpl() { + sharedClass = sharedClassFactory.getSharedClass(); + aDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + } + + protected void closeNativeImpl() { + sharedClassFactory.releaseSharedClass(); + } + + protected void dispatchMessagesNative() { + DispatchMessages0(); + } + + protected long getHInstance() { + return sharedClass.getHandle(); + } + + protected String getWindowClassName() { + return sharedClass.getName(); + } + + //---------------------------------------------------------------------- + // Internals only + // + private static native void DispatchMessages0(); +} + diff --git a/src/newt/classes/jogamp/newt/windows/WindowsScreen.java b/src/newt/classes/jogamp/newt/windows/WindowsScreen.java new file mode 100644 index 000000000..ea7fe8d55 --- /dev/null +++ b/src/newt/classes/jogamp/newt/windows/WindowsScreen.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ +package jogamp.newt.windows; + +import com.jogamp.common.util.ArrayHashSet; +import java.util.ArrayList; + +import com.jogamp.newt.*; +import jogamp.newt.ScreenImpl; +import com.jogamp.newt.ScreenMode; +import jogamp.newt.ScreenModeStatus; +import com.jogamp.newt.util.ScreenModeUtil; + +import javax.media.nativewindow.*; + +public class WindowsScreen extends ScreenImpl { + + static { + WindowsDisplay.initSingleton(); + } + + public WindowsScreen() { + } + + protected void createNativeImpl() { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx); + setScreenSize(getWidthImpl0(screen_idx), getHeightImpl0(screen_idx)); + } + + protected void closeNativeImpl() { + } + + private int[] getScreenModeIdx(int idx) { + int[] modeProps = getScreenMode0(screen_idx, idx); + if (null == modeProps || 0 == modeProps.length) { + return null; + } + if(modeProps.length < ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL) { + throw new RuntimeException("properties array too short, should be >= "+ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+modeProps.length); + } + return modeProps; + } + + private int nativeModeIdx; + + protected int[] getScreenModeFirstImpl() { + nativeModeIdx = 0; + return getScreenModeNextImpl(); + } + + protected int[] getScreenModeNextImpl() { + int[] modeProps = getScreenModeIdx(nativeModeIdx); + if (null != modeProps && 0 < modeProps.length) { + nativeModeIdx++; + return modeProps; + } + return null; + } + + protected ScreenMode getCurrentScreenModeImpl() { + int[] modeProps = getScreenModeIdx(-1); + if (null != modeProps && 0 < modeProps.length) { + return ScreenModeUtil.streamIn(modeProps, 0); + } + return null; + } + + protected boolean setCurrentScreenModeImpl(ScreenMode sm) { + return setScreenMode0(screen_idx, + sm.getMonitorMode().getSurfaceSize().getResolution().getWidth(), + sm.getMonitorMode().getSurfaceSize().getResolution().getHeight(), + sm.getMonitorMode().getSurfaceSize().getBitsPerPixel(), + sm.getMonitorMode().getRefreshRate(), + sm.getRotation()); + } + + // Native calls + private native int getWidthImpl0(int scrn_idx); + + private native int getHeightImpl0(int scrn_idx); + + private native int[] getScreenMode0(int screen_index, int mode_index); + private native boolean setScreenMode0(int screen_index, int width, int height, int bits, int freq, int rot); +} diff --git a/src/newt/classes/jogamp/newt/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/windows/WindowsWindow.java new file mode 100644 index 000000000..653de295d --- /dev/null +++ b/src/newt/classes/jogamp/newt/windows/WindowsWindow.java @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.windows; + +import jogamp.nativewindow.windows.GDI; +import jogamp.newt.WindowImpl; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Insets; +import javax.media.nativewindow.util.Point; + +public class WindowsWindow extends WindowImpl { + + private long hmon; + private long hdc; + private long windowHandleClose; + private final Insets insets = new Insets(0, 0, 0, 0); + + static { + WindowsDisplay.initSingleton(); + } + + public WindowsWindow() { + } + + @Override + protected int lockSurfaceImpl() { + if (0 != hdc) { + throw new InternalError("surface not released"); + } + hdc = GDI.GetDC(getWindowHandle()); + hmon = MonitorFromWindow0(getWindowHandle()); + return ( 0 != hdc ) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY; + } + + @Override + protected void unlockSurfaceImpl() { + if (0 == hdc) { + throw new InternalError("surface not acquired"); + } + GDI.ReleaseDC(getWindowHandle(), hdc); + hdc=0; + } + + @Override + public final long getSurfaceHandle() { + return hdc; + } + + @Override + public boolean hasDeviceChanged() { + if(0!=getWindowHandle()) { + long _hmon = MonitorFromWindow0(getWindowHandle()); + if (hmon != _hmon) { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("Info: Window Device Changed "+Thread.currentThread().getName()+ + ", HMON "+toHexString(hmon)+" -> "+toHexString(_hmon)); + e.printStackTrace(); + } + hmon = _hmon; + return true; + } + } + return false; + } + + protected void createNativeImpl() { + WindowsScreen screen = (WindowsScreen) getScreen(); + WindowsDisplay display = (WindowsDisplay) screen.getDisplay(); + config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration( + capsRequested, capsRequested, capabilitiesChooser, screen.getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + setWindowHandle(CreateWindow0(display.getHInstance(), display.getWindowClassName(), display.getWindowClassName(), + getParentWindowHandle(), 0, undecorated, x, y, width, height)); + if (getWindowHandle() == 0) { + throw new NativeWindowException("Error creating window"); + } + windowHandleClose = getWindowHandle(); + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("Info: Window new window handle "+Thread.currentThread().getName()+ + " (Parent HWND "+toHexString(getParentWindowHandle())+ + ") : HWND "+toHexString(getWindowHandle())+", "+Thread.currentThread()); + e.printStackTrace(); + } + } + + protected void closeNativeImpl() { + if (hdc != 0) { + if(windowHandleClose != 0) { + try { + GDI.ReleaseDC(windowHandleClose, hdc); + } catch (Throwable t) { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t); + e.printStackTrace(); + } + } + } + hdc = 0; + } + if(windowHandleClose != 0) { + try { + GDI.DestroyWindow(windowHandleClose); + } catch (Throwable t) { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t); + e.printStackTrace(); + } + } finally { + windowHandleClose = 0; + } + } + } + + protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) { + setVisible0(getWindowHandle(), visible, (getParentWindowHandle()==0)?true:false, x, y, width, height); + visibleChanged(visible); + } + + protected boolean reconfigureWindowImpl(int x, int y, int width, int height, + boolean parentChange, int fullScreenChange, int decorationChange) { + reconfigureWindow0( (fullScreenChange>0)?0:getParentWindowHandle(), + getWindowHandle(), x, y, width, height, isVisible(), parentChange, fullScreenChange, decorationChange); + return true; + } + + protected void requestFocusImpl(boolean force) { + requestFocus0(getWindowHandle(), force); + } + + @Override + protected void setTitleImpl(final String title) { + setTitle0(getWindowHandle(), title); + } + + @Override + public Insets getInsets() { + return (Insets)insets.clone(); + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return GDI.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y); + } + + //---------------------------------------------------------------------- + // Internals only + // + protected static native boolean initIDs0(); + protected static native long getNewtWndProc0(); + + private native long CreateWindow0(long hInstance, String wndClassName, String wndName, + long parentWindowHandle, long visualID, boolean isUndecorated, + int x, int y, int width, int height); + private native long MonitorFromWindow0(long windowHandle); + private native void setVisible0(long windowHandle, boolean visible, boolean top, int x, int y, int width, int height); + private native void reconfigureWindow0(long parentWindowHandle, long windowHandle, + int x, int y, int width, int height, boolean isVisible, + boolean parentChange, int fullScreenChange, int decorationChange); + private static native void setTitle0(long windowHandle, String title); + private native void requestFocus0(long windowHandle, boolean force); + + private void insetsChanged(int left, int top, int right, int bottom) { + if (left != -1 && top != -1 && right != -1 && bottom != -1) { + if (left != insets.left || top != insets.top || right != insets.right || bottom != insets.bottom) { + insets.left = left; + insets.top = top; + insets.right = right; + insets.bottom = bottom; + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.insetsChanged: "+insets); + } + } + } + } +} diff --git a/src/newt/classes/jogamp/newt/x11/X11Display.java b/src/newt/classes/jogamp/newt/x11/X11Display.java new file mode 100644 index 000000000..d4a83abe0 --- /dev/null +++ b/src/newt/classes/jogamp/newt/x11/X11Display.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.x11; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import jogamp.newt.*; +import jogamp.nativewindow.x11.X11Util; + +public class X11Display extends DisplayImpl { + + static { + NEWTJNILibLoader.loadNEWT(); + + if ( !initIDs0() ) { + throw new NativeWindowException("Failed to initialize X11Display jmethodIDs"); + } + + if (!X11Window.initIDs0()) { + throw new NativeWindowException("Failed to initialize X11Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public X11Display() { + } + + public String validateDisplayName(String name, long handle) { + return X11Util.validateDisplayName(name, handle); + } + + protected void createNativeImpl() { + long handle = X11Util.createDisplay(name); + if( 0 == handle ) { + throw new RuntimeException("Error creating display: "+name); + } + try { + CompleteDisplay0(handle); + } catch(RuntimeException e) { + X11Util.closeDisplay(handle); + throw e; + } + aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.getNullToolkitLock()); + // aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.createDefaultToolkitLockNoAWT(NativeWindowFactory.TYPE_X11, handle)); + // aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT); + } + + protected void closeNativeImpl() { + X11Util.closeDisplay(getHandle()); + } + + protected void dispatchMessagesNative() { + long dpy = getHandle(); + if(0!=dpy) { + DispatchMessages0(dpy, javaObjectAtom, windowDeleteAtom); + } + } + + protected long getJavaObjectAtom() { return javaObjectAtom; } + protected long getWindowDeleteAtom() { return windowDeleteAtom; } + + //---------------------------------------------------------------------- + // Internals only + // + private static native boolean initIDs0(); + + private native void CompleteDisplay0(long handle); + + private native void DispatchMessages0(long display, long javaObjectAtom, long windowDeleteAtom); + + private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) { + this.javaObjectAtom=javaObjectAtom; + this.windowDeleteAtom=windowDeleteAtom; + } + + private long windowDeleteAtom; + private long javaObjectAtom; +} + diff --git a/src/newt/classes/jogamp/newt/x11/X11Screen.java b/src/newt/classes/jogamp/newt/x11/X11Screen.java new file mode 100644 index 000000000..4788f6b52 --- /dev/null +++ b/src/newt/classes/jogamp/newt/x11/X11Screen.java @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ +package jogamp.newt.x11; + +import jogamp.nativewindow.x11.X11Util; +import jogamp.newt.ScreenImpl; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.util.ScreenModeUtil; +import java.util.List; + +import javax.media.nativewindow.x11.*; + +public class X11Screen extends ScreenImpl { + + static { + X11Display.initSingleton(); + } + + public X11Screen() { + } + + protected void createNativeImpl() { + long handle = GetScreen0(display.getHandle(), screen_idx); + if (handle == 0) { + throw new RuntimeException("Error creating screen: " + screen_idx); + } + aScreen = new X11GraphicsScreen((X11GraphicsDevice) getDisplay().getGraphicsDevice(), screen_idx); + setScreenSize(getWidth0(display.getHandle(), screen_idx), + getHeight0(display.getHandle(), screen_idx)); + } + + protected void closeNativeImpl() { + } + + private int[] nrotations; + private int nrotation_index; + private int nres_number; + private int nres_index; + private int[] nrates; + private int nrate_index; + private int nmode_number; + + protected int[] getScreenModeFirstImpl() { + // initialize iterators and static data + nrotations = getAvailableScreenModeRotations0(display.getHandle(), screen_idx); + if(null==nrotations || 0==nrotations.length) { + return null; + } + nrotation_index = 0; + + nres_number = getNumScreenModeResolutions0(display.getHandle(), screen_idx); + if(0==nres_number) { + return null; + } + nres_index = 0; + + nrates = getScreenModeRates0(display.getHandle(), screen_idx, nres_index); + if(null==nrates || 0==nrates.length) { + return null; + } + nrate_index = 0; + + nmode_number = 0; + + return getScreenModeNextImpl(); + } + + protected int[] getScreenModeNextImpl() { + // assemble: w x h x bpp x f x r + + /** + System.err.println("******** mode: "+nmode_number); + System.err.println("rot "+nrotation_index); + System.err.println("rate "+nrate_index); + System.err.println("res "+nres_index); */ + + int[] res = getScreenModeResolution0(display.getHandle(), screen_idx, nres_index); + if(null==res || 0==res.length) { + return null; + } + if(0>=res[0] || 0>=res[1]) { + throw new InternalError("invalid resolution: "+res[0]+"x"+res[1]+" for res idx "+nres_index+"/"+nres_number); + } + int bpp = 32; // FIXME + int rate = nrates[nrate_index]; + if(0>=rate) { + throw new InternalError("invalid rate: "+rate+" at index "+nrate_index+"/"+nrates.length); + } + int rotation = nrotations[nrotation_index]; + + int[] props = new int[ 1 + ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL ]; + int i = 0; + props[i++] = nres_index; // use resolution index, not unique for native -> ScreenMode + props[i++] = 0; // set later for verification of iterator + props[i++] = res[0]; // width + props[i++] = res[1]; // height + props[i++] = bpp; // bpp + props[i++] = res[2]; // widthmm + props[i++] = res[3]; // heightmm + props[i++] = rate; // rate + props[i++] = rotation; + props[i - ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL] = i - 1; // count without extra element + + nmode_number++; + + // iteration: r -> f -> bpp -> [w x h] + nrotation_index++; + if(nrotation_index == nrotations.length) { + nrotation_index=0; + nrate_index++; + if(null == nrates || nrate_index == nrates.length){ + nres_index++; + if(nres_index == nres_number) { + // done + nrates=null; + nrotations=null; + return null; + } + + nrates = getScreenModeRates0(display.getHandle(), screen_idx, nres_index); + if(null==nrates || 0==nrates.length) { + return null; + } + nrate_index = 0; + } + } + + return props; + } + + protected ScreenMode getCurrentScreenModeImpl() { + int resNumber = getNumScreenModeResolutions0(display.getHandle(), screen_idx); + if(0==resNumber) { + return null; + } + int resIdx = getCurrentScreenResolutionIndex0(display.getHandle(), screen_idx); + if(0>resIdx) { + return null; + } + if(resIdx>=resNumber) { + throw new RuntimeException("Invalid resolution index: ! "+resIdx+" < "+resNumber); + } + int[] res = getScreenModeResolution0(display.getHandle(), screen_idx, resIdx); + if(null==res || 0==res.length) { + return null; + } + if(0>=res[0] || 0>=res[1]) { + throw new InternalError("invalid resolution: "+res[0]+"x"+res[1]+" for res idx "+resIdx+"/"+resNumber); + } + int rate = getCurrentScreenRate0(display.getHandle(), screen_idx); + if(0>rate) { + return null; + } + int rot = getCurrentScreenRotation0(display.getHandle(), screen_idx); + if(0>rot) { + return null; + } + + int[] props = new int[ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL]; + int i = 0; + props[i++] = 0; // set later for verification of iterator + props[i++] = res[0]; // width + props[i++] = res[1]; // height + props[i++] = 32; // FIXME: bpp + props[i++] = res[2]; // widthmm + props[i++] = res[3]; // heightmm + props[i++] = rate; // rate + props[i++] = rot; + props[i - ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL] = i; // count + return ScreenModeUtil.streamIn(props, 0); + } + + protected boolean setCurrentScreenModeImpl(ScreenMode screenMode) { + List screenModes = this.getScreenModesOrig(); + int screenModeIdx = screenModes.indexOf(screenMode); + if(0>screenModeIdx) { + throw new RuntimeException("ScreenMode not element of ScreenMode list: "+screenMode); + } + int resNumber = getNumScreenModeResolutions0(display.getHandle(), screen_idx); + int resIdx = getScreenModesIdx2NativeIdx().get(screenModeIdx); + if(0>resIdx || resIdx>=resNumber) { + throw new RuntimeException("Invalid resolution index: ! 0 < "+resIdx+" < "+resNumber+", screenMode["+screenModeIdx+"] "+screenMode); + } + + long dpy = X11Util.createDisplay(display.getName()); + if( 0 == dpy ) { + throw new RuntimeException("Error creating display: "+display.getName()); + } + + boolean done = false; + long t0 = System.currentTimeMillis(); + try { + int f = screenMode.getMonitorMode().getRefreshRate(); + int r = screenMode.getRotation(); + if( setCurrentScreenModeStart0(dpy, screen_idx, resIdx, f, r) ) { + while(!done && System.currentTimeMillis()-t0 < SCREEN_MODE_CHANGE_TIMEOUT) { + done = setCurrentScreenModePollEnd0(dpy, screen_idx, resIdx, f, r); + if(!done) { + Thread.yield(); + } + } + } + } finally { + X11Util.closeDisplay(dpy); + } + + if(!done) { + System.err.println("X11Screen.setCurrentScreenModeImpl: TO ("+SCREEN_MODE_CHANGE_TIMEOUT+") reached: "+ + (System.currentTimeMillis()-t0)+"ms"); + } + return done; + } + + //---------------------------------------------------------------------- + // Internals only + // + private static native long GetScreen0(long dpy, int scrn_idx); + + private static native int getWidth0(long display, int scrn_idx); + + private static native int getHeight0(long display, int scrn_idx); + + /** @return int[] { rot1, .. } */ + private static native int[] getAvailableScreenModeRotations0(long display, int screen_index); + + private static native int getNumScreenModeResolutions0(long display, int screen_index); + + /** @return int[] { width, height, widthmm, heightmm } */ + private static native int[] getScreenModeResolution0(long display, int screen_index, int mode_index); + + private static native int[] getScreenModeRates0(long display, int screen_index, int mode_index); + + private static native int getCurrentScreenResolutionIndex0(long display, int screen_index); + private static native int getCurrentScreenRate0(long display, int screen_index); + private static native int getCurrentScreenRotation0(long display, int screen_index); + + /** needs own Display connection for XRANDR event handling */ + private static native boolean setCurrentScreenModeStart0(long display, int screen_index, int mode_index, int freq, int rot); + private static native boolean setCurrentScreenModePollEnd0(long display, int screen_index, int mode_index, int freq, int rot); +} diff --git a/src/newt/classes/jogamp/newt/x11/X11Window.java b/src/newt/classes/jogamp/newt/x11/X11Window.java new file mode 100644 index 000000000..8f9455629 --- /dev/null +++ b/src/newt/classes/jogamp/newt/x11/X11Window.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package jogamp.newt.x11; + +import jogamp.nativewindow.x11.X11Util; +import jogamp.newt.WindowImpl; +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import javax.media.nativewindow.util.Point; + +public class X11Window extends WindowImpl { + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + + static { + X11Display.initSingleton(); + } + + public X11Window() { + } + + protected void createNativeImpl() { + X11Screen screen = (X11Screen) getScreen(); + X11Display display = (X11Display) screen.getDisplay(); + config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration( + capsRequested, capsRequested, capabilitiesChooser, screen.getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config; + long visualID = x11config.getVisualID(); + long w = CreateWindow0(getParentWindowHandle(), + display.getHandle(), screen.getIndex(), visualID, + display.getJavaObjectAtom(), display.getWindowDeleteAtom(), + x, y, width, height, isUndecorated()); + if (w == 0) { + throw new NativeWindowException("Error creating window: "+w); + } + setWindowHandle(w); + windowHandleClose = w; + } + + protected void closeNativeImpl() { + if(0!=windowHandleClose && null!=getScreen() ) { + X11Display display = (X11Display) getScreen().getDisplay(); + try { + CloseWindow0(display.getHandle(), windowHandleClose, + display.getJavaObjectAtom(), display.getWindowDeleteAtom()); + } catch (Throwable t) { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t); + e.printStackTrace(); + } + } finally { + windowHandleClose = 0; + } + } + } + + protected void setVisibleImpl(boolean visible, int x, int y, int width, int height) { + setVisible0(getDisplayHandle(), getWindowHandle(), visible, x, y, width, height); + } + + protected boolean reconfigureWindowImpl(int x, int y, int width, int height, + boolean parentChange, int fullScreenChange, int decorationChange) { + reparentHandle=0; + reparentCount=0; + long reqNewParentHandle = ( fullScreenChange > 0 ) ? 0 : getParentWindowHandle() ; + + reconfigureWindow0( getDisplayHandle(), getScreenIndex(), reqNewParentHandle, getWindowHandle(), + x, y, width, height, isVisible(), parentChange, fullScreenChange, decorationChange); + return true; + } + + protected void requestFocusImpl(boolean force) { + requestFocus0(getDisplayHandle(), getWindowHandle(), force); + } + + @Override + protected void setTitleImpl(String title) { + setTitle0(getDisplayHandle(), getWindowHandle(), title); + } + + protected Point getLocationOnScreenImpl(int x, int y) { + return X11Util.GetRelativeLocation( getDisplayHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y); + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs0(); + private native long CreateWindow0(long parentWindowHandle, long display, int screen_index, + long visualID, long javaObjectAtom, long windowDeleteAtom, + int x, int y, int width, int height, boolean undecorated); + private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom); + private native void setVisible0(long display, long windowHandle, boolean visible, int x, int y, int width, int height); + private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle, + int x, int y, int width, int height, boolean isVisible, + boolean parentChange, int fullScreenChange, int decorationChange); + private native void setTitle0(long display, long windowHandle, String title); + private native void requestFocus0(long display, long windowHandle, boolean force); + private native Object getRelativeLocation0(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y); + + private void windowReparented(long gotParentHandle) { + reparentHandle = gotParentHandle; + reparentCount++; + if(DEBUG_IMPLEMENTATION) { + System.err.println("******** new parent ("+reparentCount+"): " + toHexString(reparentHandle) ); + } + } + + private long windowHandleClose; + private volatile long reparentHandle; + private volatile int reparentCount; +} diff --git a/src/newt/native/BroadcomEGL.c b/src/newt/native/BroadcomEGL.c new file mode 100644 index 000000000..0cca90420 --- /dev/null +++ b/src/newt/native/BroadcomEGL.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#ifdef _WIN32 + #include <windows.h> +#else + #include <inttypes.h> +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "jogamp_newt_opengl_broadcom_egl_Window.h" + +#include "MouseEvent.h" +#include "KeyEvent.h" + +#include <EGL/egl.h> + +typedef unsigned int GLuint; + +EGLDisplay EGLUtil_CreateDisplayByNative( GLuint uiWidth, GLuint uiHeight ); +void EGLUtil_DestroyDisplay( EGLDisplay eglDisplay ); + +EGLSurface EGLUtil_CreateWindowByNative( EGLDisplay eglDisplay, /* bool */ GLuint bChromakey, GLuint *puiWidth, GLuint *puiHeight ); +void EGLUtil_DestroyWindow( EGLDisplay eglDisplay, EGLSurface eglSurface ); +void EGLUtil_SwapWindow( EGLDisplay eglDisplay, EGLSurface eglSurface ); + +#define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(...) fprintf(stdout, __VA_ARGS__) +#else + #define DBG_PRINT(...) +#endif + +static jmethodID windowCreatedID = NULL; + +/** + * Display + */ + +JNIEXPORT void JNICALL Java_jogamp_newt_opengl_broadcom_egl_Display_DispatchMessages + (JNIEnv *env, jobject obj) +{ + // FIXME: n/a + (void) env; + (void) obj; +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_opengl_broadcom_egl_Display_CreateDisplay + (JNIEnv *env, jobject obj, jint width, jint height) +{ + (void) env; + (void) obj; + EGLDisplay dpy = EGLUtil_CreateDisplayByNative( (GLuint) width, (GLuint) height ); + if(NULL==dpy) { + fprintf(stderr, "[CreateDisplay] failed: NULL\n"); + } else { + DBG_PRINT( "[CreateDisplay] ok: %p, %ux%u\n", dpy, width, height); + } + return (jlong) (intptr_t) dpy; +} + +JNIEXPORT void JNICALL Java_jogamp_newt_opengl_broadcom_egl_Display_DestroyDisplay + (JNIEnv *env, jobject obj, jlong display) +{ + EGLDisplay dpy = (EGLDisplay)(intptr_t)display; + (void) env; + (void) obj; + DBG_PRINT( "[DestroyDisplay] dpy %p\n", dpy); + + EGLUtil_DestroyDisplay(dpy); + + DBG_PRINT( "[DestroyDisplay] X\n"); +} + +/** + * Window + */ + +JNIEXPORT jboolean JNICALL Java_jogamp_newt_opengl_broadcom_egl_Window_initIDs + (JNIEnv *env, jclass clazz) +{ + windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(III)V"); + if (windowCreatedID == NULL) { + DBG_PRINT( "initIDs failed\n" ); + return JNI_FALSE; + } + DBG_PRINT( "initIDs ok\n" ); + return JNI_TRUE; +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_opengl_broadcom_egl_Window_CreateWindow + (JNIEnv *env, jobject obj, jlong display, jboolean chromaKey, jint width, jint height) +{ + EGLDisplay dpy = (EGLDisplay)(intptr_t)display; + EGLSurface window = 0; + GLuint uiWidth=(GLuint)width, uiHeight=(GLuint)height; + + if(dpy==NULL) { + fprintf(stderr, "[RealizeWindow] invalid display connection..\n"); + return 0; + } + DBG_PRINT( "[RealizeWindow.Create] dpy %p %ux%u\n", dpy, uiWidth, uiHeight); + + window = EGLUtil_CreateWindowByNative( dpy, chromaKey, &uiWidth, &uiHeight ); + + if(NULL==window) { + fprintf(stderr, "[RealizeWindow.Create] failed: NULL\n"); + return 0; + } + EGLint cfgID=0; + if(EGL_FALSE==eglQuerySurface(dpy, window, EGL_CONFIG_ID, &cfgID)) { + fprintf(stderr, "[RealizeWindow.ConfigID] failed: window %p\n", window); + EGLUtil_DestroyWindow(dpy, window); + return 0; + } + (*env)->CallVoidMethod(env, obj, windowCreatedID, (jint) cfgID, (jint)uiWidth, (jint)uiHeight); + DBG_PRINT( "[RealizeWindow.Create] ok: win %p, cfgid %d, %ux%u\n", window, cfgID, uiWidth, uiHeight); + + // release and destroy already made context .. + EGLContext ctx = eglGetCurrentContext(); + DBG_PRINT( "[RealizeWindow.Create] ctx %p - KEEP ALIVE \n", ctx); + /*eglMakeCurrent(dpy, + EGL_NO_SURFACE, + EGL_NO_SURFACE, + EGL_NO_CONTEXT); */ + DBG_PRINT( "[RealizeWindow.Create] 2\n"); + // eglDestroyContext(dpy, ctx); // culprit ? FIXME ? + DBG_PRINT( "[RealizeWindow.Create] 2 - eglDestroyContext - DISABLED - Duh ?\n"); + + DBG_PRINT( "[RealizeWindow.Create] X\n"); + + return (jlong) (intptr_t) window; +} + +JNIEXPORT void JNICALL Java_jogamp_newt_opengl_broadcom_egl_Window_CloseWindow + (JNIEnv *env, jobject obj, jlong display, jlong window) +{ + EGLDisplay dpy = (EGLDisplay) (intptr_t) display; + EGLSurface surf = (EGLSurface) (intptr_t) window; + + DBG_PRINT( "[CloseWindow] dpy %p, win %p\n", dpy, surf); + + EGLUtil_DestroyWindow(dpy, surf); + + DBG_PRINT( "[CloseWindow] X\n"); +} + +JNIEXPORT void JNICALL Java_jogamp_newt_opengl_broadcom_egl_Window_SwapWindow + (JNIEnv *env, jobject obj, jlong display, jlong window) +{ + EGLDisplay dpy = (EGLDisplay) (intptr_t) display; + EGLSurface surf = (EGLSurface) (intptr_t) window; + + DBG_PRINT( "[SwapWindow] dpy %p, win %p\n", dpy, surf); + + EGLUtil_SwapWindow( dpy, surf ); + + DBG_PRINT( "[SwapWindow] X\n"); +} + diff --git a/src/newt/native/InputEvent.h b/src/newt/native/InputEvent.h new file mode 100644 index 000000000..b42c06d21 --- /dev/null +++ b/src/newt/native/InputEvent.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#ifndef _INPUT_EVENT_H_ +#define _INPUT_EVENT_H_ + +#define EVENT_SHIFT_MASK 1 +#define EVENT_CTRL_MASK 2 +#define EVENT_META_MASK 4 +#define EVENT_ALT_MASK 8 +#define EVENT_ALT_GRAPH_MASK 32 +#define EVENT_BUTTON1_MASK (1<<6) +#define EVENT_BUTTON2_MASK (1<<7) +#define EVENT_BUTTON3_MASK (1<<8) + +#endif diff --git a/src/newt/native/IntelGDL.c b/src/newt/native/IntelGDL.c new file mode 100644 index 000000000..953181ccc --- /dev/null +++ b/src/newt/native/IntelGDL.c @@ -0,0 +1,401 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#include <inttypes.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "jogamp_newt_intel_gdl_Display.h" +#include "jogamp_newt_intel_gdl_Screen.h" +#include "jogamp_newt_intel_gdl_Window.h" + +#include "MouseEvent.h" +#include "KeyEvent.h" + +#include <gdl.h> +#include <gdl_version.h> + +#define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(...) fprintf(stdout, "*** INTEL-GDL: " __VA_ARGS__) +#else + #define DBG_PRINT(...) +#endif + +static jmethodID screenCreatedID = NULL; +static jmethodID updateBoundsID = NULL; + +#define NUM_PLANES 5 +static jobject newtWindows[NUM_PLANES] = { NULL, NULL, NULL, NULL, NULL } ; +static gdl_plane_id_t planes[NUM_PLANES] = { GDL_PLANE_ID_UPP_A, GDL_PLANE_ID_UPP_B, GDL_PLANE_ID_UPP_C, GDL_PLANE_ID_UPP_D, GDL_PLANE_ID_UPP_E }; + +static int getWindowIdx(jobject win) { + int i; + for(i=0; i<NUM_PLANES && newtWindows[i]!=win; i++) ; + return (i<NUM_PLANES)?i:-1; +} +static int getPlaneIdx(gdl_plane_id_t plane) { + int i; + for(i=0; i<NUM_PLANES && planes[i]!=plane; i++) ; + return (i<NUM_PLANES)?i:-1; +} + +static jobject getNewtWindow(gdl_plane_id_t plane) { + int idx = getPlaneIdx(plane); + if(idx>0) { + return newtWindows[idx]; + } + return NULL; +} +static gdl_plane_id_t getPlane(jobject win) { + int idx = getWindowIdx(win); + if(idx>0) { + return planes[idx]; + } + return GDL_PLANE_ID_UNDEFINED; +} + +static gdl_plane_id_t allocPlane(JNIEnv *env, jobject newtWindow) { + int i = getWindowIdx(NULL); + if (i<NUM_PLANES) { + newtWindows[i] = (*env)->NewGlobalRef(env, newtWindow); + return planes[i]; + } + return GDL_PLANE_ID_UNDEFINED; +} +static void freePlane(JNIEnv *env, gdl_plane_id_t plane) { + int i = getPlaneIdx(plane); + if (i<NUM_PLANES) { + if(NULL!=newtWindows[i]) { + (*env)->DeleteGlobalRef(env, newtWindows[i]); + newtWindows[i] = NULL;; + } + } +} + +static void JNI_ThrowNew(JNIEnv *env, const char *throwable, const char* message) { + jclass throwableClass = (*env)->FindClass(env, throwable); + if (throwableClass == NULL) { + (*env)->FatalError(env, "Failed to load throwable class"); + } + + if ((*env)->ThrowNew(env, throwableClass, message) != 0) { + (*env)->FatalError(env, "Failed to throw throwable"); + } +} + + +/** + * Display + */ + +JNIEXPORT void JNICALL Java_jogamp_newt_intel_gdl_Display_DispatchMessages + (JNIEnv *env, jobject obj, jlong displayHandle, jobject focusedWindow) +{ + // FIXME: n/a + (void) env; + (void) obj; + (void) displayHandle; + /** + gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; + jobject newtWin = getNewtWindow(plane); + if(NULL!=newtWin) { + // here we can dispatch messages .. etc + } */ +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_intel_gdl_Display_CreateDisplay + (JNIEnv *env, jobject obj) +{ + gdl_ret_t retval; + gdl_driver_info_t * p_driver_info = NULL; + + (void) env; + (void) obj; + + DBG_PRINT("[CreateDisplay]\n"); + + retval = gdl_init(0); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_init"); + return (jlong)0; + } + + p_driver_info = calloc(sizeof(gdl_driver_info_t), 1); + retval = gdl_get_driver_info(p_driver_info); + if (retval != GDL_SUCCESS) { + free(p_driver_info); + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_get_driver_info"); + return (jlong)0; + } + DBG_PRINT("[gdl_get_driver_info: major %d minor %d vers %d build %d flags %x name %s size %d avail %d]\n", + p_driver_info->header_version_major, p_driver_info->header_version_minor, + p_driver_info->gdl_version, p_driver_info->build_tag, p_driver_info->flags, + p_driver_info->name, p_driver_info->mem_size, p_driver_info->mem_avail); + + + return (jlong) (intptr_t) p_driver_info; +} + +JNIEXPORT void JNICALL Java_jogamp_newt_intel_gdl_Display_DestroyDisplay + (JNIEnv *env, jobject obj, jlong displayHandle) +{ + gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; + (void) env; + (void) obj; + + if(NULL!=p_driver_info) { + gdl_close(); + free(p_driver_info); + } + + DBG_PRINT("[DestroyDisplay] X\n"); +} + +/** + * Screen + */ + +JNIEXPORT jboolean JNICALL Java_jogamp_newt_intel_gdl_Screen_initIDs + (JNIEnv *env, jclass clazz) +{ + screenCreatedID = (*env)->GetMethodID(env, clazz, "screenCreated", "(II)V"); + if (screenCreatedID == NULL) { + DBG_PRINT("initIDs failed\n" ); + return JNI_FALSE; + } + DBG_PRINT("initIDs ok\n" ); + return JNI_TRUE; +} + +JNIEXPORT void JNICALL Java_jogamp_newt_intel_gdl_Screen_GetScreenInfo + (JNIEnv *env, jobject obj, jlong displayHandle, jint idx) +{ + gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; + gdl_display_info_t display_info; + gdl_display_id_t id; + gdl_ret_t retval; + + switch(idx) { + case 1: + id = GDL_DISPLAY_ID_1; + break; + default: + id = GDL_DISPLAY_ID_0; + } + + retval = gdl_get_display_info(id, &display_info); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_get_display_info"); + return; + } + + DBG_PRINT("[gdl_get_display_info: width %d height %d]\n", + display_info.tvmode.width, display_info.tvmode.height); + + (*env)->CallVoidMethod(env, obj, screenCreatedID, (jint)display_info.tvmode.width, (jint)display_info.tvmode.height); +} + +/** + * Window + */ + +JNIEXPORT jboolean JNICALL Java_jogamp_newt_intel_gdl_Window_initIDs + (JNIEnv *env, jclass clazz) +{ + updateBoundsID = (*env)->GetMethodID(env, clazz, "updateBounds", "(IIII)V"); + if (updateBoundsID == NULL) { + DBG_PRINT("initIDs failed\n" ); + return JNI_FALSE; + } + DBG_PRINT("initIDs ok\n" ); + return JNI_TRUE; +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_intel_gdl_Window_CreateSurface + (JNIEnv *env, jobject obj, jlong displayHandle, jint scr_width, jint scr_height, jint x, jint y, jint width, jint height) { + + gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; + gdl_ret_t retval; + gdl_pixel_format_t pixelFormat = GDL_PF_ARGB_32; + gdl_color_space_t colorSpace = GDL_COLOR_SPACE_RGB; + gdl_rectangle_t srcRect, dstRect; + + (void) env; + (void) obj; + + gdl_plane_id_t plane = allocPlane(env, obj); + if(plane == GDL_PLANE_ID_UNDEFINED) { + DBG_PRINT("CreateSurface failed, couldn't alloc plane\n" ); + return 0; + } + + DBG_PRINT("[CreateSurface: screen %dx%d, win %d/%d %dx%d plane %d]\n", + scr_width, scr_height, x, y, width, height, plane); + + /** Overwrite - TEST - Check semantics of dstRect! + x = 0; + y = 0; + width = scr_width; + height = scr_height; */ + + srcRect.origin.x = x; + srcRect.origin.y = y; + srcRect.width = width; + srcRect.height = height; + + dstRect.origin.x = x; + dstRect.origin.y = y; + dstRect.width = width; + dstRect.height = height; + + retval = gdl_plane_reset(plane); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_reset"); + freePlane(env, plane); + return (jlong)0; + } + + retval = gdl_plane_config_begin(plane); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_config_begin"); + freePlane(env, plane); + return (jlong)0; + } + + retval = gdl_plane_set_attr(GDL_PLANE_SRC_COLOR_SPACE, &colorSpace); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_set_attr color space"); + freePlane(env, plane); + return (jlong)0; + } + + retval = gdl_plane_set_attr(GDL_PLANE_PIXEL_FORMAT, &pixelFormat); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_set_attr pixel format"); + freePlane(env, plane); + return (jlong)0; + } + + retval = gdl_plane_set_attr(GDL_PLANE_DST_RECT, &dstRect); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_set_attr dstRect"); + freePlane(env, plane); + return (jlong)0; + } + + retval = gdl_plane_set_attr(GDL_PLANE_SRC_RECT, &srcRect); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_set_attr srcRect"); + freePlane(env, plane); + return (jlong)0; + } + + retval = gdl_plane_config_end(GDL_FALSE); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_config_end"); + freePlane(env, plane); + return (jlong)0; + } + + (*env)->CallVoidMethod(env, obj, updateBoundsID, (jint)x, (jint)y, (jint)width, (jint)height); + + DBG_PRINT("[CreateSurface] returning plane %d\n", plane); + + return (jlong) (intptr_t) plane; +} + +JNIEXPORT void JNICALL Java_jogamp_newt_intel_gdl_Window_CloseSurface + (JNIEnv *env, jobject obj, jlong display, jlong surface) +{ + gdl_plane_id_t plane = (gdl_plane_id_t) (intptr_t) surface ; + freePlane(env, plane); + + DBG_PRINT("[CloseSurface] plane %d\n", plane); +} + +JNIEXPORT void JNICALL Java_jogamp_newt_intel_gdl_Window_SetBounds0 + (JNIEnv *env, jobject obj, jlong surface, jint scr_width, jint scr_height, jint x, jint y, jint width, jint height) { + + gdl_plane_id_t plane = (gdl_plane_id_t) (intptr_t) surface ; + gdl_ret_t retval; + gdl_rectangle_t srcRect, dstRect; + + (void) env; + (void) obj; + + DBG_PRINT("[SetBounds0: screen %dx%d, win %d/%d %dx%d plane %d]\n", + scr_width, scr_height, x, y, width, height, plane); + + srcRect.origin.x = x; + srcRect.origin.y = y; + srcRect.width = width; + srcRect.height = height; + + dstRect.origin.x = x; + dstRect.origin.y = y; + dstRect.width = width; + dstRect.height = height; + + retval = gdl_plane_config_begin(plane); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_config_begin"); + return; + } + + retval = gdl_plane_set_attr(GDL_PLANE_DST_RECT, &dstRect); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_set_attr dstRect"); + return; + } + + retval = gdl_plane_set_attr(GDL_PLANE_SRC_RECT, &srcRect); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_set_attr srcRect"); + return; + } + + retval = gdl_plane_config_end(GDL_FALSE); + if (retval != GDL_SUCCESS) { + JNI_ThrowNew(env, "java/lang/IllegalStateException", "gdl_plane_config_end"); + return; + } + + (*env)->CallVoidMethod(env, obj, updateBoundsID, (jint)x, (jint)y, (jint)width, (jint)height); + + DBG_PRINT("[SetBounds0] returning plane %d\n", plane); +} + diff --git a/src/newt/native/KDWindow.c b/src/newt/native/KDWindow.c new file mode 100644 index 000000000..be0488fd1 --- /dev/null +++ b/src/newt/native/KDWindow.c @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#ifdef _WIN32 + #include <windows.h> +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#ifdef _WIN32 + /* This typedef is apparently needed for Microsoft compilers before VC8, + and on Windows CE */ + #if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1400 ) + #ifdef _WIN64 + typedef long long intptr_t; + #else + typedef int intptr_t; + #endif + #elif !defined(__MINGW64__) && _MSC_VER <= 1500 + #ifdef _WIN64 // [ + typedef __int64 intptr_t; + #else // _WIN64 ][ + typedef int intptr_t; + #endif // _WIN64 ] + #else + #include <inttypes.h> + #endif +#else + #include <inttypes.h> +#endif + +#include <KD/kd.h> + +#include "jogamp_newt_opengl_kd_KDWindow.h" + +#include "MouseEvent.h" +#include "KeyEvent.h" + +// #define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(...) fprintf(stdout, __VA_ARGS__) +#else + #define DBG_PRINT(...) +#endif + +#ifdef VERBOSE_ON + #ifdef _WIN32_WCE + #define STDOUT_FILE "\\Storage Card\\stdout.txt" + #define STDERR_FILE "\\Storage Card\\stderr.txt" + #endif +#endif + +#define JOGL_KD_USERDATA_MAGIC 0xDEADBEEF +typedef struct { + long magic; + KDWindow * kdWindow; + jobject javaWindow; +} JOGLKDUserdata; + +static jmethodID windowCreatedID = NULL; +static jmethodID sizeChangedID = NULL; +static jmethodID visibleChangedID = NULL; +static jmethodID windowDestroyNotifyID = NULL; +static jmethodID sendMouseEventID = NULL; +static jmethodID sendKeyEventID = NULL; + +/** + * Display + */ + +JNIEXPORT void JNICALL Java_jogamp_newt_opengl_kd_KDDisplay_DispatchMessages + (JNIEnv *env, jobject obj) +{ + const KDEvent * evt; + int numEvents = 0; + + // Periodically take a break + while( numEvents<100 && NULL!=(evt=kdWaitEvent(0)) ) { + KDWindow *kdWindow; + jobject javaWindow; + JOGLKDUserdata * userData = (JOGLKDUserdata *)(intptr_t)evt->userptr; + if(NULL == userData || userData->magic!=JOGL_KD_USERDATA_MAGIC) { + DBG_PRINT( "event unrelated: evt type: 0x%X\n", evt->type); + continue; + } + kdWindow = userData->kdWindow; + javaWindow = userData->javaWindow; + DBG_PRINT( "[DispatchMessages]: userData %p, evt type: 0x%X\n", userData, evt->type); + + numEvents++; + + // FIXME: support resize and window re-positioning events + + switch(evt->type) { + case KD_EVENT_WINDOW_FOCUS: + { + KDboolean hasFocus; + kdGetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_FOCUS, &hasFocus); + DBG_PRINT( "event window focus : src: %p\n", userData); + } + break; + case KD_EVENT_WINDOW_CLOSE: + { + DBG_PRINT( "event window close : src: %p\n", userData); + (*env)->CallVoidMethod(env, javaWindow, windowDestroyNotifyID); + } + break; + case KD_EVENT_WINDOWPROPERTY_CHANGE: + { + const KDEventWindowProperty* prop = &evt->data.windowproperty; + switch (prop->pname) { + case KD_WINDOWPROPERTY_SIZE: + { + KDint32 v[2]; + if(!kdGetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_SIZE, v)) { + DBG_PRINT( "event window size change : src: %p %dx%d\n", userData, v[0], v[1]); + (*env)->CallVoidMethod(env, javaWindow, sizeChangedID, (jint) v[0], (jint) v[1], JNI_FALSE); + } else { + DBG_PRINT( "event window size change error: src: %p %dx%d\n", userData, v[0], v[1]); + } + } + break; + case KD_WINDOWPROPERTY_FOCUS: + DBG_PRINT( "event window focus: src: %p\n", userData); + break; + case KD_WINDOWPROPERTY_VISIBILITY: + { + KDboolean visible; + kdGetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visible); + DBG_PRINT( "event window visibility: src: %p, v:%d\n", userData, visible); + (*env)->CallVoidMethod(env, javaWindow, visibleChangedID, visible?JNI_TRUE:JNI_FALSE); + } + break; + default: + break; + } + } + break; + case KD_EVENT_INPUT_POINTER: + { + const KDEventInputPointer* ptr = &(evt->data.inputpointer); + // button idx: evt->data.input.index + // pressed = ev->data.input.value.i + // time = ev->timestamp + if(KD_INPUT_POINTER_SELECT==ptr->index) { + DBG_PRINT( "event mouse click: src: %p, s:%d, (%d,%d)\n", userData, ptr->select, ptr->x, ptr->y); + (*env)->CallVoidMethod(env, javaWindow, sendMouseEventID, + (ptr->select==0) ? (jint) EVENT_MOUSE_RELEASED : (jint) EVENT_MOUSE_PRESSED, + (jint) 0, + (jint) ptr->x, (jint) ptr->y, 1, 0); + } else { + DBG_PRINT( "event mouse: src: %d, s:%p, i:0x%X (%d,%d)\n", userData, ptr->select, ptr->index, ptr->x, ptr->y); + (*env)->CallVoidMethod(env, javaWindow, sendMouseEventID, (jint) EVENT_MOUSE_MOVED, + 0, + (jint) ptr->x, (jint) ptr->y, 0, 0); + } + } + break; + } + } +} + +/** + * Window + */ + +JNIEXPORT jboolean JNICALL Java_jogamp_newt_opengl_kd_KDWindow_initIDs + (JNIEnv *env, jclass clazz) +{ +#ifdef VERBOSE_ON + #ifdef _WIN32_WCE + _wfreopen(TEXT(STDOUT_FILE),L"w",stdout); + _wfreopen(TEXT(STDERR_FILE),L"w",stderr); + #endif +#endif + windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(J)V"); + sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(IIZ)V"); + visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V"); + windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V"); + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V"); + sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + if (windowCreatedID == NULL || + sizeChangedID == NULL || + visibleChangedID == NULL || + windowDestroyNotifyID == NULL || + sendMouseEventID == NULL || + sendKeyEventID == NULL) { + DBG_PRINT( "initIDs failed\n" ); + return JNI_FALSE; + } + DBG_PRINT( "initIDs ok\n" ); + return JNI_TRUE; +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_opengl_kd_KDWindow_CreateWindow + (JNIEnv *env, jobject obj, jlong display, jintArray jAttrs) +{ + jint * attrs = NULL; + jsize attrsLen; + EGLDisplay dpy = (EGLDisplay)(intptr_t)display; + KDWindow *window = 0; + + if(dpy==NULL) { + fprintf(stderr, "[CreateWindow] invalid display connection..\n"); + return 0; + } + + attrsLen = (*env)->GetArrayLength(env, jAttrs); + if(0==attrsLen) { + fprintf(stderr, "[CreateWindow] attribute array size 0..\n"); + return 0; + } + attrs = (*env)->GetIntArrayElements(env, jAttrs, 0); + if(NULL==attrs) { + fprintf(stderr, "[CreateWindow] attribute array NULL..\n"); + return 0; + } + + JOGLKDUserdata * userData = kdMalloc(sizeof(JOGLKDUserdata)); + userData->magic = JOGL_KD_USERDATA_MAGIC; + window = kdCreateWindow(dpy, attrs, (void *)userData); + + (*env)->ReleaseIntArrayElements(env, jAttrs, attrs, 0); + + if(NULL==window) { + kdFree(userData); + fprintf(stderr, "[CreateWindow] failed: 0x%X\n", kdGetError()); + } else { + userData->javaWindow = (*env)->NewGlobalRef(env, obj); + userData->kdWindow = window; + (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) userData); + DBG_PRINT( "[CreateWindow] ok: %p, userdata %p\n", window, userData); + } + return (jlong) (intptr_t) window; +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_opengl_kd_KDWindow_RealizeWindow + (JNIEnv *env, jobject obj, jlong window) +{ + KDWindow *w = (KDWindow*) (intptr_t) window; + EGLNativeWindowType nativeWindow=0; + + jint res = kdRealizeWindow(w, &nativeWindow); + if(res) { + fprintf(stderr, "[RealizeWindow] failed: 0x%X, 0x%X\n", res, kdGetError()); + nativeWindow = NULL; + } + DBG_PRINT( "[RealizeWindow] ok: %p\n", nativeWindow); + return (jlong) (intptr_t) nativeWindow; +} + +JNIEXPORT jint JNICALL Java_jogamp_newt_opengl_kd_KDWindow_CloseWindow + (JNIEnv *env, jobject obj, jlong window, jlong juserData) +{ + KDWindow *w = (KDWindow*) (intptr_t) window; + JOGLKDUserdata * userData = (JOGLKDUserdata*) (intptr_t) juserData; + int res = kdDestroyWindow(w); + (*env)->DeleteGlobalRef(env, userData->javaWindow); + kdFree(userData); + + DBG_PRINT( "[CloseWindow] res: %d\n", res); + return res; +} + +/* + * Class: jogamp_newt_opengl_kd_KDWindow + * Method: setVisible0 + * Signature: (JJZ)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_opengl_kd_KDWindow_setVisible0 + (JNIEnv *env, jobject obj, jlong window, jboolean visible) +{ + KDWindow *w = (KDWindow*) (intptr_t) window; + KDboolean v = (visible==JNI_TRUE)?KD_TRUE:KD_FALSE; + kdSetWindowPropertybv(w, KD_WINDOWPROPERTY_VISIBILITY, &v); + DBG_PRINT( "[setVisible] v=%d\n", visible); + (*env)->CallVoidMethod(env, obj, visibleChangedID, visible); // FIXME: or send via event ? +} + +JNIEXPORT void JNICALL Java_jogamp_newt_opengl_kd_KDWindow_setFullScreen0 + (JNIEnv *env, jobject obj, jlong window, jboolean fullscreen) +{ +/** not supported, due to missing NV property .. + KDWindow *w = (KDWindow*) (intptr_t) window; + KDboolean v = fullscreen; + + int res = kdSetWindowPropertybv(w, KD_WINDOWPROPERTY_FULLSCREEN_NV, &v); + DBG_PRINT( "[setFullScreen] v=%d, res=%d\n", fullscreen, res); + (void)res; +*/ + (void)env; + (void)obj; + (void)window; + (void)fullscreen; +} + +JNIEXPORT void JNICALL Java_jogamp_newt_opengl_kd_KDWindow_setSize0 + (JNIEnv *env, jobject obj, jlong window, jint width, jint height) +{ + KDWindow *w = (KDWindow*) (intptr_t) window; + KDint32 v[] = { width, height }; + + int res = kdSetWindowPropertyiv(w, KD_WINDOWPROPERTY_SIZE, v); + DBG_PRINT( "[setSize] v=%dx%d, res=%d\n", width, height, res); + (void)res; + + (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height, JNI_FALSE); +} + diff --git a/src/newt/native/KeyEvent.h b/src/newt/native/KeyEvent.h new file mode 100644 index 000000000..1ead0f5e8 --- /dev/null +++ b/src/newt/native/KeyEvent.h @@ -0,0 +1,200 @@ + +#ifndef _KEY_EVENT_H_ +#define _KEY_EVENT_H_ + +#define EVENT_KEY_PRESSED 300 +#define EVENT_KEY_RELEASED 301 +#define EVENT_KEY_TYPED 302 + +#define J_CHAR_UNDEFINED 0xFFFF; +#define J_VK_ENTER '\n' +#define J_VK_BACK_SPACE '\b' +#define J_VK_TAB '\t' +#define J_VK_CANCEL 0x03 +#define J_VK_CLEAR 0x0C +#define J_VK_SHIFT 0x10 +#define J_VK_CONTROL 0x11 +#define J_VK_ALT 0x12 +#define J_VK_PAUSE 0x13 +#define J_VK_CAPS_LOCK 0x14 +#define J_VK_ESCAPE 0x1B +#define J_VK_SPACE 0x20 +#define J_VK_PAGE_UP 0x21 +#define J_VK_PAGE_DOWN 0x22 +#define J_VK_END 0x23 +#define J_VK_HOME 0x24 +#define J_VK_LEFT 0x25 +#define J_VK_UP 0x26 +#define J_VK_RIGHT 0x27 +#define J_VK_DOWN 0x28 +#define J_VK_COMMA 0x2C +#define J_VK_MINUS 0x2D +#define J_VK_PERIOD 0x2E +#define J_VK_SLASH 0x2F +#define J_VK_0 0x30 +#define J_VK_1 0x31 +#define J_VK_2 0x32 +#define J_VK_3 0x33 +#define J_VK_4 0x34 +#define J_VK_5 0x35 +#define J_VK_6 0x36 +#define J_VK_7 0x37 +#define J_VK_8 0x38 +#define J_VK_9 0x39 +#define J_VK_SEMICOLON 0x3B +#define J_VK_EQUALS 0x3D +#define J_VK_A 0x41 +#define J_VK_B 0x42 +#define J_VK_C 0x43 +#define J_VK_D 0x44 +#define J_VK_E 0x45 +#define J_VK_F 0x46 +#define J_VK_G 0x47 +#define J_VK_H 0x48 +#define J_VK_I 0x49 +#define J_VK_J 0x4A +#define J_VK_K 0x4B +#define J_VK_L 0x4C +#define J_VK_M 0x4D +#define J_VK_N 0x4E +#define J_VK_O 0x4F +#define J_VK_P 0x50 +#define J_VK_Q 0x51 +#define J_VK_R 0x52 +#define J_VK_S 0x53 +#define J_VK_T 0x54 +#define J_VK_U 0x55 +#define J_VK_V 0x56 +#define J_VK_W 0x57 +#define J_VK_X 0x58 +#define J_VK_Y 0x59 +#define J_VK_Z 0x5A +#define J_VK_OPEN_BRACKET 0x5B +#define J_VK_BACK_SLASH 0x5C +#define J_VK_CLOSE_BRACKET 0x5D +#define J_VK_NUMPAD0 0x60 +#define J_VK_NUMPAD1 0x61 +#define J_VK_NUMPAD2 0x62 +#define J_VK_NUMPAD3 0x63 +#define J_VK_NUMPAD4 0x64 +#define J_VK_NUMPAD5 0x65 +#define J_VK_NUMPAD6 0x66 +#define J_VK_NUMPAD7 0x67 +#define J_VK_NUMPAD8 0x68 +#define J_VK_NUMPAD9 0x69 +#define J_VK_MULTIPLY 0x6A +#define J_VK_ADD 0x6B +#define J_VK_SEPARATOR 0x6C +#define J_VK_SUBTRACT 0x6D +#define J_VK_DECIMAL 0x6E +#define J_VK_DIVIDE 0x6F +#define J_VK_DELETE 0x7F /* ASCII DEL */ +#define J_VK_NUM_LOCK 0x90 +#define J_VK_SCROLL_LOCK 0x91 +#define J_VK_F1 0x70 +#define J_VK_F2 0x71 +#define J_VK_F3 0x72 +#define J_VK_F4 0x73 +#define J_VK_F5 0x74 +#define J_VK_F6 0x75 +#define J_VK_F7 0x76 +#define J_VK_F8 0x77 +#define J_VK_F9 0x78 +#define J_VK_F10 0x79 +#define J_VK_F11 0x7A +#define J_VK_F12 0x7B +#define J_VK_F13 0xF000 +#define J_VK_F14 0xF001 +#define J_VK_F15 0xF002 +#define J_VK_F16 0xF003 +#define J_VK_F17 0xF004 +#define J_VK_F18 0xF005 +#define J_VK_F19 0xF006 +#define J_VK_F20 0xF007 +#define J_VK_F21 0xF008 +#define J_VK_F22 0xF009 +#define J_VK_F23 0xF00A +#define J_VK_F24 0xF00B +#define J_VK_PRINTSCREEN 0x9A +#define J_VK_INSERT 0x9B +#define J_VK_HELP 0x9C +#define J_VK_META 0x9D +#define J_VK_BACK_QUOTE 0xC0 +#define J_VK_QUOTE 0xDE +#define J_VK_KP_UP 0xE0 +#define J_VK_KP_DOWN 0xE1 +#define J_VK_KP_LEFT 0xE2 +#define J_VK_KP_RIGHT 0xE3 +#define J_VK_DEAD_GRAVE 0x80 +#define J_VK_DEAD_ACUTE 0x81 +#define J_VK_DEAD_CIRCUMFLEX 0x82 +#define J_VK_DEAD_TILDE 0x83 +#define J_VK_DEAD_MACRON 0x84 +#define J_VK_DEAD_BREVE 0x85 +#define J_VK_DEAD_ABOVEDOT 0x86 +#define J_VK_DEAD_DIAERESIS 0x87 +#define J_VK_DEAD_ABOVERING 0x88 +#define J_VK_DEAD_DOUBLEACUTE 0x89 +#define J_VK_DEAD_CARON 0x8a +#define J_VK_DEAD_CEDILLA 0x8b +#define J_VK_DEAD_OGONEK 0x8c +#define J_VK_DEAD_IOTA 0x8d +#define J_VK_DEAD_VOICED_SOUND 0x8e +#define J_VK_DEAD_SEMIVOICED_SOUND 0x8f +#define J_VK_AMPERSAND 0x96 +#define J_VK_ASTERISK 0x97 +#define J_VK_QUOTEDBL 0x98 +#define J_VK_LESS 0x99 +#define J_VK_GREATER 0xa0 +#define J_VK_BRACELEFT 0xa1 +#define J_VK_BRACERIGHT 0xa2 +#define J_VK_AT 0x0200 +#define J_VK_COLON 0x0201 +#define J_VK_CIRCUMFLEX 0x0202 +#define J_VK_DOLLAR 0x0203 +#define J_VK_EURO_SIGN 0x0204 +#define J_VK_EXCLAMATION_MARK 0x0205 +#define J_VK_INVERTED_EXCLAMATION_MARK 0x0206 +#define J_VK_LEFT_PARENTHESIS 0x0207 +#define J_VK_NUMBER_SIGN 0x0208 +#define J_VK_PLUS 0x0209 +#define J_VK_RIGHT_PARENTHESIS 0x020A +#define J_VK_UNDERSCORE 0x020B +#define J_VK_WINDOWS 0x020C +#define J_VK_CONTEXT_MENU 0x020D +#define J_VK_FINAL 0x0018 +#define J_VK_CONVERT 0x001C +#define J_VK_NONCONVERT 0x001D +#define J_VK_ACCEPT 0x001E +#define J_VK_MODECHANGE 0x001F +#define J_VK_KANA 0x0015 +#define J_VK_KANJI 0x0019 +#define J_VK_ALPHANUMERIC 0x00F0 +#define J_VK_KATAKANA 0x00F1 +#define J_VK_HIRAGANA 0x00F2 +#define J_VK_FULL_WIDTH 0x00F3 +#define J_VK_HALF_WIDTH 0x00F4 +#define J_VK_ROMAN_CHARACTERS 0x00F5 +#define J_VK_ALL_CANDIDATES 0x0100 +#define J_VK_PREVIOUS_CANDIDATE 0x0101 +#define J_VK_CODE_INPUT 0x0102 +#define J_VK_JAPANESE_KATAKANA 0x0103 +#define J_VK_JAPANESE_HIRAGANA 0x0104 +#define J_VK_JAPANESE_ROMAN 0x0105 +#define J_VK_KANA_LOCK 0x0106 +#define J_VK_INPUT_METHOD_ON_OFF 0x0107 +#define J_VK_CUT 0xFFD1 +#define J_VK_COPY 0xFFCD +#define J_VK_PASTE 0xFFCF +#define J_VK_UNDO 0xFFCB +#define J_VK_AGAIN 0xFFC9 +#define J_VK_FIND 0xFFD0 +#define J_VK_PROPS 0xFFCA +#define J_VK_STOP 0xFFC8 +#define J_VK_COMPOSE 0xFF20 +#define J_VK_ALT_GRAPH 0xFF7E +#define J_VK_BEGIN 0xFF58 +#define J_VK_UNDEFINED 0x0 + +#endif + diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m new file mode 100644 index 000000000..3b708acce --- /dev/null +++ b/src/newt/native/MacWindow.m @@ -0,0 +1,504 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#import <inttypes.h> + +#import "jogamp_newt_macosx_MacWindow.h" +#import "NewtMacWindow.h" + +#import "MouseEvent.h" +#import "KeyEvent.h" + +#import <ApplicationServices/ApplicationServices.h> + +#import <stdio.h> + +NSString* jstringToNSString(JNIEnv* env, jstring jstr) +{ + const jchar* jstrChars = (*env)->GetStringChars(env, jstr, NULL); + NSString* str = [[NSString alloc] initWithCharacters: jstrChars length: (*env)->GetStringLength(env, jstr)]; + (*env)->ReleaseStringChars(env, jstr, jstrChars); + return str; +} + +void setFrameTopLeftPoint(NSWindow* pwin, NSWindow* win, jint x, jint y) +{ + NSScreen* screen = [NSScreen mainScreen]; + + // this allows for better compatibility with awt behavior + NSRect visibleRect; // either screen or parent-window + NSPoint pt; + int d_pty=0; // parent titlebar height + int d_ptx=0; + + if(NULL==pwin) { + visibleRect = [screen frame]; + } else { + visibleRect = [pwin frame]; + NSView* pview = [pwin contentView]; + NSRect viewRect = [pview frame]; + d_pty = visibleRect.size.height - viewRect.size.height; + (void) d_ptx; + //d_pty = visibleRect.origin.y - viewRect.size.height; + //d_ptx = visibleRect.size.height - viewRect.size.height; + fprintf(stderr, "pwin %lf/%lf %lfx%lf, pview %lf/%lf %lfx%lf -> %d/%d\n", + visibleRect.origin.x, + visibleRect.origin.y, + visibleRect.size.width, + visibleRect.size.height, + viewRect.origin.x, + viewRect.origin.y, + viewRect.size.width, + viewRect.size.height, + (int)x, (int)y); + + } + + pt = NSMakePoint(visibleRect.origin.x + x, visibleRect.origin.y + visibleRect.size.height - y - d_pty); + + [win setFrameTopLeftPoint: pt]; +} + +static NewtView * changeContentView(JNIEnv *env, jobject javaWindowObject, NSWindow *pwin, NSWindow *win, NewtView *newView) { + NSView* oldNSView = [win contentView]; + NewtView* oldView = NULL; + + if(NULL!=oldNSView) { +NS_DURING + // Available >= 10.5 - Makes the menubar disapear + if([oldNSView isInFullScreenMode]) { + [oldNSView exitFullScreenModeWithOptions: NULL]; + } +NS_HANDLER +NS_ENDHANDLER + if( [oldNSView isMemberOfClass:[NewtView class]] ) { + oldView = (NewtView *) oldNSView; + + jobject globJavaWindowObject = [oldView getJavaWindowObject]; + (*env)->DeleteGlobalRef(env, globJavaWindowObject); + [oldView setJavaWindowObject: NULL]; + } + /** FIXME: Tried child window: auto clip or message reception .. + if(NULL!=pwin) { + [oldView removeFromSuperview]; + } */ + } + if(NULL!=newView) { + jobject globJavaWindowObject = (*env)->NewGlobalRef(env, javaWindowObject); + [newView setJavaWindowObject: globJavaWindowObject]; + [newView setJNIEnv: env]; + + /** FIXME: Tried child window: auto clip or message reception .. + if(NULL!=pwin) { + NSView* pview = [pwin contentView]; + [pview addSubview: newView]; + } */ + } + [win setContentView: newView]; + + // make sure the insets are updated in the java object + NewtMacWindow* newtw = (NewtMacWindow*)win; + [newtw updateInsets: env]; + + return oldView; +} + +/* + * Class: jogamp_newt_macosx_MacDisplay + * Method: initIDs + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_macosx_MacDisplay_initNSApplication0 + (JNIEnv *env, jclass clazz) +{ + static int initialized = 0; + + if(initialized) return JNI_TRUE; + initialized = 1; + + // This little bit of magic is needed in order to receive mouse + // motion events and allow key focus to be properly transferred. + // FIXME: are these Carbon APIs? They come from the + // ApplicationServices.framework. + ProcessSerialNumber psn; + if (GetCurrentProcess(&psn) == noErr) { + TransformProcessType(&psn, kProcessTransformToForegroundApplication); + SetFrontProcess(&psn); + } + + // Initialize the shared NSApplication instance + [NSApplication sharedApplication]; + + // Need this when debugging, as it is necessary to attach gdb to + // the running java process -- "gdb java" doesn't work + // printf("Going to sleep for 10 seconds\n"); + // sleep(10); + + return (jboolean) JNI_TRUE; +} + +/* + * Class: jogamp_newt_macosx_MacDisplay + * Method: dispatchMessages0 + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_macosx_MacDisplay_dispatchMessages0 + (JNIEnv *env, jobject unused) +{ + NSEvent* event = NULL; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + +NS_DURING + + int num_events = 0; + + // Periodically take a break + do { + // FIXME: ignoring event mask for the time being + event = [NSApp nextEventMatchingMask: NSAnyEventMask + untilDate: [NSDate distantPast] + inMode: NSDefaultRunLoopMode + dequeue: YES]; + if (event != NULL) { + [NSApp sendEvent: event]; + + num_events++; + } + } while (num_events<100 && event != NULL); + +NS_HANDLER + + // just ignore it .. + +NS_ENDHANDLER + + [pool release]; +} + +/* + * Class: jogamp_newt_macosx_MacScreen + * Method: getWidthImpl + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_jogamp_newt_macosx_MacScreen_getWidthImpl0 + (JNIEnv *env, jclass clazz, jint screen_idx) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + NSArray *screens = [NSScreen screens]; + if(screen_idx<0) screen_idx=0; + if(screen_idx>=[screens count]) screen_idx=0; + NSScreen *screen = (NSScreen *) [screens objectAtIndex: screen_idx]; + NSRect rect = [screen frame]; + + [pool release]; + + return (jint) (rect.size.width); +} + +/* + * Class: jogamp_newt_macosx_MacScreen + * Method: getHeightImpl + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_jogamp_newt_macosx_MacScreen_getHeightImpl0 + (JNIEnv *env, jclass clazz, jint screen_idx) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + NSArray *screens = [NSScreen screens]; + if(screen_idx<0) screen_idx=0; + if(screen_idx>=[screens count]) screen_idx=0; + NSScreen *screen = (NSScreen *) [screens objectAtIndex: screen_idx]; + NSRect rect = [screen frame]; + + [pool release]; + + return (jint) (rect.size.height); +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: initIDs + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_macosx_MacWindow_initIDs0 + (JNIEnv *env, jclass clazz) +{ + static int initialized = 0; + + if(initialized) return JNI_TRUE; + initialized = 1; + + // Need this when debugging, as it is necessary to attach gdb to + // the running java process -- "gdb java" doesn't work + // printf("Going to sleep for 10 seconds\n"); + // sleep(10); + + return (jboolean) [NewtMacWindow initNatives: env forClass: clazz]; +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: createWindow0 + * Signature: (JIIIIZIIIJ)J + */ +JNIEXPORT jlong JNICALL Java_jogamp_newt_macosx_MacWindow_createWindow0 + (JNIEnv *env, jobject jthis, jlong parent, jint x, jint y, jint w, jint h, jboolean fullscreen, jint styleMask, + jint bufferingType, jint screen_idx, jlong jview) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSRect rect = NSMakeRect(x, y, w, h); + + NSArray *screens = [NSScreen screens]; + if(screen_idx<0) screen_idx=0; + if(screen_idx>=[screens count]) screen_idx=0; + NSScreen *screen = (NSScreen *) [screens objectAtIndex: screen_idx]; + + if (fullscreen) { + styleMask = NSBorderlessWindowMask; + NSRect rect = [screen frame]; + w = (jint) (rect.size.width); + h = (jint) (rect.size.height); + } + + // Allocate the window + NSWindow* window = [[[NewtMacWindow alloc] initWithContentRect: rect + styleMask: (NSUInteger) styleMask + backing: (NSBackingStoreType) bufferingType + screen: screen] retain]; + + NSObject *nsParentObj = (NSObject*) ((intptr_t) parent); + NSWindow* parentWindow = NULL; + if( nsParentObj != NULL && [nsParentObj isKindOfClass:[NSWindow class]] ) { + parentWindow = (NSWindow*) nsParentObj; + } else if( nsParentObj != NULL && [nsParentObj isKindOfClass:[NSView class]] ) { + NSView* view = (NSView*) nsParentObj; + parentWindow = [view window]; + fprintf(stderr, "createWindow0 - Parent is NSView : %p -> %p (win) \n", nsParentObj, parentWindow); + } else { + fprintf(stderr, "createWindow0 - Parent is neither NSWindow nor NSView : %p\n", nsParentObj); + } + if(NULL!=parentWindow) { + [parentWindow addChildWindow: window ordered: NSWindowAbove]; + [window setParentWindow: parentWindow]; + } + + if (fullscreen) { + [window setOpaque: YES]; + } else { + // If the window is undecorated, assume we want the possibility of + // a shaped window, so make it non-opaque and the background color clear + if ((styleMask & NSTitledWindowMask) == 0) { + [window setOpaque: NO]; + [window setBackgroundColor: [NSColor clearColor]]; + } + } + + // Immediately re-position the window based on an upper-left coordinate system + setFrameTopLeftPoint(parentWindow, window, x, y); + + // specify we want mouse-moved events + [window setAcceptsMouseMovedEvents:YES]; + + // Use given NewtView or allocate an NewtView if NULL + NewtView* view = (0==jview)? [[NewtView alloc] initWithFrame: rect] : (NewtView*) ((intptr_t) jview) ; + + // Set the content view + (void) changeContentView(env, jthis, parentWindow, window, view); + +NS_DURING + // Available >= 10.5 - Makes the menubar disapear + if(fullscreen) { + [view enterFullScreenMode: screen withOptions:NULL]; + } +NS_HANDLER +NS_ENDHANDLER + + // Set the next responder to be the window so that we can forward + // right mouse button down events + [view setNextResponder: window]; + + [pool release]; + + return (jlong) ((intptr_t) window); +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: makeKeyAndOrderFront + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_macosx_MacWindow_makeKeyAndOrderFront0 + (JNIEnv *env, jobject unused, jlong window) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* win = (NSWindow*) ((intptr_t) window); + [win makeKeyAndOrderFront: win]; + [pool release]; +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: makeKey + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_macosx_MacWindow_makeKey0 + (JNIEnv *env, jobject unused, jlong window) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* win = (NSWindow*) ((intptr_t) window); + [win makeKeyWindow]; + [pool release]; +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: orderOut + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_macosx_MacWindow_orderOut0 + (JNIEnv *env, jobject unused, jlong window) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* win = (NSWindow*) ((intptr_t) window); + [win orderOut: win]; + [pool release]; +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: close0 + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_macosx_MacWindow_close0 + (JNIEnv *env, jobject unused, jlong window) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* win = (NSWindow*) ((intptr_t) window); + NSView* view = [win contentView]; + [win orderOut: win]; +NS_DURING + if(NULL!=view) { + // Available >= 10.5 - Makes the menubar disapear + if([view isInFullScreenMode]) { + [view exitFullScreenModeWithOptions: NULL]; + } + } +NS_HANDLER +NS_ENDHANDLER + [win close]; + [pool release]; +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: setTitle0 + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_macosx_MacWindow_setTitle0 + (JNIEnv *env, jobject unused, jlong window, jstring title) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* win = (NSWindow*) ((intptr_t) window); + NSString* str = jstringToNSString(env, title); + [str autorelease]; + [win setTitle: str]; + [pool release]; +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: contentView + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_jogamp_newt_macosx_MacWindow_contentView0 + (JNIEnv *env, jobject unused, jlong window) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* win = (NSWindow*) ((intptr_t) window); + jlong res = (jlong) ((intptr_t) [win contentView]); + [pool release]; + return res; +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: changeContentView + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_jogamp_newt_macosx_MacWindow_changeContentView0 + (JNIEnv *env, jobject jthis, jlong parent, jlong window, jlong jview) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* pwin = (NewtMacWindow*) ((intptr_t) parent); + NSWindow* win = (NewtMacWindow*) ((intptr_t) window); + NewtView* newView = (NewtView *) ((intptr_t) jview); + + NewtView* oldView = changeContentView(env, jthis, pwin, win, newView); + + [pool release]; + + return (jlong) ((intptr_t) oldView); +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: setContentSize + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_macosx_MacWindow_setContentSize0 + (JNIEnv *env, jobject unused, jlong window, jint w, jint h) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* win = (NSWindow*) ((intptr_t) window); + NSSize sz = NSMakeSize(w, h); + [win setContentSize: sz]; + [pool release]; +} + +/* + * Class: jogamp_newt_macosx_MacWindow + * Method: setFrameTopLeftPoint + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_macosx_MacWindow_setFrameTopLeftPoint0 + (JNIEnv *env, jobject unused, jlong parent, jlong window, jint x, jint y) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* pwin = (NSWindow*) ((intptr_t) parent); + NSWindow* win = (NSWindow*) ((intptr_t) window); + setFrameTopLeftPoint(pwin, win, x, y); + [pool release]; +} + diff --git a/src/newt/native/MouseEvent.h b/src/newt/native/MouseEvent.h new file mode 100644 index 000000000..e9c0476ef --- /dev/null +++ b/src/newt/native/MouseEvent.h @@ -0,0 +1,15 @@ + +#ifndef _MOUSE_EVENT_H_ +#define _MOUSE_EVENT_H_ + +// Generated by Java: EVENT_MOUSE_CLICKED = 200; +#define EVENT_MOUSE_ENTERED 201 +#define EVENT_MOUSE_EXITED 202 +#define EVENT_MOUSE_PRESSED 203 +#define EVENT_MOUSE_RELEASED 204 +#define EVENT_MOUSE_MOVED 205 +// can't find how to regenerate this file, adding manually +#define EVENT_MOUSE_WHEEL_MOVED 207 +// Generated by Java: EVENT_MOUSE_DRAGGED = 206; + +#endif diff --git a/src/newt/native/NewtCommon.c b/src/newt/native/NewtCommon.c new file mode 100644 index 000000000..0e3f99282 --- /dev/null +++ b/src/newt/native/NewtCommon.c @@ -0,0 +1,55 @@ + +#include "NewtCommon.h" + +static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException"; +static jclass runtimeExceptionClz=NULL; + +void NewtCommon_FatalError(JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + fprintf(stderr, "%s\n", buffer); + (*env)->FatalError(env, buffer); +} + +void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + (*env)->ThrowNew(env, runtimeExceptionClz, buffer); +} + +void NewtCommon_init(JNIEnv *env) { + if(NULL==runtimeExceptionClz) { + jclass c = (*env)->FindClass(env, ClazzNameRuntimeException); + if(NULL==c) { + NewtCommon_FatalError(env, "NEWT X11Window: can't find %s", ClazzNameRuntimeException); + } + runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==runtimeExceptionClz) { + NewtCommon_FatalError(env, "NEWT X11Window: can't use %s", ClazzNameRuntimeException); + } + } +} + +jchar* NewtCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str) +{ + jchar* strChars = NULL; + strChars = calloc((*env)->GetStringLength(env, str) + 1, sizeof(jchar)); + if (strChars != NULL) { + (*env)->GetStringRegion(env, str, 0, (*env)->GetStringLength(env, str), strChars); + } + return strChars; +} + diff --git a/src/newt/native/NewtCommon.h b/src/newt/native/NewtCommon.h new file mode 100644 index 000000000..f5835f7c8 --- /dev/null +++ b/src/newt/native/NewtCommon.h @@ -0,0 +1,15 @@ + +#ifndef NEWT_COMMON_H +#define NEWT_COMMON_H 1 + +#include <jni.h> +#include <stdlib.h> + +void NewtCommon_init(JNIEnv *env); + +jchar* NewtCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str); + +void NewtCommon_FatalError(JNIEnv *env, const char* msg, ...); +void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...); + +#endif diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h new file mode 100644 index 000000000..7f0cd60c6 --- /dev/null +++ b/src/newt/native/NewtMacWindow.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#import <AppKit/AppKit.h> +#import "jni.h" + +@interface NewtView : NSView +{ + jobject javaWindowObject; + + // This is set while messages are being dispatched and cleared afterward + JNIEnv* env; +} + +/* Set during event dispatching cycle */ +- (void) setJNIEnv: (JNIEnv*) env; +- (JNIEnv*) getJNIEnv; + +/* Register or deregister (NULL) the java Window object, + ie, if NULL, no events are send */ +- (void) setJavaWindowObject: (jobject) javaWindowObj; +- (jobject) getJavaWindowObject; + +- (void) rightMouseDown: (NSEvent*) theEvent; + +@end + +#if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 +@interface NewtMacWindow : NSWindow <NSWindowDelegate> +#else +@interface NewtMacWindow : NSWindow +#endif +{ +} + ++ (BOOL) initNatives: (JNIEnv*) env forClass: (jobject) clazz; + +- (void) updateInsets: (JNIEnv*) env; + +- (id) initWithContentRect: (NSRect) contentRect + styleMask: (NSUInteger) windowStyle + backing: (NSBackingStoreType) bufferingType + screen:(NSScreen *)screen; + +@end diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m new file mode 100644 index 000000000..cba69498a --- /dev/null +++ b/src/newt/native/NewtMacWindow.m @@ -0,0 +1,495 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#import "NewtMacWindow.h" +#import "InputEvent.h" +#import "KeyEvent.h" +#import "MouseEvent.h" + +jint GetDeltaY(NSEvent *event, jint javaMods) { + CGFloat deltaY = 0.0; + CGEventRef cgEvent = [event CGEvent]; + + if (CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventIsContinuous)) { + // mouse pad case + deltaY = + CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis1); + } else { + // traditional mouse wheel case + deltaY = [event deltaY]; + if (deltaY == 0.0 && (javaMods & EVENT_SHIFT_MASK) != 0) { + // shift+vertical wheel scroll produces horizontal scroll + // we convert it to vertical + deltaY = [event deltaX]; + } + if (deltaY < 1.0 && deltaY > -1.0) { + deltaY *= 10.0; + } else { + if (deltaY < 0.0) { + deltaY = deltaY - 0.5f; + } else { + deltaY = deltaY + 0.5f; + } + } + } + + if (deltaY > 0) { + return (NSInteger)deltaY; + } else if (deltaY < 0) { + return -(NSInteger)deltaY; + } + + return 0; +} + +static jmethodID sendMouseEventID = NULL; +static jmethodID sendKeyEventID = NULL; +static jmethodID insetsChangedID = NULL; +static jmethodID sizeChangedID = NULL; +static jmethodID visibleChangedID = NULL; +static jmethodID positionChangedID = NULL; +static jmethodID focusChangedID = NULL; +static jmethodID windowDestroyNotifyID = NULL; + +@implementation NewtView +- (void) setJNIEnv: (JNIEnv*) theEnv +{ + env = theEnv; +} +- (JNIEnv*) getJNIEnv +{ + return env; +} + +- (void) setJavaWindowObject: (jobject) javaWindowObj +{ + javaWindowObject = javaWindowObj; +} + +- (jobject) getJavaWindowObject +{ + return javaWindowObject; +} + +- (void) rightMouseDown: (NSEvent*) theEvent +{ + NSResponder* next = [self nextResponder]; + if (next != nil) { + [next rightMouseDown: theEvent]; + } +} + +- (void)viewWillDraw +{ + fprintf(stderr, "*************** viewWillDraw: 0x%p", javaWindowObject); fflush(stderr); + [super viewWillDraw]; +} + +- (void)viewDidHide +{ + (*env)->CallVoidMethod(env, javaWindowObject, visibleChangedID, JNI_FALSE); + [super viewDidHide]; +} + +- (void)viewDidUnhide +{ + (*env)->CallVoidMethod(env, javaWindowObject, visibleChangedID, JNI_TRUE); + [super viewDidUnhide]; +} + +@end + +@implementation NewtMacWindow + ++ (BOOL) initNatives: (JNIEnv*) env forClass: (jclass) clazz +{ + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V"); + sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(IIZ)V"); + visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V"); + insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(IIII)V"); + positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V"); + focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(Z)V"); + windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V"); + if (sendMouseEventID && sendKeyEventID && sizeChangedID && visibleChangedID && insetsChangedID && + positionChangedID && focusChangedID && windowDestroyNotifyID) + { + return YES; + } + return NO; +} + +- (void) updateInsets: (JNIEnv*) env +{ + NSView* nsview = [self contentView]; + if( ! [nsview isMemberOfClass:[NewtView class]] ) { + return; + } + NewtView* view = (NewtView *) nsview; + jobject javaWindowObject = [view getJavaWindowObject]; + if (env==NULL || javaWindowObject == NULL) { + return; + } + + NSRect frameRect = [self frame]; + NSRect contentRect = [self contentRectForFrameRect: frameRect]; + + // note: this is a simplistic implementation which doesn't take + // into account DPI and scaling factor + CGFloat l = contentRect.origin.x - frameRect.origin.x; + jint top = (jint)(frameRect.size.height - contentRect.size.height); + jint left = (jint)l; + jint bottom = (jint)(contentRect.origin.y - frameRect.origin.y); + jint right = (jint)(frameRect.size.width - (contentRect.size.width + l)); + + (*env)->CallVoidMethod(env, javaWindowObject, insetsChangedID, + left, top, right, bottom); +} + +- (id) initWithContentRect: (NSRect) contentRect + styleMask: (NSUInteger) windowStyle + backing: (NSBackingStoreType) bufferingType + screen:(NSScreen *)screen +{ + id res = [super initWithContentRect: contentRect + styleMask: windowStyle + backing: bufferingType + defer: YES + screen: screen]; + // Why is this necessary? Without it we don't get any of the + // delegate methods like resizing and window movement. + [self setDelegate: self]; + return res; +} + +- (BOOL) canBecomeKeyWindow +{ + // Even if the window is borderless, we still want it to be able + // to become the key window to receive keyboard events + return YES; +} + +static jint mods2JavaMods(NSUInteger mods) +{ + int javaMods = 0; + if (mods & NSShiftKeyMask) { + javaMods |= EVENT_SHIFT_MASK; + } + if (mods & NSControlKeyMask) { + javaMods |= EVENT_CTRL_MASK; + } + if (mods & NSCommandKeyMask) { + javaMods |= EVENT_META_MASK; + } + if (mods & NSAlternateKeyMask) { + javaMods |= EVENT_ALT_MASK; + } + return javaMods; +} + +- (void) sendKeyEvent: (NSEvent*) event eventType: (jint) evType +{ + NSView* nsview = [self contentView]; + if( ! [nsview isMemberOfClass:[NewtView class]] ) { + return; + } + NewtView* view = (NewtView *) nsview; + jobject javaWindowObject = [view getJavaWindowObject]; + JNIEnv* env = [view getJNIEnv]; + if (env==NULL || javaWindowObject == NULL) { + return; + } + + int i; + jint keyCode = (jint) [event keyCode]; + NSString* chars = [event charactersIgnoringModifiers]; + int len = [chars length]; + jint javaMods = mods2JavaMods([event modifierFlags]); + + for (i = 0; i < len; i++) { + // Note: the key code in the NSEvent does not map to anything we can use + jchar keyChar = (jchar) [chars characterAtIndex: i]; + + (*env)->CallVoidMethod(env, javaWindowObject, sendKeyEventID, + evType, javaMods, keyCode, keyChar); + } +} + +- (void) keyDown: (NSEvent*) theEvent +{ + [self sendKeyEvent: theEvent eventType: EVENT_KEY_PRESSED]; +} + +- (void) keyUp: (NSEvent*) theEvent +{ + [self sendKeyEvent: theEvent eventType: EVENT_KEY_RELEASED]; + [self sendKeyEvent: theEvent eventType: EVENT_KEY_TYPED]; +} + +- (void) sendMouseEvent: (NSEvent*) event eventType: (jint) evType +{ + NSView* nsview = [self contentView]; + if( ! [nsview isMemberOfClass:[NewtView class]] ) { + return; + } + NewtView* view = (NewtView *) nsview; + jobject javaWindowObject = [view getJavaWindowObject]; + JNIEnv* env = [view getJNIEnv]; + if (env==NULL || javaWindowObject == NULL) { + return; + } + + jint javaMods = mods2JavaMods([event modifierFlags]); + NSRect frameRect = [self frame]; + NSRect contentRect = [self contentRectForFrameRect: frameRect]; + // NSPoint location = [event locationInWindow]; + // The following computation improves the behavior of mouse drag + // events when they also affect the location of the window, but it + // still isn't perfect + NSPoint curLocation = [NSEvent mouseLocation]; + NSPoint location = NSMakePoint(curLocation.x - frameRect.origin.x, + curLocation.y - frameRect.origin.y); + + // convert to 1-based button number (or use zero if no button is involved) + // TODO: detect mouse button when mouse wheel scrolled + jint javaButtonNum = 0; + jint scrollDeltaY = 0; + switch ([event type]) { + case NSScrollWheel: { + scrollDeltaY = GetDeltaY(event, javaMods); + break; + } + case NSLeftMouseDown: + case NSLeftMouseUp: + case NSLeftMouseDragged: + javaButtonNum = 1; + break; + case NSRightMouseDown: + case NSRightMouseUp: + case NSRightMouseDragged: + javaButtonNum = 3; + break; + case NSOtherMouseDown: + case NSOtherMouseUp: + case NSOtherMouseDragged: + javaButtonNum = 2; + break; + default: + javaButtonNum = 0; + break; + } + + if (evType == EVENT_MOUSE_WHEEL_MOVED && scrollDeltaY == 0) { + // ignore 0 increment wheel scroll events + return; + } + (*env)->CallVoidMethod(env, javaWindowObject, sendMouseEventID, + evType, javaMods, + (jint) location.x, + (jint) (contentRect.size.height - location.y), + javaButtonNum, scrollDeltaY); +} + +- (void) mouseEntered: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_ENTERED]; +} + +- (void) mouseExited: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_EXITED]; +} + +- (void) mouseMoved: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_MOVED]; +} + +- (void) scrollWheel: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_WHEEL_MOVED]; +} + +- (void) mouseDown: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_PRESSED]; +} + +- (void) mouseDragged: (NSEvent*) theEvent +{ + // Note use of MOUSE_MOVED event type because mouse dragged events are synthesized by Java + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_MOVED]; +} + +- (void) mouseUp: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_RELEASED]; +} + +- (void) rightMouseDown: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_PRESSED]; +} + +- (void) rightMouseDragged: (NSEvent*) theEvent +{ + // Note use of MOUSE_MOVED event type because mouse dragged events are synthesized by Java + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_MOVED]; +} + +- (void) rightMouseUp: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_RELEASED]; +} + +- (void) otherMouseDown: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_PRESSED]; +} + +- (void) otherMouseDragged: (NSEvent*) theEvent +{ + // Note use of MOUSE_MOVED event type because mouse dragged events are synthesized by Java + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_MOVED]; +} + +- (void) otherMouseUp: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_RELEASED]; +} + +- (void)windowDidResize: (NSNotification*) notification +{ + NSView* nsview = [self contentView]; + if( ! [nsview isMemberOfClass:[NewtView class]] ) { + return; + } + NewtView* view = (NewtView *) nsview; + jobject javaWindowObject = [view getJavaWindowObject]; + JNIEnv* env = [view getJNIEnv]; + if (env==NULL || javaWindowObject == NULL) { + return; + } + + // update insets on every window resize for lack of better hook place + [self updateInsets: env]; + + NSRect frameRect = [self frame]; + NSRect contentRect = [self contentRectForFrameRect: frameRect]; + + (*env)->CallVoidMethod(env, javaWindowObject, sizeChangedID, + (jint) contentRect.size.width, + (jint) contentRect.size.height, JNI_FALSE); +} + +- (void)windowDidMove: (NSNotification*) notification +{ + NSView* nsview = [self contentView]; + if( ! [nsview isMemberOfClass:[NewtView class]] ) { + return; + } + NewtView* view = (NewtView *) nsview; + jobject javaWindowObject = [view getJavaWindowObject]; + JNIEnv* env = [view getJNIEnv]; + if (env==NULL || javaWindowObject == NULL) { + return; + } + + NSRect rect = [self frame]; + NSScreen* screen = NULL; + NSRect screenRect; + NSPoint pt; + + screen = [self screen]; + // this allows for better compatibility with awt behavior + screenRect = [screen frame]; + pt = NSMakePoint(rect.origin.x, screenRect.origin.y + screenRect.size.height - rect.origin.y - rect.size.height); + + (*env)->CallVoidMethod(env, javaWindowObject, positionChangedID, + (jint) pt.x, (jint) pt.y); +} + +- (void)windowWillClose: (NSNotification*) notification +{ + NSView* nsview = [self contentView]; + if( ! [nsview isMemberOfClass:[NewtView class]] ) { + return; + } + NewtView* view = (NewtView *) nsview; + jobject javaWindowObject = [view getJavaWindowObject]; + JNIEnv* env = [view getJNIEnv]; + if (env==NULL || javaWindowObject == NULL) { + return; + } + + (*env)->CallVoidMethod(env, javaWindowObject, windowDestroyNotifyID); + // Can't issue call here - locked window state, done from Java method + + // EOL .. + (*env)->DeleteGlobalRef(env, javaWindowObject); + [view setJavaWindowObject: NULL]; +} + +- (void) windowDidBecomeKey: (NSNotification *) notification +{ + NSView* nsview = [self contentView]; + if( ! [nsview isMemberOfClass:[NewtView class]] ) { + return; + } + NewtView* view = (NewtView *) nsview; + jobject javaWindowObject = [view getJavaWindowObject]; + JNIEnv* env = [view getJNIEnv]; + if (env==NULL || javaWindowObject == NULL) { + return; + } + + (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_TRUE); +} + +- (void) windowDidResignKey: (NSNotification *) notification +{ + NSView* nsview = [self contentView]; + if( ! [nsview isMemberOfClass:[NewtView class]] ) { + return; + } + NewtView* view = (NewtView *) nsview; + jobject javaWindowObject = [view getJavaWindowObject]; + JNIEnv* env = [view getJNIEnv]; + if (env==NULL || javaWindowObject == NULL) { + return; + } + + (*env)->CallVoidMethod(env, javaWindowObject, focusChangedID, JNI_FALSE); +} + +@end diff --git a/src/newt/native/ScreenMode.h b/src/newt/native/ScreenMode.h new file mode 100644 index 000000000..0a760d54a --- /dev/null +++ b/src/newt/native/ScreenMode.h @@ -0,0 +1,16 @@ +/** + * WARNING: must be synced with com.jogamp.newt.util.ScreenModeUtil#streamIn*(int[]) + */ + +#ifndef _SCREEN_MODE_H +#define _SCREEN_MODE_H + +#define NUM_RESOLUTION_PROPERTIES 2 /* width, height */ +#define NUM_SURFACE_SIZE_PROPERTIES 1 /* bpp */ +#define NUM_MONITOR_MODE_PROPERTIES 3 /* ScreenSizeMM[width, height], refresh-rate */ +#define NUM_SCREEN_MODE_PROPERTIES 1 /* rotation */ + +#define NUM_SCREEN_MODE_PROPERTIES_ALL 8 /* count + the above */ + +#endif + diff --git a/src/newt/native/WindowEvent.h b/src/newt/native/WindowEvent.h new file mode 100644 index 000000000..05491b43c --- /dev/null +++ b/src/newt/native/WindowEvent.h @@ -0,0 +1,13 @@ + +#ifndef _WINDOW_EVENT_H_ +#define _WINDOW_EVENT_H_ + +#define EVENT_WINDOW_RESIZED 100 +#define EVENT_WINDOW_MOVED 101 +#define EVENT_WINDOW_DESTROY_NOTIFY 102 +#define EVENT_WINDOW_GAINED_FOCUS 103 +#define EVENT_WINDOW_LOST_FOCUS 104 +#define EVENT_WINDOW_REPAINT 105 +#define EVENT_WINDOW_DESTROYED 106 + +#endif diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c new file mode 100644 index 000000000..95f036b39 --- /dev/null +++ b/src/newt/native/WindowsWindow.c @@ -0,0 +1,1599 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#include <Windows.h> +#include <Windowsx.h> +#include <tchar.h> +#include <stdlib.h> +// NOTE: it looks like SHFullScreen and/or aygshell.dll is not available on the APX 2500 any more +// #ifdef UNDER_CE +// #include "aygshell.h" +// #endif + +/* This typedef is apparently needed for Microsoft compilers before VC8, + and on Windows CE and MingW32 */ +#if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1400 ) + #ifdef _WIN64 + typedef long long intptr_t; + #else + typedef int intptr_t; + #endif +#elif !defined(__MINGW64__) && _MSC_VER <= 1500 + #ifdef _WIN64 // [ + typedef __int64 intptr_t; + #else // _WIN64 ][ + typedef int intptr_t; + #endif // _WIN64 ] +#else + #include <inttypes.h> +#endif + +#if !defined(__MINGW64__) && _MSC_VER <= 1500 + // FIXME: Determine for which MSVC versions .. + #define strdup(s) _strdup(s) +#endif + +#ifndef WM_MOUSEWHEEL +#define WM_MOUSEWHEEL 0x020A +#endif //WM_MOUSEWHEEL + +#ifndef WHEEL_DELTA +#define WHEEL_DELTA 120 +#endif //WHEEL_DELTA + +#ifndef WHEEL_PAGESCROLL +#define WHEEL_PAGESCROLL (UINT_MAX) +#endif //WHEEL_PAGESCROLL + +#ifndef GET_WHEEL_DELTA_WPARAM // defined for (_WIN32_WINNT >= 0x0500) +#define GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam)) +#endif + +#ifndef MONITOR_DEFAULTTONULL +#define MONITOR_DEFAULTTONULL 0 +#endif +#ifndef MONITOR_DEFAULTTOPRIMARY +#define MONITOR_DEFAULTTOPRIMARY 1 +#endif +#ifndef MONITOR_DEFAULTTONEAREST +#define MONITOR_DEFAULTTONEAREST 2 +#endif +#ifndef EDS_ROTATEDMODE +#define EDS_ROTATEDMODE 0x00000004 +#endif +#ifndef DISPLAY_DEVICE_ACTIVE +#define DISPLAY_DEVICE_ACTIVE 0x00000001 +#endif + +#include "jogamp_newt_windows_WindowsDisplay.h" +#include "jogamp_newt_windows_WindowsScreen.h" +#include "jogamp_newt_windows_WindowsWindow.h" + +#include "MouseEvent.h" +#include "InputEvent.h" +#include "KeyEvent.h" +#include "ScreenMode.h" + +#include "NewtCommon.h" + +// #define VERBOSE_ON 1 +// #define DEBUG_KEYS 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr) +#else + #define DBG_PRINT(...) +#endif + +#define STD_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr) + +static jmethodID insetsChangedID = NULL; +static jmethodID sizeChangedID = NULL; +static jmethodID positionChangedID = NULL; +static jmethodID focusChangedID = NULL; +static jmethodID visibleChangedID = NULL; +static jmethodID windowDestroyNotifyID = NULL; +static jmethodID windowRepaintID = NULL; +static jmethodID enqueueMouseEventID = NULL; +static jmethodID sendMouseEventID = NULL; +static jmethodID enqueueKeyEventID = NULL; +static jmethodID sendKeyEventID = NULL; +static jmethodID focusActionID = NULL; +static jmethodID enqueueRequestFocusID = NULL; + +static RECT* UpdateInsets(JNIEnv *env, jobject window, HWND hwnd); + +typedef struct { + JNIEnv* jenv; + jobject jinstance; +} WindowUserData; + +typedef struct { + UINT javaKey; + UINT windowsKey; +} KeyMapEntry; + +// Static table, arranged more or less spatially. +static KeyMapEntry keyMapTable[] = { + // Modifier keys + {J_VK_CAPS_LOCK, VK_CAPITAL}, + {J_VK_SHIFT, VK_SHIFT}, + {J_VK_CONTROL, VK_CONTROL}, + {J_VK_ALT, VK_MENU}, + {J_VK_NUM_LOCK, VK_NUMLOCK}, + + // Miscellaneous Windows keys + {J_VK_WINDOWS, VK_LWIN}, + {J_VK_WINDOWS, VK_RWIN}, + {J_VK_CONTEXT_MENU, VK_APPS}, + + // Alphabet + {J_VK_A, 'A'}, + {J_VK_B, 'B'}, + {J_VK_C, 'C'}, + {J_VK_D, 'D'}, + {J_VK_E, 'E'}, + {J_VK_F, 'F'}, + {J_VK_G, 'G'}, + {J_VK_H, 'H'}, + {J_VK_I, 'I'}, + {J_VK_J, 'J'}, + {J_VK_K, 'K'}, + {J_VK_L, 'L'}, + {J_VK_M, 'M'}, + {J_VK_N, 'N'}, + {J_VK_O, 'O'}, + {J_VK_P, 'P'}, + {J_VK_Q, 'Q'}, + {J_VK_R, 'R'}, + {J_VK_S, 'S'}, + {J_VK_T, 'T'}, + {J_VK_U, 'U'}, + {J_VK_V, 'V'}, + {J_VK_W, 'W'}, + {J_VK_X, 'X'}, + {J_VK_Y, 'Y'}, + {J_VK_Z, 'Z'}, + {J_VK_0, '0'}, + {J_VK_1, '1'}, + {J_VK_2, '2'}, + {J_VK_3, '3'}, + {J_VK_4, '4'}, + {J_VK_5, '5'}, + {J_VK_6, '6'}, + {J_VK_7, '7'}, + {J_VK_8, '8'}, + {J_VK_9, '9'}, + {J_VK_ENTER, VK_RETURN}, + {J_VK_SPACE, VK_SPACE}, + {J_VK_BACK_SPACE, VK_BACK}, + {J_VK_TAB, VK_TAB}, + {J_VK_ESCAPE, VK_ESCAPE}, + {J_VK_INSERT, VK_INSERT}, + {J_VK_DELETE, VK_DELETE}, + {J_VK_HOME, VK_HOME}, + {J_VK_END, VK_END}, + {J_VK_PAGE_UP, VK_PRIOR}, + {J_VK_PAGE_DOWN, VK_NEXT}, + {J_VK_CLEAR, VK_CLEAR}, // NumPad 5 + + // NumPad with NumLock off & extended arrows block (triangular) + {J_VK_LEFT, VK_LEFT}, + {J_VK_RIGHT, VK_RIGHT}, + {J_VK_UP, VK_UP}, + {J_VK_DOWN, VK_DOWN}, + + // NumPad with NumLock on: numbers + {J_VK_NUMPAD0, VK_NUMPAD0}, + {J_VK_NUMPAD1, VK_NUMPAD1}, + {J_VK_NUMPAD2, VK_NUMPAD2}, + {J_VK_NUMPAD3, VK_NUMPAD3}, + {J_VK_NUMPAD4, VK_NUMPAD4}, + {J_VK_NUMPAD5, VK_NUMPAD5}, + {J_VK_NUMPAD6, VK_NUMPAD6}, + {J_VK_NUMPAD7, VK_NUMPAD7}, + {J_VK_NUMPAD8, VK_NUMPAD8}, + {J_VK_NUMPAD9, VK_NUMPAD9}, + + // NumPad with NumLock on + {J_VK_MULTIPLY, VK_MULTIPLY}, + {J_VK_ADD, VK_ADD}, + {J_VK_SEPARATOR, VK_SEPARATOR}, + {J_VK_SUBTRACT, VK_SUBTRACT}, + {J_VK_DECIMAL, VK_DECIMAL}, + {J_VK_DIVIDE, VK_DIVIDE}, + + // Functional keys + {J_VK_F1, VK_F1}, + {J_VK_F2, VK_F2}, + {J_VK_F3, VK_F3}, + {J_VK_F4, VK_F4}, + {J_VK_F5, VK_F5}, + {J_VK_F6, VK_F6}, + {J_VK_F7, VK_F7}, + {J_VK_F8, VK_F8}, + {J_VK_F9, VK_F9}, + {J_VK_F10, VK_F10}, + {J_VK_F11, VK_F11}, + {J_VK_F12, VK_F12}, + {J_VK_F13, VK_F13}, + {J_VK_F14, VK_F14}, + {J_VK_F15, VK_F15}, + {J_VK_F16, VK_F16}, + {J_VK_F17, VK_F17}, + {J_VK_F18, VK_F18}, + {J_VK_F19, VK_F19}, + {J_VK_F20, VK_F20}, + {J_VK_F21, VK_F21}, + {J_VK_F22, VK_F22}, + {J_VK_F23, VK_F23}, + {J_VK_F24, VK_F24}, + + {J_VK_PRINTSCREEN, VK_SNAPSHOT}, + {J_VK_SCROLL_LOCK, VK_SCROLL}, + {J_VK_PAUSE, VK_PAUSE}, + {J_VK_CANCEL, VK_CANCEL}, + {J_VK_HELP, VK_HELP}, + + // Japanese +/* + {J_VK_CONVERT, VK_CONVERT}, + {J_VK_NONCONVERT, VK_NONCONVERT}, + {J_VK_INPUT_METHOD_ON_OFF, VK_KANJI}, + {J_VK_ALPHANUMERIC, VK_DBE_ALPHANUMERIC}, + {J_VK_KATAKANA, VK_DBE_KATAKANA}, + {J_VK_HIRAGANA, VK_DBE_HIRAGANA}, + {J_VK_FULL_WIDTH, VK_DBE_DBCSCHAR}, + {J_VK_HALF_WIDTH, VK_DBE_SBCSCHAR}, + {J_VK_ROMAN_CHARACTERS, VK_DBE_ROMAN}, +*/ + + {J_VK_UNDEFINED, 0} +}; + +/* +Dynamic mapping table for OEM VK codes. This table is refilled +by BuildDynamicKeyMapTable when keyboard layout is switched. +(see NT4 DDK src/input/inc/vkoem.h for OEM VK_ values). +*/ +typedef struct { + // OEM VK codes known in advance + UINT windowsKey; + // depends on input langauge (kbd layout) + UINT javaKey; +} DynamicKeyMapEntry; + +static DynamicKeyMapEntry dynamicKeyMapTable[] = { + {0x00BA, J_VK_UNDEFINED}, // VK_OEM_1 + {0x00BB, J_VK_UNDEFINED}, // VK_OEM_PLUS + {0x00BC, J_VK_UNDEFINED}, // VK_OEM_COMMA + {0x00BD, J_VK_UNDEFINED}, // VK_OEM_MINUS + {0x00BE, J_VK_UNDEFINED}, // VK_OEM_PERIOD + {0x00BF, J_VK_UNDEFINED}, // VK_OEM_2 + {0x00C0, J_VK_UNDEFINED}, // VK_OEM_3 + {0x00DB, J_VK_UNDEFINED}, // VK_OEM_4 + {0x00DC, J_VK_UNDEFINED}, // VK_OEM_5 + {0x00DD, J_VK_UNDEFINED}, // VK_OEM_6 + {0x00DE, J_VK_UNDEFINED}, // VK_OEM_7 + {0x00DF, J_VK_UNDEFINED}, // VK_OEM_8 + {0x00E2, J_VK_UNDEFINED}, // VK_OEM_102 + {0, 0} +}; + +// Auxiliary tables used to fill the above dynamic table. We first +// find the character for the OEM VK code using ::MapVirtualKey and +// then go through these auxiliary tables to map it to Java VK code. + +typedef struct { + WCHAR c; + UINT javaKey; +} CharToVKEntry; + +static const CharToVKEntry charToVKTable[] = { + {L'!', J_VK_EXCLAMATION_MARK}, + {L'"', J_VK_QUOTEDBL}, + {L'#', J_VK_NUMBER_SIGN}, + {L'$', J_VK_DOLLAR}, + {L'&', J_VK_AMPERSAND}, + {L'\'', J_VK_QUOTE}, + {L'(', J_VK_LEFT_PARENTHESIS}, + {L')', J_VK_RIGHT_PARENTHESIS}, + {L'*', J_VK_ASTERISK}, + {L'+', J_VK_PLUS}, + {L',', J_VK_COMMA}, + {L'-', J_VK_MINUS}, + {L'.', J_VK_PERIOD}, + {L'/', J_VK_SLASH}, + {L':', J_VK_COLON}, + {L';', J_VK_SEMICOLON}, + {L'<', J_VK_LESS}, + {L'=', J_VK_EQUALS}, + {L'>', J_VK_GREATER}, + {L'@', J_VK_AT}, + {L'[', J_VK_OPEN_BRACKET}, + {L'\\', J_VK_BACK_SLASH}, + {L']', J_VK_CLOSE_BRACKET}, + {L'^', J_VK_CIRCUMFLEX}, + {L'_', J_VK_UNDERSCORE}, + {L'`', J_VK_BACK_QUOTE}, + {L'{', J_VK_BRACELEFT}, + {L'}', J_VK_BRACERIGHT}, + {0x00A1, J_VK_INVERTED_EXCLAMATION_MARK}, + {0x20A0, J_VK_EURO_SIGN}, // ???? + {0,0} +}; + +// For dead accents some layouts return ASCII punctuation, while some +// return spacing accent chars, so both should be listed. NB: MS docs +// say that conversion routings return spacing accent character, not +// combining. +static const CharToVKEntry charToDeadVKTable[] = { + {L'`', J_VK_DEAD_GRAVE}, + {L'\'', J_VK_DEAD_ACUTE}, + {0x00B4, J_VK_DEAD_ACUTE}, + {L'^', J_VK_DEAD_CIRCUMFLEX}, + {L'~', J_VK_DEAD_TILDE}, + {0x02DC, J_VK_DEAD_TILDE}, + {0x00AF, J_VK_DEAD_MACRON}, + {0x02D8, J_VK_DEAD_BREVE}, + {0x02D9, J_VK_DEAD_ABOVEDOT}, + {L'"', J_VK_DEAD_DIAERESIS}, + {0x00A8, J_VK_DEAD_DIAERESIS}, + {0x02DA, J_VK_DEAD_ABOVERING}, + {0x02DD, J_VK_DEAD_DOUBLEACUTE}, + {0x02C7, J_VK_DEAD_CARON}, // aka hacek + {L',', J_VK_DEAD_CEDILLA}, + {0x00B8, J_VK_DEAD_CEDILLA}, + {0x02DB, J_VK_DEAD_OGONEK}, + {0x037A, J_VK_DEAD_IOTA}, // ASCII ??? + {0x309B, J_VK_DEAD_VOICED_SOUND}, + {0x309C, J_VK_DEAD_SEMIVOICED_SOUND}, + {0,0} +}; + +// ANSI CP identifiers are no longer than this +#define MAX_ACP_STR_LEN 7 + +static void BuildDynamicKeyMapTable() +{ + HKL hkl = GetKeyboardLayout(0); + // Will need this to reset layout after dead keys. + UINT spaceScanCode = MapVirtualKeyEx(VK_SPACE, 0, hkl); + DynamicKeyMapEntry *dynamic; + + LANGID idLang = LOWORD(GetKeyboardLayout(0)); + UINT codePage; + TCHAR strCodePage[MAX_ACP_STR_LEN]; + // use the LANGID to create a LCID + LCID idLocale = MAKELCID(idLang, SORT_DEFAULT); + // get the ANSI code page associated with this locale + if (GetLocaleInfo(idLocale, LOCALE_IDEFAULTANSICODEPAGE, + strCodePage, sizeof(strCodePage)/sizeof(TCHAR)) > 0 ) + { + codePage = _ttoi(strCodePage); + } else { + codePage = GetACP(); + } + + // Entries in dynamic table that maps between Java VK and Windows + // VK are built in three steps: + // 1. Map windows VK to ANSI character (cannot map to unicode + // directly, since ::ToUnicode is not implemented on win9x) + // 2. Convert ANSI char to Unicode char + // 3. Map Unicode char to Java VK via two auxilary tables. + + for (dynamic = dynamicKeyMapTable; dynamic->windowsKey != 0; ++dynamic) + { + char cbuf[2] = { '\0', '\0'}; + WCHAR ucbuf[2] = { L'\0', L'\0' }; + int nchars; + UINT scancode; + const CharToVKEntry *charMap; + int nconverted; + WCHAR uc; + BYTE kbdState[256]; + + // Defaults to J_VK_UNDEFINED + dynamic->javaKey = J_VK_UNDEFINED; + + GetKeyboardState(kbdState); + + kbdState[dynamic->windowsKey] |= 0x80; // Press the key. + + // Unpress modifiers, since they are most likely pressed as + // part of the keyboard switching shortcut. + kbdState[VK_CONTROL] &= ~0x80; + kbdState[VK_SHIFT] &= ~0x80; + kbdState[VK_MENU] &= ~0x80; + + scancode = MapVirtualKeyEx(dynamic->windowsKey, 0, hkl); + nchars = ToAsciiEx(dynamic->windowsKey, scancode, kbdState, + (WORD*)cbuf, 0, hkl); + + // Auxiliary table used to map Unicode character to Java VK. + // Will assign a different table for dead keys (below). + charMap = charToVKTable; + + if (nchars < 0) { // Dead key + char junkbuf[2] = { '\0', '\0'}; + // Use a different table for dead chars since different layouts + // return different characters for the same dead key. + charMap = charToDeadVKTable; + + // We also need to reset layout so that next translation + // is unaffected by the dead status. We do this by + // translating <SPACE> key. + kbdState[dynamic->windowsKey] &= ~0x80; + kbdState[VK_SPACE] |= 0x80; + + ToAsciiEx(VK_SPACE, spaceScanCode, kbdState, + (WORD*)junkbuf, 0, hkl); + } + + nconverted = MultiByteToWideChar(codePage, 0, + cbuf, 1, ucbuf, 2); + + uc = ucbuf[0]; + { + const CharToVKEntry *map; + for (map = charMap; map->c != 0; ++map) { + if (uc == map->c) { + dynamic->javaKey = map->javaKey; + break; + } + } + } + + } // for each VK_OEM_* +} + +static jint GetModifiers() { + jint modifiers = 0; + // have to do &0xFFFF to avoid runtime assert caused by compiling with + // /RTCcsu + if (HIBYTE((GetKeyState(VK_CONTROL) & 0xFFFF)) != 0) { + modifiers |= EVENT_CTRL_MASK; + } + if (HIBYTE((GetKeyState(VK_SHIFT) & 0xFFFF)) != 0) { + modifiers |= EVENT_SHIFT_MASK; + } + if (HIBYTE((GetKeyState(VK_MENU) & 0xFFFF)) != 0) { + modifiers |= EVENT_ALT_MASK; + } + if (HIBYTE((GetKeyState(VK_LBUTTON) & 0xFFFF)) != 0) { + modifiers |= EVENT_BUTTON1_MASK; + } + if (HIBYTE((GetKeyState(VK_MBUTTON) & 0xFFFF)) != 0) { + modifiers |= EVENT_BUTTON2_MASK; + } + if (HIBYTE((GetKeyState(VK_RBUTTON) & 0xFFFF)) != 0) { + modifiers |= EVENT_BUTTON3_MASK; + } + + return modifiers; +} + +static int WmChar(JNIEnv *env, jobject window, UINT character, UINT repCnt, + UINT flags, BOOL system) +{ + // The Alt modifier is reported in the 29th bit of the lParam, + // i.e., it is the 13th bit of `flags' (which is HIWORD(lParam)). + BOOL alt_is_down = (flags & (1<<13)) != 0; + if (system && alt_is_down) { + if (character == VK_SPACE) { + return 1; + } + } + + if (character == VK_RETURN) { + character = J_VK_ENTER; + } + (*env)->CallVoidMethod(env, window, sendKeyEventID, + (jint) EVENT_KEY_TYPED, + GetModifiers(), + (jint) -1, + (jchar) character); + return 1; +} + +UINT WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers) +{ + int i, j; + // for the general case, use a bi-directional table + for (i = 0; keyMapTable[i].windowsKey != 0; i++) { + if (keyMapTable[i].windowsKey == windowsKey) { + return keyMapTable[i].javaKey; + } + } + for (j = 0; dynamicKeyMapTable[j].windowsKey != 0; j++) { + if (dynamicKeyMapTable[j].windowsKey == windowsKey) { + if (dynamicKeyMapTable[j].javaKey != J_VK_UNDEFINED) { + return dynamicKeyMapTable[j].javaKey; + } else { + break; + } + } + } + + return J_VK_UNDEFINED; +} + +static int WmKeyDown(JNIEnv *env, jobject window, UINT wkey, UINT repCnt, + UINT flags, BOOL system) +{ + UINT modifiers = 0, jkey = 0, character = -1; + if (wkey == VK_PROCESSKEY) { + return 1; + } + + modifiers = GetModifiers(); + jkey = WindowsKeyToJavaKey(wkey, modifiers); + +/* + character = WindowsKeyToJavaChar(wkey, modifiers, SAVE); +*/ + + (*env)->CallVoidMethod(env, window, sendKeyEventID, + (jint) EVENT_KEY_PRESSED, + modifiers, + (jint) jkey, + (jchar) character); + + /* windows does not create a WM_CHAR for the Del key + for some reason, so we need to create the KEY_TYPED event on the + WM_KEYDOWN. + */ + if (jkey == J_VK_DELETE) { + (*env)->CallVoidMethod(env, window, sendKeyEventID, + (jint) EVENT_KEY_TYPED, + GetModifiers(), + (jint) -1, + (jchar) '\177'); + } + + return 0; +} + +static int WmKeyUp(JNIEnv *env, jobject window, UINT wkey, UINT repCnt, + UINT flags, BOOL system) +{ + UINT modifiers = 0, jkey = 0, character = -1; + if (wkey == VK_PROCESSKEY) { + return 1; + } + + modifiers = GetModifiers(); + jkey = WindowsKeyToJavaKey(wkey, modifiers); +/* + character = WindowsKeyToJavaChar(wkey, modifiers, SAVE); +*/ + + (*env)->CallVoidMethod(env, window, sendKeyEventID, + (jint) EVENT_KEY_RELEASED, + modifiers, + (jint) jkey, + (jchar) character); + + return 0; +} + +static void NewtWindows_requestFocus (JNIEnv *env, jobject window, HWND hwnd, jboolean force) { + HWND pHwnd, current; + pHwnd = GetParent(hwnd); + current = GetFocus(); + DBG_PRINT("*** WindowsWindow: requestFocus.S parent %p, window %p, isCurrent %d\n", + (void*) pHwnd, (void*)hwnd, current==hwnd); + if( JNI_TRUE==force || current!=hwnd) { + if( JNI_TRUE==force || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { + UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE; + SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags); + SetForegroundWindow(hwnd); // Slightly Higher Priority + SetFocus(hwnd);// Sets Keyboard Focus To Window + if(NULL!=pHwnd) { + SetActiveWindow(hwnd); + } + DBG_PRINT("*** WindowsWindow: requestFocus.X1\n"); + } else { + DBG_PRINT("*** WindowsWindow: requestFocus.X0\n"); + } + } + DBG_PRINT("*** WindowsWindow: requestFocus.XX\n"); +} + +#if 0 + +static RECT* UpdateInsets(JNIEnv *env, jobject window, HWND hwnd) +{ + // being naughty here + static RECT m_insets = { 0, 0, 0, 0 }; + RECT outside; + RECT inside; + POINT *rp_inside = (POINT *) (void *) &inside; + int dx, dy, dw, dh; + + if (IsIconic(hwnd)) { + m_insets.left = m_insets.top = m_insets.right = m_insets.bottom = -1; + return FALSE; + } + + m_insets.left = m_insets.top = m_insets.right = m_insets.bottom = 0; + + GetClientRect(hwnd, &inside); + GetWindowRect(hwnd, &outside); + + DBG_PRINT("*** WindowsWindow: UpdateInsets (a1) window %p, Inside CC: %d/%d - %d/%d %dx%d\n", + (void*)hwnd, + (int)inside.left, (int)inside.top, (int)inside.right, (int)inside.bottom, + (int)(inside.right - inside.left), (int)(inside.bottom - inside.top)); + DBG_PRINT("*** WindowsWindow: UpdateInsets (a1) window %p, Outside SC: %d/%d - %d/%d %dx%d\n", + (void*)hwnd, + (int)outside.left, (int)outside.top, (int)outside.right, (int)outside.bottom, + (int)(outside.right - outside.left), (int)(outside.bottom - outside.top)); + + // xform client -> screen coord + ClientToScreen(hwnd, rp_inside); + ClientToScreen(hwnd, rp_inside+1); + + DBG_PRINT("*** WindowsWindow: UpdateInsets (a2) window %p, Inside SC: %d/%d - %d/%d %dx%d\n", + (void*)hwnd, + (int)inside.left, (int)inside.top, (int)inside.right, (int)inside.bottom, + (int)(inside.right - inside.left), (int)(inside.bottom - inside.top)); + + m_insets.top = inside.top - outside.top; + m_insets.bottom = outside.bottom - inside.bottom; + m_insets.left = inside.left - outside.left; + m_insets.right = outside.right - inside.right; + + DBG_PRINT("*** WindowsWindow: UpdateInsets (1.0) window %p, %d/%d - %d/%d %dx%d\n", + (void*)hwnd, + (int)m_insets.left, (int)m_insets.top, (int)m_insets.right, (int)m_insets.bottom, + (int)(m_insets.right-m_insets.left), (int)(m_insets.top-m_insets.bottom)); + + (*env)->CallVoidMethod(env, window, insetsChangedID, + m_insets.left, m_insets.top, + m_insets.right, m_insets.bottom); + return &m_insets; +} + +#else + +static RECT* UpdateInsets(JNIEnv *env, jobject window, HWND hwnd) +{ + // being naughty here + static RECT m_insets = { 0, 0, 0, 0 }; + RECT outside; + RECT inside; + + if (IsIconic(hwnd)) { + m_insets.left = m_insets.top = m_insets.right = m_insets.bottom = -1; + return FALSE; + } + + m_insets.left = m_insets.top = m_insets.right = m_insets.bottom = 0; + + GetClientRect(hwnd, &inside); + GetWindowRect(hwnd, &outside); + + if (outside.right - outside.left > 0 && outside.bottom - outside.top > 0) { + MapWindowPoints(hwnd, 0, (LPPOINT)&inside, 2); + m_insets.top = inside.top - outside.top; + m_insets.bottom = outside.bottom - inside.bottom; + m_insets.left = inside.left - outside.left; + m_insets.right = outside.right - inside.right; + } else { + m_insets.top = -1; + } + if (m_insets.left < 0 || m_insets.top < 0 || + m_insets.right < 0 || m_insets.bottom < 0) + { + LONG style = GetWindowLong(hwnd, GWL_STYLE); + // TODO: TDV: better undecorated checking needed + + BOOL bIsUndecorated = (style & (WS_CHILD|WS_POPUP|WS_SYSMENU)) != 0; + if (!bIsUndecorated) { + /* Get outer frame sizes. */ + if (style & WS_THICKFRAME) { + m_insets.left = m_insets.right = + GetSystemMetrics(SM_CXSIZEFRAME); + m_insets.top = m_insets.bottom = + GetSystemMetrics(SM_CYSIZEFRAME); + } else { + m_insets.left = m_insets.right = + GetSystemMetrics(SM_CXDLGFRAME); + m_insets.top = m_insets.bottom = + GetSystemMetrics(SM_CYDLGFRAME); + } + + /* Add in title. */ + m_insets.top += GetSystemMetrics(SM_CYCAPTION); + } else { + /* undo the -1 set above */ + m_insets.left = m_insets.top = m_insets.right = m_insets.bottom = 0; + } + } + + DBG_PRINT("*** WindowsWindow: UpdateInsets window %p, %d/%d %dx%d\n", + (void*)hwnd, (int)m_insets.left, (int)m_insets.top, (int)(m_insets.right-m_insets.left), (int)(m_insets.top-m_insets.bottom)); + + (*env)->CallVoidMethod(env, window, insetsChangedID, + m_insets.left, m_insets.top, + m_insets.right, m_insets.bottom); + return &m_insets; +} + +#endif + +static void WmSize(JNIEnv *env, jobject window, HWND wnd, UINT type) +{ + RECT rc; + int w, h; + BOOL isVisible = IsWindowVisible(wnd); + + // make sure insets are up to date + (void)UpdateInsets(env, window, wnd); + + if (type == SIZE_MINIMIZED) { + // TODO: deal with minimized window sizing + return; + } + + GetClientRect(wnd, &rc); + + // we report back the dimensions of the client area + w = rc.right - rc.left; + h = rc.bottom - rc.top; + + DBG_PRINT("*** WindowsWindow: WmSize window %p, %dx%d, visible %d\n", (void*)wnd, w, h, isVisible); + + if(isVisible) { + (*env)->CallVoidMethod(env, window, sizeChangedID, w, h, JNI_FALSE); + } +} + +static LRESULT CALLBACK wndProc(HWND wnd, UINT message, + WPARAM wParam, LPARAM lParam) +{ + LRESULT res = 0; + int useDefWindowProc = 0; + JNIEnv *env = NULL; + jobject window = NULL; + BOOL isKeyDown = FALSE; + WindowUserData * wud; + +#ifdef DEBUG_KEYS + if ( WM_KEYDOWN == message ) { + STD_PRINT("*** WindowsWindow: wndProc window %p, 0x%X %d/%d\n", wnd, message, (int)LOWORD(lParam), (int)HIWORD(lParam)); + } +#endif + +#if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1200 ) + wud = (WindowUserData *) GetWindowLong(wnd, GWL_USERDATA); +#else + wud = (WindowUserData *) GetWindowLongPtr(wnd, GWLP_USERDATA); +#endif + if(NULL==wud) { + return DefWindowProc(wnd, message, wParam, lParam); + } + env = wud->jenv; + window = wud->jinstance; + + // DBG_PRINT("*** WindowsWindow: thread 0x%X - window %p -> %p, 0x%X %d/%d\n", (int)GetCurrentThreadId(), wnd, window, message, (int)LOWORD(lParam), (int)HIWORD(lParam)); + + if (NULL==window || NULL==env) { + return DefWindowProc(wnd, message, wParam, lParam); + } + + switch (message) { + + // + // The signal pipeline for destruction is: + // Java::DestroyWindow(wnd) _or_ window-close-button -> + // WM_CLOSE -> Java::windowDestroyNotify -> W_DESTROY + case WM_CLOSE: + (*env)->CallVoidMethod(env, window, windowDestroyNotifyID); + break; + + case WM_DESTROY: + { +#if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1200 ) + SetWindowLong(wnd, GWL_USERDATA, (intptr_t) NULL); +#else + SetWindowLongPtr(wnd, GWLP_USERDATA, (intptr_t) NULL); +#endif + free(wud); wud=NULL; + (*env)->DeleteGlobalRef(env, window); + } + break; + + case WM_SYSCHAR: + useDefWindowProc = WmChar(env, window, wParam, + LOWORD(lParam), HIWORD(lParam), FALSE); + break; + + case WM_CHAR: + useDefWindowProc = WmChar(env, window, wParam, + LOWORD(lParam), HIWORD(lParam), TRUE); + break; + + case WM_KEYDOWN: +#ifdef DEBUG_KEYS + STD_PRINT("*** WindowsWindow: windProc sending window %p -> %p, 0x%X %d/%d\n", wnd, window, message, (int)LOWORD(lParam), (int)HIWORD(lParam)); +#endif + useDefWindowProc = WmKeyDown(env, window, wParam, + LOWORD(lParam), HIWORD(lParam), FALSE); + break; + + case WM_KEYUP: + useDefWindowProc = WmKeyUp(env, window, wParam, + LOWORD(lParam), HIWORD(lParam), FALSE); + break; + + case WM_SIZE: + WmSize(env, window, wnd, (UINT)wParam); + break; + + case WM_SETTINGCHANGE: + if (wParam == SPI_SETNONCLIENTMETRICS) { + // make sure insets are updated, we don't need to resize the window + // because the size of the client area doesn't change + (void)UpdateInsets(env, window, wnd); + } else { + useDefWindowProc = 1; + } + break; + + + case WM_LBUTTONDOWN: + DBG_PRINT("*** WindowsWindow: LBUTTONDOWN\n"); + (*env)->CallVoidMethod(env, window, enqueueRequestFocusID, JNI_FALSE); + (*env)->CallVoidMethod(env, window, sendMouseEventID, + (jint) EVENT_MOUSE_PRESSED, + GetModifiers(), + (jint) LOWORD(lParam), (jint) HIWORD(lParam), + (jint) 1, (jint) 0); + useDefWindowProc = 1; + break; + + case WM_LBUTTONUP: + (*env)->CallVoidMethod(env, window, sendMouseEventID, + (jint) EVENT_MOUSE_RELEASED, + GetModifiers(), + (jint) LOWORD(lParam), (jint) HIWORD(lParam), + (jint) 1, (jint) 0); + useDefWindowProc = 1; + break; + + case WM_MBUTTONDOWN: + DBG_PRINT("*** WindowsWindow: MBUTTONDOWN\n"); + (*env)->CallVoidMethod(env, window, enqueueRequestFocusID, JNI_FALSE); + (*env)->CallVoidMethod(env, window, sendMouseEventID, + (jint) EVENT_MOUSE_PRESSED, + GetModifiers(), + (jint) LOWORD(lParam), (jint) HIWORD(lParam), + (jint) 2, (jint) 0); + useDefWindowProc = 1; + break; + + case WM_MBUTTONUP: + (*env)->CallVoidMethod(env, window, sendMouseEventID, + (jint) EVENT_MOUSE_RELEASED, + GetModifiers(), + (jint) LOWORD(lParam), (jint) HIWORD(lParam), + (jint) 2, (jint) 0); + useDefWindowProc = 1; + break; + + case WM_RBUTTONDOWN: + DBG_PRINT("*** WindowsWindow: RBUTTONDOWN\n"); + (*env)->CallVoidMethod(env, window, enqueueRequestFocusID, JNI_FALSE); + (*env)->CallVoidMethod(env, window, sendMouseEventID, + (jint) EVENT_MOUSE_PRESSED, + GetModifiers(), + (jint) LOWORD(lParam), (jint) HIWORD(lParam), + (jint) 3, (jint) 0); + useDefWindowProc = 1; + break; + + case WM_RBUTTONUP: + (*env)->CallVoidMethod(env, window, sendMouseEventID, + (jint) EVENT_MOUSE_RELEASED, + GetModifiers(), + (jint) LOWORD(lParam), (jint) HIWORD(lParam), + (jint) 3, (jint) 0); + useDefWindowProc = 1; + break; + + case WM_MOUSEMOVE: + (*env)->CallVoidMethod(env, window, sendMouseEventID, + (jint) EVENT_MOUSE_MOVED, + GetModifiers(), + (jint) LOWORD(lParam), (jint) HIWORD(lParam), + (jint) 0, (jint) 0); + useDefWindowProc = 1; + break; + + case WM_MOUSEWHEEL: { + // need to convert the coordinates to component-relative + int x = GET_X_LPARAM(lParam); + int y = GET_Y_LPARAM(lParam); + POINT eventPt; + eventPt.x = x; + eventPt.y = y; + ScreenToClient(wnd, &eventPt); + (*env)->CallVoidMethod(env, window, sendMouseEventID, + (jint) EVENT_MOUSE_WHEEL_MOVED, + GetModifiers(), + (jint) eventPt.x, (jint) eventPt.y, + (jint) 0, (jint) (GET_WHEEL_DELTA_WPARAM(wParam)/120.0f)); + useDefWindowProc = 1; + break; + } + + case WM_SETFOCUS: + (*env)->CallVoidMethod(env, window, focusChangedID, JNI_TRUE); + useDefWindowProc = 1; + break; + + case WM_KILLFOCUS: + (*env)->CallVoidMethod(env, window, focusChangedID, JNI_FALSE); + useDefWindowProc = 1; + break; + + case WM_SHOWWINDOW: + (*env)->CallVoidMethod(env, window, visibleChangedID, wParam==TRUE?JNI_TRUE:JNI_FALSE); + break; + + case WM_MOVE: + DBG_PRINT("*** WindowsWindow: WM_MOVE window %p, %d/%d\n", wnd, (int)LOWORD(lParam), (int)HIWORD(lParam)); + (*env)->CallVoidMethod(env, window, positionChangedID, + (jint)LOWORD(lParam), (jint)HIWORD(lParam)); + useDefWindowProc = 1; + break; + + case WM_PAINT: { + RECT r; + useDefWindowProc = 0; + if (GetUpdateRect(wnd, &r, TRUE /* erase background */)) { + /* + jint width = r.right-r.left; + jint height = r.bottom-r.top; + if (width > 0 && height > 0) { + (*env)->CallVoidMethod(env, window, windowRepaintID, r.left, r.top, width, height); + } + ValidateRect(wnd, &r); + */ + } + break; + } + case WM_ERASEBKGND: + // ignore erase background + (*env)->CallVoidMethod(env, window, windowRepaintID, 0, 0, -1, -1); + useDefWindowProc = 0; + res = 1; // OpenGL, etc .. erases the background, hence we claim to have just done this + break; + + + // FIXME: generate EVENT_MOUSE_ENTERED, EVENT_MOUSE_EXITED + default: + useDefWindowProc = 1; + } + + if (useDefWindowProc) + return DefWindowProc(wnd, message, wParam, lParam); + return res; +} + +/* + * Class: jogamp_newt_windows_WindowsDisplay + * Method: DispatchMessages + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_windows_WindowsDisplay_DispatchMessages0 + (JNIEnv *env, jclass clazz) +{ + int i = 0; + MSG msg; + BOOL gotOne; + + // Periodically take a break + do { + gotOne = PeekMessage(&msg, (HWND) NULL, 0, 0, PM_REMOVE); + // DBG_PRINT("*** WindowsWindow.DispatchMessages0: thread 0x%X - gotOne %d\n", (int)GetCurrentThreadId(), (int)gotOne); + if (gotOne) { + ++i; +#ifdef DEBUG_KEYS + if(WM_KEYDOWN == msg.message) { + STD_PRINT("*** WindowsWindow: DispatchMessages window %p, 0x%X %d/%d\n", msg.hwnd, msg.message, (int)LOWORD(msg.lParam), (int)HIWORD(msg.lParam)); + } +#endif + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } while (gotOne && i < 100); +} + +/* + * Class: jogamp_newt_windows_WindowsScreen + * Method: getWidthImpl + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_jogamp_newt_windows_WindowsScreen_getWidthImpl0 + (JNIEnv *env, jobject obj, jint scrn_idx) +{ + return (jint)GetSystemMetrics(SM_CXSCREEN); +} + +/* + * Class: jogamp_newt_windows_WindowsScreen + * Method: getHeightImpl + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_jogamp_newt_windows_WindowsScreen_getHeightImpl0 + (JNIEnv *env, jobject obj, jint scrn_idx) +{ + return (jint)GetSystemMetrics(SM_CYSCREEN); +} + +static int NewtScreen_RotationNativeCCW2NewtCCW(JNIEnv *env, int native) { + int newt; + switch (native) { + case DMDO_DEFAULT: + newt = 0; + break; + case DMDO_90: + newt = 90; + break; + case DMDO_180: + newt = 180; + break; + case DMDO_270: + newt = 270; + break; + default: + NewtCommon_throwNewRuntimeException(env, "invalid native rotation: %d", native); + break; + } + return newt; +} + +static int NewtScreen_RotationNewtCCW2NativeCCW(JNIEnv *env, jint newt) { + int native; + switch (newt) { + case 0: + native = DMDO_DEFAULT; + break; + case 90: + native = DMDO_90; + break; + case 180: + native = DMDO_180; + break; + case 270: + native = DMDO_270; + break; + default: + NewtCommon_throwNewRuntimeException(env, "invalid newt rotation: %d", newt); + } + return native; +} + +/* +static void NewtScreen_scanDisplayDevices() { + DISPLAY_DEVICE device; + int i = 0; + LPCTSTR name; + while(NULL != (name = NewtScreen_getDisplayDeviceName(&device, i))) { + fprintf(stderr, "*** [%d]: <%s> active %d\n", i, name, ( 0 != ( device.StateFlags & DISPLAY_DEVICE_ACTIVE ) ) ); + i++; + } +}*/ + +static LPCTSTR NewtScreen_getDisplayDeviceName(DISPLAY_DEVICE * device, int scrn_idx) { + device->cb = sizeof(DISPLAY_DEVICE); + if( FALSE == EnumDisplayDevices(NULL, scrn_idx, device, 0) ) { + DBG_PRINT("*** WindowsWindow: getDisplayDeviceName.EnumDisplayDevices(scrn_idx %d) -> FALSE\n", scrn_idx); + return NULL; + } + + if( 0 == ( device->StateFlags & DISPLAY_DEVICE_ACTIVE ) ) { + DBG_PRINT("*** WindowsWindow: !DISPLAY_DEVICE_ACTIVE(scrn_idx %d)\n", scrn_idx); + return NULL; + } + + return device->DeviceName; +} + +static HDC NewtScreen_createDisplayDC(LPCTSTR displayDeviceName) { + return CreateDC("DISPLAY", displayDeviceName, NULL, NULL); +} + +/* + * Class: jogamp_newt_windows_WindowsScreen + * Method: getScreenMode0 + * Signature: (II)[I + */ +JNIEXPORT jintArray JNICALL Java_jogamp_newt_windows_WindowsScreen_getScreenMode0 + (JNIEnv *env, jobject obj, jint scrn_idx, jint mode_idx) +{ + DISPLAY_DEVICE device; + int prop_num = NUM_SCREEN_MODE_PROPERTIES_ALL; + LPCTSTR deviceName = NewtScreen_getDisplayDeviceName(&device, scrn_idx); + if(NULL == deviceName) { + DBG_PRINT("*** WindowsWindow: getScreenMode.getDisplayDeviceName(scrn_idx %d) -> NULL\n", scrn_idx); + return (*env)->NewIntArray(env, 0); + } + + int devModeID; + int widthmm, heightmm; + if(-1 < mode_idx) { + // only at initialization time, where index >= 0 + HDC hdc = NewtScreen_createDisplayDC(deviceName); + widthmm = GetDeviceCaps(hdc, HORZSIZE); + heightmm = GetDeviceCaps(hdc, VERTSIZE); + DeleteDC(hdc); + devModeID = (int) mode_idx; + prop_num++; // add 1st extra prop, mode_idx + } else { + widthmm = 0; + heightmm = 0; + devModeID = ENUM_CURRENT_SETTINGS; + } + + DEVMODE dm; + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + + if (0 == EnumDisplaySettingsEx(deviceName, devModeID, &dm, ( ENUM_CURRENT_SETTINGS == devModeID ) ? 0 : EDS_ROTATEDMODE)) { + DBG_PRINT("*** WindowsWindow: getScreenMode.EnumDisplaySettingsEx(mode_idx %d/%d) -> NULL\n", mode_idx, devModeID); + return (*env)->NewIntArray(env, 0); + } + + // swap width and height, since Windows reflects rotated dimension, we don't + if (DMDO_90 == dm.dmDisplayOrientation || DMDO_270 == dm.dmDisplayOrientation) { + int tempWidth = dm.dmPelsWidth; + dm.dmPelsWidth = dm.dmPelsHeight; + dm.dmPelsHeight = tempWidth; + } + + jint prop[ prop_num ]; + int propIndex = 0; + + if( -1 < mode_idx ) { + prop[propIndex++] = mode_idx; + } + prop[propIndex++] = 0; // set later for verification of iterator + prop[propIndex++] = dm.dmPelsWidth; + prop[propIndex++] = dm.dmPelsHeight; + prop[propIndex++] = dm.dmBitsPerPel; + prop[propIndex++] = widthmm; + prop[propIndex++] = heightmm; + prop[propIndex++] = dm.dmDisplayFrequency; + prop[propIndex++] = NewtScreen_RotationNativeCCW2NewtCCW(env, dm.dmDisplayOrientation); + prop[propIndex - NUM_SCREEN_MODE_PROPERTIES_ALL] = ( -1 < mode_idx ) ? propIndex-1 : propIndex ; // count == NUM_SCREEN_MODE_PROPERTIES_ALL + + jintArray properties = (*env)->NewIntArray(env, prop_num); + if (properties == NULL) { + NewtCommon_throwNewRuntimeException(env, "Could not allocate int array of size %d", prop_num); + } + (*env)->SetIntArrayRegion(env, properties, 0, prop_num, prop); + + return properties; +} + +/* + * Class: jogamp_newt_windows_WindowsScreen + * Method: setScreenMode0 + * Signature: (IIIIII)Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_windows_WindowsScreen_setScreenMode0 + (JNIEnv *env, jobject object, jint scrn_idx, jint width, jint height, jint bits, jint rate, jint rot) +{ + DISPLAY_DEVICE device; + LPCTSTR deviceName = NewtScreen_getDisplayDeviceName(&device, scrn_idx); + if(NULL == deviceName) { + DBG_PRINT("*** WindowsWindow: setScreenMode.getDisplayDeviceName(scrn_idx %d) -> NULL\n", scrn_idx); + return JNI_FALSE; + } + + DEVMODE dm; + // initialize the DEVMODE structure + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + dm.dmPelsWidth = (int)width; + dm.dmPelsHeight = (int)height; + dm.dmBitsPerPel = (int)bits; + dm.dmDisplayFrequency = (int)rate; + dm.dmDisplayOrientation = NewtScreen_RotationNewtCCW2NativeCCW(env, rot); + + // swap width and height, since Windows reflects rotated dimension, we don't + if ( DMDO_90 == dm.dmDisplayOrientation || DMDO_270 == dm.dmDisplayOrientation ) { + int tempWidth = dm.dmPelsWidth; + dm.dmPelsWidth = dm.dmPelsHeight; + dm.dmPelsHeight = tempWidth; + } + + dm.dmFields = DM_DISPLAYORIENTATION | DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; + + return ( DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettings(&dm, 0) ) ? JNI_TRUE : JNI_FALSE ; +} + +/* + * Class: jogamp_newt_windows_WindowsWindow + * Method: initIDs0 + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_windows_WindowsWindow_initIDs0 + (JNIEnv *env, jclass clazz) +{ + NewtCommon_init(env); + + insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(IIII)V"); + sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(IIZ)V"); + positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V"); + focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(Z)V"); + visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V"); + windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V"); + windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(IIII)V"); + enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZIIIIII)V"); + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V"); + enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(ZIIIC)V"); + sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + enqueueRequestFocusID = (*env)->GetMethodID(env, clazz, "enqueueRequestFocus", "(Z)V"); + focusActionID = (*env)->GetMethodID(env, clazz, "focusAction", "()Z"); + + if (insetsChangedID == NULL || + sizeChangedID == NULL || + positionChangedID == NULL || + focusChangedID == NULL || + visibleChangedID == NULL || + windowDestroyNotifyID == NULL || + windowRepaintID == NULL || + enqueueMouseEventID == NULL || + sendMouseEventID == NULL || + enqueueKeyEventID == NULL || + sendKeyEventID == NULL || + focusActionID == NULL || + enqueueRequestFocusID == NULL) { + return JNI_FALSE; + } + BuildDynamicKeyMapTable(); + return JNI_TRUE; +} + +/* + * Class: jogamp_newt_windows_WindowsWindow + * Method: getNewtWndProc0 + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_jogamp_newt_windows_WindowsWindow_getNewtWndProc0 + (JNIEnv *env, jclass clazz) +{ + return (jlong) (intptr_t) wndProc; +} + +/* + * Class: jogamp_newt_windows_WindowsWindow + * Method: CreateWindow + */ +JNIEXPORT jlong JNICALL Java_jogamp_newt_windows_WindowsWindow_CreateWindow0 + (JNIEnv *env, jobject obj, + jlong hInstance, jstring jWndClassName, jstring jWndName, + jlong parent, jlong visualID, jboolean bIsUndecorated, + jint jx, jint jy, jint defaultWidth, jint defaultHeight) +{ + HWND parentWindow = (HWND) (intptr_t) parent; + const TCHAR* wndClassName = NULL; + const TCHAR* wndName = NULL; + DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_TABSTOP; + int x=(int)jx, y=(int)jy; + int width=(int)defaultWidth, height=(int)defaultHeight; + HWND window = NULL; + +#ifdef UNICODE + wndClassName = NewtCommon_GetNullTerminatedStringChars(env, jWndClassName); + wndName = NewtCommon_GetNullTerminatedStringChars(env, jWndName); +#else + wndClassName = (*env)->GetStringUTFChars(env, jWndClassName, NULL); + wndName = (*env)->GetStringUTFChars(env, jWndName, NULL); +#endif + + if(NULL!=parentWindow) { + if (!IsWindow(parentWindow)) { + DBG_PRINT("*** WindowsWindow: CreateWindow failure: Passed parentWindow %p is invalid\n", parentWindow); + return 0; + } + windowStyle |= WS_CHILD ; + } else if (bIsUndecorated) { + windowStyle |= WS_POPUP | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; + } else { + windowStyle |= WS_OVERLAPPEDWINDOW; + x = CW_USEDEFAULT; + y = 0; + } + + (void) visualID; // FIXME: use the visualID .. + + window = CreateWindow(wndClassName, wndName, windowStyle, + x, y, width, height, + parentWindow, NULL, + (HINSTANCE) (intptr_t) hInstance, + NULL); + + DBG_PRINT("*** WindowsWindow: CreateWindow thread 0x%X, parent %p, window %p, %d/%d %dx%d\n", + (int)GetCurrentThreadId(), parentWindow, window, x, y, width, height); + + if (NULL == window) { + int lastError = (int) GetLastError(); + DBG_PRINT("*** WindowsWindow: CreateWindow failure: 0x%X %d\n", lastError, lastError); + return 0; + } else { + WindowUserData * wud = (WindowUserData *) malloc(sizeof(WindowUserData)); + wud->jinstance = (*env)->NewGlobalRef(env, obj); + wud->jenv = env; +#if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1200 ) + SetWindowLong(window, GWL_USERDATA, (intptr_t) wud); +#else + SetWindowLongPtr(window, GWLP_USERDATA, (intptr_t) wud); +#endif + + UpdateInsets(env, obj, window); + } + +#ifdef UNICODE + free((void*) wndClassName); + free((void*) wndName); +#else + (*env)->ReleaseStringUTFChars(env, jWndClassName, wndClassName); + (*env)->ReleaseStringUTFChars(env, jWndName, wndName); +#endif + + return (jlong) (intptr_t) window; +} + +/* + * Class: jogamp_newt_windows_WindowsWindow + * Method: MonitorFromWindow + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_jogamp_newt_windows_WindowsWindow_MonitorFromWindow0 + (JNIEnv *env, jobject obj, jlong window) +{ + #if (_WIN32_WINNT >= 0x0500 || _WIN32_WINDOWS >= 0x0410 || WINVER >= 0x0500) && !defined(_WIN32_WCE) + return (jlong) (intptr_t) MonitorFromWindow((HWND) (intptr_t) window, MONITOR_DEFAULTTOPRIMARY); + #else + return 0; + #endif +} + +/*** + * returns bits: 1: size change, 2: pos change + */ +int NewtWindow_setVisiblePosSize(JNIEnv *env, jobject obj, HWND hwnd, jboolean top, jboolean visible, + int x, int y, int width, int height) +{ + UINT flags; + HWND hWndInsertAfter; + BOOL bRes; + int iRes=0; + int wwidth = width; // final window width + int wheight = height; // final window height + + DBG_PRINT("*** WindowsWindow: NewtWindow_setVisiblePosSize %d/%d %dx%d, top %d, visible %d\n", + x, y, width, height, (int)top, (int)visible); + + if(JNI_TRUE == visible) { + flags = SWP_SHOWWINDOW; + } else { + flags = SWP_NOACTIVATE | SWP_NOZORDER; + } + + if(0>x || 0>y ) { + flags |= SWP_NOMOVE; + } else { + iRes |= 2; + } + if(0>=width || 0>=height ) { + flags |= SWP_NOSIZE; + } else { + iRes |= 1; + } + + if(JNI_TRUE == top) { + hWndInsertAfter = HWND_TOPMOST; + if ( 0 == ( flags & SWP_NOSIZE ) ) { + + // since width, height are the size of the client area, we need to add insets + RECT *pInsets = UpdateInsets(env, obj, hwnd); + + wwidth += pInsets->left + pInsets->right; + wheight += pInsets->top + pInsets->bottom; + } + DBG_PRINT("*** WindowsWindow: NewtWindow_setVisiblePosSize top size w/ insets: %d/%d %dx%d\n", x, y, wwidth, wheight); + } else { + hWndInsertAfter = HWND_TOP; + DBG_PRINT("*** WindowsWindow: NewtWindow_setVisiblePosSize client size: %d/%d %dx%d\n", x, y, wwidth, wheight); + } + + SetWindowPos(hwnd, hWndInsertAfter, x, y, wwidth, wheight, flags); + + InvalidateRect(hwnd, NULL, TRUE); + UpdateWindow(hwnd); + + // we report back the size of client area + (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height, JNI_FALSE); + + return iRes; +} + +/* + * Class: jogamp_newt_windows_WindowsWindow + * Method: setVisible0 + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_windows_WindowsWindow_setVisible0 + (JNIEnv *env, jobject obj, jlong window, jboolean visible, jboolean top, jint x, jint y, jint width, jint height) +{ + HWND hwnd = (HWND) (intptr_t) window; + DBG_PRINT("*** WindowsWindow: setVisible window %p, visible: %d, top %d, %d/%d %dx%d\n", + hwnd, (int)visible, (int)top, x, y, width, height); + if (visible) { + NewtWindow_setVisiblePosSize(env, obj, hwnd, top, visible, x, y, width, height); + ShowWindow(hwnd, SW_SHOW); + } else { + ShowWindow(hwnd, SW_HIDE); + } +} + +static jboolean NewtWindows_setFullScreen(jboolean fullscreen) +{ + int flags = 0; + DEVMODE dm; + // initialize the DEVMODE structure + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + + if (0 == EnumDisplaySettings(NULL /*current display device*/, ENUM_CURRENT_SETTINGS, &dm)) + { + return JNI_FALSE; + } + + flags = ( JNI_TRUE == fullscreen ) ? CDS_FULLSCREEN : CDS_RESET ; + + return ( DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettings(&dm, flags) ) ? JNI_TRUE : JNI_FALSE; +} + +/* + * Class: jogamp_newt_windows_WindowsWindow + * Method: reconfigureWindow0 + * Signature: (JIIIIZZII)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_windows_WindowsWindow_reconfigureWindow0 + (JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y, jint width, jint height, + jboolean visible, jboolean parentChange, jint fullScreenChange, jint decorationChange) +{ + HWND hwndP = (HWND) (intptr_t) parent; + HWND hwnd = (HWND) (intptr_t) window; + DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN ; + BOOL styleChange = ( 0 != decorationChange || 0 != fullScreenChange || JNI_TRUE == parentChange ) ? TRUE : FALSE ; + UINT flags = SWP_SHOWWINDOW; + HWND hWndInsertAfter; + + DBG_PRINT("*** WindowsWindow: reconfigureWindow0 parent %p, window %p, %d/%d %dx%d, parentChange %d, fullScreenChange %d, visible %d, decorationChange %d -> styleChange %d\n", + parent, window, x, y, width, height, parentChange, fullScreenChange, visible, decorationChange, styleChange); + + if (!IsWindow(hwnd)) { + DBG_PRINT("*** WindowsWindow: reconfigureWindow0 failure: Passed window %p is invalid\n", (void*)hwnd); + return; + } + + if (NULL!=hwndP && !IsWindow(hwndP)) { + DBG_PRINT("*** WindowsWindow: reconfigureWindow0 failure: Passed parent window %p is invalid\n", (void*)hwndP); + return; + } + + if(JNI_TRUE == visible) { + windowStyle |= WS_VISIBLE ; + } + + if(fullScreenChange < 0) + { + NewtWindows_setFullScreen(JNI_FALSE); + } + + // order of call sequence: (MS documentation) + // TOP: SetParent(.., NULL); Clear WS_CHILD [, Set WS_POPUP] + // CHILD: Set WS_CHILD [, Clear WS_POPUP]; SetParent(.., PARENT) + // + if ( JNI_TRUE == parentChange && NULL == hwndP ) { + SetParent(hwnd, NULL); + } + + if(fullScreenChange > 0) + { + NewtWindows_setFullScreen(JNI_TRUE); + } + + if ( styleChange ) { + if(NULL!=hwndP) { + windowStyle |= WS_CHILD ; + } else if ( decorationChange < 0 || 0 < fullScreenChange ) { + windowStyle |= WS_POPUP | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; + } else { + windowStyle |= WS_OVERLAPPEDWINDOW; + } + SetWindowLong(hwnd, GWL_STYLE, windowStyle); + SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER ); + } + + if ( JNI_TRUE == parentChange && NULL != hwndP ) { + SetParent(hwnd, hwndP ); + } + + NewtWindow_setVisiblePosSize(env, obj, hwnd, (NULL == hwndP) ? JNI_TRUE : JNI_FALSE /* top */, visible, + x, y, width, height); + + DBG_PRINT("*** WindowsWindow: reconfigureWindow0.X\n"); +} + +/* + * Class: jogamp_newt_windows_WindowsWindow + * Method: setTitle + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_windows_WindowsWindow_setTitle0 + (JNIEnv *env, jclass clazz, jlong window, jstring title) +{ + HWND hwnd = (HWND) (intptr_t) window; + if (title != NULL) { + jchar *titleString = NewtCommon_GetNullTerminatedStringChars(env, title); + if (titleString != NULL) { + SetWindowTextW(hwnd, titleString); + free(titleString); + } + } +} + +/* + * Class: jogamp_newt_windows_WindowsWindow + * Method: requestFocus + * Signature: (JZ)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_windows_WindowsWindow_requestFocus0 + (JNIEnv *env, jobject obj, jlong window, jboolean force) +{ + DBG_PRINT("*** WindowsWindow: RequestFocus0\n"); + NewtWindows_requestFocus ( env, obj, (HWND) (intptr_t) window, force) ; +} + + diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c new file mode 100644 index 000000000..66b036ef5 --- /dev/null +++ b/src/newt/native/X11Window.c @@ -0,0 +1,1583 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <stdarg.h> +// Building on obsolete platform on SPARC right now +#ifdef __sparc + #include <inttypes.h> +#else + #include <stdint.h> +#endif +#include <unistd.h> +#include <errno.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/keysym.h> +#include <X11/Xatom.h> + +#include <X11/extensions/Xrandr.h> + +#include "jogamp_newt_x11_X11Screen.h" +#include "jogamp_newt_x11_X11Display.h" +#include "jogamp_newt_x11_X11Window.h" + +#include "MouseEvent.h" +#include "InputEvent.h" +#include "KeyEvent.h" +#include "WindowEvent.h" +#include "ScreenMode.h" + +#include "NewtCommon.h" + +// #define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr) + + #define DUMP_VISUAL_INFO(a,b) _dumpVisualInfo((a),(b)) + + static void _dumpVisualInfo(const char * msg, XVisualInfo *pVisualQuery) { + if(pVisualQuery!=NULL) { + fprintf(stderr, "%s: screen %d, visual: %p, visual-id: 0x%X, depth: %d, class %d, cmap sz: %d, bpp: 3x%d, rgb 0x%X 0x%X 0x%X\n", + msg, + pVisualQuery->screen, + pVisualQuery->visual, + (int)pVisualQuery->visualid, + pVisualQuery->depth, + pVisualQuery->class, + pVisualQuery->colormap_size, + pVisualQuery->bits_per_rgb, + (int)pVisualQuery->red_mask, + (int)pVisualQuery->green_mask, + (int)pVisualQuery->blue_mask + ); + } else { + fprintf(stderr, "%s: NULL XVisualInfo\n", msg); + } + } + +#else + + #define DBG_PRINT(...) + + #define DUMP_VISUAL_INFO(a,b) + +#endif + +/** + * Keycode + */ + +#define IS_WITHIN(k,a,b) ((a)<=(k)&&(k)<=(b)) + +static jint X11KeySym2NewtVKey(KeySym keySym) { + if(IS_WITHIN(keySym,XK_F1,XK_F12)) + return (keySym-XK_F1)+J_VK_F1; + + switch(keySym) { + case XK_Alt_L: + case XK_Alt_R: + return J_VK_ALT; + + case XK_Left: + return J_VK_LEFT; + case XK_Right: + return J_VK_RIGHT; + case XK_Up: + return J_VK_UP; + case XK_Down: + return J_VK_DOWN; + case XK_Page_Up: + return J_VK_PAGE_UP; + case XK_Page_Down: + return J_VK_PAGE_DOWN; + case XK_Shift_L: + case XK_Shift_R: + return J_VK_SHIFT; + case XK_Control_L: + case XK_Control_R: + return J_VK_CONTROL; + case XK_Escape: + return J_VK_ESCAPE; + case XK_Delete: + return J_VK_DELETE; + } + return keySym; +} + +static jint X11InputState2NewtModifiers(unsigned int xstate) { + jint modifiers = 0; + if ((ControlMask & xstate) != 0) { + modifiers |= EVENT_CTRL_MASK; + } + if ((ShiftMask & xstate) != 0) { + modifiers |= EVENT_SHIFT_MASK; + } + if ((Mod1Mask & xstate) != 0) { + modifiers |= EVENT_ALT_MASK; + } + if ((Button1Mask & xstate) != 0) { + modifiers |= EVENT_BUTTON1_MASK; + } + if ((Button2Mask & xstate) != 0) { + modifiers |= EVENT_BUTTON2_MASK; + } + if ((Button3Mask & xstate) != 0) { + modifiers |= EVENT_BUTTON3_MASK; + } + + return modifiers; +} + +static const char * const ClazzNameNewtWindow = "com/jogamp/newt/Window"; + +static jclass newtWindowClz=NULL; + +static jmethodID sizeChangedID = NULL; +static jmethodID positionChangedID = NULL; +static jmethodID focusChangedID = NULL; +static jmethodID visibleChangedID = NULL; +static jmethodID windowDestroyNotifyID = NULL; +static jmethodID windowRepaintID = NULL; +static jmethodID windowReparentedID = NULL; +static jmethodID enqueueMouseEventID = NULL; +static jmethodID sendMouseEventID = NULL; +static jmethodID enqueueKeyEventID = NULL; +static jmethodID sendKeyEventID = NULL; +static jmethodID focusActionID = NULL; +static jmethodID enqueueRequestFocusID = NULL; + +static jmethodID displayCompletedID = NULL; + + +/** + * Display + */ + +static JNIEnv * x11ErrorHandlerJNIEnv = NULL; +static XErrorHandler origErrorHandler = NULL ; + +static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) +{ + fprintf(stderr, "Warning: NEWT X11 Error: DisplayDispatch %p, Code 0x%X, errno %s\n", dpy, e->error_code, strerror(errno)); + + if (e->error_code == BadAtom) { + fprintf(stderr, " BadAtom (%p): Atom probably already removed\n", (void*)e->resourceid); + } else if (e->error_code == BadWindow) { + fprintf(stderr, " BadWindow (%p): Window probably already removed\n", (void*)e->resourceid); + } else { + NewtCommon_throwNewRuntimeException(x11ErrorHandlerJNIEnv, "NEWT X11 Error: Display %p, Code 0x%X, errno %s", + dpy, e->error_code, strerror(errno)); + } + + return 0; +} + +static void displayDispatchErrorHandlerEnable(int onoff, JNIEnv * env) { + if(onoff) { + if(NULL==origErrorHandler) { + x11ErrorHandlerJNIEnv = env; + origErrorHandler = XSetErrorHandler(displayDispatchErrorHandler); + } + } else { + if(NULL!=origErrorHandler) { + XSetErrorHandler(origErrorHandler); + origErrorHandler = NULL; + } + } +} + +/* + * Class: jogamp_newt_x11_X11Display + * Method: initIDs + * Signature: (Z)Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_x11_X11Display_initIDs0 + (JNIEnv *env, jclass clazz) +{ + jclass c; + + NewtCommon_init(env); + + displayCompletedID = (*env)->GetMethodID(env, clazz, "displayCompleted", "(JJ)V"); + if (displayCompletedID == NULL) { + return JNI_FALSE; + } + + if(NULL==newtWindowClz) { + c = (*env)->FindClass(env, ClazzNameNewtWindow); + if(NULL==c) { + NewtCommon_FatalError(env, "NEWT X11Window: can't find %s", ClazzNameNewtWindow); + } + newtWindowClz = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==newtWindowClz) { + NewtCommon_FatalError(env, "NEWT X11Window: can't use %s", ClazzNameNewtWindow); + } + } + + return JNI_TRUE; +} + +/* + * Class: jogamp_newt_x11_X11Display + * Method: CompleteDisplay + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_x11_X11Display_CompleteDisplay0 + (JNIEnv *env, jobject obj, jlong display) +{ + Display * dpy = (Display *)(intptr_t)display; + jlong javaObjectAtom; + jlong windowDeleteAtom; + + if(dpy==NULL) { + NewtCommon_FatalError(env, "invalid display connection.."); + } + + javaObjectAtom = (jlong) XInternAtom(dpy, "JOGL_JAVA_OBJECT", False); + if(None==javaObjectAtom) { + NewtCommon_throwNewRuntimeException(env, "could not create Atom JOGL_JAVA_OBJECT, bail out!"); + return; + } + + windowDeleteAtom = (jlong) XInternAtom(dpy, "WM_DELETE_WINDOW", False); + if(None==windowDeleteAtom) { + NewtCommon_throwNewRuntimeException(env, "could not create Atom WM_DELETE_WINDOW, bail out!"); + return; + } + + // XSetCloseDownMode(dpy, RetainTemporary); // Just a try .. + + DBG_PRINT("X11: X11Display_completeDisplay dpy %p\n", dpy); + + (*env)->CallVoidMethod(env, obj, displayCompletedID, javaObjectAtom, windowDeleteAtom); +} + +/** + * Window + */ + +static int putPtrIn32Long(unsigned long * dst, uintptr_t src) { + int i=0; + dst[i++] = (unsigned long) ( ( src >> 0 ) & 0xFFFFFFFF ) ; + if(sizeof(uintptr_t) == 8) { + dst[i++] = (unsigned long) ( ( src >> 32 ) & 0xFFFFFFFF ) ; + } + return i; +} + +static uintptr_t getPtrOut32Long(unsigned long * src) { + uintptr_t res = ( (uintptr_t) ( src[0] & 0xFFFFFFFF ) ) << 0 ; + if(sizeof(uintptr_t) == 8) { + res |= ( (uintptr_t) ( src[1] & 0xFFFFFFFF ) ) << 32 ; + } + return res; +} + +static void setJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, jlong javaObjectAtom, jobject jwindow) { + unsigned long jogl_java_object_data[2]; // X11 is based on 'unsigned long' + int nitems_32 = putPtrIn32Long( jogl_java_object_data, (uintptr_t) jwindow); + + { + jobject test = (jobject) getPtrOut32Long(jogl_java_object_data); + if( ! (jwindow==test) ) { + NewtCommon_FatalError(env, "Internal Error .. Encoded Window ref not the same %p != %p !", jwindow, test); + } + } + + XChangeProperty( dpy, window, (Atom)javaObjectAtom, (Atom)javaObjectAtom, 32, PropModeReplace, + (unsigned char *)&jogl_java_object_data, nitems_32); +} + +static jobject getJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, jlong javaObjectAtom, Bool showWarning) { + Atom actual_type_return; + int actual_format_return; + int nitems_32 = ( sizeof(uintptr_t) == 8 ) ? 2 : 1 ; + unsigned char * jogl_java_object_data_pp = NULL; + jobject jwindow; + + { + unsigned long nitems_return = 0; + unsigned long bytes_after_return = 0; + jobject jwindow = NULL; + int res; + + res = XGetWindowProperty(dpy, window, (Atom)javaObjectAtom, 0, nitems_32, False, + (Atom)javaObjectAtom, &actual_type_return, &actual_format_return, + &nitems_return, &bytes_after_return, &jogl_java_object_data_pp); + + if ( Success != res ) { + if(True==showWarning) { + fprintf(stderr, "Warning: NEWT X11Window: Could not fetch Atom JOGL_JAVA_OBJECT window property (res %d) nitems_return %ld, bytes_after_return %ld, result 0!\n", res, nitems_return, bytes_after_return); + } + return NULL; + } + + if(actual_type_return!=(Atom)javaObjectAtom || nitems_return<nitems_32 || NULL==jogl_java_object_data_pp) { + XFree(jogl_java_object_data_pp); + if(True==showWarning) { + fprintf(stderr, "Warning: NEWT X11Window: Fetched invalid Atom JOGL_JAVA_OBJECT window property (res %d) nitems_return %ld, bytes_after_return %ld, actual_type_return %ld, JOGL_JAVA_OBJECT %ld, result 0!\n", + res, nitems_return, bytes_after_return, (long)actual_type_return, javaObjectAtom); + } + return NULL; + } + } + + jwindow = (jobject) getPtrOut32Long( (unsigned long *) jogl_java_object_data_pp ) ; + XFree(jogl_java_object_data_pp); + +#ifdef VERBOSE_ON + if(JNI_FALSE == (*env)->IsInstanceOf(env, jwindow, newtWindowClz)) { + NewtCommon_throwNewRuntimeException(env, "fetched Atom JOGL_JAVA_OBJECT window is not a NEWT Window: javaWindow 0x%X !", jwindow); + } +#endif + return jwindow; +} + +/** @return zero if fails, non zero if OK */ +static Status NewtWindows_getRootAndParent (Display *dpy, Window w, Window * root_return, Window * parent_return) { + Window *children_return=NULL; + unsigned int nchildren_return=0; + + Status res = XQueryTree(dpy, w, root_return, parent_return, &children_return, &nchildren_return); + if(NULL!=children_return) { + XFree(children_return); + } + return res; +} +static Window NewtWindows_getRoot (Display *dpy, Window w) { + Window root_return; + Window parent_return; + if( 0 != NewtWindows_getRootAndParent(dpy, w, &root_return, &parent_return) ) { + return root_return; + } + return 0; +} +static Window NewtWindows_getParent (Display *dpy, Window w) { + Window root_return; + Window parent_return; + if( 0 != NewtWindows_getRootAndParent(dpy, w, &root_return, &parent_return) ) { + return parent_return; + } + return 0; +} + + +static void NewtWindows_requestFocus (JNIEnv *env, jobject window, Display *dpy, Window w, jboolean force) { + XWindowAttributes xwa; + Window focus_return; + int revert_to_return; + + XGetInputFocus(dpy, &focus_return, &revert_to_return); + if( JNI_TRUE==force || focus_return!=w) { + if( JNI_TRUE==force || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { + XRaiseWindow(dpy, w); + // Avoid 'BadMatch' errors from XSetInputFocus, ie if window is not viewable + XGetWindowAttributes(dpy, w, &xwa); + if(xwa.map_state == IsViewable) { + XSetInputFocus(dpy, w, RevertToParent, CurrentTime); + } + } + } + XSync(dpy, False); +} + +#define MWM_HINTS_DECORATIONS (1L << 1) +#define PROP_MWM_HINTS_ELEMENTS 5 + +static void NewtWindows_setDecorations (Display *dpy, Window w, Bool decorated) { + unsigned long mwmhints[PROP_MWM_HINTS_ELEMENTS] = { 0, 0, 0, 0, 0 }; // flags, functions, decorations, input_mode, status + Atom _MOTIF_WM_HINTS_DECORATIONS = XInternAtom( dpy, "_MOTIF_WM_HINTS", False ); + Atom _NET_WM_WINDOW_TYPE = XInternAtom( dpy, "_NET_WM_WINDOW_TYPE", False ); + Atom types[3]={0}; + int ntypes=0; + if(True==decorated) { + types[ntypes++] = XInternAtom( dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False ); + } else { + types[ntypes++] = XInternAtom( dpy, "_NET_WM_WINDOW_TYPE_POPUP_MENU", False ); + types[ntypes++] = XInternAtom( dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False ); + } + + mwmhints[0] = MWM_HINTS_DECORATIONS; + mwmhints[2] = decorated ; + + XChangeProperty( dpy, w, _MOTIF_WM_HINTS_DECORATIONS, _MOTIF_WM_HINTS_DECORATIONS, 32, PropModeReplace, (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS); + XChangeProperty( dpy, w, _NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *)&types, ntypes); +} + +#define _NET_WM_STATE_REMOVE 0 +#define _NET_WM_STATE_ADD 1 + +static void NewtWindows_setFullscreen (Display *dpy, Window root, Window w, Bool fullscreen) { + Atom _NET_WM_STATE = XInternAtom( dpy, "_NET_WM_STATE", False ); + Atom _NET_WM_STATE_ABOVE = XInternAtom( dpy, "_NET_WM_STATE_ABOVE", False ); + Atom _NET_WM_STATE_FULLSCREEN = XInternAtom( dpy, "_NET_WM_STATE_FULLSCREEN", False ); + + Atom types[2]={0}; + int ntypes=0; + + types[ntypes++] = _NET_WM_STATE_FULLSCREEN; + types[ntypes++] = _NET_WM_STATE_ABOVE; + + XEvent xev; + memset ( &xev, 0, sizeof(xev) ); + + xev.type = ClientMessage; + xev.xclient.window = w; + xev.xclient.message_type = _NET_WM_STATE; + xev.xclient.format = 32; + + if(True==fullscreen) { + xev.xclient.data.l[0] = _NET_WM_STATE_ADD; + xev.xclient.data.l[1] = _NET_WM_STATE_FULLSCREEN; + xev.xclient.data.l[2] = _NET_WM_STATE_ABOVE; + xev.xclient.data.l[3] = 1; //source indication for normal applications + } else { + xev.xclient.data.l[0] = _NET_WM_STATE_REMOVE; + xev.xclient.data.l[1] = _NET_WM_STATE_FULLSCREEN; + xev.xclient.data.l[2] = _NET_WM_STATE_ABOVE; + xev.xclient.data.l[3] = 1; //source indication for normal applications + } + + XChangeProperty( dpy, w, _NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *)&types, ntypes); + XSync(dpy, False); + XSendEvent (dpy, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev ); +} + +#define USE_SENDIO_DIRECT 1 + +/* + * Class: jogamp_newt_x11_X11Display + * Method: DispatchMessages + * Signature: (JIJJ)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_x11_X11Display_DispatchMessages0 + (JNIEnv *env, jobject obj, jlong display, jlong javaObjectAtom, jlong wmDeleteAtom) +{ + Display * dpy = (Display *) (intptr_t) display; + int num_events = 100; + + if ( NULL == dpy ) { + return; + } + + // Periodically take a break + while( num_events > 0 ) { + jobject jwindow = NULL; + XEvent evt; + KeySym keySym = 0; + jint modifiers = 0; + char keyChar = 0; + char text[255]; + + // num_events = XPending(dpy); // I/O Flush .. + // num_events = XEventsQueued(dpy, QueuedAfterFlush); // I/O Flush only of no already queued events are available + // num_events = XEventsQueued(dpy, QueuedAlready); // no I/O Flush at all, doesn't work on some cards (eg ATI) + if ( 0 >= XEventsQueued(dpy, QueuedAfterFlush) ) { + // DBG_PRINT( "X11: DispatchMessages 0x%X - Leave 1\n", dpy); + return; + } + + XNextEvent(dpy, &evt); + num_events--; + + if( 0==evt.xany.window ) { + NewtCommon_throwNewRuntimeException(env, "event window NULL, bail out!"); + return ; + } + + if(dpy!=evt.xany.display) { + NewtCommon_throwNewRuntimeException(env, "wrong display, bail out!"); + return ; + } + + // DBG_PRINT( "X11: DispatchMessages dpy %p, win %p, Event %d\n", (void*)dpy, (void*)evt.xany.window, evt.type); + + displayDispatchErrorHandlerEnable(1, env); + + jwindow = getJavaWindowProperty(env, dpy, evt.xany.window, javaObjectAtom, + #ifdef VERBOSE_ON + True + #else + False + #endif + ); + + displayDispatchErrorHandlerEnable(0, env); + + if(NULL==jwindow) { + fprintf(stderr, "Warning: NEWT X11 DisplayDispatch %p, Couldn't handle event %d for X11 window %p\n", + (void*)dpy, evt.type, (void*)evt.xany.window); + continue; + } + + switch(evt.type) { + case KeyRelease: + case KeyPress: + if(XLookupString(&evt.xkey,text,255,&keySym,0)==1) { + KeySym lower_return = 0, upper_return = 0; + keyChar=text[0]; + XConvertCase(keySym, &lower_return, &upper_return); + // always return upper case, set modifier masks (SHIFT, ..) + keySym = upper_return; + modifiers = X11InputState2NewtModifiers(evt.xkey.state); + } else { + keyChar=0; + } + break; + + case ButtonPress: + case ButtonRelease: + case MotionNotify: + modifiers = X11InputState2NewtModifiers(evt.xbutton.state); + break; + + default: + break; + } + + switch(evt.type) { + case ButtonPress: + (*env)->CallVoidMethod(env, jwindow, enqueueRequestFocusID, JNI_FALSE); + #ifdef USE_SENDIO_DIRECT + (*env)->CallVoidMethod(env, jwindow, sendMouseEventID, + (jint) EVENT_MOUSE_PRESSED, + modifiers, + (jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button, 0 /*rotation*/); + #else + (*env)->CallVoidMethod(env, jwindow, enqueueMouseEventID, JNI_FALSE, (jint) EVENT_MOUSE_PRESSED, + modifiers, + (jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button, 0 /*rotation*/); + #endif + break; + case ButtonRelease: + #ifdef USE_SENDIO_DIRECT + (*env)->CallVoidMethod(env, jwindow, sendMouseEventID, (jint) EVENT_MOUSE_RELEASED, + modifiers, + (jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button, 0 /*rotation*/); + #else + (*env)->CallVoidMethod(env, jwindow, enqueueMouseEventID, JNI_FALSE, (jint) EVENT_MOUSE_RELEASED, + modifiers, + (jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button, 0 /*rotation*/); + #endif + break; + case MotionNotify: + #ifdef USE_SENDIO_DIRECT + (*env)->CallVoidMethod(env, jwindow, sendMouseEventID, (jint) EVENT_MOUSE_MOVED, + modifiers, + (jint) evt.xmotion.x, (jint) evt.xmotion.y, (jint) 0, 0 /*rotation*/); + #else + (*env)->CallVoidMethod(env, jwindow, enqueueMouseEventID, JNI_FALSE, (jint) EVENT_MOUSE_MOVED, + modifiers, + (jint) evt.xmotion.x, (jint) evt.xmotion.y, (jint) 0, 0 /*rotation*/); + #endif + break; + case KeyPress: + #ifdef USE_SENDIO_DIRECT + (*env)->CallVoidMethod(env, jwindow, sendKeyEventID, (jint) EVENT_KEY_PRESSED, + modifiers, X11KeySym2NewtVKey(keySym), (jchar) keyChar); + #else + (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, JNI_FALSE, (jint) EVENT_KEY_PRESSED, + modifiers, X11KeySym2NewtVKey(keySym), (jchar) keyChar); + #endif + + break; + case KeyRelease: + #ifdef USE_SENDIO_DIRECT + (*env)->CallVoidMethod(env, jwindow, sendKeyEventID, (jint) EVENT_KEY_RELEASED, + modifiers, X11KeySym2NewtVKey(keySym), (jchar) keyChar); + + (*env)->CallVoidMethod(env, jwindow, sendKeyEventID, (jint) EVENT_KEY_TYPED, + modifiers, (jint) -1, (jchar) keyChar); + #else + (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, JNI_FALSE, (jint) EVENT_KEY_RELEASED, + modifiers, X11KeySym2NewtVKey(keySym), (jchar) keyChar); + + (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, JNI_FALSE, (jint) EVENT_KEY_TYPED, + modifiers, (jint) -1, (jchar) keyChar); + #endif + + break; + case DestroyNotify: + DBG_PRINT( "X11: event . DestroyNotify call %p, parent %p, child-event: %d\n", + (void*)evt.xdestroywindow.window, (void*)evt.xdestroywindow.event, evt.xdestroywindow.window != evt.xdestroywindow.event); + if ( evt.xdestroywindow.window == evt.xdestroywindow.event ) { + // ignore child destroy notification + } + break; + case CreateNotify: + DBG_PRINT( "X11: event . CreateNotify call %p, parent %p, child-event: 1\n", + (void*)evt.xcreatewindow.window, (void*) evt.xcreatewindow.parent); + break; + case ConfigureNotify: + DBG_PRINT( "X11: event . ConfigureNotify call %p (parent %p, above %p) %d/%d %dx%d %d, child-event: %d\n", + (void*)evt.xconfigure.window, (void*)evt.xconfigure.event, (void*)evt.xconfigure.above, + evt.xconfigure.x, evt.xconfigure.y, evt.xconfigure.width, evt.xconfigure.height, + evt.xconfigure.override_redirect, evt.xconfigure.window != evt.xconfigure.event); + if ( evt.xconfigure.window == evt.xconfigure.event ) { + // ignore child window change notification + (*env)->CallVoidMethod(env, jwindow, sizeChangedID, + (jint) evt.xconfigure.width, (jint) evt.xconfigure.height, JNI_FALSE); + (*env)->CallVoidMethod(env, jwindow, positionChangedID, + (jint) evt.xconfigure.x, (jint) evt.xconfigure.y); + } + break; + case ClientMessage: + if (evt.xclient.send_event==True && evt.xclient.data.l[0]==(Atom)wmDeleteAtom) { + DBG_PRINT( "X11: event . ClientMessage call %p type 0x%X !!!\n", + (void*)evt.xclient.window, (unsigned int)evt.xclient.message_type); + (*env)->CallVoidMethod(env, jwindow, windowDestroyNotifyID); + // Called by Window.java: CloseWindow(); + } + break; + + case FocusIn: + DBG_PRINT( "X11: event . FocusIn call %p\n", (void*)evt.xvisibility.window); + (*env)->CallVoidMethod(env, jwindow, focusChangedID, JNI_TRUE); + break; + + case FocusOut: + DBG_PRINT( "X11: event . FocusOut call %p\n", (void*)evt.xvisibility.window); + (*env)->CallVoidMethod(env, jwindow, focusChangedID, JNI_FALSE); + break; + + case Expose: + DBG_PRINT( "X11: event . Expose call %p %d/%d %dx%d count %d\n", (void*)evt.xexpose.window, + evt.xexpose.x, evt.xexpose.y, evt.xexpose.width, evt.xexpose.height, evt.xexpose.count); + + if (evt.xexpose.count == 0 && evt.xexpose.width > 0 && evt.xexpose.height > 0) { + (*env)->CallVoidMethod(env, jwindow, windowRepaintID, + evt.xexpose.x, evt.xexpose.y, evt.xexpose.width, evt.xexpose.height); + } + break; + + case MapNotify: + DBG_PRINT( "X11: event . MapNotify call Event %p, Window %p, override_redirect %d, child-event: %d\n", + (void*)evt.xmap.event, (void*)evt.xmap.window, (int)evt.xmap.override_redirect, + evt.xmap.event!=evt.xmap.window); + if( evt.xmap.event == evt.xmap.window ) { + // ignore child window notification + (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_TRUE); + } + break; + + case UnmapNotify: + DBG_PRINT( "X11: event . UnmapNotify call Event %p, Window %p, from_configure %d, child-event: %d\n", + (void*)evt.xunmap.event, (void*)evt.xunmap.window, (int)evt.xunmap.from_configure, + evt.xunmap.event!=evt.xunmap.window); + if( evt.xunmap.event == evt.xunmap.window ) { + // ignore child window notification + (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_FALSE); + } + break; + + case ReparentNotify: + { + jlong parentResult; // 0 if root, otherwise proper value + Window winRoot, winTopParent; + #ifdef VERBOSE_ON + Window oldParentRoot, oldParentTopParent; + Window parentRoot, parentTopParent; + if( 0 == NewtWindows_getRootAndParent(dpy, evt.xreparent.event, &oldParentRoot, &oldParentTopParent) ) { + oldParentRoot=0; oldParentTopParent = 0; + } + if( 0 == NewtWindows_getRootAndParent(dpy, evt.xreparent.parent, &parentRoot, &parentTopParent) ) { + parentRoot=0; parentTopParent = 0; + } + #endif + if( 0 == NewtWindows_getRootAndParent(dpy, evt.xreparent.window, &winRoot, &winTopParent) ) { + winRoot=0; winTopParent = 0; + } + if(evt.xreparent.parent == winRoot) { + parentResult = 0; // our java indicator for root window + } else { + parentResult = (jlong) (intptr_t) evt.xreparent.parent; + } + #ifdef VERBOSE_ON + DBG_PRINT( "X11: event . ReparentNotify: call OldParent %p (root %p, top %p), NewParent %p (root %p, top %p), Window %p (root %p, top %p)\n", + (void*)evt.xreparent.event, (void*)oldParentRoot, (void*)oldParentTopParent, + (void*)evt.xreparent.parent, (void*)parentRoot, (void*)parentTopParent, + (void*)evt.xreparent.window, (void*)winRoot, (void*)winTopParent); + #endif + + (*env)->CallVoidMethod(env, jwindow, windowReparentedID, parentResult); + } + break; + + // unhandled events .. yet .. + + default: + DBG_PRINT("X11: event . unhandled %d 0x%X call %p\n", (int)evt.type, (unsigned int)evt.type, (void*)evt.xunmap.window); + } + } +} + + +/** + * Screen + */ + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: GetScreen + * Signature: (JI)J + */ +JNIEXPORT jlong JNICALL Java_jogamp_newt_x11_X11Screen_GetScreen0 + (JNIEnv *env, jclass clazz, jlong display, jint screen_index) +{ + Display * dpy = (Display *)(intptr_t)display; + Screen * scrn= NULL; + + DBG_PRINT("X11: X11Screen_GetScreen0 dpy %p START\n", dpy); + + if(dpy==NULL) { + NewtCommon_FatalError(env, "invalid display connection.."); + } + + scrn = ScreenOfDisplay(dpy,screen_index); + if(scrn==NULL) { + scrn=DefaultScreenOfDisplay(dpy); + } + if(scrn==NULL) { + fprintf(stderr, "couldn't get screen ..\n"); + } + DBG_PRINT("X11: X11Screen_GetScreen0 scrn %p DONE\n", scrn); + return (jlong) (intptr_t) scrn; +} + +JNIEXPORT jint JNICALL Java_jogamp_newt_x11_X11Screen_getWidth0 + (JNIEnv *env, jclass clazz, jlong display, jint scrn_idx) +{ + Display * dpy = (Display *) (intptr_t) display; + return (jint) XDisplayWidth( dpy, scrn_idx); +} + +JNIEXPORT jint JNICALL Java_jogamp_newt_x11_X11Screen_getHeight0 + (JNIEnv *env, jclass clazz, jlong display, jint scrn_idx) +{ + Display * dpy = (Display *) (intptr_t) display; + return (jint) XDisplayHeight( dpy, scrn_idx); +} + + +static Bool NewtScreen_getRANDRVersion(Display *dpy, int *major, int *minor) { + if( 0 == XRRQueryVersion(dpy, major, minor) ) { + return False; + } + return True; +} + +static Bool NewtScreen_hasRANDR(Display *dpy) { + int major, minor; + return NewtScreen_getRANDRVersion(dpy, &major, &minor); +} + +static int NewtScreen_XRotation2Degree(JNIEnv *env, int xrotation) { + int rot; + if(xrotation == RR_Rotate_0) { + rot = 0; + } + else if(xrotation == RR_Rotate_90) { + rot = 90; + } + else if(xrotation == RR_Rotate_180) { + rot = 180; + } + else if(xrotation == RR_Rotate_270) { + rot = 270; + } else { + NewtCommon_throwNewRuntimeException(env, "invalid native rotation: %d", xrotation); + } + return rot; +} + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: getAvailableScreenModeRotations0 + * Signature: (JI)I + */ +JNIEXPORT jintArray JNICALL Java_jogamp_newt_x11_X11Screen_getAvailableScreenModeRotations0 + (JNIEnv *env, jclass clazz, jlong display, jint scrn_idx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_idx); + int num_rotations = 0; + Rotation cur_rotation, rotations_supported; + int rotations[4]; + int major, minor; + + if(False == NewtScreen_getRANDRVersion(dpy, &major, &minor)) { + fprintf(stderr, "RANDR not available\n"); + return (*env)->NewIntArray(env, 0); + } + + rotations_supported = XRRRotations (dpy, (int)scrn_idx, &cur_rotation); + + if(0 != (rotations_supported & RR_Rotate_0)) { + rotations[num_rotations++] = 0; + } + if(0 != (rotations_supported & RR_Rotate_90)) { + rotations[num_rotations++] = 90; + } + if(0 != (rotations_supported & RR_Rotate_180)) { + rotations[num_rotations++] = 180; + } + if(0 != (rotations_supported & RR_Rotate_270)) { + rotations[num_rotations++] = 270; + } + + jintArray properties = NULL; + + if(num_rotations>0) { + properties = (*env)->NewIntArray(env, num_rotations); + if (properties == NULL) { + NewtCommon_throwNewRuntimeException(env, "Could not allocate int array of size %d", num_rotations); + } + + // move from the temp structure to the java structure + (*env)->SetIntArrayRegion(env, properties, 0, num_rotations, rotations); + } + + return properties; +} + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: getNumScreenModeResolution0 + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_jogamp_newt_x11_X11Screen_getNumScreenModeResolutions0 + (JNIEnv *env, jclass clazz, jlong display, jint scrn_idx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_idx); + + if(False == NewtScreen_hasRANDR(dpy)) { + DBG_PRINT("Java_jogamp_newt_x11_X11Screen_getNumScreenModeResolutions0: RANDR not available\n"); + return 0; + } + + int num_sizes; + XRRScreenSize *xrrs = XRRSizes(dpy, (int)scrn_idx, &num_sizes); //get possible screen resolutions + + return num_sizes; +} + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: getScreenModeResolutions0 + * Signature: (JII)[I + */ +JNIEXPORT jintArray JNICALL Java_jogamp_newt_x11_X11Screen_getScreenModeResolution0 + (JNIEnv *env, jclass clazz, jlong display, jint scrn_idx, jint resMode_idx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_idx); + + if(False == NewtScreen_hasRANDR(dpy)) { + DBG_PRINT("Java_jogamp_newt_x11_X11Screen_getScreenModeResolution0: RANDR not available\n"); + return (*env)->NewIntArray(env, 0); + } + + int num_sizes; + XRRScreenSize *xrrs = XRRSizes(dpy, (int)scrn_idx, &num_sizes); //get possible screen resolutions + + if( 0 > resMode_idx || resMode_idx >= num_sizes ) { + NewtCommon_throwNewRuntimeException(env, "Invalid resolution index: ! 0 < %d < %d", resMode_idx, num_sizes); + } + + // Fill the properties in temp jint array + int propIndex = 0; + jint prop[4]; + + prop[propIndex++] = xrrs[(int)resMode_idx].width; + prop[propIndex++] = xrrs[(int)resMode_idx].height; + prop[propIndex++] = xrrs[(int)resMode_idx].mwidth; + prop[propIndex++] = xrrs[(int)resMode_idx].mheight; + + jintArray properties = (*env)->NewIntArray(env, 4); + if (properties == NULL) { + NewtCommon_throwNewRuntimeException(env, "Could not allocate int array of size %d", 4); + } + + // move from the temp structure to the java structure + (*env)->SetIntArrayRegion(env, properties, 0, 4, prop); + + return properties; +} + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: getScreenModeRates0 + * Signature: (JII)[I + */ +JNIEXPORT jintArray JNICALL Java_jogamp_newt_x11_X11Screen_getScreenModeRates0 + (JNIEnv *env, jclass clazz, jlong display, jint scrn_idx, jint resMode_idx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_idx); + + if(False == NewtScreen_hasRANDR(dpy)) { + DBG_PRINT("Java_jogamp_newt_x11_X11Screen_getScreenModeRates0: RANDR not available\n"); + return (*env)->NewIntArray(env, 0); + } + + int num_sizes; + XRRScreenSize *xrrs = XRRSizes(dpy, (int)scrn_idx, &num_sizes); //get possible screen resolutions + + if( 0 > resMode_idx || resMode_idx >= num_sizes ) { + NewtCommon_throwNewRuntimeException(env, "Invalid resolution index: ! 0 < %d < %d", resMode_idx, num_sizes); + } + + int num_rates; + short *rates = XRRRates(dpy, (int)scrn_idx, (int)resMode_idx, &num_rates); + + jint prop[num_rates]; + int i; + for(i=0; i<num_rates; i++) { + prop[i] = (int) rates[i]; + /** fprintf(stderr, "rate[%d, %d, %d/%d]: %d\n", (int)scrn_idx, resMode_idx, i, num_rates, prop[i]); */ + } + + jintArray properties = (*env)->NewIntArray(env, num_rates); + if (properties == NULL) { + NewtCommon_throwNewRuntimeException(env, "Could not allocate int array of size %d", num_rates); + } + + // move from the temp structure to the java structure + (*env)->SetIntArrayRegion(env, properties, 0, num_rates, prop); + + return properties; +} + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: getCurrentScreenRate0 + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_jogamp_newt_x11_X11Screen_getCurrentScreenRate0 + (JNIEnv *env, jclass clazz, jlong display, jint scrn_idx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_idx); + + if(False == NewtScreen_hasRANDR(dpy)) { + DBG_PRINT("Java_jogamp_newt_x11_X11Screen_getCurrentScreenRate0: RANDR not available\n"); + return -1; + } + + // get current resolutions and frequencies + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); + short original_rate = XRRConfigCurrentRate(conf); + + //free + XRRFreeScreenConfigInfo(conf); + + return (jint) original_rate; +} + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: getCurrentScreenRotation0 + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_jogamp_newt_x11_X11Screen_getCurrentScreenRotation0 + (JNIEnv *env, jclass clazz, jlong display, jint scrn_idx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_idx); + + if(False == NewtScreen_hasRANDR(dpy)) { + DBG_PRINT("Java_jogamp_newt_x11_X11Screen_getCurrentScreenRotation0: RANDR not available\n"); + return -1; + } + + //get current resolutions and frequencies + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); + + Rotation rotation; + XRRConfigCurrentConfiguration(conf, &rotation); + + //free + XRRFreeScreenConfigInfo(conf); + + return NewtScreen_XRotation2Degree(env, rotation); +} + + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: getCurrentScreenResolutionIndex0 + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_jogamp_newt_x11_X11Screen_getCurrentScreenResolutionIndex0 + (JNIEnv *env, jclass clazz, jlong display, jint scrn_idx) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)scrn_idx); + + if(False == NewtScreen_hasRANDR(dpy)) { + DBG_PRINT("Java_jogamp_newt_x11_X11Screen_getCurrentScreenResolutionIndex0: RANDR not available\n"); + return -1; + } + + // get current resolutions and frequency configuration + XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); + short original_rate = XRRConfigCurrentRate(conf); + + Rotation original_rotation; + SizeID original_size_id = XRRConfigCurrentConfiguration(conf, &original_rotation); + + //free + XRRFreeScreenConfigInfo(conf); + + return (jint)original_size_id; +} + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: setCurrentScreenModeStart0 + * Signature: (JIIII)Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_x11_X11Screen_setCurrentScreenModeStart0 + (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jint resMode_idx, jint freq, jint rotation) +{ + Display *dpy = (Display *) (intptr_t) display; + Window root = RootWindow(dpy, (int)screen_idx); + + if(False == NewtScreen_hasRANDR(dpy)) { + DBG_PRINT("Java_jogamp_newt_x11_X11Screen_setCurrentScreenModeStart0: RANDR not available\n"); + return JNI_FALSE; + } + + int num_sizes; + XRRScreenSize *xrrs = XRRSizes(dpy, (int)screen_idx, &num_sizes); //get possible screen resolutions + XRRScreenConfiguration *conf; + int rot; + + if( 0 > resMode_idx || resMode_idx >= num_sizes ) { + NewtCommon_throwNewRuntimeException(env, "Invalid resolution index: ! 0 < %d < %d", resMode_idx, num_sizes); + } + + conf = XRRGetScreenInfo(dpy, root); + + switch(rotation) { + case 0: + rot = RR_Rotate_0; + break; + case 90: + rot = RR_Rotate_90; + break; + case 180: + rot = RR_Rotate_180; + break; + case 270: + rot = RR_Rotate_270; + break; + default: + NewtCommon_throwNewRuntimeException(env, "Invalid rotation: %d", rotation); + } + + DBG_PRINT("X11Screen.setCurrentScreenMode0: CHANGED TO %d: %d x %d PIXELS, %d Hz, %d degree\n", + resMode_idx, xrrs[resMode_idx].width, xrrs[resMode_idx].height, (int)freq, rotation); + + XRRSelectInput (dpy, root, RRScreenChangeNotifyMask); + + XSync(dpy, False); + XRRSetScreenConfigAndRate(dpy, conf, root, (int)resMode_idx, rot, (short)freq, CurrentTime); + XSync(dpy, False); + + //free + XRRFreeScreenConfigInfo(conf); + XSync(dpy, False); + + return JNI_TRUE; +} + +/* + * Class: jogamp_newt_x11_X11Screen + * Method: setCurrentScreenModePollEnd0 + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_x11_X11Screen_setCurrentScreenModePollEnd0 + (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jint resMode_idx, jint freq, jint rotation) +{ + Display *dpy = (Display *) (intptr_t) display; + int randr_event_base, randr_error_base; + XEvent evt; + XRRScreenChangeNotifyEvent * scn_event = (XRRScreenChangeNotifyEvent *) &evt; + + if(False == NewtScreen_hasRANDR(dpy)) { + DBG_PRINT("Java_jogamp_newt_x11_X11Screen_setCurrentScreenModePollEnd0: RANDR not available\n"); + return JNI_FALSE; + } + + int num_sizes; + XRRScreenSize *xrrs = XRRSizes(dpy, (int)screen_idx, &num_sizes); //get possible screen resolutions + XRRScreenConfiguration *conf; + + if( 0 > resMode_idx || resMode_idx >= num_sizes ) { + NewtCommon_throwNewRuntimeException(env, "Invalid resolution index: ! 0 < %d < %d", resMode_idx, num_sizes); + } + + XRRQueryExtension(dpy, &randr_event_base, &randr_error_base); + + int done = 0; + int rot; + do { + if ( 0 >= XEventsQueued(dpy, QueuedAfterFlush) ) { + return; + } + XNextEvent(dpy, &evt); + + switch (evt.type - randr_event_base) { + case RRScreenChangeNotify: + rot = NewtScreen_XRotation2Degree(env, (int)scn_event->rotation); + DBG_PRINT( "XRANDR: event . RRScreenChangeNotify call %p (root %p) resIdx %d rot %d %dx%d\n", + (void*)scn_event->window, (void*)scn_event->root, + (int)scn_event->size_index, rot, + scn_event->width, scn_event->height); + // done = scn_event->size_index == resMode_idx; // not reliable .. + done = rot == rotation && + scn_event->width == xrrs[resMode_idx].width && + scn_event->height == xrrs[resMode_idx].height; + break; + default: + DBG_PRINT("RANDR: event . unhandled %d 0x%X call %p\n", (int)evt.type, (int)evt.type, (void*)evt.xany.window); + } + XRRUpdateConfiguration(&evt); + } while(!done); + + XSync(dpy, False); + +} + +/** + * Window + */ + +/* + * Class: jogamp_newt_x11_X11Window + * Method: initIDs + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_x11_X11Window_initIDs0 + (JNIEnv *env, jclass clazz) +{ + sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(IIZ)V"); + positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V"); + focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(Z)V"); + visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V"); + windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V"); + windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(IIII)V"); + windowReparentedID = (*env)->GetMethodID(env, clazz, "windowReparented", "(J)V"); + enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZIIIIII)V"); + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V"); + enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(ZIIIC)V"); + sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + enqueueRequestFocusID = (*env)->GetMethodID(env, clazz, "enqueueRequestFocus", "(Z)V"); + focusActionID = (*env)->GetMethodID(env, clazz, "focusAction", "()Z"); + + if (sizeChangedID == NULL || + positionChangedID == NULL || + focusChangedID == NULL || + visibleChangedID == NULL || + windowDestroyNotifyID == NULL || + windowRepaintID == NULL || + windowReparentedID == NULL || + enqueueMouseEventID == NULL || + sendMouseEventID == NULL || + enqueueKeyEventID == NULL || + sendKeyEventID == NULL || + focusActionID == NULL || + enqueueRequestFocusID == NULL) { + return JNI_FALSE; + } + return JNI_TRUE; +} + +/* + * Class: jogamp_newt_x11_X11Window + * Method: CreateWindow + * Signature: (JJIJIIII)J + */ +JNIEXPORT jlong JNICALL Java_jogamp_newt_x11_X11Window_CreateWindow0 + (JNIEnv *env, jobject obj, jlong parent, jlong display, jint screen_index, + jlong visualID, + jlong javaObjectAtom, jlong windowDeleteAtom, + jint x, jint y, jint width, jint height, + jboolean undecorated) +{ + Display * dpy = (Display *)(intptr_t)display; + int scrn_idx = (int)screen_index; + Window windowParent = (Window) parent; + Window window = 0; + + XVisualInfo visualTemplate; + XVisualInfo *pVisualQuery = NULL; + Visual *visual = NULL; + int depth; + + XSetWindowAttributes xswa; + unsigned long attrMask; + int n; + + Screen* scrn; + Atom wm_delete_atom; + + if(dpy==NULL) { + NewtCommon_FatalError(env, "invalid display connection.."); + } + + if(visualID<0) { + NewtCommon_throwNewRuntimeException(env, "invalid VisualID .."); + return 0; + } + + XSync(dpy, False); + + scrn = ScreenOfDisplay(dpy, scrn_idx); + if(0==windowParent) { + windowParent = XRootWindowOfScreen(scrn); + } + if( XRootWindowOfScreen(scrn) != XRootWindow(dpy, scrn_idx) ) { + NewtCommon_FatalError(env, "XRoot Malfunction: %p != %p"+XRootWindowOfScreen(scrn), XRootWindow(dpy, scrn_idx)); + } + DBG_PRINT( "X11: CreateWindow dpy %p, parent %p, %x/%d %dx%d, undeco %d\n", + (void*)dpy, (void*)windowParent, x, y, width, height, undecorated); + + // try given VisualID on screen + memset(&visualTemplate, 0, sizeof(XVisualInfo)); + visualTemplate.screen = scrn_idx; + visualTemplate.visualid = (VisualID)visualID; + pVisualQuery = XGetVisualInfo(dpy, VisualIDMask|VisualScreenMask, &visualTemplate,&n); + DUMP_VISUAL_INFO("Given VisualID,ScreenIdx", pVisualQuery); + if(pVisualQuery!=NULL) { + visual = pVisualQuery->visual; + depth = pVisualQuery->depth; + visualID = (jlong)pVisualQuery->visualid; + XFree(pVisualQuery); + pVisualQuery=NULL; + } + DBG_PRINT( "X11: [CreateWindow] trying given (dpy %p, screen %d, visualID: %d, parent %p) found: %p\n", + dpy, scrn_idx, (int)visualID, (void*)windowParent, visual); + + if (visual==NULL) + { + NewtCommon_throwNewRuntimeException(env, "could not query Visual by given VisualID, bail out!"); + return 0; + } + + if(pVisualQuery!=NULL) { + XFree(pVisualQuery); + pVisualQuery=NULL; + } + + attrMask = ( CWBackingStore | CWBackingPlanes | CWBackingPixel | CWBackPixmap | + CWBorderPixel | CWColormap | CWOverrideRedirect ) ; + + memset(&xswa, 0, sizeof(xswa)); + xswa.override_redirect = False; // use the window manager, always + xswa.border_pixel = 0; + xswa.background_pixmap = None; + xswa.backing_store=NotUseful; /* NotUseful, WhenMapped, Always */ + xswa.backing_planes=0; /* planes to be preserved if possible */ + xswa.backing_pixel=0; /* value to use in restoring planes */ + + xswa.colormap = XCreateColormap(dpy, + windowParent, + visual, + AllocNone); + + window = XCreateWindow(dpy, + windowParent, + x, y, + width, height, + 0, // border width + depth, + InputOutput, + visual, + attrMask, + &xswa); + + if(0==window) { + NewtCommon_throwNewRuntimeException(env, "could not create Window, bail out!"); + return 0; + } + + wm_delete_atom = (Atom)windowDeleteAtom; + XSetWMProtocols(dpy, window, &wm_delete_atom, 1); + + setJavaWindowProperty(env, dpy, window, javaObjectAtom, (*env)->NewGlobalRef(env, obj)); + + // XClearWindow(dpy, window); + XSync(dpy, False); + + { + long xevent_mask = 0; + xevent_mask |= ButtonPressMask | ButtonReleaseMask | PointerMotionMask ; + xevent_mask |= KeyPressMask | KeyReleaseMask ; + xevent_mask |= FocusChangeMask | SubstructureNotifyMask | StructureNotifyMask | ExposureMask ; + + XSelectInput(dpy, window, xevent_mask); + } + + NewtWindows_setDecorations(dpy, window, ( JNI_TRUE == undecorated ) ? False : True ); + XSync(dpy, False); + + DBG_PRINT( "X11: [CreateWindow] created window %p on display %p\n", (void*)window, dpy); + return (jlong) window; +} + +/* + * Class: jogamp_newt_x11_X11Window + * Method: CloseWindow + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_x11_X11Window_CloseWindow0 + (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom, jlong wmDeleteAtom) +{ + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + jobject jwindow; + + if(dpy==NULL) { + NewtCommon_FatalError(env, "invalid display connection.."); + } + + DBG_PRINT( "X11: CloseWindow START dpy %p, win %p\n", (void*)dpy, (void*)w); + + jwindow = getJavaWindowProperty(env, dpy, w, javaObjectAtom, True); + if(NULL==jwindow) { + NewtCommon_throwNewRuntimeException(env, "could not fetch Java Window object, bail out!"); + return; + } + if ( JNI_FALSE == (*env)->IsSameObject(env, jwindow, obj) ) { + NewtCommon_throwNewRuntimeException(env, "Internal Error .. Window global ref not the same!"); + return; + } + + XSync(dpy, False); + XSelectInput(dpy, w, 0); + XUnmapWindow(dpy, w); + + // Drain all events related to this window .. + Java_jogamp_newt_x11_X11Display_DispatchMessages0(env, obj, display, javaObjectAtom, wmDeleteAtom); + + XDestroyWindow(dpy, w); + XSync(dpy, False); + + (*env)->DeleteGlobalRef(env, jwindow); + + DBG_PRINT( "X11: CloseWindow END\n"); +} + +static void NewtWindows_setPosSize(Display *dpy, Window w, jint x, jint y, jint width, jint height) +{ + if(width>0 && height>0 || x>=0 && y>=0) { // resize/position if requested + XWindowChanges xwc; + unsigned int mod_flags = ( (x>=0)?CWX:0 ) | ( (y>=0)?CWY:0 ) | + ( (width>0)?CWWidth:0 ) | ( (height>0)?CWHeight:0 ) ; + DBG_PRINT( "X11: reconfigureWindow0 pos/size mod: 0x%X\n", mod_flags); + memset(&xwc, 0, sizeof(XWindowChanges)); + xwc.x=x; + xwc.y=y; + xwc.width=width; + xwc.height=height; + XConfigureWindow(dpy, w, mod_flags, &xwc); + XSync(dpy, False); + } +} + +/* + * Class: jogamp_newt_x11_X11Window + * Method: setVisible0 + * Signature: (JJZIIII)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_x11_X11Window_setVisible0 + (JNIEnv *env, jobject obj, jlong display, jlong window, jboolean visible, jint x, jint y, jint width, jint height) +{ + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + DBG_PRINT( "X11: setVisible0 vis %d\n", visible); + + if(dpy==NULL) { + NewtCommon_FatalError(env, "invalid display connection.."); + } + + if(visible==JNI_TRUE) { + XMapRaised(dpy, w); + } else { + XUnmapWindow(dpy, w); + } + XSync(dpy, False); + + NewtWindows_setPosSize(dpy, w, x, y, width, height); +} + +/* + * Class: jogamp_newt_x11_X11Window + * Method: reconfigureWindow0 + * Signature: (JIJJIIIIZZII)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_x11_X11Window_reconfigureWindow0 + (JNIEnv *env, jobject obj, jlong jdisplay, jint screen_index, jlong jparent, jlong jwindow, + jint x, jint y, jint width, jint height, jboolean isVisible, jboolean parentChange, jint fullscreenChange, jint decorationChange) +{ + Display * dpy = (Display *) (intptr_t) jdisplay; + Screen * scrn = ScreenOfDisplay(dpy, (int)screen_index); + Window w = (Window)jwindow; + Window root = XRootWindowOfScreen(scrn); + Window parent = (0!=jparent)?(Window)jparent:root; + Window topParentParent; + Window topParentWindow; + Bool moveIntoParent = False; + + displayDispatchErrorHandlerEnable(1, env); + + topParentParent = NewtWindows_getParent (dpy, parent); + topParentWindow = NewtWindows_getParent (dpy, w); + + DBG_PRINT( "X11: reconfigureWindow0 dpy %p, scrn %d/%p, parent %p/%p (top %p), win %p (top %p), %d/%d %dx%d visible %d, parentChange %d, fullscreenChange %d, decorationChange %d\n", + (void*)dpy, screen_index, (void*)scrn, (void*) jparent, (void*)parent, (void*) topParentParent, (void*)w, (void*)topParentWindow, + x, y, width, height, isVisible, parentChange, fullscreenChange, decorationChange); + + if(parentChange && JNI_TRUE == isVisible) { // unmap window if visible, reduce X11 internal signaling (WM unmap) + XUnmapWindow(dpy, w); + XSync(dpy, False); + } + + if(0 > fullscreenChange ) { // FS off + NewtWindows_setFullscreen(dpy, root, w, False ); + XSync(dpy, False); + } + + if(parentChange) { + if(0 != jparent) { // move into parent .. + moveIntoParent = True; + NewtWindows_setDecorations (dpy, w, False); + XSync(dpy, False); + } + XReparentWindow( dpy, w, parent, x, y ); // actual reparent call + XSync(dpy, False); + } + + if(!moveIntoParent && 0!=decorationChange) { + NewtWindows_setDecorations (dpy, w, (0 < decorationChange) ? True : False); + XSync(dpy, False); + } + + NewtWindows_setPosSize(dpy, w, x, y, width, height); + + if(0 < fullscreenChange ) { // FS on + NewtWindows_setFullscreen(dpy, root, w, True ); + XSync(dpy, False); + } + + if(parentChange && JNI_TRUE == isVisible) { // map window + XMapRaised(dpy, w); + XSync(dpy, False); + } + + displayDispatchErrorHandlerEnable(0, env); + + DBG_PRINT( "X11: reconfigureWindow0 X\n"); +} + +/* + * Class: jogamp_newt_x11_X11Window + * Method: requestFocus0 + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_x11_X11Window_requestFocus0 + (JNIEnv *env, jobject obj, jlong display, jlong window, jboolean force) +{ + NewtWindows_requestFocus ( env, obj, (Display *) (intptr_t) display, (Window)window, force ) ; +} + +/* + * Class: Java_jogamp_newt_x11_X11Window + * Method: setTitle0 + * Signature: (JJLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_x11_X11Window_setTitle0 + (JNIEnv *env, jclass clazz, jlong display, jlong window, jstring title) +{ + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + +#if 1 + const char* title_str; + if (NULL != title) { + title_str = (*env)->GetStringUTFChars(env, title, NULL); + if(NULL != title_str) { + DBG_PRINT( "X11: setTitle: <%s> SET\n", title_str); + XStoreName(dpy, w, title_str); + (*env)->ReleaseStringUTFChars(env, title, title_str); + } else { + DBG_PRINT( "X11: setTitle: NULL - NOT SET (1)\n"); + } + } else { + DBG_PRINT( "X11: setTitle: NULL TITLE\n"); + } +#else + char *str_list[] = { NULL }; + XTextProperty text_prop; + if (NULL != title) { + str_list[0] = (char *) NewtCommon_GetNullTerminatedStringChars(env, title); + if (str_list[0] != NULL) { + memset(&text_prop, 0, sizeof(XTextProperty)); + if ( Success != XmbTextListToTextProperty(dpy, str_list, 1, XStringStyle, &text_prop) ) { + DBG_PRINT( "X11: setTitle.XmbTextListToTextProperty not completly successfull\n"); + fprintf(stderr, "X11: setTitle.XmbTextListToTextProperty not completly successfull\n"); + } + if(NULL!=text_prop.value) { + DBG_PRINT( "X11: setTitle: <%s> SET\n", str_list[0]); + XSetWMName(dpy, w, &text_prop); + XFree(text_prop.value); + } else { + DBG_PRINT( "X11: setTitle: <%s> NOT SET (1)\n", str_list[0]); + } + free(str_list[0]); + } else { + DBG_PRINT( "X11: setTitle: NULL\n"); + } + } +#endif +} + diff --git a/src/org/apache/harmony/misc/HashCode.java b/src/org/apache/harmony/misc/HashCode.java deleted file mode 100644 index e8ce8f620..000000000 --- a/src/org/apache/harmony/misc/HashCode.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.misc; - -/** - * This class is a convenience method to sequentially calculate hash code of the - * object based on the field values. The result depends on the order of elements - * appended. The exact formula is the same as for - * <code>java.util.List.hashCode</code>. - * - * If you need order independent hash code just summate, multiply or XOR all - * elements. - * - * <p> - * Suppose we have class: - * - * <pre><code> - * class Thing { - * long id; - * String name; - * float weight; - * } - * </code></pre> - * - * The hash code calculation can be expressed in 2 forms. - * - * <p> - * For maximum performance: - * - * <pre><code> - * public int hashCode() { - * int hashCode = HashCode.EMPTY_HASH_CODE; - * hashCode = HashCode.combine(hashCode, id); - * hashCode = HashCode.combine(hashCode, name); - * hashCode = HashCode.combine(hashCode, weight); - * return hashCode; - * } - * </code></pre> - * - * <p> - * For convenience: <code><pre> - * public int hashCode() { - * return new HashCode().append(id).append(name).append(weight).hashCode(); - * } - * </code></pre> - * - * @see java.util.List#hashCode() - */ -public final class HashCode { - /** - * The hashCode value before any data is appended, equals to 1. - * @see java.util.List#hashCode() - */ - public static final int EMPTY_HASH_CODE = 1; - - private int hashCode = EMPTY_HASH_CODE; - - /** - * Returns accumulated hashCode - */ - public final int hashCode() { - return hashCode; - } - - /** - * Combines hashCode of previous elements sequence and value's hashCode. - * @param hashCode previous hashCode value - * @param value new element - * @return combined hashCode - */ - public static int combine(int hashCode, boolean value) { - int v = value ? 1231 : 1237; - return combine(hashCode, v); - } - - /** - * Combines hashCode of previous elements sequence and value's hashCode. - * @param hashCode previous hashCode value - * @param value new element - * @return combined hashCode - */ - public static int combine(int hashCode, long value) { - int v = (int) (value ^ (value >>> 32)); - return combine(hashCode, v); - } - - /** - * Combines hashCode of previous elements sequence and value's hashCode. - * @param hashCode previous hashCode value - * @param value new element - * @return combined hashCode - */ - public static int combine(int hashCode, float value) { - int v = Float.floatToIntBits(value); - return combine(hashCode, v); - } - - /** - * Combines hashCode of previous elements sequence and value's hashCode. - * @param hashCode previous hashCode value - * @param value new element - * @return combined hashCode - */ - public static int combine(int hashCode, double value) { - long v = Double.doubleToLongBits(value); - return combine(hashCode, v); - } - - /** - * Combines hashCode of previous elements sequence and value's hashCode. - * @param hashCode previous hashCode value - * @param value new element - * @return combined hashCode - */ - public static int combine(int hashCode, Object value) { - return combine(hashCode, value.hashCode()); - } - - /** - * Combines hashCode of previous elements sequence and value's hashCode. - * @param hashCode previous hashCode value - * @param value new element - * @return combined hashCode - */ - public static int combine(int hashCode, int value) { - return 31 * hashCode + value; - } - - /** - * Appends value's hashCode to the current hashCode. - * @param value new element - * @return this - */ - public final HashCode append(int value) { - hashCode = combine(hashCode, value); - return this; - } - - /** - * Appends value's hashCode to the current hashCode. - * @param value new element - * @return this - */ - public final HashCode append(long value) { - hashCode = combine(hashCode, value); - return this; - } - - /** - * Appends value's hashCode to the current hashCode. - * @param value new element - * @return this - */ - public final HashCode append(float value) { - hashCode = combine(hashCode, value); - return this; - } - - /** - * Appends value's hashCode to the current hashCode. - * @param value new element - * @return this - */ - public final HashCode append(double value) { - hashCode = combine(hashCode, value); - return this; - } - - /** - * Appends value's hashCode to the current hashCode. - * @param value new element - * @return this - */ - public final HashCode append(boolean value) { - hashCode = combine(hashCode, value); - return this; - } - - /** - * Appends value's hashCode to the current hashCode. - * @param value new element - * @return this - */ - public final HashCode append(Object value) { - hashCode = combine(hashCode, value); - return this; - } -} diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanelTest1.java b/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanelTest1.java new file mode 100644 index 000000000..ceee2c876 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanelTest1.java @@ -0,0 +1,72 @@ +package com.jogamp.opengl.test.bugs;
+
+import javax.swing.*;
+import java.awt.*;
+import javax.media.opengl.*;
+import javax.media.opengl.awt.*;
+
+public class Bug427GLJPanelTest1 extends JFrame implements GLEventListener {
+
+ public Bug427GLJPanelTest1() {
+ super("Bug427GLJPanelTest1");
+
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setLayout(new BorderLayout());
+
+ setSize(600, 600);
+ setLocation(40, 40);
+ setVisible(true);
+
+ GLProfile glp = GLProfile.getDefault();
+ GLCapabilities caps = new GLCapabilities(glp);
+ caps.setDoubleBuffered(true);
+ caps.setHardwareAccelerated(true);
+
+ GLJPanel panel = new GLJPanel(caps);
+ panel.addGLEventListener(this);
+
+ add(panel, BorderLayout.CENTER);
+ }
+
+ public static void main(String[] args) {
+ Bug427GLJPanelTest1 demo = new Bug427GLJPanelTest1();
+ demo.setVisible(true);
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT);
+ gl.glBegin(GL.GL_TRIANGLES);
+
+ gl.glColor3f(1, 0, 0);
+ gl.glVertex3f(0.25f, 0.25f, 0);
+
+ gl.glColor3f(0, 1, 0);
+ gl.glVertex3f(0.5f, 0.25f, 0);
+
+ gl.glColor3f(0, 0, 1);
+ gl.glVertex3f(0.25f, 0.5f, 0);
+
+ gl.glEnd();
+ gl.glFlush();
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.glClearColor(0, 0, 0, 0);
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glLoadIdentity();
+ gl.glOrtho(0, 1, 0, 1, -1, 1);
+ }
+
+ public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java b/src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java new file mode 100644 index 000000000..4c2b54755 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java @@ -0,0 +1,94 @@ +package com.jogamp.opengl.test.bugs; + +import java.awt.Frame; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.Random; + +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.awt.GLCanvas; +import javax.media.opengl.glu.GLU; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.awt.TextRenderer; + +/** + * Demonstrates corruption with older versions of TextRenderer. Two + * problems: errors when punting from glyph-based renderer to + * string-by-string renderer, and failure of glyph-based renderer when + * backing store was NPOT using GL_ARB_texture_rectangle. + * + * @author emzic + */ + +public class Issue326Test1 extends Frame implements GLEventListener { + + int width, height; + + public static void main(String[] args) { + new Issue326Test1(); + } + + GLCanvas canvas; + TextRenderer tr ; + + public Issue326Test1() { + super("TextTest"); + this.setSize(800, 800); + canvas = new GLCanvas(); + canvas.addGLEventListener(this); + add(canvas); + + setVisible(true); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + gl.glClearColor(0, 0, 0, 0); + gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT); + + + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + //new GLU().gluPerspective(45f, (float)width/(float)height, 0.1f, 1000f); + gl.glOrtho(0.0, 800, 0.0, 800, -100.0, 100.0); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + + tr.beginRendering(800,800); + tr.draw( "die Marktwirtschaft. Da regelt sich � angeblich", 16, 32); + tr.draw( "Hello World! This text is scrambled", 16, 16); + tr.endRendering(); + + } + + public void init(GLAutoDrawable arg0) { + tr = new TextRenderer(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 12), true, false, null, false); + tr.setColor(1, 1, 1 ,1); + } + + public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { + width = arg3; + height = arg4; + GL2 gl = arg0.getGL().getGL2(); + gl.glViewport(0, 0, width, height); + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(0.0, 800, 0.0, 200, -100.0, 100.0); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) {} +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java b/src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java new file mode 100644 index 000000000..8960c9658 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java @@ -0,0 +1,73 @@ +package com.jogamp.opengl.test.bugs; + +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.*; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.awt.GLCanvas; + +import com.jogamp.opengl.util.awt.*; + +/** + * Another test case demonstrating corruption with older version of + * TextRenderer when glyphs were too big for backing store. Font and + * text courtesy of Patrick Murris. Adapted from Issue326Test1. + */ + +public class Issue326Test2 extends Frame implements GLEventListener { + + int width, height; + + public static void main(String[] args) { + new Issue326Test2(); + } + + GLCanvas canvas; + TextRenderer tr; + + public Issue326Test2() { + super(""); + this.setSize(800, 800); + canvas = new GLCanvas(); + canvas.addGLEventListener(this); + add(canvas); + + setVisible(true); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + gl.glClearColor(0, 0, 0, 0); + gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT); + + tr.beginRendering(drawable.getWidth(), drawable.getHeight()); + tr.draw("LA CLAPI\u00c8RE \nAlt: 1100-1700m \nGlissement de terrain majeur", 16, 80); + tr.draw("dans la haute Tin\u00e9e, sur un flanc du Parc du Mercantour.", 16, 16); + tr.endRendering(); + + } + + public void init(GLAutoDrawable arg0) { + tr = new TextRenderer(Font.decode("Arial-BOLD-64")); + tr.setColor(1, 1, 1 ,1); + } + + public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) { + GL2 gl = arg0.getGL().getGL2(); + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(0.0, w, 0.0, h, -1, 1); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) {} +} + diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java new file mode 100644 index 000000000..c3401fec3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java @@ -0,0 +1,107 @@ +package com.jogamp.opengl.test.bugs; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.*; +import java.awt.geom.*; + +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.awt.GLCanvas; +import javax.media.opengl.glu.*; +import com.jogamp.opengl.util.awt.TextRenderer; + +/** Test Code adapted from TextCube.java (in JOGL demos) + * + * @author spiraljetty + * @author kbr + */ + +public abstract class Issue344Base implements GLEventListener +{ + GLU glu = new GLU(); + TextRenderer renderer; + + float textScaleFactor; + Font font; + boolean useMipMaps; + + protected Issue344Base() { + font = new Font("default", Font.PLAIN, 200); + useMipMaps = true; //false + } + + protected abstract String getText(); + + protected void run(String[] args) { + Frame frame = new Frame(getClass().getName()); + frame.setLayout(new BorderLayout()); + + GLCanvas canvas = new GLCanvas(); + canvas.addGLEventListener(this); + frame.add(canvas, BorderLayout.CENTER); + + frame.setSize(512, 512); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + new Thread(new Runnable() { + public void run() { + System.exit(0); + } + }).start(); + } + }); + frame.setVisible(true); + } + + public void init(GLAutoDrawable drawable) + { + GL2 gl = drawable.getGL().getGL2(); + + gl.glEnable(GL2.GL_DEPTH_TEST); + + renderer = new TextRenderer(font, useMipMaps); + + Rectangle2D bounds = renderer.getBounds(getText()); + float w = (float) bounds.getWidth(); + float h = (float) bounds.getHeight(); + textScaleFactor = 2.0f / (w * 1.1f); + gl.setSwapInterval(0); + } + + public void display(GLAutoDrawable drawable) + { + GL2 gl = drawable.getGL().getGL2(); + gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); + + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + glu.gluLookAt(0, 0, 10, + 0, 0, 0, + 0, 1, 0); + + renderer.begin3DRendering(); + Rectangle2D bounds = renderer.getBounds(getText()); + float w = (float) bounds.getWidth(); + float h = (float) bounds.getHeight(); + renderer.draw3D(getText(), + w / -2.0f * textScaleFactor, + h / -2.0f * textScaleFactor, + 3f, + textScaleFactor); + + renderer.end3DRendering(); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) + { + GL2 gl = drawable.getGL().getGL2(); + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluPerspective(15, (float) width / (float) height, 5, 15); + } + + public void dispose(GLAutoDrawable drawable) {} +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java new file mode 100644 index 000000000..f0da7cbf8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java @@ -0,0 +1,12 @@ +package com.jogamp.opengl.test.bugs; + +public class Issue344Test1 extends Issue344Base { + protected String getText() { + // test 1 - weird artifacts appear with a large font & long string + return "abcdefghijklmnopqrstuvwxyz1234567890"; + } + + public static void main(String[] args) { + new Issue344Test1().run(args); + } +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java new file mode 100644 index 000000000..bb1acf2de --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java @@ -0,0 +1,12 @@ +package com.jogamp.opengl.test.bugs; + +public class Issue344Test2 extends Issue344Base { + protected String getText() { + // test 2 - unicode hangs program with a large font & long string + return "\u201Cabcdefghijklmnopqrstuvwxyz\u201D"; + } + + public static void main(String[] args) { + new Issue344Test2().run(args); + } +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java new file mode 100644 index 000000000..bb73d84ec --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java @@ -0,0 +1,12 @@ +package com.jogamp.opengl.test.bugs; + +public class Issue344Test3 extends Issue344Base { + protected String getText() { + // test 3 - slight rendering artifacts around very large letters + return "abcde"; + } + + public static void main(String[] args) { + new Issue344Test3().run(args); + } +} diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java new file mode 100644 index 000000000..de4c37a40 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java @@ -0,0 +1,12 @@ +package com.jogamp.opengl.test.bugs; + +public class Issue344Test4 extends Issue344Base { + protected String getText() { + // test 4 - unicode letter as second-to-last is rendered incorrectly + return "\u201CGreetings\u201D!"; + } + + public static void main(String[] args) { + new Issue344Test4().run(args); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLExtensionQueryOffscreen.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLExtensionQueryOffscreen.java new file mode 100644 index 000000000..a7d57a9a9 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLExtensionQueryOffscreen.java @@ -0,0 +1,100 @@ +/** + * 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.jogl.acore; + +import java.util.Collections; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.opengl.DefaultGLCapabilitiesChooser; +import javax.media.opengl.GL; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLProfile; + +import org.junit.Test; + +public class TestGLExtensionQueryOffscreen { + + static { + GLProfile.initSingleton(false); + } + + public static void main(String[] args) { + TestGLExtensionQueryOffscreen instance = new TestGLExtensionQueryOffscreen(); + instance.testJogl2ExtensionCheck1(); + instance.testJogl2ExtensionCheck2(); + } + + @Test + public void testJogl2ExtensionCheck1() { + GLDrawableFactory factory = GLDrawableFactory.getDesktopFactory(); + GLContext sharedContext = factory.getOrCreateSharedContext(null); + sharedContext.makeCurrent(); + String extensions; + try { + extensions = sharedContext.getGL().glGetString(GL.GL_EXTENSIONS); + } finally { + sharedContext.release(); + } + String[] tabExtensions = extensions.split(" "); + SortedSet<String> setExtensions = new TreeSet<String>(); + Collections.addAll(setExtensions, tabExtensions); + System.out.println("SharedContext: "+sharedContext); + System.out.println("SharedContext: "+setExtensions); + } + + @Test + public void testJogl2ExtensionCheck2() { + GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + GLDrawableFactory factory = GLDrawableFactory.getDesktopFactory(); + GLCapabilitiesChooser glCapsChooser = new DefaultGLCapabilitiesChooser(); + AbstractGraphicsDevice agd = factory.getDefaultDevice(); + + GLAutoDrawable drawable = factory.createGLPbuffer(agd, caps, glCapsChooser, 256, 256, null); + GLContext context = drawable.getContext(); + context.makeCurrent(); + String extensions; + try { + extensions = context.getGL().glGetString(GL.GL_EXTENSIONS); + } finally { + context.release(); + } + String[] tabExtensions = extensions.split(" "); + SortedSet<String> setExtensions = new TreeSet<String>(); + Collections.addAll(setExtensions, tabExtensions); + System.out.println("DefaulContext: "+context); + System.out.println("DefaulContext: "+setExtensions); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java new file mode 100644 index 000000000..d4f24bb19 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java @@ -0,0 +1,166 @@ +/** + * 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.jogl.acore; + +import java.io.IOException; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import javax.media.opengl.*; + +import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.nativewindow.NativeWindowVersion; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.DumpGLInfo; +import com.jogamp.opengl.JoglVersion; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.*; + +public class TestGLProfile01NEWT extends UITestCase { + + @Test + public void test00Version() throws InterruptedException { + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(GlueGenVersion.getInstance()); + System.err.println(NativeWindowVersion.getInstance()); + System.err.println(JoglVersion.getInstance()); + System.err.println(NewtVersion.getInstance()); + + GLDrawableFactory factory = GLDrawableFactory.getFactory(GLProfile.getDefault()); + List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null); + for(int i=0; i<availCaps.size(); i++) { + System.err.println(availCaps.get(i)); + } + } + + @Test + public void test01GLProfileDefault() throws InterruptedException { + System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); + GLProfile glp = GLProfile.getDefault(); + System.out.println("GLProfile.getDefault(): "+glp); + if(glp.getName().equals(GLProfile.GL4bc)) { + Assert.assertTrue(GLProfile.isGL4bcAvailable()); + Assert.assertTrue(GLProfile.isGL3bcAvailable()); + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL3bc)) { + Assert.assertTrue(GLProfile.isGL3bcAvailable()); + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL2)) { + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL2ES1)) { + Assert.assertTrue(GLProfile.isGL2ES1Available()); + } + dumpVersion(glp); + } + + @Test + public void test02GL2() throws InterruptedException { + GLProfile glp = GLProfile.get(GLProfile.GL2); + dumpVersion(glp); + } + + @Test + public void test03GLProfileMaxProgrammable() throws InterruptedException { + // Assuming at least one programmable profile is available + GLProfile glp = GLProfile.getMaxProgrammable(); + System.out.println("GLProfile.getMaxProgrammable(): "+glp); + if(glp.getName().equals(GLProfile.GL4)) { + Assert.assertTrue(GLProfile.isGL4Available()); + Assert.assertTrue(GLProfile.isGL3Available()); + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL3)) { + Assert.assertTrue(GLProfile.isGL3Available()); + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL2)) { + Assert.assertTrue(GLProfile.isGL2Available()); + Assert.assertTrue(GLProfile.isGL2ES1Available()); + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } else if(glp.getName().equals(GLProfile.GL2ES2)) { + Assert.assertTrue(GLProfile.isGL2ES2Available()); + } + dumpVersion(glp); + } + + @Test + public void test04GLProfileGL2ES1() throws InterruptedException { + if(!GLProfile.isGL2ES1Available()) { + System.out.println("GLProfile GL2ES1 n/a"); + return; + } + GLProfile glp = GLProfile.getGL2ES1(); + System.out.println("GLProfile GL2ES1: "+glp); + dumpVersion(glp); + } + + @Test + public void test05GLProfileGL2ES2() throws InterruptedException { + if(!GLProfile.isGL2ES2Available()) { + System.out.println("GLProfile GL2ES2 n/a"); + return; + } + GLProfile glp = GLProfile.getGL2ES2(); + System.out.println("GLProfile GL2ES2: "+glp); + dumpVersion(glp); + } + + protected void dumpVersion(GLProfile glp) throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glWindow.setTitle("TestGLProfile01NEWT"); + + glWindow.addGLEventListener(new DumpGLInfo()); + + glWindow.setSize(128, 128); + glWindow.setVisible(true); + + glWindow.display(); + Thread.sleep(100); + glWindow.invalidate(); + } + + public static void main(String args[]) throws IOException { + String tstname = TestGLProfile01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java new file mode 100644 index 000000000..bf4c493bc --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java @@ -0,0 +1,158 @@ +/** + * 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.jogl.acore; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; + +import java.awt.Frame; +import javax.swing.SwingUtilities; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestSharedContextListAWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + GLPbuffer sharedDrawable; + Gears sharedGears; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + width = 512; + height = 512; + } + + private void initShared() { + sharedDrawable = GLDrawableFactory.getFactory(glp).createGLPbuffer(null, caps, null, width, height, null); + Assert.assertNotNull(sharedDrawable); + sharedGears = new Gears(); + Assert.assertNotNull(sharedGears); + sharedDrawable.addGLEventListener(sharedGears); + // init and render one frame, which will setup the Gears display lists + sharedDrawable.display(); + } + + private void releaseShared() { + Assert.assertNotNull(sharedDrawable); + sharedDrawable.destroy(); + } + protected Frame createFrame(int x, int y, boolean useShared) { + return new Frame("Shared Gears AWT Test: "+x+"/"+y+" shared "+useShared); + } + + protected GLCanvas runTestGL(final Frame frame, final Animator animator, final int x, final int y, final boolean useShared) + throws InterruptedException + { + final GLCanvas glCanvas = new GLCanvas(caps, useShared ? sharedDrawable.getContext() : null); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setLocation(x, y); + frame.setSize(width, height); + + Gears gears = new Gears(); + if(useShared) { + gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + } + glCanvas.addGLEventListener(gears); + + animator.add(glCanvas); + + frame.setVisible(true); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); + + return glCanvas; + } + + @Test + public void test01() throws InterruptedException { + initShared(); + + Frame f1 = createFrame(0, 0, true); + Frame f2 = createFrame(width, 0, true); + Frame f3 = createFrame(0, height, false); + + Animator animator = new Animator(); + + GLCanvas glc1 = runTestGL(f1, animator, 0, 0, true); + GLCanvas glc2 = runTestGL(f2, animator, width, 0, true); + GLCanvas glc3 = runTestGL(f3, animator, 0, height, false); + + animator.start(); + while(animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + animator.stop(); + + // here we go again: On AMD/X11 the create/destroy sequence must be the same + // even though this is agains the chicken/egg logic here .. + releaseShared(); + + f1.dispose(); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glc1, false)); + + f2.dispose(); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glc2, false)); + + f3.dispose(); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glc3, false)); + + // see above .. + //releaseShared(); + } + + static long duration = 500; // ms + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + org.junit.runner.JUnitCore.main(TestSharedContextListAWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java new file mode 100644 index 000000000..f5c950646 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java @@ -0,0 +1,140 @@ +/** + * 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.jogl.acore; + +import com.jogamp.newt.opengl.GLWindow; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestSharedContextListNEWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + GLPbuffer sharedDrawable; + Gears sharedGears; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + width = 512; + height = 512; + } + + private void initShared() { + sharedDrawable = GLDrawableFactory.getFactory(glp).createGLPbuffer(null, caps, null, width, height, null); + Assert.assertNotNull(sharedDrawable); + sharedGears = new Gears(); + Assert.assertNotNull(sharedGears); + sharedDrawable.addGLEventListener(sharedGears); + // init and render one frame, which will setup the Gears display lists + sharedDrawable.display(); + } + + private void releaseShared() { + Assert.assertNotNull(sharedDrawable); + sharedDrawable.destroy(); + } + + protected GLWindow runTestGL(Animator animator, int x, int y, boolean useShared) { + GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y+" shared "+useShared); + if(useShared) { + glWindow.setSharedContext(sharedDrawable.getContext()); + } + + glWindow.setSize(width, height); + glWindow.setPosition(x, y); + + Gears gears = new Gears(); + if(useShared) { + gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + } + glWindow.addGLEventListener(gears); + + animator.add(glWindow); + + glWindow.setVisible(true); + + return glWindow; + } + + @Test + public void test01() throws InterruptedException { + initShared(); + Animator animator = new Animator(); + GLWindow f1 = runTestGL(animator, 0, 0, true); + GLWindow f2 = runTestGL(animator, width, 0, true); + GLWindow f3 = runTestGL(animator, 0, height, false); + animator.start(); + while(animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + animator.stop(); + + // here we go again: On AMD/X11 the create/destroy sequence must be the same + // even though this is agains the chicken/egg logic here .. + releaseShared(); + + f1.destroy(); + f2.destroy(); + f3.destroy(); + + // see above .. + // releaseShared(); + } + + static long duration = 500; // ms + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + org.junit.runner.JUnitCore.main(TestSharedContextListNEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java new file mode 100644 index 000000000..21e1a4aca --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java @@ -0,0 +1,135 @@ +/** + * 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.jogl.awt; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +import java.awt.Frame; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; + + +public class TestAWT01GLn extends UITestCase { + Frame frame=null; + GLCanvas glCanvas=null; + + @BeforeClass + public static void startup() { + GLProfile.initSingleton(true); + System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); + } + + @Before + public void init() { + frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); + } + + @After + public void release() { + Assert.assertNotNull(frame); + Assert.assertNotNull(glCanvas); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(false); + frame.remove(glCanvas); + frame.dispose(); + }}); + } catch (Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + frame=null; + glCanvas=null; + } + + protected void runTestGL(GLCapabilities caps) throws InterruptedException { + glCanvas = new GLCanvas(caps); + Assert.assertNotNull(glCanvas); + glCanvas.addGLEventListener(new Gears()); + frame.add(glCanvas); + + // Revalidate size/layout. + // Always validate if component added/removed. + // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created. + frame.setSize(512, 512); + frame.validate(); + + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + }}); + } catch (Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + + glCanvas.display(); // one in process display + + Animator animator = new Animator(glCanvas); + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + } + + @Test + public void test01GLDefault() throws InterruptedException { + GLProfile glp = GLProfile.getDefault(); + System.out.println("GLProfile Default: "+glp); + GLCapabilities caps = new GLCapabilities(glp); + runTestGL(caps); + } + + @Test + public void test02GL2() throws InterruptedException { + GLProfile glprofile = GLProfile.get(GLProfile.GL2); + System.out.println( "GLProfile GL2: " + glprofile ); + GLCapabilities caps = new GLCapabilities(glprofile); + runTestGL(caps); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestAWT01GLn.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT02WindowClosing.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT02WindowClosing.java new file mode 100644 index 000000000..535f0e99e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT02WindowClosing.java @@ -0,0 +1,111 @@ +/** + * 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.jogl.awt; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import javax.media.opengl.GLProfile; + +import java.awt.*; +import java.awt.event.*; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; + +public class TestAWT02WindowClosing extends UITestCase { + + static long durationPerTest = 200; // ms + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + } + + @Test + public void test01WindowClosing() throws InterruptedException { + Frame frame = new Frame(); + frame.setSize(500, 500); + ClosingWindowAdapter closingWindowAdapter = new ClosingWindowAdapter(frame); + frame.addWindowListener(closingWindowAdapter); + final Frame _frame = frame; + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _frame.setVisible(true); + }}); + } catch (Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + + Thread.sleep(durationPerTest); + if(!closingWindowAdapter.closingCalled) { + // programatically issue windowClosing + Toolkit tk = Toolkit.getDefaultToolkit(); + EventQueue evtQ = tk.getSystemEventQueue(); + evtQ.postEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); + Thread.sleep(200); + } + Assert.assertEquals(true, closingWindowAdapter.closingCalled); + } + + static class ClosingWindowAdapter extends WindowAdapter { + boolean closingCalled = false; + Frame frame; + public ClosingWindowAdapter(Frame frame) { + this.frame = frame; + } + public void windowClosing(WindowEvent ev) { + System.out.println("windowClosing() called .."); + closingCalled = true; + frame.dispose(); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + System.out.println("durationPerTest: "+durationPerTest); + org.junit.runner.JUnitCore.main(TestAWT02WindowClosing.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java new file mode 100644 index 000000000..2faf8fa66 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java @@ -0,0 +1,183 @@ +/** + * 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.jogl.awt; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.MiscUtils; + +import java.awt.Frame; +import java.awt.Label; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; + + +public class TestAWT03GLCanvasRecreate01 extends UITestCase { + static long durationPerTest = 1000; // ms + + Frame frame1=null; + Frame frame2=null; + GLCanvas glCanvas=null; + Label label = null; + Animator animator = null; + + @BeforeClass + public static void startup() { + GLProfile.initSingleton(true); + System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); + } + + @Before + public void init() { + glCanvas = new GLCanvas(); + Assert.assertNotNull(glCanvas); + glCanvas.addGLEventListener(new Gears()); + + animator = new Animator(glCanvas); + animator.start(); + + label = new Label("No GLCanvas"); + + frame1 = new Frame("Frame 1"); + Assert.assertNotNull(frame1); + frame1.add(label); + frame1.setSize(512, 512); + frame1.setLocation(0, 0); + + frame2 = new Frame("Frame 2"); + Assert.assertNotNull(frame2); + frame2.add(label); + frame2.setSize(512, 512); + frame2.setLocation(512, 0); + } + + @After + public void release() { + Assert.assertNotNull(frame1); + Assert.assertNotNull(frame2); + Assert.assertNotNull(glCanvas); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + glCanvas.destroy(); + frame1.dispose(); + frame2.dispose(); + }}); + } catch (Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + frame1=null; + frame2=null; + glCanvas=null; + + animator.stop(); + animator=null; + } + + private void addCanvas(final Frame frame) { + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.remove(label); + frame.add(glCanvas); + frame.validate(); + }}); + } catch (Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + } + + private void removeCanvas(final Frame frame) { + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.remove(glCanvas); + frame.add(label); + frame.validate(); + }}); + } catch (Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + } + + private void setVisible(final Frame frame, final boolean v) { + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(v); + }}); + } catch (Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + } + + + @Test + public void testAddRemove3Times() throws InterruptedException { + setVisible(frame1, true); + setVisible(frame2, true); + + addCanvas(frame1); + Thread.sleep(durationPerTest/4); + + removeCanvas(frame1); + addCanvas(frame2); + Thread.sleep(durationPerTest/4); + + removeCanvas(frame2); + addCanvas(frame1); + Thread.sleep(durationPerTest/4); + + removeCanvas(frame1); + addCanvas(frame2); + Thread.sleep(durationPerTest/4); + } + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest); + } + } + org.junit.runner.JUnitCore.main(TestAWT03GLCanvasRecreate01.class.getName()); + } +} diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug460GLCanvasNPEAWT.java index 3739f28ea..6de9e9788 100644 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug460GLCanvasNPEAWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,48 +20,38 @@ * 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; - + +package com.jogamp.opengl.test.junit.jogl.awt; import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; + +import org.junit.Test; -import com.jogamp.graph.curve.Region; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.util.Animator; +public class TestBug460GLCanvasNPEAWT { -public class GPUTextNewtDemo01 { - 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 Text Newt Demo 01 - r2t0 msaa1"); - - GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(Region.SINGLE_PASS, 0, DEBUG, TRACE); - textGLListener.attachInputListenerTo(window); - window.addGLEventListener(textGLListener); + public static void main(String[] args) { + TestBug460GLCanvasNPEAWT instance = new TestBug460GLCanvasNPEAWT(); + instance.testIncompleteGLCanvasNPE(); + } - window.enablePerfLog(true); - window.setVisible(true); - // FPSAnimator animator = new FPSAnimator(10); - Animator animator = new Animator(); - animator.add(window); - animator.start(); - } + @Test + public void testIncompleteGLCanvasNPE() { + GLProfile.initSingleton(false); + GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + GLCanvas glc = new GLCanvas(caps); + // GLDrawableFactory factory = glc.getFactory(); // null ok: not realized + // GLCapabilitiesImmutable glci = glc.getChosenGLCapabilities(); -> NPE ok: .. not realized + GLCapabilitiesImmutable glCapsRequested = glc.getRequestedGLCapabilities(); + System.out.println("ReqCaps: "+glCapsRequested); + System.out.println("GLCanvas: "+glc); + } } + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461OffscreenSupersamplingSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461OffscreenSupersamplingSwingAWT.java new file mode 100644 index 000000000..55c9c6812 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461OffscreenSupersamplingSwingAWT.java @@ -0,0 +1,173 @@ +/** + * Copyright 2011 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.jogl.awt; + +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +/** + * Copyright 2011 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. + */ + +import java.awt.image.BufferedImage; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +/** + * Tests for bug 461, a failure of GLDrawableFactory.createGLPbuffer() on Windows + * when the stencil buffer is turned on. + * + * @author Wade Walker (from code sample provided by Owen Dimond) + */ +public class TestBug461OffscreenSupersamplingSwingAWT extends UITestCase implements GLEventListener { + JFrame jframe; + GLPbuffer offScreenBuffer; + + private void render(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + Assert.assertNotNull(gl); + gl.glClear(GL.GL_COLOR_BUFFER_BIT); + + // draw a triangle filling the window + gl.glBegin(GL.GL_TRIANGLES); + gl.glColor3f(1, 0, 0); + gl.glVertex2d(-1, -1); + gl.glColor3f(0, 1, 0); + gl.glVertex2d(0, 1); + gl.glColor3f(0, 0, 1); + gl.glVertex2d(1, -1); + gl.glEnd(); + } + + /* @Override */ + public void init(GLAutoDrawable drawable) { + } + + /* @Override */ + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + /* @Override */ + public void display(GLAutoDrawable drawable) { + render(offScreenBuffer); + BufferedImage outputImage = com.jogamp.opengl.util.awt.Screenshot.readToBufferedImage(200, 200, false); + Assert.assertNotNull(outputImage); + ImageIcon imageIcon = new ImageIcon(outputImage); + JLabel imageLabel = new JLabel(imageIcon); + jframe.getContentPane().add(imageLabel); + } + + /* @Override */ + public void dispose(GLAutoDrawable drawable) { + jframe.setVisible(false); + jframe.dispose(); + } + + @Test + public void testOffscreenSupersampling() { + jframe = new JFrame("Offscreen Supersampling"); + Assert.assertNotNull(jframe); + jframe.setSize( 300, 300); + jframe.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + + GLProfile glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + + GLDrawableFactory fac = GLDrawableFactory.getFactory(glp); + Assert.assertNotNull(fac); + + Assert.assertTrue( fac.canCreateGLPbuffer(GLProfile.getDefaultDesktopDevice()) ); + + GLCapabilities glCap = new GLCapabilities(glp); + Assert.assertNotNull(glCap); + + // COMMENTING OUT THIS LINE FIXES THE ISSUE. + // Setting this in JOGL1 works. Thus this is a JOGL2 issue. + glCap.setSampleBuffers(true); + + // Without line below, there is an error on Windows. + glCap.setDoubleBuffered(false); + // Needed for drop shadows + glCap.setStencilBits(1); + + //makes a new buffer + offScreenBuffer = fac.createGLPbuffer(GLProfile.getDefaultDesktopDevice(), glCap, null, 200, 200, null); + Assert.assertNotNull(offScreenBuffer); + offScreenBuffer.addGLEventListener(this); + offScreenBuffer.display(); + jframe.setVisible( true ); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestBug461OffscreenSupersamplingSwingAWT.class.getName()); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java new file mode 100644 index 000000000..779ad7666 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java @@ -0,0 +1,147 @@ +/** + * 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.jogl.awt; + +import java.lang.reflect.InvocationTargetException; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import java.awt.Frame; +import java.awt.Window; +import javax.swing.JFrame; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assume.*; +import static org.junit.Assert.*; +import static javax.swing.SwingUtilities.*; + +/** + * Tests context creation + display on various kinds of Window implementations. + * @author Michael Bien + */ +public class TestSwingAWT01GLn extends UITestCase { + private Window[] windows; + + + @BeforeClass + public static void startup() { + GLProfile.initSingleton(true); + System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); + } + + @Before + public void init() { + windows = new Window[]{ + new Window(null), + new Frame("Frame GL test"), + new JFrame("JFrame GL test") + }; + } + + protected void runTestGL(final GLCapabilities caps) throws InterruptedException, InvocationTargetException { + + for (final Window window : windows) { + + System.out.println("testing with "+window.getClass().getName()); + + // final array as mutable container hack + final GLCanvas[] glCanvas = new GLCanvas[1]; + + Runnable test = new Runnable() { + public void run() { + glCanvas[0] = new GLCanvas(caps); + glCanvas[0].addGLEventListener(new Gears()); + window.add(glCanvas[0]); + + // Revalidate size/layout. + // Always validate if component added/removed. + // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created. + window.setSize(512, 512); + window.validate(); + + window.setVisible(true); + glCanvas[0].display(); + } + }; + + Runnable cleanup = new Runnable() { + public void run() { + System.out.println("cleaning up..."); + window.setVisible(false); + try { + window.removeAll(); + } catch (Throwable t) { + assumeNoException(t); + t.printStackTrace(); + } + window.dispose(); + } + + }; + + // AWT / Swing on EDT.. + invokeAndWait(test); + + Animator animator = new Animator(glCanvas[0]); + animator.start(); + Thread.sleep(1000); + animator.stop(); + + // AWT / Swing on EDT.. + invokeAndWait(cleanup); + } + } + + @Test + public void test01GLDefault() throws InterruptedException, InvocationTargetException { + GLProfile glp = GLProfile.getDefault(); + System.out.println("GLProfile Default: "+glp); + GLCapabilities caps = new GLCapabilities(glp); + runTestGL(caps); + } + + @Test + public void test02GL2() throws InterruptedException, InvocationTargetException { + GLProfile glprofile = GLProfile.get(GLProfile.GL2); + System.out.println( "GLProfile GL2: " + glprofile ); + GLCapabilities caps = new GLCapabilities(glprofile); + runTestGL(caps); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestSwingAWT01GLn.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TestAWTTextRendererUseVertexArrayBug464.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TestAWTTextRendererUseVertexArrayBug464.java new file mode 100644 index 000000000..fc19a6842 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TestAWTTextRendererUseVertexArrayBug464.java @@ -0,0 +1,155 @@ +/** + * Copyright 2011 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.jogl.awt.text; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import java.awt.Frame; +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; + +/* + * Unit tests for Bug464 + * Some ATI-Drivers crash the JVM if VBO-related glFunctions are called. This test checks + * if TextRenderer calls any of these functions while it's useVertexArray variable is set + * to false. + * 2D- and 3D-TextRendering is tested by creating a GLCanvas showing a simple line of text + * while filtering all glFunction calls by using a modified version of TraceGL2. + * VBO-related function are logged to the disallowedMethodCalls String of the GLEventListener + * instead of being executed (to prevent JVM crashes). Therefore, if the + * disallowedMethodCalls isn't an empty String after the test, the test fails. + * + * Other classes related to this test: + * TestTextRendererGLEventListener01 + * TestTextRendererTraceGL2Mock01 + */ + +public class TestAWTTextRendererUseVertexArrayBug464 extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + + private GLCanvas glCanvas; + private Frame frame; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + @Before + public void initTest() { + glCanvas = new GLCanvas(caps); + + frame = new Frame("TextRenderer Test"); + Assert.assertNotNull(frame); + frame.add(glCanvas); + frame.setSize(512, 512); + frame.setVisible(true); + + } + + @After + public void cleanupTest() { + frame.setVisible(false); + frame.remove(glCanvas); + glCanvas=null; + Assert.assertNotNull(frame); + frame.dispose(); + frame=null; + } + + @Test + public void testTextRendererDraw2D() throws InterruptedException { + + TextRendererGLEventListener01 listener = new TextRendererGLEventListener01(1); + Assert.assertNotNull(listener); + glCanvas.addGLEventListener(listener); + Animator animator = new Animator(glCanvas); + + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + + String disallowedMethods = listener.getDisallowedMethodCalls(); + if (!disallowedMethods.equals("")) { + Assert.fail("Following VBO-related glMethods have been called: "+ disallowedMethods); + } + } + + @Test + public void testTextRendererDraw3D() throws InterruptedException { + + TextRendererGLEventListener01 listener = new TextRendererGLEventListener01(2); + Assert.assertNotNull(listener); + glCanvas.addGLEventListener(listener); + Animator animator = new Animator(glCanvas); + + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + + String disallowedMethods = listener.getDisallowedMethodCalls(); + if (!disallowedMethods.equals("")) { + Assert.fail("Following VBO-related glMethods have been called: "+ disallowedMethods); + } + } + + public static void main(String args[]) throws IOException { + String tstname = TestAWTTextRendererUseVertexArrayBug464.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererGLEventListener01.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererGLEventListener01.java new file mode 100644 index 000000000..b14704142 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererGLEventListener01.java @@ -0,0 +1,124 @@ +/** + * Copyright 2011 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.jogl.awt.text; + +import java.awt.Font; +import java.io.OutputStream; +import java.io.PrintStream; + +import com.jogamp.opengl.util.awt.TextRenderer; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.glu.GLU; + +import org.junit.Assert; + +/* + * Unit tests for Bug464 + * GLEventListener for unit test TestAWTTextRendererUseVertexArrayBug464. The display + * method renders the String "ABC123#+?" to the lower left corner of the canvas. + * + * The testNumber variable is used to switch between 2D- and 3D-textrendering in the display + * method. + * The disallowedMethodCalls variable is used to log VBO-related glFunction calls during + * the execution of the test. + * + * Other classes related to this test: + * TestAWTTextRendererUseVertexArrayBug464 + * TextRendererTraceGL2Mock01 + */ + +public class TextRendererGLEventListener01 implements GLEventListener { + private GLU glu = new GLU(); + private TextRenderer renderer; + private String text; + private String disallowedMethodCalls; + private int testNumber; + + public TextRendererGLEventListener01(int testNumber) { + this.disallowedMethodCalls = ""; + this.testNumber = testNumber; + } + + public void init(GLAutoDrawable drawable) { + renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36)); + renderer.setUseVertexArrays(false); + Assert.assertNotNull(renderer); + Assert.assertFalse(renderer.getUseVertexArrays()); + + text = "ABC123#+?"; + + PrintStream nullStream = new PrintStream(new OutputStream(){ public void write(int b){}}); + drawable.setGL(new TextRendererTraceGL2Mock01(drawable.getGL().getGL2(), nullStream, this)); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2 gl = drawable.getGL().getGL2(); + gl.glMatrixMode(GL2ES1.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluOrtho2D(0, 1, 0, 1); + gl.glMatrixMode(GL2ES1.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) { + renderer.dispose(); + } + + public void display(GLAutoDrawable drawable) { + if (disallowedMethodCalls.equals("")) { + if (testNumber == 1) { + renderer.beginRendering(drawable.getWidth(), drawable.getHeight()); + renderer.setColor(1.0f, 1.0f, 1.0f, 1.0f); + renderer.draw(text, 0, 0); + renderer.endRendering(); + } + if (testNumber == 2) { + renderer.begin3DRendering(); + renderer.setColor(1.0f, 1.0f, 1.0f, 1.0f); + renderer.draw3D(text, 0, 0, 0, 0.002f); + renderer.end3DRendering(); + } + } + } + + public void disallowedMethodCalled (String method) { + if (!disallowedMethodCalls.equals("")) { + disallowedMethodCalls += ", "; + } + disallowedMethodCalls += method; + } + + public String getDisallowedMethodCalls() { + return this.disallowedMethodCalls; + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererTraceGL2Mock01.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererTraceGL2Mock01.java new file mode 100644 index 000000000..63258a574 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererTraceGL2Mock01.java @@ -0,0 +1,137 @@ +/** + * Copyright 2011 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.jogl.awt.text; + +import java.io.PrintStream; +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +import javax.media.opengl.GL2; +import javax.media.opengl.TraceGL2; + +import com.jogamp.common.nio.Buffers; + +/* + * Unit tests for Bug464 + * Modified Version of TraceGL2 for unit test TestAWTTextRendererUseVertexArrayBug464. + * This class overrides all glFunctions related to VBO's according to + * http://code.google.com/p/glextensions/wiki/GL_ARB_vertex_buffer_object: + * glBindBuffer (glBindBufferARB) + * glDeleteBuffers (glDeleteBuffersARB) + * glGenBuffers (glGenBuffersARB) + * glIsBuffer (glIsBufferARB) + * glBufferData (glBufferDataARB) + * glBufferSubData (glBufferSubDataARB) + * glGetBufferSubData (glGetBufferSubDataARB) + * glMapBuffer (glMapBufferARB) + * glUnmapBuffer (glUnmapBufferARB) + * glGetBufferParameteriv (glGetBufferParameterivARB) + * glGetBufferPointerv (glGetBufferPointervARB) + * Calls to the overridden methods are logged to the disallowedMethodCalls variable of + * the GLEventListener instead of being passed to the downstreamGL object. + * + * Other classes related to this test: + * TestAWTTextRendererUseVertexArrayBug464 + * TextRendererGLEventListener01 + */ + +public class TextRendererTraceGL2Mock01 extends TraceGL2 { + + TextRendererGLEventListener01 listener; + + public TextRendererTraceGL2Mock01(GL2 downstreamGL2, PrintStream stream, TextRendererGLEventListener01 listener) { + super(downstreamGL2, stream); + this.listener = listener; + } + + @Override + public void glGetBufferSubData(int arg0, long arg1, long arg2, Buffer arg3) { + listener.disallowedMethodCalled("glGetBufferSubData"); + } + + @Override + public ByteBuffer glMapBuffer(int arg0, int arg1) { + listener.disallowedMethodCalled("glMapBuffer"); + return Buffers.newDirectByteBuffer(0); + } + + @Override + public void glGetBufferParameteriv(int arg0, int arg1, IntBuffer arg2) { + listener.disallowedMethodCalled("glGetBufferParameteriv"); + } + + @Override + public boolean glUnmapBuffer(int arg0) { + listener.disallowedMethodCalled("glUnmapBuffer"); + return false; + } + + @Override + public void glGenBuffers(int arg0, IntBuffer arg1) { + listener.disallowedMethodCalled("glGenBuffers"); + } + + @Override + public void glGenBuffers(int arg0, int[] arg1, int arg2) { + listener.disallowedMethodCalled("glGenBuffers"); + } + + @Override + public boolean glIsBuffer(int arg0) { + listener.disallowedMethodCalled("glIsBuffer"); + return false; + } + + @Override + public void glBindBuffer(int arg0, int arg1) { + listener.disallowedMethodCalled("glBindBuffer"); + } + + @Override + public void glDeleteBuffers(int arg0, int[] arg1, int arg2) { + listener.disallowedMethodCalled("glDeleteBuffers"); + } + + @Override + public void glBufferSubData(int arg0, long arg1, long arg2, Buffer arg3) { + listener.disallowedMethodCalled("glBufferSubData"); + } + + @Override + public void glGetBufferParameteriv(int arg0, int arg1, int[] arg2, int arg3) { + listener.disallowedMethodCalled("glGetBufferParameteriv"); + } + + @Override + public void glBufferData(int arg0, long arg1, Buffer arg2, int arg3) { + listener.disallowedMethodCalled("glBufferData"); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java new file mode 100644 index 000000000..c2182b8b7 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.opengl.test.junit.jogl.caps; + +import java.util.List; +import javax.media.opengl.DefaultGLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; + +class MultisampleChooser01 extends DefaultGLCapabilitiesChooser { + + public int chooseCapabilities(GLCapabilitiesImmutable desired, List/*<GLCapabilitiesImmutable>*/ available, int windowSystemRecommendedChoice) { + boolean anyHaveSampleBuffers = false; + for (int i = 0; i < available.size(); i++) { + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) available.get(i); + if ( caps.getSampleBuffers() ) { + anyHaveSampleBuffers = true; + break; + } + } + int selection = super.chooseCapabilities(desired, available, windowSystemRecommendedChoice); + if (!anyHaveSampleBuffers) { + System.err.println("WARNING: antialiasing will be disabled because none of the available pixel formats had it to offer"); + } else { + GLCapabilitiesImmutable selected = (GLCapabilitiesImmutable) available.get(selection); + if (!selected.getSampleBuffers()) { + System.err.println("WARNING: antialiasing will be disabled because the DefaultGLCapabilitiesChooser didn't supply it"); + } + } + return selection; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java new file mode 100644 index 000000000..b41501a9b --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.test.junit.jogl.caps; + +import jogamp.opengl.x11.glx.GLX; +import jogamp.opengl.x11.glx.X11GLXGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLPipelineFactory; + +class MultisampleDemo01 implements GLEventListener { + + static boolean glDebug = false; + static boolean glTrace = false; + + boolean multisample; + + public MultisampleDemo01(boolean multisample) { + this.multisample = multisample; + } + + public void init(GLAutoDrawable drawable) { + AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + System.err.println(); + System.err.println("Info: " + config); + System.err.println(); + if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(false))) { + X11GLXGraphicsConfiguration x11config = (X11GLXGraphicsConfiguration) config; + long display = drawable.getNativeSurface().getDisplayHandle(); + int[] foo = new int[1]; + GLX.glXGetFBConfigAttrib(display, x11config.getFBConfig(), GLX.GLX_SAMPLES, foo, 0); + System.out.println("GLX_SAMPLES " + foo[0]); + GLX.glXGetFBConfigAttrib(display, x11config.getFBConfig(), GLX.GLX_SAMPLE_BUFFERS, foo, 0); + System.out.println("GLX_SAMPLE_BUFFERS " + foo[0]); + } + GL _gl = drawable.getGL(); + if (glDebug) { + try { + // Debug .. + _gl = _gl.getContext().setGL(GLPipelineFactory.create("javax.media.opengl.Debug", GL2.class, _gl, null)); + if (glTrace) { + // Trace .. + _gl = _gl.getContext().setGL(GLPipelineFactory.create("javax.media.opengl.Trace", GL2.class, _gl, new Object[]{System.err})); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + GL2 gl = _gl.getGL2(); + if (multisample) { + gl.glEnable(GL.GL_MULTISAMPLE); + } + gl.glClearColor(0, 0, 0, 0); + // gl.glEnable(GL.GL_DEPTH_TEST); + // gl.glDepthFunc(GL.GL_LESS); + gl.glMatrixMode(GL2ES1.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glMatrixMode(GL2ES1.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(-1, 1, -1, 1, -1, 1); + if (multisample) { + gl.glDisable(GL.GL_MULTISAMPLE); + } + } + + public void dispose(GLAutoDrawable drawable) { + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + if (multisample) { + gl.glEnable(GL.GL_MULTISAMPLE); + } + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + int numSteps = 20; + double increment = Math.PI / numSteps; + double radius = 1; + gl.glBegin(GL.GL_LINES); + for (int i = numSteps - 1; i >= 0; i--) { + gl.glVertex3d(radius * Math.cos(i * increment), radius * Math.sin(i * increment), 0); + gl.glVertex3d(-1.0 * radius * Math.cos(i * increment), -1.0 * radius * Math.sin(i * increment), 0); + } + gl.glEnd(); + if (multisample) { + gl.glDisable(GL.GL_MULTISAMPLE); + } + } + + // Unused routines + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java new file mode 100755 index 000000000..786fd608b --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.test.junit.jogl.caps; + +import java.lang.reflect.InvocationTargetException; +import java.awt.BorderLayout; +import java.awt.Frame; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.awt.GLCanvas; + +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import org.junit.Test; + + +public class TestMultisampleAWT extends UITestCase { + static long durationPerTest = 250; // ms + private GLCanvas canvas; + + public static void main(String[] args) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atoi(args[++i], 500); + } + } + System.out.println("durationPerTest: "+durationPerTest); + String tstname = TestMultisampleAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + + @Test + public void testMultiSampleAA4() throws InterruptedException, InvocationTargetException { + testMultiSampleAAImpl(4); + } + + @Test + public void testMultiSampleNone() throws InterruptedException, InvocationTargetException { + testMultiSampleAAImpl(0); + } + + private void testMultiSampleAAImpl(int samples) throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(null); + GLCapabilitiesChooser chooser = new MultisampleChooser01(); + + if(samples>0) { + caps.setSampleBuffers(true); + caps.setNumSamples(samples); + // turns out we need to have alpha, + // otherwise no AA will be visible. + caps.setAlphaBits(1); + } + + canvas = new GLCanvas(caps, chooser, null, null); + canvas.addGLEventListener(new MultisampleDemo01(samples>0?true:false)); + + final Frame frame = new Frame("Multi Samples "+samples); + frame.setLayout(new BorderLayout()); + canvas.setSize(512, 512); + frame.add(canvas, BorderLayout.CENTER); + frame.pack(); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + frame.setLocation(0, 0); + canvas.requestFocus(); + canvas.display(); + }}); + + Thread.sleep(durationPerTest); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(false); + frame.remove(canvas); + frame.dispose(); + }}); + + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java new file mode 100755 index 000000000..8285a6699 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.test.junit.jogl.caps; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import javax.media.opengl.*; +import org.junit.Test; + +public class TestMultisampleNEWT { + static long durationPerTest = 500; // ms + private GLWindow window; + + public static void main(String[] args) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atoi(args[++i], 500); + } + } + System.out.println("durationPerTest: "+durationPerTest); + String tstname = TestMultisampleNEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + + @Test + public void testMultiSampleAA4() throws InterruptedException { + testMultiSampleAAImpl(4); + } + + // @Test + public void testMultiSampleNone() throws InterruptedException { + testMultiSampleAAImpl(0); + } + + private void testMultiSampleAAImpl(int samples) throws InterruptedException { + GLCapabilities caps = new GLCapabilities(null); + GLCapabilitiesChooser chooser = new MultisampleChooser01(); + + if(samples>0) { + caps.setSampleBuffers(true); + caps.setNumSamples(4); + } + // turns out we need to have alpha, + // otherwise no AA will be visible. + caps.setAlphaBits(1); + + window = GLWindow.create(caps); + window.setCapabilitiesChooser(chooser); + window.addGLEventListener(new MultisampleDemo01(samples>0?true:false)); + window.setSize(512, 512); + window.setVisible(true); + window.setPosition(0, 0); + window.requestFocus(); + + GLCapabilitiesImmutable capsChosen0 = window.getChosenGLCapabilities(); + + Thread.sleep(durationPerTest); + + window.destroy(); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java new file mode 100644 index 000000000..eaf697a10 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java @@ -0,0 +1,169 @@ +package com.jogamp.opengl.test.junit.jogl.demos.es1; + +import com.jogamp.common.nio.Buffers; +import java.nio.*; +import java.util.*; +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.glsl.fixedfunc.*; + +public class RedSquare implements GLEventListener { + + public static boolean glDebugEmu = false; + public static boolean glDebug = false ; + public static boolean glTrace = false ; + public static boolean oneThread = false; + public static boolean useAnimator = false; + public static int swapInterval = -1; + + boolean debug = false; + long startTime = 0; + long curTime = 0; + + GLU glu = null; + + public RedSquare() { + this(false); + } + + public RedSquare(boolean debug) { + this.debug = debug; + } + + // FIXME: we must add storage of the pointers in the GL state to + // the GLImpl classes. The need for this can be seen by making + // these variables method local instead of instance members. The + // square will disappear after a second or so due to garbage + // collection. On desktop OpenGL this implies a stack of + // references due to the existence of glPush/PopClientAttrib. On + // OpenGL ES 1/2 it can simply be one set of references. + private FloatBuffer colors; + private FloatBuffer vertices; + + public void init(GLAutoDrawable drawable) { + System.out.println("RedSquare: Init"); + GL _gl = drawable.getGL(); + + if(glDebugEmu) { + try { + // Debug .. + _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES2.class, _gl, null) ); + + if(glTrace) { + // Trace .. + _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", GL2ES2.class, _gl, new Object[] { System.err } ) ); + } + } catch (Exception e) {e.printStackTrace();} + glDebug = false; + glTrace = false; + } + + GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(_gl); + if(swapInterval>=0) { + gl.setSwapInterval(swapInterval); + } + + if(glDebug) { + try { + // Debug .. + gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES1.class, gl, null) ); + } catch (Exception e) {e.printStackTrace();} + } + + if(glTrace) { + try { + // Trace .. + gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", GL2ES1.class, gl, new Object[] { System.err } ) ); + } catch (Exception e) {e.printStackTrace();} + } + + glu = GLU.createGLU(gl); + + if(debug) { + System.err.println(Thread.currentThread()+" Entering initialization"); + System.err.println(Thread.currentThread()+" GL Profile: "+gl.getGLProfile()); + System.err.println(Thread.currentThread()+" GL:" + gl); + System.err.println(Thread.currentThread()+" GL_VERSION=" + gl.glGetString(gl.GL_VERSION)); + System.err.println(Thread.currentThread()+" GL_EXTENSIONS:"); + System.err.println(Thread.currentThread()+" " + gl.glGetString(gl.GL_EXTENSIONS)); + System.err.println(Thread.currentThread()+" swapInterval: " + swapInterval + " (GL: "+gl.getSwapInterval()+")"); + System.err.println(Thread.currentThread()+" GLU: " + glu); + } + + // Allocate vertex arrays + colors = Buffers.newDirectFloatBuffer(16); + vertices = Buffers.newDirectFloatBuffer(12); + // Fill them up + colors.put( 0, 1); colors.put( 1, 0); colors.put( 2, 0); colors.put( 3, 1); + colors.put( 4, 0); colors.put( 5, 0); colors.put( 6, 1); colors.put( 7, 1); + colors.put( 8, 1); colors.put( 9, 0); colors.put(10, 0); colors.put(11, 1); + colors.put(12, 1); colors.put(13, 0); colors.put(14, 0); colors.put(15, 1); + vertices.put(0, -2); vertices.put( 1, 2); vertices.put( 2, 0); + vertices.put(3, 2); vertices.put( 4, 2); vertices.put( 5, 0); + vertices.put(6, -2); vertices.put( 7, -2); vertices.put( 8, 0); + vertices.put(9, 2); vertices.put(10, -2); vertices.put(11, 0); + + gl.glEnableClientState(gl.GL_VERTEX_ARRAY); + gl.glEnableClientState(gl.GL_COLOR_ARRAY); + gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices); + gl.glColorPointer(4, GL.GL_FLOAT, 0, colors); + + // OpenGL Render Settings + gl.glClearColor(0, 0, 0, 1); + gl.glEnable(GL.GL_DEPTH_TEST); + + startTime = System.currentTimeMillis(); + curTime = startTime; + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + System.out.println("RedSquare: Reshape"); + GL2ES1 gl = drawable.getGL().getGL2ES1(); + // Set location in front of camera + gl.glMatrixMode(gl.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f); + //gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); + //glu.gluLookAt(0, 0, -20, 0, 0, 0, 0, 1, 0); + } + + public void display(GLAutoDrawable drawable) { + curTime = System.currentTimeMillis(); + GL2ES1 gl = drawable.getGL().getGL2ES1(); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + // One rotation every four seconds + gl.glMatrixMode(gl.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(0, 0, -10); + float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f; + gl.glRotatef(ang, 0, 0, 1); + gl.glRotatef(ang, 0, 1, 0); + + + // Draw a square + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); + } + + public void dispose(GLAutoDrawable drawable) { + System.out.println("RedSquare: Dispose"); + GL2ES1 gl = drawable.getGL().getGL2ES1(); + if(debug) { + System.out.println(Thread.currentThread()+" RedSquare.dispose: "+gl.getContext()); + } + gl.glDisableClientState(gl.GL_VERTEX_ARRAY); + gl.glDisableClientState(gl.GL_COLOR_ARRAY); + glu.destroy(); + glu = null; + colors.clear(); + colors = null; + vertices.clear(); + vertices = null; + if(debug) { + System.out.println(Thread.currentThread()+" RedSquare.dispose: FIN"); + } + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java new file mode 100644 index 000000000..f062a7375 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java @@ -0,0 +1,198 @@ +/** + * 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.jogl.demos.es2; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLArrayDataWrapper; +import com.jogamp.opengl.util.PMVMatrix; +import com.jogamp.opengl.test.junit.jogl.demos.es2.shader.RedSquareShader; +import com.jogamp.opengl.test.junit.util.GLSLSimpleProgram; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.FloatBuffer; +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLUniformData; +import org.junit.Assert; + +public class RedSquare0 implements GLEventListener { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream pbaos = new PrintStream(baos); + GLSLSimpleProgram myShader; + PMVMatrix pmvMatrix; + int mgl_PMVMatrix; + GLUniformData pmvMatrixUniform; + int mgl_Vertex; + int mgl_Color; + long t0; + + public void init(GLAutoDrawable glad) { + GLContext context = glad.getContext(); + context.makeCurrent(); + GL2ES2 gl = context.getGL().getGL2ES2(); + myShader = GLSLSimpleProgram.create(gl, RedSquareShader.VERTEX_SHADER_TEXT, RedSquareShader.FRAGMENT_SHADER_TEXT, true); + gl.glUseProgram(myShader.getShaderProgram()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // setup mgl_PMVMatrix + pmvMatrix = new PMVMatrix(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + mgl_PMVMatrix = gl.glGetUniformLocation(myShader.getShaderProgram(), "mgl_PMVMatrix"); + Assert.assertTrue(0 <= mgl_PMVMatrix); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); + pmvMatrixUniform.setLocation(mgl_PMVMatrix); + gl.glUniform(pmvMatrixUniform); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // Allocate Vertex Array + int components = 3; + int numElements = 4; + mgl_Vertex = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Vertex"); + Assert.assertTrue(0 <= mgl_Vertex); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + FloatBuffer buffer = Buffers.newDirectFloatBuffer(numElements * components); + GLArrayDataWrapper vertices = GLArrayDataWrapper.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 0, buffer, -1, 0); + { + // Fill them up + FloatBuffer verticeb = (FloatBuffer) vertices.getBuffer(); + verticeb.put(-2); + verticeb.put(2); + verticeb.put(0); + verticeb.put(2); + verticeb.put(2); + verticeb.put(0); + verticeb.put(-2); + verticeb.put(-2); + verticeb.put(0); + verticeb.put(2); + verticeb.put(-2); + verticeb.put(0); + } + buffer.flip(); + vertices.setLocation(mgl_Vertex); + gl.glEnableVertexAttribArray(mgl_Vertex); + gl.glVertexAttribPointer(vertices); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // Allocate Color Array + components = 4; + numElements = 4; + mgl_Color = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Color"); + Assert.assertTrue(0 <= mgl_Color); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + buffer = Buffers.newDirectFloatBuffer(numElements * components); + GLArrayDataWrapper colors = GLArrayDataWrapper.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 0, buffer, -1, 0); + { + // Fill them up + FloatBuffer colorb = (FloatBuffer) colors.getBuffer(); + colorb.put(1); + colorb.put(0); + colorb.put(0); + colorb.put(1); + colorb.put(0); + colorb.put(0); + colorb.put(1); + colorb.put(1); + colorb.put(1); + colorb.put(0); + colorb.put(0); + colorb.put(1); + colorb.put(1); + colorb.put(0); + colorb.put(0); + colorb.put(1); + } + buffer.flip(); + colors.setLocation(mgl_Color); + gl.glEnableVertexAttribArray(mgl_Color); + gl.glVertexAttribPointer(colors); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // OpenGL Render Settings + gl.glClearColor(0, 0, 0, 1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + gl.glUseProgram(0); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + t0 = System.currentTimeMillis(); + } + + public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { + GL2ES2 gl = glad.getGL().getGL2ES2(); + gl.glUseProgram(myShader.getShaderProgram()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // Set location in front of camera + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.gluPerspective(45.0F, (float) width / (float) height, 1.0F, 100.0F); + //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); + gl.glUniform(pmvMatrixUniform); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glUseProgram(0); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + } + + public void display(GLAutoDrawable glad) { + long t1 = System.currentTimeMillis(); + + GL2ES2 gl = glad.getGL().getGL2ES2(); + gl.glUseProgram(myShader.getShaderProgram()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // One rotation every four seconds + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glTranslatef(0, 0, -10); + float ang = ((float) (t1 - t0) * 360.0F) / 4000.0F; + pmvMatrix.glRotatef(ang, 0, 0, 1); + pmvMatrix.glRotatef(ang, 0, 1, 0); + gl.glUniform(pmvMatrixUniform); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // Draw a square + gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glUseProgram(0); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + } + + public void dispose(GLAutoDrawable glad) { + GL2ES2 gl = glad.getGL().getGL2ES2(); + gl.glDisableVertexAttribArray(mgl_Vertex); + gl.glDisableVertexAttribArray(mgl_Color); + myShader.release(gl); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + pmvMatrix.destroy(); + pmvMatrix = null; + System.err.println("dispose done"); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java new file mode 100644 index 000000000..3ef62df31 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java @@ -0,0 +1,68 @@ +/** + * 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.jogl.demos.es2.shader; + +public class RedSquareShader { + public static String VERTEX_SHADER_TEXT = + " #ifdef GL_ES\n" + + " #define MEDIUMP mediump\n" + + " #define HIGHP highp\n" + + "#else\n" + + " #define MEDIUMP\n" + + " #define HIGHP\n" + + "#endif\n" + + "\n" + + "uniform MEDIUMP mat4 mgl_PMVMatrix[2];\n" + + "attribute HIGHP vec4 mgl_Vertex;\n" + + "attribute HIGHP vec4 mgl_Color;\n" + + "varying HIGHP vec4 frontColor;\n" + + "\n" + + "void main(void)\n" + + "{\n" + + " frontColor=mgl_Color;\n" + + " gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;\n" + + "}\n" ; + + public static String FRAGMENT_SHADER_TEXT = + "#ifdef GL_ES\n" + + " #define MEDIUMP mediump\n" + + " #define HIGHP highp\n" + + "#else\n" + + " #define MEDIUMP\n" + + " #define HIGHP\n" + + "#endif\n" + + "\n" + + "varying HIGHP vec4 frontColor;\n" + + "\n" + + "void main (void)\n" + + "{\n" + + " gl_FragColor = frontColor;\n" + + "}\n" ; + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java new file mode 100644 index 000000000..b7298ca44 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java @@ -0,0 +1,387 @@ + +package com.jogamp.opengl.test.junit.jogl.demos.gl2.gears; + +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.newt.Window; +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.event.KeyListener; +import com.jogamp.newt.event.MouseAdapter; +import com.jogamp.newt.event.MouseEvent; +import com.jogamp.newt.event.MouseListener; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTMouseAdapter; + +/** + * Gears.java <BR> + * author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P> + * + * This version is equal to Brian Paul's version 1.2 1999/10/21 + */ + +public class Gears implements GLEventListener { + private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; + private int gear1=0, gear2=0, gear3=0; + private float angle = 0.0f; + private int swapInterval; + + private boolean mouseRButtonDown = false; + private int prevMouseX, prevMouseY; + + public Gears(int swapInterval) { + this.swapInterval = swapInterval; + } + + public Gears() { + this.swapInterval = 1; + } + + public void setGears(int g1, int g2, int g3) { + gear1 = g1; + gear2 = g2; + gear3 = g3; + } + + /** + * @return display list gear1 + */ + public int getGear1() { return gear1; } + + /** + * @return display list gear2 + */ + public int getGear2() { return gear2; } + + /** + * @return display list gear3 + */ + public int getGear3() { return gear3; } + + public void init(GLAutoDrawable drawable) { + System.err.println("Gears: Init: "+drawable); + // Use debug pipeline + // drawable.setGL(new DebugGL(drawable.getGL())); + + GL2 gl = drawable.getGL().getGL2(); + + System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities()); + System.err.println("INIT GL IS: " + gl.getClass().getName()); + System.err.println("GL_VENDOR: " + gl.glGetString(GL2.GL_VENDOR)); + System.err.println("GL_RENDERER: " + gl.glGetString(GL2.GL_RENDERER)); + System.err.println("GL_VERSION: " + gl.glGetString(GL2.GL_VERSION)); + + float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; + float red[] = { 0.8f, 0.1f, 0.0f, 0.7f }; + float green[] = { 0.0f, 0.8f, 0.2f, 0.7f }; + float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f }; + + gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, 0); + gl.glEnable(GL2.GL_CULL_FACE); + gl.glEnable(GL2.GL_LIGHTING); + gl.glEnable(GL2.GL_LIGHT0); + gl.glEnable(GL2.GL_DEPTH_TEST); + + /* make the gears */ + if(0>=gear1) { + gear1 = gl.glGenLists(1); + gl.glNewList(gear1, GL2.GL_COMPILE); + gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, red, 0); + gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f); + gl.glEndList(); + System.err.println("gear1 list created: "+gear1); + } else { + System.err.println("gear1 list reused: "+gear1); + } + + if(0>=gear2) { + gear2 = gl.glGenLists(1); + gl.glNewList(gear2, GL2.GL_COMPILE); + gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, green, 0); + gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f); + gl.glEndList(); + System.err.println("gear2 list created: "+gear2); + } else { + System.err.println("gear2 list reused: "+gear2); + } + + if(0>=gear3) { + gear3 = gl.glGenLists(1); + gl.glNewList(gear3, GL2.GL_COMPILE); + gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blue, 0); + gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f); + gl.glEndList(); + System.err.println("gear3 list created: "+gear3); + } else { + System.err.println("gear3 list reused: "+gear3); + } + + gl.glEnable(GL2.GL_NORMALIZE); + + // MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter()); + MouseListener gearsMouse = new GearsMouseAdapter(); + KeyListener gearsKeys = new GearsKeyAdapter(); + + if (drawable instanceof Window) { + Window window = (Window) drawable; + window.addMouseListener(gearsMouse); + window.addKeyListener(gearsKeys); + } else if (GLProfile.isAWTAvailable() && drawable instanceof java.awt.Component) { + java.awt.Component comp = (java.awt.Component) drawable; + new AWTMouseAdapter(gearsMouse).addTo(comp); + new AWTKeyAdapter(gearsKeys).addTo(comp); + } + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height); + GL2 gl = drawable.getGL().getGL2(); + + gl.setSwapInterval(swapInterval); + + float h = (float)height / (float)width; + + gl.glMatrixMode(GL2.GL_PROJECTION); + + gl.glLoadIdentity(); + gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); + gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(0.0f, 0.0f, -40.0f); + } + + public void dispose(GLAutoDrawable drawable) { + System.err.println("Gears: Dispose"); + setGears(0, 0, 0); + } + + public void display(GLAutoDrawable drawable) { + // Turn the gears' teeth + angle += 2.0f; + + // Get the GL corresponding to the drawable we are animating + GL2 gl = drawable.getGL().getGL2(); + + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + // Special handling for the case where the GLJPanel is translucent + // and wants to be composited with other Java 2D content + if (GLProfile.isAWTAvailable() && + (drawable instanceof javax.media.opengl.awt.GLJPanel) && + !((javax.media.opengl.awt.GLJPanel) drawable).isOpaque() && + ((javax.media.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) { + gl.glClear(GL2.GL_DEPTH_BUFFER_BIT); + } else { + gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); + } + + // Rotate the entire assembly of gears based on how the user + // dragged the mouse around + gl.glPushMatrix(); + gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); + gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); + gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); + + // Place the first gear and call its display list + gl.glPushMatrix(); + gl.glTranslatef(-3.0f, -2.0f, 0.0f); + gl.glRotatef(angle, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear1); + gl.glPopMatrix(); + + // Place the second gear and call its display list + gl.glPushMatrix(); + gl.glTranslatef(3.1f, -2.0f, 0.0f); + gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear2); + gl.glPopMatrix(); + + // Place the third gear and call its display list + gl.glPushMatrix(); + gl.glTranslatef(-3.1f, 4.2f, 0.0f); + gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear3); + gl.glPopMatrix(); + + // Remember that every push needs a pop; this one is paired with + // rotating the entire gear assembly + gl.glPopMatrix(); + } + + public static void gear(GL2 gl, + float inner_radius, + float outer_radius, + float width, + int teeth, + float tooth_depth) + { + int i; + float r0, r1, r2; + float angle, da; + float u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0f; + r2 = outer_radius + tooth_depth / 2.0f; + + da = 2.0f * (float) Math.PI / teeth / 4.0f; + + gl.glShadeModel(GL2.GL_FLAT); + + gl.glNormal3f(0.0f, 0.0f, 1.0f); + + /* draw front face */ + gl.glBegin(GL2.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + if(i < teeth) + { + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); + } + } + gl.glEnd(); + + /* draw front sides of teeth */ + gl.glBegin(GL2.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); + } + gl.glEnd(); + + /* draw back face */ + gl.glBegin(GL2.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw back sides of teeth */ + gl.glBegin(GL2.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw outward faces of teeth */ + gl.glBegin(GL2.GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle); + v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle); + len = (float)Math.sqrt(u * u + v * v); + u /= len; + v /= len; + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da); + v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da); + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + } + gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f); + gl.glEnd(); + + gl.glShadeModel(GL2.GL_SMOOTH); + + /* draw inside radius cylinder */ + gl.glBegin(GL2.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + } + gl.glEnd(); + } + + class GearsKeyAdapter extends KeyAdapter { + public void keyPressed(KeyEvent e) { + int kc = e.getKeyCode(); + if(KeyEvent.VK_LEFT == kc) { + view_roty -= 1; + } else if(KeyEvent.VK_RIGHT == kc) { + view_roty += 1; + } else if(KeyEvent.VK_UP == kc) { + view_rotx -= 1; + } else if(KeyEvent.VK_DOWN == kc) { + view_rotx += 1; + } + } + } + + class GearsMouseAdapter extends MouseAdapter { + public void mousePressed(MouseEvent e) { + prevMouseX = e.getX(); + prevMouseY = e.getY(); + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = true; + } + } + + public void mouseReleased(MouseEvent e) { + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = false; + } + } + + public void mouseDragged(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + int width=0, height=0; + Object source = e.getSource(); + if(source instanceof Window) { + Window window = (Window) source; + width=window.getWidth(); + height=window.getHeight(); + } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) { + java.awt.Component comp = (java.awt.Component) source; + width=comp.getWidth(); + height=comp.getHeight(); + } else { + throw new RuntimeException("Event source neither Window nor Component: "+source); + } + float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width); + float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height); + + prevMouseX = x; + prevMouseY = y; + + view_rotx += thetaX; + view_roty += thetaY; + } + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java new file mode 100644 index 000000000..d04ce3849 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java @@ -0,0 +1,122 @@ +/** + * 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.jogl.demos.gl2.gears; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.Animator; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTWindowAdapter; +import com.jogamp.newt.event.TraceKeyAdapter; +import com.jogamp.newt.event.TraceWindowAdapter; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import java.awt.Frame; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +public class TestGearsAWT extends UITestCase { + static GLProfile glp; + static int width, height; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 512; + } + + @AfterClass + public static void releaseClass() { + } + + protected void runTestGL(GLCapabilities caps) throws InterruptedException { + Frame frame = new Frame("Gears AWT Test"); + Assert.assertNotNull(frame); + + GLCanvas glCanvas = new GLCanvas(caps); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setSize(512, 512); + + glCanvas.addGLEventListener(new Gears()); + + Animator animator = new Animator(glCanvas); + QuitAdapter quitAdapter = new QuitAdapter(); + + new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glCanvas); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + + frame.setVisible(true); + animator.start(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + + Assert.assertNotNull(frame); + Assert.assertNotNull(glCanvas); + Assert.assertNotNull(animator); + + animator.stop(); + Assert.assertEquals(false, animator.isAnimating()); + frame.setVisible(false); + Assert.assertEquals(false, frame.isVisible()); + frame.remove(glCanvas); + frame.dispose(); + frame=null; + glCanvas=null; + } + + @Test + public void test01() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + runTestGL(caps); + } + + static long duration = 500; // ms + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + org.junit.runner.JUnitCore.main(TestGearsAWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java new file mode 100644 index 000000000..40e2ae933 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java @@ -0,0 +1,130 @@ +/** + * 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.jogl.demos.gl2.gears; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.FPSAnimator; +import javax.media.opengl.awt.GLJPanel; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.lang.reflect.InvocationTargetException; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Ignore; +import org.junit.Test; + +public class TestGearsGLJPanelAWT extends UITestCase { + static GLProfile glp; + static int width, height; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(false); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 512; + } + + @AfterClass + public static void releaseClass() { + } + + protected void runTestGL(GLCapabilities caps) + throws AWTException, InterruptedException, InvocationTargetException + { + JFrame frame = new JFrame("Swing GLJPanel"); + Assert.assertNotNull(frame); + + GLJPanel glJPanel = new GLJPanel(caps); + Assert.assertNotNull(glJPanel); + glJPanel.addGLEventListener(new Gears()); + + FPSAnimator animator = new FPSAnimator(glJPanel, 60); + + final JFrame _frame = frame; + final GLJPanel _glJPanel = glJPanel; + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _frame.getContentPane().add(_glJPanel, BorderLayout.CENTER); + _frame.setSize(512, 512); + _frame.setVisible(true); + } } ) ; + + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + + while(animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + + Assert.assertNotNull(frame); + Assert.assertNotNull(glJPanel); + Assert.assertNotNull(animator); + + animator.stop(); + Assert.assertEquals(false, animator.isAnimating()); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _frame.setVisible(false); + _frame.getContentPane().remove(_glJPanel); + _frame.remove(_glJPanel); + _glJPanel.destroy(); + _frame.dispose(); + } } ); + } + + @Test + public void test01() + throws AWTException, InterruptedException, InvocationTargetException + { + GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + runTestGL(caps); + } + + static long duration = 500; // ms + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + org.junit.runner.JUnitCore.main(TestGearsGLJPanelAWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWTBug450.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWTBug450.java new file mode 100644 index 000000000..cd2682541 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWTBug450.java @@ -0,0 +1,163 @@ +/** + * 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.jogl.demos.gl2.gears; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.FPSAnimator; + +import javax.media.opengl.awt.GLJPanel; +import javax.media.opengl.glu.gl2.GLUgl2; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.lang.reflect.InvocationTargetException; +import java.nio.ByteBuffer; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +/** + * Test for bug 450, which causes the right part of the frame to be black + * for all x >= height. + * + * Draws the Gears demo in a window that's twice as wide than it is tall, + * and checks to see if a particular pixel in the right half of the frame + * is colored. + * + * @author Wade Walker (adapted from TestGearsGLJPanelAWT) + */ +public class TestGearsGLJPanelAWTBug450 extends UITestCase { + static GLProfile glp; + static int width, height; + /** Set this if test fails. Needed because we can't throw an exception + * all the way up the stack from where we test the pixel. */ + static boolean failed; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(false); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 256; + } + + @AfterClass + public static void releaseClass() { + } + + protected void runTestGL(GLCapabilities caps) + throws AWTException, InterruptedException, InvocationTargetException + { + JFrame frame = new JFrame("Swing GLJPanel"); + Assert.assertNotNull(frame); + + GLJPanel glJPanel = new GLJPanel(caps); + Assert.assertNotNull(glJPanel); + glJPanel.addGLEventListener(new Gears() { + @Override + public void display(GLAutoDrawable drawable) { + super.display(drawable); + // look at one pixel at the bottom of the frame, just right of + // the center line, and make sure it's not black + GL2 gl = GLUgl2.getCurrentGL2(); + ByteBuffer bytebuffer = ByteBuffer.allocateDirect( 3 ); + gl.glReadPixels( 260, 10, 1, 1, GL2.GL_BGR, GL2.GL_UNSIGNED_BYTE, bytebuffer ); + byte byte0 = bytebuffer.get( 0 ); + byte byte1 = bytebuffer.get( 1 ); + byte byte2 = bytebuffer.get( 2 ); + if( (byte0 == 0) && (byte1 == 0) && (byte2 == 0) ) + failed = true; + } + }); + + FPSAnimator animator = new FPSAnimator(glJPanel, 60); + + final JFrame _frame = frame; + final GLJPanel _glJPanel = glJPanel; + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _frame.getContentPane().add(_glJPanel, BorderLayout.CENTER); + _frame.setSize(width, height); + _frame.setVisible(true); + } } ) ; + + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + + while(animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + + Assert.assertNotNull(frame); + Assert.assertNotNull(glJPanel); + Assert.assertNotNull(animator); + + animator.stop(); + Assert.assertEquals(false, animator.isAnimating()); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _frame.setVisible(false); + _frame.getContentPane().remove(_glJPanel); + _frame.remove(_glJPanel); + _glJPanel.destroy(); + _frame.dispose(); + } } ); + + Assert.assertFalse( failed ); + } + + @Test + public void test01() + throws AWTException, InterruptedException, InvocationTargetException + { + GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + runTestGL(caps); + } + + static long duration = 500; // ms + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + org.junit.runner.JUnitCore.main(TestGearsGLJPanelAWTBug450.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java new file mode 100644 index 000000000..0f7d77f82 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java @@ -0,0 +1,130 @@ +/** + * 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.jogl.demos.gl2.gears.newt; + +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.QuitAdapter; + +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLRunnable; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +public class TestGearsNEWT extends UITestCase { + static GLProfile glp; + static int width, height; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 512; + } + + @AfterClass + public static void releaseClass() { + } + + protected void runTestGL(GLCapabilities caps) throws InterruptedException { + GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Gears NEWT Test"); + + glWindow.addGLEventListener(new Gears()); + + Animator animator = new Animator(glWindow); + QuitAdapter quitAdapter = new QuitAdapter(); + + //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter)); + //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter)); + glWindow.addKeyListener(quitAdapter); + glWindow.addWindowListener(quitAdapter); + + final GLWindow f_glWindow = glWindow; + glWindow.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + if(e.getKeyChar()=='f') { + new Thread() { + public void run() { + f_glWindow.setFullscreen(!f_glWindow.isFullscreen()); + } }.start(); + } else if(e.getKeyChar()=='d') { + new Thread() { + public void run() { + f_glWindow.setUndecorated(!f_glWindow.isUndecorated()); + } }.start(); + } + } + }); + + glWindow.setSize(width, height); + glWindow.setVisible(true); + animator.start(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + + animator.stop(); + glWindow.invalidate(); + } + + @Test + public void test01() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + runTestGL(caps); + } + + static long duration = 500; // ms + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + org.junit.runner.JUnitCore.main(TestGearsNEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java new file mode 100644 index 000000000..f05c20c4c --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java @@ -0,0 +1,112 @@ +/** + * 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.jogl.demos.gl2.gears.newt; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +public class TestGearsNewtAWTWrapper extends UITestCase { + static GLProfile glp; + static int width, height; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 512; + } + + @AfterClass + public static void releaseClass() { + } + + protected void runTestGL(GLCapabilitiesImmutable caps) throws InterruptedException { + Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null, false); // local display + Screen nScreen = NewtFactory.createScreen(nDisplay, 0); // screen 0 + Window nWindow = NewtFactory.createWindow(nScreen, caps); + + GLWindow glWindow = GLWindow.create(nWindow); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Gears NewtAWTWrapper Test"); + + glWindow.addGLEventListener(new Gears()); + + Animator animator = new Animator(glWindow); + QuitAdapter quitAdapter = new QuitAdapter(); + + glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter)); + glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter)); + + glWindow.setSize(width, height); + glWindow.setVisible(true); + animator.start(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + + animator.stop(); + glWindow.invalidate(); + } + + @Test + public void test01() throws InterruptedException { + GLCapabilitiesImmutable caps = new GLCapabilities(GLProfile.getDefault()); + runTestGL(caps); + } + + static long duration = 500; // ms + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + org.junit.runner.JUnitCore.main(TestGearsNewtAWTWrapper.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java new file mode 100644 index 000000000..8897dc6fe --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java @@ -0,0 +1,184 @@ +/** + * 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.jogl.drawable; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.opengl.*; + +import com.jogamp.newt.*; +import java.io.IOException; + +public class TestDrawable01NEWT extends UITestCase { + static GLProfile glp; + static GLDrawableFactory factory; + static int width, height; + GLCapabilities caps; + Window window; + GLDrawable drawable; + GLContext context; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + factory = GLDrawableFactory.getFactory(glp); + Assert.assertNotNull(factory); + width = 640; + height = 480; + } + + @AfterClass + public static void releaseClass() { + Assert.assertNotNull(factory); + factory=null; + } + + @Before + public void initTest() { + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + void createWindow(boolean onscreen, boolean pbuffer, boolean undecorated) { + caps.setOnscreen(onscreen); + caps.setPBuffer(!onscreen && pbuffer); + caps.setDoubleBuffered(onscreen); + // System.out.println("Requested: "+caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + window = NewtFactory.createWindow(screen, caps); + Assert.assertNotNull(window); + window.setUndecorated(onscreen && undecorated); + window.setSize(width, height); + window.setVisible(true); + // System.out.println("Created: "+window); + + // + // Create native OpenGL resources .. XGL/WGL/CGL .. + // equivalent to GLAutoDrawable methods: setVisible(true) + // + GLCapabilities glCaps = (GLCapabilities) window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(glCaps); + Assert.assertTrue(glCaps.getGreenBits()>5); + Assert.assertTrue(glCaps.getBlueBits()>5); + Assert.assertTrue(glCaps.getRedBits()>5); + Assert.assertEquals(glCaps.isOnscreen(),onscreen); + Assert.assertTrue(onscreen || !pbuffer || glCaps.isPBuffer()); // pass if onscreen, or !pbuffer req. or have pbuffer + Assert.assertEquals(glCaps.getDoubleBuffered(),onscreen); + Assert.assertTrue(glCaps.getDepthBits()>4); + + drawable = factory.createGLDrawable(window); + Assert.assertNotNull(drawable); + // System.out.println("Pre: "+drawable); + // + drawable.setRealized(true); + // Assert.assertEquals(width,drawable.getWidth()); + // Assert.assertEquals(height,drawable.getHeight()); + // Assert.assertEquals(glCaps,drawable.getChosenGLCapabilities()); + Assert.assertEquals(window,drawable.getNativeSurface()); + // System.out.println("Post: "+drawable); + + context = drawable.createContext(null); + Assert.assertNotNull(context); + // System.out.println(context); + + int res = context.makeCurrent(); + Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res); + + // draw something .. + + drawable.swapBuffers(); + context.release(); + + // System.out.println("Final: "+window); + } + + void destroyWindow() { + // GLWindow.dispose(..) sequence + Assert.assertNotNull(context); + context.destroy(); + + Assert.assertNotNull(drawable); + drawable.setRealized(false); + + // GLWindow.destroy(..) sequence cont.. + Assert.assertNotNull(window); + window.invalidate(); + + drawable = null; + context = null; + window = null; + } + + @Test + public void testOnScreenDecorated() throws InterruptedException { + createWindow(true, false, false); + Thread.sleep(1000); // 1000 ms + destroyWindow(); + } + + @Test + public void testOnScreenUndecorated() throws InterruptedException { + createWindow(true, false, true); + Thread.sleep(1000); // 1000 ms + destroyWindow(); + } + + public static void main(String args[]) throws IOException { + String tstname = TestDrawable01NEWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java new file mode 100644 index 000000000..ed2f5d3cb --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java @@ -0,0 +1,143 @@ +/** + * 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.jogl.glsl; + +import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquare0; +import com.jogamp.opengl.test.junit.util.GLSLSimpleProgram; +import com.jogamp.opengl.test.junit.util.UITestCase; + + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.test.junit.jogl.demos.es2.shader.RedSquareShader; +import com.jogamp.opengl.test.junit.util.MiscUtils; + +import java.io.IOException; +import javax.media.opengl.GL2ES2; +import org.junit.AfterClass; + +public class TestGLSLSimple01NEWT extends UITestCase { + static long durationPerTest = 100; // ms + + @BeforeClass + public static void initClass() { + System.err.println("class init"); + GLProfile.initSingleton(true); + } + + @AfterClass + public static void tearDownClass() { + System.err.println("class tear down .."); + GLProfile.shutdown(); + System.err.println("class tear down end"); + } + + @Test(timeout=60000) + public void testGLSLCompilation01() { + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + GLWindow window = GLWindow.create(caps); + Assert.assertNotNull(window); + window.setSize(800, 600); + window.setVisible(true); + Assert.assertTrue(window.isNativeValid()); + + GLContext context = window.getContext(); + context.setSynchronized(true); + + // trigger native creation of drawable/context + window.display(); + Assert.assertTrue(window.isRealized()); + Assert.assertTrue(window.getContext().isCreated()); + + context.makeCurrent(); + + // given + + GL2ES2 gl = context.getGL().getGL2ES2(); + GLSLSimpleProgram myShader = GLSLSimpleProgram.create(gl, + RedSquareShader.VERTEX_SHADER_TEXT, + RedSquareShader.FRAGMENT_SHADER_TEXT, + true); + + myShader.release(gl); + context.release(); + window.destroy(); + } + + @Test(timeout=60000) + public void testGLSLUse01() throws InterruptedException { + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + GLWindow window = GLWindow.create(caps); + Assert.assertNotNull(window); + window.setSize(800, 600); + window.setVisible(true); + Assert.assertTrue(window.isNativeValid()); + window.addGLEventListener(new RedSquare0()); + + Animator animator = new Animator(window); + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + while(animator.isAnimating() && animator.getDuration()<durationPerTest) { + Thread.sleep(100); + } + Assert.assertEquals(true, animator.isAnimating()); + + window.destroy(); + animator.stop(); + } + + public static void main(String args[]) throws IOException { + System.err.println("main - start"); + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest); + } + } + String tstname = TestGLSLSimple01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + System.err.println("main - end"); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestShaderCompilationBug459AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestShaderCompilationBug459AWT.java new file mode 100644 index 000000000..e7f376e3e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestShaderCompilationBug459AWT.java @@ -0,0 +1,162 @@ +/** + * 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.jogl.glsl; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +import javax.media.opengl.GL2GL3; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import java.awt.Frame; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +/** + * Duplicates bug 459, where a vertex shader won't compile when 8 bits of stencil are requested. + * This bug is Windows-only; it works on Mac OS X and CentOS. + */ +public class TestShaderCompilationBug459AWT extends UITestCase { + static GLProfile glp; + static int width, height; + static long duration = 500; // ms + /** Exception in shader code sets this, since it won't bubble up through AWT. */ + GLException glexception; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 512; + } + + @AfterClass + public static void releaseClass() { + } + + @Test + public void compileShader() throws InterruptedException { + GLProfile glp = GLProfile.get("GL2GL3"); + GLCapabilities caps = new GLCapabilities(glp); + // commenting out this line makes it work + caps.setStencilBits(8); + + // commenting in this line also makes it work + //caps.setSampleBuffers(true); + + Frame frame = new Frame("Bug 459 shader compilation test"); + Assert.assertNotNull(frame); + + GLCanvas glCanvas = new GLCanvas(caps); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setSize(512, 512); + + glCanvas.addGLEventListener(new GLEventListener() { + /* @Override */ + public void init(GLAutoDrawable drawable) { + String code = "void main(void){gl_Position = vec4(0,0,0,1);}"; + + GL2GL3 gl = drawable.getGL().getGL2GL3(); + int id = gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER); + + try { + gl.glShaderSource(id, 1, new String[] { code }, (int[])null, 0); + gl.glCompileShader(id); + + int[] compiled = new int[1]; + gl.glGetShaderiv(id, GL2GL3.GL_COMPILE_STATUS, compiled, 0); + if (compiled[0] == GL2GL3.GL_FALSE) { + int[] logLength = new int[1]; + gl.glGetShaderiv(id, GL2GL3.GL_INFO_LOG_LENGTH, logLength, 0); + + byte[] log = new byte[logLength[0]]; + gl.glGetShaderInfoLog(id, logLength[0], (int[])null, 0, log, 0); + + System.err.println("Error compiling the shader: " + new String(log)); + + gl.glDeleteShader(id); + } + else { + System.out.println("Shader compiled: id=" + id); + } + } + catch( GLException e ) { + glexception = e; + } + } + + /* @Override */ + public void dispose(GLAutoDrawable drawable) { + } + + /* @Override */ + public void display(GLAutoDrawable drawable) { + } + + /* @Override */ + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + }); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + while(animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + + Assert.assertTrue( glexception != null ? glexception.getMessage() : "", glexception == null ); + Assert.assertNotNull(frame); + Assert.assertNotNull(glCanvas); + Assert.assertNotNull(animator); + + animator.stop(); + Assert.assertEquals(false, animator.isAnimating()); + frame.setVisible(false); + Assert.assertEquals(false, frame.isVisible()); + frame.remove(glCanvas); + frame.dispose(); + frame=null; + glCanvas=null; + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestShaderCompilationBug459AWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java new file mode 100644 index 000000000..be4873ff6 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java @@ -0,0 +1,231 @@ +package com.jogamp.opengl.test.junit.jogl.glsl; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import javax.media.opengl.GL3; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.glsl.ShaderUtil; + +import java.io.IOException; +import org.junit.AfterClass; + +/** + * Bug 'Function glTransformFeedbackVaryings incorrectly passes argument' + * http://jogamp.org/bugzilla/show_bug.cgi?id=407 + */ +public class TestTransformFeedbackVaryingsBug407NEWT extends UITestCase { + + private String VERTEX_SHADER_TEXT; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + } + + @AfterClass + public static void tearDownClass() { + GLProfile.shutdown(); + } + + class MyShader { + int shaderProgram; + int vertShader; + + MyShader(int shaderProgram, int vertShader) { + this.shaderProgram = shaderProgram; + this.vertShader = vertShader; + } + } + + private MyShader getShader(GL3 gl, String text, int type) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream pbaos = new PrintStream(baos); + + int shaderProgram = gl.glCreateProgram(); + + int vertShader = gl.glCreateShader(type); + + String[] lines = new String[]{text}; + int[] lengths = new int[]{lines[0].length()}; + gl.glShaderSource(vertShader, lines.length, lines, lengths, 0); + gl.glCompileShader(vertShader); + + if(!ShaderUtil.isShaderStatusValid(gl, vertShader, gl.GL_COMPILE_STATUS, pbaos)) { + System.out.println("getShader:postCompile: "+baos.toString()); + Assert.assertTrue(false); + } + pbaos.flush(); baos.reset(); + + gl.glAttachShader(shaderProgram, vertShader); + + return new MyShader(shaderProgram, vertShader); + } + + private void releaseShader(GL3 gl, MyShader myShader) { + if(null!=myShader) { + gl.glDetachShader(myShader.shaderProgram, myShader.vertShader); + gl.glDeleteShader(myShader.vertShader); + gl.glDeleteProgram(myShader.shaderProgram); + } + } + + + private GLWindow prepareTest() { + if(!GLProfile.isGL3Available()) { + System.err.println("GL3 not available"); + System.err.println(GLProfile.glAvailabilityToString()); + return null; + } + VERTEX_SHADER_TEXT = + "#version 150 \n" + + " \n" + + "out vec4 Position; \n" + + " \n" + + "void main() { \n" + + " Position = vec4(1.0, 1.0, 1.0, 1.0); \n" + + "} \n"; + + GLCapabilities caps; + + GLProfile glp = null; + try { + glp = GLProfile.get(GLProfile.GL3); + } catch (Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + caps = new GLCapabilities(glp); + + caps.setOnscreen(true); + caps.setDoubleBuffered(true); + + GLWindow window = GLWindow.create(caps); + Assert.assertNotNull(window); + window.setUndecorated(true); + window.setSize(800, 600); + window.setVisible(true); + Assert.assertTrue(window.isNativeValid()); + + window.getContext().setSynchronized(true); + + // trigger native creation of drawable/context + window.display(); + Assert.assertTrue(window.isRealized()); + Assert.assertTrue(window.getContext().isCreated()); + + return window; + } + + private void cleanupTest(GLWindow window) { + if(null!=window) { + window.destroy(); + } + } + + @Test(timeout=60000) + public void testGlTransformFeedbackVaryings_WhenVarNameOK() { + if(!GLProfile.isGL3Available()) { + return; + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream pbaos = new PrintStream(baos); + + GLWindow window = prepareTest(); + GLContext context = window.getContext(); + context.makeCurrent(); + + // given + + GL3 gl = context.getGL().getGL3(); + MyShader myShader = getShader(gl, VERTEX_SHADER_TEXT, GL3.GL_VERTEX_SHADER); + String[] vars = new String[]{"Position"}; + + // when + + gl.glTransformFeedbackVaryings(myShader.shaderProgram, 1, vars, GL3.GL_SEPARATE_ATTRIBS); + gl.glLinkProgram(myShader.shaderProgram); + + // then + + boolean error = false; + + if(!ShaderUtil.isProgramValid(gl, myShader.shaderProgram, pbaos)) { + System.out.println("Error (unexpected link error) - testGlTransformFeedbackVaryings_WhenVarNameOK:postLink: "+baos.toString()); + error = true; + } + pbaos.flush(); baos.reset(); + + Assert.assertEquals(GL3.GL_NO_ERROR, gl.glGetError()); + + releaseShader(gl, myShader); + context.release(); + cleanupTest(window); + + Assert.assertFalse(error); + } + + @Test(timeout=60000) + public void testGlTransformFeedbackVaryings_WhenVarNameWrong() { + if(!GLProfile.isGL3Available()) { + return; + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream pbaos = new PrintStream(baos); + + GLWindow window = prepareTest(); + GLContext context = window.getContext(); + context.makeCurrent(); + + // given + + GL3 gl = context.getGL().getGL3(); + MyShader myShader = getShader(gl, VERTEX_SHADER_TEXT, GL3.GL_VERTEX_SHADER); + String[] vars = new String[]{"PPPosition"}; + + // when + + gl.glTransformFeedbackVaryings(myShader.shaderProgram, 1, vars, GL3.GL_SEPARATE_ATTRIBS); + gl.glLinkProgram(myShader.shaderProgram); + + // then + + boolean error = false; + + if(!ShaderUtil.isProgramValid(gl, myShader.shaderProgram, pbaos)) { + System.out.println("GOOD (expected link error) - testGlTransformFeedbackVaryings_WhenVarNameWrong:postLink: "+baos.toString()); + // should be invalid, due to wrong var name + } else { + // oops + System.out.println("Error (unexpected link success) - testGlTransformFeedbackVaryings_WhenVarNameWrong link worked, but it should not"); + error = true; + } + pbaos.flush(); baos.reset(); + + Assert.assertEquals(GL3.GL_NO_ERROR, gl.glGetError()); + // You cannot assume this error message - Assert.assertTrue(baos.toString().contains("(named PPPosition)")); + + releaseShader(gl, myShader); + context.release(); + cleanupTest(window); + + Assert.assertFalse(error); + } + + public static void main(String args[]) throws IOException { + String tstname = TestTransformFeedbackVaryingsBug407NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestBug463ScaleImageMemoryAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestBug463ScaleImageMemoryAWT.java new file mode 100644 index 000000000..1f525a643 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestBug463ScaleImageMemoryAWT.java @@ -0,0 +1,114 @@ +/** + * Copyright 2011 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.jogl.glu; + +import java.awt.Frame; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.nio.ByteBuffer; + +import javax.media.opengl.GL; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import javax.media.opengl.glu.gl2.GLUgl2; + +import org.junit.Test; + +/** + * Tests for bug 463, where gluScaleImage uses up all system memory. This was due to creating millions of + * 4-byte direct buffer objects inside the tight loops of Image.fill_image() and Image.empty_image(). Since + * the JVM apparently can only allocate direct buffer in 4MB chunks, each 4-byte buffer cost us a million times + * the memory it should have. Changing the constructor of Type_Widget.java back to non-direct buffer (like it + * was in JOGL 1) solves the problem. + * @author Wade Walker + */ +public class TestBug463ScaleImageMemoryAWT implements GLEventListener { + + /* @Override */ + public void init(GLAutoDrawable drawable) { + } + + /* @Override */ + public void display(GLAutoDrawable drawable) { + int widthin = 559; + int heightin = 425; + + int widthout = 1024; + int heightout = 512; + + int textureInLength = widthin * heightin * 4; + int textureOutLength = widthout * heightout * 4; + + byte[] datain = new byte[textureInLength]; + byte[] dataout = new byte[textureOutLength]; + + ByteBuffer bufferIn = ByteBuffer.wrap(datain); + ByteBuffer bufferOut = ByteBuffer.wrap(dataout); + GLUgl2 glu = new GLUgl2(); + // in the failing case, the system would run out of memory in here + glu.gluScaleImage( GL.GL_RGBA, + widthin, heightin, GL.GL_UNSIGNED_BYTE, bufferIn, + widthout, heightout, GL.GL_UNSIGNED_BYTE, bufferOut ); + } + + /* @Override */ + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + + /* @Override */ + public void dispose(GLAutoDrawable drawable) { + } + + @Test + public void test01() { + Frame frame = new Frame("Test"); + GLProfile glprofile = GLProfile.getDefault(); + GLCapabilities glCapabilities = new GLCapabilities(glprofile); + final GLCanvas canvas = new GLCanvas(glCapabilities); + frame.setSize(256, 256); + frame.add(canvas); + frame.setVisible( true ); + canvas.addGLEventListener( this ); + + frame.addWindowListener(new WindowAdapter() { + public void windowClosing( WindowEvent e ) { + System.exit(0); + } + }); + canvas.display(); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestBug463ScaleImageMemoryAWT.class.getName()); + } +} diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectDoubleNOUI.java index 7290246d1..34b30f04e 100644..100755 --- a/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectDoubleNOUI.java @@ -3,14 +3,14 @@ * * 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 @@ -20,42 +20,38 @@ * 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; + +package com.jogamp.opengl.test.junit.jogl.glu; +import javax.media.opengl.glu.GLU; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLAutoDrawable; +import org.junit.Assert; +import org.junit.Test; -import com.jogamp.graph.curve.opengl.TextRenderer; -import com.jogamp.graph.geom.opengl.SVertex; +/** + * @author Julien Gouesse + */ +public class TestGluUnprojectDoubleNOUI { -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); - } + @Test + public void test(){ + final GLU glu = new GLU(); + final int[] pickedPoint = new int[]{400,300}; + final double pickedPointDepth = 0; + final double[] sceneModelViewValues = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final double[] projectionValues = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final int[] viewport = new int[]{0,0,800,600}; + final double[] objCoords = new double[]{Double.NaN,Double.NaN,Double.NaN}; + glu.gluUnProject(pickedPoint[0], pickedPoint[1], pickedPointDepth, sceneModelViewValues, 0, projectionValues, 0, viewport, 0, objCoords, 0); + Assert.assertTrue(!Double.isNaN(objCoords[0])&&!Double.isNaN(objCoords[1])&&!Double.isNaN(objCoords[2])); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestGluUnprojectDoubleNOUI.class.getName()); + } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java new file mode 100755 index 000000000..9e48a2000 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java @@ -0,0 +1,58 @@ +/** + * 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.jogl.glu; + +import javax.media.opengl.glu.GLU; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Julien Gouesse + */ +public class TestGluUnprojectFloatNOUI { + + + @Test + public void test(){ + final GLU glu = new GLU(); + final int[] pickedPoint = new int[]{400,300}; + final float pickedPointDepth = 0; + final float[] sceneModelViewValues = new float[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final float[] projectionValues = new float[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final int[] viewport = new int[]{0,0,800,600}; + final float[] objCoords = new float[]{Float.NaN,Float.NaN,Float.NaN}; + glu.gluUnProject(pickedPoint[0], pickedPoint[1], pickedPointDepth, sceneModelViewValues, 0, projectionValues, 0, viewport, 0, objCoords, 0); + Assert.assertTrue(!Double.isNaN(objCoords[0])&&!Double.isNaN(objCoords[1])&&!Double.isNaN(objCoords[2])); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestGluUnprojectFloatNOUI.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java new file mode 100644 index 000000000..21a97363c --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java @@ -0,0 +1,333 @@ +/** + * 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.jogl.newt; + +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.*; + +import java.lang.reflect.InvocationTargetException; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.newt.Screen; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.AWTException; +import java.awt.Robot; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.InputEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.media.opengl.GLEventListener; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.BorderFactory; +import javax.swing.border.Border; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { + static long durationPerTest = 500; // ms + static Robot robot; + static Border border; + static JFrame frame; + static JButton button; + static JPanel panel; + static JPanel colorPanel; + static boolean windowClosing; + + boolean modLightBrighter = true; + + Color modLight(Color c) { + Color c2; + if(modLightBrighter) { + c2 = c.brighter(); + } else { + c2 = c.darker(); + } + if(c2.equals(c)) { + modLightBrighter = !modLightBrighter; + } + return c2; + } + + class SwingGLAction implements GLEventListener { + public void init(GLAutoDrawable glad) { + } + + public void dispose(GLAutoDrawable glad) { + } + + public void display(GLAutoDrawable glad) { + colorPanel.setBackground(modLight(colorPanel.getBackground())); + colorPanel.repaint(); + } + + public void reshape(GLAutoDrawable glad, final int x, final int y, final int width, final int height) { + } + } + + @BeforeClass + public static void setup() throws InterruptedException, InvocationTargetException, AWTException { + int count; + + System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Start Pre-JOGL-Swing"); + + // GLProfile.initSingleton(false); + // GLProfile.initSingleton(true); + + // simulate AWT usage before JOGL's initialization of X11 threading + windowClosing=false; + border = BorderFactory.createLineBorder (Color.yellow, 2); + + panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + button = new JButton("Click me"); + button.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + System.err.println("Test: "+e); + } + }); + panel.add(button, BorderLayout.NORTH); + + colorPanel = new JPanel(); + Dimension size = new Dimension(400,100); + colorPanel.setPreferredSize(size); + colorPanel.setBorder(border); + panel.add(colorPanel, BorderLayout.SOUTH); + + frame = new JFrame("PRE JOGL"); + frame.addWindowListener( new WindowAdapter() { + public void windowClosing(WindowEvent ev) { + windowClosing=true; + } + }); + frame.setContentPane(panel); + frame.setSize(512, 512); + frame.setLocation(0, 0); + frame.pack(); + + // AWT/Swing: From here on (post setVisible(true) + // you need to use AWT/Swing's invokeAndWait() + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + colorPanel.setBackground(Color.white); + colorPanel.repaint(); + }}); + + robot = new Robot(); + robot.setAutoWaitForIdle(true); + + AWTRobotUtil.toFront(robot, frame); + AWTRobotUtil.requestFocus(robot, button); + + System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Before JOGL init"); + + GLProfile.initSingleton(false); + + System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): End Pre-JOGL-Swing"); + } + + @AfterClass + public static void release() throws InterruptedException, InvocationTargetException { + System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.release(): Start"); + robot = null; + Assert.assertNotNull(frame); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.dispose(); + } + }); + frame=null; + System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.release(): End"); + } + + protected void runTestGL(final Canvas canvas, GLAutoDrawable drawable) + throws AWTException, InterruptedException, InvocationTargetException { + + Dimension size = new Dimension(400,400); + canvas.setPreferredSize(size); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + panel.add(canvas, BorderLayout.CENTER); + frame.pack(); + } + }); + + AWTRobotUtil.toFront(robot, frame); + + drawable.addGLEventListener(new Gears()); + + for(int i=0; i<100; i++) { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + colorPanel.setBackground(modLight(colorPanel.getBackground())); + colorPanel.repaint(); + } + }); + drawable.display(); // one in process display + Thread.sleep(10); + } + + colorPanel.setBackground(Color.blue); + drawable.addGLEventListener(new SwingGLAction()); + + Point p0 = canvas.getLocationOnScreen(); + Rectangle r0 = canvas.getBounds(); + robot.mouseMove( (int) ( p0.getX() + .5 ) , + (int) ( p0.getY() + .5 ) ); + robot.mousePress(InputEvent.BUTTON1_MASK); + for(int i=0; !windowClosing && i<durationPerTest/10; i++) { + p0.translate(1,1); + robot.mouseMove( (int) ( p0.getX() + .5 ) , + (int) ( p0.getY() + .5 ) ); + Thread.sleep(10); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + for(int i=0; !windowClosing && i<durationPerTest/100; i++) { + Thread.sleep(100); + } + + Assert.assertNotNull(canvas); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + panel.remove(canvas); + frame.pack(); + } + }); + } + + @Test + public void test01NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException { + System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test01NewtCanvasAWT(): Start"); + + GLProfile glp = GLProfile.getDefault(); + GLCapabilities caps = new GLCapabilities(glp); + + GLWindow win0 = GLWindow.create(caps); + win0.setSize(100,100); + win0.setVisible(true); + Screen screen = win0.getScreen(); + win0.setPosition(screen.getWidth()-150, 0); + win0.addGLEventListener(new Gears()); + Animator anim = new Animator(win0); + anim.start(); + + GLWindow win1 = GLWindow.create(caps); + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(win1); + anim.add(win1); + runTestGL(newtCanvasAWT, win1); + + win0.destroy(); + Assert.assertEquals(true, anim.isAnimating()); + + newtCanvasAWT.destroy(); + + win0.invalidate(); + Assert.assertEquals(true, anim.isAnimating()); + win1.invalidate(); + Assert.assertEquals(false, anim.isAnimating()); + + anim.stop(); + + System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test01NewtCanvasAWT(): End"); + } + + @Test + public void test02GLCanvas() throws AWTException, InterruptedException, InvocationTargetException { + System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test02GLCanvas(): Start"); + GLProfile glp = GLProfile.getDefault(); + GLCapabilities caps = new GLCapabilities(glp); + + Animator anim = new Animator(); + anim.start(); + + /** + * Using GLCanvas _and_ NEWT side by side currently causes a deadlock + * in AWT with AMD drivers ! + * + GLWindow win0 = GLWindow.create(caps); + win0.setSize(100,100); + win0.setVisible(true); + Screen screen = win0.getScreen(); + win0.setPosition(screen.getWidth()-150, 0); + win0.addGLEventListener(new Gears()); + anim.add(win0); + */ + + GLCanvas glCanvas = new GLCanvas(caps); + anim.add(glCanvas); + runTestGL(glCanvas, glCanvas); + + /** + win0.destroy(); + Assert.assertEquals(true, anim.isAnimating()); + */ + anim.stop(); + System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test02GLCanvas(): End"); + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + System.out.println("durationPerTest: "+durationPerTest); + org.junit.runner.JUnitCore.main(TestSwingAWTRobotUsageBeforeJOGLInitBug411.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java new file mode 100644 index 000000000..95e7d6e53 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java @@ -0,0 +1,70 @@ +/** + * 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.jogl.offscreen; + +import java.io.IOException; +import javax.media.opengl.*; + +import com.jogamp.opengl.util.texture.TextureIO; +import java.io.File; + +public class ReadBuffer2File extends ReadBufferBase { + + public ReadBuffer2File(GLDrawable externalRead) { + super(externalRead); + } + + @Override + public void dispose(GLAutoDrawable drawable) { + super.dispose(drawable); + } + int shotNum = 0; + + void copyTextureData2File() throws IOException { + if (!readBufferUtil.isValid()) { + return; + } + + File file = File.createTempFile("shot" + shotNum + "-", ".ppm"); + TextureIO.write(readBufferUtil.getTextureData(), file); + System.out.println("Wrote: " + file.getAbsolutePath() + ", ..."); + shotNum++; + readBufferUtil.rewindPixelBuffer(); + } + + @Override + public void display(GLAutoDrawable drawable) { + super.display(drawable); + try { + copyTextureData2File(); + } catch (IOException ex) { + throw new RuntimeException("can not read buffer to file", ex); + } + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java new file mode 100644 index 000000000..96a830a53 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java @@ -0,0 +1,188 @@ +/** + * 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.jogl.offscreen; + +import java.nio.*; +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; + +import com.jogamp.opengl.util.*; + +import javax.media.opengl.fixedfunc.GLPointerFunc; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.GLArrayDataClient; +import com.jogamp.opengl.util.GLArrayDataServer; + +public class ReadBuffer2Screen extends ReadBufferBase { + PMVMatrix pmvMatrix; + GLArrayDataClient readTextureVertices = null; + GLArrayDataClient readTextureCoords = null; + boolean enableBufferAlways = false; // FIXME + boolean enableBufferVBO = true; // FIXME + + public ReadBuffer2Screen (GLDrawable externalRead) { + super(externalRead); + } + + @Override + public void init(GLAutoDrawable drawable) { + super.init(drawable); + + GL gl = drawable.getGL(); + + pmvMatrix = new PMVMatrix(); + + float f_edge = 1f; + if(null==readTextureVertices) { + //readTextureVertices = GLArrayDataClient.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex", + // 2, GL.GL_FLOAT, true, 4); + readTextureVertices = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex", + 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + readTextureVertices.setEnableAlways(enableBufferAlways); + readTextureVertices.setVBOUsage(enableBufferVBO); + { + FloatBuffer vb = (FloatBuffer)readTextureVertices.getBuffer(); + vb.put(-f_edge); vb.put(-f_edge); + vb.put( f_edge); vb.put(-f_edge); + vb.put(-f_edge); vb.put( f_edge); + vb.put( f_edge); vb.put( f_edge); + } + readTextureVertices.seal(gl, true); + System.out.println(readTextureVertices); + } + + // Clear background to gray + gl.glClearColor(0.5f, 0.5f, 0.5f, 0.4f); + } + + @Override + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + super.reshape(drawable, x, y, width, height); + + GL gl = drawable.getGL(); + + gl.glViewport(0, 0, width, height); + + if(gl instanceof GLLightingFunc) { + ((GLLightingFunc)gl).glShadeModel(GLLightingFunc.GL_SMOOTH); + } + + GLMatrixFunc glM; + if(gl instanceof GLMatrixFunc) { + glM = (GLMatrixFunc)gl; + } else { + throw new GLException("ES2 currently unhandled .. "); + } + + // Identity .. + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glTranslatef(0, 0, -2.5f); + if(null!=glM) { + glM.glMatrixMode(PMVMatrix.GL_MODELVIEW); + glM.glLoadMatrixf(pmvMatrix.glGetMvMatrixf()); + } + + // Set location in front of camera + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f); + if(null!=glM) { + glM.glMatrixMode(PMVMatrix.GL_PROJECTION); + glM.glLoadMatrixf(pmvMatrix.glGetPMatrixf()); + } + } + + @Override + public void dispose(GLAutoDrawable drawable) { + super.dispose(drawable); + } + + void renderOffscreenTexture(GL gl) { + if(!readBufferUtil.isValid()) return; + + // Now draw one quad with the texture + readBufferUtil.getTexture().enable(); + readBufferUtil.getTexture().bind(); + + if(gl.isGL2ES1()) { + // gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_REPLACE); + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_MODULATE); + } + + updateTextureCoords(gl, false); + + readTextureVertices.enableBuffer(gl, true); + if(null!=readTextureCoords) { + readTextureCoords.enableBuffer(gl, true); + } + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, readTextureVertices.getElementNumber()); + /** + if(null!=readTextureCoords) { + readTextureCoords.enableBuffer(gl, false); + } + readTextureVertices.enableBuffer(gl, false); */ + + readBufferUtil.getTexture().disable(); + } + + void updateTextureCoords(GL gl, boolean force) { + if(force || null==readTextureCoords) { + readTextureCoords = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, "mgl_MultiTexCoord0", + 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + readTextureCoords.setEnableAlways(enableBufferAlways); + readTextureCoords.setVBOUsage(enableBufferVBO); + { + TextureCoords coords = readBufferUtil.getTexture().getImageTexCoords(); + FloatBuffer cb = (FloatBuffer)readTextureCoords.getBuffer(); + cb.put(coords.left()); cb.put(coords.bottom()); + cb.put(coords.right()); cb.put(coords.bottom()); + cb.put(coords.left()); cb.put(coords.top()); + cb.put(coords.right()); cb.put(coords.top()); + } + readTextureCoords.seal(gl, true); + System.out.println(readTextureCoords); + } + } + + @Override + public void display(GLAutoDrawable drawable) { + super.display(drawable); + + GL gl = drawable.getGL(); + + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); + if(gl instanceof GLLightingFunc) { + ((GLLightingFunc)gl).glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } + + renderOffscreenTexture(gl); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java new file mode 100644 index 000000000..71a73a7e1 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java @@ -0,0 +1,91 @@ +/** + * 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.jogl.offscreen; + +import javax.media.opengl.*; + +public class ReadBufferBase implements GLEventListener { + public boolean glDebug = false ; + public boolean glTrace = false ; + + protected GLDrawable externalRead; + + ReadBufferUtil readBufferUtil = new ReadBufferUtil(); + + public ReadBufferBase (GLDrawable externalRead) { + this.externalRead = externalRead ; + } + + public void init(GLAutoDrawable drawable) { + GL _gl = drawable.getGL(); + + _gl.glGetError(); // flush error .. + + if(glDebug) { + try { + _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, _gl, null) ); + } catch (Exception e) { + throw new RuntimeException("can not set debug pipeline", e); + } + } + + if(glTrace) { + try { + _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, _gl, new Object[] { System.err } ) ); + } catch (Exception e) { + throw new RuntimeException("can not set trace pipeline", e); + } + } + + System.out.println(_gl); + + _gl.getContext().setGLReadDrawable(externalRead); + if(_gl.isGL2GL3()) { + _gl.getGL2GL3().glReadBuffer(GL2GL3.GL_FRONT); + } + System.out.println("---------------------------"); + System.out.println(_gl.getContext()); + System.out.println("---------------------------"); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void dispose(GLAutoDrawable drawable) { + readBufferUtil.dispose(); + } + + public void display(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + + readBufferUtil.fetchOffscreenTexture(drawable, gl); + } + +} + diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/ReadBufferUtil.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java index 172eef4fc..d4fa0d654 100644 --- a/src/com/jogamp/opengl/test/junit/graph/demos/ReadBufferUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java @@ -26,7 +26,7 @@ * or implied, of JogAmp Community. */ -package com.jogamp.opengl.test.junit.graph.demos; +package com.jogamp.opengl.test.junit.jogl.offscreen; import com.jogamp.opengl.util.GLBuffers; import java.nio.*; @@ -61,11 +61,11 @@ public class ReadBufferUtil { readTextureData = new TextureData( gl.getGLProfile(), // gl.isGL2GL3()?gl.GL_RGBA:gl.GL_RGB, - GL.GL_RGB, + gl.GL_RGB, drawable.getWidth(), drawable.getHeight(), 0, - GL.GL_RGB, - GL.GL_UNSIGNED_BYTE, + gl.GL_RGB, + gl.GL_UNSIGNED_BYTE, false, false, false /* flip */, readPixelBuffer, @@ -95,13 +95,11 @@ public class ReadBufferUtil { } @SuppressWarnings("deprecation") - public void dispose() { + public void dispose() { readTexture.dispose(); readTextureData = null; - if(null != readPixelBuffer) { - readPixelBuffer.clear(); - readPixelBuffer = null; - } + readPixelBuffer.clear(); + readPixelBuffer = null; readPixelSizeLast = 0; } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java new file mode 100644 index 000000000..3ad2c4213 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java @@ -0,0 +1,79 @@ +/** + * 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.jogl.offscreen; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.texture.TextureIO; + +import java.io.File; +import java.io.IOException; + +import javax.media.nativewindow.*; + +public class Surface2File implements SurfaceUpdatedListener { + + ReadBufferUtil readBufferUtil = new ReadBufferUtil(); + int shotNum = 0; + + public void dispose() { + readBufferUtil.dispose(); + } + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { + if (updater instanceof GLDrawable) { + GLDrawable drawable = (GLDrawable) updater; + GLContext ctx = GLContext.getCurrent(); + if (null != ctx && ctx.getGLDrawable() == drawable) { + GL gl = ctx.getGL(); + // FIXME glFinish() is an expensive paranoia sync, should not be necessary due to spec + gl.glFinish(); + readBufferUtil.fetchOffscreenTexture(drawable, gl); + gl.glFinish(); + try { + surface2File("shot"); + } catch (IOException ex) { + throw new RuntimeException("can not write survace to file", ex); + } + } + } + } + + public void surface2File(String basename) throws IOException { + if (!readBufferUtil.isValid()) { + return; + } + + File file = File.createTempFile(basename + shotNum + "-", ".ppm"); + TextureIO.write(readBufferUtil.getTextureData(), file); + System.err.println("Wrote: " + file.getAbsolutePath() + ", ..."); + shotNum++; + readBufferUtil.rewindPixelBuffer(); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01GLPBufferNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01GLPBufferNEWT.java new file mode 100644 index 000000000..6a02bc03b --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01GLPBufferNEWT.java @@ -0,0 +1,327 @@ +/** + * 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.jogl.offscreen; + + +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.event.MouseListener; +import com.jogamp.newt.event.WindowListener; +import com.jogamp.newt.opengl.GLWindow; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import java.io.IOException; + +public class TestOffscreen01GLPBufferNEWT extends UITestCase { + static GLProfile glpDefault; + static GLDrawableFactory glDrawableFactory; + static int width, height; + GLCapabilities capsDefault; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glpDefault = GLProfile.getDefault(); + Assert.assertNotNull(glpDefault); + glDrawableFactory = GLDrawableFactory.getFactory(glpDefault); + System.out.println("INFO: PBuffer supported: "+ glDrawableFactory.canCreateGLPbuffer(null)); + width = 640; + height = 480; + } + + @AfterClass + public static void releaseClass() { + } + + @Before + public void init() { + capsDefault = new GLCapabilities(glpDefault); + Assert.assertNotNull(capsDefault); + } + + private void do01OffscreenWindowPBuffer(GLCapabilities caps) { + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + Window window = NewtFactory.createWindow(screen, caps); + Assert.assertNotNull(window); + window.setSize(width, height); + GLWindow glWindow = GLWindow.create(window); + Assert.assertNotNull(glWindow); + glWindow.setVisible(true); + + GLEventListener demo = new RedSquare(); + WindowUtilNEWT.setDemoFields(demo, window, glWindow, false); + glWindow.addGLEventListener(demo); + + while ( glWindow.getTotalFrames() < 2) { + glWindow.display(); + } + + if(null!=glWindow) { + glWindow.destroy(); + } + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void test01aOffscreenWindowPBuffer() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test01bOffscreenWindowPBufferStencil() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + caps2.setStencilBits(8); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test01cOffscreenWindowPBufferStencilAlpha() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + caps2.setStencilBits(8); + caps2.setAlphaBits(8); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test01cOffscreenWindowPBuffer555() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + caps2.setRedBits(5); + caps2.setGreenBits(5); + caps2.setBlueBits(5); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test02Offscreen3Windows1DisplayPBuffer() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + int winnum = 3, i; + Window windows[] = new Window[winnum]; + GLWindow glWindows[] = new GLWindow[winnum]; + GLEventListener demos[] = new GLEventListener[winnum]; + + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + for(i=0; i<winnum; i++) { + System.out.println("Create Window "+i); + windows[i] = NewtFactory.createWindow(screen, caps2); + Assert.assertNotNull(windows[i]); + windows[i].setSize(width, height); + glWindows[i] = GLWindow.create(windows[i]); + Assert.assertNotNull(glWindows[i]); + glWindows[i].setVisible(true); + + demos[i] = new RedSquare(); + WindowUtilNEWT.setDemoFields(demos[i], windows[i], glWindows[i], false); + glWindows[i].addGLEventListener(demos[i]); + } + + while ( glWindows[0].getTotalFrames() < 2) { + for(i=0; i<winnum; i++) { + glWindows[i].display(); + } + } + + for(i=0; i<winnum; i++) { + if(null!=glWindows[i]) { + glWindows[i].destroy(); + } + if(null!=windows[i]) { + windows[i].destroy(); + } + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void test03Offscreen3Windows3DisplaysPBuffer() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + int winnum = 3, i; + Display displays[] = new Display[winnum]; + Screen screens[] = new Screen[winnum]; + Window windows[] = new Window[winnum]; + GLWindow glWindows[] = new GLWindow[winnum]; + GLEventListener demos[] = new GLEventListener[winnum]; + + for(i=0; i<winnum; i++) { + System.out.println("Create Window "+i); + displays[i] = NewtFactory.createDisplay(null, false); // local display + Assert.assertNotNull(displays[i]); + screens[i] = NewtFactory.createScreen(displays[i], 0); // screen 0 + Assert.assertNotNull(screens[i]); + windows[i] = NewtFactory.createWindow(screens[i], caps2); + Assert.assertNotNull(windows[i]); + windows[i].setSize(width, height); + glWindows[i] = GLWindow.create(windows[i]); + Assert.assertNotNull(glWindows[i]); + glWindows[i].setVisible(true); + demos[i] = new RedSquare(); + WindowUtilNEWT.setDemoFields(demos[i], windows[i], glWindows[i], false); + glWindows[i].addGLEventListener(demos[i]); + } + + while ( glWindows[0].getTotalFrames() < 2) { + for(i=0; i<winnum; i++) { + glWindows[i].display(); + } + } + + for(i=0; i<winnum; i++) { + if(null!=glWindows[i]) { + glWindows[i].destroy(); + } + if(null!=windows[i]) { + windows[i].destroy(); + } + if(null!=screens[i]) { + screens[i].destroy(); + } + if(null!=displays[i]) { + displays[i].destroy(); + } + } + } + + @Test + public void test04OffscreenSnapshotWithDemoPBuffer() { + if(!glDrawableFactory.canCreateGLPbuffer(null)) { + System.out.println("WARNING: PBuffer not supported on this platform - cannot test"); + return; + } + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); + + System.out.println("Create Window 1"); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + Window window = NewtFactory.createWindow(screen, caps2); + Assert.assertNotNull(window); + window.setSize(width, height); + GLWindow glWindow = GLWindow.create(window); + Assert.assertNotNull(glWindow); + glWindow.setVisible(true); + + GLWindow windowOnScreen = null; + WindowListener wl=null; + MouseListener ml=null; + SurfaceUpdatedListener ul=null; + + GLEventListener demo = new RedSquare(); + Assert.assertNotNull(demo); + + WindowUtilNEWT.run(glWindow, demo, windowOnScreen, wl, ml, ul, 2, true /*snapshot*/, false /*debug*/); + + if(null!=windowOnScreen) { + windowOnScreen.destroy(); + } + if(null!=glWindow) { + glWindow.destroy(); + } + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + public static void main(String args[]) throws IOException { + String tstname = TestOffscreen01GLPBufferNEWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen02BitmapNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen02BitmapNEWT.java new file mode 100644 index 000000000..d92b4ffbf --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen02BitmapNEWT.java @@ -0,0 +1,184 @@ +/** + * 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.jogl.offscreen; + + +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.event.MouseListener; +import com.jogamp.newt.event.WindowListener; +import com.jogamp.newt.opengl.GLWindow; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import java.io.IOException; + +public class TestOffscreen02BitmapNEWT extends UITestCase { + static GLProfile glpDefault; + static GLDrawableFactory glDrawableFactory; + static int width, height; + GLCapabilities capsDefault; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glpDefault = GLProfile.getDefault(); + Assert.assertNotNull(glpDefault); + glDrawableFactory = GLDrawableFactory.getFactory(glpDefault); + System.out.println("INFO: PBuffer supported: "+ glDrawableFactory.canCreateGLPbuffer(null)); + width = 640; + height = 480; + } + + @AfterClass + public static void releaseClass() { + } + + @Before + public void init() { + capsDefault = new GLCapabilities(glpDefault); + Assert.assertNotNull(capsDefault); + } + + @Test + public void test11OffscreenWindowPixmap() { + // Offscreen doesn't work on >= GL3 (ATI) + GLProfile glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false); + + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + Window window = NewtFactory.createWindow(screen, caps2); + Assert.assertNotNull(window); + window.setSize(width, height); + GLWindow glWindow = GLWindow.create(window); + Assert.assertNotNull(glWindow); + glWindow.setVisible(true); + + GLEventListener demo = new RedSquare(); + WindowUtilNEWT.setDemoFields(demo, window, glWindow, false); + glWindow.addGLEventListener(demo); + + while ( glWindow.getTotalFrames() < 2) { + glWindow.display(); + } + + if(null!=glWindow) { + glWindow.destroy(); + } + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void test14OffscreenSnapshotWithDemoPixmap() { + // Offscreen doesn't work on >= GL3 (ATI) + GLProfile glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false); + + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + Window window = NewtFactory.createWindow(screen, caps2); + Assert.assertNotNull(window); + window.setSize(width, height); + GLWindow glWindow = GLWindow.create(window); + Assert.assertNotNull(glWindow); + glWindow.setVisible(true); + + GLWindow windowOnScreen = null; + WindowListener wl=null; + MouseListener ml=null; + SurfaceUpdatedListener ul=null; + + GLEventListener demo = new RedSquare(); + Assert.assertNotNull(demo); + + WindowUtilNEWT.run(glWindow, demo, windowOnScreen, wl, ml, ul, 2, true /*snapshot*/, false /*debug*/); + + if(null!=windowOnScreen) { + windowOnScreen.destroy(); + } + if(null!=glWindow) { + glWindow.destroy(); + } + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + public static void main(String args[]) throws IOException { + String tstname = TestOffscreen02BitmapNEWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java new file mode 100644 index 000000000..4420a5107 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java @@ -0,0 +1,110 @@ +/** + * 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.jogl.offscreen; + +import com.jogamp.opengl.test.junit.util.*; + +import org.junit.Assert; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; + +public class WindowUtilNEWT { + + public static GLCapabilities fixCaps(GLCapabilities caps, boolean onscreen, boolean pbuffer, boolean undecorated) { + GLCapabilities caps2 = (GLCapabilities) caps.cloneMutable(); + caps2.setOnscreen(onscreen); + caps2.setPBuffer(!onscreen && pbuffer); + caps2.setDoubleBuffered(!onscreen); + return caps2; + } + + public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(window); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + public static void run(GLWindow windowOffScreen, GLEventListener demo, + GLWindow windowOnScreen, WindowListener wl, MouseListener ml, + SurfaceUpdatedListener ul, int frames, boolean snapshot, boolean debug) { + Assert.assertNotNull(windowOffScreen); + Assert.assertNotNull(demo); + + setDemoFields(demo, windowOffScreen, windowOffScreen, debug); + windowOffScreen.addGLEventListener(demo); + + if ( null != windowOnScreen ) { + if(null!=wl) { + windowOnScreen.addWindowListener(wl); + } + if(null!=ml) { + windowOnScreen.addMouseListener(ml); + } + windowOnScreen.setVisible(true); + } + + GLDrawable readDrawable = windowOffScreen.getContext().getGLDrawable() ; + + if ( null == windowOnScreen ) { + if(snapshot) { + Surface2File s2f = new Surface2File(); + windowOffScreen.addSurfaceUpdatedListener(s2f); + } + } else { + ReadBuffer2Screen readDemo = new ReadBuffer2Screen( readDrawable ) ; + windowOnScreen.addGLEventListener(readDemo); + } + if(null!=ul) { + windowOffScreen.addSurfaceUpdatedListener(ul); + } + + if(debug) { + System.err.println("+++++++++++++++++++++++++++"); + System.err.println(windowOffScreen); + System.err.println("+++++++++++++++++++++++++++"); + } + + while ( windowOffScreen.getTotalFrames() < frames) { + windowOffScreen.display(); + } + windowOffScreen.removeAllSurfaceUpdatedListener(); + + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/OneTriangle.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/OneTriangle.java new file mode 100644 index 000000000..655e590a3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/OneTriangle.java @@ -0,0 +1,71 @@ +/**
+ * 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.jogl.swt;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.glu.GLU;
+
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * A utility class to encapsulate drawing a single triangle for unit tests.
+ * @author Wade Walker
+ */
+public class OneTriangle {
+
+ public static void setup( GL2 gl, Rectangle rectangle ) {
+ gl.glMatrixMode( GL2.GL_PROJECTION );
+ gl.glLoadIdentity();
+
+ // coordinate system origin at lower left with width and height same as the window
+ GLU glu = new GLU();
+ glu.gluOrtho2D( 0.0f, rectangle.width, 0.0f, rectangle.height );
+
+ gl.glMatrixMode( GL2.GL_MODELVIEW );
+ gl.glLoadIdentity();
+
+ gl.glViewport( 0, 0, rectangle.width, rectangle.height );
+ }
+
+ public static void render( GL2 gl, Rectangle rectangle ) {
+ gl.glClear( GL.GL_COLOR_BUFFER_BIT );
+
+ // draw a triangle filling the window
+ gl.glLoadIdentity();
+ gl.glBegin( GL.GL_TRIANGLES );
+ gl.glColor3f( 1, 0, 0 );
+ gl.glVertex2f( 0, 0 );
+ gl.glColor3f( 0, 1, 0 );
+ gl.glVertex2f( rectangle.width, 0 );
+ gl.glColor3f( 0, 0, 1 );
+ gl.glVertex2f( rectangle.width / 2, rectangle.height );
+ gl.glEnd();
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java new file mode 100644 index 000000000..af125d4df --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java @@ -0,0 +1,199 @@ +/**
+ * 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.jogl.swt;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLProfile;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.opengl.GLCanvas;
+import org.eclipse.swt.opengl.GLData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+/**
+ * Tests that a basic SWT app can open without crashing under different GL profiles. Uses the SWT GL canvas.
+ * @author Wade Walker
+ */
+public class TestSWT01GLn extends UITestCase {
+
+ static int duration = 250;
+
+ static final int iwidth = 640;
+ static final int iheight = 480;
+
+ Display display = null;
+ Shell shell = null;
+ Composite composite = null;
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton( true );
+ System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
+ }
+
+ @Before
+ public void init() {
+ display = new Display();
+ Assert.assertNotNull( display );
+ shell = new Shell( display );
+ Assert.assertNotNull( shell );
+ shell.setLayout( new FillLayout() );
+ composite = new Composite( shell, SWT.NONE );
+ composite.setLayout( new FillLayout() );
+ Assert.assertNotNull( composite );
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull( display );
+ Assert.assertNotNull( shell );
+ Assert.assertNotNull( composite );
+ try {
+ composite.dispose();
+ shell.dispose();
+ display.dispose();
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ display = null;
+ shell = null;
+ composite = null;
+ }
+
+ protected void runTestAGL( GLProfile glprofile ) throws InterruptedException {
+ GLData gldata = new GLData();
+ gldata.doubleBuffer = true;
+ // need SWT.NO_BACKGROUND to prevent SWT from clearing the window
+ // at the wrong times (we use glClear for this instead)
+ final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );
+ Assert.assertNotNull( glcanvas );
+ glcanvas.setCurrent();
+ final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();
+ Assert.assertNotNull( glcontext );
+
+ // fix the viewport when the user resizes the window
+ glcanvas.addListener( SWT.Resize, new Listener() {
+ public void handleEvent( Event event ) {
+ Rectangle rectangle = glcanvas.getClientArea();
+ glcanvas.setCurrent();
+ glcontext.makeCurrent();
+ GL2 gl = glcontext.getGL().getGL2();
+ OneTriangle.setup( gl, rectangle );
+ glcontext.release();
+ System.err.println("resize");
+ }
+ });
+
+ // draw the triangle when the OS tells us that any part of the window needs drawing
+ glcanvas.addPaintListener( new PaintListener() {
+ public void paintControl( PaintEvent paintevent ) {
+ Rectangle rectangle = glcanvas.getClientArea();
+ glcanvas.setCurrent();
+ glcontext.makeCurrent();
+ GL2 gl = glcontext.getGL().getGL2();
+ OneTriangle.render( gl, rectangle );
+ glcanvas.swapBuffers();
+ glcontext.release();
+ System.err.println("paint");
+ }
+ });
+
+ shell.setText( getClass().getName() );
+ shell.setSize( 640, 480 );
+ shell.open();
+
+ long lStartTime = System.currentTimeMillis();
+ long lEndTime = lStartTime + duration;
+ try {
+ while( (System.currentTimeMillis() < lEndTime) && !glcanvas.isDisposed() ) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ } catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ glcanvas.dispose();
+ }
+
+ @Test
+ public void testA01GLDefault() throws InterruptedException {
+ GLProfile glprofile = GLProfile.getDefault();
+ System.out.println( "GLProfile Default: " + glprofile );
+ runTestAGL( glprofile );
+ }
+
+ @Test
+ public void test02GL2() throws InterruptedException {
+ GLProfile glprofile = GLProfile.get(GLProfile.GL2);
+ System.out.println( "GLProfile GL2: " + glprofile );
+ runTestAGL( glprofile );
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ duration = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+duration);
+ org.junit.runner.JUnitCore.main(TestSWT01GLn.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java new file mode 100644 index 000000000..b3d167b80 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java @@ -0,0 +1,236 @@ +/** + * 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.jogl.swt; + +import javax.media.opengl.GL2; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLProfile; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.ProxySurface; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLDrawable; +import jogamp.nativewindow.swt.SWTAccessor; +import org.eclipse.swt.widgets.Canvas; + +/** + * Tests that a basic SWT app can open without crashing under different GL profiles. Uses the SWT GL canvas. + * @author Wade Walker + */ +public class TestSWT02GLn extends UITestCase { + + static int duration = 250; + + static final int iwidth = 640; + static final int iheight = 480; + + Display display = null; + Shell shell = null; + Composite composite = null; + + @BeforeClass + public static void startup() { + GLProfile.initSingleton( true ); + System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() ); + } + + @Before + public void init() { + display = new Display(); + Assert.assertNotNull( display ); + shell = new Shell( display ); + Assert.assertNotNull( shell ); + shell.setLayout( new FillLayout() ); + composite = new Composite( shell, SWT.NONE ); + composite.setLayout( new FillLayout() ); + Assert.assertNotNull( composite ); + } + + @After + public void release() { + Assert.assertNotNull( display ); + Assert.assertNotNull( shell ); + Assert.assertNotNull( composite ); + try { + composite.dispose(); + shell.dispose(); + display.dispose(); + } + catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + display = null; + shell = null; + composite = null; + } + + protected void runTestAGL( GLProfile glprofile ) throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glprofile); + GLDrawableFactory factory = GLDrawableFactory.getFactory(glprofile); + + // need SWT.NO_BACKGROUND to prevent SWT from clearing the window + // at the wrong times (we use glClear for this instead) + final Canvas canvas = new Canvas( composite, SWT.NO_BACKGROUND); + Assert.assertNotNull( canvas ); + + SWTAccessor.setRealized(canvas, true); + AbstractGraphicsDevice device = SWTAccessor.getDevice(canvas); + long nativeWindowHandle = SWTAccessor.getWindowHandle(canvas); + System.err.println("*** device: " + device); + System.err.println("*** window handle: 0x" + Long.toHexString(nativeWindowHandle)); + + ProxySurface proxySurface = factory.createProxySurface(device, nativeWindowHandle, caps, null); + Assert.assertNotNull( proxySurface ); + proxySurface.setSize( 640, 480 ); + System.err.println("*** ProxySurface: " + proxySurface); + final GLDrawable drawable = factory.createGLDrawable(proxySurface); + Assert.assertNotNull( drawable ); + drawable.setRealized(true); + System.err.println("*** Drawable: " + drawable); + Assert.assertTrue( drawable.isRealized() ); + final GLContext glcontext = drawable.createContext(null); + // trigger native creation .. + if( GLContext.CONTEXT_NOT_CURRENT < glcontext.makeCurrent() ) { + glcontext.release(); + } + + final boolean[] sizeMissing = new boolean[] { false }; + + // fix the viewport when the user resizes the window + canvas.addListener( SWT.Resize, new Listener() { + public void handleEvent( Event event ) { + Rectangle rectangle = canvas.getClientArea(); + boolean glok=false; + if( GLContext.CONTEXT_NOT_CURRENT < glcontext.makeCurrent() ) { + glok=true; + GL2 gl = glcontext.getGL().getGL2(); + OneTriangle.setup( gl, rectangle ); + glcontext.release(); + } else { + sizeMissing[0] = true; + } + System.err.println("resize: glok " + glok); + } + }); + + // draw the triangle when the OS tells us that any part of the window needs drawing + canvas.addPaintListener( new PaintListener() { + public void paintControl( PaintEvent paintevent ) { + Rectangle rectangle = canvas.getClientArea(); + boolean glok=false; + if( GLContext.CONTEXT_NOT_CURRENT < glcontext.makeCurrent() ) { + glok=true; + GL2 gl = glcontext.getGL().getGL2(); + if(sizeMissing[0]) { + OneTriangle.setup( gl, rectangle ); + sizeMissing[0] = false; + } + OneTriangle.render( gl, rectangle ); + drawable.swapBuffers(); + glcontext.release(); + } + System.err.println("paint: glok " + glok); + } + }); + + shell.setText( getClass().getName() ); + shell.setSize( 640, 480 ); + shell.open(); + + long lStartTime = System.currentTimeMillis(); + long lEndTime = lStartTime + duration; + try { + while( (System.currentTimeMillis() < lEndTime) && !canvas.isDisposed() ) { + if( !display.readAndDispatch() ) { + // blocks on linux .. display.sleep(); + Thread.sleep(10); + } + } + } catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + glcontext.destroy(); + drawable.setRealized(false); + canvas.dispose(); + } + + @Test + public void testA01GLDefault() throws InterruptedException { + GLProfile glprofile = GLProfile.getDefault(); + System.out.println( "GLProfile Default: " + glprofile ); + runTestAGL( glprofile ); + } + + @Test + public void test02GL2() throws InterruptedException { + GLProfile glprofile = GLProfile.get(GLProfile.GL2); + System.out.println( "GLProfile GL2: " + glprofile ); + runTestAGL( glprofile ); + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + duration = atoi(args[++i]); + } + } + System.out.println("durationPerTest: "+duration); + org.junit.runner.JUnitCore.main(TestSWT02GLn.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java new file mode 100644 index 000000000..25653ab21 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java @@ -0,0 +1,184 @@ +/**
+ * 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.jogl.swt;
+
+import java.awt.Frame;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.awt.SWT_AWT;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+/**
+ * Tests that a basic SWT app can open without crashing under different GL profiles. Uses the AWT GL canvas with
+ * the SWT_AWT bridge.
+ * @author Wade Walker
+ */
+public class TestSWTAWT01GLn extends UITestCase {
+
+ static final int duration = 250;
+
+ Display display = null;
+ Shell shell = null;
+ Composite composite = null;
+ Frame frame = null;
+ GLCanvas glcanvas = null;
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton( true );
+ System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
+ }
+
+ @Before
+ public void init() {
+ display = new Display();
+ Assert.assertNotNull( display );
+ shell = new Shell( display );
+ Assert.assertNotNull( shell );
+ shell.setLayout( new FillLayout() );
+ composite = new Composite( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
+ composite.setLayout( new FillLayout() );
+ Assert.assertNotNull( composite );
+ frame = SWT_AWT.new_Frame( composite );
+ Assert.assertNotNull( frame );
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull( display );
+ Assert.assertNotNull( shell );
+ Assert.assertNotNull( composite );
+ Assert.assertNotNull( glcanvas );
+ try {
+ frame.setVisible( false );
+ frame.remove( glcanvas );
+ frame.dispose();
+ composite.dispose();
+ shell.dispose();
+ display.dispose();
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ display = null;
+ shell = null;
+ composite = null;
+ frame = null;
+ glcanvas = null;
+ }
+
+ protected void runTestGL( GLProfile glprofile ) throws InterruptedException {
+ GLCapabilities glcapabilities = new GLCapabilities( glprofile );
+ glcanvas = new GLCanvas( glcapabilities );
+ Assert.assertNotNull( glcanvas );
+ frame.add( glcanvas );
+
+ glcanvas.addGLEventListener( new GLEventListener() {
+ /* @Override */
+ public void init( GLAutoDrawable glautodrawable ) {
+ }
+
+ /* @Override */
+ public void dispose( GLAutoDrawable glautodrawable ) {
+ }
+
+ /* @Override */
+ public void display( GLAutoDrawable glautodrawable ) {
+ Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() );
+ GL2 gl = glautodrawable.getGL().getGL2();
+ OneTriangle.render( gl, rectangle );
+ }
+
+ /* @Override */
+ public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {
+ Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() );
+ GL2 gl = glautodrawable.getGL().getGL2();
+ OneTriangle.setup( gl, rectangle );
+ }
+ });
+
+ shell.setText( getClass().getName() );
+ shell.setSize( 640, 480 );
+ shell.open();
+
+ long lStartTime = System.currentTimeMillis();
+ long lEndTime = lStartTime + duration;
+ try {
+ while( (System.currentTimeMillis() < lEndTime) && !composite.isDisposed() ) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+
+ @Test
+ public void test01GLDefault() throws InterruptedException {
+ GLProfile glprofile = GLProfile.getDefault();
+ System.out.println( "GLProfile Default: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ @Test
+ public void test02GL2() throws InterruptedException {
+ GLProfile glprofile = GLProfile.get(GLProfile.GL2);
+ System.out.println( "GLProfile GL2: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main( TestSWTAWT01GLn.class.getName() );
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java new file mode 100644 index 000000000..82cd91718 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java @@ -0,0 +1,143 @@ +/** + * 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.jogl.texture; + +import com.jogamp.opengl.test.junit.jogl.util.texture.gl2.TextureGL2ListenerDraw1; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.Animator; + +import java.awt.Frame; + +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Assert; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Unit test for bug 417, which shows a GLException when reading a grayscale texture. + * Couldn't duplicate the failure, so it must have been fixed unknowingly sometime + * after the bug was submitted. + * @author Wade Walker + */ +public class TestGrayTextureFromFileAWTBug417 extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + InputStream textureStream; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.get(GLProfile.GL2GL3); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + @Before + public void initTest() { + textureStream = TestGrayTextureFromFileAWTBug417.class.getResourceAsStream( "grayscale_texture.png" ); + Assert.assertNotNull(textureStream); + } + + @After + public void cleanupTest() { + textureStream=null; + } + + @Test + public void test1() throws InterruptedException { + GLCanvas glCanvas = new GLCanvas(caps); + + Frame frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); + frame.add(glCanvas); + frame.setSize( 256, 128 ); + + // load texture from file inside current GL context to match the way + // the bug submitter was doing it + glCanvas.addGLEventListener(new TextureGL2ListenerDraw1( null ) { + @Override + public void init(GLAutoDrawable drawable) { + try { + setTexture( TextureIO.newTexture( textureStream, true, TextureIO.PNG ) ); + } + catch(GLException glexception) { + glexception.printStackTrace(); + Assume.assumeNoException(glexception); + } + catch(IOException ioexception) { + ioexception.printStackTrace(); + Assume.assumeNoException(ioexception); + } + } + }); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + frame.setVisible(false); + frame.remove(glCanvas); + glCanvas=null; + Assert.assertNotNull(frame); + frame.dispose(); + frame=null; + } + + public static void main(String args[]) throws IOException { + String tstname = TestGrayTextureFromFileAWTBug417.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java new file mode 100644 index 000000000..bd83799d4 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java @@ -0,0 +1,146 @@ +/** + * 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.jogl.texture; + +import com.jogamp.opengl.test.junit.jogl.util.texture.gl2.TextureGL2ListenerDraw1; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.awt.AWTTextureIO; +import com.jogamp.opengl.util.Animator; + +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Frame; +import java.awt.GradientPaint; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +import java.io.IOException; +import org.junit.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestTexture01AWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + BufferedImage textureImage; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.get(GLProfile.GL2GL3); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + @Before + public void initTest() { + // create base image + BufferedImage baseImage = new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR); + Assert.assertNotNull(baseImage); + Graphics2D g = baseImage.createGraphics(); + Assert.assertNotNull(g); + g.setPaint(new GradientPaint(0, 0, Color.CYAN, + baseImage.getWidth(), baseImage.getHeight(), Color.BLUE)); + g.fillRect(0, 0, baseImage.getWidth(), baseImage.getHeight()); + g.dispose(); + + // create texture image + int imageType = BufferedImage.TYPE_3BYTE_BGR; + textureImage = new BufferedImage(baseImage.getWidth(), + baseImage.getHeight(), + imageType); + Assert.assertNotNull(textureImage); + g = textureImage.createGraphics(); + g.setComposite(AlphaComposite.Src); + g.drawImage(baseImage, 0, 0, null); + g.dispose(); + + baseImage.flush(); + baseImage=null; + } + + @After + public void cleanupTest() { + Assert.assertNotNull(textureImage); + textureImage.flush(); + textureImage=null; + } + + @Test + public void test1() throws InterruptedException { + GLCanvas glCanvas = new GLCanvas(caps); + + Frame frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); + frame.add(glCanvas); + frame.setSize(512, 512); + + // create texture + TextureData textureData = AWTTextureIO.newTextureData(caps.getGLProfile(), textureImage, false); + glCanvas.addGLEventListener(new TextureGL2ListenerDraw1(textureData)); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + frame.setVisible(false); + frame.remove(glCanvas); + glCanvas=null; + Assert.assertNotNull(frame); + frame.dispose(); + frame=null; + } + + public static void main(String args[]) throws IOException { + String tstname = TestTexture01AWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png b/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png Binary files differnew file mode 100755 index 000000000..dac0f13de --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java new file mode 100644 index 000000000..649a3b19a --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java @@ -0,0 +1,112 @@ +/** + * 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.jogl.util.texture.gl2; + +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.glu.GLU; + +public class TextureGL2ListenerDraw1 implements GLEventListener { + private GLU glu = new GLU(); + private TextureData textureData; + private Texture texture; + + public TextureGL2ListenerDraw1(TextureData td) { + this.textureData = td; + } + + public void init(GLAutoDrawable drawable) { + if(null!=textureData) { + this.texture = TextureIO.newTexture(textureData); + } + } + + public void setTexture( Texture texture ) { + this.texture = texture; + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2 gl = drawable.getGL().getGL2(); + gl.glMatrixMode(GL2ES1.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluOrtho2D(0, 1, 0, 1); + gl.glMatrixMode(GL2ES1.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + if(null!=texture) { + texture.disable(); + texture.destroy(gl); + } + if(null!=textureData) { + textureData.destroy(); + } + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + + // need a valid GL context for this .. + + /** OpenGL .. + texture.updateSubImage(textureData, 0, + 20, 20, + 20, 20, + 100, 100); */ + + + // Now draw one quad with the texture + if(null!=texture) { + texture.enable(); + texture.bind(); + gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); + TextureCoords coords = texture.getImageTexCoords(); + gl.glBegin(GL2.GL_QUADS); + gl.glTexCoord2f(coords.left(), coords.bottom()); + gl.glVertex3f(0, 0, 0); + gl.glTexCoord2f(coords.right(), coords.bottom()); + gl.glVertex3f(1, 0, 0); + gl.glTexCoord2f(coords.right(), coords.top()); + gl.glVertex3f(1, 1, 0); + gl.glTexCoord2f(coords.left(), coords.top()); + gl.glVertex3f(0, 1, 0); + gl.glEnd(); + texture.disable(); + } + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java new file mode 100644 index 000000000..69f9da052 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java @@ -0,0 +1,122 @@ +/** + * 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.newt; + +import org.junit.Test; +import org.junit.Assert; + +import java.lang.reflect.InvocationTargetException; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.util.Point; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import com.jogamp.newt.Window; +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestCloseNewtAWT extends UITestCase { + + GLWindow newtWindow = null; + NewtCanvasAWT newtCanvas = null; + JFrame frame = null; + + class MyCanvas extends NewtCanvasAWT { + public MyCanvas(Window window) { + super(window); + } + + public void addNotify() { + System.err.println("MyCanvas START add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + super.addNotify(); + System.err.println("MyCanvas END add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + } + + public void removeNotify() { + System.err.println("MyCanvas START remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + + // trigger critical situation around the AWT TreeLock + newtWindow.runOnEDTIfAvail(true, new Runnable() { + public void run() { + // NEWT EDT while AWT is locked + System.err.println("MyCanvas On NEWT-EDT From AWT-EDT: "+Thread.currentThread()+ + ", holds AWTTreeLock: "+Thread.holdsLock(MyCanvas.this.getTreeLock())); + + // Critical: Within NEWT EDT, while AWT is locked + NativeWindow nw = MyCanvas.this.getNativeWindow(); + if(null != nw) { + Point p = nw.getLocationOnScreen(null); + System.err.println("MyCanvas On NEWT-EDT: position: "+p); + } else { + System.err.println("MyCanvas On NEWT-EDT: position n/a, null NativeWindow"); + } + } + }); + System.err.println("MyCanvas passed critical: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + + super.removeNotify(); + + System.err.println("MyCanvas END remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + } + } + + @Test + public void testCloseNewtAWT() throws InterruptedException, InvocationTargetException { + newtWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); + newtCanvas = new MyCanvas(newtWindow); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame = new JFrame("NEWT Close Test"); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.getContentPane().add(newtCanvas); + frame.pack(); + frame.setSize(800, 600); + frame.setVisible(true); + } + }); + Thread.sleep(1000); + + Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true)); + + GLProfile.shutdown(); + } + + public static void main(String[] args) { + String tstname = TestCloseNewtAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java new file mode 100644 index 000000000..9343e2dd8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java @@ -0,0 +1,264 @@ +/** + * 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.newt; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; + +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestDisplayLifecycle01NEWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + static long durationPerTest = 100; // ms + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + caps = new GLCapabilities(glp); + } + + static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height) + throws InterruptedException + { + Assert.assertNotNull(caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + GLWindow glWindow; + if(null!=screen) { + Window window = NewtFactory.createWindow(screen, caps); + Assert.assertNotNull(window); + glWindow = GLWindow.create(window); + } else { + glWindow = GLWindow.create(caps); + } + + GLEventListener demo = new Gears(); + setDemoFields(demo, glWindow); + glWindow.addGLEventListener(demo); + glWindow.addWindowListener(new TraceWindowAdapter()); + glWindow.setSize(width, height); + return glWindow; + } + + private void testDisplayCreate01(Display display, Screen screen) throws InterruptedException { + // start-state == end-state + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + + // Create Window, pending lazy native creation + GLWindow window = createWindow(screen, caps, width, height); + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + + Assert.assertNotNull(window.getScreen()); + Assert.assertEquals(true,window.isValid()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + // lazy native creation sequence: Display, Screen and Window + Assert.assertEquals(0, window.getTotalFrames()); + window.setVisible(true); + + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); + + while(window.getDuration()<1*durationPerTest) { + window.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window.getDuration()); + + // just make the Window invisible + window.setVisible(false); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + // just make the Window visible again + window.resetCounter(); + Assert.assertEquals(0, window.getTotalFrames()); + window.setVisible(true); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); + + while(window.getDuration()<2*durationPerTest) { + window.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window.getDuration()); + + // destruction .. + window.destroy(); + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(true, window.isValid()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + window.resetCounter(); + Assert.assertEquals(0, window.getTotalFrames()); + + // a display call shall not change a thing + window.display(); + Assert.assertEquals(0, window.getTotalFrames()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + // recover Window + window.setVisible(true); + + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); + + while(window.getDuration()<1*durationPerTest) { + window.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window.getDuration()); + + // destruction .. + window.destroy(); + display.dumpDisplayList("Post destroy(true)"); + + // end-state == start-state + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + + Assert.assertNotNull(window.getScreen()); + Assert.assertEquals(true,window.isValid()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + } + + @Test + public void testDisplayCreate01_AutoDestroyLifecycle() throws InterruptedException { + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + // Create Display/Screen, pending lazy native creation + Display display = NewtFactory.createDisplay(null); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + testDisplayCreate01(display, screen); + testDisplayCreate01(display, screen); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + System.err.println("durationPerTest: "+durationPerTest); + String tstname = TestDisplayLifecycle01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java new file mode 100644 index 000000000..d17c5f025 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java @@ -0,0 +1,386 @@ +/** + * 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.newt; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.nativewindow.*; +import javax.media.opengl.*; + +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestDisplayLifecycle02NEWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + static long durationPerTest = 100; // ms + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + caps = new GLCapabilities(glp); + } + + static GLWindow createWindow(GLCapabilities caps, int width, int height) + throws InterruptedException + { + Assert.assertNotNull(caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + GLWindow glWindow = GLWindow.create(caps); + + GLEventListener demo = new Gears(); + setDemoFields(demo, glWindow); + glWindow.addGLEventListener(demo); + glWindow.addWindowListener(new TraceWindowAdapter()); + glWindow.setSize(width, height); + return glWindow; + } + + private void testDisplayCreate01Impl() throws InterruptedException { + // start-state == end-state + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + // Create Window, pending lazy native creation + GLWindow window = createWindow(caps, width, height); + Screen screen = window.getScreen(); + Display display = screen.getDisplay(); + + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,Screen.getActiveScreenNumber()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + // lazy native creation sequence: Display, Screen and Window + Assert.assertEquals(0, window.getTotalFrames()); + window.setVisible(true); + + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,Screen.getActiveScreenNumber()); + Assert.assertEquals(1,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); + + while(window.getDuration()<1*durationPerTest) { + window.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window.getDuration()); + + // just make the Window invisible + window.setVisible(false); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + // just make the Window visible again + window.resetCounter(); + Assert.assertEquals(0, window.getTotalFrames()); + window.setVisible(true); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); + + while(window.getDuration()<2*durationPerTest) { + window.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window.getDuration()); + + // destruction.. ref count down, but keep all + window.destroy(); + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,Screen.getActiveScreenNumber()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertNotNull(window.getScreen()); + Assert.assertEquals(true,window.isValid()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.resetCounter(); + Assert.assertEquals(0, window.getTotalFrames()); + + // a display call shall not change a thing + window.display(); + Assert.assertEquals(0, window.getTotalFrames()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + // recover Window + window.setVisible(true); + + Assert.assertEquals(screen,window.getScreen()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,window.isValid()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,Screen.getActiveScreenNumber()); + Assert.assertEquals(1,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); + + while(window.getDuration()<1*durationPerTest) { + window.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window.getDuration()); + + // destruction + invalidate, ie Display/Screen will be unreferenced + window.invalidate(); + Assert.assertNull(window.getScreen()); + Assert.assertEquals(false,window.isValid()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + display.dumpDisplayList("Post destroy(true)"); + + // end-state == start-state + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,Screen.getActiveScreenNumber()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + } + + @Test + public void testDisplayCreate01() throws InterruptedException { + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + // Create Display/Screen, pending lazy native creation + testDisplayCreate01Impl(); + testDisplayCreate01Impl(); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + } + + private void testDisplayCreate02Impl() throws InterruptedException { + // start-state == end-state + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + // Create Window, pending lazy native creation + GLWindow window1 = createWindow(caps, width, height); + window1.setPosition(0, 0); + Screen screen = window1.getScreen(); + Display display = screen.getDisplay(); + + GLWindow window2 = createWindow(caps, width, height); + Assert.assertSame(screen, window2.getScreen()); + Assert.assertSame(display, window2.getScreen().getDisplay()); + window2.setPosition(screen.getWidth()-width, 0); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,Screen.getActiveScreenNumber()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,window1.isNativeValid()); + Assert.assertEquals(false,window1.isVisible()); + Assert.assertEquals(false,window2.isNativeValid()); + Assert.assertEquals(false,window2.isVisible()); + + // lazy native creation sequence: Display, Screen and Window + Assert.assertEquals(0, window1.getTotalFrames()); + window1.setVisible(true); + + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,Screen.getActiveScreenNumber()); + Assert.assertEquals(1,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window1.isNativeValid()); + Assert.assertEquals(true,window1.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window1.getTotalFrames()); + Assert.assertTrue(0 < window1.getTotalFrames()); + + Assert.assertEquals(0, window2.getTotalFrames()); + window2.setVisible(true); + + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,Screen.getActiveScreenNumber()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window2.isNativeValid()); + Assert.assertEquals(true,window2.isVisible()); + System.err.println("Frames for setVisible(true) 2: "+window2.getTotalFrames()); + Assert.assertTrue(0 < window2.getTotalFrames()); + + while(window1.getDuration()<1*durationPerTest) { + window1.display(); + Thread.sleep(100); + } + System.err.println("duration: "+window1.getDuration()); + + // just make the Window invisible + window1.setVisible(false); + Assert.assertEquals(true,window1.isNativeValid()); + Assert.assertEquals(false,window1.isVisible()); + + // destruction ... + window1.destroy(); + Assert.assertNotNull(window1.getScreen()); + Assert.assertEquals(true,window1.isValid()); + Assert.assertEquals(false,window1.isNativeValid()); + Assert.assertEquals(false,window1.isVisible()); + + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,Screen.getActiveScreenNumber()); + Assert.assertEquals(1,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + + // destruction + window2.destroy(); + Assert.assertNotNull(window2.getScreen()); + Assert.assertEquals(true,window2.isValid()); + Assert.assertEquals(false,window2.isNativeValid()); + Assert.assertEquals(false,window2.isVisible()); + + // end-state == start-state + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,Screen.getActiveScreenNumber()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + + // invalidate .. remove all refs + window1.invalidate(); + Assert.assertNull(window1.getScreen()); + Assert.assertEquals(false,window1.isValid()); + Assert.assertEquals(false,window1.isNativeValid()); + Assert.assertEquals(false,window1.isVisible()); + + // invalidate .. remove all refs + window2.invalidate(); + Assert.assertNull(window2.getScreen()); + Assert.assertEquals(false,window2.isValid()); + Assert.assertEquals(false,window2.isNativeValid()); + Assert.assertEquals(false,window2.isVisible()); + + } + + @Test + public void testDisplayCreate02() throws InterruptedException { + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + // Create Display/Screen, pending lazy native creation + testDisplayCreate02Impl(); + testDisplayCreate02Impl(); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + System.err.println("durationPerTest: "+durationPerTest); + String tstname = TestDisplayLifecycle02NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java b/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java new file mode 100644 index 000000000..67dd2a33c --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java @@ -0,0 +1,110 @@ +/** + * 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.newt; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import java.io.IOException; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; + +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.*; + +/** + * This simple program will throw a {@link RuntimeException} when the application is closed. + */ +public class TestEventSourceNotAWTBug extends UITestCase { + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + } + + @Test + public void testEventSourceNotNewtBug() throws InterruptedException { + JFrame jf = new JFrame(); + + jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + + final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + final GLWindow glWindow = GLWindow.create(caps); + final NewtCanvasAWT canvas = new NewtCanvasAWT(glWindow); + jf.getContentPane().add(canvas); + + // The following line isn't event necessary to see the problem. + glWindow.addGLEventListener(new Gears()); + + final JFrame f_jf = jf; + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + f_jf.setSize(800, 600); + f_jf.setVisible(true); + } + }); + + Thread.sleep(500); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + f_jf.dispose(); + } + }); + glWindow.invalidate(); + } + + public static void main(String args[]) throws IOException { + String tstname = TestEventSourceNotAWTBug.class.getName(); + /* + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */ + org.junit.runner.JUnitCore.main(tstname); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java new file mode 100644 index 000000000..047df5cf7 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java @@ -0,0 +1,201 @@ +/** + * 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.newt; + +import org.junit.Assert; +import org.junit.AfterClass; + +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Robot; +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import javax.swing.JFrame; + +import java.util.ArrayList; +import java.io.IOException; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; + +import com.jogamp.opengl.test.junit.util.*; + +public class TestFocus01SwingAWTRobot extends UITestCase { + static int width, height; + static long durationPerTest = 800; + static long awtWaitTimeout = 1000; + + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glCaps = new GLCapabilities(null); + } + + @AfterClass + public static void release() { + } + + @Test + public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException { + testFocus01ProgrFocusImpl(null); + } + + @Test + public void testFocus02RobotFocus() throws AWTException, InterruptedException, InvocationTargetException { + Robot robot = new Robot(); + robot.setAutoWaitForIdle(true); + testFocus01ProgrFocusImpl(robot); + } + + private void testFocus01ProgrFocusImpl(Robot robot) throws AWTException, + InvocationTargetException, InterruptedException { + ArrayList eventCountAdapters = new ArrayList(); + + // Create a window. + GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.setTitle("testNewtChildFocus"); + GLEventListener demo1 = new RedSquare(); + TestListenerCom01AWT.setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1"); + eventCountAdapters.add(glWindow1FA); + glWindow1.addWindowListener(glWindow1FA); + + // Monitor NEWT focus and keyboard events. + NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1"); + eventCountAdapters.add(glWindow1KA); + glWindow1.addKeyListener(glWindow1KA); + + // Wrap the window in a canvas. + final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + + // Monitor AWT focus and keyboard events. + AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT"); + newtCanvasAWT.addKeyListener(newtCanvasAWTKA); + eventCountAdapters.add(newtCanvasAWTKA); + AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT"); + newtCanvasAWT.addFocusListener(newtCanvasAWTFA); + eventCountAdapters.add(newtCanvasAWTFA); + + // Add the canvas to a frame, and make it all visible. + JFrame frame1 = new JFrame("Swing AWT Parent Frame: " + + glWindow1.getTitle()); + frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER); + Button button = new Button("Click me .."); + AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button"); + button.addFocusListener(buttonFA); + eventCountAdapters.add(buttonFA); + AWTKeyAdapter buttonKA = new AWTKeyAdapter("Button"); + button.addKeyListener(buttonKA); + eventCountAdapters.add(buttonKA); + frame1.getContentPane().add(button, BorderLayout.NORTH); + frame1.setSize(width, height); + frame1.setVisible(true); + Assert.assertTrue(AWTRobotUtil.toFront(robot, frame1)); + + int wait=0; + while(wait<awtWaitTimeout/100 && glWindow1.getTotalFrames()<1) { Thread.sleep(awtWaitTimeout/10); wait++; } + System.err.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames()); + Assert.assertTrue(glWindow1.isVisible()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + + // Continuous animation .. + Animator animator = new Animator(glWindow1); + animator.start(); + + // Button Focus + Thread.sleep(100); // allow event sync + System.err.println("FOCUS AWT Button request"); + EventCountAdapterUtil.reset(eventCountAdapters); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, button, button, buttonFA, null)); + Assert.assertEquals(1, buttonFA.getCount()); + Assert.assertEquals(0, glWindow1FA.getCount()); + Assert.assertEquals(0, newtCanvasAWTFA.getCount()); + System.err.println("FOCUS AWT Button sync"); + Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, button, buttonKA)); + + // Request the AWT focus, which should automatically provide the NEWT window with focus. + Thread.sleep(100); // allow event sync + System.err.println("FOCUS NEWT Canvas/GLWindow request"); + EventCountAdapterUtil.reset(eventCountAdapters); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonFA)); + Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA)); + Assert.assertEquals(1, glWindow1FA.getCount()); + Assert.assertEquals(0, newtCanvasAWTFA.getCount()); + Assert.assertEquals(-1, buttonFA.getCount()); // lost focus + System.err.println("FOCUS NEWT Canvas/GLWindow sync"); + Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA)); + Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount()); + + // Remove listeners to avoid logging during dispose/destroy. + glWindow1.removeKeyListener(glWindow1KA); + glWindow1.removeWindowListener(glWindow1FA); + newtCanvasAWT.removeKeyListener(newtCanvasAWTKA); + newtCanvasAWT.removeFocusListener(newtCanvasAWTFA); + + // Shutdown the test. + animator.stop(); + frame1.dispose(); + glWindow1.invalidate(); + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + System.out.println("durationPerTest: "+durationPerTest); + String tstname = TestFocus01SwingAWTRobot.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java new file mode 100644 index 000000000..15e4c3ad8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java @@ -0,0 +1,301 @@ +/** + * 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.newt; + +import java.lang.reflect.*; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +import java.awt.AWTException; +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Robot; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import java.util.ArrayList; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestFocus02SwingAWTRobot extends UITestCase { + static int width, height; + static long durationPerTest = 800; + static long awtWaitTimeout = 1000; + static long waitReparent = 0; + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() throws AWTException { + width = 640; + height = 480; + + JFrame f = new JFrame(); + f.setSize(100,100); + f.setVisible(true); + f.dispose(); + f=null; + + GLProfile.initSingleton(false); + glCaps = new GLCapabilities(null); + } + + @AfterClass + public static void release() { + } + + private void testFocus01ProgrFocusImpl(Robot robot) + throws AWTException, InterruptedException, InvocationTargetException { + int x = 0; + int y = 0; + + ArrayList eventCountAdapters = new ArrayList(); + + /** + * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow + */ + GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + GLEventListener demo1 = new Gears(); + glWindow1.addGLEventListener(demo1); + NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1"); + glWindow1.addWindowListener(glWindow1FA); + eventCountAdapters.add(glWindow1FA); + NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1"); + glWindow1.addKeyListener(glWindow1KA); + eventCountAdapters.add(glWindow1KA); + NEWTMouseAdapter glWindow1MA = new NEWTMouseAdapter("GLWindow1"); + glWindow1.addMouseListener(glWindow1MA); + eventCountAdapters.add(glWindow1MA); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT"); + newtCanvasAWT.addFocusListener(newtCanvasAWTFA); + eventCountAdapters.add(newtCanvasAWTFA); + AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT"); + newtCanvasAWT.addKeyListener(newtCanvasAWTKA); + eventCountAdapters.add(newtCanvasAWTKA); + AWTMouseAdapter newtCanvasAWTMA = new AWTMouseAdapter("NewtCanvasAWT"); + newtCanvasAWT.addMouseListener(newtCanvasAWTMA); + eventCountAdapters.add(newtCanvasAWTMA); + + Button buttonNorthInner = new Button("north"); + AWTFocusAdapter buttonNorthInnerFA = new AWTFocusAdapter("ButtonNorthInner"); + buttonNorthInner.addFocusListener(buttonNorthInnerFA); + eventCountAdapters.add(buttonNorthInnerFA); + AWTKeyAdapter buttonNorthInnerKA = new AWTKeyAdapter("ButtonNorthInner"); + buttonNorthInner.addKeyListener(buttonNorthInnerKA); + eventCountAdapters.add(buttonNorthInnerKA); + AWTMouseAdapter buttonNorthInnerMA = new AWTMouseAdapter("ButtonNorthInner"); + buttonNorthInner.addMouseListener(buttonNorthInnerMA); + eventCountAdapters.add(buttonNorthInnerMA); + Container container1 = new Container(); + container1.setLayout(new BorderLayout()); + container1.add(buttonNorthInner, BorderLayout.NORTH); + container1.add(new Button("south"), BorderLayout.SOUTH); + container1.add(new Button("east"), BorderLayout.EAST); + container1.add(new Button("west"), BorderLayout.WEST); + container1.add(newtCanvasAWT, BorderLayout.CENTER); + + Button buttonNorthOuter = new Button("north"); + AWTFocusAdapter buttonNorthOuterFA = new AWTFocusAdapter("ButtonNorthOuter"); + buttonNorthOuter.addFocusListener(buttonNorthOuterFA); + eventCountAdapters.add(buttonNorthOuterFA); + AWTKeyAdapter buttonNorthOuterKA = new AWTKeyAdapter("ButtonNorthOuter"); + buttonNorthOuter.addKeyListener(buttonNorthOuterKA); + eventCountAdapters.add(buttonNorthOuterKA); + AWTMouseAdapter buttonNorthOuterMA = new AWTMouseAdapter("ButtonNorthOuter"); + buttonNorthOuter.addMouseListener(buttonNorthOuterMA); + eventCountAdapters.add(buttonNorthOuterMA); + JPanel jPanel1 = new JPanel(); + jPanel1.setLayout(new BorderLayout()); + jPanel1.add(buttonNorthOuter, BorderLayout.NORTH); + jPanel1.add(new Button("south"), BorderLayout.SOUTH); + jPanel1.add(new Button("east"), BorderLayout.EAST); + jPanel1.add(new Button("west"), BorderLayout.WEST); + jPanel1.add(container1, BorderLayout.CENTER); + + JFrame jFrame1 = new JFrame("Swing Parent JFrame"); + AWTFocusAdapter jFrame1FA = new AWTFocusAdapter("JFrame1"); + jFrame1.addFocusListener(jFrame1FA); + // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event! + jFrame1.setContentPane(jPanel1); + jFrame1.setSize(width, height); + jFrame1.setVisible(true); // from here on, we need to run modifications on EDT + Assert.assertTrue(AWTRobotUtil.toFront(robot, jFrame1)); + + int wait=0; + while(wait<awtWaitTimeout/100 && glWindow1.getTotalFrames()<1) { Thread.sleep(awtWaitTimeout/10); wait++; } + System.err.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames()); + Assert.assertTrue(glWindow1.isVisible()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + + // Continuous animation .. + Animator animator1 = new Animator(glWindow1); + animator1.start(); + + // Button Outer Focus + Thread.sleep(100); // allow event sync + System.err.println("FOCUS AWT Button Outer request"); + EventCountAdapterUtil.reset(eventCountAdapters); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter, buttonNorthOuterFA, null)); + Assert.assertEquals(1, buttonNorthOuterFA.getCount()); + Assert.assertEquals(0, glWindow1FA.getCount()); + Assert.assertEquals(0, newtCanvasAWTFA.getCount()); + Assert.assertEquals(0, buttonNorthInnerFA.getCount()); + Assert.assertEquals(0, jFrame1FA.getCount()); + System.err.println("FOCUS AWT Button Outer sync"); + Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, buttonNorthOuter, buttonNorthOuterKA)); + Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, + buttonNorthOuter, buttonNorthOuterMA)); + Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, + buttonNorthOuter, buttonNorthOuterMA)); + + // NEWT Focus + Thread.sleep(100); // allow event sync + System.err.println("FOCUS NEWT Canvas/GLWindow request"); + EventCountAdapterUtil.reset(eventCountAdapters); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthOuterFA)); + Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA)); + Assert.assertEquals(1, glWindow1FA.getCount()); + Assert.assertEquals(0, newtCanvasAWTFA.getCount()); + Assert.assertEquals(0, buttonNorthInnerFA.getCount()); + Assert.assertEquals(-1, buttonNorthOuterFA.getCount()); // lost focus + Assert.assertEquals(0, jFrame1FA.getCount()); + System.err.println("FOCUS NEWT Canvas/GLWindow sync"); + Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA)); + Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount()); + Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, + glWindow1, glWindow1MA)); + Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, + glWindow1, glWindow1MA)); + Assert.assertEquals("AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount()); + + // Button Inner Focus + Thread.sleep(100); // allow event sync + System.err.println("FOCUS AWT Button request"); + EventCountAdapterUtil.reset(eventCountAdapters); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthInner, buttonNorthInner, buttonNorthInnerFA, glWindow1FA)); + Assert.assertEquals(1, buttonNorthInnerFA.getCount()); + Assert.assertEquals(-1, glWindow1FA.getCount()); // lost focus + Assert.assertEquals(0, newtCanvasAWTFA.getCount()); + Assert.assertEquals(0, buttonNorthOuterFA.getCount()); + Assert.assertEquals(0, jFrame1FA.getCount()); + System.err.println("FOCUS AWT Button sync"); + Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, buttonNorthInner, buttonNorthInnerKA)); + Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, + buttonNorthInner, buttonNorthInnerMA)); + Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, + buttonNorthInner, buttonNorthInnerMA)); + + // NEWT Focus + Thread.sleep(100); // allow event sync + System.err.println("FOCUS NEWT Canvas/GLWindow request"); + EventCountAdapterUtil.reset(eventCountAdapters); + Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthInnerFA)); + Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA)); + Assert.assertEquals(1, glWindow1FA.getCount()); + Assert.assertEquals(0, newtCanvasAWTFA.getCount()); + Assert.assertEquals(-1, buttonNorthInnerFA.getCount()); // lost focus + Assert.assertEquals(0, buttonNorthOuterFA.getCount()); + Assert.assertEquals(0, jFrame1FA.getCount()); + System.err.println("FOCUS NEWT Canvas/GLWindow sync"); + Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA)); + Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount()); + Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1, + glWindow1, glWindow1MA)); + Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2, + glWindow1, glWindow1MA)); + Assert.assertEquals("AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount()); + + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + + final JFrame _jFrame1 = jFrame1; + final JPanel _jPanel1 = jPanel1; + final Container _container1 = container1; + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _jFrame1.setVisible(false); + _jPanel1.remove(_container1); + _jFrame1.dispose(); + } }); + + glWindow1.invalidate(); + } + + @Test + public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException { + testFocus01ProgrFocusImpl(null); + } + + @Test + public void testFocus02RobotFocus() throws AWTException, InterruptedException, InvocationTargetException { + Robot robot = new Robot(); + robot.setAutoWaitForIdle(true); + testFocus01ProgrFocusImpl(robot); + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } else if(args[i].equals("-wait")) { + waitReparent = atoi(args[++i]); + } + } + System.err.println("durationPerTest "+durationPerTest); + System.err.println("waitReparent "+waitReparent); + String tstname = TestFocus02SwingAWTRobot.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java new file mode 100644 index 000000000..f9571574e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java @@ -0,0 +1,133 @@ +/** + * 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.newt; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.opengl.*; + +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import javax.media.nativewindow.AbstractGraphicsDevice; + +public class TestGLWindows00NEWT extends UITestCase { + static GLProfile glp; + static int width, height; + static long durationPerTest = 100; // ms + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + // GLProfile.initSingleton(false); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(Screen screen, GLCapabilitiesImmutable caps) + throws InterruptedException + { + Assert.assertNotNull(caps); + // + // Create native windowing resources .. X11/Win/OSX + // + GLWindow glWindow; + if(null!=screen) { + glWindow = GLWindow.create(screen, caps); + Assert.assertNotNull(glWindow); + } else { + glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + } + + GLEventListener demo = new Gears(); + glWindow.addGLEventListener(demo); + + glWindow.setSize(512, 512); + glWindow.setVisible(true); + Assert.assertEquals(true,glWindow.isVisible()); + Assert.assertEquals(true,glWindow.isNativeValid()); + + return glWindow; + } + + static void destroyWindow(GLWindow glWindow) { + if(null!=glWindow) { + glWindow.invalidate(); + Assert.assertEquals(false,glWindow.isNativeValid()); + Assert.assertEquals(false,glWindow.isValid()); + } + } + + @Test + public void testWindow00() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window1 = createWindow(null, caps); // local + Assert.assertEquals(true,window1.isNativeValid()); + Assert.assertEquals(true,window1.isVisible()); + AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice(); + + System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1)); + + for(int state=0; state*100<durationPerTest; state++) { + Thread.sleep(100); + } + + destroyWindow(window1); + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + System.out.println("durationPerTest: "+durationPerTest); + String tstname = TestGLWindows00NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java new file mode 100644 index 000000000..5be97714d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java @@ -0,0 +1,384 @@ +/** + * 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.newt; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.opengl.*; + +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestGLWindows01NEWT extends UITestCase { + static GLProfile glp; + static int width, height; + static long durationPerTest = 100; // ms + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + // GLProfile.initSingleton(false); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(Screen screen, GLCapabilities caps, + int width, int height, boolean onscreen, boolean undecorated, + boolean addGLEventListenerAfterVisible) + throws InterruptedException + { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + // System.out.println("Requested: "+caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + GLWindow glWindow; + if(null!=screen) { + glWindow = GLWindow.create(screen, caps); + Assert.assertNotNull(glWindow); + } else { + glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + } + + glWindow.setUndecorated(onscreen && undecorated); + Assert.assertEquals(false,glWindow.isVisible()); + Assert.assertEquals(false,glWindow.isNativeValid()); + + GLEventListener demo = new Gears(); + setDemoFields(demo, glWindow); + if(!addGLEventListenerAfterVisible) { + glWindow.addGLEventListener(demo); + } + glWindow.addWindowListener(new TraceWindowAdapter()); + + glWindow.setSize(width, height); + + Assert.assertEquals(0, glWindow.getTotalFrames()); + glWindow.setVisible(true); + Assert.assertEquals(true,glWindow.isVisible()); + Assert.assertEquals(true,glWindow.isNativeValid()); + System.out.println("Frames for initial setVisible(true): "+glWindow.getTotalFrames()); + Assert.assertTrue(0 < glWindow.getTotalFrames()); + + // + // Create native OpenGL resources .. XGL/WGL/CGL .. + // equivalent to GLAutoDrawable methods: setVisible(true) + // + GLCapabilitiesImmutable caps2 = glWindow.getChosenGLCapabilities(); + Assert.assertNotNull(caps2); + Assert.assertTrue(caps2.getGreenBits()>=5); + Assert.assertTrue(caps2.getBlueBits()>=5); + Assert.assertTrue(caps2.getRedBits()>=5); + Assert.assertEquals(caps2.isOnscreen(),onscreen); + + if(addGLEventListenerAfterVisible) { + glWindow.addGLEventListener(demo); + glWindow.display(); + } + + return glWindow; + } + + static void destroyWindow(GLWindow glWindow) { + if(null!=glWindow) { + glWindow.invalidate(); + Assert.assertEquals(false,glWindow.isNativeValid()); + Assert.assertEquals(false,glWindow.isValid()); + } + } + + @Test + public void testWindowNativeRecreate01aSimple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); + + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + window.destroy(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.display(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.setVisible(true); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + window.setVisible(false); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + destroyWindow(window); + } + + @Test + public void testWindowNativeRecreate01bSimple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + true /*addGLEventListenerAfterVisible*/); + + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + window.destroy(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.display(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.setVisible(true); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + window.setVisible(false); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + destroyWindow(window); + } + + @Test + public void testWindowDecor01aSimple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); + System.out.println("Created: "+window); + int state; + for(state=0; state*100<durationPerTest; state++) { + Thread.sleep(100); + } + System.out.println("duration: "+window.getDuration()); + destroyWindow(window); + } + + @Test + public void testWindowDecor01bSimple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + true /*addGLEventListenerAfterVisible*/); + System.out.println("Created: "+window); + int state; + for(state=0; state*100<durationPerTest; state++) { + Thread.sleep(100); + } + System.out.println("duration: "+window.getDuration()); + destroyWindow(window); + } + + @Test + public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); + int state; + for(state=0; state*100<durationPerTest; state++) { + Thread.sleep(100); + } + System.out.println("duration: "+window.getDuration()); + destroyWindow(window); + } + + @Test + public void testWindowDecor03TwoWinOneDisplay() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + GLWindow window1 = createWindow(screen, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); + Assert.assertNotNull(window1); + + GLWindow window2 = createWindow(screen, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); + Assert.assertNotNull(window2); + + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + + int state; + for(state=0; state*100<durationPerTest; state++) { + Thread.sleep(100); + } + System.out.println("duration1: "+window1.getDuration()); + System.out.println("duration2: "+window2.getDuration()); + + destroyWindow(window1); + destroyWindow(window2); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + } + + @Test + public void testWindowDecor03TwoWinTwoDisplays() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + Display display1 = NewtFactory.createDisplay(null, false); // local display + Assert.assertNotNull(display1); + Display display2 = NewtFactory.createDisplay(null, false); // local display + Assert.assertNotNull(display2); + Assert.assertNotSame(display1, display2); + + Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0 + Assert.assertNotNull(screen1); + GLWindow window1 = createWindow(screen1, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); + Assert.assertNotNull(window1); + + Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0 + Assert.assertNotNull(screen2); + GLWindow window2 = createWindow(screen2, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); + Assert.assertNotNull(window2); + + Assert.assertEquals(2,Display.getActiveDisplayNumber()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + + Assert.assertEquals(1,display2.getReferenceCount()); + Assert.assertEquals(true,display2.isNativeValid()); + Assert.assertNotNull(display2.getEDTUtil()); + Assert.assertEquals(true,display2.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen2.getReferenceCount()); + Assert.assertEquals(true,screen2.isNativeValid()); + + int state; + for(state=0; state*100<durationPerTest; state++) { + Thread.sleep(100); + } + System.out.println("duration1: "+window1.getDuration()); + System.out.println("duration2: "+window2.getDuration()); + + // It is observed that some X11 drivers, eg ATI, fglrx 8.78.6, + // are quite sensitive to multiple Display connections (NEWT Display -> X11 Display). + // In such cases, closing displays shall happen in the same order as + // opening them, otherwise some driver related bug appears. + // You may test this, ie just reverse the destroy order below. + // See also native test: jogl/test/native/displayMultiple02.c + destroyWindow(window1); + destroyWindow(window2); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(false,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertNotNull(display2.getEDTUtil()); + Assert.assertEquals(false,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + System.out.println("durationPerTest: "+durationPerTest); + String tstname = TestGLWindows01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java new file mode 100644 index 000000000..6582a96c0 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java @@ -0,0 +1,303 @@ +/** + * 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.newt; + + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestGLWindows02NEWTAnimated extends UITestCase { + static GLProfile glp; + static int width, height; + static long durationPerTest = 100; // ms + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + // System.out.println("Requested: "+caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + GLWindow glWindow; + if(null!=screen) { + Window window = NewtFactory.createWindow(screen, caps); + Assert.assertNotNull(window); + glWindow = GLWindow.create(window); + } else { + glWindow = GLWindow.create(caps); + } + Assert.assertNotNull(glWindow); + glWindow.setUndecorated(onscreen && undecorated); + + GLEventListener demo = new Gears(); + setDemoFields(demo, glWindow); + glWindow.addGLEventListener(demo); + glWindow.addWindowListener(new TraceWindowAdapter()); + Assert.assertEquals(false,glWindow.isNativeValid()); + + glWindow.setSize(width, height); + Assert.assertEquals(false,glWindow.isVisible()); + glWindow.setVisible(true); + Assert.assertEquals(true,glWindow.isVisible()); + Assert.assertEquals(true,glWindow.isNativeValid()); + // Assert.assertEquals(width,glWindow.getWidth()); + // Assert.assertEquals(height,glWindow.getHeight()); + // System.out.println("Created: "+glWindow); + + // + // Create native OpenGL resources .. XGL/WGL/CGL .. + // equivalent to GLAutoDrawable methods: setVisible(true) + // + GLCapabilitiesImmutable caps2 = glWindow.getChosenGLCapabilities(); + Assert.assertNotNull(caps2); + Assert.assertTrue(caps2.getGreenBits()>=5); + Assert.assertTrue(caps2.getBlueBits()>=5); + Assert.assertTrue(caps2.getRedBits()>=5); + Assert.assertEquals(caps2.isOnscreen(),onscreen); + + return glWindow; + } + + static void destroyWindow(GLWindow glWindow) { + if(null!=glWindow) { + glWindow.destroy(); + } + } + + @Test + public void testWindowDecor01Simple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */); + Animator animator = new Animator(window); + Assert.assertTrue(animator.start()); + while(animator.isAnimating() && animator.getDuration()<durationPerTest) { + Thread.sleep(100); + } + destroyWindow(window); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertTrue(animator.stop()); + } + + @Test + public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */); + Animator animator = new Animator(window); + Assert.assertTrue(animator.start()); + while(animator.isAnimating() && animator.getDuration()<durationPerTest) { + Thread.sleep(100); + } + destroyWindow(window); + destroyWindow(window); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertTrue(animator.stop()); + } + + @Test + public void testWindowDecor03TwoWinOneDisplay() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + GLWindow window1 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Assert.assertNotNull(window1); + window1.setPosition(0, 0); + + GLWindow window2 = createWindow(screen, caps, width-10, height-10, true /* onscreen */, false /* undecorated */); + Assert.assertNotNull(window2); + window2.setPosition(screen.getWidth()-width, 0); + + Animator animator = new Animator(); + Assert.assertEquals(false, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + Assert.assertTrue(animator.start()); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.add(window1); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.add(window2); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + while(animator.isAnimating() && animator.getDuration()<durationPerTest) { + Thread.sleep(100); + } + window1.invalidate(); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + while(animator.isAnimating() && animator.getDuration()<2*durationPerTest) { + Thread.sleep(100); + } + window2.invalidate(); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + Assert.assertTrue(animator.stop()); + } + + @Test + public void testWindowDecor03TwoWinTwoDisplays() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + + Display display1 = NewtFactory.createDisplay(null, false); // local display + Assert.assertNotNull(display1); + Display display2 = NewtFactory.createDisplay(null, false); // local display + Assert.assertNotNull(display2); + Assert.assertNotSame(display1, display2); + + Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0 + Assert.assertNotNull(screen1); + GLWindow window1 = createWindow(screen1, caps, width, height, true /* onscreen */, false /* undecorated */); + Assert.assertNotNull(window1); + window1.setPosition(0, 0); + + Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0 + Assert.assertNotNull(screen2); + GLWindow window2 = createWindow(screen2, caps, width-10, height-10, true /* onscreen */, false /* undecorated */); + Assert.assertNotNull(window2); + window2.setPosition(screen2.getWidth()-width, 0); + + Animator animator = new Animator(); + Assert.assertEquals(false, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + Assert.assertTrue(animator.start()); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.add(window1); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.add(window2); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + while(animator.isAnimating() && animator.getDuration()<durationPerTest) { + Thread.sleep(100); + } + destroyWindow(window1); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + while(animator.isAnimating() && animator.getDuration()<2*durationPerTest) { + Thread.sleep(100); + } + destroyWindow(window2); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + Assert.assertEquals(true, animator.pause()); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(true, animator.isPaused()); + + Assert.assertEquals(true, animator.resume()); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + Assert.assertTrue(animator.stop()); + Assert.assertEquals(false, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + String tstname = TestGLWindows02NEWTAnimated.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java new file mode 100644 index 000000000..b2068d976 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java @@ -0,0 +1,167 @@ +/** + * 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.newt; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Frame; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestListenerCom01AWT extends UITestCase { + static int width, height; + static long durationPerTest = 500; + static boolean verbose = false; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + } + + @Test + public void testListenerStringPassingAndOrder() throws InterruptedException { + // setup NEWT GLWindow .. + GLWindow glWindow = GLWindow.create(new GLCapabilities(null)); + Assert.assertNotNull(glWindow); + glWindow.setTitle("NEWT - CHILD"); + + System.out.println("durationPerTest "+durationPerTest); + + GLEventListener demo = new Gears(); + setDemoFields(demo, glWindow, false); + glWindow.addGLEventListener(demo); + + WindowEventCom1 wl1 = new WindowEventCom1(); + WindowEventCom2 wl2 = new WindowEventCom2(); + WindowEventCom3 wl3 = new WindowEventCom3(); + + // TraceWindowAdapter wlT = new TraceWindowAdapter(); + // glWindow.addWindowListener(0, wlT); + // Assert.assertEquals(wlT, glWindow.getWindowListener(0)); + + glWindow.addWindowListener(0, wl3); + glWindow.addWindowListener(0, wl2); + glWindow.addWindowListener(0, wl1); + + Assert.assertEquals(wl1, glWindow.getWindowListener(0)); + Assert.assertEquals(wl2, glWindow.getWindowListener(1)); + Assert.assertEquals(wl3, glWindow.getWindowListener(2)); + + // attach NEWT GLWindow to AWT Canvas + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow); + Frame frame = new Frame("AWT Parent Frame"); + frame.add(newtCanvasAWT); + frame.setSize(width, height); + frame.setVisible(true); + + Animator animator1 = new Animator(glWindow); + animator1.start(); + while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { + Thread.sleep(100); + width+=10; height+=10; + frame.setSize(width, height); + } + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + + frame.dispose(); + glWindow.invalidate(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + verbose = true; + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + String tstname = TestListenerCom01AWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java new file mode 100644 index 000000000..6b501e31d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java @@ -0,0 +1,171 @@ +/** + * 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.newt; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.newt.*; +import com.jogamp.newt.opengl.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowException; + +public class TestRemoteGLWindows01NEWT extends UITestCase { + static GLProfile glp; + static int width, height; + static long durationPerTest = 100; // ms + static String remoteDisplay = "nowhere:0.0"; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + // GLProfile.initSingleton(false); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(Screen screen, GLCapabilities caps, GLEventListener demo) + throws InterruptedException + { + Assert.assertNotNull(caps); + // + // Create native windowing resources .. X11/Win/OSX + // + GLWindow glWindow; + if(null!=screen) { + glWindow = GLWindow.create(screen, caps); + Assert.assertNotNull(glWindow); + } else { + glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + } + + glWindow.addGLEventListener(demo); + + glWindow.setSize(512, 512); + glWindow.setVisible(true); + Assert.assertEquals(true,glWindow.isVisible()); + Assert.assertEquals(true,glWindow.isNativeValid()); + + return glWindow; + } + + static void destroyWindow(GLWindow glWindow) { + if(null!=glWindow) { + glWindow.invalidate(); + Assert.assertEquals(false,glWindow.isNativeValid()); + Assert.assertEquals(false,glWindow.isValid()); + } + } + + @Test + public void testRemoteWindow01() throws InterruptedException { + Animator animator = new Animator(); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window1 = createWindow(null, caps, new Gears(1)); // local with vsync + Assert.assertEquals(true,window1.isNativeValid()); + Assert.assertEquals(true,window1.isVisible()); + AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice(); + + System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1)); + + animator.add(window1); + + // Remote Display/Device/Screen/Window .. + // Eager initialization of NEWT Display -> AbstractGraphicsDevice -> GLProfile (device) + Display display2; // remote display + AbstractGraphicsDevice device2; + Screen screen2; + GLWindow window2; + try { + display2 = NewtFactory.createDisplay(remoteDisplay); // remote display + display2.createNative(); + System.err.println(display2); + device2 = display2.getGraphicsDevice(); + System.err.println(device2); + GLProfile.initProfiles(device2); // just to make sure + System.err.println(""); + System.err.println("GLProfiles window2: "+device2.getConnection()+": "+GLProfile.glAvailabilityToString(device2)); + screen2 = NewtFactory.createScreen(display2, 0); // screen 0 + window2 = createWindow(screen2, caps, new Gears(0)); // remote, no vsync + } catch (NativeWindowException nwe) { + System.err.println(nwe); + Assume.assumeNoException(nwe); + destroyWindow(window1); + return; + } + + Assert.assertEquals(true,window2.isNativeValid()); + Assert.assertEquals(true,window2.isVisible()); + + animator.add(window2); + animator.start(); + + while(animator.getDuration()<durationPerTest) { + Thread.sleep(100); + } + + destroyWindow(window1); + destroyWindow(window2); + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } else if(args[i].equals("-display")) { + remoteDisplay = args[++i]; + } + } + System.out.println("durationPerTest: "+durationPerTest); + System.out.println("display: "+remoteDisplay); + String tstname = TestRemoteGLWindows01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java new file mode 100644 index 000000000..9c44545f2 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java @@ -0,0 +1,151 @@ +/** + * 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.newt; + + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.nativewindow.*; + +import com.jogamp.newt.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestRemoteWindow01NEWT extends UITestCase { + static int width, height; + static String remoteDisplay = "nowhere:0.0"; + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + } + + static Window createWindow(Screen screen, Capabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + // System.out.println("Requested: "+caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + Window window = NewtFactory.createWindow(screen, caps); + Assert.assertNotNull(window); + window.setUndecorated(onscreen && undecorated); + window.setSize(width, height); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + window.setVisible(true); + Assert.assertEquals(true,window.isVisible()); + Assert.assertEquals(true,window.isNativeValid()); + // Assert.assertEquals(width,window.getWidth()); + // Assert.assertEquals(height,window.getHeight()); + // System.out.println("Created: "+window); + + // + // Create native OpenGL resources .. XGL/WGL/CGL .. + // equivalent to GLAutoDrawable methods: setVisible(true) + // + CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(chosenCapabilities); + Assert.assertTrue(chosenCapabilities.getGreenBits()>5); + Assert.assertTrue(chosenCapabilities.getBlueBits()>5); + Assert.assertTrue(chosenCapabilities.getRedBits()>5); + Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen); + + return window; + } + + static void destroyWindow(Display display, Screen screen, Window window) { + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void testRemoteWindow01() throws InterruptedException { + Capabilities caps = new Capabilities(); + Display display1 = NewtFactory.createDisplay(null); // local display + Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0 + Window window1 = createWindow(screen1, caps, width, height, true /* onscreen */, false /* undecorated */); + window1.setVisible(true); + + Assert.assertEquals(true,window1.isNativeValid()); + Assert.assertEquals(true,window1.isVisible()); + + // Remote Display/Device/Screen/Window .. + Display display2; + AbstractGraphicsDevice device2; + Screen screen2; + Window window2; + try { + display2 = NewtFactory.createDisplay(remoteDisplay); + display2.createNative(); + screen2 = NewtFactory.createScreen(display2, 0); // screen 0 + window2 = createWindow(screen2, caps, width, height, true /* onscreen */, false /* undecorated */); + window2.setVisible(true); + } catch (NativeWindowException nwe) { + System.err.println(nwe); + Assume.assumeNoException(nwe); + destroyWindow(display1, screen1, window1); + return; + } + + Assert.assertEquals(true,window2.isNativeValid()); + Assert.assertEquals(true,window2.isVisible()); + + Thread.sleep(500); // 500 ms + + destroyWindow(display1, screen1, window1); + destroyWindow(display2, screen2, window2); + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-display")) { + remoteDisplay = args[++i]; + } + } + System.out.println("display: "+remoteDisplay); + String tstname = TestRemoteWindow01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java new file mode 100644 index 000000000..7de63e6a6 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java @@ -0,0 +1,135 @@ +/** + * 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.newt; + +import java.io.IOException; +import javax.media.nativewindow.NativeWindowFactory; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.util.MonitorMode; +import com.jogamp.newt.util.ScreenModeUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; +import java.util.Iterator; +import java.util.List; +import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionReadOnly; +import javax.media.nativewindow.util.SurfaceSize; + +public class TestScreenMode00NEWT extends UITestCase { + static int width, height; + + static int waitTimeShort = 4; //1 sec + static int waitTimeLong = 6; //6 sec + + + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + } + + @Test + public void testScreenModeInfo00() throws InterruptedException { + DimensionReadOnly res = new Dimension(640, 480); + SurfaceSize surfsz = new SurfaceSize(res, 32); + DimensionReadOnly mm = new Dimension(500, 400); + MonitorMode mon = new MonitorMode(surfsz, mm, 60); + ScreenMode sm_out = new ScreenMode(mon, 90); + System.err.println("00 out: "+sm_out); + + int[] props = ScreenModeUtil.streamOut(sm_out); + ScreenMode sm_in = ScreenModeUtil.streamIn(props, 0); + System.err.println("00 in : "+sm_in); + + Assert.assertEquals(sm_in.getMonitorMode().getSurfaceSize().getResolution(), + sm_out.getMonitorMode().getSurfaceSize().getResolution()); + + Assert.assertEquals(sm_in.getMonitorMode().getSurfaceSize(), + sm_out.getMonitorMode().getSurfaceSize()); + + Assert.assertEquals(sm_in.getMonitorMode().getScreenSizeMM(), + sm_out.getMonitorMode().getScreenSizeMM()); + + Assert.assertEquals(sm_in.getMonitorMode(), sm_out.getMonitorMode()); + + Assert.assertEquals(sm_in, sm_out); + + Assert.assertEquals(sm_out.hashCode(), sm_in.hashCode()); + } + + @Test + public void testScreenModeInfo01() throws InterruptedException { + Capabilities caps = new Capabilities(); + Window window = NewtFactory.createWindow(caps); + window.setSize(width, height); + window.setVisible(true); + + Screen screen = window.getScreen(); + + List screenModes = screen.getScreenModes(); + if(null != screenModes) { + Assert.assertTrue(screenModes.size()>0); + int i=0; + for(Iterator iter=screenModes.iterator(); iter.hasNext(); i++) { + System.err.println(i+": "+iter.next()); + } + ScreenMode sm_o = screen.getOriginalScreenMode(); + Assert.assertNotNull(sm_o); + ScreenMode sm_c = screen.getOriginalScreenMode(); + Assert.assertNotNull(sm_c); + System.err.println("orig: "+sm_o); + System.err.println("curr: "+sm_c); + } else { + // no support .. + System.err.println("Your platform has no ScreenMode change support, sorry"); + } + + window.invalidate(); + + Assert.assertEquals(false,window.isVisible()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,screen.getDisplay().isNativeValid()); + } + + public static void main(String args[]) throws IOException { + String tstname = TestScreenMode00NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java new file mode 100644 index 000000000..ffff682dc --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java @@ -0,0 +1,284 @@ +/** + * 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.newt; + +import java.io.IOException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.opengl.util.Animator; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.newt.util.ScreenModeUtil; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import java.util.List; +import javax.media.nativewindow.util.Dimension; + +public class TestScreenMode01NEWT extends UITestCase { + static GLProfile glp; + static int width, height; + + static int waitTimeShort = 1000; // 1 sec + static int waitTimeLong = 5000; // 5 sec + + + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + + GLWindow window = GLWindow.create(screen, caps); + window.setSize(width, height); + window.addGLEventListener(new Gears()); + Assert.assertNotNull(window); + window.setVisible(true); + return window; + } + + static void destroyWindow(Window window) { + if(null!=window) { + window.destroy(); + } + } + + @Test + public void testFullscreenChange01() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Animator animator = new Animator(window); + animator.start(); + + window.setFullscreen(true); + Assert.assertEquals(true, window.isFullscreen()); + + Thread.sleep(waitTimeShort); + + window.setFullscreen(false); + Assert.assertEquals(false, window.isFullscreen()); + + Thread.sleep(waitTimeShort); + + animator.stop(); + destroyWindow(window); + } + + @Test + public void testScreenModeChange01() throws InterruptedException { + Thread.sleep(waitTimeShort); + + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Assert.assertNotNull(window); + + List screenModes = screen.getScreenModes(); + if(null==screenModes) { + // no support .. + System.err.println("Your platform has no ScreenMode change support, sorry"); + destroyWindow(window); + return; + } + Assert.assertTrue(screenModes.size()>0); + + Animator animator = new Animator(window); + animator.start(); + + ScreenMode smCurrent = screen.getCurrentScreenMode(); + Assert.assertNotNull(smCurrent); + ScreenMode smOrig = screen.getOriginalScreenMode(); + Assert.assertNotNull(smOrig); + Assert.assertEquals(smCurrent, smOrig); + System.err.println("[0] current/orig: "+smCurrent); + + screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate()); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByRotation(screenModes, 0); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601)); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + + ScreenMode sm = (ScreenMode) screenModes.get(0); + System.err.println("[0] set current: "+sm); + screen.setCurrentScreenMode(sm); + Assert.assertEquals(sm, screen.getCurrentScreenMode()); + Assert.assertNotSame(smOrig, screen.getCurrentScreenMode()); + + Thread.sleep(waitTimeLong); + + // check reset .. + + ScreenMode saveOrigMode = (ScreenMode) smOrig.clone(); + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + animator.stop(); + destroyWindow(window); + + Assert.assertEquals(false,window.isVisible()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + + screen.createNative(); // trigger native re-creation + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + + smCurrent = screen.getCurrentScreenMode(); + System.err.println("[1] current/orig: "+smCurrent); + + Assert.assertNotNull(smCurrent); + Assert.assertEquals(saveOrigMode, smOrig); + + screen.destroy(); + + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + + Thread.sleep(waitTimeShort); + } + + @Test + public void testScreenModeChangeWithFS01Pre() throws InterruptedException { + Thread.sleep(waitTimeShort); + testScreenModeChangeWithFS01Impl(true) ; + Thread.sleep(waitTimeShort); + } + + @Test + public void testScreenModeChangeWithFS01Post() throws InterruptedException { + Thread.sleep(waitTimeShort); + testScreenModeChangeWithFS01Impl(false) ; + Thread.sleep(waitTimeShort); + } + + protected void testScreenModeChangeWithFS01Impl(boolean preFS) throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Display display = NewtFactory.createDisplay(null); // local display + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Animator animator = new Animator(window); + animator.start(); + + ScreenMode smOrig = screen.getOriginalScreenMode(); + List screenModes = screen.getScreenModes(); + if(null==screenModes) { + // no support .. + destroyWindow(window); + return; + } + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate()); + screenModes = ScreenModeUtil.filterByRotation(screenModes, 0); + screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601)); + screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); + + ScreenMode screenMode = (ScreenMode) screenModes.get(0); + Assert.assertNotNull(screenMode); + + if(preFS) { + System.err.println("[0] set FS pre 0: "+window.isFullscreen()); + window.setFullscreen(true); + Assert.assertEquals(true, window.isFullscreen()); + System.err.println("[0] set FS pre X: "+window.isFullscreen()); + } + + System.err.println("[0] set current: "+screenMode); + screen.setCurrentScreenMode(screenMode); + + if(!preFS) { + System.err.println("[0] set FS post 0: "+window.isFullscreen()); + window.setFullscreen(true); + Assert.assertEquals(true, window.isFullscreen()); + System.err.println("[0] set FS post X: "+window.isFullscreen()); + } + + Thread.sleep(waitTimeLong); + + // check reset .. + + ScreenMode saveOrigMode = (ScreenMode) smOrig.clone(); + + animator.stop(); + destroyWindow(window); + + screen.createNative(); // trigger native re-creation + + ScreenMode smCurrent = screen.getCurrentScreenMode(); + System.err.println("[1] current/orig: "+smCurrent); + + Assert.assertNotNull(smCurrent); + Assert.assertEquals(saveOrigMode, smOrig); + + screen.destroy(); + } + + public static void main(String args[]) throws IOException { + String tstname = TestScreenMode01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java new file mode 100644 index 000000000..2ec0490f0 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java @@ -0,0 +1,187 @@ +/** + * 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.newt; + +import java.io.IOException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.opengl.util.Animator; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.newt.util.ScreenModeUtil; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import java.util.List; +import javax.media.nativewindow.util.Dimension; + +public class TestScreenMode02NEWT extends UITestCase { + static GLProfile glp; + static int width, height; + + static int waitTimeShort = 1000; // 1 sec + static int waitTimeLong = 5000; // 5 sec + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + + GLWindow window = GLWindow.create(screen, caps); + window.setSize(width, height); + window.addGLEventListener(new Gears()); + Assert.assertNotNull(window); + window.setVisible(true); + Assert.assertTrue(window.isVisible()); + return window; + } + + static void destroyWindow(Window window) { + if(null!=window) { + window.destroy(); + } + } + + @Test + public void testScreenRotationChange01() throws InterruptedException { + Thread.sleep(waitTimeShort); + + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Assert.assertNotNull(window); + + List screenModes = screen.getScreenModes(); + if(null==screenModes) { + // no support .. + System.err.println("Your platform has no ScreenMode change support, sorry"); + destroyWindow(window); + return; + } + Assert.assertTrue(screenModes.size()>0); + + Animator animator = new Animator(window); + animator.start(); + + ScreenMode smCurrent = screen.getCurrentScreenMode(); + Assert.assertNotNull(smCurrent); + ScreenMode smOrig = screen.getOriginalScreenMode(); + Assert.assertNotNull(smOrig); + Assert.assertEquals(smCurrent, smOrig); + System.err.println("[0] current/orig: "+smCurrent); + + screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate()); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByRotation(screenModes, 90); + if(null==screenModes) { + // no rotation support .. + System.err.println("Your platform has no rotation support, sorry"); + destroyWindow(window); + return; + } + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601)); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + + ScreenMode sm = (ScreenMode) screenModes.get(0); + System.err.println("[0] set current: "+sm); + screen.setCurrentScreenMode(sm); + Assert.assertEquals(sm, screen.getCurrentScreenMode()); + Assert.assertNotSame(smOrig, screen.getCurrentScreenMode()); + + Thread.sleep(waitTimeLong); + + // check reset .. + + ScreenMode saveOrigMode = (ScreenMode) smOrig.clone(); + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + animator.stop(); + destroyWindow(window); + + Assert.assertEquals(false,window.isVisible()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + + screen.createNative(); // trigger native re-creation + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + + smCurrent = screen.getCurrentScreenMode(); + System.err.println("[1] current/orig: "+smCurrent); + + Assert.assertNotNull(smCurrent); + Assert.assertEquals(saveOrigMode, smOrig); + + screen.destroy(); + + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + + Thread.sleep(waitTimeShort); + } + + public static void main(String args[]) throws IOException { + String tstname = TestScreenMode02NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java new file mode 100644 index 000000000..581877e50 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol01AWT.java @@ -0,0 +1,160 @@ +/** + * 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.newt; + +import org.junit.Test; +import org.junit.Assert; + +import java.lang.reflect.InvocationTargetException; +import java.awt.Frame; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import javax.media.nativewindow.WindowClosingProtocol; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; + +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestWindowClosingProtocol01AWT extends UITestCase { + + @Test + public void testCloseFrameGLCanvas() throws InterruptedException, InvocationTargetException { + final Frame frame = new Frame("testCloseFrameGLCanvas AWT"); + + GLProfile glp = GLProfile.getDefault(); + GLCapabilities caps = new GLCapabilities(glp); + final GLCanvas glCanvas = new GLCanvas(caps); + glCanvas.addGLEventListener(new Gears()); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.add(glCanvas); + frame.pack(); + frame.setSize(512, 512); + frame.validate(); + frame.setVisible(true); + } }); + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); + + // + // close with op: DO_NOTHING_ON_CLOSE -> NOP (default) + // + int op = glCanvas.getDefaultCloseOperation(); + Assert.assertEquals(WindowClosingProtocol.DO_NOTHING_ON_CLOSE, op); + + Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false)); // nop + Thread.sleep(100); + Assert.assertEquals(true, frame.isDisplayable()); + Assert.assertEquals(true, glCanvas.isValid()); + Assert.assertEquals(true, glCanvas.isDisplayable()); + + // + // close with op (GLCanvas): DISPOSE_ON_CLOSE -> dispose + // + glCanvas.setDefaultCloseOperation(WindowClosingProtocol.DISPOSE_ON_CLOSE); + op = glCanvas.getDefaultCloseOperation(); + Assert.assertEquals(WindowClosingProtocol.DISPOSE_ON_CLOSE, op); + + Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false)); // no frame close + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, false)); + Assert.assertEquals(true, frame.isDisplayable()); + Assert.assertEquals(false, glCanvas.isRealized()); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.dispose(); + } }); + } + + @Test + public void testCloseJFrameGLCanvas() throws InterruptedException, InvocationTargetException { + final JFrame frame = new JFrame("testCloseJFrameGLCanvas AWT"); + + GLProfile glp = GLProfile.getDefault(); + GLCapabilities caps = new GLCapabilities(glp); + GLCanvas glCanvas = new GLCanvas(caps); + glCanvas.addGLEventListener(new Gears()); + frame.getContentPane().add(glCanvas); + frame.pack(); + frame.setSize(512, 512); + frame.validate(); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.setVisible(true); + } }); + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); + + // + // close with op: DO_NOTHING_ON_CLOSE -> NOP / HIDE (default) + // + Assert.assertEquals(JFrame.HIDE_ON_CLOSE, frame.getDefaultCloseOperation()); + int op = glCanvas.getDefaultCloseOperation(); + Assert.assertEquals(WindowClosingProtocol.DO_NOTHING_ON_CLOSE, op); + + Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false)); // nop + Thread.sleep(100); + Assert.assertEquals(true, frame.isDisplayable()); + Assert.assertEquals(true, glCanvas.isValid()); + Assert.assertEquals(true, glCanvas.isDisplayable()); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.setVisible(true); + } }); + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); + + // + // close with op (JFrame): DISPOSE_ON_CLOSE -- GLCanvas --> dispose + // + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + Assert.assertEquals(JFrame.DISPOSE_ON_CLOSE, frame.getDefaultCloseOperation()); + op = glCanvas.getDefaultCloseOperation(); + Assert.assertEquals(WindowClosingProtocol.DISPOSE_ON_CLOSE, op); + + Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true)); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, false)); + Assert.assertEquals(false, frame.isDisplayable()); + Assert.assertEquals(false, glCanvas.isValid()); + Assert.assertEquals(false, glCanvas.isDisplayable()); + Assert.assertEquals(false, glCanvas.isRealized()); + } + + public static void main(String[] args) { + String tstname = TestWindowClosingProtocol01AWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol02NEWT.java new file mode 100644 index 000000000..8f5baece9 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol02NEWT.java @@ -0,0 +1,96 @@ +/** + * 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.newt; + +import java.lang.reflect.InvocationTargetException; + +import org.junit.Test; +import org.junit.Assert; + +import javax.media.nativewindow.WindowClosingProtocol; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.newt.opengl.GLWindow; + +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestWindowClosingProtocol02NEWT extends UITestCase { + + @Test + public void testCloseGLWindow() throws InterruptedException, InvocationTargetException { + GLProfile glp = GLProfile.getDefault(); + GLCapabilities caps = new GLCapabilities(glp); + final GLWindow glWindow = GLWindow.create(caps); + final AWTRobotUtil.WindowClosingListener windowClosingListener = AWTRobotUtil.addClosingListener(glWindow); + + glWindow.addGLEventListener(new Gears()); + glWindow.setSize(512, 512); + glWindow.setVisible(true); + Assert.assertEquals(true, glWindow.isVisible()); + + // CHECK DEFAULT .. + int op = glWindow.getDefaultCloseOperation(); + Assert.assertEquals(WindowClosingProtocol.DISPOSE_ON_CLOSE, op); + + // + // close with op: DO_NOTHING_ON_CLOSE -> NOP + // + glWindow.setDefaultCloseOperation(WindowClosingProtocol.DO_NOTHING_ON_CLOSE); + op = glWindow.getDefaultCloseOperation(); + Assert.assertEquals(WindowClosingProtocol.DO_NOTHING_ON_CLOSE, op); + + Assert.assertEquals(true, AWTRobotUtil.closeWindow(glWindow, false)); // nop + Assert.assertEquals(true, glWindow.isValid()); + Assert.assertEquals(true, glWindow.isNativeValid()); + Assert.assertEquals(true, windowClosingListener.isWindowClosing()); + windowClosingListener.reset(); + + // + // close with op (GLCanvas): DISPOSE_ON_CLOSE -> dispose + // + glWindow.setDefaultCloseOperation(WindowClosingProtocol.DISPOSE_ON_CLOSE); + op = glWindow.getDefaultCloseOperation(); + Assert.assertEquals(WindowClosingProtocol.DISPOSE_ON_CLOSE, op); + + Assert.assertEquals(true, AWTRobotUtil.closeWindow(glWindow, true)); + Assert.assertEquals(true, glWindow.isValid()); + Assert.assertEquals(false, glWindow.isNativeValid()); + Assert.assertEquals(true, windowClosingListener.isWindowClosing()); + } + + public static void main(String[] args) { + String tstname = TestWindowClosingProtocol02NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java new file mode 100644 index 000000000..a10730680 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowClosingProtocol03NewtAWT.java @@ -0,0 +1,115 @@ +/** + * 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.newt; + +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.opengl.GLWindow; +import org.junit.Test; +import org.junit.Assert; + +import java.lang.reflect.InvocationTargetException; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import javax.media.nativewindow.WindowClosingProtocol; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestWindowClosingProtocol03NewtAWT extends UITestCase { + + @Test + public void testCloseJFrameNewtCanvasAWT() throws InterruptedException, InvocationTargetException { + final JFrame frame = new JFrame("testCloseJFrameNewtCanvasAWT"); + + GLProfile glp = GLProfile.getDefault(); + GLCapabilities caps = new GLCapabilities(glp); + final GLWindow glWindow = GLWindow.create(caps); + final AWTRobotUtil.WindowClosingListener windowClosingListener = AWTRobotUtil.addClosingListener(glWindow); + + glWindow.addGLEventListener(new Gears()); + + NewtCanvasAWT newtCanvas = new NewtCanvasAWT(glWindow); + + frame.getContentPane().add(newtCanvas); + frame.pack(); + frame.setSize(512, 512); + frame.validate(); + frame.setVisible(true); + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); + + // + // close with op: DO_NOTHING_ON_CLOSE -> NOP / HIDE (default) + // + Assert.assertEquals(JFrame.HIDE_ON_CLOSE, frame.getDefaultCloseOperation()); + int op = newtCanvas.getDefaultCloseOperation(); + Assert.assertEquals(WindowClosingProtocol.DO_NOTHING_ON_CLOSE, op); + + Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false)); + Assert.assertEquals(true, frame.isDisplayable()); + Assert.assertEquals(true, newtCanvas.isValid()); + Assert.assertEquals(true, newtCanvas.isDisplayable()); + Assert.assertEquals(true, glWindow.isValid()); + Assert.assertEquals(true, glWindow.isNativeValid()); + Assert.assertEquals(true, windowClosingListener.isWindowClosing()); + windowClosingListener.reset(); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame.setVisible(true); + } }); + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); + + // + // close with op (JFrame): DISPOSE_ON_CLOSE -- newtCanvas -- glWindow --> dispose + // + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + Assert.assertEquals(JFrame.DISPOSE_ON_CLOSE, frame.getDefaultCloseOperation()); + op = newtCanvas.getDefaultCloseOperation(); + Assert.assertEquals(WindowClosingProtocol.DISPOSE_ON_CLOSE, op); + + Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true)); + Assert.assertEquals(false, frame.isDisplayable()); + Assert.assertEquals(false, newtCanvas.isValid()); + Assert.assertEquals(false, newtCanvas.isDisplayable()); + Assert.assertEquals(true, glWindow.isValid()); + Assert.assertEquals(false, glWindow.isNativeValid()); + Assert.assertEquals(true, windowClosingListener.isWindowClosing()); + } + + public static void main(String[] args) { + String tstname = TestWindowClosingProtocol03NewtAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java new file mode 100644 index 000000000..5ac6041ac --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java @@ -0,0 +1,179 @@ +/** + * 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.newt; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.nativewindow.*; + +import com.jogamp.newt.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestWindows01NEWT extends UITestCase { + static int width, height; + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + } + + static Window createWindow(Screen screen, Capabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + // System.out.println("Requested: "+caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + Window window = NewtFactory.createWindow(screen, caps); + Assert.assertNotNull(window); + window.setUndecorated(onscreen && undecorated); + window.setSize(width, height); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + window.setVisible(true); + Assert.assertEquals(true,window.isVisible()); + Assert.assertEquals(true,window.isNativeValid()); + // Assert.assertEquals(width,window.getWidth()); + // Assert.assertEquals(height,window.getHeight()); + // System.out.println("Created: "+window); + + // + // Create native OpenGL resources .. XGL/WGL/CGL .. + // equivalent to GLAutoDrawable methods: setVisible(true) + // + CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(chosenCapabilities); + Assert.assertTrue(chosenCapabilities.getGreenBits()>5); + Assert.assertTrue(chosenCapabilities.getBlueBits()>5); + Assert.assertTrue(chosenCapabilities.getRedBits()>5); + Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen); + + return window; + } + + static void destroyWindow(Display display, Screen screen, Window window) { + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void testWindowNativeRecreate01Simple() throws InterruptedException { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + window.destroy(); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + + window.setVisible(true); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + + Thread.sleep(100); // 100 ms + destroyWindow(display, screen, window); + } + + @Test + public void testWindowDecor01Simple() throws InterruptedException { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Thread.sleep(100); // 100 ms + destroyWindow(display, screen, window); + } + + @Test + public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Thread.sleep(100); // 100 ms + destroyWindow(null, null, window); + destroyWindow(display, screen, window); + } + + @Test + public void testWindowDecor03TwoWin() throws InterruptedException { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window1 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Window window2 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Thread.sleep(100); // 100 ms + destroyWindow(null, null, window2); + destroyWindow(display, screen, window1); + } + + public static void main(String args[]) throws IOException { + String tstname = TestWindows01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java new file mode 100644 index 000000000..609d443aa --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java @@ -0,0 +1,42 @@ +/** + * 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.newt; + +import com.jogamp.newt.event.*; + +class WindowEventCom1 extends WindowAdapter { + + public void windowResized(WindowEvent e) { + e.setAttachment(new String("WindowEventCom1.windowResized: "+e)); + } + public void windowMoved(WindowEvent e) { + e.setAttachment(new String("WindowEventCom1.windowMoved: "+e)); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java new file mode 100644 index 000000000..d15a3ccd8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java @@ -0,0 +1,48 @@ +/** + * 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.newt; + +import com.jogamp.newt.event.*; + +class WindowEventCom2 extends WindowAdapter { + + public void windowResized(WindowEvent e) { + String str = (String) e.getAttachment(); + if(null==str) { + e.setAttachment(new String("WindowEventCom2.windowResized: "+e)); + } + } + public void windowMoved(WindowEvent e) { + String str = (String) e.getAttachment(); + if(null==str) { + e.setAttachment(new String("WindowEventCom2.windowMoved: "+e)); + } + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java new file mode 100644 index 000000000..87e5eccbb --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java @@ -0,0 +1,44 @@ +/** + * 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.newt; + +import com.jogamp.newt.event.*; + +class WindowEventCom3 extends WindowAdapter { + + public void windowResized(WindowEvent e) { + String str = (String) e.getAttachment(); + System.out.println("WindowEventCom3.windowResized: "+str); + } + public void windowMoved(WindowEvent e) { + String str = (String) e.getAttachment(); + System.out.println("WindowEventCom3.windowMoved: "+str); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java new file mode 100644 index 000000000..d518616b1 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java @@ -0,0 +1,57 @@ +/** + * 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.newt.parenting; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.opengl.*; + +public class GLRunnableDummy implements GLRunnable { + float r=0.0f; + float g=0.0f; + float b=0.0f; + float d=0.001f; + + public void run(GLAutoDrawable drawable) { + GL2ES1 gl = drawable.getGL().getGL2ES1(); + gl.glClearColor(r, g, b, 1f); + r+=d; + if(r>1f) { + r=1f; + d*=-1f; + } else if(r<0f) { + r=0f; + d*=-1f; + } + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java new file mode 100644 index 000000000..3313ec65c --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java @@ -0,0 +1,45 @@ +/** + * 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.newt.parenting; + +import com.jogamp.newt.event.*; + +class KeyAction extends KeyAdapter { + NEWTEventFiFo eventFifo; + + public KeyAction(NEWTEventFiFo eventFifo) { + this.eventFifo = eventFifo; + } + + public void keyTyped(KeyEvent e) { + eventFifo.put(e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java new file mode 100644 index 000000000..5173d0f22 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java @@ -0,0 +1,716 @@ +/** + * 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.newt.parenting; + + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting01NEWT extends UITestCase { + static int width, height; + static long durationPerTest = 500; + static long waitAbout10FramesAt30fps = 10*34; // 10 frames @ 30fps + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glCaps = new GLCapabilities(null); + } + + @Test + public void testWindowParenting01CreateVisibleDestroy() throws InterruptedException { + int x = 0; + int y = 0; + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Display display = null; + Screen screen = null; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + Assert.assertNotNull(glWindow1); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + screen = glWindow1.getScreen(); + display = screen.getDisplay(); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + glWindow1.setSize(640, 480); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps); + Assert.assertNotNull(glWindow2); + Assert.assertEquals(false, glWindow2.isVisible()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + Assert.assertSame(screen,glWindow2.getScreen()); + Assert.assertSame(display,glWindow2.getScreen().getDisplay()); + glWindow2.setSize(320, 240); + GLEventListener demo2 = new Gears(); + setDemoFields(demo2, glWindow2, false); + glWindow2.addGLEventListener(demo2); + + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); // GLWindow -> invoke .. + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + // visible test + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); + glWindow1.setVisible(true); + System.err.println("Frames for setVisible(true): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + glWindow1.setVisible(false); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + + glWindow1.resetCounter(); + glWindow2.resetCounter(); + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); + glWindow1.setVisible(true); + System.err.println("Frames for setVisible(true): A2: "+glWindow1.getTotalFrames()+", B2: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + + glWindow1.resetCounter(); + glWindow2.resetCounter(); + Animator animator1 = new Animator(glWindow1); + animator1.start(); + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); + Animator animator2 = new Animator(glWindow2); + animator2.start(); + Assert.assertEquals(true, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertNotNull(animator2.getThread()); + while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { + Thread.sleep(100); + } + System.err.println("Frames for setVisible(true): A3: "+glWindow1.getTotalFrames()+", B3: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(true, animator1.pause()); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(true, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); + Assert.assertEquals(true, animator2.pause()); + Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(true, animator2.isPaused()); + Assert.assertNotNull(animator2.getThread()); + + glWindow1.resetCounter(); + glWindow2.resetCounter(); + Assert.assertEquals(true, animator1.resume()); + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); + Assert.assertEquals(true, animator2.resume()); + Assert.assertEquals(true, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertNotNull(animator2.getThread()); + Thread.sleep(waitAbout10FramesAt30fps); + System.err.println("Frames for setVisible(true): A4: "+glWindow1.getTotalFrames()+", B4: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + animator2.stop(); + Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertEquals(null, animator2.getThread()); + + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + glWindow2.destroy(); // can be recreated, refs are hold + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(true, glWindow2.isValid()); + + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + glWindow1.destroy(); // can be recreated, refs are hold + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(true, glWindow2.isValid()); + + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + // recreation .. + glWindow1.resetCounter(); + glWindow2.resetCounter(); + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); + glWindow1.setVisible(true); + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + + System.err.println("Frames for setVisible(true): A3: "+glWindow1.getTotalFrames()+", B3: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + // chain glwindow1 -> glwindow2 ; can be recreated .. + glWindow1.destroy(); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow2.isValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + glWindow1.invalidate(); + Assert.assertEquals(false, glWindow1.isValid()); + Assert.assertEquals(false, glWindow2.isValid()); + + // test double destroy/invalidate .. + glWindow2.invalidate(); + Assert.assertEquals(false, glWindow2.isValid()); + + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + } + + @Test + public void testWindowParenting02ReparentTop2WinReparentRecreate() throws InterruptedException { + testWindowParenting02ReparentTop2WinImpl(true); + } + + @Test + public void testWindowParenting02ReparentTop2WinReparentNative() throws InterruptedException { + testWindowParenting02ReparentTop2WinImpl(false); + } + + /** + * @param reparentRecreate true, if the followup reparent should utilize destroy/create, instead of native reparenting + */ + protected void testWindowParenting02ReparentTop2WinImpl(boolean reparentRecreate) throws InterruptedException { + int x = 0; + int y = 0; + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Display display1 = null; + Screen screen1 = null; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.setTitle("testWindowParenting02ReparentTop2Win"); + glWindow1.setSize(640, 480); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + screen1 = glWindow1.getScreen(); + display1 = screen1.getDisplay(); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + GLWindow glWindow2 = GLWindow.create(glCaps); + glWindow2.setSize(320, 240); + GLEventListener demo2 = new Gears(); + setDemoFields(demo2, glWindow2, false); + glWindow2.addGLEventListener(demo2); + Assert.assertSame(screen1, glWindow2.getScreen()); + Assert.assertSame(display1, glWindow2.getScreen().getDisplay()); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + Assert.assertEquals(0, glWindow1.getTotalFrames()); + glWindow1.setVisible(true); + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(true, glWindow1.isVisible()); + System.err.println("Frames for setVisible(true) A1: "+glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + + Assert.assertEquals(0, glWindow2.getTotalFrames()); + glWindow2.setVisible(true); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + Assert.assertEquals(true, glWindow2.isVisible()); + System.err.println("Frames for setVisible(true) B1: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + Animator animator2 = new Animator(glWindow2); + animator2.start(); + + int state = 0; + int reparentAction; + while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + // glWindow2 -- child --> glWindow1: compatible + Assert.assertEquals(true, glWindow2.isVisible()); + System.err.println("Frames(1) "+glWindow2.getTotalFrames()); + reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate); + System.err.println("Frames(2) "+glWindow2.getTotalFrames()); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + break; + + case 1: + // glWindow2 --> top + Assert.assertEquals(true, glWindow2.isVisible()); + + reparentAction = glWindow2.reparentWindow(null, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + Assert.assertNull(glWindow2.getParent()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + break; + } + state++; + } + // + // both windows are now top level + // + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + animator2.stop(); + Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertEquals(null, animator2.getThread()); + + // pre-destroy check (both valid and running) + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + // destroy glWindow2 + glWindow2.destroy(); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow2.isValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + // destroy glWindow1 + glWindow1.destroy(); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow2.isValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(false,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + glWindow1.invalidate(); + Assert.assertEquals(false, glWindow1.isValid()); + Assert.assertEquals(true, glWindow2.isValid()); + + glWindow2.invalidate(); + Assert.assertEquals(false, glWindow2.isValid()); + } + + @Test + public void testWindowParenting03ReparentWin2TopReparentRecreate() throws InterruptedException { + testWindowParenting03ReparentWin2TopImpl(true); + } + + @Test + public void testWindowParenting03ReparentWin2TopReparentNative() throws InterruptedException { + testWindowParenting03ReparentWin2TopImpl(false); + } + + protected void testWindowParenting03ReparentWin2TopImpl(boolean reparentRecreate) throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Display display1 = null; + Screen screen1 = null; + Display display2 = null; + Screen screen2 = null; + + GLWindow glWindow1 = GLWindow.create(glCaps); + screen1 = glWindow1.getScreen(); + display1 = screen1.getDisplay(); + glWindow1.setTitle("testWindowParenting03ReparentWin2Top"); + glWindow1.setSize(640, 480); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps); + screen2 = glWindow2.getScreen(); + display2 = screen2.getDisplay(); + glWindow2.setSize(320, 240); + GLEventListener demo2 = new Gears(); + setDemoFields(demo2, glWindow2, false); + glWindow2.addGLEventListener(demo2); + + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertNotNull(display2.getEDTUtil()); + Assert.assertEquals(true,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); + glWindow1.setVisible(true); + System.err.println("Frames for setVisible(): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + Animator animator2 = new Animator(glWindow2); + animator2.start(); + + int state = 0; + int reparentAction; + while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + Assert.assertEquals(true, glWindow2.isVisible()); + reparentAction = glWindow2.reparentWindow(null, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + Assert.assertNull(glWindow2.getParent()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + break; + case 1: + Assert.assertEquals(true, glWindow2.isVisible()); + reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3 "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + break; + } + state++; + } + // + // glwindow2 is child of glwindow1 + // + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + animator2.stop(); + Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertEquals(null, animator2.getThread()); + + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParent()); + Assert.assertSame(screen1,glWindow2.getScreen()); + + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + glWindow1.destroy(); // should destroy both windows, actually, since glWindow2 is a child + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow2.isValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(false,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertNotNull(display2.getEDTUtil()); + Assert.assertEquals(false,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + glWindow2.destroy(); // dbl destroy check .. + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + + glWindow1.invalidate(); // parent -> child + Assert.assertEquals(false, glWindow1.isValid()); + Assert.assertEquals(false, glWindow2.isValid()); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + System.err.println("durationPerTest: "+durationPerTest); + String tstname = TestParenting01NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} + diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java new file mode 100644 index 000000000..424fff0e2 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java @@ -0,0 +1,443 @@ +/** + * 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.newt.parenting; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Container; +import java.awt.Frame; +import java.awt.Dimension; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting01aAWT extends UITestCase { + static int width, height; + static long durationPerTest = 800; + static long waitReparent = 0; + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() throws InterruptedException { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glCaps = new GLCapabilities(null); + // Thread.sleep(10000); + } + + @Test + public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + Assert.assertNotNull(glWindow1); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + Assert.assertNotNull(newtCanvasAWT); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + + Frame frame1 = new Frame("AWT Parent Frame"); + frame1.setLayout(new BorderLayout()); + frame1.add(new Button("North"), BorderLayout.NORTH); + frame1.add(new Button("South"), BorderLayout.SOUTH); + frame1.add(new Button("East"), BorderLayout.EAST); + frame1.add(new Button("West"), BorderLayout.WEST); + + Container container1 = new Container(); + container1.setLayout(new BorderLayout()); + container1.add(new Button("north"), BorderLayout.NORTH); + container1.add(new Button("south"), BorderLayout.SOUTH); + container1.add(new Button("east"), BorderLayout.EAST); + container1.add(new Button("west"), BorderLayout.WEST); + container1.add(newtCanvasAWT, BorderLayout.CENTER); + + frame1.add(container1, BorderLayout.CENTER); + frame1.setSize(width, height); + + // visible test + frame1.setVisible(true); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { + Thread.sleep(100); + } + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + + frame1.setVisible(false); + Assert.assertEquals(true, glWindow1.isValid()); + + frame1.setVisible(true); + Assert.assertEquals(true, glWindow1.isValid()); + + frame1.remove(newtCanvasAWT); + // Assert.assertNull(glWindow1.getParent()); + Assert.assertEquals(true, glWindow1.isValid()); + + frame1.dispose(); + Assert.assertEquals(true, glWindow1.isValid()); + + glWindow1.invalidate(); + //Assert.assertEquals(false, glWindow1.isValid()); + } + + @Test + public void testWindowParenting02CreateVisibleDestroy2Defered() throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + Assert.assertNotNull(glWindow1); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + Assert.assertNotNull(newtCanvasAWT); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + + Frame frame = new Frame("AWT Parent Frame"); + Assert.assertNotNull(frame); + frame.setSize(width, height); + + // visible test + frame.setVisible(true); + + frame.add(newtCanvasAWT); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { + Thread.sleep(100); + } + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + + frame.dispose(); + glWindow1.invalidate(); + } + + @Test + public void testWindowParenting02CreateVisibleDestroy3Odd() throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + + Frame frame = new Frame("AWT Parent Frame"); + Assert.assertNotNull(frame); + frame.setSize(width, height); + + // visible test + frame.setVisible(true); + + frame.add(newtCanvasAWT); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + Assert.assertEquals(true, animator1.isStarted()); + Assert.assertEquals(true, animator1.isAnimating()); + while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { + Thread.sleep(100); + } + + Assert.assertEquals(true, animator1.isAnimating()); // !!! + + frame.dispose(); + glWindow1.invalidate(); + } + + @Test + public void testWindowParenting03ReparentNewtWin2Top() throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + + Frame frame = new Frame("AWT Parent Frame"); + frame.setSize(width, height); + frame.setLocation(640, 480); + frame.setVisible(true); + + frame.add(newtCanvasAWT); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + + int state = 0; + while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + glWindow1.reparentWindow(null); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + break; + case 1: + glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + break; + } + state++; + } + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + + frame.dispose(); + glWindow1.invalidate(); + } + + @Test + public void testWindowParenting04ReparentNewtWin2TopLayouted() throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + + Frame frame = new Frame("AWT Parent Frame"); + frame.setLayout(new BorderLayout()); + frame.add(new Button("North"), BorderLayout.NORTH); + frame.add(new Button("South"), BorderLayout.SOUTH); + frame.add(new Button("East"), BorderLayout.EAST); + frame.add(new Button("West"), BorderLayout.WEST); + frame.setSize(width, height); + frame.setLocation(640, 480); + frame.setVisible(true); + + frame.add(newtCanvasAWT, BorderLayout.CENTER); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + + int state = 0; + while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + glWindow1.reparentWindow(null); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + break; + case 1: + glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + break; + } + state++; + } + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + + frame.dispose(); + glWindow1.invalidate(); + } + + @Test + public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.setUndecorated(true); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + + Frame frame1 = new Frame("AWT Parent Frame"); + frame1.setLayout(new BorderLayout()); + frame1.add(new Button("North"), BorderLayout.NORTH); + frame1.add(new Button("South"), BorderLayout.SOUTH); + frame1.add(new Button("East"), BorderLayout.EAST); + frame1.add(new Button("West"), BorderLayout.WEST); + frame1.setSize(width, height); + frame1.setLocation(0, 0); + frame1.setVisible(true); + + Frame frame2 = new Frame("AWT Parent Frame"); + frame2.setLayout(new BorderLayout()); + frame2.add(new Button("North"), BorderLayout.NORTH); + frame2.add(new Button("South"), BorderLayout.SOUTH); + frame2.add(new Button("East"), BorderLayout.EAST); + frame2.add(new Button("West"), BorderLayout.WEST); + frame2.setSize(width, height); + frame2.setLocation(640, 480); + frame2.setVisible(true); + + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + + int state = 0; + while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + frame1.remove(newtCanvasAWT); + frame2.add(newtCanvasAWT, BorderLayout.CENTER); + break; + case 1: + frame2.remove(newtCanvasAWT); + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + break; + } + state++; + } + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + + frame1.dispose(); + frame2.dispose(); + glWindow1.invalidate(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } else if(args[i].equals("-wait")) { + waitReparent = atoi(args[++i]); + } + } + String tstname = TestParenting01aAWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java new file mode 100644 index 000000000..2b8d34423 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java @@ -0,0 +1,205 @@ +/** + * 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.newt.parenting; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Frame; +import java.awt.Dimension; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.FPSAnimator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting01bAWT extends UITestCase { + static int width, height; + static long durationPerTest = 800; + static long waitReparent = 0; + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glCaps = new GLCapabilities(null); + } + + @Test + public void testWindowParenting05ReparentAWTWinHopFrame2FrameFPS25Animator() throws InterruptedException { + testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(25); + } + + @Test + public void testWindowParenting05ReparentAWTWinHopFrame2FrameStdAnimator() throws InterruptedException { + testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(0); + } + + public void testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(int fps) throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.setUndecorated(true); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + + Frame frame1 = new Frame("AWT Parent Frame"); + frame1.setLayout(new BorderLayout()); + frame1.add(new Button("North"), BorderLayout.NORTH); + frame1.add(new Button("South"), BorderLayout.SOUTH); + frame1.add(new Button("East"), BorderLayout.EAST); + frame1.add(new Button("West"), BorderLayout.WEST); + frame1.setSize(width, height); + frame1.setLocation(0, 0); + frame1.setVisible(true); + + Frame frame2 = new Frame("AWT Parent Frame"); + frame2.setLayout(new BorderLayout()); + frame2.add(new Button("North"), BorderLayout.NORTH); + frame2.add(new Button("South"), BorderLayout.SOUTH); + frame2.add(new Button("East"), BorderLayout.EAST); + frame2.add(new Button("West"), BorderLayout.WEST); + frame2.setSize(width, height); + frame2.setLocation(640, 480); + frame2.setVisible(true); + + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + GLAnimatorControl animator1; + if(fps>0) { + animator1 = new FPSAnimator(glWindow1, fps); + } else { + animator1 = new Animator(glWindow1); + } + animator1.start(); + + int state; + for(state=0; state<3; state++) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + frame1.remove(newtCanvasAWT); + frame2.add(newtCanvasAWT, BorderLayout.CENTER); + break; + case 1: + frame2.remove(newtCanvasAWT); + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + break; + } + } + + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + + frame1.dispose(); + frame2.dispose(); + glWindow1.invalidate(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } else if(args[i].equals("-wait")) { + waitReparent = atoi(args[++i]); + } + } + String tstname = TestParenting01bAWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java new file mode 100644 index 000000000..7321c6ba2 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java @@ -0,0 +1,243 @@ +/** + * 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.newt.parenting; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Container; +import java.awt.Frame; +import java.awt.Dimension; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting01cAWT extends UITestCase { + static int width, height; + static long durationPerTest = 800; + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glCaps = new GLCapabilities(null); + } + + @Test + public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException { + int x = 0; + int y = 0; + int i; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + Assert.assertNotNull(glWindow1); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + Assert.assertNotNull(newtCanvasAWT); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + + Frame frame1 = new Frame("AWT Parent Frame"); + frame1.setLayout(new BorderLayout()); + frame1.add(new Button("North"), BorderLayout.NORTH); + frame1.add(new Button("South"), BorderLayout.SOUTH); + frame1.add(new Button("East"), BorderLayout.EAST); + frame1.add(new Button("West"), BorderLayout.WEST); + + Container container1 = new Container(); + container1.setLayout(new BorderLayout()); + container1.add(new Button("north"), BorderLayout.NORTH); + container1.add(new Button("south"), BorderLayout.SOUTH); + container1.add(new Button("east"), BorderLayout.EAST); + container1.add(new Button("west"), BorderLayout.WEST); + container1.add(newtCanvasAWT, BorderLayout.CENTER); + + frame1.add(container1, BorderLayout.CENTER); + frame1.setSize(width, height); + + // visible test + frame1.setVisible(true); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + for(i=0; i*100<durationPerTest; i++) { + Thread.sleep(100); + } + + frame1.setVisible(false); + Assert.assertEquals(true, glWindow1.isValid()); + + frame1.setVisible(true); + Assert.assertEquals(true, glWindow1.isValid()); + + frame1.remove(newtCanvasAWT); + // Assert.assertNull(glWindow1.getParent()); + Assert.assertEquals(true, glWindow1.isValid()); + + frame1.dispose(); + Assert.assertEquals(true, glWindow1.isValid()); + + glWindow1.invalidate(); + //Assert.assertEquals(false, glWindow1.isValid()); + } + + @Test + public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.setUndecorated(true); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + + Frame frame1 = new Frame("AWT Parent Frame"); + frame1.setLayout(new BorderLayout()); + frame1.add(new Button("North"), BorderLayout.NORTH); + frame1.add(new Button("South"), BorderLayout.SOUTH); + frame1.add(new Button("East"), BorderLayout.EAST); + frame1.add(new Button("West"), BorderLayout.WEST); + frame1.setSize(width, height); + frame1.setLocation(0, 0); + frame1.setVisible(true); + + Frame frame2 = new Frame("AWT Parent Frame"); + frame2.setLayout(new BorderLayout()); + frame2.add(new Button("North"), BorderLayout.NORTH); + frame2.add(new Button("South"), BorderLayout.SOUTH); + frame2.add(new Button("East"), BorderLayout.EAST); + frame2.add(new Button("West"), BorderLayout.WEST); + frame2.setSize(width, height); + frame2.setLocation(640, 480); + frame2.setVisible(true); + + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + int state; + for(state=0; state<3; state++) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + frame1.remove(newtCanvasAWT); + frame2.add(newtCanvasAWT, BorderLayout.CENTER); + break; + case 1: + frame2.remove(newtCanvasAWT); + frame1.add(newtCanvasAWT, BorderLayout.CENTER); + break; + } + } + + frame1.dispose(); + frame2.dispose(); + glWindow1.invalidate(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + String tstname = TestParenting01cAWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java new file mode 100644 index 000000000..1c155f75a --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java @@ -0,0 +1,365 @@ +/** + * 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.newt.parenting; + +import java.lang.reflect.*; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Container; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; + +public class TestParenting01cSwingAWT extends UITestCase { + static int width, height; + static long durationPerTest = 800; + static long waitReparent = 0; + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + glCaps = new GLCapabilities(null); + } + + @Test + public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + /** + * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow + */ + GLWindow glWindow1 = GLWindow.create(glCaps); + Assert.assertNotNull(glWindow1); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + Animator animator1 = new Animator(glWindow1); + animator1.start(); + final GLWindow _glWindow1 = glWindow1; + final GLRunnable _glRunnable = new GLRunnableDummy(); + Thread disturbanceThread = new Thread(new Runnable() { + public void run() { + System.out.println("$"); + while(true) + { + try { + _glWindow1.invoke(true, _glRunnable); + Thread.yield(); + } catch (Throwable t) {} + } + } + }); + disturbanceThread.start(); + + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + Assert.assertNotNull(newtCanvasAWT); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + + Container container1 = new Container(); + container1.setLayout(new BorderLayout()); + container1.add(new Button("north"), BorderLayout.NORTH); + container1.add(new Button("south"), BorderLayout.SOUTH); + container1.add(new Button("east"), BorderLayout.EAST); + container1.add(new Button("west"), BorderLayout.WEST); + container1.add(newtCanvasAWT, BorderLayout.CENTER); + + JPanel jPanel1 = new JPanel(); + jPanel1.setLayout(new BorderLayout()); + jPanel1.add(new Button("north"), BorderLayout.NORTH); + jPanel1.add(new Button("south"), BorderLayout.SOUTH); + jPanel1.add(new Button("east"), BorderLayout.EAST); + jPanel1.add(new Button("west"), BorderLayout.WEST); + jPanel1.add(container1, BorderLayout.CENTER); + + JFrame jFrame1 = new JFrame("Swing Parent JFrame"); + // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event! + jFrame1.setContentPane(jPanel1); + jFrame1.setSize(width, height); + System.out.println("Demos: 1 - Visible"); + jFrame1.setVisible(true); // from here on, we need to run modifications on EDT + + final JFrame _jFrame1 = jFrame1; + final JPanel _jPanel1 = jPanel1; + final Container _container1 = container1; + + // visible test + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { + Thread.sleep(100); + } + System.out.println("Demos: 2 - StopAnimator"); + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + System.out.println("Demos: 3 - !Visible"); + _jFrame1.setVisible(false); + } }); + Assert.assertEquals(true, glWindow1.isValid()); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + System.out.println("Demos: 4 - Visible"); + _jFrame1.setVisible(true); + } }); + Assert.assertEquals(true, glWindow1.isValid()); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + System.out.println("Demos: 5 - X Container"); + _jPanel1.remove(_container1); + } }); + // Assert.assertNull(glWindow1.getParent()); + Assert.assertEquals(true, glWindow1.isValid()); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _jFrame1.dispose(); + } }); + Assert.assertEquals(true, glWindow1.isValid()); + + glWindow1.invalidate(); + //Assert.assertEquals(false, glWindow1.isValid()); + } + + @Test + public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException, InvocationTargetException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + /** + * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow + */ + GLWindow glWindow1 = GLWindow.create(glCaps); + Assert.assertNotNull(glWindow1); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + Animator animator1 = new Animator(glWindow1); + animator1.start(); + final GLWindow _glWindow1 = glWindow1; + final GLRunnable _glRunnable = new GLRunnableDummy(); + Thread disturbanceThread = new Thread(new Runnable() { + public void run() { + System.out.println("$"); + while(true) + { + try { + _glWindow1.invoke(true, _glRunnable); + Thread.yield(); + } catch (Throwable t) {} + } + } + }); + disturbanceThread.start(); + + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); + Assert.assertNotNull(newtCanvasAWT); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertNull(glWindow1.getParent()); + + Container container1 = new Container(); + container1.setLayout(new BorderLayout()); + container1.add(new Button("north"), BorderLayout.NORTH); + container1.add(new Button("south"), BorderLayout.SOUTH); + container1.add(new Button("east"), BorderLayout.EAST); + container1.add(new Button("west"), BorderLayout.WEST); + container1.add(newtCanvasAWT, BorderLayout.CENTER); + + JPanel jPanel1 = new JPanel(); + jPanel1.setLayout(new BorderLayout()); + jPanel1.add(new Button("north"), BorderLayout.NORTH); + jPanel1.add(new Button("south"), BorderLayout.SOUTH); + jPanel1.add(new Button("east"), BorderLayout.EAST); + jPanel1.add(new Button("west"), BorderLayout.WEST); + jPanel1.add(container1, BorderLayout.CENTER); + + JFrame jFrame1 = new JFrame("Swing Parent JFrame"); + // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event! + jFrame1.setContentPane(jPanel1); + jFrame1.setLocation(0, 0); + jFrame1.setSize(width, height); + jFrame1.setVisible(true); // from here on, we need to run modifications on EDT + + JPanel jPanel2 = new JPanel(); + jPanel2.setLayout(new BorderLayout()); + jPanel2.add(new Button("north"), BorderLayout.NORTH); + jPanel2.add(new Button("south"), BorderLayout.SOUTH); + jPanel2.add(new Button("east"), BorderLayout.EAST); + jPanel2.add(new Button("west"), BorderLayout.WEST); + + JFrame jFrame2 = new JFrame("Swing Parent JFrame"); + // jFrame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jFrame2.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event! + jFrame2.setContentPane(jPanel2); + jFrame2.setLocation(640, 480); + jFrame2.setSize(width, height); + jFrame2.setVisible(true); // from here on, we need to run modifications on EDT + + final NewtCanvasAWT _newtCanvasAWT = newtCanvasAWT; + final JFrame _jFrame1 = jFrame1; + final JPanel _jPanel1 = jPanel1; + final Container _container1 = container1; + final JFrame _jFrame2 = jFrame2; + final JPanel _jPanel2 = jPanel2; + + // visible test + Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent()); + + int state = 0; + while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + Thread.sleep(durationPerTest); + switch(state) { + case 0: + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _container1.remove(_newtCanvasAWT); + _jPanel2.add(_newtCanvasAWT, BorderLayout.CENTER); + } }); + break; + case 1: + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _jPanel2.remove(_newtCanvasAWT); + _container1.add(_newtCanvasAWT, BorderLayout.CENTER); + } }); + break; + } + state++; + } + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _jFrame1.setVisible(false); + _jFrame2.setVisible(false); + } }); + Assert.assertEquals(true, glWindow1.isValid()); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _jFrame1.dispose(); + _jFrame2.dispose(); + } }); + Assert.assertEquals(true, glWindow1.isValid()); + + glWindow1.invalidate(); + //Assert.assertEquals(false, glWindow1.isValid()); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } else if(args[i].equals("-wait")) { + waitReparent = atoi(args[++i]); + } + } + System.out.println("durationPerTest "+durationPerTest); + System.out.println("waitReparent "+waitReparent); + String tstname = TestParenting01cSwingAWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java new file mode 100644 index 000000000..20388e295 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java @@ -0,0 +1,267 @@ +/** + * 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.newt.parenting; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Frame; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting02AWT extends UITestCase { + static int width, height; + static long durationPerTest = 500; + static long waitReparent = 300; + static boolean verbose = false; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + } + + @Test + public void testWindowParenting01NewtChildOnAWTParentLayouted() throws InterruptedException { + runNewtChildOnAWTParent(true, false); + } + + @Test + public void testWindowParenting02NewtChildOnAWTParentLayoutedDef() throws InterruptedException { + runNewtChildOnAWTParent(true, true); + } + + @Test + public void testWindowParenting03NewtChildOnAWTParentDirect() throws InterruptedException { + runNewtChildOnAWTParent(false, false); + } + + @Test + public void testWindowParenting04NewtChildOnAWTParentDirectDef() throws InterruptedException { + runNewtChildOnAWTParent(false, true); + } + + public void runNewtChildOnAWTParent(boolean useLayout, boolean deferredPeer) throws InterruptedException { + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + // setup NEWT GLWindow .. + GLWindow glWindow = GLWindow.create(new GLCapabilities(null)); + Assert.assertNotNull(glWindow); + glWindow.setTitle("NEWT - CHILD"); + glWindow.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo))); + glWindow.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo))); + GLEventListener demo = new Gears(); + setDemoFields(demo, glWindow, false); + glWindow.addGLEventListener(demo); + + // attach NEWT GLWindow to AWT Canvas + NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow); + Assert.assertNotNull(newtCanvasAWT); + Assert.assertEquals(false, glWindow.isVisible()); + Assert.assertEquals(false, glWindow.isNativeValid()); + Assert.assertNull(glWindow.getParent()); + + Frame frame = new Frame("AWT Parent Frame"); + Assert.assertNotNull(frame); + if(useLayout) { + frame.setLayout(new BorderLayout()); + frame.add(new Button("North"), BorderLayout.NORTH); + frame.add(new Button("South"), BorderLayout.SOUTH); + frame.add(new Button("East"), BorderLayout.EAST); + frame.add(new Button("West"), BorderLayout.WEST); + if(!deferredPeer) { + frame.add(newtCanvasAWT, BorderLayout.CENTER); + } + } else { + if(!deferredPeer) { + frame.add(newtCanvasAWT); + } + } + + frame.setSize(width, height); + + frame.setVisible(true); + // X11: true, Windows: false - Assert.assertEquals(true, glWindow.isVisible()); + + if(deferredPeer) { + if(useLayout) { + frame.add(newtCanvasAWT, BorderLayout.CENTER); + } else { + frame.add(newtCanvasAWT); + } + } + + // Since it is not defined when AWT's addNotify call happen + // we just have to wait for it in this junit test + // because we have assertions on the state. + // Regular application shall not need to do that. + do { + Thread.yield(); + // 1st display .. creation + glWindow.display(); + } while(!glWindow.isNativeValid()) ; + + Assert.assertEquals(true, glWindow.isNativeValid()); + Assert.assertNotNull(glWindow.getParent()); + if(verbose) { + System.out.println("+++++++++++++++++++ 1st ADDED"); + } + Thread.sleep(waitReparent); + + if(useLayout) { + // test some fancy re-layout .. + frame.remove(newtCanvasAWT); + Assert.assertEquals(false, glWindow.isVisible()); + Assert.assertEquals(true, glWindow.isNativeValid()); + Assert.assertNull(glWindow.getParent()); + if(verbose) { + System.out.println("+++++++++++++++++++ REMOVED!"); + } + Thread.sleep(waitReparent); + + // should recreate properly .. + frame.add(newtCanvasAWT, BorderLayout.CENTER); + glWindow.display(); + Assert.assertEquals(true, glWindow.isVisible()); + Assert.assertEquals(true, glWindow.isNativeValid()); + Assert.assertNotNull(glWindow.getParent()); + if(verbose) { + System.out.println("+++++++++++++++++++ 2nd ADDED"); + } + Thread.sleep(waitReparent); + } + + long duration = durationPerTest; + long step = 20; + NEWTEvent event; + boolean shouldQuit = false; + + while (duration>0 && !shouldQuit) { + glWindow.display(); + Thread.sleep(step); + duration -= step; + + while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { + Window source = (Window) event.getSource(); + if(event instanceof KeyEvent) { + KeyEvent keyEvent = (KeyEvent) event; + switch(keyEvent.getKeyChar()) { + case 'q': + shouldQuit = true; + break; + case 'f': + source.setFullscreen(!source.isFullscreen()); + break; + } + } + } + } + if(verbose) { + System.out.println("+++++++++++++++++++ END"); + } + Thread.sleep(waitReparent); + + glWindow.invalidate(); + if(useLayout) { + frame.remove(newtCanvasAWT); + } + frame.dispose(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + verbose = true; + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } else if(args[i].equals("-wait")) { + waitReparent = atoi(args[++i]); + } + } + String tstname = TestParenting02AWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java new file mode 100644 index 000000000..b9bd2d93d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java @@ -0,0 +1,235 @@ +/** + * 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.newt.parenting; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.*; + +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting02NEWT extends UITestCase { + static int width, height; + static long durationPerTest = 500; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 640; + height = 480; + } + + static Window createWindow(Screen screen, Capabilities caps) { + Assert.assertNotNull(caps); + Window window = NewtFactory.createWindow(screen, caps) ; + Assert.assertNotNull(window); + return window; + } + + static Window createWindow(NativeWindow parent, Capabilities caps) { + Assert.assertNotNull(caps); + Window window = NewtFactory.createWindow(parent, caps); + window.setUndecorated(true); + Assert.assertNotNull(window); + return window; + } + + static void destroyWindow(Display display, Screen screen, Window window, GLWindow glWindow) { + if(null!=glWindow) { + glWindow.destroy(); + } + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void testWindowParenting01NewtOnNewtParentChildDraw() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(null); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + int x = 1; + int y = 1; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + Window window1 = createWindow(screen, caps); + Assert.assertNotNull(window1); + GLWindow glWindow1 = GLWindow.create(window1); + Assert.assertNotNull(glWindow1); + glWindow1.setSize(width, height); + Assert.assertEquals(width,glWindow1.getWidth()); + Assert.assertEquals(height,glWindow1.getHeight()); + glWindow1.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - PARENT"); + glWindow1.setPosition(x,y); + glWindow1.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo))); + glWindow1.addWindowListener(new TraceWindowAdapter()); + + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, window1, glWindow1, false); + // glWindow1.addGLEventListener(demo1); + + glWindow1.setVisible(true); + CapabilitiesImmutable capsChosen = glWindow1.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(capsChosen); + Assert.assertTrue(capsChosen.isOnscreen()==true); + + Window window2 = createWindow(window1, caps); + Assert.assertNotNull(window2); + GLWindow glWindow2 = GLWindow.create(window2); + Assert.assertNotNull(glWindow2); + glWindow2.setSize(width/2, height/2); + //Assert.assertEquals(width/2,glWindow2.getWidth()); + //Assert.assertEquals(height/2,glWindow2.getHeight()); + glWindow2.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - CHILD"); + glWindow2.setPosition(glWindow1.getWidth()/2, glWindow1.getHeight()/2); + glWindow2.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo))); + glWindow2.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo))); + // glWindow2.addMouseListener(new TraceMouseAdapter()); + + GLEventListener demo2 = new Gears(); + setDemoFields(demo2, window2, glWindow2, false); + // glWindow2.addGLEventListener(demo2); + + glWindow2.setVisible(true); + capsChosen = glWindow2.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(capsChosen); + Assert.assertTrue(capsChosen.isOnscreen()==true); + + glWindow1.addGLEventListener(demo1); + glWindow2.addGLEventListener(demo2); + + boolean shouldQuit = false; + long duration = durationPerTest; + long step = 20; + NEWTEvent event; + + while (duration>0 && !shouldQuit) { + glWindow1.display(); + glWindow2.display(); + Thread.sleep(step); + duration -= step; + x += 1; + y += 1; + glWindow1.setPosition(x,y); + glWindow2.setPosition(glWindow1.getWidth()/2,glWindow1.getHeight()/2-y); + + while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { + Window source = (Window) event.getSource(); + if(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY == event.getEventType()) { + shouldQuit = true; + } else if(event instanceof KeyEvent) { + KeyEvent keyEvent = (KeyEvent) event; + switch(keyEvent.getKeyChar()) { + case 'q': + shouldQuit = true; + break; + case 'f': + source.setFullscreen(!source.isFullscreen()); + break; + } + } + } + } + destroyWindow(null, null, window2, glWindow2); + destroyWindow(display, screen, window1, glWindow1); + } + + public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(window); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + String tstname = TestParenting02NEWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java new file mode 100644 index 000000000..7da30cf18 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java @@ -0,0 +1,203 @@ +/** + * 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.newt.parenting; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Label; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.FPSAnimator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting03AWT extends UITestCase { + static Dimension size; + static long durationPerTest = 400; + static long waitAdd2nd = 200; + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + size = new Dimension(400,200); + glCaps = new GLCapabilities(null); + glCaps.setAlphaBits(8); + glCaps.setBackgroundOpaque(false); + } + + @Test + public void testWindowParenting1AWTOneNewtChild01() throws InterruptedException, InvocationTargetException { + testWindowParenting1AWTOneNewtChild(); + } + + public void testWindowParenting1AWTOneNewtChild() throws InterruptedException, InvocationTargetException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.enablePerfLog(true); + glWindow1.setUndecorated(true); + NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); + newtCanvasAWT1.setPreferredSize(size); + + GLEventListener demo1 = new Gears(1); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + final NewtCanvasAWT f_newtCanvasAWT1 = newtCanvasAWT1; + final GLWindow f_glWindow1 = glWindow1; + glWindow1.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + if(e.getKeyChar()=='d') { + f_glWindow1.setUndecorated(!f_glWindow1.isUndecorated()); + } else if(e.getKeyChar()=='f') { + f_glWindow1.setFullscreen(!f_glWindow1.isFullscreen()); + } else if(e.getKeyChar()=='r') { + if(f_glWindow1.getParent()==null) { + System.err.println("XXX glWin1 to home"); + f_glWindow1.reparentWindow(f_newtCanvasAWT1.getNativeWindow()); + } else { + System.err.println("XXX glWin1 to TOP"); + f_glWindow1.reparentWindow(null); + } + } + } + }); + GLAnimatorControl animator1 = new Animator(glWindow1); + animator1.start(); + + Container cont1 = new Container(); + cont1.setLayout(new BorderLayout()); + cont1.add(newtCanvasAWT1, BorderLayout.CENTER); + cont1.setVisible(true); + final Container f_cont1 = cont1; + + Frame frame1 = new Frame("AWT Parent Frame"); + frame1.setLayout(new BorderLayout()); + frame1.add(cont1, BorderLayout.EAST); + frame1.add(new Label("center"), BorderLayout.CENTER); + frame1.setLocation(0, 0); + frame1.setSize((int)size.getWidth(), (int)size.getHeight()); + final Frame f_frame1 = frame1; + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + f_frame1.pack(); + f_frame1.setVisible(true); + }}); + + Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent()); + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); + + Thread.sleep(durationPerTest); + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + + frame1.dispose(); + glWindow1.invalidate(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } else if(args[i].equals("-wait")) { + waitAdd2nd = atoi(args[++i]); + } + } + String tstname = TestParenting03AWT.class.getName(); + /* + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */ + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03bAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03bAWT.java new file mode 100644 index 000000000..34d95d8ee --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03bAWT.java @@ -0,0 +1,258 @@ +/** + * 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.newt.parenting; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import java.awt.Button; +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Label; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.FPSAnimator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting03bAWT extends UITestCase { + static Dimension size; + static long durationPerTest = 800; + static long waitAdd2nd = 500; + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + size = new Dimension(400,200); + glCaps = new GLCapabilities(null); + } + + @Test + public void testWindowParenting1AWTTwoNewtChilds01() throws InterruptedException, InvocationTargetException { + testWindowParenting1AWTTwoNewtChilds(); + } + + public void testWindowParenting1AWTTwoNewtChilds() throws InterruptedException, InvocationTargetException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.enablePerfLog(true); + glWindow1.setUndecorated(true); + NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); + newtCanvasAWT1.setPreferredSize(size); + + GLEventListener demo1 = new Gears(1); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + final NewtCanvasAWT f_newtCanvasAWT1 = newtCanvasAWT1; + final GLWindow f_glWindow1 = glWindow1; + glWindow1.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + if(e.getKeyChar()=='d') { + f_glWindow1.setUndecorated(!f_glWindow1.isUndecorated()); + } else if(e.getKeyChar()=='f') { + f_glWindow1.setFullscreen(!f_glWindow1.isFullscreen()); + } else if(e.getKeyChar()=='r') { + if(f_glWindow1.getParent()==null) { + System.err.println("XXX glWin1 to home"); + f_glWindow1.reparentWindow(f_newtCanvasAWT1.getNativeWindow()); + } else { + System.err.println("XXX glWin1 to TOP"); + f_glWindow1.reparentWindow(null); + } + } + } + }); + GLAnimatorControl animator1 = new Animator(glWindow1); + animator1.start(); + + GLWindow glWindow2 = GLWindow.create(glCaps); + glWindow2.enablePerfLog(true); + glWindow2.setUndecorated(true); + NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2); + newtCanvasAWT2.setPreferredSize(size); + + GLEventListener demo2 = new Gears(1); + setDemoFields(demo2, glWindow2, false); + glWindow2.addGLEventListener(demo2); + final NewtCanvasAWT f_newtCanvasAWT2 = newtCanvasAWT2; + final GLWindow f_glWindow2 = glWindow2; + glWindow2.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + if(e.getKeyChar()=='d') { + f_glWindow2.setUndecorated(!f_glWindow2.isUndecorated()); + } else if(e.getKeyChar()=='f') { + f_glWindow2.setFullscreen(!f_glWindow2.isFullscreen()); + } else if(e.getKeyChar()=='r') { + if(f_glWindow2.getParent()==null) { + System.err.println("XXX glWin2 to home"); + f_glWindow2.reparentWindow(f_newtCanvasAWT2.getNativeWindow()); + } else { + System.err.println("XXX glWin2 to TOP"); + f_glWindow2.reparentWindow(null); + } + } + } + }); + GLAnimatorControl animator2 = new Animator(glWindow2); + animator2.start(); + + Container cont1 = new Container(); + cont1.setLayout(new BorderLayout()); + cont1.add(newtCanvasAWT1, BorderLayout.CENTER); + cont1.setVisible(true); + final Container f_cont1 = cont1; + + Container cont2 = new Container(); + cont2.setLayout(new BorderLayout()); + cont2.add(newtCanvasAWT2, BorderLayout.CENTER); + cont2.setVisible(true); + final Container f_cont2 = cont2; + + Frame frame1 = new Frame("AWT Parent Frame"); + frame1.setLayout(new BorderLayout()); + frame1.add(cont1, BorderLayout.EAST); + frame1.add(new Label("center"), BorderLayout.CENTER); + frame1.setLocation(0, 0); + frame1.setSize((int)size.getWidth()*2, (int)size.getHeight()*2); + final Frame f_frame1 = frame1; + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + f_frame1.pack(); + f_frame1.setVisible(true); + }}); + + Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent()); + Assert.assertEquals(newtCanvasAWT2.getNativeWindow(),glWindow2.getParent()); + + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); + + Assert.assertEquals(true, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertNotNull(animator2.getThread()); + + Thread.sleep(waitAdd2nd); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + f_frame1.add(f_cont2, BorderLayout.WEST); + f_frame1.pack(); + }}); + + Thread.sleep(durationPerTest); + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + + animator2.stop(); + Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertEquals(null, animator2.getThread()); + + frame1.dispose(); + glWindow1.invalidate(); + glWindow2.invalidate(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } else if(args[i].equals("-wait")) { + waitAdd2nd = atoi(args[++i]); + } + } + String tstname = TestParenting03bAWT.class.getName(); + /* + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */ + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/WindowAction.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/WindowAction.java new file mode 100644 index 000000000..05793b96e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/WindowAction.java @@ -0,0 +1,47 @@ +/** + * 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.newt.parenting; + +import com.jogamp.newt.event.*; + +class WindowAction extends WindowAdapter { + NEWTEventFiFo eventFifo; + + public WindowAction(NEWTEventFiFo eventFifo) { + this.eventFifo = eventFifo; + } + + public void windowDestroyNotify(WindowEvent e) { + eventFifo.put(e); + } + public void windowDestroyed(WindowEvent e) { + eventFifo.put(e); + } +} + diff --git a/src/jogamp/graph/curve/tess/GraphOutline.java b/src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java index 5dae296e5..9e5a01ebb 100644 --- a/src/jogamp/graph/curve/tess/GraphOutline.java +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java @@ -3,14 +3,14 @@ * * 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 @@ -20,62 +20,54 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package jogamp.graph.curve.tess; + +package com.jogamp.opengl.test.junit.util; + +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; -import java.util.ArrayList; +public class AWTFocusAdapter implements EventCountAdapter, FocusListener { -import com.jogamp.graph.geom.Outline; -import com.jogamp.graph.geom.Vertex; + String prefix; + int focusGained; + boolean wasTemporary; -public class GraphOutline { - final private Outline outline; - final private ArrayList<GraphVertex> controlpoints = new ArrayList<GraphVertex>(3); - - public GraphOutline(){ - this.outline = new Outline(); - } - - /**Create a control polyline of control vertices - * the curve pieces can be identified by onCurve flag - * of each cp the control polyline is open by default - */ - public GraphOutline(Outline ol){ - this.outline = ol; - ArrayList<Vertex> vertices = this.outline.getVertices(); - for(Vertex v:vertices){ - this.controlpoints.add(new GraphVertex(v)); - } - } + public AWTFocusAdapter(String prefix) { + this.prefix = prefix; + reset(); + } - public Outline getOutline() { - return outline; - } + /** @return the balance of focus gained/lost, ie should be 0 or 1 */ + public int getCount() { + return focusGained; + } - /*public void setOutline(Outline<T> outline) { - this.outline = outline; - }*/ - + public void reset() { + focusGained = 0; + wasTemporary = false; + } - public ArrayList<GraphVertex> getGraphPoint() { - return controlpoints; - } - - public ArrayList<Vertex> getPoints() { - return outline.getVertices(); - } + /** @return true, if the last change was temporary */ + public boolean getWasTemporary() { + return wasTemporary; + } - /*public void setControlpoints(ArrayList<GraphPoint<T>> controlpoints) { - this.controlpoints = controlpoints; - }*/ + /* @Override */ + public void focusGained(FocusEvent e) { + ++focusGained; + wasTemporary = e.isTemporary(); + System.err.println("FOCUS AWT GAINED "+(wasTemporary?"TEMP":"PERM")+" ["+focusGained+"]: "+prefix+", "+e); + } - public void addVertex(GraphVertex v) { - controlpoints.add(v); - outline.addVertex(v.getPoint()); - } - + /* @Override */ + public void focusLost(FocusEvent e) { + --focusGained; + wasTemporary = e.isTemporary(); + System.err.println("FOCUS AWT LOST "+(wasTemporary?"TEMP":"PERM")+" ["+focusGained+"]: "+prefix+", "+e); + } } diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java new file mode 100644 index 000000000..ed09ecd8c --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java @@ -0,0 +1,54 @@ +/** + * 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.util; + +public class AWTKeyAdapter extends java.awt.event.KeyAdapter implements EventCountAdapter { + + String prefix; + int keyTyped; + + public AWTKeyAdapter(String prefix) { + this.prefix = prefix; + reset(); + } + + public int getCount() { + return keyTyped; + } + + public void reset() { + keyTyped = 0; + } + + public void keyTyped(java.awt.event.KeyEvent e) { + ++keyTyped; + System.err.println("KEY AWT TYPED ["+keyTyped+"]: "+prefix+", "+e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java new file mode 100644 index 000000000..7fa201512 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java @@ -0,0 +1,53 @@ +/** + * 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.util; + +public class AWTMouseAdapter extends java.awt.event.MouseAdapter implements EventCountAdapter { + String prefix; + int mouseClicked; + + public AWTMouseAdapter(String prefix) { + this.prefix = prefix; + reset(); + } + + public int getCount() { + return mouseClicked; + } + + public void reset() { + mouseClicked = 0; + } + + public void mouseClicked(java.awt.event.MouseEvent e) { + mouseClicked+=e.getClickCount(); + System.err.println("MOUSE AWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java new file mode 100644 index 000000000..d0f9172bc --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java @@ -0,0 +1,497 @@ +/** + * 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.util; + +import jogamp.newt.WindowImplAccess; +import java.lang.reflect.InvocationTargetException; +import java.awt.AWTException; +import java.awt.Component; +import java.awt.Container; +import java.awt.EventQueue; +import java.awt.KeyboardFocusManager; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.event.InputEvent; +import javax.media.opengl.awt.GLCanvas; +import javax.swing.JFrame; + +public class AWTRobotUtil { + + public static int TIME_OUT = 1000; // 1s + public static int ROBOT_DELAY = 50; // ms + public static int POLL_DIVIDER = 20; // TO/20 + + public static Point getCenterLocation(Object obj, boolean frameTitlebar) + throws InterruptedException, InvocationTargetException { + Component comp = null; + com.jogamp.newt.Window win = null; + + if(obj instanceof com.jogamp.newt.Window) { + win = (com.jogamp.newt.Window) obj; + } else if(obj instanceof Component) { + comp = (Component) obj; + } else { + throw new RuntimeException("Neither AWT nor NEWT: "+obj); + } + + int x0, y0; + if(null!=comp) { + Point p0 = comp.getLocationOnScreen(); + Rectangle r0 = comp.getBounds(); + if( frameTitlebar && comp instanceof JFrame ) { + JFrame jFrame = (JFrame) comp; + Container cont = jFrame.getContentPane(); + Point p1 = cont.getLocationOnScreen(); + int dx = (int) ( r0.getWidth() / 2.0 + .5 ); + int dy = (int) ( ( p1.getY() - p0.getY() ) / 2.0 + .5 ); + x0 = (int) ( p0.getX() + dx + .5 ) ; + y0 = (int) ( p0.getY() + dy + .5 ) ; + } else { + x0 = (int) ( p0.getX() + r0.getWidth() / 2.0 + .5 ) ; + y0 = (int) ( p0.getY() + r0.getHeight() / 2.0 + .5 ) ; + } + } else { + javax.media.nativewindow.util.Point p0 = win.getLocationOnScreen(null); + p0.translate(win.getWidth()/2, win.getHeight()/2); + x0 = p0.getX(); + y0 = p0.getY(); + } + + return new Point(x0, y0); + } + + /** + * toFront, call setVisible(true) and toFront(), + * after positioning the mouse in the middle of the window via robot. + * If the given robot is null, a new one is created (waitForIdle=true). + * + * @return True if the Window became the global focused Window within TIME_OUT + */ + public static boolean toFront(Robot robot, final java.awt.Window window) + throws AWTException, InterruptedException, InvocationTargetException { + + if(null == robot) { + robot = new Robot(); + robot.setAutoWaitForIdle(true); + } + Point p0 = getCenterLocation(window, false); + System.err.println("robot pos: "+p0); + robot.mouseMove( (int) p0.getX(), (int) p0.getY() ); + robot.delay(ROBOT_DELAY); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + window.setVisible(true); + window.toFront(); + window.requestFocus(); + }}); + robot.delay(ROBOT_DELAY); + + KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + int wait; + for (wait=0; wait<POLL_DIVIDER && window != kfm.getFocusedWindow(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + return wait<POLL_DIVIDER; + } + + /** + * centerMouse + */ + public static void centerMouse(Robot robot, Object obj) + throws AWTException, InterruptedException, InvocationTargetException { + + if(null == robot) { + robot = new Robot(); + robot.setAutoWaitForIdle(true); + } + + Point p0 = getCenterLocation(obj, false); + System.err.println("robot pos: "+p0); + + robot.mouseMove( (int) p0.getX(), (int) p0.getY() ); + robot.delay(ROBOT_DELAY); + } + + /** + * requestFocus, if robot is valid, use mouse operation, + * otherwise programatic, ie call requestFocus + */ + public static void requestFocus(Robot robot, Object obj) + throws AWTException, InterruptedException, InvocationTargetException { + Component comp = null; + com.jogamp.newt.Window win = null; + + if(obj instanceof com.jogamp.newt.Window) { + win = (com.jogamp.newt.Window) obj; + } else if(obj instanceof Component) { + comp = (Component) obj; + } else { + throw new RuntimeException("Neither AWT nor NEWT: "+obj); + } + + if(null == robot) { + if(null!=comp) { + final Component f_comp = comp; + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + f_comp.requestFocus(); + }}); + } else { + win.requestFocus(); + } + return; + } + + centerMouse(robot, obj); + + robot.delay(ROBOT_DELAY); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.delay(ROBOT_DELAY); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.delay(ROBOT_DELAY); + } + + /** + * + * @return True if the Window became the global focused Window within TIME_OUT + */ + public static boolean waitForFocus(Object obj) throws InterruptedException { + int wait; + if(obj instanceof Component) { + Component comp = (Component) obj; + KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + for (wait=0; wait<POLL_DIVIDER && comp != kfm.getPermanentFocusOwner(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + } else if(obj instanceof com.jogamp.newt.Window) { + com.jogamp.newt.Window win = (com.jogamp.newt.Window) obj; + for (wait=0; wait<POLL_DIVIDER && !win.hasFocus(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + } else { + throw new RuntimeException("Neither AWT nor NEWT: "+obj); + } + return wait<POLL_DIVIDER; + } + + /** + * + * @return True if the Window became the global focused Window within TIME_OUT + */ + public static boolean waitForFocus(Object obj, int gainT0, EventCountAdapter gain, + int lostT0, EventCountAdapter lost) throws InterruptedException { + if(!waitForFocus(obj)) { + return false; + } + int wait; + for (wait=0; wait<POLL_DIVIDER; wait++) { + int gainT1 = gain.getCount(); + int lostT1 = (null!=lost) ? lost.getCount() : -1; + if(gainT1-gainT0==1 && lostT1-lostT0==-1) { + return true; + } + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + return false; + } + + public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus) + throws AWTException, InterruptedException, InvocationTargetException { + + requestFocus(robot, requestFocus); + return waitForFocus(waitForFocus); + } + + public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus, + EventCountAdapter gain, EventCountAdapter lost) + throws AWTException, InterruptedException, InvocationTargetException { + + int gainT0 = gain.getCount(); + int lostT0 = (null!=lost) ? lost.getCount() : 0; + + requestFocus(robot, requestFocus); + return waitForFocus(waitForFocus, gainT0, gain, lostT0, lost); + } + + /** + * @param keyTypedCounter shall return the number of keys typed (press + release) + * @return True if typeCount keys within TIME_OUT has been received + */ + public static int testKeyType(Robot robot, int typeCount, Object obj, EventCountAdapter keyTypedCounter) + throws AWTException, InterruptedException, InvocationTargetException { + Component comp = null; + com.jogamp.newt.Window win = null; + + if(null == robot) { + robot = new Robot(); + robot.setAutoWaitForIdle(true); + } + + centerMouse(robot, obj); + + int c0 = keyTypedCounter.getCount(); + + for(int i=0; i<typeCount; i++) { + robot.keyPress(java.awt.event.KeyEvent.VK_A); + robot.delay(ROBOT_DELAY); + robot.keyRelease(java.awt.event.KeyEvent.VK_A); + robot.delay(ROBOT_DELAY); + } + + // Wait for the key events to be processed. + int wait; + for (wait=0; wait<POLL_DIVIDER && (keyTypedCounter.getCount()-c0)<typeCount; wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + return keyTypedCounter.getCount()-c0; + } + + /** + * @param mouseButton ie InputEvent.BUTTON1_MASK + * @param clickCount ie 1, or 2 + * @return True if the desired clickCount within TIME_OUT has been received + */ + public static int testMouseClick(Robot robot, int mouseButton, int clickCount, + Object obj, EventCountAdapter mouseClickCounter) + throws AWTException, InterruptedException, InvocationTargetException { + + if(null == robot) { + robot = new Robot(); + robot.setAutoWaitForIdle(true); + } + + final int clickTO = com.jogamp.newt.event.MouseEvent.getClickTimeout(); + + centerMouse(robot, obj); + + robot.delay(2*clickTO); + + int c0 = mouseClickCounter.getCount(); + + for(int i=0; i<clickCount; i++) { + robot.mousePress(mouseButton); + robot.delay(clickTO/4); + robot.mouseRelease(mouseButton); + robot.delay(clickTO/4); + } + + // Wait for the key events to be processed. + int wait; + for (wait=0; wait<POLL_DIVIDER && (mouseClickCounter.getCount()-c0)<clickCount; wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + return mouseClickCounter.getCount()-c0; + } + + /** + * + * @return True if the EventCountAdapter became the desired value within TIME_OUT + */ + public static boolean waitForCount(int desired, EventCountAdapter eca) throws InterruptedException { + for (int wait=0; wait<POLL_DIVIDER; wait++) { + if( eca.getCount() == desired ) { + return true; + } + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + return false; + } + + /** + * + * @return True if the Component becomes <code>visible</code> within TIME_OUT + */ + public static boolean waitForVisible(Object obj, boolean visible) throws InterruptedException { + int wait; + if(obj instanceof Component) { + Component comp = (Component) obj; + for (wait=0; wait<POLL_DIVIDER && visible != comp.isVisible(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + } else if(obj instanceof com.jogamp.newt.Window) { + com.jogamp.newt.Window win = (com.jogamp.newt.Window) obj; + for (wait=0; wait<POLL_DIVIDER && visible != win.isVisible(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + } else { + throw new RuntimeException("Neither AWT nor NEWT: "+obj); + } + return wait<POLL_DIVIDER; + } + + /** + * + * @return True if the Component becomes realized (not displayable, native invalid) within TIME_OUT + */ + public static boolean waitForRealized(Object obj, boolean realized) throws InterruptedException { + int wait; + if (obj instanceof Component) { + Component comp = (Component) obj; + for (wait=0; wait<POLL_DIVIDER && realized != comp.isDisplayable(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + // if GLCanvas, ensure it got also painted -> drawable.setRealized(true); + if(wait<POLL_DIVIDER && comp instanceof GLCanvas) { + GLCanvas glcanvas = (GLCanvas) comp; + for (wait=0; wait<POLL_DIVIDER && realized != glcanvas.isRealized(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + if(wait>=POLL_DIVIDER) { + // for some reason GLCanvas hasn't been painted yet, force it! + System.err.println("XXX: FORCE REPAINT PRE - canvas: "+glcanvas); + glcanvas.repaint(); + for (wait=0; wait<POLL_DIVIDER && realized != glcanvas.isRealized(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + System.err.println("XXX: FORCE REPAINT POST - canvas: "+glcanvas); + } + for (wait=0; wait<POLL_DIVIDER && realized != glcanvas.isRealized(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + } + } else if(obj instanceof com.jogamp.newt.Window) { + com.jogamp.newt.Window win = (com.jogamp.newt.Window) obj; + for (wait=0; wait<POLL_DIVIDER && realized != win.isNativeValid(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + } else { + throw new RuntimeException("Neither AWT nor NEWT: "+obj); + } + return wait<POLL_DIVIDER; + } + + /** + * Programmatically issue windowClosing on AWT or NEWT. + * Wait until the window is closing within TIME_OUT. + * + * @param obj either an AWT Window (Frame, JFrame) or NEWT Window + * @param willClose indicating that the window will close, hence this method waits for the window to be closed + * @return True if the Window is closing and closed (if willClose is true), each within TIME_OUT + * @throws InterruptedException + */ + public static boolean closeWindow(Object obj, boolean willClose) throws InterruptedException, InvocationTargetException { + WindowClosingListener closingListener = addClosingListener(obj); + if(obj instanceof java.awt.Window) { + final java.awt.Window win = (java.awt.Window) obj; + Toolkit tk = Toolkit.getDefaultToolkit(); + final EventQueue evtQ = tk.getSystemEventQueue(); + EventQueue.invokeAndWait(new Runnable() { + public void run() { + evtQ.postEvent(new java.awt.event.WindowEvent(win, java.awt.event.WindowEvent.WINDOW_CLOSING)); + } }); + } else if(obj instanceof com.jogamp.newt.Window) { + com.jogamp.newt.Window win = (com.jogamp.newt.Window) obj; + WindowImplAccess.windowDestroyNotify(win); + } + int wait; + for (wait=0; wait<POLL_DIVIDER && !closingListener.isWindowClosing(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + if(wait<POLL_DIVIDER && willClose) { + for (wait=0; wait<POLL_DIVIDER && !closingListener.isWindowClosed(); wait++) { + Thread.sleep(TIME_OUT/POLL_DIVIDER); + } + } + return wait<POLL_DIVIDER; + } + + public static WindowClosingListener addClosingListener(Object obj) throws InterruptedException { + WindowClosingListener cl = null; + if(obj instanceof java.awt.Window) { + java.awt.Window win = (java.awt.Window) obj; + AWTWindowClosingAdapter acl = new AWTWindowClosingAdapter(); + win.addWindowListener(acl); + cl = acl; + } else if(obj instanceof com.jogamp.newt.Window) { + com.jogamp.newt.Window win = (com.jogamp.newt.Window) obj; + NEWTWindowClosingAdapter ncl = new NEWTWindowClosingAdapter(); + win.addWindowListener(ncl); + cl = ncl; + } else { + throw new RuntimeException("Neither AWT nor NEWT: "+obj); + } + return cl; + } + public static interface WindowClosingListener { + void reset(); + public boolean isWindowClosing(); + public boolean isWindowClosed(); + } + static class AWTWindowClosingAdapter + extends java.awt.event.WindowAdapter implements WindowClosingListener + { + volatile boolean closing = false; + volatile boolean closed = false; + + public void reset() { + closing = false; + closed = false; + } + public boolean isWindowClosing() { + return closing; + } + public boolean isWindowClosed() { + return closed; + } + public void windowClosing(java.awt.event.WindowEvent e) { + closing = true; + } + public void windowClosed(java.awt.event.WindowEvent e) { + closed = true; + } + } + static class NEWTWindowClosingAdapter + extends com.jogamp.newt.event.WindowAdapter implements WindowClosingListener + { + volatile boolean closing = false; + volatile boolean closed = false; + + public void reset() { + closing = false; + closed = false; + } + public boolean isWindowClosing() { + return closing; + } + public boolean isWindowClosed() { + return closed; + } + public void windowDestroyNotify(com.jogamp.newt.event.WindowEvent e) { + closing = true; + } + public void windowDestroyed(com.jogamp.newt.event.WindowEvent e) { + closed = true; + } + } + +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java b/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java new file mode 100644 index 000000000..e49679dc3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java @@ -0,0 +1,51 @@ +/** + * 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.util; + + +import javax.media.opengl.*; +import com.jogamp.opengl.JoglVersion; + + +public class DumpGLInfo implements GLEventListener { + + public void init(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + System.err.println(JoglVersion.getGLInfo(gl, null)); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void display(GLAutoDrawable drawable) { + } + + public void dispose(GLAutoDrawable drawable) { + } +} diff --git a/src/jogamp/graph/font/FontConstructor.java b/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapter.java index a382d292e..105d2503e 100644 --- a/src/jogamp/graph/font/FontConstructor.java +++ b/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapter.java @@ -1,16 +1,16 @@ /** - * Copyright 2011 JogAmp Community. All rights reserved. + * 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 @@ -20,15 +20,17 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package jogamp.graph.font; + +package com.jogamp.opengl.test.junit.util; -import com.jogamp.graph.font.Font; +public interface EventCountAdapter { -public interface FontConstructor { - Font create(String name); + int getCount(); + void reset(); } + diff --git a/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapterUtil.java b/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapterUtil.java new file mode 100644 index 000000000..d919d7cb6 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapterUtil.java @@ -0,0 +1,49 @@ +/** + * 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.util; + +import java.util.List; +import java.util.Iterator; + +public abstract class EventCountAdapterUtil { + + public static void reset(EventCountAdapter[] adapters) { + for(int i=0; i<adapters.length; i++) { + adapters[i].reset(); + } + } + + public static void reset(List/*<EventCountAdapter>*/ adapters) { + for(Iterator i = adapters.iterator(); i.hasNext(); ) { + EventCountAdapter adapter = (EventCountAdapter) i.next(); + adapter.reset(); + } + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java b/src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java new file mode 100644 index 000000000..bcafc02f7 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java @@ -0,0 +1,121 @@ +/** + * 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.util; + +import com.jogamp.opengl.util.glsl.ShaderUtil; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import org.junit.Assert; + +public class GLSLSimpleProgram { + private int shaderProgram; + private int vertShader; + private int fragShader; + + private GLSLSimpleProgram(int shaderProgram, int vertShader, int fragShader) { + this.shaderProgram = shaderProgram; + this.vertShader = vertShader; + this.fragShader = fragShader; + } + + public static GLSLSimpleProgram create(GL2ES2 gl, String vertShaderCode, String fragShaderCode, boolean link) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream pbaos = new PrintStream(baos); + + int vertShader = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + int fragShader = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + String[] vlines = new String[] { vertShaderCode }; + int[] vlengths = new int[] { vlines[0].length() }; + gl.glShaderSource(vertShader, vlines.length, vlines, vlengths, 0); + gl.glCompileShader(vertShader); + if(!ShaderUtil.isShaderStatusValid(gl, vertShader, gl.GL_COMPILE_STATUS, pbaos)) { + System.out.println("getShader:postCompile vertShader: "+baos.toString()); + Assert.assertTrue(false); + } + pbaos.flush(); baos.reset(); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + + String[] flines = new String[] { fragShaderCode }; + int[] flengths = new int[] { flines[0].length() }; + gl.glShaderSource(fragShader, flines.length, flines, flengths, 0); + gl.glCompileShader(fragShader); + if(!ShaderUtil.isShaderStatusValid(gl, fragShader, gl.GL_COMPILE_STATUS, pbaos)) { + System.out.println("getShader:postCompile fragShader: "+baos.toString()); + Assert.assertTrue(false); + } + pbaos.flush(); baos.reset(); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + int shaderProgram = gl.glCreateProgram(); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glAttachShader(shaderProgram, vertShader); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + gl.glAttachShader(shaderProgram, fragShader); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + if(link) { + gl.glLinkProgram(shaderProgram); + if(!ShaderUtil.isProgramValid(gl, shaderProgram, pbaos)) { + System.out.println("Error (GLSL link error): "+baos.toString()); + Assert.assertTrue(false); + } + } + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + GLSLSimpleProgram res = new GLSLSimpleProgram(shaderProgram, vertShader, fragShader); + return res; + } + + public void release(GL2ES2 gl) { + gl.glUseProgram(0); + gl.glDetachShader(shaderProgram, vertShader); + gl.glDeleteShader(vertShader); + gl.glDetachShader(shaderProgram, fragShader); + gl.glDeleteShader(fragShader); + gl.glDeleteProgram(shaderProgram); + } + + public int getFragShader() { + return fragShader; + } + + public int getShaderProgram() { + return shaderProgram; + } + + public int getVertShader() { + return vertShader; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java new file mode 100644 index 000000000..506fe2d97 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java @@ -0,0 +1,63 @@ +/** + * 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.util; + +import java.lang.reflect.*; + +public class MiscUtils { + public static int atoi(String str, int def) { + try { + return Integer.parseInt(str); + } catch (Exception ex) { + ex.printStackTrace(); + } + return def; + } + + public static boolean setFieldIfExists(Object instance, String fieldName, Object value) { + try { + Field f = instance.getClass().getField(fieldName); + if(value instanceof Boolean || f.getType().isInstance(value)) { + f.set(instance, value); + return true; + } else { + System.out.println(instance.getClass()+" '"+fieldName+"' field not assignable with "+value.getClass()+", it's a: "+f.getType()); + } + } catch (IllegalAccessException ex) { + throw new RuntimeException(ex); + } catch (NoSuchFieldException nsfe) { + // OK - throw new RuntimeException(instance.getClass()+" has no '"+fieldName+"' field", nsfe); + } + return false; + } +} + + + diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java new file mode 100644 index 000000000..9ee74aeff --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java @@ -0,0 +1,64 @@ +/** + * 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.util; + +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; + +public class NEWTFocusAdapter extends WindowAdapter implements EventCountAdapter { + + String prefix; + int focusGained; + + public NEWTFocusAdapter(String prefix) { + this.prefix = prefix; + reset(); + } + + public int getCount() { + return focusGained; + } + + public void reset() { + focusGained = 0; + } + + @Override + public void windowGainedFocus(WindowEvent e) { + ++focusGained; + System.err.println("FOCUS NEWT GAINED ["+focusGained+"]: "+prefix+", "+e); + } + + @Override + public void windowLostFocus(WindowEvent e) { + --focusGained; + System.err.println("FOCUS NEWT LOST ["+focusGained+"]: "+prefix+", "+e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java new file mode 100644 index 000000000..ba1a2f3f5 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java @@ -0,0 +1,58 @@ +/** + * 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.util; + +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; + +public class NEWTKeyAdapter extends KeyAdapter implements EventCountAdapter { + + String prefix; + int keyTyped; + + public NEWTKeyAdapter(String prefix) { + this.prefix = prefix; + reset(); + } + + public int getCount() { + return keyTyped; + } + + public void reset() { + keyTyped = 0; + } + + @Override + public void keyTyped(KeyEvent e) { + ++keyTyped; + System.err.println("KEY NEWT TYPED ["+keyTyped+"]: "+prefix+", "+e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java new file mode 100644 index 000000000..617d951ec --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java @@ -0,0 +1,57 @@ +/** + * 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.util; + +import com.jogamp.newt.event.MouseAdapter; +import com.jogamp.newt.event.MouseEvent; + +public class NEWTMouseAdapter extends MouseAdapter implements EventCountAdapter { + + String prefix; + int mouseClicked; + + public NEWTMouseAdapter(String prefix) { + this.prefix = prefix; + reset(); + } + + public int getCount() { + return mouseClicked; + } + + public void reset() { + mouseClicked = 0; + } + + public void mouseClicked(MouseEvent e) { + mouseClicked+=e.getClickCount(); + System.err.println("MOUSE NEWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java new file mode 100644 index 000000000..77996bf1e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java @@ -0,0 +1,52 @@ +/** + * 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.util; + +import com.jogamp.newt.event.*; + +public class QuitAdapter extends WindowAdapter implements WindowListener, KeyListener { + boolean shouldQuit = false; + + public boolean shouldQuit() { return shouldQuit; } + + public void windowDestroyNotify(WindowEvent e) { + System.out.println("QUIT Window "+Thread.currentThread()); + shouldQuit = true; + } + + public void keyTyped(KeyEvent e) { + if(e.getKeyChar()=='q') { + System.out.println("QUIT Key "+Thread.currentThread()); + shouldQuit = true; + } + } + public void keyPressed(KeyEvent e) {} + public void keyReleased(KeyEvent e) {} +} + diff --git a/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java b/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java new file mode 100644 index 000000000..7e3b9ebc0 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java @@ -0,0 +1,143 @@ +/** + * 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.util; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.channels.FileLock; + +public class SingletonInstance { + + static final boolean DEBUG = true; + static final String temp_file_path; + + static { + String s = null; + try { + File tmpFile = File.createTempFile("TEST", "tst"); + String absTmpFile = tmpFile.getCanonicalPath(); + tmpFile.delete(); + s = absTmpFile.substring(0, absTmpFile.lastIndexOf(File.separator)); + } catch (IOException ex) { + ex.printStackTrace(); + } + temp_file_path = s; + } + + public static String getCanonicalTempPath() { + return temp_file_path; + } + + public static String getCanonicalTempLockFilePath(String basename) { + return getCanonicalTempPath() + File.separator + basename; + } + + public SingletonInstance(String lockFileBasename) { + this.file = new File ( getCanonicalTempLockFilePath ( lockFileBasename ) ); + } + + public SingletonInstance(File lockFile) { + this.file = lockFile ; + } + + public synchronized void lock(long timeout_ms, long poll_ms) { + long i=0; + try { + do { + if(tryLock()) { + return; + } + if(DEBUG && 0==i) { + System.err.println("Wait for lock " + file); + } + i++; + Thread.sleep(poll_ms); + } while ( i < timeout_ms / poll_ms ) ; + } catch ( InterruptedException ie ) { + throw new RuntimeException(ie); + } + throw new RuntimeException("SingletonInstance couldn't get lock within "+timeout_ms+"ms"); + } + + public synchronized boolean tryLock() { + try { + randomAccessFile = new RandomAccessFile(file, "rw"); + fileLock = randomAccessFile.getChannel().tryLock(); + + if (fileLock != null) { + //final File f_file = file; + //final RandomAccessFile f_randomAccessFile = randomAccessFile; + //final FileLock f_fileLock = fileLock; + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + unlock(); + } + }); + locked = true; + if(DEBUG) { + System.err.println("Locked " + file); + } + return true; + } + } catch (Exception e) { + System.err.println("Unable to create and/or lock file: " + file); + e.printStackTrace(); + } + return false; + } + + public synchronized boolean unlock() { + if(locked) { + try { + fileLock.release(); + randomAccessFile.close(); + file.delete(); + return true; + } catch (Exception e) { + System.err.println("Unable to remove lock file: " + file); + e.printStackTrace(); + } finally { + fileLock = null; + randomAccessFile = null; + locked = false; + } + } + return false; + } + + public synchronized boolean isLocked() { + return locked; + } + + File file = null; + RandomAccessFile randomAccessFile = null; + FileLock fileLock = null; + boolean locked = false; +} diff --git a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java new file mode 100644 index 000000000..b01ba1be9 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java @@ -0,0 +1,72 @@ +/** + * 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.util; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; + + +public abstract class UITestCase { + + public static final String SINGLE_INSTANCE_LOCK_FILE = "UITestCase.lock"; + + static SingletonInstance singletonInstance; + + protected SingletonInstance getSingletonInstance() { + return singletonInstance; + } + + @BeforeClass + public static void oneTimeSetUp() { + // one-time initialization code + singletonInstance = new SingletonInstance(SINGLE_INSTANCE_LOCK_FILE); + singletonInstance.lock(3*60*1000, 100); // wait up to 3 min, poll every 100ms + } + + @AfterClass + public static void oneTimeTearDown() { + // one-time cleanup code + System.gc(); // force cleanup + singletonInstance.unlock(); + } + + @Before + public void setUp() { + System.err.println("++++ UITestCase.setUp: "+getClass().getName()); + } + + @After + public void tearDown() { + System.err.println("++++ UITestCase.tearDown: "+getClass().getName()); + } + +} + diff --git a/src/test/jogamp/newt/WindowImplAccess.java b/src/test/jogamp/newt/WindowImplAccess.java new file mode 100644 index 000000000..76d0dc050 --- /dev/null +++ b/src/test/jogamp/newt/WindowImplAccess.java @@ -0,0 +1,57 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.newt; + +import com.jogamp.newt.Window; +import com.jogamp.newt.opengl.GLWindow; + +/** + * Allows access to protected methods of WindowImpl + */ +public class WindowImplAccess { + public static final void windowDestroyNotify(Window win) { + WindowImpl winImpl = null; + if(win instanceof GLWindow) { + GLWindow glwin = (GLWindow) win; + winImpl = (WindowImpl) glwin.getWindow(); + } else if(win instanceof WindowImpl) { + winImpl = (WindowImpl) win; + } else { + throw new RuntimeException("Given Window not a GLWindow, not WindowImpl, but "+win.getClass()); + } + final WindowImpl winImplF = winImpl; + winImplF.runOnEDTIfAvail(true, new Runnable() { + public void run() { + winImplF.windowDestroyNotify(); + } + }); + } +} + + diff --git a/src/test/native/displayMultiple01.c b/src/test/native/displayMultiple01.c new file mode 100644 index 000000000..d51453687 --- /dev/null +++ b/src/test/native/displayMultiple01.c @@ -0,0 +1,18 @@ +#include <X11/X.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <GL/glx.h> +#include <stdio.h> + +int main(int nargs, char **vargs) { + int major, minor; + Display *disp = XOpenDisplay(NULL); + glXQueryVersion(disp, &major, &minor); + fprintf(stderr, "%p: %d.%d\n", disp, major, minor); + XCloseDisplay(disp); + disp = XOpenDisplay(NULL); + glXQueryVersion(disp, &major, &minor); + fprintf(stderr, "%p: %d.%d\n", disp, major, minor); + XCloseDisplay(disp); + return 0; +} diff --git a/src/test/native/displayMultiple02.c b/src/test/native/displayMultiple02.c new file mode 100644 index 000000000..1bfe95b95 --- /dev/null +++ b/src/test/native/displayMultiple02.c @@ -0,0 +1,113 @@ +/** + * compile with: gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL + */ + +#include <stdio.h> +#include <X11/X.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <GL/glx.h> +#include <GL/gl.h> + +static void testOrder(int reverseDestroyOrder, const char * msg); + +int main(int nargs, char **vargs) { + testOrder(0, "Normal order"); + testOrder(1, "Reverse order"); + return 0; +} + +static void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx); +static void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height); + +void testOrder(int reverseDestroyOrder, const char * msg) { + int major, minor; + Display *disp1; + Window win1; + GLXContext ctx1; + + Display *disp2; + Window win2; + GLXContext ctx2; + + fprintf(stderr, "%s: Create #1\n", msg); + disp1 = XOpenDisplay(NULL); + createGLWin(disp1, 200, 200, &win1, &ctx1); + useGL(disp1, win1, ctx1, 200, 200); + + fprintf(stderr, "%s: Create #2\n", msg); + disp2 = XOpenDisplay(NULL); + createGLWin(disp2, 300, 300, &win2, &ctx2); + useGL(disp2, win2, ctx2, 300, 300); + + if(reverseDestroyOrder) { + fprintf(stderr, "%s: Destroy #2\n", msg); + glXMakeCurrent(disp2, 0, 0); + glXDestroyContext(disp2, ctx2); + XCloseDisplay(disp2); + + fprintf(stderr, "%s: Destroy #1\n", msg); + glXMakeCurrent(disp1, 0, 0); + glXDestroyContext(disp1, ctx1); + XCloseDisplay(disp1); + } else { + fprintf(stderr, "%s: Destroy #1\n", msg); + glXMakeCurrent(disp1, 0, 0); + glXDestroyContext(disp1, ctx1); + XCloseDisplay(disp1); + + fprintf(stderr, "%s: Destroy #2\n", msg); + glXMakeCurrent(disp2, 0, 0); + glXDestroyContext(disp2, ctx2); + XCloseDisplay(disp2); + + } + + fprintf(stderr, "%s: Success - no bug\n", msg); +} + +/* attributes for a double buffered visual in RGBA format with at least + * 4 bits per color and a 16 bit depth buffer */ +static int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER, + GLX_RED_SIZE, 4, + GLX_GREEN_SIZE, 4, + GLX_BLUE_SIZE, 4, + GLX_DEPTH_SIZE, 16, + None }; + +void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx) +{ + int screen = DefaultScreen(dpy); + XVisualInfo *vi = glXChooseVisual(dpy, screen, attrListDbl); + Colormap cmap; + XSetWindowAttributes attr; + + /* create a GLX context */ + *rCtx = glXCreateContext(dpy, vi, 0, GL_TRUE); + /* create a color map */ + cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); + attr.colormap = cmap; + attr.border_pixel = 0; + + /* create a window in window mode*/ + attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | + StructureNotifyMask; + *rWin = XCreateWindow(dpy, RootWindow(dpy, vi->screen), + 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, + CWBorderPixel | CWColormap | CWEventMask, &attr); + + XMapRaised(dpy, *rWin); +} + +void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height) +{ + glXMakeCurrent(dpy, win, ctx); + glShadeModel(GL_SMOOTH); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClearDepth(1.0f); + glViewport(0, 0, width, height); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glXSwapBuffers(dpy, win); + glXMakeCurrent(dpy, 0, 0); +} + diff --git a/src/test/native/glExtensionsListGL2.c b/src/test/native/glExtensionsListGL2.c new file mode 100644 index 000000000..89815e9c0 --- /dev/null +++ b/src/test/native/glExtensionsListGL2.c @@ -0,0 +1,95 @@ +/** + * compile with: gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL + */ + +#include <stdio.h> +#include <X11/X.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <GL/glx.h> +#include <GL/gl.h> + +static void testExtensions(); + +int main(int nargs, char **vargs) { + testExtensions(); + return 0; +} + +static void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx); +static void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height); + +void testExtensions() { + int major, minor; + Display *disp1; + Window win1; + GLXContext ctx1; + + disp1 = XOpenDisplay(NULL); + createGLWin(disp1, 200, 200, &win1, &ctx1); + if(0 != win1 && 0 != ctx1) { + useGL(disp1, win1, ctx1, 200, 200); + + glXMakeCurrent(disp1, 0, 0); + glXDestroyContext(disp1, ctx1); + } + XCloseDisplay(disp1); +} + +/* attributes for a double buffered visual in RGBA format with at least + * 4 bits per color and a 16 bit depth buffer */ +static int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER, + GLX_RED_SIZE, 4, + GLX_GREEN_SIZE, 4, + GLX_BLUE_SIZE, 4, + GLX_DEPTH_SIZE, 16, + None }; + +void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx) +{ + int screen = DefaultScreen(dpy); + XVisualInfo *vi = glXChooseVisual(dpy, screen, attrListDbl); + Colormap cmap; + XSetWindowAttributes attr; + + /* create a GLX context */ + *rCtx = glXCreateContext(dpy, vi, 0, GL_TRUE); + /* create a color map */ + cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); + attr.colormap = cmap; + attr.border_pixel = 0; + + /* create a window in window mode*/ + attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | + StructureNotifyMask; + *rWin = XCreateWindow(dpy, RootWindow(dpy, vi->screen), + 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, + CWBorderPixel | CWColormap | CWEventMask, &attr); + + XMapRaised(dpy, *rWin); +} + +void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height) +{ + PFNGLGETSTRINGIPROC glGetStringi = 0; + int i, n; + + glXMakeCurrent(dpy, win, ctx); + + fprintf(stderr, "GL_VENDOR: %s\n", glGetString(GL_VENDOR)); + + glGetIntegerv(GL_NUM_EXTENSIONS, &n); + fprintf(stderr, "GL_NUM_EXTENSIONS: %d\n", n); + + glGetStringi = (PFNGLGETSTRINGIPROC)glXGetProcAddressARB("glGetStringi"); + if(NULL==glGetStringi) { + return; + } + + for (i=0; i<n; i++) { + const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i); + fprintf(stderr, "GL_EXTENSION %d/%d: %s\n", (i+1), n, extension); + } + +} + diff --git a/src/test/native/glExtensionsListGL3.c b/src/test/native/glExtensionsListGL3.c new file mode 100644 index 000000000..c531577e8 --- /dev/null +++ b/src/test/native/glExtensionsListGL3.c @@ -0,0 +1,300 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <GL/gl.h> +#include <GL/glext.h> +#include <GL/glx.h> +#include <GL/glxext.h> + +typedef int bool; +#define true 1; +#define false 0; + +// Helper to check for extension string presence. Adapted from: +// http://www.opengl.org/resources/features/OGLextensions/ +static bool isExtensionSupported(const char *extList, const char *extension) +{ + + const char *start; + const char *where, *terminator; + + /* Extension names should not have spaces. */ + where = strchr(extension, ' '); + if ( where || *extension == '\0' ) + return false; + + /* It takes a bit of care to be fool-proof about parsing the + OpenGL extensions string. Don't be fooled by sub-strings, + etc. */ + for ( start = extList; ; ) { + where = strstr( start, extension ); + + if ( !where ) + break; + + terminator = where + strlen( extension ); + + if ( where == start || *(where - 1) == ' ' ) + if ( *terminator == ' ' || *terminator == '\0' ) + return true; + + start = terminator; + } + + return false; +} + +static bool ctxErrorOccurred = false; +static int ctxErrorHandler( Display *dpy, XErrorEvent *ev ) +{ + ctxErrorOccurred = true; + return 0; +} + +void dumpGLExtension() { + PFNGLGETSTRINGIPROC glGetStringi = 0; + int i, n; + + fprintf(stderr, "GL_VENDOR: %s\n", glGetString(GL_VENDOR)); + + glGetIntegerv(GL_NUM_EXTENSIONS, &n); + fprintf(stderr, "GL_NUM_EXTENSIONS: %d\n", n); + + glGetStringi = (PFNGLGETSTRINGIPROC)glXGetProcAddressARB("glGetStringi"); + if(NULL==glGetStringi) { + return; + } + + for (i=0; i<n; i++) { + const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i); + fprintf(stderr, "GL_EXTENSION %d/%d: %s\n", (i+1), n, extension); + } + +} + +int main (int argc, char ** argv) +{ + Display *display = XOpenDisplay(0); + + if ( !display ) + { + printf( "Failed to open X display\n" ); + exit(1); + } + + // Get a matching FB config + static int visual_attribs[] = + { + GLX_X_RENDERABLE , True, + GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT, + GLX_RENDER_TYPE , GLX_RGBA_BIT, + GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR, + GLX_RED_SIZE , 8, + GLX_GREEN_SIZE , 8, + GLX_BLUE_SIZE , 8, + GLX_ALPHA_SIZE , 8, + GLX_DEPTH_SIZE , 24, + GLX_STENCIL_SIZE , 8, + GLX_DOUBLEBUFFER , True, + //GLX_SAMPLE_BUFFERS , 1, + //GLX_SAMPLES , 4, + None + }; + + int glx_major, glx_minor; + + // FBConfigs were added in GLX version 1.3. + if ( !glXQueryVersion( display, &glx_major, &glx_minor ) || + ( ( glx_major == 1 ) && ( glx_minor < 3 ) ) || ( glx_major < 1 ) ) + { + printf( "Invalid GLX version" ); + exit(1); + } + + printf( "Getting matching framebuffer configs\n" ); + int fbcount; + GLXFBConfig *fbc = glXChooseFBConfig( display, DefaultScreen( display ), + visual_attribs, &fbcount ); + if ( !fbc ) + { + printf( "Failed to retrieve a framebuffer config\n" ); + exit(1); + } + printf( "Found %d matching FB configs.\n", fbcount ); + + // Pick the FB config/visual with the most samples per pixel + printf( "Getting XVisualInfos\n" ); + int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999; + + int i; + for ( i = 0; i < fbcount; i++ ) + { + XVisualInfo *vi = glXGetVisualFromFBConfig( display, fbc[i] ); + if ( vi ) + { + int samp_buf, samples; + glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf ); + glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLES , &samples ); + + printf( " Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d," + " SAMPLES = %d\n", + (int)i, (int)( vi -> visualid), samp_buf, samples ); + + if ( best_fbc < 0 || samp_buf && samples > best_num_samp ) + best_fbc = i, best_num_samp = samples; + if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp ) + worst_fbc = i, worst_num_samp = samples; + } + XFree( vi ); + } + + GLXFBConfig bestFbc = fbc[ best_fbc ]; + + // Be sure to free the FBConfig list allocated by glXChooseFBConfig() + XFree( fbc ); + + // Get a visual + XVisualInfo *vi = glXGetVisualFromFBConfig( display, bestFbc ); + printf( "Chosen visual ID = 0x%x\n", (int) vi->visualid ); + + printf( "Creating colormap\n" ); + XSetWindowAttributes swa; + Colormap cmap; + swa.colormap = cmap = XCreateColormap( display, + RootWindow( display, vi->screen ), + vi->visual, AllocNone ); + swa.background_pixmap = None ; + swa.border_pixel = 0; + swa.event_mask = StructureNotifyMask; + + printf( "Creating window\n" ); + Window win = XCreateWindow( display, RootWindow( display, vi->screen ), + 0, 0, 100, 100, 0, vi->depth, InputOutput, + vi->visual, + CWBorderPixel|CWColormap|CWEventMask, &swa ); + if ( !win ) + { + printf( "Failed to create window.\n" ); + exit(1); + } + + // Done with the visual info data + XFree( vi ); + + XStoreName( display, win, "GL 3.0 Window" ); + + printf( "Mapping window\n" ); + XMapWindow( display, win ); + + // Get the default screen's GLX extension list + const char *glxExts = glXQueryExtensionsString( display, + DefaultScreen( display ) ); + + // NOTE: It is not necessary to create or make current to a context before + // calling glXGetProcAddressARB + PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0; + glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) + glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" ); + + GLXContext ctx = 0; + + // Install an X error handler so the application won't exit if GL 3.0 + // context allocation fails. + // + // Note this error handler is global. All display connections in all threads + // of a process use the same error handler, so be sure to guard against other + // threads issuing X commands while this code is running. + ctxErrorOccurred = false; + int (*oldHandler)(Display*, XErrorEvent*) = + XSetErrorHandler(&ctxErrorHandler); + + // Check for the GLX_ARB_create_context extension string and the function. + // If either is not present, use GLX 1.3 context creation method. + if ( !isExtensionSupported( glxExts, "GLX_ARB_create_context" ) || + !glXCreateContextAttribsARB ) + { + printf( "glXCreateContextAttribsARB() not found" + " ... using old-style GLX context\n" ); + ctx = glXCreateNewContext( display, bestFbc, GLX_RGBA_TYPE, 0, True ); + } + + // If it does, try to get a GL 3.0 context! + else + { + int context_attribs[] = + { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 0, + GLX_RENDER_TYPE , GLX_RGBA_TYPE, + GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, + None + }; + + printf( "Creating context\n" ); + ctx = glXCreateContextAttribsARB( display, bestFbc, 0, + True, context_attribs ); + + // Sync to ensure any errors generated are processed. + XSync( display, False ); + if ( !ctxErrorOccurred && ctx ) { + printf( "Created GL 3.0 context\n" ); + } else + { + // Couldn't create GL 3.0 context. Fall back to old-style 2.x context. + // When a context version below 3.0 is requested, implementations will + // return the newest context version compatible with OpenGL versions less + // than version 3.0. + // GLX_CONTEXT_MAJOR_VERSION_ARB = 1 + context_attribs[1] = 1; + // GLX_CONTEXT_MINOR_VERSION_ARB = 0 + context_attribs[3] = 0; + + ctxErrorOccurred = false; + + printf( "Failed to create GL 3.0 context" + " ... using old-style GLX context\n" ); + ctx = glXCreateContextAttribsARB( display, bestFbc, 0, + True, context_attribs ); + } + } + + // Sync to ensure any errors generated are processed. + XSync( display, False ); + + // Restore the original error handler + XSetErrorHandler( oldHandler ); + + if ( ctxErrorOccurred || !ctx ) + { + printf( "Failed to create an OpenGL context\n" ); + exit(1); + } + + // Verifying that context is a direct context + if ( ! glXIsDirect ( display, ctx ) ) + { + printf( "Indirect GLX rendering context obtained\n" ); + } + else + { + printf( "Direct GLX rendering context obtained\n" ); + } + + printf( "Making context current\n" ); + glXMakeCurrent( display, win, ctx ); + + dumpGLExtension(); + + glXMakeCurrent( display, 0, 0 ); + glXDestroyContext( display, ctx ); + + XDestroyWindow( display, win ); + XFreeColormap( display, cmap ); + XCloseDisplay( display ); + + return 0; +} + diff --git a/src/test/native/make.sh b/src/test/native/make.sh new file mode 100755 index 000000000..20bd49e4a --- /dev/null +++ b/src/test/native/make.sh @@ -0,0 +1,6 @@ +#! /bin/bash + +gcc -o displayMultiple01 displayMultiple01.c -lX11 -lGL +gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL +gcc -o glExtensionsListGL2 glExtensionsListGL2.c -lX11 -lGL +gcc -o glExtensionsListGL3 glExtensionsListGL3.c -lX11 -lGL |