making pgl non-static member of PGraphicsOpenGL

This commit is contained in:
codeanticode
2014-01-19 01:56:55 -05:00
parent 376bbb1938
commit a8a15d112e
6 changed files with 154 additions and 151 deletions

View File

@@ -63,11 +63,11 @@ class FontTexture implements PConstants {
protected TextureInfo[] glyphTexinfos;
protected HashMap<PFont.Glyph, TextureInfo> texinfoMap;
public FontTexture(PGraphicsOpenGL pg, PFont font, boolean is3D) {
pgl = PGraphicsOpenGL.pgl;
public FontTexture(PFont font, boolean is3D) {
pgl = PGraphicsOpenGL.pgPrimary.pgl;
this.is3D = is3D;
initTexture(pg, font);
initTexture(PGraphicsOpenGL.pgPrimary, font);
}

View File

@@ -68,14 +68,14 @@ public class FrameBuffer implements PConstants {
FrameBuffer() {
pgl = PGraphicsOpenGL.pgl;
pgl = PGraphicsOpenGL.pgPrimary.pgl;
context = pgl.createEmptyContext();
}
FrameBuffer(int w, int h, int samples, int colorBuffers,
int depthBits, int stencilBits, boolean packedDepthStencil,
boolean screen) {
int depthBits, int stencilBits, boolean packedDepthStencil,
boolean screen) {
this();
glFbo = 0;
@@ -141,7 +141,7 @@ public class FrameBuffer implements PConstants {
}
FrameBuffer(int w, int h, boolean screen) {
FrameBuffer(PGraphicsOpenGL pg, int w, int h, boolean screen) {
this(w, h, 1, 1, 0, 0, false, screen);
}
@@ -345,7 +345,7 @@ public class FrameBuffer implements PConstants {
glFbo = 0;
} else {
//create the FBO object...
glFbo = PGraphicsOpenGL.createFrameBufferObject(context);
glFbo = PGraphicsOpenGL.createFrameBufferObject(context, pgl);
// ... and then create the rest of the stuff.
if (multisample) {
@@ -423,7 +423,7 @@ public class FrameBuffer implements PConstants {
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
glMultisample = PGraphicsOpenGL.createRenderBufferObject(context);
glMultisample = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
PGL.RGBA8, width, height);
@@ -444,7 +444,7 @@ public class FrameBuffer implements PConstants {
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context);
glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
if (multisample) {
@@ -474,7 +474,7 @@ public class FrameBuffer implements PConstants {
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
glDepth = PGraphicsOpenGL.createRenderBufferObject(context);
glDepth = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
int glConst = PGL.DEPTH_COMPONENT16;
@@ -510,7 +510,7 @@ public class FrameBuffer implements PConstants {
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
glStencil = PGraphicsOpenGL.createRenderBufferObject(context);
glStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
int glConst = PGL.STENCIL_INDEX1;

View File

@@ -34,7 +34,7 @@ import java.util.*;
*/
public class PGraphicsOpenGL extends PGraphics {
/** Interface between Processing and OpenGL */
public static PGL pgl;
public PGL pgl;
/** The main PApplet renderer. */
protected static PGraphicsOpenGL pgPrimary = null;
@@ -520,9 +520,7 @@ public class PGraphicsOpenGL extends PGraphics {
public PGraphicsOpenGL() {
if (pgl == null) {
pgl = createPGL(this);
}
pgl = createPGL(this);
if (tessellator == null) {
tessellator = new Tessellator();
@@ -647,7 +645,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
deleteFinalizedGLResources();
deleteFinalizedGLResources(pgl);
if (primarySurface) {
pgl.deleteSurface();
@@ -656,7 +654,7 @@ public class PGraphicsOpenGL extends PGraphics {
// This is important in the context of, say, a unit test suite, which
// runs more than one OpenGL sketch within the same classloader
// (as in the case of processing.py). Please don't remove it!
pgl = null;
//pgl = null;
}
}
@@ -738,8 +736,8 @@ public class PGraphicsOpenGL extends PGraphics {
// Texture Objects -----------------------------------------------------------
protected static int createTextureObject(int context) {
deleteFinalizedTextureObjects();
protected static int createTextureObject(int context, PGL pgl) {
deleteFinalizedTextureObjects(pgl);
pgl.genTextures(1, intBuffer);
int id = intBuffer.get(0);
@@ -752,7 +750,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected static void deleteTextureObject(int id, int context) {
protected static void deleteTextureObject(int id, int context, PGL pgl) {
GLResource res = new GLResource(id, context);
if (glTextureObjects.containsKey(res)) {
intBuffer.put(0, id);
@@ -761,7 +759,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteAllTextureObjects() {
protected static void deleteAllTextureObjects(PGL pgl) {
for (GLResource res : glTextureObjects.keySet()) {
intBuffer.put(0, res.id);
if (pgl.threadIsCurrent()) pgl.deleteTextures(1, intBuffer);
@@ -777,7 +775,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteFinalizedTextureObjects() {
protected static void deleteFinalizedTextureObjects(PGL pgl) {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glTextureObjects.keySet()) {
@@ -802,8 +800,8 @@ public class PGraphicsOpenGL extends PGraphics {
// Vertex Buffer Objects -----------------------------------------------------
protected static int createVertexBufferObject(int context) {
deleteFinalizedVertexBufferObjects();
protected static int createVertexBufferObject(int context, PGL pgl) {
deleteFinalizedVertexBufferObjects(pgl);
pgl.genBuffers(1, intBuffer);
int id = intBuffer.get(0);
@@ -816,7 +814,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected static void deleteVertexBufferObject(int id, int context) {
protected static void deleteVertexBufferObject(int id, int context, PGL pgl) {
GLResource res = new GLResource(id, context);
if (glVertexBuffers.containsKey(res)) {
intBuffer.put(0, id);
@@ -825,7 +823,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteAllVertexBufferObjects() {
protected static void deleteAllVertexBufferObjects(PGL pgl) {
for (GLResource res : glVertexBuffers.keySet()) {
intBuffer.put(0, res.id);
if (pgl.threadIsCurrent()) pgl.deleteBuffers(1, intBuffer);
@@ -841,7 +839,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteFinalizedVertexBufferObjects() {
protected static void deleteFinalizedVertexBufferObjects(PGL pgl) {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glVertexBuffers.keySet()) {
@@ -866,8 +864,8 @@ public class PGraphicsOpenGL extends PGraphics {
// FrameBuffer Objects -------------------------------------------------------
protected static int createFrameBufferObject(int context) {
deleteFinalizedFrameBufferObjects();
protected static int createFrameBufferObject(int context, PGL pgl) {
deleteFinalizedFrameBufferObjects(pgl);
pgl.genFramebuffers(1, intBuffer);
int id = intBuffer.get(0);
@@ -880,7 +878,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected static void deleteFrameBufferObject(int id, int context) {
protected static void deleteFrameBufferObject(int id, int context, PGL pgl) {
GLResource res = new GLResource(id, context);
if (glFrameBuffers.containsKey(res)) {
intBuffer.put(0, id);
@@ -889,7 +887,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteAllFrameBufferObjects() {
protected static void deleteAllFrameBufferObjects(PGL pgl) {
for (GLResource res : glFrameBuffers.keySet()) {
intBuffer.put(0, res.id);
if (pgl.threadIsCurrent()) pgl.deleteFramebuffers(1, intBuffer);
@@ -905,7 +903,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteFinalizedFrameBufferObjects() {
protected static void deleteFinalizedFrameBufferObjects(PGL pgl) {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glFrameBuffers.keySet()) {
@@ -932,8 +930,8 @@ public class PGraphicsOpenGL extends PGraphics {
// RenderBuffer Objects ------------------------------------------------------
protected static int createRenderBufferObject(int context) {
deleteFinalizedRenderBufferObjects();
protected static int createRenderBufferObject(int context, PGL pgl) {
deleteFinalizedRenderBufferObjects(pgl);
pgl.genRenderbuffers(1, intBuffer);
int id = intBuffer.get(0);
@@ -946,7 +944,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected static void deleteRenderBufferObject(int id, int context) {
protected static void deleteRenderBufferObject(int id, int context, PGL pgl) {
GLResource res = new GLResource(id, context);
if (glRenderBuffers.containsKey(res)) {
intBuffer.put(0, id);
@@ -955,7 +953,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteAllRenderBufferObjects() {
protected static void deleteAllRenderBufferObjects(PGL pgl) {
for (GLResource res : glRenderBuffers.keySet()) {
intBuffer.put(0, res.id);
if (pgl.threadIsCurrent()) pgl.deleteRenderbuffers(1, intBuffer);
@@ -971,7 +969,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteFinalizedRenderBufferObjects() {
protected static void deleteFinalizedRenderBufferObjects(PGL pgl) {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glRenderBuffers.keySet()) {
@@ -996,8 +994,8 @@ public class PGraphicsOpenGL extends PGraphics {
// GLSL Program Objects ------------------------------------------------------
protected static int createGLSLProgramObject(int context) {
deleteFinalizedGLSLProgramObjects();
protected static int createGLSLProgramObject(int context, PGL pgl) {
deleteFinalizedGLSLProgramObjects(pgl);
int id = pgl.createProgram();
@@ -1009,7 +1007,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected static void deleteGLSLProgramObject(int id, int context) {
protected static void deleteGLSLProgramObject(int id, int context, PGL pgl) {
GLResource res = new GLResource(id, context);
if (glslPrograms.containsKey(res)) {
if (pgl.threadIsCurrent()) pgl.deleteProgram(res.id);
@@ -1017,7 +1015,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteAllGLSLProgramObjects() {
protected static void deleteAllGLSLProgramObjects(PGL pgl) {
for (GLResource res : glslPrograms.keySet()) {
if (pgl.threadIsCurrent()) pgl.deleteProgram(res.id);
}
@@ -1032,7 +1030,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteFinalizedGLSLProgramObjects() {
protected static void deleteFinalizedGLSLProgramObjects(PGL pgl) {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glslPrograms.keySet()) {
@@ -1056,8 +1054,8 @@ public class PGraphicsOpenGL extends PGraphics {
// GLSL Vertex Shader Objects ------------------------------------------------
protected static int createGLSLVertShaderObject(int context) {
deleteFinalizedGLSLVertShaderObjects();
protected static int createGLSLVertShaderObject(int context, PGL pgl) {
deleteFinalizedGLSLVertShaderObjects(pgl);
int id = pgl.createShader(PGL.VERTEX_SHADER);
@@ -1069,7 +1067,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected static void deleteGLSLVertShaderObject(int id, int context) {
protected static void deleteGLSLVertShaderObject(int id, int context, PGL pgl) {
GLResource res = new GLResource(id, context);
if (glslVertexShaders.containsKey(res)) {
if (pgl.threadIsCurrent()) pgl.deleteShader(res.id);
@@ -1077,7 +1075,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteAllGLSLVertShaderObjects() {
protected static void deleteAllGLSLVertShaderObjects(PGL pgl) {
for (GLResource res : glslVertexShaders.keySet()) {
if (pgl.threadIsCurrent()) pgl.deleteShader(res.id);
}
@@ -1093,7 +1091,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteFinalizedGLSLVertShaderObjects() {
protected static void deleteFinalizedGLSLVertShaderObjects(PGL pgl) {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glslVertexShaders.keySet()) {
@@ -1117,8 +1115,8 @@ public class PGraphicsOpenGL extends PGraphics {
// GLSL Fragment Shader Objects ----------------------------------------------
protected static int createGLSLFragShaderObject(int context) {
deleteFinalizedGLSLFragShaderObjects();
protected static int createGLSLFragShaderObject(int context, PGL pgl) {
deleteFinalizedGLSLFragShaderObjects(pgl);
int id = pgl.createShader(PGL.FRAGMENT_SHADER);
@@ -1130,7 +1128,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected static void deleteGLSLFragShaderObject(int id, int context) {
protected static void deleteGLSLFragShaderObject(int id, int context, PGL pgl) {
GLResource res = new GLResource(id, context);
if (glslFragmentShaders.containsKey(res)) {
if (pgl.threadIsCurrent()) pgl.deleteShader(res.id);
@@ -1138,7 +1136,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteAllGLSLFragShaderObjects() {
protected static void deleteAllGLSLFragShaderObjects(PGL pgl) {
for (GLResource res : glslFragmentShaders.keySet()) {
if (pgl.threadIsCurrent()) pgl.deleteShader(res.id);
}
@@ -1154,7 +1152,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected static void deleteFinalizedGLSLFragShaderObjects() {
protected static void deleteFinalizedGLSLFragShaderObjects(PGL pgl) {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glslFragmentShaders.keySet()) {
@@ -1178,14 +1176,14 @@ public class PGraphicsOpenGL extends PGraphics {
// All OpenGL resources ------------------------------------------------------
protected static void deleteFinalizedGLResources() {
deleteFinalizedTextureObjects();
deleteFinalizedVertexBufferObjects();
deleteFinalizedFrameBufferObjects();
deleteFinalizedRenderBufferObjects();
deleteFinalizedGLSLProgramObjects();
deleteFinalizedGLSLVertShaderObjects();
deleteFinalizedGLSLFragShaderObjects();
protected static void deleteFinalizedGLResources(PGL pgl) {
deleteFinalizedTextureObjects(pgl);
deleteFinalizedVertexBufferObjects(pgl);
deleteFinalizedFrameBufferObjects(pgl);
deleteFinalizedRenderBufferObjects(pgl);
deleteFinalizedGLSLProgramObjects(pgl);
deleteFinalizedGLSLVertShaderObjects(pgl);
deleteFinalizedGLSLFragShaderObjects(pgl);
}
@@ -1238,41 +1236,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);
glPolyVertex = createVertexBufferObject(polyBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
glPolyColor = createVertexBufferObject(polyBuffersContext);
glPolyColor = createVertexBufferObject(polyBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolyNormal = createVertexBufferObject(polyBuffersContext);
glPolyNormal = createVertexBufferObject(polyBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
glPolyTexcoord = createVertexBufferObject(polyBuffersContext);
glPolyTexcoord = createVertexBufferObject(polyBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, null, PGL.STATIC_DRAW);
glPolyAmbient = createVertexBufferObject(polyBuffersContext);
glPolyAmbient = createVertexBufferObject(polyBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolySpecular = createVertexBufferObject(polyBuffersContext);
glPolySpecular = createVertexBufferObject(polyBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolyEmissive = createVertexBufferObject(polyBuffersContext);
glPolyEmissive = createVertexBufferObject(polyBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolyShininess = createVertexBufferObject(polyBuffersContext);
glPolyShininess = createVertexBufferObject(polyBuffersContext, pgl);
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);
glPolyIndex = createVertexBufferObject(polyBuffersContext, pgl);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW);
@@ -1357,31 +1355,31 @@ public class PGraphicsOpenGL extends PGraphics {
protected void deletePolyBuffers() {
if (polyBuffersCreated) {
deleteVertexBufferObject(glPolyVertex, polyBuffersContext);
deleteVertexBufferObject(glPolyVertex, polyBuffersContext, pgl);
glPolyVertex = 0;
deleteVertexBufferObject(glPolyColor, polyBuffersContext);
deleteVertexBufferObject(glPolyColor, polyBuffersContext, pgl);
glPolyColor = 0;
deleteVertexBufferObject(glPolyNormal, polyBuffersContext);
deleteVertexBufferObject(glPolyNormal, polyBuffersContext, pgl);
glPolyNormal = 0;
deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext);
deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext, pgl);
glPolyTexcoord = 0;
deleteVertexBufferObject(glPolyAmbient, polyBuffersContext);
deleteVertexBufferObject(glPolyAmbient, polyBuffersContext, pgl);
glPolyAmbient = 0;
deleteVertexBufferObject(glPolySpecular, polyBuffersContext);
deleteVertexBufferObject(glPolySpecular, polyBuffersContext, pgl);
glPolySpecular = 0;
deleteVertexBufferObject(glPolyEmissive, polyBuffersContext);
deleteVertexBufferObject(glPolyEmissive, polyBuffersContext, pgl);
glPolyEmissive = 0;
deleteVertexBufferObject(glPolyShininess, polyBuffersContext);
deleteVertexBufferObject(glPolyShininess, polyBuffersContext, pgl);
glPolyShininess = 0;
deleteVertexBufferObject(glPolyIndex, polyBuffersContext);
deleteVertexBufferObject(glPolyIndex, polyBuffersContext, pgl);
glPolyIndex = 0;
polyBuffersCreated = false;
@@ -1397,22 +1395,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);
glLineVertex = createVertexBufferObject(lineBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
glLineColor = createVertexBufferObject(lineBuffersContext);
glLineColor = createVertexBufferObject(lineBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glLineAttrib = createVertexBufferObject(lineBuffersContext);
glLineAttrib = createVertexBufferObject(lineBuffersContext, pgl);
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);
glLineIndex = createVertexBufferObject(lineBuffersContext, pgl);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW);
@@ -1466,16 +1464,16 @@ public class PGraphicsOpenGL extends PGraphics {
protected void deleteLineBuffers() {
if (lineBuffersCreated) {
deleteVertexBufferObject(glLineVertex, lineBuffersContext);
deleteVertexBufferObject(glLineVertex, lineBuffersContext, pgl);
glLineVertex = 0;
deleteVertexBufferObject(glLineColor, lineBuffersContext);
deleteVertexBufferObject(glLineColor, lineBuffersContext, pgl);
glLineColor = 0;
deleteVertexBufferObject(glLineAttrib, lineBuffersContext);
deleteVertexBufferObject(glLineAttrib, lineBuffersContext, pgl);
glLineAttrib = 0;
deleteVertexBufferObject(glLineIndex, lineBuffersContext);
deleteVertexBufferObject(glLineIndex, lineBuffersContext, pgl);
glLineIndex = 0;
lineBuffersCreated = false;
@@ -1491,21 +1489,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);
glPointVertex = createVertexBufferObject(pointBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW);
glPointColor = createVertexBufferObject(pointBuffersContext);
glPointColor = createVertexBufferObject(pointBuffersContext, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPointAttrib = createVertexBufferObject(pointBuffersContext);
glPointAttrib = createVertexBufferObject(pointBuffersContext, pgl);
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);
glPointIndex = createVertexBufferObject(pointBuffersContext, pgl);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW);
@@ -1559,16 +1557,16 @@ public class PGraphicsOpenGL extends PGraphics {
protected void deletePointBuffers() {
if (pointBuffersCreated) {
deleteVertexBufferObject(glPointVertex, pointBuffersContext);
deleteVertexBufferObject(glPointVertex, pointBuffersContext, pgl);
glPointVertex = 0;
deleteVertexBufferObject(glPointColor, pointBuffersContext);
deleteVertexBufferObject(glPointColor, pointBuffersContext, pgl);
glPointColor = 0;
deleteVertexBufferObject(glPointAttrib, pointBuffersContext);
deleteVertexBufferObject(glPointAttrib, pointBuffersContext, pgl);
glPointAttrib = 0;
deleteVertexBufferObject(glPointIndex, pointBuffersContext);
deleteVertexBufferObject(glPointIndex, pointBuffersContext, pgl);
glPointIndex = 0;
pointBuffersCreated = false;
@@ -3510,7 +3508,7 @@ public class PGraphicsOpenGL extends PGraphics {
textTex = pgPrimary.getFontTexture(textFont);
if (textTex == null || textTex.contextIsOutdated()) {
textTex = new FontTexture(pgPrimary, textFont, is3D());
textTex = new FontTexture(textFont, is3D());
pgPrimary.setFontTexture(textFont, textTex);
}
@@ -6208,11 +6206,11 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.beginDraw(clearColorBuffer);
if (drawFramebuffer == null) {
drawFramebuffer = new FrameBuffer(width, height, true);
drawFramebuffer = new FrameBuffer(this, width, height, true);
}
drawFramebuffer.setFBO(pgl.getDrawFramebuffer());
if (readFramebuffer == null) {
readFramebuffer = new FrameBuffer(width, height, true);
readFramebuffer = new FrameBuffer(this, width, height, true);
}
readFramebuffer.setFBO(pgl.getReadFramebuffer());
if (currentFramebuffer == null) {
@@ -9659,8 +9657,6 @@ public class PGraphicsOpenGL extends PGraphics {
int beginPath;
public Tessellator() {
callback = new TessellatorCallback();
gluTess = pgl.createTessellator(callback);
rawIndices = new int[512];
accurate2DStrokes = true;
transform = null;
@@ -9668,6 +9664,13 @@ public class PGraphicsOpenGL extends PGraphics {
is3D = true;
}
void initGluTess() {
if (gluTess == null) {
callback = new TessellatorCallback();
gluTess = pg.pgl.createTessellator(callback);
}
}
void setInGeometry(InGeometry in) {
this.in = in;
@@ -9689,7 +9692,6 @@ public class PGraphicsOpenGL extends PGraphics {
void setTexCache(TexCache texCache, PImage newTexImage) {
this.texCache = texCache;
//this.prevTexImage = prevTexImage;
this.newTexImage = newTexImage;
}
@@ -11198,6 +11200,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (3 <= nInVert) {
firstPolyIndexCache = -1;
initGluTess();
boolean clamp = clampPolygon();
callback.init(in.renderMode == RETAINED, false, calcNormals, clamp);
@@ -11727,8 +11730,8 @@ public class PGraphicsOpenGL extends PGraphics {
// Based on the opengl stroke hack described here:
// http://wiki.processing.org/w/Stroke_attributes_in_OpenGL
public void tessellateLinePath(LinePath path) {
initGluTess();
boolean clamp = clampLinePath();
callback.init(in.renderMode == RETAINED, true, false, clamp);
int cap = strokeCap == ROUND ? LinePath.CAP_ROUND :
@@ -11960,7 +11963,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
public void error(int errnum) {
String estring = pgl.tessError(errnum);
String estring = pg.pgl.tessError(errnum);
PGraphics.showWarning(TESSELLATION_ERROR, estring);
}

View File

@@ -180,7 +180,7 @@ public class PShader implements PConstants {
public PShader(PApplet parent) {
this();
this.parent = parent;
pgl = PGraphicsOpenGL.pgl;
pgl = PGraphicsOpenGL.pgCurrent.pgl;
context = pgl.createEmptyContext();
}
@@ -195,7 +195,7 @@ public class PShader implements PConstants {
*/
public PShader(PApplet parent, String vertFilename, String fragFilename) {
this.parent = parent;
pgl = PGraphicsOpenGL.pgl;
pgl = PGraphicsOpenGL.pgCurrent.pgl;
this.vertexURL = null;
this.fragmentURL = null;
@@ -233,7 +233,7 @@ public class PShader implements PConstants {
*/
public PShader(PApplet parent, URL vertURL, URL fragURL) {
this.parent = parent;
pgl = PGraphicsOpenGL.pgl;
pgl = PGraphicsOpenGL.pgCurrent.pgl;
this.vertexURL = vertURL;
this.fragmentURL = fragURL;
@@ -266,7 +266,7 @@ public class PShader implements PConstants {
public PShader(PApplet parent, String[] vertSource, String[] fragSource) {
this.parent = parent;
pgl = PGraphicsOpenGL.pgl;
pgl = PGraphicsOpenGL.pgCurrent.pgl;
this.vertexURL = null;
this.fragmentURL = null;
@@ -894,7 +894,7 @@ public class PShader implements PConstants {
protected void init() {
if (glProgram == 0 || contextIsOutdated()) {
context = pgl.getCurrentContext();
glProgram = PGraphicsOpenGL.createGLSLProgramObject(context);
glProgram = PGraphicsOpenGL.createGLSLProgramObject(context, pgl);
boolean vertRes = true;
if (hasVertexShader()) {
@@ -964,7 +964,7 @@ public class PShader implements PConstants {
* @param shaderSource a string containing the shader's code
*/
protected boolean compileVertexShader() {
glVertex = PGraphicsOpenGL.createGLSLVertShaderObject(context);
glVertex = PGraphicsOpenGL.createGLSLVertShaderObject(context, pgl);
pgl.shaderSource(glVertex, PApplet.join(vertexShaderSource, "\n"));
pgl.compileShader(glVertex);
@@ -985,7 +985,7 @@ public class PShader implements PConstants {
* @param shaderSource a string containing the shader's code
*/
protected boolean compileFragmentShader() {
glFragment = PGraphicsOpenGL.createGLSLFragShaderObject(context);
glFragment = PGraphicsOpenGL.createGLSLFragShaderObject(context, pgl);
pgl.shaderSource(glFragment, PApplet.join(fragmentShaderSource, "\n"));
pgl.compileShader(glFragment);
@@ -1004,15 +1004,15 @@ public class PShader implements PConstants {
protected void dispose() {
if (glVertex != 0) {
PGraphicsOpenGL.deleteGLSLVertShaderObject(glVertex, context);
PGraphicsOpenGL.deleteGLSLVertShaderObject(glVertex, context, pgl);
glVertex = 0;
}
if (glFragment != 0) {
PGraphicsOpenGL.deleteGLSLFragShaderObject(glFragment, context);
PGraphicsOpenGL.deleteGLSLFragShaderObject(glFragment, context, pgl);
glFragment = 0;
}
if (glProgram != 0) {
PGraphicsOpenGL.deleteGLSLProgramObject(glProgram, context);
PGraphicsOpenGL.deleteGLSLProgramObject(glProgram, context, pgl);
glProgram = 0;
}
}

View File

@@ -292,7 +292,7 @@ public class PShapeOpenGL extends PShape {
public PShapeOpenGL(PApplet parent, int family) {
pg = PGraphicsOpenGL.pgCurrent;
pgl = PGraphicsOpenGL.pgl;
pgl = pg.pgl;
context = pgl.createEmptyContext();
glPolyVertex = 0;
@@ -3651,56 +3651,56 @@ public class PShapeOpenGL extends PShape {
tessGeo.updatePolyVerticesBuffer();
if (glPolyVertex == 0)
glPolyVertex = PGraphicsOpenGL.createVertexBufferObject(context);
glPolyVertex = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.polyVerticesBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyColorsBuffer();
if (glPolyColor == 0)
glPolyColor = PGraphicsOpenGL.createVertexBufferObject(context);
glPolyColor = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.polyColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyNormalsBuffer();
if (glPolyNormal == 0)
glPolyNormal = PGraphicsOpenGL.createVertexBufferObject(context);
glPolyNormal = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef,
tessGeo.polyNormalsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyTexCoordsBuffer();
if (glPolyTexcoord == 0)
glPolyTexcoord = PGraphicsOpenGL.createVertexBufferObject(context);
glPolyTexcoord = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
tessGeo.polyTexCoordsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyAmbientBuffer();
if (glPolyAmbient == 0)
glPolyAmbient = PGraphicsOpenGL.createVertexBufferObject(context);
glPolyAmbient = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.polyAmbientBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolySpecularBuffer();
if (glPolySpecular == 0)
glPolySpecular = PGraphicsOpenGL.createVertexBufferObject(context);
glPolySpecular = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.polySpecularBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyEmissiveBuffer();
if (glPolyEmissive == 0)
glPolyEmissive = PGraphicsOpenGL.createVertexBufferObject(context);
glPolyEmissive = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.polyEmissiveBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyShininessBuffer();
if (glPolyShininess == 0)
glPolyShininess = PGraphicsOpenGL.createVertexBufferObject(context);
glPolyShininess = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess);
pgl.bufferData(PGL.ARRAY_BUFFER, sizef,
tessGeo.polyShininessBuffer, PGL.STATIC_DRAW);
@@ -3709,7 +3709,7 @@ public class PShapeOpenGL extends PShape {
tessGeo.updatePolyIndicesBuffer();
if (glPolyIndex == 0)
glPolyIndex = PGraphicsOpenGL.createVertexBufferObject(context);
glPolyIndex = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.polyIndexCount * PGL.SIZEOF_INDEX,
@@ -3726,21 +3726,21 @@ public class PShapeOpenGL extends PShape {
tessGeo.updateLineVerticesBuffer();
if (glLineVertex == 0)
glLineVertex = PGraphicsOpenGL.createVertexBufferObject(context);
glLineVertex = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.lineVerticesBuffer, PGL.STATIC_DRAW);
tessGeo.updateLineColorsBuffer();
if (glLineColor == 0)
glLineColor = PGraphicsOpenGL.createVertexBufferObject(context);
glLineColor = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.lineColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updateLineDirectionsBuffer();
if (glLineAttrib == 0)
glLineAttrib = PGraphicsOpenGL.createVertexBufferObject(context);
glLineAttrib = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.lineDirectionsBuffer, PGL.STATIC_DRAW);
@@ -3749,7 +3749,7 @@ public class PShapeOpenGL extends PShape {
tessGeo.updateLineIndicesBuffer();
if (glLineIndex == 0)
glLineIndex = PGraphicsOpenGL.createVertexBufferObject(context);
glLineIndex = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.lineIndexCount * PGL.SIZEOF_INDEX,
@@ -3766,21 +3766,21 @@ public class PShapeOpenGL extends PShape {
tessGeo.updatePointVerticesBuffer();
if (glPointVertex == 0)
glPointVertex = PGraphicsOpenGL.createVertexBufferObject(context);
glPointVertex = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.pointVerticesBuffer, PGL.STATIC_DRAW);
tessGeo.updatePointColorsBuffer();
if (glPointColor == 0)
glPointColor = PGraphicsOpenGL.createVertexBufferObject(context);
glPointColor = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.pointColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePointOffsetsBuffer();
if (glPointAttrib == 0)
glPointAttrib = PGraphicsOpenGL.createVertexBufferObject(context);
glPointAttrib = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
tessGeo.pointOffsetsBuffer, PGL.STATIC_DRAW);
@@ -3789,7 +3789,7 @@ public class PShapeOpenGL extends PShape {
tessGeo.updatePointIndicesBuffer();
if (glPointIndex == 0)
glPointIndex = PGraphicsOpenGL.createVertexBufferObject(context);
glPointIndex = PGraphicsOpenGL.createVertexBufferObject(context, pgl);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.pointIndexCount * PGL.SIZEOF_INDEX,
@@ -3870,47 +3870,47 @@ public class PShapeOpenGL extends PShape {
protected void deletePolyBuffers() {
if (glPolyVertex != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPolyVertex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyVertex, context, pgl);
glPolyVertex = 0;
}
if (glPolyColor != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPolyColor, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyColor, context, pgl);
glPolyColor = 0;
}
if (glPolyNormal != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPolyNormal, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyNormal, context, pgl);
glPolyNormal = 0;
}
if (glPolyTexcoord != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPolyTexcoord, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyTexcoord, context, pgl);
glPolyTexcoord = 0;
}
if (glPolyAmbient != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPolyAmbient, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyAmbient, context, pgl);
glPolyAmbient = 0;
}
if (glPolySpecular != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPolySpecular, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolySpecular, context, pgl);
glPolySpecular = 0;
}
if (glPolyEmissive != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPolyEmissive, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyEmissive, context, pgl);
glPolyEmissive = 0;
}
if (glPolyShininess != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPolyShininess, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyShininess, context, pgl);
glPolyShininess = 0;
}
if (glPolyIndex != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPolyIndex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyIndex, context, pgl);
glPolyIndex = 0;
}
}
@@ -3918,22 +3918,22 @@ public class PShapeOpenGL extends PShape {
protected void deleteLineBuffers() {
if (glLineVertex != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glLineVertex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glLineVertex, context, pgl);
glLineVertex = 0;
}
if (glLineColor != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glLineColor, context);
PGraphicsOpenGL.deleteVertexBufferObject(glLineColor, context, pgl);
glLineColor = 0;
}
if (glLineAttrib != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glLineAttrib, context);
PGraphicsOpenGL.deleteVertexBufferObject(glLineAttrib, context, pgl);
glLineAttrib = 0;
}
if (glLineIndex != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glLineIndex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glLineIndex, context, pgl);
glLineIndex = 0;
}
}
@@ -3941,22 +3941,22 @@ public class PShapeOpenGL extends PShape {
protected void deletePointBuffers() {
if (glPointVertex != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPointVertex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPointVertex, context, pgl);
glPointVertex = 0;
}
if (glPointColor != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPointColor, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPointColor, context, pgl);
glPointColor = 0;
}
if (glPointAttrib != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPointAttrib, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPointAttrib, context, pgl);
glPointAttrib = 0;
}
if (glPointIndex != 0) {
PGraphicsOpenGL.deleteVertexBufferObject(glPointIndex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPointIndex, context, pgl);
glPointIndex = 0;
}
}

View File

@@ -119,7 +119,7 @@ public class Texture implements PConstants {
public Texture() {
pgl = PGraphicsOpenGL.pgl;
pgl = PGraphicsOpenGL.pgPrimary.pgl;
context = pgl.createEmptyContext();
colorBuffer = false;
@@ -147,7 +147,7 @@ public class Texture implements PConstants {
* @param params Parameters
*/
public Texture(int width, int height, Object params) {
pgl = PGraphicsOpenGL.pgl;
pgl = PGraphicsOpenGL.pgPrimary.pgl;
context = pgl.createEmptyContext();
colorBuffer = false;
@@ -1157,7 +1157,7 @@ public class Texture implements PConstants {
}
context = pgl.getCurrentContext();
glName = PGraphicsOpenGL.createTextureObject(context);
glName = PGraphicsOpenGL.createTextureObject(context, pgl);
pgl.bindTexture(glTarget, glName);
pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter);