propane 3.1.0.pre-java → 3.2.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/CHANGELOG.md +1 -5
- data/README.md +23 -12
- data/Rakefile +23 -12
- data/lib/propane/helpers/version_error.rb +6 -0
- data/lib/propane/runner.rb +12 -0
- data/lib/propane/version.rb +1 -1
- data/library/slider/slider.rb +1 -1
- data/mvnw +234 -0
- data/mvnw.cmd +145 -0
- data/pom.xml +28 -27
- data/propane.gemspec +2 -2
- data/src/main/java/japplemenubar/JAppleMenuBar.java +41 -47
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/MathToolModule.java +12 -11
- data/src/main/java/monkstone/PropaneLibrary.java +9 -10
- data/src/main/java/monkstone/core/LibraryProxy.java +124 -113
- data/src/main/java/monkstone/fastmath/Deglut.java +86 -89
- data/src/main/java/monkstone/filechooser/Chooser.java +7 -13
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -1
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +4 -4
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +9 -9
- data/src/main/java/monkstone/slider/SimpleSlider.java +0 -9
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +11 -13
- data/src/main/java/monkstone/slider/Slider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +8 -9
- data/src/main/java/monkstone/vecmath/AppRender.java +2 -2
- data/src/main/java/monkstone/vecmath/ShapeRender.java +2 -2
- data/src/main/java/monkstone/vecmath/package-info.java +2 -2
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/VideoInterface.java +11 -5
- data/src/main/java/monkstone/videoevent/package-info.java +2 -2
- data/src/main/java/processing/awt/PGraphicsJava2D.java +1742 -2243
- data/src/main/java/processing/awt/PShapeJava2D.java +268 -270
- data/src/main/java/processing/awt/PSurfaceAWT.java +821 -920
- data/src/main/java/processing/core/DesktopHandler.java +94 -0
- data/src/main/java/processing/core/PApplet.java +14170 -14082
- data/src/main/java/processing/core/PConstants.java +447 -473
- data/src/main/java/processing/core/PFont.java +867 -873
- data/src/main/java/processing/core/PGraphics.java +7193 -7428
- data/src/main/java/processing/core/PImage.java +3051 -3117
- data/src/main/java/processing/core/PMatrix.java +159 -172
- data/src/main/java/processing/core/PMatrix2D.java +403 -444
- data/src/main/java/processing/core/PMatrix3D.java +735 -749
- data/src/main/java/processing/core/PShape.java +2651 -2793
- data/src/main/java/processing/core/PShapeOBJ.java +415 -422
- data/src/main/java/processing/core/PShapeSVG.java +1466 -1475
- data/src/main/java/processing/core/PStyle.java +37 -40
- data/src/main/java/processing/core/PSurface.java +98 -103
- data/src/main/java/processing/core/PSurfaceNone.java +208 -236
- data/src/main/java/processing/core/PVector.java +961 -990
- data/src/main/java/processing/data/DoubleDict.java +709 -753
- data/src/main/java/processing/data/DoubleList.java +695 -748
- data/src/main/java/processing/data/FloatDict.java +702 -746
- data/src/main/java/processing/data/FloatList.java +697 -751
- data/src/main/java/processing/data/IntDict.java +673 -718
- data/src/main/java/processing/data/IntList.java +633 -699
- data/src/main/java/processing/data/JSONArray.java +873 -931
- data/src/main/java/processing/data/JSONObject.java +1165 -1262
- data/src/main/java/processing/data/JSONTokener.java +341 -351
- data/src/main/java/processing/data/LongDict.java +662 -707
- data/src/main/java/processing/data/LongList.java +634 -700
- data/src/main/java/processing/data/Sort.java +41 -37
- data/src/main/java/processing/data/StringDict.java +486 -522
- data/src/main/java/processing/data/StringList.java +580 -624
- data/src/main/java/processing/data/Table.java +3508 -3686
- data/src/main/java/processing/data/TableRow.java +183 -182
- data/src/main/java/processing/data/XML.java +883 -957
- data/src/main/java/processing/event/Event.java +66 -87
- data/src/main/java/processing/event/KeyEvent.java +41 -48
- data/src/main/java/processing/event/MouseEvent.java +93 -103
- data/src/main/java/processing/event/TouchEvent.java +6 -10
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +5 -69
- data/src/main/java/processing/javafx/PSurfaceFX.java +2 -7
- data/src/main/java/processing/opengl/FontTexture.java +270 -290
- data/src/main/java/processing/opengl/FrameBuffer.java +363 -375
- data/src/main/java/processing/opengl/LinePath.java +500 -543
- data/src/main/java/processing/opengl/LineStroker.java +582 -593
- data/src/main/java/processing/opengl/PGL.java +2881 -2904
- data/src/main/java/processing/opengl/PGraphics2D.java +315 -408
- data/src/main/java/processing/opengl/PGraphics3D.java +72 -107
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12043 -12230
- data/src/main/java/processing/opengl/PJOGL.java +1681 -1745
- data/src/main/java/processing/opengl/PShader.java +1257 -1260
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4599 -4662
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1030 -1047
- data/src/main/java/processing/opengl/Texture.java +1397 -1462
- data/src/main/java/processing/opengl/VertexBuffer.java +55 -57
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/vendors/Rakefile +1 -1
- metadata +12 -8
- data/src/main/java/processing/core/ThinkDifferent.java +0 -70
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
|
2
|
-
|
|
3
1
|
/*
|
|
4
2
|
Part of the Processing project - http://processing.org
|
|
5
3
|
|
|
@@ -20,8 +18,7 @@
|
|
|
20
18
|
Public License along with this library; if not, write to the
|
|
21
19
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
22
20
|
Boston, MA 02111-1307 USA
|
|
23
|
-
*/
|
|
24
|
-
|
|
21
|
+
*/
|
|
25
22
|
package processing.opengl;
|
|
26
23
|
|
|
27
24
|
import processing.core.PApplet;
|
|
@@ -33,217 +30,204 @@ import processing.core.PImage;
|
|
|
33
30
|
import java.util.HashMap;
|
|
34
31
|
|
|
35
32
|
/**
|
|
36
|
-
* All the infrastructure needed for optimized font rendering
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* glyphs
|
|
45
|
-
* in the case that the font size is very large, one single
|
|
46
|
-
* OpenGL texture might not be enough to store all the glyphs,
|
|
47
|
-
* so PFontTexture also takes care of spreading a single font
|
|
33
|
+
* All the infrastructure needed for optimized font rendering in OpenGL.
|
|
34
|
+
* Basically, this special class is needed because fonts in Processing are
|
|
35
|
+
* handled by a separate PImage for each glyph. For performance reasons, all
|
|
36
|
+
* these glyphs should be stored in a single OpenGL texture (otherwise,
|
|
37
|
+
* rendering a string of text would involve binding and un-binding several
|
|
38
|
+
* textures. PFontTexture manages the correspondence between individual glyphs
|
|
39
|
+
* and the large OpenGL texture containing them. Also, in the case that the font
|
|
40
|
+
* size is very large, one single OpenGL texture might not be enough to store
|
|
41
|
+
* all the glyphs, so PFontTexture also takes care of spreading a single font
|
|
48
42
|
* over several textures.
|
|
43
|
+
*
|
|
49
44
|
* @author Andres Colubri
|
|
50
45
|
*/
|
|
51
46
|
class FontTexture implements PConstants {
|
|
52
|
-
protected PGL pgl;
|
|
53
|
-
protected boolean is3D;
|
|
54
|
-
|
|
55
|
-
protected int minSize;
|
|
56
|
-
protected int maxSize;
|
|
57
|
-
protected int offsetX;
|
|
58
|
-
protected int offsetY;
|
|
59
|
-
protected int lineHeight;
|
|
60
|
-
protected Texture[] textures = null;
|
|
61
|
-
protected PImage[] images = null;
|
|
62
|
-
protected int lastTex;
|
|
63
|
-
protected TextureInfo[] glyphTexinfos;
|
|
64
|
-
protected HashMap<PFont.Glyph, TextureInfo> texinfoMap;
|
|
65
47
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
48
|
+
protected PGL pgl;
|
|
49
|
+
protected boolean is3D;
|
|
50
|
+
|
|
51
|
+
protected int minSize;
|
|
52
|
+
protected int maxSize;
|
|
53
|
+
protected int offsetX;
|
|
54
|
+
protected int offsetY;
|
|
55
|
+
protected int lineHeight;
|
|
56
|
+
protected Texture[] textures = null;
|
|
57
|
+
protected PImage[] images = null;
|
|
58
|
+
protected int lastTex;
|
|
59
|
+
protected TextureInfo[] glyphTexinfos;
|
|
60
|
+
protected HashMap<PFont.Glyph, TextureInfo> texinfoMap;
|
|
61
|
+
|
|
62
|
+
public FontTexture(PGraphicsOpenGL pg, PFont font, boolean is3D) {
|
|
63
|
+
pgl = pg.pgl;
|
|
64
|
+
this.is3D = is3D;
|
|
65
|
+
|
|
66
|
+
initTexture(pg, font);
|
|
67
|
+
}
|
|
72
68
|
|
|
69
|
+
protected void allocate() {
|
|
70
|
+
// Nothing to do here: the font textures will allocate
|
|
71
|
+
// themselves.
|
|
72
|
+
}
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
protected void dispose() {
|
|
75
|
+
for (int i = 0; i < textures.length; i++) {
|
|
76
|
+
textures[i].dispose();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
78
79
|
|
|
80
|
+
protected void initTexture(PGraphicsOpenGL pg, PFont font) {
|
|
81
|
+
lastTex = -1;
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
int spow = PGL.nextPowerOfTwo(font.getSize());
|
|
84
|
+
minSize = PApplet.min(PGraphicsOpenGL.maxTextureSize,
|
|
85
|
+
PApplet.max(PGL.MIN_FONT_TEX_SIZE, spow));
|
|
86
|
+
maxSize = PApplet.min(PGraphicsOpenGL.maxTextureSize,
|
|
87
|
+
PApplet.max(PGL.MAX_FONT_TEX_SIZE, 2 * spow));
|
|
85
88
|
|
|
89
|
+
if (maxSize < spow) {
|
|
90
|
+
PGraphics.showWarning("The font size is too large to be properly "
|
|
91
|
+
+ "displayed with OpenGL");
|
|
92
|
+
}
|
|
86
93
|
|
|
87
|
-
|
|
88
|
-
lastTex = -1;
|
|
94
|
+
addTexture(pg);
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
maxSize = PApplet.min(PGraphicsOpenGL.maxTextureSize,
|
|
94
|
-
PApplet.max(PGL.MAX_FONT_TEX_SIZE, 2 * spow));
|
|
96
|
+
offsetX = 0;
|
|
97
|
+
offsetY = 0;
|
|
98
|
+
lineHeight = 0;
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
texinfoMap = new HashMap<PFont.Glyph, TextureInfo>();
|
|
101
|
+
glyphTexinfos = new TextureInfo[font.getGlyphCount()];
|
|
102
|
+
addAllGlyphsToTexture(pg, font);
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
addTexture(pg)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
public boolean addTexture(PGraphicsOpenGL pg) {
|
|
106
|
+
int w, h;
|
|
107
|
+
boolean resize;
|
|
108
|
+
|
|
109
|
+
w = maxSize;
|
|
110
|
+
if (-1 < lastTex && textures[lastTex].glHeight < maxSize) {
|
|
111
|
+
// The height of the current texture is less than the maximum, this
|
|
112
|
+
// means we can replace it with a larger texture.
|
|
113
|
+
h = PApplet.min(2 * textures[lastTex].glHeight, maxSize);
|
|
114
|
+
resize = true;
|
|
115
|
+
} else {
|
|
116
|
+
h = minSize;
|
|
117
|
+
resize = false;
|
|
118
|
+
}
|
|
106
119
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
120
|
+
Texture tex;
|
|
121
|
+
if (is3D) {
|
|
122
|
+
// Bilinear sampling ensures that the texture doesn't look pixelated
|
|
123
|
+
// either when it is magnified or minified...
|
|
124
|
+
tex = new Texture(pg, w, h,
|
|
125
|
+
new Texture.Parameters(ARGB, Texture.BILINEAR, false));
|
|
126
|
+
} else {
|
|
127
|
+
// ...however, the effect of bilinear sampling is to add some blurriness
|
|
128
|
+
// to the text in its original size. In 2D, we assume that text will be
|
|
129
|
+
// shown at its original size, so linear sampling is chosen instead (which
|
|
130
|
+
// only affects minimized text).
|
|
131
|
+
tex = new Texture(pg, w, h,
|
|
132
|
+
new Texture.Parameters(ARGB, Texture.LINEAR, false));
|
|
133
|
+
}
|
|
111
134
|
|
|
135
|
+
if (textures == null) {
|
|
136
|
+
textures = new Texture[1];
|
|
137
|
+
textures[0] = tex;
|
|
138
|
+
images = new PImage[1];
|
|
139
|
+
images[0] = pg.wrapTexture(tex);
|
|
140
|
+
lastTex = 0;
|
|
141
|
+
} else if (resize) {
|
|
142
|
+
// Replacing old smaller texture with larger one.
|
|
143
|
+
// But first we must copy the contents of the older
|
|
144
|
+
// texture into the new one.
|
|
145
|
+
Texture tex0 = textures[lastTex];
|
|
146
|
+
tex.put(tex0);
|
|
147
|
+
textures[lastTex] = tex;
|
|
148
|
+
|
|
149
|
+
pg.setCache(images[lastTex], tex);
|
|
150
|
+
images[lastTex].width = tex.width;
|
|
151
|
+
images[lastTex].height = tex.height;
|
|
152
|
+
} else {
|
|
153
|
+
// Adding new texture to the list.
|
|
154
|
+
lastTex = textures.length;
|
|
155
|
+
Texture[] tempTex = new Texture[lastTex + 1];
|
|
156
|
+
PApplet.arrayCopy(textures, tempTex, textures.length);
|
|
157
|
+
tempTex[lastTex] = tex;
|
|
158
|
+
textures = tempTex;
|
|
159
|
+
|
|
160
|
+
PImage[] tempImg = new PImage[textures.length];
|
|
161
|
+
PApplet.arrayCopy(images, tempImg, images.length);
|
|
162
|
+
tempImg[lastTex] = pg.wrapTexture(tex);
|
|
163
|
+
images = tempImg;
|
|
164
|
+
}
|
|
112
165
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
boolean resize;
|
|
166
|
+
// Make sure that the current texture is bound.
|
|
167
|
+
tex.bind();
|
|
116
168
|
|
|
117
|
-
|
|
118
|
-
if (-1 < lastTex && textures[lastTex].glHeight < maxSize) {
|
|
119
|
-
// The height of the current texture is less than the maximum, this
|
|
120
|
-
// means we can replace it with a larger texture.
|
|
121
|
-
h = PApplet.min(2 * textures[lastTex].glHeight, maxSize);
|
|
122
|
-
resize = true;
|
|
123
|
-
} else {
|
|
124
|
-
h = minSize;
|
|
125
|
-
resize = false;
|
|
169
|
+
return resize;
|
|
126
170
|
}
|
|
127
171
|
|
|
128
|
-
|
|
129
|
-
if (is3D) {
|
|
130
|
-
// Bilinear sampling ensures that the texture doesn't look pixelated
|
|
131
|
-
// either when it is magnified or minified...
|
|
132
|
-
tex = new Texture(pg, w, h,
|
|
133
|
-
new Texture.Parameters(ARGB, Texture.BILINEAR, false));
|
|
134
|
-
} else {
|
|
135
|
-
// ...however, the effect of bilinear sampling is to add some blurriness
|
|
136
|
-
// to the text in its original size. In 2D, we assume that text will be
|
|
137
|
-
// shown at its original size, so linear sampling is chosen instead (which
|
|
138
|
-
// only affects minimized text).
|
|
139
|
-
tex = new Texture(pg, w, h,
|
|
140
|
-
new Texture.Parameters(ARGB, Texture.LINEAR, false));
|
|
172
|
+
public void begin() {
|
|
141
173
|
}
|
|
142
174
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
images[0] = pg.wrapTexture(tex);
|
|
148
|
-
lastTex = 0;
|
|
149
|
-
} else if (resize) {
|
|
150
|
-
// Replacing old smaller texture with larger one.
|
|
151
|
-
// But first we must copy the contents of the older
|
|
152
|
-
// texture into the new one.
|
|
153
|
-
Texture tex0 = textures[lastTex];
|
|
154
|
-
tex.put(tex0);
|
|
155
|
-
textures[lastTex] = tex;
|
|
156
|
-
|
|
157
|
-
pg.setCache(images[lastTex], tex);
|
|
158
|
-
images[lastTex].width = tex.width;
|
|
159
|
-
images[lastTex].height = tex.height;
|
|
160
|
-
} else {
|
|
161
|
-
// Adding new texture to the list.
|
|
162
|
-
lastTex = textures.length;
|
|
163
|
-
Texture[] tempTex = new Texture[lastTex + 1];
|
|
164
|
-
PApplet.arrayCopy(textures, tempTex, textures.length);
|
|
165
|
-
tempTex[lastTex] = tex;
|
|
166
|
-
textures = tempTex;
|
|
167
|
-
|
|
168
|
-
PImage[] tempImg = new PImage[textures.length];
|
|
169
|
-
PApplet.arrayCopy(images, tempImg, images.length);
|
|
170
|
-
tempImg[lastTex] = pg.wrapTexture(tex);
|
|
171
|
-
images = tempImg;
|
|
175
|
+
public void end() {
|
|
176
|
+
for (int i = 0; i < textures.length; i++) {
|
|
177
|
+
pgl.disableTexturing(textures[i].glTarget);
|
|
178
|
+
}
|
|
172
179
|
}
|
|
173
180
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return resize;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
public void begin() {
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
public void end() {
|
|
186
|
-
for (int i = 0; i < textures.length; i++) {
|
|
187
|
-
pgl.disableTexturing(textures[i].glTarget);
|
|
181
|
+
public PImage getTexture(TextureInfo info) {
|
|
182
|
+
return images[info.texIndex];
|
|
188
183
|
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
184
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
public void addAllGlyphsToTexture(PGraphicsOpenGL pg, PFont font) {
|
|
199
|
-
// loop over current glyphs.
|
|
200
|
-
for (int i = 0; i < font.getGlyphCount(); i++) {
|
|
201
|
-
addToTexture(pg, i, font.getGlyph(i));
|
|
185
|
+
// Add all the current glyphs to opengl texture.
|
|
186
|
+
public void addAllGlyphsToTexture(PGraphicsOpenGL pg, PFont font) {
|
|
187
|
+
// loop over current glyphs.
|
|
188
|
+
for (int i = 0; i < font.getGlyphCount(); i++) {
|
|
189
|
+
addToTexture(pg, i, font.getGlyph(i));
|
|
190
|
+
}
|
|
202
191
|
}
|
|
203
|
-
}
|
|
204
192
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
193
|
+
public void updateGlyphsTexCoords() {
|
|
194
|
+
// loop over current glyphs.
|
|
195
|
+
for (int i = 0; i < glyphTexinfos.length; i++) {
|
|
196
|
+
TextureInfo tinfo = glyphTexinfos[i];
|
|
197
|
+
if (tinfo != null && tinfo.texIndex == lastTex) {
|
|
198
|
+
tinfo.updateUV();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
213
201
|
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
public TextureInfo getTexInfo(PFont.Glyph glyph) {
|
|
218
|
-
TextureInfo info = texinfoMap.get(glyph);
|
|
219
|
-
return info;
|
|
220
|
-
}
|
|
221
202
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (n == 0) {
|
|
226
|
-
glyphTexinfos = new TextureInfo[1];
|
|
203
|
+
public TextureInfo getTexInfo(PFont.Glyph glyph) {
|
|
204
|
+
TextureInfo info = texinfoMap.get(glyph);
|
|
205
|
+
return info;
|
|
227
206
|
}
|
|
228
|
-
addToTexture(pg, n, glyph);
|
|
229
|
-
return glyphTexinfos[n];
|
|
230
|
-
}
|
|
231
|
-
|
|
232
207
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
208
|
+
public TextureInfo addToTexture(PGraphicsOpenGL pg, PFont.Glyph glyph) {
|
|
209
|
+
int n = glyphTexinfos.length;
|
|
210
|
+
if (n == 0) {
|
|
211
|
+
glyphTexinfos = new TextureInfo[1];
|
|
212
|
+
}
|
|
213
|
+
addToTexture(pg, n, glyph);
|
|
214
|
+
return glyphTexinfos[n];
|
|
239
215
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
216
|
+
|
|
217
|
+
public boolean contextIsOutdated() {
|
|
218
|
+
boolean outdated = false;
|
|
219
|
+
for (int i = 0; i < textures.length; i++) {
|
|
220
|
+
if (textures[i].contextIsOutdated()) {
|
|
221
|
+
outdated = true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (outdated) {
|
|
225
|
+
for (int i = 0; i < textures.length; i++) {
|
|
226
|
+
textures[i].dispose();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return outdated;
|
|
244
230
|
}
|
|
245
|
-
return outdated;
|
|
246
|
-
}
|
|
247
231
|
|
|
248
232
|
// public void draw() {
|
|
249
233
|
// Texture tex = textures[lastTex];
|
|
@@ -251,129 +235,125 @@ class FontTexture implements PConstants {
|
|
|
251
235
|
// tex.glWidth, tex.glHeight,
|
|
252
236
|
// 0, 0, tex.glWidth, tex.glHeight);
|
|
253
237
|
// }
|
|
238
|
+
// Adds this glyph to the opengl texture in PFont.
|
|
239
|
+
protected void addToTexture(PGraphicsOpenGL pg, int idx, PFont.Glyph glyph) {
|
|
240
|
+
// We add one pixel to avoid issues when sampling the font texture at
|
|
241
|
+
// fractional screen positions. I.e.: the pixel on the screen only contains
|
|
242
|
+
// half of the font rectangle, so it would sample half of the color from the
|
|
243
|
+
// glyph area in the texture, and the other half from the contiguous pixel.
|
|
244
|
+
// If the later contains a portion of the neighbor glyph and the former
|
|
245
|
+
// doesn't, this would result in a shaded pixel when the correct output is
|
|
246
|
+
// blank. This is a consequence of putting all the glyphs in a common
|
|
247
|
+
// texture with bilinear sampling.
|
|
248
|
+
int w = 1 + glyph.width + 1;
|
|
249
|
+
int h = 1 + glyph.height + 1;
|
|
250
|
+
|
|
251
|
+
// Converting the pixels array from the PImage into a valid RGBA array for
|
|
252
|
+
// OpenGL.
|
|
253
|
+
int[] rgba = new int[w * h];
|
|
254
|
+
int t = 0;
|
|
255
|
+
int p = 0;
|
|
256
|
+
if (PGL.BIG_ENDIAN) {
|
|
257
|
+
java.util.Arrays.fill(rgba, 0, w, 0xFFFFFF00); // Set the first row to blank pixels.
|
|
258
|
+
t = w;
|
|
259
|
+
for (int y = 0; y < glyph.height; y++) {
|
|
260
|
+
rgba[t++] = 0xFFFFFF00; // Set the leftmost pixel in this row as blank
|
|
261
|
+
for (int x = 0; x < glyph.width; x++) {
|
|
262
|
+
rgba[t++] = 0xFFFFFF00 | glyph.image.pixels[p++];
|
|
263
|
+
}
|
|
264
|
+
rgba[t++] = 0xFFFFFF00; // Set the rightmost pixel in this row as blank
|
|
265
|
+
}
|
|
266
|
+
java.util.Arrays.fill(rgba, (h - 1) * w, h * w, 0xFFFFFF00); // Set the last row to blank pixels.
|
|
267
|
+
} else {
|
|
268
|
+
java.util.Arrays.fill(rgba, 0, w, 0x00FFFFFF); // Set the first row to blank pixels.
|
|
269
|
+
t = w;
|
|
270
|
+
for (int y = 0; y < glyph.height; y++) {
|
|
271
|
+
rgba[t++] = 0x00FFFFFF; // Set the leftmost pixel in this row as blank
|
|
272
|
+
for (int x = 0; x < glyph.width; x++) {
|
|
273
|
+
rgba[t++] = (glyph.image.pixels[p++] << 24) | 0x00FFFFFF;
|
|
274
|
+
}
|
|
275
|
+
rgba[t++] = 0x00FFFFFF; // Set the rightmost pixel in this row as blank
|
|
276
|
+
}
|
|
277
|
+
java.util.Arrays.fill(rgba, (h - 1) * w, h * w, 0x00FFFFFF); // Set the last row to blank pixels.
|
|
278
|
+
}
|
|
254
279
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
// half of the font rectangle, so it would sample half of the color from the
|
|
261
|
-
// glyph area in the texture, and the other half from the contiguous pixel.
|
|
262
|
-
// If the later contains a portion of the neighbor glyph and the former
|
|
263
|
-
// doesn't, this would result in a shaded pixel when the correct output is
|
|
264
|
-
// blank. This is a consequence of putting all the glyphs in a common
|
|
265
|
-
// texture with bilinear sampling.
|
|
266
|
-
int w = 1 + glyph.width + 1;
|
|
267
|
-
int h = 1 + glyph.height + 1;
|
|
268
|
-
|
|
269
|
-
// Converting the pixels array from the PImage into a valid RGBA array for
|
|
270
|
-
// OpenGL.
|
|
271
|
-
int[] rgba = new int[w * h];
|
|
272
|
-
int t = 0;
|
|
273
|
-
int p = 0;
|
|
274
|
-
if (PGL.BIG_ENDIAN) {
|
|
275
|
-
java.util.Arrays.fill(rgba, 0, w, 0xFFFFFF00); // Set the first row to blank pixels.
|
|
276
|
-
t = w;
|
|
277
|
-
for (int y = 0; y < glyph.height; y++) {
|
|
278
|
-
rgba[t++] = 0xFFFFFF00; // Set the leftmost pixel in this row as blank
|
|
279
|
-
for (int x = 0; x < glyph.width; x++) {
|
|
280
|
-
rgba[t++] = 0xFFFFFF00 | glyph.image.pixels[p++];
|
|
280
|
+
// Is there room for this glyph in the current line?
|
|
281
|
+
if (offsetX + w > textures[lastTex].glWidth) {
|
|
282
|
+
// No room, go to the next line:
|
|
283
|
+
offsetX = 0;
|
|
284
|
+
offsetY += lineHeight;
|
|
281
285
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
286
|
+
lineHeight = Math.max(lineHeight, h);
|
|
287
|
+
|
|
288
|
+
boolean resized = false;
|
|
289
|
+
if (offsetY + lineHeight > textures[lastTex].glHeight) {
|
|
290
|
+
// We run out of space in the current texture, so we add a new texture:
|
|
291
|
+
resized = addTexture(pg);
|
|
292
|
+
if (resized) {
|
|
293
|
+
// Because the current texture has been resized, we need to
|
|
294
|
+
// update the UV coordinates of all the glyphs associated to it:
|
|
295
|
+
updateGlyphsTexCoords();
|
|
296
|
+
} else {
|
|
297
|
+
// A new texture has been created. Reseting texture coordinates
|
|
298
|
+
// and line.
|
|
299
|
+
offsetX = 0;
|
|
300
|
+
offsetY = 0;
|
|
301
|
+
lineHeight = 0;
|
|
302
|
+
}
|
|
292
303
|
}
|
|
293
|
-
rgba[t++] = 0x00FFFFFF; // Set the rightmost pixel in this row as blank
|
|
294
|
-
}
|
|
295
|
-
java.util.Arrays.fill(rgba, (h - 1) * w, h * w, 0x00FFFFFF); // Set the last row to blank pixels.
|
|
296
|
-
}
|
|
297
304
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
// No room, go to the next line:
|
|
301
|
-
offsetX = 0;
|
|
302
|
-
offsetY += lineHeight;
|
|
303
|
-
}
|
|
304
|
-
lineHeight = Math.max(lineHeight, h);
|
|
305
|
-
|
|
306
|
-
boolean resized = false;
|
|
307
|
-
if (offsetY + lineHeight > textures[lastTex].glHeight) {
|
|
308
|
-
// We run out of space in the current texture, so we add a new texture:
|
|
309
|
-
resized = addTexture(pg);
|
|
310
|
-
if (resized) {
|
|
311
|
-
// Because the current texture has been resized, we need to
|
|
312
|
-
// update the UV coordinates of all the glyphs associated to it:
|
|
313
|
-
updateGlyphsTexCoords();
|
|
314
|
-
} else {
|
|
315
|
-
// A new texture has been created. Reseting texture coordinates
|
|
316
|
-
// and line.
|
|
317
|
-
offsetX = 0;
|
|
318
|
-
offsetY = 0;
|
|
319
|
-
lineHeight = 0;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
305
|
+
TextureInfo tinfo = new TextureInfo(lastTex, offsetX, offsetY, w, h, rgba);
|
|
306
|
+
offsetX += w;
|
|
322
307
|
|
|
323
|
-
|
|
324
|
-
|
|
308
|
+
if (idx == glyphTexinfos.length) {
|
|
309
|
+
TextureInfo[] temp = new TextureInfo[glyphTexinfos.length + 1];
|
|
310
|
+
System.arraycopy(glyphTexinfos, 0, temp, 0, glyphTexinfos.length);
|
|
311
|
+
glyphTexinfos = temp;
|
|
312
|
+
}
|
|
325
313
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
System.arraycopy(glyphTexinfos, 0, temp, 0, glyphTexinfos.length);
|
|
329
|
-
glyphTexinfos = temp;
|
|
314
|
+
glyphTexinfos[idx] = tinfo;
|
|
315
|
+
texinfoMap.put(glyph, tinfo);
|
|
330
316
|
}
|
|
331
317
|
|
|
332
|
-
|
|
333
|
-
texinfoMap.put(glyph, tinfo);
|
|
334
|
-
}
|
|
335
|
-
|
|
318
|
+
class TextureInfo {
|
|
336
319
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
int[] pixels;
|
|
320
|
+
int texIndex;
|
|
321
|
+
int width;
|
|
322
|
+
int height;
|
|
323
|
+
int[] crop;
|
|
324
|
+
float u0, u1;
|
|
325
|
+
float v0, v1;
|
|
326
|
+
int[] pixels;
|
|
345
327
|
|
|
346
|
-
|
|
328
|
+
TextureInfo(int tidx, int cropX, int cropY, int cropW, int cropH,
|
|
347
329
|
int[] pix) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
void updateUV() {
|
|
364
|
-
width = textures[texIndex].glWidth;
|
|
365
|
-
height = textures[texIndex].glHeight;
|
|
330
|
+
texIndex = tidx;
|
|
331
|
+
crop = new int[4];
|
|
332
|
+
// The region of the texture corresponding to the glyph is surrounded by a
|
|
333
|
+
// 1-pixel wide border to avoid artifacts due to bilinear sampling. This
|
|
334
|
+
// is why the additions and subtractions to the crop values.
|
|
335
|
+
crop[0] = cropX + 1;
|
|
336
|
+
crop[1] = cropY + 1 + cropH - 2;
|
|
337
|
+
crop[2] = cropW - 2;
|
|
338
|
+
crop[3] = -cropH + 2;
|
|
339
|
+
pixels = pix;
|
|
340
|
+
updateUV();
|
|
341
|
+
updateTex();
|
|
342
|
+
}
|
|
366
343
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
v1 = v0 - (float)crop[3] / (float)height;
|
|
371
|
-
}
|
|
344
|
+
void updateUV() {
|
|
345
|
+
width = textures[texIndex].glWidth;
|
|
346
|
+
height = textures[texIndex].glHeight;
|
|
372
347
|
|
|
348
|
+
u0 = (float) crop[0] / (float) width;
|
|
349
|
+
u1 = u0 + (float) crop[2] / (float) width;
|
|
350
|
+
v0 = (float) (crop[1] + crop[3]) / (float) height;
|
|
351
|
+
v1 = v0 - (float) crop[3] / (float) height;
|
|
352
|
+
}
|
|
373
353
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
354
|
+
void updateTex() {
|
|
355
|
+
textures[texIndex].setNative(pixels, crop[0] - 1, crop[1] + crop[3] - 1,
|
|
356
|
+
crop[2] + 2, -crop[3] + 2);
|
|
357
|
+
}
|
|
377
358
|
}
|
|
378
|
-
}
|
|
379
359
|
}
|