mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Added tint() methods to PShape and PShape3D
This commit is contained in:
@@ -141,6 +141,9 @@ public class PShape implements PConstants {
|
||||
|
||||
protected boolean fill;
|
||||
protected int fillColor;
|
||||
|
||||
protected boolean tint;
|
||||
protected int tintColor;
|
||||
|
||||
/** Temporary toggle for whether styles should be honored. */
|
||||
protected boolean style = true;
|
||||
@@ -477,7 +480,6 @@ public class PShape implements PConstants {
|
||||
|
||||
// STROKE COLOR
|
||||
|
||||
|
||||
public void noStroke() {
|
||||
}
|
||||
|
||||
@@ -498,6 +500,32 @@ public class PShape implements PConstants {
|
||||
|
||||
public void stroke(float x, float y, float z, float alpha) {
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// TINT COLOR
|
||||
|
||||
|
||||
public void noTint() {
|
||||
}
|
||||
|
||||
public void tint(int rgb) {
|
||||
}
|
||||
|
||||
public void tint(int rgb, float alpha) {
|
||||
}
|
||||
|
||||
public void tint(float gray) {
|
||||
}
|
||||
|
||||
public void tint(float gray, float alpha) {
|
||||
}
|
||||
|
||||
public void tint(float x, float y, float z) {
|
||||
}
|
||||
|
||||
public void tint(float x, float y, float z, float alpha) {
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -462,7 +462,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
public static int flushMode = FLUSH_WHEN_FULL;
|
||||
// public static int flushMode = FLUSH_AFTER_SHAPE;
|
||||
|
||||
public static final int MIN_ARRAYCOPY_SIZE = 3;
|
||||
public static final int MIN_ARRAYCOPY_SIZE = 2;
|
||||
|
||||
public static final int MAX_TESS_VERTICES = 1000000;
|
||||
public static final int MAX_TESS_INDICES = 3000000;
|
||||
@@ -2482,9 +2482,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
|
||||
lineAttribsID = lineShader.getAttribLocation("attribs");
|
||||
gl2x.glEnableVertexAttribArray(lineAttribsID);
|
||||
gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID);
|
||||
gl2f.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(attribs));
|
||||
gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID);
|
||||
gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs, 0, 4 * nvert), vboMode);
|
||||
gl2x.glVertexAttribPointer(lineAttribsID, 4, GL.GL_FLOAT, false, 0, 0);
|
||||
}
|
||||
|
||||
@@ -2531,8 +2530,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
pointAttribsID = PGraphicsOpenGL.pointShader.getAttribLocation("vertDisp");
|
||||
gl2x.glEnableVertexAttribArray(pointAttribsID);
|
||||
gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID);
|
||||
gl2f.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, 2 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT,
|
||||
FloatBuffer.wrap(attribs));
|
||||
gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 2 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs, 0, 2 * nvert), vboMode);
|
||||
ogl.gl2x.glVertexAttribPointer(pointAttribsID, 2, GL.GL_FLOAT, false, 0, 0);
|
||||
}
|
||||
|
||||
@@ -7342,7 +7340,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
fillNormals[index ] = nx * tr.m20 + ny * tr.m21 + nz * tr.m22;
|
||||
}
|
||||
} else {
|
||||
if (nvert < MIN_ARRAYCOPY_SIZE) {
|
||||
if (nvert <= MIN_ARRAYCOPY_SIZE) {
|
||||
// Copying elements one by one instead of using arrayCopy is more efficient for
|
||||
// few vertices...
|
||||
for (int i = 0; i < nvert; i++) {
|
||||
@@ -7375,7 +7373,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
}
|
||||
|
||||
if (nvert < MIN_ARRAYCOPY_SIZE) {
|
||||
if (nvert <= MIN_ARRAYCOPY_SIZE) {
|
||||
for (int i = 0; i < nvert; i++) {
|
||||
int inIdx = i0 + i;
|
||||
int tessIdx = firstFillVertex + i;
|
||||
@@ -7397,8 +7395,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
fillColors[index ] = a;
|
||||
|
||||
index = 2 * tessIdx;
|
||||
fillNormals[index++] = u;
|
||||
fillNormals[index ] = v;
|
||||
fillTexcoords[index++] = u;
|
||||
fillTexcoords[index ] = v;
|
||||
}
|
||||
} else {
|
||||
PApplet.arrayCopy(in.colors, 4 * i0, fillColors, 4 * firstFillVertex, 4 * nvert);
|
||||
|
||||
@@ -654,7 +654,7 @@ public class PShape3D extends PShape {
|
||||
}
|
||||
|
||||
protected void updateFillColor() {
|
||||
if (!shapeEnded || tess.fillVertexCount == 0) {
|
||||
if (!shapeEnded || tess.fillVertexCount == 0 || texture != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -769,6 +769,77 @@ public class PShape3D extends PShape {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// TINT COLOR
|
||||
|
||||
public void noTint() {
|
||||
tint = false;
|
||||
colorCalc(0, 0);
|
||||
tintFromCalc();
|
||||
}
|
||||
|
||||
public void tint(int rgb) {
|
||||
colorCalc(rgb);
|
||||
tintFromCalc();
|
||||
}
|
||||
|
||||
public void tint(int rgb, float alpha) {
|
||||
colorCalc(rgb, alpha);
|
||||
tintFromCalc();
|
||||
}
|
||||
|
||||
public void tint(float gray) {
|
||||
colorCalc(gray);
|
||||
tintFromCalc();
|
||||
}
|
||||
|
||||
public void tint(float gray, float alpha) {
|
||||
colorCalc(gray, alpha);
|
||||
tintFromCalc();
|
||||
}
|
||||
|
||||
public void tint(float x, float y, float z) {
|
||||
colorCalc(x, y, z);
|
||||
tintFromCalc();
|
||||
}
|
||||
|
||||
public void tint(float x, float y, float z, float alpha) {
|
||||
colorCalc(x, y, z, alpha);
|
||||
tintFromCalc();
|
||||
}
|
||||
|
||||
protected void tintFromCalc() {
|
||||
tint = true;
|
||||
tintR = calcR;
|
||||
tintG = calcG;
|
||||
tintB = calcB;
|
||||
tintA = calcA;
|
||||
tintColor = calcColor;
|
||||
updateTintColor();
|
||||
}
|
||||
|
||||
protected void updateTintColor() {
|
||||
if (!shapeEnded || tess.fillVertexCount == 0 || texture == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateTesselation();
|
||||
|
||||
int size = tess.fillVertexCount;
|
||||
float[] colors = tess.fillColors;
|
||||
int index;
|
||||
for (int i = 0; i < size; i++) {
|
||||
index = 4 * i;
|
||||
colors[index++] = tintR;
|
||||
colors[index++] = tintG;
|
||||
colors[index++] = tintB;
|
||||
colors[index ] = tintA;
|
||||
}
|
||||
modifiedFillColors = true;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
@@ -2004,7 +2075,7 @@ public class PShape3D extends PShape {
|
||||
protected void copyFillGeometry(int offset, int size,
|
||||
float[] vertices, float[] colors,
|
||||
float[] normals, float[] texcoords) {
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID);
|
||||
getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT,
|
||||
3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices));
|
||||
|
||||
@@ -2025,7 +2096,7 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
protected void copyFillVertices(int offset, int size, float[] vertices) {
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID);
|
||||
getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT,
|
||||
3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices));
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -2035,7 +2106,7 @@ public class PShape3D extends PShape {
|
||||
protected void copyFillColors(int offset, int size, float[] colors) {
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID);
|
||||
getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT,
|
||||
4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors));
|
||||
4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors));
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
@@ -2528,14 +2599,15 @@ public class PShape3D extends PShape {
|
||||
ogl.startPointShader();
|
||||
|
||||
getGl().glEnableClientState(GL2.GL_NORMAL_ARRAY);
|
||||
getGl().glEnableClientState(GL2.GL_COLOR_ARRAY);
|
||||
getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY);
|
||||
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glPointNormalBufferID);
|
||||
getGl().glNormalPointer(GL.GL_FLOAT, 0, 0);
|
||||
|
||||
getGl().glEnableClientState(GL2.GL_COLOR_ARRAY);
|
||||
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glPointColorBufferID);
|
||||
getGl().glColorPointer(4, GL.GL_FLOAT, 0, 0);
|
||||
|
||||
getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glPointVertexBufferID);
|
||||
getGl().glVertexPointer(3, GL.GL_FLOAT, 0, 0);
|
||||
|
||||
@@ -2560,14 +2632,15 @@ public class PShape3D extends PShape {
|
||||
ogl.startLineShader();
|
||||
|
||||
getGl().glEnableClientState(GL2.GL_NORMAL_ARRAY);
|
||||
getGl().glEnableClientState(GL2.GL_COLOR_ARRAY);
|
||||
getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY);
|
||||
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineNormalBufferID);
|
||||
getGl().glNormalPointer(GL.GL_FLOAT, 0, 0);
|
||||
|
||||
getGl().glEnableClientState(GL2.GL_COLOR_ARRAY);
|
||||
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineColorBufferID);
|
||||
getGl().glColorPointer(4, GL.GL_FLOAT, 0, 0);
|
||||
|
||||
getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY);
|
||||
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineVertexBufferID);
|
||||
getGl().glVertexPointer(3, GL.GL_FLOAT, 0, 0);
|
||||
|
||||
@@ -2590,18 +2663,19 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void renderFill(PImage textureImage) {
|
||||
getGl().glEnableClientState(GL2.GL_NORMAL_ARRAY);
|
||||
getGl().glEnableClientState(GL2.GL_COLOR_ARRAY);
|
||||
getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY);
|
||||
getGl().glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillNormalBufferID);
|
||||
getGl().glNormalPointer(GL.GL_FLOAT, 0, 0);
|
||||
|
||||
getGl().glEnableClientState(GL2.GL_COLOR_ARRAY);
|
||||
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillColorBufferID);
|
||||
getGl().glColorPointer(4, GL.GL_FLOAT, 0, 0);
|
||||
|
||||
getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillVertexBufferID);
|
||||
getGl().glVertexPointer(3, GL.GL_FLOAT, 0, 0);
|
||||
|
||||
getGl().glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillTexCoordBufferID);
|
||||
getGl().glTexCoordPointer(2, GL.GL_FLOAT, 0, 0);
|
||||
|
||||
@@ -2669,7 +2743,34 @@ public class PShape3D extends PShape {
|
||||
expand(newSize);
|
||||
}
|
||||
|
||||
PApplet.arrayCopy(newData, 0, data, ncoords * size, ncoords * dataSize);
|
||||
if (dataSize <= PGraphicsOpenGL.MIN_ARRAYCOPY_SIZE) {
|
||||
// Copying elements one by one instead of using arrayCopy is more efficient for
|
||||
// few vertices...
|
||||
for (int i = 0; i < dataSize; i++) {
|
||||
int srcIndex = ncoords * i;
|
||||
int destIndex = ncoords * (size + i);
|
||||
|
||||
if (ncoords == 2) {
|
||||
data[destIndex++] = newData[srcIndex++];
|
||||
data[destIndex ] = newData[srcIndex ];
|
||||
} else if (ncoords == 3) {
|
||||
data[destIndex++] = newData[srcIndex++];
|
||||
data[destIndex++] = newData[srcIndex++];
|
||||
data[destIndex ] = newData[srcIndex ];
|
||||
} else if (ncoords == 4) {
|
||||
data[destIndex++] = newData[srcIndex++];
|
||||
data[destIndex++] = newData[srcIndex++];
|
||||
data[destIndex++] = newData[srcIndex++];
|
||||
data[destIndex ] = newData[srcIndex ];
|
||||
} else {
|
||||
for (int j = 0; j < ncoords; j++) {
|
||||
data[destIndex++] = newData[srcIndex++];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PApplet.arrayCopy(newData, 0, data, ncoords * size, ncoords * dataSize);
|
||||
}
|
||||
|
||||
size += dataSize;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user