Skip to content

Commit 565da7a

Browse files
committed
add GL_COORDS hint and better calc of cameraZ in VR
1 parent c0624aa commit 565da7a

File tree

5 files changed

+152
-141
lines changed

5 files changed

+152
-141
lines changed

core/src/processing/core/PApplet.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7904,24 +7904,6 @@ public void endPGL() {
79047904
}
79057905

79067906

7907-
/**
7908-
* Enable a hint option.
7909-
* <P>
7910-
* For the most part, hints are temporary api quirks,
7911-
* for which a proper api hasn't been properly worked out.
7912-
* for instance SMOOTH_IMAGES existed because smooth()
7913-
* wasn't yet implemented, but it will soon go away.
7914-
* <P>
7915-
* They also exist for obscure features in the graphics
7916-
* engine, like enabling/disabling single pixel lines
7917-
* that ignore the zbuffer, the way they do in alphabot.
7918-
* <P>
7919-
* Current hint options:
7920-
* <UL>
7921-
* <LI><TT>DISABLE_DEPTH_TEST</TT> -
7922-
* turns off the z-buffer in the P3D or OPENGL renderers.
7923-
* </UL>
7924-
*/
79257907
public void hint(int which) {
79267908
g.hint(which);
79277909
}
@@ -9805,4 +9787,4 @@ public void blend(PImage src,
98059787
int dx, int dy, int dw, int dh, int mode) {
98069788
g.blend(src, sx, sy, sw, sh, dx, dy, dw, dh, mode);
98079789
}
9808-
}
9790+
}

