PImage methods like loadTexture() don't creat the texture object unless the width and height of the image is larger than zero. This partially solves the asynchronous load problem pointed out in issue 465

This commit is contained in:
codeanticode
2010-12-04 02:31:05 +00:00
parent 08ca757d1f
commit a82eee35e3
3 changed files with 15 additions and 9 deletions
@@ -2331,7 +2331,7 @@ public class PGraphicsAndroid3D extends PGraphics {
PImage[] images = faceTextures[j];
if (1 < numMultitextures) {
for (int t = 0; t < numMultitextures; t++)
for (int t = 0; t < numMultitextures; t++) {
if (images[t] != null) {
PTexture tex = images[t].getTexture();
if (tex != null) {
@@ -2341,8 +2341,10 @@ public class PGraphicsAndroid3D extends PGraphics {
renderTextures[numTextures] = tex;
numTextures++;
} else {
// Null PTexture field in A3D? no good!
throw new RuntimeException("A3D: missing image texture");
// Null PTexture field in A3D. It can happen and things still ok
// when, for example, a PImage is being loaded asynchronously and
// used for drawing in the meantime...
break;
}
} else {
// If there is a null texture image at some point in the
@@ -2351,6 +2353,7 @@ public class PGraphicsAndroid3D extends PGraphics {
// the user, anyways.
break;
}
}
} else if (images[0] != null) {
PTexture tex = images[0].getTexture();
if (tex != null) {
@@ -2359,9 +2362,6 @@ public class PGraphicsAndroid3D extends PGraphics {
gl.glBindTexture(tex.getGLTarget(), tex.getGLID());
renderTextures[0] = tex;
numTextures = 1;
} else {
// Null PTexture field in A3D? no good!
throw new RuntimeException("A3D: missing image texture");
}
}
+5 -1
View File
@@ -198,6 +198,7 @@ public class PImage implements PConstants, Cloneable {
public void loadTexture() {
if (width == 0 || height == 0) return;
if (texture == null) {
texture = new PTexture(parent, width, height, new PTexture.Parameters(format));
}
@@ -210,6 +211,7 @@ public class PImage implements PConstants, Cloneable {
public void loadTexture(int filter) {
if (width == 0 || height == 0) return;
if (texture == null) {
texture = new PTexture(parent, width, height, new PTexture.Parameters(format, filter));
}
@@ -222,6 +224,7 @@ public class PImage implements PConstants, Cloneable {
public void loadTexture(PTexture.Parameters params) {
if (width == 0 || height == 0) return;
if (texture == null) {
texture = new PTexture(parent, width, height, params);
}
@@ -265,6 +268,7 @@ public class PImage implements PConstants, Cloneable {
protected void reloadTexture() {
if (width == 0 || height == 0) return;
if (texture != null) {
texture = new PTexture(parent, width, height, texture.getParameters());
}
@@ -345,7 +349,7 @@ public class PImage implements PConstants, Cloneable {
if (bitmap != null) {
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
}
if (parent.g.is3D()) {
if (parent.g.is3D() && 0 < width && 0 < height) {
if (texture == null) {
texture = new PTexture(parent, width, height, new PTexture.Parameters(format));
}
@@ -1719,8 +1719,10 @@ public class PShape3D extends PShape implements PConstants {
renderTextures[numTextures] = tex;
numTextures++;
} else {
// Null PTexture field in A3D? no good!
throw new RuntimeException("A3D: missing image texture");
// Null PTexture field in A3D. It can happen and things still ok
// when, for example, a PImage is being loaded asynchronously and
// used for drawing in the meantime...
break;
}
} else {
break;