From 2d63eff8b408925dd77e9a3b98af717676d8fb49 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 6 Mar 2010 06:59:59 +0000 Subject: [PATCH] GLTexture not subclassed from PImage anymore --- .../core/src/processing/core/GLTexture.java | 44 ++++++++----------- android/core/src/processing/core/PApplet.java | 16 +++++-- .../processing/core/PGraphicsAndroid3D.java | 20 ++++----- android/core/src/processing/core/PImage.java | 12 +++++ 4 files changed, 52 insertions(+), 40 deletions(-) diff --git a/android/core/src/processing/core/GLTexture.java b/android/core/src/processing/core/GLTexture.java index 5c236d2bd..98f6580fc 100644 --- a/android/core/src/processing/core/GLTexture.java +++ b/android/core/src/processing/core/GLTexture.java @@ -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); - } } diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index 1eae09b0b..e953a7272 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -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) { diff --git a/android/core/src/processing/core/PGraphicsAndroid3D.java b/android/core/src/processing/core/PGraphicsAndroid3D.java index c40afd235..6dac800e6 100644 --- a/android/core/src/processing/core/PGraphicsAndroid3D.java +++ b/android/core/src/processing/core/PGraphicsAndroid3D.java @@ -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; } diff --git a/android/core/src/processing/core/PImage.java b/android/core/src/processing/core/PImage.java index 4d732e90a..54ac3476d 100644 --- a/android/core/src/processing/core/PImage.java +++ b/android/core/src/processing/core/PImage.java @@ -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; }