core/src/processing/core/PConstants.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -410,31 +410,34 @@ public interface PConstants {
410410
static final int DISABLE_OPENGL_ERRORS = 4;
411411
static final int ENABLE_OPENGL_ERRORS = -4;
412412

413-
static final int DISABLE_DEPTH_MASK = 5;
414-
static final int ENABLE_DEPTH_MASK = -5;
413+
static final int ENABLE_OPENGL_COORDINATES = 5;
414+
static final int DISABLE_OPENGL_COORDINATES = -5;
415415

416-
static final int DISABLE_OPTIMIZED_STROKE = 6;
417-
static final int ENABLE_OPTIMIZED_STROKE = -6;
416+
static final int DISABLE_DEPTH_MASK = 6;
417+
static final int ENABLE_DEPTH_MASK = -6;
418418

419-
static final int ENABLE_STROKE_PERSPECTIVE = 7;
420-
static final int DISABLE_STROKE_PERSPECTIVE = -7;
419+
static final int DISABLE_OPTIMIZED_STROKE = 7;
420+
static final int ENABLE_OPTIMIZED_STROKE = -7;
421421

422-
static final int DISABLE_TEXTURE_MIPMAPS = 8;
423-
static final int ENABLE_TEXTURE_MIPMAPS = -8;
422+
static final int ENABLE_STROKE_PERSPECTIVE = 8;
423+
static final int DISABLE_STROKE_PERSPECTIVE = -8;
424424

425-
static final int ENABLE_STROKE_PURE = 9;
426-
static final int DISABLE_STROKE_PURE = -9;
425+
static final int DISABLE_TEXTURE_MIPMAPS = 9;
426+
static final int ENABLE_TEXTURE_MIPMAPS = -9;
427427

428-
static final int ENABLE_BUFFER_READING = 10;
429-
static final int DISABLE_BUFFER_READING = -10;
428+
static final int ENABLE_STROKE_PURE = 10;
429+
static final int DISABLE_STROKE_PURE = -10;
430430

431-
static final int DISABLE_KEY_REPEAT = 11;
432-
static final int ENABLE_KEY_REPEAT = -11;
431+
static final int ENABLE_BUFFER_READING = 11;
432+
static final int DISABLE_BUFFER_READING = -11;
433433

434-
static final int DISABLE_ASYNC_SAVEFRAME = 12;
435-
static final int ENABLE_ASYNC_SAVEFRAME = -12;
434+
static final int DISABLE_KEY_REPEAT = 12;
435+
static final int ENABLE_KEY_REPEAT = -12;
436436

437-
static final int HINT_COUNT = 13;
437+
static final int DISABLE_ASYNC_SAVEFRAME = 13;
438+
static final int ENABLE_ASYNC_SAVEFRAME = -13;
439+
440+
static final int HINT_COUNT = 14;
438441

439442

440443
// error messages

core/src/processing/opengl/PGL.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ protected Texture wrapBackTexture(Texture texture) {
544544
glColorTex.get(backTex), TEXTURE_2D, RGBA,
545545
fboWidth, fboHeight, NEAREST, NEAREST,
546546
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
547-
texture.invertedY(PGraphicsOpenGL.Y_AXIS_DOWN);
547+
texture.invertedY(graphics.glCoordsEnabled);
548548
texture.colorBuffer(true);
549549
graphics.setCache(graphics, texture);
550550
} else {
@@ -561,7 +561,7 @@ protected Texture wrapFrontTexture(Texture texture) {
561561
glColorTex.get(frontTex), TEXTURE_2D, RGBA,
562562
fboWidth, fboHeight, NEAREST, NEAREST,
563563
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
564-
texture.invertedY(PGraphicsOpenGL.Y_AXIS_DOWN);
564+
texture.invertedY(graphics.glCoordsEnabled);
565565
texture.colorBuffer(true);
566566
} else {
567567
texture.glName = glColorTex.get(frontTex);

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ public void dispose() {
105105
/** Current flush mode. */
106106
protected int flushMode = FLUSH_WHEN_FULL;
107107

108-
/** Orientation of Y axis. */
109-
static protected boolean Y_AXIS_DOWN = true;
108+
/**
109+
* Keeps track of ENABLE_OPENGL_COORDINATES hint
110+
*/
111+
protected boolean glCoordsEnabled = false;
110112

111113
// ........................................................
112114

@@ -1851,7 +1853,15 @@ public void hint(int which) {
18511853
return;
18521854
}
18531855

1854-
if (which == DISABLE_DEPTH_TEST) {
1856+
if (which == DISABLE_OPENGL_COORDINATES) {
1857+
flush();
1858+
glCoordsEnabled = false;
1859+
1860+
} else if (which == ENABLE_OPENGL_COORDINATES) {
1861+
flush();
1862+
glCoordsEnabled = true;
1863+
1864+
} else if (which == DISABLE_DEPTH_TEST) {
18551865
flush();
18561866
pgl.disable(PGL.DEPTH_TEST);
18571867
} else if (which == ENABLE_DEPTH_TEST) {
@@ -3465,7 +3475,7 @@ public void text(char c, float x, float y) {
34653475
defaultFontOrDeath("text");
34663476
}
34673477

3468-
int sign = Y_AXIS_DOWN ? +1 : -1;
3478+
int sign = glCoordsEnabled ? +1 : -1;
34693479

34703480
if (textAlignY == CENTER) {
34713481
y += sign * textAscent() / 2;
@@ -3488,7 +3498,7 @@ public void text(String str, float x, float y) {
34883498
defaultFontOrDeath("text");
34893499
}
34903500

3491-
int sign = Y_AXIS_DOWN ? +1 : -1;
3501+
int sign = glCoordsEnabled ? +1 : -1;
34923502

34933503
int length = str.length();
34943504
if (length > textBuffer.length) {
@@ -3540,7 +3550,7 @@ public void text(String str, float x1, float y1, float x2, float y2) {
35403550
defaultFontOrDeath("text");
35413551
}
35423552

3543-
int sign = Y_AXIS_DOWN ? +1 : -1;
3553+
int sign = glCoordsEnabled ? +1 : -1;
35443554

35453555
float hradius, vradius;
35463556
switch (rectMode) {
@@ -3618,21 +3628,21 @@ public void text(String str, float x1, float y1, float x2, float y2) {
36183628
if (textAlignY == CENTER) {
36193629
lineX = 0;
36203630
float lineHigh = textAscent() + textLeading * (lineCount - 1);
3621-
float y = Y_AXIS_DOWN ? y1 + textAscent() + (boxHeight - lineHigh) / 2 : y2 - textAscent() - (boxHeight - lineHigh) / 2;
3631+
float y = glCoordsEnabled ? y1 + textAscent() + (boxHeight - lineHigh) / 2 : y2 - textAscent() - (boxHeight - lineHigh) / 2;
36223632
for (int i = 0; i < lineCount; i++) {
36233633
textLineAlignImpl(textBuffer, textBreakStart[i], textBreakStop[i], lineX, y);
36243634
y += sign * textLeading;
36253635
}
36263636

36273637
} else if (textAlignY == BOTTOM) {
3628-
float y = Y_AXIS_DOWN ? y2 - textDescent() - textLeading * (lineCount - 1) : y1 + textDescent() + textLeading * (lineCount - 1);
3638+
float y = glCoordsEnabled ? y2 - textDescent() - textLeading * (lineCount - 1) : y1 + textDescent() + textLeading * (lineCount - 1);
36293639
for (int i = 0; i < lineCount; i++) {
36303640
textLineAlignImpl(textBuffer, textBreakStart[i], textBreakStop[i], lineX, y);
36313641
y += sign * textLeading;
36323642
}
36333643

36343644
} else { // TOP or BASELINE just go to the default
3635-
float y = Y_AXIS_DOWN ? y1 + textAscent() : y2 - textAscent();
3645+
float y = glCoordsEnabled ? y1 + textAscent() : y2 - textAscent();
36363646
for (int i = 0; i < lineCount; i++) {
36373647
textLineAlignImpl(textBuffer, textBreakStart[i], textBreakStop[i], lineX, y);
36383648
y += sign * textLeading;
@@ -3764,7 +3774,7 @@ protected void textCharImpl(char ch, float x, float y) {
37643774

37653775
// The default text setting assumes an Y axis pointing down, so
37663776
// inverting in the the case Y points up
3767-
int sign = Y_AXIS_DOWN ? +1 : -1;
3777+
int sign = glCoordsEnabled ? +1 : -1;
37683778

37693779
float x1 = x + lextent * textSize;
37703780
float y1 = y - sign * textent * textSize;
@@ -6064,7 +6074,7 @@ protected void loadTextureImpl(int sampling, boolean mipmap) {
60646074
Texture.Parameters params = new Texture.Parameters(ARGB,
60656075
sampling, mipmap);
60666076
texture = new Texture(this, pixelWidth, pixelHeight, params);
6067-
texture.invertedY(Y_AXIS_DOWN);
6077+
texture.invertedY(glCoordsEnabled);
60686078
texture.colorBuffer(true);
60696079
setCache(this, texture);
60706080
}
@@ -6075,7 +6085,7 @@ protected void createPTexture() {
60756085
updatePixelSize();
60766086
if (texture != null) {
60776087
ptexture = new Texture(this, pixelWidth, pixelHeight, texture.getParameters());
6078-
ptexture.invertedY(Y_AXIS_DOWN);
6088+
ptexture.invertedY(glCoordsEnabled);
60796089
ptexture.colorBuffer(true);
60806090
}
60816091
}
@@ -6215,7 +6225,7 @@ public void filter(PShader shader) {
62156225
if (filterTexture == null || filterTexture.contextIsOutdated()) {
62166226
filterTexture = new Texture(this, texture.width, texture.height,
62176227
texture.getParameters());
6218-
filterTexture.invertedY(Y_AXIS_DOWN);
6228+
filterTexture.invertedY(glCoordsEnabled);
62196229
filterImage = wrapTexture(filterTexture);
62206230
}
62216231
filterTexture.set(texture);
@@ -6285,7 +6295,7 @@ public void copy(int sx, int sy, int sw, int sh,
62856295
loadTexture();
62866296
if (filterTexture == null || filterTexture.contextIsOutdated()) {
62876297
filterTexture = new Texture(this, texture.width, texture.height, texture.getParameters());
6288-
filterTexture.invertedY(Y_AXIS_DOWN);
6298+
filterTexture.invertedY(glCoordsEnabled);
62896299
filterImage = wrapTexture(filterTexture);
62906300
}
62916301
filterTexture.put(texture, sx, height - (sy + sh), sw, height - sy);
@@ -6605,7 +6615,7 @@ protected Texture addTexture(PImage img, Texture.Parameters params) {
66056615
img.parent = parent;
66066616
}
66076617
Texture tex = new Texture(this, img.pixelWidth, img.pixelHeight, params);
6608-
tex.invertedY(!Y_AXIS_DOWN); // Pixels are read upside down
6618+
tex.invertedY(!glCoordsEnabled); // Pixels are read upside down
66096619
setCache(img, tex);
66106620
return tex;
66116621
}

0 commit comments

Comments
 (0)