Skip to content

Commit 2be9cfd

Browse files
committed
Merged-in the changes in the core needed for the new opengl renderer
1 parent 91680d2 commit 2be9cfd

10 files changed

Lines changed: 1112 additions & 129 deletions

File tree

core/src/processing/core/PApplet.java

Lines changed: 380 additions & 29 deletions
Large diffs are not rendered by default.

core/src/processing/core/PConstants.java

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,20 @@ public interface PConstants {
111111
// has this vertex been lit yet
112112
static public final int BEEN_LIT = 35;
113113

114-
static public final int VERTEX_FIELD_COUNT = 36;
115-
114+
// has this vertex been assigned a normal yet
115+
static public final int HAS_NORMAL = 36;
116+
117+
static public final int VERTEX_FIELD_COUNT = 37;
116118

117119
// renderers known to processing.core
118120

119-
static final String P2D = "processing.core.PGraphics2D";
120-
static final String P3D = "processing.core.PGraphics3D";
121-
static final String JAVA2D = "processing.core.PGraphicsJava2D";
122-
static final String OPENGL = "processing.opengl.PGraphicsOpenGL";
123-
static final String PDF = "processing.pdf.PGraphicsPDF";
124-
static final String DXF = "processing.dxf.RawDXF";
121+
static final String P2D = "processing.core.PGraphics2D";
122+
static final String P3D = "processing.core.PGraphics3D";
123+
static final String JAVA2D = "processing.core.PGraphicsJava2D";
124+
static final String OPENGL = "processing.opengl.PGraphicsOpenGL";
125+
static final String OPENGL2 = "processing.opengl2.PGraphicsOpenGL2";
126+
static final String PDF = "processing.pdf.PGraphicsPDF";
127+
static final String DXF = "processing.dxf.RawDXF";
125128

126129

127130
// platform IDs for PApplet.platform
@@ -326,7 +329,11 @@ public interface PConstants {
326329
static final int SPHERE = 40;
327330
static final int BOX = 41;
328331

332+
static public final int LINE_STRIP = 50;
333+
static public final int LINE_LOOP = 51;
334+
static public final int POINT_SPRITES = 52;
329335

336+
330337
// shape closing modes
331338

332339
static final int OPEN = 1;
@@ -403,7 +410,37 @@ public interface PConstants {
403410
// text alignment modes
404411
// are inherited from LEFT, CENTER, RIGHT
405412

406-
413+
// PTexture
414+
415+
/** This constant identifies the texture target GL_TEXTURE_2D, that is, textures with normalized coordinates */
416+
public static final int TEXTURE2D = 0;
417+
418+
/** This constant identifies the nearest texture filter (point sampling) */
419+
//public static final int POINT = 2; // shared with shape feature
420+
/** This constant identifies the linear texture filter, usually called bilinear sampling */
421+
public static final int BILINEAR = 3;
422+
/** This constant identifies the linear/linear function to build mipmaps */
423+
public static final int TRILINEAR = 4;
424+
425+
/** This constant identifies the clamp-to-edge wrapping mode */
426+
public static final int CLAMP = 0;
427+
/** This constant identifies the repeat wrapping mode */
428+
public static final int REPEAT = 1;
429+
430+
/** Point sprite distance attenuation functions */
431+
public static final int LINEAR = 0;
432+
public static final int QUADRATIC = 1;
433+
434+
// PShape3D
435+
436+
/** Static usage mode for PShape3D (vertices won't be updated after creation). */
437+
public static final int STATIC = 0;
438+
/** Dynamic usage mode for PShape3D (vertices will be updated after creation). */
439+
public static final int DYNAMIC = 1;
440+
/** Dynamic usage mode for PShape3D (vertices will be updated at every frame). */
441+
public static final int STREAM = 2;
442+
443+
407444
// stroke modes
408445

409446
static final int SQUARE = 1 << 0; // called 'butt' in the svg spec
@@ -485,9 +522,18 @@ public interface PConstants {
485522
static final int ENABLE_ACCURATE_TEXTURES = 7;
486523
static final int DISABLE_ACCURATE_TEXTURES = -7;
487524

525+
static final int DISABLE_DEPTH_MASK = 8;
526+
static final int ENABLE_DEPTH_MASK = -8;
527+
488528
static final int HINT_COUNT = 10;
489529

490-
530+
// Rendering pipeline modes
531+
532+
static final int FIXED = 0;
533+
static final int PROG_GL2 = 1;
534+
static final int PROG_GL3 = 2;
535+
static final int PROG_GL4 = 3;
536+
491537
// error messages
492538

493539
static final String ERROR_BACKGROUND_IMAGE_SIZE =

core/src/processing/core/PFont.java

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.*;
2929
import java.util.Arrays;
3030
import java.util.HashMap;
31+
import java.util.Set;
3132

3233

3334
/**
@@ -154,7 +155,11 @@ public class PFont implements PConstants {
154155
protected FontMetrics lazyMetrics;
155156
protected int[] lazySamples;
156157

158+
159+
/** for subclasses that need to store metadata about the font */
160+
protected HashMap<PGraphics, PMetadata> cacheMap;
157161

162+
158163
public PFont() { } // for subclasses
159164

160165

@@ -239,7 +244,8 @@ public PFont(Font font, boolean smooth, char charset[]) {
239244
if (glyf.value < 128) {
240245
ascii[glyf.value] = glyphCount;
241246
}
242-
glyphs[glyphCount++] = glyf;
247+
glyf.index = glyphCount;
248+
glyphs[glyphCount++] = glyf;
243249
}
244250
}
245251

@@ -340,6 +346,7 @@ public PFont(InputStream input) throws IOException {
340346
if (glyph.value < 128) {
341347
ascii[glyph.value] = i;
342348
}
349+
glyph.index = i;
343350
glyphs[i] = glyph;
344351
}
345352

@@ -366,6 +373,19 @@ public PFont(InputStream input) throws IOException {
366373
findFont();
367374
}
368375

376+
377+
void delete() {
378+
if (cacheMap != null) {
379+
Set<PGraphics> keySet = cacheMap.keySet();
380+
if (!keySet.isEmpty()) {
381+
Object[] keys = keySet.toArray();
382+
for (int i = 0; i < keys.length; i++) {
383+
PMetadata data = getCache((PGraphics)keys[i]);
384+
data.delete();
385+
}
386+
}
387+
}
388+
}
369389

370390
/**
371391
* Write this PFont to an OutputStream.
@@ -420,6 +440,7 @@ protected void addGlyph(char c) {
420440
glyphs = (Glyph[]) PApplet.expand(glyphs);
421441
}
422442
if (glyphCount == 0) {
443+
glyph.index = 0;
423444
glyphs[glyphCount] = glyph;
424445
if (glyph.value < 128) {
425446
ascii[glyph.value] = 0;
@@ -440,6 +461,7 @@ protected void addGlyph(char c) {
440461
ascii[glyphs[j].value] = j;
441462
}
442463
}
464+
glyph.index = i;
443465
glyphs[i] = glyph;
444466
// cache locations of the ascii charset
445467
if (c < 128) ascii[c] = i;
@@ -481,6 +503,14 @@ public Font getFont() {
481503
return font;
482504
}
483505

506+
507+
/**
508+
* Return size of this font.
509+
*/
510+
public int getSize() {
511+
return size;
512+
}
513+
484514

485515
public boolean isStream() {
486516
return stream;
@@ -625,6 +655,59 @@ public float width(char c) {
625655
}
626656

627657

658+
//////////////////////////////////////////////////////////////
659+
660+
// METADATA REQUIRED BY THE RENDERERS
661+
662+
663+
/**
664+
* Store data of some kind for a renderer that requires extra metadata of
665+
* some kind. Usually this is a renderer-specific representation of the
666+
* font data, for instance a custom OpenGL texture for PGraphicsOpenGL2.
667+
* @param renderer The PGraphics renderer associated to the font
668+
* @param storage The metadata required by the renderer
669+
*/
670+
public void setCache(PGraphics renderer, PMetadata storage) {
671+
if (cacheMap == null) cacheMap = new HashMap<PGraphics, PMetadata>();
672+
cacheMap.put(renderer, storage);
673+
}
674+
675+
676+
/**
677+
* Get cache storage data for the specified renderer. Because each renderer
678+
* will cache data in different formats, it's necessary to store cache data
679+
* keyed by the renderer object. Otherwise, attempting to draw the same
680+
* image to both a PGraphicsJava2D and a PGraphicsOpenGL2 will cause errors.
681+
* @param renderer The PGraphics renderer associated to the font
682+
* @return metadata stored for the specified renderer
683+
*/
684+
public PMetadata getCache(PGraphics renderer) {
685+
if (cacheMap == null) return null;
686+
return cacheMap.get(renderer);
687+
}
688+
689+
690+
/**
691+
* Remove information associated with this renderer from the cache, if any.
692+
* @param parent The PGraphics renderer whose cache data should be removed
693+
*/
694+
public void removeCache(PGraphics renderer) {
695+
if (cacheMap != null) {
696+
cacheMap.remove(renderer);
697+
}
698+
}
699+
700+
701+
//////////////////////////////////////////////////////////////
702+
703+
public int getGlyphCount() {
704+
return glyphCount;
705+
}
706+
707+
public Glyph getGlyph(int i) {
708+
return glyphs[i];
709+
}
710+
628711
//////////////////////////////////////////////////////////////
629712

630713

@@ -757,21 +840,24 @@ static public Font findFont(String name) {
757840
* A single character, and its visage.
758841
*/
759842
public class Glyph {
760-
PImage image;
761-
int value;
762-
int height;
763-
int width;
764-
int setWidth;
765-
int topExtent;
766-
int leftExtent;
767-
843+
public PImage image;
844+
public int value;
845+
public int height;
846+
public int width;
847+
public int index;
848+
public int setWidth;
849+
public int topExtent;
850+
public int leftExtent;
851+
768852

769853
protected Glyph() {
854+
index = -1;
770855
// used when reading from a stream or for subclasses
771856
}
772857

773858

774859
protected Glyph(DataInputStream is) throws IOException {
860+
index = -1;
775861
readHeader(is);
776862
}
777863

0 commit comments

Comments
 (0)