mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
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:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user