cleaning up line classes

This commit is contained in:
benfry
2012-05-18 19:57:40 +00:00
parent d3983b70c8
commit 4eb708dacb
5 changed files with 88 additions and 185 deletions
@@ -1453,15 +1453,15 @@ public class PGraphicsOpenGL extends PGraphics {
if (primarySurface) {
int[] temp = new int[1];
pgl.glGetIntegerv(PGL.GL_SAMPLES, temp, 0);
if (antialias != temp[0] && 1 < temp[0] && 1 < antialias) {
antialias = temp[0];
if (quality != temp[0] && 1 < temp[0] && 1 < quality) {
quality = temp[0];
}
}
if (antialias < 2) {
if (quality < 2) {
pgl.glDisable(PGL.GL_MULTISAMPLE);
pgl.glEnable(PGL.GL_POINT_SMOOTH);
pgl.glEnable(PGL.GL_LINE_SMOOTH);
pgl.glEnable(PGL.GL_POLYGON_SMOOTH);
// pgl.glEnable(PGL.GL_POINT_SMOOTH);
// pgl.glEnable(PGL.GL_LINE_SMOOTH);
// pgl.glEnable(PGL.GL_POLYGON_SMOOTH);
} else {
pgl.glEnable(PGL.GL_MULTISAMPLE);
pgl.glDisable(PGL.GL_POINT_SMOOTH);
@@ -1647,11 +1647,11 @@ public class PGraphicsOpenGL extends PGraphics {
}
pgl.glDepthFunc(PGL.GL_LEQUAL);
if (antialias < 2) {
if (quality < 2) {
pgl.glDisable(PGL.GL_MULTISAMPLE);
pgl.glEnable(PGL.GL_POINT_SMOOTH);
pgl.glEnable(PGL.GL_LINE_SMOOTH);
pgl.glEnable(PGL.GL_POLYGON_SMOOTH);
// pgl.glEnable(PGL.GL_POINT_SMOOTH);
// pgl.glEnable(PGL.GL_LINE_SMOOTH);
// pgl.glEnable(PGL.GL_POLYGON_SMOOTH);
} else {
pgl.glEnable(PGL.GL_MULTISAMPLE);
pgl.glDisable(PGL.GL_POINT_SMOOTH);
@@ -3099,10 +3099,10 @@ public class PGraphicsOpenGL extends PGraphics {
level = maxSamples;
}
if (antialias != level) {
antialias = level;
if (antialias == 1) {
antialias = 0;
if (quality != level) {
quality = level;
if (quality == 1) {
quality = 0;
}
// This will trigger a surface restart next time
// requestDraw() is called.
@@ -3114,8 +3114,8 @@ public class PGraphicsOpenGL extends PGraphics {
public void noSmooth() {
smooth = false;
if (1 < antialias) {
antialias = 0;
if (1 < quality) {
quality = 0;
// This will trigger a surface restart next time
// requestDraw() is called.
pgl.initialized = false;
@@ -5615,7 +5615,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected void initPrimary() {
pgl.initPrimarySurface(antialias);
pgl.initPrimarySurface(quality);
pg = this;
}
@@ -5638,8 +5638,8 @@ public class PGraphicsOpenGL extends PGraphics {
offscreenFramebufferMultisample.release();
}
if (PGraphicsOpenGL.fboMultisampleSupported && 1 < antialias) {
offscreenFramebufferMultisample = new PFramebuffer(parent, texture.glWidth, texture.glHeight, antialias, 0,
if (PGraphicsOpenGL.fboMultisampleSupported && 1 < quality) {
offscreenFramebufferMultisample = new PFramebuffer(parent, texture.glWidth, texture.glHeight, quality, 0,
depthBits, stencilBits,
depthBits == 24 && stencilBits == 8 && packedDepthStencilSupported, false);
@@ -5653,7 +5653,7 @@ public class PGraphicsOpenGL extends PGraphics {
false, false);
} else {
antialias = 0;
quality = 0;
offscreenFramebuffer = new PFramebuffer(parent, texture.glWidth, texture.glHeight, 1, 1,
depthBits, stencilBits,
depthBits == 24 && stencilBits == 8 && packedDepthStencilSupported, false);
@@ -392,7 +392,8 @@ public class LinePath {
float miterlimit, PMatrix2D transform) {
final LinePath dest = new LinePath();
strokeTo(src, weight, caps, join, miterlimit, transform, new LineSink() {
// strokeTo(src, weight, caps, join, miterlimit, transform, new LineSink() {
strokeTo(src, weight, caps, join, miterlimit, transform, new LineStroker() {
public void moveTo(int x0, int y0) {
dest.moveTo(S15_16ToFloat(x0), S15_16ToFloat(y0));
}
@@ -418,7 +419,8 @@ public class LinePath {
private static void strokeTo(LinePath src, float width, int caps, int join,
float miterlimit, PMatrix2D transform,
LineSink lsink) {
// LineSink lsink) {
LineStroker lsink) {
lsink = new LineStroker(lsink, FloatToS15_16(width), caps, join,
FloatToS15_16(miterlimit),
transform == null ? identity : transform);
@@ -428,7 +430,8 @@ public class LinePath {
}
private static void pathTo(PathIterator pi, LineSink lsink) {
// private static void pathTo(PathIterator pi, LineSink lsink) {
private static void pathTo(PathIterator pi, LineStroker lsink) {
float coords[] = new float[2];
while (!pi.isDone()) {
switch (pi.currentSegment(coords)) {
@@ -1,85 +0,0 @@
/*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package processing.opengl.geom;
/**
* The <code>LineSink</code> interface accepts a series of line
* drawing commands: <code>moveTo</code>, <code>lineTo</code>,
* <code>close</code> (equivalent to a <code>lineTo</code> command
* with an argument equal to the argument of the last
* <code>moveTo</code> command), and <code>end</code>.
*
*/
public abstract class LineSink {
/**
* Moves the current drawing position to the point <code>(x0,
* y0)</code>.
*
* @param x0 the X coordinate in S15.16 format
* @param y0 the Y coordinate in S15.16 format
*/
public abstract void moveTo(int x0, int y0);
/**
* Provides a hint that the current segment should be joined to
* the following segment using an explicit miter or round join if
* required.
*
* <p> An application-generated path will generally have no need
* to contain calls to this method; they are typically introduced
* by a <code>Flattener</code> to mark segment divisions that
* appear in its input, and consumed by a <code>Stroker</code>
* that is responsible for emitting the miter or round join
* segments.
*
* <p> Other <code>LineSink</code> classes should simply pass this
* hint to their output sink as needed.
*/
public abstract void lineJoin();
/**
* Draws a line from the current drawing position to the point
* <code>(x1, y1)</code> and sets the current drawing position to
* <code>(x1, y1)</code>.
*
* @param x1 the X coordinate in S15.16 format
* @param y1 the Y coordinate in S15.16 format
*/
public abstract void lineTo(int x1, int y1);
/**
* Closes the current path by drawing a line from the current
* drawing position to the point specified by the moset recent
* <code>moveTo</code> command.
*/
public abstract void close();
/**
* Ends the current path. It may be necessary to end a path in
* order to allow end caps to be drawn.
*/
public abstract void end();
}
@@ -27,24 +27,17 @@ package processing.opengl.geom;
import processing.core.PMatrix2D;
public class LineStroker extends LineSink {
LineSink output;
int lineWidth;
int capStyle;
int joinStyle;
int miterLimit;
int m00, m01;
int m10, m11;
int lineWidth2;
long scaledLineWidth2;
public class LineStroker /*extends LineSink*/ {
// private LineSink output;
private LineStroker output;
// private int lineWidth;
private int capStyle;
private int joinStyle;
// private int miterLimit;
private int m00, m01;
private int m10, m11;
private int lineWidth2;
private long scaledLineWidth2;
// For any pen offset (pen_dx, pen_dy) that does not depend on
// the line orientation, the pen should be transformed so that:
@@ -59,45 +52,30 @@ public class LineStroker extends LineSink {
//
// pen_dx'(r, theta) = r*(m00*cos(theta) + m01*sin(theta))
// pen_dy'(r, theta) = r*(m10*cos(theta) + m11*sin(theta))
int numPenSegments;
private int numPenSegments;
private int[] pen_dx;
private int[] pen_dy;
int[] pen_dx;
int[] pen_dy;
boolean[] penIncluded;
int[] join;
int[] offset = new int[2];
int[] reverse = new int[100];
int[] miter = new int[2];
long miterLimitSq;
int prev;
int rindex;
boolean started;
boolean lineToOrigin;
boolean joinToOrigin;
int sx0, sy0, sx1, sy1, x0, y0, x1, y1;
int mx0, my0, mx1, my1, omx, omy;
int lx0, ly0, lx1, ly1, lx0p, ly0p, px0, py0;
double m00_2_m01_2;
double m10_2_m11_2;
double m00_m10_m01_m11;
private boolean[] penIncluded;
private int[] join;
private int[] offset = new int[2];
private int[] reverse = new int[100];
private int[] miter = new int[2];
private long miterLimitSq;
private int prev;
private int rindex;
private boolean started;
private boolean lineToOrigin;
private boolean joinToOrigin;
// private int sx0, sy0, sx1, sy1, x0, y0, x1, y1;
// private int mx0, my0, mx1, my1, omx, omy;
// private int lx0, ly0, lx1, ly1, lx0p, ly0p, px0, py0;
private int sx0, sy0, sx1, sy1, x0, y0;
private int mx0, my0, omx, omy;
private int px0, py0;
private double m00_2_m01_2;
private double m10_2_m11_2;
private double m00_m10_m01_m11;
/**
* Empty constructor. <code>setOutput</code> and <code>setParameters</code>
@@ -127,7 +105,8 @@ public class LineStroker extends LineSink {
* required in order to produce consistently shaped end caps and
* joins.
*/
public LineStroker(LineSink output, int lineWidth, int capStyle, int joinStyle,
// public LineStroker(LineSink output, int lineWidth, int capStyle, int joinStyle,
public LineStroker(LineStroker output, int lineWidth, int capStyle, int joinStyle,
int miterLimit, PMatrix2D transform) {
setOutput(output);
setParameters(lineWidth, capStyle, joinStyle, miterLimit, transform);
@@ -139,7 +118,8 @@ public class LineStroker extends LineSink {
* @param output
* an output <code>LineSink</code>.
*/
public void setOutput(LineSink output) {
// public void setOutput(LineSink output) {
public void setOutput(LineStroker output) {
this.output = output;
}
@@ -169,12 +149,12 @@ public class LineStroker extends LineSink {
this.m10 = LinePath.FloatToS15_16(transform.m10);
this.m11 = LinePath.FloatToS15_16(transform.m11);
this.lineWidth = lineWidth;
// this.lineWidth = lineWidth;
this.lineWidth2 = lineWidth >> 1;
this.scaledLineWidth2 = ((long) m00 * lineWidth2) >> 16;
this.capStyle = capStyle;
this.joinStyle = joinStyle;
this.miterLimit = miterLimit;
// this.miterLimit = miterLimit;
this.m00_2_m01_2 = (double) m00 * m00 + (double) m01 * m01;
this.m10_2_m11_2 = (double) m10 * m10 + (double) m11 * m11;
@@ -203,7 +183,7 @@ public class LineStroker extends LineSink {
for (int i = 0; i < numPenSegments; i++) {
double r = lineWidth / 2.0;
double theta = (double) i * 2.0 * Math.PI / numPenSegments;
double theta = i * 2 * Math.PI / numPenSegments;
double cos = Math.cos(theta);
double sin = Math.sin(theta);
@@ -528,12 +508,12 @@ public class LineStroker extends LineSink {
emitLineTo(x0 - mx, y0 - my, true);
emitLineTo(x1 - mx, y1 - my, true);
lx0 = x1 + mx;
ly0 = y1 + my;
lx0p = x1 - mx;
ly0p = y1 - my;
lx1 = x1;
ly1 = y1;
// lx0 = x1 + mx;
// ly0 = y1 + my;
// lx0p = x1 - mx;
// ly0p = y1 - my;
// lx1 = x1;
// ly1 = y1;
this.omx = mx;
this.omy = my;
@@ -639,8 +619,8 @@ public class LineStroker extends LineSink {
long lineLength(long ldx, long ldy) {
long ldet = ((long) m00 * m11 - (long) m01 * m10) >> 16;
long la = ((long) ldy * m00 - (long) ldx * m10) / ldet;
long lb = ((long) ldy * m01 - (long) ldx * m11) / ldet;
long la = (ldy * m00 - ldx * m10) / ldet;
long lb = (ldy * m01 - ldx * m11) / ldet;
long llen = (int) LinePath.hypot(la, lb);
return llen;
}
@@ -650,8 +630,8 @@ public class LineStroker extends LineSink {
drawRoundJoin(x0, y0, omx, omy, -omx, -omy, 1, false, false,
ROUND_JOIN_THRESHOLD);
} else if (capStyle == LinePath.CAP_SQUARE) {
long ldx = (long) (px0 - x0);
long ldy = (long) (py0 - y0);
long ldx = px0 - x0;
long ldy = py0 - y0;
long llen = lineLength(ldx, ldy);
if (0 < llen) {
long s = (long) lineWidth2 * 65536 / llen;
@@ -673,8 +653,8 @@ public class LineStroker extends LineSink {
drawRoundJoin(sx0, sy0, -mx0, -my0, mx0, my0, 1, false, false,
ROUND_JOIN_THRESHOLD);
} else if (capStyle == LinePath.CAP_SQUARE) {
long ldx = (long) (sx1 - sx0);
long ldy = (long) (sy1 - sy0);
long ldx = sx1 - sx0;
long ldy = sy1 - sy0;
long llen = lineLength(ldx, ldy);
if (0 < llen) {
long s = (long) lineWidth2 * 65536 / llen;