mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
removed some commented out code
This commit is contained in:
@@ -6329,39 +6329,6 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
shader.setVertexShader(defTextureShaderVertURL);
|
||||
}
|
||||
return shader;
|
||||
|
||||
/*
|
||||
int shaderType = getShaderType(fragFilename);
|
||||
PShader shader = null;
|
||||
if (shaderType == PShader.POINT) {
|
||||
shader = new PointShader(parent);
|
||||
shader.setVertexShader(defPointShaderVertURL);
|
||||
} else if (shaderType == PShader.LINE) {
|
||||
shader = new LineShader(parent);
|
||||
shader.setVertexShader(defLineShaderVertURL);
|
||||
} else if (shaderType == PShader.TEXLIGHT) {
|
||||
shader = new PolyShader(parent);
|
||||
shader.setVertexShader(defTexlightShaderVertURL);
|
||||
((PolyShader)shader).setType(PShader.TEXLIGHT);
|
||||
} else if (shaderType == PShader.LIGHT) {
|
||||
shader = new PolyShader(parent);
|
||||
shader.setVertexShader(defLightShaderVertURL);
|
||||
((PolyShader)shader).setType(PShader.LIGHT);
|
||||
} else if (shaderType == PShader.TEXTURE) {
|
||||
shader = new PolyShader(parent);
|
||||
((PolyShader)shader).setType(PShader.TEXTURE);
|
||||
shader.setVertexShader(defTextureShaderVertURL);
|
||||
} else if (shaderType == PShader.COLOR) {
|
||||
shader = new PolyShader(parent);
|
||||
shader.setVertexShader(defColorShaderVertURL);
|
||||
((PolyShader)shader).setType(PShader.COLOR);
|
||||
} else {
|
||||
shader = new PolyShader(parent);
|
||||
shader.setVertexShader(defTextureShaderVertURL);
|
||||
}
|
||||
shader.setFragmentShader(fragFilename);
|
||||
return shader;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -6376,69 +6343,6 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
} else {
|
||||
return new PShader(parent, vertFilename, fragFilename);
|
||||
}
|
||||
|
||||
/*
|
||||
int vertType = getShaderType(vertFilename);
|
||||
int fragType = getShaderType(fragFilename);
|
||||
|
||||
int shaderType = -1;
|
||||
if (vertType == -1 && fragType == -1) {
|
||||
shaderType = PShader.POLY;
|
||||
} else if (vertType == -1) {
|
||||
shaderType = fragType;
|
||||
} else if (fragType == -1) {
|
||||
shaderType = vertType;
|
||||
} else if (fragType == vertType) {
|
||||
shaderType = vertType;
|
||||
} else if (2 <= fragType && 2 <= vertType) {
|
||||
shaderType = PShader.POLY;
|
||||
} else {
|
||||
PGraphics.showWarning(INCONSISTENT_SHADER_TYPES);
|
||||
return null;
|
||||
}
|
||||
|
||||
PShader shader = null;
|
||||
if (fragFilename == null || fragFilename.equals("")) {
|
||||
if (shaderType == PShader.POINT) {
|
||||
shader = new PointShader(parent);
|
||||
shader.setFragmentShader(defPointShaderFragURL);
|
||||
} else if (shaderType == PShader.LINE) {
|
||||
shader = new LineShader(parent);
|
||||
shader.setFragmentShader(defLineShaderFragURL);
|
||||
} else if (shaderType == PShader.TEXLIGHT) {
|
||||
shader = new PolyShader(parent);
|
||||
shader.setFragmentShader(defTextureShaderFragURL);
|
||||
((PolyShader)shader).setType(PShader.TEXLIGHT);
|
||||
} else if (shaderType == PShader.LIGHT) {
|
||||
shader = new PolyShader(parent);
|
||||
shader.setFragmentShader(defColorShaderFragURL);
|
||||
((PolyShader)shader).setType(PShader.LIGHT);
|
||||
} else if (shaderType == PShader.TEXTURE) {
|
||||
shader = new PolyShader(parent);
|
||||
shader.setFragmentShader(defTextureShaderFragURL);
|
||||
((PolyShader)shader).setType(PShader.TEXTURE);
|
||||
} else if (shaderType == PShader.COLOR) {
|
||||
shader = new PolyShader(parent);
|
||||
shader.setFragmentShader(defColorShaderFragURL);
|
||||
((PolyShader)shader).setType(PShader.COLOR);
|
||||
} else {
|
||||
shader = new PolyShader(parent);
|
||||
shader.setVertexShader(defTextureShaderVertURL);
|
||||
}
|
||||
if (shader != null) {
|
||||
shader.setVertexShader(vertFilename);
|
||||
}
|
||||
} else {
|
||||
if (shaderType == PShader.POINT) {
|
||||
shader = new PointShader(parent, vertFilename, fragFilename);
|
||||
} else if (shaderType == PShader.LINE) {
|
||||
shader = new LineShader(parent, vertFilename, fragFilename);
|
||||
} else {
|
||||
shader = new PolyShader(parent, vertFilename, fragFilename);
|
||||
}
|
||||
}
|
||||
return shader;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -6457,30 +6361,6 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
// TODO: deprecate this method, the kind arguments is not used anymore
|
||||
public void shader(PShader shader, int kind) {
|
||||
shader(shader);
|
||||
|
||||
/*
|
||||
if (kind == TRIANGLES || kind == QUADS || kind == POLYGON) {
|
||||
if (shader instanceof PolyShader) {
|
||||
polyShader = (PolyShader) shader;
|
||||
} else {
|
||||
PGraphics.showWarning(WRONG_SHADER_TYPE_ERROR);
|
||||
}
|
||||
} else if (kind == LINES) {
|
||||
if (shader instanceof LineShader) {
|
||||
lineShader = (LineShader)shader;
|
||||
} else {
|
||||
PGraphics.showWarning(WRONG_SHADER_TYPE_ERROR);
|
||||
}
|
||||
} else if (kind == POINTS) {
|
||||
if (shader instanceof PointShader) {
|
||||
pointShader = (PointShader)shader;
|
||||
} else {
|
||||
PGraphics.showWarning(WRONG_SHADER_TYPE_ERROR);
|
||||
}
|
||||
} else {
|
||||
PGraphics.showWarning(UNKNOWN_SHADER_KIND_ERROR);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -6668,641 +6548,6 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
return shader;
|
||||
}
|
||||
|
||||
/*
|
||||
protected class BaseShader extends PShader {
|
||||
protected int transformMatLoc;
|
||||
protected int modelviewMatLoc;
|
||||
protected int projectionMatLoc;
|
||||
protected int bufferLoc;
|
||||
protected int bufferUnit;
|
||||
protected int viewportLoc;
|
||||
|
||||
public BaseShader(PApplet parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public BaseShader(PApplet parent, String vertFilename, String fragFilename) {
|
||||
super(parent, vertFilename, fragFilename);
|
||||
}
|
||||
|
||||
public BaseShader(PApplet parent, URL vertURL, URL fragURL) {
|
||||
super(parent, vertURL, fragURL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms() {
|
||||
transformMatLoc = getUniformLoc("transform");
|
||||
if (transformMatLoc == -1)
|
||||
transformMatLoc = getUniformLoc("transformMatrix");
|
||||
|
||||
modelviewMatLoc = getUniformLoc("modelview");
|
||||
if (modelviewMatLoc == -1)
|
||||
modelviewMatLoc = getUniformLoc("modelviewMatrix");
|
||||
|
||||
projectionMatLoc = getUniformLoc("projection");
|
||||
if (projectionMatLoc == -1)
|
||||
projectionMatLoc = getUniformLoc("projectionMatrix");
|
||||
|
||||
viewportLoc = getUniformLoc("viewport");
|
||||
bufferLoc = getUniformLoc("buffer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind() {
|
||||
if (-1 < bufferLoc) {
|
||||
pgl.requestFBOLayer();
|
||||
pgl.activeTexture(PGL.TEXTURE0 + bufferUnit);
|
||||
pg.unbindFrontTexture();
|
||||
pgl.activeTexture(PGL.TEXTURE0);
|
||||
}
|
||||
|
||||
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
|
||||
|
||||
super.unbind();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setCommonUniforms() {
|
||||
if (-1 < transformMatLoc) {
|
||||
pg.updateGLProjmodelview();
|
||||
setUniformMatrix(transformMatLoc, pg.glProjmodelview);
|
||||
}
|
||||
|
||||
if (-1 < modelviewMatLoc) {
|
||||
pg.updateGLModelview();
|
||||
setUniformMatrix(modelviewMatLoc, pg.glModelview);
|
||||
}
|
||||
|
||||
if (-1 < projectionMatLoc) {
|
||||
pg.updateGLProjection();
|
||||
setUniformMatrix(projectionMatLoc, pg.glProjection);
|
||||
}
|
||||
|
||||
if (-1 < viewportLoc) {
|
||||
float x = pg.viewport.get(0);
|
||||
float y = pg.viewport.get(1);
|
||||
float w = pg.viewport.get(2);
|
||||
float h = pg.viewport.get(3);
|
||||
setUniformValue(viewportLoc, x, y, w, h);
|
||||
}
|
||||
|
||||
if (-1 < bufferLoc) {
|
||||
bufferUnit = super.getLastTexUnit() + 1;
|
||||
setUniformValue(bufferLoc, bufferUnit);
|
||||
pgl.activeTexture(PGL.TEXTURE0 + bufferUnit);
|
||||
pg.bindFrontTexture();
|
||||
} else {
|
||||
bufferUnit = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLastTexUnit() {
|
||||
return -1 < bufferUnit ? bufferUnit : super.getLastTexUnit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTexturing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportLighting() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accessTexCoords() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accessNormals() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accessLightAttribs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVertexAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) { }
|
||||
@Override
|
||||
public void setColorAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) { }
|
||||
@Override
|
||||
public void setNormalAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) { }
|
||||
@Override
|
||||
public void setAmbientAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) { }
|
||||
@Override
|
||||
public void setSpecularAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) { }
|
||||
@Override
|
||||
public void setEmissiveAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) { }
|
||||
@Override
|
||||
public void setShininessAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) { }
|
||||
@Override
|
||||
public void setTexcoordAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) { }
|
||||
@Override
|
||||
public void setTexture(Texture tex) { }
|
||||
}
|
||||
|
||||
|
||||
protected class PolyShader extends BaseShader {
|
||||
protected int type = 0;
|
||||
|
||||
protected int vertexLoc;
|
||||
protected int colorLoc;
|
||||
protected int normalLoc;
|
||||
protected int texCoordLoc;
|
||||
protected int normalMatLoc;
|
||||
|
||||
protected int lightCountLoc;
|
||||
protected int lightPositionLoc;
|
||||
protected int lightNormalLoc;
|
||||
protected int lightAmbientLoc;
|
||||
protected int lightDiffuseLoc;
|
||||
protected int lightSpecularLoc;
|
||||
protected int lightFalloffLoc;
|
||||
protected int lightSpotLoc;
|
||||
|
||||
protected int ambientLoc;
|
||||
protected int specularLoc;
|
||||
protected int emissiveLoc;
|
||||
protected int shininessLoc;
|
||||
|
||||
protected Texture texture;
|
||||
protected int texUnit;
|
||||
|
||||
protected int textureLoc;
|
||||
protected int texMatrixLoc;
|
||||
protected int texOffsetLoc;
|
||||
|
||||
protected float[] tcmat;
|
||||
|
||||
public PolyShader(PApplet parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public PolyShader(PApplet parent, String vertFilename,
|
||||
String fragFilename) {
|
||||
super(parent, vertFilename, fragFilename);
|
||||
}
|
||||
|
||||
public PolyShader(PApplet parent, URL vertURL, URL fragURL) {
|
||||
super(parent, vertURL, fragURL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAttributes() {
|
||||
vertexLoc = getAttributeLoc("vertex");
|
||||
if (vertexLoc == -1) vertexLoc = getAttributeLoc("position");
|
||||
|
||||
colorLoc = getAttributeLoc("color");
|
||||
texCoordLoc = getAttributeLoc("texCoord");
|
||||
normalLoc = getAttributeLoc("normal");
|
||||
|
||||
ambientLoc = getAttributeLoc("ambient");
|
||||
specularLoc = getAttributeLoc("specular");
|
||||
emissiveLoc = getAttributeLoc("emissive");
|
||||
shininessLoc = getAttributeLoc("shininess");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms() {
|
||||
super.loadUniforms();
|
||||
|
||||
normalMatLoc = getUniformLoc("normalMatrix");
|
||||
|
||||
lightCountLoc = getUniformLoc("lightCount");
|
||||
lightPositionLoc = getUniformLoc("lightPosition");
|
||||
lightNormalLoc = getUniformLoc("lightNormal");
|
||||
lightAmbientLoc = getUniformLoc("lightAmbient");
|
||||
lightDiffuseLoc = getUniformLoc("lightDiffuse");
|
||||
lightSpecularLoc = getUniformLoc("lightSpecular");
|
||||
lightFalloffLoc = getUniformLoc("lightFalloff");
|
||||
lightSpotLoc = getUniformLoc("lightSpot");
|
||||
|
||||
textureLoc = getUniformLoc("texture");
|
||||
texMatrixLoc = getUniformLoc("texMatrix");
|
||||
texOffsetLoc = getUniformLoc("texOffset");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexture(Texture tex) {
|
||||
texture = tex;
|
||||
|
||||
float scaleu = 1;
|
||||
float scalev = 1;
|
||||
float dispu = 0;
|
||||
float dispv = 0;
|
||||
|
||||
if (tex != null) {
|
||||
if (tex.invertedX()) {
|
||||
scaleu = -1;
|
||||
dispu = 1;
|
||||
}
|
||||
|
||||
if (tex.invertedY()) {
|
||||
scalev = -1;
|
||||
dispv = 1;
|
||||
}
|
||||
|
||||
scaleu *= tex.maxTexcoordU();
|
||||
dispu *= tex.maxTexcoordU();
|
||||
scalev *= tex.maxTexcoordV();
|
||||
dispv *= tex.maxTexcoordV();
|
||||
|
||||
setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
|
||||
|
||||
if (-1 < textureLoc) {
|
||||
texUnit = getLastTexUnit() + 1;
|
||||
setUniformValue(textureLoc, texUnit);
|
||||
pgl.activeTexture(PGL.TEXTURE0 + texUnit);
|
||||
tex.bind();
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 < texMatrixLoc) {
|
||||
if (tcmat == null) {
|
||||
tcmat = new float[16];
|
||||
}
|
||||
tcmat[0] = scaleu; tcmat[4] = 0; tcmat[ 8] = 0; tcmat[12] = dispu;
|
||||
tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv;
|
||||
tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0;
|
||||
tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0;
|
||||
setUniformMatrix(texMatrixLoc, tcmat);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasType() {
|
||||
return COLOR <= type && type <= TEXLIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkType(int type) {
|
||||
if (!hasType()) return true;
|
||||
|
||||
if (getType() != type) {
|
||||
if (type == TEXLIGHT) {
|
||||
PGraphics.showWarning(NO_TEXLIGHT_SHADER_ERROR);
|
||||
} else if (type == LIGHT) {
|
||||
PGraphics.showWarning(NO_LIGHT_SHADER_ERROR);
|
||||
} else if (type == TEXTURE) {
|
||||
PGraphics.showWarning(NO_TEXTURE_SHADER_ERROR);
|
||||
} else if (type == COLOR) {
|
||||
PGraphics.showWarning(NO_COLOR_SHADER_ERROR);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTexturing() {
|
||||
return -1 < textureLoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportLighting() {
|
||||
return -1 < lightCountLoc || -1 < lightPositionLoc || -1 < lightNormalLoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accessTexCoords() {
|
||||
return -1 < texCoordLoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accessNormals() {
|
||||
return -1 < normalLoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accessLightAttribs() {
|
||||
return -1 < ambientLoc || -1 < specularLoc || -1 < emissiveLoc ||
|
||||
-1 < shininessLoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVertexAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNormalAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(normalLoc, vboId, size, type, false, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexcoordAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAmbientAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(ambientLoc, vboId, size, type, true, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpecularAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(specularLoc, vboId, size, type, true, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEmissiveAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(emissiveLoc, vboId, size, type, true, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShininessAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(shininessLoc, vboId, size, type, false, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind() {
|
||||
super.bind();
|
||||
if (pg == null) {
|
||||
setRenderer(PGraphicsOpenGL.pgCurrent);
|
||||
loadAttributes();
|
||||
loadUniforms();
|
||||
}
|
||||
setCommonUniforms();
|
||||
|
||||
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
|
||||
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
|
||||
if (-1 < texCoordLoc) pgl.enableVertexAttribArray(texCoordLoc);
|
||||
if (-1 < normalLoc) pgl.enableVertexAttribArray(normalLoc);
|
||||
|
||||
if (-1 < normalMatLoc) {
|
||||
pg.updateGLNormal();
|
||||
setUniformMatrix(normalMatLoc, pg.glNormal);
|
||||
}
|
||||
|
||||
if (-1 < ambientLoc) pgl.enableVertexAttribArray(ambientLoc);
|
||||
if (-1 < specularLoc) pgl.enableVertexAttribArray(specularLoc);
|
||||
if (-1 < emissiveLoc) pgl.enableVertexAttribArray(emissiveLoc);
|
||||
if (-1 < shininessLoc) pgl.enableVertexAttribArray(shininessLoc);
|
||||
|
||||
int count = pg.lightCount;
|
||||
setUniformValue(lightCountLoc, count);
|
||||
if (0 < count) {
|
||||
setUniformVector(lightPositionLoc, pg.lightPosition, 4, count);
|
||||
setUniformVector(lightNormalLoc, pg.lightNormal, 3, count);
|
||||
setUniformVector(lightAmbientLoc, pg.lightAmbient, 3, count);
|
||||
setUniformVector(lightDiffuseLoc, pg.lightDiffuse, 3, count);
|
||||
setUniformVector(lightSpecularLoc, pg.lightSpecular, 3, count);
|
||||
setUniformVector(lightFalloffLoc, pg.lightFalloffCoefficients,
|
||||
3, count);
|
||||
setUniformVector(lightSpotLoc, pg.lightSpotParameters, 2, count);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind() {
|
||||
if (-1 < textureLoc && texture != null) {
|
||||
pgl.activeTexture(PGL.TEXTURE0 + texUnit);
|
||||
texture.unbind();
|
||||
pgl.activeTexture(PGL.TEXTURE0);
|
||||
texture = null;
|
||||
}
|
||||
|
||||
if (-1 < ambientLoc) pgl.disableVertexAttribArray(ambientLoc);
|
||||
if (-1 < specularLoc) pgl.disableVertexAttribArray(specularLoc);
|
||||
if (-1 < emissiveLoc) pgl.disableVertexAttribArray(emissiveLoc);
|
||||
if (-1 < shininessLoc) pgl.disableVertexAttribArray(shininessLoc);
|
||||
|
||||
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
|
||||
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
|
||||
if (-1 < texCoordLoc) pgl.disableVertexAttribArray(texCoordLoc);
|
||||
if (-1 < normalLoc) pgl.disableVertexAttribArray(normalLoc);
|
||||
|
||||
super.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected class LineShader extends BaseShader {
|
||||
protected int perspectiveLoc;
|
||||
protected int scaleLoc;
|
||||
|
||||
protected int vertexLoc;
|
||||
protected int colorLoc;
|
||||
protected int directionLoc;
|
||||
|
||||
public LineShader(PApplet parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public LineShader(PApplet parent, String vertFilename,
|
||||
String fragFilename) {
|
||||
super(parent, vertFilename, fragFilename);
|
||||
}
|
||||
|
||||
public LineShader(PApplet parent, URL vertURL, URL fragURL) {
|
||||
super(parent, vertURL, fragURL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAttributes() {
|
||||
vertexLoc = getAttributeLoc("vertex");
|
||||
if (vertexLoc == -1) vertexLoc = getAttributeLoc("position");
|
||||
|
||||
colorLoc = getAttributeLoc("color");
|
||||
directionLoc = getAttributeLoc("direction");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms() {
|
||||
super.loadUniforms();
|
||||
|
||||
viewportLoc = getUniformLoc("viewport");
|
||||
perspectiveLoc = getUniformLoc("perspective");
|
||||
scaleLoc = getUniformLoc("scale");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVertexAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLineAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(directionLoc, vboId, size, type, false, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind() {
|
||||
super.bind();
|
||||
if (pg == null) {
|
||||
setRenderer(PGraphicsOpenGL.pgCurrent);
|
||||
loadAttributes();
|
||||
loadUniforms();
|
||||
}
|
||||
|
||||
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
|
||||
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
|
||||
if (-1 < directionLoc) pgl.enableVertexAttribArray(directionLoc);
|
||||
|
||||
if (pg.getHint(ENABLE_STROKE_PERSPECTIVE) &&
|
||||
pg.nonOrthoProjection()) {
|
||||
setUniformValue(perspectiveLoc, 1);
|
||||
} else {
|
||||
setUniformValue(perspectiveLoc, 0);
|
||||
}
|
||||
|
||||
if (pg.getHint(DISABLE_OPTIMIZED_STROKE)) {
|
||||
setUniformValue(scaleLoc, 1.0f, 1.0f, 1.0f);
|
||||
} else {
|
||||
float f = PGL.STROKE_DISPLACEMENT;
|
||||
if (orthoProjection()) {
|
||||
setUniformValue(scaleLoc, 1, 1, f);
|
||||
} else {
|
||||
setUniformValue(scaleLoc, f, f, f);
|
||||
}
|
||||
}
|
||||
|
||||
setCommonUniforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind() {
|
||||
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
|
||||
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
|
||||
if (-1 < directionLoc) pgl.disableVertexAttribArray(directionLoc);
|
||||
|
||||
super.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected class PointShader extends BaseShader {
|
||||
protected int perspectiveLoc;
|
||||
|
||||
protected int vertexLoc;
|
||||
protected int colorLoc;
|
||||
protected int offsetLoc;
|
||||
|
||||
public PointShader(PApplet parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public PointShader(PApplet parent, String vertFilename,
|
||||
String fragFilename) {
|
||||
super(parent, vertFilename, fragFilename);
|
||||
}
|
||||
|
||||
public PointShader(PApplet parent, URL vertURL, URL fragURL) {
|
||||
super(parent, vertURL, fragURL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAttributes() {
|
||||
vertexLoc = getAttributeLoc("vertex");
|
||||
if (vertexLoc == -1) vertexLoc = getAttributeLoc("position");
|
||||
|
||||
colorLoc = getAttributeLoc("color");
|
||||
offsetLoc = getAttributeLoc("offset");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms() {
|
||||
super.loadUniforms();
|
||||
|
||||
perspectiveLoc = getUniformLoc("perspective");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVertexAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPointAttribute(int vboId, int size, int type,
|
||||
int stride, int offset) {
|
||||
setAttributeVBO(offsetLoc, vboId, size, type, false, stride, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind() {
|
||||
super.bind();
|
||||
if (pg == null) {
|
||||
setRenderer(PGraphicsOpenGL.pgCurrent);
|
||||
loadAttributes();
|
||||
loadUniforms();
|
||||
}
|
||||
|
||||
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
|
||||
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
|
||||
if (-1 < offsetLoc) pgl.enableVertexAttribArray(offsetLoc);
|
||||
|
||||
if (pg.getHint(ENABLE_STROKE_PERSPECTIVE) &&
|
||||
pg.nonOrthoProjection()) {
|
||||
setUniformValue(perspectiveLoc, 1);
|
||||
} else {
|
||||
setUniformValue(perspectiveLoc, 0);
|
||||
}
|
||||
|
||||
super.setCommonUniforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind() {
|
||||
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
|
||||
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
|
||||
if (-1 < offsetLoc) pgl.disableVertexAttribArray(offsetLoc);
|
||||
|
||||
super.unbind();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user