diff --git a/core/src/processing/core/PConstants.java b/core/src/processing/core/PConstants.java index 7437520aa..776c1f4e0 100644 --- a/core/src/processing/core/PConstants.java +++ b/core/src/processing/core/PConstants.java @@ -550,35 +550,37 @@ public interface PConstants { // hints - hint values are positive for the alternate version, // negative of the same value returns to the normal/default state - static final int ENABLE_NATIVE_FONTS = 1; - static final int DISABLE_NATIVE_FONTS = -1; + static final int ENABLE_NATIVE_FONTS = 1; + static final int DISABLE_NATIVE_FONTS = -1; - static final int DISABLE_DEPTH_TEST = 2; - static final int ENABLE_DEPTH_TEST = -2; + static final int DISABLE_DEPTH_TEST = 2; + static final int ENABLE_DEPTH_TEST = -2; - static final int ENABLE_DEPTH_SORT = 3; - static final int DISABLE_DEPTH_SORT = -3; + static final int ENABLE_DEPTH_SORT = 3; + static final int DISABLE_DEPTH_SORT = -3; - static final int DISABLE_OPENGL_ERROR_REPORT = 4; - static final int ENABLE_OPENGL_ERROR_REPORT = -4; + static final int DISABLE_OPENGL_ERROR_REPORT = 4; + static final int ENABLE_OPENGL_ERROR_REPORT = -4; - static final int ENABLE_ACCURATE_TEXTURES = 5; - static final int DISABLE_ACCURATE_TEXTURES = -5; + static final int ENABLE_ACCURATE_TEXTURES = 5; + static final int DISABLE_ACCURATE_TEXTURES = -5; - static final int DISABLE_DEPTH_MASK = 6; - static final int ENABLE_DEPTH_MASK = -6; + static final int DISABLE_DEPTH_MASK = 6; + static final int ENABLE_DEPTH_MASK = -6; - static final int ENABLE_ACCURATE_2D = 7; - static final int DISABLE_ACCURATE_2D = -7; + static final int ENABLE_ACCURATE_2D = 7; + static final int DISABLE_ACCURATE_2D = -7; - static final int DISABLE_TEXTURE_CACHE = 8; - static final int ENABLE_TEXTURE_CACHE = -8; + static final int DISABLE_TEXTURE_CACHE = 8; + static final int ENABLE_TEXTURE_CACHE = -8; - static final int DISABLE_TRANSFORM_CACHE = 9; - static final int ENABLE_TRANSFORM_CACHE = -9; + static final int DISABLE_TRANSFORM_CACHE = 9; + static final int ENABLE_TRANSFORM_CACHE = -9; + + static final int ENABLE_PERSPECTIVE_CORRECTED_LINES = 10; + static final int DISABLE_PERSPECTIVE_CORRECTED_LINES = -10; - static final int HINT_COUNT = 10; - + static final int HINT_COUNT = 11; // error messages diff --git a/java/libraries/opengl/src/processing/opengl/LineShaderVert.glsl b/java/libraries/opengl/src/processing/opengl/LineShaderVert.glsl index 3546e48ad..140f14b5b 100644 --- a/java/libraries/opengl/src/processing/opengl/LineShaderVert.glsl +++ b/java/libraries/opengl/src/processing/opengl/LineShaderVert.glsl @@ -104,19 +104,17 @@ void main() { float thickness = attribs.w; vec2 window_offset = perp * thickness; -/* if (0 < perspective) { // Perspective correction (lines will look thiner as they move away // from the view position). gl_Position.xy = clip_p.xy + window_offset.xy; gl_Position.zw = clip_p.zw; } else { - */ // No perspective correction. float clip_p_w = clip_p.w; vec4 offset_p = windowToClipVector(window_offset, viewport, clip_p_w); gl_Position = clip_p + offset_p; - //} + } vec4 color = vec4(0, 0, 0, 0); vec4 globalAmbient = gl_Color * gl_LightModel.ambient; diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 22bd32268..363388072 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -1413,7 +1413,7 @@ public class PGraphicsOpenGL extends PGraphics { } if (hints[ENABLE_ACCURATE_2D]) { - flushMode = FLUSH_CONTINUOUSLY; + flushMode = FLUSH_CONTINUOUSLY; } else { flushMode = FLUSH_WHEN_FULL; } @@ -1737,8 +1737,14 @@ public class PGraphicsOpenGL extends PGraphics { // HINTS public void hint(int which) { - super.hint(which); + boolean oldValue = hints[which]; + super.hint(which); + boolean newValue = hints[which]; + if (oldValue == newValue) { + return; + } + if (which == DISABLE_DEPTH_TEST) { flush(); pgl.disableDepthTest(); @@ -1768,6 +1774,17 @@ public class PGraphicsOpenGL extends PGraphics { } else if (which == DISABLE_TEXTURE_CACHE) { flush(); + } else if (which == DISABLE_PERSPECTIVE_CORRECTED_LINES) { + if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) { + flush(); + } + + } else if (which == ENABLE_PERSPECTIVE_CORRECTED_LINES && + 0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) { + if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) { + flush(); + } + } } @@ -2442,6 +2459,12 @@ public class PGraphicsOpenGL extends PGraphics { protected void setupLineShader(int attrBufID, float[] attribs, int nvert) { lineShader.setVecUniform("viewport", viewport[0], viewport[1], viewport[2], viewport[3]); + if (hints[ENABLE_PERSPECTIVE_CORRECTED_LINES]) { + lineShader.setIntUniform("perspective", 1); + } else { + lineShader.setIntUniform("perspective", 0); + } + lineShader.setIntUniform("lights", lightCount); lineShader.setVecUniform("eye", cameraEyeX, cameraEyeY, cameraEyeZ, 0); @@ -2457,6 +2480,12 @@ public class PGraphicsOpenGL extends PGraphics { protected void setupLineShader(int attrBufID) { lineShader.setVecUniform("viewport", viewport[0], viewport[1], viewport[2], viewport[3]); + + if (hints[ENABLE_PERSPECTIVE_CORRECTED_LINES]) { + lineShader.setIntUniform("perspective", 1); + } else { + lineShader.setIntUniform("perspective", 0); + } lineShader.setIntUniform("lights", lightCount);