last name change in the shaders: endpoint to direction in line shader

This commit is contained in:
codeanticode
2013-02-19 10:35:48 -05:00
parent 355aff7b24
commit eef67d2c7c
4 changed files with 123 additions and 925 deletions
+17 -19
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;
+87 -76
View File
@@ -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;
@@ -6978,7 +6978,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 +6997,7 @@ public class PGraphicsOpenGL extends PGraphics {
public void loadAttributes() {
vertexLoc = getAttributeLoc("vertex");
colorLoc = getAttributeLoc("color");
endpointLoc = getAttributeLoc("endpoint");
directionLoc = getAttributeLoc("direction");
}
@Override
@@ -7023,7 +7023,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
@@ -7037,7 +7037,7 @@ 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 < directionLoc) pgl.enableVertexAttribArray(directionLoc);
if (pgCurrent.getHint(ENABLE_STROKE_PERSPECTIVE) &&
pgCurrent.nonOrthoProjection()) {
@@ -7063,7 +7063,7 @@ public class PGraphicsOpenGL extends PGraphics {
public void unbind() {
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < endpointLoc) pgl.disableVertexAttribArray(endpointLoc);
if (-1 < directionLoc) pgl.disableVertexAttribArray(directionLoc);
super.unbind();
}
@@ -8894,7 +8894,7 @@ public class PGraphicsOpenGL extends PGraphics {
int lastLineVertex;
FloatBuffer lineVerticesBuffer;
IntBuffer lineColorsBuffer;
FloatBuffer lineAttribsBuffer;
FloatBuffer lineDirectionsBuffer;
int lineIndexCount;
int firstLineIndex;
@@ -8908,7 +8908,7 @@ public class PGraphicsOpenGL extends PGraphics {
int lastPointVertex;
FloatBuffer pointVerticesBuffer;
IntBuffer pointColorsBuffer;
FloatBuffer pointAttribsBuffer;
FloatBuffer pointOffsetsBuffer;
int pointIndexCount;
int firstPointIndex;
@@ -8928,11 +8928,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 +8957,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 +8977,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 +9075,7 @@ public class PGraphicsOpenGL extends PGraphics {
expandLineVertices(newSize);
expandLineColors(newSize);
expandLineAttribs(newSize);
expandLineDirections(newSize);
}
firstLineVertex = lineVertexCount;
@@ -9103,7 +9103,7 @@ public class PGraphicsOpenGL extends PGraphics {
expandPointVertices(newSize);
expandPointColors(newSize);
expandPointAttribs(newSize);
expandPointOffsets(newSize);
}
firstPointVertex = pointVertexCount;
@@ -9314,12 +9314,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 +9348,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 +9446,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 +9474,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 +9511,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 +9521,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 +9606,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 +9634,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 +9787,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 +9809,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 +9823,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 +9834,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 +10098,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 +10173,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 +10188,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 +10395,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 +10526,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++;
}
+17 -828
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;
@@ -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() {