Android sync

This commit is contained in:
codeanticode
2013-02-10 00:13:32 -05:00
parent e710c4f3d1
commit 92f62c45ce
21 changed files with 1971 additions and 752 deletions
File diff suppressed because it is too large Load Diff
@@ -249,7 +249,7 @@ class FontTexture implements PConstants {
}
if (outdated) {
for (int i = 0; i < textures.length; i++) {
pg.removeTextureObject(textures[i].glName, textures[i].context.id());
pg.removeTextureObject(textures[i].glName, textures[i].context);
textures[i].glName = 0;
}
}
@@ -43,7 +43,7 @@ public class FrameBuffer implements PConstants {
protected PApplet parent;
protected PGraphicsOpenGL pg;
protected PGL pgl;
protected PGL.Context context; // The context that created this framebuffer.
protected int context; // The context that created this framebuffer.
public int glFbo;
public int glDepth;
@@ -151,19 +151,19 @@ public class FrameBuffer implements PConstants {
try {
if (!screenFb) {
if (glFbo != 0) {
pg.finalizeFrameBufferObject(glFbo, context.id());
pg.finalizeFrameBufferObject(glFbo, context);
}
if (glDepth != 0) {
pg.finalizeRenderBufferObject(glDepth, context.id());
pg.finalizeRenderBufferObject(glDepth, context);
}
if (glStencil != 0) {
pg.finalizeRenderBufferObject(glStencil, context.id());
pg.finalizeRenderBufferObject(glStencil, context);
}
if (glMultisample != 0) {
pg.finalizeRenderBufferObject(glMultisample, context.id());
pg.finalizeRenderBufferObject(glMultisample, context);
}
if (glDepthStencil != 0) {
pg.finalizeRenderBufferObject(glDepthStencil, context.id());
pg.finalizeRenderBufferObject(glDepthStencil, context);
}
}
} finally {
@@ -345,7 +345,7 @@ public class FrameBuffer implements PConstants {
glFbo = 0;
} else {
//create the FBO object...
glFbo = pg.createFrameBufferObject(context.id());
glFbo = pg.createFrameBufferObject(context);
// ... and then create the rest of the stuff.
if (multisample) {
@@ -370,23 +370,23 @@ public class FrameBuffer implements PConstants {
if (screenFb) return;
if (glFbo != 0) {
pg.finalizeFrameBufferObject(glFbo, context.id());
pg.finalizeFrameBufferObject(glFbo, context);
glFbo = 0;
}
if (glDepth != 0) {
pg.finalizeRenderBufferObject(glDepth, context.id());
pg.finalizeRenderBufferObject(glDepth, context);
glDepth = 0;
}
if (glStencil != 0) {
pg.finalizeRenderBufferObject(glStencil, context.id());
pg.finalizeRenderBufferObject(glStencil, context);
glStencil = 0;
}
if (glMultisample != 0) {
pg.finalizeRenderBufferObject(glMultisample, context.id());
pg.finalizeRenderBufferObject(glMultisample, context);
glMultisample = 0;
}
if (glDepthStencil != 0) {
pg.finalizeRenderBufferObject(glDepthStencil, context.id());
pg.finalizeRenderBufferObject(glDepthStencil, context);
glDepthStencil = 0;
}
}
@@ -397,11 +397,11 @@ public class FrameBuffer implements PConstants {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
pg.removeFrameBufferObject(glFbo, context.id());
pg.removeRenderBufferObject(glDepth, context.id());
pg.removeRenderBufferObject(glStencil, context.id());
pg.removeRenderBufferObject(glDepthStencil, context.id());
pg.removeRenderBufferObject(glMultisample, context.id());
pg.removeFrameBufferObject(glFbo, context);
pg.removeRenderBufferObject(glDepth, context);
pg.removeRenderBufferObject(glStencil, context);
pg.removeRenderBufferObject(glDepthStencil, context);
pg.removeRenderBufferObject(glMultisample, context);
glFbo = 0;
glDepth = 0;
@@ -423,7 +423,7 @@ public class FrameBuffer implements PConstants {
pg.pushFramebuffer();
pg.setFramebuffer(this);
glMultisample = pg.createRenderBufferObject(context.id());
glMultisample = pg.createRenderBufferObject(context);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
PGL.RGBA8, width, height);
@@ -444,7 +444,7 @@ public class FrameBuffer implements PConstants {
pg.pushFramebuffer();
pg.setFramebuffer(this);
glDepthStencil = pg.createRenderBufferObject(context.id());
glDepthStencil = pg.createRenderBufferObject(context);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
if (multisample) {
@@ -474,7 +474,7 @@ public class FrameBuffer implements PConstants {
pg.pushFramebuffer();
pg.setFramebuffer(this);
glDepth = pg.createRenderBufferObject(context.id());
glDepth = pg.createRenderBufferObject(context);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
int glConst = PGL.DEPTH_COMPONENT16;
@@ -510,7 +510,7 @@ public class FrameBuffer implements PConstants {
pg.pushFramebuffer();
pg.setFramebuffer(this);
glStencil = pg.createRenderBufferObject(context.id());
glStencil = pg.createRenderBufferObject(context);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
int glConst = PGL.STENCIL_INDEX1;
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,16 +18,18 @@
Boston, MA 02111-1307 USA
*/
uniform mat4 modelviewMatrix;
uniform mat4 projectionMatrix;
#define PROCESSING_LINE_SHADER
uniform mat4 modelview;
uniform mat4 projection;
uniform vec4 viewport;
uniform int perspective;
uniform vec3 scale;
attribute vec4 inVertex;
attribute vec4 inColor;
attribute vec4 inLine;
attribute vec4 vertex;
attribute vec4 color;
attribute vec4 endpoint;
varying vec4 vertColor;
@@ -43,21 +45,21 @@ vec4 windowToClipVector(vec2 window, vec4 viewport, float clip_w) {
}
void main() {
vec4 pos_p = inVertex;
vec4 v_p = modelviewMatrix * pos_p;
vec4 pos_p = vertex;
vec4 v_p = modelview * pos_p;
// 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 = projectionMatrix * v_p;
float thickness = inLine.w;
vec4 clip_p = projection * v_p;
float thickness = endpoint.w;
if (thickness != 0.0) {
vec4 pos_q = vec4(inLine.xyz, 1);
vec4 v_q = modelviewMatrix * pos_q;
vec4 pos_q = vec4(endpoint.xyz, 1);
vec4 v_q = modelview * pos_q;
v_q.xyz = v_q.xyz * scale;
vec4 clip_q = projectionMatrix * v_q;
vec4 clip_q = projection * v_q;
vec3 window_p = clipToWindow(clip_p, viewport);
vec3 window_q = clipToWindow(clip_q, viewport);
@@ -81,5 +83,5 @@ void main() {
gl_Position = clip_p;
}
vertColor = inColor;
vertColor = color;
}
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012 Ben Fry and Casey Reas
Copyright (c) 2012-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,14 +18,16 @@
Boston, MA 02111-1307 USA
*/
uniform sampler2D textureSampler;
uniform sampler2D maskSampler;
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
uniform sampler2D mask;
varying vec4 vertTexcoord;
varying vec4 vertTexCoord;
void main() {
vec3 texColor = texture2D(textureSampler, vertTexcoord.st).rgb;
vec3 maskColor = texture2D(maskSampler, vertTexcoord.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);
}
+9 -48
View File
@@ -844,7 +844,7 @@ public class PGL {
}
protected static boolean glThreadIsCurrent() {
protected boolean threadIsCurrent() {
return Thread.currentThread() == glThread;
}
@@ -1502,48 +1502,13 @@ public class PGL {
// Context interface
protected Context createEmptyContext() {
return new Context();
protected int createEmptyContext() {
return -1;
}
protected Context getCurrentContext() {
return new Context(context);
}
protected class Context {
protected int id;
Context() {
id = -1;
}
Context(EGLContext context) {
if (context != null) {
id = context.hashCode();
} else {
id = -1;
}
}
boolean current() {
return equal(context);
}
boolean equal(EGLContext context) {
if (id == -1 || context == null) {
// A null context means a still non-created resource,
// so it is considered equal to the argument.
return true;
} else {
return id == context.hashCode();
}
}
int id() {
return id;
}
protected int getCurrentContext() {
return context.hashCode();
}
@@ -1648,8 +1613,8 @@ public class PGL {
// Utility functions
protected boolean contextIsCurrent(Context other) {
return other == null || other.current();
protected boolean contextIsCurrent(int other) {
return other == -1 || other == context.hashCode();
}
@@ -1742,8 +1707,6 @@ public class PGL {
}
if (texData == null) {
// This buffer has to be direct because vertexAttribPointer only accepts
// direct buffers.
texData = allocateDirectFloatBuffer(texCoords.length);
}
@@ -1766,25 +1729,21 @@ public class PGL {
// Vertex coordinates of the textured quad are specified
// in normalized screen space (-1, 1):
// Corner 1
texCoords[ 0] = 2 * (float)scrX0 / pg.width - 1;
texCoords[ 1] = 2 * (float)scrY0 / pg.height - 1;
texCoords[ 2] = (float)texX0 / width;
texCoords[ 3] = (float)texY0 / height;
// Corner 2
texCoords[ 4] = 2 * (float)scrX1 / pg.width - 1;
texCoords[ 5] = 2 * (float)scrY0 / pg.height - 1;
texCoords[ 6] = (float)texX1 / width;
texCoords[ 7] = (float)texY0 / height;
// Corner 3
texCoords[ 8] = 2 * (float)scrX0 / pg.width - 1;
texCoords[ 9] = 2 * (float)scrY1 / pg.height - 1;
texCoords[10] = (float)texX0 / width;
texCoords[11] = (float)texY1 / height;
// Corner 4
texCoords[12] = 2 * (float)scrX1 / pg.width - 1;
texCoords[13] = 2 * (float)scrY1 / pg.height - 1;
@@ -1802,6 +1761,8 @@ public class PGL {
}
bindTexture(target, id);
bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point.
texData.position(0);
vertexAttribPointer(texVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
texData);
@@ -283,7 +283,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
@Override
public PShape createShape() {
return createShape(POLYGON);
return createShape(PShape.GEOMETRY);
}
@@ -305,7 +305,12 @@ public class PGraphics2D extends PGraphicsOpenGL {
shape = new PShapeOpenGL(parent, PConstants.GROUP);
} else if (type == PShape.PATH) {
shape = new PShapeOpenGL(parent, PShape.PATH);
} else if (type == POINTS) {
} else if (type == PShape.GEOMETRY) {
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
}
/*
if (type == POINTS) {
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
shape.setKind(POINTS);
} else if (type == LINES) {
@@ -330,6 +335,8 @@ public class PGraphics2D extends PGraphicsOpenGL {
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
shape.setKind(POLYGON);
}
*/
shape.is3D(false);
return shape;
}
@@ -35,7 +35,7 @@ public class PGraphics3D extends PGraphicsOpenGL {
public PGraphics3D() {
super();
hints[ENABLE_STROKE_PERSPECTIVE] = true;
hints[ENABLE_STROKE_PERSPECTIVE] = false;
}
//////////////////////////////////////////////////////////////
@@ -150,7 +150,7 @@ public class PGraphics3D extends PGraphicsOpenGL {
@Override
public PShape createShape() {
return createShape(POLYGON);
return createShape(PShape.GEOMETRY);
}
@@ -172,14 +172,22 @@ public class PGraphics3D extends PGraphicsOpenGL {
shape = new PShapeOpenGL(parent, PConstants.GROUP);
} else if (type == PShape.PATH) {
shape = new PShapeOpenGL(parent, PShape.PATH);
} else if (type == POINTS) {
} else if (type == PShape.GEOMETRY) {
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
}
/*
(type == POINTS) {
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
shape.setKind(POINTS);
} else if (type == LINES) {
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
shape.setKind(LINES);
} else if (type == TRIANGLE || type == TRIANGLES) {
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
shape.setKind(TRIANGLES);
} else if (type == TRIANGLE_FAN) {
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
@@ -197,6 +205,8 @@ public class PGraphics3D extends PGraphicsOpenGL {
shape = new PShapeOpenGL(parent, PShape.GEOMETRY);
shape.setKind(POLYGON);
}
*/
shape.is3D(true);
return shape;
}
@@ -3,7 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2004-12 Ben Fry and Casey Reas
Copyright (c) 2004-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -27,7 +27,6 @@ import processing.core.*;
import java.net.URL;
import java.nio.*;
import java.util.*;
import java.util.regex.*;
/**
* OpenGL renderer.
@@ -138,21 +137,21 @@ public class PGraphicsOpenGL extends PGraphics {
public int glPolyShininess;
public int glPolyIndex;
protected boolean polyBuffersCreated = false;
protected PGL.Context polyBuffersContext;
protected int polyBuffersContext;
public int glLineVertex;
public int glLineColor;
public int glLineAttrib;
public int glLineIndex;
protected boolean lineBuffersCreated = false;
protected PGL.Context lineBuffersContext;
protected int lineBuffersContext;
public int glPointVertex;
public int glPointColor;
public int glPointAttrib;
public int glPointIndex;
protected boolean pointBuffersCreated = false;
protected PGL.Context pointBuffersContext;
protected int pointBuffersContext;
protected static final int INIT_VERTEX_BUFFER_SIZE = 256;
protected static final int INIT_INDEX_BUFFER_SIZE = 512;
@@ -1198,45 +1197,41 @@ public class PGraphicsOpenGL extends PGraphics {
int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT;
int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX;
glPolyVertex = createVertexBufferObject(polyBuffersContext.id());
glPolyVertex = createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
glPolyColor = createVertexBufferObject(polyBuffersContext.id());
glPolyColor = createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolyNormal = createVertexBufferObject(polyBuffersContext.id());
glPolyNormal = createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
glPolyTexcoord = createVertexBufferObject(polyBuffersContext.id());
glPolyTexcoord = createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, null, PGL.STATIC_DRAW);
glPolyAmbient = pgPrimary.createVertexBufferObject(
polyBuffersContext.id());
glPolyAmbient = pgPrimary.createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolySpecular = pgPrimary.createVertexBufferObject(
polyBuffersContext.id());
glPolySpecular = pgPrimary.createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolyEmissive = pgPrimary.createVertexBufferObject(
polyBuffersContext.id());
glPolyEmissive = pgPrimary.createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolyShininess = pgPrimary.createVertexBufferObject(
polyBuffersContext.id());
glPolyShininess = pgPrimary.createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess);
pgl.bufferData(PGL.ARRAY_BUFFER, sizef, null, PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
glPolyIndex = createVertexBufferObject(polyBuffersContext.id());
glPolyIndex = createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW);
@@ -1319,31 +1314,31 @@ public class PGraphicsOpenGL extends PGraphics {
protected void deletePolyBuffers() {
if (polyBuffersCreated) {
deleteVertexBufferObject(glPolyVertex, polyBuffersContext.id());
deleteVertexBufferObject(glPolyVertex, polyBuffersContext);
glPolyVertex = 0;
deleteVertexBufferObject(glPolyColor, polyBuffersContext.id());
deleteVertexBufferObject(glPolyColor, polyBuffersContext);
glPolyColor = 0;
deleteVertexBufferObject(glPolyNormal, polyBuffersContext.id());
deleteVertexBufferObject(glPolyNormal, polyBuffersContext);
glPolyNormal = 0;
deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext.id());
deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext);
glPolyTexcoord = 0;
deleteVertexBufferObject(glPolyAmbient, polyBuffersContext.id());
deleteVertexBufferObject(glPolyAmbient, polyBuffersContext);
glPolyAmbient = 0;
deleteVertexBufferObject(glPolySpecular, polyBuffersContext.id());
deleteVertexBufferObject(glPolySpecular, polyBuffersContext);
glPolySpecular = 0;
deleteVertexBufferObject(glPolyEmissive, polyBuffersContext.id());
deleteVertexBufferObject(glPolyEmissive, polyBuffersContext);
glPolyEmissive = 0;
deleteVertexBufferObject(glPolyShininess, polyBuffersContext.id());
deleteVertexBufferObject(glPolyShininess, polyBuffersContext);
glPolyShininess = 0;
deleteVertexBufferObject(glPolyIndex, polyBuffersContext.id());
deleteVertexBufferObject(glPolyIndex, polyBuffersContext);
glPolyIndex = 0;
polyBuffersCreated = false;
@@ -1359,22 +1354,22 @@ public class PGraphicsOpenGL extends PGraphics {
int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT;
int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX;
glLineVertex = createVertexBufferObject(lineBuffersContext.id());
glLineVertex = createVertexBufferObject(lineBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
glLineColor = createVertexBufferObject(lineBuffersContext.id());
glLineColor = createVertexBufferObject(lineBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glLineAttrib = createVertexBufferObject(lineBuffersContext.id());
glLineAttrib = createVertexBufferObject(lineBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, null, PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
glLineIndex = createVertexBufferObject(lineBuffersContext.id());
glLineIndex = createVertexBufferObject(lineBuffersContext);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW);
@@ -1428,16 +1423,16 @@ public class PGraphicsOpenGL extends PGraphics {
protected void deleteLineBuffers() {
if (lineBuffersCreated) {
deleteVertexBufferObject(glLineVertex, lineBuffersContext.id());
deleteVertexBufferObject(glLineVertex, lineBuffersContext);
glLineVertex = 0;
deleteVertexBufferObject(glLineColor, lineBuffersContext.id());
deleteVertexBufferObject(glLineColor, lineBuffersContext);
glLineColor = 0;
deleteVertexBufferObject(glLineAttrib, lineBuffersContext.id());
deleteVertexBufferObject(glLineAttrib, lineBuffersContext);
glLineAttrib = 0;
deleteVertexBufferObject(glLineIndex, lineBuffersContext.id());
deleteVertexBufferObject(glLineIndex, lineBuffersContext);
glLineIndex = 0;
lineBuffersCreated = false;
@@ -1453,21 +1448,21 @@ public class PGraphicsOpenGL extends PGraphics {
int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT;
int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX;
glPointVertex = createVertexBufferObject(pointBuffersContext.id());
glPointVertex = createVertexBufferObject(pointBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
glPointColor = createVertexBufferObject(pointBuffersContext.id());
glPointColor = createVertexBufferObject(pointBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPointAttrib = createVertexBufferObject(pointBuffersContext.id());
glPointAttrib = createVertexBufferObject(pointBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, null, PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
glPointIndex = createVertexBufferObject(pointBuffersContext.id());
glPointIndex = createVertexBufferObject(pointBuffersContext);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW);
@@ -1521,16 +1516,16 @@ public class PGraphicsOpenGL extends PGraphics {
protected void deletePointBuffers() {
if (pointBuffersCreated) {
deleteVertexBufferObject(glPointVertex, pointBuffersContext.id());
deleteVertexBufferObject(glPointVertex, pointBuffersContext);
glPointVertex = 0;
deleteVertexBufferObject(glPointColor, pointBuffersContext.id());
deleteVertexBufferObject(glPointColor, pointBuffersContext);
glPointColor = 0;
deleteVertexBufferObject(glPointAttrib, pointBuffersContext.id());
deleteVertexBufferObject(glPointAttrib, pointBuffersContext);
glPointAttrib = 0;
deleteVertexBufferObject(glPointIndex, pointBuffersContext.id());
deleteVertexBufferObject(glPointIndex, pointBuffersContext);
glPointIndex = 0;
pointBuffersCreated = false;
@@ -5329,7 +5324,7 @@ public class PGraphicsOpenGL extends PGraphics {
maskShader = new PolyTexShader(parent, defPolyTexShaderVertURL,
maskShaderFragURL);
}
maskShader.set("maskSampler", alpha);
maskShader.set("mask", alpha);
filter(maskShader);
}
@@ -5745,7 +5740,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected boolean checkGLThread() {
if (PGL.glThreadIsCurrent()) {
if (pgl.threadIsCurrent()) {
return true;
} else {
PGraphics.showWarning(OPENGL_THREAD_ERROR);
@@ -6130,27 +6125,47 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public PShader loadShader(String fragFilename) {
int shaderType = getTypeFromFragmentShader(fragFilename);
int shaderType = getShaderType(fragFilename);
if (shaderType == -1) {
PGraphics.showWarning(INVALID_PROCESSING_SHADER_ERROR);
return null;
}
PShader shader = null;
if (shaderType == PShader.TEXTURE) {
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 PolyTexlightShader(parent);
shader.setVertexShader(defPolyTexlightShaderVertURL);
} else if (shaderType == PShader.LIGHT) {
shader = new PolyLightShader(parent);
shader.setVertexShader(defPolyLightShaderVertURL);
} else if (shaderType == PShader.TEXTURE) {
shader = new PolyTexShader(parent);
shader.setVertexShader(defPolyTexShaderVertURL);
} else if (shaderType == PShader.COLOR) {
shader = new PolyColorShader(parent);
shader.setVertexShader(defPolyColorShaderVertURL);
}
if (shader == null){
PGraphics.showWarning(INVALID_PROCESSING_SHADER_ERROR);
} else {
shader.setFragmentShader(fragFilename);
}
shader.setFragmentShader(fragFilename);
return shader;
}
@Override
public PShader loadShader(String fragFilename, String vertFilename) {
int shaderType = getTypeFromVertexShader(vertFilename);
int shaderType = getShaderType(vertFilename);
if (shaderType == -1) {
shaderType = getShaderType(fragFilename);
}
if (shaderType == -1) {
PGraphics.showWarning(INVALID_PROCESSING_SHADER_ERROR);
return null;
}
PShader shader = null;
if (fragFilename == null || fragFilename.equals("")) {
if (shaderType == PShader.POINT) {
@@ -6190,9 +6205,6 @@ public class PGraphicsOpenGL extends PGraphics {
shader = new PolyColorShader(parent, vertFilename, fragFilename);
}
}
if (shader == null) {
PGraphics.showWarning(INVALID_PROCESSING_SHADER_ERROR);
}
return shader;
}
@@ -6267,60 +6279,28 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected int getTypeFromFragmentShader(String filename) {
protected int getShaderType(String filename) {
String[] source = parent.loadStrings(filename);
Pattern pattern = Pattern.compile("uniform *sampler2D *textureSampler");
int type = PShader.COLOR;
int type = -1;
for (int i = 0; i < source.length; i++) {
Matcher matcher = pattern.matcher(source[i]);
if (matcher.find()) {
if (source[i].equals("#define PROCESSING_POINT_SHADER")) {
type = PShader.POINT;
} else if (source[i].equals("#define PROCESSING_LINE_SHADER")) {
type = PShader.LINE;
} else if (source[i].equals("#define PROCESSING_COLOR_SHADER")) {
type = PShader.COLOR;
} else if (source[i].equals("#define PROCESSING_LIGHT_SHADER")) {
type = PShader.LIGHT;
} else if (source[i].equals("#define PROCESSING_TEXTURE_SHADER")) {
type = PShader.TEXTURE;
break;
} else if (source[i].equals("#define PROCESSING_TEXLIGHT_SHADER")) {
type = PShader.TEXLIGHT;
}
}
return type;
}
protected int getTypeFromVertexShader(String filename) {
String[] source = parent.loadStrings(filename);
Pattern pointPattern = Pattern.compile("attribute *vec2 *inPoint");
Pattern linePattern = Pattern.compile("attribute *vec4 *inLine");
Pattern lightPattern1 = Pattern.compile("uniform *vec4 *lightPosition");
Pattern lightPattern2 = Pattern.compile("uniform *vec3 *lightNormal");
Pattern texPattern = Pattern.compile("attribute vec2 inTexcoord");
boolean foundPoint = false;
boolean foundLine = false;
boolean foundLight = false;
boolean foundTex = false;
for (int i = 0; i < source.length; i++) {
foundPoint |= pointPattern.matcher(source[i]).find();
foundLine |= linePattern.matcher(source[i]).find();
foundLight |= lightPattern1.matcher(source[i]).find();
foundLight |= lightPattern2.matcher(source[i]).find();
foundTex |= texPattern.matcher(source[i]).find();
}
int type = PShader.COLOR;
if (foundPoint) {
type = PShader.POINT;
} else if (foundLine) {
type = PShader.LINE;
} else if (foundLight && foundTex) {
type = PShader.TEXLIGHT;
} else if (foundLight) {
type = PShader.LIGHT;
} else if (foundTex) {
type = PShader.TEXTURE;
}
return type;
}
protected void deleteDefaultShaders() {
// The default shaders contains references to the PGraphics object that
// creates them, so when restarting the renderer, those references should
@@ -6474,15 +6454,11 @@ public class PGraphicsOpenGL extends PGraphics {
protected class BaseShader extends PShader {
protected int projmodelviewMatrixLoc;
protected int modelviewMatrixLoc;
protected int projectionMatrixLoc;
protected int pframeSamplerLoc;
protected int resolutionLoc;
protected int transformLoc;
protected int modelviewLoc;
protected int projectionLoc;
protected int bufferLoc;
protected int viewportLoc;
protected int mouseLoc;
protected int pmouseLoc;
protected int timeLoc;
public BaseShader(PApplet parent) {
super(parent);
@@ -6498,22 +6474,16 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void loadUniforms() {
projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix");
modelviewMatrixLoc = getUniformLoc("modelviewMatrix");
projectionMatrixLoc = getUniformLoc("projectionMatrix");
resolutionLoc = getUniformLoc("resolution");
transformLoc = getUniformLoc("transform");
modelviewLoc = getUniformLoc("modelview");
projectionLoc = getUniformLoc("projection");
viewportLoc = getUniformLoc("viewport");
mouseLoc = getUniformLoc("mouse");
pmouseLoc = getUniformLoc("pmouse");
timeLoc = getUniformLoc("time");
pframeSamplerLoc = getUniformLoc("pframeSampler");
bufferLoc = getUniformLoc("buffer");
}
@Override
public void unbind() {
if (-1 < pframeSamplerLoc) {
if (-1 < bufferLoc) {
pgl.needFBOLayer();
pgl.activeTexture(PGL.TEXTURE0 + lastTexUnit);
pgCurrent.unbindBackTexture();
@@ -6526,25 +6496,19 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected void setCommonUniforms() {
if (-1 < projmodelviewMatrixLoc) {
if (-1 < transformLoc) {
pgCurrent.updateGLProjmodelview();
setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview);
setUniformMatrix(transformLoc, pgCurrent.glProjmodelview);
}
if (-1 < modelviewMatrixLoc) {
if (-1 < modelviewLoc) {
pgCurrent.updateGLModelview();
setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview);
setUniformMatrix(modelviewLoc, pgCurrent.glModelview);
}
if (-1 < projectionMatrixLoc) {
if (-1 < projectionLoc) {
pgCurrent.updateGLProjection();
setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection);
}
if (1 < resolutionLoc) {
float w = pgCurrent.width;
float h = pgCurrent.height;
setUniformValue(resolutionLoc, w, h);
setUniformMatrix(projectionLoc, pgCurrent.glProjection);
}
if (-1 < viewportLoc) {
@@ -6555,25 +6519,8 @@ public class PGraphicsOpenGL extends PGraphics {
setUniformValue(viewportLoc, x, y, w, h);
}
if (-1 < mouseLoc) {
float mx = pgCurrent.parent.mouseX;
float my = pgCurrent.parent.height - pgCurrent.parent.mouseY;
setUniformValue(mouseLoc, mx, my);
}
if (-1 < pmouseLoc) {
float pmx = pgCurrent.parent.pmouseX;
float pmy = pgCurrent.parent.height - pgCurrent.parent.pmouseY;
setUniformValue(pmouseLoc, pmx, pmy);
}
if (-1 < timeLoc) {
float sec = pgCurrent.parent.millis() / 1000.0f;
setUniformValue(timeLoc, sec);
}
if (-1 < pframeSamplerLoc) {
setUniformValue(pframeSamplerLoc, lastTexUnit);
if (-1 < bufferLoc) {
setUniformValue(bufferLoc, lastTexUnit);
pgl.activeTexture(PGL.TEXTURE0 + lastTexUnit);
pgCurrent.bindBackTexture();
}
@@ -6600,8 +6547,8 @@ public class PGraphicsOpenGL extends PGraphics {
protected class PolyColorShader extends BaseShader {
protected int inVertexLoc;
protected int inColorLoc;
protected int vertexLoc;
protected int colorLoc;
public PolyColorShader(PApplet parent) {
super(parent);
@@ -6618,8 +6565,8 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void loadAttributes() {
inVertexLoc = getAttributeLoc("inVertex");
inColorLoc = getAttributeLoc("inColor");
vertexLoc = getAttributeLoc("vertex");
colorLoc = getAttributeLoc("color");
}
@Override
@@ -6630,13 +6577,13 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void setVertexAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
}
@Override
public void setColorAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset);
setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
}
@Override
@@ -6648,16 +6595,16 @@ public class PGraphicsOpenGL extends PGraphics {
loadUniforms();
}
if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc);
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
setCommonUniforms();
}
@Override
public void unbind() {
if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc);
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
super.unbind();
}
@@ -6673,17 +6620,17 @@ public class PGraphicsOpenGL extends PGraphics {
protected int lightAmbientLoc;
protected int lightDiffuseLoc;
protected int lightSpecularLoc;
protected int lightFalloffCoefficientsLoc;
protected int lightSpotParametersLoc;
protected int lightFalloffLoc;
protected int lightSpotLoc;
protected int inVertexLoc;
protected int inColorLoc;
protected int inNormalLoc;
protected int vertexLoc;
protected int colorLoc;
protected int normalLoc;
protected int inAmbientLoc;
protected int inSpecularLoc;
protected int inEmissiveLoc;
protected int inShineLoc;
protected int ambientLoc;
protected int specularLoc;
protected int emissiveLoc;
protected int shininessLoc;
public PolyLightShader(PApplet parent) {
super(parent);
@@ -6700,14 +6647,14 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void loadAttributes() {
inVertexLoc = getAttributeLoc("inVertex");
inColorLoc = getAttributeLoc("inColor");
inNormalLoc = getAttributeLoc("inNormal");
vertexLoc = getAttributeLoc("vertex");
colorLoc = getAttributeLoc("color");
normalLoc = getAttributeLoc("normal");
inAmbientLoc = getAttributeLoc("inAmbient");
inSpecularLoc = getAttributeLoc("inSpecular");
inEmissiveLoc = getAttributeLoc("inEmissive");
inShineLoc = getAttributeLoc("inShine");
ambientLoc = getAttributeLoc("ambient");
specularLoc = getAttributeLoc("specular");
emissiveLoc = getAttributeLoc("emissive");
shininessLoc = getAttributeLoc("shininess");
}
@Override
@@ -6722,50 +6669,50 @@ public class PGraphicsOpenGL extends PGraphics {
lightAmbientLoc = getUniformLoc("lightAmbient");
lightDiffuseLoc = getUniformLoc("lightDiffuse");
lightSpecularLoc = getUniformLoc("lightSpecular");
lightFalloffCoefficientsLoc = getUniformLoc("lightFalloffCoefficients");
lightSpotParametersLoc = getUniformLoc("lightSpotParameters");
lightFalloffLoc = getUniformLoc("lightFalloff");
lightSpotLoc = getUniformLoc("lightSpot");
}
@Override
public void setVertexAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
}
@Override
public void setColorAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset);
setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
}
@Override
public void setNormalAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inNormalLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(normalLoc, vboId, size, type, false, stride, offset);
}
@Override
public void setAmbientAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inAmbientLoc, vboId, size, type, true, stride, offset);
setAttributeVBO(ambientLoc, vboId, size, type, true, stride, offset);
}
@Override
public void setSpecularAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inSpecularLoc, vboId, size, type, true, stride, offset);
setAttributeVBO(specularLoc, vboId, size, type, true, stride, offset);
}
@Override
public void setEmissiveAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inEmissiveLoc, vboId, size, type, true, stride, offset);
setAttributeVBO(emissiveLoc, vboId, size, type, true, stride, offset);
}
@Override
public void setShininessAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inShineLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(shininessLoc, vboId, size, type, false, stride, offset);
}
@Override
@@ -6777,14 +6724,14 @@ public class PGraphicsOpenGL extends PGraphics {
loadUniforms();
}
if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc);
if (-1 < inNormalLoc) pgl.enableVertexAttribArray(inNormalLoc);
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < normalLoc) pgl.enableVertexAttribArray(normalLoc);
if (-1 < inAmbientLoc) pgl.enableVertexAttribArray(inAmbientLoc);
if (-1 < inSpecularLoc) pgl.enableVertexAttribArray(inSpecularLoc);
if (-1 < inEmissiveLoc) pgl.enableVertexAttribArray(inEmissiveLoc);
if (-1 < inShineLoc) pgl.enableVertexAttribArray(inShineLoc);
if (-1 < ambientLoc) pgl.enableVertexAttribArray(ambientLoc);
if (-1 < specularLoc) pgl.enableVertexAttribArray(specularLoc);
if (-1 < emissiveLoc) pgl.enableVertexAttribArray(emissiveLoc);
if (-1 < shininessLoc) pgl.enableVertexAttribArray(shininessLoc);
if (-1 < normalMatrixLoc) {
pgCurrent.updateGLNormal();
@@ -6798,9 +6745,9 @@ public class PGraphicsOpenGL extends PGraphics {
setUniformVector(lightAmbientLoc, pgCurrent.lightAmbient, 3, count);
setUniformVector(lightDiffuseLoc, pgCurrent.lightDiffuse, 3, count);
setUniformVector(lightSpecularLoc, pgCurrent.lightSpecular, 3, count);
setUniformVector(lightFalloffCoefficientsLoc,
setUniformVector(lightFalloffLoc,
pgCurrent.lightFalloffCoefficients, 3, count);
setUniformVector(lightSpotParametersLoc,
setUniformVector(lightSpotLoc,
pgCurrent.lightSpotParameters, 2, count);
setCommonUniforms();
@@ -6808,14 +6755,14 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void unbind() {
if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc);
if (-1 < inNormalLoc) pgl.disableVertexAttribArray(inNormalLoc);
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < normalLoc) pgl.disableVertexAttribArray(normalLoc);
if (-1 < inAmbientLoc) pgl.disableVertexAttribArray(inAmbientLoc);
if (-1 < inSpecularLoc) pgl.disableVertexAttribArray(inSpecularLoc);
if (-1 < inEmissiveLoc) pgl.disableVertexAttribArray(inEmissiveLoc);
if (-1 < inShineLoc) pgl.disableVertexAttribArray(inShineLoc);
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();
}
@@ -6823,11 +6770,11 @@ public class PGraphicsOpenGL extends PGraphics {
protected class PolyTexShader extends PolyColorShader {
protected int inTexcoordLoc;
protected int texCoordLoc;
protected int textureSamplerLoc;
protected int texcoordMatrixLoc;
protected int texcoordOffsetLoc;
protected int textureLoc;
protected int texMatrixLoc;
protected int texOffsetLoc;
protected float[] tcmat;
@@ -6848,22 +6795,22 @@ public class PGraphicsOpenGL extends PGraphics {
public void loadUniforms() {
super.loadUniforms();
textureSamplerLoc = getUniformLoc("textureSampler");
texcoordMatrixLoc = getUniformLoc("texcoordMatrix");
texcoordOffsetLoc = getUniformLoc("texcoordOffset");
textureLoc = getUniformLoc("texture");
texMatrixLoc = getUniformLoc("texMatrix");
texOffsetLoc = getUniformLoc("texOffset");
}
@Override
public void loadAttributes() {
super.loadAttributes();
inTexcoordLoc = getAttributeLoc("inTexcoord");
texCoordLoc = getAttributeLoc("texCoord");
}
@Override
public void setTexcoordAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset);
}
@Override
@@ -6888,7 +6835,7 @@ public class PGraphicsOpenGL extends PGraphics {
scalev *= tex.maxTexcoordV();
dispv *= tex.maxTexcoordV();
if (-1 < texcoordMatrixLoc) {
if (-1 < texMatrixLoc) {
if (tcmat == null) {
tcmat = new float[16];
}
@@ -6896,12 +6843,12 @@ public class PGraphicsOpenGL extends PGraphics {
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(texcoordMatrixLoc, tcmat);
setUniformMatrix(texMatrixLoc, tcmat);
}
setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
setUniformValue(textureSamplerLoc, 0);
setUniformValue(textureLoc, 0);
}
@Override
@@ -6910,12 +6857,12 @@ public class PGraphicsOpenGL extends PGraphics {
super.bind();
if (-1 < inTexcoordLoc) pgl.enableVertexAttribArray(inTexcoordLoc);
if (-1 < texCoordLoc) pgl.enableVertexAttribArray(texCoordLoc);
}
@Override
public void unbind() {
if (-1 < inTexcoordLoc) pgl.disableVertexAttribArray(inTexcoordLoc);
if (-1 < texCoordLoc) pgl.disableVertexAttribArray(texCoordLoc);
super.unbind();
}
@@ -6923,11 +6870,11 @@ public class PGraphicsOpenGL extends PGraphics {
protected class PolyTexlightShader extends PolyLightShader {
protected int inTexcoordLoc;
protected int texCoordLoc;
protected int textureSamplerLoc;
protected int texcoordMatrixLoc;
protected int texcoordOffsetLoc;
protected int textureLoc;
protected int texMatrixLoc;
protected int texOffsetLoc;
protected float[] tcmat;
@@ -6948,22 +6895,22 @@ public class PGraphicsOpenGL extends PGraphics {
public void loadUniforms() {
super.loadUniforms();
textureSamplerLoc = getUniformLoc("textureSampler");
texcoordMatrixLoc = getUniformLoc("texcoordMatrix");
texcoordOffsetLoc = getUniformLoc("texcoordOffset");
textureLoc = getUniformLoc("texture");
texMatrixLoc = getUniformLoc("texMatrix");
texOffsetLoc = getUniformLoc("texOffset");
}
@Override
public void loadAttributes() {
super.loadAttributes();
inTexcoordLoc = getAttributeLoc("inTexcoord");
texCoordLoc = getAttributeLoc("texCoord");
}
@Override
public void setTexcoordAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset);
}
@Override
@@ -6988,7 +6935,7 @@ public class PGraphicsOpenGL extends PGraphics {
scalev *= tex.maxTexcoordV;
dispv *= tex.maxTexcoordV;
if (-1 < texcoordMatrixLoc) {
if (-1 < texMatrixLoc) {
if (tcmat == null) {
tcmat = new float[16];
}
@@ -6996,12 +6943,12 @@ public class PGraphicsOpenGL extends PGraphics {
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(texcoordMatrixLoc, tcmat);
setUniformMatrix(texMatrixLoc, tcmat);
}
setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
setUniformValue(textureSamplerLoc, 0);
setUniformValue(textureLoc, 0);
}
@Override
@@ -7010,12 +6957,12 @@ public class PGraphicsOpenGL extends PGraphics {
super.bind();
if (-1 < inTexcoordLoc) pgl.enableVertexAttribArray(inTexcoordLoc);
if (-1 < texCoordLoc) pgl.enableVertexAttribArray(texCoordLoc);
}
@Override
public void unbind() {
if (-1 < inTexcoordLoc) pgl.disableVertexAttribArray(inTexcoordLoc);
if (-1 < texCoordLoc) pgl.disableVertexAttribArray(texCoordLoc);
super.unbind();
}
@@ -7026,9 +6973,9 @@ public class PGraphicsOpenGL extends PGraphics {
protected int perspectiveLoc;
protected int scaleLoc;
protected int inVertexLoc;
protected int inColorLoc;
protected int inAttribLoc;
protected int vertexLoc;
protected int colorLoc;
protected int endpointLoc;
public LineShader(PApplet parent) {
super(parent);
@@ -7045,9 +6992,9 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void loadAttributes() {
inVertexLoc = getAttributeLoc("inVertex");
inColorLoc = getAttributeLoc("inColor");
inAttribLoc = getAttributeLoc("inLine");
vertexLoc = getAttributeLoc("vertex");
colorLoc = getAttributeLoc("color");
endpointLoc = getAttributeLoc("endpoint");
}
@Override
@@ -7062,18 +7009,18 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void setVertexAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
}
@Override
public void setColorAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset);
setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
}
public void setLineAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inAttribLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(endpointLoc, vboId, size, type, false, stride, offset);
}
@Override
@@ -7085,9 +7032,9 @@ public class PGraphicsOpenGL extends PGraphics {
loadUniforms();
}
if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc);
if (-1 < inAttribLoc) pgl.enableVertexAttribArray(inAttribLoc);
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < endpointLoc) pgl.enableVertexAttribArray(endpointLoc);
if (pgCurrent.getHint(ENABLE_STROKE_PERSPECTIVE) &&
pgCurrent.nonOrthoProjection()) {
@@ -7111,9 +7058,9 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void unbind() {
if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc);
if (-1 < inAttribLoc) pgl.disableVertexAttribArray(inAttribLoc);
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < endpointLoc) pgl.disableVertexAttribArray(endpointLoc);
super.unbind();
}
@@ -7123,9 +7070,9 @@ public class PGraphicsOpenGL extends PGraphics {
protected class PointShader extends BaseShader {
protected int perspectiveLoc;
protected int inVertexLoc;
protected int inColorLoc;
protected int inPointLoc;
protected int vertexLoc;
protected int colorLoc;
protected int offsetLoc;
public PointShader(PApplet parent) {
super(parent);
@@ -7142,9 +7089,9 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void loadAttributes() {
inVertexLoc = getAttributeLoc("inVertex");
inColorLoc = getAttributeLoc("inColor");
inPointLoc = getAttributeLoc("inPoint");
vertexLoc = getAttributeLoc("vertex");
colorLoc = getAttributeLoc("color");
offsetLoc = getAttributeLoc("offset");
}
@Override
@@ -7157,18 +7104,18 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void setVertexAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
}
@Override
public void setColorAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset);
setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
}
public void setPointAttribute(int vboId, int size, int type,
int stride, int offset) {
setAttributeVBO(inPointLoc, vboId, size, type, false, stride, offset);
setAttributeVBO(offsetLoc, vboId, size, type, false, stride, offset);
}
@Override
@@ -7180,9 +7127,9 @@ public class PGraphicsOpenGL extends PGraphics {
loadUniforms();
}
if (-1 < inVertexLoc) pgl.enableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.enableVertexAttribArray(inColorLoc);
if (-1 < inPointLoc) pgl.enableVertexAttribArray(inPointLoc);
if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
if (-1 < offsetLoc) pgl.enableVertexAttribArray(offsetLoc);
if (pgCurrent.getHint(ENABLE_STROKE_PERSPECTIVE) &&
pgCurrent.nonOrthoProjection()) {
@@ -7196,9 +7143,9 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void unbind() {
if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc);
if (-1 < inPointLoc) pgl.disableVertexAttribArray(inPointLoc);
if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
if (-1 < offsetLoc) pgl.disableVertexAttribArray(offsetLoc);
super.unbind();
}
+14 -14
View File
@@ -58,7 +58,7 @@ public class PShader {
protected PGraphicsOpenGL pgCurrent;
protected PGL pgl;
protected PGL.Context context; // The context that created this shader.
protected int context; // The context that created this shader.
public int glProgram;
public int glVertex;
@@ -89,7 +89,7 @@ public class PShader {
parent = null;
pgMain = null;
pgl = null;
context = null;
context = -1;
this.vertexURL = null;
this.fragmentURL = null;
@@ -172,13 +172,13 @@ public class PShader {
protected void finalize() throws Throwable {
try {
if (glVertex != 0) {
pgMain.finalizeGLSLVertShaderObject(glVertex, context.id());
pgMain.finalizeGLSLVertShaderObject(glVertex, context);
}
if (glFragment != 0) {
pgMain.finalizeGLSLFragShaderObject(glFragment, context.id());
pgMain.finalizeGLSLFragShaderObject(glFragment, context);
}
if (glProgram != 0) {
pgMain.finalizeGLSLProgramObject(glProgram, context.id());
pgMain.finalizeGLSLProgramObject(glProgram, context);
}
} finally {
super.finalize();
@@ -698,7 +698,7 @@ public class PShader {
protected void init() {
if (glProgram == 0 || contextIsOutdated()) {
context = pgl.getCurrentContext();
glProgram = pgMain.createGLSLProgramObject(context.id());
glProgram = pgMain.createGLSLProgramObject(context);
boolean hasVert = false;
if (vertexFilename != null) {
@@ -761,9 +761,9 @@ public class PShader {
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
pgMain.removeGLSLProgramObject(glProgram, context.id());
pgMain.removeGLSLVertShaderObject(glVertex, context.id());
pgMain.removeGLSLFragShaderObject(glFragment, context.id());
pgMain.removeGLSLProgramObject(glProgram, context);
pgMain.removeGLSLVertShaderObject(glVertex, context);
pgMain.removeGLSLFragShaderObject(glFragment, context);
glProgram = 0;
glVertex = 0;
@@ -833,7 +833,7 @@ public class PShader {
* @param shaderSource a string containing the shader's code
*/
protected boolean compileVertexShader() {
glVertex = pgMain.createGLSLVertShaderObject(context.id());
glVertex = pgMain.createGLSLVertShaderObject(context);
pgl.shaderSource(glVertex, vertexShaderSource);
pgl.compileShader(glVertex);
@@ -854,7 +854,7 @@ public class PShader {
* @param shaderSource a string containing the shader's code
*/
protected boolean compileFragmentShader() {
glFragment = pgMain.createGLSLFragShaderObject(context.id());
glFragment = pgMain.createGLSLFragShaderObject(context);
pgl.shaderSource(glFragment, fragmentShaderSource);
pgl.compileShader(glFragment);
@@ -883,15 +883,15 @@ public class PShader {
protected void release() {
if (glVertex != 0) {
pgMain.deleteGLSLVertShaderObject(glVertex, context.id());
pgMain.deleteGLSLVertShaderObject(glVertex, context);
glVertex = 0;
}
if (glFragment != 0) {
pgMain.deleteGLSLFragShaderObject(glFragment, context.id());
pgMain.deleteGLSLFragShaderObject(glFragment, context);
glFragment = 0;
}
if (glProgram != 0) {
pgMain.deleteGLSLProgramObject(glProgram, context.id());
pgMain.deleteGLSLProgramObject(glProgram, context);
glProgram = 0;
}
}
File diff suppressed because it is too large Load Diff
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,15 +18,17 @@
Boston, MA 02111-1307 USA
*/
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
#define PROCESSING_POINT_SHADER
uniform mat4 projection;
uniform mat4 modelview;
uniform vec4 viewport;
uniform int perspective;
attribute vec4 inVertex;
attribute vec4 inColor;
attribute vec2 inPoint;
attribute vec4 vertex;
attribute vec4 color;
attribute vec2 offset;
varying vec4 vertColor;
@@ -36,18 +38,18 @@ vec4 windowToClipVector(vec2 window, vec4 viewport, float clip_w) {
}
void main() {
vec4 pos = modelviewMatrix * inVertex;
vec4 clip = projectionMatrix * pos;
vec4 pos = modelview * vertex;
vec4 clip = projection * pos;
if (0 < perspective) {
// Perspective correction (points will look thiner as they move away
// from the view position).
gl_Position = clip + projectionMatrix * vec4(inPoint.xy, 0, 0);
gl_Position = clip + projection * vec4(offset.xy, 0, 0);
} else {
// No perspective correction.
vec4 offset = windowToClipVector(inPoint.xy, viewport, clip.w);
vec4 offset = windowToClipVector(offset.xy, viewport, clip.w);
gl_Position = clip + offset;
}
vertColor = inColor;
vertColor = color;
}
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,15 +18,17 @@
Boston, MA 02111-1307 USA
*/
uniform mat4 projmodelviewMatrix;
#define PROCESSING_COLOR_SHADER
attribute vec4 inVertex;
attribute vec4 inColor;
uniform mat4 transform;
attribute vec4 vertex;
attribute vec4 color;
varying vec4 vertColor;
void main() {
gl_Position = projmodelviewMatrix * inVertex;
gl_Position = transform * vertex;
vertColor = inColor;
vertColor = color;
}
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,8 +18,10 @@
Boston, MA 02111-1307 USA
*/
uniform mat4 modelviewMatrix;
uniform mat4 projmodelviewMatrix;
#define PROCESSING_LIGHT_SHADER
uniform mat4 modelview;
uniform mat4 transform;
uniform mat3 normalMatrix;
uniform int lightCount;
@@ -28,17 +30,17 @@ uniform vec3 lightNormal[8];
uniform vec3 lightAmbient[8];
uniform vec3 lightDiffuse[8];
uniform vec3 lightSpecular[8];
uniform vec3 lightFalloffCoefficients[8];
uniform vec2 lightSpotParameters[8];
uniform vec3 lightFalloff[8];
uniform vec2 lightSpot[8];
attribute vec4 inVertex;
attribute vec4 inColor;
attribute vec3 inNormal;
attribute vec4 vertex;
attribute vec4 color;
attribute vec3 normal;
attribute vec4 inAmbient;
attribute vec4 inSpecular;
attribute vec4 inEmissive;
attribute float inShine;
attribute vec4 ambient;
attribute vec4 specular;
attribute vec4 emissive;
attribute float shininess;
varying vec4 vertColor;
@@ -73,13 +75,13 @@ float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine)
void main() {
// Vertex in clip coordinates
gl_Position = projmodelviewMatrix * inVertex;
gl_Position = transform * vertex;
// Vertex in eye coordinates
vec3 ecVertex = vec3(modelviewMatrix * inVertex);
vec3 ecVertex = vec3(modelview * vertex);
// Normal vector in eye coordinates
vec3 ecNormal = normalize(normalMatrix * inNormal);
vec3 ecNormal = normalize(normalMatrix * normal);
if (dot(-one_float * ecVertex, ecNormal) < zero_float) {
// If normal is away from camera, choose its opposite.
@@ -96,8 +98,8 @@ void main() {
vec3 lightPos = lightPosition[i].xyz;
bool isDir = zero_float < lightPosition[i].w;
float spotCos = lightSpotParameters[i].x;
float spotExp = lightSpotParameters[i].y;
float spotCos = lightSpot[i].x;
float spotExp = lightSpot[i].y;
vec3 lightDir;
float falloff;
@@ -107,7 +109,7 @@ void main() {
falloff = one_float;
lightDir = -one_float * lightNormal[i];
} else {
falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]);
falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
lightDir = normalize(lightPos - ecVertex);
}
@@ -126,14 +128,14 @@ void main() {
if (any(greaterThan(lightSpecular[i], zero_vec3))) {
totalSpecular += lightSpecular[i] * falloff * spotf *
blinnPhongFactor(lightDir, ecVertex, ecNormal, inShine);
blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
}
}
// Calculating final color as result of all lights (plus emissive term).
// Transparency is determined exclusively by the diffuse component.
vertColor = vec4(totalAmbient, 0) * inAmbient +
vec4(totalDiffuse, 1) * inColor +
vec4(totalSpecular, 0) * inSpecular +
vec4(inEmissive.rgb, 0);
vertColor = vec4(totalAmbient, 0) * ambient +
vec4(totalDiffuse, 1) * color +
vec4(totalSpecular, 0) * specular +
vec4(emissive.rgb, 0);
}
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -23,13 +23,13 @@ precision mediump float;
precision mediump int;
#endif
uniform sampler2D textureSampler;
uniform sampler2D texture;
uniform vec2 texcoordOffset;
uniform vec2 texOffset;
varying vec4 vertColor;
varying vec4 vertTexcoord;
varying vec4 vertTexCoord;
void main() {
gl_FragColor = texture2D(textureSampler, vertTexcoord.st) * vertColor;
gl_FragColor = texture2D(texture, vertTexCoord.st) * vertColor;
}
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,19 +18,21 @@
Boston, MA 02111-1307 USA
*/
uniform mat4 projmodelviewMatrix;
uniform mat4 texcoordMatrix;
#define PROCESSING_TEXTURE_SHADER
attribute vec4 inVertex;
attribute vec4 inColor;
attribute vec2 inTexcoord;
uniform mat4 transform;
uniform mat4 texMatrix;
attribute vec4 vertex;
attribute vec4 color;
attribute vec2 texCoord;
varying vec4 vertColor;
varying vec4 vertTexcoord;
varying vec4 vertTexCoord;
void main() {
gl_Position = projmodelviewMatrix * inVertex;
gl_Position = transform * vertex;
vertColor = inColor;
vertTexcoord = texcoordMatrix * vec4(inTexcoord, 1.0, 1.0);
vertColor = color;
vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
}
@@ -1,7 +1,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011-12 Ben Fry and Casey Reas
Copyright (c) 2011-13 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,10 +18,12 @@
Boston, MA 02111-1307 USA
*/
uniform mat4 modelviewMatrix;
uniform mat4 projmodelviewMatrix;
#define PROCESSING_TEXLIGHT_SHADER
uniform mat4 modelview;
uniform mat4 transform;
uniform mat3 normalMatrix;
uniform mat4 texcoordMatrix;
uniform mat4 texMatrix;
uniform int lightCount;
uniform vec4 lightPosition[8];
@@ -29,21 +31,21 @@ uniform vec3 lightNormal[8];
uniform vec3 lightAmbient[8];
uniform vec3 lightDiffuse[8];
uniform vec3 lightSpecular[8];
uniform vec3 lightFalloffCoefficients[8];
uniform vec2 lightSpotParameters[8];
uniform vec3 lightFalloff[8];
uniform vec2 lightSpot[8];
attribute vec4 inVertex;
attribute vec4 inColor;
attribute vec3 inNormal;
attribute vec2 inTexcoord;
attribute vec4 vertex;
attribute vec4 color;
attribute vec3 normal;
attribute vec2 texCoord;
attribute vec4 inAmbient;
attribute vec4 inSpecular;
attribute vec4 inEmissive;
attribute float inShine;
attribute vec4 ambient;
attribute vec4 specular;
attribute vec4 emissive;
attribute float shininess;
varying vec4 vertColor;
varying vec4 vertTexcoord;
varying vec4 vertTexCoord;
const float zero_float = 0.0;
const float one_float = 1.0;
@@ -76,13 +78,13 @@ float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine)
void main() {
// Vertex in clip coordinates
gl_Position = projmodelviewMatrix * inVertex;
gl_Position = transform * vertex;
// Vertex in eye coordinates
vec3 ecVertex = vec3(modelviewMatrix * inVertex);
vec3 ecVertex = vec3(modelview * vertex);
// Normal vector in eye coordinates
vec3 ecNormal = normalize(normalMatrix * inNormal);
vec3 ecNormal = normalize(normalMatrix * normal);
if (dot(-one_float * ecVertex, ecNormal) < zero_float) {
// If normal is away from camera, choose its opposite.
@@ -99,8 +101,8 @@ void main() {
vec3 lightPos = lightPosition[i].xyz;
bool isDir = zero_float < lightPosition[i].w;
float spotCos = lightSpotParameters[i].x;
float spotExp = lightSpotParameters[i].y;
float spotCos = lightSpot[i].x;
float spotExp = lightSpot[i].y;
vec3 lightDir;
float falloff;
@@ -110,7 +112,7 @@ void main() {
falloff = one_float;
lightDir = -one_float * lightNormal[i];
} else {
falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]);
falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
lightDir = normalize(lightPos - ecVertex);
}
@@ -129,17 +131,17 @@ void main() {
if (any(greaterThan(lightSpecular[i], zero_vec3))) {
totalSpecular += lightSpecular[i] * falloff * spotf *
blinnPhongFactor(lightDir, ecVertex, ecNormal, inShine);
blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
}
}
// Calculating final color as result of all lights (plus emissive term).
// Transparency is determined exclusively by the diffuse component.
vertColor = vec4(totalAmbient, 0) * inAmbient +
vec4(totalDiffuse, 1) * inColor +
vec4(totalSpecular, 0) * inSpecular +
vec4(inEmissive.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
vertTexcoord = texcoordMatrix * vec4(inTexcoord, 1.0, 1.0);
vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
}
@@ -78,10 +78,10 @@ public class Texture implements PConstants {
public int glWidth;
public int glHeight;
protected PApplet parent; // The Processing applet
protected PGraphicsOpenGL pg; // The main renderer
protected PGL pgl; // The interface between Processing and OpenGL.
protected PGL.Context context; // The context that created this texture.
protected PApplet parent; // The Processing applet
protected PGraphicsOpenGL pg; // The main renderer
protected PGL pgl; // The interface between Processing and OpenGL.
protected int context; // The context that created this texture.
protected PGraphicsOpenGL pgDraw; // The main renderer is the color buffer of.
protected boolean usingMipmaps;
@@ -162,7 +162,7 @@ public class Texture implements PConstants {
protected void finalize() throws Throwable {
try {
if (glName != 0) {
pg.finalizeTextureObject(glName, context.id());
pg.finalizeTextureObject(glName, context);
}
} finally {
super.finalize();
@@ -1193,7 +1193,7 @@ public class Texture implements PConstants {
}
context = pgl.getCurrentContext();
glName = pg.createTextureObject(context.id());
glName = pg.createTextureObject(context);
pgl.bindTexture(glTarget, glName);
pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter);
@@ -1228,7 +1228,7 @@ public class Texture implements PConstants {
*/
protected void release() {
if (glName != 0) {
pg.finalizeTextureObject(glName, context.id());
pg.finalizeTextureObject(glName, context);
glName = 0;
}
}
@@ -1240,7 +1240,7 @@ public class Texture implements PConstants {
// Removing the texture object from the renderer's list so it
// doesn't get deleted by OpenGL. The texture object was
// automatically disposed when the old context was destroyed.
pg.removeTextureObject(glName, context.id());
pg.removeTextureObject(glName, context);
// And then set the id to zero, so it doesn't try to be
// deleted when the object's finalizer is invoked by the GC.