Merge branch 'processing:master' into merging-all-test

This commit is contained in:
codeanticode
2022-01-22 17:28:28 -05:00
committed by GitHub
212 changed files with 7733 additions and 8027 deletions
+23 -17
View File
@@ -102,8 +102,6 @@ public class PGraphicsJava2D extends PGraphics {
public boolean strokeGradient;
public Paint strokeGradientObject;
Font fontObject;
//////////////////////////////////////////////////////////////
@@ -353,8 +351,11 @@ public class PGraphicsJava2D extends PGraphics {
g2.setStroke(strokeObject);
}
// https://github.com/processing/processing/issues/2617
if (fontObject != null) {
g2.setFont(fontObject);
if (textFont != null) {
Font fontObject = (Font) textFont.getNative();
if (fontObject != null) {
g2.setFont(fontObject);
}
}
// https://github.com/processing/processing/issues/4019
if (blendMode != 0) {
@@ -1030,7 +1031,6 @@ public class PGraphicsJava2D extends PGraphics {
*
* @webref Rendering
* @webBrief Blends the pixels in the display window according to a defined mode
* @param mode the blending mode to use
*/
@Override
protected void blendModeImpl() {
@@ -1902,7 +1902,6 @@ public class PGraphicsJava2D extends PGraphics {
Font font = (Font) textFont.getNative();
if (font != null) {
//return getFontMetrics(font).getAscent();
return g2.getFontMetrics(font).getAscent();
}
return super.textAscent();
@@ -1916,7 +1915,6 @@ public class PGraphicsJava2D extends PGraphics {
}
Font font = (Font) textFont.getNative();
if (font != null) {
//return getFontMetrics(font).getDescent();
return g2.getFontMetrics(font).getDescent();
}
return super.textDescent();
@@ -1951,21 +1949,17 @@ public class PGraphicsJava2D extends PGraphics {
protected void handleTextSize(float size) {
// if a native version available, derive this font
Font font = (Font) textFont.getNative();
// don't derive again if the font size has not changed
if (font != null) {
// don't derive again if the font size has not changed
if (font.getSize2D() != size) {
Map<TextAttribute, Object> map =
new HashMap<>();
Map<TextAttribute, Object> map = new HashMap<>();
map.put(TextAttribute.SIZE, size);
map.put(TextAttribute.KERNING,
TextAttribute.KERNING_ON);
// map.put(TextAttribute.TRACKING,
// TextAttribute.TRACKING_TIGHT);
map.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
// map.put(TextAttribute.TRACKING, TextAttribute.TRACKING_TIGHT);
font = font.deriveFont(map);
}
g2.setFont(font);
textFont.setNative(font);
fontObject = font;
/*
Map<TextAttribute, ?> attrs = font.getAttributes();
@@ -2061,8 +2055,20 @@ public class PGraphicsJava2D extends PGraphics {
protected void textLineImpl(char[] buffer, int start, int stop,
float x, float y) {
Font font = (Font) textFont.getNative();
// if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) {
if (font != null) {
// If using the default font, warn the user when their code calls
// text() called with unavailable characters. Not done with all
// fonts because it would be too slow, but useful/acceptable for
// the default case because it will hit beginners/casual use.
if (textFont.getName().equals(defaultFontName)) {
if (font.canDisplayUpTo(buffer, start, stop) != -1) {
final String msg =
"Some characters not available in the current font, " +
"use createFont() to specify a typeface the includes them.";
showWarning(msg);
}
}
/*
// save the current setting for text smoothing. note that this is
// different from the smooth() function, because the font smoothing
@@ -2115,7 +2121,7 @@ public class PGraphicsJava2D extends PGraphics {
//g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textAntialias);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialias);
} else { // otherwise just do the default
} else { // otherwise, just do the default
super.textLineImpl(buffer, start, stop, x, y);
}
}
+90 -115
View File
@@ -81,7 +81,7 @@ import processing.opengl.*;
* project of our (tiny) size, we should be focusing on the future, rather
* than working around legacy Java code.
*/
@SuppressWarnings({"unused", "FinalStaticMethod"})
@SuppressWarnings({"unused", "FinalStaticMethod", "ManualMinMaxCalculation"})
public class PApplet implements PConstants {
//public class PApplet extends PSketch { // possible in the next alpha
/** Full name of the Java version (i.e. 1.5.0_11). */
@@ -141,8 +141,8 @@ public class PApplet implements PConstants {
public PGraphics g;
/**
* System variable that stores the width of the computer screen. For
* example, if the current screen resolution is 1920x1080,
* System variable that stores the width of the computer screen.
* For example, if the current screen resolution is 1920x1080,
* <b>displayWidth</b> is 1920 and <b>displayHeight</b> is 1080.
*
* @webref environment
@@ -153,8 +153,8 @@ public class PApplet implements PConstants {
public int displayWidth;
/**
* System variable that stores the height of the computer screen. For
* example, if the current screen resolution is 1920x1080,
* System variable that stores the height of the computer screen.
* For example, if the current screen resolution is 1920x1080,
* <b>displayWidth</b> is 1920 and <b>displayHeight</b> is 1080.
*
* @webref environment
@@ -175,12 +175,11 @@ public class PApplet implements PConstants {
public String[] args;
/**
* Path to sketch folder. Previously undocumented, made private in 3.0a5
* so that people use the sketchPath() method and it's initialized properly.
* Call sketchPath() once to set the default.
* Path to sketch folder. Previously undocumented, and made private
* in 3.0 alpha 5 so that people use the sketchPath() method which
* will initialize it properly. Call sketchPath() once to set it.
*/
private String sketchPath;
// public String sketchPath;
static final boolean DEBUG = false;
// static final boolean DEBUG = true;
@@ -190,7 +189,6 @@ public class PApplet implements PConstants {
static public final int DEFAULT_HEIGHT = 100;
/**
*
* The <b>pixels[]</b> array contains the values for all the pixels in the
* display window. These values are of the color datatype. This array is
* defined by the size of the display window. For example, if the window is
@@ -275,7 +273,6 @@ public class PApplet implements PConstants {
/**
*
* When <b>pixelDensity(2)</b> is used to make use of a high resolution
* display (called a Retina display on OS X or high-dpi on Windows and
* Linux), the width and height of the sketch do not change, but the
@@ -301,7 +298,6 @@ public class PApplet implements PConstants {
protected boolean keyRepeatEnabled = false;
/**
*
* The system variable <b>mouseX</b> always contains the current horizontal
* coordinate of the mouse.
* <br /><br />
@@ -325,15 +321,12 @@ public class PApplet implements PConstants {
* @see PApplet#mouseDragged()
* @see PApplet#mouseButton
* @see PApplet#mouseWheel(MouseEvent)
*
*
*/
public int mouseX;
/**
*
* The system variable <b>mouseY</b> always contains the current vertical
* coordinate of the mouse.
* The system variable <b>mouseY</b> always contains the current
* vertical coordinate of the mouse.
* <br /><br />
* Note that Processing can only track the mouse position when the pointer
* is over the current window. The default value of <b>mouseY</b> is <b>0</b>,
@@ -360,7 +353,6 @@ public class PApplet implements PConstants {
public int mouseY;
/**
*
* The system variable <b>pmouseX</b> always contains the horizontal
* position of the mouse in the frame previous to the current frame.<br />
* <br />
@@ -398,7 +390,6 @@ public class PApplet implements PConstants {
public int pmouseX;
/**
*
* The system variable <b>pmouseY</b> always contains the vertical position
* of the mouse in the frame previous to the current frame. More detailed
* information about how <b>pmouseY</b> is updated inside of <b>draw()</b>
@@ -452,7 +443,6 @@ public class PApplet implements PConstants {
public boolean firstMouse = true;
/**
*
* When a mouse button is pressed, the value of the system variable
* <b>mouseButton</b> is set to either <b>LEFT</b>, <b>RIGHT</b>, or
* <b>CENTER</b>, depending on which button is pressed. (If no button is
@@ -464,7 +454,7 @@ public class PApplet implements PConstants {
*
* <h3>Advanced:</h3>
*
* If running on Mac OS, a ctrl-click will be interpreted as the right-hand
* If running on macOS, a ctrl-click will be interpreted as the right-hand
* mouse button (unlike Java, which reports it as the left mouse).
* @webref input:mouse
* @webBrief Shows which mouse button is pressed
@@ -483,7 +473,6 @@ public class PApplet implements PConstants {
public int mouseButton;
/**
*
* The <b>mousePressed()</b> function is called once after every time a
* mouse button is pressed. The <b>mouseButton</b> variable (see the
* related reference entry) can be used to determine which button has
@@ -509,12 +498,12 @@ public class PApplet implements PConstants {
*/
public boolean mousePressed;
// MACOSX: CTRL + Left Mouse is converted to Right Mouse. This boolean keeps
// track of whether the conversion happened on PRESS, because we should report
// the same button during DRAG and on RELEASE, even though CTRL might have
// been released already. Otherwise the events are inconsistent, e.g.
// Left Pressed - Left Drag - CTRL Pressed - Right Drag - Right Released.
// See: https://github.com/processing/processing/issues/5672
// macOS: Ctrl + Left Mouse is converted to Right Mouse.
// This boolean tracks whether the conversion happened on PRESS,
// to report the same button during DRAG and on RELEASE,
// even though CTRL might have been released already.
// Otherwise, the events are inconsistent.
// https://github.com/processing/processing/issues/5672
private boolean macosCtrlClick;
@@ -523,7 +512,6 @@ public class PApplet implements PConstants {
public MouseEvent mouseEvent;
/**
*
* The system variable <b>key</b> always contains the value of the most
* recent key on the keyboard that was used (either pressed or released).
* <br/> <br/>
@@ -558,7 +546,6 @@ public class PApplet implements PConstants {
public char key;
/**
*
* The variable <b>keyCode</b> is used to detect special keys such as the
* UP, DOWN, LEFT, RIGHT arrow keys and ALT, CONTROL, SHIFT.
* <br /><br />
@@ -580,10 +567,10 @@ public class PApplet implements PConstants {
* <a href="https://docs.oracle.com/javase/8/docs/api/java/awt/event/KeyEvent.html">KeyEvent</a>
* reference.
* <br /><br />
* There are issues with how <b>keyCode</b> behaves across different renderers
* and operating systems. Watch out for unexpected behavior as you switch
* renderers and operating systems and you are using keys are aren't mentioned
* in this reference entry.
* There are issues with how <b>keyCode</b> behaves across different
* renderers and operating systems. Watch out for unexpected behavior
* as you switch renderers and operating systems, and also whenever
* you are using keys not mentioned in this reference entry.
* <br /><br />
* If you are using P2D or P3D as your renderer, use the
* <a href="https://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/newt/event/KeyEvent.html">NEWT KeyEvent constants</a>.
@@ -593,7 +580,7 @@ public class PApplet implements PConstants {
* When "key" is set to CODED, this will contain a Java key code.
* <p>
* For the arrow keys, keyCode will be one of UP, DOWN, LEFT and RIGHT.
* Also available are ALT, CONTROL and SHIFT. A full set of constants
* ALT, CONTROL and SHIFT are also available. A full set of constants
* can be obtained from java.awt.event.KeyEvent, from the VK_XXXX variables.
*
* @webref input:keyboard
@@ -606,9 +593,8 @@ public class PApplet implements PConstants {
public int keyCode;
/**
*
* The boolean system variable <b>keyPressed</b> is <b>true</b> if any key
* is pressed and <b>false</b> if no keys are pressed.
* The boolean system variable <b>keyPressed</b> is <b>true</b>
* if any key is pressed and <b>false</b> if no keys are pressed.
* <br /><br />
* Note that there is a similarly named function called <b>keyPressed()</b>.
* See its reference page for more information.
@@ -642,17 +628,6 @@ public class PApplet implements PConstants {
*/
public boolean focused = false;
// /**
// * Confirms if a Processing program is running inside a web browser. This
// * variable is "true" if the program is online and "false" if not.
// */
// @Deprecated
// public boolean online = false;
// // This is deprecated because it's poorly named (and even more poorly
// // understood). Further, we'll probably be removing applets soon, in which
// // case this won't work at all. If you want this feature, you can check
// // whether getAppletContext() returns null.
/**
* Time in milliseconds when the applet was started.
* <p>
@@ -681,10 +656,9 @@ public class PApplet implements PConstants {
protected boolean redraw = true;
/**
*
* The system variable <b>frameCount</b> contains the number of frames
* displayed since the program started. Inside <b>setup()</b> the value is
* 0 and and after the first iteration of draw it is 1, etc.
* The system variable <b>frameCount</b> contains the number o
* frames displayed since the program started. Inside <b>setup()</b>
* the value is 0 and during the first iteration of draw it is 1, etc.
*
* @webref environment
* @webBrief The system variable that contains the number of frames
@@ -700,12 +674,6 @@ public class PApplet implements PConstants {
/** used by the UncaughtExceptionHandler, so has to be static */
static Throwable uncaughtThrowable;
// public, but undocumented.. removing for 3.0a5
// /**
// * true if the animation thread is paused.
// */
// public volatile boolean paused;
/**
* true if exit() has been called so that things shut down
* once the main thread kicks off.
@@ -834,7 +802,7 @@ public class PApplet implements PConstants {
/**
* @param method "size" or "fullScreen"
* @param args parameters passed to the function so we can show the user
* @param args parameters passed to the function to show the user
* @return true if safely inside the settings() method
*/
boolean insideSettings(String method, Object... args) {
@@ -895,17 +863,25 @@ public class PApplet implements PConstants {
} catch (InterruptedException ignored) { }
if (resultCode == 1) {
System.err.println("Could not check the status of “Displays have separate spaces.”");
System.err.format("Received message '%s' and result code %d.%n", trim(stderr.toString()), resultCode);
String msg = trim(stderr.toString());
// This message is confusing, so don't print if it's something typical
if (!(msg.contains("The domain/default pair") && msg.contains("does not exist"))) {
System.err.println("Could not check the status of “Displays have separate spaces.”");
System.err.println("Result for 'defaults read' was " + resultCode);
System.err.println(msg);
}
}
String processOutput = trim(stdout.toString());
// It looks like on Catalina, the option may not be set, so resultCode
// will be 1 (an error, since the param doesn't exist. But "Displays
// have separate spaces" is on by default, so show the message.
// On Catalina, the option may not be set, so resultCode
// will be 1 (an error, since the param doesn't exist.)
// But "Displays have separate spaces" is on by default.
// For Monterey, it appears to not be set until the user
// has visited the Mission Control preference pane once.
if (resultCode == 1 || "0".equals(processOutput)) {
System.err.println("To use fullScreen(SPAN), first turn off “Displays have separate spaces”");
System.err.println("in System Preferences \u2192 Mission Control. Then log out and log back in.");
System.err.println("To use fullScreen(SPAN), visit System Preferences \u2192 Mission Control");
System.err.println("and make sure that “Displays have separate spaces” is turned off.");
System.err.println("Then log out and log back in.");
}
}
@@ -914,32 +890,31 @@ public class PApplet implements PConstants {
/**
*
* The <b>settings()</b> function is new with Processing 3.0.
* It's not needed in most sketches. It's only useful when it's
* absolutely necessary to define the parameters to <b>size()</b>
* with a variable. Alternately, the <b>settings()</b> function
* is necessary when using Processing code outside of the
* Processing Development Environment (PDE). For example, when
* using the Eclipse code editor, it's necessary to use
* <b>settings()</b> to define the <b>size()</b> and
* <b>smooth()</b> values for a sketch.</b>.
* <br /> <br />
* The <b>settings()</b> method runs before the sketch has been
* set up, so other Processing functions cannot be used at that
* point. For instance, do not use loadImage() inside settings().
* The settings() method runs "passively" to set a few variables,
* compared to the <b>setup()</b> command that call commands in
* the Processing API.
*
* @webref environment
* @webBrief Used when absolutely necessary to define the parameters to <b>size()</b>
* with a variable
* @see PApplet#fullScreen()
* @see PApplet#setup()
* @see PApplet#size(int,int)
* @see PApplet#smooth()
*/
* The <b>settings()</b> function is new with Processing 3.0.
* It's not needed in most sketches. It's only useful when it's
* absolutely necessary to define the parameters to <b>size()</b>
* with a variable. Alternately, the <b>settings()</b> function
* is necessary when using Processing code outside the
* Processing Development Environment (PDE). For example, when
* using the Eclipse code editor, it's necessary to use
* <b>settings()</b> to define the <b>size()</b> and
* <b>smooth()</b> values for a sketch.</b>.
* <br /> <br />
* The <b>settings()</b> method runs before the sketch has been
* set up, so other Processing functions cannot be used at that
* point. For instance, do not use loadImage() inside settings().
* The settings() method runs "passively" to set a few variables,
* compared to the <b>setup()</b> command that call commands in
* the Processing API.
*
* @webref environment
* @webBrief Used when absolutely necessary to define the parameters to <b>size()</b>
* with a variable
* @see PApplet#fullScreen()
* @see PApplet#setup()
* @see PApplet#size(int,int)
* @see PApplet#smooth()
*/
public void settings() {
// is this necessary? (doesn't appear to be, so removing)
//size(DEFAULT_WIDTH, DEFAULT_HEIGHT, JAVA2D);
@@ -1062,21 +1037,20 @@ public class PApplet implements PConstants {
/**
* This function is new with Processing 3.0. It makes it
* possible for Processing to render using all of the
* pixels on high resolutions screens like Apple Retina
* displays and Windows High-DPI displays. This function
* can only be run once within a program and it must be
* used right after <b>size()</b> in a program without a <b>setup()</b>
* and used within <b>setup()</b> when a program has one. The
* This function makes it possible to render using all the pixels
* on high resolutions screens like Apple Retina and Windows HiDPI.
* This function can only be run once within a program, and must
* be called right after <b>size()</b> in a program without a
* <b>setup()</b> function, or within <b>setup()</b> if present.
*
* <b>pixelDensity()</b> should only be used with hardcoded
* numbers (in almost all cases this number will be 2)
* or in combination with <b>displayDensity()</b> as in the
* third example above.
*
* When the pixel density is set to more than 1, it
* changes all of the pixel operations including the way
* <b>get()</b>, <b>set()</b>, <b>blend()</b>, <b>copy()</b>, and <b>updatePixels()</b>
* When the pixel density is set to more than 1, it changes the
* pixel operations including the way <b>get()</b>, <b>set()</b>,
* <b>blend()</b>, <b>copy()</b>, and <b>updatePixels()</b>
* all work. See the reference for <b>pixelWidth</b> and
* pixelHeight for more information.
*
@@ -1086,7 +1060,7 @@ public class PApplet implements PConstants {
* about this on the <b>settings()</b> reference page.
*
* @webref environment
* @webBrief It makes it possible for Processing to render using all of the
* @webBrief It makes it possible for Processing to render using all the
* pixels on high resolutions screens
* @param density 1 or 2
* @see PApplet#pixelWidth
@@ -1394,7 +1368,7 @@ public class PApplet implements PConstants {
} else {
t = e;
}
// check for RuntimeException, and allow to bubble up
// check for RuntimeException, and allow it to bubble up
if (t instanceof RuntimeException) {
// re-throw exception
throw (RuntimeException) t;
@@ -1435,7 +1409,7 @@ public class PApplet implements PConstants {
entries.remove(object);
methods.remove(object);
} else {
// Currently iterating the list of methods, remove this afterwards
// Iterates the list of methods, remove this afterwards
removals.add(object);
}
}
@@ -4603,7 +4577,7 @@ public class PApplet implements PConstants {
* returned as a <b>float</b> in the range from <b>PI</b> to <b>-PI</b>.
* The <b>atan2()</b> function is most often used for orienting geometry to
* the position of the cursor. Note: The y-coordinate of the point is the
* first parameter and the x-coordinate is the second due the the structure
* first parameter and the x-coordinate is the second due the structure
* of calculating the tangent.
*
* @webref math:trigonometry
@@ -4773,7 +4747,7 @@ public class PApplet implements PConstants {
* Normalizes a number from another range into a value between 0 and 1.
* Identical to <b>map(value, low, high, 0, 1)</b>.<br />
* <br />
* Numbers outside of the range are not clamped to 0 and 1, because
* Numbers outside the range are not clamped to 0 and 1, because
* out-of-range values are often intentional and useful. (See the second
* example above.)
*
@@ -4801,9 +4775,9 @@ public class PApplet implements PConstants {
* range of 0 to 100 into a value that ranges from the left edge of the window
* (0) to the right edge (width).<br />
* <br />
* As shown in the second example, numbers outside of the range are not
* clamped to the minimum and maximum parameters values, because out-of-range
* values are often intentional and useful.
* As shown in the second example, numbers outside the range are
* not clamped to the minimum and maximum parameters values,
* because out-of-range values are often intentional and useful.
*
* @webref math:calculation
* @webBrief Re-maps a number from one range to another
@@ -5272,6 +5246,11 @@ public class PApplet implements PConstants {
g.awaitAsyncSaveCompletion(filename);
}
// Hack so that calling loadImage() in settings() will work
// https://github.com/processing/processing4/issues/299
if (surface == null) {
return ShimAWT.loadImage(this, filename, extension);
}
return surface.loadImage(filename, extension);
}
@@ -10277,10 +10256,6 @@ public class PApplet implements PConstants {
// For 3.0.1, moved this above handleSettings() so that loadImage() can be
// used inside settings(). Sets a terrible precedent, but the alternative
// of not being able to size a sketch to an image is driving people loopy.
// A handful of things that need to be set before init/start.
// if (folder == null) {
// folder = calcSketchPath();
// }
sketch.sketchPath = folder;
// Don't set 'args' to a zero-length array if it should be null [3.0a8]
+1 -1
View File
@@ -88,7 +88,7 @@ public interface PConstants {
int MACOSX = 2;
String[] platformNames = {
"other", "windows", "macosx", "linux"
"other", "windows", "macos", "linux"
};
+8 -3
View File
@@ -460,6 +460,9 @@ public class PGraphics extends PImage implements PConstants {
/** The current text leading (read-only) */
public float textLeading;
/** Used internally to check whether still using the default font */
protected String defaultFontName;
static final protected String ERROR_TEXTFONT_NULL_PFONT =
"A null PFont was passed to textFont()";
@@ -4243,13 +4246,13 @@ public class PGraphics extends PImage implements PConstants {
InputStream input = getClass().getResourceAsStream("/font/ProcessingSansPro-Regular.ttf");
if (input != null) {
baseFont = Font.createFont(Font.TRUETYPE_FONT, input);
defaultFontName = baseFont.getName();
}
} catch (Exception e) {
// Fall back to how this was handled in 3.x, ugly!
e.printStackTrace(); // dammit
}
// Fall back to how this was handled in 3.x, ugly!
if (baseFont == null) {
baseFont = new Font("Lucida Sans", Font.PLAIN, 1);
}
@@ -8471,7 +8474,9 @@ public class PGraphics extends PImage implements PConstants {
*/
protected void defaultFontOrDeath(String method, float size) {
if (parent != null) {
textFont = createDefaultFont(size);
// Call textFont() so that subclasses can do necessary setup
// https://github.com/processing/processing4/issues/303
textFont(createDefaultFont(size));
} else {
throw new RuntimeException("Use textFont() before " + method + "()");
}
+1 -1
View File
@@ -121,7 +121,7 @@ public class PShapeSVG extends PShape {
this(null, svg, true);
if (!svg.getName().equals("svg")) {
if (svg.getName().toLowerCase().equals("html")) {
if (svg.getName().equalsIgnoreCase("html")) {
// Common case is that files aren't downloaded properly
throw new RuntimeException("This appears to be a web page, not an SVG file.");
} else {
+89 -97
View File
@@ -359,7 +359,7 @@ public abstract class PGL {
protected static int INDEX_TYPE = 0x1403; // GL_UNSIGNED_SHORT
/** Machine Epsilon for float precision. */
protected static float FLOAT_EPS = Float.MIN_VALUE;
protected static float FLOAT_EPS;
// Calculation of the Machine Epsilon for float precision. From:
// http://en.wikipedia.org/wiki/Machine_epsilon#Approximation_using_Java
static {
@@ -545,14 +545,14 @@ public abstract class PGL {
protected boolean getDepthTest() {
intBuffer.rewind();
getBooleanv(DEPTH_TEST, intBuffer);
return intBuffer.get(0) == 0 ? false : true;
return intBuffer.get(0) != 0;
}
protected boolean getDepthWriteMask() {
intBuffer.rewind();
getBooleanv(DEPTH_WRITEMASK, intBuffer);
return intBuffer.get(0) == 0 ? false : true;
return intBuffer.get(0) != 0;
}
@@ -828,14 +828,14 @@ public abstract class PGL {
// Multiply the texture by the button color
float ba = ((stopButtonColor >> 24) & 0xFF) / 255f;
float br = ((stopButtonColor >> 16) & 0xFF) / 255f;
float bg = ((stopButtonColor >> 8) & 0xFF) / 255f;
float bb = ((stopButtonColor >> 0) & 0xFF) / 255f;
float bg = ((stopButtonColor >> 8) & 0xFF) / 255f;
float bb = (stopButtonColor & 0xFF) / 255f;
for (int i = 0; i < color.length; i++) {
int c = closeButtonPix[i];
int a = (int)(ba * ((c >> 24) & 0xFF));
int r = (int)(br * ((c >> 16) & 0xFF));
int g = (int)(bg * ((c >> 8) & 0xFF));
int b = (int)(bb * ((c >> 0) & 0xFF));
int g = (int)(bg * ((c >> 8) & 0xFF));
int b = (int)(bb * (c & 0xFF));
color[i] = javaToNativeARGB((a << 24) | (r << 16) | (g << 8) | b);
}
IntBuffer buf = allocateIntBuffer(color);
@@ -1111,8 +1111,8 @@ public abstract class PGL {
depthComponent = DEPTH_COMPONENT32;
} else if (depthBits == 24) {
depthComponent = DEPTH_COMPONENT24;
} else if (depthBits == 16) {
depthComponent = DEPTH_COMPONENT16;
//} else if (depthBits == 16) {
//depthComponent = DEPTH_COMPONENT16;
}
IntBuffer depthBuf = multisample ? glMultiDepth : glDepth;
@@ -1135,8 +1135,8 @@ public abstract class PGL {
stencilIndex = STENCIL_INDEX8;
} else if (stencilBits == 4) {
stencilIndex = STENCIL_INDEX4;
} else if (stencilBits == 1) {
stencilIndex = STENCIL_INDEX1;
//} else if (stencilBits == 1) {
//stencilIndex = STENCIL_INDEX1;
}
IntBuffer stencilBuf = multisample ? glMultiStencil : glStencil;
@@ -1621,7 +1621,9 @@ public abstract class PGL {
// bit shifting this might be more efficient
protected static int nextPowerOfTwo(int val) {
int ret = 1;
while (ret < val) ret <<= 1;
while (ret < val) {
ret <<= 1;
}
return ret;
}
@@ -1873,8 +1875,7 @@ public abstract class PGL {
return 1;
} else {
// Number of samples is always an even number:
int n = 2 * (quality / 2);
return n;
return 2 * (quality / 2);
}
}
@@ -1987,31 +1988,29 @@ public abstract class PGL {
String[] vertSrc;
Pattern[] search;
String[] replace;
int offset = 1;
if (version < 130) {
Pattern[] search = { };
String[] replace = { };
int offset = 1;
search = new Pattern[] { };
replace = new String[] { };
vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
vertSrc[0] = "#version " + version + versionSuffix;
} else {
// We need to replace 'texture' uniform by 'texMap' uniform and
// 'textureXXX()' functions by 'texture()' functions. Order of these
// replacements is important to prevent collisions between these two.
Pattern[] search = new Pattern[] {
Pattern.compile(String.format(GLSL_ID_REGEX, "varying")),
Pattern.compile(String.format(GLSL_ID_REGEX, "attribute")),
Pattern.compile(String.format(GLSL_ID_REGEX, "texture")),
Pattern.compile(String.format(GLSL_FN_REGEX, "texture2DRect|texture2D|texture3D|textureCube"))
search = new Pattern[] {
Pattern.compile(String.format(GLSL_ID_REGEX, "varying")),
Pattern.compile(String.format(GLSL_ID_REGEX, "attribute")),
Pattern.compile(String.format(GLSL_ID_REGEX, "texture")),
Pattern.compile(String.format(GLSL_FN_REGEX, "texture2DRect|texture2D|texture3D|textureCube"))
};
String[] replace = new String[] {
"out", "in", "texMap", "texture",
replace = new String[]{
"out", "in", "texMap", "texture",
};
int offset = 1;
vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
vertSrc[0] = "#version " + version + versionSuffix;
}
vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
vertSrc[0] = "#version " + version + versionSuffix;
return vertSrc;
}
@@ -2041,8 +2040,7 @@ public abstract class PGL {
}
protected static boolean containsVersionDirective(String[] shSrc) {
for (int i = 0; i < shSrc.length; i++) {
String line = shSrc[i];
for (String line : shSrc) {
int versionIndex = line.indexOf("#version");
if (versionIndex >= 0) {
int commentIndex = line.indexOf("//");
@@ -2090,14 +2088,14 @@ public abstract class PGL {
protected boolean compiled(int shader) {
intBuffer.rewind();
getShaderiv(shader, COMPILE_STATUS, intBuffer);
return intBuffer.get(0) == 0 ? false : true;
return intBuffer.get(0) != 0;
}
protected boolean linked(int program) {
intBuffer.rewind();
getProgramiv(program, LINK_STATUS, intBuffer);
return intBuffer.get(0) == 0 ? false : true;
return intBuffer.get(0) != 0;
}
@@ -2106,38 +2104,27 @@ public abstract class PGL {
if (status == FRAMEBUFFER_COMPLETE) {
return 0;
} else if (status == FRAMEBUFFER_UNDEFINED) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"framebuffer undefined"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "framebuffer undefined");
} else if (status == FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"incomplete attachment"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "incomplete attachment");
} else if (status == FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"incomplete missing attachment"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "incomplete missing attachment");
} else if (status == FRAMEBUFFER_INCOMPLETE_DIMENSIONS) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"incomplete dimensions"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "incomplete dimensions");
} else if (status == FRAMEBUFFER_INCOMPLETE_FORMATS) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"incomplete formats"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "incomplete formats");
} else if (status == FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"incomplete draw buffer"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "incomplete draw buffer");
} else if (status == FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"incomplete read buffer"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "incomplete read buffer");
} else if (status == FRAMEBUFFER_UNSUPPORTED) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"framebuffer unsupported"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "framebuffer unsupported");
} else if (status == FRAMEBUFFER_INCOMPLETE_MULTISAMPLE) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"incomplete multisample buffer"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "incomplete multisample buffer");
} else if (status == FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS) {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"incomplete layer targets"));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "incomplete layer targets");
} else {
System.err.println(String.format(FRAMEBUFFER_ERROR,
"unknown error " + status));
System.err.printf((FRAMEBUFFER_ERROR) + "%n", "unknown error " + status);
}
return status;
}
@@ -2157,21 +2144,27 @@ public abstract class PGL {
int[] res = {0, 0, 0};
String[] parts = version.split(" ");
for (int i = 0; i < parts.length; i++) {
if (0 < parts[i].indexOf(".")) {
String[] nums = parts[i].split("\\.");
for (String part : parts) {
if (0 < part.indexOf(".")) {
String[] nums = part.split("\\.");
try {
res[0] = Integer.parseInt(nums[0]);
} catch (NumberFormatException e) { }
} catch (NumberFormatException e) {
// ignored
}
if (1 < nums.length) {
try {
res[1] = Integer.parseInt(nums[1]);
} catch (NumberFormatException e) { }
} catch (NumberFormatException e) {
// ignored
}
}
if (2 < nums.length) {
try {
res[2] = Integer.parseInt(nums[2]);
} catch (NumberFormatException e) { }
} catch (NumberFormatException e) {
// ignored
}
}
break;
}
@@ -2185,10 +2178,10 @@ public abstract class PGL {
int major = getGLVersion()[0];
if (major < 2) {
String ext = getString(EXTENSIONS);
return ext.indexOf("_framebuffer_object") != -1 &&
ext.indexOf("_vertex_shader") != -1 &&
ext.indexOf("_shader_objects") != -1 &&
ext.indexOf("_shading_language") != -1;
return (ext.contains("_framebuffer_object") &&
ext.contains("_vertex_shader") &&
ext.contains("_shader_objects") &&
ext.contains("_shading_language"));
} else {
return true;
}
@@ -2202,10 +2195,10 @@ public abstract class PGL {
int major = getGLVersion()[0];
if (major < 2) {
String ext = getString(EXTENSIONS);
return ext.indexOf("_fragment_shader") != -1 &&
ext.indexOf("_vertex_shader") != -1 &&
ext.indexOf("_shader_objects") != -1 &&
ext.indexOf("_shading_language") != -1;
return (ext.contains("_fragment_shader") &&
ext.contains("_vertex_shader") &&
ext.contains("_shader_objects") &&
ext.contains("_shading_language"));
} else {
return true;
}
@@ -2217,9 +2210,9 @@ public abstract class PGL {
if (major < 3) {
String ext = getString(EXTENSIONS);
if (isES()) {
return -1 < ext.indexOf("_texture_npot");
return ext.contains("_texture_npot");
} else {
return -1 < ext.indexOf("_texture_non_power_of_two");
return ext.contains("_texture_non_power_of_two");
}
} else {
return true;
@@ -2235,7 +2228,7 @@ public abstract class PGL {
return true;
} else {
String ext = getString(EXTENSIONS);
return -1 < ext.indexOf("_generate_mipmap");
return ext.contains("_generate_mipmap");
}
}
@@ -2244,7 +2237,7 @@ public abstract class PGL {
int major = getGLVersion()[0];
if (major < 3) {
String ext = getString(EXTENSIONS);
return -1 < ext.indexOf("_framebuffer_multisample");
return ext.contains("_framebuffer_multisample");
} else {
return true;
}
@@ -2255,7 +2248,7 @@ public abstract class PGL {
int major = getGLVersion()[0];
if (major < 3) {
String ext = getString(EXTENSIONS);
return -1 < ext.indexOf("_packed_depth_stencil");
return ext.contains("_packed_depth_stencil");
} else {
return true;
}
@@ -2266,7 +2259,7 @@ public abstract class PGL {
int major = getGLVersion()[0];
if (isES() || major < 3) {
String ext = getString(EXTENSIONS);
return -1 < ext.indexOf("_texture_filter_anisotropic");
return ext.contains("_texture_filter_anisotropic");
} else {
return true;
}
@@ -2621,8 +2614,7 @@ public abstract class PGL {
protected static FloatBuffer allocateDirectFloatBuffer(int size) {
int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_FLOAT;
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
asFloatBuffer();
return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).asFloatBuffer();
}
@@ -2735,27 +2727,27 @@ public abstract class PGL {
protected interface Tessellator {
public void setCallback(int flag);
public void setWindingRule(int rule);
public void setProperty(int property, int value);
void setCallback(int flag);
void setWindingRule(int rule);
void setProperty(int property, int value);
public void beginPolygon();
public void beginPolygon(Object data);
public void endPolygon();
public void beginContour();
public void endContour();
public void addVertex(double[] v);
public void addVertex(double[] v, int n, Object data);
void beginPolygon();
void beginPolygon(Object data);
void endPolygon();
void beginContour();
void endContour();
void addVertex(double[] v);
void addVertex(double[] v, int n, Object data);
}
protected interface TessellatorCallback {
public void begin(int type);
public void end();
public void vertex(Object data);
public void combine(double[] coords, Object[] data,
float[] weight, Object[] outData);
public void error(int errnum);
void begin(int type);
void end();
void vertex(Object data);
void combine(double[] coords, Object[] data,
float[] weight, Object[] outData);
void error(int errnum);
}
@@ -2781,9 +2773,9 @@ public abstract class PGL {
protected interface FontOutline {
public boolean isDone();
public int currentSegment(float coords[]);
public void next();
boolean isDone();
int currentSegment(float[] coords);
void next();
}
+40 -51
View File
@@ -239,7 +239,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected AsyncPixelReader asyncPixelReader;
protected boolean asyncPixelReaderInitialized;
// Keeps track of ongoing transfers so they can be finished.
// Keeps track of ongoing transfers so that they can be finished.
// Set is copied to the List when we need to iterate it
// so that readers can remove themselves from the Set during
// iteration if they don't have any ongoing transfers.
@@ -875,12 +875,11 @@ public class PGraphicsOpenGL extends PGraphics {
int glName;
private PGL pgl;
private int context;
private final int context;
public GLResourceTexture(Texture tex) {
super(tex);
pgl = tex.pg.getPrimaryPGL();
pgl.genTextures(1, intBuffer);
tex.glName = intBuffer.get(0);
@@ -925,7 +924,7 @@ public class PGraphicsOpenGL extends PGraphics {
int glId;
private PGL pgl;
private int context;
final private int context;
public GLResourceVertexBuffer(VertexBuffer vbo) {
super(vbo);
@@ -976,7 +975,7 @@ public class PGraphicsOpenGL extends PGraphics {
int glFragment;
private PGL pgl;
private int context;
final private int context;
public GLResourceShader(PShader sh) {
super(sh);
@@ -1044,7 +1043,7 @@ public class PGraphicsOpenGL extends PGraphics {
int glMultisample;
private PGL pgl;
private int context;
final private int context;
public GLResourceFrameBuffer(FrameBuffer fb) {
super(fb);
@@ -1518,7 +1517,7 @@ public class PGraphicsOpenGL extends PGraphics {
// neither GL_MULTISAMPLE nor GL_POLYGON_SMOOTH are part of GLES2 or GLES3
} else if (smooth < 1) {
pgl.disable(PGL.MULTISAMPLE);
} else if (1 <= smooth) {
} else {
pgl.enable(PGL.MULTISAMPLE);
}
if (!pgl.isES()) {
@@ -1539,16 +1538,14 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.activeTexture(PGL.TEXTURE0);
if (hints[DISABLE_DEPTH_MASK]) {
pgl.depthMask(false);
} else {
pgl.depthMask(true);
}
pgl.depthMask(!hints[DISABLE_DEPTH_MASK]);
FrameBuffer fb = getCurrentFB();
if (fb != null) {
fb.bind();
if (drawBufferSupported) pgl.drawBuffer(fb.getDefaultDrawBuffer());
if (drawBufferSupported) {
pgl.drawBuffer(fb.getDefaultDrawBuffer());
}
}
}
@@ -2288,7 +2285,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (hasPolys && isDepthSortingEnabled) {
// We flush after lines so they are visible
// Flush after lines so that they are visible
// under transparent polygons
flushSortedPolys();
if (raw != null) {
@@ -2734,12 +2731,11 @@ public class PGraphicsOpenGL extends PGraphics {
int voffset = cache.vertexOffset[n];
for (int ln = ioffset / 6; ln < (ioffset + icount) / 6; ln++) {
// Each line segment is defined by six indices since its
// formed by two triangles. We only need the first and last
// vertices.
// Each line segment is defined by six indices since it is
// formed by two triangles. Only need the first and last verts.
// This bunch of vertices could also be the bevel triangles,
// with we detect this situation by looking at the line weight.
int i0 = voffset + indices[6 * ln + 0];
int i0 = voffset + indices[6 * ln];
int i1 = voffset + indices[6 * ln + 5];
float sw0 = 2 * attribs[4 * i0 + 3];
float sw1 = 2 * attribs[4 * i1 + 3];
@@ -2839,7 +2835,7 @@ public class PGraphicsOpenGL extends PGraphics {
float weight;
int perim;
if (0 < size) { // round point
weight = +size / 0.5f;
weight = size / 0.5f;
perim = PApplet.min(MAX_POINT_ACCURACY, PApplet.max(MIN_POINT_ACCURACY,
(int) (TWO_PI * weight / POINT_ACCURACY_FACTOR))) + 1;
} else { // Square point
@@ -4457,8 +4453,8 @@ public class PGraphicsOpenGL extends PGraphics {
// Flushing geometry with a different perspective configuration.
flush();
float x = +2.0f / w;
float y = +2.0f / h;
float x = 2.0f / w;
float y = 2.0f / h;
float z = -2.0f / d;
float tx = -(right + left) / w;
@@ -4616,8 +4612,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (nonZero(ow)) {
ox /= ow;
}
float sx = width * (1 + ox) / 2.0f;
return sx;
return width * (1 + ox) / 2.0f;
}
@@ -4672,8 +4667,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (nonZero(ow)) {
oz /= ow;
}
float sz = (oz + 1) / 2.0f;
return sz;
return (oz + 1) / 2.0f;
}
@@ -5394,6 +5388,7 @@ public class PGraphicsOpenGL extends PGraphics {
PGL.getIntArray(pixelBuffer, pixels);
PGL.nativeToJavaARGB(pixels, pixelWidth, pixelHeight);
} catch (ArrayIndexOutOfBoundsException e) {
// ignored
}
}
@@ -5423,6 +5418,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
PGL.javaToNativeARGB(nativePixels, w, h);
} catch (ArrayIndexOutOfBoundsException e) {
// ignored
}
PGL.putIntArray(nativePixelBuffer, nativePixels);
// Copying pixel buffer to screen texture...
@@ -5840,6 +5836,7 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.readPixelsImpl(0, 0, pixelWidth, pixelHeight, PGL.RGBA, PGL.UNSIGNED_BYTE,
nativePixelBuffer);
} catch (IndexOutOfBoundsException e) {
// ignored
}
endPixelsOp();
@@ -6453,20 +6450,12 @@ public class PGraphicsOpenGL extends PGraphics {
if (!tex.colorBuffer() &&
(tex.usingMipmaps == hints[DISABLE_TEXTURE_MIPMAPS] ||
tex.currentSampling() != textureSampling)) {
if (hints[DISABLE_TEXTURE_MIPMAPS]) {
tex.usingMipmaps(false, textureSampling);
} else {
tex.usingMipmaps(true, textureSampling);
}
tex.usingMipmaps(!hints[DISABLE_TEXTURE_MIPMAPS], textureSampling);
}
if ((tex.usingRepeat && textureWrap == CLAMP) ||
(!tex.usingRepeat && textureWrap == REPEAT)) {
if (textureWrap == CLAMP) {
tex.usingRepeat(false);
} else {
tex.usingRepeat(true);
}
tex.usingRepeat(textureWrap != CLAMP);
}
}
@@ -6760,7 +6749,7 @@ public class PGraphicsOpenGL extends PGraphics {
// neither GL_MULTISAMPLE nor GL_POLYGON_SMOOTH are part of GLES2 or GLES3
} else if (smooth < 1) {
pgl.disable(PGL.MULTISAMPLE);
} else if (1 <= smooth) {
} else {
pgl.enable(PGL.MULTISAMPLE);
}
if (!pgl.isES()) {
@@ -6776,7 +6765,7 @@ public class PGraphicsOpenGL extends PGraphics {
background(backgroundColor);
} else {
// offscreen surfaces are transparent by default.
background(0x00 << 24 | (backgroundColor & 0xFFFFFF));
background(backgroundColor & 0xFFFFFF);
// Recreate offscreen FBOs
restartPGL();
@@ -7828,8 +7817,8 @@ public class PGraphicsOpenGL extends PGraphics {
int col = iarray[aidx];
vector[vidx++] = (col >> 24) & 0xFF;
vector[vidx++] = (col >> 16) & 0xFF;
vector[vidx++] = (col >> 8) & 0xFF;
vector[vidx++] = (col >> 0) & 0xFF;
vector[vidx++] = (col >> 8) & 0xFF;
vector[vidx++] = col & 0xFF;
} else {
if (attrib.isFloat()) {
float[] farray = fattribs.get(name);
@@ -12523,7 +12512,7 @@ public class PGraphicsOpenGL extends PGraphics {
path.moveTo(in.vertices[0], in.vertices[1], in.strokeColors[0]);
for (int ln = 0; ln < lineCount - 1; ln++) {
int i1 = ln + 1;
path.lineTo(in.vertices[3 * i1 + 0], in.vertices[3 * i1 + 1],
path.lineTo(in.vertices[3 * i1], in.vertices[3 * i1 + 1],
in.strokeColors[i1]);
}
path.closePath();
@@ -12641,19 +12630,19 @@ public class PGraphicsOpenGL extends PGraphics {
int i1 = edge[1];
switch (edge[2]) {
case EDGE_MIDDLE:
path.lineTo(strokeVertices[3 * i1 + 0], strokeVertices[3 * i1 + 1],
path.lineTo(strokeVertices[3 * i1], strokeVertices[3 * i1 + 1],
strokeColors[i1]);
break;
case EDGE_START:
path.moveTo(strokeVertices[3 * i0 + 0], strokeVertices[3 * i0 + 1],
path.moveTo(strokeVertices[3 * i0], strokeVertices[3 * i0 + 1],
strokeColors[i0]);
path.lineTo(strokeVertices[3 * i1 + 0], strokeVertices[3 * i1 + 1],
path.lineTo(strokeVertices[3 * i1], strokeVertices[3 * i1 + 1],
strokeColors[i1]);
break;
case EDGE_STOP:
path.lineTo(strokeVertices[3 * i1 + 0], strokeVertices[3 * i1 + 1],
path.lineTo(strokeVertices[3 * i1], strokeVertices[3 * i1 + 1],
strokeColors[i1]);
path.moveTo(strokeVertices[3 * i1 + 0], strokeVertices[3 * i1 + 1],
path.moveTo(strokeVertices[3 * i1], strokeVertices[3 * i1 + 1],
strokeColors[i1]);
break;
case EDGE_SINGLE:
@@ -12711,8 +12700,8 @@ public class PGraphicsOpenGL extends PGraphics {
weight = constStroke ? strokeWeight : strokeWeights[i0];
weight *= transformScale();
tess.setLineVertex(vidx++, strokeVertices, i0, i1, color, +weight/2);
tess.lineIndices[iidx++] = (short) (count + 0);
tess.setLineVertex(vidx++, strokeVertices, i0, i1, color, weight/2);
tess.lineIndices[iidx++] = (short) (count);
tess.setLineVertex(vidx++, strokeVertices, i0, i1, color, -weight/2);
tess.lineIndices[iidx++] = (short) (count + 1);
@@ -12750,7 +12739,7 @@ public class PGraphicsOpenGL extends PGraphics {
tess.lineIndices[iidx++] = (short) (count + 4);
tess.lineIndices[iidx++] = (short) (count + 5);
tess.lineIndices[iidx++] = (short) (count + 0);
tess.lineIndices[iidx++] = (short) (count);
tess.lineIndices[iidx++] = (short) (count + 4);
tess.lineIndices[iidx++] = (short) (count + 6);
@@ -12763,7 +12752,7 @@ public class PGraphicsOpenGL extends PGraphics {
tess.lineIndices[iidx++] = (short) (count + 4);
tess.lineIndices[iidx++] = lastInd[0];
tess.lineIndices[iidx++] = (short) (count + 0);
tess.lineIndices[iidx++] = (short) (count);
tess.lineIndices[iidx++] = (short) (count + 4);
tess.lineIndices[iidx++] = lastInd[1];
@@ -12960,7 +12949,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
boolean noCapsJoins() {
// The stroke weight is scaled so it corresponds to the current
// The stroke weight is scaled to correspond to the current
// "zoom level" being applied on the geometry due to scaling:
return tess.renderMode == IMMEDIATE &&
transformScale() * strokeWeight < PGL.MIN_CAPS_JOINS_WEIGHT;
@@ -12972,7 +12961,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
boolean segmentIsAxisAligned(int i0, int i1) {
return zero(in.vertices[3 * i0 + 0] - in.vertices[3 * i1 + 0]) ||
return zero(in.vertices[3 * i0] - in.vertices[3 * i1]) ||
zero(in.vertices[3 * i0 + 1] - in.vertices[3 * i1 + 1]);
}
+16 -20
View File
@@ -33,16 +33,18 @@ import java.nio.IntBuffer;
import java.util.HashMap;
/**
* This class encapsulates a GLSL shader program, including a vertex and a
* fragment shader. It's compatible with the P2D and P3D renderers, but not with
* the default renderer. Use the <b>loadShader()</b> function to load your
* shader code. [Note: It's strongly encouraged to use <b>loadShader()</b> to
* create a <b>PShader</b> object, rather than calling the <b>PShader</b> constructor
* manually.]
* This class encapsulates a GLSL shader program, including a vertex
* and a fragment shader. It is compatible with P2D and P3D, but not
* with the default renderer.
*
* Use the <b>loadShader()</b> function to load your shader code.
* Note: It's strongly encouraged to use <b>loadShader()</b> to create
* a <b>PShader</b> object, rather than calling the <b>PShader</b>
* constructor manually.
*
* @webref rendering:shaders
* @webBrief This class encapsulates a GLSL shader program, including a vertex
* and a fragment shader
* @webBrief This class encapsulates a GLSL shader program,
* including a vertex and a fragment shader
*/
public class PShader implements PConstants {
static protected final int POINT = 0;
@@ -939,7 +941,7 @@ public class PShader implements PConstants {
protected void validate() {
pgl.getProgramiv(glProgram, PGL.LINK_STATUS, intBuffer);
boolean linked = intBuffer.get(0) == 0 ? false : true;
boolean linked = intBuffer.get(0) != 0;
if (!linked) {
PGraphics.showException("Cannot link shader program:\n" +
pgl.getProgramInfoLog(glProgram));
@@ -947,7 +949,7 @@ public class PShader implements PConstants {
pgl.validateProgram(glProgram);
pgl.getProgramiv(glProgram, PGL.VALIDATE_STATUS, intBuffer);
boolean validated = intBuffer.get(0) == 0 ? false : true;
boolean validated = intBuffer.get(0) != 0;
if (!validated) {
PGraphics.showException("Cannot validate shader program:\n" +
pgl.getProgramInfoLog(glProgram));
@@ -975,15 +977,12 @@ public class PShader implements PConstants {
}
/**
* @param shaderSource a string containing the shader's code
*/
protected boolean compileVertexShader() {
pgl.shaderSource(glVertex, PApplet.join(vertexShaderSource, "\n"));
pgl.compileShader(glVertex);
pgl.getShaderiv(glVertex, PGL.COMPILE_STATUS, intBuffer);
boolean compiled = intBuffer.get(0) == 0 ? false : true;
boolean compiled = intBuffer.get(0) != 0;
if (!compiled) {
PGraphics.showException("Cannot compile vertex shader:\n" +
pgl.getShaderInfoLog(glVertex));
@@ -994,15 +993,12 @@ public class PShader implements PConstants {
}
/**
* @param shaderSource a string containing the shader's code
*/
protected boolean compileFragmentShader() {
pgl.shaderSource(glFragment, PApplet.join(fragmentShaderSource, "\n"));
pgl.compileShader(glFragment);
pgl.getShaderiv(glFragment, PGL.COMPILE_STATUS, intBuffer);
boolean compiled = intBuffer.get(0) == 0 ? false : true;
boolean compiled = intBuffer.get(0) != 0;
if (!compiled) {
PGraphics.showException("Cannot compile fragment shader:\n" +
pgl.getShaderInfoLog(glFragment));
@@ -1025,8 +1021,8 @@ public class PShader implements PConstants {
static protected int getShaderType(String[] source, int defaultType) {
for (int i = 0; i < source.length; i++) {
String line = source[i].trim();
for (String s : source) {
String line = s.trim();
if (PApplet.match(line, colorShaderDefRegexp) != null)
return PShader.COLOR;