Skip to content

Commit eb513ac

Browse files
committed
Fixing several problems with the handling of offsecreen surfaces
1 parent b952cbd commit eb513ac

6 files changed

Lines changed: 167 additions & 136 deletions

File tree

core/src/processing/opengl/FrameBuffer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public class FrameBuffer implements PConstants {
149149
@Override
150150
protected void finalize() throws Throwable {
151151
try {
152-
// PApplet.println("finalize FBO");
153152
if (!screenFb) {
154153
if (glFbo != 0) {
155154
PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context);

core/src/processing/opengl/MaskFrag.glsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
Boston, MA 02111-1307 USA
1919
*/
2020

21+
#ifdef GL_ES
22+
precision mediump float;
23+
precision mediump int;
24+
#endif
25+
2126
#define PROCESSING_TEXTURE_SHADER
2227

2328
uniform sampler2D texture;

core/src/processing/opengl/PGL.java

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ protected void beginDraw(boolean clear0) {
965965
// Render previous back texture (now is the front) as background,
966966
// because no background() is being used ("incremental drawing")
967967
drawTexture(TEXTURE_2D, glColorTex.get(frontTex),
968-
fboWidth, fboHeight, 0, 0, pg.width, pg.height,
968+
fboWidth, fboHeight, pg.width, pg.height,
969+
0, 0, pg.width, pg.height,
969970
0, 0, pg.width, pg.height);
970971
}
971972

@@ -997,6 +998,7 @@ protected void endDraw(boolean clear0) {
997998
gl.glDisable(GL.GL_BLEND);
998999
drawTexture(GL.GL_TEXTURE_2D, backTexAttach.getName(),
9991000
backTexAttach.getWidth(), backTexAttach.getHeight(),
1001+
pg.width, pg.height,
10001002
0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height);
10011003
backFBO.bind(gl);
10021004
}
@@ -1014,7 +1016,8 @@ protected void endDraw(boolean clear0) {
10141016
// Render current back texture to screen, without blending.
10151017
disable(BLEND);
10161018
drawTexture(TEXTURE_2D, glColorTex.get(backTex),
1017-
fboWidth, fboHeight, 0, 0, pg.width, pg.height,
1019+
fboWidth, fboHeight, pg.width, pg.height,
1020+
0, 0, pg.width, pg.height,
10181021
0, 0, pg.width, pg.height);
10191022

10201023
// Swapping front and back textures.
@@ -1329,26 +1332,28 @@ protected void copyToTexture(int target, int format, int id, int x, int y,
13291332

13301333
protected void drawTexture(int target, int id, int width, int height,
13311334
int X0, int Y0, int X1, int Y1) {
1332-
drawTexture(target, id, width, height, X0, Y0, X1, Y1, X0, Y0, X1, Y1);
1335+
drawTexture(target, id, width, height, width, height,
1336+
X0, Y0, X1, Y1, X0, Y0, X1, Y1);
13331337
}
13341338

13351339

1336-
protected void drawTexture(int target, int id, int width, int height,
1340+
protected void drawTexture(int target, int id,
1341+
int texW, int texH, int scrW, int scrH,
13371342
int texX0, int texY0, int texX1, int texY1,
13381343
int scrX0, int scrY0, int scrX1, int scrY1) {
13391344
if (target == TEXTURE_2D) {
1340-
drawTexture2D(id, width, height,
1345+
drawTexture2D(id, texW, texH, scrW, scrH,
13411346
texX0, texY0, texX1, texY1,
13421347
scrX0, scrY0, scrX1, scrY1);
13431348
} else if (target == TEXTURE_RECTANGLE) {
1344-
drawTextureRect(id, width, height,
1349+
drawTextureRect(id, texW, texH, scrW, scrH,
13451350
texX0, texY0, texX1, texY1,
13461351
scrX0, scrY0, scrX1, scrY1);
13471352
}
13481353
}
13491354

13501355

1351-
protected void drawTexture2D(int id, int width, int height,
1356+
protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
13521357
int texX0, int texY0, int texX1, int texY1,
13531358
int scrX0, int scrY0, int scrX1, int scrY1) {
13541359
if (!loadedTex2DShader ||
@@ -1390,25 +1395,25 @@ protected void drawTexture2D(int id, int width, int height,
13901395
// Vertex coordinates of the textured quad are specified
13911396
// in normalized screen space (-1, 1):
13921397
// Corner 1
1393-
texCoords[ 0] = 2 * (float)scrX0 / pg.width - 1;
1394-
texCoords[ 1] = 2 * (float)scrY0 / pg.height - 1;
1395-
texCoords[ 2] = (float)texX0 / width;
1396-
texCoords[ 3] = (float)texY0 / height;
1398+
texCoords[ 0] = 2 * (float)scrX0 / scrW - 1;
1399+
texCoords[ 1] = 2 * (float)scrY0 / scrH - 1;
1400+
texCoords[ 2] = (float)texX0 / texW;
1401+
texCoords[ 3] = (float)texY0 / texH;
13971402
// Corner 2
1398-
texCoords[ 4] = 2 * (float)scrX1 / pg.width - 1;
1399-
texCoords[ 5] = 2 * (float)scrY0 / pg.height - 1;
1400-
texCoords[ 6] = (float)texX1 / width;
1401-
texCoords[ 7] = (float)texY0 / height;
1403+
texCoords[ 4] = 2 * (float)scrX1 / scrW - 1;
1404+
texCoords[ 5] = 2 * (float)scrY0 / scrH - 1;
1405+
texCoords[ 6] = (float)texX1 / texW;
1406+
texCoords[ 7] = (float)texY0 / texH;
14021407
// Corner 3
1403-
texCoords[ 8] = 2 * (float)scrX0 / pg.width - 1;
1404-
texCoords[ 9] = 2 * (float)scrY1 / pg.height - 1;
1405-
texCoords[10] = (float)texX0 / width;
1406-
texCoords[11] = (float)texY1 / height;
1408+
texCoords[ 8] = 2 * (float)scrX0 / scrW - 1;
1409+
texCoords[ 9] = 2 * (float)scrY1 / scrH - 1;
1410+
texCoords[10] = (float)texX0 / texW;
1411+
texCoords[11] = (float)texY1 / texH;
14071412
// Corner 4
1408-
texCoords[12] = 2 * (float)scrX1 / pg.width - 1;
1409-
texCoords[13] = 2 * (float)scrY1 / pg.height - 1;
1410-
texCoords[14] = (float)texX1 / width;
1411-
texCoords[15] = (float)texY1 / height;
1413+
texCoords[12] = 2 * (float)scrX1 / scrW - 1;
1414+
texCoords[13] = 2 * (float)scrY1 / scrH - 1;
1415+
texCoords[14] = (float)texX1 / texW;
1416+
texCoords[15] = (float)texY1 / texH;
14121417

14131418
texData.rewind();
14141419
texData.put(texCoords);
@@ -1452,7 +1457,7 @@ protected void drawTexture2D(int id, int width, int height,
14521457
}
14531458

14541459

1455-
protected void drawTextureRect(int id, int width, int height,
1460+
protected void drawTextureRect(int id, int texW, int texH, int scrW, int scrH,
14561461
int texX0, int texY0, int texX1, int texY1,
14571462
int scrX0, int scrY0, int scrX1, int scrY1) {
14581463
if (!loadedTexRectShader ||
@@ -1495,23 +1500,23 @@ protected void drawTextureRect(int id, int width, int height,
14951500
// Vertex coordinates of the textured quad are specified
14961501
// in normalized screen space (-1, 1):
14971502
// Corner 1
1498-
texCoords[ 0] = 2 * (float)scrX0 / pg.width - 1;
1499-
texCoords[ 1] = 2 * (float)scrY0 / pg.height - 1;
1503+
texCoords[ 0] = 2 * (float)scrX0 / scrW - 1;
1504+
texCoords[ 1] = 2 * (float)scrY0 / scrH - 1;
15001505
texCoords[ 2] = texX0;
15011506
texCoords[ 3] = texY0;
15021507
// Corner 2
1503-
texCoords[ 4] = 2 * (float)scrX1 / pg.width - 1;
1504-
texCoords[ 5] = 2 * (float)scrY0 / pg.height - 1;
1508+
texCoords[ 4] = 2 * (float)scrX1 / scrW - 1;
1509+
texCoords[ 5] = 2 * (float)scrY0 / scrH - 1;
15051510
texCoords[ 6] = texX1;
15061511
texCoords[ 7] = texY0;
15071512
// Corner 3
1508-
texCoords[ 8] = 2 * (float)scrX0 / pg.width - 1;
1509-
texCoords[ 9] = 2 * (float)scrY1 / pg.height - 1;
1513+
texCoords[ 8] = 2 * (float)scrX0 / scrW - 1;
1514+
texCoords[ 9] = 2 * (float)scrY1 / scrH - 1;
15101515
texCoords[10] = texX0;
15111516
texCoords[11] = texY1;
15121517
// Corner 4
1513-
texCoords[12] = 2 * (float)scrX1 / pg.width - 1;
1514-
texCoords[13] = 2 * (float)scrY1 / pg.height - 1;
1518+
texCoords[12] = 2 * (float)scrX1 / scrW - 1;
1519+
texCoords[13] = 2 * (float)scrY1 / scrH - 1;
15151520
texCoords[14] = texX1;
15161521
texCoords[15] = texY1;
15171522

0 commit comments

Comments
 (0)