change up how smoothing is handled (see #3357)

This commit is contained in:
Ben Fry
2015-06-06 16:09:12 -04:00
parent 40bd81d40b
commit 9bb8a6ab19
8 changed files with 291 additions and 218 deletions
+40 -52
View File
@@ -879,9 +879,9 @@ public class PApplet implements PConstants {
* Description to come...
*
* ( end auto-generated )
*
*
* Override this method to call size() when not using the PDE.
*
*
* @webref environment
* @see PApplet#fullScreen()
* @see PApplet#setup()
@@ -972,6 +972,41 @@ public class PApplet implements PConstants {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public void smooth() {
smooth(1);
}
public void smooth(int level) {
if (insideSettings) {
this.smooth = level;
} else if (this.smooth != level) {
smoothWarning("smooth");
}
}
public void noSmooth() {
if (insideSettings) {
this.smooth = 0;
} else if (this.smooth != 0) {
smoothWarning("noSmooth");
}
}
private void smoothWarning(String method) {
// When running from the PDE, say setup(), otherwise say settings()
final String where = external ? "setup" : "settings";
PGraphics.showWarning("%s() can only be used inside %s()", method, where);
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public PGraphics getGraphics() {
return g;
}
@@ -2021,7 +2056,7 @@ public class PApplet implements PConstants {
// Store the quality setting in case it's changed during draw and the
// drawing context needs to be re-built before the next frame.
int pquality = g.quality;
int pquality = g.smooth;
if (insideDraw) {
System.err.println("handleDraw() called before finishing");
@@ -2087,8 +2122,8 @@ public class PApplet implements PConstants {
}
g.endDraw();
if (pquality != g.quality) {
surface.setSmooth(g.quality);
if (pquality != g.smooth) {
surface.setSmooth(g.smooth);
}
if (recorder != null) {
@@ -11475,53 +11510,6 @@ public class PApplet implements PConstants {
}
/**
* ( begin auto-generated from smooth.xml )
*
* Draws all geometry with smooth (anti-aliased) edges. This will sometimes
* slow down the frame rate of the application, but will enhance the visual
* refinement. Note that <b>smooth()</b> will also improve image quality of
* resized images, and <b>noSmooth()</b> will disable image (and font)
* smoothing altogether.
*
* ( end auto-generated )
*
* @webref shape:attributes
* @see PGraphics#noSmooth()
* @see PGraphics#hint(int)
* @see PApplet#size(int, int, String)
*/
public void smooth() {
if (recorder != null) recorder.smooth();
g.smooth();
}
/**
*
* @param level either 2, 4, or 8
*/
public void smooth(int level) {
if (recorder != null) recorder.smooth(level);
g.smooth(level);
}
/**
* ( begin auto-generated from noSmooth.xml )
*
* Draws all geometry with jagged (aliased) edges.
*
* ( end auto-generated )
* @webref shape:attributes
* @see PGraphics#smooth()
*/
public void noSmooth() {
if (recorder != null) recorder.noSmooth();
g.noSmooth();
}
/**
* ( begin auto-generated from imageMode.xml )
*
+97 -57
View File
@@ -157,13 +157,11 @@ public class PGraphics extends PImage implements PConstants {
/// width * height (useful for many calculations)
public int pixelCount;
/// true if smoothing is enabled (read-only)
public boolean smooth;
// /// true if smoothing is enabled (read-only)
// public boolean smooth;
/// the anti-aliasing level for renderers that support it
public int quality;
// public int smooth;
public int smooth;
// ........................................................
@@ -704,7 +702,7 @@ public class PGraphics extends PImage implements PConstants {
this.parent = parent;
// Some renderers (OpenGL) need to know what smoothing level will be used
// before the rendering surface is even created.
quality = parent.sketchSmooth();
smooth = parent.sketchSmooth();
}
@@ -762,6 +760,11 @@ public class PGraphics extends PImage implements PConstants {
}
// public void setSmooth(int level) {
// this.smooth = level;
// }
// /**
// * Allocate memory or an image buffer for this renderer.
// */
@@ -919,12 +922,12 @@ public class PGraphics extends PImage implements PConstants {
protected void defaultSettings() { // ignore
// System.out.println("PGraphics.defaultSettings() " + width + " " + height);
//smooth(); // 2.0a5
if (quality > 0) { // 2.0a5
smooth();
} else {
noSmooth();
}
// //smooth(); // 2.0a5
// if (quality > 0) { // 2.0a5
// smooth();
// } else {
// noSmooth();
// }
colorMode(RGB, 255);
fill(255);
@@ -1015,12 +1018,12 @@ public class PGraphics extends PImage implements PConstants {
} else {
noTint();
}
if (smooth) {
smooth();
} else {
// Don't bother setting this, cuz it'll anger P3D.
noSmooth();
}
// if (smooth) {
// smooth();
// } else {
// // Don't bother setting this, cuz it'll anger P3D.
// noSmooth();
// }
if (textFont != null) {
// System.out.println(" textFont in reapply is " + textFont);
// textFont() resets the leading, so save it in case it's changed
@@ -3558,53 +3561,90 @@ public class PGraphics extends PImage implements PConstants {
// SMOOTHING
/**
* If true in PImage, use bilinear interpolation for copy()
* operations. When inherited by PGraphics, also controls shapes.
*/
// /**
// * If true in PImage, use bilinear interpolation for copy()
// * operations. When inherited by PGraphics, also controls shapes.
// */
//
// /**
// * ( begin auto-generated from smooth.xml )
// *
// * Draws all geometry with smooth (anti-aliased) edges. This will sometimes
// * slow down the frame rate of the application, but will enhance the visual
// * refinement. Note that <b>smooth()</b> will also improve image quality of
// * resized images, and <b>noSmooth()</b> will disable image (and font)
// * smoothing altogether.
// *
// * ( end auto-generated )
// *
// * @webref shape:attributes
// * @see PGraphics#noSmooth()
// * @see PGraphics#hint(int)
// * @see PApplet#size(int, int, String)
// */
// public void smooth() {
// smooth = true;
// }
//
// /**
// *
// * @param level either 2, 4, or 8
// */
// public void smooth(int level) {
// smooth = true;
// }
//
// /**
// * ( begin auto-generated from noSmooth.xml )
// *
// * Draws all geometry with jagged (aliased) edges.
// *
// * ( end auto-generated )
// * @webref shape:attributes
// * @see PGraphics#smooth()
// */
// public void noSmooth() {
// smooth = false;
// }
/**
* ( begin auto-generated from smooth.xml )
*
* Draws all geometry with smooth (anti-aliased) edges. This will sometimes
* slow down the frame rate of the application, but will enhance the visual
* refinement. Note that <b>smooth()</b> will also improve image quality of
* resized images, and <b>noSmooth()</b> will disable image (and font)
* smoothing altogether.
*
* ( end auto-generated )
*
* @webref shape:attributes
* @see PGraphics#noSmooth()
* @see PGraphics#hint(int)
* @see PApplet#size(int, int, String)
*/
public void smooth() {
smooth = true;
final public void smooth() { // ignore
smooth(1);
}
/**
*
* @param level either 2, 4, or 8
*/
public void smooth(int level) {
smooth = true;
final public void smooth(int quality) { // ignore
if (primarySurface) {
parent.smooth(quality);
} else {
// make sure beginDraw() not called yet
if (settingsInited) {
// ignore if it's just a repeat of the current state
if (this.smooth != quality) {
smoothWarning("smooth");
}
} else {
this.smooth = quality;
}
}
}
/**
* ( begin auto-generated from noSmooth.xml )
*
* Draws all geometry with jagged (aliased) edges.
*
* ( end auto-generated )
* @webref shape:attributes
* @see PGraphics#smooth()
*/
public void noSmooth() {
smooth = false;
final public void noSmooth() { // ignore
smooth(0);
/*
if (primarySurface) {
parent.noSmooth();
} else {
}
*/
}
private void smoothWarning(String method) {
PGraphics.showWarning("%s() can only be used before beginDraw()", method);
}
//////////////////////////////////////////////////////////////
@@ -63,7 +63,7 @@ public class PGraphicsDanger2D extends PGraphicsJava2D {
// }
// Calling getGraphics() seems to nuke the smoothing settings
smooth(quality);
smooth(smooth);
checkSettings();
resetMatrix(); // reset model matrix
+16 -16
View File
@@ -843,22 +843,22 @@ public class PGraphicsFX2D extends PGraphics {
// }
@Override
public void smooth(int quality) {
// this.quality = quality;
// if (quality == 0) {
// noSmooth();
// } else {
// smooth();
// }
showMissingWarning("smooth");
}
@Override
public void noSmooth() {
showMissingWarning("noSmooth");
}
// @Override
// public void smooth(int quality) {
//// this.quality = quality;
//// if (quality == 0) {
//// noSmooth();
//// } else {
//// smooth();
//// }
// showMissingWarning("smooth");
// }
//
//
// @Override
// public void noSmooth() {
// showMissingWarning("noSmooth");
// }
+101 -62
View File
@@ -316,7 +316,8 @@ public class PGraphicsJava2D extends PGraphics {
//g2 = (Graphics2D) image.getGraphics();
// Calling getGraphics() seems to nuke the smoothing settings
smooth(quality);
//smooth(quality);
handleSmooth();
/*
// NOTE: Calling image.getGraphics() will create a new Graphics context,
@@ -377,6 +378,44 @@ public class PGraphicsJava2D extends PGraphics {
}
protected void handleSmooth() {
if (smooth == 0) {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
} else {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
(smooth == 1 || smooth == 4) ?
RenderingHints.VALUE_INTERPOLATION_BICUBIC :
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
// http://docs.oracle.com/javase/tutorial/2d/text/renderinghints.html
// Oracle Java text anti-aliasing on OS X looks like s*t compared to the
// text rendering with Apple's old Java 6. Below, several attempts to fix:
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// Turns out this is the one that actually makes things work.
// Kerning is still screwed up, however.
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
// RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
// RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
// g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
// RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
}
}
@Override
public void endDraw() {
// hm, mark pixels as changed, because this will instantly do a full
@@ -1395,69 +1434,69 @@ public class PGraphicsJava2D extends PGraphics {
//////////////////////////////////////////////////////////////
// SMOOTH
@Override
public void smooth() {
smooth = true;
if (quality == 0) {
quality = 4; // change back to bicubic
}
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
quality == 4 ?
RenderingHints.VALUE_INTERPOLATION_BICUBIC :
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
// http://docs.oracle.com/javase/tutorial/2d/text/renderinghints.html
// Oracle Java text anti-aliasing on OS X looks like s*t compared to the
// text rendering with Apple's old Java 6. Below, several attempts to fix:
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// Turns out this is the one that actually makes things work.
// Kerning is still screwed up, however.
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
// //////////////////////////////////////////////////////////////
//
// // SMOOTH
//
//
// @Override
// public void smooth() {
// smooth = true;
//
// if (quality == 0) {
// quality = 4; // change back to bicubic
// }
//
// g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
// RenderingHints.VALUE_ANTIALIAS_ON);
//
// g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
// quality == 4 ?
// RenderingHints.VALUE_INTERPOLATION_BICUBIC :
// RenderingHints.VALUE_INTERPOLATION_BILINEAR);
//
// // http://docs.oracle.com/javase/tutorial/2d/text/renderinghints.html
// // Oracle Java text anti-aliasing on OS X looks like s*t compared to the
// // text rendering with Apple's old Java 6. Below, several attempts to fix:
// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
// RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
// RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// // Turns out this is the one that actually makes things work.
// // Kerning is still screwed up, however.
// g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
// RenderingHints.VALUE_FRACTIONALMETRICS_ON);
//// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
//// RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
//// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
//// RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
//
//// g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
//// RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
//
// }
//
//
// @Override
// public void smooth(int quality) {
// this.quality = quality;
// if (quality == 0) {
// noSmooth();
// } else {
// smooth();
// }
// }
//
//
// @Override
// public void noSmooth() {
// smooth = false;
// quality = 0; // https://github.com/processing/processing/issues/3113
// g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
// RenderingHints.VALUE_ANTIALIAS_OFF);
// g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
// RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
// RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
// g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
// RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
}
@Override
public void smooth(int quality) {
this.quality = quality;
if (quality == 0) {
noSmooth();
} else {
smooth();
}
}
@Override
public void noSmooth() {
smooth = false;
quality = 0; // https://github.com/processing/processing/issues/3113
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
}
// RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
// }
@@ -1852,7 +1852,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
pgl.depthFunc(PGL.LEQUAL);
if (quality < 2) {
if (smooth < 2) {
pgl.disable(PGL.MULTISAMPLE);
} else {
pgl.enable(PGL.MULTISAMPLE);
@@ -3481,7 +3481,7 @@ public class PGraphicsOpenGL extends PGraphics {
// SMOOTH
/*
@Override
public void smooth() {
if (quality < 2) {
@@ -3553,6 +3553,7 @@ public class PGraphicsOpenGL extends PGraphics {
restartPGL();
}
}
*/
//////////////////////////////////////////////////////////////
@@ -6544,9 +6545,9 @@ public class PGraphicsOpenGL extends PGraphics {
boolean packed = depthBits == 24 && stencilBits == 8 &&
packedDepthStencilSupported;
if (PGraphicsOpenGL.fboMultisampleSupported && 1 < quality) {
if (PGraphicsOpenGL.fboMultisampleSupported && 1 < smooth) {
multisampleFramebuffer =
new FrameBuffer(this, texture.glWidth, texture.glHeight, quality, 0,
new FrameBuffer(this, texture.glWidth, texture.glHeight, smooth, 0,
depthBits, stencilBits, packed, false);
multisampleFramebuffer.clear();
@@ -6560,7 +6561,7 @@ public class PGraphicsOpenGL extends PGraphics {
false, false);
} else {
quality = 0;
smooth = 0;
offscreenFramebuffer =
new FrameBuffer(this, texture.glWidth, texture.glHeight, 1, 1,
depthBits, stencilBits, packed, false);
@@ -6673,12 +6674,12 @@ public class PGraphicsOpenGL extends PGraphics {
if (primarySurface) {
pgl.getIntegerv(PGL.SAMPLES, intBuffer);
int temp = intBuffer.get(0);
if (quality != temp && 1 < temp && 1 < quality) {
if (smooth != temp && 1 < temp && 1 < smooth) {
// TODO check why the samples is higher that initialized smooth level.
// quality = temp;
}
}
if (quality < 2) {
if (smooth < 2) {
pgl.disable(PGL.MULTISAMPLE);
} else {
pgl.enable(PGL.MULTISAMPLE);
+1 -1
View File
@@ -193,7 +193,7 @@ public class PSurfaceJOGL implements PSurface {
// caps.setPBuffer(false);
// caps.setFBO(false);
pgl.reqNumSamples = graphics.quality;
pgl.reqNumSamples = graphics.smooth;
caps.setSampleBuffers(true);
caps.setNumSamples(pgl.reqNumSamples);
caps.setBackgroundOpaque(true);
+27 -22
View File
@@ -8,6 +8,8 @@ X probably remove anything inside settings() as well?
o add imageSmooth()?
o https://github.com/processing/processing/issues/1272
X decided no, again
X sketchQuality() vs sketchSmooth()?
X 'quality' is being removed since smoothing will be a one-time thing
fixed earlier/can no longer reproduce
X strips when rendering spheres with lights and anti-aliasing
@@ -37,10 +39,11 @@ X key problem with DELETE, BACKSPACE and CMD in P3D / P2D
X https://github.com/processing/processing/issues/3352
X save() and saveFrame() with OPENGL renderer fails
X https://github.com/processing/processing/issues/3334
X Errors in glsl code are only caught when set() is used
X https://github.com/processing/processing/issues/2268
X move glsl entries to their own subdirectory
beta
X sketchXxxx() methods are final, need to move folks away from these
X fix up handling of fullScreen()
X https://github.com/processing/processing/issues/3296
X right now using a (display ignoring) hack to displayWidth/Height
@@ -48,27 +51,27 @@ X maybe we use the AWT screen sizes first, then match the others w/ em?
X --full-screen replaced with --present (to untangle things)
X if you want full screen, use the fullScreen() method
X --span removed as an option, better to just do this from code
_ docs: no mixing size() and fullScreen(). pick one.
X docs: no mixing size() and fullScreen(). pick one.
X instead of all these sketchXxxx() methods, should we have sketchSetting()
_ and an internal dictionary that stores them all?
_ intParam(), stringParam() and setParam()?
_ or sketchInt() or settingsInt()?
o too much soup inside main() to handle arg parsing and passing to the sketch
X moved things to settings()
_ noSmooth()
X split 'present' and 'full screen'?
X --full-screen causes considerable flicker at this point
X or split them when sketchWidth/Height are implemented?
_ smooth() and noSmooth()
_ can only be called inside setup(), show warning elsewhere
_ is lifted out of setup() and into settings()
_ goes before the first beginDraw() with createGraphics()
_ sketchQuality() needs to be rooted out
_ sort out display stuff (bug in the numbering in 3.0a9)
_ Text looks blurry in GL Retina (andres)
_ https://github.com/processing/processing/issues/2739
_ check retina with PGraphicsRetina2D
_ Text is half size in PGraphicsRetina2D
_ https://github.com/processing/processing/issues/2738
_ text not getting the correct font in Retina2D
_ https://github.com/processing/processing/issues/2617
_ https://github.com/processing/processing/issues/3357
_ https://github.com/processing/processing-docs/issues/251
_ replace sketchXxxx() methods with another mechanism?
_ and an internal dictionary that stores them all?
_ intParam(), stringParam() and setParam()?
_ or sketchInt() or settingsInt()?
_ surface.size(), surface.noSmooth()... just like PGraphics methods?
X sketchXxxx() methods are final, need to move folks away from these
_ or is this a bad move until we've sorted out Android?
critical
_ draw() executes twice when noLoop() called in setup()
@@ -147,8 +150,6 @@ _ https://github.com/processing/processing/issues/3339
opengl questions
_ sketchQuality() vs sketchSmooth()?
_ move glsl entries to their own subdirectory
_ exitCalled() and exitActual made public by Andres, breaks Python
_ also not API we want to expose, so sort this out
_ or maybe we're fine b/c now FX2D needs it as well
@@ -159,12 +160,9 @@ _ https://github.com/processing/processing/issues/1278
full screen
_ claim about a bar at the top in 10.9
_ full screen needs to ignore location setting for frame?
_ https://github.com/processing/processing/issues/3305
_ present window draws in stages (OS X)
_ split 'present' and 'full screen'?
_ --full-screen causes considerable flicker at this point
_ or split them when sketchWidth/Height are implemented?
_ "run sketches on display" not working in 3.0a7
_ https://github.com/processing/processing/issues/3264
_ full screen doesn't work on second window w/o present mode
@@ -271,6 +269,13 @@ _ zero alpha values still a problem with retina renderer
_ https://github.com/processing/processing/issues/2030
_ NPE when using image() created with createGraphics(PGraphicsRetina2D)
_ https://github.com/processing/processing/issues/2510
_ Text looks blurry in GL Retina (andres)
_ https://github.com/processing/processing/issues/2739
_ check retina with PGraphicsRetina2D
_ Text is half size in PGraphicsRetina2D
_ https://github.com/processing/processing/issues/2738
_ text not getting the correct font in Retina2D
_ https://github.com/processing/processing/issues/2617
decisions/misc