Merge branch 'master' of github.com:processing/processing

This commit is contained in:
Ben Fry
2013-04-21 12:31:33 -04:00
8 changed files with 344 additions and 293 deletions
+19 -24
View File
@@ -47,10 +47,7 @@ import java.util.HashMap;
* @author Andres Colubri
*/
class FontTexture implements PConstants {
protected PApplet parent;
protected PGraphicsOpenGL pg;
protected PGL pgl;
protected PFont font;
protected boolean is3D;
protected int maxTexWidth;
@@ -65,15 +62,12 @@ class FontTexture implements PConstants {
protected TextureInfo[] glyphTexinfos;
protected HashMap<PFont.Glyph, TextureInfo> texinfoMap;
public FontTexture(PApplet parent, PFont font, int maxw, int maxh,
public FontTexture(PGraphicsOpenGL pg, PFont font, int maxw, int maxh,
boolean is3D) {
this.parent = parent;
this.font = font;
pg = (PGraphicsOpenGL)parent.g;
pgl = pg.pgl;
pgl = PGraphicsOpenGL.pgl;
this.is3D = is3D;
initTexture(maxw, maxh);
initTexture(pg, font, maxw, maxh);
}
@@ -83,14 +77,14 @@ class FontTexture implements PConstants {
}
protected void initTexture(int w, int h) {
protected void initTexture(PGraphicsOpenGL pg, PFont font, int w, int h) {
maxTexWidth = w;
maxTexHeight = h;
currentTex = -1;
lastTex = -1;
addTexture();
addTexture(pg);
offsetX = 0;
offsetY = 0;
@@ -98,11 +92,11 @@ class FontTexture implements PConstants {
texinfoMap = new HashMap<PFont.Glyph, TextureInfo>();
glyphTexinfos = new TextureInfo[font.getGlyphCount()];
addAllGlyphsToTexture();
addAllGlyphsToTexture(pg, font);
}
public boolean addTexture() {
public boolean addTexture(PGraphicsOpenGL pg) {
int w, h;
boolean resize;
@@ -122,15 +116,15 @@ class FontTexture implements PConstants {
if (is3D) {
// Bilinear sampling ensures that the texture doesn't look pixelated
// either when it is magnified or minified...
tex = new Texture(parent, w, h,
new Texture.Parameters(ARGB, Texture.BILINEAR, false));
tex = new Texture(w, h, new Texture.Parameters(ARGB, Texture.BILINEAR,
false));
} else {
// ...however, the effect of bilinear sampling is to add some blurriness
// to the text in its original size. In 2D, we assume that text will be
// shown at its original size, so linear sampling is chosen instead (which
// only affects minimized text).
tex = new Texture(parent, w, h,
new Texture.Parameters(ARGB, Texture.LINEAR, false));
tex = new Texture(w, h, new Texture.Parameters(ARGB, Texture.LINEAR,
false));
}
if (textures == null) {
@@ -205,10 +199,10 @@ class FontTexture implements PConstants {
// Add all the current glyphs to opengl texture.
public void addAllGlyphsToTexture() {
public void addAllGlyphsToTexture(PGraphicsOpenGL pg, PFont font) {
// loop over current glyphs.
for (int i = 0; i < font.getGlyphCount(); i++) {
addToTexture(i, font.getGlyph(i));
addToTexture(pg, i, font.getGlyph(i));
}
}
@@ -230,12 +224,12 @@ class FontTexture implements PConstants {
}
public TextureInfo addToTexture(PFont.Glyph glyph) {
public TextureInfo addToTexture(PGraphicsOpenGL pg, PFont.Glyph glyph) {
int n = glyphTexinfos.length;
if (n == 0) {
glyphTexinfos = new TextureInfo[1];
}
addToTexture(n, glyph);
addToTexture(pg, n, glyph);
return glyphTexinfos[n];
}
@@ -249,7 +243,8 @@ class FontTexture implements PConstants {
}
if (outdated) {
for (int i = 0; i < textures.length; i++) {
pg.removeTextureObject(textures[i].glName, textures[i].context);
PGraphicsOpenGL.removeTextureObject(textures[i].glName,
textures[i].context);
textures[i].glName = 0;
}
}
@@ -257,7 +252,7 @@ class FontTexture implements PConstants {
}
// Adds this glyph to the opengl texture in PFont.
protected void addToTexture(int idx, PFont.Glyph glyph) {
protected void addToTexture(PGraphicsOpenGL pg, int idx, PFont.Glyph glyph) {
// We add one pixel to avoid issues when sampling the font texture at
// fractional screen positions. I.e.: the pixel on the screen only contains
// half of the font rectangle, so it would sample half of the color from the
@@ -310,7 +305,7 @@ class FontTexture implements PConstants {
boolean resized = false;
if (offsetY + lineHeight > textures[currentTex].glHeight) {
// We run out of space in the current texture, so we add a new texture:
resized = addTexture();
resized = addTexture(pg);
if (resized) {
// Because the current texture has been resized, we need to
// update the UV coordinates of all the glyphs associated to it:
+58 -57
View File
@@ -40,8 +40,6 @@ import java.nio.IntBuffer;
*/
public class FrameBuffer implements PConstants {
protected PApplet parent;
protected PGraphicsOpenGL pg;
protected PGL pgl;
protected int context; // The context that created this framebuffer.
@@ -68,25 +66,17 @@ public class FrameBuffer implements PConstants {
protected IntBuffer pixelBuffer;
FrameBuffer(PApplet parent, int w, int h) {
this(parent, w, h, 1, 1, 0, 0, false, false);
}
FrameBuffer(PApplet parent, int w, int h, boolean screen) {
this(parent, w, h, 1, 1, 0, 0, false, screen);
}
FrameBuffer(PApplet parent) {
this.parent = parent;
pg = (PGraphicsOpenGL)parent.g;
pgl = pg.pgl;
FrameBuffer() {
pgl = PGraphicsOpenGL.pgl;
context = pgl.createEmptyContext();
}
FrameBuffer(PApplet parent, int w, int h, int samples, int colorBuffers,
FrameBuffer(int w, int h, int samples, int colorBuffers,
int depthBits, int stencilBits, boolean packedDepthStencil,
boolean screen) {
this(parent);
this();
glFbo = 0;
glDepth = 0;
@@ -146,24 +136,35 @@ public class FrameBuffer implements PConstants {
}
FrameBuffer(int w, int h) {
this(w, h, 1, 1, 0, 0, false, false);
}
FrameBuffer(int w, int h, boolean screen) {
this(w, h, 1, 1, 0, 0, false, screen);
}
@Override
protected void finalize() throws Throwable {
try {
PApplet.println("finalize FBO");
if (!screenFb) {
if (glFbo != 0) {
pg.finalizeFrameBufferObject(glFbo, context);
PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context);
}
if (glDepth != 0) {
pg.finalizeRenderBufferObject(glDepth, context);
PGraphicsOpenGL.finalizeRenderBufferObject(glDepth, context);
}
if (glStencil != 0) {
pg.finalizeRenderBufferObject(glStencil, context);
PGraphicsOpenGL.finalizeRenderBufferObject(glStencil, context);
}
if (glMultisample != 0) {
pg.finalizeRenderBufferObject(glMultisample, context);
PGraphicsOpenGL.finalizeRenderBufferObject(glMultisample, context);
}
if (glDepthStencil != 0) {
pg.finalizeRenderBufferObject(glDepthStencil, context);
PGraphicsOpenGL.finalizeRenderBufferObject(glDepthStencil, context);
}
}
} finally {
@@ -172,15 +173,15 @@ public class FrameBuffer implements PConstants {
}
public void clear() {
pg.pushFramebuffer();
pg.setFramebuffer(this);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
pgl.clearDepth(1);
pgl.clearStencil(0);
pgl.clearColor(0, 0, 0, 0);
pgl.clear(PGL.DEPTH_BUFFER_BIT |
PGL.STENCIL_BUFFER_BIT |
PGL.COLOR_BUFFER_BIT);
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
}
public void copy(FrameBuffer dest, FrameBuffer current) {
@@ -201,7 +202,7 @@ public class FrameBuffer implements PConstants {
noDepth = true;
}
public void finish() {
public void finish(PGraphicsOpenGL pg) {
if (noDepth) {
// No need to clear depth buffer because depth testing was disabled.
if (pg.getHint(ENABLE_DEPTH_TEST)) {
@@ -271,8 +272,8 @@ public class FrameBuffer implements PConstants {
colorBufferTex[i] = textures[i];
}
pg.pushFramebuffer();
pg.setFramebuffer(this);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
// Making sure nothing is attached.
for (int i = 0; i < numColorBuffers; i++) {
@@ -288,7 +289,7 @@ public class FrameBuffer implements PConstants {
pgl.validateFramebuffer();
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
}
@@ -300,8 +301,8 @@ public class FrameBuffer implements PConstants {
colorBufferTex[i1] = tmp;
}
pg.pushFramebuffer();
pg.setFramebuffer(this);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
for (int i = 0; i < numColorBuffers; i++) {
pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
colorBufferTex[i].glTarget,
@@ -309,7 +310,7 @@ public class FrameBuffer implements PConstants {
}
pgl.validateFramebuffer();
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
}
@@ -345,7 +346,7 @@ public class FrameBuffer implements PConstants {
glFbo = 0;
} else {
//create the FBO object...
glFbo = pg.createFrameBufferObject(context);
glFbo = PGraphicsOpenGL.createFrameBufferObject(context);
// ... and then create the rest of the stuff.
if (multisample) {
@@ -370,23 +371,23 @@ public class FrameBuffer implements PConstants {
if (screenFb) return;
if (glFbo != 0) {
pg.finalizeFrameBufferObject(glFbo, context);
PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context);
glFbo = 0;
}
if (glDepth != 0) {
pg.finalizeRenderBufferObject(glDepth, context);
PGraphicsOpenGL.finalizeRenderBufferObject(glDepth, context);
glDepth = 0;
}
if (glStencil != 0) {
pg.finalizeRenderBufferObject(glStencil, context);
PGraphicsOpenGL.finalizeRenderBufferObject(glStencil, context);
glStencil = 0;
}
if (glMultisample != 0) {
pg.finalizeRenderBufferObject(glMultisample, context);
PGraphicsOpenGL.finalizeRenderBufferObject(glMultisample, context);
glMultisample = 0;
}
if (glDepthStencil != 0) {
pg.finalizeRenderBufferObject(glDepthStencil, context);
PGraphicsOpenGL.finalizeRenderBufferObject(glDepthStencil, context);
glDepthStencil = 0;
}
}
@@ -397,11 +398,11 @@ public class FrameBuffer implements PConstants {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
pg.removeFrameBufferObject(glFbo, context);
pg.removeRenderBufferObject(glDepth, context);
pg.removeRenderBufferObject(glStencil, context);
pg.removeRenderBufferObject(glDepthStencil, context);
pg.removeRenderBufferObject(glMultisample, context);
PGraphicsOpenGL.removeFrameBufferObject(glFbo, context);
PGraphicsOpenGL.removeRenderBufferObject(glDepth, context);
PGraphicsOpenGL.removeRenderBufferObject(glStencil, context);
PGraphicsOpenGL.removeRenderBufferObject(glDepthStencil, context);
PGraphicsOpenGL.removeRenderBufferObject(glMultisample, context);
glFbo = 0;
glDepth = 0;
@@ -420,17 +421,17 @@ public class FrameBuffer implements PConstants {
protected void createColorBufferMultisample() {
if (screenFb) return;
pg.pushFramebuffer();
pg.setFramebuffer(this);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
glMultisample = pg.createRenderBufferObject(context);
glMultisample = PGraphicsOpenGL.createRenderBufferObject(context);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
PGL.RGBA8, width, height);
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0,
PGL.RENDERBUFFER, glMultisample);
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
}
@@ -441,10 +442,10 @@ public class FrameBuffer implements PConstants {
throw new RuntimeException("PFramebuffer: size undefined.");
}
pg.pushFramebuffer();
pg.setFramebuffer(this);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
glDepthStencil = pg.createRenderBufferObject(context);
glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
if (multisample) {
@@ -460,7 +461,7 @@ public class FrameBuffer implements PConstants {
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
PGL.RENDERBUFFER, glDepthStencil);
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
}
@@ -471,10 +472,10 @@ public class FrameBuffer implements PConstants {
throw new RuntimeException("PFramebuffer: size undefined.");
}
pg.pushFramebuffer();
pg.setFramebuffer(this);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
glDepth = pg.createRenderBufferObject(context);
glDepth = PGraphicsOpenGL.createRenderBufferObject(context);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
int glConst = PGL.DEPTH_COMPONENT16;
@@ -496,7 +497,7 @@ public class FrameBuffer implements PConstants {
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
PGL.RENDERBUFFER, glDepth);
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
}
@@ -507,10 +508,10 @@ public class FrameBuffer implements PConstants {
throw new RuntimeException("PFramebuffer: size undefined.");
}
pg.pushFramebuffer();
pg.setFramebuffer(this);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(this);
glStencil = pg.createRenderBufferObject(context);
glStencil = PGraphicsOpenGL.createRenderBufferObject(context);
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
int glConst = PGL.STENCIL_INDEX1;
@@ -531,7 +532,7 @@ public class FrameBuffer implements PConstants {
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
PGL.RENDERBUFFER, glStencil);
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
}
+4 -5
View File
@@ -693,7 +693,6 @@ public class PGL {
firstFrame = false;
GLProfile.shutdown();
}
@@ -951,7 +950,7 @@ public class PGL {
protected Texture wrapBackTexture() {
if (USE_JOGL_FBOLAYER) {
Texture tex = new Texture(pg.parent);
Texture tex = new Texture();
tex.init(pg.width, pg.height,
backTexAttach.getName(), GL.GL_TEXTURE_2D, GL.GL_RGBA,
backTexAttach.getWidth(), backTexAttach.getHeight(),
@@ -962,7 +961,7 @@ public class PGL {
pg.setCache(pg, tex);
return tex;
} else {
Texture tex = new Texture(pg.parent);
Texture tex = new Texture();
tex.init(pg.width, pg.height,
glColorTex.get(backTex), TEXTURE_2D, RGBA,
fboWidth, fboHeight, NEAREST, NEAREST,
@@ -977,7 +976,7 @@ public class PGL {
protected Texture wrapFrontTexture() {
if (USE_JOGL_FBOLAYER) {
Texture tex = new Texture(pg.parent);
Texture tex = new Texture();
tex.init(pg.width, pg.height,
backTexAttach.getName(), GL.GL_TEXTURE_2D, GL.GL_RGBA,
frontTexAttach.getWidth(), frontTexAttach.getHeight(),
@@ -987,7 +986,7 @@ public class PGL {
tex.colorBufferOf(pg);
return tex;
} else {
Texture tex = new Texture(pg.parent);
Texture tex = new Texture();
tex.init(pg.width, pg.height,
glColorTex.get(frontTex), TEXTURE_2D, RGBA,
fboWidth, fboHeight, NEAREST, NEAREST,
+142 -75
View File
@@ -34,7 +34,7 @@ import java.util.*;
*/
public class PGraphicsOpenGL extends PGraphics {
/** Interface between Processing and OpenGL */
public PGL pgl;
public static PGL pgl;
/** The main PApplet renderer. */
protected static PGraphicsOpenGL pgPrimary = null;
@@ -520,8 +520,8 @@ public class PGraphicsOpenGL extends PGraphics {
{ {-1, +1}, {-1, -1}, {+1, -1}, {+1, +1} };
/** To get data from OpenGL. */
protected IntBuffer intBuffer;
protected FloatBuffer floatBuffer;
static protected IntBuffer intBuffer;
static protected FloatBuffer floatBuffer;
//////////////////////////////////////////////////////////////
@@ -529,14 +529,19 @@ public class PGraphicsOpenGL extends PGraphics {
public PGraphicsOpenGL() {
pgl = new PGL(this);
if (pgl == null) {
pgl = new PGL(this);
}
if (tessellator == null) {
tessellator = new Tessellator();
}
intBuffer = PGL.allocateIntBuffer(2);
floatBuffer = PGL.allocateFloatBuffer(2);
if (intBuffer == null) {
intBuffer = PGL.allocateIntBuffer(2);
floatBuffer = PGL.allocateFloatBuffer(2);
}
viewport = PGL.allocateIntBuffer(4);
inGeo = newInGeometry(IMMEDIATE);
@@ -636,14 +641,52 @@ public class PGraphicsOpenGL extends PGraphics {
@Override
public void dispose() { // PGraphics
super.dispose();
deleteFinalizedGLResources();
deletePolyBuffers();
deleteLineBuffers();
deletePointBuffers();
deleteDefaultShaders();
pgl.deleteSurface();
deleteSurfaceTextures();
if (primarySurface) {
deleteDefaultShaders();
} else {
if (offscreenFramebuffer != null) {
offscreenFramebuffer.release();
}
if (multisampleFramebuffer != null) {
multisampleFramebuffer.release();
}
}
deleteFinalizedGLResources();
if (primarySurface) pgl.deleteSurface();
}
// @Override
@Override
protected void finalize() throws Throwable {
try {
deletePolyBuffers();
deleteLineBuffers();
deletePointBuffers();
deleteSurfaceTextures();
if (!primarySurface) {
PApplet.println("finalize offscreen surface");
if (offscreenFramebuffer != null) {
offscreenFramebuffer.release();
offscreenFramebuffer = null;
}
if (multisampleFramebuffer != null) {
multisampleFramebuffer.release();
multisampleFramebuffer = null;
}
}
} finally {
super.finalize();
}
}
protected void setFlushMode(int mode) {
flushMode = mode;
@@ -673,7 +716,7 @@ public class PGraphicsOpenGL extends PGraphics {
// RESOURCE HANDLING
protected class GLResource {
protected static class GLResource {
int id;
int context;
@@ -700,7 +743,7 @@ public class PGraphicsOpenGL extends PGraphics {
// Texture Objects -----------------------------------------------------------
protected int createTextureObject(int context) {
protected static int createTextureObject(int context) {
deleteFinalizedTextureObjects();
pgl.genTextures(1, intBuffer);
@@ -714,7 +757,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected void deleteTextureObject(int id, int context) {
protected static void deleteTextureObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glTextureObjects.containsKey(res)) {
intBuffer.put(0, id);
@@ -723,7 +766,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void deleteAllTextureObjects() {
protected static void deleteAllTextureObjects() {
for (GLResource res : glTextureObjects.keySet()) {
intBuffer.put(0, res.id);
if (pgl.threadIsCurrent()) pgl.deleteTextures(1, intBuffer);
@@ -732,14 +775,14 @@ public class PGraphicsOpenGL extends PGraphics {
}
// This is synchronized because it is called from the GC thread.
synchronized protected void finalizeTextureObject(int id, int context) {
synchronized protected static void finalizeTextureObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glTextureObjects.containsKey(res)) {
glTextureObjects.put(res, true);
}
}
protected void deleteFinalizedTextureObjects() {
protected static void deleteFinalizedTextureObjects() {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glTextureObjects.keySet()) {
@@ -753,9 +796,10 @@ public class PGraphicsOpenGL extends PGraphics {
for (GLResource res : finalized) {
glTextureObjects.remove(res);
}
if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " texture objects, " + glTextureObjects.size() + " remaining");
}
protected void removeTextureObject(int id, int context) {
protected static void removeTextureObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glTextureObjects.containsKey(res)) {
glTextureObjects.remove(res);
@@ -764,7 +808,7 @@ public class PGraphicsOpenGL extends PGraphics {
// Vertex Buffer Objects -----------------------------------------------------
protected int createVertexBufferObject(int context) {
protected static int createVertexBufferObject(int context) {
deleteFinalizedVertexBufferObjects();
pgl.genBuffers(1, intBuffer);
@@ -778,7 +822,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected void deleteVertexBufferObject(int id, int context) {
protected static void deleteVertexBufferObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glVertexBuffers.containsKey(res)) {
intBuffer.put(0, id);
@@ -787,7 +831,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void deleteAllVertexBufferObjects() {
protected static void deleteAllVertexBufferObjects() {
for (GLResource res : glVertexBuffers.keySet()) {
intBuffer.put(0, res.id);
if (pgl.threadIsCurrent()) pgl.deleteBuffers(1, intBuffer);
@@ -796,14 +840,14 @@ public class PGraphicsOpenGL extends PGraphics {
}
// This is synchronized because it is called from the GC thread.
synchronized protected void finalizeVertexBufferObject(int id, int context) {
synchronized static protected void finalizeVertexBufferObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glVertexBuffers.containsKey(res)) {
glVertexBuffers.put(res, true);
}
}
protected void deleteFinalizedVertexBufferObjects() {
protected static void deleteFinalizedVertexBufferObjects() {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glVertexBuffers.keySet()) {
@@ -817,9 +861,10 @@ public class PGraphicsOpenGL extends PGraphics {
for (GLResource res : finalized) {
glVertexBuffers.remove(res);
}
if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " vertex buffer objects, " + glVertexBuffers.size() + " remaining");
}
protected void removeVertexBufferObject(int id, int context) {
protected static void removeVertexBufferObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glVertexBuffers.containsKey(res)) {
glVertexBuffers.remove(res);
@@ -828,7 +873,7 @@ public class PGraphicsOpenGL extends PGraphics {
// FrameBuffer Objects -------------------------------------------------------
protected int createFrameBufferObject(int context) {
protected static int createFrameBufferObject(int context) {
deleteFinalizedFrameBufferObjects();
pgl.genFramebuffers(1, intBuffer);
@@ -842,7 +887,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected void deleteFrameBufferObject(int id, int context) {
protected static void deleteFrameBufferObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glFrameBuffers.containsKey(res)) {
intBuffer.put(0, id);
@@ -851,7 +896,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void deleteAllFrameBufferObjects() {
protected static void deleteAllFrameBufferObjects() {
for (GLResource res : glFrameBuffers.keySet()) {
intBuffer.put(0, res.id);
if (pgl.threadIsCurrent()) pgl.deleteFramebuffers(1, intBuffer);
@@ -860,30 +905,33 @@ public class PGraphicsOpenGL extends PGraphics {
}
// This is synchronized because it is called from the GC thread.
synchronized protected void finalizeFrameBufferObject(int id, int context) {
synchronized static protected void finalizeFrameBufferObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glFrameBuffers.containsKey(res)) {
glFrameBuffers.put(res, true);
}
}
protected void deleteFinalizedFrameBufferObjects() {
protected static void deleteFinalizedFrameBufferObjects() {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glFrameBuffers.keySet()) {
if (glFrameBuffers.get(res)) {
finalized.add(res);
intBuffer.put(0, res.id);
if (pgl.threadIsCurrent()) pgl.deleteFramebuffers(1, intBuffer);
if (pgl.threadIsCurrent()) {
pgl.deleteFramebuffers(1, intBuffer);
}
}
}
for (GLResource res : finalized) {
glFrameBuffers.remove(res);
}
if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " framebuffer objects, " + glFrameBuffers.size() + " remaining");
}
protected void removeFrameBufferObject(int id, int context) {
protected static void removeFrameBufferObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glFrameBuffers.containsKey(res)) {
glFrameBuffers.remove(res);
@@ -892,7 +940,7 @@ public class PGraphicsOpenGL extends PGraphics {
// RenderBuffer Objects ------------------------------------------------------
protected int createRenderBufferObject(int context) {
protected static int createRenderBufferObject(int context) {
deleteFinalizedRenderBufferObjects();
pgl.genRenderbuffers(1, intBuffer);
@@ -906,7 +954,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected void deleteRenderBufferObject(int id, int context) {
protected static void deleteRenderBufferObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glRenderBuffers.containsKey(res)) {
intBuffer.put(0, id);
@@ -915,7 +963,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void deleteAllRenderBufferObjects() {
protected static void deleteAllRenderBufferObjects() {
for (GLResource res : glRenderBuffers.keySet()) {
intBuffer.put(0, res.id);
if (pgl.threadIsCurrent()) pgl.deleteRenderbuffers(1, intBuffer);
@@ -924,14 +972,14 @@ public class PGraphicsOpenGL extends PGraphics {
}
// This is synchronized because it is called from the GC thread.
synchronized protected void finalizeRenderBufferObject(int id, int context) {
synchronized static protected void finalizeRenderBufferObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glRenderBuffers.containsKey(res)) {
glRenderBuffers.put(res, true);
}
}
protected void deleteFinalizedRenderBufferObjects() {
protected static void deleteFinalizedRenderBufferObjects() {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glRenderBuffers.keySet()) {
@@ -945,9 +993,10 @@ public class PGraphicsOpenGL extends PGraphics {
for (GLResource res : finalized) {
glRenderBuffers.remove(res);
}
if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " renderbuffer objects, " + glRenderBuffers.size() + " remaining");
}
protected void removeRenderBufferObject(int id, int context) {
protected static void removeRenderBufferObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glRenderBuffers.containsKey(res)) {
glRenderBuffers.remove(res);
@@ -956,7 +1005,7 @@ public class PGraphicsOpenGL extends PGraphics {
// GLSL Program Objects ------------------------------------------------------
protected int createGLSLProgramObject(int context) {
protected static int createGLSLProgramObject(int context) {
deleteFinalizedGLSLProgramObjects();
int id = pgl.createProgram();
@@ -969,7 +1018,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected void deleteGLSLProgramObject(int id, int context) {
protected static void deleteGLSLProgramObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glslPrograms.containsKey(res)) {
if (pgl.threadIsCurrent()) pgl.deleteProgram(res.id);
@@ -977,7 +1026,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void deleteAllGLSLProgramObjects() {
protected static void deleteAllGLSLProgramObjects() {
for (GLResource res : glslPrograms.keySet()) {
if (pgl.threadIsCurrent()) pgl.deleteProgram(res.id);
}
@@ -985,14 +1034,14 @@ public class PGraphicsOpenGL extends PGraphics {
}
// This is synchronized because it is called from the GC thread.
synchronized protected void finalizeGLSLProgramObject(int id, int context) {
synchronized static protected void finalizeGLSLProgramObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glslPrograms.containsKey(res)) {
glslPrograms.put(res, true);
}
}
protected void deleteFinalizedGLSLProgramObjects() {
protected static void deleteFinalizedGLSLProgramObjects() {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glslPrograms.keySet()) {
@@ -1005,9 +1054,10 @@ public class PGraphicsOpenGL extends PGraphics {
for (GLResource res : finalized) {
glslPrograms.remove(res);
}
if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " GLSL program objects, " + glslPrograms.size() + " remaining");
}
protected void removeGLSLProgramObject(int id, int context) {
protected static void removeGLSLProgramObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glslPrograms.containsKey(res)) {
glslPrograms.remove(res);
@@ -1016,7 +1066,7 @@ public class PGraphicsOpenGL extends PGraphics {
// GLSL Vertex Shader Objects ------------------------------------------------
protected int createGLSLVertShaderObject(int context) {
protected static int createGLSLVertShaderObject(int context) {
deleteFinalizedGLSLVertShaderObjects();
int id = pgl.createShader(PGL.VERTEX_SHADER);
@@ -1029,7 +1079,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected void deleteGLSLVertShaderObject(int id, int context) {
protected static void deleteGLSLVertShaderObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glslVertexShaders.containsKey(res)) {
if (pgl.threadIsCurrent()) pgl.deleteShader(res.id);
@@ -1037,7 +1087,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void deleteAllGLSLVertShaderObjects() {
protected static void deleteAllGLSLVertShaderObjects() {
for (GLResource res : glslVertexShaders.keySet()) {
if (pgl.threadIsCurrent()) pgl.deleteShader(res.id);
}
@@ -1045,7 +1095,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
// This is synchronized because it is called from the GC thread.
synchronized protected void finalizeGLSLVertShaderObject(int id,
synchronized static protected void finalizeGLSLVertShaderObject(int id,
int context) {
GLResource res = new GLResource(id, context);
if (glslVertexShaders.containsKey(res)) {
@@ -1053,7 +1103,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void deleteFinalizedGLSLVertShaderObjects() {
protected static void deleteFinalizedGLSLVertShaderObjects() {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glslVertexShaders.keySet()) {
@@ -1066,9 +1116,10 @@ public class PGraphicsOpenGL extends PGraphics {
for (GLResource res : finalized) {
glslVertexShaders.remove(res);
}
if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " GLSL vertex shader objects, " + glslVertexShaders.size() + " remaining");
}
protected void removeGLSLVertShaderObject(int id, int context) {
protected static void removeGLSLVertShaderObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glslVertexShaders.containsKey(res)) {
glslVertexShaders.remove(res);
@@ -1077,7 +1128,7 @@ public class PGraphicsOpenGL extends PGraphics {
// GLSL Fragment Shader Objects ----------------------------------------------
protected int createGLSLFragShaderObject(int context) {
protected static int createGLSLFragShaderObject(int context) {
deleteFinalizedGLSLFragShaderObjects();
int id = pgl.createShader(PGL.FRAGMENT_SHADER);
@@ -1090,7 +1141,7 @@ public class PGraphicsOpenGL extends PGraphics {
return id;
}
protected void deleteGLSLFragShaderObject(int id, int context) {
protected static void deleteGLSLFragShaderObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glslFragmentShaders.containsKey(res)) {
if (pgl.threadIsCurrent()) pgl.deleteShader(res.id);
@@ -1098,7 +1149,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void deleteAllGLSLFragShaderObjects() {
protected static void deleteAllGLSLFragShaderObjects() {
for (GLResource res : glslFragmentShaders.keySet()) {
if (pgl.threadIsCurrent()) pgl.deleteShader(res.id);
}
@@ -1106,7 +1157,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
// This is synchronized because it is called from the GC thread.
synchronized protected void finalizeGLSLFragShaderObject(int id,
synchronized static protected void finalizeGLSLFragShaderObject(int id,
int context) {
GLResource res = new GLResource(id, context);
if (glslFragmentShaders.containsKey(res)) {
@@ -1114,7 +1165,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void deleteFinalizedGLSLFragShaderObjects() {
protected static void deleteFinalizedGLSLFragShaderObjects() {
Set<GLResource> finalized = new HashSet<GLResource>();
for (GLResource res : glslFragmentShaders.keySet()) {
@@ -1127,9 +1178,10 @@ public class PGraphicsOpenGL extends PGraphics {
for (GLResource res : finalized) {
glslFragmentShaders.remove(res);
}
if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " GLSL fragment shader objects, " + glslFragmentShaders.size() + " remaining");
}
protected void removeGLSLFragShaderObject(int id, int context) {
protected static void removeGLSLFragShaderObject(int id, int context) {
GLResource res = new GLResource(id, context);
if (glslFragmentShaders.containsKey(res)) {
glslFragmentShaders.remove(res);
@@ -1138,7 +1190,7 @@ public class PGraphicsOpenGL extends PGraphics {
// All OpenGL resources ------------------------------------------------------
protected void deleteFinalizedGLResources() {
protected static void deleteFinalizedGLResources() {
deleteFinalizedTextureObjects();
deleteFinalizedVertexBufferObjects();
deleteFinalizedFrameBufferObjects();
@@ -1154,7 +1206,7 @@ public class PGraphicsOpenGL extends PGraphics {
// FRAMEBUFFERS
protected void pushFramebuffer() {
protected static void pushFramebuffer() {
if (fbStackDepth == FB_STACK_DEPTH) {
throw new RuntimeException("Too many pushFramebuffer calls");
}
@@ -1163,7 +1215,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected void setFramebuffer(FrameBuffer fbo) {
protected static void setFramebuffer(FrameBuffer fbo) {
if (currentFramebuffer != fbo) {
currentFramebuffer = fbo;
currentFramebuffer.bind();
@@ -1171,14 +1223,14 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected void popFramebuffer() {
protected static void popFramebuffer() {
if (fbStackDepth == 0) {
throw new RuntimeException("popFramebuffer call is unbalanced.");
}
fbStackDepth--;
FrameBuffer fbo = fbStack[fbStackDepth];
if (currentFramebuffer != fbo) {
currentFramebuffer.finish();
currentFramebuffer.finish(pgPrimary);
currentFramebuffer = fbo;
currentFramebuffer.bind();
}
@@ -1214,19 +1266,19 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, null, PGL.STATIC_DRAW);
glPolyAmbient = pgPrimary.createVertexBufferObject(polyBuffersContext);
glPolyAmbient = createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolySpecular = pgPrimary.createVertexBufferObject(polyBuffersContext);
glPolySpecular = createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolyEmissive = pgPrimary.createVertexBufferObject(polyBuffersContext);
glPolyEmissive = createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW);
glPolyShininess = pgPrimary.createVertexBufferObject(polyBuffersContext);
glPolyShininess = createVertexBufferObject(polyBuffersContext);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess);
pgl.bufferData(PGL.ARRAY_BUFFER, sizef, null, PGL.STATIC_DRAW);
@@ -3224,12 +3276,12 @@ public class PGraphicsOpenGL extends PGraphics {
float x, float y) {
textTex = pgPrimary.getFontTexture(textFont);
if (textTex == null) {
textTex = new FontTexture(parent, textFont, maxTextureSize,
maxTextureSize, is3D());
textTex = new FontTexture(pgPrimary, textFont, maxTextureSize,
maxTextureSize, is3D());
pgPrimary.setFontTexture(textFont, textTex);
} else {
if (textTex.contextIsOutdated()) {
textTex = new FontTexture(parent, textFont,
textTex = new FontTexture(pgPrimary, textFont,
PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize),
PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), is3D());
pgPrimary.setFontTexture(textFont, textTex);
@@ -3288,7 +3340,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (tinfo == null) {
// Adding new glyph to the font texture.
tinfo = textTex.addToTexture(glyph);
tinfo = textTex.addToTexture(pgPrimary, glyph);
}
if (textMode == MODEL) {
@@ -5247,13 +5299,13 @@ public class PGraphicsOpenGL extends PGraphics {
if (texture == null || texture.contextIsOutdated()) {
Texture.Parameters params = new Texture.Parameters(ARGB,
sampling, mipmap);
texture = new Texture(parent, width, height, params);
texture = new Texture(width, height, params);
texture.invertedY(true);
texture.colorBufferOf(this);
pgPrimary.setCache(this, texture);
if (!primarySurface) {
ptexture = new Texture(parent, width, height, params);
ptexture = new Texture(width, height, params);
ptexture.invertedY(true);
ptexture.colorBufferOf(this);
}
@@ -5365,7 +5417,7 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.needFBOLayer();
loadTexture();
if (filterTexture == null || filterTexture.contextIsOutdated()) {
filterTexture = new Texture(parent, texture.width, texture.height,
filterTexture = new Texture(texture.width, texture.height,
texture.getParameters());
filterTexture.invertedY(true);
filterImage = wrapTexture(filterTexture);
@@ -5684,7 +5736,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (img.parent == null) {
img.parent = parent;
}
Texture tex = new Texture(img.parent, img.width, img.height, params);
Texture tex = new Texture(/*img.parent,*/ img.width, img.height, params);
pgPrimary.setCache(img, tex);
return tex;
}
@@ -5736,6 +5788,21 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected void deleteSurfaceTextures() {
if (texture != null) {
texture.release();
}
if (ptexture != null) {
ptexture.release();
}
if (filterTexture != null) {
filterTexture.release();
}
}
protected boolean checkGLThread() {
if (pgl.threadIsCurrent()) {
return true;
@@ -5783,11 +5850,11 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.beginDraw(clearColorBuffer);
if (drawFramebuffer == null) {
drawFramebuffer = new FrameBuffer(parent, width, height, true);
drawFramebuffer = new FrameBuffer(width, height, true);
}
drawFramebuffer.setFBO(pgl.getDrawFramebuffer());
if (readFramebuffer == null) {
readFramebuffer = new FrameBuffer(parent, width, height, true);
readFramebuffer = new FrameBuffer(width, height, true);
}
readFramebuffer.setFBO(pgl.getReadFramebuffer());
if (currentFramebuffer == null) {
@@ -5832,7 +5899,7 @@ public class PGraphicsOpenGL extends PGraphics {
packedDepthStencilSupported;
if (PGraphicsOpenGL.fboMultisampleSupported && 1 < quality) {
multisampleFramebuffer =
new FrameBuffer(parent, texture.glWidth, texture.glHeight, quality, 0,
new FrameBuffer(texture.glWidth, texture.glHeight, quality, 0,
depthBits, stencilBits, packed, false);
multisampleFramebuffer.clear();
@@ -5842,13 +5909,13 @@ public class PGraphicsOpenGL extends PGraphics {
// to doesn't need depth and stencil buffers since they are part of the
// multisampled framebuffer.
offscreenFramebuffer =
new FrameBuffer(parent, texture.glWidth, texture.glHeight, 1, 1, 0, 0,
new FrameBuffer(texture.glWidth, texture.glHeight, 1, 1, 0, 0,
false, false);
} else {
quality = 0;
offscreenFramebuffer =
new FrameBuffer(parent, texture.glWidth, texture.glHeight, 1, 1,
new FrameBuffer(texture.glWidth, texture.glHeight, 1, 1,
depthBits, stencilBits, packed, false);
offscreenMultisample = false;
}
+18 -17
View File
@@ -81,10 +81,11 @@ public class PShader {
protected int firstTexUnit;
protected int lastTexUnit;
// Direct buffers to pass shader dat to GL
// Direct buffers to pass shader data to GL
protected IntBuffer intBuffer;
protected FloatBuffer floatBuffer;
public PShader() {
parent = null;
pgMain = null;
@@ -109,12 +110,11 @@ public class PShader {
}
public PShader(PApplet parent) {
this();
this.parent = parent;
pgMain = (PGraphicsOpenGL) parent.g;
pgl = pgMain.pgl;
pgl = PGraphicsOpenGL.pgl;
context = pgl.createEmptyContext();
}
@@ -130,7 +130,7 @@ public class PShader {
public PShader(PApplet parent, String vertFilename, String fragFilename) {
this.parent = parent;
pgMain = (PGraphicsOpenGL) parent.g;
pgl = pgMain.pgl;
pgl = PGraphicsOpenGL.pgl;
this.vertexURL = null;
this.fragmentURL = null;
@@ -145,6 +145,7 @@ public class PShader {
floatBuffer = PGL.allocateFloatBuffer(1);
}
/**
* @param vertURL network location of the vertex shader
* @param fragURL network location of the fragment shader
@@ -152,7 +153,7 @@ public class PShader {
public PShader(PApplet parent, URL vertURL, URL fragURL) {
this.parent = parent;
pgMain = (PGraphicsOpenGL) parent.g;
pgl = pgMain.pgl;
pgl = PGraphicsOpenGL.pgl;
this.vertexURL = vertURL;
this.fragmentURL = fragURL;
@@ -172,13 +173,13 @@ public class PShader {
protected void finalize() throws Throwable {
try {
if (glVertex != 0) {
pgMain.finalizeGLSLVertShaderObject(glVertex, context);
PGraphicsOpenGL.finalizeGLSLVertShaderObject(glVertex, context);
}
if (glFragment != 0) {
pgMain.finalizeGLSLFragShaderObject(glFragment, context);
PGraphicsOpenGL.finalizeGLSLFragShaderObject(glFragment, context);
}
if (glProgram != 0) {
pgMain.finalizeGLSLProgramObject(glProgram, context);
PGraphicsOpenGL.finalizeGLSLProgramObject(glProgram, context);
}
} finally {
super.finalize();
@@ -698,7 +699,7 @@ public class PShader {
protected void init() {
if (glProgram == 0 || contextIsOutdated()) {
context = pgl.getCurrentContext();
glProgram = pgMain.createGLSLProgramObject(context);
glProgram = PGraphicsOpenGL.createGLSLProgramObject(context);
boolean hasVert = false;
if (vertexFilename != null) {
@@ -761,9 +762,9 @@ public class PShader {
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
pgMain.removeGLSLProgramObject(glProgram, context);
pgMain.removeGLSLVertShaderObject(glVertex, context);
pgMain.removeGLSLFragShaderObject(glFragment, context);
PGraphicsOpenGL.removeGLSLProgramObject(glProgram, context);
PGraphicsOpenGL.removeGLSLVertShaderObject(glVertex, context);
PGraphicsOpenGL.removeGLSLFragShaderObject(glFragment, context);
glProgram = 0;
glVertex = 0;
@@ -833,7 +834,7 @@ public class PShader {
* @param shaderSource a string containing the shader's code
*/
protected boolean compileVertexShader() {
glVertex = pgMain.createGLSLVertShaderObject(context);
glVertex = PGraphicsOpenGL.createGLSLVertShaderObject(context);
pgl.shaderSource(glVertex, vertexShaderSource);
pgl.compileShader(glVertex);
@@ -854,7 +855,7 @@ public class PShader {
* @param shaderSource a string containing the shader's code
*/
protected boolean compileFragmentShader() {
glFragment = pgMain.createGLSLFragShaderObject(context);
glFragment = PGraphicsOpenGL.createGLSLFragShaderObject(context);
pgl.shaderSource(glFragment, fragmentShaderSource);
pgl.compileShader(glFragment);
@@ -883,15 +884,15 @@ public class PShader {
protected void release() {
if (glVertex != 0) {
pgMain.deleteGLSLVertShaderObject(glVertex, context);
PGraphicsOpenGL.deleteGLSLVertShaderObject(glVertex, context);
glVertex = 0;
}
if (glFragment != 0) {
pgMain.deleteGLSLFragShaderObject(glFragment, context);
PGraphicsOpenGL.deleteGLSLFragShaderObject(glFragment, context);
glFragment = 0;
}
if (glProgram != 0) {
pgMain.deleteGLSLProgramObject(glProgram, context);
PGraphicsOpenGL.deleteGLSLProgramObject(glProgram, context);
glProgram = 0;
}
}
+69 -69
View File
@@ -274,7 +274,7 @@ public class PShapeOpenGL extends PShape {
public PShapeOpenGL(PApplet parent, int family) {
pg = (PGraphicsOpenGL)parent.g;
pgl = pg.pgl;
pgl = PGraphicsOpenGL.pgl;
context = pgl.createEmptyContext();
glPolyVertex = 0;
@@ -462,77 +462,77 @@ public class PShapeOpenGL extends PShape {
protected void finalizePolyBuffers() {
if (glPolyVertex != 0) {
pg.finalizeVertexBufferObject(glPolyVertex, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPolyVertex, context);
}
if (glPolyColor != 0) {
pg.finalizeVertexBufferObject(glPolyColor, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPolyColor, context);
}
if (glPolyNormal != 0) {
pg.finalizeVertexBufferObject(glPolyNormal, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPolyNormal, context);
}
if (glPolyTexcoord != 0) {
pg.finalizeVertexBufferObject(glPolyTexcoord, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPolyTexcoord, context);
}
if (glPolyAmbient != 0) {
pg.finalizeVertexBufferObject(glPolyAmbient, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPolyAmbient, context);
}
if (glPolySpecular != 0) {
pg.finalizeVertexBufferObject(glPolySpecular, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPolySpecular, context);
}
if (glPolyEmissive != 0) {
pg.finalizeVertexBufferObject(glPolyEmissive, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPolyEmissive, context);
}
if (glPolyShininess != 0) {
pg.finalizeVertexBufferObject(glPolyShininess, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPolyShininess, context);
}
if (glPolyIndex != 0) {
pg.finalizeVertexBufferObject(glPolyIndex, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPolyIndex, context);
}
}
protected void finalizeLineBuffers() {
if (glLineVertex != 0) {
pg.finalizeVertexBufferObject(glLineVertex, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glLineVertex, context);
}
if (glLineColor != 0) {
pg.finalizeVertexBufferObject(glLineColor, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glLineColor, context);
}
if (glLineAttrib != 0) {
pg.finalizeVertexBufferObject(glLineAttrib, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glLineAttrib, context);
}
if (glLineIndex != 0) {
pg.finalizeVertexBufferObject(glLineIndex, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glLineIndex, context);
}
}
protected void finalizePointBuffers() {
if (glPointVertex != 0) {
pg.finalizeVertexBufferObject(glPointVertex, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPointVertex, context);
}
if (glPointColor != 0) {
pg.finalizeVertexBufferObject(glPointColor, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPointColor, context);
}
if (glPointAttrib != 0) {
pg.finalizeVertexBufferObject(glPointAttrib, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPointAttrib, context);
}
if (glPointIndex != 0) {
pg.finalizeVertexBufferObject(glPointIndex, context);
PGraphicsOpenGL.finalizeVertexBufferObject(glPointIndex, context);
}
}
@@ -3241,50 +3241,50 @@ public class PShapeOpenGL extends PShape {
int sizei = size * PGL.SIZEOF_INT;
tessGeo.updatePolyVerticesBuffer();
glPolyVertex = pg.createVertexBufferObject(context);
glPolyVertex = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.polyVerticesBuffer,
PGL.STATIC_DRAW);
tessGeo.updatePolyColorsBuffer();
glPolyColor = pg.createVertexBufferObject(context);
glPolyColor = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.polyColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyNormalsBuffer();
glPolyNormal = pg.createVertexBufferObject(context);
glPolyNormal = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal);
pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef,
tessGeo.polyNormalsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyTexCoordsBuffer();
glPolyTexcoord = pg.createVertexBufferObject(context);
glPolyTexcoord = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
tessGeo.polyTexCoordsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyAmbientBuffer();
glPolyAmbient = pg.createVertexBufferObject(context);
glPolyAmbient = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.polyAmbientBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolySpecularBuffer();
glPolySpecular = pg.createVertexBufferObject(context);
glPolySpecular = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.polySpecularBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyEmissiveBuffer();
glPolyEmissive = pg.createVertexBufferObject(context);
glPolyEmissive = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.polyEmissiveBuffer, PGL.STATIC_DRAW);
tessGeo.updatePolyShininessBuffer();
glPolyShininess = pg.createVertexBufferObject(context);
glPolyShininess = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess);
pgl.bufferData(PGL.ARRAY_BUFFER, sizef,
tessGeo.polyShininessBuffer, PGL.STATIC_DRAW);
@@ -3292,7 +3292,7 @@ public class PShapeOpenGL extends PShape {
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
tessGeo.updatePolyIndicesBuffer();
glPolyIndex = pg.createVertexBufferObject(context);
glPolyIndex = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.polyIndexCount * PGL.SIZEOF_INDEX,
@@ -3308,19 +3308,19 @@ public class PShapeOpenGL extends PShape {
int sizei = size * PGL.SIZEOF_INT;
tessGeo.updateLineVerticesBuffer();
glLineVertex = pg.createVertexBufferObject(context);
glLineVertex = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.lineVerticesBuffer, PGL.STATIC_DRAW);
tessGeo.updateLineColorsBuffer();
glLineColor = pg.createVertexBufferObject(context);
glLineColor = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.lineColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updateLineDirectionsBuffer();
glLineAttrib = pg.createVertexBufferObject(context);
glLineAttrib = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.lineDirectionsBuffer, PGL.STATIC_DRAW);
@@ -3328,7 +3328,7 @@ public class PShapeOpenGL extends PShape {
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
tessGeo.updateLineIndicesBuffer();
glLineIndex = pg.createVertexBufferObject(context);
glLineIndex = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.lineIndexCount * PGL.SIZEOF_INDEX,
@@ -3344,19 +3344,19 @@ public class PShapeOpenGL extends PShape {
int sizei = size * PGL.SIZEOF_INT;
tessGeo.updatePointVerticesBuffer();
glPointVertex = pg.createVertexBufferObject(context);
glPointVertex = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex);
pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef,
tessGeo.pointVerticesBuffer, PGL.STATIC_DRAW);
tessGeo.updatePointColorsBuffer();
glPointColor = pg.createVertexBufferObject(context);
glPointColor = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor);
pgl.bufferData(PGL.ARRAY_BUFFER, sizei,
tessGeo.pointColorsBuffer, PGL.STATIC_DRAW);
tessGeo.updatePointOffsetsBuffer();
glPointAttrib = pg.createVertexBufferObject(context);
glPointAttrib = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib);
pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef,
tessGeo.pointOffsetsBuffer, PGL.STATIC_DRAW);
@@ -3364,7 +3364,7 @@ public class PShapeOpenGL extends PShape {
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
tessGeo.updatePointIndicesBuffer();
glPointIndex = pg.createVertexBufferObject(context);
glPointIndex = PGraphicsOpenGL.createVertexBufferObject(context);
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER,
tessGeo.pointIndexCount * PGL.SIZEOF_INDEX,
@@ -3381,25 +3381,25 @@ public class PShapeOpenGL extends PShape {
// doesn't get deleted by OpenGL. The VBOs were already
// automatically disposed when the old context was
// destroyed.
pg.removeVertexBufferObject(glPolyVertex, context);
pg.removeVertexBufferObject(glPolyColor, context);
pg.removeVertexBufferObject(glPolyNormal, context);
pg.removeVertexBufferObject(glPolyTexcoord, context);
pg.removeVertexBufferObject(glPolyAmbient, context);
pg.removeVertexBufferObject(glPolySpecular, context);
pg.removeVertexBufferObject(glPolyEmissive, context);
pg.removeVertexBufferObject(glPolyShininess, context);
pg.removeVertexBufferObject(glPolyIndex, context);
PGraphicsOpenGL.removeVertexBufferObject(glPolyVertex, context);
PGraphicsOpenGL.removeVertexBufferObject(glPolyColor, context);
PGraphicsOpenGL.removeVertexBufferObject(glPolyNormal, context);
PGraphicsOpenGL.removeVertexBufferObject(glPolyTexcoord, context);
PGraphicsOpenGL.removeVertexBufferObject(glPolyAmbient, context);
PGraphicsOpenGL.removeVertexBufferObject(glPolySpecular, context);
PGraphicsOpenGL.removeVertexBufferObject(glPolyEmissive, context);
PGraphicsOpenGL.removeVertexBufferObject(glPolyShininess, context);
PGraphicsOpenGL.removeVertexBufferObject(glPolyIndex, context);
pg.removeVertexBufferObject(glLineVertex, context);
pg.removeVertexBufferObject(glLineColor, context);
pg.removeVertexBufferObject(glLineAttrib, context);
pg.removeVertexBufferObject(glLineIndex, context);
PGraphicsOpenGL.removeVertexBufferObject(glLineVertex, context);
PGraphicsOpenGL.removeVertexBufferObject(glLineColor, context);
PGraphicsOpenGL.removeVertexBufferObject(glLineAttrib, context);
PGraphicsOpenGL.removeVertexBufferObject(glLineIndex, context);
pg.removeVertexBufferObject(glPointVertex, context);
pg.removeVertexBufferObject(glPointColor, context);
pg.removeVertexBufferObject(glPointAttrib, context);
pg.removeVertexBufferObject(glPointIndex, context);
PGraphicsOpenGL.removeVertexBufferObject(glPointVertex, context);
PGraphicsOpenGL.removeVertexBufferObject(glPointColor, context);
PGraphicsOpenGL.removeVertexBufferObject(glPointAttrib, context);
PGraphicsOpenGL.removeVertexBufferObject(glPointIndex, context);
// The OpenGL resources have been already deleted
// when the context changed. We only need to zero
@@ -3445,47 +3445,47 @@ public class PShapeOpenGL extends PShape {
protected void deletePolyBuffers() {
if (glPolyVertex != 0) {
pg.deleteVertexBufferObject(glPolyVertex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyVertex, context);
glPolyVertex = 0;
}
if (glPolyColor != 0) {
pg.deleteVertexBufferObject(glPolyColor, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyColor, context);
glPolyColor = 0;
}
if (glPolyNormal != 0) {
pg.deleteVertexBufferObject(glPolyNormal, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyNormal, context);
glPolyNormal = 0;
}
if (glPolyTexcoord != 0) {
pg.deleteVertexBufferObject(glPolyTexcoord, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyTexcoord, context);
glPolyTexcoord = 0;
}
if (glPolyAmbient != 0) {
pg.deleteVertexBufferObject(glPolyAmbient, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyAmbient, context);
glPolyAmbient = 0;
}
if (glPolySpecular != 0) {
pg.deleteVertexBufferObject(glPolySpecular, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolySpecular, context);
glPolySpecular = 0;
}
if (glPolyEmissive != 0) {
pg.deleteVertexBufferObject(glPolyEmissive, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyEmissive, context);
glPolyEmissive = 0;
}
if (glPolyShininess != 0) {
pg.deleteVertexBufferObject(glPolyShininess, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyShininess, context);
glPolyShininess = 0;
}
if (glPolyIndex != 0) {
pg.deleteVertexBufferObject(glPolyIndex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPolyIndex, context);
glPolyIndex = 0;
}
}
@@ -3493,22 +3493,22 @@ public class PShapeOpenGL extends PShape {
protected void deleteLineBuffers() {
if (glLineVertex != 0) {
pg.deleteVertexBufferObject(glLineVertex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glLineVertex, context);
glLineVertex = 0;
}
if (glLineColor != 0) {
pg.deleteVertexBufferObject(glLineColor, context);
PGraphicsOpenGL.deleteVertexBufferObject(glLineColor, context);
glLineColor = 0;
}
if (glLineAttrib != 0) {
pg.deleteVertexBufferObject(glLineAttrib, context);
PGraphicsOpenGL.deleteVertexBufferObject(glLineAttrib, context);
glLineAttrib = 0;
}
if (glLineIndex != 0) {
pg.deleteVertexBufferObject(glLineIndex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glLineIndex, context);
glLineIndex = 0;
}
}
@@ -3516,22 +3516,22 @@ public class PShapeOpenGL extends PShape {
protected void deletePointBuffers() {
if (glPointVertex != 0) {
pg.deleteVertexBufferObject(glPointVertex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPointVertex, context);
glPointVertex = 0;
}
if (glPointColor != 0) {
pg.deleteVertexBufferObject(glPointColor, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPointColor, context);
glPointColor = 0;
}
if (glPointAttrib != 0) {
pg.deleteVertexBufferObject(glPointAttrib, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPointAttrib, context);
glPointAttrib = 0;
}
if (glPointIndex != 0) {
pg.deleteVertexBufferObject(glPointIndex, context);
PGraphicsOpenGL.deleteVertexBufferObject(glPointIndex, context);
glPointIndex = 0;
}
}
+32 -44
View File
@@ -26,7 +26,7 @@ package processing.opengl;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PGraphics;
import processing.core.PImage;
//import processing.core.PImage;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
@@ -78,8 +78,6 @@ public class Texture implements PConstants {
public int glWidth;
public int glHeight;
protected PApplet parent; // The Processing applet
protected PGraphicsOpenGL pg; // The main renderer
protected PGL pgl; // The interface between Processing and OpenGL.
protected int context; // The context that created this texture.
protected PGraphicsOpenGL pgDraw; // The main renderer is the color buffer of.
@@ -110,11 +108,9 @@ public class Texture implements PConstants {
// Constructors.
public Texture(PApplet parent) {
this.parent = parent;
pg = (PGraphicsOpenGL)parent.g;
pgl = pg.pgl;
public Texture() {
pgl = PGraphicsOpenGL.pgl;
context = pgl.createEmptyContext();
pgDraw = null;
@@ -126,28 +122,23 @@ public class Texture implements PConstants {
/**
* Creates an instance of PTexture with size width x height. The texture is
* initialized (empty) to that size.
* @param parent PApplet
* @param width int
* @param height int
*/
public Texture(PApplet parent, int width, int height) {
this(parent, width, height, new Parameters());
public Texture(int width, int height) {
this(width, height, new Parameters());
}
/**
* Creates an instance of PTexture with size width x height and with the
* specified parameters. The texture is initialized (empty) to that size.
* @param parent PApplet
* @param width int
* @param height int
* @param params Parameters
*/
public Texture(PApplet parent, int width, int height, Object params) {
this.parent = parent;
pg = (PGraphicsOpenGL)parent.g;
pgl = pg.pgl;
public Texture(int width, int height, Object params) {
pgl = PGraphicsOpenGL.pgl;
context = pgl.createEmptyContext();
pgDraw = null;
@@ -162,7 +153,7 @@ public class Texture implements PConstants {
protected void finalize() throws Throwable {
try {
if (glName != 0) {
pg.finalizeTextureObject(glName, context);
PGraphicsOpenGL.finalizeTextureObject(glName, context);
}
} finally {
super.finalize();
@@ -249,7 +240,7 @@ public class Texture implements PConstants {
release();
// Creating new texture with the appropriate size.
Texture tex = new Texture(parent, wide, high, getParameters());
Texture tex = new Texture(wide, high, getParameters());
// Copying the contents of this texture into tex.
tex.set(this);
@@ -277,16 +268,16 @@ public class Texture implements PConstants {
// Set methods
public void set(PImage img) {
Texture tex = (Texture)pg.getCache(img);
set(tex);
}
// public void set(PImage tex) {
// Texture tex = (Texture)pg.getCache(img);
// set(tex);
// }
public void set(PImage img, int x, int y, int w, int h) {
Texture tex = (Texture)pg.getCache(img);
set(tex, x, y, w, h);
}
// public void set(PImage img, int x, int y, int w, int h) {
// Texture tex = (Texture)pg.getCache(img);
// set(tex, x, y, w, h);
// }
public void set(Texture tex) {
@@ -519,17 +510,17 @@ public class Texture implements PConstants {
}
if (tempFbo == null) {
tempFbo = new FrameBuffer(parent, glWidth, glHeight);
tempFbo = new FrameBuffer(glWidth, glHeight);
}
// Attaching the texture to the color buffer of a FBO, binding the FBO and
// reading the pixels from the current draw buffer (which is the color
// buffer of the FBO).
tempFbo.setColorBuffer(this);
pg.pushFramebuffer();
pg.setFramebuffer(tempFbo);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(tempFbo);
tempFbo.readPixels();
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
tempFbo.getPixels(pixels);
convertToARGB(pixels);
@@ -1192,7 +1183,7 @@ public class Texture implements PConstants {
}
context = pgl.getCurrentContext();
glName = pg.createTextureObject(context);
glName = PGraphicsOpenGL.createTextureObject(context);
pgl.bindTexture(glTarget, glName);
pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter);
@@ -1227,7 +1218,7 @@ public class Texture implements PConstants {
*/
protected void release() {
if (glName != 0) {
pg.finalizeTextureObject(glName, context);
PGraphicsOpenGL.finalizeTextureObject(glName, context);
glName = 0;
}
}
@@ -1239,7 +1230,7 @@ public class Texture implements PConstants {
// Removing the texture object from the renderer's list so it
// doesn't get deleted by OpenGL. The texture object was
// automatically disposed when the old context was destroyed.
pg.removeTextureObject(glName, context);
PGraphicsOpenGL.removeTextureObject(glName, context);
// And then set the id to zero, so it doesn't try to be
// deleted when the object's finalizer is invoked by the GC.
@@ -1272,7 +1263,7 @@ public class Texture implements PConstants {
}
if (tempFbo == null) {
tempFbo = new FrameBuffer(parent, glWidth, glHeight);
tempFbo = new FrameBuffer(glWidth, glHeight);
}
// This texture is the color (destination) buffer of the FBO.
@@ -1280,8 +1271,8 @@ public class Texture implements PConstants {
tempFbo.disableDepthTest();
// FBO copy:
pg.pushFramebuffer();
pg.setFramebuffer(tempFbo);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(tempFbo);
// Clear the color buffer to make sure that the alpha of the
pgl.clearColor(0, 0, 0, 0);
pgl.clear(PGL.COLOR_BUFFER_BIT);
@@ -1298,7 +1289,7 @@ public class Texture implements PConstants {
pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight,
x, y, w, h, x, y, w, h);
}
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
updateTexels(x, y, w, h);
}
@@ -1308,7 +1299,7 @@ public class Texture implements PConstants {
int texWidth, int texHeight,
int x, int y, int w, int h, boolean scale) {
if (tempFbo == null) {
tempFbo = new FrameBuffer(parent, glWidth, glHeight);
tempFbo = new FrameBuffer(glWidth, glHeight);
}
// This texture is the color (destination) buffer of the FBO.
@@ -1316,8 +1307,8 @@ public class Texture implements PConstants {
tempFbo.disableDepthTest();
// FBO copy:
pg.pushFramebuffer();
pg.setFramebuffer(tempFbo);
PGraphicsOpenGL.pushFramebuffer();
PGraphicsOpenGL.setFramebuffer(tempFbo);
if (scale) {
// Rendering tex into "this", and scaling the source rectangle
// to cover the entire destination region.
@@ -1331,7 +1322,7 @@ public class Texture implements PConstants {
pgl.drawTexture(texTarget, texName, texWidth, texHeight,
x, y, w, h, x, y, w, h);
}
pg.popFramebuffer();
PGraphicsOpenGL.popFramebuffer();
updateTexels(x, y, w, h);
}
@@ -1344,9 +1335,6 @@ public class Texture implements PConstants {
width = src.width;
height = src.height;
parent = src.parent;
pg = src.pg;
glName = src.glName;
glTarget = src.glTarget;
glFormat = src.glFormat;
@@ -786,7 +786,7 @@ public class PGL extends processing.opengl.PGL {
protected Texture wrapBackTexture() {
Texture tex = new Texture(pg.parent);
Texture tex = new Texture();
tex.init(pg.width, pg.height,
glColorTex.get(backTex), TEXTURE_2D, RGBA,
fboWidth, fboHeight, NEAREST, NEAREST,
@@ -799,7 +799,7 @@ public class PGL extends processing.opengl.PGL {
protected Texture wrapFrontTexture() {
Texture tex = new Texture(pg.parent);
Texture tex = new Texture();
tex.init(pg.width, pg.height,
glColorTex.get(frontTex), TEXTURE_2D, RGBA,
fboWidth, fboHeight, NEAREST, NEAREST,