aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl')
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/OutlineShape.java408
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/Region.java166
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/RegionFactory.java51
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java70
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java55
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java256
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java155
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java324
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java34
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/AABBox.java475
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Outline.java258
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Triangle.java84
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Vertex.java62
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java278
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/math/Quaternion.java668
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/math/VectorUtil.java466
-rw-r--r--src/jogl/classes/com/jogamp/graph/package.html33
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/Animator.java14
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java61
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/FBObject.java133
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java20
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java248
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java63
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java203
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java257
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java41
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java14
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java54
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/Locator.java77
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java4
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java29
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/gl2/GLUT.java8
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java60
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java55
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java193
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java931
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java33
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java195
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java67
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java92
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java10
-rw-r--r--src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java2
-rw-r--r--src/jogl/classes/javax/media/opengl/FPSCounter.java117
-rw-r--r--src/jogl/classes/javax/media/opengl/GLAnimatorControl.java42
-rw-r--r--src/jogl/classes/javax/media/opengl/GLArrayData.java37
-rw-r--r--src/jogl/classes/javax/media/opengl/GLAutoDrawable.java23
-rw-r--r--src/jogl/classes/javax/media/opengl/GLContext.java149
-rw-r--r--src/jogl/classes/javax/media/opengl/GLDebugListener.java44
-rw-r--r--src/jogl/classes/javax/media/opengl/GLDebugMessage.java248
-rw-r--r--src/jogl/classes/javax/media/opengl/GLProfile.java106
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLCanvas.java21
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLJPanel.java18
-rwxr-xr-xsrc/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java167
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java133
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java172
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java609
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java326
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java18
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java10
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl13
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl10
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp172
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp24
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl14
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl21
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl13
-rw-r--r--src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java80
-rw-r--r--src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java160
-rw-r--r--src/jogl/classes/jogamp/graph/curve/tess/HEdge.java190
-rw-r--r--src/jogl/classes/jogamp/graph/curve/tess/Loop.java668
-rw-r--r--src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java230
-rw-r--r--src/jogl/classes/jogamp/graph/curve/text/GlyphString.java228
-rw-r--r--src/jogl/classes/jogamp/graph/font/JavaFontLoader.java4
-rw-r--r--src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java12
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java142
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java38
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java30
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java148
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java4
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java4
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java4
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/ot/table/PostTable.java6
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Interpreter.java48
-rw-r--r--src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java38
-rw-r--r--src/jogl/classes/jogamp/graph/geom/plane/Path2D.java6
-rw-r--r--src/jogl/classes/jogamp/graph/math/plane/Crossing.java10
-rw-r--r--src/jogl/classes/jogamp/opengl/FPSCounterImpl.java137
-rw-r--r--src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java26
-rw-r--r--src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java8
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextImpl.java178
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextLock.java157
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDebugMessageHandler.java266
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDrawableHelper.java58
-rw-r--r--src/jogl/classes/jogamp/opengl/GLPbufferImpl.java15
-rw-r--r--src/jogl/classes/jogamp/opengl/ListenerSyncedImplStub.java79
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLContext.java10
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/GLUquadricImpl.java16
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2CurveEvaluator.java8
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2SurfaceEvaluator.java12
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GLUgl2nurbsImpl.java12
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/ArcSdirSorter.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTdirSorter.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTesselator.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/Backend.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/Curve.java14
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/DisplayList.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/Knotspec.java10
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/Knotvector.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/Mapdesc.java6
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/Patch.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/Patchlist.java14
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/Quilt.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/README.txt110
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/nurbs/Subdivider.java52
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/ActiveRegion.java14
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/GLUface.java14
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/GLUhalfEdge.java16
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/GLUmesh.java8
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/GLUtessellatorImpl.java50
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/GLUvertex.java14
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/Mesh.java8
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/Normal.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQHeap.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQSort.java6
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/Render.java6
-rw-r--r--src/jogl/classes/jogamp/opengl/glu/tessellator/Sweep.java30
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java20
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLContext.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java28
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java122
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java29
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java30
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java46
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java33
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java2
-rw-r--r--src/jogl/native/GLDebugMessageHandler.c181
-rw-r--r--src/jogl/native/JoglCommon.c55
-rw-r--r--src/jogl/native/JoglCommon.h15
-rw-r--r--src/jogl/native/macosx/ContextUpdater.h8
-rw-r--r--src/jogl/native/macosx/ContextUpdater.m74
-rw-r--r--src/jogl/native/macosx/MacOSXWindowSystemInterface.m692
-rw-r--r--src/jogl/native/openmax/omx_tool.c12
144 files changed, 8142 insertions, 5863 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
index 827717aa5..724380f4a 100755
--- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
@@ -50,13 +50,13 @@ import com.jogamp.graph.curve.tess.CDTriangulator2D;
* <br><br>
* Example to creating an Outline Shape:
* <pre>
- addVertex(...)
- addVertex(...)
- addVertex(...)
- addEnptyOutline()
- addVertex(...)
- addVertex(...)
- addVertex(...)
+ addVertex(...)
+ addVertex(...)
+ addVertex(...)
+ addEnptyOutline()
+ addVertex(...)
+ addVertex(...)
+ addVertex(...)
* </pre>
*
* The above will create two outlines each with three vertices. By adding these two outlines to
@@ -72,10 +72,10 @@ import com.jogamp.graph.curve.tess.CDTriangulator2D;
*
* <br>Example: <br>
* <pre>
- addVertex(0,0, true);
- addVertex(0,1, false);
- addVertex(1,1, false);
- addVertex(1,0, true);
+ 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)
@@ -83,8 +83,8 @@ import com.jogamp.graph.curve.tess.CDTriangulator2D;
*
* <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>
+ * <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
@@ -92,216 +92,216 @@ import com.jogamp.graph.curve.tess.CDTriangulator2D;
*/
public class OutlineShape {
- public static final int QUADRATIC_NURBS = 10;
- private final Vertex.Factory<? extends Vertex> vertexFactory;
+ 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);
+ /** 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());
- }
+ /** 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; }
+ /** 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());
- }
+ /** 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 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);
- }
+ /** 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 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 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);
- }
+ /** 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);
- }
+ /** 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();
- }
- }
+ /** 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);
+ 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();
+ /**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);
+ 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;
- }
+ 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++;
- }
- }
- }
+ 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;
- }
+ /** @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 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();
+ /**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;
- }
+ return triangles;
+ }
- /** Sort the outlines from large
- * to small depending on the AABox
- */
- private void sortOutlines() {
- Collections.sort(outlines);
- Collections.reverse(outlines);
- }
+ /** Sort the outlines from large
+ * to small depending on the AABox
+ */
+ private void sortOutlines() {
+ Collections.sort(outlines);
+ Collections.reverse(outlines);
+ }
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 051cb1c38..eb88b787c 100755
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -29,6 +29,12 @@ package com.jogamp.graph.curve;
import java.util.ArrayList;
+import javax.media.opengl.GL2ES2;
+
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.geom.AABBox;
+import jogamp.opengl.Debug;
+
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.PMVMatrix;
@@ -44,85 +50,83 @@ import com.jogamp.opengl.util.PMVMatrix;
* @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);
+ public static final boolean DEBUG = Debug.debug("graph.curve");
+ public static final boolean DEBUG_INSTANCE = false;
+
+ /** 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;
+ public static int TWO_PASS_DEFAULT_TEXTURE_UNIT = 0;
+
+ /** 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(GL2ES2 gl);
+
+ /** 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(GL2ES2 gl, RenderState rs, 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(GL2ES2 gl, RenderState rs);
+
+ public AABBox getBounds();
+
+ 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/jogl/classes/com/jogamp/graph/curve/RegionFactory.java b/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java
index d3b978b8a..23b318e8a 100755
--- a/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/RegionFactory.java
@@ -27,36 +27,43 @@
*/
package com.jogamp.graph.curve;
-import javax.media.opengl.GLContext;
-import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
-import com.jogamp.opengl.util.glsl.ShaderState;
+import com.jogamp.graph.curve.opengl.RenderState;
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);
- }
- }
+
+ /**
+ * Create a Region using the passed curren GL object.
+ *
+ * <p> In case {@link Region#TWO_PASS} is being requested the default texture unit
+ * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p>
+ * @param rs TODO
+ * @param type can be one of {@link Region#SINGLE_PASS} or {@link Region#TWO_PASS}
+ *
+ * @return region
+ */
+ public static Region create(RenderState rs, int type) {
+ if( Region.TWO_PASS == type ){
+ return new VBORegion2PES2(rs, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ }
+ else{
+ return new VBORegionSPES2(rs);
+ }
+ }
+
+ public static Region createSinglePass(RenderState rs) {
+ return new VBORegionSPES2(rs);
+ }
+
+ public static Region createTwoPass(RenderState rs, int textureUnit) {
+ return new VBORegion2PES2(rs, textureUnit);
+ }
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
index c6e03cad6..69fdd5c4a 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -1,3 +1,30 @@
+/**
+ * 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.opengl;
import java.util.ArrayList;
@@ -13,15 +40,18 @@ 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
+
+ /**
+ * Create a Hardware accelerated Text Renderer.
+ * @param rs the used {@link RenderState}
+ * @param renderType either {@link com.jogamp.graph.curve.Region#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS}
*/
- public static RegionRenderer create(Vertex.Factory<? extends Vertex> factory, int type) {
- return new jogamp.graph.curve.opengl.RegionRendererImpl01(factory, type);
+ public static RegionRenderer create(RenderState rs, int type) {
+ return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, type);
}
- public RegionRenderer(Vertex.Factory<? extends Vertex> factory, int type) {
- super(factory, type);
+ protected RegionRenderer(RenderState rs, int type) {
+ super(rs, type);
}
/** Render an array of {@link OutlineShape}s combined in one region
@@ -45,52 +75,50 @@ public abstract class RegionRenderer extends Renderer {
protected HashMap<Integer, Region> regions = new HashMap<Integer, Region>();
- public void flushCache() {
+ public void flushCache(GL2ES2 gl) {
Iterator<Region> iterator = regions.values().iterator();
while(iterator.hasNext()){
Region region = iterator.next();
- region.destroy();
+ region.destroy(gl, rs);
}
regions.clear();
}
@Override
protected void disposeImpl(GL2ES2 gl) {
- flushCache();
+ // fluchCache(gl) already called
}
- /** Create an ogl {@link Region} defining this {@link OutlineShape}
- * @param sharpness parameter for Region generation
+ /**
+ * Create an ogl {@link Region} defining this {@link OutlineShape}
* @return the resulting Region.
*/
- protected Region createRegion(GL2ES2 gl, OutlineShape outlineShape, float sharpness) {
- Region region = RegionFactory.create(gl.getContext(), st, renderType);
+ protected Region createRegion(GL2ES2 gl, OutlineShape outlineShape) {
+ Region region = RegionFactory.create(rs, renderType);
outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS);
-
- ArrayList<Triangle> triangles = (ArrayList<Triangle>) outlineShape.triangulate(sharpness);
+ ArrayList<Triangle> triangles = (ArrayList<Triangle>) outlineShape.triangulate(rs.getSharpness().floatValue());
ArrayList<Vertex> vertices = (ArrayList<Vertex>) outlineShape.getVertices();
region.addVertices(vertices);
region.addTriangles(triangles);
- region.update();
+ region.update(gl);
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);
+ protected Region createRegion(GL2ES2 gl, OutlineShape[] outlineShapes) {
+ Region region = RegionFactory.create(rs, renderType);
int numVertices = region.getNumVertices();
for(OutlineShape outlineShape:outlineShapes){
outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS);
- ArrayList<Triangle> triangles = outlineShape.triangulate(sharpness);
+ ArrayList<Triangle> triangles = outlineShape.triangulate(rs.getSharpness().floatValue());
region.addTriangles(triangles);
ArrayList<Vertex> vertices = outlineShape.getVertices();
@@ -100,7 +128,7 @@ public abstract class RegionRenderer extends Renderer {
region.addVertices(vertices);
}
- region.update();
+ region.update(gl);
return region;
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
new file mode 100644
index 000000000..84323f6e5
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
@@ -0,0 +1,55 @@
+/**
+ * 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.curve.opengl;
+
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLUniformData;
+
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+public interface RenderState {
+
+ void destroy(GL2ES2 gl);
+
+ ShaderState getShaderState();
+ Vertex.Factory<? extends Vertex> getPointFactory();
+ PMVMatrix pmvMatrix();
+ GLUniformData getPMVMatrix();
+ GLUniformData getSharpness();
+ GLUniformData getAlpha();
+ GLUniformData getColorStatic();
+ GLUniformData getStrength();
+
+ RenderState attachTo(GL2ES2 gl);
+ boolean detachFrom(GL2ES2 gl);
+
+ StringBuilder toString(StringBuilder sb);
+ String toString();
+}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
index 57eeb016f..35022f769 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
@@ -1,39 +1,75 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
package com.jogamp.graph.curve.opengl;
+import java.nio.FloatBuffer;
+
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLUniformData;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
-import jogamp.opengl.Debug;
+import jogamp.graph.curve.opengl.RenderStateImpl;
+import com.jogamp.graph.curve.Region;
import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
public abstract class Renderer {
- protected static final boolean DEBUG = Debug.debug("CurveRenderer");
+ protected static final boolean DEBUG = Region.DEBUG;
+ protected static final boolean DEBUG_INSTANCE = Region.DEBUG_INSTANCE;
+
+ public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) {
+ return new RenderStateImpl(st, pointFactory, pmvMatrix);
+ }
- protected abstract boolean initImpl(GL2ES2 gl);
+ public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) {
+ return new RenderStateImpl(st, pointFactory);
+ }
+
+ /**
+ * Implementation shall load, compile and link the shader program and leave it active.
+ * @param gl
+ * @return
+ */
+ protected abstract boolean initShaderProgram(GL2ES2 gl);
protected abstract void disposeImpl(GL2ES2 gl);
/**
* Flushes all cached data
+ * @see #destroy(GL2ES2)
*/
- public abstract void flushCache();
+ public abstract void flushCache(GL2ES2 gl);
+
+ protected final RenderState rs;
+ public final int renderType;
- 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;
@@ -41,16 +77,15 @@ public abstract class Renderer {
private boolean initialized = false;
/**
- *
- * @param factory
+ * @param rs the used {@link RenderState}
* @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) {
+ protected Renderer(RenderState rs, int renderType) {
+ this.rs = rs;
this.renderType = renderType;
- this.pointFactory = (null != factory) ? factory : SVertex.factory();
}
- public Vertex.Factory<? extends Vertex> getFactory() { return pointFactory; }
+ public Vertex.Factory<? extends Vertex> getFactory() { return rs.getPointFactory(); }
public final boolean isInitialized() { return initialized; }
@@ -62,10 +97,12 @@ public abstract class Renderer {
public final int getHeight() { return vp_height; }
/**
- * Initialize shaders and bindings for GPU based rendering.
- * Leaves the renderer enabled, ie ShaderState on.
+ * Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext.
*
- * @param gl the current GL state
+ * Leaves the renderer enabled, ie ShaderState.
+ *
+ * @param gl referencing the current GLContext to which the ShaderState is bound to
+ *
* @return true if succeeded, false otherwise
*/
public boolean init(GL2ES2 gl) {
@@ -86,85 +123,176 @@ public abstract class Renderer {
System.err.println("TextRendererImpl01: VBO Supported = " + isVBOSupported());
}
- initialized = initImpl(gl);
+ if(!vboSupported){
+ return false;
+ }
+
+ rs.attachTo(gl);
+
+ gl.glEnable(GL2ES2.GL_BLEND);
+ gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA); // FIXME: alpha blending stage ?
+
+ initialized = initShaderProgram(gl);
+ if(!initialized) {
+ return false;
+ }
+
+ if(!rs.getShaderState().uniform(gl, rs.getPMVMatrix())) {
+ if(DEBUG){
+ System.err.println("Error setting PMVMatrix in shader: "+rs.getShaderState());
+ }
+ return false;
+ }
+
+ if(!rs.getShaderState().uniform(gl, rs.getSharpness())) {
+ if(DEBUG){
+ System.err.println("Error setting sharpness in shader: "+rs.getShaderState());
+ }
+ return false;
+ }
+
+ if(!rs.getShaderState().uniform(gl, rs.getAlpha())) {
+ if(DEBUG){
+ System.err.println("Error setting global alpha in shader: "+rs.getShaderState());
+ }
+ return false;
+ }
+
+ if(!rs.getShaderState().uniform(gl, rs.getColorStatic())) {
+ if(DEBUG){
+ System.err.println("Error setting global color in shader: "+rs.getShaderState());
+ }
+ return false;
+ }
+
+ if(!rs.getShaderState().uniform(gl, rs.getStrength())) {
+ System.err.println("Error setting antialias strength in shader: "+rs.getShaderState());
+ }
+
return initialized;
}
- public void dispose(GL2ES2 gl) {
+ public void destroy(GL2ES2 gl) {
if(!initialized){
- if(DEBUG) {
+ if(DEBUG_INSTANCE) {
System.err.println("TextRenderer: Not initialized!");
}
return;
}
+ rs.getShaderState().useProgram(gl, false);
+ flushCache(gl);
disposeImpl(gl);
- st.destroy(gl);
- flushCache();
+ rs.destroy(gl);
initialized = false;
}
- public final ShaderState getShaderState() { return st; }
+ public final RenderState getRenderState() { return rs; }
+ public final ShaderState getShaderState() { return rs.getShaderState(); }
public final void enable(GL2ES2 gl, boolean enable) {
- st.glUseProgram(gl, enable);
+ rs.getShaderState().useProgram(gl, enable);
}
- public final PMVMatrix getMatrix() { return pmvMatrix; }
+ public float getSharpness() {
+ return rs.getSharpness().floatValue();
+ }
+
+ public void setSharpness(GL2ES2 gl, float v) {
+ rs.getSharpness().setData(v);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().uniform(gl, rs.getSharpness());
+ }
+ }
- 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 float getStrength() {
+ return rs.getStrength().floatValue();
+ }
+
+ public void setStrength(GL2ES2 gl, float v) {
+ rs.getStrength().setData(v);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().uniform(gl, rs.getStrength());
}
}
+
+ public float getAlpha() {
+ return rs.getAlpha().floatValue();
+ }
- 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 setAlpha(GL2ES2 gl, float alpha_t) {
+ rs.getAlpha().setData(alpha_t);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().uniform(gl, rs.getAlpha());
}
+
}
- 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 getColorStatic(GL2ES2 gl, float[] rgb) {
+ FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
+ rgb[0] = fb.get(0);
+ rgb[1] = fb.get(1);
+ rgb[2] = fb.get(2);
+ }
+
+ public void setColorStatic(GL2ES2 gl, float r, float g, float b){
+ FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
+ fb.put(0, r);
+ fb.put(1, g);
+ fb.put(2, b);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().uniform(gl, rs.getColorStatic());
}
}
+
+ public final PMVMatrix getMatrix() { return rs.pmvMatrix(); }
+
+ public void rotate(GL2ES2 gl, float angle, float x, float y, float z) {
+ rs.pmvMatrix().glRotatef(angle, x, y, z);
+ updateMatrix(gl);
+ }
+
+ public void translate(GL2ES2 gl, float x, float y, float z) {
+ rs.pmvMatrix().glTranslatef(x, y, z);
+ updateMatrix(gl);
+ }
+
+ public void scale(GL2ES2 gl, float x, float y, float z) {
+ rs.pmvMatrix().glScalef(x, y, z);
+ updateMatrix(gl);
+ }
+
+ public void resetModelview(GL2ES2 gl) {
+ rs.pmvMatrix().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ rs.pmvMatrix().glLoadIdentity();
+ updateMatrix(gl);
+ }
public void updateMatrix(GL2ES2 gl) {
- if(initialized && null != gl && st.inUse()) {
- st.glUniform(gl, mgl_PMVMatrix);
+ if(initialized && null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().uniform(gl, rs.getPMVMatrix());
}
}
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);
- }
-
+ final float ratio = (float)width/(float)height;
+ final PMVMatrix p = rs.pmvMatrix();
+ p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ p.glLoadIdentity();
+ p.gluPerspective(angle, ratio, near, far);
+ updateMatrix(gl);
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);
- }
-
+ final PMVMatrix p = rs.pmvMatrix();
+ p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ p.glLoadIdentity();
+ p.glOrthof(0, width, 0, height, near, far);
+ updateMatrix(gl);
return true;
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
index 45f78fc23..deaa1dfad 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
@@ -1,9 +1,37 @@
+/**
+ * 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.opengl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import jogamp.graph.curve.text.GlyphString;
@@ -12,21 +40,21 @@ 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.
+ * @param rs the used {@link RenderState}
+ * @param renderType either {@link com.jogamp.graph.curve.Region#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS}
*/
- public static TextRenderer create(Vertex.Factory<? extends Vertex> factory, int type) {
- return new jogamp.graph.curve.opengl.TextRendererImpl01(factory, type);
+ public static TextRenderer create(RenderState rs, int type) {
+ return new jogamp.graph.curve.opengl.TextRendererImpl01(rs, type);
}
- protected TextRenderer(Vertex.Factory<? extends Vertex> factory, int type) {
- super(factory, type);
+ protected TextRenderer(RenderState rs, int type) {
+ super(rs, 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
@@ -46,27 +74,29 @@ public abstract class TextRenderer extends Renderer {
* @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);
+ public GlyphString createString(GL2ES2 gl, Font font, int size, String str) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("createString: "+getCacheSize()+"/"+getCacheLimit()+" - "+Font.NAME_UNIQUNAME + " - " + str + " - " + size);
+ }
+ AffineTransform affineTransform = new AffineTransform(rs.getPointFactory());
Path2D[] paths = new Path2D[str.length()];
((FontInt)font).getOutline(str, size, affineTransform, paths);
- GlyphString glyphString = new GlyphString(pointFactory, font.getName(Font.NAME_UNIQUNAME), str);
- glyphString.createfromFontPath(paths, affineTransform);
- glyphString.generateRegion(gl.getContext(), sharpness, st, renderType);
+ GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str);
+ glyphString.createfromFontPath(rs.getPointFactory(), paths, affineTransform);
+ glyphString.generateRegion(gl, rs, renderType);
return glyphString;
}
- public void flushCache() {
+ public void flushCache(GL2ES2 gl) {
Iterator<GlyphString> iterator = stringCacheMap.values().iterator();
while(iterator.hasNext()){
GlyphString glyphString = iterator.next();
- glyphString.destroy();
+ glyphString.destroy(gl, rs);
}
stringCacheMap.clear();
stringCacheArray.clear();
@@ -74,35 +104,90 @@ public abstract class TextRenderer extends Renderer {
@Override
protected void disposeImpl(GL2ES2 gl) {
- flushCache();
+ // fluchCache(gl) already called
}
- public final void setCacheMaxSize(int newSize ) { stringCacheMaxSize = newSize; validateCache(0); }
- public final int getCacheMaxSize() { return stringCacheMaxSize; }
+ /**
+ * <p>Sets the cache limit for reusing GlyphString's and their Region.
+ * Default is {@link #DEFAULT_CACHE_LIMIT}, -1 unlimited, 0 turns cache off, >0 limited </p>
+ *
+ * <p>The cache will be validate when the next string rendering happens.</p>
+ *
+ * @param newLimit new cache size
+ *
+ * @see #DEFAULT_CACHE_LIMIT
+ */
+ public final void setCacheLimit(int newLimit ) { stringCacheLimit = newLimit; }
+
+ /**
+ * Sets the cache limit, see {@link #setCacheLimit(int)} and validates the cache.
+ *
+ * @see #setCacheLimit(int)
+ *
+ * @param gl current GL used to remove cached objects if required
+ * @param newLimit new cache size
+ */
+ public final void setCacheLimit(GL2ES2 gl, int newLimit ) { stringCacheLimit = newLimit; validateCache(gl, 0); }
+
+ /**
+ * @return the current cache limit
+ */
+ public final int getCacheLimit() { return stringCacheLimit; }
+
+ /**
+ * @return the current utilized cache size, <= {@link #getCacheLimit()}
+ */
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 final void validateCache(GL2ES2 gl, int space) {
+ if ( getCacheLimit() > 0 ) {
+ while ( getCacheSize() + space > getCacheLimit() ) {
+ removeCachedGlyphString(gl, 0);
+ }
}
}
- protected GlyphString getCachedGlyphString(Font font, String str, int fontSize) {
- final String key = font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize;
- return stringCacheMap.get(key);
+ protected final GlyphString getCachedGlyphString(Font font, String str, int fontSize) {
+ return stringCacheMap.get(getKey(font, str, fontSize));
}
- protected void addCachedGlyphString(Font font, String str, int fontSize, GlyphString glyphString) {
- final String key = font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize;
- validateCache(1);
- stringCacheMap.put(key, glyphString);
- stringCacheArray.add(stringCacheArray.size(), key);
+ protected final void addCachedGlyphString(GL2ES2 gl, Font font, String str, int fontSize, GlyphString glyphString) {
+ if ( 0 != getCacheLimit() ) {
+ final String key = getKey(font, str, fontSize);
+ GlyphString oldGlyphString = stringCacheMap.put(key, glyphString);
+ if ( null == oldGlyphString ) {
+ // new entry ..
+ validateCache(gl, 1);
+ stringCacheArray.add(stringCacheArray.size(), key);
+ } /// else overwrite is nop ..
+ }
+ }
+
+ protected final void removeCachedGlyphString(GL2ES2 gl, Font font, String str, int fontSize) {
+ final String key = getKey(font, str, fontSize);
+ GlyphString glyphString = stringCacheMap.remove(key);
+ if(null != glyphString) {
+ glyphString.destroy(gl, rs);
+ }
+ stringCacheArray.remove(key);
+ }
+
+ protected final void removeCachedGlyphString(GL2ES2 gl, int idx) {
+ final String key = stringCacheArray.remove(idx);
+ final GlyphString glyphString = stringCacheMap.remove(key);
+ if(null != glyphString) {
+ glyphString.destroy(gl, rs);
+ }
+ }
+
+ protected final String getKey(Font font, String str, int fontSize) {
+ return font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize;
}
- // 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
+ /** Default cache limit, see {@link #setCacheLimit(int)} */
+ public static final int DEFAULT_CACHE_LIMIT = 256;
+
+ private HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_LIMIT);
+ private ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_LIMIT);
+ private int stringCacheLimit = DEFAULT_CACHE_LIMIT;
} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java
index a2e4ca50f..42eebf7a8 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/tess/CDTriangulator2D.java
@@ -48,169 +48,169 @@ import jogamp.opengl.Debug;
*/
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;
+ 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++;
+
+ 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;
- }
+ 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;
- }
+ 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/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index d8c30c61b..1010d4f1a 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -52,27 +52,27 @@ public interface Font {
public static final int NAME_DESIGNER = 9;
- /**
- * 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
+ /**
+ * 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);
+ float getAscent(float pixelSize);
+ float getDescent(float pixelSize);
+ float getLineGap(float pixelSize);
+ float getMaxExtend(float pixelSize);
+ float getScale(float pixelSize);
+ AABBox getBBox(float pixelSize);
}
- /**
- * Glyph for font
- */
+ /**
+ * Glyph for font
+ */
public interface Glyph {
public Font getFont();
public char getSymbol();
diff --git a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java b/src/jogl/classes/com/jogamp/graph/geom/AABBox.java
index 8cd06329e..7051e9110 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/AABBox.java
@@ -36,176 +36,181 @@ import com.jogamp.graph.math.VectorUtil;
*
*/
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];
+ private float[] low = new float[3];
+ private float[] high = new float[3];
+ 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 a Axis Aligned bounding box (AABBox)
+ * where the low and and high MAX float Values.
+ */
+ public AABBox() {
+ reset();
+ }
- /** 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);
+ /** 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)
+ {
+ reset();
+ resize(lx, ly, lz);
+ resize(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();
+ }
+
+ /** Create a AABBox defining the low and high
+ * @param low min xyz-coordinates
+ * @param high max xyz-coordinates
+ */
+ public AABBox(float[] low, float[] high) {
+ reset();
+ resize(low[0],low[1],low[2]);
+ resize(high[0],high[1],high[2]);
- 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;
- }
+ computeCenter();
+ }
+
+ /** resets this box to the inverse low/high, allowing the next {@link #resize(float, float, float)} command to hit. */
+ public void reset() {
+ setLow(Float.MAX_VALUE,Float.MAX_VALUE,Float.MAX_VALUE);
+ setHigh(-1*Float.MAX_VALUE,-1*Float.MAX_VALUE,-1*Float.MAX_VALUE);
+ center[0] = 0f;
+ center[1] = 0f;
+ center[2] = 0f;
+ }
+
+ /** 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();
+ /** 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 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];
+ /** 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();
- }
+ 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;
- }
+ 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;
+ /** 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();
- }
+ /** 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 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
+ * 2D region irrespective of z range
* @param x lower left x-coord
* @param y lower left y-coord
* @param w width
@@ -213,87 +218,87 @@ public class AABBox {
* @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);
+ 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 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;
- }
+ /**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);
- }
+ /** 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]+" ]";
- }
+ 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/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
index a805adf6c..315be002f 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
@@ -44,133 +44,133 @@ import com.jogamp.graph.math.VectorUtil;
* @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;
- }
+
+ 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/jogl/classes/com/jogamp/graph/geom/Triangle.java b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
index d13e8ddb1..fb34de221 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
@@ -28,52 +28,52 @@
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;
+ private int id = Integer.MAX_VALUE;
+ final private Vertex[] vertices;
+ private boolean[] boundaryEdges = new boolean[3];
+ private boolean[] boundaryVertices = null;
- public Triangle(Vertex ... v123){
- vertices = v123;
- }
+ public Triangle(Vertex ... v123){
+ vertices = v123;
+ }
- public int getId() {
- return id;
- }
+ public int getId() {
+ return id;
+ }
- public void setId(int id) {
- this.id = id;
- }
+ public void setId(int id) {
+ this.id = id;
+ }
- 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 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 void setEdgesBoundary(boolean[] boundary) {
- this.boundaryEdges = boundary;
- }
-
- public boolean[] getEdgeBoundary() {
- return boundaryEdges;
- }
-
- public boolean[] getVerticesBoundary() {
- return boundaryVertices;
- }
+ public void setEdgesBoundary(boolean[] boundary) {
+ this.boundaryEdges = boundary;
+ }
+
+ public boolean[] getEdgeBoundary() {
+ return boundaryEdges;
+ }
+
+ public boolean[] getVerticesBoundary() {
+ return boundaryVertices;
+ }
- 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 void setVerticesBoundary(boolean[] boundaryVertices) {
+ this.boundaryVertices = boundaryVertices;
+ }
+
+ public String toString() {
+ return "Tri ID: " + id + "\n" + vertices[0] + "\n" + vertices[1] + "\n" + vertices[2];
+ }
}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
index 0e4e5e8df..859add943 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
@@ -32,49 +32,49 @@ package com.jogamp.graph.geom;
*/
public interface Vertex extends Comparable<Vertex>, Cloneable {
- public static interface Factory <T extends Vertex> {
- T create();
+ public static interface Factory <T extends Vertex> {
+ T create();
- T create(float x, float y);
+ T create(float x, float y);
- T create(float x, float y, float z);
+ T create(float x, float y, float z);
- T create(float[] coordsBuffer, int offset, int length);
- }
-
- void setCoord(float x, float y);
+ 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 x, float y, float z);
- void setCoord(float[] coordsBuffer, int offset, int length);
-
- float[] getCoord();
+ void setCoord(float[] coordsBuffer, int offset, int length);
+
+ float[] getCoord();
- void setX(float x);
+ void setX(float x);
- void setY(float y);
+ void setY(float y);
- void setZ(float z);
+ void setZ(float z);
- float getX();
+ float getX();
- float getY();
+ float getY();
- float getZ();
+ float getZ();
- boolean isOnCurve();
+ boolean isOnCurve();
- void setOnCurve(boolean onCurve);
+ void setOnCurve(boolean onCurve);
- int getId();
-
- void setId(int id);
-
- int compareTo(Vertex p);
-
- float[] getTexCoord();
-
- void setTexCoord(float s, float t);
-
- Vertex clone();
+ int getId();
+
+ void setId(int id);
+
+ int compareTo(Vertex p);
+
+ float[] getTexCoord();
+
+ void setTexCoord(float s, float t);
+
+ Vertex clone();
}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java b/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
index 681067e40..6241d60df 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
@@ -36,143 +36,143 @@ import com.jogamp.graph.math.VectorUtil;
*
*/
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] + "]";
- }
+ 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/jogl/classes/com/jogamp/graph/math/Quaternion.java b/src/jogl/classes/com/jogamp/graph/math/Quaternion.java
index b77a5fa08..38638dc5a 100755
--- a/src/jogl/classes/com/jogamp/graph/math/Quaternion.java
+++ b/src/jogl/classes/com/jogamp/graph/math/Quaternion.java
@@ -30,353 +30,353 @@ package com.jogamp.graph.math;
import jogamp.graph.math.MathFloat;
public class Quaternion {
- protected float x,y,z,w;
+ protected float x,y,z,w;
- public Quaternion(){
+ 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);
+ }
+
+ 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];
+ 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];
+ 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];
+ 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;
- }
+ 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);
+ /** 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;
+ 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 = 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;
+ 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;
+ 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;
+ 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[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[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];
- }
+ 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/jogl/classes/com/jogamp/graph/math/VectorUtil.java b/src/jogl/classes/com/jogamp/graph/math/VectorUtil.java
index cca9a454f..7cbb742e5 100755
--- a/src/jogl/classes/com/jogamp/graph/math/VectorUtil.java
+++ b/src/jogl/classes/com/jogamp/graph/math/VectorUtil.java
@@ -35,261 +35,261 @@ 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;
+ 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];
+ /** 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;
- }
+ 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];
+ /** 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] = 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;
- }
+ 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];
+ /** 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];
+ 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;
- }
+ 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];
+ /** 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];
+ 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];
+ 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];
+ 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 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]};
+ 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]);
+ float distance = MathFloat.sqrt(w[0]*w[0] + w[1]*w[1] + w[2]*w[2]);
- return distance;
- }
+ 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;
- }
+ /**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;
- }
+ /** 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);
- }
+ /** 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;
- }
+ /** 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;
- }
+ /** 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());
- }
+ /** 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;
- }
+ /** 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;
- }
+ /** 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/jogl/classes/com/jogamp/graph/package.html b/src/jogl/classes/com/jogamp/graph/package.html
new file mode 100644
index 000000000..f696020ab
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/graph/package.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <title>Public Graph Utility Package</title>
+</head>
+ <body>
+
+<h2>Public <i>Graph</i> Utility Package</h2>
+
+<h3>Disclaimer</h3>
+ <p>
+ The API of the namespace <i>com.jogamp.graph.**</i>
+ is experimental and subject to change until further notice.
+ </p>
+ <p>
+ It's implementation <i>jogamp.graph.**</i> may change at any time
+ as it is natural with all other API implementations.
+ </p>
+ <p>
+ We are currently refining and completing this new API and it's implementation.
+ Feel free to comment and help using our public channels.
+ </p>
+<h3>Revision History<br>
+ </h3>
+
+<ul>
+<li> Early Draft Review, April 1st 2011</li>
+</ul>
+ <br>
+ <br>
+ <br>
+</body>
+</html>
diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java
index 4fbd0e478..e7fbc4d58 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/Animator.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java
@@ -125,7 +125,7 @@ public class Animator extends AnimatorBase {
class MainLoop implements Runnable {
public String toString() {
- return "[started "+isStartedImpl()+", animating "+isAnimatingImpl()+", paused "+isPausedImpl()+", frames "+getTotalFrames()+", drawable "+drawables.size()+"]";
+ return "[started "+isStartedImpl()+", animating "+isAnimatingImpl()+", paused "+isPausedImpl()+", drawable "+drawables.size()+"]";
}
public void run() {
@@ -134,11 +134,7 @@ public class Animator extends AnimatorBase {
if(DEBUG) {
System.err.println("Animator start:" + Thread.currentThread() + ": " + toString());
}
-
- startTime = System.currentTimeMillis();
- curTime = startTime;
- totalFrames = 0;
-
+ fpsCounter.resetFPSCounter();
animThread = Thread.currentThread();
setIsAnimatingSynced(false); // barrier
Animator.this.notifyAll();
@@ -161,9 +157,7 @@ public class Animator extends AnimatorBase {
if (wasPaused) {
// resume from pause -> reset counter
- startTime = System.currentTimeMillis();
- curTime = startTime;
- totalFrames = 0;
+ fpsCounter.resetFPSCounter();
if (DEBUG) {
System.err.println("Animator resume:" + Thread.currentThread() + ": " + toString());
}
@@ -269,7 +263,7 @@ public class Animator extends AnimatorBase {
if (runnable == null) {
runnable = new MainLoop();
}
- resetCounter();
+ fpsCounter.resetFPSCounter();
String threadName = Thread.currentThread().getName()+"-"+baseName;
Thread thread;
if(null==threadGroup) {
diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
index 01c2ea664..a6ba74665 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
@@ -30,7 +30,12 @@ package com.jogamp.opengl.util;
import com.jogamp.common.util.locks.RecursiveLock;
import jogamp.opengl.Debug;
+import jogamp.opengl.FPSCounterImpl;
+
+import java.io.PrintStream;
import java.util.ArrayList;
+
+import javax.media.opengl.FPSCounter;
import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLProfile;
@@ -61,9 +66,7 @@ public abstract class AnimatorBase implements GLAnimatorControl {
protected Thread animThread;
protected boolean ignoreExceptions;
protected boolean printExceptions;
- protected long startTime;
- protected long curTime;
- protected int totalFrames;
+ protected FPSCounterImpl fpsCounter = new FPSCounterImpl();
protected RecursiveLock stateSync = new RecursiveLock();
/** Creates a new, empty Animator. */
@@ -83,7 +86,6 @@ public abstract class AnimatorBase implements GLAnimatorControl {
baseName = baseName.concat("-"+animatorCount);
drawablesEmpty = true;
}
- resetCounter();
}
protected abstract String getBaseName(String prefix);
@@ -138,25 +140,48 @@ public abstract class AnimatorBase implements GLAnimatorControl {
lightweight widgets are continually being redrawn. */
protected void display() {
impl.display(drawables, ignoreExceptions, printExceptions);
- curTime = System.currentTimeMillis();
- totalFrames++;
+ fpsCounter.tickFPS();
+ }
+
+ public final void setUpdateFPSFrames(int frames, PrintStream out) {
+ fpsCounter.setUpdateFPSFrames(frames, out);
+ }
+
+ public final void resetFPSCounter() {
+ fpsCounter.resetFPSCounter();
}
- public long getCurrentTime() {
- return curTime;
+ public final int getUpdateFPSFrames() {
+ return fpsCounter.getUpdateFPSFrames();
+ }
+
+ public final long getFPSStartTime() {
+ return fpsCounter.getFPSStartTime();
}
- public long getDuration() {
- return curTime - startTime;
+ public final long getLastFPSUpdateTime() {
+ return fpsCounter.getLastFPSUpdateTime();
}
- public long getStartTime() {
- return startTime;
+ public final long getLastFPSPeriod() {
+ return fpsCounter.getLastFPSPeriod();
+ }
+
+ public final float getLastFPS() {
+ return fpsCounter.getLastFPS();
+ }
+
+ public final int getTotalFPSFrames() {
+ return fpsCounter.getTotalFPSFrames();
}
- public int getTotalFrames() {
- return totalFrames;
+ public final long getTotalFPSDuration() {
+ return fpsCounter.getTotalFPSDuration();
}
+
+ public final float getTotalFPS() {
+ return fpsCounter.getTotalFPS();
+ }
public final Thread getThread() {
stateSync.lock();
@@ -167,12 +192,6 @@ public abstract class AnimatorBase implements GLAnimatorControl {
}
}
- 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. */
@@ -189,6 +208,6 @@ public abstract class AnimatorBase implements GLAnimatorControl {
}
public String toString() {
- return getClass().getName()+"[started "+isStarted()+", animating "+isAnimating()+", paused "+isPaused()+", frames "+getTotalFrames()+", drawable "+drawables.size()+"]";
+ return getClass().getName()+"[started "+isStarted()+", animating "+isAnimating()+", paused "+isPaused()+", drawable "+drawables.size()+"]";
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/FBObject.java b/src/jogl/classes/com/jogamp/opengl/util/FBObject.java
index ad32b4ffe..c57d4b057 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/FBObject.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/FBObject.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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
@@ -39,21 +40,23 @@ public class FBObject {
private int width, height;
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;
-
+ private boolean bound;
+
public FBObject(int width, int height) {
this.width = width;
this.height = height;
this.fb = 0;
this.fbo_tex = 0;
this.depth_rb = 0;
- this.stencil_rb = 0;
+ this.stencil_rb = 0;
+ this.bound = false;
}
-
- public boolean validateStatus(GL gl) {
- /* vStatus = */ getStatus(gl);
+
+ /**
+ * @return true if the FB status is valid, otherwise false
+ * @see #getStatus()
+ */
+ public boolean isStatusValid() {
switch(vStatus) {
case GL.GL_FRAMEBUFFER_COMPLETE:
return true;
@@ -73,48 +76,40 @@ public class FBObject {
}
}
- /** @return {@link GL.GL_FRAMEBUFFER_COMPLETE} if ok, otherwise return GL FBO error state or -1 */
+ /**
+ * @return The FB status. {@link GL.GL_FRAMEBUFFER_COMPLETE} if ok, otherwise return GL FBO error state or -1
+ * @see #validateStatus()
+ */
public int getStatus() {
return vStatus;
}
- public int getStatus(GL gl) {
- if(!gl.glIsFramebuffer(fb)) {
- vStatus = -1;
- } else {
- vStatus = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER);
- }
- return vStatus;
- }
-
public String getStatusString() {
return getStatusString(vStatus);
}
- public static String getStatusString(int fbStatus) {
+ public static final 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_ATTACHMENT:
+ return("GL FBO: incomplete, incomplete attachment\n");
case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
- return("GL FBO: 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");
+ 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");
- /*
+ return("GL FBO: incomplete, attached images must have same format");
case GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
- return("GL FBO: incomplete,missing 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");
- */
+ return("GL FBO: incomplete, missing read buffer");
+ case GL2.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
+ return("GL FBO: incomplete, missing multisample buffer");
case 0:
return("GL FBO: incomplete, implementation fault");
default:
@@ -154,6 +149,19 @@ public class FBObject {
return init(gl, textureInternalFormat, textureDataFormat, textureDataType, magFilter, minFilter, wrapS, wrapT);
}
+ private boolean checkNoError(GL gl, int err, String exceptionMessage) {
+ if(GL.GL_NO_ERROR != err) {
+ if(null != gl) {
+ destroy(gl);
+ }
+ if(null != exceptionMessage) {
+ throw new GLException(exceptionMessage+" GL Error 0x"+Integer.toHexString(err));
+ }
+ return false;
+ }
+ return true;
+ }
+
/**
* Initializes this FBO's instance with it's texture.
*
@@ -176,6 +184,8 @@ public class FBObject {
throw new GLException("FBO already initialized (fb "+fb+", tex "+fbo_tex+")");
}
+ checkNoError(null, gl.glGetError(), "FBObject Init.pre"); // throws GLException if error
+
texInternalFormat=textureInternalFormat;
texDataFormat=textureDataFormat;
texDataType=textureDataType;
@@ -189,24 +199,24 @@ public class FBObject {
throw new GLException("null generated framebuffer");
}
- gl.glGenTextures(1, name, 0);
- fbo_tex = name[0];
- if(fbo_tex==0) {
- throw new GLException("null generated texture");
- }
-
// bind fbo ..
- gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb);
+ gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb);
+ checkNoError(gl, gl.glGetError(), "FBObject Init.bindFB"); // throws GLException if error
if(!gl.glIsFramebuffer(fb)) {
- destroy(gl);
- System.err.println("not a framebuffer: "+ fb);
- return false;
+ checkNoError(gl, GL.GL_INVALID_VALUE, "FBObject Init.isFB"); // throws GLException
}
bound = true;
+ gl.glGenTextures(1, name, 0);
+ fbo_tex = name[0];
+ if(fbo_tex==0) {
+ throw new GLException("null generated texture");
+ }
gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex);
+ checkNoError(gl, gl.glGetError(), "FBObject Init.bindTex"); // throws GLException if error
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, texInternalFormat, width, height, 0,
texDataFormat, texDataType, null);
+ checkNoError(gl, gl.glGetError(), "FBObject Init.texImage2D"); // throws GLException if error
if( 0 < magFilter ) {
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, magFilter);
}
@@ -225,7 +235,8 @@ public class FBObject {
GL.GL_COLOR_ATTACHMENT0,
GL.GL_TEXTURE_2D, fbo_tex, 0);
- return validateStatus(gl);
+ updateStatus(gl);
+ return isStatusValid();
}
/**
@@ -264,7 +275,8 @@ public class FBObject {
gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
GL.GL_DEPTH_ATTACHMENT,
GL.GL_RENDERBUFFER, depth_rb);
- return validateStatus(gl);
+ updateStatus(gl);
+ return isStatusValid();
}
/**
@@ -283,7 +295,6 @@ public class FBObject {
checkBound(true);
int name[] = new int[1];
gl.glGenRenderbuffers(1, name, 0);
- gl.glGenRenderbuffers(1, name, 0);
stencil_rb = name[0];
if(stencil_rb==0) {
throw new GLException("null generated stencilbuffer");
@@ -299,7 +310,8 @@ public class FBObject {
gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
GL.GL_STENCIL_ATTACHMENT,
GL.GL_RENDERBUFFER, stencil_rb);
- return validateStatus(gl);
+ updateStatus(gl);
+ return isStatusValid();
}
public void destroy(GL gl) {
@@ -331,8 +343,6 @@ public class FBObject {
}
}
- boolean bound = false;
-
private final void checkBound(boolean shallBeBound) {
if(bound != shallBeBound) {
final String s0 = shallBeBound ? "not" : "already" ;
@@ -355,16 +365,31 @@ public class FBObject {
}
public void use(GL gl) {
- if(bound) {
- unbind(gl);
- }
- gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex); // to use it ..
+ checkBound(false);
+ gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex); // use it ..
}
- public int getFBName() {
- return fb;
+ public void unuse(GL gl) {
+ checkBound(false);
+ gl.glBindTexture(GL.GL_TEXTURE_2D, 0); // don't use it
}
- public int getTextureName() {
- return fbo_tex;
+
+ public final boolean isBound() { return bound; }
+ public final int getWidth() { return width; }
+ public final int getHeight() { return height; }
+ public final int getFBName() { return fb; }
+ public final int getTextureName() { return fbo_tex; }
+ public final int getStencilBuffer() { return stencil_rb; }
+ public final int getDepthBuffer() { return depth_rb; }
+ public final String toString() {
+ return "FBO[name "+fb+", size "+width+"x"+height+", tex "+fbo_tex+", depth "+depth_rb+", stencil "+stencil_rb+"]";
}
+
+ private void updateStatus(GL gl) {
+ if(!gl.glIsFramebuffer(fb)) {
+ vStatus = -1;
+ } else {
+ vStatus = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER);
+ }
+ }
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java
index fc364b67a..f7fc58160 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java
@@ -116,9 +116,9 @@ public class FPSAnimator extends AnimatorBase {
}
private void startTask() {
- if(null != task) {
- return;
- }
+ if(null != task) {
+ return;
+ }
long delay = (long) (1000.0f / (float) fps);
task = new TimerTask() {
public void run() {
@@ -130,7 +130,7 @@ public class FPSAnimator extends AnimatorBase {
}
};
- resetCounter();
+ fpsCounter.resetFPSCounter();
shouldRun = true;
if (scheduleAtFixedRate) {
@@ -165,12 +165,12 @@ public class FPSAnimator extends AnimatorBase {
try {
shouldRun = false;
if(null != task) {
- task.cancel();
- task = null;
+ task.cancel();
+ task = null;
}
if(null != timer) {
- timer.cancel();
- timer = null;
+ timer.cancel();
+ timer = null;
}
animThread = null;
try {
@@ -190,8 +190,8 @@ public class FPSAnimator extends AnimatorBase {
try {
shouldRun = false;
if(null != task) {
- task.cancel();
- task = null;
+ task.cancel();
+ task = null;
}
animThread = null;
try {
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
index 4586d1df5..d80d398aa 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
@@ -28,65 +28,106 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
}) != null;
/**
+ * Create a client side buffer 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 chosen.
+ *
* @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
+ * @param normalized Whether the data shall be normalized
+ * @param initialSize
*
* @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)
+ */
+ public static GLArrayDataClient createFixed(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);
+ adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, -1, -1, -1, -1);
return adc;
}
- public static GLArrayDataClient createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized,
- int stride, Buffer buffer)
+ /**
+ * Create a client side buffer 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 chosen.
+ *
+ * @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 Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ *
+ * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
+ */
+ public static GLArrayDataClient createFixed(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);
+ adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler, -1, -1, -1, -1);
return adc;
}
- public static GLArrayDataClient createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
- int initialSize)
+ /**
+ * Create a client side buffer object, using a custom GLSL array attribute name
+ * and starting with a new created Buffer object with initialSize size
+ *
+ * @param st The ShaderState managing the state of the used shader program, vertex attributes and uniforms
+ * @param name The custom name for the GL attribute.
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param initialSize
+ */
+ public static GLArrayDataClient createGLSL(ShaderState st, 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);
+ GLArrayHandler glArrayHandler = new GLSLArrayHandler(st, adc);
+ adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, -1, -1, -1, -1);
return adc;
}
- public static GLArrayDataClient createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
- int stride, Buffer buffer)
+ /**
+ * Create a client side buffer object, using a custom GLSL array attribute name
+ * and starting with a given Buffer object incl it's stride
+ *
+ * @param st The ShaderState managing the state of the used shader program, vertex attributes and uniforms
+ * @param name The custom name for the GL attribute.
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ */
+ public static GLArrayDataClient createGLSL(ShaderState st, 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);
+ GLArrayHandler glArrayHandler = new GLSLArrayHandler(st, adc);
+ adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler, -1, -1, -1, -1);
return adc;
}
@@ -94,21 +135,21 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
// Data read access
//
- public final boolean isBufferWritten() { return bufferWritten; }
+ public final boolean isVBOWritten() { return bufferWritten; }
public final boolean sealed() { return sealed; }
-
- public int getBufferUsage() { return -1; }
+
+ public final boolean enabled() { return bufferEnabled; }
//
// Data and GL state modification ..
//
- public final void setBufferWritten(boolean written) { bufferWritten=written; }
+ public final void setVBOWritten(boolean written) { bufferWritten=written; }
public void destroy(GL gl) {
reset(gl);
- buffer=null;
+ super.destroy(gl);
}
public void reset(GL gl) {
@@ -116,30 +157,17 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
reset();
}
- public void seal(GL gl, boolean seal)
- {
+ 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);
- }
+ enableBuffer(gl, seal);
}
public void enableBuffer(GL gl, boolean enable) {
- if(enableBufferAlways && enable) {
- bufferEnabled = false;
- }
- if( bufferEnabled != enable && components>0 ) {
+ if( enableBufferAlways || bufferEnabled != enable ) {
if(enable) {
checkSeal(true);
- if(null!=buffer) {
- buffer.rewind();
- }
+ // init/generate VBO name if not done yet
+ init_vbo(gl);
}
glArrayHandler.enableBuffer(gl, enable);
bufferEnabled = enable;
@@ -167,16 +195,14 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
{
if(sealed==seal) return;
sealed = seal;
+ bufferWritten=false;
if(seal) {
- bufferWritten=false;
if (null!=buffer) {
buffer.flip();
}
- } else {
- if (null!=buffer) {
- buffer.position(buffer.limit());
- buffer.limit(buffer.capacity());
- }
+ } else if (null!=buffer) {
+ buffer.position(buffer.limit());
+ buffer.limit(buffer.capacity());
}
}
@@ -202,7 +228,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
* The arguments remaining elements must be a multiple of this arrays element stride.
*/
public void put(Buffer v) {
- if ( buffer==null || sealed ) return;
+ if ( sealed ) return;
if(0!=(v.remaining() % strideL)) {
throw new GLException("Buffer length ("+v.remaining()+") is not a multiple of component-stride:\n\t"+this);
}
@@ -211,19 +237,19 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
}
public void putb(byte v) {
- if ( buffer==null || sealed ) return;
+ if ( sealed ) return;
growBufferIfNecessary(1);
Buffers.putb(buffer, v);
}
public void puts(short v) {
- if ( buffer==null || sealed ) return;
+ if ( sealed ) return;
growBufferIfNecessary(1);
Buffers.puts(buffer, v);
}
public void puti(int v) {
- if ( buffer==null || sealed ) return;
+ if ( sealed ) return;
growBufferIfNecessary(1);
Buffers.puti(buffer, v);
}
@@ -233,7 +259,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
}
public void putf(float v) {
- if ( buffer==null || sealed ) return;
+ if ( sealed ) return;
growBufferIfNecessary(1);
Buffers.putf(buffer, v);
}
@@ -243,8 +269,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
", index "+index+
", location "+location+
", isVertexAttribute "+isVertexAttribute+
- ", dataType "+dataType+
- ", bufferClazz "+clazz+
+ ", dataType "+componentType+
+ ", bufferClazz "+componentClazz+
", elements "+getElementNumber()+
", components "+components+
", stride "+stride+"u "+strideB+"b "+strideL+"c"+
@@ -252,7 +278,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
", sealed "+sealed+
", bufferEnabled "+bufferEnabled+
", bufferWritten "+bufferWritten+
- ", buffer "+buffer+
+ ", buffer "+buffer+
+ ", alive "+alive+
"]";
}
@@ -260,55 +287,58 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
protected final boolean growBufferIfNecessary(int spare) {
if(buffer==null || buffer.remaining()<spare) {
- growBuffer(initialSize);
+ growBuffer(Math.max(initialSize, spare));
return true;
}
return false;
}
- protected final void growBuffer(int additional) {
- if(sealed || 0==additional || 0==components) return;
+ protected final void growBuffer(int additional) {
+ if(!alive || sealed) {
+ throw new GLException("Invalid state: "+this);
+ }
// 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);
+ int osize = (buffer!=null)?buffer.capacity():0;
+ if(componentClazz==ByteBuffer.class) {
+ ByteBuffer newBBuffer = Buffers.newDirectByteBuffer( (osize+additional) * components );
+ if(buffer!=null) {
+ buffer.flip();
+ newBBuffer.put((ByteBuffer)buffer);
+ }
+ buffer = newBBuffer;
+ } else if(componentClazz==ShortBuffer.class) {
+ ShortBuffer newSBuffer = Buffers.newDirectShortBuffer( (osize+additional) * components );
+ if(buffer!=null) {
+ buffer.flip();
+ newSBuffer.put((ShortBuffer)buffer);
}
+ buffer = newSBuffer;
+ } else if(componentClazz==IntBuffer.class) {
+ IntBuffer newIBuffer = Buffers.newDirectIntBuffer( (osize+additional) * components );
+ if(buffer!=null) {
+ buffer.flip();
+ newIBuffer.put((IntBuffer)buffer);
+ }
+ buffer = newIBuffer;
+ } else if(componentClazz==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: "+componentClazz+":\n\t"+this);
}
}
protected final void checkSeal(boolean test) throws GLException {
+ if(!alive) {
+ throw new GLException("Invalid state: "+this);
+ }
if(sealed!=test) {
if(test) {
throw new GLException("Not Sealed yet, seal first:\n\t"+this);
@@ -320,29 +350,35 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
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)
+ int vboName, long vboOffset, int vboUsage, int vboTarget)
throws GLException
{
super.init(name, index, comps, dataType, normalized, stride, data, isVertexAttribute,
- vboName, bufferOffset);
+ vboName, vboOffset, vboUsage, vboTarget);
this.initialSize = initialSize;
this.glArrayHandler = handler;
this.sealed=false;
- this.sealedGL=false;
this.bufferEnabled=false;
this.enableBufferAlways=false;
this.bufferWritten=false;
- if(null==buffer) {
+ if(null==buffer && initialSize>0) {
growBuffer(initialSize);
}
}
- protected void init_vbo(GL gl) {}
+ private boolean isValidated = false;
+
+ protected void init_vbo(GL gl) {
+ if(!isValidated ) {
+ isValidated = true;
+ validate(gl.getGLProfile(), true);
+ }
+ }
protected GLArrayDataClient() { }
- protected boolean sealed, sealedGL;
+ protected boolean sealed;
protected boolean bufferEnabled;
protected boolean bufferWritten;
protected boolean enableBufferAlways;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
index 0f8ed27be..0da7d1171 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
@@ -14,21 +14,18 @@ import java.nio.*;
public interface GLArrayDataEditable extends GLArrayData {
public boolean sealed();
+
+ public boolean enabled();
/**
- * The VBO buffer usage, if it's an VBO, otherwise -1
+ * Is the buffer written to the VBO ?
*/
- public int getBufferUsage();
+ public boolean isVBOWritten();
/**
- * Is the buffer written to the GPU ?
+ * Marks the buffer written to the VBO
*/
- public boolean isBufferWritten();
-
- /**
- * Marks the buffer written to the GPU
- */
- public void setBufferWritten(boolean written);
+ public void setVBOWritten(boolean written);
//
// Data and GL state modification ..
@@ -39,29 +36,27 @@ public interface GLArrayDataEditable extends GLArrayData {
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.
+ * Convenience method calling {@link #seal(boolean)} and {@link #enableBuffer(GL, boolean)}.
*
* @see #seal(boolean)
+ * @see #enableBuffer(GL, 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.
+ * <p>Enables/disables the buffer,
+ * sets the client state, binds the VBO if used
+ * and transfers the data if necessary.</p>
+ *
+ * <p>The action will only be executed,
+ * if the internal enable state differs,
+ * or 'setEnableAlways' was called with 'true'.</b>
*
- * The above will only be executed,
- * if the buffer is disabled,
- * or 'setEnableAlways' was called with 'true'.
+ * <p>It is up to the user to enable/disable the array properly,
+ * ie in case of multiple data sets for the same vertex attribute (VA).
+ * Meaning in such case usage of one set while expecting another one
+ * to be used for the same VA implies decorating each usage with enable/disable.</p>
*
* @see #setEnableAlways(boolean)
*/
@@ -72,8 +67,9 @@ public interface GLArrayDataEditable extends GLArrayData {
*
* The default is 'false'
*
- * This is usefull when you mix up
- * GLArrayData usage with conventional GL array calls.
+ * This is useful when you mix up
+ * GLArrayData usage with conventional GL array calls
+ * or in case of a buggy GL VBO implementation.
*
* @see #enableBuffer(GL, boolean)
*/
@@ -86,16 +82,17 @@ public interface GLArrayDataEditable extends GLArrayData {
public void reset();
/**
- * If seal is true, it
- * disable write operations to the buffer.
- * Calls flip, ie limit:=position and position:=0.
+ * <p>If <i>seal</i> is true, it
+ * disables write operations to the buffer.
+ * Calls flip, ie limit:=position and position:=0.</p>
*
- * If seal is false, it
+ * <p>If <i>seal</i> is false, it
* enable write operations continuing
* at the buffer position, where you left off at seal(true),
- * ie position:=limit and limit:=capacity.
+ * ie position:=limit and limit:=capacity.</p>
*
- */
+ * @see #seal(boolean)
+ */
public void seal(boolean seal);
public void rewind();
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
index c061e212a..23c237909 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
@@ -2,6 +2,7 @@
package com.jogamp.opengl.util;
import javax.media.opengl.*;
+
import java.nio.*;
import com.jogamp.opengl.util.glsl.*;
@@ -13,111 +14,170 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
//
/**
- * Create a VBOBuffer object, using a predefined fixed function array index
+ * Create a VBO, 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.
- *
+ * and a predefined vertex attribute variable name will be chosen.
+ *
* @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.
+ * 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
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
*
* @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)
+ public static GLArrayDataServer createFixed(int index, String name, int comps, int dataType, boolean normalized, int stride,
+ Buffer buffer, int vboUsage)
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);
+ ads.init(name, index, comps, dataType, normalized, stride, buffer, buffer.limit(), false, glArrayHandler,
+ 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
return ads;
}
/**
- * Create a VBOBuffer object, using a predefined fixed function array index
+ * Create a VBO, 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.
+ * and a predefined vertex attribute variable name will be chosen.
+ *
+ * @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 Whether the data shall be normalized
+ * @param initialSize
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
*
* @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)
+ public static GLArrayDataServer createFixed(int index, String name, int comps, int dataType, boolean normalized, int initialSize,
+ int vboUsage)
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);
+ GLArrayDataServer ads = new GLArrayDataServer();
+ GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
+ ads.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler,
+ 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
return ads;
}
/**
- * Create a VBOBuffer object, using a custom GLSL array attribute name
+ * Create a VBO, 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)
+ *
+ * @param st The ShaderState managing the state of the used shader program, vertex attributes and uniforms
+ * @param name The custom name for the GL attribute, maybe null if gpuBufferTarget is {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param initialSize
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ */
+ public static GLArrayDataServer createGLSL(ShaderState st, String name,
+ int comps, int dataType, boolean normalized, int initialSize,
+ int vboUsage)
+ throws GLException
+ {
+ GLArrayDataServer ads = new GLArrayDataServer();
+ GLArrayHandler glArrayHandler = new GLSLArrayHandler(st, ads);
+ ads.init(name, -1, comps, dataType, normalized, 0, null, initialSize,
+ true, glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
+ return ads;
+ }
+
+ /**
+ * Create a VBO, using a custom GLSL array attribute name
+ * and starting with a given Buffer object incl it's stride
+ *
+ * @param st The ShaderState managing the state of the used shader program, vertex attributes and uniforms
+ * @param name The custom name for the GL attribute, maybe null if gpuBufferTarget is
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
*/
- public static GLArrayDataServer createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
- int initialSize, int vboBufferUsage)
+ public static GLArrayDataServer createGLSL(ShaderState st, String name,
+ int comps, int dataType, boolean normalized, int stride,
+ Buffer buffer, int vboUsage)
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);
+ GLArrayHandler glArrayHandler = new GLSLArrayHandler(st, ads);
+ ads.init(name, -1, comps, dataType, normalized, stride, buffer, buffer.limit(), true, glArrayHandler,
+ 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
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)
+ * Create a VBO data object for any target w/o render pipeline association, ie {@link GL#GL_ELEMENT_ARRAY_BUFFER}.
+ *
+ * Hence no index, name for a fixed function pipeline nor vertex attribute is given.
+ *
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param stride
+ * @param buffer the user define data
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ * @param vboTarget {@link GL#GL_ELEMENT_ARRAY_BUFFER}, ..
+ * {@link GL#glGenBuffers(int, int[], int)
*/
- public static GLArrayDataServer createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
- int stride, Buffer buffer, int vboBufferUsage)
+ public static GLArrayDataServer createData(int comps, int dataType, int stride,
+ Buffer buffer, int vboUsage, int vboTarget)
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 GLDataArrayHandler(ads);
+ ads.init(null, -1, comps, dataType, false, stride, buffer, buffer.limit(), false, glArrayHandler,
+ 0, 0, vboUsage, vboTarget);
+ return ads;
+ }
+ /**
+ * Create a VBO data object for any target w/o render pipeline association, ie {@link GL#GL_ELEMENT_ARRAY_BUFFER}.
+ *
+ * Hence no index, name for a fixed function pipeline nor vertex attribute is given.
+ *
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param initialSize
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ * @param vboTarget {@link GL#GL_ELEMENT_ARRAY_BUFFER}, ..
+ */
+ public static GLArrayDataServer createData(int comps, int dataType, int initialSize,
+ int vboUsage, int vboTarget)
+ throws GLException
+ {
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);
+ GLArrayHandler glArrayHandler = new GLDataArrayHandler(ads);
+ ads.init(null, -1, comps, dataType, false, 0, null, initialSize, false, glArrayHandler,
+ 0, 0, vboUsage, vboTarget);
return ads;
}
+
//
// Data matters GLArrayData
//
- public int getBufferUsage() { return vboBufferUsage; }
-
//
// Data and GL state modification ..
//
@@ -141,9 +201,9 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
* switch to client side data one
* Only possible if buffer is defined.
*/
- public void setVBOUsage(boolean vboUsage) {
+ public void setVBOEnabled(boolean vboUsage) {
checkSeal(false);
- super.setVBOUsage(vboUsage);
+ super.setVBOEnabled(vboUsage);
}
public String toString() {
@@ -151,20 +211,22 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
", index "+index+
", location "+location+
", isVertexAttribute "+isVertexAttribute+
- ", dataType "+dataType+
- ", bufferClazz "+clazz+
+ ", dataType "+componentType+
+ ", bufferClazz "+componentClazz+
", elements "+getElementNumber()+
", components "+components+
", stride "+stride+"u "+strideB+"b "+strideL+"c"+
", initialSize "+initialSize+
- ", vboBufferUsage "+vboBufferUsage+
- ", vboUsage "+vboUsage+
+ ", vboUsage 0x"+Integer.toHexString(vboUsage)+
+ ", vboTarget 0x"+Integer.toHexString(vboTarget)+
+ ", vboEnabled "+vboEnabled+
", vboName "+vboName+
", sealed "+sealed+
", bufferEnabled "+bufferEnabled+
", bufferWritten "+bufferWritten+
", buffer "+buffer+
- ", offset "+bufferOffset+
+ ", offset "+vboOffset+
+ ", alive "+alive+
"]";
}
@@ -172,38 +234,25 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
// non public matters ..
//
- protected void init(GL gl, String name, int index, int comps, int dataType, boolean normalized,
+ protected void init(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)
+ int vboName, long vboOffset, int vboUsage, int vboTarget)
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;
+ vboName, vboOffset, vboUsage, vboTarget);
+
+ vboEnabled=true;
}
protected void init_vbo(GL gl) {
- if(vboUsage && vboName==0) {
+ super.init_vbo(gl);
+ if(vboEnabled && 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
index 88a8603f9..735bd11f7 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
@@ -9,34 +9,85 @@ 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)
+ /**
+ * Create a VBO, using a predefined fixed function array index, wrapping the given data.
+ *
+ * @param index The GL array index
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ * @param vboName
+ * @param vboOffset
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ *
+ * @return the new create instance
+ *
+ * @throws GLException
+ */
+ public static GLArrayDataWrapper createFixed(int index, int comps, int dataType, boolean normalized, int stride,
+ Buffer buffer, int vboName,
+ long vboOffset, int vboUsage)
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);
+ vboName, vboOffset, vboUsage, GL.GL_ARRAY_BUFFER);
return adc;
}
- public static GLArrayDataWrapper createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
- int stride, Buffer buffer,
- int vboName, long bufferOffset)
+ /**
+ * Create a VBO, using a custom GLSL array attribute name, wrapping the given data.
+ *
+ * @param name The custom name for the GL attribute, maybe null if gpuBufferTarget is {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ * @param vboName
+ * @param vboOffset
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ *
+ * @return the new create instance
+ * @throws GLException
+ */
+ public static GLArrayDataWrapper createGLSL(String name, int comps, int dataType, boolean normalized, int stride,
+ Buffer buffer, int vboName,
+ long vboOffset, int vboUsage)
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);
+ vboName, vboOffset, vboUsage, GL.GL_ARRAY_BUFFER);
return adc;
}
+ /**
+ * Validates this instance's parameter. Called automatically by {@link GLArrayDataClient} and {@link GLArrayDataServer}.
+ * {@link GLArrayDataWrapper} does not validate it's instance by itself.
+ *
+ * @param glp the GLProfile to use
+ * @param throwException whether to throw an exception if this instance has invalid parameter or not
+ * @return true if this instance has invalid parameter, otherwise false
+ */
+ public final boolean validate(GLProfile glp, boolean throwException) {
+ if(!alive) {
+ if(throwException) {
+ throw new GLException("Instance !alive "+this);
+ }
+ return false;
+ }
+ if(this.isVertexAttribute() && !glp.hasGLSL()) {
+ if(throwException) {
+ throw new GLException("GLSL not supported on "+glp+", "+this);
+ }
+ return false;
+ }
+ return glp.isValidArrayDataType(getIndex(), getComponentNumber(), getComponentType(), isVertexAttribute(), throwException);
+ }
+
//
// Data read access
//
@@ -51,54 +102,45 @@ public class GLArrayDataWrapper implements GLArrayData {
public final String getName() { return name; }
- public final long getOffset() { return vboUsage?bufferOffset:-1; }
+ public final long getVBOOffset() { return vboEnabled?vboOffset:-1; }
- public final int getVBOName() { return vboUsage?vboName:-1; }
+ public final int getVBOName() { return vboEnabled?vboName:-1; }
- public final boolean isVBO() { return vboUsage; }
+ public final boolean isVBO() { return vboEnabled; }
+ public final int getVBOUsage() { return vboEnabled?vboUsage:-1; }
+
+ public final int getVBOTarget() { return vboEnabled?vboTarget:-1; }
+
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 getComponentType() { return componentType; }
+ public final int getComponentSize() { return componentSize; }
+
public final int getElementNumber() {
if(null==buffer) return 0;
return ( buffer.position()==0 ) ? ( buffer.limit() / components ) : ( buffer.position() / components ) ;
}
-
+ public final int getByteSize() {
+ if(null==buffer) return 0;
+ return ( buffer.position()==0 ) ? ( buffer.limit() * componentSize ) : ( buffer.position() * componentSize ) ;
+ }
+
public final boolean getNormalized() { return normalized; }
public final int getStride() { return stride; }
- public final Class getBufferClass() { return clazz; }
+ public final Class getBufferClass() { return componentClazz; }
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;
+ buffer = null;
+ vboName=0;
+ vboEnabled=false;
+ vboOffset=-1;
+ alive = false;
}
public String toString() {
@@ -106,15 +148,18 @@ public class GLArrayDataWrapper implements GLArrayData {
", index "+index+
", location "+location+
", isVertexAttribute "+isVertexAttribute+
- ", dataType "+dataType+
- ", bufferClazz "+clazz+
+ ", dataType "+componentType+
+ ", bufferClazz "+componentClazz+
", elements "+getElementNumber()+
", components "+components+
", stride "+stride+"u "+strideB+"b "+strideL+"c"+
", buffer "+buffer+
- ", offset "+bufferOffset+
- ", vboUsage "+vboUsage+
+ ", offset "+vboOffset+
+ ", vboUsage 0x"+Integer.toHexString(vboUsage)+
+ ", vboTarget 0x"+Integer.toHexString(vboTarget)+
+ ", vboEnabled "+vboEnabled+
", vboName "+vboName+
+ ", alive "+alive+
"]";
}
@@ -140,76 +185,140 @@ public class GLArrayDataWrapper implements GLArrayData {
name = newName;
}
- public void setVBOUsage(boolean vboUsage) {
- this.vboUsage=vboUsage;
+ /**
+ * Enable or disable use of VBO.
+ * Only possible if a VBO buffer name is defined.
+ * @see #setVBOName(int)
+ */
+ public void setVBOEnabled(boolean vboEnabled) {
+ this.vboEnabled=vboEnabled;
}
+ /**
+ * Set the VBO buffer name, if valid (>0) enable use of VBO
+ * @see #setVBOEnabled(boolean)
+ */
public void setVBOName(int vboName) {
this.vboName=vboName;
- setVBOUsage(vboName>0);
+ setVBOEnabled(vboName>0);
}
- protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data,
+ /**
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ */
+ public void setVBOUsage(int vboUsage) {
+ this.vboUsage = vboUsage;
+ }
+
+ /**
+ * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ */
+ public void setVBOTarget(int vboTarget) {
+ this.vboTarget = vboTarget;
+ }
+
+ protected void init(String name, int index, int components, int componentType,
+ boolean normalized, int stride, Buffer data,
boolean isVertexAttribute,
- int vboName, long bufferOffset)
+ int vboName, long vboOffset, int vboUsage, int vboTarget)
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);
+
+ if( GL.GL_ELEMENT_ARRAY_BUFFER == vboTarget ) {
+ // ok ..
+ } else if( GL.GL_ARRAY_BUFFER == vboTarget ) {
+ // check name ..
+ this.name = ( null == name ) ? FixedFuncPipeline.getPredefinedArrayIndexName(index) : name ;
+ if(null == this.name ) {
+ throw new GLException("Not a valid array buffer index: "+index);
+ }
+ } else if( 0 <= vboTarget ) {
+ throw new GLException("Invalid GPUBuffer target: 0x"+Integer.toHexString(vboTarget));
}
- this.dataType = dataType;
- this.clazz = getBufferClass(dataType);
- switch(dataType) {
+
+ this.componentType = componentType;
+ componentClazz = getBufferClass(componentType);
+ switch(componentType) {
case GL.GL_BYTE:
case GL.GL_UNSIGNED_BYTE:
case GL.GL_SHORT:
case GL.GL_UNSIGNED_SHORT:
- case GL2ES1.GL_FIXED:
+ case GL.GL_FIXED:
this.normalized = normalized;
break;
default:
this.normalized = false;
}
+ componentSize = GLBuffers.sizeOfGLType(componentType);
+ if(0 > componentSize) {
+ throw new GLException("Given componentType not supported: "+componentType+":\n\t"+this);
+ }
+ if(0 >= components) {
+ throw new GLException("Invalid number of components: " + components);
+ }
+ this.components = components;
- int bpc = getComponentSize();
- if(0<stride && stride<comps*bpc) {
- throw new GLException("stride ("+stride+") lower than component bytes, "+comps+" * "+bpc);
+ if(0<stride && stride<components*componentSize) {
+ throw new GLException("stride ("+stride+") lower than component bytes, "+components+" * "+componentSize);
}
- if(0<stride && stride%bpc!=0) {
- throw new GLException("stride ("+stride+") not a multiple of bpc "+bpc);
+ if(0<stride && stride%componentSize!=0) {
+ throw new GLException("stride ("+stride+") not a multiple of bpc "+componentSize);
}
this.buffer = data;
- this.components = comps;
this.stride=stride;
- this.strideB=(0==stride)?comps*bpc:stride;
- this.strideL=(0==stride)?comps:strideB/bpc;
+ this.strideB=(0==stride)?components*componentSize:stride;
+ this.strideL=(0==stride)?components:strideB/componentSize;
this.vboName=vboName;
- this.vboUsage=vboName>0;
- this.bufferOffset=bufferOffset;
+ this.vboEnabled=vboName>0;
+ this.vboOffset=vboOffset;
+
+ switch(vboUsage) {
+ case -1: // nop
+ case GL.GL_STATIC_DRAW:
+ case GL.GL_DYNAMIC_DRAW:
+ case GL2ES2.GL_STREAM_DRAW:
+ break;
+ default:
+ throw new GLException("invalid gpuBufferUsage: "+vboUsage+":\n\t"+this);
+ }
+ switch(vboTarget) {
+ case -1: // nop
+ case GL.GL_ARRAY_BUFFER:
+ case GL.GL_ELEMENT_ARRAY_BUFFER:
+ break;
+ default:
+ throw new GLException("invalid gpuBufferTarget: "+vboTarget+":\n\t"+this);
+ }
+ this.vboUsage=vboUsage;
+ this.vboTarget=vboTarget;
+ this.alive=true;
}
protected GLArrayDataWrapper() { }
+ protected boolean alive;
protected int index;
protected int location;
protected String name;
protected int components;
- protected int dataType;
+ protected int componentType;
+ protected Class componentClazz;
+ protected int componentSize;
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 long vboOffset;
protected int vboName;
- protected boolean vboUsage;
+ protected boolean vboEnabled;
+ protected int vboUsage;
+ protected int vboTarget;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java
new file mode 100644
index 000000000..74d49aa6c
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java
@@ -0,0 +1,41 @@
+
+package com.jogamp.opengl.util;
+
+import javax.media.opengl.*;
+import javax.media.opengl.fixedfunc.*;
+import com.jogamp.opengl.util.*;
+import java.nio.*;
+
+public class GLDataArrayHandler implements GLArrayHandler {
+ private GLArrayDataEditable ad;
+
+ public GLDataArrayHandler(GLArrayDataEditable ad) {
+ this.ad = ad;
+ }
+
+ public void enableBuffer(GL gl, boolean enable) {
+ GLPointerFunc glp = gl.getGL2ES1();
+ if(enable) {
+ 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(ad.getVBOTarget(), ad.getVBOName());
+ if(!ad.isVBOWritten()) {
+ if(null!=buffer) {
+ gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage());
+ }
+ ad.setVBOWritten(true);
+ }
+ } else if(null!=buffer) {
+ ad.setVBOWritten(true);
+ }
+ } else {
+ if(ad.isVBO()) {
+ gl.glBindBuffer(ad.getVBOTarget(), 0);
+ }
+ }
+ }
+}
+
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java
index f0f5ea896..a825ca690 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java
@@ -13,7 +13,7 @@ public class GLFixedArrayHandler implements GLArrayHandler {
this.ad = ad;
}
- protected final void passArrayPointer(GLPointerFunc gl) {
+ private final void passArrayPointer(GLPointerFunc gl) {
switch(ad.getIndex()) {
case GLPointerFunc.GL_VERTEX_ARRAY:
gl.glVertexPointer(ad);
@@ -42,21 +42,21 @@ public class GLFixedArrayHandler implements GLArrayHandler {
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()) {
+ gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName());
+ if(!ad.isVBOWritten()) {
if(null!=buffer) {
- gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage());
+ gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage());
}
- ad.setBufferWritten(true);
+ ad.setVBOWritten(true);
}
passArrayPointer(glp);
} else if(null!=buffer) {
passArrayPointer(glp);
- ad.setBufferWritten(true);
+ ad.setVBOWritten(true);
}
} else {
if(ad.isVBO()) {
- gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ gl.glBindBuffer(ad.getVBOTarget(), 0);
}
glp.glDisableClientState(ad.getIndex());
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
index d9fce6e6a..9e92a9a1d 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
@@ -2,6 +2,8 @@
package com.jogamp.opengl.util;
import com.jogamp.common.util.*;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
import javax.media.opengl.*;
import javax.media.opengl.fixedfunc.*;
import java.nio.*;
@@ -35,8 +37,8 @@ public class ImmModeSink {
* 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()
+ * @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
public static ImmModeSink createGLSL(GL gl, int glBufferUsage, int initialSize,
int vComps, int vDataType,
@@ -745,11 +747,11 @@ public class ImmModeSink {
}
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();
+ ShaderState st = ShaderState.getShaderState(gl);
if(null==st) {
- throw new GLException("No ShaderState current");
- }
+ throw new GLException("No ShaderState in "+gl);
+ }
+ GL2ES2 glsl = gl.getGL2ES2();
if(enable) {
glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
@@ -760,35 +762,35 @@ public class ImmModeSink {
}
if(vComps>0) {
- st.glEnableVertexAttribArray(glsl, vArrayData.getName());
- st.glVertexAttribPointer(glsl, vArrayData);
+ st.enableVertexAttribArray(glsl, vArrayData);
+ st.vertexAttribPointer(glsl, vArrayData);
}
if(cComps>0) {
- st.glEnableVertexAttribArray(glsl, cArrayData.getName());
- st.glVertexAttribPointer(glsl, cArrayData);
+ st.enableVertexAttribArray(glsl, cArrayData);
+ st.vertexAttribPointer(glsl, cArrayData);
}
if(nComps>0) {
- st.glEnableVertexAttribArray(glsl, nArrayData.getName());
- st.glVertexAttribPointer(glsl, nArrayData);
+ st.enableVertexAttribArray(glsl, nArrayData);
+ st.vertexAttribPointer(glsl, nArrayData);
}
if(tComps>0) {
- st.glEnableVertexAttribArray(glsl, tArrayData.getName());
- st.glVertexAttribPointer(glsl, tArrayData);
+ st.enableVertexAttribArray(glsl, tArrayData);
+ st.vertexAttribPointer(glsl, tArrayData);
}
glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
} else {
if(vComps>0) {
- st.glDisableVertexAttribArray(glsl, vArrayData.getName());
+ st.disableVertexAttribArray(glsl, vArrayData);
}
if(cComps>0) {
- st.glDisableVertexAttribArray(glsl, cArrayData.getName());
+ st.disableVertexAttribArray(glsl, cArrayData);
}
if(nComps>0) {
- st.glDisableVertexAttribArray(glsl, nArrayData.getName());
+ st.disableVertexAttribArray(glsl, nArrayData);
}
if(tComps>0) {
- st.glDisableVertexAttribArray(glsl, tArrayData.getName());
+ st.disableVertexAttribArray(glsl, tArrayData);
}
}
}
@@ -860,26 +862,26 @@ public class ImmModeSink {
buffer.flip();
if(vComps>0) {
- vArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, vComps, vDataType, false,
- 0, vertexArray, 0, vOffset);
+ vArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_VERTEX_ARRAY, vComps, vDataType, false, 0,
+ vertexArray, 0, vOffset, GL.GL_STATIC_DRAW);
} else {
vArrayData = null;
}
if(cComps>0) {
- cArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_COLOR_ARRAY, cComps, cDataType, false,
- 0, colorArray, 0, cOffset);
+ cArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_COLOR_ARRAY, cComps, cDataType, false, 0,
+ colorArray, 0, cOffset, GL.GL_STATIC_DRAW);
} else {
cArrayData = null;
}
if(nComps>0) {
- nArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_NORMAL_ARRAY, nComps, nDataType, false,
- 0, normalArray, 0, nOffset);
+ nArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_NORMAL_ARRAY, nComps, nDataType, false, 0,
+ normalArray, 0, nOffset, GL.GL_STATIC_DRAW);
} else {
nArrayData = null;
}
if(tComps>0) {
- tArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false,
- 0, textCoordArray, 0, tOffset);
+ tArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false, 0,
+ textCoordArray, 0, tOffset, GL.GL_STATIC_DRAW);
} else {
tArrayData = null;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/Locator.java b/src/jogl/classes/com/jogamp/opengl/util/Locator.java
index 8dbd7cd93..0176b575a 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/Locator.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/Locator.java
@@ -49,6 +49,9 @@ public class Locator {
* @see #getResource(String, ClassLoader)
*/
public static URL getResource(Class context, String path) {
+ if(null == path) {
+ return null;
+ }
ClassLoader contextCL = (null!=context)?context.getClassLoader():null;
URL url = getResource(path, contextCL);
if (url == null && null!=context) {
@@ -73,24 +76,36 @@ public class Locator {
* @see File#File(String)
*/
public static URL getResource(String path, ClassLoader cl) {
+ if(null == path) {
+ return null;
+ }
URL url = null;
if (cl != null) {
url = cl.getResource(path);
- } else {
+ if(!urlExists(url)) {
+ url = null;
+ }
+ }
+ if(null == url) {
url = ClassLoader.getSystemResource(path);
+ if(!urlExists(url)) {
+ url = null;
+ }
}
- if(!urlExists(url)) {
- url = null;
+ if(null == url) {
try {
url = new URL(path);
+ if(!urlExists(url)) {
+ url = null;
+ }
} catch (MalformedURLException e) { }
}
- if(!urlExists(url)) {
- url = null;
+ if(null == url) {
try {
File file = new File(path);
if(file.exists()) {
url = file.toURL();
+ } else {
}
} catch (MalformedURLException e) {}
}
@@ -98,25 +113,53 @@ public class Locator {
}
/**
- * Generates a path for the 'relativeFile' relative to the 'absoluteFileLocation'
+ * Generates a path for the 'relativeFile' relative to the 'baseLocation'.
+ *
+ * @param baseLocation denotes a directory
+ * @param relativeFile denotes a relative file to the baseLocation
*/
- public static String getRelativeOf(String absoluteFileLocation, String relativeFile) {
- File file = new File(absoluteFileLocation);
- file = file.getParentFile();
- while (file != null && relativeFile.startsWith("../")) {
- file = file.getParentFile();
+ public static String getRelativeOf(File baseLocation, String relativeFile) {
+ if(null == relativeFile) {
+ return null;
+ }
+
+ while (baseLocation != null && relativeFile.startsWith("../")) {
+ baseLocation = baseLocation.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;
+ if (baseLocation != null) {
+ final File file = new File(baseLocation, relativeFile);
+ // Handle things on Windows
+ return file.getPath().replace('\\', '/');
}
+ return null;
}
/**
+ * Generates a path for the 'relativeFile' relative to the 'baseLocation'.
+ *
+ * @param baseLocation denotes a URL to a file
+ * @param relativeFile denotes a relative file to the baseLocation's parent directory
+ */
+ public static String getRelativeOf(URL baseLocation, String relativeFile) {
+ String urlPath = baseLocation.getPath();
+
+ if ( baseLocation.toString().startsWith("jar") ) {
+ JarURLConnection jarConnection;
+ try {
+ jarConnection = (JarURLConnection) baseLocation.openConnection();
+ urlPath = jarConnection.getEntryName();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ // Try relative path first
+ return getRelativeOf(new File(urlPath).getParentFile(), relativeFile);
+ }
+
+ /**
* Returns true, if the url exists,
* trying to open a connection.
*/
diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
index 86882176a..de28dc70a 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
@@ -1590,7 +1590,7 @@ public class TextRenderer {
int lengthInGlyphs = fullRunGlyphVector.getNumGlyphs();
int i = 0;
while (i < lengthInGlyphs) {
- Character letter = CharacterCache.valueOf(inString.charAt(i));
+ Character letter = CharacterCache.valueOf(inString.charAt(i));
GlyphMetrics metrics = (GlyphMetrics) glyphMetricsCache.get(letter);
if (metrics == null) {
metrics = fullRunGlyphVector.getGlyphMetrics(i);
@@ -1656,7 +1656,7 @@ public class TextRenderer {
// if the unicode or glyph ID would be out of bounds of the
// glyph cache.
private Glyph getGlyph(CharSequence inString,
- GlyphMetrics glyphMetrics,
+ GlyphMetrics glyphMetrics,
int index) {
char unicodeID = inString.charAt(index);
diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java
index 86dca59f4..922fc69c1 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java
@@ -307,7 +307,7 @@ public class TextureRenderer {
*/
public void dispose() throws GLException {
if (texture != null) {
- texture.dispose();
+ texture.destroy(GLContext.getCurrentGL());
texture = null;
}
if (image != null) {
@@ -576,23 +576,23 @@ public class TextureRenderer {
gl.glEnable(GL2.GL_BLEND);
gl.glBlendFunc(GL2.GL_ONE, GL2.GL_ONE_MINUS_SRC_ALPHA);
Texture texture = getTexture();
- texture.enable();
- texture.bind();
+ texture.enable(gl);
+ texture.bind(gl);
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);
+ texture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
if (mipmap) {
- texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR);
+ texture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR);
} else {
- texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
+ texture.setTexParameteri(gl, 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);
+ texture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
+ texture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
}
}
}
@@ -600,7 +600,7 @@ public class TextureRenderer {
private void endRendering(boolean ortho) {
GL2 gl = GLContext.getCurrentGL().getGL2();
Texture texture = getTexture();
- texture.disable();
+ texture.disable(gl);
if (ortho) {
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glPopMatrix();
@@ -661,15 +661,16 @@ public class TextureRenderer {
// 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);
+ texture.updateSubImage(GLContext.getCurrentGL(), textureData, 0, x, y, x, y, width, height);
}
}
// Returns true if the texture was newly allocated, false if not
private boolean ensureTexture() {
+ GL gl = GLContext.getCurrentGL();
if (mustReallocateTexture) {
if (texture != null) {
- texture.dispose();
+ texture.destroy(gl);
texture = null;
}
mustReallocateTexture = false;
@@ -679,7 +680,7 @@ public class TextureRenderer {
texture = TextureIO.newTexture(textureData);
if (mipmap && !texture.isUsingAutoMipmapGeneration()) {
// Only try this once
- texture.dispose();
+ texture.destroy(gl);
mipmap = false;
textureData.setMipmap(false);
texture = TextureIO.newTexture(textureData);
@@ -687,8 +688,8 @@ public class TextureRenderer {
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);
+ texture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
+ texture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
}
return true;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUT.java b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUT.java
index 8befc13ba..010ce6699 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUT.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/gl2/GLUT.java
@@ -163,7 +163,7 @@ public class GLUT {
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];
@@ -174,7 +174,7 @@ public class GLUT {
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);
@@ -184,7 +184,7 @@ public class GLUT {
}
gl.glVertex3d(x[0], y[0], 0);
gl.glEnd();
-
+
// Draw top cap
gl.glBegin(GL2.GL_TRIANGLE_FAN);
gl.glNormal3d(0,0,1);
@@ -194,7 +194,7 @@ public class GLUT {
}
gl.glVertex3d(x[0], y[0], height);
gl.glEnd();
-
+
// Draw walls
quadObjInit(glu);
glu.gluQuadricDrawStyle(quadObj, GLU.GLU_FILL);
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
index 95a550ab6..73a1c2721 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
@@ -28,56 +28,68 @@
package com.jogamp.opengl.util.glsl;
-import javax.media.opengl.*;
-import com.jogamp.opengl.util.*;
-import java.nio.*;
+import java.nio.Buffer;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLException;
+import com.jogamp.opengl.util.GLArrayDataEditable;
+import com.jogamp.opengl.util.GLArrayHandler;
public class GLSLArrayHandler implements GLArrayHandler {
+ private static final boolean DEBUG = ShaderState.DEBUG;
private GLArrayDataEditable ad;
+ private ShaderState st;
- public GLSLArrayHandler(GLArrayDataEditable ad) {
+ public GLSLArrayHandler(ShaderState st, GLArrayDataEditable ad) {
+ this.st = st;
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());
+ st.enableVertexAttribArray(glsl, ad);
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()) {
+ // bind and refresh the VBO / vertex-attr only if necessary
+ if(!ad.isVBOWritten()) {
+ if(DEBUG) {
+ System.err.println("XXX VA "+ad.getName()+" VBO write: "+ad.getVBOName());
+ }
+ glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName());
if(null!=buffer) {
- glsl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage());
+ glsl.glBufferData(ad.getVBOTarget(), ad.getByteSize(), buffer, ad.getVBOUsage());
+ }
+ ad.setVBOWritten(true);
+ st.vertexAttribPointer(glsl, ad);
+ } else {
+ // didn't experience a performance hit on this query ..
+ int[] qi = new int[1];
+ glsl.glGetVertexAttribiv(ad.getLocation(), GL2ES2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, qi, 0);
+ if(ad.getVBOName() != qi[0]) {
+ if(DEBUG) {
+ System.err.println("XXX VA "+ad.getName()+" VBO rebind: "+qi[0]+" -> "+ad.getVBOName());
+ }
+ glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName());
+ st.vertexAttribPointer(glsl, ad);
}
- ad.setBufferWritten(true);
}
- passVertexAttribPointer(glsl, st);
} else if(null!=buffer) {
- passVertexAttribPointer(glsl, st);
- ad.setBufferWritten(true);
+ st.vertexAttribPointer(glsl, ad);
+ ad.setVBOWritten(true);
}
} else {
if(ad.isVBO()) {
- glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ glsl.glBindBuffer(ad.getVBOTarget(), 0);
}
- st.glDisableVertexAttribArray(glsl, ad.getName());
+ st.disableVertexAttribArray(glsl, ad);
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
index 1f59318f2..20b032a41 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
@@ -155,9 +155,9 @@ public class ShaderCode {
return res;
}
}
- Set binFmts = ShaderUtil.getShaderBinaryFormats(gl);
- for(Iterator iter=binFmts.iterator(); null==res && iter.hasNext(); ) {
- int bFmt = ((Integer)(iter.next())).intValue();
+ Set<Integer> binFmts = ShaderUtil.getShaderBinaryFormats(gl);
+ for(Iterator<Integer> iter=binFmts.iterator(); null==res && iter.hasNext(); ) {
+ int bFmt = iter.next().intValue();
String bFmtPath = getBinarySubPath(bFmt);
if(null==bFmtPath) continue;
binFileName = binRoot + '/' + bFmtPath + '/' + basename + "." + getFileSuffix(true, type);
@@ -174,16 +174,8 @@ public class ShaderCode {
/**
* 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 id() { return id; }
public int shaderType() { return shaderType; }
public String shaderTypeStr() { return shaderTypeStr(shaderType); }
@@ -239,7 +231,7 @@ public class ShaderCode {
shaderSource=null;
shaderBinaryFormat=-1;
shaderType=-1;
- id=null;
+ id=-1;
}
public boolean equals(Object obj) {
@@ -250,7 +242,7 @@ public class ShaderCode {
return false;
}
public int hashCode() {
- return id.intValue();
+ return id;
}
public String toString() {
StringBuffer buf = new StringBuffer("ShaderCode [id="+id+", type="+shaderTypeStr()+", valid="+valid+", shader: ");
@@ -290,26 +282,35 @@ public class ShaderCode {
}
}
- public static void readShaderSource(ClassLoader context, String path, URL url, StringBuffer result) {
+ public static void readShaderSource(Class context, URL url, StringBuffer result) {
try {
+ if(DEBUG_CODE) {
+ System.err.println("ShaderCode.readShaderSource<0>: "+url);
+ }
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();
+ URL nextURL = null;
+
// Try relative path first
- String next = Locator.getRelativeOf(path, includeFile);
- URL nextURL = Locator.getResource(next, context);
+ String next = Locator.getRelativeOf(url, includeFile);
+ if(null != next) {
+ nextURL = Locator.getResource(context, next);
+ }
if (nextURL == null) {
// Try absolute path
- next = includeFile;
- nextURL = Locator.getResource(next, context);
+ nextURL = Locator.getResource(context, includeFile);
}
if (nextURL == null) {
// Fail
throw new FileNotFoundException("Can't find include file " + includeFile);
}
- readShaderSource(context, next, nextURL, result);
+ if(DEBUG_CODE) {
+ System.err.println("ShaderCode.readShaderSource<I>: "+url+" + "+includeFile+" := "+nextURL);
+ }
+ readShaderSource(context, nextURL, result);
} else {
result.append(line + "\n");
}
@@ -320,16 +321,12 @@ public class ShaderCode {
}
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);
+ readShaderSource(context, url, result);
return result.toString();
}
@@ -354,12 +351,12 @@ public class ShaderCode {
protected int shaderBinaryFormat = -1;
protected IntBuffer shader = null;
protected int shaderType = -1;
- protected Integer id = null;
+ protected int id = -1;
protected boolean valid=false;
- private static synchronized Integer getNextID() {
- return new Integer(nextID++);
+ private static synchronized int getNextID() {
+ return 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
index b6908c1a1..b622571e7 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java
@@ -30,11 +30,12 @@ package com.jogamp.opengl.util.glsl;
import javax.media.opengl.*;
-import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.io.PrintStream;
public class ShaderProgram {
+
public ShaderProgram() {
id = getNextID();
}
@@ -51,16 +52,8 @@ public class 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; }
+ public int id() { return id; }
/**
* Detaches all shader codes and deletes the program.
@@ -88,15 +81,18 @@ public class ShaderProgram {
* 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());
+ useProgram(gl, false);
+ for(Iterator<ShaderCode> iter=allShaderCode.iterator(); iter.hasNext(); ) {
+ ShaderCode shaderCode = iter.next();
+ if(attachedShaderCode.remove(shaderCode)) {
+ ShaderUtil.detachShader(gl, shaderProgram, shaderCode.shader());
+ }
if(releaseShaderToo) {
shaderCode.destroy(gl);
}
}
- shaderMap.clear();
+ allShaderCode.clear();
+ attachedShaderCode.clear();
gl.glDeleteProgram(shaderProgram);
shaderProgram=-1;
}
@@ -106,35 +102,78 @@ public class ShaderProgram {
//
/**
- * 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.
+ * Adds a new shader to this program.
+ *
+ * <p>This command does not compile and attach the shader,
+ * use {@link #add(GL2ES2, ShaderCode)} for this purpose.</p>
*/
- public synchronized boolean add(ShaderCode shaderCode) {
- if(shaderMap.containsKey(shaderCode.key())) return false;
- shaderMap.put(shaderCode.key(), shaderCode);
- return true;
+ public synchronized void add(ShaderCode shaderCode) throws GLException {
+ allShaderCode.add(shaderCode);
}
+ public synchronized boolean contains(ShaderCode shaderCode) {
+ return allShaderCode.contains(shaderCode);
+ }
+
+ /**
+ * Warning slow O(n) operation ..
+ * @param id
+ * @return
+ */
public synchronized ShaderCode getShader(int id) {
- return (ShaderCode) shaderMap.get(new Integer(id));
+ for(Iterator<ShaderCode> iter=allShaderCode.iterator(); iter.hasNext(); ) {
+ ShaderCode shaderCode = iter.next();
+ if(shaderCode.id() == id) {
+ return shaderCode;
+ }
+ }
+ return null;
}
//
- // Program handling
+ // ShaderCode / Program handling
//
/**
- * Replace a shader in a 'running' program.
- * Refetches all previously bin/get attribute names
- * and resets all attribute data as well
+ * Creates the empty GL program object using {@link GL2ES2#glCreateProgram()}
+ *
+ * @param gl
+ */
+ public synchronized final void init(GL2ES2 gl) {
+ if(0>shaderProgram) {
+ shaderProgram = gl.glCreateProgram();
+ }
+ }
+
+ /**
+ * Adds a new shader to a this non running program.
+ *
+ * <p>Compiles and attaches the shader, if not done yet.</p>
+ *
+ * @return true if the shader was successfully added, false if compilation failed.
+ */
+ public synchronized boolean add(GL2ES2 gl, ShaderCode shaderCode, PrintStream verboseOut) {
+ init(gl);
+ if( allShaderCode.add(shaderCode) ) {
+ if(!shaderCode.compile(gl, verboseOut)) {
+ return false;
+ }
+ if(attachedShaderCode.add(shaderCode)) {
+ ShaderUtil.attachShader(gl, shaderProgram, shaderCode.shader());
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Replace a shader in a program and re-links the program.
*
* @param gl
- * @param oldShaderID the to be replace Shader
+ * @param oldShader the to be replace Shader
* @param newShader the new ShaderCode
- * @param verboseOut the optional verbose outputstream
- * @throws GLException is the program is not linked
+ * @param verboseOut the optional verbose output stream
+ *
+ * @return true if all steps are valid, shader compilation, attachment and linking; otherwise false.
*
* @see ShaderState#glEnableVertexAttribArray
* @see ShaderState#glDisableVertexAttribArray
@@ -145,47 +184,44 @@ public class ShaderProgram {
* @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);
+ public synchronized boolean replaceShader(GL2ES2 gl, ShaderCode oldShader, ShaderCode newShader, PrintStream verboseOut) {
+ init(gl);
+
if(!newShader.compile(gl, verboseOut)) {
return false;
- }
- if(oldShaderID>=0) {
- ShaderCode oldShader = (ShaderCode) shaderMap.remove(new Integer(oldShaderID));
- if(null!=oldShader) {
+ }
+
+ boolean shaderWasInUse = inUse();
+ if(shaderWasInUse) {
+ useProgram(gl, false);
+ }
+
+ if(null != oldShader && allShaderCode.remove(oldShader)) {
+ if(attachedShaderCode.remove(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(attachedShaderCode.add(newShader)) {
+ ShaderUtil.attachShader(gl, shaderProgram, newShader.shader());
}
-
- if(shaderWasInUse) {
- glUseProgram(gl, true);
+
+ gl.glLinkProgram(shaderProgram);
+
+ programLinked = ShaderUtil.isProgramValid(gl, shaderProgram, System.err);
+ if ( programLinked && shaderWasInUse ) {
+ useProgram(gl, true);
}
- return true;
+ return programLinked;
}
/**
- * Creates the empty GL program object using {@link GL2ES2#glCreateProgram()}
- *
- * @param gl
- */
- public final void init(GL2ES2 gl) {
- if(0>shaderProgram) {
- shaderProgram = gl.glCreateProgram();
- }
- }
-
- /**
- * Compiles and links the shader code to the program.
- * Within this process, all GL resources (shader and program objects) are created if necessary.
+ * Links the shader code to the program.
+ *
+ * <p>Compiles and attaches the shader code to the program if not done by yet</p>
+ *
+ * <p>Within this process, all GL resources (shader and program objects) are created if necessary.</p>
*
* @param gl
* @param verboseOut
@@ -194,18 +230,16 @@ public class ShaderProgram {
* @see #init(GL2ES2)
*/
public synchronized boolean link(GL2ES2 gl, PrintStream verboseOut) {
- if(programLinked) throw new GLException("Program is already linked");
+ init(gl);
- if(0>shaderProgram) {
- shaderProgram = gl.glCreateProgram();
- }
-
- for(Iterator iter=shaderMap.values().iterator(); iter.hasNext(); ) {
- ShaderCode shaderCode = (ShaderCode) iter.next();
+ for(Iterator<ShaderCode> iter=allShaderCode.iterator(); iter.hasNext(); ) {
+ final ShaderCode shaderCode = iter.next();
if(!shaderCode.compile(gl, verboseOut)) {
return false;
}
- ShaderUtil.attachShader(gl, shaderProgram, shaderCode.shader());
+ if(attachedShaderCode.add(shaderCode)) {
+ ShaderUtil.attachShader(gl, shaderProgram, shaderCode.shader());
+ }
}
// Link the program
@@ -225,40 +259,37 @@ public class ShaderProgram {
}
public int hashCode() {
- return id.intValue();
+ return id;
}
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());
+ for(Iterator<ShaderCode> iter=allShaderCode.iterator(); iter.hasNext(); ) {
+ buf.append(iter.next());
buf.append(" ");
}
buf.append("]");
return buf.toString();
}
- protected synchronized void glUseProgram(GL2ES2 gl, boolean on) {
+ protected synchronized void useProgram(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;
+ protected HashSet<ShaderCode> allShaderCode = new HashSet<ShaderCode>();
+ protected HashSet<ShaderCode> attachedShaderCode = new HashSet<ShaderCode>();
+ protected int id = -1;
- private static synchronized Integer getNextID() {
- return new Integer(nextID++);
+ private static synchronized int getNextID() {
+ return 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
index 57ae6cfda..f8fe987d7 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
@@ -28,13 +28,23 @@
package com.jogamp.opengl.util.glsl;
-import javax.media.opengl.*;
-import jogamp.opengl.Debug;
-
+import java.security.AccessController;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.security.*;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLArrayData;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLUniformData;
+
+import jogamp.opengl.Debug;
+
+import com.jogamp.common.util.IntObjectHashMap;
+import com.jogamp.opengl.util.GLArrayDataEditable;
public class ShaderState {
public static final boolean DEBUG = Debug.isPropertyDefined("jogl.debug.GLSLState", true, AccessController.getContext());
@@ -47,38 +57,107 @@ public class ShaderState {
public void setVerbose(boolean v) { verbose=v; }
/**
- * Fetches the current shader state from the thread local storage (TLS)
+ * Fetches the current shader state from this thread (TLS) current GLContext
*
- * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean)
- * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrent()
+ * @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getShaderState(GL)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
- 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());
+ public static synchronized ShaderState getCurrentShaderState() {
+ return getShaderState(GLContext.getCurrentGL());
+ }
+
+ /**
+ * Fetches the shader state from the GL object's GLContext
+ *
+ * @param gl the GL object referencing the GLContext
+ *
+ * @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getShaderState(GL)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
+ */
+ public static synchronized ShaderState getShaderState(GL gl) {
+ return (ShaderState) gl.getContext().getAttachedObject(ShaderState.class.getName());
+ }
+
+ /**
+ * Returns the attached user object for the given name to this ShaderState.
+ */
+ public final Object getAttachedObject(String name) {
+ return attachedObjectsByString.get(name);
}
/**
+ * Attach user object for the given name to this ShaderState.
+ * Returns the previously set object or null.
+ *
+ * @return the previous mapped object or null if none
+ */
+ public final Object attachObject(String name, Object obj) {
+ return attachedObjectsByString.put(name, obj);
+ }
+
+ /**
+ * @param name name of the mapped object to detach
+ *
+ * @return the previous mapped object or null if none
+ */
+ public final Object detachObject(String name) {
+ return attachedObjectsByString.remove(name);
+ }
+
+ /**
+ * Returns the attached user object for the given name to this ShaderState.
+ */
+ public final Object getAttachedObject(int name) {
+ return attachedObjectsByInt.get(name);
+ }
+
+ /**
+ * Attach user object for the given name to this ShaderState.
+ * Returns the previously set object or null.
+ */
+ public final Object attachObject(int name, Object obj) {
+ return attachedObjectsByInt.put(name, obj);
+ }
+
+ public final Object detachObject(int name) {
+ return attachedObjectsByInt.remove(name);
+ }
+
+ /**
* 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()
+ * @throws GLException if no program is attached
+ *
+ * @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getShaderState(GL)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
- public synchronized void glUseProgram(GL2ES2 gl, boolean on) {
+ public synchronized void useProgram(GL2ES2 gl, boolean on) throws GLException {
+ if(null==shaderProgram) { throw new GLException("No program is attached"); }
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);
+ gl.getContext().attachObject(ShaderState.class.getName(), this);
+ if(shaderProgram.linked()) {
+ shaderProgram.useProgram(gl, true);
+ if(resetAllShaderData) {
+ resetAllAttributes(gl);
+ resetAllUniforms(gl);
+ }
+ } else if(resetAllShaderData) {
+ setAllAttributes(gl);
+ if(!shaderProgram.link(gl, System.err)) {
+ throw new GLException("could not link program: "+shaderProgram);
+ }
+ shaderProgram.useProgram(gl, true);
+ resetAllUniforms(gl);
+ }
+ resetAllShaderData = false;
+ } else {
+ shaderProgram.useProgram(gl, false);
}
}
@@ -93,11 +172,16 @@ public class ShaderState {
/**
* Attach or switch a shader program
*
- * Attaching a shader program the first time,
+ * <p>Attaching a shader program the first time,
* as well as switching to another program on the fly,
- * while managing all attribute and uniform data.
+ * while managing all attribute and uniform data.</p>
+ *
+ * <p>[Re]sets all data and use program in case of a program switch.<br>
+ * Use program if linked in case of a 1st time attachment.</p>
+ *
+ * @throws GLException if program was not linked and linking fails
*/
- public synchronized void attachShaderProgram(GL2ES2 gl, ShaderProgram prog) {
+ public synchronized void attachShaderProgram(GL2ES2 gl, ShaderProgram prog) throws GLException {
boolean prgInUse = false; // earmarked state
if(DEBUG) {
@@ -118,19 +202,21 @@ public class ShaderState {
return;
}
prgInUse = shaderProgram.inUse();
- shaderProgram.glUseProgram(gl, false);
+ useProgram(gl, false);
+ resetAllShaderData = true;
}
// 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);
+ // [re]set all data and use program if switching program,
+ // or use program if program is linked
+ if(shaderProgram.linked() || resetAllShaderData) {
+ useProgram(gl, true);
+ if(!prgInUse) {
+ shaderProgram.useProgram(gl, false);
+ }
}
}
if(DEBUG) {
@@ -141,25 +227,27 @@ public class ShaderState {
public ShaderProgram shaderProgram() { return shaderProgram; }
/**
- * Calls release(gl, true, true)
+ * Calls {@link #release(GL2ES2, boolean, boolean, boolean) release(gl, true, true, true)}
*
* @see #glReleaseAllVertexAttributes
* @see #glReleaseAllUniforms
- * @see #release(GL2ES2, boolean, boolean)
+ * @see #release(GL2ES2, boolean, boolean, boolean)
*/
public synchronized void destroy(GL2ES2 gl) {
- release(gl, true, true);
+ release(gl, true, true, true);
+ attachedObjectsByString.clear();
+ attachedObjectsByInt.clear();
}
/**
- * Calls release(gl, false, false)
+ * Calls {@link #release(GL2ES2, boolean, boolean, boolean) release(gl, false, false, false)}
*
* @see #glReleaseAllVertexAttributes
* @see #glReleaseAllUniforms
- * @see #release(GL2ES2, boolean, boolean)
+ * @see #release(GL2ES2, boolean, boolean, boolean)
*/
public synchronized void releaseAllData(GL2ES2 gl) {
- release(gl, false, false);
+ release(gl, false, false, false);
}
/**
@@ -167,22 +255,21 @@ public class ShaderState {
* @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);
- }
+ public synchronized void release(GL2ES2 gl, boolean destroyBoundAttributes, boolean releaseProgramToo, boolean releaseShaderToo) {
+ if(null!=shaderProgram) {
+ shaderProgram.useProgram(gl, false);
}
- glReleaseAllVertexAttributes(gl);
- glReleaseAllUniforms(gl);
+ if(destroyBoundAttributes) {
+ for(Iterator<GLArrayData> iter = managedAttributes.iterator(); iter.hasNext(); ) {
+ iter.next().destroy(gl);
+ }
+ }
+ releaseAllAttributes(gl);
+ releaseAllUniforms(gl);
if(null!=shaderProgram) {
if(releaseProgramToo) {
shaderProgram.release(gl, releaseShaderToo);
- } else if(!prgInUse) {
- shaderProgram.glUseProgram(gl, false);
- }
+ }
}
}
@@ -191,226 +278,379 @@ public class ShaderState {
//
/**
- * 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
+ * Gets the cached location of a shader attribute.
+ *
+ * @return -1 if there is no such attribute available,
+ * otherwise >= 0
+ *
+ * @see #bindAttribLocation(GL2ES2, int, String)
+ * @see #bindAttribLocation(GL2ES2, int, GLArrayData)
+ * @see #getAttribLocation(GL2ES2, String)
+ * @see GL2ES2#glGetAttribLocation(int, String)
+ */
+ public int getAttribLocation(String name) {
+ Integer idx = (Integer) activeAttribLocationMap.get(name);
+ return (null!=idx)?idx.intValue():-1;
+ }
+
+ /**
+ * Get the previous cached vertex attribute data.
*
- * @throws GLException is the program is already linked
+ * @return the GLArrayData object, null if not previously set.
+ *
+ * @see #ownAttribute(GLArrayData, boolean)
*
- * @see #glBindAttribLocation
- * @see javax.media.opengl.GL2ES2#glBindAttribLocation
- * @see #glGetAttribLocation
- * @see javax.media.opengl.GL2ES2#glGetAttribLocation
- * @see #getAttribLocation
+ * @see #glEnableVertexAttribArray
+ * @see #glDisableVertexAttribArray
+ * @see #glVertexAttribPointer
+ * @see #getVertexAttribPointer
+ * @see #glReleaseAllVertexAttributes
+ * @see #glResetAllVertexAttributes
* @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);
+ public GLArrayData getAttribute(String name) {
+ return (GLArrayData) activeAttribDataMap.get(name);
+ }
+
+ /**
+ * Binds or unbinds the {@link GLArrayData} lifecycle to this ShaderState.
+ *
+ * <p>If an attribute location is cached (ie {@link #bindAttribLocation(GL2ES2, int, String)})
+ * it is promoted to the {@link GLArrayData} instance.</p>
+ *
+ * <p>The attribute will be destroyed with {@link #destroy(GL2ES2)}
+ * and it's location will be reset when switching shader with {@link #attachShaderProgram(GL2ES2, ShaderProgram)}.</p>
+ *
+ * <p>The data will not be transfered to the GPU, use {@link #vertexAttribPointer(GL2ES2, GLArrayData)} additionally.</p>
+ *
+ * @param attribute the {@link GLArrayData} which lifecycle shall be managed
+ * @param own true if <i>owning</i> shall be performs, false if <i>disowning</i>.
+ *
+ * @see #bindAttribLocation(GL2ES2, int, String)
+ * @see #getAttribute(String)
+ */
+ public void ownAttribute(GLArrayData attribute, boolean own) {
+ if(own) {
+ final int location = getAttribLocation(attribute.getName());
+ if(0<=location) {
+ attribute.setLocation(location);
+ }
+ managedAttributes.add(managedAttributes.size(), attribute);
+ } else {
+ managedAttributes.remove(attribute);
}
}
+
+ public boolean ownsAttribute(GLArrayData attribute) {
+ return managedAttributes.contains(attribute);
+ }
+
+ /**
+ * Binds a shader attribute to a location.
+ * Multiple names can be bound to one location.
+ * The value will be cached and can be retrieved via {@link #getAttribLocation(String)}
+ * before or after linking.
+ *
+ * @throws GLException if no program is attached
+ * @throws GLException if the program is already linked
+ *
+ * @see javax.media.opengl.GL2ES2#glBindAttribLocation(int, int, String)
+ * @see #getAttribLocation(GL2ES2, String)
+ * @see #getAttribLocation(String)
+ */
+ public void bindAttribLocation(GL2ES2 gl, int location, String name) {
+ if(null==shaderProgram) throw new GLException("No program is attached");
+ if(shaderProgram.linked()) throw new GLException("Program is already linked");
+ final Integer loc = new Integer(location);
+ activeAttribLocationMap.put(name, loc);
+ gl.glBindAttribLocation(shaderProgram.program(), location, name);
+ }
+
+ /**
+ * Binds a shader {@link GLArrayData} attribute to a location.
+ * Multiple names can be bound to one location.
+ * The value will be cached and can be retrieved via {@link #getAttribLocation(String)}
+ * and {@link #getAttribute(String)}before or after linking.
+ * The {@link GLArrayData}'s location will be set as well.
+ *
+ * @throws GLException if no program is attached
+ * @throws GLException if the program is already linked
+ *
+ * @see javax.media.opengl.GL2ES2#glBindAttribLocation(int, int, String)
+ * @see #getAttribLocation(GL2ES2, String)
+ * @see #getAttribLocation(String)
+ * @see #getAttribute(String)
+ */
+ public void bindAttribLocation(GL2ES2 gl, int location, GLArrayData data) {
+ bindAttribLocation(gl, location, data.getName());
+ data.setLocation(location);
+ activeAttribDataMap.put(data.getName(), data);
+ }
/**
- * Gets the index of a shader attribute.
- * This must be done after the program is linked !
+ * Gets the location of a shader attribute,
+ * either the cached value {@link #getAttribLocation(String)} if valid or
+ * the retrieved one {@link GL2ES2#glGetAttribLocation(int, String)}.
+ * In the latter case the value will be cached.
*
* @return -1 if there is no such attribute available,
* otherwise >= 0
- * @throws GLException is the program is not linked
+ * @throws GLException if no program is attached
+ * @throws GLException if the program is not linked and no location was cached.
*
- * @see #glBindAttribLocation
- * @see javax.media.opengl.GL2ES2#glBindAttribLocation
- * @see #glGetAttribLocation
- * @see javax.media.opengl.GL2ES2#glGetAttribLocation
- * @see #getAttribLocation
- * @see ShaderProgram#glReplaceShader
+ * @see #getAttribLocation(String)
+ * @see #bindAttribLocation(GL2ES2, int, GLArrayData)
+ * @see #bindAttribLocation(GL2ES2, int, String)
+ * @see GL2ES2#glGetAttribLocation(int, String)
*/
- 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);
+ public int getAttribLocation(GL2ES2 gl, String name) {
+ if(null==shaderProgram) throw new GLException("No program is attached");
+ int location = getAttribLocation(name);
+ if(0>location) {
+ if(!shaderProgram.linked()) throw new GLException("Program is not linked");
+ location = gl.glGetAttribLocation(shaderProgram.program(), name);
+ if(0<=location) {
+ Integer idx = new Integer(location);
+ activeAttribLocationMap.put(name, idx);
if(DEBUG) {
- System.err.println("Info: glGetAttribLocation: "+name+", loc: "+index);
+ System.err.println("Info: glGetAttribLocation: "+name+", loc: "+location);
}
} else if(verbose) {
- Throwable tX = new Throwable("Info: glGetAttribLocation failed, no location for: "+name+", index: "+index);
+ Throwable tX = new Throwable("Info: glGetAttribLocation failed, no location for: "+name+", loc: "+location);
tX.printStackTrace();
}
}
- return index;
+ return location;
}
- protected int getAttribLocation(String name) {
- Integer idx = (Integer) attribMap2Idx.get(name);
- return (null!=idx)?idx.intValue():-1;
+ /**
+ * Gets the location of a shader attribute,
+ * either the cached value {@link #getAttribLocation(String)} if valid or
+ * the retrieved one {@link GL2ES2#glGetAttribLocation(int, String)}.
+ * In the latter case the value will be cached.
+ * The {@link GLArrayData}'s location will be set as well.
+ *
+ * @return -1 if there is no such attribute available,
+ * otherwise >= 0
+ *
+ * @throws GLException if no program is attached
+ * @throws GLException if the program is not linked and no location was cached.
+ *
+ * @see #getAttribLocation(String)
+ * @see #bindAttribLocation(GL2ES2, int, GLArrayData)
+ * @see #bindAttribLocation(GL2ES2, int, String)
+ * @see GL2ES2#glGetAttribLocation(int, String)
+ * @see #getAttribute(String)
+ */
+ public int getAttribLocation(GL2ES2 gl, GLArrayData data) {
+ int location = getAttribLocation(gl, data.getName());
+ data.setLocation(location);
+ activeAttribDataMap.put(data.getName(), data);
+ return location;
}
-
-
+
//
// Enabled Vertex Arrays and its data
//
/**
- * Enable a vertex attribute array
+ * @return true if the named attribute is enable
+ */
+ public final boolean isVertexAttribArrayEnabled(String name) {
+ return enabledAttributes.contains(name);
+ }
+
+ /**
+ * @return true if the {@link GLArrayData} attribute is enable
+ */
+ public final boolean isVertexAttribArrayEnabled(GLArrayData data) {
+ return isVertexAttribArrayEnabled(data.getName());
+ }
+
+ private boolean enableVertexAttribArray(GL2ES2 gl, String name, int location) {
+ enabledAttributes.add(name);
+ if(0>location) {
+ location = getAttribLocation(gl, name);
+ if(0>location) {
+ 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: "+location);
+ }
+ gl.glEnableVertexAttribArray(location);
+ return true;
+ }
+
+ /**
+ * Enables a vertex attribute array.
+ *
+ * This method retrieves the the location via {@link #getAttribLocation(GL2ES2, GLArrayData)}
+ * hence {@link #enableVertexAttribArray(GL2ES2, GLArrayData)} shall be preferred.
*
* Even if the attribute is not found in the current shader,
- * it is stored in this state.
+ * it is marked enabled in this state.
*
* @return false, if the name is not found, otherwise true
*
- * @throws GLException if the program is not in use
- *
+ * @throws GLException if the program is not linked and no location was cached.
+ *
* @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);
+ public boolean enableVertexAttribArray(GL2ES2 gl, String name) {
+ return enableVertexAttribArray(gl, name, -1);
}
+
/**
- * Disables a vertex attribute array
+ * Enables a vertex attribute array, usually invoked by {@link GLArrayDataEditable#enableBuffer(GL, boolean)}.
*
+ * This method uses the {@link GLArrayData}'s location if set
+ * and is the preferred alternative to {@link #enableVertexAttribArray(GL2ES2, String)}.
+ * If data location is unset it will be retrieved via {@link #getAttribLocation(GL2ES2, GLArrayData)} set
+ * and cached in this state.
+ *
* Even if the attribute is not found in the current shader,
- * it is removed from this state.
+ * it is marked enabled in this state.
*
* @return false, if the name is not found, otherwise true
*
- * @throws GLException if the program is not in use
+ * @throws GLException if the program is not linked and no location was cached.
*
* @see #glEnableVertexAttribArray
* @see #glDisableVertexAttribArray
* @see #glVertexAttribPointer
* @see #getVertexAttribPointer
- * @see #glReleaseAllVertexAttributes
- * @see #glResetAllVertexAttributes
- * @see ShaderProgram#glReplaceShader
+ * @see GLArrayDataEditable#enableBuffer(GL, boolean)
*/
- 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();
+ public boolean enableVertexAttribArray(GL2ES2 gl, GLArrayData data) {
+ if(0 > data.getLocation()) {
+ getAttribLocation(gl, data);
+ } else {
+ // ensure data is the current bound one
+ activeAttribDataMap.put(data.getName(), data);
+ }
+ return enableVertexAttribArray(gl, data.getName(), data.getLocation());
+ }
+
+ private boolean disableVertexAttribArray(GL2ES2 gl, String name, int location) {
+ enabledAttributes.remove(name);
+ if(0>location) {
+ location = getAttribLocation(gl, name);
+ if(0>location) {
+ if(verbose) {
+ Throwable tX = new Throwable("Info: glDisableVertexAttribArray failed, no index for: "+name);
+ tX.printStackTrace();
+ }
+ return false;
}
- return false;
}
if(DEBUG) {
System.err.println("Info: glDisableVertexAttribArray: "+name);
}
- gl.glDisableVertexAttribArray(index);
+ gl.glDisableVertexAttribArray(location);
return true;
}
-
+
/**
- * Set the vertex attribute data.
- * Enable the attribute, if it is not enabled yet.
+ * Disables a vertex attribute array
*
+ * This method retrieves the the location via {@link #getAttribLocation(GL2ES2, GLArrayData)}
+ * hence {@link #disableVertexAttribArray(GL2ES2, GLArrayData)} shall be preferred.
+ *
* 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.
+ * it is removed from this state enabled list.
*
* @return false, if the name is not found, otherwise true
*
- * @throws GLException if the program is not in use
+ * @throws GLException if no program is attached
+ * @throws GLException if the program is not linked and no location was cached.
*
* @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;
+ public boolean disableVertexAttribArray(GL2ES2 gl, String name) {
+ return disableVertexAttribArray(gl, name, -1);
}
/**
- * Get the vertex attribute data, previously set.
+ * Disables a vertex attribute array
*
- * @return the GLArrayData object, null if not previously set.
+ * This method uses the {@link GLArrayData}'s location if set
+ * and is the preferred alternative to {@link #disableVertexAttribArray(GL2ES2, String)}.
+ * If data location is unset it will be retrieved via {@link #getAttribLocation(GL2ES2, GLArrayData)} set
+ * and cached in this state.
+ *
+ * Even if the attribute is not found in the current shader,
+ * it is removed from this state enabled list.
+ *
+ * @return false, if the name is not found, otherwise true
+ *
+ * @throws GLException if no program is attached
+ * @throws GLException if the program is not linked and no location was cached.
*
* @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);
+ public boolean disableVertexAttribArray(GL2ES2 gl, GLArrayData data) {
+ if(0 > data.getLocation()) {
+ getAttribLocation(gl, data);
+ }
+ return disableVertexAttribArray(gl, data.getName(), data.getLocation());
+ }
+
+ /**
+ * Set the {@link GLArrayData} vertex attribute data.
+ *
+ * This method uses the {@link GLArrayData}'s location if set.
+ * If data location is unset it will be retrieved via {@link #getAttribLocation(GL2ES2, GLArrayData)}, set
+ * and cached in this state.
+ *
+ * @return false, if the location could not be determined, otherwise true
+ *
+ * @throws GLException if no program is attached
+ * @throws GLException if the program is not linked and no location was cached.
+ *
+ * @see #glEnableVertexAttribArray
+ * @see #glDisableVertexAttribArray
+ * @see #glVertexAttribPointer
+ * @see #getVertexAttribPointer
+ */
+ public boolean vertexAttribPointer(GL2ES2 gl, GLArrayData data) {
+ int location = data.getLocation();
+ if(0 > location) {
+ location = getAttribLocation(gl, data);
+ } /* else {
+ done via enable ..
+ // ensure data is the current bound one
+ activeAttribDataMap.put(data.getName(), data);
+ } */
+ if(0 <= location) {
+ // 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;
}
/**
* 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
@@ -420,23 +660,23 @@ public class ShaderState {
* @see #glResetAllVertexAttributes
* @see ShaderProgram#glReplaceShader
*/
- public void glReleaseAllVertexAttributes(GL2ES2 gl) {
+ public void releaseAllAttributes(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())) {
+ for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) {
+ if(!disableVertexAttribArray(gl, 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())) {
+ for(Iterator<String> iter = enabledAttributes.iterator(); iter.hasNext(); ) {
+ if(!disableVertexAttribArray(gl, iter.next())) {
throw new GLException("Internal Error: prev enabled vertex attribute couldn't be disabled");
}
}
}
- vertexAttribMap2Data.clear();
- enabledVertexAttribArraySet.clear();
- attribMap2Idx.clear();
+ activeAttribDataMap.clear();
+ enabledAttributes.clear();
+ activeAttribLocationMap.clear();
+ managedAttributes.clear();
}
/**
@@ -447,8 +687,6 @@ public class ShaderState {
*
* 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
@@ -458,73 +696,92 @@ public class ShaderState {
* @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();
+ public void disableAllVertexAttributeArrays(GL2ES2 gl, boolean removeFromState) {
+ for(Iterator<String> iter = enabledAttributes.iterator(); iter.hasNext(); ) {
+ String name = iter.next();
if(removeFromState) {
- enabledVertexAttribArraySet.remove(name);
+ enabledAttributes.remove(name);
}
- int index = glGetAttribLocation(gl, name);
+ int index = getAttribLocation(gl, name);
if(0<=index) {
gl.glDisableVertexAttribArray(index);
}
}
}
+ private final void relocateAttribute(GL2ES2 gl, GLArrayData attribute) {
+ // get new location ..
+ String name = attribute.getName();
+ int loc = getAttribLocation(gl, name);
+ attribute.setLocation(loc);
+
+ if(0<=loc) {
+ if(enabledAttributes.contains(name)) {
+ // enable attrib, VBO and pass location/data
+ gl.glEnableVertexAttribArray(loc);
+ }
+
+ if( attribute.isVBO() ) {
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, attribute.getVBOName());
+ }
+
+ gl.glVertexAttribPointer(attribute);
+ }
+ }
+
/**
- * Reset all previously enabled mapped vertex attribute data,
- * incl enabling them
+ * Reset all previously enabled mapped vertex attribute data.
+ *
+ * <p>Attribute data is bound to the GL state</p>
+ * <p>Attribute location is bound to the program</p>
+ *
+ * <p>However, since binding an attribute to a location via {@link #bindAttribLocation(GL2ES2, int, GLArrayData)}
+ * <i>must</i> happen before linking <b>and</b> we try to promote the attributes to the new program,
+ * we have to gather the probably new location etc.</p>
*
- * @throws GLException is the program is not in use
+ * @throws GLException is the program is not linked
*
- * @see #glEnableVertexAttribArray
- * @see #glDisableVertexAttribArray
- * @see #glVertexAttribPointer
- * @see #getVertexAttribPointer
- * @see #glReleaseAllVertexAttributes
- * @see #glResetAllVertexAttributes
- * @see ShaderProgram#glReplaceShader
+ * @see #attachShaderProgram(GL2ES2, ShaderProgram)
*/
- 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());
+ private final void resetAllAttributes(GL2ES2 gl) {
+ if(!shaderProgram.linked()) throw new GLException("Program is not linked");
+ activeAttribLocationMap.clear();
+
+ for(Iterator<GLArrayData> iter = managedAttributes.iterator(); iter.hasNext(); ) {
+ iter.next().setLocation(-1);
}
- 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);
+ for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) {
+ relocateAttribute(gl, iter.next());
+ }
+ }
- if(0>loc) {
- // not used in shader
- continue;
+ private final void setAttribute(GL2ES2 gl, GLArrayData attribute) {
+ // get new location ..
+ final String name = attribute.getName();
+ final int loc = attribute.getLocation();
+
+ if(0<=loc) {
+ this.bindAttribLocation(gl, loc, name);
+
+ if(enabledAttributes.contains(name)) {
+ // enable attrib, VBO and pass location/data
+ gl.glEnableVertexAttribArray(loc);
}
-
- // enable attrib, VBO and pass location/data
- gl.glEnableVertexAttribArray(loc);
-
- if( data.isVBO() ) {
- gl.glBindBuffer(GL.GL_ARRAY_BUFFER, data.getVBOName());
+
+ if( attribute.isVBO() ) {
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, attribute.getVBOName());
}
-
- gl.glVertexAttribPointer(data);
+
+ gl.glVertexAttribPointer(attribute);
+ }
+ }
+
+ /**
+ * preserves the attribute location .. (program not linked)
+ */
+ private final void setAllAttributes(GL2ES2 gl) {
+ for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) {
+ setAttribute(gl, iter.next());
}
}
@@ -533,6 +790,33 @@ public class ShaderState {
//
/**
+ * Bind the {@link GLUniform} lifecycle to this ShaderState.
+ *
+ * <p>If a uniform location is cached it is promoted to the {@link GLUniformData} instance.</p>
+ *
+ * <p>The attribute will be destroyed with {@link #destroy(GL2ES2)}
+ * and it's location will be reset when switching shader with {@link #attachShaderProgram(GL2ES2, ShaderProgram)}.</p>
+ *
+ * <p>The data will not be transfered to the GPU, use {@link #uniform(GL2ES2, GLUniformData)} additionally.</p>
+ *
+ * @param uniform the {@link GLUniformData} which lifecycle shall be managed
+ *
+ * @see #getUniform(String)
+ */
+ public void ownUniform(GLUniformData uniform) {
+ final int location = getUniformLocation(uniform.getName());
+ if(0<=location) {
+ uniform.setLocation(location);
+ }
+ activeUniformDataMap.put(uniform.getName(), uniform);
+ managedUniforms.add(uniform);
+ }
+
+ public boolean ownsUniform(GLUniformData uniform) {
+ return managedUniforms.contains(uniform);
+ }
+
+ /**
* Gets the index of a shader uniform.
* This must be done when the program is in use !
*
@@ -546,24 +830,24 @@ public class ShaderState {
* @see #getUniformLocation
* @see ShaderProgram#glReplaceShader
*/
- protected int glGetUniformLocation(GL2ES2 gl, String name) {
+ protected final int getUniformLocation(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);
+ int location = getUniformLocation(name);
+ if(0>location) {
+ location = gl.glGetUniformLocation(shaderProgram.program(), name);
+ if(0<=location) {
+ Integer idx = new Integer(location);
+ activeUniformLocationMap.put(name, idx);
} else if(verbose) {
- Throwable tX = new Throwable("Info: glUniform failed, no location for: "+name+", index: "+index);
+ Throwable tX = new Throwable("Info: glUniform failed, no location for: "+name+", index: "+location);
tX.printStackTrace();
}
}
- return index;
+ return location;
}
- protected int getUniformLocation(String name) {
- Integer idx = (Integer) uniformMap2Idx.get(name);
+ protected final int getUniformLocation(String name) {
+ Integer idx = (Integer) activeUniformLocationMap.get(name);
return (null!=idx)?idx.intValue():-1;
}
@@ -587,11 +871,14 @@ public class ShaderState {
* @see #getUniformLocation
* @see ShaderProgram#glReplaceShader
*/
- public boolean glUniform(GL2ES2 gl, GLUniformData data) {
+ public boolean uniform(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);
+ int location = data.getLocation();
+ if(0>location) {
+ location = getUniformLocation(gl, data.getName());
+ data.setLocation(location);
+ }
+ activeUniformDataMap.put(data.getName(), data);
if(0<=location) {
// only pass the data, if the uniform exists in the current shader
if(DEBUG) {
@@ -608,69 +895,97 @@ public class ShaderState {
* @return the GLUniformData object, null if not previously set.
*/
public GLUniformData getUniform(String name) {
- return (GLUniformData) uniformMap2Data.get(name);
+ return activeUniformDataMap.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();
+ public void releaseAllUniforms(GL2ES2 gl) {
+ activeUniformDataMap.clear();
+ activeUniformLocationMap.clear();
+ managedUniforms.clear();
}
/**
* Reset all previously mapped uniform data
+ *
+ * Uniform data and location is bound to the program,
+ * hence both are updated here
*
* @throws GLException is the program is not in use
+ *
+ * @see #attachShaderProgram(GL2ES2, ShaderProgram)
*/
- 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());
+ private final void resetAllUniforms(GL2ES2 gl) {
+ if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
+ activeUniformLocationMap.clear();
+ for(Iterator<GLUniformData> iter = managedUniforms.iterator(); iter.hasNext(); ) {
+ iter.next().setLocation(-1);
+ }
+ for(Iterator<GLUniformData> iter = activeUniformDataMap.values().iterator(); iter.hasNext(); ) {
+ final GLUniformData uniform = iter.next();
+ uniform.setLocation(-1);
+ uniform(gl, uniform);
}
}
- 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);
- }
+ public StringBuilder toString(StringBuilder sb) {
+ if(null==sb) {
+ sb = new StringBuilder();
}
- 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);
- }
+
+ sb.append("ShaderState[");
+ sb.append(shaderProgram.toString());
+ sb.append(", enabledAttributes: [");
+ for(Iterator<String> iter = enabledAttributes.iterator(); iter.hasNext(); ) {
+ sb.append("\n ");
+ sb.append((String)iter.next());
+ }
+ sb.append("], activeAttributes [");
+ for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) {
+ sb.append("\n ");
+ sb.append(iter.next());
}
- buf.append("]");
- return buf.toString();
+ sb.append("], managedAttributes [");
+ for(Iterator<GLArrayData> iter = managedAttributes.iterator(); iter.hasNext(); ) {
+ sb.append("\n ");
+ sb.append(iter.next());
+ }
+ sb.append("], activeUniforms [");
+ for(Iterator<GLUniformData> iter=activeUniformDataMap.values().iterator(); iter.hasNext(); ) {
+ sb.append("\n ");
+ sb.append(iter.next());
+ }
+ sb.append("], managedUniforms [");
+ for(Iterator<GLUniformData> iter = managedUniforms.iterator(); iter.hasNext(); ) {
+ sb.append("\n ");
+ sb.append(iter.next());
+ }
+ sb.append("]");
+ return sb;
}
-
- 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();
-
+
+ @Override
+ public String toString() {
+ return toString(null).toString();
+ }
+
+ private boolean verbose = false;
+ private ShaderProgram shaderProgram=null;
+
+ private HashSet<String> enabledAttributes = new HashSet<String>();
+ private HashMap<String, Integer> activeAttribLocationMap = new HashMap<String, Integer>();
+ private HashMap<String, GLArrayData> activeAttribDataMap = new HashMap<String, GLArrayData>();
+ private ArrayList<GLArrayData> managedAttributes = new ArrayList<GLArrayData>();
+
+ private HashMap<String, Integer> activeUniformLocationMap = new HashMap<String, Integer>();
+ private HashMap<String, GLUniformData> activeUniformDataMap = new HashMap<String, GLUniformData>();
+ private ArrayList<GLUniformData> managedUniforms = new ArrayList<GLUniformData>();
+
+ private HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>();
+ private IntObjectHashMap attachedObjectsByInt = new IntObjectHashMap();
+ private boolean resetAllShaderData = false;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java
index c7e845953..c81e1f961 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java
@@ -51,7 +51,7 @@ public class ShaderUtil {
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 Set<Integer> 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);
@@ -74,7 +74,7 @@ public class ShaderUtil {
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);
+ gl.glGetShaderiv(shaderObj, GL2ES2.GL_INFO_LOG_LENGTH, infoLogLength, 0);
if(infoLogLength[0]==0) {
return "(no info log)";
@@ -89,7 +89,7 @@ public class ShaderUtil {
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);
+ gl.glGetProgramiv(programObj, GL2ES2.GL_INFO_LOG_LENGTH, infoLogLength, 0);
if(infoLogLength[0]==0) {
return "(no info log)";
@@ -143,14 +143,13 @@ public class ShaderUtil {
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(!isProgramStatusValid(gl, programObj, GL2ES2.GL_LINK_STATUS)) {
if(null!=verboseOut) {
verboseOut.println("Program link failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj));
}
@@ -159,7 +158,7 @@ public class ShaderUtil {
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(!isProgramStatusValid(gl, programObj, GL2ES2.GL_VALIDATE_STATUS)) {
if(null!=verboseOut) {
verboseOut.println("Program validation failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj));
}
@@ -177,17 +176,15 @@ public class ShaderUtil {
}
private Boolean shaderCompilerAvailable = null;
- private Set shaderBinaryFormats = null;
+ private Set<Integer> shaderBinaryFormats = null;
- public Set getShaderBinaryFormats(GL _gl) {
+ public Set<Integer> getShaderBinaryFormats(GL _gl) {
GL2ES2 gl = _gl.getGL2ES2();
if(null==shaderBinaryFormats) {
- if(gl.getContext()!=GLContext.getCurrent()) {
- return new HashSet(0); // bail out
- }
+ gl.getContext().validateCurrent();
int[] param = new int[1];
- shaderBinaryFormats = new HashSet();
+ shaderBinaryFormats = new HashSet<Integer>();
if (gl.isGLES2()) {
gl.glGetIntegerv(GL2ES2.GL_NUM_SHADER_BINARY_FORMATS, param, 0);
@@ -208,10 +205,8 @@ public class ShaderUtil {
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);
+ gl.getContext().validateCurrent();
+ Set<Integer> bfs = getShaderBinaryFormats(gl);
if(gl.isGLES2()) {
byte[] param = new byte[1];
gl.glGetBooleanv(GL2ES2.GL_SHADER_COMPILER, param, 0);
@@ -370,7 +365,7 @@ public class ShaderUtil {
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;
+ return isShaderStatusValid(gl, shader, GL2ES2.GL_COMPILE_STATUS, verboseOut) && err == GL.GL_NO_ERROR;
}
}
@@ -415,7 +410,7 @@ public class ShaderUtil {
getImpl(gl).createShader(gl, type, shaders);
}
- public static Set getShaderBinaryFormats(GL gl) {
+ public static Set<Integer> getShaderBinaryFormats(GL gl) {
return getImpl(gl).getShaderBinaryFormats(gl);
}
@@ -469,7 +464,7 @@ public class ShaderUtil {
Impl impl = (Impl) context.getAttachedObject(ShaderUtil.class.getName());
if (impl == null) {
impl = new GL2ES2Impl();
- context.putAttachedObject(ShaderUtil.class.getName(), impl);
+ context.attachObject(ShaderUtil.class.getName(), impl);
}
return impl;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java
index 38f8ff974..35604ba30 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java
@@ -178,38 +178,33 @@ public class Texture {
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 {
+ public Texture(GL gl, TextureData data) throws GLException {
texID = 0;
- updateImage(data);
+ updateImage(gl, data);
}
// Constructor for use when creating e.g. cube maps, where there is
// no initial texture data
- public Texture(int target) throws GLException {
+ public Texture(int target) {
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);
+ 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
+ * given GL context's state. This method is a shorthand equivalent
* of the following OpenGL code:
<pre>
gl.glEnable(texture.getTarget());
@@ -221,13 +216,13 @@ public class Texture {
* @throws GLException if no OpenGL context was current or if any
* OpenGL-related errors occurred
*/
- public void enable() throws GLException {
- GLContext.getCurrentGL().glEnable(target);
+ public void enable(GL gl) throws GLException {
+ gl.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
+ * given GL state. This method is a shorthand equivalent
* of the following OpenGL code:
<pre>
gl.glDisable(texture.getTarget());
@@ -235,16 +230,17 @@ public class Texture {
*
* See the <a href="#perftips">performance tips</a> above for hints
* on how to maximize performance when using many Texture objects.
+ * @param gl TODO
*
* @throws GLException if no OpenGL context was current or if any
* OpenGL-related errors occurred
*/
- public void disable() throws GLException {
- GLContext.getCurrentGL().glDisable(target);
+ public void disable(GL gl) throws GLException {
+ gl.glDisable(target);
}
-
+
/**
- * Binds this texture to the current GL context. This method is a
+ * Binds this texture to the given GL context. This method is a
* shorthand equivalent of the following OpenGL code:
<pre>
gl.glBindTexture(texture.getTarget(), texture.getTextureObject());
@@ -252,36 +248,22 @@ public class Texture {
*
* See the <a href="#perftips">performance tips</a> above for hints
* on how to maximize performance when using many Texture objects.
+ * @param gl TODO
*
* @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());
+ public void bind(GL gl) throws GLException {
+ validateTexID(gl, true);
+ gl.glBindTexture(target, texID);
}
-
+
/**
- * Disposes the native resources used by this texture object.
- *
- * @throws GLException if any OpenGL-related errors occurred
- * @deprecated use destroy(GL)
+ * @deprecated use {@link #destroy(GL)}
*/
- public void dispose(GL gl) throws GLException {
+ public final void dispose(GL gl) throws GLException {
destroy(gl);
}
-
/**
* Destroys the native resources used by this texture object.
*
@@ -414,11 +396,10 @@ public class Texture {
* 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
+ * @throws GLException if any OpenGL-related errors occurred
*/
- public void updateImage(TextureData data) throws GLException {
- updateImage(data, 0);
+ public void updateImage(GL gl, TextureData data) throws GLException {
+ updateImage(gl, data, 0);
}
/**
@@ -438,11 +419,9 @@ public class 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
+ * @throws GLException if any OpenGL-related errors occurred
*/
- public void updateImage(TextureData data, int target) throws GLException {
- GL gl = GLContext.getCurrentGL();
+ public void updateImage(GL gl, TextureData data, int target) throws GLException {
validateTexID(gl, true);
imgWidth = data.getWidth();
@@ -593,7 +572,7 @@ public class Texture {
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, align[0]); // restore alignment
}
} else {
- checkCompressedTextureExtensions(data);
+ checkCompressedTextureExtensions(gl, data);
Buffer[] mipmapData = data.getMipmapData();
if (mipmapData != null) {
int width = texWidth;
@@ -610,7 +589,7 @@ public class Texture {
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());
+ updateSubImageImpl(gl, data, texTarget, i, 0, 0, 0, 0, data.getWidth(), data.getHeight());
}
width = Math.max(width / 2, 1);
@@ -631,7 +610,7 @@ public class Texture {
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());
+ updateSubImageImpl(gl, data, texTarget, 0, 0, 0, 0, 0, data.getWidth(), data.getHeight());
}
} else {
if (data.getMipmap() && haveAutoMipmapGeneration && gl.isGL2ES1()) {
@@ -646,7 +625,7 @@ public class Texture {
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());
+ updateSubImageImpl(gl, data, texTarget, 0, 0, 0, 0, 0, data.getWidth(), data.getHeight());
}
}
}
@@ -697,17 +676,16 @@ public class 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
+ * @throws GLException if any OpenGL-related errors occurred
*/
- public void updateSubImage(TextureData data, int mipmapLevel, int x, int y) throws GLException {
+ public void updateSubImage(GL gl, 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());
+ bind(gl);
+ updateSubImageImpl(gl, data, target, mipmapLevel, x, y, 0, 0, data.getWidth(), data.getHeight());
}
/**
@@ -740,7 +718,7 @@ public class Texture {
* @throws GLException if no OpenGL context was current or if any
* OpenGL-related errors occurred
*/
- public void updateSubImage(TextureData data, int mipmapLevel,
+ public void updateSubImage(GL gl, TextureData data, int mipmapLevel,
int dstx, int dsty,
int srcx, int srcy,
int width, int height) throws GLException {
@@ -752,8 +730,8 @@ public class Texture {
// don't need to update other mipmap levels
return;
}
- bind();
- updateSubImageImpl(data, target, mipmapLevel, dstx, dsty, srcx, srcy, width, height);
+ bind(gl);
+ updateSubImageImpl(gl, data, target, mipmapLevel, dstx, dsty, srcx, srcy, width, height);
}
/**
@@ -765,10 +743,9 @@ public class Texture {
* @throws GLException if no OpenGL context was current or if any
* OpenGL-related errors occurred
*/
- public void setTexParameterf(int parameterName,
+ public void setTexParameterf(GL gl, int parameterName,
float value) {
- bind();
- GL gl = GLContext.getCurrentGL();
+ bind(gl);
gl.glTexParameterf(target, parameterName, value);
}
@@ -777,13 +754,11 @@ public class Texture {
* 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
+ * @throws GLException if any OpenGL-related errors occurred
*/
- public void setTexParameterfv(int parameterName,
+ public void setTexParameterfv(GL gl, int parameterName,
FloatBuffer params) {
- bind();
- GL gl = GLContext.getCurrentGL();
+ bind(gl);
gl.glTexParameterfv(target, parameterName, params);
}
@@ -792,13 +767,11 @@ public class Texture {
* 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
+ * @throws GLException if any OpenGL-related errors occurred
*/
- public void setTexParameterfv(int parameterName,
+ public void setTexParameterfv(GL gl, int parameterName,
float[] params, int params_offset) {
- bind();
- GL gl = GLContext.getCurrentGL();
+ bind(gl);
gl.glTexParameterfv(target, parameterName, params, params_offset);
}
@@ -810,13 +783,11 @@ public class Texture {
* 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
+ * @throws GLException if any OpenGL-related errors occurred
*/
- public void setTexParameteri(int parameterName,
+ public void setTexParameteri(GL gl, int parameterName,
int value) {
- bind();
- GL gl = GLContext.getCurrentGL();
+ bind(gl);
gl.glTexParameteri(target, parameterName, value);
}
@@ -825,13 +796,11 @@ public class Texture {
* 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
+ * @throws GLException if any OpenGL-related errors occurred
*/
- public void setTexParameteriv(int parameterName,
+ public void setTexParameteriv(GL gl, int parameterName,
IntBuffer params) {
- bind();
- GL gl = GLContext.getCurrentGL();
+ bind(gl);
gl.glTexParameteriv(target, parameterName, params);
}
@@ -840,23 +809,21 @@ public class Texture {
* 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
+ * @throws GLException if any OpenGL-related errors occurred
*/
- public void setTexParameteriv(int parameterName,
+ public void setTexParameteriv(GL gl, int parameterName,
int[] params, int params_offset) {
- bind();
- GL gl = GLContext.getCurrentGL();
+ bind(gl);
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.
+ * handled automatically by the bind(GL) and destroy(GL) APIs.
*/
- public int getTextureObject() {
- validateTexID(null, false);
+ public int getTextureObject(GL gl) {
+ validateTexID(gl, false);
return texID;
}
@@ -936,10 +903,9 @@ public class Texture {
}
}
- private void updateSubImageImpl(TextureData data, int newTarget, int mipmapLevel,
+ private void updateSubImageImpl(GL gl, 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"));
@@ -1000,7 +966,7 @@ public class Texture {
height = texHeight - dsty;
}
- checkCompressedTextureExtensions(data);
+ checkCompressedTextureExtensions(gl, data);
if (data.isDataCompressed()) {
gl.glCompressedTexSubImage2D(newTarget, mipmapLevel,
@@ -1052,8 +1018,7 @@ public class Texture {
}
}
- private void checkCompressedTextureExtensions(TextureData data) {
- GL gl = GLContext.getCurrentGL();
+ private void checkCompressedTextureExtensions(GL gl, TextureData data) {
if (data.isDataCompressed()) {
switch (data.getInternalFormat()) {
case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
@@ -1073,22 +1038,20 @@ public class Texture {
}
}
- 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");
+ private boolean validateTexID(GL gl, boolean throwException) {
+ if( 0 >= texID ) {
+ if( null != gl ) {
+ int[] tmp = new int[1];
+ gl.glGenTextures(1, tmp, 0);
+ texID = tmp[0];
+ if ( 0 >= texID && throwException ) {
+ throw new GLException("Create texture ID invalid: texID "+texID+", glerr 0x"+Integer.toHexString(gl.glGetError()));
+ }
+ } else if ( throwException ) {
+ throw new GLException("No GL context given, can't create texture ID");
}
}
-
- if(null!=gl) {
- int[] tmp = new int[1];
- gl.glGenTextures(1, tmp, 0);
- texID = tmp[0];
- }
+ return 0 < texID;
}
// Helper routines for disabling certain codepaths
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
index e86ff161b..792f80ff8 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
@@ -400,12 +400,25 @@ public class TextureIO {
* @throws IllegalArgumentException if the passed TextureData was null
*/
public static Texture newTexture(TextureData data) throws GLException, IllegalArgumentException {
+ return newTexture(GLContext.getCurrentGL(), data);
+ }
+
+ /**
+ * 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(GL gl, TextureData data) throws GLException, IllegalArgumentException {
if (data == null) {
throw new IllegalArgumentException("Null TextureData");
}
- return new Texture(data);
+ return new Texture(gl, data);
}
-
+
/**
* Creates an OpenGL texture object from the specified file using
* the current OpenGL context.
@@ -422,9 +435,10 @@ public class TextureIO {
* OpenGL error occurred
*/
public static Texture newTexture(File file, boolean mipmap) throws IOException, GLException {
- GLProfile glp = GLContext.getCurrentGL().getGLProfile();
+ GL gl = GLContext.getCurrentGL();
+ GLProfile glp = gl.getGLProfile();
TextureData data = newTextureData(glp, file, mipmap, FileUtil.getFileSuffix(file));
- Texture texture = newTexture(data);
+ Texture texture = newTexture(gl, data);
data.flush();
return texture;
}
@@ -450,9 +464,10 @@ public class TextureIO {
* OpenGL error occurred
*/
public static Texture newTexture(InputStream stream, boolean mipmap, String fileSuffix) throws IOException, GLException {
- GLProfile glp = GLContext.getCurrentGL().getGLProfile();
+ GL gl = GLContext.getCurrentGL();
+ GLProfile glp = gl.getGLProfile();
TextureData data = newTextureData(glp, stream, mipmap, fileSuffix);
- Texture texture = newTexture(data);
+ Texture texture = newTexture(gl, data);
data.flush();
return texture;
}
@@ -481,26 +496,24 @@ public class TextureIO {
if (fileSuffix == null) {
fileSuffix = FileUtil.getFileSuffix(url.getPath());
}
- GLProfile glp = GLContext.getCurrentGL().getGLProfile();
+ GL gl = GLContext.getCurrentGL();
+ GLProfile glp = gl.getGLProfile();
TextureData data = newTextureData(glp, url, mipmap, fileSuffix);
- Texture texture = newTexture(data);
+ Texture texture = newTexture(gl, 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
+ * texture target. 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 {
+ public static Texture newTexture(int target) {
return new Texture(target);
}
@@ -528,19 +541,19 @@ public class TextureIO {
* 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);
+ int target,
+ int texWidth,
+ int texHeight,
+ int imgWidth,
+ int imgHeight,
+ boolean mustFlipVertically) {
+ return new Texture(textureID,
+ target,
+ texWidth,
+ texHeight,
+ imgWidth,
+ imgHeight,
+ mustFlipVertically);
}
/**
@@ -581,7 +594,7 @@ public class TextureIO {
}
GL2 gl = _gl.getGL2();
- texture.bind();
+ texture.bind(gl);
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);
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
index d5f49599c..37dbc54df 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java
@@ -37,7 +37,7 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.jogamp.opengl.util.texture.spi;
+package com.jogamp.opengl.util.texture.spi;
import java.io.DataInput;
import java.io.DataInputStream;
@@ -65,16 +65,16 @@ import java.io.IOException;
* 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
+ * @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.
+ * To reuse some of the non endian dependent methods from
+ * DataInputStreams methods.
*/
- DataInputStream dataIn;
+ DataInputStream dataIn;
public LEDataInputStream(InputStream in)
{
@@ -84,29 +84,29 @@ public class LEDataInputStream extends FilterInputStream implements DataInput
public void close() throws IOException
{
- dataIn.close(); // better close as we create it.
+ dataIn.close(); // better close as we create it.
// this will close underlying as well.
}
- public synchronized final int read(byte b[]) throws IOException
+ 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
+ public synchronized final int read(byte b[], int off, int len) throws IOException
{
- int rl = dataIn.read(b, off, len);
+ int rl = dataIn.read(b, off, len);
return rl;
}
public final void readFully(byte b[]) throws IOException
{
- dataIn.readFully(b, 0, b.length);
+ dataIn.readFully(b, 0, b.length);
}
- public final void readFully(byte b[], int off, int len) throws IOException
+ public final void readFully(byte b[], int off, int len) throws IOException
{
- dataIn.readFully(b, off, len);
+ dataIn.readFully(b, off, len);
}
public final int skipBytes(int n) throws IOException
@@ -116,23 +116,23 @@ public class LEDataInputStream extends FilterInputStream implements DataInput
public final boolean readBoolean() throws IOException
{
- int ch = dataIn.read();
+ int ch = dataIn.read();
if (ch < 0)
throw new EOFException();
return (ch != 0);
}
- public final byte readByte() throws IOException
+ public final byte readByte() throws IOException
{
- int ch = dataIn.read();
+ int ch = dataIn.read();
if (ch < 0)
throw new EOFException();
return (byte)(ch);
}
- public final int readUnsignedByte() throws IOException
+ public final int readUnsignedByte() throws IOException
{
- int ch = dataIn.read();
+ int ch = dataIn.read();
if (ch < 0)
throw new EOFException();
return ch;
@@ -140,47 +140,47 @@ public class LEDataInputStream extends FilterInputStream implements DataInput
public final short readShort() throws IOException
{
- int ch1 = dataIn.read();
- int ch2 = dataIn.read();
- if ((ch1 | ch2) < 0)
+ int ch1 = dataIn.read();
+ int ch2 = dataIn.read();
+ if ((ch1 | ch2) < 0)
throw new EOFException();
- return (short)((ch1 << 0) + (ch2 << 8));
+ return (short)((ch1 << 0) + (ch2 << 8));
}
- public final int readUnsignedShort() throws IOException
+ public final int readUnsignedShort() throws IOException
{
- int ch1 = dataIn.read();
- int ch2 = dataIn.read();
- if ((ch1 | ch2) < 0)
+ int ch1 = dataIn.read();
+ int ch2 = dataIn.read();
+ if ((ch1 | ch2) < 0)
throw new EOFException();
- return (ch1 << 0) + (ch2 << 8);
+ return (ch1 << 0) + (ch2 << 8);
}
- public final char readChar() throws IOException
+ public final char readChar() throws IOException
{
- int ch1 = dataIn.read();
- int ch2 = dataIn.read();
- if ((ch1 | ch2) < 0)
+ int ch1 = dataIn.read();
+ int ch2 = dataIn.read();
+ if ((ch1 | ch2) < 0)
throw new EOFException();
- return (char)((ch1 << 0) + (ch2 << 8));
+ 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)
+ 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));
+ return ((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24));
}
- public final long readLong() throws IOException
+ public final long readLong() throws IOException
{
- int i1 = readInt();
- int i2 = readInt();
- return ((long)(i1) & 0xFFFFFFFFL) + (i2 << 32);
+ int i1 = readInt();
+ int i2 = readInt();
+ return ((long)(i1) & 0xFFFFFFFFL) + (i2 << 32);
}
public final float readFloat() throws IOException
@@ -188,7 +188,7 @@ public class LEDataInputStream extends FilterInputStream implements DataInput
return Float.intBitsToFloat(readInt());
}
- public final double readDouble() throws IOException
+ public final double readDouble() throws IOException
{
return Double.longBitsToDouble(readLong());
}
@@ -197,7 +197,7 @@ public class LEDataInputStream extends FilterInputStream implements DataInput
* dont call this it is not implemented.
* @return empty new string
**/
- public final String readLine() throws IOException
+ public final String readLine() throws IOException
{
return new String();
}
@@ -206,7 +206,7 @@ public class LEDataInputStream extends FilterInputStream implements DataInput
* dont call this it is not implemented
* @return empty new string
**/
- public final String readUTF() throws IOException
+ public final String readUTF() throws IOException
{
return new String();
}
@@ -215,7 +215,7 @@ public class LEDataInputStream extends FilterInputStream implements DataInput
* dont call this it is not implemented
* @return empty new string
**/
- public final static String readUTF(DataInput in) throws IOException
+ public final static String readUTF(DataInput in) throws IOException
{
return new String();
}
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
index bb5040a31..c60c91bda 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java
@@ -477,7 +477,7 @@ public class SGIImage {
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;
@@ -485,7 +485,7 @@ public class SGIImage {
int start_ptr = ptr;
int num_ptr = ptr++;
byte repeat_val = 0;
-
+
while (x < xsize) {
// see if we should switch modes
should_switch = false;
@@ -502,7 +502,7 @@ public class SGIImage {
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;
@@ -530,7 +530,7 @@ public class SGIImage {
repeat_mode = true;
repeat_val = imgref(data, x, y, z, xsize, ysize, zsize);
}
-
+
if (x > 0) {
// reset the number pointer
num_ptr = ptr++;
@@ -538,7 +538,7 @@ public class SGIImage {
count = 0;
}
}
-
+
// if not in repeat mode, copy element to ptr
if (!repeat_mode) {
rlebuf[ptr++] = imgref(data, x, y, z, xsize, ysize, zsize);
diff --git a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java
index 9352ad4f3..52628f6fa 100644
--- a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java
+++ b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java
@@ -230,7 +230,7 @@ public class DefaultGLCapabilitiesChooser implements GLCapabilitiesChooser {
// 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)))) {
+ ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) {
scoreClosestToZero = score;
chosenIndex = i;
}
diff --git a/src/jogl/classes/javax/media/opengl/FPSCounter.java b/src/jogl/classes/javax/media/opengl/FPSCounter.java
new file mode 100644
index 000000000..9c07b58e4
--- /dev/null
+++ b/src/jogl/classes/javax/media/opengl/FPSCounter.java
@@ -0,0 +1,117 @@
+/**
+ * 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 javax.media.opengl;
+
+import java.io.PrintStream;
+
+/**
+ * FPSCounter feature.<br>
+ * An implementation initially has the FPSCounter feature disabled.<br>
+ * Use {@link #setUpdateFPSFrames(int, PrintStream)} to enable and disable the FPSCounter feature.
+ */
+public interface FPSCounter {
+ public static final int DEFAULT_FRAMES_PER_INTERVAL = 5*60;
+
+ /**
+ * @param frames Update interval in frames.<br> At every rendered <i>frames</i> interval the currentTime and fps values are updated.
+ * If the <i>frames</i> interval is <= 0, no update will be issued, ie the FPSCounter feature is turned off. You may choose {@link #DEFAULT_FRAMES_PER_INTERVAL}.
+ * @param out optional print stream where the fps values gets printed if not null at every <i>frames</i> interval
+ */
+ void setUpdateFPSFrames(int frames, PrintStream out);
+
+ /**
+ * Reset all performance counter (startTime, currentTime, frame number)
+ */
+ void resetFPSCounter();
+
+ /**
+ * @return update interval in frames
+ *
+ * @see #setUpdateFPSFrames(int, PrintStream)
+ */
+ int getUpdateFPSFrames();
+
+ /**
+ * Returns the time of the first display call in milliseconds after enabling this feature via {@link #setUpdateFPSFrames(int, PrintStream)}.<br>
+ * This value is reset via {@link #resetFPSCounter()}.
+ *
+ * @see #setUpdateFPSFrames(int, PrintStream)
+ * @see #resetFPSCounter()
+ */
+ long getFPSStartTime();
+
+ /**
+ * Returns the time of the last update interval in milliseconds, if this feature is enabled via {@link #setUpdateFPSFrames(int, PrintStream)}.<br>
+ * This value is reset via {@link #resetFPSCounter()}.
+ *
+ * @see #setUpdateFPSFrames(int, PrintStream)
+ * @see #resetFPSCounter()
+ */
+ long getLastFPSUpdateTime();
+
+ /**
+ * @return Duration of the last update interval in milliseconds.
+ *
+ * @see #setUpdateFPSFrames(int, PrintStream)
+ * @see #resetFPSCounter()
+ */
+ long getLastFPSPeriod();
+
+ /**
+ * @return Last update interval's frames per seconds, {@link #getUpdateFPSFrames()} / {@link #getLastFPSPeriod()}
+ *
+ * @see #setUpdateFPSFrames(int, PrintStream)
+ * @see #resetFPSCounter()
+ */
+ float getLastFPS();
+
+ /**
+ * @return Number of frame rendered since {@link #getFPSStartTime()} up to {@link #getLastFPSUpdateTime()}
+ *
+ * @see #setUpdateFPSFrames(int, PrintStream)
+ * @see #resetFPSCounter()
+ */
+ int getTotalFPSFrames();
+
+ /**
+ * @return Total duration in milliseconds, {@link #getLastFPSUpdateTime()} - {@link #getFPSStartTime()}
+ *
+ * @see #setUpdateFPSFrames(int, PrintStream)
+ * @see #resetFPSCounter()
+ */
+ long getTotalFPSDuration();
+
+
+ /**
+ * @return Total frames per seconds, {@link #getTotalFPSFrames()} / {@link #getTotalFPSDuration()}
+ *
+ * @see #setUpdateFPSFrames(int, PrintStream)
+ * @see #resetFPSCounter()
+ */
+ float getTotalFPS();
+}
diff --git a/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java b/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java
index 2c8c7cca3..83e9e22c4 100644
--- a/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java
+++ b/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java
@@ -32,47 +32,7 @@ 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();
+public interface GLAnimatorControl extends FPSCounter {
/**
* Indicates whether this animator is running, ie. has been started and not stopped.
diff --git a/src/jogl/classes/javax/media/opengl/GLArrayData.java b/src/jogl/classes/javax/media/opengl/GLArrayData.java
index 6c8122f27..448ddd10c 100644
--- a/src/jogl/classes/javax/media/opengl/GLArrayData.java
+++ b/src/jogl/classes/javax/media/opengl/GLArrayData.java
@@ -37,7 +37,6 @@ import java.nio.*;
*
*/
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
@@ -76,28 +75,41 @@ public interface GLArrayData {
* Sets the determined location of the shader attribute
* This is usually done within ShaderState.
*
- * @see com.jogamp.opengl.util.glsl.ShaderState#glVertexAttribPointer(GL2ES2, GLArrayData)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#vertexAttribPointer(GL2ES2, GLArrayData)
*/
public void setLocation(int v);
/**
- * Determines wheather the data is server side (VBO),
+ * Determines whether the data is server side (VBO) and enabled,
* or a client side array (false).
*/
public boolean isVBO();
/**
- * The offset, if it's an VBO, otherwise -1
+ * The VBO buffer offset or -1 if not a VBO
*/
- public long getOffset();
+ public long getVBOOffset();
/**
- * The VBO name, if it's an VBO, otherwise -1
+ * The VBO name or -1 if not a VBO
*/
public int getVBOName();
/**
- * The Buffer holding the data, may be null in case of VBO
+ * The VBO usage or -1 if not a VBO
+ * @return -1 if not a GPU buffer, otherwise {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ */
+ public int getVBOUsage();
+
+ /**
+ * The VBO target or -1 if not a VBO
+ * @return -1 if not a GPU buffer, otherwise {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ */
+ public int getVBOTarget();
+
+
+ /**
+ * The Buffer holding the data, may be null if a GPU buffer without client bound data
*/
public Buffer getBuffer();
@@ -112,14 +124,21 @@ public interface GLArrayData {
public int getComponentType();
/**
- * The components size in bytes
+ * The component's size in bytes
*/
public int getComponentSize();
/**
- * Return the number of elements.
+ * The current number of used elements.<br>
+ * In case the buffer's position is 0 (sealed, flipped), it's based on it's limit instead of it's position.
*/
public int getElementNumber();
+
+ /**
+ * The current number of used bytes.<br>
+ * In case the buffer's position is 0 (sealed, flipped), it's based on it's limit instead of it's position.
+ */
+ public int getByteSize();
/**
* True, if GL shall normalize fixed point data while converting
diff --git a/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java
index cf24d1028..90290d882 100644
--- a/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java
+++ b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java
@@ -185,14 +185,14 @@ public interface GLAutoDrawable extends GLDrawable {
* 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>
+ * If no {@link javax.media.opengl.GLAnimatorControl} is registered, or if it is 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>
+ * a {@link #display()} call is issued after enqueue the <code>GLRunnable</code>.<br>
+ * No extra synchronization is 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>
+ * no {@link #display()} call is issued, since the animator thread performs it.<br>
+ * If <code>wait</code> is true, the implementation waits until the <code>GLRunnable</code> is executed.<br>
* </p><br>
*
* @see #setAnimator(javax.media.opengl.GLAnimatorControl)
@@ -255,6 +255,19 @@ public interface GLAutoDrawable extends GLDrawable {
drawable. See {@link #setAutoSwapBufferMode}. */
public boolean getAutoSwapBufferMode();
+ /**
+ * @param flags Additional context creation flags.
+ *
+ * @see GLContext#setContextCreationFlags(int)
+ * @see GLContext#enableGLDebugMessage(boolean)
+ */
+ public void setContextCreationFlags(int flags);
+
+ /**
+ * @return Additional context creation flags
+ */
+ public int getContextCreationFlags();
+
/** 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
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java
index f5d47d27c..08bbcbb96 100644
--- a/src/jogl/classes/javax/media/opengl/GLContext.java
+++ b/src/jogl/classes/javax/media/opengl/GLContext.java
@@ -40,9 +40,13 @@
package javax.media.opengl;
+import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.HashSet;
import javax.media.nativewindow.AbstractGraphicsDevice;
+
+import com.jogamp.common.util.IntObjectHashMap;
+
import jogamp.opengl.Debug;
import jogamp.opengl.GLContextImpl;
@@ -81,19 +85,20 @@ public abstract class GLContext {
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 */
+ /** <code>ARB_create_context</code> related: flag not 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;
+ public 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 static ThreadLocal<GLContext> currentContext = new ThreadLocal<GLContext>();
- private HashMap/*<int, Object>*/ attachedObjects = new HashMap();
+ private HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>();
+ private IntObjectHashMap attachedObjectsByInt = new IntObjectHashMap();
/** The underlying native OpenGL context */
protected long contextHandle;
@@ -112,9 +117,8 @@ public abstract class GLContext {
ctxMinorVersion=-1;
ctxOptions=0;
ctxVersionString=null;
- if(null!=attachedObjects) {
- attachedObjects.clear();
- }
+ attachedObjectsByString.clear();
+ attachedObjectsByInt.clear();
contextHandle=0;
}
@@ -248,7 +252,7 @@ public abstract class GLContext {
* is current.
*/
public static GLContext getCurrent() {
- return (GLContext) currentContext.get();
+ return currentContext.get();
}
/**
@@ -259,6 +263,15 @@ public abstract class GLContext {
}
/**
+ * @throws GLException if this GLContext is not current on this thread
+ */
+ public final void validateCurrent() throws GLException {
+ if(getCurrent() != this) {
+ throw new GLException("Given GL context not current");
+ }
+ }
+
+ /**
* 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.
@@ -314,32 +327,40 @@ public abstract class GLContext {
* Returns the attached user object for the given name to this GLContext.
*/
public final Object getAttachedObject(int name) {
- return attachedObjects.get(new Integer(name));
+ return attachedObjectsByInt.get(name);
}
/**
* Returns the attached user object for the given name to this GLContext.
*/
public final Object getAttachedObject(String name) {
- return attachedObjects.get(name);
+ return attachedObjectsByString.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);
+ public final Object attachObject(int name, Object obj) {
+ return attachedObjectsByInt.put(name, obj);
}
+ public final Object detachObject(int name) {
+ return attachedObjectsByInt.remove(name);
+ }
+
/**
* 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);
+ public final Object attachObject(String name, Object obj) {
+ return attachedObjectsByString.put(name, obj);
}
+ public final Object detachObject(String name) {
+ return attachedObjectsByString.remove(name);
+ }
+
/**
* Classname, GL, GLDrawable
*/
@@ -399,6 +420,20 @@ public abstract class GLContext {
public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); }
public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); }
+ /**
+ * @return Additional context creation flags, supported: {@link GLContext#CTX_OPTION_DEBUG}.
+ */
+ public abstract int getContextCreationFlags();
+
+ /**
+ * @param flags Additional context creation flags, supported: {@link GLContext#CTX_OPTION_DEBUG}.
+ * Unsupported flags are masked out.
+ * Only affects this context state if not created yet via {@link #makeCurrent()}.
+ * @see #enableGLDebugMessage(boolean)
+ * @see GLAutoDrawable#setContextCreationFlags(int)
+ */
+ public abstract void setContextCreationFlags(int flags);
+
/**
* Returns a valid OpenGL version string, ie<br>
* <pre>
@@ -496,6 +531,87 @@ public abstract class GLContext {
return isGL2ES2() ;
}
+ /**
+ * @return The extension implementing the GLDebugOutput feature,
+ * either <i>GL_ARB_debug_output</i> or <i>GL_AMD_debug_output</i>.
+ * If unavailable or called before initialized via {@link #makeCurrent()}, <i>null</i> is returned.
+ */
+ public abstract String getGLDebugMessageExtension();
+
+ /**
+ * @return true if the GLDebugOutput feature is enabled or not.
+ */
+ public abstract boolean isGLDebugMessageEnabled();
+
+ /**
+ * Enables or disables the GLDebugOutput feature of extension <i>GL_ARB_debug_output</i>
+ * or <i>GL_AMD_debug_output</i>, if available.
+ *
+ * <p>To enable the GLDebugOutput feature {@link #enableGLDebugMessage(boolean) enableGLDebugMessage(true)}
+ * or {@link #setContextCreationFlags(int) setContextCreationFlags}({@link GLContext#CTX_OPTION_DEBUG})
+ * shall be called <b>before</b> context creation via {@link #makeCurrent()}!</p>
+ *
+ * <p>In case {@link GLAutoDrawable} are being used,
+ * {@link GLAutoDrawable#setContextCreationFlags(int) glAutoDrawable.setContextCreationFlags}({@link GLContext#CTX_OPTION_DEBUG})
+ * shall be issued before context creation via {@link #makeCurrent()}!</p>
+ *
+ * <p>After context creation, the GLDebugOutput feature may be enabled or disabled at any time using this method.</p>
+ *
+ * @param enable If true enables, otherwise disables the GLDebugOutput feature.
+ *
+ * @throws GLException if this context is not current or GLDebugOutput registration failed (enable)
+ *
+ * @see #setContextCreationFlags(int)
+ * @see #addGLDebugListener(GLDebugListener)
+ * @see GLAutoDrawable#setContextCreationFlags(int)
+ */
+ public abstract void enableGLDebugMessage(boolean enable) throws GLException;
+
+ /**
+ * Add {@link GLDebugListener}.<br>
+ *
+ * @param listener {@link GLDebugListener} handling {@GLDebugMessage}s
+ * @see #enableGLDebugMessage(boolean)
+ * @see #removeGLDebugListener(GLDebugListener)
+ */
+ public abstract void addGLDebugListener(GLDebugListener listener);
+
+ /**
+ * Remove {@link GLDebugListener}.<br>
+ *
+ * @param listener {@link GLDebugListener} handling {@GLDebugMessage}s
+ * @see #enableGLDebugMessage(boolean)
+ * @see #addGLDebugListener(GLDebugListener)
+ */
+ public abstract void removeGLDebugListener(GLDebugListener listener);
+
+ /**
+ * @return number of added {@link GLDebugListener}. If > 0, the GLDebugFeature is turned on, otherwise off.
+ * @see #enableGLDebugMessage(boolean)
+ */
+ public abstract int getGLDebugListenerSize();
+
+ /**
+ * Generic entry for {@link GL2GL3#glDebugMessageControlARB(int, int, int, int, IntBuffer, boolean)}
+ * and {@link GL2GL3#glDebugMessageEnableAMD(int, int, int, IntBuffer, boolean)} of the GLDebugOutput feature.
+ * @see #enableGLDebugMessage(boolean)
+ */
+ public abstract void glDebugMessageControl(int source, int type, int severity, int count, IntBuffer ids, boolean enabled);
+
+ /**
+ * Generic entry for {@link GL2GL3#glDebugMessageControlARB(int, int, int, int, int[], int, boolean)}
+ * and {@link GL2GL3#glDebugMessageEnableAMD(int, int, int, int[], int, boolean)} of the GLDebugOutput feature.
+ * @see #enableGLDebugMessage(boolean)
+ */
+ public abstract void glDebugMessageControl(int source, int type, int severity, int count, int[] ids, int ids_offset, boolean enabled);
+
+ /**
+ * Generic entry for {@link GL2GL3#glDebugMessageInsertARB(int, int, int, int, int, String)}
+ * and {@link GL2GL3#glDebugMessageInsertAMD(int, int, int, int, String)} of the GLDebugOutput feature.
+ * @see #enableGLDebugMessage(boolean)
+ */
+ public abstract void glDebugMessageInsert(int source, int type, int id, int severity, int length, String buf);
+
public static final int GL_VERSIONS[][] = {
/* 0.*/ { -1 },
/* 1.*/ { 0, 1, 2, 3, 4, 5 },
@@ -730,7 +846,7 @@ public abstract class GLContext {
public static String getGLVersion(int major, int minor, int ctp, String gl_version) {
boolean needColon = false;
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append(major);
sb.append(".");
sb.append(minor);
@@ -739,6 +855,7 @@ public abstract class GLContext {
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, "debug", needColon, 0 != ( CTX_OPTION_DEBUG & 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 ));
@@ -765,7 +882,7 @@ public abstract class GLContext {
return "0x" + Long.toHexString(hex);
}
- private static boolean appendString(StringBuffer sb, String string, boolean needColon, boolean condition) {
+ private static boolean appendString(StringBuilder sb, String string, boolean needColon, boolean condition) {
if(condition) {
if(needColon) {
sb.append(", ");
diff --git a/src/jogl/classes/javax/media/opengl/GLDebugListener.java b/src/jogl/classes/javax/media/opengl/GLDebugListener.java
new file mode 100644
index 000000000..8887d022a
--- /dev/null
+++ b/src/jogl/classes/javax/media/opengl/GLDebugListener.java
@@ -0,0 +1,44 @@
+/**
+ * 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 javax.media.opengl;
+
+/**
+ * Listener for {@link GLDebugMessage}s.
+ *
+ * <p>One can enable GLDebugOutput via {@link GLContext#enableGLDebugMessage(boolean)}
+ * and add listeners via {@link GLContext#addGLDebugListener(GLDebugListener)}.
+ */
+public interface GLDebugListener {
+ /**
+ * Handle {@link GLDebugMessage} message sent from native GL implementation.
+ *
+ * <p>Since this method is invoked directly by the GL implementation, it shall
+ * return as fast as possible.</p>
+ */
+ void messageSent(GLDebugMessage event);
+}
diff --git a/src/jogl/classes/javax/media/opengl/GLDebugMessage.java b/src/jogl/classes/javax/media/opengl/GLDebugMessage.java
new file mode 100644
index 000000000..3ab0683c6
--- /dev/null
+++ b/src/jogl/classes/javax/media/opengl/GLDebugMessage.java
@@ -0,0 +1,248 @@
+/**
+ * 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 javax.media.opengl;
+
+import com.jogamp.common.os.Platform;
+
+public class GLDebugMessage {
+ final GLContext source;
+ final long when;
+ final int dbgSource;
+ final int dbgType;
+ final int dbgId;
+ final int dbgSeverity;
+ final String dbgMsg;
+
+ /**
+ * @param source The source of the event
+ * @param when The time of the event
+ * @param dbgSource The ARB source
+ * @param dbgType The ARB type
+ * @param dbgId The ARB id
+ * @param dbgSeverity The ARB severity level
+ * @param dbgMsg The debug message
+ */
+ public GLDebugMessage(GLContext source, long when, int dbgSource, int dbgType, int dbgId, int dbgSeverity, String dbgMsg) {
+ this.source = source;
+ this.when = when;
+ this.dbgSource = dbgSource;
+ this.dbgType = dbgType;
+ this.dbgId = dbgId;
+ this.dbgSeverity = dbgSeverity;
+ this.dbgMsg = dbgMsg;
+ }
+
+ /**
+ *
+ * @param source
+ * @param when
+ * @param dbgId
+ * @param amdDbgCategory
+ * @param dbgSeverity AMD severity level equals ARB severity level (value and semantic)
+ * @param dbgMsg
+ * @return
+ */
+ public static GLDebugMessage translateAMDEvent(GLContext source, long when, int dbgId, int amdDbgCategory, int dbgSeverity, String dbgMsg) {
+ int dbgSource, dbgType;
+
+ // AMD category == ARB source/type
+ switch(amdDbgCategory) {
+ case GL2GL3.GL_DEBUG_CATEGORY_API_ERROR_AMD:
+ dbgSource = GL2GL3.GL_DEBUG_SOURCE_API_ARB;
+ dbgType = GL2GL3.GL_DEBUG_TYPE_ERROR_ARB;
+ break;
+
+ //
+ // def source / other type
+ //
+
+ case GL2GL3.GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD:
+ dbgSource = GL2GL3.GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB;
+ dbgType = GL2GL3.GL_DEBUG_TYPE_OTHER_ARB;
+ break;
+
+ case GL2GL3.GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD:
+ dbgSource = GL2GL3.GL_DEBUG_SOURCE_SHADER_COMPILER_ARB;
+ dbgType = GL2GL3.GL_DEBUG_TYPE_OTHER_ARB;
+ break;
+
+ case GL2GL3.GL_DEBUG_CATEGORY_APPLICATION_AMD:
+ dbgSource = GL2GL3.GL_DEBUG_SOURCE_APPLICATION_ARB;
+ dbgType = GL2GL3.GL_DEBUG_TYPE_OTHER_ARB;
+ break;
+
+
+ //
+ // other source / def type
+ //
+
+ case GL2GL3.GL_DEBUG_CATEGORY_DEPRECATION_AMD:
+ dbgSource = GL2GL3.GL_DEBUG_SOURCE_OTHER_ARB;
+ dbgType = GL2GL3.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB;
+ break;
+
+ case GL2GL3.GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD:
+ dbgSource = GL2GL3.GL_DEBUG_SOURCE_OTHER_ARB;
+ dbgType = GL2GL3.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB;
+ break;
+
+ case GL2GL3.GL_DEBUG_CATEGORY_PERFORMANCE_AMD:
+ dbgSource = GL2GL3.GL_DEBUG_SOURCE_OTHER_ARB;
+ dbgType = GL2GL3.GL_DEBUG_TYPE_PERFORMANCE_ARB;
+ break;
+
+ case GL2GL3.GL_DEBUG_CATEGORY_OTHER_AMD:
+ default:
+ dbgSource = GL2GL3.GL_DEBUG_SOURCE_OTHER_ARB;
+ dbgType = GL2GL3.GL_DEBUG_TYPE_OTHER_ARB;
+ }
+
+ return new GLDebugMessage(source, when, dbgSource, dbgType, dbgId, dbgSeverity, dbgMsg);
+ }
+
+ public static int translateARB2AMDCategory(int dbgSource, int dbgType) {
+ switch (dbgSource) {
+ case GL2GL3.GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB:
+ return GL2GL3.GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD;
+
+ case GL2GL3.GL_DEBUG_SOURCE_SHADER_COMPILER_ARB:
+ return GL2GL3.GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD;
+
+ case GL2GL3.GL_DEBUG_SOURCE_APPLICATION_ARB:
+ return GL2GL3.GL_DEBUG_CATEGORY_APPLICATION_AMD;
+ }
+
+ switch(dbgType) {
+ case GL2GL3.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB:
+ return GL2GL3.GL_DEBUG_CATEGORY_DEPRECATION_AMD;
+
+ case GL2GL3.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB:
+ return GL2GL3.GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD;
+
+ case GL2GL3.GL_DEBUG_TYPE_PERFORMANCE_ARB:
+ return GL2GL3.GL_DEBUG_CATEGORY_PERFORMANCE_AMD;
+ }
+
+ return GL2GL3.GL_DEBUG_CATEGORY_OTHER_AMD;
+ }
+
+ public GLContext getSource() {
+ return source;
+ }
+
+ public long getWhen() {
+ return when;
+ }
+
+ public int getDbgSource() {
+ return dbgSource;
+ }
+
+ public int getDbgType() {
+ return dbgType;
+ }
+
+ public int getDbgId() {
+ return dbgId;
+ }
+
+ public int getDbgSeverity() {
+ return dbgSeverity;
+ }
+
+ public String getDbgMsg() {
+ return dbgMsg;
+ }
+
+ public StringBuilder toString(StringBuilder sb) {
+ final String crtab = Platform.getNewline()+"\t";
+ if(null==sb) {
+ sb = new StringBuilder();
+ }
+ sb.append("GLDebugEvent[ id ");
+ toHexString(sb, dbgId)
+ .append(crtab).append("type ").append(getDbgTypeString(dbgType))
+ .append(crtab).append("severity ").append(getDbgSeverityString(dbgSeverity))
+ .append(crtab).append("source ").append(getDbgSourceString(dbgSource))
+ .append(crtab).append("msg ").append(dbgMsg)
+ .append(crtab).append("when ").append(when);
+ if(null != source) {
+ sb.append(crtab).append("source ").append(source.getGLVersion()).append(" - hash 0x").append(Integer.toHexString(source.hashCode()));
+ }
+ sb.append("]");
+ return sb;
+ }
+
+ public String toString() {
+ return toString(null).toString();
+ }
+
+ public static String getDbgSourceString(int dbgSource) {
+ switch(dbgSource) {
+ case GL2GL3.GL_DEBUG_SOURCE_API_ARB: return "GL API";
+ case GL2GL3.GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: return "GLSL or extension compiler";
+ case GL2GL3.GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: return "Native Windowing binding";
+ case GL2GL3.GL_DEBUG_SOURCE_THIRD_PARTY_ARB: return "Third party";
+ case GL2GL3.GL_DEBUG_SOURCE_APPLICATION_ARB: return "Application";
+ case GL2GL3.GL_DEBUG_SOURCE_OTHER_ARB: return "generic";
+ default: return "Unknown (" + toHexString(dbgSource) + ")";
+ }
+ }
+
+ public static String getDbgTypeString(int dbgType) {
+ switch(dbgType) {
+ case GL2GL3.GL_DEBUG_TYPE_ERROR_ARB: return "Error";
+ case GL2GL3.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: return "Warning: marked for deprecation";
+ case GL2GL3.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: return "Warning: undefined behavior";
+ case GL2GL3.GL_DEBUG_TYPE_PERFORMANCE_ARB: return "Warning: implementation dependent performance";
+ case GL2GL3.GL_DEBUG_TYPE_PORTABILITY_ARB: return "Warning: vendor-specific extension use";
+ case GL2GL3.GL_DEBUG_TYPE_OTHER_ARB: return "Warning: generic";
+ default: return "Unknown (" + toHexString(dbgType) + ")";
+ }
+ }
+
+ public static String getDbgSeverityString(int dbgSeverity) {
+ switch(dbgSeverity) {
+ case GL2GL3.GL_DEBUG_SEVERITY_HIGH_ARB: return "High: dangerous undefined behavior";
+ case GL2GL3.GL_DEBUG_SEVERITY_MEDIUM_ARB: return "Medium: Severe performance/deprecation/other warnings";
+ case GL2GL3.GL_DEBUG_SEVERITY_LOW_ARB: return "Low: Performance warnings (redundancy/undefined)";
+ default: return "Unknown (" + toHexString(dbgSeverity) + ")";
+ }
+ }
+
+ public static StringBuilder toHexString(StringBuilder sb, int i) {
+ if(null==sb) {
+ sb = new StringBuilder();
+ }
+ return sb.append("0x").append(Integer.toHexString(i));
+ }
+ public static String toHexString(int i) {
+ return "0x"+Integer.toHexString(i);
+ }
+
+}
diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java
index 17313f770..1921d117b 100644
--- a/src/jogl/classes/javax/media/opengl/GLProfile.java
+++ b/src/jogl/classes/javax/media/opengl/GLProfile.java
@@ -353,22 +353,23 @@ public class GLProfile {
* 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.
+ * <p> This includes the generic subset profiles GL2GL3, GL2ES2 and GL2ES1.</p>
*
* <ul>
* <li> GL4bc
* <li> GL3bc
* <li> GL2
- * <li> GL2GL3
* <li> GL4
* <li> GL3
- * <li> GL2ES2
+ * <li> GL2GL3
* <li> GLES2
- * <li> GL2ES1
+ * <li> GL2ES2
* <li> GLES1
+ * <li> GL2ES1
* </ul>
*
*/
- public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL4bc, GL3bc, GL2, GL2GL3, GL4, GL3, GL2ES2, GLES2, GL2ES1, GLES1 };
+ public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL4bc, GL3bc, GL2, GL4, GL3, GL2GL3, GLES2, GL2ES2, GLES1, GL2ES1 };
/**
* Order of maximum profiles.
@@ -379,15 +380,12 @@ public class GLProfile {
* <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 };
+ public static final String[] GL_PROFILE_LIST_MAX = new String[] { GL4bc, GL4, GL3bc, GL3, GL2, GLES2, GLES1 };
/**
* Order of minimum original desktop profiles.
@@ -410,56 +408,40 @@ public class GLProfile {
* <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 };
+ public static final String[] GL_PROFILE_LIST_MAX_FIXEDFUNC = new String[] { GL4bc, GL3bc, GL2, GLES1 };
/**
* Order of maximum programmable shader profiles
*
* <ul>
- * <li> GL4
* <li> GL4bc
- * <li> GL3
+ * <li> GL4
* <li> GL3bc
+ * <li> GL3
* <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 };
+ public static final String[] GL_PROFILE_LIST_MAX_PROGSHADER = new String[] { GL4bc, GL4, GL3bc, GL3, GL2, GLES2 };
/**
* All GL2ES2 Profiles in the order of default detection.
*
- * <ul>
- * <li> GL2ES2
- * <li> GL2
- * <li> GL3
- * <li> GL4
- * <li> GLES2
- * </ul>
- *
+ * @see #GL_PROFILE_LIST_MAX_PROGSHADER
*/
- public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL4, GL3, GL2, GLES2 };
+ public static final String[] GL_PROFILE_LIST_GL2ES2 = GL_PROFILE_LIST_MAX_PROGSHADER;
/**
* All GL2ES1 Profiles in the order of default detection.
*
- * <ul>
- * <li> GL2ES1
- * <li> GL2
- * <li> GL3bc
- * <li> GL4bc
- * <li> GLES1
- * </ul>
- *
+ * @see #GL_PROFILE_LIST_MAX_FIXEDFUNC
*/
- public static final String[] GL_PROFILE_LIST_GL2ES1 = new String[] { GL2ES1, GL4bc, GL3bc, GL2, GLES1 };
+ public static final String[] GL_PROFILE_LIST_GL2ES1 = GL_PROFILE_LIST_MAX_FIXEDFUNC;
/**
* All GLES Profiles in the order of default detection.
@@ -568,9 +550,9 @@ public class GLProfile {
}
/**
- * Returns a profile, implementing the interface GL2ES1.
- * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES1}
- *
+ * Returns an available GL2ES1 compatible profile.
+ * It returns the first available 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
*/
@@ -580,7 +562,13 @@ public class GLProfile {
return get(device, GL_PROFILE_LIST_GL2ES1);
}
- /** Uses the default device */
+ /**
+ * Returns an available GL2ES1 compatible profile.
+ * It returns the first available 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()
throws GLException
{
@@ -588,8 +576,8 @@ public class GLProfile {
}
/**
- * Returns a profile, implementing the interface GL2ES2.
- * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES2}
+ * Returns an available GL2ES2 compatible profile.
+ * It returns the first available 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
@@ -600,7 +588,13 @@ public class GLProfile {
return get(device, GL_PROFILE_LIST_GL2ES2);
}
- /** Uses the default device */
+ /**
+ * Returns an available GL2ES2 compatible profile
+ * It returns the first available 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()
throws GLException
{
@@ -1458,7 +1452,7 @@ public class GLProfile {
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 */);
+ HashMap<String, GLProfile> _mappedProfiles = new HashMap<String, GLProfile>(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);
@@ -1493,12 +1487,12 @@ public class GLProfile {
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;
+ if(GLContext.isGL4bcAvailable(device)) {
+ return GL4bc;
} else if(GLContext.isGL3bcAvailable(device)) {
return GL3bc;
- } else if(GLContext.isGL4bcAvailable(device)) {
- return GL4bc;
+ } else if(desktopCtxUndef || GLContext.isGL2Available(device)) {
+ return GL2;
}
}
if(hasGLES1Impl && ( eglCtxUndef || GLContext.isGLES1Available(device))) {
@@ -1506,12 +1500,16 @@ public class GLProfile {
}
} else if (GL2ES2.equals(profile)) {
if(hasGL234Impl) {
- if(desktopCtxUndef || GLContext.isGL2Available(device)) {
- return GL2;
- } else if(GLContext.isGL3Available(device)) {
- return GL3;
+ if(GLContext.isGL4bcAvailable(device)) {
+ return GL4bc;
} else if(GLContext.isGL4Available(device)) {
return GL4;
+ } else if(GLContext.isGL3bcAvailable(device)) {
+ return GL3bc;
+ } else if(GLContext.isGL3Available(device)) {
+ return GL3;
+ } else if(desktopCtxUndef || GLContext.isGL2Available(device)) {
+ return GL2;
}
}
if(hasGLES2Impl && ( eglCtxUndef || GLContext.isGLES2Available(device))) {
@@ -1519,16 +1517,16 @@ public class GLProfile {
}
} else if(GL2GL3.equals(profile)) {
if(hasGL234Impl) {
- if(desktopCtxUndef || GLContext.isGL2Available(device)) {
- return GL2;
+ if(GLContext.isGL4bcAvailable(device)) {
+ return GL4bc;
+ } else if(GLContext.isGL4Available(device)) {
+ return GL4;
} 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(desktopCtxUndef || GLContext.isGL2Available(device)) {
+ return GL2;
}
}
} else if(GL4bc.equals(profile) && hasGL234Impl && ( desktopCtxUndef || GLContext.isGL4bcAvailable(device))) {
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index 4076dac54..160cdce51 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -152,7 +152,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
// copy of the cstr args, mainly for recreation
private GLCapabilitiesImmutable capsReqUser;
private GLCapabilitiesChooser chooser;
- private GLContext shareWith;
+ private GLContext shareWith;
+ private int additionalCtxCreationFlags = 0;
private GraphicsDevice device;
private AWTWindowClosingProtocol awtWindowClosingProtocol =
@@ -525,6 +526,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
.createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig));
context = (GLContextImpl) drawable.createContext(shareWith);
context.setSynchronized(true);
+ context.setContextCreationFlags(additionalCtxCreationFlags);
}
// before native peer is valid: X11
@@ -660,6 +662,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
public void setContext(GLContext ctx) {
context=(GLContextImpl)ctx;
+ if(null != context) {
+ context.setContextCreationFlags(additionalCtxCreationFlags);
+ }
}
public GLContext getContext() {
@@ -696,6 +701,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
maybeDoSingleThreadedWorkaround(swapBuffersOnEventDispatchThreadAction, swapBuffersAction);
}
+ public void setContextCreationFlags(int flags) {
+ additionalCtxCreationFlags = flags;
+ }
+
+ public int getContextCreationFlags() {
+ return additionalCtxCreationFlags;
+ }
+
public GLProfile getGLProfile() {
return capsReqUser.getGLProfile();
}
@@ -745,9 +758,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
@Override
public String toString() {
- final int dw = (null!=drawable) ? drawable.getWidth() : -1;
- final int dh = (null!=drawable) ? drawable.getHeight() : -1;
-
+ 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()+
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index d58ad0304..2d58584f7 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -136,6 +136,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
private GLDrawableFactoryImpl factory;
private GLCapabilitiesChooser chooser;
private GLContext shareWith;
+ private int additionalCtxCreationFlags = 0;
+
// Width of the actual GLJPanel
private int panelWidth = 0;
private int panelHeight = 0;
@@ -488,6 +490,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
if (backend == null) {
return;
}
+ if(null != ctx) {
+ ctx.setContextCreationFlags(additionalCtxCreationFlags);
+ }
backend.setContext(ctx);
}
@@ -531,7 +536,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
// 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
@@ -540,6 +545,14 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
// Swing portion of the GLJPanel in any of the rendering paths.
}
+ public void setContextCreationFlags(int flags) {
+ additionalCtxCreationFlags = flags;
+ }
+
+ public int getContextCreationFlags() {
+ return additionalCtxCreationFlags;
+ }
+
/** For a translucent GLJPanel (one for which {@link #setOpaque
setOpaque}(false) has been called), indicates whether the
application should preserve the OpenGL color buffer
@@ -1023,6 +1036,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
Math.max(1, panelHeight));
offscreenContext = (GLContextImpl) offscreenDrawable.createContext(shareWith);
offscreenContext.setSynchronized(true);
+ offscreenContext.setContextCreationFlags(additionalCtxCreationFlags);
+
isInitialized = true;
}
@@ -1108,6 +1123,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
pbufferWidth,
pbufferHeight,
shareWith);
+ pbuffer.setContextCreationFlags(additionalCtxCreationFlags);
pbuffer.addGLEventListener(updater);
isInitialized = true;
} catch (GLException e) {
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
index 9208afc24..0b47606e4 100755
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
@@ -27,53 +27,29 @@
*/
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.opengl.shader.AttributeNames;
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.graph.curve.opengl.RenderState;
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);
+ public RegionRendererImpl01(RenderState rs, int type) {
+ super(rs, type);
+ // rs.getSharpness().setData(0.5f);
+ // rs.getAlpha().setData(1.0f);
+ // rs.getStrength().setData(3.0f);
}
- 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);
+ protected boolean initShaderProgram(GL2ES2 gl) {
+ final ShaderState st = rs.getShaderState();
ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, RegionRendererImpl01.class,
"shader", "shader/bin", "curverenderer01");
@@ -85,60 +61,15 @@ public class RegionRendererImpl01 extends RegionRenderer {
sp.add(rsFp);
sp.init(gl);
- gl.glBindAttribLocation(sp.program(), Region.VERTEX_ATTR_IDX, "v_position");
- gl.glBindAttribLocation(sp.program(), Region.TEXCOORD_ATTR_IDX, "texCoord");
+ st.attachShaderProgram(gl, sp);
+ st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
+ st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
if(!sp.link(gl, System.err)) {
throw new GLException("RegionRenderer: Couldn't link program: "+sp);
- }
-
- st = new ShaderState();
- st.attachShaderProgram(gl, sp);
-
- 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);
+ }
+ st.useProgram(gl, true);
- 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);
}
@@ -150,59 +81,35 @@ public class RegionRendererImpl01 extends RegionRenderer {
super.disposeImpl(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);
+ 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);
+ regions.put(hashCode, region);
+ }
+ region.render(gl, rs, vp_width, vp_height, texSize);
}
-
- @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
+ @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);
- }
+
+ int hashCode = getHashCode(outlineShapes);
+ Region region = regions.get(hashCode);
+
+ if(null == region) {
+ region = createRegion(gl, outlineShapes);
+ regions.put(hashCode, region);
+ }
+ region.render(gl, rs, vp_width, vp_height, texSize);
+ }
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java
new file mode 100644
index 000000000..eef64dab5
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.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.graph.curve.opengl;
+
+import java.nio.FloatBuffer;
+
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLUniformData;
+import javax.media.opengl.fixedfunc.GLMatrixFunc;
+
+import jogamp.graph.curve.opengl.shader.UniformNames;
+
+import com.jogamp.common.os.Platform;
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+public class RenderStateImpl implements RenderState {
+
+ private final ShaderState st;
+ private final Vertex.Factory<? extends Vertex> pointFactory;
+ private final PMVMatrix pmvMatrix;
+ private final GLUniformData gcu_PMVMatrix;
+
+ /**
+ * Sharpness is equivalent to the texture-coord component <i>t</i>
+ * on the off-curve vertex. Higher values of sharpness will
+ * result in higher curvature.
+ */
+ private final GLUniformData gcu_Sharpness;
+ private final GLUniformData gcu_Alpha;
+ private final GLUniformData gcu_ColorStatic;
+ private final GLUniformData gcu_Strength;
+
+ public static final RenderState getRenderState(GL2ES2 gl) {
+ return (RenderState) gl.getContext().getAttachedObject(RenderState.class.getName());
+ }
+
+ public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) {
+ this.st = st;
+ this.pointFactory = pointFactory;
+ this.pmvMatrix = pmvMatrix;
+ this.gcu_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMatrixf());
+ st.ownUniform(gcu_PMVMatrix);
+
+ gcu_Sharpness = new GLUniformData(UniformNames.gcu_P1Y, 0.5f);
+ st.ownUniform(gcu_PMVMatrix);
+ gcu_Alpha = new GLUniformData(UniformNames.gcu_Alpha, 1.0f);
+ st.ownUniform(gcu_Alpha);
+ gcu_ColorStatic = new GLUniformData(UniformNames.gcu_ColorStatic, 3, FloatBuffer.allocate(3));
+ st.ownUniform(gcu_ColorStatic);
+ gcu_Strength = new GLUniformData(UniformNames.gcu_Strength, 3.0f);
+ st.ownUniform(gcu_Strength);
+ }
+
+ public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) {
+ this(st, pointFactory, new PMVMatrix());
+
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ }
+
+ public final ShaderState getShaderState() { return st; }
+ public final Vertex.Factory<? extends Vertex> getPointFactory () { return pointFactory; }
+ public final PMVMatrix pmvMatrix() { return pmvMatrix; }
+ public final GLUniformData getPMVMatrix() { return gcu_PMVMatrix; }
+ public final GLUniformData getSharpness() { return gcu_Sharpness; }
+ public final GLUniformData getAlpha() { return gcu_Alpha; }
+ public final GLUniformData getColorStatic() { return gcu_ColorStatic; }
+ public final GLUniformData getStrength() { return gcu_Strength; }
+
+ public void destroy(GL2ES2 gl) {
+ st.destroy(gl);
+ }
+
+ public final RenderState attachTo(GL2ES2 gl) {
+ return (RenderState) gl.getContext().attachObject(RenderState.class.getName(), this);
+ }
+ public final boolean detachFrom(GL2ES2 gl) {
+ RenderState _rs = (RenderState) gl.getContext().getAttachedObject(RenderState.class.getName());
+ if(_rs == this) {
+ gl.getContext().detachObject(RenderState.class.getName());
+ return true;
+ }
+ return false;
+ }
+
+ public StringBuilder toString(StringBuilder sb) {
+ if(null==sb) {
+ sb = new StringBuilder();
+ }
+
+ sb.append("RenderState[");
+ st.toString(sb).append(Platform.getNewline());
+ sb.append("]");
+
+ return sb;
+ }
+
+ public String toString() {
+ return toString(null).toString();
+ }
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
index 01572de58..2255251a7 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
@@ -27,166 +27,74 @@
*/
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.opengl.shader.AttributeNames;
import jogamp.graph.curve.text.GlyphString;
-import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.RenderState;
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;
+import com.jogamp.opengl.util.glsl.ShaderState;
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);
-
+ public TextRendererImpl01(RenderState rs, int type) {
+ super(rs, type);
+ // rs.getSharpness().setData(0.5f);
+ // rs.getAlpha().setData(1.0f);
+ // rs.getStrength().setData(3.0f);
+ rs.getStrength().setData(1.9f);
+ }
+
+ @Override
+ protected boolean initShaderProgram(GL2ES2 gl){
+ final ShaderState st = rs.getShaderState();
+
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);
sp.init(gl);
- gl.glBindAttribLocation(sp.program(), Region.VERTEX_ATTR_IDX, "v_position");
- gl.glBindAttribLocation(sp.program(), Region.TEXCOORD_ATTR_IDX, "texCoord");
+ st.attachShaderProgram(gl, sp);
+ st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
+ st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
if(!sp.link(gl, System.err)) {
throw new GLException("TextRendererImpl01: Couldn't link program: "+sp);
}
+ st.useProgram(gl, true);
- st.attachShaderProgram(gl, sp);
-
- 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) {
- super.disposeImpl(gl);
- }
-
+ if(DEBUG) {
+ System.err.println("TextRendererImpl01 initialized: " + Thread.currentThread()+" "+st);
+ }
+ return true;
+ }
+
@Override
- public float getAlpha() {
- return mgl_alpha.floatValue();
+ protected void disposeImpl(GL2ES2 gl) {
+ super.disposeImpl(gl);
}
-
+
@Override
- public void setAlpha(GL2ES2 gl, float alpha_t) {
- mgl_alpha.setData(alpha_t);
- if(null != gl && st.inUse()) {
- st.glUniform(gl, mgl_alpha);
+ 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);
+ addCachedGlyphString(gl, font, str, fontSize, glyphString);
}
+
+ glyphString.renderString3D(gl, rs, vp_width, vp_height, texSize);
}
-
- @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/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
index 075a65ec9..90b3d47cd 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
@@ -27,324 +27,345 @@
*/
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.GL;
-import javax.media.opengl.GLContext;
import javax.media.opengl.GLUniformData;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
-import com.jogamp.common.nio.Buffers;
+import jogamp.graph.curve.opengl.shader.AttributeNames;
+import jogamp.graph.curve.opengl.shader.UniformNames;
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.graph.curve.opengl.RenderState;
import com.jogamp.opengl.util.FBObject;
+import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
-public class VBORegion2PES2 implements Region{
- private int numVertices = 0;
- private 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 FBObject fbo = null;
+public class VBORegion2PES2 implements Region {
+ private int numVertices = 0;
+
+ private ArrayList<Triangle> triangles = new ArrayList<Triangle>();
+ private ArrayList<Vertex> vertices = new ArrayList<Vertex>();
+ private GLArrayDataServer verticeTxtAttr;
+ private GLArrayDataServer texCoordTxtAttr;
+ private GLArrayDataServer indicesTxt;
+ private GLArrayDataServer verticeFboAttr;
+ private GLArrayDataServer texCoordFboAttr;
+ private GLArrayDataServer indicesFbo;
+
+ private boolean flipped = false;
+
+ private boolean dirty = true;
+
+ private AABBox box;
+ private FBObject fbo;
- 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){
- initFBOTexture(matrix, width);
- }
-// 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);
- fbo.use(gl);
-
- st.glUniform(gl, new GLUniformData("texture", fbo.getTextureName()));
- int loc = gl.glGetUniformLocation(st.shaderProgram().program(), "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();
+ private PMVMatrix fboPMVMatrix;
+ GLUniformData mgl_fboPMVMatrix;
+
+ private int tex_width_c = 0;
+ private int tex_height_c = 0;
+ GLUniformData mgl_ActiveTexture;
+ int activeTexture; // texture engine 0 == GL.GL_TEXTURE0
+
+ public VBORegion2PES2(RenderState rs, int textureEngine) {
+ fboPMVMatrix = new PMVMatrix();
+ mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf());
+
+ activeTexture = GL.GL_TEXTURE0 + textureEngine;
+ mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureEngine);
+
+ final int initialSize = 256;
+ final ShaderState st = rs.getShaderState();
+
+ indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
+ indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
+ indicesFbo.seal(true);
+
+ texCoordFboAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.ownAttribute(texCoordFboAttr, true);
+ texCoordFboAttr.putf(5); texCoordFboAttr.putf(5);
+ texCoordFboAttr.putf(5); texCoordFboAttr.putf(6);
+ texCoordFboAttr.putf(6); texCoordFboAttr.putf(6);
+ texCoordFboAttr.putf(6); texCoordFboAttr.putf(5);
+ texCoordFboAttr.seal(true);
+
+ verticeFboAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.ownAttribute(verticeFboAttr, true);
+
+
+ box = new AABBox();
+
+ indicesTxt = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+
+ verticeTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.ownAttribute(verticeTxtAttr, true);
+
+ texCoordTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.ownAttribute(texCoordTxtAttr, true);
+
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Create: " + this);
+ }
+ }
+
+ public void update(GL2ES2 gl){
+ if(!dirty) {
+ return;
+ }
+
+ // process triangles
+ indicesTxt.seal(gl, false);
+ indicesTxt.rewind();
+ for(Triangle t:triangles){
+ if(t.getVertices()[0].getId() == Integer.MAX_VALUE){
+ t.getVertices()[0].setId(numVertices++);
+ t.getVertices()[1].setId(numVertices++);
+ t.getVertices()[2].setId(numVertices++);
+
+ vertices.add(t.getVertices()[0]);
+ vertices.add(t.getVertices()[1]);
+ vertices.add(t.getVertices()[2]);
+
+ indicesTxt.puts((short) t.getVertices()[0].getId());
+ indicesTxt.puts((short) t.getVertices()[1].getId());
+ indicesTxt.puts((short) t.getVertices()[2].getId());
+ }
+ else{
+ Vertex v1 = t.getVertices()[0];
+ Vertex v2 = t.getVertices()[1];
+ Vertex v3 = t.getVertices()[2];
+
+ indicesTxt.puts((short) v1.getId());
+ indicesTxt.puts((short) v2.getId());
+ indicesTxt.puts((short) v3.getId());
+ }
+ }
+ indicesTxt.seal(gl, true);
+ indicesTxt.enableBuffer(gl, false);
- 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 tex_width){
- tex_width_c = tex_width;
- tex_height_c = (int)(tex_width_c*box.getHeight()/box.getWidth());
-
- 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));
+ // process vertices and update bbox
+ box.reset();
+ verticeTxtAttr.seal(gl, false);
+ verticeTxtAttr.rewind();
+ texCoordTxtAttr.seal(gl, false);
+ texCoordTxtAttr.rewind();
+ for(Vertex v:vertices){
+ verticeTxtAttr.putf(v.getX());
+ if(flipped){
+ verticeTxtAttr.putf(-1*v.getY());
+ } else {
+ verticeTxtAttr.putf(v.getY());
+ }
+ verticeTxtAttr.putf(v.getZ());
+ if(flipped){
+ box.resize(v.getX(), -1*v.getY(), v.getZ());
+ } else {
+ box.resize(v.getX(), v.getY(), v.getZ());
+ }
+
+ final float[] tex = v.getTexCoord();
+ texCoordTxtAttr.putf(tex[0]);
+ texCoordTxtAttr.putf(tex[1]);
+ }
+ texCoordTxtAttr.seal(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.seal(gl, true);
+ verticeTxtAttr.enableBuffer(gl, false);
+
+ // update all bbox related data
+ verticeFboAttr.seal(gl, false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.seal(gl, true);
+ verticeFboAttr.enableBuffer(gl, false);
+
+ fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getLow()[0], box.getHigh()[0], box.getLow()[1], box.getHigh()[1], -1, 1);
+
+ // push data 2 GPU ..
+ indicesFbo.seal(gl, true);
+ indicesFbo.enableBuffer(gl, false);
+
+ dirty = false;
+
+ // the buffers were disabled, since due to real/fbo switching and other vbo usage
+ }
+
+ public void render(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int width) {
+ if(vp_width <=0 || vp_height <= 0 || width <= 0){
+ renderRegion(gl);
+ } else {
+ if(width != tex_width_c){
+ renderRegion2FBO(gl, rs, width);
+ }
+ // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
+ renderFBO(gl, rs, vp_width, vp_height);
+ }
+ }
+
+ private void renderFBO(GL2ES2 gl, RenderState rs, int width, int hight) {
+ final ShaderState st = rs.getShaderState();
+
+ gl.glViewport(0, 0, width, hight);
+
+ gl.glEnable(GL2ES2.GL_TEXTURE_2D);
+ /* setback:
+ int[] currentActiveTextureEngine = new int[1];
+ gl.glGetIntegerv(GL.GL_ACTIVE_TEXTURE, currentActiveTextureEngine, 0);
+ */
+ gl.glActiveTexture(activeTexture);
+ st.uniform(gl, mgl_ActiveTexture);
+
+ fbo.use(gl);
+ verticeFboAttr.enableBuffer(gl, true);
+ texCoordFboAttr.enableBuffer(gl, true);
+ indicesFbo.enableBuffer(gl, true);
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementNumber() * indicesFbo.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ verticeFboAttr.enableBuffer(gl, false);
+ texCoordFboAttr.enableBuffer(gl, false);
+ indicesFbo.enableBuffer(gl, false);
+ fbo.unuse(gl);
+
+ // setback: gl.glActiveTexture(currentActiveTextureEngine[0]);
+ }
+
+ private void renderRegion2FBO(GL2ES2 gl, RenderState rs, int tex_width) {
+ final ShaderState st = rs.getShaderState();
+
+ tex_width_c = tex_width;
+ tex_height_c = (int)(tex_width_c*box.getHeight()/box.getWidth());
+
+ // System.out.println("FBO Size: "+tex_width+" -> "+tex_height_c+"x"+tex_width_c);
+ // System.out.println("FBO Scale: " + m.glGetMatrixf().get(0) +" " + m.glGetMatrixf().get(5));
- GL2ES2 gl = context.getGL().getGL2ES2();
- if(null != fbo) {
+ if(null != fbo && fbo.getWidth() != tex_width_c && fbo.getHeight() != tex_height_c ) {
fbo.destroy(gl);
fbo = null;
}
- fbo = new FBObject(tex_width_c, tex_height_c);
- // FIXME: shall not use bilinear, due to own AA ? However, w/o bilinear result is not smooth
- fbo.init(gl, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
- // fbo.init(gl, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
- fbo.attachDepthBuffer(gl, GL.GL_DEPTH_COMPONENT16); // FIXME: or shall we use 24 or 32 bit depth ?
-
-
- //render texture
- PMVMatrix tex_matrix = new PMVMatrix();
- gl.glViewport(0, 0, tex_width_c, tex_height_c);
- tex_matrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- tex_matrix.glLoadIdentity();
- tex_matrix.glOrthof(box.getLow()[0], box.getHigh()[0], box.getLow()[1], box.getHigh()[1], -1, 1);
-
- if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, tex_matrix.glGetPMvMatrixf()))){
- System.out.println("Cnt set tex based mat");
- }
-
- gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
- renderRegion();
-
- fbo.unbind(gl);
-
- 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);
- if(null != fbo) {
- fbo.destroy(gl);
- fbo = null;
- }
- }
-
- public boolean isFlipped() {
- return flipped;
- }
+ if(null == fbo) {
+ fbo = new FBObject(tex_width_c, tex_height_c);
+ // FIXME: shall not use bilinear, due to own AA ? However, w/o bilinear result is not smooth
+ fbo.init(gl, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ // fbo.init(gl, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ fbo.attachDepthBuffer(gl, GL.GL_DEPTH_COMPONENT16); // FIXME: or shall we use 24 or 32 bit depth ?
+ } else {
+ fbo.bind(gl);
+ }
+
+ //render texture
+ gl.glViewport(0, 0, tex_width_c, tex_height_c);
+ st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
+
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
+ renderRegion(gl);
+ fbo.unbind(gl);
+
+ st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix
+ }
+
+ private void renderRegion(GL2ES2 gl) {
+ verticeTxtAttr.enableBuffer(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, true);
+ indicesTxt.enableBuffer(gl, true);
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementNumber() * indicesTxt.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ verticeTxtAttr.enableBuffer(gl, false);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ indicesTxt.enableBuffer(gl, false);
+ }
+
+ public void addTriangles(ArrayList<Triangle> tris) {
+ triangles.addAll(tris);
+ dirty = true;
+ }
+
+ public int getNumVertices(){
+ return numVertices;
+ }
+
+ public void addVertices(ArrayList<Vertex> verts){
+ vertices.addAll(verts);
+ numVertices = vertices.size();
+ dirty = true;
+ }
+
+ public boolean isDirty(){
+ return dirty;
+ }
+
+ public void destroy(GL2ES2 gl, RenderState rs) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Destroy: " + this);
+ }
+ final ShaderState st = rs.getShaderState();
+ if(null != fbo) {
+ fbo.destroy(gl);
+ fbo = null;
+ }
+ if(null != verticeTxtAttr) {
+ st.ownAttribute(verticeTxtAttr, false);
+ verticeTxtAttr.destroy(gl);
+ verticeTxtAttr = null;
+ }
+ if(null != texCoordTxtAttr) {
+ st.ownAttribute(texCoordTxtAttr, false);
+ texCoordTxtAttr.destroy(gl);
+ texCoordTxtAttr = null;
+ }
+ if(null != indicesTxt) {
+ indicesTxt.destroy(gl);
+ indicesTxt = null;
+ }
+ if(null != verticeFboAttr) {
+ st.ownAttribute(verticeFboAttr, false);
+ verticeFboAttr.destroy(gl);
+ verticeFboAttr = null;
+ }
+ if(null != texCoordFboAttr) {
+ st.ownAttribute(texCoordFboAttr, false);
+ texCoordFboAttr.destroy(gl);
+ texCoordFboAttr = null;
+ }
+ if(null != indicesFbo) {
+ indicesFbo.destroy(gl);
+ indicesFbo = null;
+ }
+ triangles.clear();
+ vertices.clear();
+ }
+
+ public boolean isFlipped() {
+ return flipped;
+ }
- public void setFlipped(boolean flipped) {
- this.flipped = flipped;
- }
+ public void setFlipped(boolean flipped) {
+ this.flipped = flipped;
+ }
+
+ public AABBox getBounds(){
+ return box;
+ }
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 701549d46..7956e5137 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -27,159 +27,195 @@
*/
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.GL;
import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLContext;
-import com.jogamp.common.nio.Buffers;
+import jogamp.graph.curve.opengl.shader.AttributeNames;
+
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.geom.AABBox;
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]);
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.glsl.ShaderState;
- 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();
+public class VBORegionSPES2 implements Region {
+ private int numVertices = 0;
+
+ private ArrayList<Triangle> triangles = new ArrayList<Triangle>();
+ private ArrayList<Vertex> vertices = new ArrayList<Vertex>();
+ private GLArrayDataServer verticeAttr = null;
+ private GLArrayDataServer texCoordAttr = null;
+ private GLArrayDataServer indices = null;
+
+ private boolean flipped = false;
+ private boolean dirty = true;
+
+ private AABBox box = null;
+
+ public VBORegionSPES2(RenderState rs){
+ box = new AABBox();
+
+ final int initialSize = 256;
+ final ShaderState st = rs.getShaderState();
+
+ indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+
+ verticeAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.ownAttribute(verticeAttr, true);
+
+ texCoordAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2,
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.ownAttribute(texCoordAttr, true);
+
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2 Create: " + this);
+ }
+ }
+
+ public void update(GL2ES2 gl){
+ if(!dirty) {
+ return;
+ }
+
+ // process triangles
+ indices.seal(gl, false);
+ indices.rewind();
+ 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]);
- 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;
- }
+ indices.puts((short) t.getVertices()[0].getId());
+ indices.puts((short) t.getVertices()[1].getId());
+ indices.puts((short) t.getVertices()[2].getId());
+ }
+ else{
+ Vertex v1 = t_vertices[0];
+ Vertex v2 = t_vertices[1];
+ Vertex v3 = t_vertices[2];
+
+ indices.puts((short) v1.getId());
+ indices.puts((short) v2.getId());
+ indices.puts((short) v3.getId());
+ }
+ }
+ indices.seal(gl, true);
+ indices.enableBuffer(gl, false);
+
+ // process vertices and update bbox
+ box.reset();
+ verticeAttr.seal(gl, false);
+ verticeAttr.rewind();
+ texCoordAttr.seal(gl, false);
+ texCoordAttr.rewind();
+ for(Vertex v:vertices){
+ if(flipped){
+ verticeAttr.putf(v.getX());
+ verticeAttr.putf(-1*v.getY());
+ verticeAttr.putf(v.getZ());
+
+ box.resize(v.getX(),-1*v.getY(),v.getZ());
+ }
+ else{
+ verticeAttr.putf(v.getX());
+ verticeAttr.putf(v.getY());
+ verticeAttr.putf(v.getZ());
+
+ box.resize(v.getX(),v.getY(),v.getZ());
+ }
+
+ final float[] tex = v.getTexCoord();
+ texCoordAttr.putf(tex[0]);
+ texCoordAttr.putf(tex[1]);
+ }
+ verticeAttr.seal(gl, true);
+ verticeAttr.enableBuffer(gl, false);
+ texCoordAttr.seal(gl, true);
+ texCoordAttr.enableBuffer(gl, false);
+
+ // update all bbox related data: nope
+
+ dirty = false;
+
+ // the buffers were disabled, since due to real/fbo switching and other vbo usage
+ }
+
+ private void render(GL2ES2 gl) {
+ verticeAttr.enableBuffer(gl, true);
+ texCoordAttr.enableBuffer(gl, true);
+ indices.enableBuffer(gl, true);
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indices.getElementNumber() * indices.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ verticeAttr.enableBuffer(gl, false);
+ texCoordAttr.enableBuffer(gl, false);
+ indices.enableBuffer(gl, false);
+ }
+
+ public void render(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int width) {
+ render(gl);
+ }
+
+ public void addTriangles(ArrayList<Triangle> tris) {
+ triangles.addAll(tris);
+ dirty = true;
+ }
+
+ public int getNumVertices(){
+ return numVertices;
+ }
+
+ public void addVertices(ArrayList<Vertex> verts){
+ vertices.addAll(verts);
+ numVertices = vertices.size();
+ dirty = true;
+ }
+
+ public boolean isDirty(){
+ return dirty;
+ }
+
+ public final void destroy(GL2ES2 gl, RenderState rs) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2 Destroy: " + this);
+ }
+ final ShaderState st = rs.getShaderState();
+ if(null != verticeAttr) {
+ st.ownAttribute(verticeAttr, false);
+ verticeAttr.destroy(gl);
+ verticeAttr = null;
+ }
+ if(null != texCoordAttr) {
+ st.ownAttribute(texCoordAttr, false);
+ texCoordAttr.destroy(gl);
+ texCoordAttr = null;
+ }
+ if(null != indices) {
+ indices.destroy(gl);
+ indices = null;
+ }
+ }
+
+ public boolean isFlipped() {
+ return flipped;
+ }
- public void setFlipped(boolean flipped) {
- this.flipped = flipped;
- }
+ public void setFlipped(boolean flipped) {
+ this.flipped = flipped;
+ }
+ public AABBox getBounds(){
+ return box;
+ }
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java
new file mode 100644
index 000000000..59dacf8af
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java
@@ -0,0 +1,18 @@
+package jogamp.graph.curve.opengl.shader;
+
+public class AttributeNames {
+ /** The vertices index in an OGL object
+ */
+ public static final int VERTEX_ATTR_IDX = 0; // FIXME: AMD needs this to be location 0 ? hu ?
+ public static final String VERTEX_ATTR_NAME = "gca_Vertices";
+
+ /** The Texture Coord index in an OGL object
+ */
+ public static final int TEXCOORD_ATTR_IDX = 1;
+ public static final String TEXCOORD_ATTR_NAME = "gca_TexCoords";
+
+ /** The color index in an OGL object
+ */
+ public static final int COLOR_ATTR_IDX = 2;
+ public static final String COLOR_ATTR_NAME = "gca_Colors";
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java
new file mode 100644
index 000000000..2e04278ca
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java
@@ -0,0 +1,10 @@
+package jogamp.graph.curve.opengl.shader;
+
+public class UniformNames {
+ public static final String gcu_PMVMatrix = "gcu_PMVMatrix"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi
+ public static final String gcu_ColorStatic = "gcu_ColorStatic";
+ public static final String gcu_Alpha = "gcu_Alpha";
+ public static final String gcu_P1Y = "gcu_P1Y";
+ public static final String gcu_Strength = "gcu_Strength";
+ public static final String gcu_TextureUnit = "gcu_TextureUnit";
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl
new file mode 100644
index 000000000..c9a242573
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl
@@ -0,0 +1,13 @@
+
+#ifndef attributes_glsl
+#define attributes_glsl
+
+#include precision.glsl
+
+// attribute HIGHP vec3 gca_Vertices;
+attribute HIGHP vec4 gca_Vertices;
+attribute HIGHP vec2 gca_TexCoords;
+//attribute HIGHP vec4 gca_Colors;
+//attribute HIGHP vec3 gca_Normals;
+
+#endif // attributes_glsl
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl
new file mode 100644
index 000000000..4cb41c903
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl
@@ -0,0 +1,10 @@
+
+#ifndef consts_glsl
+#define consts_glsl
+
+#include precision.glsl
+
+const LOWP int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits
+// const LOWP int MAX_LIGHTS = 8;
+
+#endif // consts_glsl
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp
index 3a1ef5157..975c2dc5b 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp
@@ -1,95 +1,97 @@
//Copyright 2010 JogAmp Community. All rights reserved.
-//#version 100
-uniform float p1y;
-uniform float g_alpha;
-uniform vec3 g_color;
-uniform float a_strength;
+/**
+ * AMD complains: #version must occur before any other statement in the program
+#ifdef GL_ES
+ #version 100
+#else
+ #version 110
+#endif
+ */
+
+#include uniforms.glsl
+#include varyings.glsl
-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);
+const vec3 b_color = vec3(0.0, 0.0, 0.0);
+const 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;
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+ vec3 c = gcu_ColorStatic.rgb;
+
+ float alpha = 0.0;
+
+ if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)){
+ alpha = gcu_Alpha;
+ }
+ else if((gcv_TexCoord.x >= 5.0)){
+ vec2 dfx = dFdx(gcv_TexCoord);
+ vec2 dfy = dFdy(gcv_TexCoord);
+
+ vec2 size = 1.0/textureSize(gcu_TextureUnit,0); //version 130 - FIXME: replace with uniform value
+ rtex -= 5.0;
+ vec4 t = texture2D(gcu_TextureUnit, 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 - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
- float position = rtex.y - (rtex.x * (1.0 - rtex.x));
- float d = position/(length(f));
+ t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*weights.x;
+ t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*weights.x;
+ t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*weights.x;
+ t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*weights.x;
+
+ t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*weights.y;
+ t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*weights.y;
+ t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*weights.y;
+ t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*weights.y;
+
+ t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*weights.z;
+ t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*weights.z;
+ t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*weights.z;
+ t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*weights.z;
+
+ t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*weights.w;
+ t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*weights.w;
+ t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*weights.w;
+ t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*weights.w;
+
+ if(t.w == 0.0){
+ discard;
+ }
+
+ c = t.xyz;
+ alpha = gcu_Alpha * t.w;
+ }
+ ///////////////////////////////////////////////////////////
+ else if ((gcv_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(gcv_TexCoord.y < 0.0)
+ discard;
+ else{
+ rtex.y = 0.0;
+ }
+ }
+
+ vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
+ float position = rtex.y - (rtex.x * (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;
- }
- else if (a <= 0.0) {
- alpha = 0.0;//discard;
- }
- else {
- alpha = g_alpha*a;
- mix(b_color,g_color, a);
- }
- }
-
+ float a = (0.5 - d * sign(gcv_TexCoord.y));
+
+ if (a >= 1.0) {
+ alpha = gcu_Alpha;
+ }
+ else if (a <= 0.0) {
+ alpha = 0.0;//discard;
+ }
+ else {
+ alpha = gcu_Alpha * a;
+ mix(b_color,gcu_ColorStatic.rgb, a);
+ }
+ }
+
gl_FragColor = vec4(c, alpha);
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp
index bc9ecb41e..fe74caffb 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp
@@ -1,13 +1,21 @@
-//#version 100
+//Copyright 2010 JogAmp Community. All rights reserved.
-uniform mat4 mgl_PMVMatrix[2];
-attribute vec4 v_position;
-attribute vec2 texCoord;
+/**
+ * AMD complains: #version must occur before any other statement in the program
+#ifdef GL_ES
+ #version 100
+#else
+ #version 110
+#endif
+ */
-varying vec2 v_texCoord;
+#include uniforms.glsl
+#include attributes.glsl
+#include varyings.glsl
void main(void)
{
- gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * v_position;
- v_texCoord = texCoord.st;
-} \ No newline at end of file
+ // gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * vec4(gca_Vertices, 1);
+ gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * gca_Vertices;
+ gcv_TexCoord = gca_TexCoords;
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl
new file mode 100644
index 000000000..1ac4ed8e9
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl
@@ -0,0 +1,14 @@
+#ifndef precision_glsl
+#define precision_glsl
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+ #define HIGHP highp
+ #define LOWP lowp
+#else
+ #define MEDIUMP
+ #define HIGHP
+ #define LOWP
+#endif
+
+#endif // precision_glsl
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
new file mode 100644
index 000000000..677c7324f
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
@@ -0,0 +1,21 @@
+
+#ifndef uniforms_glsl
+#define uniforms_glsl
+
+#include precision.glsl
+
+// #include consts.glsl
+
+uniform HIGHP mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi
+uniform HIGHP vec3 gcu_ColorStatic;
+uniform HIGHP float gcu_Alpha;
+uniform HIGHP float gcu_P1Y;
+uniform HIGHP float gcu_Strength;
+uniform sampler2D gcu_TextureUnit;
+
+// uniform HIGHP mat3 gcu_NormalMatrix; // transpose(inverse(ModelView)).3x3
+// uniform LOWP int gcu_ColorEnabled;
+// uniform LOWP int gcu_TexCoordEnabled[MAX_TEXTURE_UNITS];
+// uniform LOWP int gcu_CullFace;
+
+#endif // uniforms_glsl
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl
new file mode 100644
index 000000000..e70c25266
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl
@@ -0,0 +1,13 @@
+
+#ifndef varyings_glsl
+#define varyings_glsl
+
+#include precision.glsl
+
+#include consts.glsl
+
+varying vec4 gcv_FrontColor;
+varying vec2 gcv_TexCoord;
+
+#endif // varyings_glsl
+
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java
index 5dae296e5..a0d1923a9 100644
--- a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java
+++ b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java
@@ -33,49 +33,49 @@ import com.jogamp.graph.geom.Outline;
import com.jogamp.graph.geom.Vertex;
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));
- }
- }
+ 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 Outline getOutline() {
- return outline;
- }
+ public Outline getOutline() {
+ return outline;
+ }
- /*public void setOutline(Outline<T> outline) {
- this.outline = outline;
- }*/
-
+ /*public void setOutline(Outline<T> outline) {
+ this.outline = outline;
+ }*/
+
- public ArrayList<GraphVertex> getGraphPoint() {
- return controlpoints;
- }
-
- public ArrayList<Vertex> getPoints() {
- return outline.getVertices();
- }
+ public ArrayList<GraphVertex> getGraphPoint() {
+ return controlpoints;
+ }
+
+ public ArrayList<Vertex> getPoints() {
+ return outline.getVertices();
+ }
- /*public void setControlpoints(ArrayList<GraphPoint<T>> controlpoints) {
- this.controlpoints = controlpoints;
- }*/
+ /*public void setControlpoints(ArrayList<GraphPoint<T>> controlpoints) {
+ this.controlpoints = controlpoints;
+ }*/
- public void addVertex(GraphVertex v) {
- controlpoints.add(v);
- outline.addVertex(v.getPoint());
- }
-
+ public void addVertex(GraphVertex v) {
+ controlpoints.add(v);
+ outline.addVertex(v.getPoint());
+ }
+
}
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java b/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java
index b9f95a0e7..5efe57c28 100644
--- a/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java
+++ b/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java
@@ -32,89 +32,89 @@ 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;
- }
+ 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 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 void setPoint(Vertex point) {
+ this.point = point;
+ }
- public ArrayList<HEdge> getEdges() {
- return edges;
- }
+ 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 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;
- }
+ public void setBoundaryContained(boolean boundaryContained) {
+ this.boundaryContained = boundaryContained;
+ }
}
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/HEdge.java b/src/jogl/classes/jogamp/graph/curve/tess/HEdge.java
index d1bcc6e17..4d29a81f3 100644
--- a/src/jogl/classes/jogamp/graph/curve/tess/HEdge.java
+++ b/src/jogl/classes/jogamp/graph/curve/tess/HEdge.java
@@ -32,99 +32,99 @@ 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();
- }
-
+ 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/jogl/classes/jogamp/graph/curve/tess/Loop.java b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java
index fd7736a20..9e29d3973 100644
--- a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java
+++ b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java
@@ -36,338 +36,338 @@ 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;
- }
+ 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/jogl/classes/jogamp/graph/curve/text/GlyphShape.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java
index 36ba57244..4d1880064 100644
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java
+++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java
@@ -38,124 +38,124 @@ 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);
+
+ 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);
+ 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(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 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);
- }
+ 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();
- }
+ /** Get the list of Vertices of this Object
+ * @return arrayList of Vertices
+ */
+ public ArrayList<Vertex> getVertices(){
+ return shape.getVertices();
+ }
}
diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
index 808e3a415..1faee87ff 100644
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
+++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
@@ -29,11 +29,13 @@ package jogamp.graph.curve.text;
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.geom.Vertex.Factory;
import com.jogamp.graph.geom.opengl.SVertex;
-import javax.media.opengl.GLContext;
+import javax.media.opengl.GL2ES2;
import jogamp.graph.geom.plane.AffineTransform;
import jogamp.graph.geom.plane.Path2D;
@@ -42,122 +44,124 @@ 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.graph.curve.opengl.RenderState;
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();
+ 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;
- }
+ /** 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(String fontname, String str){
+ this.fontname = fontname;
+ this.str = str;
+ }
+
+ 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();
- }
+ /** Creates the Curve based Glyphs from a Font
+ * @param pointFactory TODO
+ * @param paths a list of FontPath2D objects that define the outline
+ * @param affineTransform a global affine transformation applied to the paths.
+ */
+ public void createfromFontPath(Factory<? extends Vertex> pointFactory, 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(GL2ES2 gl, RenderState rs, int type){
+ region = RegionFactory.create(rs, type);
+ region.setFlipped(true);
+
+ ArrayList<Triangle> tris = initializeTriangles(rs.getSharpness().floatValue());
+ 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(gl);
+ }
+
+ /** 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;
- }
+ /** Render the Object based using the associated Region
+ * previously generated.
+ */
+ public void renderString3D(GL2ES2 gl) {
+ region.render(gl, null, 0, 0, 0);
+ }
+ /** Render the Object based using the associated Region
+ * previously generated.
+ */
+ public void renderString3D(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int size) {
+ region.render(gl, rs, vp_width, vp_height, size);
+ }
+
+ /** Get the Origin of this GlyphString
+ * @return
+ */
+ public Vertex getOrigin() {
+ return origin;
+ }
- /** Destroy the associated OGL objects
- */
- public void destroy(){
- region.destroy();
- }
+ /** Destroy the associated OGL objects
+ * @param rs TODO
+ */
+ public void destroy(GL2ES2 gl, RenderState rs){
+ region.destroy(gl, rs);
+ }
+
+ public AABBox getBounds(){
+ return region.getBounds();
+ }
}
diff --git a/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java b/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java
index a9ab902a9..bead9a5d2 100644
--- a/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java
+++ b/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java
@@ -74,7 +74,7 @@ public class JavaFontLoader implements FontSet {
return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular
}
- public Font get(int family, int style) {
+ public Font get(int family, int style) {
Font font = (Font)fontMap.get( ( family << 8 ) | style );
if (font != null) {
return font;
@@ -121,7 +121,7 @@ public class JavaFontLoader implements FontSet {
return font;
}
-
+
Font abspath(String fname, int family, int style) {
final String err = "Problem loading font "+fname+", file "+javaFontPath+fname ;
diff --git a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java
index 3614add5c..31990af37 100644
--- a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java
+++ b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java
@@ -58,9 +58,7 @@ public class UbuntuFontLoader implements FontSet {
};
- final static String relPath = "fonts/ubuntu/" ;
- // debug final static String relPath = "/usr/local/projects/JOGL/jogl/src/jogl/classes/jogamp/graph/font/fonts/ubuntu/" ;
-
+ final static String relPath = "fonts/ubuntu/" ;
private UbuntuFontLoader() {
}
@@ -76,8 +74,8 @@ public class UbuntuFontLoader implements FontSet {
return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular
}
- public Font get(int family, int style)
- {
+ public Font get(int family, int style)
+ {
Font font = (Font)fontMap.get( ( family << 8 ) | style );
if (font != null) {
return font;
@@ -119,7 +117,7 @@ public class UbuntuFontLoader implements FontSet {
return font;
}
-
+
Font abspath(String fname, int family, int style) {
final String err = "Problem loading font "+fname+", stream "+relPath+fname;
try {
@@ -136,5 +134,5 @@ public class UbuntuFontLoader implements FontSet {
} catch(IOException ioe) {
throw new GLException(err, ioe);
}
- }
+ }
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
index f702b981f..6292c8826 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
@@ -43,97 +43,97 @@ import com.jogamp.graph.font.FontFactory;
import com.jogamp.graph.geom.AABBox;
class TypecastFont implements FontInt {
- static final boolean DEBUG = false;
-
- final OTFontCollection fontset;
- final OTFont font;
+ 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 ??
+ int cmapentries;
+
+ // FIXME: Add cache size to limit memory usage ??
IntObjectHashMap char2Glyph;
public TypecastFont(OTFontCollection fontset) {
- this.fontset = 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();
+ 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();
+ 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( _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) {
+ } 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 ?
+ _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);
- }
+ }
+ 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;
+ 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());
+ 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);
- }
+ final int code = cmapFormat.mapCharCode(j);
+ if(code < 15) {
+ System.err.println(" char: " + (int)j + " ( " + (char)j +" ) -> " + code);
+ }
}
}
}
@@ -155,9 +155,9 @@ class TypecastFont implements FontInt {
}
public Glyph getGlyph(char symbol) {
- TypecastGlyph result = (TypecastGlyph) char2Glyph.get(symbol);
+ TypecastGlyph result = (TypecastGlyph) char2Glyph.get(symbol);
if (null == result) {
- // final short code = (short) char2Code.get(symbol);
+ // final short code = (short) char2Code.get(symbol);
short code = (short) cmapFormat.mapCharCode(symbol);
if(0 == code && 0 != symbol) {
// reserved special glyph IDs by convention
@@ -168,19 +168,19 @@ class TypecastFont implements FontInt {
}
}
- jogamp.graph.font.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();
+ jogamp.graph.font.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);
@@ -193,14 +193,14 @@ class TypecastFont implements FontInt {
System.err.println("hdmx advance : pixelsize = "+dr.getWidth(code)+" : "+ dr.getPixelSize());
}
}
- }
- char2Glyph.put(symbol, result);
+ }
+ char2Glyph.put(symbol, result);
}
return result;
}
public void getOutline(String string, float pixelSize, AffineTransform transform, Path2D[] result) {
- TypecastRenderer.getOutline(this, string, pixelSize, transform, result);
+ TypecastRenderer.getOutline(this, string, pixelSize, transform, result);
}
public float getStringWidth(String string, float pixelSize) {
@@ -217,7 +217,7 @@ class TypecastFont implements FontInt {
}
}
- return (int)(width + 0.5f);
+ return (int)(width + 0.5f);
}
public float getStringHeight(String string, float pixelSize) {
@@ -233,7 +233,7 @@ class TypecastFont implements FontInt {
height = (int)Math.ceil(Math.max(bbox.getHeight(), height));
}
}
- return height;
+ return height;
}
public AABBox getStringBounds(CharSequence string, float pixelSize) {
@@ -263,11 +263,11 @@ class TypecastFont implements FontInt {
totalHeight -= advanceY;
totalWidth = Math.max(curLineWidth, totalWidth);
}
- return new AABBox(0, 0, 0, totalWidth, totalHeight,0);
+ return new AABBox(0, 0, 0, totalWidth, totalHeight,0);
}
final public int getNumGlyphs() {
- return font.getNumGlyphs();
+ return font.getNumGlyphs();
}
public boolean isPrintableChar( char c ) {
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
index 88d865f9c..f20b7d1e7 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
@@ -42,7 +42,7 @@ public class TypecastGlyph implements FontInt.Glyph {
final Font font;
final float advance;
HashMap<Float, Float> size2advance = new HashMap<Float, Float>();
-
+
public Advance(Font font, float advance)
{
this.font = font;
@@ -86,12 +86,12 @@ public class TypecastGlyph implements FontInt.Glyph {
"\n advances: \n"+size2advance;
}
}
-
+
public class Metrics
{
- AABBox bbox;
+ AABBox bbox;
Advance advance;
-
+
public Metrics(Font font, AABBox bbox, float advance)
{
this.bbox = bbox;
@@ -128,13 +128,13 @@ public class TypecastGlyph implements FontInt.Glyph {
"\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;
@@ -143,15 +143,15 @@ public class TypecastGlyph implements FontInt.Glyph {
protected Path2D path; // in EM units
protected Path2D pathSized;
protected float numberSized;
-
+
protected TypecastGlyph(Font font, char symbol) {
- this.font = font;
+ this.font = font;
this.symbol = symbol;
}
protected TypecastGlyph(Font font,
- char symbol, short id, AABBox bbox, int advance, Path2D path) {
- this.font = font;
+ char symbol, short id, AABBox bbox, int advance, Path2D path) {
+ this.font = font;
this.symbol = symbol;
this.advance = advance;
@@ -161,7 +161,7 @@ public class TypecastGlyph implements FontInt.Glyph {
this.pathSized = null;
this.numberSized = 0.0f;
}
-
+
void init(short id, AABBox bbox, int advance) {
this.id = id;
this.advance = advance;
@@ -176,11 +176,11 @@ public class TypecastGlyph implements FontInt.Glyph {
public Font getFont() {
return this.font;
}
-
+
public char getSymbol() {
return this.symbol;
}
-
+
AABBox getBBoxUnsized() {
return this.metrics.getBBox();
}
@@ -192,22 +192,22 @@ public class TypecastGlyph implements FontInt.Glyph {
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);
}
@@ -217,9 +217,9 @@ public class TypecastGlyph implements FontInt.Glyph {
}
public Path2D getPath() {
- return this.path;
+ return this.path;
}
-
+
public Path2D getPath(float pixelSize) {
final float size = getScale(pixelSize);
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
index a69948006..0dd7a6178 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
@@ -34,22 +34,22 @@ import com.jogamp.graph.font.Font.Metrics;
import com.jogamp.graph.geom.AABBox;
class TypecastHMetrics implements Metrics {
- private final TypecastFont fontImpl;
-
- // HeadTable
+ private final TypecastFont fontImpl;
+
+ // HeadTable
private final HeadTable headTable;
- private final float unitsPerEM_Inv;
- private final AABBox bbox;
- // HheaTable
- private final HheaTable hheaTable;
+ 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();
+
+ 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();
@@ -59,8 +59,8 @@ class TypecastHMetrics implements Metrics {
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
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
index 9a81d78d3..ab5e673db 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
@@ -40,48 +40,48 @@ import com.jogamp.graph.font.Font;
*/
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();
+ 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);
+ 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);
- }
- }
-
+ 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 jogamp.graph.font.typecast.ot.OTGlyph Glyph}. This glyph path can then
@@ -116,44 +116,44 @@ public class TypecastRenderer {
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)
+ 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++;
- }
- }
+
+ 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++;
+ }
+ }
}
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java
index 5afb939ab..6b3dc1f6f 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java
@@ -72,9 +72,9 @@ public class Mnemonic {
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 GC = 0x46; // [a]
public static final short SCFS = 0x48;
- public static final short MD = 0x49; // [a]
+ 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;
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java
index 17b5af594..6e7e76bc7 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java
@@ -182,8 +182,8 @@ public class OTFont {
}
public OTGlyph getGlyph(int i) {
-
- final GlyfDescript _glyfDescr = _glyf.getDescription(i);
+
+ final GlyfDescript _glyfDescr = _glyf.getDescription(i);
return (null != _glyfDescr)
? new OTGlyph(
_glyfDescr,
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java
index 4b6242d56..5c004246a 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java
@@ -103,7 +103,7 @@ public class OTGlyph {
}
public AABBox getBBox() {
- return _bbox;
+ return _bbox;
}
public int getAdvanceWidth() {
@@ -164,6 +164,6 @@ public class OTGlyph {
// _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);
+ _bbox = new AABBox(gd.getXMinimum(), gd.getYMinimum(), 0, gd.getXMaximum(), gd.getYMaximum(), 0);
}
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PostTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PostTable.java
index ed82f2654..4804c35f2 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PostTable.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PostTable.java
@@ -175,15 +175,15 @@ public class PostTable implements Table {
"lessequal", // 148
"greaterequal", // 149
"yen", // 150
- "mu", // 151
+ "mu", // 151
"partialdiff", // 152
"summation", // 153
"product", // 154
- "pi", // 155
+ "pi", // 155
"integral'", // 156
"ordfeminine", // 157
"ordmasculine", // 158
- "Omega", // 159
+ "Omega", // 159
"ae", // 160
"oslash", // 161
"questiondown", // 162
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Interpreter.java b/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Interpreter.java
index 252c6acc4..a659a7003 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Interpreter.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Interpreter.java
@@ -140,8 +140,8 @@ public class Interpreter {
private void _deltac1() {
int n = pop();
for (int i = 0; i < n; i++) {
- pop(); // pn
- pop(); // argn
+ pop(); // pn
+ pop(); // argn
}
}
@@ -151,8 +151,8 @@ public class Interpreter {
private void _deltac2() {
int n = pop();
for (int i = 0; i < n; i++) {
- pop(); // pn
- pop(); // argn
+ pop(); // pn
+ pop(); // argn
}
}
@@ -162,8 +162,8 @@ public class Interpreter {
private void _deltac3() {
int n = pop();
for (int i = 0; i < n; i++) {
- pop(); // pn
- pop(); // argn
+ pop(); // pn
+ pop(); // argn
}
}
@@ -173,8 +173,8 @@ public class Interpreter {
private void _deltap1() {
int n = pop();
for (int i = 0; i < n; i++) {
- pop(); // pn
- pop(); // argn
+ pop(); // pn
+ pop(); // argn
}
}
@@ -184,8 +184,8 @@ public class Interpreter {
private void _deltap2() {
int n = pop();
for (int i = 0; i < n; i++) {
- pop(); // pn
- pop(); // argn
+ pop(); // pn
+ pop(); // argn
}
}
@@ -195,8 +195,8 @@ public class Interpreter {
private void _deltap3() {
int n = pop();
for (int i = 0; i < n; i++) {
- pop(); // pn
- pop(); // argn
+ pop(); // pn
+ pop(); // argn
}
}
@@ -407,12 +407,12 @@ public class Interpreter {
* 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
+ * 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
@@ -923,8 +923,8 @@ public class Interpreter {
* Set Freedom_Vector From Stack
*/
private void _sfvfs() {
- gs.freedom_vector[1] = pop(); // y
- gs.freedom_vector[0] = pop(); // x
+ gs.freedom_vector[1] = pop(); // y
+ gs.freedom_vector[0] = pop(); // x
}
/*
@@ -988,9 +988,9 @@ public class Interpreter {
* USES: loop
*/
private void _shpix() {
- pop(); // amount
+ pop(); // amount
while (gs.loop-- > 0) {
- pop(); // p
+ pop(); // p
}
gs.loop = 1;
}
@@ -1017,8 +1017,8 @@ public class Interpreter {
* Set Projection_Vector From Stack
*/
private void _spvfs() {
- gs.projection_vector[1] = pop(); // y
- gs.projection_vector[0] = pop(); // x
+ gs.projection_vector[1] = pop(); // y
+ gs.projection_vector[0] = pop(); // x
}
/*
diff --git a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
index 3e2a594c5..79e842887 100644
--- a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
+++ b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
@@ -80,14 +80,14 @@ public class AffineTransform implements Cloneable, Serializable {
}
public AffineTransform(Factory<? extends Vertex> factory) {
- pointFactory = 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.pointFactory = t.pointFactory;
this.type = t.type;
this.m00 = t.m00;
this.m10 = t.m10;
@@ -98,7 +98,7 @@ public class AffineTransform implements Cloneable, Serializable {
}
public AffineTransform(Vertex.Factory<? extends Vertex> factory, float m00, float m10, float m01, float m11, float m02, float m12) {
- pointFactory = factory;
+ pointFactory = factory;
this.type = TYPE_UNKNOWN;
this.m00 = m00;
this.m10 = m10;
@@ -109,7 +109,7 @@ public class AffineTransform implements Cloneable, Serializable {
}
public AffineTransform(Vertex.Factory<? extends Vertex> factory, float[] matrix) {
- pointFactory = factory;
+ pointFactory = factory;
this.type = TYPE_UNKNOWN;
m00 = matrix[0];
m10 = matrix[1];
@@ -316,25 +316,25 @@ public class AffineTransform implements Cloneable, Serializable {
}
public static <T extends Vertex> AffineTransform getScaleInstance(Vertex.Factory<? extends Vertex> factory, float scx, float scY) {
- AffineTransform t = new AffineTransform(factory);
+ 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);
+ 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);
+ 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);
+ AffineTransform t = new AffineTransform(factory);
t.setToRotation(angle, x, y);
return t;
}
@@ -391,7 +391,7 @@ public class AffineTransform implements Cloneable, Serializable {
throw new NoninvertibleTransformException(determinantIsZero);
}
return new AffineTransform(
- this.pointFactory,
+ this.pointFactory,
m11 / det, // m00
-m10 / det, // m10
-m01 / det, // m01
@@ -401,9 +401,9 @@ public class AffineTransform implements Cloneable, Serializable {
);
}
- public Vertex transform(Vertex src, Vertex dst) {
+ public Vertex transform(Vertex src, Vertex dst) {
if (dst == null) {
- dst = pointFactory.create();
+ dst = pointFactory.create();
}
float x = src.getX();
@@ -415,12 +415,12 @@ public class AffineTransform implements Cloneable, Serializable {
public void transform(Vertex[] src, int srcOff, Vertex[] dst, int dstOff, int length) {
while (--length >= 0) {
- Vertex srcPoint = src[srcOff++];
+ 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");
+ throw new IllegalArgumentException("dst["+dstOff+"] is null");
}
dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12);
dst[dstOff++] = dstPoint;
@@ -444,9 +444,9 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
- public Vertex deltaTransform(Vertex src, Vertex dst) {
+ public Vertex deltaTransform(Vertex src, Vertex dst) {
if (dst == null) {
- dst = pointFactory.create();
+ dst = pointFactory.create();
}
float x = src.getX();
@@ -465,13 +465,13 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
- public Vertex inverseTransform(Vertex src, Vertex dst) throws NoninvertibleTransformException {
+ public Vertex inverseTransform(Vertex src, Vertex dst) throws NoninvertibleTransformException {
float det = getDeterminant();
if (MathFloat.abs(det) < ZERO) {
- throw new NoninvertibleTransformException(determinantIsZero);
+ throw new NoninvertibleTransformException(determinantIsZero);
}
if (dst == null) {
- dst = pointFactory.create();
+ dst = pointFactory.create();
}
float x = src.getX() - m02;
@@ -486,7 +486,7 @@ public class AffineTransform implements Cloneable, Serializable {
{
float det = getDeterminant();
if (MathFloat.abs(det) < ZERO) {
- throw new NoninvertibleTransformException(determinantIsZero);
+ throw new NoninvertibleTransformException(determinantIsZero);
}
while (--length >= 0) {
diff --git a/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java b/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java
index 431891361..edeabaa40 100644
--- a/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java
+++ b/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java
@@ -243,11 +243,11 @@ public final class Path2D implements Cloneable {
}
final public int size() {
- return typeSize;
+ return typeSize;
}
final public boolean isClosed() {
- return typeSize > 0 && types[typeSize - 1] == PathIterator.SEG_CLOSE ;
+ return typeSize > 0 && types[typeSize - 1] == PathIterator.SEG_CLOSE ;
}
public void closePath() {
@@ -258,7 +258,7 @@ public final class Path2D implements Cloneable {
}
public String toString() {
- return "[size "+size()+", closed "+isClosed()+"]";
+ return "[size "+size()+", closed "+isClosed()+"]";
}
public void append(Path2D path, boolean connect) {
diff --git a/src/jogl/classes/jogamp/graph/math/plane/Crossing.java b/src/jogl/classes/jogamp/graph/math/plane/Crossing.java
index 8f8638632..2138b217d 100644
--- a/src/jogl/classes/jogamp/graph/math/plane/Crossing.java
+++ b/src/jogl/classes/jogamp/graph/math/plane/Crossing.java
@@ -385,12 +385,12 @@ public class Crossing {
// START
if (x == x1) {
- return x1 < x2 ? 0 : -1;
+ return x1 < x2 ? 0 : -1;
}
// END
if (x == x2) {
- return x1 < x2 ? 1 : 0;
+ return x1 < x2 ? 1 : 0;
}
// INSIDE-DOWN
@@ -496,9 +496,9 @@ public class Crossing {
// checks if the point (x,y) is the vertex of shape with PathIterator p
if (x == cx && y == cy) {
- cross = 0;
- cy = my;
- break;
+ cross = 0;
+ cy = my;
+ break;
}
p.next();
}
diff --git a/src/jogl/classes/jogamp/opengl/FPSCounterImpl.java b/src/jogl/classes/jogamp/opengl/FPSCounterImpl.java
new file mode 100644
index 000000000..96d62fbb3
--- /dev/null
+++ b/src/jogl/classes/jogamp/opengl/FPSCounterImpl.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 jogamp.opengl;
+
+import java.io.PrintStream;
+import javax.media.opengl.FPSCounter;
+
+/**
+ * Default implementation of FPSCounter to be used for FPSCounter implementing renderer.
+ */
+public class FPSCounterImpl implements FPSCounter {
+ private int fpsUpdateFramesInterval;
+ private PrintStream fpsOutputStream ;
+ private long fpsStartTime, fpsLastUpdateTime, fpsLastPeriod, fpsTotalDuration;
+ private int fpsTotalFrames;
+ private float fpsLast, fpsTotal;
+
+ /** Creates a disabled instance */
+ public FPSCounterImpl() {
+ setUpdateFPSFrames(0, null);
+ }
+
+ /**
+ * Increases total frame count and updates values if feature is enabled and
+ * update interval is reached.<br>
+ *
+ * Shall be called by actual FPSCounter implementing renderer, after display a new frame.
+ *
+ */
+ public final synchronized void tickFPS() {
+ fpsTotalFrames++;
+ if(fpsUpdateFramesInterval>0 && fpsTotalFrames%fpsUpdateFramesInterval == 0) {
+ final long now = System.currentTimeMillis();
+ fpsLastPeriod = now - fpsLastUpdateTime;
+ fpsLastPeriod = Math.max(fpsLastPeriod, 1); // div 0
+ fpsLast = ( (float)fpsUpdateFramesInterval * 1000f ) / ( (float) fpsLastPeriod ) ;
+
+ fpsTotalDuration = now - fpsStartTime;
+ fpsTotalDuration = Math.max(fpsTotalDuration, 1); // div 0
+ fpsTotal= ( (float)fpsTotalFrames * 1000f ) / ( (float) fpsTotalDuration ) ;
+
+ if(null != fpsOutputStream) {
+ fpsOutputStream.println(toString());
+ }
+
+ fpsLastUpdateTime = now;
+ }
+ }
+
+ public StringBuilder toString(StringBuilder sb) {
+ if(null==sb) {
+ sb = new StringBuilder();
+ }
+ String fpsLastS = String.valueOf(fpsLast);
+ fpsLastS = fpsLastS.substring(0, fpsLastS.indexOf('.') + 2);
+ String fpsTotalS = String.valueOf(fpsTotal);
+ fpsTotalS = fpsTotalS.substring(0, fpsTotalS.indexOf('.') + 2);
+ sb.append(fpsTotalDuration/1000 +" s: "+ fpsUpdateFramesInterval+" f / "+ fpsLastPeriod+" ms, " + fpsLastS+" fps, "+ fpsLastPeriod/fpsUpdateFramesInterval+" ms/f; "+
+ "total: "+ fpsTotalFrames+" f, "+ fpsTotalS+ " fps, "+ fpsTotalDuration/fpsTotalFrames+" ms/f");
+ return sb;
+ }
+
+ public String toString() {
+ return toString(null).toString();
+ }
+
+ public final synchronized void setUpdateFPSFrames(int frames, PrintStream out) {
+ fpsUpdateFramesInterval = frames;
+ fpsOutputStream = out;
+ resetFPSCounter();
+ }
+
+ public final synchronized void resetFPSCounter() {
+ fpsStartTime = System.currentTimeMillis(); // overwrite startTime to real init one
+ fpsLastUpdateTime = fpsStartTime;
+ fpsLastPeriod = 0;
+ fpsTotalFrames = 0;
+ fpsLast = 0f; fpsTotal = 0f;
+ }
+
+ public final synchronized int getUpdateFPSFrames() {
+ return fpsUpdateFramesInterval;
+ }
+
+ public final synchronized long getFPSStartTime() {
+ return fpsStartTime;
+ }
+
+ public final synchronized long getLastFPSUpdateTime() {
+ return fpsLastUpdateTime;
+ }
+
+ public final synchronized long getLastFPSPeriod() {
+ return fpsLastPeriod;
+ }
+
+ public final synchronized float getLastFPS() {
+ return fpsLast;
+ }
+
+ public final synchronized int getTotalFPSFrames() {
+ return fpsTotalFrames;
+ }
+
+ public final synchronized long getTotalFPSDuration() {
+ return fpsTotalDuration;
+ }
+
+ public final synchronized float getTotalFPS() {
+ return fpsTotal;
+ }
+}
diff --git a/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java b/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java
index 15e3affee..fc8be95e9 100644
--- a/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java
+++ b/src/jogl/classes/jogamp/opengl/GLBufferSizeTracker.java
@@ -107,17 +107,7 @@ public class GLBufferSizeTracker {
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));
- }
+ if (buffer != 0) {
setDirectStateBufferSize(buffer, caller, size);
}
// We don't know the current buffer state. Note that the buffer
@@ -135,18 +125,8 @@ public class GLBufferSizeTracker {
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));
- }
+ final int buffer = bufferStateTracker.getBoundBufferObject(target, caller);
+ if (0 != buffer) {
return getBufferSizeImpl(target, buffer, caller);
}
// We don't know what's going on in this case; query the GL for an answer
diff --git a/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java b/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java
index d028bf98d..5a31431d8 100644
--- a/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java
+++ b/src/jogl/classes/jogamp/opengl/GLBufferStateTracker.java
@@ -136,14 +136,6 @@ public class GLBufferStateTracker {
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
diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
index 9361fb0f9..6128b30b4 100644
--- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
@@ -41,11 +41,13 @@
package jogamp.opengl;
import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.Map;
import com.jogamp.common.os.DynamicLookupHelper;
import com.jogamp.common.util.ReflectionUtil;
+import com.jogamp.common.util.locks.RecursiveLock;
import com.jogamp.gluegen.runtime.FunctionAddressResolver;
import com.jogamp.gluegen.runtime.ProcAddressTable;
import com.jogamp.gluegen.runtime.opengl.GLExtensionNames;
@@ -57,6 +59,8 @@ import javax.media.nativewindow.NativeSurface;
import javax.media.opengl.GL;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDebugListener;
+import javax.media.opengl.GLDebugMessage;
import javax.media.opengl.GLDrawable;
import javax.media.opengl.GLException;
import javax.media.opengl.GLPipelineFactory;
@@ -65,7 +69,8 @@ import javax.media.opengl.GLProfile;
public abstract class GLContextImpl extends GLContext {
public static final boolean DEBUG = Debug.debug("GLContext");
- protected GLContextLock lock = new GLContextLock();
+ // RecursiveLock maintains a queue of waiting Threads, ensuring the longest waiting thread will be notified at unlock.
+ protected RecursiveLock lock = new RecursiveLock();
/**
* Context full qualified name: display_type + display_connection + major + minor + ctp.
@@ -73,6 +78,8 @@ public abstract class GLContextImpl extends GLContext {
*/
private String contextFQN;
+ private int additionalCtxCreationFlags;
+
// Cache of the functions that are available to be called at the current
// moment in time
protected ExtensionAvailabilityCache extensionAvailability;
@@ -85,22 +92,23 @@ public abstract class GLContextImpl extends GLContext {
private GLBufferSizeTracker bufferSizeTracker; // Singleton - Set by GLContextShareSet
private GLBufferStateTracker bufferStateTracker = new GLBufferStateTracker();
private GLStateTracker glStateTracker = new GLStateTracker();
-
+ private GLDebugMessageHandler glDebugHandler = null;
+
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;
+ protected static final HashMap<String, ExtensionAvailabilityCache> mappedExtensionAvailabilityCache;
+ protected static final HashMap<String, ProcAddressTable> mappedGLProcAddress;
+ protected static final HashMap<String, ProcAddressTable> mappedGLXProcAddress;
static {
mappedContextTypeObjectLock = new Object();
- mappedExtensionAvailabilityCache = new HashMap();
- mappedGLProcAddress = new HashMap();
- mappedGLXProcAddress = new HashMap();
+ mappedExtensionAvailabilityCache = new HashMap<String, ExtensionAvailabilityCache>();
+ mappedGLProcAddress = new HashMap<String, ProcAddressTable>();
+ mappedGLXProcAddress = new HashMap<String, ProcAddressTable>();
}
public GLContextImpl(GLDrawableImpl drawable, GLContext shareWith) {
@@ -113,6 +121,8 @@ public abstract class GLContextImpl extends GLContext {
this.drawable = drawable;
this.drawableRead = drawable;
+
+ this.glDebugHandler = new GLDebugMessageHandler(this);
}
protected void resetStates() {
@@ -137,6 +147,7 @@ public abstract class GLContextImpl extends GLContext {
glProcAddressTable = null;
gl = null;
contextFQN = null;
+ additionalCtxCreationFlags = 0;
super.resetStates();
}
@@ -145,7 +156,7 @@ public abstract class GLContextImpl extends GLContext {
if(null!=read && drawable!=read && !isGLReadDrawableAvailable()) {
throw new GLException("GL Read Drawable not available");
}
- boolean lockHeld = lock.isHeld();
+ boolean lockHeld = lock.isOwner();
if(lockHeld) {
release();
}
@@ -185,19 +196,36 @@ public abstract class GLContextImpl extends GLContext {
// This is only needed for Mac OS X on-screen contexts
protected void update() throws GLException { }
+ boolean lockFailFast = true;
+ Object lockFailFastSync = new Object();
+
public boolean isSynchronized() {
- return !lock.getFailFastMode();
+ synchronized (lockFailFastSync) {
+ return !lockFailFast;
+ }
}
public void setSynchronized(boolean isSynchronized) {
- lock.setFailFastMode(!isSynchronized);
+ synchronized (lockFailFastSync) {
+ lockFailFast = !isSynchronized;
+ }
}
+ private final void lockConsiderFailFast() {
+ synchronized (lockFailFastSync) {
+ if(lockFailFast && lock.isLockedByOtherThread()) {
+ throw new GLException("Error: Attempt to make context current on thread " + Thread.currentThread() +
+ " which is already current on thread " + lock.getOwner());
+ }
+ }
+ lock.lock();
+ }
+
public abstract Object getPlatformGLExtensions();
// Note: the surface is locked within [makeCurrent .. swap .. release]
public void release() throws GLException {
- if (!lock.isHeld()) {
+ if ( !lock.isOwner() ) {
throw new GLException("Context not current on current thread");
}
setCurrent(null);
@@ -213,14 +241,17 @@ public abstract class GLContextImpl extends GLContext {
protected abstract void releaseImpl() throws GLException;
public final void destroy() {
- if (lock.isHeld()) {
- // release current context
+ if ( lock.isOwner() ) {
+ // release current context
+ if(null != glDebugHandler) {
+ glDebugHandler.enable(false);
+ }
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();
+ lockConsiderFailFast();
try {
/* FIXME: refactor dependence on Java 2D / JOGL bridge
if (tracker != null) {
@@ -248,6 +279,7 @@ public abstract class GLContextImpl extends GLContext {
try {
destroyImpl();
contextHandle = 0;
+ glDebugHandler = null;
GLContextShareSet.contextDestroyed(this);
} finally {
drawable.unlockSurface();
@@ -345,9 +377,10 @@ public abstract class GLContextImpl extends GLContext {
if (null == getGLDrawable().getChosenGLCapabilities()) {
throw new GLException("drawable has no chosen GLCapabilities: "+getGLDrawable());
}
+ additionalCtxCreationFlags |= DEBUG_GL ? GLContext.CTX_OPTION_DEBUG : 0 ;
}
- lock.lock();
+ lockConsiderFailFast();
int res = 0;
try {
res = makeCurrentLocking();
@@ -366,6 +399,7 @@ public abstract class GLContextImpl extends GLContext {
if (res == CONTEXT_NOT_CURRENT) {
lock.unlock();
} else {
+ setCurrent(this);
if(res == CONTEXT_CURRENT_NEW) {
// check if the drawable's and the GL's GLProfile are equal
// throws an GLException if not
@@ -373,12 +407,13 @@ public abstract class GLContextImpl extends GLContext {
if(DEBUG_GL) {
gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, gl, null) );
+ glDebugHandler.addListener(new GLDebugMessageHandler.StdErrGLDebugListener());
}
if(TRACE_GL) {
gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, gl, new Object[] { System.err } ) );
}
+ glDebugHandler.init(0 != (additionalCtxCreationFlags & GLContext.CTX_OPTION_DEBUG));
}
- setCurrent(this);
/* FIXME: refactor dependence on Java 2D / JOGL bridge
@@ -501,13 +536,13 @@ public abstract class GLContextImpl extends GLContext {
* @see #createContextARBImpl
* @see #destroyContextARBImpl
*/
- protected final long createContextARB(long share, boolean direct,
- int major[], int minor[], int ctp[])
+ protected final long createContextARB(long share, boolean direct)
{
AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
AbstractGraphicsDevice device = config.getScreen().getDevice();
GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
GLProfile glp = glCaps.getGLProfile();
+ GLProfile glpImpl = GLProfile.get(glp.getImplName());
if (DEBUG) {
System.err.println(getThreadName() + ": !!! createContextARB: mappedVersionsAvailableSet("+device.getConnection()+"): "+
@@ -519,15 +554,15 @@ public abstract class GLContextImpl extends GLContext {
}
int reqMajor;
- if(glp.isGL4()) {
+ if(glpImpl.isGL4()) {
reqMajor=4;
- } else if (glp.isGL3()) {
+ } else if (glpImpl.isGL3()) {
reqMajor=3;
- } else /* if (glp.isGL2()) */ {
+ } else /* if (glpImpl.isGL2()) */ {
reqMajor=2;
}
- boolean compat = glp.isGL2(); // incl GL3bc and GL4bc
+ boolean compat = glpImpl.isGL2(); // incl GL3bc and GL4bc
int _major[] = { 0 };
int _minor[] = { 0 };
int _ctp[] = { 0 };
@@ -535,6 +570,7 @@ public abstract class GLContextImpl extends GLContext {
if( GLContext.getAvailableGLVersion(device, reqMajor, compat?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE,
_major, _minor, _ctp)) {
+ _ctp[0] |= additionalCtxCreationFlags;
_ctx = createContextARBImpl(share, direct, _ctp[0], _major[0], _minor[0]);
if(0!=_ctx) {
setGLFunctionAvailability(true, _major[0], _minor[0], _ctp[0]);
@@ -545,17 +581,16 @@ public abstract class GLContextImpl extends GLContext {
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(4, false /* core */); // GL4
createContextARBMapVersionsAvailable(3, true /* compat */); // GL3bc
+ createContextARBMapVersionsAvailable(3, false /* core */); // GL3
createContextARBMapVersionsAvailable(2, true /* compat */); // GL2
GLContext.setAvailableGLVersionsSet(device);
}
}
- private final void createContextARBMapVersionsAvailable(int reqMajor, boolean compat)
- {
+ private final void createContextARBMapVersionsAvailable(int reqMajor, boolean compat) {
resetStates();
long _context;
@@ -765,14 +800,14 @@ public abstract class GLContextImpl extends GLContext {
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;
+ Map<String, String> map = getFunctionNameMap();
+ String lookup = ( null != map ) ? map.get(glFunctionName) : null;
if (lookup != null) {
return lookup;
}
return glFunctionName;
}
- protected abstract Map/*<String, String>*/ getFunctionNameMap() ;
+ 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
@@ -780,14 +815,14 @@ public abstract class GLContextImpl extends GLContext {
"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;
+ Map<String, String> map = getExtensionNameMap();
+ String lookup = ( null != map ) ? map.get(glExtensionName) : null;
if (lookup != null) {
return lookup;
}
return glExtensionName;
}
- protected abstract Map/*<String, String>*/ getExtensionNameMap() ;
+ 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. */
@@ -841,7 +876,7 @@ public abstract class GLContextImpl extends GLContext {
ProcAddressTable table = null;
synchronized(mappedContextTypeObjectLock) {
- table = (ProcAddressTable) mappedGLProcAddress.get( contextFQN );
+ table = 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());
@@ -877,7 +912,7 @@ public abstract class GLContextImpl extends GLContext {
//
ExtensionAvailabilityCache eCache;
synchronized(mappedContextTypeObjectLock) {
- eCache = (ExtensionAvailabilityCache) mappedExtensionAvailabilityCache.get( contextFQN );
+ eCache = mappedExtensionAvailabilityCache.get( contextFQN );
}
if(null != eCache) {
extensionAvailability = eCache;
@@ -1046,7 +1081,78 @@ public abstract class GLContextImpl extends GLContext {
//
public boolean hasWaiters() {
- return lock.hasWaiters();
+ return lock.getWaitingThreadQueueSize()>0;
+ }
+
+ //---------------------------------------------------------------------------
+ // GL_ARB_debug_output, GL_AMD_debug_output helpers
+ //
+
+ public final String getGLDebugMessageExtension() {
+ return glDebugHandler.getExtension();
+ }
+
+ public final boolean isGLDebugMessageEnabled() {
+ return glDebugHandler.isEnabled();
+ }
+
+ public int getContextCreationFlags() {
+ return additionalCtxCreationFlags;
}
+ public void setContextCreationFlags(int flags) {
+ if(!isCreated()) {
+ additionalCtxCreationFlags = flags & GLContext.CTX_OPTION_DEBUG;
+ }
+ }
+
+ public void enableGLDebugMessage(boolean enable) throws GLException {
+ if(!isCreated()) {
+ if(enable) {
+ additionalCtxCreationFlags |= GLContext.CTX_OPTION_DEBUG;
+ } else {
+ additionalCtxCreationFlags &= ~GLContext.CTX_OPTION_DEBUG;
+ }
+ } else if(0 != (additionalCtxCreationFlags & GLContext.CTX_OPTION_DEBUG) &&
+ null != getGLDebugMessageExtension()) {
+ glDebugHandler.enable(enable);
+ }
+ }
+
+ public void addGLDebugListener(GLDebugListener listener) {
+ glDebugHandler.addListener(listener);
+ }
+
+ public void removeGLDebugListener(GLDebugListener listener) {
+ glDebugHandler.removeListener(listener);
+ }
+
+ public int getGLDebugListenerSize() {
+ return glDebugHandler.listenerSize();
+ }
+
+ public void glDebugMessageControl(int source, int type, int severity, int count, IntBuffer ids, boolean enabled) {
+ if(glDebugHandler.isExtensionARB()) {
+ gl.getGL2GL3().glDebugMessageControlARB(source, type, severity, count, ids, enabled);
+ } else if(glDebugHandler.isExtensionAMD()) {
+ gl.getGL2GL3().glDebugMessageEnableAMD(GLDebugMessage.translateARB2AMDCategory(source, type), severity, count, ids, enabled);
+ }
+ }
+
+ public void glDebugMessageControl(int source, int type, int severity, int count, int[] ids, int ids_offset, boolean enabled) {
+ if(glDebugHandler.isExtensionARB()) {
+ gl.getGL2GL3().glDebugMessageControlARB(source, type, severity, count, ids, ids_offset, enabled);
+ } else if(glDebugHandler.isExtensionAMD()) {
+ gl.getGL2GL3().glDebugMessageEnableAMD(GLDebugMessage.translateARB2AMDCategory(source, type), severity, count, ids, ids_offset, enabled);
+ }
+ }
+
+ public void glDebugMessageInsert(int source, int type, int id, int severity, int length, String buf) {
+ if(glDebugHandler.isExtensionARB()) {
+ gl.getGL2GL3().glDebugMessageInsertARB(source, type, id, severity, length, buf);
+ } else if(glDebugHandler.isExtensionAMD()) {
+ if(0>length) { length = 0; }
+ gl.getGL2GL3().glDebugMessageInsertAMD(GLDebugMessage.translateARB2AMDCategory(source, type), severity, id, length, buf);
+ }
+ }
}
diff --git a/src/jogl/classes/jogamp/opengl/GLContextLock.java b/src/jogl/classes/jogamp/opengl/GLContextLock.java
deleted file mode 100644
index f725508d8..000000000
--- a/src/jogl/classes/jogamp/opengl/GLContextLock.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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/GLDebugMessageHandler.java b/src/jogl/classes/jogamp/opengl/GLDebugMessageHandler.java
new file mode 100644
index 000000000..f67c916ea
--- /dev/null
+++ b/src/jogl/classes/jogamp/opengl/GLDebugMessageHandler.java
@@ -0,0 +1,266 @@
+/**
+ * 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.opengl;
+
+import java.util.ArrayList;
+
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GLDebugListener;
+import javax.media.opengl.GLDebugMessage;
+import javax.media.opengl.GLException;
+
+import com.jogamp.gluegen.runtime.ProcAddressTable;
+import jogamp.opengl.gl4.GL4bcProcAddressTable;
+
+/**
+ * The GLDebugMessageHandler, handling <i>GL_ARB_debug_output</i> or <i>GL_AMD_debug_output</i>
+ * debug messages.<br>
+ *
+ * <p>An instance must be bound to the current thread's GLContext to achieve thread safety.</p>
+ *
+ * <p>A native callback function is registered at {@link #enable(boolean) enable(true)},
+ * which forwards received messages to the added {@link GLDebugListener} directly.
+ * Hence the {@link GLDebugListener#messageSent(GLDebugMessage)} implementation shall
+ * return as fast as possible.</p>
+ *
+ * <p>In case no <i>GL_ARB_debug_output</i> is available, but <i>GL_AMD_debug_output</i>,
+ * the messages are translated to <i>ARB</i> {@link GLDebugMessage}, using {@link GLDebugMessage#translateAMDEvent(javax.media.opengl.GLContext, long, int, int, int, String)}.</p>
+ */
+public class GLDebugMessageHandler {
+ /** Extension <i>GL_ARB_debug_output</i> implementing GLDebugMessage */
+ public static final String GL_ARB_debug_output = "GL_ARB_debug_output".intern();
+
+ /** Extension <i>GL_AMD_debug_output</i> implementing GLDebugMessage */
+ public static final String GL_AMD_debug_output = "GL_AMD_debug_output".intern();
+
+ private static final boolean DEBUG = Debug.debug("GLDebugMessageHandler");
+
+ private static final int EXT_ARB = 1;
+ private static final int EXT_AMD = 2;
+
+ static {
+ if ( !initIDs0() ) {
+ throw new NativeWindowException("Failed to initialize GLDebugMessageHandler jmethodIDs");
+ }
+ }
+
+ private final GLContextImpl ctx;
+ private final ListenerSyncedImplStub<GLDebugListener> listenerImpl;
+
+ // licefycle: init - EOL
+ private String extName;
+ private int extType;
+ private long glDebugMessageCallbackProcAddress;
+ private boolean extAvailable;
+
+ // licefycle: enable - disable/EOL
+ private long handle;
+
+ /**
+ * @param ctx the associated GLContext
+ * @param glDebugExtension chosen extension to use
+ */
+ public GLDebugMessageHandler(GLContextImpl ctx) {
+ this.ctx = ctx;
+ this.listenerImpl = new ListenerSyncedImplStub<GLDebugListener>();
+ this.glDebugMessageCallbackProcAddress = 0;
+ this.extName = null;
+ this.extType = 0;
+ this.extAvailable = false;
+ this.handle = 0;
+ }
+
+ public void init(boolean enable) {
+ init();
+ if(isAvailable()) {
+ enableImpl(enable);
+ }
+ }
+
+ public void init() {
+ ctx.validateCurrent();
+ if( isAvailable()) {
+ return;
+ }
+
+ if( ctx.isExtensionAvailable(GL_ARB_debug_output) ) {
+ extName = GL_ARB_debug_output;
+ extType = EXT_ARB;
+ } else if( ctx.isExtensionAvailable(GL_AMD_debug_output) ) {
+ extName = GL_AMD_debug_output;
+ extType = EXT_AMD;
+ }
+ if(DEBUG) {
+ System.err.println("GLDebugMessageHandler: Using extension: <"+extName+">");
+ }
+
+ if(0 == extType) {
+ if(DEBUG) {
+ System.err.println("GLDebugMessageHandler: No extension available!");
+ }
+ return;
+ }
+
+ final ProcAddressTable procAddressTable = ctx.getGLProcAddressTable();
+ if( procAddressTable instanceof GL4bcProcAddressTable) {
+ final GL4bcProcAddressTable desktopProcAddressTable = (GL4bcProcAddressTable)procAddressTable;
+ switch(extType) {
+ case EXT_ARB:
+ glDebugMessageCallbackProcAddress = desktopProcAddressTable._addressof_glDebugMessageCallbackARB;
+ break;
+ case EXT_AMD:
+ glDebugMessageCallbackProcAddress = desktopProcAddressTable._addressof_glDebugMessageCallbackAMD;
+ break;
+ }
+ } else {
+ if(DEBUG) {
+ System.err.println("Non desktop context not supported");
+ }
+ }
+ extAvailable = 0 < extType && null != extName && 0 != glDebugMessageCallbackProcAddress;
+
+ if(DEBUG) {
+ System.err.println("GLDebugMessageHandler: extAvailable: "+extAvailable+", glDebugMessageCallback* : 0x"+Long.toHexString(glDebugMessageCallbackProcAddress));
+ }
+
+ if(!extAvailable) {
+ glDebugMessageCallbackProcAddress = 0;
+ }
+
+ handle = 0;
+ }
+
+ public final boolean isAvailable() { return extAvailable; }
+
+ /**
+ * @return The extension implementing the GLDebugMessage feature,
+ * either {@link #GL_ARB_debug_output} or {@link #GL_AMD_debug_output}.
+ * If unavailable <i>null</i> is returned.
+ */
+ public final String getExtension() {
+ return extName;
+ }
+
+ public final boolean isExtensionARB() {
+ return extName == GL_ARB_debug_output;
+ }
+
+ public final boolean isExtensionAMD() {
+ return extName == GL_AMD_debug_output;
+ }
+
+ /**
+ * @throws GLException if context not current or callback registration failed (enable)
+ */
+ public final void enable(boolean enable) throws GLException {
+ ctx.validateCurrent();
+ if(!isAvailable()) {
+ return;
+ }
+ enableImpl(enable);
+ }
+ final void enableImpl(boolean enable) throws GLException {
+ if(enable) {
+ if(0 == handle) {
+ handle = register0(glDebugMessageCallbackProcAddress, extType);
+ if(0 == handle) {
+ throw new GLException("Failed to register via \"glDebugMessageCallback*\" using "+extName);
+ }
+ }
+ } else {
+ if(0 != handle) {
+ unregister0(glDebugMessageCallbackProcAddress, handle);
+ handle = 0;
+ }
+ }
+ if(DEBUG) {
+ System.err.println("GLDebugMessageHandler: enable("+enable+") -> 0x" + Long.toHexString(handle));
+ }
+ }
+
+ public final boolean isEnabled() { return 0 != handle; }
+
+ public final int listenerSize() {
+ return listenerImpl.size();
+ }
+
+ public final void addListener(GLDebugListener listener) {
+ listenerImpl.addListener(-1, listener);
+ }
+
+ public final void addListener(int index, GLDebugListener listener) {
+ listenerImpl.addListener(index, listener);
+ }
+
+ public final void removeListener(GLDebugListener listener) {
+ listenerImpl.removeListener(listener);
+ }
+
+ private final void sendMessage(GLDebugMessage msg) {
+ synchronized(listenerImpl) {
+ if(DEBUG) {
+ System.err.println("GLDebugMessageHandler: "+msg);
+ }
+ final ArrayList<GLDebugListener> listeners = listenerImpl.getListeners();
+ for(int i=0; i<listeners.size(); i++) {
+ listeners.get(i).messageSent(msg);
+ }
+ }
+ }
+
+ public static class StdErrGLDebugListener implements GLDebugListener {
+ public void messageSent(GLDebugMessage event) {
+ System.err.println(event);
+ }
+ }
+
+ //
+ // native -> java
+ //
+
+ protected final void glDebugMessageARB(int source, int type, int id, int severity, String msg) {
+ final GLDebugMessage event = new GLDebugMessage(ctx, System.currentTimeMillis(), source, type, id, severity, msg);
+ sendMessage(event);
+ }
+
+ protected final void glDebugMessageAMD(int id, int category, int severity, String msg) {
+ final GLDebugMessage event = GLDebugMessage.translateAMDEvent(ctx, System.currentTimeMillis(), id, category, severity, msg);
+ sendMessage(event);
+ }
+
+ //
+ // java -> native
+ //
+
+ private static native boolean initIDs0();
+ private native long register0(long glDebugMessageCallbackProcAddress, int extType);
+ private native void unregister0(long glDebugMessageCallbackProcAddress, long handle);
+}
+
+
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
index d079a1bd1..887e571cc 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
@@ -50,12 +50,11 @@ 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 ArrayList<GLEventListener> listeners;
+ private HashSet<GLEventListener> listenersToBeInit;
private boolean autoSwapBufferMode;
private Object glRunnablesLock = new Object();
- private ArrayList glRunnables;
+ private ArrayList<GLRunnable> glRunnables;
private GLAnimatorControl animatorCtrl;
public GLDrawableHelper() {
@@ -64,13 +63,12 @@ public class GLDrawableHelper {
public final void reset() {
synchronized(listenersLock) {
- listeners = new ArrayList();
- listenersIter = false;
- listenersToBeInit = new HashSet();
+ listeners = new ArrayList<GLEventListener>();
+ listenersToBeInit = new HashSet<GLEventListener>();
}
autoSwapBufferMode = true;
synchronized(glRunnablesLock) {
- glRunnables = new ArrayList();
+ glRunnables = new ArrayList<GLRunnable>();
}
animatorCtrl = null;
}
@@ -81,7 +79,6 @@ public class GLDrawableHelper {
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);
@@ -89,7 +86,6 @@ public class GLDrawableHelper {
sb.append( !listenersToBeInit.contains(l) );
sb.append("], ");
}
- listenersIter = false;
}
sb.append("]");
return sb.toString();
@@ -107,29 +103,13 @@ public class GLDrawableHelper {
// 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;
- }
+ listeners.add(index, listener);
}
}
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;
- }
+ listeners.remove(listener);
listenersToBeInit.remove(listener);
}
}
@@ -141,12 +121,9 @@ public class GLDrawableHelper {
*/
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);
+ listeners.get(i).dispose(drawable);
}
- listenersIter = false;
}
}
@@ -163,9 +140,8 @@ public class GLDrawableHelper {
public final void init(GLAutoDrawable drawable) {
synchronized(listenersLock) {
- listenersIter = true;
for (int i=0; i < listeners.size(); i++) {
- GLEventListener listener = (GLEventListener) listeners.get(i) ;
+ final GLEventListener listener = 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),
@@ -176,21 +152,18 @@ public class GLDrawableHelper {
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) ;
+ final GLEventListener listener = 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);
}
@@ -205,27 +178,25 @@ public class GLDrawableHelper {
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;
+ ArrayList<GLRunnable> _glRunnables = null;
synchronized(glRunnablesLock) {
if(glRunnables.size()>0) {
_glRunnables = glRunnables;
- glRunnables = new ArrayList();
+ glRunnables = new ArrayList<GLRunnable>();
}
}
if(null!=_glRunnables) {
for (int i=0; i < _glRunnables.size(); i++) {
- ((GLRunnable) _glRunnables.get(i)).run(drawable);
+ _glRunnables.get(i).run(drawable);
}
}
}
@@ -337,6 +308,7 @@ public class GLDrawableHelper {
// Support for recursive makeCurrent() calls as well as calling
// other drawables' display() methods from within another one's
+ // FIXME: re-evaluate due to possible expensive TLS access ?
GLContext lastContext = GLContext.getCurrent();
Runnable lastInitAction = (Runnable) perThreadInitAction.get();
if (lastContext != null) {
diff --git a/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
index 671390fbb..1d52bedbb 100644
--- a/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
@@ -64,6 +64,7 @@ public class GLPbufferImpl implements GLPbuffer {
private GLContextImpl context;
private GLDrawableHelper drawableHelper = new GLDrawableHelper();
private int floatMode;
+ private int additionalCtxCreationFlags = 0;
public GLPbufferImpl(GLDrawableImpl pbufferDrawable,
GLContext parentContext) {
@@ -177,6 +178,9 @@ public class GLPbufferImpl implements GLPbuffer {
public void setContext(GLContext ctx) {
context=(GLContextImpl)ctx;
+ if(null != context) {
+ context.setContextCreationFlags(additionalCtxCreationFlags);
+ }
}
public GLContext getContext() {
@@ -207,6 +211,17 @@ public class GLPbufferImpl implements GLPbuffer {
invokeGL(swapBuffersAction);
}
+ public void setContextCreationFlags(int flags) {
+ additionalCtxCreationFlags = flags;
+ if(null != context) {
+ context.setContextCreationFlags(additionalCtxCreationFlags);
+ }
+ }
+
+ public int getContextCreationFlags() {
+ return additionalCtxCreationFlags;
+ }
+
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
diff --git a/src/jogl/classes/jogamp/opengl/ListenerSyncedImplStub.java b/src/jogl/classes/jogamp/opengl/ListenerSyncedImplStub.java
new file mode 100644
index 000000000..1cde551be
--- /dev/null
+++ b/src/jogl/classes/jogamp/opengl/ListenerSyncedImplStub.java
@@ -0,0 +1,79 @@
+/**
+ * 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.opengl;
+
+import java.util.ArrayList;
+
+/**
+ * Simple locked listener implementation stub to be used for listener handler,
+ * synchronized on it's instance.
+ *
+ * <p>Utilizing simple locking via synchronized.</p>
+ *
+ * @param <E> The listener type
+ */
+public class ListenerSyncedImplStub<E> {
+ private ArrayList<E> listeners;
+
+ public ListenerSyncedImplStub() {
+ reset();
+ }
+
+ public synchronized final void reset() {
+ listeners = new ArrayList<E>();
+ }
+
+ public synchronized final void destroy() {
+ listeners.clear();
+ listeners = null;
+ }
+
+ public synchronized final int size() {
+ return listeners.size();
+ }
+
+ public synchronized final void addListener(E listener) {
+ addListener(-1, listener);
+ }
+
+ public synchronized final void addListener(int index, E listener) {
+ if(0>index) {
+ index = listeners.size();
+ }
+ listeners.add(index, listener);
+ }
+
+ public synchronized final void removeListener(E listener) {
+ listeners.remove(listener);
+ }
+
+ public final ArrayList<E> getListeners() {
+ return listeners;
+ }
+}
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
index 864b9583d..dbdfcd5d9 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
@@ -76,9 +76,9 @@ public abstract class EGLContext extends GLContextImpl {
return eglExtProcAddressTable;
}
- protected Map/*<String, String>*/ getFunctionNameMap() { return null; }
+ protected Map<String, String> getFunctionNameMap() { return null; }
- protected Map/*<String, String>*/ getExtensionNameMap() { return null; }
+ protected Map<String, String> getExtensionNameMap() { return null; }
public final boolean isGLReadDrawableAvailable() {
return true;
@@ -203,12 +203,12 @@ public abstract class EGLContext extends GLContextImpl {
eglQueryStringInitialized = false;
eglQueryStringAvailable = false;
- EGLExtProcAddressTable table = null;
+ ProcAddressTable table = null;
synchronized(mappedContextTypeObjectLock) {
- table = (EGLExtProcAddressTable) mappedGLXProcAddress.get( key );
+ table = mappedGLXProcAddress.get( key );
}
if(null != table) {
- eglExtProcAddressTable = table;
+ eglExtProcAddressTable = (EGLExtProcAddressTable) table;
if(DEBUG) {
System.err.println(getThreadName() + ": !!! GLContext EGL ProcAddressTable reusing key("+key+") -> "+table.hashCode());
}
diff --git a/src/jogl/classes/jogamp/opengl/glu/GLUquadricImpl.java b/src/jogl/classes/jogamp/opengl/glu/GLUquadricImpl.java
index 5eb73cd2e..3f8a76535 100644
--- a/src/jogl/classes/jogamp/opengl/glu/GLUquadricImpl.java
+++ b/src/jogl/classes/jogamp/opengl/glu/GLUquadricImpl.java
@@ -223,7 +223,7 @@ public class GLUquadricImpl implements GLUquadric {
* 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.
+ * separating coplanar faces will not be drawn.
*
* GLU.POINT: Quadrics are rendered as a set of points.
*
@@ -234,8 +234,8 @@ public class GLUquadricImpl implements GLUquadric {
}
/**
- * specifies what kind of normals are desired for quadrics.
- * The legal values are as follows:
+ * specifies what kind of normals are desired for quadrics.
+ * The legal values are as follows:
*
* GLU.NONE: No normals are generated.
*
@@ -252,7 +252,7 @@ public class GLUquadricImpl implements GLUquadric {
/**
* specifies what kind of orientation is desired for.
- * The orientation values are as follows:
+ * The orientation values are as follows:
*
* GLU.OUTSIDE: Quadrics are drawn with normals pointing outward.
*
@@ -495,10 +495,10 @@ public class GLUquadricImpl implements GLUquadric {
glNormal3f(gl, 0.0f, 0.0f, -1.0f);
}
}
-
+
da = 2.0f * PI / slices;
dr = (outerRadius - innerRadius) / loops;
-
+
switch (drawStyle) {
case GLU.GLU_FILL:
{
@@ -916,7 +916,7 @@ public class GLUquadricImpl implements GLUquadric {
}
/**
- * draws a sphere of the given radius centered around the origin.
+ * 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).
*
@@ -1188,7 +1188,7 @@ public class GLUquadricImpl implements GLUquadric {
*/
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;
diff --git a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2CurveEvaluator.java b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2CurveEvaluator.java
index 043edac89..2ef4468e5 100644
--- a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2CurveEvaluator.java
+++ b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2CurveEvaluator.java
@@ -131,7 +131,7 @@ class GL2CurveEvaluator implements CurveEvaluator {
CArrayOfFloats ps) {
if (output_triangles) {
// TODO code for callback (output_triangles probably indicates callback)
- // System.out.println("TODO curveevaluator.map1f-output_triangles");
+ // System.out.println("TODO curveevaluator.map1f-output_triangles");
} else {
gl.glMap1f(type, ulo, uhi, stride, order, ps.getArray(), ps
.getPointer());
@@ -166,10 +166,10 @@ class GL2CurveEvaluator implements CurveEvaluator {
*/
public void mapgrid1f(int nu, float u1, float u2) {
if (output_triangles) {
- // System.out.println("TODO curveevaluator.mapgrid1f");
+ // System.out.println("TODO curveevaluator.mapgrid1f");
} else
gl.glMapGrid1f(nu, u1, u2);
- // // System.out.println("upravit NU");
+ // // System.out.println("upravit NU");
// gl.glMapGrid1f(50,u1,u2);
}
@@ -189,7 +189,7 @@ class GL2CurveEvaluator implements CurveEvaluator {
*/
if (output_triangles) {
// TODO code for callback
- // System.out.println("TODO openglcurveevaluator.mapmesh1f output_triangles");
+ // System.out.println("TODO openglcurveevaluator.mapmesh1f output_triangles");
} else {
switch (style) {
case Backend.N_MESHFILL:
diff --git a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2SurfaceEvaluator.java b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2SurfaceEvaluator.java
index bc63994cb..155c4f9a9 100644
--- a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2SurfaceEvaluator.java
+++ b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GL2SurfaceEvaluator.java
@@ -76,10 +76,10 @@ class GL2SurfaceEvaluator implements SurfaceEvaluator {
if (output_triangles) {
// TODO outp triangles surfaceevaluator bgnmap2f
- // System.out.println("TODO surfaceevaluator.bgnmap2f output triangles");
+ // System.out.println("TODO surfaceevaluator.bgnmap2f output triangles");
} else {
gl.glPushAttrib(GL2.GL_EVAL_BIT);
- // System.out.println("TODO surfaceevaluator.bgnmap2f glgetintegerv");
+ // System.out.println("TODO surfaceevaluator.bgnmap2f glgetintegerv");
}
}
@@ -112,7 +112,7 @@ class GL2SurfaceEvaluator implements SurfaceEvaluator {
public void endmap2f() {
// TODO Auto-generated method stub
if (output_triangles) {
- // System.out.println("TODO surfaceevaluator.endmap2f output triangles");
+ // System.out.println("TODO surfaceevaluator.endmap2f output triangles");
} else {
gl.glPopAttrib();
// TODO use LOD
@@ -142,7 +142,7 @@ class GL2SurfaceEvaluator implements SurfaceEvaluator {
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");
+ // System.out.println("TODO openglsurfaceavaluator.mapgrid2f output_triangles");
} else {
gl.glMapGrid2d(nu, u0, u1, nv, v0, v1);
}
@@ -159,7 +159,7 @@ class GL2SurfaceEvaluator implements SurfaceEvaluator {
*/
public void mapmesh2f(int style, int umin, int umax, int vmin, int vmax) {
if (output_triangles) {
- // System.out.println("TODO openglsurfaceavaluator.mapmesh2f output_triangles");
+ // System.out.println("TODO openglsurfaceavaluator.mapmesh2f output_triangles");
} else {
/* //DEBUG - draw control points
this.poradi++;
@@ -199,7 +199,7 @@ class GL2SurfaceEvaluator implements SurfaceEvaluator {
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");
+ // System.out.println("TODO openglsurfaceevaluator.map2f output_triangles");
} else {
gl.glMap2f(type, ulo, uhi, ustride, uorder, vlo, vhi, vstride,
vorder, pts.getArray(), pts.getPointer());
diff --git a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GLUgl2nurbsImpl.java b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GLUgl2nurbsImpl.java
index bd0eaf771..58b565484 100644
--- a/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GLUgl2nurbsImpl.java
+++ b/src/jogl/classes/jogamp/opengl/glu/gl2/nurbs/GLUgl2nurbsImpl.java
@@ -442,7 +442,7 @@ public class GLUgl2nurbsImpl implements GLUnurbs {
// TODO errval ??
if (numTrims > 0) {
- // System.out.println("TODO glunurbs.do_endsurface - numtrims > 0");
+ // System.out.println("TODO glunurbs.do_endsurface - numtrims > 0");
}
subdivider.beginQuilts(new GL2Backend());
@@ -461,7 +461,7 @@ public class GLUgl2nurbsImpl implements GLUnurbs {
*/
public void do_endcurve() {
// DONE
- // // System.out.println("do_endcurve");
+ // // System.out.println("do_endcurve");
if (inCurve <= 0) {
do_nurbserror(7);
return;
@@ -509,7 +509,7 @@ public class GLUgl2nurbsImpl implements GLUnurbs {
*/
private void do_nurbserror(int i) {
// TODO nurberror
- // System.out.println("TODO nurbserror " + i);
+ // System.out.println("TODO nurbserror " + i);
}
/**
@@ -527,7 +527,7 @@ public class GLUgl2nurbsImpl implements GLUnurbs {
*/
private void loadGLMatrices() {
// TODO Auto-generated method stub
- // System.out.println("TODO glunurbs.loadGLMatrices");
+ // System.out.println("TODO glunurbs.loadGLMatrices");
}
/**
@@ -783,7 +783,7 @@ public class GLUgl2nurbsImpl implements GLUnurbs {
// DONE
O_surface o_surface = new O_surface();
// TODO nuid
- // System.out.println("TODO glunurbs.bgnsurface nuid");
+ // System.out.println("TODO glunurbs.bgnsurface nuid");
thread("do_bgnsurface", o_surface);
}
@@ -800,7 +800,7 @@ public class GLUgl2nurbsImpl implements GLUnurbs {
*/
private void endtrim() {
// TODO Auto-generated method stub
- // System.out.println("TODO glunurbs.endtrim");
+ // System.out.println("TODO glunurbs.endtrim");
}
/**
diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcSdirSorter.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcSdirSorter.java
index 0d04d4cd6..f4ad70193 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcSdirSorter.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcSdirSorter.java
@@ -47,7 +47,7 @@ public class ArcSdirSorter {
*/
public ArcSdirSorter(Subdivider subdivider) {
//TODO
- // System.out.println("TODO arcsdirsorter.constructor");
+ // System.out.println("TODO arcsdirsorter.constructor");
}
/**
@@ -57,7 +57,7 @@ public class ArcSdirSorter {
*/
public void qsort(CArrayOfArcs list, int count) {
// TODO
- // System.out.println("TODO arcsdirsorter.qsort");
+ // 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
index bee98b8c3..be72c53d2 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTdirSorter.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTdirSorter.java
@@ -46,7 +46,7 @@ public class ArcTdirSorter {
*/
public ArcTdirSorter(Subdivider subdivider) {
// TODO Auto-generated constructor stub
- // System.out.println("TODO arcTsorter.konstruktor");
+ // System.out.println("TODO arcTsorter.konstruktor");
}
/**
* Sorts list of arcs
@@ -55,6 +55,6 @@ public class ArcTdirSorter {
*/
public void qsort(CArrayOfArcs list, int count) {
// TODO Auto-generated method stub
- // System.out.println("TODO arcTsorter.qsort");
+ // 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
index 2e4d3eb96..bd6311414 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTesselator.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/ArcTesselator.java
@@ -72,7 +72,7 @@ public class ArcTesselator {
*/
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");
+ // System.out.println("TODO arctesselator.pwl_right");
}
/**
@@ -85,6 +85,6 @@ public class ArcTesselator {
*/
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");
+ // 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
index 4959f8000..610a19556 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/Backend.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Backend.java
@@ -188,7 +188,7 @@ public abstract class Backend {
* @param m step in v direction
*/
public void surfmesh(int u, int v, int n, int m) {
- // System.out.println("TODO backend.surfmesh wireframequads");
+ // System.out.println("TODO backend.surfmesh wireframequads");
// TODO wireframequads
surfaceEvaluator.mapmesh2f(NurbsConsts.N_MESHFILL, u, u + n, v, v + m);
}
diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Curve.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Curve.java
index b0ff4e6e5..786781723 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/Curve.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Curve.java
@@ -135,7 +135,7 @@ public class Curve {
stride);
}
if (cullval == Subdivider.CULL_ACCEPT) {
- // System.out.println("TODO curve.Curve-cullval");
+ // System.out.println("TODO curve.Curve-cullval");
// mapdesc.xformCulling(ps,qs.get().order,qs.get().stride,cpts,stride);
}
@@ -145,13 +145,13 @@ public class Curve {
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");
+ // 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");
+ // System.out.println("TODO curve.Curve-range1");
// Curve lower=new Curve(this,ptb,0);
}
}
@@ -162,7 +162,7 @@ public class Curve {
*/
public int cullCheck() {
if (cullval == Subdivider.CULL_ACCEPT) {
- // System.out.println("TODO curve.cullval");
+ // System.out.println("TODO curve.cullval");
// cullval=mapdesc.cullCheck(cpts,order,stride);
}
// TODO compute cullval and return the computed value
@@ -189,16 +189,16 @@ public class Curve {
int val = 0;
// mapdesc.project(spts,stride,tmp,tstride,order);
- // System.out.println("TODO curve.getsptepsize mapdesc.project");
+ // 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");
+ // System.out.println("TODO curve.getstepsize - parametric");
} else if (mapdesc.isPathLengthSampling()) {
- // System.out.println("TODO curve.getstepsize - pathlength");
+ // System.out.println("TODO curve.getstepsize - pathlength");
} else {
setstepsize(mapdesc.maxrate);
}
diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/DisplayList.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/DisplayList.java
index 5c80ffd30..d9d012606 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/DisplayList.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/DisplayList.java
@@ -51,6 +51,6 @@ public class DisplayList {
*/
public void append(Object src, Method m, Object arg) {
// TODO Auto-generated method stub
- // System.out.println("TODO displaylist append");
+ // System.out.println("TODO displaylist append");
}
}
diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotspec.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotspec.java
index 4f97b1271..114832a1c 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotspec.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotspec.java
@@ -366,7 +366,7 @@ public class Knotspec {
break;
default:
// TODO break with copying in general case
- // System.out.println("TODO knotspec.pt_io_copy");
+ // System.out.println("TODO knotspec.pt_io_copy");
break;
}
@@ -388,7 +388,7 @@ public class Knotspec {
if (istransformed) {
p.raisePointerBy(postoffset);
for (CArrayOfFloats pend = new CArrayOfFloats(p.getArray(),
- p.getPointer() + postwidth); p.getPointer() != pend
+ p.getPointer() + postwidth); p.getPointer() != pend
.getPointer(); p.raisePointerBy(poststride))
next.transform(p);
@@ -409,7 +409,7 @@ public class Knotspec {
if (istransformed) {
p.raisePointerBy(postoffset);
for (CArrayOfFloats pend = new CArrayOfFloats(p.getArray(),
- p.getPointer() + postwidth); p.getPointer() != pend
+ p.getPointer() + postwidth); p.getPointer() != pend
.getPointer(); p.raisePointerBy(poststride)) {
kspectotrans.insert(p);
}
@@ -549,8 +549,8 @@ public class Knotspec {
* z.getRelative(0)));
break;
default:
- //no need of default - see previous method and its case statement
- // System.out.println("TODO pt_oo_sum 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
index 89389dea6..aac4dfc52 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotvector.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Knotvector.java
@@ -160,7 +160,7 @@ public class Knotvector {
*/
public void show(String msg) {
// TODO Auto-generated method stub
- // System.out.println("TODO knotvector.show");
+ // System.out.println("TODO knotvector.show");
}
diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Mapdesc.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Mapdesc.java
index 8fab114ff..bd5d2db98 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/Mapdesc.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Mapdesc.java
@@ -349,7 +349,7 @@ public class Mapdesc {
*/
public float getProperty(int tag) {
// TODO Auto-generated method stub
- // System.out.println("TODO mapdesc.getproperty");
+ // System.out.println("TODO mapdesc.getproperty");
return 0;
}
@@ -428,10 +428,10 @@ public class Mapdesc {
* @param outstride output number of control points' coordinates
*/
private void xFormMat(float[][] mat, CArrayOfFloats pts, int order,
- int stride, float[] cp, int outstride) {
+ int stride, float[] cp, int outstride) {
// TODO Auto-generated method stub
- // System.out.println("TODO mapdsc.xformmat ; change cp from float[] to carrayoffloats");
+ // System.out.println("TODO mapdsc.xformmat ; change cp from float[] to carrayoffloats");
if (isrational > 0) {
diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Patch.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Patch.java
index 51c43fca7..a44f2451c 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/Patch.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Patch.java
@@ -49,6 +49,6 @@ public class Patch {
* @param patch
*/
public Patch(Quilt q, float[] pta, float[] ptb, Patch patch) {
- // System.out.println("TODO patch.constructor");
+ // 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
index f60a0cc43..f1e499a28 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/Patchlist.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Patchlist.java
@@ -82,7 +82,7 @@ public class Patchlist {
*/
public Patchlist(Patchlist patchlist, int param, float mid) {
// TODO Auto-generated constructor stub
- // System.out.println("TODO patchlist.konstruktor 2");
+ // System.out.println("TODO patchlist.konstruktor 2");
}
/**
@@ -91,7 +91,7 @@ public class Patchlist {
*/
public int cullCheck() {
// TODO Auto-generated method stub
- // System.out.println("TODO patchlist.cullcheck");
+ // System.out.println("TODO patchlist.cullcheck");
return 0;
}
@@ -99,7 +99,7 @@ public class Patchlist {
* Empty method
*/
public void getstepsize() {
- // System.out.println("TODO patchlist.getsptepsize");
+ // System.out.println("TODO patchlist.getsptepsize");
// TODO Auto-generated method stub
}
@@ -110,7 +110,7 @@ public class Patchlist {
*/
public boolean needsSamplingSubdivision() {
// TODO Auto-generated method stub
- // System.out.println("patchlist.needsSamplingSubdivision");
+ // System.out.println("patchlist.needsSamplingSubdivision");
return false;
}
@@ -121,7 +121,7 @@ public class Patchlist {
*/
public boolean needsSubdivision(int i) {
// TODO Auto-generated method stub
- // System.out.println("TODO patchlist.needsSubdivision");
+ // System.out.println("TODO patchlist.needsSubdivision");
return false;
}
@@ -131,7 +131,7 @@ public class Patchlist {
*/
public boolean needsNonSamplingSubdivision() {
// TODO Auto-generated method stub
- // System.out.println("TODO patchlist.needsNonSamplingSubdivision");
+ // System.out.println("TODO patchlist.needsNonSamplingSubdivision");
return false;
}
@@ -140,6 +140,6 @@ public class Patchlist {
*/
public void bbox() {
// TODO Auto-generated method stub
- // System.out.println("TODO patchlist.bbox");
+ // System.out.println("TODO patchlist.bbox");
}
}
diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/Quilt.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Quilt.java
index 6d732a44f..6bea4928c 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/Quilt.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Quilt.java
@@ -248,7 +248,7 @@ public class Quilt {
*/
public int isCulled() {
if (mapdesc.isCulling()) {
- // System.out.println("TODO quilt.isculled mapdesc.isculling");
+ // System.out.println("TODO quilt.isculled mapdesc.isculling");
return 0;
} else {
return Subdivider.CULL_ACCEPT;
@@ -277,6 +277,6 @@ public class Quilt {
*/
public void findRates(Flist sbrkpts, Flist tbrkpts, float[] rate) {
// TODO Auto-generated method stub
- // System.out.println("TODO quilt.findrates");
+ // System.out.println("TODO quilt.findrates");
}
}
diff --git a/src/jogl/classes/jogamp/opengl/glu/nurbs/README.txt b/src/jogl/classes/jogamp/opengl/glu/nurbs/README.txt
index 89630c71e..7f80e568c 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/README.txt
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/README.txt
@@ -1,59 +1,59 @@
Unimplemented functionality
- - tesselation and callbacks
- - trimming
- - setting NURBS properties (-> sampling etc.)
+ - 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
+ - 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
+ 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
+ - 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/Subdivider.java b/src/jogl/classes/jogamp/opengl/glu/nurbs/Subdivider.java
index 3378dba8d..37774f811 100644
--- a/src/jogl/classes/jogamp/opengl/glu/nurbs/Subdivider.java
+++ b/src/jogl/classes/jogamp/opengl/glu/nurbs/Subdivider.java
@@ -187,7 +187,7 @@ public class Subdivider {
renderhints.init();
if (qlist == null) {
- // System.out.println("qlist is null");
+ // System.out.println("qlist is null");
return;
}
@@ -217,7 +217,7 @@ public class Subdivider {
} else {
float[] rate = new float[2];
qlist.findRates(spbrkpts, tpbrkpts, rate);
- // System.out.println("subdivider.drawsurfaces decompose");
+ // System.out.println("subdivider.drawsurfaces decompose");
}
backend.bgnsurf(renderhints.wiretris, renderhints.wirequads);
@@ -268,7 +268,7 @@ public class Subdivider {
*/
private void freejarcs(Bin initialbin2) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.freejarcs");
+ // System.out.println("TODO subdivider.freejarcs");
}
/**
@@ -319,7 +319,7 @@ public class Subdivider {
}
}
} else{
- // System.out.println("Source is empty - subdivider.splitins");
+ // System.out.println("Source is empty - subdivider.splitins");
}
}
@@ -331,7 +331,7 @@ public class Subdivider {
*/
private void splitInT(Bin source, int start, int end) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.splitint");
+ // System.out.println("TODO subdivider.splitint");
if (source.isnonempty()) {
if (start != end) {
@@ -485,7 +485,7 @@ public class Subdivider {
*/
private void monosplitInS(Bin source, int start, int end) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.monosplitins");
+ // System.out.println("TODO subdivider.monosplitins");
}
/**
@@ -494,7 +494,7 @@ public class Subdivider {
*/
private void findIrregularS(Bin source) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.findIrregularS");
+ // System.out.println("TODO subdivider.findIrregularS");
}
/**
@@ -502,7 +502,7 @@ public class Subdivider {
*/
private void setArcTypePwl() {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.setarctypepwl");
+ // System.out.println("TODO subdivider.setarctypepwl");
}
/**
@@ -512,7 +512,7 @@ public class Subdivider {
*/
private void tesselation(Bin source, Patchlist patchlist) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.tesselation");
+ // System.out.println("TODO subdivider.tesselation");
}
/**
@@ -520,7 +520,7 @@ public class Subdivider {
*/
private void setDegenerate() {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.setdegenerate");
+ // System.out.println("TODO subdivider.setdegenerate");
}
/**
@@ -611,7 +611,7 @@ public class Subdivider {
*/
private void join_t(Bin left, Bin right, Arc arc, Arc relative) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.join_t");
+ // System.out.println("TODO subdivider.join_t");
}
/**
@@ -621,7 +621,7 @@ public class Subdivider {
*/
private void check_t(Arc arc, Arc relative) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.check_t");
+ // System.out.println("TODO subdivider.check_t");
}
/**
@@ -670,7 +670,7 @@ public class Subdivider {
*/
private void link(Arc jarc1, Arc jarc2, Arc newright, Arc newleft) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.link");
+ // System.out.println("TODO subdivider.link");
}
/**
@@ -679,7 +679,7 @@ public class Subdivider {
*/
private boolean isBezierArcType() {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.isbezierarc");
+ // System.out.println("TODO subdivider.isbezierarc");
return true;
}
@@ -690,7 +690,7 @@ public class Subdivider {
*/
private void simplelink(Arc jarc1, Arc jarc2) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.simplelink");
+ // System.out.println("TODO subdivider.simplelink");
}
/**
@@ -700,7 +700,7 @@ public class Subdivider {
*/
private void check_s(Arc arc, Arc relative) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.check_s");
+ // System.out.println("TODO subdivider.check_s");
}
@@ -756,7 +756,7 @@ public class Subdivider {
} else {
if (hdiff > 0) {
// TODO rest
- // System.out.println("TODO subdivider.partition rest of else");
+ // System.out.println("TODO subdivider.partition rest of else");
} else if (hdiff == 0) {
tailonleft.addarc(jarc);
} else {
@@ -788,7 +788,7 @@ public class Subdivider {
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");
+ // System.out.println("TODO subdivider.classify_tailonright_t");
}
@@ -862,7 +862,7 @@ public class Subdivider {
*/
private boolean ccwTurn_sr(Arc prev, Arc j) {
// TODO Auto-generated method stub
- // System.out.println("TODO ccwTurn_sr");
+ // System.out.println("TODO ccwTurn_sr");
return false;
}
@@ -876,7 +876,7 @@ public class Subdivider {
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");
+ // System.out.println("TODO subdivider.classify_headonright_t");
}
/**
@@ -889,7 +889,7 @@ public class Subdivider {
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");
+ // System.out.println("TODO subdivider.classify_tailonleft_t");
}
/**
@@ -930,7 +930,7 @@ public class Subdivider {
*/
private boolean ccwTurn_tl(Arc prev, Arc j) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.ccwTurn_tl");
+ // System.out.println("TODO subdivider.ccwTurn_tl");
return false;
}
@@ -1004,7 +1004,7 @@ public class Subdivider {
*/
private boolean ccwTurn_sl(Arc prev, Arc j) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.ccwTurn_sl");
+ // System.out.println("TODO subdivider.ccwTurn_sl");
return false;
}
@@ -1018,7 +1018,7 @@ public class Subdivider {
*/
private int arc_split(Arc jarc, int param, float value, int i) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.arc_split");
+ // System.out.println("TODO subdivider.arc_split");
return 0;
}
@@ -1045,7 +1045,7 @@ public class Subdivider {
*/
private void outline(Bin source) {
// TODO Auto-generated method stub
- // System.out.println("TODO subdivider.outline");
+ // System.out.println("TODO subdivider.outline");
}
/**
@@ -1128,7 +1128,7 @@ public class Subdivider {
if (curvelist.needsSamplingSubdivision() && (subdivisions > 0)) {
// TODO kód
- // System.out.println("TODO subdivider-needsSamplingSubdivision");
+ // 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);
diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/ActiveRegion.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/ActiveRegion.java
index 13c226a7c..17f58309a 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/ActiveRegion.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/ActiveRegion.java
@@ -54,16 +54,16 @@ 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
+ 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
+ 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
+ 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/GLUface.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUface.java
index b15bf7195..892722d9f 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUface.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUface.java
@@ -53,13 +53,13 @@
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 */
+ 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 */
+ 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
index 385a4384b..29944f9b2 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUhalfEdge.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUhalfEdge.java
@@ -53,16 +53,16 @@
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 */
+ 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 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) {
diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUmesh.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUmesh.java
index dfdf5be70..10af74319 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUmesh.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUmesh.java
@@ -53,8 +53,8 @@
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 */
+ 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
index 182820bbc..d594cb3eb 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUtessellatorImpl.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUtessellatorImpl.java
@@ -59,32 +59,32 @@ 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 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
+ 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) */
+ 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 */
+ 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 */
+ 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 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 */
@@ -96,12 +96,12 @@ public class GLUtessellatorImpl implements GLUtessellator {
/*** 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 */
+ 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 Object polygonData; /* client data for current polygon */
private GLUtessellatorCallback callBegin;
private GLUtessellatorCallback callEdgeFlag;
@@ -120,10 +120,10 @@ public class GLUtessellatorImpl implements GLUtessellator {
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 final int GLU_TESS_MESH = 100112; /* void (*)(GLUmesh *mesh) */
private static GLUtessellatorCallback NULL_CB = new GLUtessellatorCallbackAdapter();
-// #define MAX_FAST_ALLOC (MAX(sizeof(EdgePair), \
+// #define MAX_FAST_ALLOC (MAX(sizeof(EdgePair), \
// MAX(sizeof(GLUvertex),sizeof(GLUface))))
private GLUtessellatorImpl() {
@@ -220,7 +220,7 @@ public class GLUtessellatorImpl implements GLUtessellator {
case GLU.GLU_TESS_WINDING_RULE:
int windingRule = (int) value;
- if (windingRule != value) break; /* not an integer */
+ if (windingRule != value) break; /* not an integer */
switch (windingRule) {
case GLU.GLU_TESS_WINDING_ODD:
@@ -523,7 +523,7 @@ public class GLUtessellatorImpl implements GLUtessellator {
* Each interior region is guaranteed be monotone.
*/
if (!Sweep.__gl_computeInterior(this)) {
- throw new RuntimeException(); /* could've used a label */
+ throw new RuntimeException(); /* could've used a label */
}
mesh = this.mesh;
@@ -539,7 +539,7 @@ public class GLUtessellatorImpl implements GLUtessellator {
} else {
rc = TessMono.__gl_meshTessellateInterior(mesh, avoidDegenerateTris);
}
- if (!rc) throw new RuntimeException(); /* could've used a label */
+ if (!rc) throw new RuntimeException(); /* could've used a label */
Mesh.__gl_meshCheckMesh(mesh);
@@ -552,7 +552,7 @@ public class GLUtessellatorImpl implements GLUtessellator {
if (boundaryOnly) {
Render.__gl_renderBoundary(this, mesh); /* output boundary contours */
} else {
- Render.__gl_renderMesh(this, mesh); /* output strips and fans */
+ Render.__gl_renderMesh(this, mesh); /* output strips and fans */
}
}
// if (callMesh != NULL_CB) {
@@ -564,7 +564,7 @@ public class GLUtessellatorImpl implements GLUtessellator {
// * faces in the first place.
// */
// TessMono.__gl_meshDiscardExterior(mesh);
-// callMesh.mesh(mesh); /* user wants the mesh itself */
+// callMesh.mesh(mesh); /* user wants the mesh itself */
// mesh = null;
// polygonData = null;
// return;
diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUvertex.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUvertex.java
index c30d75946..ecc91c2b6 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUvertex.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/GLUvertex.java
@@ -53,13 +53,13 @@
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 */
+ 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 */
+ 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/Mesh.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Mesh.java
index 942dfe8d1..eb48aa5a4 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/Mesh.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Mesh.java
@@ -281,8 +281,8 @@ class Mesh {
/* __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 )
+ * 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:
@@ -453,9 +453,9 @@ class Mesh {
/* 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.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.winding = eOrg.winding; /* copy old winding information */
eNew.Sym.winding = eOrg.Sym.winding;
return eNew;
diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/Normal.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Normal.java
index 7d5acd9f8..196e6cf27 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/Normal.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Normal.java
@@ -60,7 +60,7 @@ class Normal {
}
static boolean SLANTED_SWEEP = false;
- static double S_UNIT_X; /* Pre-normalized */
+ static double S_UNIT_X; /* Pre-normalized */
static double S_UNIT_Y;
private static final boolean TRUE_PROJECT = false;
@@ -75,7 +75,7 @@ class Normal {
* direction to be something unusual (ie. not parallel to one of the
* coordinate axes).
*/
- S_UNIT_X = 0.50941539564955385; /* Pre-normalized */
+ S_UNIT_X = 0.50941539564955385; /* Pre-normalized */
S_UNIT_Y = 0.86052074622010633;
} else {
S_UNIT_X = 1.0;
diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQHeap.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQHeap.java
index 899df2e3d..474056cc3 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQHeap.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQHeap.java
@@ -76,7 +76,7 @@ class PriorityQHeap extends jogamp.opengl.glu.tessellator.PriorityQ {
freeList = 0;
this.leq = leq;
- nodes[1].handle = 1; /* so that Minimum() returns NULL */
+ nodes[1].handle = 1; /* so that Minimum() returns NULL */
handles[1].key = null;
}
@@ -171,7 +171,7 @@ class PriorityQHeap extends jogamp.opengl.glu.tessellator.PriorityQ {
}
nodes = pqNodes;
if (nodes == null) {
- nodes = saveNodes; /* restore ptr to free upon return */
+ nodes = saveNodes; /* restore ptr to free upon return */
return Integer.MAX_VALUE;
}
diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQSort.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQSort.java
index f37f98ace..f9e0225e3 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQSort.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/PriorityQSort.java
@@ -152,7 +152,7 @@ class PriorityQSort extends jogamp.opengl.glu.tessellator.PriorityQ {
} while (LT(leq, keys[order[j]], keys[piv]));
Swap(order, i, j);
} while (i < j);
- Swap(order, i, j); /* Undo last swap */
+ Swap(order, i, j); /* Undo last swap */
if (i - p < r - j) {
stack[top].p = j + 1;
stack[top].r = r;
@@ -176,7 +176,7 @@ class PriorityQSort extends jogamp.opengl.glu.tessellator.PriorityQ {
}
max = size;
initialized = true;
- heap.pqInit(); /* always succeeds */
+ heap.pqInit(); /* always succeeds */
/* #ifndef NDEBUG
p = order;
@@ -208,7 +208,7 @@ class PriorityQSort extends jogamp.opengl.glu.tessellator.PriorityQ {
System.arraycopy( keys, 0, pqKeys, 0, keys.length );
keys = pqKeys;
if (keys == null) {
- keys = saveKey; /* restore ptr to free upon return */
+ keys = saveKey; /* restore ptr to free upon return */
return Integer.MAX_VALUE;
}
}
diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/Render.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Render.java
index 34b7ee55b..1801e1c59 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/Render.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Render.java
@@ -79,8 +79,8 @@ class Render {
this.render = render;
}
- long size; /* number of triangles used */
- jogamp.opengl.glu.tessellator.GLUhalfEdge eStart; /* edge where this primitive starts */
+ long size; /* number of triangles used */
+ jogamp.opengl.glu.tessellator.GLUhalfEdge eStart; /* edge where this primitive starts */
renderCallBack render;
};
@@ -295,7 +295,7 @@ class Render {
*/
jogamp.opengl.glu.tessellator.GLUhalfEdge e;
int newState;
- int edgeState = -1; /* force edge state output for first vertex */
+ int edgeState = -1; /* force edge state output for first vertex */
tess.callBeginOrBeginData(GL.GL_TRIANGLES);
diff --git a/src/jogl/classes/jogamp/opengl/glu/tessellator/Sweep.java b/src/jogl/classes/jogamp/opengl/glu/tessellator/Sweep.java
index 95eb5dda1..b4a400c1c 100644
--- a/src/jogl/classes/jogamp/opengl/glu/tessellator/Sweep.java
+++ b/src/jogl/classes/jogamp/opengl/glu/tessellator/Sweep.java
@@ -300,7 +300,7 @@ class Sweep {
regPrev = regFirst;
ePrev = regFirst.eUp;
while (regPrev != regLast) {
- regPrev.fixUpperEdge = false; /* placement was OK */
+ regPrev.fixUpperEdge = false; /* placement was OK */
reg = RegionBelow(regPrev);
e = reg.eUp;
if (e.Org != ePrev.Org) {
@@ -327,7 +327,7 @@ class Sweep {
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 */
+ FinishRegion(tess, regPrev); /* may change reg.eUp */
ePrev = reg.eUp;
regPrev = reg;
}
@@ -627,11 +627,11 @@ class Sweep {
assert (orgUp != tess.event && orgLo != tess.event);
assert (!regUp.fixUpperEdge && !regLo.fixUpperEdge);
- if (orgUp == orgLo) return false; /* right endpoints are the same */
+ 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 (tMinUp > tMaxLo) return false; /* t ranges do not overlap */
if (Geom.VertLeq(orgUp, orgLo)) {
if (Geom.EdgeSign(dstLo, orgUp, orgLo) > 0) return false;
@@ -743,7 +743,7 @@ class Sweep {
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.pqDeletePriorityQ(); /* __gl_pqSortDeletePriorityQ */
tess.pq = null;
throw new RuntimeException();
}
@@ -959,7 +959,7 @@ class Sweep {
regUp.fixUpperEdge = false;
}
if (!Mesh.__gl_meshSplice(vEvent.anEdge, e)) throw new RuntimeException();
- SweepEvent(tess, vEvent); /* recurse */
+ SweepEvent(tess, vEvent); /* recurse */
return;
}
@@ -1001,9 +1001,9 @@ class Sweep {
*
* - 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
+ * - 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;
@@ -1063,7 +1063,7 @@ class Sweep {
ActiveRegion regUp, reg;
GLUhalfEdge e, eTopLeft, eBottomLeft;
- tess.event = vEvent; /* for access in EdgeLeq() */
+ tess.event = vEvent; /* for access in EdgeLeq() */
DebugEvent(tess);
/* Check if this vertex is the right endpoint of an edge that is
@@ -1130,7 +1130,7 @@ class Sweep {
e.Org.t = t;
e.Sym.Org.s = -SENTINEL_COORD;
e.Sym.Org.t = t;
- tess.event = e.Sym.Org; /* initialize it */
+ tess.event = e.Sym.Org; /* initialize it */
reg.eUp = e;
reg.windingNumber = 0;
@@ -1180,7 +1180,7 @@ class Sweep {
DeleteRegion(tess, reg);
/* __gl_meshDelete( reg.eUp );*/
}
- Dict.dictDeleteDict(tess.dict); /* __gl_dictListDeleteDict */
+ Dict.dictDeleteDict(tess.dict); /* __gl_dictListDeleteDict */
}
@@ -1199,7 +1199,7 @@ class Sweep {
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 */
+ 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;
@@ -1243,7 +1243,7 @@ class Sweep {
if (v.pqHandle == Long.MAX_VALUE) break;
}
if (v != vHead || !pq.pqInit()) { /* __gl_pqSortInit */
- tess.pq.pqDeletePriorityQ(); /* __gl_pqSortDeletePriorityQ */
+ tess.pq.pqDeletePriorityQ(); /* __gl_pqSortDeletePriorityQ */
tess.pq = null;
return false;
}
@@ -1306,7 +1306,7 @@ class Sweep {
* 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)
+ * e1 < e2 iff e1.x < e2.x || (e1.x == e2.x && e1.y < e2.y)
*/
RemoveDegenerateEdges(tess);
if (!InitPriorityQ(tess)) return false; /* if error */
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
index 085889739..db737902a 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
@@ -49,7 +49,7 @@ 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
@@ -82,9 +82,9 @@ public abstract class MacOSXCGLContext extends GLContextImpl
return cglExtProcAddressTable;
}
- protected Map/*<String, String>*/ getFunctionNameMap() { return null; }
+ protected Map<String, String> getFunctionNameMap() { return null; }
- protected Map/*<String, String>*/ getExtensionNameMap() { 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
@@ -178,7 +178,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl
}
}
}
-
+
protected void releaseImpl() throws GLException {
if ( isNSContext ) {
if (!CGL.clearCurrentContext(contextHandle)) {
@@ -188,7 +188,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl
CGL.CGLReleaseContext(contextHandle);
}
}
-
+
protected void destroyImpl() throws GLException {
if ( !isNSContext ) {
if (CGL.kCGLNoError != CGL.CGLDestroyContext(contextHandle)) {
@@ -230,12 +230,12 @@ public abstract class MacOSXCGLContext extends GLContextImpl
if (DEBUG) {
System.err.println(getThreadName() + ": !!! Initializing CGL extension address table: "+key);
}
- CGLExtProcAddressTable table = null;
+ ProcAddressTable table = null;
synchronized(mappedContextTypeObjectLock) {
- table = (CGLExtProcAddressTable) mappedGLXProcAddress.get( key );
+ table = mappedGLXProcAddress.get( key );
}
if(null != table) {
- cglExtProcAddressTable = table;
+ cglExtProcAddressTable = (CGLExtProcAddressTable) table;
if(DEBUG) {
System.err.println(getThreadName() + ": !!! GLContext CGL ProcAddressTable reusing key("+key+") -> "+table.hashCode());
}
@@ -254,12 +254,12 @@ public abstract class MacOSXCGLContext extends GLContextImpl
}
}
}
-
+
public String getPlatformExtensionsString()
{
return "";
}
-
+
protected void swapBuffers() {
DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)config.getChosenCapabilities();
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java
index 6dba11038..949963fa0 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java
@@ -48,7 +48,7 @@ public class MacOSXOffscreenCGLContext extends MacOSXPbufferCGLContext
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;
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLContext.java
index 6eda3f068..dc5ce26c8 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLContext.java
@@ -138,7 +138,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable)config.getChosenCapabilities();
if (capabilities.getPbufferFloatingPointBuffers() &&
- !isTigerOrLater) {
+ !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
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java
index 4e5afc683..854d01fa6 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java
@@ -214,15 +214,15 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
}
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));
+ glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride, pointer, -1, -1, -1));
}
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));
+ glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride,
+ null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW));
}
public void glColorPointer(GLArrayData array) {
@@ -241,16 +241,16 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
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));
+ glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, stride,
+ pointer, -1, -1, -1));
}
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));
+ glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, stride,
+ null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW));
}
public void glNormalPointer(GLArrayData array) {
@@ -272,16 +272,16 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
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));
+ glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, stride,
+ pointer, -1, -1, -1));
}
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));
+ glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, stride,
+ null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW));
}
public void glTexCoordPointer(GLArrayData array) {
@@ -301,7 +301,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
}
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));
+ GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, -1, -1, -1));
}
public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
@@ -309,8 +309,8 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
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) );
+ GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride,
+ null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW) );
}
public final String 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
index b77cf4617..fadce2b4d 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
@@ -83,9 +83,9 @@ public class FixedFuncPipeline {
}
public void glEnableClientState(GL2ES2 gl, int glArrayIndex) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
- shaderState.glEnableVertexAttribArray(gl, getArrayIndexName(glArrayIndex));
+ shaderState.enableVertexAttribArray(gl, getArrayIndexName(glArrayIndex));
// textureCoordsEnabled |= (1 << activeTextureUnit);
if ( textureCoordsEnabled.get(activeTextureUnit) != 1 ) {
textureCoordsEnabled.put(activeTextureUnit, 1);
@@ -94,9 +94,9 @@ public class FixedFuncPipeline {
}
public void glDisableClientState(GL2ES2 gl, int glArrayIndex) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
- shaderState.glDisableVertexAttribArray(gl, getArrayIndexName(glArrayIndex));
+ shaderState.disableVertexAttribArray(gl, getArrayIndexName(glArrayIndex));
// textureCoordsEnabled &= ~(1 << activeTextureUnit);
if ( textureCoordsEnabled.get(activeTextureUnit) != 0 ) {
textureCoordsEnabled.put(activeTextureUnit, 0);
@@ -105,37 +105,37 @@ public class FixedFuncPipeline {
}
public void glVertexPointer(GL2ES2 gl, GLArrayData data) {
- shaderState.glUseProgram(gl, true);
- shaderState.glVertexAttribPointer(gl, data);
+ shaderState.useProgram(gl, true);
+ shaderState.vertexAttribPointer(gl, data);
}
public void glColorPointer(GL2ES2 gl, GLArrayData data) {
- shaderState.glUseProgram(gl, true);
- shaderState.glVertexAttribPointer(gl, data);
+ shaderState.useProgram(gl, true);
+ shaderState.vertexAttribPointer(gl, data);
}
public void glColor4fv(GL2ES2 gl, FloatBuffer data ) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
GLUniformData ud = shaderState.getUniform(mgl_ColorStatic);
if(null!=ud) {
ud.setData(data);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
public void glNormalPointer(GL2ES2 gl, GLArrayData data) {
- shaderState.glUseProgram(gl, true);
- shaderState.glVertexAttribPointer(gl, data);
+ shaderState.useProgram(gl, true);
+ shaderState.vertexAttribPointer(gl, data);
}
public void glTexCoordPointer(GL2ES2 gl, GLArrayData data) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
data.setName( getArrayIndexName(data.getIndex()) );
- shaderState.glVertexAttribPointer(gl, data);
+ shaderState.vertexAttribPointer(gl, data);
}
public void glLightfv(GL2ES2 gl, int light, int pname, java.nio.FloatBuffer params) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
light -=GLLightingFunc.GL_LIGHT0;
if(0 <= light && light < MAX_LIGHTS) {
GLUniformData ud = null;
@@ -178,7 +178,7 @@ public class FixedFuncPipeline {
}
if(null!=ud) {
ud.setData(params);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
} else if(verbose) {
System.err.println("glLightfv light not within [0.."+MAX_LIGHTS+"]: "+light);
@@ -186,7 +186,7 @@ public class FixedFuncPipeline {
}
public void glMaterialfv(GL2ES2 gl, int face, int pname, java.nio.FloatBuffer params) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
switch (face) {
case GL.GL_FRONT:
@@ -228,33 +228,33 @@ public class FixedFuncPipeline {
}
if(null!=ud) {
ud.setData(params);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
public void glShadeModel(GL2ES2 gl, int mode) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
GLUniformData ud = shaderState.getUniform(mgl_ShadeModel);
if(null!=ud) {
ud.setData(mode);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
public void glActiveTexture(GL2ES2 gl, int textureUnit) {
textureUnit -= GL.GL_TEXTURE0;
if(0 <= textureUnit && textureUnit<MAX_TEXTURE_UNITS) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
GLUniformData ud;
ud = shaderState.getUniform(mgl_ActiveTexture);
if(null!=ud) {
ud.setData(textureUnit);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
ud = shaderState.getUniform(mgl_ActiveTextureIdx);
if(null!=ud) {
ud.setData(textureUnit);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
activeTextureUnit = textureUnit;
} else {
@@ -310,20 +310,20 @@ public class FixedFuncPipeline {
}
public void validate(GL2ES2 gl) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
GLUniformData ud;
if(pmvMatrix.update()) {
ud = shaderState.getUniform(mgl_PMVMatrix);
if(null!=ud) {
// same data object ..
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
} else {
- throw new GLException("Failed to update: mgl_PMVMatrix");
+ throw new GLException("Failed to update: gcu_PMVMatrix");
}
ud = shaderState.getUniform(mgl_NormalMatrix);
if(null!=ud) {
// same data object ..
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
ud = shaderState.getUniform(mgl_ColorEnabled);
@@ -331,14 +331,14 @@ public class FixedFuncPipeline {
int ca = (shaderState.isVertexAttribArrayEnabled(mgl_Color)==true)?1:0;
if(ca!=ud.intValue()) {
ud.setData(ca);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
ud = shaderState.getUniform(mgl_CullFace);
if(null!=ud) {
if(cullFace!=ud.intValue()) {
ud.setData(cullFace);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
@@ -346,7 +346,7 @@ public class FixedFuncPipeline {
ud = shaderState.getUniform(mgl_LightsEnabled);
if(null!=ud) {
// same data object
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
lightsEnabledDirty=false;
}
@@ -355,7 +355,7 @@ public class FixedFuncPipeline {
ud = shaderState.getUniform(mgl_TexCoordEnabled);
if(null!=ud) {
// same data object
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
textureCoordsEnabledDirty=false;
}
@@ -447,43 +447,43 @@ public class FixedFuncPipeline {
}
shaderState.attachShaderProgram(gl, shaderProgramColor);
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
// mandatory ..
- if(!shaderState.glUniform(gl, new GLUniformData(mgl_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMviMatrixf()))) {
+ if(!shaderState.uniform(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));
+ shaderState.uniform(gl, new GLUniformData(mgl_NormalMatrix, 3, 3, pmvMatrix.glGetNormalMatrixf()));
+
+ shaderState.uniform(gl, new GLUniformData(mgl_ColorEnabled, 0));
+ shaderState.uniform(gl, new GLUniformData(mgl_ColorStatic, 4, zero4f));
+ shaderState.uniform(gl, new GLUniformData(mgl_TexCoordEnabled, 1, textureCoordsEnabled));
+ shaderState.uniform(gl, new GLUniformData(mgl_ActiveTexture, activeTextureUnit));
+ shaderState.uniform(gl, new GLUniformData(mgl_ActiveTextureIdx, activeTextureUnit));
+ shaderState.uniform(gl, new GLUniformData(mgl_ShadeModel, 0));
+ shaderState.uniform(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.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].ambient", 4, defAmbient));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].diffuse", 4, defDiffuse));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].specular", 4, defSpecular));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].position", 4, defPosition));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotDirection", 3, defSpotDir));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotExponent", defSpotExponent));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotCutoff", defSpotCutoff));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].constantAttenuation", defConstantAtten));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].linearAttenuation", defLinearAtten));
+ shaderState.uniform(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);
+ shaderState.uniform(gl, new GLUniformData(mgl_LightsEnabled, 1, lightsEnabled));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".ambient", 4, defMatAmbient));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".diffuse", 4, defMatDiffuse));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".specular", 4, defMatSpecular));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".emission", 4, defMatEmission));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".shininess", defMatShininess));
+
+ shaderState.useProgram(gl, false);
}
protected static final boolean DEBUG=false;
@@ -508,7 +508,7 @@ public class FixedFuncPipeline {
protected ShaderProgram shaderProgramColorTextureLight;
// uniforms ..
- protected static final String mgl_PMVMatrix = "mgl_PMVMatrix"; // m4fv[3]
+ protected static final String mgl_PMVMatrix = "gcu_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
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java
index 94017e79a..55e2e478c 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java
@@ -58,8 +58,8 @@ 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;
+ static final Map<String, String> functionNameMap;
+ static final Map<String, String> extensionNameMap;
private boolean wglGetExtensionsStringEXTInitialized;
private boolean wglGetExtensionsStringEXTAvailable;
private boolean wglGLReadDrawableAvailableSet;
@@ -70,11 +70,11 @@ public class WindowsWGLContext extends GLContextImpl {
private WGLExtProcAddressTable wglExtProcAddressTable;
static {
- functionNameMap = new HashMap();
+ functionNameMap = new HashMap<String, String>();
functionNameMap.put("glAllocateMemoryNV", "wglAllocateMemoryNV");
functionNameMap.put("glFreeMemoryNV", "wglFreeMemoryNV");
- extensionNameMap = new HashMap();
+ extensionNameMap = new HashMap<String, String>();
extensionNameMap.put("GL_ARB_pbuffer", "WGL_ARB_pbuffer");
extensionNameMap.put("GL_ARB_pixel_format", "WGL_ARB_pixel_format");
}
@@ -161,9 +161,9 @@ public class WindowsWGLContext extends GLContextImpl {
return wglExtProcAddressTable;
}
- protected Map/*<String, String>*/ getFunctionNameMap() { return functionNameMap; }
+ protected Map<String, String> getFunctionNameMap() { return functionNameMap; }
- protected Map/*<String, String>*/ getExtensionNameMap() { return extensionNameMap; }
+ protected Map<String, String> getExtensionNameMap() { return extensionNameMap; }
protected void destroyContextARBImpl(long context) {
WGL.wglMakeCurrent(0, 0);
@@ -273,14 +273,11 @@ public class WindowsWGLContext extends GLContextImpl {
}
}
- 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);
+ contextHandle = createContextARB(share, true);
createContextARBTried = true;
if (DEBUG && 0!=contextHandle) {
System.err.println(getThreadName() + ": createImpl: OK (ARB, using sharedContext) share "+share);
@@ -306,7 +303,7 @@ public class WindowsWGLContext extends GLContextImpl {
if(isCreateContextAttribsARBAvailable &&
isExtensionAvailable("WGL_ARB_create_context") ) {
// initial ARB context creation
- contextHandle = createContextARB(share, true, major, minor, ctp);
+ contextHandle = createContextARB(share, true);
createContextARBTried=true;
if (DEBUG) {
if(0!=contextHandle) {
@@ -334,10 +331,10 @@ public class WindowsWGLContext extends GLContextImpl {
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")+", ");
+ throw new GLException("WindowsWGLContext.createContext failed, but context > GL2 requested "+getGLVersion()+", ");
}
if(DEBUG) {
- System.err.println("WindowsWGLContext.createContext failed, fall back to !ARB context "+getGLVersion(major[0], minor[0], ctp[0], "@creation"));
+ System.err.println("WindowsWGLContext.createContext failed, fall back to !ARB context "+getGLVersion());
}
// continue with temp context for GL < 3.0
@@ -405,12 +402,12 @@ public class WindowsWGLContext extends GLContextImpl {
wglGLReadDrawableAvailableSet=false;
wglGLReadDrawableAvailable=false;
- WGLExtProcAddressTable table = null;
+ ProcAddressTable table = null;
synchronized(mappedContextTypeObjectLock) {
- table = (WGLExtProcAddressTable) mappedGLXProcAddress.get( key );
+ table = mappedGLXProcAddress.get( key );
}
if(null != table) {
- wglExtProcAddressTable = table;
+ wglExtProcAddressTable = (WGLExtProcAddressTable) table;
if(DEBUG) {
System.err.println(getThreadName() + ": !!! GLContext WGL ProcAddressTable reusing key("+key+") -> "+table.hashCode());
}
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
index 248dfa482..c9cdcad90 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
@@ -169,7 +169,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
/**
* http://msdn.microsoft.com/en-us/library/ms724832%28v=vs.85%29.aspx
- * Windows XP 5.1
+ * Windows XP 5.1
*/
static final VersionNumber winXPVersionNumber = new VersionNumber ( 5, 1, 0);
@@ -199,22 +199,22 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
hasARBReadDrawable = arbReadDrawable;
vendor = glVendor;
if(null != vendor) {
- isVendorNVIDIA = vendor.startsWith("NVIDIA") ;
- isVendorATI = vendor.startsWith("ATI") ;
+ 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;
+ 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;
}
}
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java
index 1899f5212..8859d636a 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java
@@ -158,7 +158,7 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
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) +
@@ -166,7 +166,7 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
}
if (DEBUG) {
System.err.println("!!! setPixelFormat (ARB): hdc "+toHexString(hdc) +", "+caps);
- }
+ }
setCapsPFD(caps);
}
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
index 8c1f5e87c..d765572a6 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
@@ -192,25 +192,25 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat
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();
- }
- }
+ 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();
@@ -400,9 +400,9 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat
}
if ( !extHDC && !pixelFormatSet ) {
- config.setPixelFormat(hdc, pixelFormatCaps);
+ config.setPixelFormat(hdc, pixelFormatCaps);
} else {
- config.setCapsPFD(pixelFormatCaps);
+ config.setCapsPFD(pixelFormatCaps);
}
return true;
}
@@ -476,9 +476,9 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat
}
if ( !extHDC && !pixelFormatSet ) {
- config.setPixelFormat(hdc, pixelFormatCaps);
+ config.setPixelFormat(hdc, pixelFormatCaps);
} else {
- config.setCapsPFD(pixelFormatCaps);
+ config.setCapsPFD(pixelFormatCaps);
}
return true;
}
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
index 7d7614ca2..9f6a5cd1a 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
@@ -56,8 +56,8 @@ 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 static final Map<String, String> functionNameMap;
+ private static final Map<String, String> extensionNameMap;
private VersionNumber glXVersion;
private boolean glXVersionOneThreeCapable;
private boolean glXQueryExtensionsStringInitialized;
@@ -74,11 +74,11 @@ public abstract class X11GLXContext extends GLContextImpl {
protected boolean isDirect;
static {
- functionNameMap = new HashMap();
+ functionNameMap = new HashMap<String, String>();
functionNameMap.put("glAllocateMemoryNV", "glXAllocateMemoryNV");
functionNameMap.put("glFreeMemoryNV", "glXFreeMemoryNV");
- extensionNameMap = new HashMap();
+ extensionNameMap = new HashMap<String, String>();
extensionNameMap.put("GL_ARB_pbuffer", "GLX_SGIX_pbuffer");
extensionNameMap.put("GL_ARB_pixel_format", "GLX_SGIX_pbuffer"); // good enough
}
@@ -118,9 +118,9 @@ public abstract class X11GLXContext extends GLContextImpl {
return glXExt;
}
- protected Map/*<String, String>*/ getFunctionNameMap() { return functionNameMap; }
+ protected Map<String, String> getFunctionNameMap() { return functionNameMap; }
- protected Map/*<String, String>*/ getExtensionNameMap() { return extensionNameMap; }
+ protected Map<String, String> getExtensionNameMap() { return extensionNameMap; }
public final boolean isGLXVersionGreaterEqualOneThree() {
if(null == glXVersion) {
@@ -297,7 +297,6 @@ public abstract class X11GLXContext extends GLContextImpl {
GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
GLProfile glp = glCaps.getGLProfile();
- isVendorATI = factory.isGLXVendorATI(device);
if(config.getFBConfigID()<0) {
// not able to use FBConfig
@@ -319,14 +318,11 @@ public abstract class X11GLXContext extends GLContextImpl {
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);
+ contextHandle = createContextARB(share, direct);
createContextARBTried = true;
if (DEBUG && 0!=contextHandle) {
System.err.println(getThreadName() + ": createContextImpl: OK (ARB, using sharedContext) share "+share);
@@ -352,7 +348,7 @@ public abstract class X11GLXContext extends GLContextImpl {
if ( isCreateContextAttribsARBAvailable &&
isExtensionAvailable("GLX_ARB_create_context") ) {
// initial ARB context creation
- contextHandle = createContextARB(share, direct, major, minor, ctp);
+ contextHandle = createContextARB(share, direct);
createContextARBTried=true;
if (DEBUG) {
if(0!=contextHandle) {
@@ -379,10 +375,10 @@ public abstract class X11GLXContext extends GLContextImpl {
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")+", ");
+ throw new GLException("X11GLXContext.createContextImpl failed, but context > GL2 requested "+getGLVersion()+", ");
}
if(DEBUG) {
- System.err.println("X11GLXContext.createContextImpl failed, fall back to !ARB context "+getGLVersion(major[0], minor[0], ctp[0], "@creation"));
+ System.err.println("X11GLXContext.createContextImpl failed, fall back to !ARB context "+getGLVersion());
}
// continue with temp context for GL <= 3.0
@@ -472,12 +468,12 @@ public abstract class X11GLXContext extends GLContextImpl {
glXQueryExtensionsStringInitialized = false;
glXQueryExtensionsStringAvailable = false;
- GLXExtProcAddressTable table = null;
+ ProcAddressTable table = null;
synchronized(mappedContextTypeObjectLock) {
- table = (GLXExtProcAddressTable) mappedGLXProcAddress.get( key );
+ table = mappedGLXProcAddress.get( key );
}
if(null != table) {
- glXExtProcAddressTable = table;
+ glXExtProcAddressTable = (GLXExtProcAddressTable) table;
if(DEBUG) {
System.err.println(getThreadName() + ": !!! GLContext GLX ProcAddressTable reusing key("+key+") -> "+table.hashCode());
}
@@ -581,7 +577,4 @@ public abstract class X11GLXContext extends GLContextImpl {
//----------------------------------------------------------------------
// Internals only below this point
//
-
- private boolean isVendorATI = false;
-
}
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
index 8203a440c..8d9de8144 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
@@ -212,7 +212,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
}
return new SharedResource(sharedDevice, sharedScreen, sharedDrawable, sharedContext, glXVersion, glXVendorName);
} catch (Throwable t) {
- throw new GLException("WindowsWGLDrawableFactory - Could not initialize shared resources for "+connection, t);
+ throw new GLException("X11GLXDrawableFactory - Could not initialize shared resources for "+connection, t);
} finally {
sharedDevice.unlock();
}
diff --git a/src/jogl/native/GLDebugMessageHandler.c b/src/jogl/native/GLDebugMessageHandler.c
new file mode 100644
index 000000000..22a7433f9
--- /dev/null
+++ b/src/jogl/native/GLDebugMessageHandler.c
@@ -0,0 +1,181 @@
+
+#include "jogamp_opengl_GLDebugMessageHandler.h"
+#include "JoglCommon.h"
+
+#include <GL/gl.h>
+#include <GL/glext.h>
+
+static jmethodID glDebugMessageARB = NULL; // int source, int type, int id, int severity, String msg
+static jmethodID glDebugMessageAMD = NULL; // int id, int category, int severity, String msg
+
+typedef void (GLAPIENTRY* _local_PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const GLvoid *userParam);
+typedef void (GLAPIENTRY* _local_GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
+
+typedef void (GLAPIENTRY* _local_PFNGLDEBUGMESSAGECALLBACKAMDPROC) (GLDEBUGPROCAMD callback, const GLvoid *userParam);
+typedef void (GLAPIENTRY* _local_GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
+
+/*
+ * Class: jogamp_opengl_GLDebugMessageHandler
+ * Method: initIDs0
+ * Signature: (V)Z
+ */
+JNIEXPORT jboolean JNICALL Java_jogamp_opengl_GLDebugMessageHandler_initIDs0
+ (JNIEnv *env, jclass clazz)
+{
+ JoglCommon_init(env);
+
+ glDebugMessageARB = (*env)->GetMethodID(env, clazz, "glDebugMessageARB", "(IIIILjava/lang/String;)V");
+ glDebugMessageAMD = (*env)->GetMethodID(env, clazz, "glDebugMessageAMD", "(IIILjava/lang/String;)V");
+
+ if ( NULL == glDebugMessageARB || NULL == glDebugMessageAMD ) {
+ return JNI_FALSE;
+ }
+ return JNI_TRUE;
+}
+
+typedef struct {
+ JavaVM *vm;
+ int version;
+ JNIEnv *env;
+ jobject obj;
+ int extType;
+} DebugHandlerType;
+
+
+// GLDEBUGARB(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
+static void GLDebugMessageARBCallback(GLenum source, GLenum type, GLuint id, GLenum severity,
+ GLsizei length, const GLchar *message, GLvoid *userParam) {
+ DebugHandlerType * handle = (DebugHandlerType*) (intptr_t) userParam;
+ JavaVM *vm = handle->vm;
+ int version = handle->version;
+ jobject obj = handle->obj;
+ JNIEnv *curEnv = NULL;
+ JNIEnv *newEnv = NULL;
+ int envRes ;
+
+ // retrieve this thread's JNIEnv curEnv - or detect it's detached
+ envRes = (*vm)->GetEnv(vm, (void **) &curEnv, version) ;
+ if( JNI_EDETACHED == envRes ) {
+ // detached thread - attach to JVM
+ if( JNI_OK != ( envRes = (*vm)->AttachCurrentThread(vm, (void**) &newEnv, NULL) ) ) {
+ fprintf(stderr, "GLDebugMessageARBCallback: can't attach thread: %d\n", envRes);
+ return;
+ }
+ curEnv = newEnv;
+ } else if( JNI_OK != envRes ) {
+ // oops ..
+ fprintf(stderr, "GLDebugMessageARBCallback: can't GetEnv: %d\n", envRes);
+ return;
+ }
+ (*curEnv)->CallVoidMethod(curEnv, obj, glDebugMessageARB,
+ (jint) source, (jint) type, (jint) id, (jint) severity,
+ (*curEnv)->NewStringUTF(curEnv, message));
+ if( NULL != newEnv ) {
+ // detached attached thread
+ (*vm)->DetachCurrentThread(vm);
+ }
+}
+
+// GLDEBUGAMD(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
+static void GLDebugMessageAMDCallback(GLuint id, GLenum category, GLenum severity,
+ GLsizei length, const GLchar *message, GLvoid *userParam) {
+ DebugHandlerType * handle = (DebugHandlerType*) (intptr_t) userParam;
+ JavaVM *vm = handle->vm;
+ int version = handle->version;
+ jobject obj = handle->obj;
+ JNIEnv *curEnv = NULL;
+ JNIEnv *newEnv = NULL;
+ int envRes ;
+
+ // retrieve this thread's JNIEnv curEnv - or detect it's detached
+ envRes = (*vm)->GetEnv(vm, (void **) &curEnv, version) ;
+ if( JNI_EDETACHED == envRes ) {
+ // detached thread - attach to JVM
+ if( JNI_OK != ( envRes = (*vm)->AttachCurrentThread(vm, (void**) &newEnv, NULL) ) ) {
+ fprintf(stderr, "GLDebugMessageAMDCallback: can't attach thread: %d\n", envRes);
+ return;
+ }
+ curEnv = newEnv;
+ } else if( JNI_OK != envRes ) {
+ // oops ..
+ fprintf(stderr, "GLDebugMessageAMDCallback: can't GetEnv: %d\n", envRes);
+ return;
+ }
+ (*curEnv)->CallVoidMethod(curEnv, obj, glDebugMessageAMD,
+ (jint) id, (jint) category, (jint) severity,
+ (*curEnv)->NewStringUTF(curEnv, message));
+ if( NULL != newEnv ) {
+ // detached attached thread
+ (*vm)->DetachCurrentThread(vm);
+ }
+}
+
+
+/*
+ * Class: jogamp_opengl_GLDebugMessageHandler
+ * Method: register0
+ * Signature: (JI)J
+ */
+JNIEXPORT jlong JNICALL Java_jogamp_opengl_GLDebugMessageHandler_register0
+ (JNIEnv *env, jobject obj, jlong procAddress, jint extType)
+{
+ JavaVM *vm;
+ DebugHandlerType * handle = malloc(sizeof(DebugHandlerType));
+ if(0 != (*env)->GetJavaVM(env, &vm)) {
+ vm = NULL;
+ JoglCommon_throwNewRuntimeException(env, "GetJavaVM failed");
+ }
+ handle->vm = vm;
+ handle->version = (*env)->GetVersion(env);
+ handle->env = env;
+ handle->obj = (*env)->NewGlobalRef(env, obj);
+ handle->extType = extType;
+
+ if(jogamp_opengl_GLDebugMessageHandler_EXT_ARB == extType) {
+ _local_PFNGLDEBUGMESSAGECALLBACKARBPROC ptr_glDebugMessageCallbackARB;
+ ptr_glDebugMessageCallbackARB = (_local_PFNGLDEBUGMESSAGECALLBACKARBPROC) (intptr_t) procAddress;
+ ptr_glDebugMessageCallbackARB((_local_GLDEBUGPROCARB)GLDebugMessageARBCallback, handle);
+ } else if(jogamp_opengl_GLDebugMessageHandler_EXT_AMD == extType) {
+ _local_PFNGLDEBUGMESSAGECALLBACKAMDPROC ptr_glDebugMessageCallbackAMD;
+ ptr_glDebugMessageCallbackAMD = (_local_PFNGLDEBUGMESSAGECALLBACKAMDPROC) (intptr_t) procAddress;
+ ptr_glDebugMessageCallbackAMD((_local_GLDEBUGPROCAMD)GLDebugMessageAMDCallback, handle);
+ } else {
+ JoglCommon_throwNewRuntimeException(env, "unsupported extension type %d", extType);
+ }
+
+ return (jlong) (intptr_t) handle;
+}
+
+/*
+ * Class: jogamp_opengl_GLDebugMessageHandler
+ * Method: unregister0
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL Java_jogamp_opengl_GLDebugMessageHandler_unregister0
+ (JNIEnv *env, jobject obj, jlong procAddress, jlong jhandle)
+{
+ DebugHandlerType * handle = (DebugHandlerType*) (intptr_t) jhandle;
+
+ if(env != handle->env) {
+ JoglCommon_throwNewRuntimeException(env, "wrong handle (env doesn't match)");
+ }
+ if(JNI_FALSE == (*env)->IsSameObject(env, obj, handle->obj)) {
+ JoglCommon_throwNewRuntimeException(env, "wrong handle (obj doesn't match)");
+ }
+
+ if(jogamp_opengl_GLDebugMessageHandler_EXT_ARB == handle->extType) {
+ _local_PFNGLDEBUGMESSAGECALLBACKARBPROC ptr_glDebugMessageCallbackARB;
+ ptr_glDebugMessageCallbackARB = (_local_PFNGLDEBUGMESSAGECALLBACKARBPROC) (intptr_t) procAddress;
+ ptr_glDebugMessageCallbackARB((_local_GLDEBUGPROCARB)NULL, NULL);
+ } else if(jogamp_opengl_GLDebugMessageHandler_EXT_AMD == handle->extType) {
+ _local_PFNGLDEBUGMESSAGECALLBACKAMDPROC ptr_glDebugMessageCallbackAMD;
+ ptr_glDebugMessageCallbackAMD = (_local_PFNGLDEBUGMESSAGECALLBACKAMDPROC) (intptr_t) procAddress;
+ ptr_glDebugMessageCallbackAMD((_local_GLDEBUGPROCAMD)NULL, NULL);
+ } else {
+ JoglCommon_throwNewRuntimeException(env, "unsupported extension type %d", handle->extType);
+ }
+
+ (*env)->DeleteGlobalRef(env, handle->obj);
+ free(handle);
+}
+
diff --git a/src/jogl/native/JoglCommon.c b/src/jogl/native/JoglCommon.c
new file mode 100644
index 000000000..16f60e4e7
--- /dev/null
+++ b/src/jogl/native/JoglCommon.c
@@ -0,0 +1,55 @@
+
+#include "JoglCommon.h"
+
+static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException";
+static jclass runtimeExceptionClz=NULL;
+
+void JoglCommon_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 JoglCommon_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 JoglCommon_init(JNIEnv *env) {
+ if(NULL==runtimeExceptionClz) {
+ jclass c = (*env)->FindClass(env, ClazzNameRuntimeException);
+ if(NULL==c) {
+ JoglCommon_FatalError(env, "JOGL: can't find %s", ClazzNameRuntimeException);
+ }
+ runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c);
+ (*env)->DeleteLocalRef(env, c);
+ if(NULL==runtimeExceptionClz) {
+ JoglCommon_FatalError(env, "JOGL: can't use %s", ClazzNameRuntimeException);
+ }
+ }
+}
+
+jchar* JoglCommon_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/jogl/native/JoglCommon.h b/src/jogl/native/JoglCommon.h
new file mode 100644
index 000000000..d82b445ce
--- /dev/null
+++ b/src/jogl/native/JoglCommon.h
@@ -0,0 +1,15 @@
+
+#ifndef JOGL_COMMON_H
+#define JOGL_COMMON_H 1
+
+#include <jni.h>
+#include <stdlib.h>
+
+void JoglCommon_init(JNIEnv *env);
+
+jchar* JoglCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str);
+
+void JoglCommon_FatalError(JNIEnv *env, const char* msg, ...);
+void JoglCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...);
+
+#endif
diff --git a/src/jogl/native/macosx/ContextUpdater.h b/src/jogl/native/macosx/ContextUpdater.h
index e8b757fac..f8ce93def 100644
--- a/src/jogl/native/macosx/ContextUpdater.h
+++ b/src/jogl/native/macosx/ContextUpdater.h
@@ -15,11 +15,11 @@ This notification is sent whenever an NSView that has an attached NSSurface chan
//#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];
+ #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];
+ #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
diff --git a/src/jogl/native/macosx/ContextUpdater.m b/src/jogl/native/macosx/ContextUpdater.m
index 587782c98..859697722 100644
--- a/src/jogl/native/macosx/ContextUpdater.m
+++ b/src/jogl/native/macosx/ContextUpdater.m
@@ -10,74 +10,74 @@ 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);
+ fprintf(stderr, "%s in function: \"%s\" at line: %d\n", message, func, line);
+ fflush(stderr);
}
+ (void) lock
{
- if (theContext != NULL)
- {
- pthread_mutex_lock(&resourceLock);
- }
+ if (theContext != NULL)
+ {
+ pthread_mutex_lock(&resourceLock);
+ }
}
+ (void) lockInFunction:(char *)func atLine:(int)line
{
- if (theContext != NULL)
- {
- printLockDebugInfo("locked ", func, line);
- [self lock];
- }
+ if (theContext != NULL)
+ {
+ printLockDebugInfo("locked ", func, line);
+ [self lock];
+ }
}
+ (void) unlock
{
- if (theContext != NULL)
- {
- pthread_mutex_unlock(&resourceLock);
- }
+ if (theContext != NULL)
+ {
+ pthread_mutex_unlock(&resourceLock);
+ }
}
+ (void) unlockInFunction:(char *)func atLine:(int)line
{
- if (theContext != NULL)
- {
- printLockDebugInfo("unlocked", func, line);
- [self unlock];
- }
+ 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;
- }
+ 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];
+ [ContextUpdater lock];
+
+ [theContext update];
+
+ [ContextUpdater unlock];
}
- (id) init
-{
- theContext = NULL;
-
- return [super init];
+{
+ theContext = NULL;
+
+ return [super init];
}
- (void) dealloc
{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
-
- [super dealloc];
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+
+ [super dealloc];
}
@end \ No newline at end of file
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
index cbfea6d71..9a7356b7c 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
@@ -5,7 +5,7 @@
#include <AvailabilityMacros.h>
#ifndef MAC_OS_X_VERSION_10_3
- #error building JOGL requires Mac OS X 10.3 or greater
+ #error building JOGL requires Mac OS X 10.3 or greater
#endif
#ifndef MAC_OS_X_VERSION_10_4
@@ -44,45 +44,45 @@
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;
+ 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;
@@ -90,263 +90,263 @@ 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
- };
+ 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};
+ 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
+ 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));
+ 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);
- }
-
+ 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");
- }
+ 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
}
@@ -368,7 +368,7 @@ long validateParameter(NSOpenGLPixelFormatAttribute attribute, long value)
}
}
}
-
+
return value;
}
@@ -472,66 +472,66 @@ void* createContext(void* shareContext,
void* pixelFormat,
int* viewNotReady)
{
- getRendererInfo();
-
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ getRendererInfo();
+
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- NSView *nsView = NULL;
+ 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]
+ 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];
+ [nsView unlockFocus];
}
}
- [pool release];
- return nsContext;
+ [pool release];
+ return nsContext;
}
void * getCurrentContext() {
NSOpenGLContext *nsContext = NULL;
-
+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
nsContext = [NSOpenGLContext currentContext];
[pool release];
@@ -541,7 +541,7 @@ void * getCurrentContext() {
void * getCGLContext(void* nsJContext) {
NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
void * cglContext = NULL;
-
+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
cglContext = [nsContext CGLContextObj];
[pool release];
@@ -551,7 +551,7 @@ void * getCGLContext(void* nsJContext) {
void * getNSView(void* nsJContext) {
NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
void * view = NULL;
-
+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
view = [nsContext view];
[pool release];
@@ -560,7 +560,7 @@ void * getNSView(void* nsJContext) {
Bool makeCurrentContext(void* nsJContext) {
NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[nsContext makeCurrentContext];
[pool release];
@@ -582,7 +582,7 @@ Bool clearCurrentContext(void* nsJContext) {
Bool deleteContext(void* nsJContext) {
NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[nsContext clearDrawable];
[nsContext release];
@@ -592,7 +592,7 @@ Bool deleteContext(void* nsJContext) {
Bool flushBuffer(void* nsJContext) {
NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[nsContext flushBuffer];
[pool release];
@@ -607,7 +607,7 @@ void setContextOpacity(void* nsJContext, int opacity) {
void updateContext(void* nsJContext) {
NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[nsContext update];
[pool release];
@@ -622,7 +622,7 @@ void copyContext(void* destContext, void* srcContext, int 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];
@@ -632,7 +632,7 @@ void* updateContextRegister(void* nsJContext, void* view) {
void updateContextUnregister(void* updater) {
ContextUpdater *contextUpdater = (ContextUpdater *)updater;
-
+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[contextUpdater release];
[pool release];
@@ -653,7 +653,7 @@ void* createPBuffer(int renderTarget, int internalFormat, int width, int height)
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) {
@@ -662,7 +662,7 @@ Bool destroyPBuffer(void* buffer) {
*/
[pBuffer release];
[pool release];
-
+
return true;
}
@@ -701,21 +701,21 @@ void* getProcAddress(const char *procname) {
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) {
+
+ 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);
diff --git a/src/jogl/native/openmax/omx_tool.c b/src/jogl/native/openmax/omx_tool.c
index c6b6494e2..57fa8ad21 100644
--- a/src/jogl/native/openmax/omx_tool.c
+++ b/src/jogl/native/openmax/omx_tool.c
@@ -199,10 +199,10 @@ static OMX_ERRORTYPE EventHandler(
if (pOMXAV->endComponent == hComponent)
{
DBG_PRINT("\t end component - FIN\n");
- pOMXAV->status = OMXAV_FIN;
+ pOMXAV->status = OMXAV_FIN;
}
- }
- break;
+ }
+ break;
case OMX_EventError:
{
if (nData1 == OMX_ErrorIncorrectStateTransition)
@@ -1053,11 +1053,11 @@ void OMXToolBasicAV_SetStream(OMXToolBasicAV_t * pOMXAV, int vBufferNum, const K
{
OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE oActiveClockType;
- INIT_PARAM(oActiveClockType);
- oActiveClockType.eClock = (pOMXAV->audioPort != -1) ?
+ 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));
+ &oActiveClockType));
}
OMXSAFEVOID(OMX_SendCommand(pOMXAV->comp[OMXAV_H_CLOCK], OMX_CommandPortDisable, (OMX_U32) -1, 0));