diff --git a/core/src/processing/opengl/ColorFrag.glsl b/core/src/processing/opengl/ColorFrag.glsl index 5ab649aec..d5d23ae22 100644 --- a/core/src/processing/opengl/ColorFrag.glsl +++ b/core/src/processing/opengl/ColorFrag.glsl @@ -23,8 +23,8 @@ precision mediump float; precision mediump int; #endif -varying vec4 varColor; +varying vec4 vertColor; void main() { - gl_FragColor = varColor; + gl_FragColor = vertColor; } \ No newline at end of file diff --git a/core/src/processing/opengl/ColorVert.glsl b/core/src/processing/opengl/ColorVert.glsl index d43d40549..3736ffd2e 100644 --- a/core/src/processing/opengl/ColorVert.glsl +++ b/core/src/processing/opengl/ColorVert.glsl @@ -25,10 +25,10 @@ uniform mat4 transformMatrix; attribute vec4 position; attribute vec4 color; -varying vec4 varColor; +varying vec4 vertColor; void main() { gl_Position = transformMatrix * position; - varColor = color; + vertColor = color; } \ No newline at end of file diff --git a/core/src/processing/opengl/LightVert.glsl b/core/src/processing/opengl/LightVert.glsl index cfdcc44e0..bfbb6a8d3 100644 --- a/core/src/processing/opengl/LightVert.glsl +++ b/core/src/processing/opengl/LightVert.glsl @@ -42,7 +42,7 @@ attribute vec4 specular; attribute vec4 emissive; attribute float shininess; -varying vec4 varColor; +varying vec4 vertColor; const float zero_float = 0.0; const float one_float = 1.0; @@ -134,8 +134,8 @@ void main() { // Calculating final color as result of all lights (plus emissive term). // Transparency is determined exclusively by the diffuse component. - varColor = vec4(totalAmbient, 0) * ambient + - vec4(totalDiffuse, 1) * color + - vec4(totalSpecular, 0) * specular + - vec4(emissive.rgb, 0); + vertColor = vec4(totalAmbient, 0) * ambient + + vec4(totalDiffuse, 1) * color + + vec4(totalSpecular, 0) * specular + + vec4(emissive.rgb, 0); } \ No newline at end of file diff --git a/core/src/processing/opengl/LineFrag.glsl b/core/src/processing/opengl/LineFrag.glsl index 8ce920e33..dc08a3fa2 100644 --- a/core/src/processing/opengl/LineFrag.glsl +++ b/core/src/processing/opengl/LineFrag.glsl @@ -23,8 +23,8 @@ precision mediump float; precision mediump int; #endif -varying vec4 varColor; +varying vec4 vertColor; void main() { - gl_FragColor = varColor; + gl_FragColor = vertColor; } \ No newline at end of file diff --git a/core/src/processing/opengl/LineVert.glsl b/core/src/processing/opengl/LineVert.glsl index 37687845a..d16f4d519 100644 --- a/core/src/processing/opengl/LineVert.glsl +++ b/core/src/processing/opengl/LineVert.glsl @@ -31,7 +31,7 @@ attribute vec4 position; attribute vec4 color; attribute vec4 direction; -varying vec4 varColor; +varying vec4 vertColor; vec3 clipToWindow(vec4 clip, vec4 viewport) { vec3 post_div = clip.xyz / clip.w; @@ -81,5 +81,5 @@ void main() { gl_Position = clipp; } - varColor = color; + vertColor = color; } diff --git a/core/src/processing/opengl/MaskFrag.glsl b/core/src/processing/opengl/MaskFrag.glsl index 4b517e3a0..508a39649 100644 --- a/core/src/processing/opengl/MaskFrag.glsl +++ b/core/src/processing/opengl/MaskFrag.glsl @@ -28,11 +28,11 @@ precision mediump int; uniform sampler2D texture; uniform sampler2D mask; -varying vec4 varTexCoord; +varying vec4 vertTexCoord; void main() { - vec3 texColor = texture2D(texture, varTexCoord.st).rgb; - vec3 maskColor = texture2D(mask, varTexCoord.st).rgb; + vec3 texColor = texture2D(texture, vertTexCoord.st).rgb; + vec3 maskColor = texture2D(mask, vertTexCoord.st).rgb; float luminance = dot(maskColor, vec3(0.2126, 0.7152, 0.0722)); gl_FragColor = vec4(texColor, luminance); } \ No newline at end of file diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 0623ba3c8..8850be7e1 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -84,18 +84,12 @@ public class PGraphicsOpenGL extends PGraphics { "shader() called with a wrong shader"; static final String UNKNOWN_SHADER_KIND_ERROR = "Unknown shader kind"; - static final String NO_TEXLIGHT_SHADER_ERROR = - "Your shader needs to be of TEXLIGHT type " + - "to render this geometry properly, using default shader instead."; - static final String NO_LIGHT_SHADER_ERROR = - "Your shader needs to be of LIGHT type " + - "to render this geometry properly, using default shader instead."; - static final String NO_TEXTURE_SHADER_ERROR = - "Your shader needs to be of TEXTURE type " + - "to render this geometry properly, using default shader instead."; - static final String NO_COLOR_SHADER_ERROR = - "Your shader needs to be of COLOR type " + - "to render this geometry properly, using default shader instead."; + static final String LIGHT_SHADER_ERROR = + "The shader expects lights but it is beging used to draw an unlit scene, " + + "this might lead to unexpected rendering errors."; + static final String TEXTURE_SHADER_ERROR = + "The shader expects textures but it is being used to draw an untextured scene, " + + "this might lead to unexpected rendering errors."; static final String TOO_LONG_STROKE_PATH_ERROR = "Stroke path is too long, some bevel triangles won't be added"; static final String TESSELLATION_ERROR = @@ -230,10 +224,6 @@ public class PGraphicsOpenGL extends PGraphics { static protected URL defPointShaderFragURL = PGraphicsOpenGL.class.getResource("PointFrag.glsl"); -// static protected ColorShader defColorShader; -// static protected TextureShader defTextureShader; -// static protected LightShader defLightShader; -// static protected TexlightShader defTexlightShader; static protected PolyShader defColorShader; static protected PolyShader defTextureShader; static protected PolyShader defLightShader; @@ -243,26 +233,12 @@ public class PGraphicsOpenGL extends PGraphics { static protected URL maskShaderFragURL = PGraphicsOpenGL.class.getResource("MaskFrag.glsl"); -// static protected TextureShader maskShader; static protected PolyShader maskShader; -// protected ColorShader colorShader; -// protected TextureShader textureShader; -// protected LightShader lightShader; -// protected TexlightShader texlightShader; protected PolyShader polyShader; protected LineShader lineShader; protected PointShader pointShader; - - // When shader warnings are enabled, the renderer is strict in regards to the - // use of the polygon shaders. For instance, if a light shader is set to - // render lit geometry, but the geometry is mixed with some pieces of unlit or - // textured geometry, then it will warn that the set shader cannot be used for - // that other type of geometry, even though Processing will use the correct, - // built-in shaders to handle it. -// protected boolean shaderWarningsEnabled = true; - // ........................................................ // Tessellator, geometry @@ -2389,7 +2365,7 @@ public class PGraphicsOpenGL extends PGraphics { // If the renderer is 2D, then lights should always be false, // so no need to worry about that. - BaseShader shader = getPolyShader(lights, tex != null); + PolyShader shader = getPolyShader(lights, tex != null); shader.bind(); int first = texCache.firstCache[i]; @@ -2422,10 +2398,14 @@ public class PGraphicsOpenGL extends PGraphics { 4 * voffset * PGL.SIZEOF_BYTE); shader.setShininessAttribute(glPolyShininess, 1, PGL.FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); + } else if (shader.supportLighting()) { + PGraphics.showWarning(LIGHT_SHADER_ERROR); } if (tex != null) { shader.setTexture(tex); + } else if (shader.supportsTexturing()) { + PGraphics.showWarning(TEXTURE_SHADER_ERROR); } pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex); @@ -5536,7 +5516,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void filter(PShader shader) { - if (!(shader instanceof PolyShader) || !((PolyShader)shader).hasTexture()) { + if (!(shader instanceof PolyShader) || !((PolyShader)shader).supportsTexturing()) { PGraphics.showWarning(INVALID_FILTER_SHADER_ERROR); return; } @@ -5583,7 +5563,6 @@ public class PGraphicsOpenGL extends PGraphics { PolyShader prevShader = polyShader; polyShader = (PolyShader)shader; - beginShape(QUADS); texture(filterImage); vertex(0, 0, 0, 0); @@ -6307,7 +6286,7 @@ public class PGraphicsOpenGL extends PGraphics { shader.setVertexShader(defColorShaderVertURL); } else { shader = new PolyShader(parent); - shader.setVertexShader(defTexlightShaderVertURL); + shader.setVertexShader(defTextureShaderVertURL); } shader.setFragmentShader(fragFilename); return shader; @@ -6328,6 +6307,8 @@ public class PGraphicsOpenGL extends PGraphics { 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; @@ -6355,7 +6336,7 @@ public class PGraphicsOpenGL extends PGraphics { shader.setFragmentShader(defColorShaderFragURL); } else { shader = new PolyShader(parent); - shader.setVertexShader(defTexlightShaderVertURL); + shader.setVertexShader(defTextureShaderVertURL); } if (shader != null) { shader.setVertexShader(vertFilename); @@ -6368,15 +6349,6 @@ public class PGraphicsOpenGL extends PGraphics { } else { shader = new PolyShader(parent, vertFilename, fragFilename); } -// if (shaderType == PShader.TEXLIGHT) { -// shader = new TexlightShader(parent, vertFilename, fragFilename); -// } else if (shaderType == PShader.LIGHT) { -// shader = new LightShader(parent, vertFilename, fragFilename); -// } else if (shaderType == PShader.TEXTURE) { -// shader = new TextureShader(parent, vertFilename, fragFilename); -// } else if (shaderType == PShader.COLOR) { -// shader = new ColorShader(parent, vertFilename, fragFilename); -// } } return shader; } @@ -6395,14 +6367,6 @@ public class PGraphicsOpenGL extends PGraphics { if (kind == TRIANGLES || kind == QUADS || kind == POLYGON) { if (shader instanceof PolyShader) { polyShader = (PolyShader) shader; -// if (shader instanceof TexlightShader) { -// texlightShader = (TexlightShader) shader; -// } else if (shader instanceof TextureShader) { -// textureShader = (TextureShader) shader; -// } else if (shader instanceof LightShader) { -// lightShader = (LightShader) shader; -// } else if (shader instanceof ColorShader) { -// colorShader = (ColorShader) shader; } else { PGraphics.showWarning(WRONG_SHADER_TYPE_ERROR); } @@ -6435,10 +6399,6 @@ public class PGraphicsOpenGL extends PGraphics { flush(); // Flushing geometry drawn with a different shader. if (kind == TRIANGLES || kind == QUADS || kind == POLYGON) { -// textureShader = null; -// colorShader = null; -// texlightShader = null; -// lightShader = null; polyShader = null; } else if (kind == LINES) { lineShader = null; @@ -6450,11 +6410,6 @@ public class PGraphicsOpenGL extends PGraphics { } -// public void shaderWarnings(boolean enable) { -// shaderWarningsEnabled = enable; -// } - - protected int getShaderType(String filename) { String[] source = parent.loadStrings(filename); int type = PShader.POLY; @@ -6510,7 +6465,6 @@ public class PGraphicsOpenGL extends PGraphics { defTextureShaderFragURL); } shader = defTexlightShader; -// texlightShaderCheck(); } else { shader = polyShader; } @@ -6522,7 +6476,6 @@ public class PGraphicsOpenGL extends PGraphics { defColorShaderFragURL); } shader = defLightShader; -// lightShaderCheck(); } else { shader = polyShader; } @@ -6536,7 +6489,6 @@ public class PGraphicsOpenGL extends PGraphics { defTextureShaderFragURL); } shader = defTextureShader; -// textureShaderCheck(); } else { shader = polyShader; } @@ -6548,7 +6500,6 @@ public class PGraphicsOpenGL extends PGraphics { defColorShaderFragURL); } shader = defColorShader; -// colorShaderCheck(); } else { shader = polyShader; } @@ -6561,46 +6512,6 @@ public class PGraphicsOpenGL extends PGraphics { } -// protected void texlightShaderCheck() { -// if (shaderWarningsEnabled && -// (lightShader != null || -// textureShader != null || -// colorShader != null)) { -// PGraphics.showWarning(NO_TEXLIGHT_SHADER_ERROR); -// } -// } -// -// -// protected void lightShaderCheck() { -// if (shaderWarningsEnabled && -// (texlightShader != null || -// textureShader != null || -// colorShader != null)) { -// PGraphics.showWarning(NO_LIGHT_SHADER_ERROR); -// } -// } -// -// -// protected void textureShaderCheck() { -// if (shaderWarningsEnabled && -// (texlightShader != null || -// lightShader != null || -// colorShader != null)) { -// PGraphics.showWarning(NO_TEXTURE_SHADER_ERROR); -// } -// } -// -// -// protected void colorShaderCheck() { -// if (shaderWarningsEnabled && -// (texlightShader != null || -// lightShader != null || -// textureShader != null)) { -// PGraphics.showWarning(NO_COLOR_SHADER_ERROR); -// } -// } - - protected LineShader getLineShader() { LineShader shader; if (lineShader == null) { @@ -6720,7 +6631,11 @@ public class PGraphicsOpenGL extends PGraphics { } } - public boolean hasTexture() { + public boolean supportsTexturing() { + return false; + } + + public boolean supportLighting() { return false; } @@ -6743,396 +6658,6 @@ public class PGraphicsOpenGL extends PGraphics { public void setTexture(Texture tex) { } } -/* - protected class ColorShader extends BaseShader { - protected int vertexLoc; - protected int colorLoc; - protected int normalLoc; - protected int texCoordLoc; - protected int normalMatLoc; - - public ColorShader(PApplet parent) { - super(parent); - } - - public ColorShader(PApplet parent, String vertFilename, - String fragFilename) { - super(parent, vertFilename, fragFilename); - } - - public ColorShader(PApplet parent, URL vertURL, URL fragURL) { - super(parent, vertURL, fragURL); - } - - @Override - public void loadAttributes() { - vertexLoc = getAttributeLoc("vertex"); - colorLoc = getAttributeLoc("color"); - texCoordLoc = getAttributeLoc("texCoord"); - normalLoc = getAttributeLoc("normal"); - } - - @Override - public void loadUniforms() { - super.loadUniforms(); - - normalMatLoc = getUniformLoc("normalMatrix"); - } - - @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 bind() { - super.bind(); - if (pgCurrent == 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) { - pgCurrent.updateGLNormal(); - setUniformMatrix(normalMatLoc, pgCurrent.glNormal); - } - } - - @Override - public void unbind() { - 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 LightShader extends ColorShader { - 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; - - public LightShader(PApplet parent) { - super(parent); - } - - public LightShader(PApplet parent, String vertFilename, - String fragFilename) { - super(parent, vertFilename, fragFilename); - } - - public LightShader(PApplet parent, URL vertURL, URL fragURL) { - super(parent, vertURL, fragURL); - } - - @Override - public void loadAttributes() { - super.loadAttributes(); - ambientLoc = getAttributeLoc("ambient"); - specularLoc = getAttributeLoc("specular"); - emissiveLoc = getAttributeLoc("emissive"); - shininessLoc = getAttributeLoc("shininess"); - } - - @Override - public void loadUniforms() { - super.loadUniforms(); - - lightCountLoc = getUniformLoc("lightCount"); - lightPositionLoc = getUniformLoc("lightPosition"); - lightNormalLoc = getUniformLoc("lightNormal"); - lightAmbientLoc = getUniformLoc("lightAmbient"); - lightDiffuseLoc = getUniformLoc("lightDiffuse"); - lightSpecularLoc = getUniformLoc("lightSpecular"); - lightFalloffLoc = getUniformLoc("lightFalloff"); - lightSpotLoc = getUniformLoc("lightSpot"); - } - - @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 (-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 = pgCurrent.lightCount; - setUniformValue(lightCountLoc, count); - setUniformVector(lightPositionLoc, pgCurrent.lightPosition, 4, count); - setUniformVector(lightNormalLoc, pgCurrent.lightNormal, 3, count); - 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); - } - - @Override - public void unbind() { - if (-1 < ambientLoc) pgl.disableVertexAttribArray(ambientLoc); - if (-1 < specularLoc) pgl.disableVertexAttribArray(specularLoc); - if (-1 < emissiveLoc) pgl.disableVertexAttribArray(emissiveLoc); - if (-1 < shininessLoc) pgl.disableVertexAttribArray(shininessLoc); - - super.unbind(); - } - } - - - protected class TextureShader extends ColorShader { - protected Texture texture; - protected int texUnit; - - protected int textureLoc; - protected int texMatrixLoc; - protected int texOffsetLoc; - - protected float[] tcmat; - - public TextureShader(PApplet parent) { - super(parent); - } - - public TextureShader(PApplet parent, String vertFilename, - String fragFilename) { - super(parent, vertFilename, fragFilename); - } - - public TextureShader(PApplet parent, URL vertURL, URL fragURL) { - super(parent, vertURL, fragURL); - } - - @Override - public void loadUniforms() { - super.loadUniforms(); - - textureLoc = getUniformLoc("texture"); - texMatrixLoc = getUniformLoc("texMatrix"); - texOffsetLoc = getUniformLoc("texOffset"); - } - - @Override - public int getLastTexUnit() { - return -1 < bufferUnit ? bufferUnit : super.getLastTexUnit(); - } - - @Override - public void setTexture(Texture tex) { - float scaleu = 1; - float scalev = 1; - float dispu = 0; - float dispv = 0; - - 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(); - - 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); - } - - 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(); - texture = tex; - } - } - - @Override - public void unbind() { - if (-1 < textureLoc && texture != null) { - pgl.activeTexture(PGL.TEXTURE0 + texUnit); - texture.unbind(); - pgl.activeTexture(PGL.TEXTURE0); - texture = null; - } - - super.unbind(); - } - } - - - protected class TexlightShader extends LightShader { - protected Texture texture; - protected int texUnit; - - protected int textureLoc; - protected int texMatrixLoc; - protected int texOffsetLoc; - - protected float[] tcmat; - - public TexlightShader(PApplet parent) { - super(parent); - } - - public TexlightShader(PApplet parent, String vertFilename, - String fragFilename) { - super(parent, vertFilename, fragFilename); - } - - public TexlightShader(PApplet parent, URL vertURL, URL fragURL) { - super(parent, vertURL, fragURL); - } - - @Override - public void loadUniforms() { - super.loadUniforms(); - - textureLoc = getUniformLoc("texture"); - texMatrixLoc = getUniformLoc("texMatrix"); - texOffsetLoc = getUniformLoc("texOffset"); - } - - @Override - public int getLastTexUnit() { - return -1 < bufferUnit ? bufferUnit : super.getLastTexUnit(); - } - - @Override - public void setTexture(Texture tex) { - float scaleu = 1; - float scalev = 1; - float dispu = 0; - float dispv = 0; - - 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; - - 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); - } - - 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(); - texture = tex; - } - } - - @Override - public void unbind() { - if (-1 < textureLoc && texture != null) { - pgl.activeTexture(PGL.TEXTURE0 + texUnit); - texture.unbind(); - pgl.activeTexture(PGL.TEXTURE0); - texture = null; - } - - super.unbind(); - } - } -*/ protected class PolyShader extends BaseShader { protected int vertexLoc; @@ -7190,10 +6715,6 @@ public class PGraphicsOpenGL extends PGraphics { specularLoc = getAttributeLoc("specular"); emissiveLoc = getAttributeLoc("emissive"); shininessLoc = getAttributeLoc("shininess"); - - textureLoc = getUniformLoc("texture"); - texMatrixLoc = getUniformLoc("texMatrix"); - texOffsetLoc = getUniformLoc("texOffset"); } @Override @@ -7216,10 +6737,10 @@ public class PGraphicsOpenGL extends PGraphics { texOffsetLoc = getUniformLoc("texOffset"); } - @Override - public int getLastTexUnit() { - return -1 < bufferUnit ? bufferUnit : super.getLastTexUnit(); - } +// @Override +// public int getLastTexUnit() { +// return -1 < bufferUnit ? bufferUnit : super.getLastTexUnit(); +// } @Override public void setTexture(Texture tex) { @@ -7266,10 +6787,15 @@ public class PGraphicsOpenGL extends PGraphics { } @Override - public boolean hasTexture() { + public boolean supportsTexturing() { return -1 < textureLoc; } + @Override + public boolean supportLighting() { + return -1 < lightCountLoc || -1 < lightPositionLoc || -1 < lightNormalLoc; + } + @Override public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { diff --git a/core/src/processing/opengl/PShader.java b/core/src/processing/opengl/PShader.java index 711e616e6..5c390a55d 100644 --- a/core/src/processing/opengl/PShader.java +++ b/core/src/processing/opengl/PShader.java @@ -43,11 +43,11 @@ public class PShader { // shaders constants static protected final int LINE = 0; static protected final int POINT = 1; - static protected final int POLY = 3; - static protected final int COLOR = 4; - static protected final int LIGHT = 5; - static protected final int TEXTURE = 6; - static protected final int TEXLIGHT = 7; + static protected final int POLY = 2; + static protected final int COLOR = 3; + static protected final int LIGHT = 4; + static protected final int TEXTURE = 5; + static protected final int TEXLIGHT = 6; protected PApplet parent; // The main renderer associated to the parent PApplet. diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 38e39d719..bfeefc37d 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -4479,10 +4479,14 @@ public class PShapeOpenGL extends PShape { 0, 4 * voffset * PGL.SIZEOF_BYTE); shader.setShininessAttribute(root.glPolyShininess, 1, PGL.FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); + } else if (shader.supportLighting()) { + PGraphics.showWarning(PGraphicsOpenGL.LIGHT_SHADER_ERROR); } if (tex != null) { shader.setTexture(tex); + } else if (shader.supportsTexturing()) { + PGraphics.showWarning(PGraphicsOpenGL.TEXTURE_SHADER_ERROR); } pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, root.glPolyIndex); diff --git a/core/src/processing/opengl/PointFrag.glsl b/core/src/processing/opengl/PointFrag.glsl index 5ab649aec..d5d23ae22 100644 --- a/core/src/processing/opengl/PointFrag.glsl +++ b/core/src/processing/opengl/PointFrag.glsl @@ -23,8 +23,8 @@ precision mediump float; precision mediump int; #endif -varying vec4 varColor; +varying vec4 vertColor; void main() { - gl_FragColor = varColor; + gl_FragColor = vertColor; } \ No newline at end of file diff --git a/core/src/processing/opengl/PointVert.glsl b/core/src/processing/opengl/PointVert.glsl index 542efaa67..c677ce75b 100644 --- a/core/src/processing/opengl/PointVert.glsl +++ b/core/src/processing/opengl/PointVert.glsl @@ -30,7 +30,7 @@ attribute vec4 position; attribute vec4 color; attribute vec2 offset; -varying vec4 varColor; +varying vec4 vertColor; vec4 windowToClipVector(vec2 window, vec4 viewport, float clipw) { vec2 xypos = (window / viewport.zw) * 2.0; @@ -51,5 +51,5 @@ void main() { gl_Position = clip + offset; } - varColor = color; + vertColor = color; } \ No newline at end of file diff --git a/core/src/processing/opengl/TexlightVert.glsl b/core/src/processing/opengl/TexlightVert.glsl index 620d50c70..6542bf8fb 100644 --- a/core/src/processing/opengl/TexlightVert.glsl +++ b/core/src/processing/opengl/TexlightVert.glsl @@ -44,8 +44,8 @@ attribute vec4 specular; attribute vec4 emissive; attribute float shininess; -varying vec4 varColor; -varying vec4 varTexCoord; +varying vec4 vertColor; +varying vec4 vertTexCoord; const float zero_float = 0.0; const float one_float = 1.0; @@ -137,11 +137,11 @@ void main() { // Calculating final color as result of all lights (plus emissive term). // Transparency is determined exclusively by the diffuse component. - varColor = vec4(totalAmbient, 0) * ambient + - vec4(totalDiffuse, 1) * color + - vec4(totalSpecular, 0) * specular + - vec4(emissive.rgb, 0); + vertColor = vec4(totalAmbient, 0) * ambient + + vec4(totalDiffuse, 1) * color + + vec4(totalSpecular, 0) * specular + + vec4(emissive.rgb, 0); // Calculating texture coordinates, with r and q set both to one - varTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0); + vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0); } diff --git a/core/src/processing/opengl/TextureFrag.glsl b/core/src/processing/opengl/TextureFrag.glsl index dc3bcbe7e..f041e61d1 100644 --- a/core/src/processing/opengl/TextureFrag.glsl +++ b/core/src/processing/opengl/TextureFrag.glsl @@ -27,9 +27,9 @@ uniform sampler2D texture; uniform vec2 texOffset; -varying vec4 varColor; -varying vec4 varTexCoord; +varying vec4 vertColor; +varying vec4 vertTexCoord; void main() { - gl_FragColor = texture2D(texture, varTexCoord.st) * varColor; + gl_FragColor = texture2D(texture, vertTexCoord.st) * vertColor; } \ No newline at end of file diff --git a/core/src/processing/opengl/TextureVert.glsl b/core/src/processing/opengl/TextureVert.glsl index e52789316..cbbb361b1 100644 --- a/core/src/processing/opengl/TextureVert.glsl +++ b/core/src/processing/opengl/TextureVert.glsl @@ -18,7 +18,7 @@ Boston, MA 02111-1307 USA */ -#define PROCESSING_TEXTURE_SHADER +//#define PROCESSING_TEXTURE_SHADER uniform mat4 transformMatrix; uniform mat4 texMatrix; @@ -27,12 +27,12 @@ attribute vec4 position; attribute vec4 color; attribute vec2 texCoord; -varying vec4 varColor; -varying vec4 varTexCoord; +varying vec4 vertColor; +varying vec4 vertTexCoord; void main() { gl_Position = transformMatrix * position; - varColor = color; - varTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0); + vertColor = color; + vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0); } \ No newline at end of file