Added new hint to enable/disable perspective corrected lines

This commit is contained in:
codeanticode
2012-01-20 16:59:15 +00:00
parent e1c836062c
commit f04373e11d
3 changed files with 54 additions and 25 deletions
+22 -20
View File
@@ -550,35 +550,37 @@ public interface PConstants {
// hints - hint values are positive for the alternate version,
// negative of the same value returns to the normal/default state
static final int ENABLE_NATIVE_FONTS = 1;
static final int DISABLE_NATIVE_FONTS = -1;
static final int ENABLE_NATIVE_FONTS = 1;
static final int DISABLE_NATIVE_FONTS = -1;
static final int DISABLE_DEPTH_TEST = 2;
static final int ENABLE_DEPTH_TEST = -2;
static final int DISABLE_DEPTH_TEST = 2;
static final int ENABLE_DEPTH_TEST = -2;
static final int ENABLE_DEPTH_SORT = 3;
static final int DISABLE_DEPTH_SORT = -3;
static final int ENABLE_DEPTH_SORT = 3;
static final int DISABLE_DEPTH_SORT = -3;
static final int DISABLE_OPENGL_ERROR_REPORT = 4;
static final int ENABLE_OPENGL_ERROR_REPORT = -4;
static final int DISABLE_OPENGL_ERROR_REPORT = 4;
static final int ENABLE_OPENGL_ERROR_REPORT = -4;
static final int ENABLE_ACCURATE_TEXTURES = 5;
static final int DISABLE_ACCURATE_TEXTURES = -5;
static final int ENABLE_ACCURATE_TEXTURES = 5;
static final int DISABLE_ACCURATE_TEXTURES = -5;
static final int DISABLE_DEPTH_MASK = 6;
static final int ENABLE_DEPTH_MASK = -6;
static final int DISABLE_DEPTH_MASK = 6;
static final int ENABLE_DEPTH_MASK = -6;
static final int ENABLE_ACCURATE_2D = 7;
static final int DISABLE_ACCURATE_2D = -7;
static final int ENABLE_ACCURATE_2D = 7;
static final int DISABLE_ACCURATE_2D = -7;
static final int DISABLE_TEXTURE_CACHE = 8;
static final int ENABLE_TEXTURE_CACHE = -8;
static final int DISABLE_TEXTURE_CACHE = 8;
static final int ENABLE_TEXTURE_CACHE = -8;
static final int DISABLE_TRANSFORM_CACHE = 9;
static final int ENABLE_TRANSFORM_CACHE = -9;
static final int DISABLE_TRANSFORM_CACHE = 9;
static final int ENABLE_TRANSFORM_CACHE = -9;
static final int ENABLE_PERSPECTIVE_CORRECTED_LINES = 10;
static final int DISABLE_PERSPECTIVE_CORRECTED_LINES = -10;
static final int HINT_COUNT = 10;
static final int HINT_COUNT = 11;
// error messages
@@ -104,19 +104,17 @@ void main() {
float thickness = attribs.w;
vec2 window_offset = perp * thickness;
/*
if (0 < perspective) {
// Perspective correction (lines will look thiner as they move away
// from the view position).
gl_Position.xy = clip_p.xy + window_offset.xy;
gl_Position.zw = clip_p.zw;
} else {
*/
// No perspective correction.
float clip_p_w = clip_p.w;
vec4 offset_p = windowToClipVector(window_offset, viewport, clip_p_w);
gl_Position = clip_p + offset_p;
//}
}
vec4 color = vec4(0, 0, 0, 0);
vec4 globalAmbient = gl_Color * gl_LightModel.ambient;
@@ -1413,7 +1413,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (hints[ENABLE_ACCURATE_2D]) {
flushMode = FLUSH_CONTINUOUSLY;
flushMode = FLUSH_CONTINUOUSLY;
} else {
flushMode = FLUSH_WHEN_FULL;
}
@@ -1737,8 +1737,14 @@ public class PGraphicsOpenGL extends PGraphics {
// HINTS
public void hint(int which) {
super.hint(which);
boolean oldValue = hints[which];
super.hint(which);
boolean newValue = hints[which];
if (oldValue == newValue) {
return;
}
if (which == DISABLE_DEPTH_TEST) {
flush();
pgl.disableDepthTest();
@@ -1768,6 +1774,17 @@ public class PGraphicsOpenGL extends PGraphics {
} else if (which == DISABLE_TEXTURE_CACHE) {
flush();
} else if (which == DISABLE_PERSPECTIVE_CORRECTED_LINES) {
if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) {
flush();
}
} else if (which == ENABLE_PERSPECTIVE_CORRECTED_LINES &&
0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) {
if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) {
flush();
}
}
}
@@ -2442,6 +2459,12 @@ public class PGraphicsOpenGL extends PGraphics {
protected void setupLineShader(int attrBufID, float[] attribs, int nvert) {
lineShader.setVecUniform("viewport", viewport[0], viewport[1], viewport[2], viewport[3]);
if (hints[ENABLE_PERSPECTIVE_CORRECTED_LINES]) {
lineShader.setIntUniform("perspective", 1);
} else {
lineShader.setIntUniform("perspective", 0);
}
lineShader.setIntUniform("lights", lightCount);
lineShader.setVecUniform("eye", cameraEyeX, cameraEyeY, cameraEyeZ, 0);
@@ -2457,6 +2480,12 @@ public class PGraphicsOpenGL extends PGraphics {
protected void setupLineShader(int attrBufID) {
lineShader.setVecUniform("viewport", viewport[0], viewport[1], viewport[2], viewport[3]);
if (hints[ENABLE_PERSPECTIVE_CORRECTED_LINES]) {
lineShader.setIntUniform("perspective", 1);
} else {
lineShader.setIntUniform("perspective", 0);
}
lineShader.setIntUniform("lights", lightCount);