Skip to content

Commit 28c1799

Browse files
committed
2 parents 3a96beb + a2d161d commit 28c1799

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public class PGraphicsOpenGL extends PGraphics {
7676
"for the rest of the sketch's execution";
7777
static final String UNSUPPORTED_SHAPE_FORMAT_ERROR =
7878
"Unsupported shape format";
79+
static final String MISSING_UV_TEXCOORDS_ERROR =
80+
"No uv texture coordinates supplied with vertex() call";
7981
static final String INVALID_FILTER_SHADER_ERROR =
8082
"Your shader needs to be of TEXTURE type to be used as a filter";
8183
static final String INCONSISTENT_SHADER_TYPES =
@@ -624,13 +626,15 @@ protected void allocate() {
624626
public void dispose() { // PGraphics
625627
super.dispose();
626628

627-
// Swap buffers the end to make sure that no
628-
// garbage is shown on the screen, this particularly
629-
// affects non-interactive sketches on windows that
630-
// render only 1 frame, so no enough rendering
631-
// iterations have been conducted so far to properly
632-
// initialize all the buffers.
633-
pgl.swapBuffers();
629+
if (primarySurface) {
630+
// Swap buffers the end to make sure that no
631+
// garbage is shown on the screen, this particularly
632+
// affects non-interactive sketches on windows that
633+
// render only 1 frame, so no enough rendering
634+
// iterations have been conducted so far to properly
635+
// initialize all the buffers.
636+
pgl.swapBuffers();
637+
}
634638

635639
deletePolyBuffers();
636640
deleteLineBuffers();
@@ -2114,6 +2118,7 @@ public void endContour() {
21142118
@Override
21152119
public void vertex(float x, float y) {
21162120
vertexImpl(x, y, 0, 0, 0);
2121+
if (textureImage != null) PGraphics.showWarning(MISSING_UV_TEXCOORDS_ERROR);
21172122
}
21182123

21192124

@@ -2126,6 +2131,7 @@ public void vertex(float x, float y, float u, float v) {
21262131
@Override
21272132
public void vertex(float x, float y, float z) {
21282133
vertexImpl(x, y, z, 0, 0);
2134+
if (textureImage != null) PGraphics.showWarning(MISSING_UV_TEXCOORDS_ERROR);
21292135
}
21302136

21312137

@@ -5036,6 +5042,11 @@ protected void backgroundImpl(PImage image) {
50365042
if (0 < parent.frameCount) {
50375043
clearColorBuffer = true;
50385044
}
5045+
// Setting the background as opaque. If this an offscreen surface, the
5046+
// alpha channel will be set to 1 in endOffscreenDraw(), even if
5047+
// blending operations during draw create translucent areas in the
5048+
// color buffer.
5049+
backgroundA = 1;
50395050
}
50405051

50415052

@@ -5324,17 +5335,17 @@ protected void setImpl(PImage sourceImage,
53245335
setgetPixels = true;
53255336
super.setImpl(sourceImage, sourceX, sourceY, sourceWidth, sourceHeight,
53265337
targetX, targetY);
5327-
// do we need this?
5328-
// see https://github.com/processing/processing/issues/2125
5329-
// if (sourceImage.format == RGB) {
5330-
// int targetOffset = targetY * width + targetX;
5331-
// for (int y = sourceY; y < sourceY + sourceHeight; y++) {
5332-
// for (int x = targetOffset; x < targetOffset + sourceWidth; x++) {
5333-
// pixels[x] |= 0xff000000;
5334-
// }
5335-
// targetOffset += width;
5336-
// }
5337-
// }
5338+
// do we need this?
5339+
// see https://github.com/processing/processing/issues/2125
5340+
// if (sourceImage.format == RGB) {
5341+
// int targetOffset = targetY * width + targetX;
5342+
// for (int y = sourceY; y < sourceY + sourceHeight; y++) {
5343+
// for (int x = targetOffset; x < targetOffset + sourceWidth; x++) {
5344+
// pixels[x] |= 0xff000000;
5345+
// }
5346+
// targetOffset += width;
5347+
// }
5348+
// }
53385349
}
53395350

53405351

@@ -6097,6 +6108,15 @@ protected void beginOffscreenDraw() {
60976108

60986109

60996110
protected void endOffscreenDraw() {
6111+
// Set alpha channel to opaque in order to match behavior of JAVA2D:
6112+
// https://github.com/processing/processing/issues/1844
6113+
// but still not working as expected. Some strange artifacts with multismapled
6114+
// surfaces (see second code example in the issue above).
6115+
// pgl.colorMask(false, false, false, true);
6116+
// pgl.clearColor(0, 0, 0, 1);
6117+
// pgl.clear(PGL.COLOR_BUFFER_BIT);
6118+
// pgl.colorMask(true, true, true, true);
6119+
61006120
if (offscreenMultisample) {
61016121
multisampleFramebuffer.copy(offscreenFramebuffer, currentFramebuffer);
61026122
}

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ protected void endContourImpl() {
10031003
@Override
10041004
public void vertex(float x, float y) {
10051005
vertexImpl(x, y, 0, 0, 0);
1006+
if (image != null)
1007+
PGraphics.showWarning(PGraphicsOpenGL.MISSING_UV_TEXCOORDS_ERROR);
10061008
}
10071009

10081010

@@ -1015,6 +1017,8 @@ public void vertex(float x, float y, float u, float v) {
10151017
@Override
10161018
public void vertex(float x, float y, float z) {
10171019
vertexImpl(x, y, z, 0, 0);
1020+
if (image != null)
1021+
PGraphics.showWarning(PGraphicsOpenGL.MISSING_UV_TEXCOORDS_ERROR);
10181022
}
10191023

10201024

0 commit comments

Comments
 (0)