Skip to content

Commit a29daed

Browse files
committed
gl update
1 parent 861c93b commit a29daed

29 files changed

+943
-1330
lines changed

core/src/processing/core/PApplet.java

+5
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,11 @@ synchronized public void noLoop() {
22172217
}
22182218

22192219

2220+
public boolean isLooping() {
2221+
return looping;
2222+
}
2223+
2224+
22202225
//////////////////////////////////////////////////////////////
22212226

22222227

core/src/processing/core/PGraphics.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -3188,15 +3188,40 @@ protected boolean textModeCheck(int mode) {
31883188
* Sets the text size, also resets the value for the leading.
31893189
*/
31903190
public void textSize(float size) {
3191+
// https://github.com/processing/processing/issues/3110
3192+
if (size <= 0) {
3193+
// Using System.err instead of showWarning to avoid running out of
3194+
// memory with a bunch of textSize() variants (cause of this bug is
3195+
// usually something done with map() or in a loop).
3196+
System.err.println("textSize(" + size + ") ignored: " +
3197+
"the text size must be larger than zero");
3198+
return;
3199+
}
31913200
if (textFont == null) {
31923201
defaultFontOrDeath("textSize", size);
31933202
}
3203+
textSizeImpl(size);
3204+
}
31943205

3206+
3207+
/**
3208+
* Called from textSize() after validating size. Subclasses
3209+
* will want to override this one.
3210+
* @param size size of the text, greater than zero
3211+
*/
3212+
protected void textSizeImpl(float size) {
3213+
handleTextSize(size);
3214+
}
3215+
3216+
3217+
/**
3218+
* Sets the actual size. Called from textSizeImpl and
3219+
* from textFontImpl after setting the font.
3220+
* @param size size of the text, greater than zero
3221+
*/
3222+
protected void handleTextSize(float size) {
31953223
textSize = size;
3196-
// PApplet.println("textSize textAscent -> " + textAscent());
3197-
// PApplet.println("textSize textDescent -> " + textDescent());
31983224
textLeading = (textAscent() + textDescent()) * 1.275f;
3199-
// PApplet.println("textSize textLeading = " + textLeading);
32003225
}
32013226

32023227

core/src/processing/core/PImage.java

+14
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public class PImage implements PConstants, Cloneable {
5151
public int[] pixels;
5252
public int width, height;
5353

54+
/**
55+
* For the time being, simply to ensure compatibility with Java mode code
56+
*/
57+
public int pixelDensity = 1;
58+
public int pixelWidth;
59+
public int pixelHeight;
60+
5461
/**
5562
* Path to parent object that will be used with save().
5663
* This prevents users from needing savePath() to use PImage.save().
@@ -148,6 +155,10 @@ public void init(int width, int height, int format) { // ignore
148155
this.pixels = new int[width*height];
149156
this.format = format;
150157
// this.cache = null;
158+
159+
pixelWidth = width * pixelDensity;
160+
pixelHeight = height * pixelDensity;
161+
this.pixels = new int[pixelWidth * pixelHeight];
151162
}
152163

153164

@@ -182,6 +193,9 @@ public PImage(Object nativeObject) {
182193
this.height = bitmap.getHeight();
183194
this.pixels = null;
184195
this.format = bitmap.hasAlpha() ? ARGB : RGB;
196+
this.pixelDensity = 1;
197+
this.pixelWidth = width;
198+
this.pixelHeight = height;
185199
}
186200

187201

core/src/processing/core/PShape.java

+3
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ public class PShape implements PConstants {
238238

239239
/** True if contains 3D data */
240240
protected boolean is3D = false;
241+
242+
protected boolean perVertexStyles = false;
243+
241244

242245
// should this be called vertices (consistent with PGraphics internals)
243246
// or does that hurt flexibility?

core/src/processing/opengl/FontTexture.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
22

33
/*
4-
Part of the Processing project - http://processing.org
4+
Processing OpenGL (c) 2011-2015 Andres Colubri
55
6-
Copyright (c) 2011-12 Ben Fry and Casey Reas
6+
Part of the Processing project - http://processing.org
7+
Copyright (c) 2001-04 Massachusetts Institute of Technology
8+
Copyright (c) 2004-12 Ben Fry and Casey Reas
9+
Copyright (c) 2012-15 The Processing Foundation
710
811
This library is free software; you can redistribute it and/or
912
modify it under the terms of the GNU Lesser General Public
10-
License as published by the Free Software Foundation; either
11-
version 2.1 of the License, or (at your option) any later version.
13+
License version 2.1 as published by the Free Software Foundation.
1214
1315
This library is distributed in the hope that it will be useful,
1416
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,7 +21,7 @@
1921
Public License along with this library; if not, write to the
2022
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
2123
Boston, MA 02111-1307 USA
22-
*/
24+
*/
2325

2426
package processing.opengl;
2527

core/src/processing/opengl/FrameBuffer.java

+60-69
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
22

33
/*
4-
Part of the Processing project - http://processing.org
4+
Processing OpenGL (c) 2011-2015 Andres Colubri
55
6-
Copyright (c) 2011-12 Ben Fry and Casey Reas
6+
Part of the Processing project - http://processing.org
7+
Copyright (c) 2001-04 Massachusetts Institute of Technology
8+
Copyright (c) 2004-12 Ben Fry and Casey Reas
9+
Copyright (c) 2012-15 The Processing Foundation
710
811
This library is free software; you can redistribute it and/or
912
modify it under the terms of the GNU Lesser General Public
10-
License as published by the Free Software Foundation; either
11-
version 2.1 of the License, or (at your option) any later version.
13+
License version 2.1 as published by the Free Software Foundation.
1214
1315
This library is distributed in the hope that it will be useful,
1416
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,12 +21,13 @@
1921
Public License along with this library; if not, write to the
2022
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
2123
Boston, MA 02111-1307 USA
22-
*/
24+
*/
2325

2426
package processing.opengl;
2527

2628
import processing.core.PApplet;
2729
import processing.core.PConstants;
30+
import processing.opengl.PGraphicsOpenGL.GLResourceFrameBuffer;
2831

2932
import java.nio.IntBuffer;
3033

@@ -51,6 +54,7 @@ public class FrameBuffer implements PConstants {
5154
public int glMultisample;
5255
public int width;
5356
public int height;
57+
private GLResourceFrameBuffer glres;
5458

5559
protected int depthBits;
5660
protected int stencilBits;
@@ -148,31 +152,6 @@ public class FrameBuffer implements PConstants {
148152
}
149153

150154

151-
@Override
152-
protected void finalize() throws Throwable {
153-
try {
154-
if (!screenFb) {
155-
if (glFbo != 0) {
156-
PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context);
157-
}
158-
if (glDepth != 0) {
159-
PGraphicsOpenGL.finalizeRenderBufferObject(glDepth, context);
160-
}
161-
if (glStencil != 0) {
162-
PGraphicsOpenGL.finalizeRenderBufferObject(glStencil, context);
163-
}
164-
if (glMultisample != 0) {
165-
PGraphicsOpenGL.finalizeRenderBufferObject(glMultisample, context);
166-
}
167-
if (glDepthStencil != 0) {
168-
PGraphicsOpenGL.finalizeRenderBufferObject(glDepthStencil, context);
169-
}
170-
}
171-
} finally {
172-
super.finalize();
173-
}
174-
}
175-
176155
public void clear() {
177156
pg.pushFramebuffer();
178157
pg.setFramebuffer(this);
@@ -353,26 +332,27 @@ protected void allocate() {
353332
dispose(); // Just in the case this object is being re-allocated.
354333

355334
context = pgl.getCurrentContext();
335+
glres = new GLResourceFrameBuffer(this);
356336

357337
if (screenFb) {
358338
glFbo = 0;
359339
} else {
360340
//create the FBO object...
361-
glFbo = PGraphicsOpenGL.createFrameBufferObject(context, pgl);
341+
// glFbo = PGraphicsOpenGL.createFrameBufferObject(context, pgl);
362342

363343
// ... and then create the rest of the stuff.
364344
if (multisample) {
365-
createColorBufferMultisample();
345+
initColorBufferMultisample();
366346
}
367347

368348
if (packedDepthStencil) {
369-
createPackedDepthStencilBuffer();
349+
initPackedDepthStencilBuffer();
370350
} else {
371351
if (0 < depthBits) {
372-
createDepthBuffer();
352+
initDepthBuffer();
373353
}
374354
if (0 < stencilBits) {
375-
createStencilBuffer();
355+
initStencilBuffer();
376356
}
377357
}
378358
}
@@ -381,27 +361,37 @@ protected void allocate() {
381361

382362
protected void dispose() {
383363
if (screenFb) return;
384-
385-
if (glFbo != 0) {
386-
PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context);
364+
if (glres != null) {
365+
glres.dispose();
387366
glFbo = 0;
388-
}
389-
if (glDepth != 0) {
390-
PGraphicsOpenGL.finalizeRenderBufferObject(glDepth, context);
391367
glDepth = 0;
392-
}
393-
if (glStencil != 0) {
394-
PGraphicsOpenGL.finalizeRenderBufferObject(glStencil, context);
395368
glStencil = 0;
396-
}
397-
if (glMultisample != 0) {
398-
PGraphicsOpenGL.finalizeRenderBufferObject(glMultisample, context);
399369
glMultisample = 0;
400-
}
401-
if (glDepthStencil != 0) {
402-
PGraphicsOpenGL.finalizeRenderBufferObject(glDepthStencil, context);
403370
glDepthStencil = 0;
371+
glres = null;
404372
}
373+
374+
375+
// if (glFbo != 0) {
376+
// PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context);
377+
// glFbo = 0;
378+
// }
379+
// if (glDepth != 0) {
380+
// PGraphicsOpenGL.finalizeRenderBufferObject(glDepth, context);
381+
// glDepth = 0;
382+
// }
383+
// if (glStencil != 0) {
384+
// PGraphicsOpenGL.finalizeRenderBufferObject(glStencil, context);
385+
// glStencil = 0;
386+
// }
387+
// if (glMultisample != 0) {
388+
// PGraphicsOpenGL.finalizeRenderBufferObject(glMultisample, context);
389+
// glMultisample = 0;
390+
// }
391+
// if (glDepthStencil != 0) {
392+
// PGraphicsOpenGL.finalizeRenderBufferObject(glDepthStencil, context);
393+
// glDepthStencil = 0;
394+
// }
405395
}
406396

407397

@@ -410,17 +400,18 @@ protected boolean contextIsOutdated() {
410400

411401
boolean outdated = !pgl.contextIsCurrent(context);
412402
if (outdated) {
413-
PGraphicsOpenGL.removeFrameBufferObject(glFbo, context);
414-
PGraphicsOpenGL.removeRenderBufferObject(glDepth, context);
415-
PGraphicsOpenGL.removeRenderBufferObject(glStencil, context);
416-
PGraphicsOpenGL.removeRenderBufferObject(glDepthStencil, context);
417-
PGraphicsOpenGL.removeRenderBufferObject(glMultisample, context);
418-
419-
glFbo = 0;
420-
glDepth = 0;
421-
glStencil = 0;
422-
glDepthStencil = 0;
423-
glMultisample = 0;
403+
dispose();
404+
// PGraphicsOpenGL.removeFrameBufferObject(glFbo, context);
405+
// PGraphicsOpenGL.removeRenderBufferObject(glDepth, context);
406+
// PGraphicsOpenGL.removeRenderBufferObject(glStencil, context);
407+
// PGraphicsOpenGL.removeRenderBufferObject(glDepthStencil, context);
408+
// PGraphicsOpenGL.removeRenderBufferObject(glMultisample, context);
409+
//
410+
// glFbo = 0;
411+
// glDepth = 0;
412+
// glStencil = 0;
413+
// glDepthStencil = 0;
414+
// glMultisample = 0;
424415

425416
for (int i = 0; i < numColorBuffers; i++) {
426417
colorBufferTex[i] = null;
@@ -430,13 +421,13 @@ protected boolean contextIsOutdated() {
430421
}
431422

432423

433-
protected void createColorBufferMultisample() {
424+
protected void initColorBufferMultisample() {
434425
if (screenFb) return;
435426

436427
pg.pushFramebuffer();
437428
pg.setFramebuffer(this);
438429

439-
glMultisample = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
430+
// glMultisample = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
440431
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
441432
pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
442433
PGL.RGBA8, width, height);
@@ -447,7 +438,7 @@ protected void createColorBufferMultisample() {
447438
}
448439

449440

450-
protected void createPackedDepthStencilBuffer() {
441+
protected void initPackedDepthStencilBuffer() {
451442
if (screenFb) return;
452443

453444
if (width == 0 || height == 0) {
@@ -457,7 +448,7 @@ protected void createPackedDepthStencilBuffer() {
457448
pg.pushFramebuffer();
458449
pg.setFramebuffer(this);
459450

460-
glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
451+
// glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
461452
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
462453

463454
if (multisample) {
@@ -477,7 +468,7 @@ protected void createPackedDepthStencilBuffer() {
477468
}
478469

479470

480-
protected void createDepthBuffer() {
471+
protected void initDepthBuffer() {
481472
if (screenFb) return;
482473

483474
if (width == 0 || height == 0) {
@@ -487,7 +478,7 @@ protected void createDepthBuffer() {
487478
pg.pushFramebuffer();
488479
pg.setFramebuffer(this);
489480

490-
glDepth = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
481+
// glDepth = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
491482
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
492483

493484
int glConst = PGL.DEPTH_COMPONENT16;
@@ -513,7 +504,7 @@ protected void createDepthBuffer() {
513504
}
514505

515506

516-
protected void createStencilBuffer() {
507+
protected void initStencilBuffer() {
517508
if (screenFb) return;
518509

519510
if (width == 0 || height == 0) {
@@ -523,7 +514,7 @@ protected void createStencilBuffer() {
523514
pg.pushFramebuffer();
524515
pg.setFramebuffer(this);
525516

526-
glStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
517+
// glStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
527518
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
528519

529520
int glConst = PGL.STENCIL_INDEX1;

0 commit comments

Comments
 (0)