Worked out some more texture handling issues in offscreen rendering in A3D

This commit is contained in:
codeanticode
2010-06-24 04:01:48 +00:00
parent e5b30b4e5b
commit 342bb2eaf0
5 changed files with 81 additions and 55 deletions

View File

@@ -7800,7 +7800,7 @@ public class PApplet extends Activity implements PConstants, Runnable {
// A3D-only functions
// TODO: Discuss proper integration into PApplet API.
synchronized public void clear() {
public void clear() {
if (g instanceof PGraphicsAndroid3D) {
((PGraphicsAndroid3D)g).clear();
} else {
@@ -7809,7 +7809,7 @@ public class PApplet extends Activity implements PConstants, Runnable {
}
synchronized public void noClear() {
public void noClear() {
if (g instanceof PGraphicsAndroid3D) {
((PGraphicsAndroid3D)g).noClear();
} else {
@@ -7817,5 +7817,4 @@ public class PApplet extends Activity implements PConstants, Runnable {
}
}
}

View File

@@ -5059,5 +5059,23 @@ public class PGraphics extends PImage implements PConstants {
public boolean is3D() {
return false;
}
//////////////////////////////////////////////////////////////
// A3D-only functions
// TODO: Discuss proper integration into PGraphics API.
public void clear() {
if (!(this instanceof PGraphicsAndroid3D)) {
showMissingWarning("clear");
}
}
public void noClear() {
if (!(this instanceof PGraphicsAndroid3D)) {
showMissingWarning("noClear");
}
}
}

View File

@@ -263,17 +263,6 @@ public class PGraphicsAndroid3D extends PGraphics {
// ........................................................
// Extensions support.
protected boolean npotTexSupported;
protected boolean mipmapSupported;
protected boolean matrixGetSupported;
protected boolean vboSupported;
protected boolean fboSupported;
protected int maxTextureSize;
protected float maxPointSize;
// ........................................................
// This array contains the recreateResource methods of all the GL objects
// created in Processing. These methods are used to recreate the open GL
// data when there is a context change or surface creation in Android.
@@ -321,13 +310,24 @@ public class PGraphicsAndroid3D extends PGraphics {
// ........................................................
boolean depthMask;
// ........................................................
// Extensions support.
static protected boolean npotTexSupported;
static protected boolean mipmapSupported;
static protected boolean matrixGetSupported;
static protected boolean vboSupported;
static protected boolean fboSupported;
static protected int maxTextureSize;
static protected float maxPointSize;
// ........................................................
public String OPENGL_VENDOR;
public String OPENGL_RENDERER;
public String OPENGL_VERSION;
// OpenGL strings
static public String OPENGL_VENDOR;
static public String OPENGL_RENDERER;
static public String OPENGL_VERSION;
// ////////////////////////////////////////////////////////////
@@ -693,12 +693,20 @@ public class PGraphicsAndroid3D extends PGraphics {
drawTexCrop[2] = width;
drawTexCrop[3] = height;
// Linear filtering is needed to keep decent image quality when rendering
// texture at a size different from its original resolution. This is expected
// to happen for offscreen rendering.
drawImages = new PImage[2];
drawImages[0] = parent.createImage(width, height, ARGB, LINEAR);
drawImages[1] = parent.createImage(width, height, ARGB, LINEAR);
if (primarySurface) {
// Nearest filtering is used for the primary surface, otherwise some
// artifacts appear (diagonal line when blending, for instance). This
// might deserve further examination.
drawImages[0] = parent.createImage(width, height, ARGB, NEAREST);
drawImages[1] = parent.createImage(width, height, ARGB, NEAREST);
} else {
// Linear filtering is needed to keep decent image quality when rendering
// texture at a size different from its original resolution. This is expected
// to happen for offscreen rendering.
drawImages[0] = parent.createImage(width, height, ARGB, LINEAR);
drawImages[1] = parent.createImage(width, height, ARGB, LINEAR);
}
drawTextures = new PTexture[2];
drawTextures[0] = drawImages[0].getTexture();
@@ -745,10 +753,16 @@ public class PGraphicsAndroid3D extends PGraphics {
TRIANGLECOUNT = 0;
FACECOUNT = 0;
if (!primarySurface) {
if (!primarySurface) {
PGraphicsAndroid3D a3d = (PGraphicsAndroid3D)parent.g;
a3d.saveGLState();
// Getting gl objects from primary surface:
gl = a3d.gl;
gl11 = a3d.gl11;
gl11x = a3d.gl11x;
gl11xp = a3d.gl11xp;
// Disabling all lights, so the offscreen renderer can set completely
// new light configuration (otherwise some light config from the
// primary renderer might stay).
@@ -756,25 +770,12 @@ public class PGraphicsAndroid3D extends PGraphics {
a3d.glLightDisable(i);
}
// Getting gl objects from primary surface:
gl = a3d.gl;
gl11 = a3d.gl11;
gl11x = a3d.gl11x;
gl11xp = a3d.gl11xp;
OPENGL_VENDOR = a3d.OPENGL_VENDOR;
OPENGL_RENDERER = a3d.OPENGL_RENDERER;
OPENGL_VERSION = a3d.OPENGL_VERSION;
npotTexSupported = a3d.npotTexSupported;
mipmapSupported = a3d.mipmapSupported;
matrixGetSupported = a3d.matrixGetSupported;
vboSupported = a3d.vboSupported;
fboSupported = a3d.fboSupported;
maxTextureSize = a3d.maxTextureSize;
maxPointSize = a3d.maxPointSize;
if (a3d.lights) {
// The offscreen renderer starts with lights off by default.
// If the primary surface had lights on, the OpenGL state is
// changed accordingly.
noLights();
}
}
if (!settingsInited) {
@@ -862,7 +863,7 @@ public class PGraphicsAndroid3D extends PGraphics {
pushFramebuffer();
setFramebuffer(drawFramebuffer);
drawFramebuffer.addColorBuffer(drawTextures[drawIndex]);
gl.glClearColor(0, 0, 0, 0);
if (clear) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
@@ -894,7 +895,7 @@ public class PGraphicsAndroid3D extends PGraphics {
if (fboSupported) {
if (drawFramebuffer != null) {
popFramebuffer();
if (primarySurface) {
// Only the primary surface in clear mode will write the contents of the
// ofscreen framebuffer to the screen.
@@ -904,6 +905,7 @@ public class PGraphicsAndroid3D extends PGraphics {
// Render current draw texture to screen.
renderDrawTexture(drawIndex);
}
swapDrawIndex();
}
} else {

View File

@@ -113,7 +113,7 @@ public class PShape3D extends PShape implements PConstants {
if (gl == null) {
throw new RuntimeException("PShape3D: OpenGL ES 1.1 required");
}
if (!a3d.vboSupported) {
if (!PGraphicsAndroid3D.vboSupported) {
throw new RuntimeException("PShape3D: Vertex Buffer Objects are not available");
}
@@ -152,7 +152,7 @@ public class PShape3D extends PShape implements PConstants {
if (gl == null) {
throw new RuntimeException("PShape3D: OpenGL ES 1.1 required");
}
if (!a3d.vboSupported) {
if (!PGraphicsAndroid3D.vboSupported) {
throw new RuntimeException("PShape3D: Vertex Buffer Objects are not available");
}
@@ -1855,7 +1855,14 @@ public class PShape3D extends PShape implements PConstants {
g.TRIANGLECOUNT = g.VERTEXCOUNT / 3;
// Setting line width and point size from stroke value.
pointSize = PApplet.min(a3d.strokeWeight, a3d.maxPointSize);
// TODO: Here the stroke weight from the g renderer is used. Normally, no issue here, but
// in the case the shape is being rendered from an offscreen A3D surface, then this might
// lead to the possibilty of a stroke weight different from that of the main renderer.
// For strokeWeight it seems to make sense that the value of the offscreen renderer and not
// of the main renderer is used. But what about other properties such as textureMode or
// colorMode. Right now they are read from a3d, which refers to the main renderer.
// So what should be the normal behavior.
pointSize = PApplet.min(g.strokeWeight, PGraphicsAndroid3D.maxPointSize);
gl.glPointSize(pointSize);
if (!depthMaskEnabled) {
@@ -1907,7 +1914,7 @@ public class PShape3D extends PShape implements PConstants {
// the minimum and maximum point sizes.
gl.glPointParameterf(GL11.GL_POINT_FADE_THRESHOLD_SIZE, 0.6f * pointSize);
gl.glPointParameterf(GL11.GL_POINT_SIZE_MIN, 1.0f);
gl.glPointParameterf(GL11.GL_POINT_SIZE_MAX, a3d.maxPointSize);
gl.glPointParameterf(GL11.GL_POINT_SIZE_MAX, PGraphicsAndroid3D.maxPointSize);
// Specify point sprite texture coordinate replacement mode for each
// texture unit
@@ -1932,7 +1939,7 @@ public class PShape3D extends PShape implements PConstants {
if (0 < group.sw) {
gl.glLineWidth(group.sw);
} else {
gl.glLineWidth(a3d.strokeWeight);
gl.glLineWidth(g.strokeWeight);
}
if (0 < group.glMode && !pointSprites) {

View File

@@ -285,7 +285,7 @@ public class PTexture implements PConstants {
gl.glBindTexture(glTarget, glTextureID[0]);
if (usingMipmaps) {
if (a3d.gl11 != null && a3d.mipmapSupported) {
if (a3d.gl11 != null && PGraphicsAndroid3D.mipmapSupported) {
gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
} else {
// TODO: alternative mipmap generation. See the following link for more info:
@@ -701,7 +701,7 @@ public class PTexture implements PConstants {
protected void createTexture(int w, int h) {
deleteTexture();
if (a3d.npotTexSupported) {
if (PGraphicsAndroid3D.npotTexSupported) {
glWidth = w;
glHeight =h;
} else {
@@ -709,10 +709,10 @@ public class PTexture implements PConstants {
glHeight = nextPowerOfTwo(h);
}
if ((glWidth > a3d.maxTextureSize) || (glHeight > a3d.maxTextureSize)) {
if ((glWidth > PGraphicsAndroid3D.maxTextureSize) || (glHeight > PGraphicsAndroid3D.maxTextureSize)) {
glWidth = glHeight = 0;
throw new RuntimeException("Image width and height cannot be" +
" larger than " + a3d.maxTextureSize +
" larger than " + PGraphicsAndroid3D.maxTextureSize +
" with this graphics card.");
}