Skip to content

Commit a470041

Browse files
committed
continues the removal of static references
1 parent ecc9974 commit a470041

File tree

10 files changed

+262
-202
lines changed

10 files changed

+262
-202
lines changed

core/src/processing/opengl/FontTexture.java

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

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

70-
initTexture(PGraphicsOpenGL.pgPrimary, font);
71+
initTexture(pg, font);
7172
}
7273

7374

@@ -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: 10 additions & 8 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.pgPrimary.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,
78+
FrameBuffer(PGraphicsOpenGL pg, int w, int h, int samples, int colorBuffers,
7779
int depthBits, int stencilBits, boolean packedDepthStencil,
7880
boolean screen) {
79-
this();
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

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

148150

@@ -201,7 +203,7 @@ public void disableDepthTest() {
201203
noDepth = true;
202204
}
203205

204-
public void finish(PGraphicsOpenGL pg) {
206+
public void finish() {
205207
if (noDepth) {
206208
// No need to clear depth buffer because depth testing was disabled.
207209
if (pg.getHint(ENABLE_DEPTH_TEST)) {

core/src/processing/opengl/PGL.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public abstract class PGL {
5252
protected PGraphicsOpenGL pg;
5353

5454
/** OpenGL thread */
55-
protected static Thread glThread;
55+
protected Thread glThread;
5656

5757
/** ID of the GL context associated to the surface **/
58-
protected static int glContext;
58+
protected int glContext;
5959

6060
// ........................................................
6161

@@ -437,7 +437,7 @@ protected boolean getDepthWriteMask() {
437437

438438
protected Texture wrapBackTexture(Texture texture) {
439439
if (texture == null) {
440-
texture = new Texture();
440+
texture = new Texture(pg);
441441
texture.init(pg.width, pg.height,
442442
glColorTex.get(backTex), TEXTURE_2D, RGBA,
443443
fboWidth, fboHeight, NEAREST, NEAREST,
@@ -454,7 +454,7 @@ protected Texture wrapBackTexture(Texture texture) {
454454

455455
protected Texture wrapFrontTexture(Texture texture) {
456456
if (texture == null) {
457-
texture = new Texture();
457+
texture = new Texture(pg);
458458
texture.init(pg.width, pg.height,
459459
glColorTex.get(frontTex), TEXTURE_2D, RGBA,
460460
fboWidth, fboHeight, NEAREST, NEAREST,
@@ -737,6 +737,9 @@ protected void endDraw(boolean clear0) {
737737
}
738738

739739

740+
protected abstract void getGL(PGL pgl);
741+
742+
740743
protected abstract boolean canDraw();
741744

742745

@@ -903,7 +906,8 @@ public void drawTexture(int target, int id,
903906

904907

905908
protected void initTex2DShader() {
906-
if (!loadedTex2DShader || tex2DShaderContext != glContext) {
909+
if (!loadedTex2DShader/* || tex2DShaderContext != glContext*/) {
910+
System.out.println("initializing texture shader");
907911
String vertSource = PApplet.join(texVertShaderSource, "\n");
908912
String fragSource = PApplet.join(tex2DFragShaderSource, "\n");
909913
tex2DVertShader = createShader(VERTEX_SHADER, vertSource);

core/src/processing/opengl/PGraphics2D.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static protected PShape loadShapeImpl(PGraphics pg, String filename,
265265
}
266266

267267
if (svg != null) {
268-
PShapeOpenGL p2d = PShapeOpenGL.createShape2D(pg.parent, svg);
268+
PShapeOpenGL p2d = PShapeOpenGL.createShape2D((PGraphicsOpenGL)pg, svg);
269269
return p2d;
270270
} else {
271271
return null;
@@ -280,7 +280,7 @@ static protected PShape loadShapeImpl(PGraphics pg, String filename,
280280

281281
@Override
282282
public PShape createShape(PShape source) {
283-
return PShapeOpenGL.createShape2D(parent, source);
283+
return PShapeOpenGL.createShape2D(this, source);
284284
}
285285

286286

@@ -292,31 +292,31 @@ public PShape createShape() {
292292

293293
@Override
294294
public PShape createShape(int type) {
295-
return createShapeImpl(parent, type);
295+
return createShapeImpl(this, type);
296296
}
297297

298298

299299
@Override
300300
public PShape createShape(int kind, float... p) {
301-
return createShapeImpl(parent, kind, p);
301+
return createShapeImpl(this, kind, p);
302302
}
303303

304304

305-
static protected PShapeOpenGL createShapeImpl(PApplet parent, int type) {
305+
static protected PShapeOpenGL createShapeImpl(PGraphicsOpenGL pg, int type) {
306306
PShapeOpenGL shape = null;
307307
if (type == PConstants.GROUP) {
308-
shape = new PShapeOpenGL(parent, PConstants.GROUP);
308+
shape = new PShapeOpenGL(pg, PConstants.GROUP);
309309
} else if (type == PShape.PATH) {
310-
shape = new PShapeOpenGL(parent, PShape.PATH);
310+
shape = new PShapeOpenGL(pg, PShape.PATH);
311311
} else if (type == PShape.GEOMETRY) {
312-
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
312+
shape = new PShapeOpenGL(pg, PShape.GEOMETRY);
313313
}
314314
shape.is3D(false);
315315
return shape;
316316
}
317317

318318

319-
static protected PShapeOpenGL createShapeImpl(PApplet parent,
319+
static protected PShapeOpenGL createShapeImpl(PGraphicsOpenGL pg,
320320
int kind, float... p) {
321321
PShapeOpenGL shape = null;
322322
int len = p.length;
@@ -326,49 +326,49 @@ static protected PShapeOpenGL createShapeImpl(PApplet parent,
326326
showWarning("Wrong number of parameters");
327327
return null;
328328
}
329-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
329+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
330330
shape.setKind(POINT);
331331
} else if (kind == LINE) {
332332
if (len != 4) {
333333
showWarning("Wrong number of parameters");
334334
return null;
335335
}
336-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
336+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
337337
shape.setKind(LINE);
338338
} else if (kind == TRIANGLE) {
339339
if (len != 6) {
340340
showWarning("Wrong number of parameters");
341341
return null;
342342
}
343-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
343+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
344344
shape.setKind(TRIANGLE);
345345
} else if (kind == QUAD) {
346346
if (len != 8) {
347347
showWarning("Wrong number of parameters");
348348
return null;
349349
}
350-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
350+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
351351
shape.setKind(QUAD);
352352
} else if (kind == RECT) {
353353
if (len != 4 && len != 5 && len != 8 && len != 9) {
354354
showWarning("Wrong number of parameters");
355355
return null;
356356
}
357-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
357+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
358358
shape.setKind(RECT);
359359
} else if (kind == ELLIPSE) {
360360
if (len != 4 && len != 5) {
361361
showWarning("Wrong number of parameters");
362362
return null;
363363
}
364-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
364+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
365365
shape.setKind(ELLIPSE);
366366
} else if (kind == ARC) {
367367
if (len != 6 && len != 7) {
368368
showWarning("Wrong number of parameters");
369369
return null;
370370
}
371-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
371+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
372372
shape.setKind(ARC);
373373
} else if (kind == BOX) {
374374
showWarning("Primitive not supported in 2D");

core/src/processing/opengl/PGraphics3D.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static protected PShape loadShapeImpl(PGraphics pg, String filename,
144144
if (obj != null) {
145145
int prevTextureMode = pg.textureMode;
146146
pg.textureMode = NORMAL;
147-
PShapeOpenGL p3d = PShapeOpenGL.createShape3D(pg.parent, obj);
147+
PShapeOpenGL p3d = PShapeOpenGL.createShape3D((PGraphicsOpenGL)pg, obj);
148148
pg.textureMode = prevTextureMode;
149149
return p3d;
150150
} else {
@@ -160,7 +160,7 @@ static protected PShape loadShapeImpl(PGraphics pg, String filename,
160160

161161
@Override
162162
public PShape createShape(PShape source) {
163-
return PShapeOpenGL.createShape3D(parent, source);
163+
return PShapeOpenGL.createShape3D(this, source);
164164
}
165165

166166

@@ -172,31 +172,31 @@ public PShape createShape() {
172172

173173
@Override
174174
public PShape createShape(int type) {
175-
return createShapeImpl(parent, type);
175+
return createShapeImpl(this, type);
176176
}
177177

178178

179179
@Override
180180
public PShape createShape(int kind, float... p) {
181-
return createShapeImpl(parent, kind, p);
181+
return createShapeImpl(this, kind, p);
182182
}
183183

184184

185-
static protected PShapeOpenGL createShapeImpl(PApplet parent, int type) {
185+
static protected PShapeOpenGL createShapeImpl(PGraphicsOpenGL pg, int type) {
186186
PShapeOpenGL shape = null;
187187
if (type == PConstants.GROUP) {
188-
shape = new PShapeOpenGL(parent, PConstants.GROUP);
188+
shape = new PShapeOpenGL(pg, PConstants.GROUP);
189189
} else if (type == PShape.PATH) {
190-
shape = new PShapeOpenGL(parent, PShape.PATH);
190+
shape = new PShapeOpenGL(pg, PShape.PATH);
191191
} else if (type == PShape.GEOMETRY) {
192-
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
192+
shape = new PShapeOpenGL(pg, PShape.GEOMETRY);
193193
}
194194
shape.is3D(true);
195195
return shape;
196196
}
197197

198198

199-
static protected PShapeOpenGL createShapeImpl(PApplet parent,
199+
static protected PShapeOpenGL createShapeImpl(PGraphicsOpenGL pg,
200200
int kind, float... p) {
201201
PShapeOpenGL shape = null;
202202
int len = p.length;
@@ -206,63 +206,63 @@ static protected PShapeOpenGL createShapeImpl(PApplet parent,
206206
showWarning("Wrong number of parameters");
207207
return null;
208208
}
209-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
209+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
210210
shape.setKind(POINT);
211211
} else if (kind == LINE) {
212212
if (len != 4 && len != 6) {
213213
showWarning("Wrong number of parameters");
214214
return null;
215215
}
216-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
216+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
217217
shape.setKind(LINE);
218218
} else if (kind == TRIANGLE) {
219219
if (len != 6) {
220220
showWarning("Wrong number of parameters");
221221
return null;
222222
}
223-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
223+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
224224
shape.setKind(TRIANGLE);
225225
} else if (kind == QUAD) {
226226
if (len != 8) {
227227
showWarning("Wrong number of parameters");
228228
return null;
229229
}
230-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
230+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
231231
shape.setKind(QUAD);
232232
} else if (kind == RECT) {
233233
if (len != 4 && len != 5 && len != 8 && len != 9) {
234234
showWarning("Wrong number of parameters");
235235
return null;
236236
}
237-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
237+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
238238
shape.setKind(RECT);
239239
} else if (kind == ELLIPSE) {
240240
if (len != 4 && len != 5) {
241241
showWarning("Wrong number of parameters");
242242
return null;
243243
}
244-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
244+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
245245
shape.setKind(ELLIPSE);
246246
} else if (kind == ARC) {
247247
if (len != 6 && len != 7) {
248248
showWarning("Wrong number of parameters");
249249
return null;
250250
}
251-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
251+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
252252
shape.setKind(ARC);
253253
} else if (kind == BOX) {
254254
if (len != 1 && len != 3) {
255255
showWarning("Wrong number of parameters");
256256
return null;
257257
}
258-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
258+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
259259
shape.setKind(BOX);
260260
} else if (kind == SPHERE) {
261261
if (len < 1 || 3 < len) {
262262
showWarning("Wrong number of parameters");
263263
return null;
264264
}
265-
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
265+
shape = new PShapeOpenGL(pg, PShape.PRIMITIVE);
266266
shape.setKind(SPHERE);
267267
} else {
268268
showWarning("Unrecognized primitive type");

0 commit comments

Comments
 (0)