use of processing.opengl.PGraphicsOpenGL.VertexAttribute in project processing by processing.
the class PShapeOpenGL method applyMatrixImpl.
protected void applyMatrixImpl(PMatrix matrix) {
if (hasPolys) {
tessGeo.applyMatrixOnPolyGeometry(matrix, firstPolyVertex, lastPolyVertex);
root.setModifiedPolyVertices(firstPolyVertex, lastPolyVertex);
root.setModifiedPolyNormals(firstPolyVertex, lastPolyVertex);
for (VertexAttribute attrib : polyAttribs.values()) {
if (attrib.isPosition() || attrib.isNormal()) {
root.setModifiedPolyAttrib(attrib, firstPolyVertex, lastPolyVertex);
}
}
}
if (is3D()) {
if (hasLines) {
tessGeo.applyMatrixOnLineGeometry(matrix, firstLineVertex, lastLineVertex);
root.setModifiedLineVertices(firstLineVertex, lastLineVertex);
root.setModifiedLineAttributes(firstLineVertex, lastLineVertex);
}
if (hasPoints) {
tessGeo.applyMatrixOnPointGeometry(matrix, firstPointVertex, lastPointVertex);
root.setModifiedPointVertices(firstPointVertex, lastPointVertex);
root.setModifiedPointAttributes(firstPointVertex, lastPointVertex);
}
}
}
use of processing.opengl.PGraphicsOpenGL.VertexAttribute in project processing by processing.
the class PShapeOpenGL method attribImpl.
protected VertexAttribute attribImpl(String name, int kind, int type, int size) {
if (4 < size) {
PGraphics.showWarning("Vertex attributes cannot have more than 4 values");
return null;
}
VertexAttribute attrib = polyAttribs.get(name);
if (attrib == null) {
attrib = new VertexAttribute(pg, name, kind, type, size);
polyAttribs.put(name, attrib);
inGeo.initAttrib(attrib);
}
if (attrib.kind != kind) {
PGraphics.showWarning("The attribute kind cannot be changed after creation");
return null;
}
if (attrib.type != type) {
PGraphics.showWarning("The attribute type cannot be changed after creation");
return null;
}
if (attrib.size != size) {
PGraphics.showWarning("New value for vertex attribute has wrong number of values");
return null;
}
return attrib;
}
use of processing.opengl.PGraphicsOpenGL.VertexAttribute in project processing by processing.
the class PShapeOpenGL method setAttrib.
@Override
public void setAttrib(String name, int index, int... values) {
if (openShape) {
PGraphics.showWarning(INSIDE_BEGIN_END_ERROR, "setNormal()");
return;
}
VertexAttribute attrib = polyAttribs.get(name);
int[] array = inGeo.iattribs.get(name);
for (int i = 0; i < values.length; i++) {
array[attrib.size * index + 0] = values[i];
}
markForTessellation();
}
use of processing.opengl.PGraphicsOpenGL.VertexAttribute in project processing by processing.
the class PShapeOpenGL method updateGeometryImpl.
protected void updateGeometryImpl() {
if (modifiedPolyVertices) {
int offset = firstModifiedPolyVertex;
int size = lastModifiedPolyVertex - offset + 1;
copyPolyVertices(offset, size);
modifiedPolyVertices = false;
firstModifiedPolyVertex = PConstants.MAX_INT;
lastModifiedPolyVertex = PConstants.MIN_INT;
}
if (modifiedPolyColors) {
int offset = firstModifiedPolyColor;
int size = lastModifiedPolyColor - offset + 1;
copyPolyColors(offset, size);
modifiedPolyColors = false;
firstModifiedPolyColor = PConstants.MAX_INT;
lastModifiedPolyColor = PConstants.MIN_INT;
}
if (modifiedPolyNormals) {
int offset = firstModifiedPolyNormal;
int size = lastModifiedPolyNormal - offset + 1;
copyPolyNormals(offset, size);
modifiedPolyNormals = false;
firstModifiedPolyNormal = PConstants.MAX_INT;
lastModifiedPolyNormal = PConstants.MIN_INT;
}
if (modifiedPolyTexCoords) {
int offset = firstModifiedPolyTexcoord;
int size = lastModifiedPolyTexcoord - offset + 1;
copyPolyTexCoords(offset, size);
modifiedPolyTexCoords = false;
firstModifiedPolyTexcoord = PConstants.MAX_INT;
lastModifiedPolyTexcoord = PConstants.MIN_INT;
}
if (modifiedPolyAmbient) {
int offset = firstModifiedPolyAmbient;
int size = lastModifiedPolyAmbient - offset + 1;
copyPolyAmbient(offset, size);
modifiedPolyAmbient = false;
firstModifiedPolyAmbient = PConstants.MAX_INT;
lastModifiedPolyAmbient = PConstants.MIN_INT;
}
if (modifiedPolySpecular) {
int offset = firstModifiedPolySpecular;
int size = lastModifiedPolySpecular - offset + 1;
copyPolySpecular(offset, size);
modifiedPolySpecular = false;
firstModifiedPolySpecular = PConstants.MAX_INT;
lastModifiedPolySpecular = PConstants.MIN_INT;
}
if (modifiedPolyEmissive) {
int offset = firstModifiedPolyEmissive;
int size = lastModifiedPolyEmissive - offset + 1;
copyPolyEmissive(offset, size);
modifiedPolyEmissive = false;
firstModifiedPolyEmissive = PConstants.MAX_INT;
lastModifiedPolyEmissive = PConstants.MIN_INT;
}
if (modifiedPolyShininess) {
int offset = firstModifiedPolyShininess;
int size = lastModifiedPolyShininess - offset + 1;
copyPolyShininess(offset, size);
modifiedPolyShininess = false;
firstModifiedPolyShininess = PConstants.MAX_INT;
lastModifiedPolyShininess = PConstants.MIN_INT;
}
for (String name : polyAttribs.keySet()) {
VertexAttribute attrib = polyAttribs.get(name);
if (attrib.modified) {
int offset = firstModifiedPolyVertex;
int size = lastModifiedPolyVertex - offset + 1;
copyPolyAttrib(attrib, offset, size);
attrib.modified = false;
attrib.firstModified = PConstants.MAX_INT;
attrib.lastModified = PConstants.MIN_INT;
}
}
if (modifiedLineVertices) {
int offset = firstModifiedLineVertex;
int size = lastModifiedLineVertex - offset + 1;
copyLineVertices(offset, size);
modifiedLineVertices = false;
firstModifiedLineVertex = PConstants.MAX_INT;
lastModifiedLineVertex = PConstants.MIN_INT;
}
if (modifiedLineColors) {
int offset = firstModifiedLineColor;
int size = lastModifiedLineColor - offset + 1;
copyLineColors(offset, size);
modifiedLineColors = false;
firstModifiedLineColor = PConstants.MAX_INT;
lastModifiedLineColor = PConstants.MIN_INT;
}
if (modifiedLineAttributes) {
int offset = firstModifiedLineAttribute;
int size = lastModifiedLineAttribute - offset + 1;
copyLineAttributes(offset, size);
modifiedLineAttributes = false;
firstModifiedLineAttribute = PConstants.MAX_INT;
lastModifiedLineAttribute = PConstants.MIN_INT;
}
if (modifiedPointVertices) {
int offset = firstModifiedPointVertex;
int size = lastModifiedPointVertex - offset + 1;
copyPointVertices(offset, size);
modifiedPointVertices = false;
firstModifiedPointVertex = PConstants.MAX_INT;
lastModifiedPointVertex = PConstants.MIN_INT;
}
if (modifiedPointColors) {
int offset = firstModifiedPointColor;
int size = lastModifiedPointColor - offset + 1;
copyPointColors(offset, size);
modifiedPointColors = false;
firstModifiedPointColor = PConstants.MAX_INT;
lastModifiedPointColor = PConstants.MIN_INT;
}
if (modifiedPointAttributes) {
int offset = firstModifiedPointAttribute;
int size = lastModifiedPointAttribute - offset + 1;
copyPointAttributes(offset, size);
modifiedPointAttributes = false;
firstModifiedPointAttribute = PConstants.MAX_INT;
lastModifiedPointAttribute = PConstants.MIN_INT;
}
modified = false;
}
use of processing.opengl.PGraphicsOpenGL.VertexAttribute in project processing by processing.
the class PShapeOpenGL method renderPolys.
protected void renderPolys(PGraphicsOpenGL g, PImage textureImage) {
boolean customShader = g.polyShader != null;
boolean needNormals = customShader ? g.polyShader.accessNormals() : false;
boolean needTexCoords = customShader ? g.polyShader.accessTexCoords() : false;
Texture tex = textureImage != null ? g.getTexture(textureImage) : null;
boolean renderingFill = false, renderingStroke = false;
PShader shader = null;
IndexCache cache = tessGeo.polyIndexCache;
for (int n = firstPolyIndexCache; n <= lastPolyIndexCache; n++) {
if (is3D() || (tex != null && (firstLineIndexCache == -1 || n < firstLineIndexCache) && (firstPointIndexCache == -1 || n < firstPointIndexCache))) {
// Rendering fill triangles, which can be lit and textured.
if (!renderingFill) {
shader = g.getPolyShader(g.lights, tex != null);
shader.bind();
renderingFill = true;
}
} else {
// Rendering line or point triangles, which are never lit nor textured.
if (!renderingStroke) {
if (tex != null) {
tex.unbind();
tex = null;
}
if (shader != null && shader.bound()) {
shader.unbind();
}
// If the renderer is 2D, then g.lights should always be false,
// so no need to worry about that.
shader = g.getPolyShader(g.lights, false);
shader.bind();
renderingFill = false;
renderingStroke = true;
}
}
int ioffset = cache.indexOffset[n];
int icount = cache.indexCount[n];
int voffset = cache.vertexOffset[n];
shader.setVertexAttribute(root.bufPolyVertex.glId, 4, PGL.FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT);
shader.setColorAttribute(root.bufPolyColor.glId, 4, PGL.UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
if (g.lights) {
shader.setNormalAttribute(root.bufPolyNormal.glId, 3, PGL.FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT);
shader.setAmbientAttribute(root.bufPolyAmbient.glId, 4, PGL.UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
shader.setSpecularAttribute(root.bufPolySpecular.glId, 4, PGL.UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
shader.setEmissiveAttribute(root.bufPolyEmissive.glId, 4, PGL.UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE);
shader.setShininessAttribute(root.bufPolyShininess.glId, 1, PGL.FLOAT, 0, voffset * PGL.SIZEOF_FLOAT);
}
if (g.lights || needNormals) {
shader.setNormalAttribute(root.bufPolyNormal.glId, 3, PGL.FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT);
}
if (tex != null || needTexCoords) {
shader.setTexcoordAttribute(root.bufPolyTexcoord.glId, 2, PGL.FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT);
shader.setTexture(tex);
}
for (VertexAttribute attrib : polyAttribs.values()) {
if (!attrib.active(shader))
continue;
attrib.bind(pgl);
shader.setAttributeVBO(attrib.glLoc, attrib.buf.glId, attrib.tessSize, attrib.type, attrib.isColor(), 0, attrib.sizeInBytes(voffset));
}
shader.draw(root.bufPolyIndex.glId, icount, ioffset);
}
for (VertexAttribute attrib : polyAttribs.values()) {
if (attrib.active(shader))
attrib.unbind(pgl);
}
if (shader != null && shader.bound()) {
shader.unbind();
}
}
Aggregations