Some renaming (backup/restore)

This commit is contained in:
codeanticode
2011-07-02 09:38:12 +00:00
parent ae2ff779c2
commit a6b7b7e84b
5 changed files with 71 additions and 34 deletions

View File

@@ -84,8 +84,17 @@ class PFontTexture implements PConstants {
}
public void refresh() {
// loop over current glyphs.
public void backup() {
// Nothing to do here: the font textures will backup
// themselves.
}
public void restore() {
// Restoration we have to do explicitly because the font
// textures don't have a backing PImage object, so the
// updateTex() method is in charge of updating each appropriate
// section of the font textures.
for (int i = 0; i < PApplet.min(font.getGlyphCount(), glyphTexinfos.length); i++) {
TextureInfo tinfo = glyphTexinfos[i];
textures[tinfo.texIndex].bind();
@@ -94,7 +103,11 @@ class PFontTexture implements PConstants {
}
}
protected void allocate() {
// Nothing to do here: the font textures will allocate
// themselves.
}
protected void initTexture(int w, int h) {
maxTexWidth = w;
maxTexHeight = h;

View File

@@ -152,8 +152,12 @@ public class PFramebuffer implements PConstants {
}
ogl.unregisterGLObject(this);
}
public void refresh() {
public void backup() {
}
public void restore() {
setColorBuffers(colorBufferTex.clone(), colorBufferTex.length);
}

View File

@@ -677,7 +677,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (context == null) {
initPrimary();
// If there are registered GL objects (i.e.: PTexture, PShape3D, etc), it means
// that the context has been recreated, so we need to re-allocate them in
// that the context has been re-created, so we need to re-allocate them in
// order to be able to keep using them. This step doesn't refresh their data, this
// is, they are empty after re-allocation.
allocateGLObjects();
@@ -730,42 +730,52 @@ public class PGraphicsOpenGL extends PGraphics {
} else if (globjs[i] instanceof PFramebuffer) {
((PFramebuffer)globjs[i]).allocate();
} else if (globjs[i] instanceof PFontTexture) {
// No need to do reallocation for a PFontTexture, since its
// textures will reallocate themselves.
((PFontTexture)globjs[i]).allocate();
}
}
}
}
protected void updateGLObjects() {
protected void backupGLObjects() {
if (!glObjects.isEmpty()) {
Object[] globjs = glObjects.toArray();
for (int i = 0; i < globjs.length; i++) {
if (globjs[i] instanceof PTexture) {
((PTexture)globjs[i]).update();
((PTexture)globjs[i]).backup();
} else if (globjs[i] instanceof PShape3D) {
//((PShape3D)globjs[i]).refresh();
((PShape3D)globjs[i]).backup();
} else if (globjs[i] instanceof PFramebuffer) {
//((PFramebuffer)globjs[i]).refresh();
((PFramebuffer)globjs[i]).backup();
} else if (globjs[i] instanceof PFontTexture) {
//((PFontTexture)globjs[i]).refresh();
((PFontTexture)globjs[i]).backup();
}
}
}
}
protected void refreshGLObjects() {
protected void clearGLFramebuffers() {
if (!glObjects.isEmpty()) {
Object[] globjs = glObjects.toArray();
for (int i = 0; i < globjs.length; i++) {
if (globjs[i] instanceof PFramebuffer) {
((PFramebuffer)globjs[i]).clear();
}
}
}
}
protected void restoreGLObjects() {
if (!glObjects.isEmpty()) {
Object[] globjs = glObjects.toArray();
for (int i = 0; i < globjs.length; i++) {
if (globjs[i] instanceof PTexture) {
((PTexture)globjs[i]).refresh();
((PTexture)globjs[i]).restore();
} else if (globjs[i] instanceof PShape3D) {
((PShape3D)globjs[i]).refresh();
((PShape3D)globjs[i]).restore();
} else if (globjs[i] instanceof PFramebuffer) {
((PFramebuffer)globjs[i]).refresh();
((PFramebuffer)globjs[i]).restore();
} else if (globjs[i] instanceof PFontTexture) {
((PFontTexture)globjs[i]).refresh();
((PFontTexture)globjs[i]).restore();
}
}
}
@@ -1164,12 +1174,13 @@ public class PGraphicsOpenGL extends PGraphics {
allocateGLObjects();
}
public void updateGL() {
updateGLObjects();
public void backupGL() {
backupGLObjects();
}
public void refreshGL() {
refreshGLObjects();
public void restoreGL() {
clearGLFramebuffers();
restoreGLObjects();
}
protected void saveGLState() {
@@ -1359,11 +1370,12 @@ public class PGraphicsOpenGL extends PGraphics {
} else if (which == DISABLE_OPENGL_2X_SMOOTH) {
if (opengl2X) {
if (primarySurface) {
backupGL();
releaseContext();
context.destroy();
context = null;
allocate();
refreshGL();
restoreGL();
throw new PApplet.RendererChangeException();
} else {
initOffscreen();
@@ -1376,11 +1388,12 @@ public class PGraphicsOpenGL extends PGraphics {
} else if (which == ENABLE_OPENGL_4X_SMOOTH) {
if (!opengl4X) {
if (primarySurface) {
backupGL();
releaseContext();
context.destroy();
context = null;
allocate();
refreshGL();
restoreGL();
throw new PApplet.RendererChangeException();
} else {
initOffscreen();
@@ -7105,8 +7118,8 @@ return width * (1 + ox) / 2.0f;
loadTextureImpl(BILINEAR);
// In case of reinitialization (for example, when the smooth level
// is changed), we make sure that all the OpenGL resources are
// released.
// 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 = null;

View File

@@ -231,7 +231,12 @@ public class PShape3D extends PShape {
ogl.unregisterGLObject(this);
}
public void refresh() {
public void backup() {
}
public void restore() {
if (root != this) return; // Can be done only from the root shape.
// Loading/updating each piece of data so the arrays on the CPU-side

View File

@@ -138,18 +138,20 @@ public class PTexture implements PConstants {
}
public void update() {
public void backup() {
if (img != null) {
//if (img.pixels == null) {
img.loadPixels();
// }
//get(img.pixels);
//img.updatePixels();
img.loadPixels();
if (img.pixels != null && (img instanceof PGraphicsOpenGL)) {
// When img is an offscreen renderer, the loadPixels() call above
// already takes care of copying the contents of the color buffer
// to the pixels array.
get(img.pixels);
}
}
}
public void refresh() {
public void restore() {
if (img != null && img.pixels != null) {
set(img.pixels);
}