All the infrastructure needed for optimized font rendering in OpenGL. Basically, this special class is needed because fonts in Processing are handled by a separate PImage for each glyph. For performance reasons, all these glyphs should be stored in a single OpenGL texture (otherwise, rendering a str
| 49 | * @author Andres Colubri |
| 50 | */ |
| 51 | 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 | |
| 66 | public FontTexture(PGraphicsOpenGL pg, PFont font, boolean is3D) { |
| 67 | pgl = pg.pgl; |
| 68 | this.is3D = is3D; |
| 69 | |
| 70 | initTexture(pg, font); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | protected void allocate() { |
| 75 | // Nothing to do here: the font textures will allocate |
| 76 | // themselves. |
| 77 | } |
| 78 | |
| 79 | |
| 80 | protected void dispose() { |
| 81 | for (int i = 0; i < textures.length; i++) { |
| 82 | textures[i].dispose(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | protected void initTexture(PGraphicsOpenGL pg, PFont font) { |
| 88 | lastTex = -1; |
| 89 | |
| 90 | int spow = PGL.nextPowerOfTwo(font.getSize()); |
| 91 | minSize = PApplet.min(PGraphicsOpenGL.maxTextureSize, |
| 92 | PApplet.max(PGL.MIN_FONT_TEX_SIZE, spow)); |
| 93 | maxSize = PApplet.min(PGraphicsOpenGL.maxTextureSize, |
| 94 | PApplet.max(PGL.MAX_FONT_TEX_SIZE, 2 * spow)); |
| 95 | |
| 96 | if (maxSize < spow) { |
| 97 | PGraphics.showWarning("The font size is too large to be properly " + |
| 98 | "displayed with OpenGL"); |
| 99 | } |
| 100 | |
| 101 | addTexture(pg); |
| 102 | |
| 103 | offsetX = 0; |
| 104 | offsetY = 0; |
| 105 | lineHeight = 0; |
| 106 | |
| 107 | texinfoMap = new HashMap<PFont.Glyph, TextureInfo>(); |
| 108 | glyphTexinfos = new TextureInfo[font.getGlyphCount()]; |
nothing calls this directly
no outgoing calls
no test coverage detected