mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
New GL resource handling mechanism, should take care of issue 806
This commit is contained in:
@@ -66,16 +66,10 @@ class PFontTexture implements PConstants {
|
||||
this.font = font;
|
||||
ogl = (PGraphicsOpenGL)parent.g;
|
||||
|
||||
// Although PFontTexture is not strictly a GL object, since it doesn't directly
|
||||
// contains any native OpenGL resources, it does contains a list of textures
|
||||
// that don't depend on any PImage, so it is registered so in the case of a refresh
|
||||
// event the textures are re-initialized with the correct data.
|
||||
ogl.registerPGLObject(this);
|
||||
|
||||
initTexture(maxw, maxh);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void delete() {
|
||||
for (int i = 0; i < textures.length; i++) {
|
||||
textures[i].delete();
|
||||
@@ -102,12 +96,14 @@ class PFontTexture implements PConstants {
|
||||
textures[tinfo.texIndex].unbind();
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
protected void allocate() {
|
||||
// Nothing to do here: the font textures will allocate
|
||||
// themselves.
|
||||
}
|
||||
|
||||
|
||||
protected void initTexture(int w, int h) {
|
||||
maxTexWidth = w;
|
||||
maxTexHeight = h;
|
||||
@@ -155,7 +151,6 @@ class PFontTexture implements PConstants {
|
||||
PTexture tex0 = textures[currentTex];
|
||||
tex.put(tex0);
|
||||
textures[currentTex] = tex;
|
||||
tex0.delete();
|
||||
} else {
|
||||
// Adding new texture to the list.
|
||||
PTexture[] temp = textures;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class PFramebuffer implements PConstants {
|
||||
boolean screen) {
|
||||
this.parent = parent;
|
||||
ogl = (PGraphicsOpenGL)parent.g;
|
||||
ogl.registerPGLObject(this);
|
||||
//gl.registerPGLObject(this);
|
||||
|
||||
glFboID = 0;
|
||||
glDepthBufferID = 0;
|
||||
@@ -152,6 +152,7 @@ public class PFramebuffer implements PConstants {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void delete() {
|
||||
release();
|
||||
for (int i = 0; i < numColorBuffers; i++) {
|
||||
@@ -166,6 +167,33 @@ public class PFramebuffer implements PConstants {
|
||||
public void restore() {
|
||||
setColorBuffers(colorBufferTex.clone(), colorBufferTex.length);
|
||||
}
|
||||
*/
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (glFboID != 0) {
|
||||
ogl.finalizeFrameBufferObject(glFboID);
|
||||
}
|
||||
|
||||
if (glDepthBufferID != 0) {
|
||||
ogl.finalizeRenderBufferObject(glDepthBufferID);
|
||||
}
|
||||
|
||||
if (glStencilBufferID != 0) {
|
||||
ogl.finalizeRenderBufferObject(glStencilBufferID);
|
||||
}
|
||||
|
||||
if (glColorBufferMultisampleID != 0) {
|
||||
ogl.finalizeRenderBufferObject(glColorBufferMultisampleID);
|
||||
}
|
||||
|
||||
if (glDepthStencilBufferID != 0) {
|
||||
ogl.finalizeRenderBufferObject(glDepthStencilBufferID);
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
ogl.pushFramebuffer();
|
||||
@@ -342,7 +370,8 @@ public class PFramebuffer implements PConstants {
|
||||
if (screenFb) {
|
||||
glFboID = 0;
|
||||
} else if (fboMode) {
|
||||
glFboID = ogl.createGLResource(PGraphicsOpenGL.GL_FRAME_BUFFER);
|
||||
//glFboID = ogl.createGLResource(PGraphicsOpenGL.GL_FRAME_BUFFER);
|
||||
glFboID = ogl.createFrameBufferObject();
|
||||
} else {
|
||||
glFboID = 0;
|
||||
}
|
||||
@@ -366,51 +395,26 @@ public class PFramebuffer implements PConstants {
|
||||
|
||||
|
||||
protected void release() {
|
||||
deleteFbo();
|
||||
deleteDepthBuffer();
|
||||
deleteStencilBuffer();
|
||||
deleteCombinedDepthStencilBuffer();
|
||||
deleteColorBufferMultisample();
|
||||
}
|
||||
|
||||
|
||||
protected void deleteFbo() {
|
||||
if (glFboID != 0) {
|
||||
ogl.deleteGLResource(glFboID, PGraphicsOpenGL.GL_FRAME_BUFFER);
|
||||
ogl.finalizeFrameBufferObject(glFboID);
|
||||
glFboID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void deleteDepthBuffer() {
|
||||
}
|
||||
if (glDepthBufferID != 0) {
|
||||
ogl.deleteGLResource(glDepthBufferID, PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
ogl.finalizeRenderBufferObject(glDepthBufferID);
|
||||
glDepthBufferID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void deleteStencilBuffer() {
|
||||
if (glStencilBufferID != 0) {
|
||||
ogl.deleteGLResource(glStencilBufferID, PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
ogl.finalizeRenderBufferObject(glStencilBufferID);
|
||||
glStencilBufferID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void deleteColorBufferMultisample() {
|
||||
}
|
||||
if (glColorBufferMultisampleID != 0) {
|
||||
ogl.deleteGLResource(glColorBufferMultisampleID, PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
ogl.finalizeRenderBufferObject(glColorBufferMultisampleID);
|
||||
glColorBufferMultisampleID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void deleteCombinedDepthStencilBuffer() {
|
||||
}
|
||||
if (glDepthStencilBufferID != 0) {
|
||||
ogl.deleteGLResource(glDepthStencilBufferID, PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
ogl.finalizeRenderBufferObject(glDepthStencilBufferID);
|
||||
glDepthStencilBufferID = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -421,7 +425,8 @@ public class PFramebuffer implements PConstants {
|
||||
ogl.pushFramebuffer();
|
||||
ogl.setFramebuffer(this);
|
||||
|
||||
glColorBufferMultisampleID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
//glColorBufferMultisampleID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
glColorBufferMultisampleID = ogl.createRenderBufferObject();
|
||||
getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glColorBufferMultisampleID);
|
||||
getGl2().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, nsamples,
|
||||
GL.GL_RGBA8, width, height);
|
||||
@@ -444,7 +449,8 @@ public class PFramebuffer implements PConstants {
|
||||
ogl.pushFramebuffer();
|
||||
ogl.setFramebuffer(this);
|
||||
|
||||
glDepthStencilBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
//glDepthStencilBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
glDepthStencilBufferID = ogl.createRenderBufferObject();
|
||||
getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glDepthStencilBufferID);
|
||||
|
||||
if (multisample) {
|
||||
@@ -474,7 +480,8 @@ public class PFramebuffer implements PConstants {
|
||||
ogl.pushFramebuffer();
|
||||
ogl.setFramebuffer(this);
|
||||
|
||||
glDepthBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
//glDepthBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
glDepthBufferID = ogl.createRenderBufferObject();
|
||||
getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glDepthBufferID);
|
||||
|
||||
int glConst = GL.GL_DEPTH_COMPONENT16;
|
||||
@@ -511,7 +518,8 @@ public class PFramebuffer implements PConstants {
|
||||
ogl.pushFramebuffer();
|
||||
ogl.setFramebuffer(this);
|
||||
|
||||
glStencilBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
//glStencilBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER);
|
||||
glStencilBufferID = ogl.createRenderBufferObject();
|
||||
getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glStencilBufferID);
|
||||
|
||||
int glConst = GL.GL_STENCIL_INDEX1;
|
||||
|
||||
@@ -28,6 +28,7 @@ import processing.core.*;
|
||||
import java.nio.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EmptyStackException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
@@ -155,6 +156,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
|
||||
// OpenGL resources:
|
||||
|
||||
/*
|
||||
static protected final int GL_TEXTURE_OBJECT = 0;
|
||||
static protected final int GL_VERTEX_BUFFER = 1;
|
||||
static protected final int GL_FRAME_BUFFER = 2;
|
||||
@@ -175,6 +177,16 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
static protected Set<Integer> glslPrograms = new HashSet<Integer>();
|
||||
static protected Set<Integer> glslVertexShaders = new HashSet<Integer>();
|
||||
static protected Set<Integer> glslFragmentShaders = new HashSet<Integer>();
|
||||
*/
|
||||
|
||||
|
||||
static protected HashMap<Integer, Boolean> glTextureObjects = new HashMap<Integer, Boolean>();
|
||||
static protected HashMap<Integer, Boolean> glVertexBuffers = new HashMap<Integer, Boolean>();
|
||||
static protected HashMap<Integer, Boolean> glFrameBuffers = new HashMap<Integer, Boolean>();
|
||||
static protected HashMap<Integer, Boolean> glRenderBuffers = new HashMap<Integer, Boolean>();
|
||||
static protected HashMap<Integer, Boolean> glslPrograms = new HashMap<Integer, Boolean>();
|
||||
static protected HashMap<Integer, Boolean> glslVertexShaders = new HashMap<Integer, Boolean>();
|
||||
static protected HashMap<Integer, Boolean> glslFragmentShaders = new HashMap<Integer, Boolean>();
|
||||
|
||||
// ........................................................
|
||||
|
||||
@@ -728,6 +740,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void delete() {
|
||||
if (primarySurface) {
|
||||
PGraphics.showWarning("You cannot delete the primary rendering surface!");
|
||||
@@ -744,12 +757,13 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
unregisterPGLObject(this);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public void dispose() { // PGraphics
|
||||
super.dispose();
|
||||
detainContext();
|
||||
deleteAllGLResources();
|
||||
deleteFinalizedGLResources();
|
||||
releaseContext();
|
||||
GLProfile.shutdown();
|
||||
}
|
||||
@@ -758,6 +772,323 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
|
||||
// RESOURCE HANDLING
|
||||
|
||||
|
||||
// Texture Objects -------------------------------------------
|
||||
|
||||
protected int createTextureObject() {
|
||||
deleteFinalizedTextureObjects();
|
||||
|
||||
int[] temp = new int[1];
|
||||
gl.glGenTextures(1, temp, 0);
|
||||
int idx = temp[0];
|
||||
|
||||
if (glTextureObjects.containsKey(idx)) {
|
||||
System.err.println("Adding same texture twice");
|
||||
} else {
|
||||
glTextureObjects.put(idx, false);
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
// This is synchronized because it is called from the GC thread.
|
||||
synchronized protected void finalizeTextureObject(int idx) {
|
||||
if (glTextureObjects.containsKey(idx)) {
|
||||
glTextureObjects.put(idx, true);
|
||||
} else {
|
||||
System.err.println("Trying to finalize non-existing texture");
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteFinalizedTextureObjects() {
|
||||
Set<Integer> finalized = new HashSet<Integer>();
|
||||
|
||||
for (Integer idx : glTextureObjects.keySet()) {
|
||||
if (glTextureObjects.get(idx)) {
|
||||
finalized.add(idx);
|
||||
int id = idx.intValue();
|
||||
int[] temp = { id };
|
||||
gl.glDeleteTextures(1, temp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer idx : finalized) {
|
||||
glTextureObjects.remove(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// Vertex Buffer Objects ----------------------------------------------
|
||||
|
||||
protected int createVertexBufferObject() {
|
||||
deleteFinalizedVertexBufferObjects();
|
||||
|
||||
int[] temp = new int[1];
|
||||
gl.glGenBuffers(1, temp, 0);
|
||||
int idx = temp[0];
|
||||
|
||||
if (glVertexBuffers.containsKey(idx)) {
|
||||
System.err.println("Adding same VBO twice");
|
||||
} else {
|
||||
glVertexBuffers.put(idx, false);
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
// This is synchronized because it is called from the GC thread.
|
||||
synchronized protected void finalizeVertexBufferObject(int idx) {
|
||||
if (glVertexBuffers.containsKey(idx)) {
|
||||
glVertexBuffers.put(idx, true);
|
||||
} else {
|
||||
System.err.println("Trying to finalize non-existing VBO");
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteFinalizedVertexBufferObjects() {
|
||||
Set<Integer> finalized = new HashSet<Integer>();
|
||||
|
||||
for (Integer idx : glVertexBuffers.keySet()) {
|
||||
if (glVertexBuffers.get(idx)) {
|
||||
finalized.add(idx);
|
||||
int id = idx.intValue();
|
||||
int[] temp = { id };
|
||||
gl.glDeleteBuffers(1, temp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer idx : finalized) {
|
||||
glVertexBuffers.remove(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// FrameBuffer Objects -----------------------------------------
|
||||
|
||||
protected int createFrameBufferObject() {
|
||||
deleteFinalizedFrameBufferObjects();
|
||||
|
||||
int[] temp = new int[1];
|
||||
gl.glGenFramebuffers(1, temp, 0);
|
||||
int idx = temp[0];
|
||||
|
||||
if (glFrameBuffers.containsKey(idx)) {
|
||||
System.err.println("Adding same FBO twice");
|
||||
} else {
|
||||
glFrameBuffers.put(idx, false);
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
// This is synchronized because it is called from the GC thread.
|
||||
synchronized protected void finalizeFrameBufferObject(int idx) {
|
||||
if (glFrameBuffers.containsKey(idx)) {
|
||||
glFrameBuffers.put(idx, true);
|
||||
} else {
|
||||
System.err.println("Trying to finalize non-existing FBO");
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteFinalizedFrameBufferObjects() {
|
||||
Set<Integer> finalized = new HashSet<Integer>();
|
||||
|
||||
for (Integer idx : glFrameBuffers.keySet()) {
|
||||
if (glFrameBuffers.get(idx)) {
|
||||
finalized.add(idx);
|
||||
int id = idx.intValue();
|
||||
int[] temp = { id };
|
||||
gl.glDeleteFramebuffers(1, temp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer idx : finalized) {
|
||||
glFrameBuffers.remove(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// RenderBuffer Objects -----------------------------------------------
|
||||
|
||||
protected int createRenderBufferObject() {
|
||||
deleteFinalizedRenderBufferObjects();
|
||||
|
||||
int[] temp = new int[1];
|
||||
gl.glGenRenderbuffers(1, temp, 0);
|
||||
int idx = temp[0];
|
||||
|
||||
if (glRenderBuffers.containsKey(idx)) {
|
||||
System.err.println("Adding same renderbuffer twice");
|
||||
} else {
|
||||
glRenderBuffers.put(idx, false);
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
// This is synchronized because it is called from the GC thread.
|
||||
synchronized protected void finalizeRenderBufferObject(int idx) {
|
||||
if (glRenderBuffers.containsKey(idx)) {
|
||||
glRenderBuffers.put(idx, true);
|
||||
} else {
|
||||
System.err.println("Trying to finalize non-existing renderbuffer");
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteFinalizedRenderBufferObjects() {
|
||||
Set<Integer> finalized = new HashSet<Integer>();
|
||||
|
||||
for (Integer idx : glRenderBuffers.keySet()) {
|
||||
if (glRenderBuffers.get(idx)) {
|
||||
finalized.add(idx);
|
||||
int id = idx.intValue();
|
||||
int[] temp = { id };
|
||||
gl.glDeleteRenderbuffers(1, temp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer idx : finalized) {
|
||||
glRenderBuffers.remove(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL Program Objects -----------------------------------------------
|
||||
|
||||
protected int createGLSLProgramObject() {
|
||||
deleteFinalizedGLSLProgramObjects();
|
||||
|
||||
int idx = gl2x.glCreateProgram();
|
||||
|
||||
if (glslPrograms.containsKey(idx)) {
|
||||
System.err.println("Adding same glsl program twice");
|
||||
} else {
|
||||
glslPrograms.put(idx, false);
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
// This is synchronized because it is called from the GC thread.
|
||||
synchronized protected void finalizeGLSLProgramObject(int idx) {
|
||||
if (glslPrograms.containsKey(idx)) {
|
||||
glslPrograms.put(idx, true);
|
||||
} else {
|
||||
System.err.println("Trying to finalize non-existing glsl program");
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteFinalizedGLSLProgramObjects() {
|
||||
Set<Integer> finalized = new HashSet<Integer>();
|
||||
|
||||
for (Integer idx : glslPrograms.keySet()) {
|
||||
if (glslPrograms.get(idx)) {
|
||||
finalized.add(idx);
|
||||
int id = idx.intValue();
|
||||
gl2x.glDeleteProgram(id);
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer idx : finalized) {
|
||||
glslPrograms.remove(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL Vertex Shader Objects -----------------------------------------------
|
||||
|
||||
protected int createGLSLVertShaderObject() {
|
||||
deleteFinalizedGLSLVertShaderObjects();
|
||||
|
||||
int idx = gl2x.glCreateShader(GL2.GL_VERTEX_SHADER);
|
||||
|
||||
if (glslVertexShaders.containsKey(idx)) {
|
||||
System.err.println("Adding same glsl vertex shader twice");
|
||||
} else {
|
||||
glslVertexShaders.put(idx, false);
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
// This is synchronized because it is called from the GC thread.
|
||||
synchronized protected void finalizeGLSLVertShaderObject(int idx) {
|
||||
if (glslVertexShaders.containsKey(idx)) {
|
||||
glslVertexShaders.put(idx, true);
|
||||
} else {
|
||||
System.err.println("Trying to finalize non-existing glsl vertex shader");
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteFinalizedGLSLVertShaderObjects() {
|
||||
Set<Integer> finalized = new HashSet<Integer>();
|
||||
|
||||
for (Integer idx : glslVertexShaders.keySet()) {
|
||||
if (glslVertexShaders.get(idx)) {
|
||||
finalized.add(idx);
|
||||
int id = idx.intValue();
|
||||
gl2x.glDeleteShader(id);
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer idx : finalized) {
|
||||
glslVertexShaders.remove(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// GLSL Fragment Shader Objects -----------------------------------------------
|
||||
|
||||
|
||||
protected int createGLSLFragShaderObject() {
|
||||
deleteFinalizedGLSLFragShaderObjects();
|
||||
|
||||
int idx = gl2x.glCreateShader(GL2.GL_FRAGMENT_SHADER);
|
||||
|
||||
if (glslFragmentShaders.containsKey(idx)) {
|
||||
System.err.println("Adding same glsl fragment shader twice");
|
||||
} else {
|
||||
glslFragmentShaders.put(idx, false);
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
// This is synchronized because it is called from the GC thread.
|
||||
synchronized protected void finalizeGLSLFragShaderObject(int idx) {
|
||||
if (glslFragmentShaders.containsKey(idx)) {
|
||||
glslFragmentShaders.put(idx, true);
|
||||
} else {
|
||||
System.err.println("Trying to finalize non-existing glsl fragment shader");
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteFinalizedGLSLFragShaderObjects() {
|
||||
Set<Integer> finalized = new HashSet<Integer>();
|
||||
|
||||
for (Integer idx : glslFragmentShaders.keySet()) {
|
||||
if (glslFragmentShaders.get(idx)) {
|
||||
finalized.add(idx);
|
||||
int id = idx.intValue();
|
||||
gl2x.glDeleteShader(id);
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer idx : finalized) {
|
||||
glslFragmentShaders.remove(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void deleteFinalizedGLResources() {
|
||||
deleteFinalizedTextureObjects();
|
||||
deleteFinalizedVertexBufferObjects();
|
||||
deleteFinalizedFrameBufferObjects();
|
||||
deleteFinalizedRenderBufferObjects();
|
||||
deleteFinalizedGLSLProgramObjects();
|
||||
deleteFinalizedGLSLVertShaderObjects();
|
||||
deleteFinalizedGLSLFragShaderObjects();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
protected void allocatePGLObjects() {
|
||||
// Note: it is important that allocation / backup / restoration are don
|
||||
// in the order below (0: PGraphicsOpenGL, 1: PTexture objects, 2: PFramebuffer
|
||||
@@ -1068,7 +1399,9 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// FRAMEBUFFERS
|
||||
@@ -1157,7 +1490,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
* the current OpenGL objects remain valid afterward.
|
||||
*/
|
||||
public void restartContext() {
|
||||
backupPGLObjects();
|
||||
//backupPGLObjects();
|
||||
|
||||
releaseContext();
|
||||
context.destroy();
|
||||
@@ -1165,10 +1498,10 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
allocate();
|
||||
detainContext();
|
||||
|
||||
updateGLInterfaces();
|
||||
allocatePGLObjects();
|
||||
clearPGLFramebuffers();
|
||||
restorePGLObjects();
|
||||
updateGLInterfaces();
|
||||
// allocatePGLObjects();
|
||||
// clearPGLFramebuffers();
|
||||
// restorePGLObjects();
|
||||
}
|
||||
|
||||
|
||||
@@ -1272,7 +1605,6 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
// corresponds to the old window size.
|
||||
this.removeCache(ogl);
|
||||
this.removeParams(ogl);
|
||||
texture.delete();
|
||||
texture = null;
|
||||
loadTexture();
|
||||
}
|
||||
@@ -1380,6 +1712,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
|
||||
drawing = false;
|
||||
|
||||
//deleteFinalizedGLResources();
|
||||
|
||||
report("bot endDraw()");
|
||||
}
|
||||
|
||||
@@ -1399,6 +1733,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void allocateGL() {
|
||||
allocatePGLObjects();
|
||||
}
|
||||
@@ -1413,6 +1748,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
clearPGLFramebuffers();
|
||||
restorePGLObjects();
|
||||
}
|
||||
*/
|
||||
|
||||
public void updateGLInterfaces() {
|
||||
gl = context.getGL();
|
||||
@@ -7558,7 +7894,7 @@ return width * (1 + ox) / 2.0f;
|
||||
capabilities = ogl.getCapabilities();
|
||||
drawable = null;
|
||||
|
||||
registerPGLObject(this);
|
||||
//registerPGLObject(this);
|
||||
|
||||
updateGLInterfaces();
|
||||
loadTextureImpl(BILINEAR);
|
||||
@@ -7567,11 +7903,11 @@ return width * (1 + ox) / 2.0f;
|
||||
// is changed), we make sure that all the OpenGL resources associated
|
||||
// to the surface are released by calling delete().
|
||||
if (offscreenFramebuffer != null) {
|
||||
offscreenFramebuffer.delete();
|
||||
//offscreenFramebuffer.delete();
|
||||
offscreenFramebuffer = null;
|
||||
}
|
||||
if (offscreenFramebufferMultisample != null) {
|
||||
offscreenFramebufferMultisample.delete();
|
||||
//offscreenFramebufferMultisample.delete();
|
||||
offscreenFramebufferMultisample = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,9 +57,7 @@ public class PShader {
|
||||
ogl = (PGraphicsOpenGL) parent.g;
|
||||
gl = ogl.gl2x;
|
||||
|
||||
ogl.createGLResource(PGraphicsOpenGL.GLSL_PROGRAM);
|
||||
|
||||
programObject = ogl.createGLResource(PGraphicsOpenGL.GLSL_PROGRAM);
|
||||
programObject = ogl.createGLSLProgramObject();
|
||||
vertexShader = 0;
|
||||
//geometryShader = 0;
|
||||
fragmentShader = 0;
|
||||
@@ -84,9 +82,23 @@ public class PShader {
|
||||
setup();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
release();
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (vertexShader != 0) {
|
||||
ogl.finalizeGLSLVertShaderObject(vertexShader);
|
||||
}
|
||||
if (fragmentShader != 0) {
|
||||
ogl.finalizeGLSLFragShaderObject(fragmentShader);
|
||||
}
|
||||
if (programObject != 0) {
|
||||
ogl.finalizeGLSLProgramObject(programObject);
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads and compiles the vertex shader contained in file.
|
||||
@@ -436,7 +448,7 @@ public class PShader {
|
||||
* @param filename the shader's filename, used to print error log information
|
||||
*/
|
||||
private void attachVertexShader(String shaderSource, String file) {
|
||||
vertexShader = ogl.createGLResource(PGraphicsOpenGL.GLSL_VERTEX_SHADER);
|
||||
vertexShader = ogl.createGLSLVertShaderObject();
|
||||
|
||||
gl.glShaderSource(vertexShader, 1, new String[] { shaderSource },
|
||||
(int[]) null, 0);
|
||||
@@ -450,7 +462,7 @@ public class PShader {
|
||||
* @param filename the shader's filename, used to print error log information
|
||||
*/
|
||||
private void attachFragmentShader(String shaderSource, String file) {
|
||||
fragmentShader = ogl.createGLResource(PGraphicsOpenGL.GLSL_FRAGMENT_SHADER);
|
||||
fragmentShader = ogl.createGLSLFragShaderObject();
|
||||
|
||||
gl.glShaderSource(fragmentShader, 1, new String[] { shaderSource },
|
||||
(int[]) null, 0);
|
||||
@@ -487,17 +499,17 @@ public class PShader {
|
||||
|
||||
protected void release() {
|
||||
if (vertexShader != 0) {
|
||||
ogl.deleteGLResource(vertexShader, PGraphicsOpenGL.GLSL_VERTEX_SHADER);
|
||||
ogl.finalizeGLSLVertShaderObject(vertexShader);
|
||||
vertexShader = 0;
|
||||
}
|
||||
if (fragmentShader != 0) {
|
||||
ogl.deleteGLResource(fragmentShader, PGraphicsOpenGL.GLSL_FRAGMENT_SHADER);
|
||||
ogl.finalizeGLSLFragShaderObject(fragmentShader);
|
||||
fragmentShader = 0;
|
||||
}
|
||||
if (programObject != 0) {
|
||||
ogl.deleteGLResource(fragmentShader, PGraphicsOpenGL.GLSL_PROGRAM);
|
||||
ogl.finalizeGLSLProgramObject(programObject);
|
||||
programObject = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -182,7 +182,7 @@ public class PShape3D extends PShape {
|
||||
this();
|
||||
this.papplet = parent;
|
||||
ogl = (PGraphicsOpenGL)parent.g;
|
||||
ogl.registerPGLObject(this);
|
||||
//ogl.registerPGLObject(this);
|
||||
|
||||
this.family = PShape.GROUP;
|
||||
this.name = "root";
|
||||
@@ -192,7 +192,7 @@ public class PShape3D extends PShape {
|
||||
public PShape3D(PApplet parent, int family) {
|
||||
this.papplet = parent;
|
||||
ogl = (PGraphicsOpenGL)parent.g;
|
||||
ogl.registerPGLObject(this);
|
||||
//ogl.registerPGLObject(this);
|
||||
|
||||
this.family = family;
|
||||
|
||||
@@ -254,7 +254,7 @@ public class PShape3D extends PShape {
|
||||
public PShape3D(PApplet parent, String filename, Parameters params) {
|
||||
this.papplet = parent;
|
||||
ogl = (PGraphicsOpenGL)parent.g;
|
||||
ogl.registerPGLObject(this);
|
||||
//ogl.registerPGLObject(this);
|
||||
|
||||
this.family = PShape.GROUP;
|
||||
this.name = "root";
|
||||
@@ -273,7 +273,7 @@ public class PShape3D extends PShape {
|
||||
public PShape3D(PApplet parent, int size, Parameters params) {
|
||||
this.papplet = parent;
|
||||
ogl = (PGraphicsOpenGL)parent.g;
|
||||
ogl.registerPGLObject(this);
|
||||
//ogl.registerPGLObject(this);
|
||||
|
||||
this.family = PShape.GROUP;
|
||||
this.name = "root";
|
||||
@@ -289,6 +289,7 @@ public class PShape3D extends PShape {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void delete() {
|
||||
if (root != this) return; // Can be done only from the root shape.
|
||||
release();
|
||||
@@ -320,6 +321,18 @@ public class PShape3D extends PShape {
|
||||
updateTexcoords();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
release();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -587,7 +600,7 @@ public class PShape3D extends PShape {
|
||||
currentStroke[3] = a;
|
||||
}
|
||||
|
||||
public void setWeight(float w) {
|
||||
public void setStrokeWeight(float w) {
|
||||
currentStroke[4] = w;
|
||||
}
|
||||
|
||||
@@ -1548,17 +1561,17 @@ public class PShape3D extends PShape {
|
||||
}
|
||||
|
||||
protected void initBuffers(int nvert, int nind) {
|
||||
glVertexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glVertexBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glVertexBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 3 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glColorBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glColorBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glColorBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 4 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glNormalBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glNormalBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glNormalBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 3 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -1571,67 +1584,67 @@ public class PShape3D extends PShape {
|
||||
|
||||
numTexBuffers = 1;
|
||||
for (int i = 0; i < numTexBuffers; i++) {
|
||||
glTexCoordBufferID[i] = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glTexCoordBufferID[i] = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glTexCoordBufferID[i]);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 2 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
glIndexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glIndexBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glIndexBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nind * PGraphicsOpenGL.SIZEOF_INT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
protected void initStrokeBuffers(int nvert, int nind) {
|
||||
glStrokeVertexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glStrokeVertexBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glStrokeVertexBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 3 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glStrokeNormalBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glStrokeNormalBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glStrokeNormalBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 3 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glStrokeColorBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glStrokeColorBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glStrokeColorBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 4 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glStrokeAttribBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glStrokeAttribBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glStrokeAttribBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 4 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glStrokeIndexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glStrokeIndexBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glStrokeIndexBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nind * PGraphicsOpenGL.SIZEOF_INT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
protected void initPointBuffers(int nvert, int nind) {
|
||||
glPointVertexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glPointVertexBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 3 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glPointNormalBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glPointNormalBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 3 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glPointColorBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glPointColorBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 4 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glPointAttribBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glPointAttribBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointAttribBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nvert * 4 * PGraphicsOpenGL.SIZEOF_FLOAT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glPointIndexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glPointIndexBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointIndexBufferID);
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, nind * PGraphicsOpenGL.SIZEOF_INT, null, glUsage);
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
|
||||
@@ -3495,7 +3508,7 @@ public class PShape3D extends PShape {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void setStrokeWeight(float sw) {
|
||||
if (family == GROUP) {
|
||||
init();
|
||||
@@ -3513,7 +3526,7 @@ public class PShape3D extends PShape {
|
||||
((PShape3D)children[idx]).setStrokeWeight(sw);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public float getMaxSpriteSize() {
|
||||
if (family == GROUP) {
|
||||
@@ -4135,7 +4148,8 @@ public class PShape3D extends PShape {
|
||||
public void initIndices(int n) {
|
||||
indexCount = n;
|
||||
|
||||
glIndexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
//glIndexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glIndexBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glIndexBufferID);
|
||||
final int bufferSize = indexCount * PGraphicsOpenGL.SIZEOF_INT;
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, bufferSize, null, GL.GL_STATIC_DRAW);
|
||||
@@ -4314,7 +4328,8 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
protected void createVertexBuffer() {
|
||||
glVertexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
//glVertexBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glVertexBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glVertexBufferID);
|
||||
final int bufferSize = vertexCount * 3 * PGraphicsOpenGL.SIZEOF_FLOAT;
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, bufferSize, null, glUsage);
|
||||
@@ -4331,7 +4346,8 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
protected void createColorBuffer() {
|
||||
glColorBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
//glColorBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glColorBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glColorBufferID);
|
||||
final int bufferSize = vertexCount * 4 * PGraphicsOpenGL.SIZEOF_FLOAT;
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, bufferSize, FloatBuffer.wrap(colors), glUsage);
|
||||
@@ -4345,7 +4361,8 @@ public class PShape3D extends PShape {
|
||||
|
||||
|
||||
protected void createNormalBuffer() {
|
||||
glNormalBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
//glNormalBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glNormalBufferID = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glNormalBufferID);
|
||||
final int bufferSize = vertexCount * 3 * PGraphicsOpenGL.SIZEOF_FLOAT;
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, bufferSize, null, glUsage);
|
||||
@@ -4368,7 +4385,8 @@ public class PShape3D extends PShape {
|
||||
}
|
||||
|
||||
for (int i = 0; i < numTexBuffers; i++) {
|
||||
glTexCoordBufferID[i] = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
//glTexCoordBufferID[i] = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glTexCoordBufferID[i] = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glTexCoordBufferID[i]);
|
||||
final int bufferSize = vertexCount * 2 * PGraphicsOpenGL.SIZEOF_FLOAT;
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, bufferSize, null, glUsage);
|
||||
@@ -4382,7 +4400,8 @@ public class PShape3D extends PShape {
|
||||
int t = numTexBuffers + i;
|
||||
deleteTexCoordBuffer(t);
|
||||
|
||||
glTexCoordBufferID[t] = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
//glTexCoordBufferID[t] = ogl.createGLResource(PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glTexCoordBufferID[t] = ogl.createVertexBufferObject();
|
||||
getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glTexCoordBufferID[t]);
|
||||
final int bufferSize = vertexCount * 2 * PGraphicsOpenGL.SIZEOF_FLOAT;
|
||||
getGl().glBufferData(GL.GL_ARRAY_BUFFER, bufferSize, null, glUsage);
|
||||
@@ -4421,7 +4440,7 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void deleteVertexBuffer() {
|
||||
if (glVertexBufferID != 0) {
|
||||
ogl.deleteGLResource(glVertexBufferID, PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
ogl.finalizeVertexBufferObject(glVertexBufferID);
|
||||
glVertexBufferID = 0;
|
||||
}
|
||||
}
|
||||
@@ -4429,7 +4448,8 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void deleteColorBuffer() {
|
||||
if (glColorBufferID != 0) {
|
||||
ogl.deleteGLResource(glColorBufferID, PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
ogl.finalizeVertexBufferObject(glColorBufferID);
|
||||
//ogl.deleteGLResource(glColorBufferID, PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glColorBufferID = 0;
|
||||
}
|
||||
}
|
||||
@@ -4437,7 +4457,8 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void deleteNormalBuffer() {
|
||||
if (glNormalBufferID != 0) {
|
||||
ogl.deleteGLResource(glNormalBufferID, PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
//ogl.deleteGLResource(glNormalBufferID, PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
ogl.finalizeVertexBufferObject(glNormalBufferID);
|
||||
glNormalBufferID = 0;
|
||||
}
|
||||
}
|
||||
@@ -4445,14 +4466,15 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void deleteIndexBuffer() {
|
||||
if (glIndexBufferID != 0) {
|
||||
ogl.deleteGLResource(glIndexBufferID, PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
ogl.finalizeVertexBufferObject(glIndexBufferID);
|
||||
//ogl.deleteGLResource(glIndexBufferID, PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glIndexBufferID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void deleteTexCoordBuffer() {
|
||||
if (glTexCoordBufferID != null) {
|
||||
if (glTexCoordBufferID != null) {
|
||||
for (int i = 0; i < glTexCoordBufferID.length; i++) {
|
||||
deleteTexCoordBuffer(i);
|
||||
}
|
||||
@@ -4462,7 +4484,8 @@ public class PShape3D extends PShape {
|
||||
|
||||
protected void deleteTexCoordBuffer(int idx) {
|
||||
if (glTexCoordBufferID[idx] != 0) {
|
||||
ogl.deleteGLResource(glTexCoordBufferID[idx], PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
ogl.finalizeVertexBufferObject(glTexCoordBufferID[idx]);
|
||||
//ogl.deleteGLResource(glTexCoordBufferID[idx], PGraphicsOpenGL.GL_VERTEX_BUFFER);
|
||||
glTexCoordBufferID[idx] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,21 +91,25 @@ public class PTexture implements PConstants {
|
||||
this.parent = parent;
|
||||
|
||||
ogl = (PGraphicsOpenGL)parent.g;
|
||||
ogl.registerPGLObject(this);
|
||||
|
||||
glID = 0;
|
||||
|
||||
init(width, height, (Parameters)params);
|
||||
}
|
||||
|
||||
|
||||
public void delete() {
|
||||
release();
|
||||
img = null;
|
||||
ogl.unregisterPGLObject(this);
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (glID != 0) {
|
||||
ogl.finalizeTextureObject(glID);
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void backup() {
|
||||
if (img != null) {
|
||||
img.loadPixels();
|
||||
@@ -124,6 +128,7 @@ public class PTexture implements PConstants {
|
||||
set(img.pixels);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -167,15 +172,16 @@ public class PTexture implements PConstants {
|
||||
|
||||
|
||||
public void resize(int wide, int high) {
|
||||
// Marking the texture object as finalized so it is deleted
|
||||
// when creating the new texture.
|
||||
release();
|
||||
|
||||
// Creating new texture with the appropriate size.
|
||||
PTexture tex = new PTexture(parent, wide, high, getParameters());
|
||||
|
||||
// Copying the contents of this texture into tex.
|
||||
tex.set(this);
|
||||
|
||||
// Releasing the opengl resources associated to "this".
|
||||
this.delete();
|
||||
|
||||
// Now, overwriting "this" with tex.
|
||||
copyObject(tex);
|
||||
|
||||
@@ -708,7 +714,9 @@ public class PTexture implements PConstants {
|
||||
release(); // Just in the case this object is being re-allocated.
|
||||
|
||||
getGl().glEnable(glTarget);
|
||||
glID = ogl.createGLResource(PGraphicsOpenGL.GL_TEXTURE_OBJECT);
|
||||
|
||||
glID = ogl.createTextureObject();
|
||||
|
||||
getGl().glBindTexture(glTarget, glID);
|
||||
getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_MIN_FILTER, glMinFilter);
|
||||
getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_MAG_FILTER, glMagFilter);
|
||||
@@ -733,13 +741,13 @@ public class PTexture implements PConstants {
|
||||
|
||||
|
||||
/**
|
||||
* Deletes the opengl texture object.
|
||||
* Marks the texture object for deletion.
|
||||
*/
|
||||
protected void release() {
|
||||
if (glID != 0) {
|
||||
ogl.deleteGLResource(glID, PGraphicsOpenGL.GL_TEXTURE_OBJECT);
|
||||
protected void release() {
|
||||
if (glID != 0) {
|
||||
ogl.finalizeTextureObject(glID);
|
||||
glID = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user