GLTexture not subclassed from PImage anymore

This commit is contained in:
codeanticode
2010-03-06 06:59:59 +00:00
parent fa2b5fb673
commit 2d63eff8b4
4 changed files with 52 additions and 40 deletions
+18 -26
View File
@@ -38,8 +38,10 @@ import java.nio.*;
*
*/
@SuppressWarnings("unused")
public class GLTexture extends PImage implements PConstants, GLConstants {
public class GLTexture implements PConstants, GLConstants {
public int width, height;
protected PApplet parent;
protected PGraphicsAndroid3D a3d;
protected GL10 gl;
@@ -50,7 +52,7 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
protected int glMagFilter;
protected int glWidth;
protected int glHeight;
protected int glHeight;
protected boolean usingMipmaps;
protected float maxTexCoordS;
@@ -60,7 +62,6 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
protected boolean flippedY;
protected int recreateResourceIdx;
protected String filenameSaved;
////////////////////////////////////////////////////////////
@@ -87,14 +88,14 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
* @param height int
* @param params Parameters
*/
public GLTexture(PApplet parent, int width, int height, Parameters params) {
super(width, height, params.format);
public GLTexture(PApplet parent, int width, int height, Parameters params) {
this.parent = parent;
this.width = width;
this.height = height;
a3d = (PGraphicsAndroid3D)parent.g;
gl = a3d.gl;
filenameSaved = "";
setParameters(params);
createTexture(width, height);
@@ -124,13 +125,11 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
* @param params Parameters
*/
public GLTexture(PApplet parent, String filename, Parameters params) {
super(1, 1, params.format);
this.parent = parent;
a3d = (PGraphicsAndroid3D)parent.g;
gl = a3d.gl;
filenameSaved = filename;
PImage img = parent.loadImage(filename);
setParameters(params);
set(img);
@@ -176,7 +175,8 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
* @param params GLTextureParameters
*/
public void init(int width, int height, Parameters params) {
super.init(width, height, params.format);
this.width = width;
this.height = height;
setParameters(params);
createTexture(width, height);
}
@@ -188,8 +188,7 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
// The following resize methods assumes the texture is already
// stored in the pixels array.
super.resize(wide, high);
update();
//update();
}
@@ -209,7 +208,8 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
public void set(PImage img) {
if (img.width != width || img.height != height) {
super.init(img.width, img.height, format);
width = img.width;
height = img.height;
createTexture(width, height);
}
@@ -226,7 +226,8 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
h = PApplet.constrain(h, 0, img.height - y);
if ((w != width) || (h != height)) {
super.init(w, h, img.format);
width = w;
width = h;
createTexture(w, h);
}
@@ -338,11 +339,13 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
/**
* Copy pixels to texture. Involves main memory to video memory transfer (slow).
*/
/*
public void update() {
if (this.pixels != null) {
set(this.pixels, this.format);
set(this.pixels, this.format);
}
}
*/
////////////////////////////////////////////////////////////
@@ -746,17 +749,6 @@ public class GLTexture extends PImage implements PConstants, GLConstants {
protected void recreateResource(PGraphicsAndroid3D renderer) {
createTexture(width, height);
if (filenameSaved.equals("")) {
// The texture was not set with an image, hopefully the data
// will be still stored in the pixels array...
update();
} else {
// The texture was initially set from a file image, loading the
// image again:
PImage img = parent.loadImage(filenameSaved);
set(img);
}
}
+13 -3
View File
@@ -1083,6 +1083,11 @@ public class PApplet extends Activity implements PConstants, Runnable {
public PImage createImage(int wide, int high, int format) {
PImage image = new PImage(wide, high, format);
image.parent = this; // make save() work
if (g instanceof PGraphicsAndroid3D) {
// TODO: Check why textures doesn't work in formats other than ARGB...
image.format = ARGB;
image.initTexture();
}
return image;
}
@@ -2803,6 +2808,11 @@ public class PApplet extends Activity implements PConstants, Runnable {
// println("loadImage(" + filename + ") was " + nfc(much));
PImage image = new PImage(bitmap);
image.parent = this;
if (g instanceof PGraphicsAndroid3D) {
// TODO: Check why textures doesn't work in formats other than ARGB...
image.format = ARGB;
image.initTexture();
}
return image;
}
@@ -3064,9 +3074,9 @@ public class PApplet extends Activity implements PConstants, Runnable {
// }
public GLTexture loadGLTexture(String filename) {
return new GLTexture(this, filename);
}
// public GLTexture loadGLTexture(String filename) {
// return new GLTexture(this, filename);
// }
public GLModel loadGLModel(String filename) {
@@ -1177,17 +1177,15 @@ public class PGraphicsAndroid3D extends PGraphics {
int i = faceOffset[j];
if (faceTexture[j] != null) {
try {
tex = (GLTexture)faceTexture[j];
} catch (ClassCastException cce) {
throw new RuntimeException("A3D only accepts GLTextures for texturing!");
}
gl.glEnable(tex.getGLTarget());
gl.glBindTexture(tex.getGLTarget(), tex.getGLTextureID());
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
texturing = true;
tex = faceTexture[j].getTexture();
if (tex != null) {
gl.glEnable(tex.getGLTarget());
gl.glBindTexture(tex.getGLTarget(), tex.getGLTextureID());
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
texturing = true;
} else {
texturing = false;
}
} else {
texturing = false;
}
@@ -191,6 +191,18 @@ public class PImage implements PConstants, Cloneable {
}
public void initTexture() {
texture = new GLTexture(parent, width, height, new GLTexture.Parameters(format));
updateTexture();
}
public void updateTexture() {
loadPixels();
texture.set(this);
}
public void setTexture(GLTexture texture) {
this.texture = texture;
}