android sync

This commit is contained in:
codeanticode
2013-02-19 11:04:44 -05:00
parent af43a904b2
commit 22290d299b
13 changed files with 264 additions and 1067 deletions

View File

@@ -29,7 +29,7 @@ uniform vec3 scale;
attribute vec4 vertex;
attribute vec4 color;
attribute vec4 endpoint;
attribute vec4 direction;
varying vec4 vertColor;
@@ -45,42 +45,40 @@ vec4 windowToClipVector(vec2 window, vec4 viewport, float clip_w) {
}
void main() {
vec4 pos_p = vertex;
vec4 v_p = modelview * pos_p;
vec4 posp = modelview * vertex;
// Moving vertices slightly toward the camera
// to avoid depth-fighting with the fill triangles.
// Discussed here:
// http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848
v_p.xyz = v_p.xyz * scale;
vec4 clip_p = projection * v_p;
float thickness = endpoint.w;
posp.xyz = posp.xyz * scale;
vec4 clipp = projection * posp;
float thickness = direction.w;
if (thickness != 0.0) {
vec4 pos_q = vec4(endpoint.xyz, 1);
vec4 v_q = modelview * pos_q;
v_q.xyz = v_q.xyz * scale;
vec4 clip_q = projection * v_q;
vec4 posq = posp + modelview * vec4(direction.xyz, 1);
posq.xyz = posq.xyz * scale;
vec4 clipq = projection * posq;
vec3 window_p = clipToWindow(clip_p, viewport);
vec3 window_q = clipToWindow(clip_q, viewport);
vec3 window_p = clipToWindow(clipp, viewport);
vec3 window_q = clipToWindow(clipq, viewport);
vec3 tangent = window_q - window_p;
vec2 perp = normalize(vec2(-tangent.y, tangent.x));
vec2 window_offset = perp * thickness;
vec2 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;
gl_Position.xy = clipp.xy + offset.xy;
gl_Position.zw = clipp.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 offsetp = windowToClipVector(offset, viewport, clipp.w);
gl_Position = clipp + offsetp;
}
} else {
gl_Position = clip_p;
gl_Position = clipp;
}
vertColor = color;

View File

