Skip to content

Commit 4386253

Browse files
committed
Android sync
1 parent 97e73e5 commit 4386253

File tree

11 files changed

+868
-713
lines changed

11 files changed

+868
-713
lines changed

core/src/processing/core/PApplet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ public SketchSurfaceViewGL(Context context, int wide, int high, boolean is3D) {
819819
setEGLContextClientVersion(2);
820820

821821
// The renderer can be set only once.
822-
setRenderer(((PGLES)PGraphicsOpenGL.pgl).getRenderer());
822+
setRenderer(((PGLES)g3.pgl).getRenderer());
823823
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
824824

825825
// assign this g to the PApplet

core/src/processing/opengl/FontTexture.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class FontTexture implements PConstants {
6363
protected TextureInfo[] glyphTexinfos;
6464
protected HashMap<PFont.Glyph, TextureInfo> texinfoMap;
6565

66+
6667
public FontTexture(PGraphicsOpenGL pg, PFont font, boolean is3D) {
67-
pgl = PGraphicsOpenGL.pgl;
68+
pgl = pg.pgl;
6869
this.is3D = is3D;
6970

7071
initTexture(pg, font);
@@ -130,15 +131,15 @@ public boolean addTexture(PGraphicsOpenGL pg) {
130131
if (is3D) {
131132
// Bilinear sampling ensures that the texture doesn't look pixelated
132133
// either when it is magnified or minified...
133-
tex = new Texture(w, h, new Texture.Parameters(ARGB, Texture.BILINEAR,
134-
false));
134+
tex = new Texture(pg, w, h,
135+
new Texture.Parameters(ARGB, Texture.BILINEAR, false));
135136
} else {
136137
// ...however, the effect of bilinear sampling is to add some blurriness
137138
// to the text in its original size. In 2D, we assume that text will be
138139
// shown at its original size, so linear sampling is chosen instead (which
139140
// only affects minimized text).
140-
tex = new Texture(w, h, new Texture.Parameters(ARGB, Texture.LINEAR,
141-
false));
141+
tex = new Texture(pg, w, h,
142+
new Texture.Parameters(ARGB, Texture.LINEAR, false));
142143
}
143144

144145
if (textures == null) {

core/src/processing/opengl/FrameBuffer.java

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*/
4141

4242
public class FrameBuffer implements PConstants {
43+
protected PGraphicsOpenGL pg;
4344
protected PGL pgl;
4445
protected int context; // The context that created this framebuffer.
4546

@@ -67,16 +68,17 @@ public class FrameBuffer implements PConstants {
6768
protected IntBuffer pixelBuffer;
6869

6970

70-
FrameBuffer() {
71-
pgl = PGraphicsOpenGL.pgl;
71+
FrameBuffer(PGraphicsOpenGL pg) {
72+
this.pg = pg;
73+
pgl = pg.pgl;
7274
context = pgl.createEmptyContext();
7375
}
7476

7577

76-
FrameBuffer(int w, int h, int samples, int colorBuffers,
77-
int depthBits, int stencilBits, boolean packedDepthStencil,
78-
boolean screen) {
79-
this();
78+
FrameBuffer(PGraphicsOpenGL pg, int w, int h, int samples, int colorBuffers,
79+
int depthBits, int stencilBits, boolean packedDepthStencil,
80+
boolean screen) {
81+
this(pg);
8082

8183
glFbo = 0;
8284
glDepth = 0;
@@ -136,13 +138,13 @@ public class FrameBuffer implements PConstants {
136138
}
137139

138140

139-
FrameBuffer(int w, int h) {
140-
this(w, h, 1, 1, 0, 0, false, false);
141+
FrameBuffer(PGraphicsOpenGL pg, int w, int h) {
142+
this(pg, w, h, 1, 1, 0, 0, false, false);
141143
}
142144

143145

144-
FrameBuffer(int w, int h, boolean screen) {
145-
this(w, h, 1, 1, 0, 0, false, screen);
146+
FrameBuffer(PGraphicsOpenGL pg, int w, int h, boolean screen) {
147+
this(pg, w, h, 1, 1, 0, 0, false, screen);
146148
}
147149

148150

@@ -172,25 +174,36 @@ protected void finalize() throws Throwable {
172174
}
173175

174176
public void clear() {
175-
PGraphicsOpenGL.pushFramebuffer();
176-
PGraphicsOpenGL.setFramebuffer(this);
177+
pg.pushFramebuffer();
178+
pg.setFramebuffer(this);
177179
pgl.clearDepth(1);
178180
pgl.clearStencil(0);
179181
pgl.clearColor(0, 0, 0, 0);
180182
pgl.clear(PGL.DEPTH_BUFFER_BIT |
181183
PGL.STENCIL_BUFFER_BIT |
182184
PGL.COLOR_BUFFER_BIT);
183-
PGraphicsOpenGL.popFramebuffer();
185+
pg.popFramebuffer();
184186
}
185187

186-
public void copy(FrameBuffer dest, FrameBuffer current) {
188+
public void copyColor(FrameBuffer dest) {
189+
copy(dest, PGL.COLOR_BUFFER_BIT);
190+
}
191+
192+
public void copyDepth(FrameBuffer dest) {
193+
copy(dest, PGL.DEPTH_BUFFER_BIT);
194+
}
195+
196+
public void copyStencil(FrameBuffer dest) {
197+
copy(dest, PGL.STENCIL_BUFFER_BIT);
198+
}
199+
200+
public void copy(FrameBuffer dest, int mask) {
187201
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, this.glFbo);
188202
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, dest.glFbo);
189203
pgl.blitFramebuffer(0, 0, this.width, this.height,
190-
0, 0, dest.width, dest.height,
191-
PGL.COLOR_BUFFER_BIT, PGL.NEAREST);
192-
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, current.glFbo);
193-
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, current.glFbo);
204+
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);
194207
}
195208

196209
public void bind() {
@@ -201,7 +214,7 @@ public void disableDepthTest() {
201214
noDepth = true;
202215
}
203216

204-
public void finish(PGraphicsOpenGL pg) {
217+
public void finish() {
205218
if (noDepth) {
206219
// No need to clear depth buffer because depth testing was disabled.
207220
if (pg.getHint(ENABLE_DEPTH_TEST)) {
@@ -271,8 +284,8 @@ public void setColorBuffers(Texture[] textures, int n) {
271284
colorBufferTex[i] = textures[i];
272285
}
273286

274-
PGraphicsOpenGL.pushFramebuffer();
275-
PGraphicsOpenGL.setFramebuffer(this);
287+
pg.pushFramebuffer();
288+
pg.setFramebuffer(this);
276289

277290
// Making sure nothing is attached.
278291
for (int i = 0; i < numColorBuffers; i++) {
@@ -288,7 +301,7 @@ public void setColorBuffers(Texture[] textures, int n) {
288301

289302
pgl.validateFramebuffer();
290303

291-
PGraphicsOpenGL.popFramebuffer();
304+
pg.popFramebuffer();
292305
}
293306

294307

@@ -300,16 +313,16 @@ public void swapColorBuffers() {
300313
colorBufferTex[i1] = tmp;
301314
}
302315

303-
PGraphicsOpenGL.pushFramebuffer();
304-
PGraphicsOpenGL.setFramebuffer(this);
316+
pg.pushFramebuffer();
317+
pg.setFramebuffer(this);
305318
for (int i = 0; i < numColorBuffers; i++) {
306319
pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
307320
colorBufferTex[i].glTarget,
308321
colorBufferTex[i].glName, 0);
309322
}
310323
pgl.validateFramebuffer();
311324

312-
PGraphicsOpenGL.popFramebuffer();
325+
pg.popFramebuffer();
313326
}
314327

315328

@@ -345,7 +358,7 @@ protected void allocate() {
345358
glFbo = 0;
346359
} else {
347360
//create the FBO object...
348-
glFbo = PGraphicsOpenGL.createFrameBufferObject(context);
361+
glFbo = PGraphicsOpenGL.createFrameBufferObject(context, pgl);
349362

350363
// ... and then create the rest of the stuff.
351364
if (multisample) {
@@ -420,17 +433,17 @@ protected boolean contextIsOutdated() {
420433
protected void createColorBufferMultisample() {
421434
if (screenFb) return;
422435

423-
PGraphicsOpenGL.pushFramebuffer();
424-
PGraphicsOpenGL.setFramebuffer(this);
436+
pg.pushFramebuffer();
437+
pg.setFramebuffer(this);
425438

426-
glMultisample = PGraphicsOpenGL.createRenderBufferObject(context);
439+
glMultisample = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
427440
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
428441
pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
429442
PGL.RGBA8, width, height);
430443
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0,
431444
PGL.RENDERBUFFER, glMultisample);
432445

433-
PGraphicsOpenGL.popFramebuffer();
446+
pg.popFramebuffer();
434447
}
435448

436449

@@ -441,10 +454,10 @@ protected void createPackedDepthStencilBuffer() {
441454
throw new RuntimeException("PFramebuffer: size undefined.");
442455
}
443456

444-
PGraphicsOpenGL.pushFramebuffer();
445-
PGraphicsOpenGL.setFramebuffer(this);
457+
pg.pushFramebuffer();
458+
pg.setFramebuffer(this);
446459

447-
glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context);
460+
glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
448461
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
449462

450463
if (multisample) {
@@ -460,7 +473,7 @@ protected void createPackedDepthStencilBuffer() {
460473
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
461474
PGL.RENDERBUFFER, glDepthStencil);
462475

463-
PGraphicsOpenGL.popFramebuffer();
476+
pg.popFramebuffer();
464477
}
465478

466479

@@ -471,10 +484,10 @@ protected void createDepthBuffer() {
471484
throw new RuntimeException("PFramebuffer: size undefined.");
472485
}
473486

474-
PGraphicsOpenGL.pushFramebuffer();
475-
PGraphicsOpenGL.setFramebuffer(this);
487+
pg.pushFramebuffer();
488+
pg.setFramebuffer(this);
476489

477-
glDepth = PGraphicsOpenGL.createRenderBufferObject(context);
490+
glDepth = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
478491
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
479492

480493
int glConst = PGL.DEPTH_COMPONENT16;
@@ -496,7 +509,7 @@ protected void createDepthBuffer() {
496509
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
497510
PGL.RENDERBUFFER, glDepth);
498511

499-
PGraphicsOpenGL.popFramebuffer();
512+
pg.popFramebuffer();
500513
}
501514

502515

@@ -507,10 +520,10 @@ protected void createStencilBuffer() {
507520
throw new RuntimeException("PFramebuffer: size undefined.");
508521
}
509522

510-
PGraphicsOpenGL.pushFramebuffer();
511-
PGraphicsOpenGL.setFramebuffer(this);
523+
pg.pushFramebuffer();
524+
pg.setFramebuffer(this);
512525

513-
glStencil = PGraphicsOpenGL.createRenderBufferObject(context);
526+
glStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
514527
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
515528

516529
int glConst = PGL.STENCIL_INDEX1;
@@ -531,7 +544,7 @@ protected void createStencilBuffer() {
531544
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
532545
PGL.RENDERBUFFER, glStencil);
533546

534-
PGraphicsOpenGL.popFramebuffer();
547+
pg.popFramebuffer();
535548
}
536549

537550

0 commit comments

Comments
 (0)