mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
gl resource arrays also store context
This commit is contained in:
@@ -227,7 +227,7 @@ class PFontTexture implements PConstants {
|
||||
}
|
||||
if (outdated) {
|
||||
for (int i = 0; i < textures.length; i++) {
|
||||
pg.removeTextureObject(textures[i].glID);
|
||||
pg.removeTextureObject(textures[i].glID, textures[i].context.code());
|
||||
textures[i].glID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ public class PFramebuffer implements PConstants {
|
||||
this.parent = parent;
|
||||
pg = (PGraphicsOpenGL)parent.g;
|
||||
pgl = pg.pgl;
|
||||
context = pgl.createEmptyContext();
|
||||
|
||||
glFboID = 0;
|
||||
glDepthBufferID = 0;
|
||||
@@ -143,19 +144,19 @@ public class PFramebuffer implements PConstants {
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (glFboID != 0) {
|
||||
pg.finalizeFrameBufferObject(glFboID);
|
||||
pg.finalizeFrameBufferObject(glFboID, context.code());
|
||||
}
|
||||
if (glDepthBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthBufferID);
|
||||
pg.finalizeRenderBufferObject(glDepthBufferID, context.code());
|
||||
}
|
||||
if (glStencilBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glStencilBufferID);
|
||||
pg.finalizeRenderBufferObject(glStencilBufferID, context.code());
|
||||
}
|
||||
if (glColorBufferMultisampleID != 0) {
|
||||
pg.finalizeRenderBufferObject(glColorBufferMultisampleID);
|
||||
pg.finalizeRenderBufferObject(glColorBufferMultisampleID, context.code());
|
||||
}
|
||||
if (glDepthStencilBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthStencilBufferID);
|
||||
pg.finalizeRenderBufferObject(glDepthStencilBufferID, context.code());
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
@@ -274,12 +275,12 @@ public class PFramebuffer implements PConstants {
|
||||
protected void allocate() {
|
||||
release(); // Just in the case this object is being re-allocated.
|
||||
|
||||
context = pgl.getContext();
|
||||
context = pgl.getCurrentContext();
|
||||
|
||||
if (screenFb) {
|
||||
glFboID = 0;
|
||||
} else {
|
||||
glFboID = pg.createFrameBufferObject();
|
||||
glFboID = pg.createFrameBufferObject(context.code());
|
||||
}
|
||||
|
||||
// create the rest of the stuff...
|
||||
@@ -302,23 +303,23 @@ public class PFramebuffer implements PConstants {
|
||||
|
||||
protected void release() {
|
||||
if (glFboID != 0) {
|
||||
pg.finalizeFrameBufferObject(glFboID);
|
||||
pg.finalizeFrameBufferObject(glFboID, context.code());
|
||||
glFboID = 0;
|
||||
}
|
||||
if (glDepthBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthBufferID);
|
||||
pg.finalizeRenderBufferObject(glDepthBufferID, context.code());
|
||||
glDepthBufferID = 0;
|
||||
}
|
||||
if (glStencilBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glStencilBufferID);
|
||||
pg.finalizeRenderBufferObject(glStencilBufferID, context.code());
|
||||
glStencilBufferID = 0;
|
||||
}
|
||||
if (glColorBufferMultisampleID != 0) {
|
||||
pg.finalizeRenderBufferObject(glColorBufferMultisampleID);
|
||||
pg.finalizeRenderBufferObject(glColorBufferMultisampleID, context.code());
|
||||
glColorBufferMultisampleID = 0;
|
||||
}
|
||||
if (glDepthStencilBufferID != 0) {
|
||||
pg.finalizeRenderBufferObject(glDepthStencilBufferID);
|
||||
pg.finalizeRenderBufferObject(glDepthStencilBufferID, context.code());
|
||||
glDepthStencilBufferID = 0;
|
||||
}
|
||||
}
|
||||
@@ -327,11 +328,11 @@ public class PFramebuffer implements PConstants {
|
||||
protected boolean contextIsOutdated() {
|
||||
boolean outdated = !pgl.contextIsCurrent(context);
|
||||
if (outdated) {
|
||||
pg.removeFrameBufferObject(glFboID);
|
||||
pg.removeRenderBufferObject(glDepthBufferID);
|
||||
pg.removeRenderBufferObject(glStencilBufferID);
|
||||
pg.removeRenderBufferObject(glDepthStencilBufferID);
|
||||
pg.removeRenderBufferObject(glColorBufferMultisampleID);
|
||||
pg.removeFrameBufferObject(glFboID, context.code());
|
||||
pg.removeRenderBufferObject(glDepthBufferID, context.code());
|
||||
pg.removeRenderBufferObject(glStencilBufferID, context.code());
|
||||
pg.removeRenderBufferObject(glDepthStencilBufferID, context.code());
|
||||
pg.removeRenderBufferObject(glColorBufferMultisampleID, context.code());
|
||||
|
||||
glFboID = 0;
|
||||
glDepthBufferID = 0;
|
||||
@@ -353,7 +354,7 @@ public class PFramebuffer implements PConstants {
|
||||
pg.pushFramebuffer();
|
||||
pg.setFramebuffer(this);
|
||||
|
||||
glColorBufferMultisampleID = pg.createRenderBufferObject();
|
||||
glColorBufferMultisampleID = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glColorBufferMultisampleID);
|
||||
pgl.glRenderbufferStorageMultisample(PGL.GL_RENDERBUFFER, nsamples, PGL.GL_RGBA8, width, height);
|
||||
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0, PGL.GL_RENDERBUFFER, glColorBufferMultisampleID);
|
||||
@@ -372,7 +373,7 @@ public class PFramebuffer implements PConstants {
|
||||
pg.pushFramebuffer();
|
||||
pg.setFramebuffer(this);
|
||||
|
||||
glDepthStencilBufferID = pg.createRenderBufferObject();
|
||||
glDepthStencilBufferID = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthStencilBufferID);
|
||||
|
||||
if (multisample) {
|
||||
@@ -398,7 +399,7 @@ public class PFramebuffer implements PConstants {
|
||||
pg.pushFramebuffer();
|
||||
pg.setFramebuffer(this);
|
||||
|
||||
glDepthBufferID = pg.createRenderBufferObject();
|
||||
glDepthBufferID = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthBufferID);
|
||||
|
||||
int glConst = PGL.GL_DEPTH_COMPONENT16;
|
||||
@@ -432,7 +433,7 @@ public class PFramebuffer implements PConstants {
|
||||
pg.pushFramebuffer();
|
||||
pg.setFramebuffer(this);
|
||||
|
||||
glStencilBufferID = pg.createRenderBufferObject();
|
||||
glStencilBufferID = pg.createRenderBufferObject(context.code());
|
||||
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glStencilBufferID);
|
||||
|
||||
int glConst = PGL.GL_STENCIL_INDEX1;
|
||||
|
||||
@@ -1123,20 +1123,48 @@ public class PGL {
|
||||
|
||||
// Context interface
|
||||
|
||||
|
||||
public Context createEmptyContext() {
|
||||
return new Context();
|
||||
}
|
||||
|
||||
|
||||
public Context getContext() {
|
||||
public Context getCurrentContext() {
|
||||
return new Context(context);
|
||||
}
|
||||
|
||||
|
||||
public class Context {
|
||||
protected GLContext context;
|
||||
|
||||
Context() {
|
||||
context = null;
|
||||
}
|
||||
|
||||
Context(GLContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
boolean same(GLContext context) {
|
||||
return this.context.hashCode() == context.hashCode();
|
||||
boolean current() {
|
||||
return equal(context);
|
||||
}
|
||||
|
||||
boolean equal(GLContext context) {
|
||||
if (this.context == null || context == null) {
|
||||
// A null context means a still non-created resource,
|
||||
// so it is considered equal to the argument.
|
||||
return true;
|
||||
} else {
|
||||
return this.context.hashCode() == context.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
int code() {
|
||||
if (context == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return context.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1233,7 +1261,7 @@ public class PGL {
|
||||
|
||||
|
||||
public boolean contextIsCurrent(Context other) {
|
||||
return other != null && other.same(context);
|
||||
return other == null || other.current();
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -54,7 +54,8 @@ public class PShader {
|
||||
public PShader() {
|
||||
parent = null;
|
||||
pg = null;
|
||||
pgl = null;
|
||||
pgl = null;
|
||||
context = null;
|
||||
|
||||
this.vertexURL = null;
|
||||
this.fragmentURL = null;
|
||||
@@ -70,7 +71,8 @@ public class PShader {
|
||||
this();
|
||||
this.parent = parent;
|
||||
pg = (PGraphicsOpenGL) parent.g;
|
||||
pgl = pg.pgl;
|
||||
pgl = pg.pgl;
|
||||
context = pgl.createEmptyContext();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,13 +116,13 @@ public class PShader {
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (vertexShader != 0) {
|
||||
pg.finalizeGLSLVertShaderObject(vertexShader);
|
||||
pg.finalizeGLSLVertShaderObject(vertexShader, context.code());
|
||||
}
|
||||
if (fragmentShader != 0) {
|
||||
pg.finalizeGLSLFragShaderObject(fragmentShader);
|
||||
pg.finalizeGLSLFragShaderObject(fragmentShader, context.code());
|
||||
}
|
||||
if (programObject != 0) {
|
||||
pg.finalizeGLSLProgramObject(programObject);
|
||||
pg.finalizeGLSLProgramObject(programObject, context.code());
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
@@ -297,8 +299,8 @@ public class PShader {
|
||||
|
||||
protected void init() {
|
||||
if (programObject == 0 || contextIsOutdated()) {
|
||||
context = pgl.getContext();
|
||||
programObject = pg.createGLSLProgramObject();
|
||||
context = pgl.getCurrentContext();
|
||||
programObject = pg.createGLSLProgramObject(context.code());
|
||||
|
||||
boolean hasVert = false;
|
||||
if (vertexFilename != null) {
|
||||
@@ -358,9 +360,9 @@ public class PShader {
|
||||
protected boolean contextIsOutdated() {
|
||||
boolean outdated = !pgl.contextIsCurrent(context);
|
||||
if (outdated) {
|
||||
pg.removeGLSLProgramObject(programObject);
|
||||
pg.removeGLSLVertShaderObject(vertexShader);
|
||||
pg.removeGLSLFragShaderObject(fragmentShader);
|
||||
pg.removeGLSLProgramObject(programObject, context.code());
|
||||
pg.removeGLSLVertShaderObject(vertexShader, context.code());
|
||||
pg.removeGLSLFragShaderObject(fragmentShader, context.code());
|
||||
|
||||
programObject = 0;
|
||||
vertexShader = 0;
|
||||
@@ -424,7 +426,7 @@ public class PShader {
|
||||
* @param shaderSource a string containing the shader's code
|
||||
*/
|
||||
protected boolean compileVertexShader() {
|
||||
vertexShader = pg.createGLSLVertShaderObject();
|
||||
vertexShader = pg.createGLSLVertShaderObject(context.code());
|
||||
|
||||
pgl.glShaderSource(vertexShader, vertexShaderSource);
|
||||
pgl.glCompileShader(vertexShader);
|
||||
@@ -444,7 +446,7 @@ public class PShader {
|
||||
* @param shaderSource a string containing the shader's code
|
||||
*/
|
||||
protected boolean compileFragmentShader() {
|
||||
fragmentShader = pg.createGLSLFragShaderObject();
|
||||
fragmentShader = pg.createGLSLFragShaderObject(context.code());
|
||||
|
||||
pgl.glShaderSource(fragmentShader, fragmentShaderSource);
|
||||
pgl.glCompileShader(fragmentShader);
|
||||
@@ -462,15 +464,15 @@ public class PShader {
|
||||
|
||||
protected void release() {
|
||||
if (vertexShader != 0) {
|
||||
pg.deleteGLSLVertShaderObject(vertexShader);
|
||||
pg.deleteGLSLVertShaderObject(vertexShader, context.code());
|
||||
vertexShader = 0;
|
||||
}
|
||||
if (fragmentShader != 0) {
|
||||
pg.deleteGLSLFragShaderObject(fragmentShader);
|
||||
pg.deleteGLSLFragShaderObject(fragmentShader, context.code());
|
||||
fragmentShader = 0;
|
||||
}
|
||||
if (programObject != 0) {
|
||||
pg.deleteGLSLProgramObject(programObject);
|
||||
pg.deleteGLSLProgramObject(programObject, context.code());
|
||||
programObject = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +259,7 @@ public class PShape3D extends PShape {
|
||||
public PShape3D(PApplet parent, int family) {
|
||||
pg = (PGraphicsOpenGL)parent.g;
|
||||
pgl = pg.pgl;
|
||||
context = pgl.createEmptyContext();
|
||||
|
||||
prevMode = mode = DYNAMIC;
|
||||
|
||||
@@ -399,75 +400,75 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void finalizeFillBuffers() {
|
||||
if (glFillVertexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glFillVertexBufferID);
|
||||
pg.finalizeVertexBufferObject(glFillVertexBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glFillColorBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glFillColorBufferID);
|
||||
pg.finalizeVertexBufferObject(glFillColorBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glFillNormalBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glFillNormalBufferID);
|
||||
pg.finalizeVertexBufferObject(glFillNormalBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glFillTexCoordBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glFillTexCoordBufferID);
|
||||
pg.finalizeVertexBufferObject(glFillTexCoordBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glFillAmbientBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glFillAmbientBufferID);
|
||||
pg.finalizeVertexBufferObject(glFillAmbientBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glFillSpecularBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glFillSpecularBufferID);
|
||||
pg.finalizeVertexBufferObject(glFillSpecularBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glFillEmissiveBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glFillEmissiveBufferID);
|
||||
pg.finalizeVertexBufferObject(glFillEmissiveBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glFillShininessBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glFillShininessBufferID);
|
||||
pg.finalizeVertexBufferObject(glFillShininessBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glFillIndexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glFillIndexBufferID);
|
||||
pg.finalizeVertexBufferObject(glFillIndexBufferID, context.code());
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalizeLineBuffers() {
|
||||
if (glLineVertexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineVertexBufferID);
|
||||
pg.finalizeVertexBufferObject(glLineVertexBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glLineColorBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineColorBufferID);
|
||||
pg.finalizeVertexBufferObject(glLineColorBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glLineDirWidthBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineDirWidthBufferID);
|
||||
pg.finalizeVertexBufferObject(glLineDirWidthBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glLineIndexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glLineIndexBufferID);
|
||||
pg.finalizeVertexBufferObject(glLineIndexBufferID, context.code());
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalizePointBuffers() {
|
||||
if (glPointVertexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointVertexBufferID);
|
||||
pg.finalizeVertexBufferObject(glPointVertexBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glPointColorBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointColorBufferID);
|
||||
pg.finalizeVertexBufferObject(glPointColorBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glPointSizeBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointSizeBufferID);
|
||||
pg.finalizeVertexBufferObject(glPointSizeBufferID, context.code());
|
||||
}
|
||||
|
||||
if (glPointIndexBufferID != 0) {
|
||||
pg.finalizeVertexBufferObject(glPointIndexBufferID);
|
||||
pg.finalizeVertexBufferObject(glPointIndexBufferID, context.code());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2945,7 +2946,7 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void copyGeometryToRoot() {
|
||||
if (root == this && parent == null) {
|
||||
context = pgl.getContext();
|
||||
context = pgl.getCurrentContext();
|
||||
|
||||
// Now that we know, we can initialize the buffers with the correct size.
|
||||
if (0 < tess.fillVertexCount && 0 < tess.fillIndexCount) {
|
||||
@@ -2994,25 +2995,25 @@ public class PShape3D extends PShape {
|
||||
// doesn't get deleted by OpenGL. The VBOs were already
|
||||
// automatically disposed when the old context was
|
||||
// destroyed.
|
||||
pg.removeVertexBufferObject(glFillVertexBufferID);
|
||||
pg.removeVertexBufferObject(glFillColorBufferID);
|
||||
pg.removeVertexBufferObject(glFillNormalBufferID);
|
||||
pg.removeVertexBufferObject(glFillTexCoordBufferID);
|
||||
pg.removeVertexBufferObject(glFillAmbientBufferID);
|
||||
pg.removeVertexBufferObject(glFillSpecularBufferID);
|
||||
pg.removeVertexBufferObject(glFillEmissiveBufferID);
|
||||
pg.removeVertexBufferObject(glFillShininessBufferID);
|
||||
pg.removeVertexBufferObject(glFillIndexBufferID);
|
||||
pg.removeVertexBufferObject(glFillVertexBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glFillColorBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glFillNormalBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glFillTexCoordBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glFillAmbientBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glFillSpecularBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glFillEmissiveBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glFillShininessBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glFillIndexBufferID, context.code());
|
||||
|
||||
pg.removeVertexBufferObject(glLineVertexBufferID);
|
||||
pg.removeVertexBufferObject(glLineColorBufferID);
|
||||
pg.removeVertexBufferObject(glLineDirWidthBufferID);
|
||||
pg.removeVertexBufferObject(glLineIndexBufferID);
|
||||
pg.removeVertexBufferObject(glLineVertexBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glLineColorBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glLineDirWidthBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glLineIndexBufferID, context.code());
|
||||
|
||||
pg.removeVertexBufferObject(glPointVertexBufferID);
|
||||
pg.removeVertexBufferObject(glPointColorBufferID);
|
||||
pg.removeVertexBufferObject(glPointSizeBufferID);
|
||||
pg.removeVertexBufferObject(glPointIndexBufferID);
|
||||
pg.removeVertexBufferObject(glPointVertexBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPointColorBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPointSizeBufferID, context.code());
|
||||
pg.removeVertexBufferObject(glPointIndexBufferID, context.code());
|
||||
|
||||
// The OpenGL resources have been already deleted
|
||||
// when the context changed. We only need to zero
|
||||
@@ -3047,41 +3048,41 @@ public class PShape3D extends PShape {
|
||||
int sizei = nvert * PGL.SIZEOF_INT;
|
||||
int sizex = nind * PGL.SIZEOF_INDEX;
|
||||
|
||||
glFillVertexBufferID = pg.createVertexBufferObject();
|
||||
glFillVertexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillVertexBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glFillColorBufferID = pg.createVertexBufferObject();
|
||||
glFillColorBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillColorBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glFillNormalBufferID = pg.createVertexBufferObject();
|
||||
glFillNormalBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillNormalBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glFillTexCoordBufferID = pg.createVertexBufferObject();
|
||||
glFillTexCoordBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillTexCoordBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glFillAmbientBufferID = pg.createVertexBufferObject();
|
||||
glFillAmbientBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillAmbientBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glFillSpecularBufferID = pg.createVertexBufferObject();
|
||||
glFillSpecularBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillSpecularBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glFillEmissiveBufferID = pg.createVertexBufferObject();
|
||||
glFillEmissiveBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillEmissiveBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glFillShininessBufferID = pg.createVertexBufferObject();
|
||||
glFillShininessBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillShininessBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizef, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glFillIndexBufferID = pg.createVertexBufferObject();
|
||||
glFillIndexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glFillIndexBufferID);
|
||||
pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, sizex, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
@@ -3391,21 +3392,21 @@ public class PShape3D extends PShape {
|
||||
int sizei = nvert * PGL.SIZEOF_INT;
|
||||
int sizex = nind * PGL.SIZEOF_INDEX;
|
||||
|
||||
glLineVertexBufferID = pg.createVertexBufferObject();
|
||||
glLineVertexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glLineColorBufferID = pg.createVertexBufferObject();
|
||||
glLineColorBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glLineDirWidthBufferID = pg.createVertexBufferObject();
|
||||
glLineDirWidthBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineDirWidthBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glLineIndexBufferID = pg.createVertexBufferObject();
|
||||
glLineIndexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID);
|
||||
pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, sizex, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
@@ -3485,21 +3486,21 @@ public class PShape3D extends PShape {
|
||||
int sizei = nvert * PGL.SIZEOF_INT;
|
||||
int sizex = nind * PGL.SIZEOF_INDEX;
|
||||
|
||||
glPointVertexBufferID = pg.createVertexBufferObject();
|
||||
glPointVertexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPointColorBufferID = pg.createVertexBufferObject();
|
||||
glPointColorBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
glPointSizeBufferID = pg.createVertexBufferObject();
|
||||
glPointSizeBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointSizeBufferID);
|
||||
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glPointIndexBufferID = pg.createVertexBufferObject();
|
||||
glPointIndexBufferID = pg.createVertexBufferObject(context.code());
|
||||
pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID);
|
||||
pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, sizex, null, PGL.GL_STATIC_DRAW);
|
||||
|
||||
@@ -3590,47 +3591,47 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void deleteFillBuffers() {
|
||||
if (glFillVertexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glFillVertexBufferID);
|
||||
pg.deleteVertexBufferObject(glFillVertexBufferID, context.code());
|
||||
glFillVertexBufferID = 0;
|
||||
}
|
||||
|
||||
if (glFillColorBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glFillColorBufferID);
|
||||
pg.deleteVertexBufferObject(glFillColorBufferID, context.code());
|
||||
glFillColorBufferID = 0;
|
||||
}
|
||||
|
||||
if (glFillNormalBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glFillNormalBufferID);
|
||||
pg.deleteVertexBufferObject(glFillNormalBufferID, context.code());
|
||||
glFillNormalBufferID = 0;
|
||||
}
|
||||
|
||||
if (glFillTexCoordBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glFillTexCoordBufferID);
|
||||
pg.deleteVertexBufferObject(glFillTexCoordBufferID, context.code());
|
||||
glFillTexCoordBufferID = 0;
|
||||
}
|
||||
|
||||
if (glFillAmbientBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glFillAmbientBufferID);
|
||||
pg.deleteVertexBufferObject(glFillAmbientBufferID, context.code());
|
||||
glFillAmbientBufferID = 0;
|
||||
}
|
||||
|
||||
if (glFillSpecularBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glFillSpecularBufferID);
|
||||
pg.deleteVertexBufferObject(glFillSpecularBufferID, context.code());
|
||||
glFillSpecularBufferID = 0;
|
||||
}
|
||||
|
||||
if (glFillEmissiveBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glFillEmissiveBufferID);
|
||||
pg.deleteVertexBufferObject(glFillEmissiveBufferID, context.code());
|
||||
glFillEmissiveBufferID = 0;
|
||||
}
|
||||
|
||||
if (glFillShininessBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glFillShininessBufferID);
|
||||
pg.deleteVertexBufferObject(glFillShininessBufferID, context.code());
|
||||
glFillShininessBufferID = 0;
|
||||
}
|
||||
|
||||
if (glFillIndexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glFillIndexBufferID);
|
||||
pg.deleteVertexBufferObject(glFillIndexBufferID, context.code());
|
||||
glFillIndexBufferID = 0;
|
||||
}
|
||||
}
|
||||
@@ -3638,22 +3639,22 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void deleteLineBuffers() {
|
||||
if (glLineVertexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glLineVertexBufferID);
|
||||
pg.deleteVertexBufferObject(glLineVertexBufferID, context.code());
|
||||
glLineVertexBufferID = 0;
|
||||
}
|
||||
|
||||
if (glLineColorBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glLineColorBufferID);
|
||||
pg.deleteVertexBufferObject(glLineColorBufferID, context.code());
|
||||
glLineColorBufferID = 0;
|
||||
}
|
||||
|
||||
if (glLineDirWidthBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glLineDirWidthBufferID);
|
||||
pg.deleteVertexBufferObject(glLineDirWidthBufferID, context.code());
|
||||
glLineDirWidthBufferID = 0;
|
||||
}
|
||||
|
||||
if (glLineIndexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glLineIndexBufferID);
|
||||
pg.deleteVertexBufferObject(glLineIndexBufferID, context.code());
|
||||
glLineIndexBufferID = 0;
|
||||
}
|
||||
}
|
||||
@@ -3661,22 +3662,22 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void deletePointBuffers() {
|
||||
if (glPointVertexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPointVertexBufferID);
|
||||
pg.deleteVertexBufferObject(glPointVertexBufferID, context.code());
|
||||
glPointVertexBufferID = 0;
|
||||
}
|
||||
|
||||
if (glPointColorBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPointColorBufferID);
|
||||
pg.deleteVertexBufferObject(glPointColorBufferID, context.code());
|
||||
glPointColorBufferID = 0;
|
||||
}
|
||||
|
||||
if (glPointSizeBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPointSizeBufferID);
|
||||
pg.deleteVertexBufferObject(glPointSizeBufferID, context.code());
|
||||
glPointSizeBufferID = 0;
|
||||
}
|
||||
|
||||
if (glPointIndexBufferID != 0) {
|
||||
pg.deleteVertexBufferObject(glPointIndexBufferID);
|
||||
pg.deleteVertexBufferObject(glPointIndexBufferID, context.code());
|
||||
glPointIndexBufferID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ public class PTexture implements PConstants {
|
||||
|
||||
pg = (PGraphicsOpenGL)parent.g;
|
||||
pgl = pg.pgl;
|
||||
context = pgl.createEmptyContext();
|
||||
|
||||
glID = 0;
|
||||
|
||||
@@ -112,7 +113,7 @@ public class PTexture implements PConstants {
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (glID != 0) {
|
||||
pg.finalizeTextureObject(glID);
|
||||
pg.finalizeTextureObject(glID, context.code());
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
@@ -754,8 +755,8 @@ public class PTexture implements PConstants {
|
||||
|
||||
pgl.enableTexturing(glTarget);
|
||||
|
||||
context = pgl.getContext();
|
||||
glID = pg.createTextureObject();
|
||||
context = pgl.getCurrentContext();
|
||||
glID = pg.createTextureObject(context.code());
|
||||
|
||||
pgl.glBindTexture(glTarget, glID);
|
||||
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MIN_FILTER, glMinFilter);
|
||||
@@ -780,7 +781,7 @@ public class PTexture implements PConstants {
|
||||
*/
|
||||
protected void release() {
|
||||
if (glID != 0) {
|
||||
pg.finalizeTextureObject(glID);
|
||||
pg.finalizeTextureObject(glID, context.code());
|
||||
glID = 0;
|
||||
}
|
||||
}
|
||||
@@ -792,7 +793,7 @@ public class PTexture 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(glID);
|
||||
pg.removeTextureObject(glID, context.code());
|
||||
|
||||
// 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.
|
||||
|
||||
Reference in New Issue
Block a user