| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3f7ea95 commit b335274
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -510,40 +510,40 @@ public interface PConstants { | |||
| 510 | 510 | // hints - hint values are positive for the alternate version, | |
| 511 | 511 | // negative of the same value returns to the normal/default state | |
| 512 | 512 | ||
| 513 | - static final int ENABLE_NATIVE_FONTS = 1; | ||
| 514 | - static final int DISABLE_NATIVE_FONTS = -1; | ||
| 513 | + static final int ENABLE_NATIVE_FONTS = 1; | ||
| 514 | + static final int DISABLE_NATIVE_FONTS = -1; | ||
| 515 | 515 | ||
| 516 | - static final int DISABLE_DEPTH_TEST = 2; | ||
| 517 | - static final int ENABLE_DEPTH_TEST = -2; | ||
| 516 | + static final int DISABLE_DEPTH_TEST = 2; | ||
| 517 | + static final int ENABLE_DEPTH_TEST = -2; | ||
| 518 | 518 | ||
| 519 | - static final int ENABLE_DEPTH_SORT = 3; | ||
| 520 | - static final int DISABLE_DEPTH_SORT = -3; | ||
| 519 | + static final int ENABLE_DEPTH_SORT = 3; | ||
| 520 | + static final int DISABLE_DEPTH_SORT = -3; | ||
| 521 | 521 | ||
| 522 | - static final int DISABLE_OPENGL_ERROR_REPORT = 4; | ||
| 523 | - static final int ENABLE_OPENGL_ERROR_REPORT = -4; | ||
| 522 | + static final int DISABLE_OPENGL_ERROR_REPORT = 4; | ||
| 523 | + static final int ENABLE_OPENGL_ERROR_REPORT = -4; | ||
| 524 | 524 | ||
| 525 | - static final int ENABLE_ACCURATE_TEXTURES = 5; | ||
| 526 | - static final int DISABLE_ACCURATE_TEXTURES = -5; | ||
| 525 | + static final int ENABLE_ACCURATE_TEXTURES = 5; | ||
| 526 | + static final int DISABLE_ACCURATE_TEXTURES = -5; | ||
| 527 | 527 | ||
| 528 | - static final int DISABLE_DEPTH_MASK = 6; | ||
| 529 | - static final int ENABLE_DEPTH_MASK = -6; | ||
| 528 | + static final int DISABLE_DEPTH_MASK = 6; | ||
| 529 | + static final int ENABLE_DEPTH_MASK = -6; | ||
| 530 | 530 | ||
| 531 | - static final int ENABLE_ACCURATE_2D = 7; | ||
| 532 | - static final int DISABLE_ACCURATE_2D = -7; | ||
| 531 | + static final int ENABLE_ACCURATE_2D = 7; | ||
| 532 | + static final int DISABLE_ACCURATE_2D = -7; | ||
| 533 | 533 | ||
| 534 | - static final int DISABLE_TEXTURE_CACHE = 8; | ||
| 535 | - static final int ENABLE_TEXTURE_CACHE = -8; | ||
| 534 | + static final int DISABLE_TEXTURE_CACHE = 8; | ||
| 535 | + static final int ENABLE_TEXTURE_CACHE = -8; | ||
| 536 | 536 | ||
| 537 | - static final int DISABLE_TRANSFORM_CACHE = 9; | ||
| 538 | - static final int ENABLE_TRANSFORM_CACHE = -9; | ||
| 537 | + static final int DISABLE_TRANSFORM_CACHE = 9; | ||
| 538 | + static final int ENABLE_TRANSFORM_CACHE = -9; | ||
| 539 | 539 | ||
| 540 | - static final int ENABLE_PERSPECTIVE_CORRECTED_LINES = 10; | ||
| 541 | - static final int DISABLE_PERSPECTIVE_CORRECTED_LINES = -10; | ||
| 540 | + static final int ENABLE_PERSPECTIVE_CORRECTED_STROKE = 10; | ||
| 541 | + static final int DISABLE_PERSPECTIVE_CORRECTED_STROKE = -10; | ||
| 542 | 542 | ||
| 543 | - static final int DISABLE_TEXTURE_MIPMAPS = 11; | ||
| 544 | - static final int ENABLE_TEXTURE_MIPMAPS = -11; | ||
| 543 | + static final int DISABLE_TEXTURE_MIPMAPS = 11; | ||
| 544 | + static final int ENABLE_TEXTURE_MIPMAPS = -11; | ||
| 545 | 545 | ||
| 546 | - static final int HINT_COUNT = 12; | ||
| 546 | + static final int HINT_COUNT = 12; | ||
| 547 | 547 | ||
| 548 | 548 | // error messages | |
| 549 | 549 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ public class PGraphics2D extends PGraphicsOpenGL { | |||
| 36 | 36 | ||
| 37 | 37 | public PGraphics2D() { | |
| 38 | 38 | super(); | |
| 39 | - hints[ENABLE_PERSPECTIVE_CORRECTED_LINES] = false; | ||
| 39 | + hints[ENABLE_PERSPECTIVE_CORRECTED_STROKE] = false; | ||
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | 42 | ||
@@ -61,7 +61,7 @@ public boolean is3D() { | |||
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | 63 | public void hint(int which) { | |
| 64 | - if (which == ENABLE_PERSPECTIVE_CORRECTED_LINES) { | ||
| 64 | + if (which == ENABLE_PERSPECTIVE_CORRECTED_STROKE) { | ||
| 65 | 65 | showWarning("2D lines cannot be perspective-corrected."); | |
| 66 | 66 | return; | |
| 67 | 67 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,11 @@ | |||
| 34 | 34 | ||
| 35 | 35 | public class PGraphics3D extends PGraphicsOpenGL { | |
| 36 | 36 | ||
| 37 | + public PGraphics3D() { | ||
| 38 | + super(); | ||
| 39 | + hints[ENABLE_PERSPECTIVE_CORRECTED_STROKE] = true; | ||
| 40 | + } | ||
| 41 | + | ||
| 37 | 42 | ////////////////////////////////////////////////////////////// | |
| 38 | 43 | ||
| 39 | 44 | // RENDERER SUPPORT QUERIES | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2093,12 +2093,12 @@ public void hint(int which) { | |||
| 2093 | 2093 | setFlushMode(FLUSH_CONTINUOUSLY); | |
| 2094 | 2094 | } else if (which == DISABLE_TEXTURE_CACHE) { | |
| 2095 | 2095 | flush(); | |
| 2096 | - } else if (which == DISABLE_PERSPECTIVE_CORRECTED_LINES) { | ||
| 2096 | + } else if (which == DISABLE_PERSPECTIVE_CORRECTED_STROKE) { | ||
| 2097 | 2097 | if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) { | |
| 2098 | 2098 | // We flush the geometry using the previous line setting. | |
| 2099 | 2099 | flush(); | |
| 2100 | 2100 | } | |
| 2101 | - } else if (which == ENABLE_PERSPECTIVE_CORRECTED_LINES) { | ||
| 2101 | + } else if (which == ENABLE_PERSPECTIVE_CORRECTED_STROKE) { | ||
| 2102 | 2102 | if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) { | |
| 2103 | 2103 | // We flush the geometry using the previous line setting. | |
| 2104 | 2104 | flush(); | |
@@ -5447,9 +5447,8 @@ public void mask(PImage alpha) { | |||
| 5447 | 5447 | } | |
| 5448 | 5448 | ||
| 5449 | 5449 | if (maskShader == null) { | |
| 5450 | - maskShader = new PolyTexShader(parent, | ||
| 5451 | - defPolyTexShaderVertURL, | ||
| 5452 | - maskShaderFragURL); | ||
| 5450 | + maskShader = new PolyTexShader(parent, defPolyTexShaderVertURL, | ||
| 5451 | + maskShaderFragURL); | ||
| 5453 | 5452 | } | |
| 5454 | 5453 | maskShader.set("maskSampler", alpha); | |
| 5455 | 5454 | filter(maskShader); | |
@@ -6846,7 +6845,7 @@ public void bind() { | |||
| 6846 | 6845 | float h = pgCurrent.viewport[3]; | |
| 6847 | 6846 | setUniformValue(viewportLoc, x, y, w, h); | |
| 6848 | 6847 | ||
| 6849 | - if (pgCurrent.hintEnabled(ENABLE_PERSPECTIVE_CORRECTED_LINES)) { | ||
| 6848 | + if (pgCurrent.hintEnabled(ENABLE_PERSPECTIVE_CORRECTED_STROKE)) { | ||
| 6850 | 6849 | setUniformValue(perspectiveLoc, 1); | |
| 6851 | 6850 | } else { | |
| 6852 | 6851 | setUniformValue(perspectiveLoc, 0); | |
@@ -6880,6 +6879,9 @@ protected class PointShader extends PShader { | |||
| 6880 | 6879 | protected int modelviewMatrixLoc; | |
| 6881 | 6880 | protected int projectionMatrixLoc; | |
| 6882 | 6881 | ||
| 6882 | + protected int viewportLoc; | ||
| 6883 | + protected int perspectiveLoc; | ||
| 6884 | + | ||
| 6883 | 6885 | protected int inVertexLoc; | |
| 6884 | 6886 | protected int inColorLoc; | |
| 6885 | 6887 | protected int inPointLoc; | |
@@ -6907,6 +6909,9 @@ public void loadUniforms() { | |||
| 6907 | 6909 | projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); | |
| 6908 | 6910 | modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); | |
| 6909 | 6911 | projectionMatrixLoc = getUniformLoc("projectionMatrix"); | |
| 6912 | + | ||
| 6913 | + viewportLoc = getUniformLoc("viewport"); | ||
| 6914 | + perspectiveLoc = getUniformLoc("perspective"); | ||
| 6910 | 6915 | } | |
| 6911 | 6916 | ||
| 6912 | 6917 | public void setVertexAttribute(int vboId, int size, int type, | |
@@ -6950,6 +6955,18 @@ public void bind() { | |||
| 6950 | 6955 | pgCurrent.updateGLProjection(); | |
| 6951 | 6956 | setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); | |
| 6952 | 6957 | } | |
| 6958 | + | ||
| 6959 | + float x = pgCurrent.viewport[0]; | ||
| 6960 | + float y = pgCurrent.viewport[1]; | ||
| 6961 | + float w = pgCurrent.viewport[2]; | ||
| 6962 | + float h = pgCurrent.viewport[3]; | ||
| 6963 | + setUniformValue(viewportLoc, x, y, w, h); | ||
| 6964 | + | ||
| 6965 | + if (pgCurrent.hintEnabled(ENABLE_PERSPECTIVE_CORRECTED_STROKE)) { | ||
| 6966 | + setUniformValue(perspectiveLoc, 1); | ||
| 6967 | + } else { | ||
| 6968 | + setUniformValue(perspectiveLoc, 0); | ||
| 6969 | + } | ||
| 6953 | 6970 | } | |
| 6954 | 6971 | ||
| 6955 | 6972 | public void unbind() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,16 +21,33 @@ | |||
| 21 | 21 | uniform mat4 projectionMatrix; | |
| 22 | 22 | uniform mat4 modelviewMatrix; | |
| 23 | 23 | ||
| 24 | + uniform vec4 viewport; | ||
| 25 | + uniform int perspective; | ||
| 26 | + | ||
| 24 | 27 | attribute vec4 inVertex; | |
| 25 | 28 | attribute vec4 inColor; | |
| 26 | 29 | attribute vec2 inPoint; | |
| 27 | 30 | ||
| 28 | 31 | varying vec4 vertColor; | |
| 29 | 32 | ||
| 33 | + vec4 windowToClipVector(vec2 window, vec4 viewport, float clip_w) { | ||
| 34 | + vec2 xypos = (window / viewport.zw) * 2.0; | ||
| 35 | + return vec4(xypos, 0.0, 0.0) * clip_w; | ||
| 36 | + } | ||
| 37 | + | ||
| 30 | 38 | void main() { | |
| 31 | 39 | vec4 pos = modelviewMatrix * inVertex; | |
| 32 | - pos.xy += inPoint.xy; | ||
| 33 | - gl_Position = projectionMatrix * pos; | ||
| 40 | + vec4 clip = projectionMatrix * pos; | ||
| 41 | + | ||
| 42 | + if (0 < perspective) { | ||
| 43 | + // Perspective correction (points will look thiner as they move away | ||
| 44 | + // from the view position). | ||
| 45 | + gl_Position = clip + projectionMatrix * vec4(inPoint.xy, 0, 0); | ||
| 46 | + } else { | ||
| 47 | + // No perspective correction. | ||
| 48 | + vec4 offset = windowToClipVector(inPoint.xy, viewport, clip.w); | ||
| 49 | + gl_Position = clip + offset; | ||
| 50 | + } | ||
| 34 | 51 | ||
| 35 | 52 | vertColor = inColor; | |
| 36 | 53 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments