Skip to content

Commit 8ea7a90

Browse files
committed
sync with desktop gl
1 parent 898409d commit 8ea7a90

File tree

5 files changed

+55
-33
lines changed

5 files changed

+55
-33
lines changed

core/src/processing/opengl/FrameBuffer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,16 @@ public void copyStencil(FrameBuffer dest) {
198198
}
199199

200200
public void copy(FrameBuffer dest, int mask) {
201-
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, this.glFbo);
202-
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, dest.glFbo);
201+
pgl.bindFramebufferImpl(PGL.READ_FRAMEBUFFER, this.glFbo);
202+
pgl.bindFramebufferImpl(PGL.DRAW_FRAMEBUFFER, dest.glFbo);
203203
pgl.blitFramebuffer(0, 0, this.width, this.height,
204204
0, 0, dest.width, dest.height, mask, PGL.NEAREST);
205-
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, pg.getCurrentFB().glFbo);
206-
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, pg.getCurrentFB().glFbo);
205+
pgl.bindFramebufferImpl(PGL.READ_FRAMEBUFFER, pg.getCurrentFB().glFbo);
206+
pgl.bindFramebufferImpl(PGL.DRAW_FRAMEBUFFER, pg.getCurrentFB().glFbo);
207207
}
208208

209209
public void bind() {
210-
pgl.bindFramebuffer(PGL.FRAMEBUFFER, glFbo);
210+
pgl.bindFramebufferImpl(PGL.FRAMEBUFFER, glFbo);
211211
}
212212

213213
public void disableDepthTest() {

core/src/processing/opengl/PGL.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ protected void unbindFrontTexture() {
511511
protected void syncBackTexture() {
512512
if (usingFrontTex) needSepFrontTex = true;
513513
if (1 < numSamples) {
514-
bindFramebuffer(READ_FRAMEBUFFER, glMultiFbo.get(0));
515-
bindFramebuffer(DRAW_FRAMEBUFFER, glColorFbo.get(0));
514+
bindFramebufferImpl(READ_FRAMEBUFFER, glMultiFbo.get(0));
515+
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
516516
blitFramebuffer(0, 0, fboWidth, fboHeight,
517517
0, 0, fboWidth, fboHeight,
518518
COLOR_BUFFER_BIT, NEAREST);
@@ -529,12 +529,12 @@ protected void beginDraw(boolean clear0) {
529529
if (needFBOLayer(clear0)) {
530530
if (!fboLayerCreated) createFBOLayer();
531531

532-
bindFramebuffer(FRAMEBUFFER, glColorFbo.get(0));
532+
bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0));
533533
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
534534
TEXTURE_2D, glColorTex.get(backTex), 0);
535535

536536
if (1 < numSamples) {
537-
bindFramebuffer(FRAMEBUFFER, glMultiFbo.get(0));
537+
bindFramebufferImpl(FRAMEBUFFER, glMultiFbo.get(0));
538538
}
539539

540540
if (firstFrame) {
@@ -580,7 +580,7 @@ protected void endDraw(boolean clear0) {
580580
syncBackTexture();
581581

582582
// Draw the contents of the back texture to the screen framebuffer.
583-
bindFramebuffer(FRAMEBUFFER, 0);
583+
bindFramebufferImpl(FRAMEBUFFER, 0);
584584

585585
clearDepth(1);
586586
clearColor(0, 0, 0, 0);
@@ -627,6 +627,8 @@ protected void endGL() { }
627627

628628

629629
private boolean needFBOLayer(boolean clear0) {
630+
// TODO: need to revise this, on windows we might not want to use FBO layer
631+
// even with anti-aliasing enabled...
630632
return !clear0 || fboLayerRequested || 1 < numSamples;
631633
}
632634

@@ -670,14 +672,14 @@ private void createFBOLayer() {
670672
frontTex = 1;
671673

672674
genFramebuffers(1, glColorFbo);
673-
bindFramebuffer(FRAMEBUFFER, glColorFbo.get(0));
675+
bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0));
674676
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D,
675677
glColorTex.get(backTex), 0);
676678

677679
if (multisample) {
678680
// Creating multisampled FBO
679681
genFramebuffers(1, glMultiFbo);
680-
bindFramebuffer(FRAMEBUFFER, glMultiFbo.get(0));
682+
bindFramebufferImpl(FRAMEBUFFER, glMultiFbo.get(0));
681683

682684
// color render buffer...
683685
genRenderbuffers(1, glColorBuf);
@@ -766,7 +768,7 @@ private void createFBOLayer() {
766768
clearColor(r, g, b, a);
767769
clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT);
768770

769-
bindFramebuffer(FRAMEBUFFER, 0);
771+
bindFramebufferImpl(FRAMEBUFFER, 0);
770772

771773
fboLayerCreated = true;
772774
}
@@ -2559,11 +2561,11 @@ protected interface FontOutline {
25592561
// to glReadPixels() should be done in readPixelsImpl().
25602562

25612563
public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer){
2562-
boolean needEndBegin = format != STENCIL_INDEX &&
2563-
format != DEPTH_COMPONENT && format != DEPTH_STENCIL;
2564-
if (needEndBegin) pg.beginReadPixels();
2564+
boolean pgCall = format != STENCIL_INDEX &&
2565+
format != DEPTH_COMPONENT && format != DEPTH_STENCIL;
2566+
if (pgCall) pg.beginReadPixels();
25652567
readPixelsImpl(x, y, width, height, format, type, buffer);
2566-
if (needEndBegin) pg.endReadPixels();
2568+
if (pgCall) pg.endReadPixels();
25672569
}
25682570

25692571
protected abstract void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer);
@@ -2745,7 +2747,13 @@ public void bindTexture(int target, int texture) {
27452747

27462748
// Framebuffers Objects
27472749

2748-
public abstract void bindFramebuffer(int target, int framebuffer);
2750+
public void bindFramebuffer(int target, int framebuffer) {
2751+
pg.beginBindFramebuffer(target, framebuffer);
2752+
bindFramebufferImpl(target, framebuffer);
2753+
pg.endBindFramebuffer(target, framebuffer);
2754+
}
2755+
protected abstract void bindFramebufferImpl(int target, int framebuffer);
2756+
27492757
public abstract void deleteFramebuffers(int n, IntBuffer framebuffers);
27502758
public abstract void genFramebuffers(int n, IntBuffer framebuffers);
27512759
public abstract void bindRenderbuffer(int target, int renderbuffer);

core/src/processing/opengl/PGLES.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ public void clearStencil(int s) {
16421642
// Framebuffers Objects
16431643

16441644
@Override
1645-
public void bindFramebuffer(int target, int framebuffer) {
1645+
protected void bindFramebufferImpl(int target, int framebuffer) {
16461646
GLES20.glBindFramebuffer(target, framebuffer);
16471647
}
16481648

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,16 +1807,29 @@ protected void restoreGL() {
18071807

18081808
FrameBuffer fb = getCurrentFB();
18091809
if (fb != null) {
1810-
getCurrentFB().bind();
1811-
pgl.drawBuffer(getCurrentFB().getDefaultDrawBuffer());
1810+
fb.bind();
1811+
pgl.drawBuffer(fb.getDefaultDrawBuffer());
1812+
}
1813+
}
1814+
1815+
protected void beginBindFramebuffer(int target, int framebuffer) {
1816+
// Actually, nothing to do here.
1817+
}
1818+
1819+
protected void endBindFramebuffer(int target, int framebuffer) {
1820+
FrameBuffer fb = getCurrentFB();
1821+
if (framebuffer == 0 && fb != null && fb.glFbo != 0) {
1822+
// The user is setting the framebuffer to 0 (screen buffer), but the
1823+
// renderer is drawing into an offscreen buffer.
1824+
fb.bind();
18121825
}
18131826
}
18141827

1815-
public void beginReadPixels() {
1828+
protected void beginReadPixels() {
18161829
beginPixelsOp(OP_READ);
18171830
}
18181831

1819-
public void endReadPixels() {
1832+
protected void endReadPixels() {
18201833
endPixelsOp();
18211834
}
18221835

@@ -2597,14 +2610,15 @@ void rawPolys() {
25972610
raw.noStroke();
25982611
raw.beginShape(TRIANGLES);
25992612

2600-
sortTriangles();
2613+
2614+
//sortTriangles();
26012615

26022616
float[] vertices = tessGeo.polyVertices;
26032617
int[] color = tessGeo.polyColors;
26042618
float[] uv = tessGeo.polyTexCoords;
2605-
//short[] indices = tessGeo.polyIndices; // unused [fry]
2606-
2619+
short[] indices = tessGeo.polyIndices; // unused [fry]
26072620

2621+
/*
26082622
sortTriangles();
26092623
for (int i = 0; i < sortedTriangleCount; i++) {
26102624
Triangle tri = sortedPolyTriangles[i];
@@ -2684,9 +2698,9 @@ void rawPolys() {
26842698
}
26852699
26862700
}
2701+
*/
26872702

26882703

2689-
/*
26902704
for (int i = 0; i < texCache.size; i++) {
26912705
PImage textureImage = texCache.getTextureImage(i);
26922706

@@ -2778,7 +2792,7 @@ void rawPolys() {
27782792
}
27792793
}
27802794
}
2781-
*/
2795+
27822796

27832797
raw.endShape();
27842798
}

core/src/processing/opengl/PShader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public class PShader implements PConstants {
116116
protected int transformMatLoc;
117117
protected int modelviewMatLoc;
118118
protected int projectionMatLoc;
119-
protected int bufferLoc;
119+
protected int ppixelsLoc;
120120
protected int bufferUnit;
121121
protected int viewportLoc;
122122

@@ -1158,7 +1158,7 @@ protected void loadUniforms() {
11581158
projectionMatLoc = getUniformLoc("projectionMatrix");
11591159

11601160
viewportLoc = getUniformLoc("viewport");
1161-
bufferLoc = getUniformLoc("buffer");
1161+
ppixelsLoc = getUniformLoc("ppixels");
11621162

11631163
normalMatLoc = getUniformLoc("normalMatrix");
11641164

@@ -1209,9 +1209,9 @@ protected void setCommonUniforms() {
12091209
setUniformValue(viewportLoc, x, y, w, h);
12101210
}
12111211

1212-
if (-1 < bufferLoc) {
1212+
if (-1 < ppixelsLoc) {
12131213
bufferUnit = getLastTexUnit() + 1;
1214-
setUniformValue(bufferLoc, bufferUnit);
1214+
setUniformValue(ppixelsLoc, bufferUnit);
12151215
pgl.activeTexture(PGL.TEXTURE0 + bufferUnit);
12161216
currentPG.bindFrontTexture();
12171217
} else {
@@ -1304,7 +1304,7 @@ protected void unbindTyped() {
13041304
if (-1 < texCoordLoc) pgl.disableVertexAttribArray(texCoordLoc);
13051305
if (-1 < normalLoc) pgl.disableVertexAttribArray(normalLoc);
13061306

1307-
if (-1 < bufferLoc) {
1307+
if (-1 < ppixelsLoc) {
13081308
pgl.requestFBOLayer();
13091309
pgl.activeTexture(PGL.TEXTURE0 + bufferUnit);
13101310
currentPG.unbindFrontTexture();

0 commit comments

Comments
 (0)