Skip to content

Commit 539e62f

Browse files
committed
Added static context variable to PGL, in order to detect surface restarts. Fixed issue 1146
1 parent 479f53b commit 539e62f

File tree

15 files changed

+326
-306
lines changed

15 files changed

+326
-306
lines changed

android/core/src/processing/opengl/FrameBuffer.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,19 @@ public class FrameBuffer implements PConstants {
145145
protected void finalize() throws Throwable {
146146
try {
147147
if (glFbo != 0) {
148-
pg.finalizeFrameBufferObject(glFbo, context.code());
148+
pg.finalizeFrameBufferObject(glFbo, context.id());
149149
}
150150
if (glDepth != 0) {
151-
pg.finalizeRenderBufferObject(glDepth, context.code());
151+
pg.finalizeRenderBufferObject(glDepth, context.id());
152152
}
153153
if (glStencil != 0) {
154-
pg.finalizeRenderBufferObject(glStencil, context.code());
154+
pg.finalizeRenderBufferObject(glStencil, context.id());
155155
}
156156
if (glMultisample != 0) {
157-
pg.finalizeRenderBufferObject(glMultisample, context.code());
157+
pg.finalizeRenderBufferObject(glMultisample, context.id());
158158
}
159159
if (glDepthStencil != 0) {
160-
pg.finalizeRenderBufferObject(glDepthStencil, context.code());
160+
pg.finalizeRenderBufferObject(glDepthStencil, context.id());
161161
}
162162
} finally {
163163
super.finalize();
@@ -290,7 +290,7 @@ protected void allocate() {
290290
if (screenFb) {
291291
glFbo = 0;
292292
} else {
293-
glFbo = pg.createFrameBufferObject(context.code());
293+
glFbo = pg.createFrameBufferObject(context.id());
294294
}
295295

296296
// create the rest of the stuff...
@@ -313,23 +313,23 @@ protected void allocate() {
313313

314314
protected void release() {
315315
if (glFbo != 0) {
316-
pg.finalizeFrameBufferObject(glFbo, context.code());
316+
pg.finalizeFrameBufferObject(glFbo, context.id());
317317
glFbo = 0;
318318
}
319319
if (glDepth != 0) {
320-
pg.finalizeRenderBufferObject(glDepth, context.code());
320+
pg.finalizeRenderBufferObject(glDepth, context.id());
321321
glDepth = 0;
322322
}
323323
if (glStencil != 0) {
324-
pg.finalizeRenderBufferObject(glStencil, context.code());
324+
pg.finalizeRenderBufferObject(glStencil, context.id());
325325
glStencil = 0;
326326
}
327327
if (glMultisample != 0) {
328-
pg.finalizeRenderBufferObject(glMultisample, context.code());
328+
pg.finalizeRenderBufferObject(glMultisample, context.id());
329329
glMultisample = 0;
330330
}
331331
if (glDepthStencil != 0) {
332-
pg.finalizeRenderBufferObject(glDepthStencil, context.code());
332+
pg.finalizeRenderBufferObject(glDepthStencil, context.id());
333333
glDepthStencil = 0;
334334
}
335335
}
@@ -338,11 +338,11 @@ protected void release() {
338338
protected boolean contextIsOutdated() {
339339
boolean outdated = !pgl.contextIsCurrent(context);
340340
if (outdated) {
341-
pg.removeFrameBufferObject(glFbo, context.code());
342-
pg.removeRenderBufferObject(glDepth, context.code());
343-
pg.removeRenderBufferObject(glStencil, context.code());
344-
pg.removeRenderBufferObject(glDepthStencil, context.code());
345-
pg.removeRenderBufferObject(glMultisample, context.code());
341+
pg.removeFrameBufferObject(glFbo, context.id());
342+
pg.removeRenderBufferObject(glDepth, context.id());
343+
pg.removeRenderBufferObject(glStencil, context.id());
344+
pg.removeRenderBufferObject(glDepthStencil, context.id());
345+
pg.removeRenderBufferObject(glMultisample, context.id());
346346

347347
glFbo = 0;
348348
glDepth = 0;
@@ -364,7 +364,7 @@ protected void createColorBufferMultisample() {
364364
pg.pushFramebuffer();
365365
pg.setFramebuffer(this);
366366

367-
glMultisample = pg.createRenderBufferObject(context.code());
367+
glMultisample = pg.createRenderBufferObject(context.id());
368368
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
369369
pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
370370
PGL.RGBA8, width, height);
@@ -385,7 +385,7 @@ protected void createPackedDepthStencilBuffer() {
385385
pg.pushFramebuffer();
386386
pg.setFramebuffer(this);
387387

388-
glDepthStencil = pg.createRenderBufferObject(context.code());
388+
glDepthStencil = pg.createRenderBufferObject(context.id());
389389
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
390390

391391
if (multisample) {
@@ -415,7 +415,7 @@ protected void createDepthBuffer() {
415415
pg.pushFramebuffer();
416416
pg.setFramebuffer(this);
417417

418-
glDepth = pg.createRenderBufferObject(context.code());
418+
glDepth = pg.createRenderBufferObject(context.id());
419419
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
420420

421421
int glConst = PGL.DEPTH_COMPONENT16;
@@ -451,7 +451,7 @@ protected void createStencilBuffer() {
451451
pg.pushFramebuffer();
452452
pg.setFramebuffer(this);
453453

454-
glStencil = pg.createRenderBufferObject(context.code());
454+
glStencil = pg.createRenderBufferObject(context.id());
455455
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
456456

457457
int glConst = PGL.STENCIL_INDEX1;

android/core/src/processing/opengl/PFontTexture.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public boolean contextIsOutdated() {
249249
}
250250
if (outdated) {
251251
for (int i = 0; i < textures.length; i++) {
252-
pg.removeTextureObject(textures[i].glName, textures[i].context.code());
252+
pg.removeTextureObject(textures[i].glName, textures[i].context.id());
253253
textures[i].glName = 0;
254254
}
255255
}

android/core/src/processing/opengl/PGL.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ public class PGL {
318318

319319
/** GLU interface **/
320320
public PGLU glu;
321+
322+
/** The current opengl context */
323+
static public EGLContext context;
321324

322325
/** The PGraphics object using this interface */
323326
protected PGraphicsOpenGL pg;
@@ -328,7 +331,7 @@ public class PGL {
328331
/** The renderer object driving the rendering loop,
329332
* analogous to the GLEventListener in JOGL */
330333
protected AndroidRenderer renderer;
331-
334+
332335
/** Which texturing targets are enabled */
333336
protected static boolean[] texturingTargets = { false };
334337

@@ -1284,25 +1287,41 @@ protected Context createEmptyContext() {
12841287

12851288

12861289
protected Context getCurrentContext() {
1287-
return new Context();
1290+
return new Context(context);
12881291
}
12891292

12901293

12911294
protected class Context {
1295+
protected int id;
12921296

1293-
Context() {
1297+
Context() {
1298+
id = -1;
12941299
}
1295-
1300+
1301+
Context(EGLContext context) {
1302+
if (context != null) {
1303+
id = context.hashCode();
1304+
} else {
1305+
id = -1;
1306+
}
1307+
}
1308+
12961309
boolean current() {
1297-
return true;
1298-
}
1299-
1300-
boolean equal() {
1301-
return true;
1310+
return equal(context);
13021311
}
1303-
1304-
int code() {
1305-
return 0;
1312+
1313+
boolean equal(EGLContext context) {
1314+
if (id == -1 || context == null) {
1315+
// A null context means a still non-created resource,
1316+
// so it is considered equal to the argument.
1317+
return true;
1318+
} else {
1319+
return id == context.hashCode();
1320+
}
1321+
}
1322+
1323+
int id() {
1324+
return id;
13061325
}
13071326
}
13081327

@@ -2035,6 +2054,7 @@ public void onSurfaceChanged(GL10 igl, int iwidth, int iheight) {
20352054

20362055
public void onSurfaceCreated(GL10 igl, EGLConfig config) {
20372056
gl = igl;
2057+
context = ((EGL10)EGLContext.getEGL()).eglGetCurrentContext();
20382058
}
20392059
}
20402060

android/core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,45 +1153,45 @@ protected void createPolyBuffers() {
11531153
int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT;
11541154
int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX;
11551155

1156-
glPolyVertex = createVertexBufferObject(polyBuffersContext.code());
1156+
glPolyVertex = createVertexBufferObject(polyBuffersContext.id());
11571157
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex);
11581158
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
11591159

1160-
glPolyColor = createVertexBufferObject(polyBuffersContext.code());
1160+
glPolyColor = createVertexBufferObject(polyBuffersContext.id());
11611161
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor);
11621162
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
11631163

1164-
glPolyNormal = createVertexBufferObject(polyBuffersContext.code());
1164+
glPolyNormal = createVertexBufferObject(polyBuffersContext.id());
11651165
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal);
11661166
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
11671167

1168-
glPolyTexcoord = createVertexBufferObject(polyBuffersContext.code());
1168+
glPolyTexcoord = createVertexBufferObject(polyBuffersContext.id());
11691169
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord);
11701170
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, null, PGL.STATIC_DRAW);
11711171

11721172
glPolyAmbient = pgPrimary.createVertexBufferObject(
1173-
polyBuffersContext.code());
1173+
polyBuffersContext.id());
11741174
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
11751175
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
11761176

11771177
glPolySpecular = pgPrimary.createVertexBufferObject(
1178-
polyBuffersContext.code());
1178+
polyBuffersContext.id());
11791179
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular);
11801180
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
11811181

11821182
glPolyEmissive = pgPrimary.createVertexBufferObject(
1183-
polyBuffersContext.code());
1183+
polyBuffersContext.id());
11841184
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive);
11851185
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
11861186

11871187
glPolyShininess = pgPrimary.createVertexBufferObject(
1188-
polyBuffersContext.code());
1188+
polyBuffersContext.id());
11891189
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess);
11901190
pgl.bufferData(PGL.ARRAY_BUFFER, sizef, null, PGL.STATIC_DRAW);
11911191

11921192
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
11931193

1194-
glPolyIndex = createVertexBufferObject(polyBuffersContext.code());
1194+
glPolyIndex = createVertexBufferObject(polyBuffersContext.id());
11951195
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex);
11961196
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW);
11971197

@@ -1266,31 +1266,31 @@ protected boolean polyBuffersContextIsOutdated() {
12661266

12671267
protected void deletePolyBuffers() {
12681268
if (polyBuffersCreated) {
1269-
deleteVertexBufferObject(glPolyVertex, polyBuffersContext.code());
1269+
deleteVertexBufferObject(glPolyVertex, polyBuffersContext.id());
12701270
glPolyVertex = 0;
12711271

1272-
deleteVertexBufferObject(glPolyColor, polyBuffersContext.code());
1272+
deleteVertexBufferObject(glPolyColor, polyBuffersContext.id());
12731273
glPolyColor = 0;
12741274

1275-
deleteVertexBufferObject(glPolyNormal, polyBuffersContext.code());
1275+
deleteVertexBufferObject(glPolyNormal, polyBuffersContext.id());
12761276
glPolyNormal = 0;
12771277

1278-
deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext.code());
1278+
deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext.id());
12791279
glPolyTexcoord = 0;
12801280

1281-
deleteVertexBufferObject(glPolyAmbient, polyBuffersContext.code());
1281+
deleteVertexBufferObject(glPolyAmbient, polyBuffersContext.id());
12821282
glPolyAmbient = 0;
12831283

1284-
deleteVertexBufferObject(glPolySpecular, polyBuffersContext.code());
1284+
deleteVertexBufferObject(glPolySpecular, polyBuffersContext.id());
12851285
glPolySpecular = 0;
12861286

1287-
deleteVertexBufferObject(glPolyEmissive, polyBuffersContext.code());
1287+
deleteVertexBufferObject(glPolyEmissive, polyBuffersContext.id());
12881288
glPolyEmissive = 0;
12891289

1290-
deleteVertexBufferObject(glPolyShininess, polyBuffersContext.code());
1290+
deleteVertexBufferObject(glPolyShininess, polyBuffersContext.id());
12911291
glPolyShininess = 0;
12921292

1293-
deleteVertexBufferObject(glPolyIndex, polyBuffersContext.code());
1293+
deleteVertexBufferObject(glPolyIndex, polyBuffersContext.id());
12941294
glPolyIndex = 0;
12951295

12961296
polyBuffersCreated = false;
@@ -1306,22 +1306,22 @@ protected void createLineBuffers() {
13061306
int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT;
13071307
int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX;
13081308

1309-
glLineVertex = createVertexBufferObject(lineBuffersContext.code());
1309+
glLineVertex = createVertexBufferObject(lineBuffersContext.id());
13101310

13111311
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex);
13121312
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
13131313

1314-
glLineColor = createVertexBufferObject(lineBuffersContext.code());
1314+
glLineColor = createVertexBufferObject(lineBuffersContext.id());
13151315
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor);
13161316
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
13171317

1318-
glLineAttrib = createVertexBufferObject(lineBuffersContext.code());
1318+
glLineAttrib = createVertexBufferObject(lineBuffersContext.id());
13191319
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
13201320
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, null, PGL.STATIC_DRAW);
13211321

13221322
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
13231323

1324-
glLineIndex = createVertexBufferObject(lineBuffersContext.code());
1324+
glLineIndex = createVertexBufferObject(lineBuffersContext.id());
13251325
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
13261326
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW);
13271327

@@ -1372,16 +1372,16 @@ protected boolean lineBufferContextIsOutdated() {
13721372

13731373
protected void deleteLineBuffers() {
13741374
if (lineBuffersCreated) {
1375-
deleteVertexBufferObject(glLineVertex, lineBuffersContext.code());
1375+
deleteVertexBufferObject(glLineVertex, lineBuffersContext.id());
13761376
glLineVertex = 0;
13771377

1378-
deleteVertexBufferObject(glLineColor, lineBuffersContext.code());
1378+
deleteVertexBufferObject(glLineColor, lineBuffersContext.id());
13791379
glLineColor = 0;
13801380

1381-
deleteVertexBufferObject(glLineAttrib, lineBuffersContext.code());
1381+
deleteVertexBufferObject(glLineAttrib, lineBuffersContext.id());
13821382
glLineAttrib = 0;
13831383

1384-
deleteVertexBufferObject(glLineIndex, lineBuffersContext.code());
1384+
deleteVertexBufferObject(glLineIndex, lineBuffersContext.id());
13851385
glLineIndex = 0;
13861386

13871387
lineBuffersCreated = false;
@@ -1397,21 +1397,21 @@ protected void createPointBuffers() {
13971397
int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT;
13981398
int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX;
13991399

1400-
glPointVertex = createVertexBufferObject(pointBuffersContext.code());
1400+
glPointVertex = createVertexBufferObject(pointBuffersContext.id());
14011401
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex);
14021402
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
14031403

1404-
glPointColor = createVertexBufferObject(pointBuffersContext.code());
1404+
glPointColor = createVertexBufferObject(pointBuffersContext.id());
14051405
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor);
14061406
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
14071407

1408-
glPointAttrib = createVertexBufferObject(pointBuffersContext.code());
1408+
glPointAttrib = createVertexBufferObject(pointBuffersContext.id());
14091409
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
14101410
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, null, PGL.STATIC_DRAW);
14111411

14121412
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
14131413

1414-
glPointIndex = createVertexBufferObject(pointBuffersContext.code());
1414+
glPointIndex = createVertexBufferObject(pointBuffersContext.id());
14151415
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
14161416
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW);
14171417

@@ -1462,16 +1462,16 @@ protected boolean pointBuffersContextIsOutdated() {
14621462

14631463
protected void deletePointBuffers() {
14641464
if (pointBuffersCreated) {
1465-
deleteVertexBufferObject(glPointVertex, pointBuffersContext.code());
1465+
deleteVertexBufferObject(glPointVertex, pointBuffersContext.id());
14661466
glPointVertex = 0;
14671467

1468-
deleteVertexBufferObject(glPointColor, pointBuffersContext.code());
1468+
deleteVertexBufferObject(glPointColor, pointBuffersContext.id());
14691469
glPointColor = 0;
14701470

1471-
deleteVertexBufferObject(glPointAttrib, pointBuffersContext.code());
1471+
deleteVertexBufferObject(glPointAttrib, pointBuffersContext.id());
14721472
glPointAttrib = 0;
14731473

1474-
deleteVertexBufferObject(glPointIndex, pointBuffersContext.code());
1474+
deleteVertexBufferObject(glPointIndex, pointBuffersContext.id());
14751475
glPointIndex = 0;
14761476

14771477
pointBuffersCreated = false;

0 commit comments

Comments
 (0)