MCPcopy Index your code
hub / github.com/benfry/processing4 / addTexture

Method addTexture

core/src/processing/opengl/FontTexture.java:113–178  ·  view source on GitHub ↗
(PGraphicsOpenGL pg)

Source from the content-addressed store, hash-verified

111
112
113 public boolean addTexture(PGraphicsOpenGL pg) {
114 int w, h;
115 boolean resize;
116
117 w = maxSize;
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;
126 }
127
128 Texture tex;
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));
141 }
142
143 if (textures == null) {
144 textures = new Texture[1];
145 textures[0] = tex;
146 images = new PImage[1];
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);

Callers 2

initTextureMethod · 0.95
addToTextureMethod · 0.95

Calls 6

minMethod · 0.95
putMethod · 0.95
arrayCopyMethod · 0.95
bindMethod · 0.95
wrapTextureMethod · 0.80
setCacheMethod · 0.45

Tested by

no test coverage detected