Skip to content

Commit 92075ef

Browse files
committed
Made PGL object static, removed references to parent and renderer in
Texture and FrameBuffer object, fixed PGraphicsOpenGL.dispose()
1 parent 5fcf88b commit 92075ef

File tree

8 files changed

+346
-295
lines changed

8 files changed

+346
-295
lines changed

core/src/processing/opengl/FontTexture.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@
4747
* @author Andres Colubri
4848
*/
4949
class FontTexture implements PConstants {
50-
protected PApplet parent;
51-
protected PGraphicsOpenGL pg;
5250
protected PGL pgl;
53-
protected PFont font;
5451
protected boolean is3D;
5552

5653
protected int maxTexWidth;
@@ -65,15 +62,12 @@ class FontTexture implements PConstants {
6562
protected TextureInfo[] glyphTexinfos;
6663
protected HashMap<PFont.Glyph, TextureInfo> texinfoMap;
6764

68-
public FontTexture(PApplet parent, PFont font, int maxw, int maxh,
65+
public FontTexture(PGraphicsOpenGL pg, PFont font, int maxw, int maxh,
6966
boolean is3D) {
70-
this.parent = parent;
71-
this.font = font;
72-
pg = (PGraphicsOpenGL)parent.g;
73-
pgl = pg.pgl;
67+
pgl = PGraphicsOpenGL.pgl;
7468
this.is3D = is3D;
7569

76-
initTexture(maxw, maxh);
70+
initTexture(pg, font, maxw, maxh);
7771
}
7872

7973

@@ -83,26 +77,26 @@ protected void allocate() {
8377
}
8478

8579

86-
protected void initTexture(int w, int h) {
80+
protected void initTexture(PGraphicsOpenGL pg, PFont font, int w, int h) {
8781
maxTexWidth = w;
8882
maxTexHeight = h;
8983

9084
currentTex = -1;
9185
lastTex = -1;
9286

93-
addTexture();
87+
addTexture(pg);
9488

9589
offsetX = 0;
9690
offsetY = 0;
9791
lineHeight = 0;
9892

9993
texinfoMap = new HashMap<PFont.Glyph, TextureInfo>();
10094
glyphTexinfos = new TextureInfo[font.getGlyphCount()];
101-
addAllGlyphsToTexture();
95+
addAllGlyphsToTexture(pg, font);
10296
}
10397

10498

105-
public boolean addTexture() {
99+
public boolean addTexture(PGraphicsOpenGL pg) {
106100
int w, h;
107101
boolean resize;
108102

@@ -122,15 +116,15 @@ public boolean addTexture() {
122116
if (is3D) {
123117
// Bilinear sampling ensures that the texture doesn't look pixelated
124118
// either when it is magnified or minified...
125-
tex = new Texture(parent, w, h,
126-
new Texture.Parameters(ARGB, Texture.BILINEAR, false));
119+
tex = new Texture(w, h, new Texture.Parameters(ARGB, Texture.BILINEAR,
120+
false));
127121
} else {
128122
// ...however, the effect of bilinear sampling is to add some blurriness
129123
// to the text in its original size. In 2D, we assume that text will be
130124
// shown at its original size, so linear sampling is chosen instead (which
131125
// only affects minimized text).
132-
tex = new Texture(parent, w, h,
133-
new Texture.Parameters(ARGB, Texture.LINEAR, false));
126+
tex = new Texture(w, h, new Texture.Parameters(ARGB, Texture.LINEAR,
127+
false));
134128
}
135129

136130
if (textures == null) {
@@ -205,10 +199,10 @@ public PImage getCurrentTexture() {
205199

206200

207201
// Add all the current glyphs to opengl texture.
208-
public void addAllGlyphsToTexture() {
202+
public void addAllGlyphsToTexture(PGraphicsOpenGL pg, PFont font) {
209203
// loop over current glyphs.
210204
for (int i = 0; i < font.getGlyphCount(); i++) {
211-
addToTexture(i, font.getGlyph(i));
205+
addToTexture(pg, i, font.getGlyph(i));
212206
}
213207
}
214208

@@ -230,12 +224,12 @@ public TextureInfo getTexInfo(PFont.Glyph glyph) {
230224
}
231225

232226

233-
public TextureInfo addToTexture(PFont.Glyph glyph) {
227+
public TextureInfo addToTexture(PGraphicsOpenGL pg, PFont.Glyph glyph) {
234228
int n = glyphTexinfos.length;
235229
if (n == 0) {
236230
glyphTexinfos = new TextureInfo[1];
237231
}
238-
addToTexture(n, glyph);
232+
addToTexture(pg, n, glyph);
239233
return glyphTexinfos[n];
240234
}
241235

@@ -249,15 +243,16 @@ public boolean contextIsOutdated() {
249243
}
250244
if (outdated) {
251245
for (int i = 0; i < textures.length; i++) {
252-
pg.removeTextureObject(textures[i].glName, textures[i].context);
246+
PGraphicsOpenGL.removeTextureObject(textures[i].glName,
247+
textures[i].context);
253248
textures[i].glName = 0;
254249
}
255250
}
256251
return outdated;
257252
}
258253

259254
// Adds this glyph to the opengl texture in PFont.
260-
protected void addToTexture(int idx, PFont.Glyph glyph) {
255+
protected void addToTexture(PGraphicsOpenGL pg, int idx, PFont.Glyph glyph) {
261256
// We add one pixel to avoid issues when sampling the font texture at
262257
// fractional screen positions. I.e.: the pixel on the screen only contains
263258
// half of the font rectangle, so it would sample half of the color from the
@@ -310,7 +305,7 @@ protected void addToTexture(int idx, PFont.Glyph glyph) {
310305
boolean resized = false;
311306
if (offsetY + lineHeight > textures[currentTex].glHeight) {
312307
// We run out of space in the current texture, so we add a new texture:
313-
resized = addTexture();
308+
resized = addTexture(pg);
314309
if (resized) {
315310
// Because the current texture has been resized, we need to
316311
// update the UV coordinates of all the glyphs associated to it:

0 commit comments

Comments
 (0)