@@ -209,42 +209,42 @@ public class PGraphicsOpenGL extends PGraphics {
// Shaders
static protected URL defPolyColorShaderVertURL =
PGraphicsOpenGL.class.getResource("PolyColorShaderVert.glsl");
static protected URL defPolyTexShaderVertURL =
PGraphicsOpenGL.class.getResource("PolyTexShaderVert.glsl");
static protected URL defPolyLightShaderVertURL =
PGraphicsOpenGL.class.getResource("PolyLightShaderVert.glsl");
static protected URL defPolyTexlightShaderVertURL =
PGraphicsOpenGL.class.getResource("PolyTexlightShaderVert.glsl");
static protected URL defPolyNoTexShaderFragURL =
PGraphicsOpenGL.class.getResource("PolyNoTexShaderFrag.glsl");
static protected URL defPolyTexShaderFragURL =
PGraphicsOpenGL.class.getResource("PolyTexShaderFrag.glsl");
static protected URL defColorShaderVertURL =
PGraphicsOpenGL.class.getResource("ColorVert.glsl");
static protected URL defTextureShaderVertURL =
PGraphicsOpenGL.class.getResource("TextureVert.glsl");
static protected URL defLightShaderVertURL =
PGraphicsOpenGL.class.getResource("LightVert.glsl");
static protected URL defTexlightShaderVertURL =
PGraphicsOpenGL.class.getResource("TexlightVert.glsl");
static protected URL defColorShaderFragURL =
PGraphicsOpenGL.class.getResource("ColorFrag.glsl");
static protected URL defTextureShaderFragURL =
PGraphicsOpenGL.class.getResource("TextureFrag.glsl");
static protected URL defLineShaderVertURL =
PGraphicsOpenGL.class.getResource("LineShaderVert.glsl");
PGraphicsOpenGL.class.getResource("LineVert.glsl");
static protected URL defLineShaderFragURL =
PGraphicsOpenGL.class.getResource("LineShaderFrag.glsl");
PGraphicsOpenGL.class.getResource("LineFrag.glsl");
static protected URL defPointShaderVertURL =
PGraphicsOpenGL.class.getResource("PointShaderVert.glsl");
PGraphicsOpenGL.class.getResource("PointVert.glsl");
static protected URL defPointShaderFragURL =
PGraphicsOpenGL.class.getResource("PointShaderFrag.glsl");
PGraphicsOpenGL.class.getResource("PointFrag.glsl");
static protected PolyColorShader defPolyColorShader;
static protected PolyTexShader defPolyTexShader;
static protected PolyLightShader defPolyLightShader;
static protected PolyTexlightShader defPolyTexlightShader;
static protected ColorShader defColorShader;
static protected TexureShader defTextureShader;
static protected LightShader defLightShader;
static protected TexlightShader defTexlightShader;
static protected LineShader defLineShader;
static protected PointShader defPointShader;
static protected URL maskShaderFragURL =
PGraphicsOpenGL.class.getResource("MaskShaderFrag.glsl");
static protected PolyTexShader maskShader;
PGraphicsOpenGL.class.getResource("MaskFrag.glsl");
static protected TexureShader maskShader;
protected PolyColorShader polyColorShader;
protected PolyTexShader polyTexShader;
protected PolyLightShader polyLightShader;
protected PolyTexlightShader polyTexlightShader;
protected ColorShader colorShader;
protected TexureShader textureShader;
protected LightShader lightShader;
protected TexlightShader texlightShader;
protected LineShader lineShader;
protected PointShader pointShader;
@@ -1397,10 +1397,10 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.lineColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updateLineAttribsBuffer();
tessGeo.updateLineDirectionsBuffer();
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.lineAttribsBuffer, PGL.STATIC_DRAW);
tessGeo.lineDirectionsBuffer, PGL.STATIC_DRAW);
tessGeo.updateLineIndicesBuffer();
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
@@ -1490,10 +1490,10 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.pointColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePointAttribsBuffer();
tessGeo.updatePointOffsetsBuffer();
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
tessGeo.pointAttribsBuffer, PGL.STATIC_DRAW);
tessGeo.pointOffsetsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePointIndicesBuffer();
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
@@ -2511,7 +2511,7 @@ public class PGraphicsOpenGL extends PGraphics {
float[] vertices = tessGeo.lineVertices;
int[] color = tessGeo.lineColors;
float[] attribs = tessGeo.lineAttribs;
float[] attribs = tessGeo.lineDirections;
short[] indices = tessGeo.lineIndices;
IndexCache cache = tessGeo.lineIndexCache;
@@ -2614,7 +2614,7 @@ public class PGraphicsOpenGL extends PGraphics {
float[] vertices = tessGeo.pointVertices;
int[] color = tessGeo.pointColors;
float[] attribs = tessGeo.pointAttribs;
float[] attribs = tessGeo.pointOffsets;
short[] indices = tessGeo.pointIndices;
IndexCache cache = tessGeo.pointIndexCache;
@@ -5321,7 +5321,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (maskShader == null) {
maskShader = new PolyTexShader(parent, defPolyTexShaderVertURL,
maskShader = new TexureShader(parent, defTextureShaderVertURL,
maskShaderFragURL);
}
maskShader.set("mask", alpha);
@@ -5363,7 +5363,7 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void filter(PShader shader) {
if (!(shader instanceof PolyTexShader)) {
if (!(shader instanceof TexureShader)) {
PGraphics.showWarning(INVALID_FILTER_SHADER_ERROR);
return;
}
@@ -5399,8 +5399,8 @@ public class PGraphicsOpenGL extends PGraphics {
stroke = false;
// int prevBlendMode = blendMode;
// blendMode(REPLACE);
PolyTexShader prevTexShader = polyTexShader;
polyTexShader = (PolyTexShader) shader;
TexureShader prevTexShader = textureShader;
textureShader = (TexureShader) shader;
beginShape(QUADS);
texture(filterImage);
vertex(0, 0, 0, 0);
@@ -5410,7 +5410,7 @@ public class PGraphicsOpenGL extends PGraphics {
endShape();
end2D();
polyTexShader = prevTexShader;
textureShader = prevTexShader;
// Restoring previous configuration.
stroke = prevStroke;
@@ -6141,17 +6141,17 @@ public class PGraphicsOpenGL extends PGraphics {
shader = new LineShader(parent);
shader.setVertexShader(defLineShaderVertURL);
} else if (shaderType == PShader.TEXLIGHT) {
shader = new PolyTexlightShader(parent);
shader.setVertexShader(defPolyTexlightShaderVertURL);
shader = new TexlightShader(parent);
shader.setVertexShader(defTexlightShaderVertURL);
} else if (shaderType == PShader.LIGHT) {
shader = new PolyLightShader(parent);
shader.setVertexShader(defPolyLightShaderVertURL);
shader = new LightShader(parent);
shader.setVertexShader(defLightShaderVertURL);
} else if (shaderType == PShader.TEXTURE) {
shader = new PolyTexShader(parent);
shader.setVertexShader(defPolyTexShaderVertURL);
shader = new TexureShader(parent);
shader.setVertexShader(defTextureShaderVertURL);
} else if (shaderType == PShader.COLOR) {
shader = new PolyColorShader(parent);
shader.setVertexShader(defPolyColorShaderVertURL);
shader = new ColorShader(parent);
shader.setVertexShader(defColorShaderVertURL);
}
shader.setFragmentShader(fragFilename);
return shader;
@@ -6178,17 +6178,17 @@ public class PGraphicsOpenGL extends PGraphics {
shader = new LineShader(parent);
shader.setFragmentShader(defLineShaderFragURL);
} else if (shaderType == PShader.TEXLIGHT) {
shader = new PolyTexlightShader(parent);
shader.setFragmentShader(defPolyTexShaderFragURL);
shader = new TexlightShader(parent);
shader.setFragmentShader(defTextureShaderFragURL);
} else if (shaderType == PShader.LIGHT) {
shader = new PolyLightShader(parent);
shader.setFragmentShader(defPolyNoTexShaderFragURL);
shader = new LightShader(parent);
shader.setFragmentShader(defColorShaderFragURL);
} else if (shaderType == PShader.TEXTURE) {
shader = new PolyTexShader(parent);
shader.setFragmentShader(defPolyTexShaderFragURL);
shader = new TexureShader(parent);
shader.setFragmentShader(defTextureShaderFragURL);
} else if (shaderType == PShader.COLOR) {
shader = new PolyColorShader(parent);
shader.setFragmentShader(defPolyNoTexShaderFragURL);
shader = new ColorShader(parent);
shader.setFragmentShader(defColorShaderFragURL);
}
if (shader != null) {
shader.setVertexShader(vertFilename);
@@ -6199,13 +6199,13 @@ public class PGraphicsOpenGL extends PGraphics {
} else if (shaderType == PShader.LINE) {
shader = new LineShader(parent, vertFilename, fragFilename);
} else if (shaderType == PShader.TEXLIGHT) {
shader = new PolyTexlightShader(parent, vertFilename, fragFilename);
shader = new TexlightShader(parent, vertFilename, fragFilename);
} else if (shaderType == PShader.LIGHT) {
shader = new PolyLightShader(parent, vertFilename, fragFilename);
shader = new LightShader(parent, vertFilename, fragFilename);
} else if (shaderType == PShader.TEXTURE) {
shader = new PolyTexShader(parent, vertFilename, fragFilename);
shader = new TexureShader(parent, vertFilename, fragFilename);
} else if (shaderType == PShader.COLOR) {
shader = new PolyColorShader(parent, vertFilename, fragFilename);
shader = new ColorShader(parent, vertFilename, fragFilename);
}
}
return shader;
@@ -6223,14 +6223,14 @@ public class PGraphicsOpenGL extends PGraphics {
flush(); // Flushing geometry drawn with a different shader.
if (kind == TRIANGLES || kind == QUADS || kind == POLYGON) {
if (shader instanceof PolyTexShader) {
polyTexShader = (PolyTexShader) shader;
} else if (shader instanceof PolyColorShader) {
polyColorShader = (PolyColorShader) shader;
} else if (shader instanceof PolyTexlightShader) {
polyTexlightShader = (PolyTexlightShader) shader;
} else if (shader instanceof PolyLightShader) {
polyLightShader = (PolyLightShader) shader;
if (shader instanceof TexureShader) {
textureShader = (TexureShader) shader;
} else if (shader instanceof ColorShader) {
colorShader = (ColorShader) shader;
} else if (shader instanceof TexlightShader) {
texlightShader = (TexlightShader) shader;
} else if (shader instanceof LightShader) {
lightShader = (LightShader) shader;
} else {
PGraphics.showWarning(WRONG_SHADER_TYPE_ERROR);
}
@@ -6263,10 +6263,10 @@ public class PGraphicsOpenGL extends PGraphics {
flush(); // Flushing geometry drawn with a different shader.
if (kind == TRIANGLES || kind == QUADS || kind == POLYGON) {
polyTexShader = null;
polyColorShader = null;
polyTexlightShader = null;
polyLightShader = null;
textureShader = null;
colorShader = null;
texlightShader = null;
lightShader = null;
} else if (kind == LINES) {
lineShader = null;
} else if (kind == POINTS) {
@@ -6308,10 +6308,10 @@ public class PGraphicsOpenGL extends PGraphics {
// The default shaders contains references to the PGraphics object that
// creates them, so when restarting the renderer, those references should
// dissapear.
defPolyColorShader = null;
defPolyTexShader = null;
defPolyLightShader = null;
defPolyTexlightShader = null;
defColorShader = null;
defTextureShader = null;
defLightShader = null;
defTexlightShader = null;
defLineShader = null;
defPointShader = null;
maskShader = null;
@@ -6322,54 +6322,54 @@ public class PGraphicsOpenGL extends PGraphics {
BaseShader shader;
if (lit) {
if (tex) {
if (polyTexlightShader == null) {
if (defPolyTexlightShader == null) {
defPolyTexlightShader = new PolyTexlightShader(parent,
defPolyTexlightShaderVertURL,
defPolyTexShaderFragURL);
if (texlightShader == null) {
if (defTexlightShader == null) {
defTexlightShader = new TexlightShader(parent,
defTexlightShaderVertURL,
defTextureShaderFragURL);
}
shader = defPolyTexlightShader;
shader = defTexlightShader;
texlightShaderCheck();
} else {
shader = polyTexlightShader;
shader = texlightShader;
}
} else {
if (polyLightShader == null) {
if (defPolyLightShader == null) {
defPolyLightShader = new PolyLightShader(parent,
defPolyLightShaderVertURL,
defPolyNoTexShaderFragURL);
if (lightShader == null) {
if (defLightShader == null) {
defLightShader = new LightShader(parent,
defLightShaderVertURL,
defColorShaderFragURL);
}
shader = defPolyLightShader;
shader = defLightShader;
lightShaderCheck();
} else {
shader = polyLightShader;
shader = lightShader;
}
}
} else {
if (tex) {
if (polyTexShader == null) {
if (defPolyTexShader == null) {
defPolyTexShader = new PolyTexShader(parent,
defPolyTexShaderVertURL,
defPolyTexShaderFragURL);
if (textureShader == null) {
if (defTextureShader == null) {
defTextureShader = new TexureShader(parent,
defTextureShaderVertURL,
defTextureShaderFragURL);
}
shader = defPolyTexShader;
texShaderCheck();
shader = defTextureShader;
textureShaderCheck();
} else {
shader = polyTexShader;
shader = textureShader;
}
} else {
if (polyColorShader == null) {
if (defPolyColorShader == null) {
defPolyColorShader = new PolyColorShader(parent,
defPolyColorShaderVertURL,
defPolyNoTexShaderFragURL);
if (colorShader == null) {
if (defColorShader == null) {
defColorShader = new ColorShader(parent,
defColorShaderVertURL,
defColorShaderFragURL);
}
shader = defPolyColorShader;
shader = defColorShader;
colorShaderCheck();
} else {
shader = polyColorShader;
shader = colorShader;
}
}
}
@@ -6382,9 +6382,9 @@ public class PGraphicsOpenGL extends PGraphics {
protected void texlightShaderCheck() {
if (shaderWarningsEnabled &&
(polyLightShader != null ||
polyTexShader != null ||
polyColorShader != null)) {
(lightShader != null ||
textureShader != null ||
colorShader != null)) {
PGraphics.showWarning(NO_TEXLIGHT_SHADER_ERROR);
}
}
@@ -6392,19 +6392,19 @@ public class PGraphicsOpenGL extends PGraphics {
protected void lightShaderCheck() {
if (shaderWarningsEnabled &&
(polyTexlightShader != null ||
polyTexShader != null ||
polyColorShader != null)) {
(texlightShader != null ||
textureShader != null ||
colorShader != null)) {
PGraphics.showWarning(NO_LIGHT_SHADER_ERROR);
}
}
protected void texShaderCheck() {
protected void textureShaderCheck() {
if (shaderWarningsEnabled &&
(polyTexlightShader != null ||
polyLightShader != null ||
polyColorShader != null)) {
(texlightShader != null ||
lightShader != null ||
colorShader != null)) {
PGraphics.showWarning(NO_TEXTURE_SHADER_ERROR);
}
}
@@ -6412,9 +6412,9 @@ public class PGraphicsOpenGL extends PGraphics {
protected void colorShaderCheck() {
if (shaderWarningsEnabled &&
(polyTexlightShader != null ||
polyLightShader != null ||
polyTexShader != null)) {
(texlightShader != null ||
lightShader != null ||
textureShader != null)) {
PGraphics.showWarning(NO_COLOR_SHADER_ERROR);
}
}
@@ -6549,20 +6549,20 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected class PolyColorShader extends BaseShader {
protected class ColorShader extends BaseShader {
protected int vertexLoc;
protected int colorLoc;
public PolyColorShader(PApplet parent) {
public ColorShader(PApplet parent) {
super(parent);
}
public PolyColorShader(PApplet parent, String vertFilename,
public ColorShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
public PolyColorShader(PApplet parent, URL vertURL, URL fragURL) {
public ColorShader(PApplet parent, URL vertURL, URL fragURL) {
super(parent, vertURL, fragURL);
}
@@ -6599,7 +6599,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
setCommonUniforms();
}
@@ -6607,14 +6607,14 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void unbind() {
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
super.unbind();
}
}
protected class PolyLightShader extends BaseShader {
protected class LightShader extends BaseShader {
protected int normalMatrixLoc;
protected int lightCountLoc;
@@ -6635,16 +6635,16 @@ public class PGraphicsOpenGL extends PGraphics {
protected int emissiveLoc;
protected int shininessLoc;
public PolyLightShader(PApplet parent) {
public LightShader(PApplet parent) {
super(parent);
}
public PolyLightShader(PApplet parent, String vertFilename,
public LightShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
public PolyLightShader(PApplet parent, URL vertURL, URL fragURL) {
public LightShader(PApplet parent, URL vertURL, URL fragURL) {
super(parent, vertURL, fragURL);
}
@@ -6728,13 +6728,13 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < normalLoc) pgl.enableVertexAttribArray(normalLoc);
if (-1 < ambientLoc) pgl.enableVertexAttribArray(ambientLoc);
if (-1 < ambientLoc) pgl.enableVertexAttribArray(ambientLoc);
if (-1 < specularLoc) pgl.enableVertexAttribArray(specularLoc);
if (-1 < emissiveLoc) pgl.enableVertexAttribArray(emissiveLoc);
if (-1 < shininessLoc) pgl.enableVertexAttribArray(shininessLoc);
if (-1 < shininessLoc) pgl.enableVertexAttribArray(shininessLoc);
if (-1 < normalMatrixLoc) {
pgCurrent.updateGLNormal();
@@ -6748,10 +6748,9 @@ public class PGraphicsOpenGL extends PGraphics {
setUniformVector(lightAmbientLoc, pgCurrent.lightAmbient, 3, count);
setUniformVector(lightDiffuseLoc, pgCurrent.lightDiffuse, 3, count);
setUniformVector(lightSpecularLoc, pgCurrent.lightSpecular, 3, count);
setUniformVector(lightFalloffLoc,
pgCurrent.lightFalloffCoefficients, 3, count);
setUniformVector(lightSpotLoc,
pgCurrent.lightSpotParameters, 2, count);
setUniformVector(lightFalloffLoc, pgCurrent.lightFalloffCoefficients,
3, count);
setUniformVector(lightSpotLoc, pgCurrent.lightSpotParameters, 2, count);
setCommonUniforms();
}
@@ -6759,10 +6758,10 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void unbind() {
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < normalLoc) pgl.disableVertexAttribArray(normalLoc);
if (-1 < ambientLoc) pgl.disableVertexAttribArray(ambientLoc);
if (-1 < ambientLoc) pgl.disableVertexAttribArray(ambientLoc);
if (-1 < specularLoc) pgl.disableVertexAttribArray(specularLoc);
if (-1 < emissiveLoc) pgl.disableVertexAttribArray(emissiveLoc);
if (-1 < shininessLoc) pgl.disableVertexAttribArray(shininessLoc);
@@ -6772,7 +6771,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected class PolyTexShader extends PolyColorShader {
protected class TexureShader extends ColorShader {
protected int texCoordLoc;
protected int textureLoc;
@@ -6781,16 +6780,16 @@ public class PGraphicsOpenGL extends PGraphics {
protected float[] tcmat;
public PolyTexShader(PApplet parent) {
public TexureShader(PApplet parent) {
super(parent);
}
public PolyTexShader(PApplet parent, String vertFilename,
public TexureShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
public PolyTexShader(PApplet parent, URL vertURL, URL fragURL) {
public TexureShader(PApplet parent, URL vertURL, URL fragURL) {
super(parent, vertURL, fragURL);
}
@@ -6872,7 +6871,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected class PolyTexlightShader extends PolyLightShader {
protected class TexlightShader extends LightShader {
protected int texCoordLoc;
protected int textureLoc;
@@ -6881,16 +6880,16 @@ public class PGraphicsOpenGL extends PGraphics {
protected float[] tcmat;
public PolyTexlightShader(PApplet parent) {
public TexlightShader(PApplet parent) {
super(parent);
}
public PolyTexlightShader(PApplet parent, String vertFilename,
public TexlightShader(PApplet parent, String vertFilename,
String fragFilename) {
super(parent, vertFilename, fragFilename);
}
public PolyTexlightShader(PApplet parent, URL vertURL, URL fragURL) {
public TexlightShader(PApplet parent, URL vertURL, URL fragURL) {
super(parent, vertURL, fragURL);
}
@@ -6978,7 +6977,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected int vertexLoc;
protected int colorLoc;
protected int endpointLoc;
protected int directionLoc;
public LineShader(PApplet parent) {
super(parent);
@@ -6997,7 +6996,7 @@ public class PGraphicsOpenGL extends PGraphics {
public void loadAttributes() {
vertexLoc = getAttributeLoc("vertex");
colorLoc = getAttributeLoc("color");
endpointLoc = getAttributeLoc("endpoint");
directionLoc = getAttributeLoc("direction");
}
@Override
@@ -7023,7 +7022,7 @@ public class PGraphicsOpenGL extends PGraphics {
public void setLineAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(endpointLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(directionLoc, vboId, size, type, false, stride, offset);
}
@Override
@@ -7036,8 +7035,8 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < endpointLoc) pgl.enableVertexAttribArray(endpointLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < directionLoc) pgl.enableVertexAttribArray(directionLoc);
if (pgCurrent.getHint(ENABLE_STROKE_PERSPECTIVE) &&
pgCurrent.nonOrthoProjection()) {
@@ -7062,8 +7061,8 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void unbind() {
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < endpointLoc) pgl.disableVertexAttribArray(endpointLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < directionLoc) pgl.disableVertexAttribArray(directionLoc);
super.unbind();
}
@@ -7131,8 +7130,8 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < offsetLoc) pgl.enableVertexAttribArray(offsetLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < offsetLoc) pgl.enableVertexAttribArray(offsetLoc);
if (pgCurrent.getHint(ENABLE_STROKE_PERSPECTIVE) &&
pgCurrent.nonOrthoProjection()) {
@@ -7147,8 +7146,8 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void unbind() {
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < offsetLoc) pgl.disableVertexAttribArray(offsetLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < offsetLoc) pgl.disableVertexAttribArray(offsetLoc);
super.unbind();
}
@@ -8894,7 +8893,7 @@ public class PGraphicsOpenGL extends PGraphics {
int lastLineVertex;
FloatBuffer lineVerticesBuffer;
IntBuffer lineColorsBuffer;
FloatBuffer lineAttribsBuffer;
FloatBuffer lineDirectionsBuffer;
int lineIndexCount;
int firstLineIndex;
@@ -8908,7 +8907,7 @@ public class PGraphicsOpenGL extends PGraphics {
int lastPointVertex;
FloatBuffer pointVerticesBuffer;
IntBuffer pointColorsBuffer;
FloatBuffer pointAttribsBuffer;
FloatBuffer pointOffsetsBuffer;
int pointIndexCount;
int firstPointIndex;
@@ -8928,11 +8927,11 @@ public class PGraphicsOpenGL extends PGraphics {
short[] polyIndices;
float[] lineVertices;
int[] lineColors;
float[] lineAttribs;
float[] lineDirections;
short[] lineIndices;
float[] pointVertices;
int[] pointColors;
float[] pointAttribs;
float[] pointOffsets;
short[] pointIndices;
TessGeometry(int mode) {
@@ -8957,12 +8956,12 @@ public class PGraphicsOpenGL extends PGraphics {
lineVertices = new float[4 * PGL.DEFAULT_TESS_VERTICES];
lineColors = new int[PGL.DEFAULT_TESS_VERTICES];
lineAttribs = new float[4 * PGL.DEFAULT_TESS_VERTICES];
lineDirections = new float[4 * PGL.DEFAULT_TESS_VERTICES];
lineIndices = new short[PGL.DEFAULT_TESS_VERTICES];
pointVertices = new float[4 * PGL.DEFAULT_TESS_VERTICES];
pointColors = new int[PGL.DEFAULT_TESS_VERTICES];
pointAttribs = new float[2 * PGL.DEFAULT_TESS_VERTICES];
pointOffsets = new float[2 * PGL.DEFAULT_TESS_VERTICES];
pointIndices = new short[PGL.DEFAULT_TESS_VERTICES];
polyVerticesBuffer = PGL.allocateFloatBuffer(polyVertices);
@@ -8977,12 +8976,12 @@ public class PGraphicsOpenGL extends PGraphics {
lineVerticesBuffer = PGL.allocateFloatBuffer(lineVertices);
lineColorsBuffer = PGL.allocateIntBuffer(lineColors);
lineAttribsBuffer = PGL.allocateFloatBuffer(lineAttribs);
lineDirectionsBuffer = PGL.allocateFloatBuffer(lineDirections);
lineIndicesBuffer = PGL.allocateShortBuffer(lineIndices);
pointVerticesBuffer = PGL.allocateFloatBuffer(pointVertices);
pointColorsBuffer = PGL.allocateIntBuffer(pointColors);
pointAttribsBuffer = PGL.allocateFloatBuffer(pointAttribs);
pointOffsetsBuffer = PGL.allocateFloatBuffer(pointOffsets);
pointIndicesBuffer = PGL.allocateShortBuffer(pointIndices);
clear();
@@ -9075,7 +9074,7 @@ public class PGraphicsOpenGL extends PGraphics {
expandLineVertices(newSize);
expandLineColors(newSize);
expandLineAttribs(newSize);
expandLineDirections(newSize);
}
firstLineVertex = lineVertexCount;
@@ -9103,7 +9102,7 @@ public class PGraphicsOpenGL extends PGraphics {
expandPointVertices(newSize);
expandPointColors(newSize);
expandPointAttribs(newSize);
expandPointOffsets(newSize);
}
firstPointVertex = pointVertexCount;
@@ -9314,12 +9313,12 @@ public class PGraphicsOpenGL extends PGraphics {
PGL.updateIntBuffer(lineColorsBuffer, lineColors, offset, size);
}
protected void updateLineAttribsBuffer() {
updateLineAttribsBuffer(0, lineVertexCount);
protected void updateLineDirectionsBuffer() {
updateLineDirectionsBuffer(0, lineVertexCount);
}
protected void updateLineAttribsBuffer(int offset, int size) {
PGL.updateFloatBuffer(lineAttribsBuffer, lineAttribs,
protected void updateLineDirectionsBuffer(int offset, int size) {
PGL.updateFloatBuffer(lineDirectionsBuffer, lineDirections,
4 * offset, 4 * size);
}
@@ -9348,12 +9347,12 @@ public class PGraphicsOpenGL extends PGraphics {
PGL.updateIntBuffer(pointColorsBuffer, pointColors, offset, size);
}
protected void updatePointAttribsBuffer() {
updatePointAttribsBuffer(0, pointVertexCount);
protected void updatePointOffsetsBuffer() {
updatePointOffsetsBuffer(0, pointVertexCount);
}
protected void updatePointAttribsBuffer(int offset, int size) {
PGL.updateFloatBuffer(pointAttribsBuffer, pointAttribs,
protected void updatePointOffsetsBuffer(int offset, int size) {
PGL.updateFloatBuffer(pointOffsetsBuffer, pointOffsets,
2 * offset, 2 * size);
}
@@ -9446,11 +9445,11 @@ public class PGraphicsOpenGL extends PGraphics {
lineColorsBuffer = PGL.allocateIntBuffer(lineColors);
}
void expandLineAttribs(int n) {
void expandLineDirections(int n) {
float temp[] = new float[4 * n];
PApplet.arrayCopy(lineAttribs, 0, temp, 0, 4 * lineVertexCount);
lineAttribs = temp;
lineAttribsBuffer = PGL.allocateFloatBuffer(lineAttribs);
PApplet.arrayCopy(lineDirections, 0, temp, 0, 4 * lineVertexCount);
lineDirections = temp;
lineDirectionsBuffer = PGL.allocateFloatBuffer(lineDirections);
}
void expandLineIndices(int n) {
@@ -9474,11 +9473,11 @@ public class PGraphicsOpenGL extends PGraphics {
pointColorsBuffer = PGL.allocateIntBuffer(pointColors);
}
void expandPointAttribs(int n) {
void expandPointOffsets(int n) {
float temp[] = new float[2 * n];
PApplet.arrayCopy(pointAttribs, 0, temp, 0, 2 * pointVertexCount);
pointAttribs = temp;
pointAttribsBuffer = PGL.allocateFloatBuffer(pointAttribs);
PApplet.arrayCopy(pointOffsets, 0, temp, 0, 2 * pointVertexCount);
pointOffsets = temp;
pointOffsetsBuffer = PGL.allocateFloatBuffer(pointOffsets);
}
void expandPointIndices(int n) {
@@ -9511,7 +9510,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (0 < lineVertexCount && lineVertexCount < lineVertices.length / 4) {
trimLineVertices();
trimLineColors();
trimLineAttribs();
trimLineDirections();
}
if (0 < lineIndexCount && lineIndexCount < lineIndices.length) {
@@ -9521,7 +9520,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (0 < pointVertexCount && pointVertexCount < pointVertices.length / 4) {
trimPointVertices();
trimPointColors();
trimPointAttribs();
trimPointOffsets();
}
if (0 < pointIndexCount && pointIndexCount < pointIndices.length) {
@@ -9606,11 +9605,11 @@ public class PGraphicsOpenGL extends PGraphics {
lineColorsBuffer = PGL.allocateIntBuffer(lineColors);
}
void trimLineAttribs() {
void trimLineDirections() {
float temp[] = new float[4 * lineVertexCount];
PApplet.arrayCopy(lineAttribs, 0, temp, 0, 4 * lineVertexCount);
lineAttribs = temp;
lineAttribsBuffer = PGL.allocateFloatBuffer(lineAttribs);
PApplet.arrayCopy(lineDirections, 0, temp, 0, 4 * lineVertexCount);
lineDirections = temp;
lineDirectionsBuffer = PGL.allocateFloatBuffer(lineDirections);
}
void trimLineIndices() {
@@ -9634,11 +9633,11 @@ public class PGraphicsOpenGL extends PGraphics {
pointColorsBuffer = PGL.allocateIntBuffer(pointColors);
}
void trimPointAttribs() {
void trimPointOffsets() {
float temp[] = new float[2 * pointVertexCount];
PApplet.arrayCopy(pointAttribs, 0, temp, 0, 2 * pointVertexCount);
pointAttribs = temp;
pointAttribsBuffer = PGL.allocateFloatBuffer(pointAttribs);
PApplet.arrayCopy(pointOffsets, 0, temp, 0, 2 * pointVertexCount);
pointOffsets = temp;
pointOffsetsBuffer = PGL.allocateFloatBuffer(pointOffsets);
}
void trimPointIndices() {
@@ -9787,10 +9786,10 @@ public class PGraphicsOpenGL extends PGraphics {
lineColors[tessIdx] = rgba;
index = 4 * tessIdx;
lineAttribs[index++] = 0;
lineAttribs[index++] = 0;
lineAttribs[index++] = 0;
lineAttribs[index ] = 0;
lineDirections[index++] = 0;
lineDirections[index++] = 0;
lineDirections[index++] = 0;
lineDirections[index ] = 0;
}
// Sets line vertex with index tessIdx using the data from input vertices
@@ -9809,6 +9808,10 @@ public class PGraphicsOpenGL extends PGraphics {
float y1 = in.vertices[index++];
float z1 = in.vertices[index ];
float dx = x1 - x0;
float dy = y1 - y0;
float dz = z1 - z0;
if (renderMode == IMMEDIATE && flushMode == FLUSH_WHEN_FULL) {
PMatrix3D mm = modelview;
@@ -9819,9 +9822,9 @@ public class PGraphicsOpenGL extends PGraphics {
lineVertices[index ] = x0*mm.m30 + y0*mm.m31 + z0*mm.m32 + mm.m33;
index = 4 * tessIdx;
lineAttribs[index++] = x1*mm.m00 + y1*mm.m01 + z1*mm.m02 + mm.m03;
lineAttribs[index++] = x1*mm.m10 + y1*mm.m11 + z1*mm.m12 + mm.m13;
lineAttribs[index ] = x1*mm.m20 + y1*mm.m21 + z1*mm.m22 + mm.m23;
lineDirections[index++] = dx*mm.m00 + dy*mm.m01 + dz*mm.m02;
lineDirections[index++] = dx*mm.m10 + dy*mm.m11 + dz*mm.m12;
lineDirections[index ] = dx*mm.m20 + dy*mm.m21 + dz*mm.m22;
} else {
index = 4 * tessIdx;
lineVertices[index++] = x0;
@@ -9830,13 +9833,13 @@ public class PGraphicsOpenGL extends PGraphics {
lineVertices[index ] = 1;
index = 4 * tessIdx;
lineAttribs[index++] = x1;
lineAttribs[index++] = y1;
lineAttribs[index ] = z1;
lineDirections[index++] = dx;
lineDirections[index++] = dy;
lineDirections[index ] = dz;
}
lineColors[tessIdx] = rgba;
lineAttribs[4 * tessIdx + 3] = weight;
lineDirections[4 * tessIdx + 3] = weight;
}
// -----------------------------------------------------------------
@@ -10094,16 +10097,19 @@ public class PGraphicsOpenGL extends PGraphics {
float y = lineVertices[index ];
index = 4 * i;
float xa = lineAttribs[index++];
float ya = lineAttribs[index ];
float xa = lineDirections[index++];
float ya = lineDirections[index ];
float dx = xa - x;
float dy = ya - y;
index = 4 * i;
lineVertices[index++] = x*tr.m00 + y*tr.m01 + tr.m02;
lineVertices[index ] = x*tr.m10 + y*tr.m11 + tr.m12;
index = 4 * i;
lineAttribs[index++] = xa*tr.m00 + ya*tr.m01 + tr.m02;
lineAttribs[index ] = xa*tr.m10 + ya*tr.m11 + tr.m12;
lineDirections[index++] = dx*tr.m00 + dy*tr.m01;
lineDirections[index ] = dx*tr.m10 + dy*tr.m11;
}
}
}
@@ -10166,9 +10172,13 @@ public class PGraphicsOpenGL extends PGraphics {
float w = lineVertices[index ];
index = 4 * i;
float xa = lineAttribs[index++];
float ya = lineAttribs[index++];
float za = lineAttribs[index ];
float xa = lineDirections[index++];
float ya = lineDirections[index++];
float za = lineDirections[index ];
float dx = xa - x;
float dy = ya - y;
float dz = za - z;
index = 4 * i;
lineVertices[index++] = x*tr.m00 + y*tr.m01 + z*tr.m02 + w*tr.m03;
@@ -10177,9 +10187,9 @@ public class PGraphicsOpenGL extends PGraphics {
lineVertices[index ] = x*tr.m30 + y*tr.m31 + z*tr.m32 + w*tr.m33;
index = 4 * i;
lineAttribs[index++] = xa*tr.m00 + ya*tr.m01 + za*tr.m02 + tr.m03;
lineAttribs[index++] = xa*tr.m10 + ya*tr.m11 + za*tr.m12 + tr.m13;
lineAttribs[index ] = xa*tr.m20 + ya*tr.m21 + za*tr.m22 + tr.m23;
lineDirections[index++] = dx*tr.m00 + dy*tr.m01 + dz*tr.m02;
lineDirections[index++] = dx*tr.m10 + dy*tr.m11 + dz*tr.m12;
lineDirections[index ] = dx*tr.m20 + dy*tr.m21 + dz*tr.m22;
}
}
}
@@ -10384,15 +10394,15 @@ public class PGraphicsOpenGL extends PGraphics {
// the circle perimeter. The point shader will read these attributes and
// displace the vertices in screen coordinates so the circles are always
// camera facing (bilboards)
tess.pointAttribs[2 * attribIdx + 0] = 0;
tess.pointAttribs[2 * attribIdx + 1] = 0;
tess.pointOffsets[2 * attribIdx + 0] = 0;
tess.pointOffsets[2 * attribIdx + 1] = 0;
attribIdx++;
float val = 0;
float inc = (float) SINCOS_LENGTH / perim;
for (int k = 0; k < perim; k++) {
tess.pointAttribs[2 * attribIdx + 0] =
tess.pointOffsets[2 * attribIdx + 0] =
0.5f * cosLUT[(int) val] * strokeWeight;
tess.pointAttribs[2 * attribIdx + 1] =
tess.pointOffsets[2 * attribIdx + 1] =
0.5f * sinLUT[(int) val] * strokeWeight;
val = (val + inc) % SINCOS_LENGTH;
attribIdx++;
@@ -10515,13 +10525,13 @@ public class PGraphicsOpenGL extends PGraphics {
// the quad corners. The point shader will read these attributes and
// displace the vertices in screen coordinates so the quads are always
// camera facing (bilboards)
tess.pointAttribs[2 * attribIdx + 0] = 0;
tess.pointAttribs[2 * attribIdx + 1] = 0;
tess.pointOffsets[2 * attribIdx + 0] = 0;
tess.pointOffsets[2 * attribIdx + 1] = 0;
attribIdx++;
for (int k = 0; k < 4; k++) {
tess.pointAttribs[2 * attribIdx + 0] =
tess.pointOffsets[2 * attribIdx + 0] =
0.5f * QUAD_POINT_SIGNS[k][0] * strokeWeight;
tess.pointAttribs[2 * attribIdx + 1] =
tess.pointOffsets[2 * attribIdx + 1] =
0.5f * QUAD_POINT_SIGNS[k][1] * strokeWeight;
attribIdx++;
}

View File

@@ -616,32 +616,6 @@ public class PShapeOpenGL extends PShape {
}
/*
@Override
public PVector getTop(PVector top) {
if (top == null) {
top = new PVector();
}
top.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
Float.POSITIVE_INFINITY);
getVertexMin(top);
return top;
}
@Override
public PVector getBottom(PVector bottom) {
if (bottom == null) {
bottom = new PVector();
}
bottom.set(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY);
getVertexMax(bottom);
return bottom;
}
*/
protected void getVertexMin(PVector min) {
updateTessellation();
@@ -990,25 +964,6 @@ public class PShapeOpenGL extends PShape {
}
}
/*
@Override
public void beginShape() {
beginShape(POLYGON);
}
@Override
public void beginShape(int kind) {
this.kind = kind;
openShape = true;
}
@Override
public void endShape() {
endShape(OPEN);
}
*/
@Override
public void endShape(int mode) {
@@ -1051,772 +1006,6 @@ public class PShapeOpenGL extends PShape {
}
//////////////////////////////////////////////////////////////
// Stroke cap/join/weight set/update
/*
@Override
public void strokeWeight(float weight) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.strokeWeight(weight);
}
} else {
updateStrokeWeight(weight);
}
}
protected void updateStrokeWeight(float newWeight) {
if (PGraphicsOpenGL.same(strokeWeight, newWeight)) return;
float oldWeight = strokeWeight;
strokeWeight = newWeight;
Arrays.fill(inGeo.strokeWeights, 0, inGeo.vertexCount, strokeWeight);
if (shapeCreated && tessellated && (hasLines || hasPoints)) {
float resizeFactor = newWeight / oldWeight;
if (hasLines) {
if (is3D()) {
for (int i = firstLineVertex; i <= lastLineVertex; i++) {
tessGeo.lineAttribs[4 * i + 3] *= resizeFactor;
}
root.setModifiedLineAttributes(firstLineVertex, lastLineVertex);
} else if (is2D()) {
// Changing the stroke weight on a 2D shape needs a
// re-tesellation in order to replace the old line
// geometry.
markForTessellation();
}
}
if (hasPoints) {
if (is3D()) {
for (int i = firstPointVertex; i <= lastPointVertex; i++) {
tessGeo.pointAttribs[2 * i + 0] *= resizeFactor;
tessGeo.pointAttribs[2 * i + 1] *= resizeFactor;
}
root.setModifiedPointAttributes(firstPointVertex, lastPointVertex);
} else if (is2D()) {
// Changing the stroke weight on a 2D shape needs a
// re-tesellation in order to replace the old point
// geometry.
markForTessellation();
}
}
}
}
@Override
public void strokeJoin(int join) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.strokeJoin(join);
}
} else {
if (is2D() && strokeJoin != join) {
// Changing the stroke join on a 2D shape needs a
// re-tesellation in order to replace the old join
// geometry.
markForTessellation();
}
strokeJoin = join;
}
}
@Override
public void strokeCap(int cap) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.strokeCap(cap);
}
} else {
if (is2D() && strokeCap != cap) {
// Changing the stroke cap on a 2D shape needs a
// re-tesellation in order to replace the old cap
// geometry.
markForTessellation();
}
strokeCap = cap;
}
}
*/
//////////////////////////////////////////////////////////////
// Fill set/update
/*
@Override
public void noFill() {
fill = false;
// if (family == GROUP) {
// for (int i = 0; i < childCount; i++) {
// PShapeOpenGL child = (PShapeOpenGL) children[i];
// child.noFill();
// }
// } else {
// fill = false;
// updateFillColor(0x0);
// }
}
@Override
public void fill(int argb) {
}
*/
/*
@Override
public void fill(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.fill(rgb);
}
} else {
colorCalc(rgb);
fillFromCalc();
}
}
@Override
public void fill(int rgb, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.fill(rgb, alpha);
}
} else {
colorCalc(rgb, alpha);
fillFromCalc();
}
}
@Override
public void fill(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.fill(gray);
}
} else {
colorCalc(gray);
fillFromCalc();
}
}
@Override
public void fill(float gray, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.fill(gray, alpha);
}
} else {
colorCalc(gray, alpha);
fillFromCalc();
}
}
@Override
public void fill(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.fill(x, y, z);
}
} else {
colorCalc(x, y, z);
fillFromCalc();
}
}
@Override
public void fill(float x, float y, float z, float a) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.fill(x, y, z, a);
}
} else {
colorCalc(x, y, z, a);
fillFromCalc();
}
}
protected void fillFromCalc() {
fill = true;
updateFillColor(calcColor);
if (!setAmbient) {
// Setting the ambient color from the current fill
// is what the old P3D did and allows to have an
// default ambient color when the user doesn't specify
// it explicitly.
ambientFromCalc();
setAmbient = false;
}
}
protected void updateFillColor(int newFillColor) {
if (!openShape) {
PGraphics.showWarning("Neet to call beginShape() first");
return;
}
fillColor = newFillColor;
}
*/
//////////////////////////////////////////////////////////////
// Stroke (color) set/update
/*
@Override
public void noStroke() {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.noStroke();
}
} else {
if (stroke) {
// Disabling stroke on a shape previously with
// stroke needs a re-tesellation in order to remove
// the additional geometry of lines and/or points.
markForTessellation();
stroke = false;
}
updateStrokeColor(0x0);
if (is2D() && parent != null) {
((PShapeOpenGL)parent).strokedTexture(false);
}
}
}
@Override
public void stroke(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.stroke(rgb);
}
} else {
colorCalc(rgb);
strokeFromCalc();
}
}
@Override
public void stroke(int rgb, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.stroke(rgb, alpha);
}
} else {
colorCalc(rgb, alpha);
strokeFromCalc();
}
}
@Override
public void stroke(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.stroke(gray);
}
} else {
colorCalc(gray);
strokeFromCalc();
}
}
@Override
public void stroke(float gray, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.stroke(gray, alpha);
}
} else {
colorCalc(gray, alpha);
strokeFromCalc();
}
}
@Override
public void stroke(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.stroke(x, y, z);
}
} else {
colorCalc(x, y, z);
strokeFromCalc();
}
}
@Override
public void stroke(float x, float y, float z, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.stroke(x, y, z, alpha);
}
} else {
colorCalc(x, y, z, alpha);
strokeFromCalc();
}
}
protected void strokeFromCalc() {
if (!stroke) {
// Enabling stroke on a shape previously without
// stroke needs a re-tessellation in order to incorporate
// the additional geometry of lines and/or points.
markForTessellation();
stroke = true;
}
updateStrokeColor(calcColor);
if (is2D() && image != null && parent != null) {
((PShapeOpenGL)parent).strokedTexture(true);
}
}
protected void updateStrokeColor(int newStrokeColor) {
if (!openShape) {
PGraphics.showWarning("Neet to call beginShape() first");
return;
}
strokeColor = newStrokeColor;
}
*/
//////////////////////////////////////////////////////////////
// Tint set/update
/*
@Override
public void noTint() {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.noTint();
}
} else {
tint = false;
updateTintColor(0x0);
}
}
@Override
public void tint(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.tint(rgb);
}
} else {
colorCalc(rgb);
tintFromCalc();
}
}
@Override
public void tint(int rgb, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.tint(rgb, alpha);
}
} else {
colorCalc(rgb, alpha);
tintFromCalc();
}
}
@Override
public void tint(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.tint(gray);
}
} else {
colorCalc(gray);
tintFromCalc();
}
}
@Override
public void tint(float gray, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.tint(gray, alpha);
}
} else {
colorCalc(gray, alpha);
tintFromCalc();
}
}
@Override
public void tint(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.tint(x, y, z);
}
} else {
colorCalc(x, y, z);
tintFromCalc();
}
}
@Override
public void tint(float x, float y, float z, float alpha) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.tint(x, y, z, alpha);
}
} else {
colorCalc(x, y, z, alpha);
tintFromCalc();
}
}
protected void tintFromCalc() {
tint = true;
updateTintColor(calcColor);
}
protected void updateTintColor(int newTintColor) {
if (tintColor == newTintColor) return;
tintColor = newTintColor;
if (image != null) {
Arrays.fill(inGeo.colors, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(tintColor));
if (shapeCreated && tessellated && hasPolys) {
if (is3D()) {
Arrays.fill(tessGeo.polyColors, firstPolyVertex, lastPolyVertex + 1,
PGL.javaToNativeARGB(tintColor));
root.setModifiedPolyColors(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
Arrays.fill(tessGeo.polyColors, firstPolyVertex, last1,
PGL.javaToNativeARGB(tintColor));
root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
}
}
}
*/
//////////////////////////////////////////////////////////////
// Ambient set/update
/*
@Override
public void ambient(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.ambient(rgb);
}
} else {
colorCalc(rgb);
ambientFromCalc();
}
}
@Override
public void ambient(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.ambient(gray);
}
} else {
colorCalc(gray);
ambientFromCalc();
}
}
@Override
public void ambient(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.ambient(x, y, z);
}
} else {
colorCalc(x, y, z);
ambientFromCalc();
}
}
protected void ambientFromCalc() {
updateAmbientColor(calcColor);
setAmbient = true;
}
protected void updateAmbientColor(int newAmbientColor) {
if (ambientColor == newAmbientColor) return;
ambientColor = newAmbientColor;
Arrays.fill(inGeo.ambient, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(ambientColor));
if (shapeCreated && tessellated && hasPolys) {
if (is3D()) {
Arrays.fill(tessGeo.polyAmbient, firstPolyVertex, lastPolyVertex + 1,
PGL.javaToNativeARGB(ambientColor));
root.setModifiedPolyAmbient(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
Arrays.fill(tessGeo.polyAmbient, firstPolyVertex, last1,
PGL.javaToNativeARGB(ambientColor));
root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
}
}
*/
//////////////////////////////////////////////////////////////
// Specular set/update
/*
@Override
public void specular(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.specular(rgb);
}
} else {
colorCalc(rgb);
specularFromCalc();
}
}
@Override
public void specular(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.specular(gray);
}
} else {
colorCalc(gray);
specularFromCalc();
}
}
@Override
public void specular(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.specular(x, y, z);
}
} else {
colorCalc(x, y, z);
specularFromCalc();
}
}
protected void specularFromCalc() {
updateSpecularColor(calcColor);
}
protected void updateSpecularColor(int newSpecularColor) {
if (specularColor == newSpecularColor) return;
specularColor = newSpecularColor;
Arrays.fill(inGeo.specular, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(specularColor));
if (shapeCreated && tessellated && hasPolys) {
if (is3D()) {
Arrays.fill(tessGeo.polySpecular, firstPolyVertex, lastPolyVertex + 1,
PGL.javaToNativeARGB(specularColor));
root.setModifiedPolySpecular(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
Arrays.fill(tessGeo.polySpecular, firstPolyVertex, last1,
PGL.javaToNativeARGB(specularColor));
root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
}
}
*/
//////////////////////////////////////////////////////////////
// Emissive set/update
/*
@Override
public void emissive(int rgb) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.emissive(rgb);
}
} else {
colorCalc(rgb);
emissiveFromCalc();
}
}
@Override
public void emissive(float gray) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.emissive(gray);
}
} else {
colorCalc(gray);
emissiveFromCalc();
}
}
@Override
public void emissive(float x, float y, float z) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.emissive(x, y, z);
}
} else {
colorCalc(x, y, z);
emissiveFromCalc();
}
}
protected void emissiveFromCalc() {
updateEmissiveColor(calcColor);
}
protected void updateEmissiveColor(int newEmissiveColor) {
if (emissiveColor == newEmissiveColor) return;
emissiveColor = newEmissiveColor;
Arrays.fill(inGeo.emissive, 0, inGeo.vertexCount,
PGL.javaToNativeARGB(emissiveColor));
if (shapeCreated && tessellated && 0 < tessGeo.polyVertexCount) {
if (is3D()) {
Arrays.fill(tessGeo.polyEmissive, firstPolyVertex, lastPolyVertex + 1,
PGL.javaToNativeARGB(emissiveColor));
root.setModifiedPolyEmissive(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
Arrays.fill(tessGeo.polyEmissive, firstPolyVertex, last1,
PGL.javaToNativeARGB(emissiveColor));
root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
}
}
*/
//////////////////////////////////////////////////////////////
// Shininess set/update
/*
@Override
public void shininess(float shine) {
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
PShapeOpenGL child = (PShapeOpenGL) children[i];
child.shininess(shine);
}
} else {
updateShininessFactor(shine);
}
}
protected void updateShininessFactor(float newShininess) {
if (PGraphicsOpenGL.same(shininess, newShininess)) return;
shininess = newShininess;
Arrays.fill(inGeo.shininess, 0, inGeo.vertexCount, shininess);
if (shapeCreated && tessellated && hasPolys) {
if (is3D()) {
Arrays.fill(tessGeo.polyShininess, firstPolyVertex, lastPolyVertex + 1,
shininess);
root.setModifiedPolyShininess(firstPolyVertex, lastPolyVertex);
} else if (is2D()) {
int last1 = lastPolyVertex + 1;
if (-1 < firstLineVertex) last1 = firstLineVertex;
if (-1 < firstPointVertex) last1 = firstPointVertex;
Arrays.fill(tessGeo.polyShininess, firstPolyVertex, last1, shininess);
root.setModifiedPolyColors(firstPolyVertex, last1 - 1);
}
}
}
*/
///////////////////////////////////////////////////////////
//
@@ -2613,7 +1802,7 @@ public class PShapeOpenGL extends PShape {
if (hasLines) {
if (is3D()) {
for (int i = firstLineVertex; i <= lastLineVertex; i++) {
tessGeo.lineAttribs[4 * i + 3] *= resizeFactor;
tessGeo.lineDirections[4 * i + 3] *= resizeFactor;
}
root.setModifiedLineAttributes(firstLineVertex, lastLineVertex);
} else if (is2D()) {
@@ -2626,8 +1815,8 @@ public class PShapeOpenGL extends PShape {
if (hasPoints) {
if (is3D()) {
for (int i = firstPointVertex; i <= lastPointVertex; i++) {
tessGeo.pointAttribs[2 * i + 0] *= resizeFactor;
tessGeo.pointAttribs[2 * i + 1] *= resizeFactor;
tessGeo.pointOffsets[2 * i + 0] *= resizeFactor;
tessGeo.pointOffsets[2 * i + 1] *= resizeFactor;
}
root.setModifiedPointAttributes(firstPointVertex, lastPointVertex);
} else if (is2D()) {
@@ -4080,11 +3269,11 @@ public class PShapeOpenGL extends PShape {
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.lineColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updateLineAttribsBuffer();
tessGeo.updateLineDirectionsBuffer();
glLineAttrib = pg.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.lineAttribsBuffer, PGL.STATIC_DRAW);
tessGeo.lineDirectionsBuffer, PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
@@ -4116,11 +3305,11 @@ public class PShapeOpenGL extends PShape {
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.pointColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePointAttribsBuffer();
tessGeo.updatePointOffsetsBuffer();
glPointAttrib = pg.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
tessGeo.pointAttribsBuffer, PGL.STATIC_DRAW);
tessGeo.pointOffsetsBuffer, PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
@@ -4544,12 +3733,12 @@ public class PShapeOpenGL extends PShape {
protected void copyLineAttributes(int offset, int size) {
tessGeo.updateLineAttribsBuffer(offset, size);
tessGeo.updateLineDirectionsBuffer(offset, size);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
tessGeo.lineAttribsBuffer.position(4 * offset);
tessGeo.lineDirectionsBuffer.position(4 * offset);
pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT,
4 * size * PGL.SIZEOF_FLOAT, tessGeo.lineAttribsBuffer);
tessGeo.lineAttribsBuffer.rewind();
4 * size * PGL.SIZEOF_FLOAT, tessGeo.lineDirectionsBuffer);
tessGeo.lineDirectionsBuffer.rewind();
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
@@ -4577,12 +3766,12 @@ public class PShapeOpenGL extends PShape {
protected void copyPointAttributes(int offset, int size) {
tessGeo.updatePointAttribsBuffer(offset, size);
tessGeo.updatePointOffsetsBuffer(offset, size);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
tessGeo.pointAttribsBuffer.position(2 * offset);
tessGeo.pointOffsetsBuffer.position(2 * offset);
pgl.bufferSubData(PGL.ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT,
2 * size * PGL.SIZEOF_FLOAT, tessGeo.pointAttribsBuffer);
tessGeo.pointAttribsBuffer.rewind();
2 * size * PGL.SIZEOF_FLOAT, tessGeo.pointOffsetsBuffer);
tessGeo.pointOffsetsBuffer.rewind();
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
}
@@ -5095,7 +4284,7 @@ public class PShapeOpenGL extends PShape {
float[] vertices = tessGeo.lineVertices;
int[] color = tessGeo.lineColors;
float[] attribs = tessGeo.lineAttribs;
float[] attribs = tessGeo.lineDirections;
short[] indices = tessGeo.lineIndices;
IndexCache cache = tessGeo.lineIndexCache;
@@ -5194,7 +4383,7 @@ public class PShapeOpenGL extends PShape {
float[] vertices = tessGeo.pointVertices;
int[] color = tessGeo.pointColors;
float[] attribs = tessGeo.pointAttribs;
float[] attribs = tessGeo.pointOffsets;
short[] indices = tessGeo.pointIndices;
IndexCache cache = tessGeo.pointIndexCache;

View File

@@ -32,9 +32,9 @@ attribute vec2 offset;
varying vec4 vertColor;
vec4 windowToClipVector(vec2 window, vec4 viewport, float clip_w) {
vec4 windowToClipVector(vec2 window, vec4 viewport, float clipw) {
vec2 xypos = (window / viewport.zw) * 2.0;
return vec4(xypos, 0.0, 0.0) * clip_w;
return vec4(xypos, 0.0, 0.0) * clipw;
}
void main() {