Sync P3D on Android

This commit is contained in:
codeanticode
2012-03-20 14:35:03 +00:00
parent 2cd80747d9
commit 9e71ae0f05
12 changed files with 899 additions and 445 deletions
@@ -2558,6 +2558,7 @@ public class PApplet extends Activity implements PConstants, Runnable {
public void frameRate(float newRateTarget) {
frameRateTarget = newRateTarget;
frameRatePeriod = (long) (1000000000.0 / frameRateTarget);
g.setFrameRate(newRateTarget);
}
@@ -49,8 +49,7 @@ import processing.core.PFont;
class PFontTexture implements PConstants {
protected PApplet parent;
protected PGraphicsAndroid3D pg;
protected PGL pgl;
protected PGL.Context context;
protected PGL pgl;
protected PFont font;
protected int maxTexWidth;
@@ -70,7 +69,6 @@ class PFontTexture implements PConstants {
this.font = font;
pg = (PGraphicsAndroid3D)parent.g;
pgl = pg.pgl;
context = pgl.getContext();
initTexture(maxw, maxh);
}
@@ -218,6 +216,21 @@ class PFontTexture implements PConstants {
}
public boolean contextIsOutdated() {
boolean outdated = false;
for (int i = 0; i < textures.length; i++) {
if (textures[i].contextIsOutdated()) {
outdated = true;
}
}
if (outdated) {
for (int i = 0; i < textures.length; i++) {
textures[i].glID = 0;
}
}
return outdated;
}
// Adds this glyph to the opengl texture in PFont.
protected void addToTexture(int idx, PFont.Glyph glyph) {
// We add one pixel to avoid issues when sampling the font texture at fractional
@@ -37,6 +37,7 @@ public class PFramebuffer implements PConstants {
protected PApplet parent;
protected PGraphicsAndroid3D pg;
protected PGL pgl;
protected PGL.Context context; // The context that created this framebuffer.
public int glFboID;
public int glDepthBufferID;
@@ -129,7 +130,7 @@ public class PFramebuffer implements PConstants {
}
screenFb = screen;
allocate();
noDepth = false;
@@ -178,10 +179,15 @@ public class PFramebuffer implements PConstants {
public void copy(PFramebuffer dest) {
pgl.glBindFramebuffer(PGL.GL_READ_FRAMEBUFFER, this.glFboID);
pgl.glBindFramebuffer(PGL.GL_DRAW_FRAMEBUFFER, dest.glFboID);
pgl.glBlitFramebuffer(0, 0,this.width, this.height, 0, 0, dest.width, dest.height, PGL.GL_COLOR_BUFFER_BIT, PGL.GL_NEAREST);
pgl.glBlitFramebuffer(0, 0, this.width, this.height,
0, 0, dest.width, dest.height,
PGL.GL_COLOR_BUFFER_BIT, PGL.GL_NEAREST);
}
public void bind() {
// if context is outdated ??
if (screenFb) {
if (PGraphicsAndroid3D.fboSupported) {
pgl.glBindFramebuffer(PGL.GL_FRAMEBUFFER, 0);
@@ -336,10 +342,11 @@ public class PFramebuffer implements PConstants {
protected void allocate() {
release(); // Just in the case this object is being re-allocated.
context = pgl.getContext();
if (screenFb) {
glFboID = 0;
} else if (fboMode) {
//glFboID = ogl.createGLResource(PGraphicsAndroid3D.GL_FRAME_BUFFER);
} else if (fboMode) {
glFboID = pg.createFrameBufferObject();
} else {
glFboID = 0;
@@ -349,7 +356,7 @@ public class PFramebuffer implements PConstants {
if (multisample) {
createColorBufferMultisample();
}
if (combinedDepthStencil) {
createCombinedDepthStencilBuffer();
} else {
@@ -359,7 +366,7 @@ public class PFramebuffer implements PConstants {
if (0 < stencilBits) {
createStencilBuffer();
}
}
}
}
@@ -387,6 +394,25 @@ public class PFramebuffer implements PConstants {
}
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
glFboID = 0;
glDepthBufferID = 0;
glStencilBufferID = 0;
glDepthStencilBufferID = 0;
glColorBufferMultisampleID = 0;
for (int i = 0; i < numColorBuffers; i++) {
colorBufferTex[i] = null;
}
backupTexture = null;
}
return outdated;
}
protected void createColorBufferMultisample() {
if (screenFb) return;
@@ -395,7 +421,7 @@ public class PFramebuffer implements PConstants {
pg.setFramebuffer(this);
glColorBufferMultisampleID = pg.createRenderBufferObject();
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glColorBufferMultisampleID);
pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glColorBufferMultisampleID);
pgl.glRenderbufferStorageMultisample(PGL.GL_RENDERBUFFER, nsamples, PGL.GL_RGBA8, width, height);
pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0, PGL.GL_RENDERBUFFER, glColorBufferMultisampleID);
+153 -45
View File
@@ -26,10 +26,12 @@ package processing.core;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.Arrays;
import processing.glu.PGLU;
import processing.glu.PGLUtessellator;
import processing.glu.PGLUtessellatorCallbackAdapter;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
@@ -70,7 +72,7 @@ public class PGL {
public static final int DEFAULT_TESS_INDICES = 32;
/** Initial sizes for vertex cache used in PShape3D. */
public static final int DEFAULT_VERTEX_CACHE_SIZE = 512;
public static final int DEFAULT_VERTEX_CACHE_SIZE = 256;
/** Maximum lights by default is 8, the minimum defined by OpenGL. */
public static final int MAX_LIGHTS = 8;
@@ -128,7 +130,7 @@ public class PGL {
public static final int GL_CLAMP_TO_EDGE = GLES20.GL_CLAMP_TO_EDGE;
public static final int GL_REPEAT = GLES20.GL_REPEAT;
public static final int GL_RGBA8 = -1;
public static final int GL_RGBA8 = -1;
public static final int GL_DEPTH24_STENCIL8 = -1;
public static final int GL_DEPTH_COMPONENT16 = GLES20.GL_DEPTH_COMPONENT16;
@@ -142,6 +144,8 @@ public class PGL {
public static final int GL_ARRAY_BUFFER = GLES20.GL_ARRAY_BUFFER;
public static final int GL_ELEMENT_ARRAY_BUFFER = GLES20.GL_ELEMENT_ARRAY_BUFFER;
public static final int GL_SAMPLES = GLES20.GL_SAMPLES;
public static final int GL_FRAMEBUFFER_COMPLETE = GLES20.GL_FRAMEBUFFER_COMPLETE;
public static final int GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = GLES20.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
public static final int GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GLES20.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
@@ -169,9 +173,9 @@ public class PGL {
public static final int GL_EXTENSIONS = GLES20.GL_EXTENSIONS;
public static final int GL_MAX_TEXTURE_SIZE = GLES20.GL_MAX_TEXTURE_SIZE;
public static final int GL_MAX_SAMPLES = -1;
public static final int GL_ALIASED_LINE_WIDTH_RANGE = GLES20.GL_ALIASED_LINE_WIDTH_RANGE;
public static final int GL_ALIASED_POINT_SIZE_RANGE = GLES20.GL_ALIASED_POINT_SIZE_RANGE;
public static final int GL_SAMPLES = GLES20.GL_SAMPLES;
public static final int GLU_TESS_WINDING_NONZERO = PGLU.GLU_TESS_WINDING_NONZERO;
public static final int GLU_TESS_WINDING_ODD = PGLU.GLU_TESS_WINDING_ODD;
@@ -196,16 +200,16 @@ public class PGL {
public static final int GL_DST_COLOR = GLES20.GL_DST_COLOR;
public static final int GL_SRC_COLOR = GLES20.GL_SRC_COLOR;
public static final int GL_FRAMEBUFFER = GLES20.GL_FRAMEBUFFER;
public static final int GL_COLOR_ATTACHMENT0 = GLES20.GL_COLOR_ATTACHMENT0;
public static final int GL_FRAMEBUFFER = GLES20.GL_FRAMEBUFFER;
public static final int GL_COLOR_ATTACHMENT0 = GLES20.GL_COLOR_ATTACHMENT0;
public static final int GL_COLOR_ATTACHMENT1 = -1;
public static final int GL_COLOR_ATTACHMENT2 = -1;
public static final int GL_COLOR_ATTACHMENT3 = -1;
public static final int GL_RENDERBUFFER = GLES20.GL_RENDERBUFFER;
public static final int GL_DEPTH_ATTACHMENT = GLES20.GL_DEPTH_ATTACHMENT;
public static final int GL_STENCIL_ATTACHMENT = GLES20.GL_STENCIL_ATTACHMENT;
public static final int GL_READ_FRAMEBUFFER = -1;
public static final int GL_DRAW_FRAMEBUFFER = -1;
public static final int GL_COLOR_ATTACHMENT1 = -1;
public static final int GL_COLOR_ATTACHMENT2 = -1;
public static final int GL_COLOR_ATTACHMENT3 = -1;
public static final int GL_READ_FRAMEBUFFER = -1;
public static final int GL_DRAW_FRAMEBUFFER = -1;
public static final int GL_VERTEX_SHADER = GLES20.GL_VERTEX_SHADER;
public static final int GL_FRAGMENT_SHADER = GLES20.GL_FRAGMENT_SHADER;
@@ -219,38 +223,45 @@ public class PGL {
public static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
public static final int EGL_OPENGL_ES2_BIT = 0x0004;
/** Basic GLES 1.0 interface */
public GL10 gl;
public PGLU glu;
public AndroidRenderer renderer;
/** GLU interface **/
public PGLU glu;
/** The PGraphics object using this interface */
public PGraphicsAndroid3D pg;
/** Whether OpenGL has been initialized or not */
public boolean initialized;
/** The renderer object driving the rendering loop,
* analogous to the GLEventListener in JOGL */
protected AndroidRenderer renderer;
///////////////////////////////////////////////////////////////////////////////////
// Intialization, finalization
// TODO: implement double buffering support in onscreen rendering, offscreen rendering.
public PGL(PGraphicsAndroid3D pg) {
this.pg = pg;
renderer = new AndroidRenderer();
glu = new PGLU();
initialized = false;
}
static public void startup(boolean beforeUI) {
public void setFramerate(float framerate) {
}
static public void shutdown() {
}
public void updatePrimary() {
public void updatePrimary() {
}
public void updateOffscreen(PGL primary) {
gl = primary.gl;
}
@@ -301,6 +312,7 @@ public class PGL {
initialized = true;
}
public void initOffscreenSurface(PGL primary) {
/*
@@ -345,25 +357,11 @@ public class PGL {
initialized = true;
}
public void updateOffscreenSurface(PGL primary) {
}
protected void detainContext() {
}
public void releaseContext() {
}
public void destroyContext() {
}
///////////////////////////////////////////////////////////////////////////////////
// Frame rendering
public boolean initOnscreenDraw() {
return true;
}
public void beginOnscreenDraw(boolean clear, int frame) {
GLES20.glClearColor(0, 0, 0, 0);
@@ -411,6 +409,7 @@ public class PGL {
*/
}
public void endOnscreenDraw(boolean clear0) {
/*
if (!clear0) {
@@ -458,14 +457,17 @@ public class PGL {
*/
}
public void endOffscreenDraw(boolean clear0) {
//swapOffscreenIndex();
}
public boolean canDraw() {
return true;
}
public void requestDraw() {
if (pg.parent.looping) { // This "if" is needed to avoid flickering when looping is disabled.
((GLSurfaceView) pg.parent.surfaceView).requestRender();
@@ -477,71 +479,91 @@ public class PGL {
// Caps query
public String glGetString(int name) {
return GLES20.glGetString(name);
}
public void glGetIntegerv(int name, int[] values, int offset) {
GLES20.glGetIntegerv(name, values, offset);
if (-1 < name) {
GLES20.glGetIntegerv(name, values, offset);
} else {
Arrays.fill(values, 0);
}
}
///////////////////////////////////////////////////////////////////////////////////
// Enable/disable caps
public void glEnable(int cap) {
if (-1 < cap) {
GLES20.glEnable(cap);
}
}
public void glDisable(int cap) {
if (-1 < cap) {
GLES20.glDisable(cap);
}
}
///////////////////////////////////////////////////////////////////////////////////
// Render control
public void glFlush() {
GLES20.glFlush();
}
public void glFinish() {
GLES20.glFinish();
}
/////////////////////////////////////////////////////////////////////////////////
// Error handling
public int glGetError() {
return GLES20.glGetError();
}
public String glErrorString(int err) {
return GLU.gluErrorString(err);
}
public String gluErrorString(int err) {
return PGLU.gluErrorString(err);
}
/////////////////////////////////////////////////////////////////////////////////
// Rendering options
public void setFrontFace(int mode) {
public void glFrontFace(int mode) {
GLES20.glFrontFace(mode);
}
public void glDepthMask(boolean flag) {
GLES20.glDepthMask(flag);
}
public void setDepthFunc(int func) {
public void glDepthFunc(int func) {
GLES20.glDepthFunc(func);
}
@@ -550,58 +572,72 @@ public class PGL {
// Textures
public void glGenTextures(int n, int[] ids, int offset) {
GLES20.glGenTextures(n, ids, offset);
}
public void glDeleteTextures(int n, int[] ids, int offset) {
GLES20.glDeleteTextures(n, ids, offset);
}
public void glActiveTexture(int unit) {
GLES20.glActiveTexture(unit);
}
public void glBindTexture(int target, int id) {
GLES20.glBindTexture(target, id);
}
public void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data) {
GLES20.glTexImage2D(target, level, internalFormat, width, height, border, format, type, data);
}
public void glTexSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, Buffer data) {
GLES20.glTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, data);
}
public void glTexParameterf(int target, int param, int value) {
GLES20.glTexParameterf(target, param, value);
}
public void glGenerateMipmap(int target) {
GLES20.glGenerateMipmap(target);
}
/////////////////////////////////////////////////////////////////////////////////
// Vertex Buffers
public void glGenBuffers(int n, int[] ids, int offset) {
GLES20.glGenBuffers(n, ids, offset);
}
public void glDeleteBuffers(int n, int[] ids, int offset) {
GLES20.glDeleteBuffers(n, ids, offset);
}
public void glBindBuffer(int target, int id) {
GLES20.glBindBuffer(target, id);
}
public void glBufferData(int target, int size, Buffer data, int usage) {
GLES20.glBufferData(target, size, data, usage);
}
public void glBufferSubData(int target, int offset, int size, Buffer data) {
GLES20.glBufferSubData(target, offset, size, data);
}
@@ -616,10 +652,12 @@ public class PGL {
GLES20.glEnableVertexAttribArray(loc);
}
public void glDisableVertexAttribArray(int loc) {
GLES20.glDisableVertexAttribArray(loc);
}
public void glVertexAttribPointer(int loc, int size, int type, boolean normalized, int stride, int offset) {
GLES20.glVertexAttribPointer(loc, size, type, normalized, stride, offset);
}
@@ -630,183 +668,228 @@ public class PGL {
return null;
}
public ByteBuffer glMapBufferRange(int target, int offset, int length, int access) {
//return gl2x.glMapBufferRange(GL.GL_ARRAY_BUFFER, offset, length, GL2.GL_READ_WRITE);
return null;
}
public void glUnmapBuffer(int target) {
//gl2f.glUnmapBuffer(GL.GL_ARRAY_BUFFER);
}
/////////////////////////////////////////////////////////////////////////////////
// Framebuffers, renderbuffers
public void glGenFramebuffers(int n, int[] ids, int offset) {
GLES20.glGenFramebuffers(n, ids, offset);
}
public void glDeleteFramebuffers(int n, int[] ids, int offset) {
GLES20.glDeleteFramebuffers(n, ids, offset);
}
public void glGenRenderbuffers(int n, int[] ids, int offset) {
GLES20.glGenRenderbuffers(n, ids, offset);
}
public void glDeleteRenderbuffers(int n, int[] ids, int offset) {
GLES20.glDeleteRenderbuffers(n, ids, offset);
}
public void glBindFramebuffer(int target, int id) {
GLES20.glBindFramebuffer(target, id);
}
public void glBlitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) {
// GLES20.glBlitFramebuffer(0, 0, srcW, srcH, 0, 0, destW, destH, GLES20.GL_COLOR_BUFFER_BIT, GLES20.GL_NEAREST);
}
public void glFramebufferTexture2D(int target, int attachment, int texTarget, int texId, int level) {
GLES20.glFramebufferTexture2D(target, attachment, texTarget, texId, level);
}
public void glBindRenderbuffer(int target, int id) {
GLES20.glBindRenderbuffer(target, id);
}
public void glRenderbufferStorageMultisample(int target, int samples, int format, int width, int height) {
// GLES20.glRenderbufferStorageMultisample(GLES20.GL_RENDERBUFFER, samples, format, w, h);
}
public void glRenderbufferStorage(int target, int format, int width, int height) {
// GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, format, w, h);
}
public void glFramebufferRenderbuffer(int target, int attachment, int rendbufTarget, int rendbufId) {
GLES20.glFramebufferRenderbuffer(target, attachment, rendbufTarget, rendbufId);
}
public int glCheckFramebufferStatus(int target) {
return GLES20.glCheckFramebufferStatus(target);
}
/////////////////////////////////////////////////////////////////////////////////
// Shaders
public int glCreateProgram() {
return GLES20.glCreateProgram();
}
public void glDeleteProgram(int id) {
GLES20.glDeleteProgram(id);
}
public int glCreateShader(int type) {
return GLES20.glCreateShader(type);
}
public void glDeleteShader(int id) {
GLES20.glDeleteShader(id);
}
public void glLinkProgram(int prog) {
GLES20.glLinkProgram(prog);
}
public void glValidateProgram(int prog) {
GLES20.glValidateProgram(prog);
}
public void glUseProgram(int prog) {
GLES20.glUseProgram(prog);
}
public int glGetAttribLocation(int prog, String name) {
return GLES20.glGetAttribLocation(prog, name);
}
public int glGetUniformLocation(int prog, String name) {
return GLES20.glGetUniformLocation(prog, name);
}
public void glUniform1i(int loc, int value) {
GLES20.glUniform1i(loc, value);
}
public void glUniform1f(int loc, float value) {
GLES20.glUniform1f(loc, value);
}
public void glUniform2f(int loc, float value0, float value1) {
GLES20.glUniform2f(loc, value0, value1);
}
public void glUniform3f(int loc, float value0, float value1, float value2) {
GLES20.glUniform3f(loc, value0, value1, value2);
}
public void glUniform4f(int loc, float value0, float value1, float value2, float value3) {
GLES20.glUniform4f(loc, value0, value1, value2, value3);
}
public void glUniform1fv(int loc, int count, float[] v, int offset) {
GLES20.glUniform1fv(loc, count, v, offset);
}
public void glUniform2fv(int loc, int count, float[] v, int offset) {
GLES20.glUniform2fv(loc, count, v, offset);
}
public void glUniform3fv(int loc, int count, float[] v, int offset) {
GLES20.glUniform3fv(loc, count, v, offset);
}
public void glUniform4fv(int loc, int count, float[] v, int offset) {
GLES20.glUniform4fv(loc, count, v, offset);
}
public void glUniformMatrix2fv(int loc, int count, boolean transpose, float[] mat, int offset) {
GLES20.glUniformMatrix2fv(loc, count, transpose, mat, offset);
}
public void glUniformMatrix3fv(int loc, int count, boolean transpose, float[] mat, int offset) {
GLES20.glUniformMatrix3fv(loc, count, transpose, mat, offset);
}
public void glUniformMatrix4fv(int loc, int count, boolean transpose, float[] mat, int offset) {
GLES20.glUniformMatrix4fv(loc, count, transpose, mat, offset);
}
public void glVertexAttrib1f(int loc, float value) {
GLES20.glVertexAttrib1f(loc, value);
}
public void glVertexAttrib2f(int loc, float value0, float value1) {
GLES20.glVertexAttrib2f(loc, value0, value1);
}
public void glVertexAttrib3f(int loc, float value0, float value1, float value2) {
GLES20.glVertexAttrib3f(loc, value0, value1, value2);
}
public void glVertexAttrib4f(int loc, float value0, float value1, float value2, float value3) {
GLES20.glVertexAttrib4f(loc, value0, value1, value2, value3);
}
public void glShaderSource(int id, String source) {
GLES20.glShaderSource(id, source);
}
public void glCompileShader(int id) {
GLES20.glCompileShader(id);
}
public void glAttachShader(int prog, int shader) {
GLES20.glAttachShader(prog, shader);
}
/////////////////////////////////////////////////////////////////////////////////
// Viewport
@@ -816,6 +899,7 @@ public class PGL {
GLES20.glViewport(x, y, width, height);
}
/////////////////////////////////////////////////////////////////////////////////
// Clipping (scissor test)
@@ -845,22 +929,27 @@ public class PGL {
// Pixels
public void setReadBuffer(int buf) {
public void glReadBuffer(int buf) {
// GLES20.glReadBuffer(buf);
}
public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer buffer) {
GLES20.glReadPixels(x, y, width, height, format, type, buffer);
}
public void setDrawBuffer(int buf) {
public void glDrawBuffer(int buf) {
// GLES20.glDrawBuffer(GLES20.GL_COLOR_ATTACHMENT0 + buf);
}
public void glClearColor(float r, float g, float b, float a) {
GLES20.glClearColor(r, g, b, a);
}
public void glClear(int mask) {
GLES20.glClear(mask);
}
@@ -870,10 +959,12 @@ public class PGL {
// Context interface
public Context getContext() {
return new Context(/*context*/);
}
public class Context {
//protected GLContext context;
@@ -890,11 +981,13 @@ public class PGL {
/////////////////////////////////////////////////////////////////////////////////
// Tessellator interface
public Tessellator createTessellator(TessellatorCallback callback) {
return new Tessellator(callback);
}
public class Tessellator {
protected PGLUtessellator tess;
protected TessellatorCallback callback;
@@ -960,6 +1053,7 @@ public class PGL {
}
}
public interface TessellatorCallback {
public void begin(int type);
public void end();
@@ -969,14 +1063,17 @@ public class PGL {
public void error(int errnum);
}
///////////////////////////////////////////////////////////////////////////////////
// Utility functions
public boolean contextIsCurrent(Context other) {
return other.same(/*context*/);
}
static public short makeIndex(int intIdx) {
// When the index value is greater than 32767, subtracting 65536
// will make it (as a short) to wrap around to the negative range, which
@@ -986,14 +1083,17 @@ public class PGL {
return 32767 < intIdx ? (short)(intIdx - 65536) : (short)intIdx;
}
public void enableTexturing(int target) {
//gl.glEnable(target);
}
public void disableTexturing(int target) {
//gl.glDisable(target);
}
public void initTexture(int target, int width, int height, int format, int type) {
// Doing in patches of 16x16 pixels to avoid creating a (potentially)
// very large transient array which in certain situations (memory-
@@ -1008,6 +1108,7 @@ public class PGL {
}
}
public String getShaderLog(int id) {
int[] compiled = new int[1];
GLES20.glGetShaderiv(id, GLES20.GL_COMPILE_STATUS, compiled, 0);
@@ -1018,22 +1119,27 @@ public class PGL {
}
}
/////////////////////////////////////////////////////////////////////////////////
// Android specific stuff
public AndroidRenderer getRenderer() {
return renderer;
}
public AndroidContextFactory getContextFactory() {
return new AndroidContextFactory();
}
public AndroidConfigChooser getConfigChooser(int r, int g, int b, int a, int d, int s) {
return new AndroidConfigChooser(r, g, b, a, d, s);
}
public class AndroidRenderer implements Renderer {
public AndroidRenderer() {
}
@@ -1057,6 +1163,7 @@ public class PGL {
}
}
public class AndroidContextFactory implements GLSurfaceView.EGLContextFactory {
public EGLContext createContext(EGL10 egl, EGLDisplay display,
EGLConfig eglConfig) {
@@ -1071,6 +1178,7 @@ public class PGL {
}
}
public class AndroidConfigChooser implements EGLConfigChooser {
// Desired size (in bits) for the rgba color, depth and stencil buffers.
public int redTarget;
@@ -583,6 +583,10 @@ public class PGraphics extends PImage implements PConstants {
this.path = path;
}
public void setFrameRate(float framerate) { // ignore
}
/**
* The final step in setting up a renderer, set its size of this renderer.
File diff suppressed because it is too large Load Diff
+15 -1
View File
@@ -35,6 +35,7 @@ public class PShader {
protected PApplet parent;
protected PGraphicsAndroid3D pg;
protected PGL pgl;
protected PGL.Context context; // The context that created this shader.
protected URL vertexURL;
protected URL fragmentURL;
@@ -291,7 +292,9 @@ public class PShader {
}
protected void init() {
if (programObject == 0) {
if (programObject == 0 || contextIsOutdated()) {
context = pgl.getContext();
programObject = pg.createGLSLProgramObject();
if (vertexFilename != null) {
@@ -319,6 +322,17 @@ public class PShader {
}
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
programObject = 0;
vertexShader = 0;
fragmentShader = 0;
}
return outdated;
}
/**
* Loads and compiles the vertex shader contained in file.
*
+218 -73
View File
@@ -28,6 +28,7 @@ import processing.core.PGraphicsAndroid3D.LineShader;
import processing.core.PGraphicsAndroid3D.PointShader;
import processing.core.PGraphicsAndroid3D.TessGeometry;
import processing.core.PGraphicsAndroid3D.Tessellator;
import java.nio.FloatBuffer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
@@ -39,6 +40,16 @@ import java.util.Hashtable;
import java.io.BufferedReader;
//Notes about geometry update in PShape3D.
//1) When applying a transformation on a group shape
// check if it is more efficient to apply as a gl
// transformation on all the childs, instead of
// propagating the transformation downwards in order
// to calculate the transformation matrices.
//2) Change the transformation logic, so the matrix is applied
// on the values stored in the vertex cache and not on the
// tessellated vertices.
/**
* This class holds a 3D model composed of vertices, normals, colors (per vertex) and
* texture coordinates (also per vertex). All this data is stored in Vertex Buffer Objects
@@ -58,6 +69,7 @@ import java.io.BufferedReader;
public class PShape3D extends PShape {
protected PGraphicsAndroid3D pg;
protected PGL pgl;
protected PGL.Context context; // The context that created this shape.
protected PShape3D root;
protected int glMode;
@@ -2029,49 +2041,85 @@ public class PShape3D extends PShape {
return tess.fillIndexCount;
}
public float[] fillVertices() {
public float[] fillVertices(float[] vertices) {
updateTesselation();
return tess.fillVertices;
if (vertices == null || vertices.length != tess.fillVertices.length) {
vertices = new float[tess.fillVertices.length];
}
PApplet.arrayCopy(tess.fillVertices, vertices);
return vertices;
}
public int[] fillColors() {
public int[] fillColors(int[] colors) {
updateTesselation();
return tess.fillColors;
if (colors == null || colors.length != tess.fillColors.length) {
colors = new int[tess.fillColors.length];
}
PApplet.arrayCopy(tess.fillColors, colors);
return colors;
}
public float[] fillNormals() {
public float[] fillNormals(float[] normals) {
updateTesselation();
return tess.fillNormals;
if (normals == null || normals.length != tess.fillNormals.length) {
normals = new float[tess.fillNormals.length];
}
PApplet.arrayCopy(tess.fillNormals, normals);
return normals;
}
public float[] fillTexCoords() {
public float[] fillTexCoords(float[] texcoords) {
updateTesselation();
return tess.fillTexcoords;
if (texcoords == null || texcoords.length != tess.fillTexcoords.length) {
texcoords = new float[tess.fillTexcoords.length];
}
PApplet.arrayCopy(tess.fillTexcoords, texcoords);
return texcoords;
}
public int[] fillAmbient() {
public int[] fillAmbient(int[] ambient) {
updateTesselation();
return tess.fillAmbient;
if (ambient == null || ambient.length != tess.fillAmbient.length) {
ambient = new int[tess.fillAmbient.length];
}
PApplet.arrayCopy(tess.fillAmbient, ambient);
return ambient;
}
public int[] fillSpecular() {
public int[] fillSpecular(int[] specular) {
updateTesselation();
return tess.fillSpecular;
if (specular == null || specular.length != tess.fillSpecular.length) {
specular = new int[tess.fillSpecular.length];
}
PApplet.arrayCopy(tess.fillSpecular, specular);
return specular;
}
public int[] fillEmissive() {
public int[] fillEmissive(int[] emissive) {
updateTesselation();
return tess.fillEmissive;
if (emissive == null || emissive.length != tess.fillEmissive.length) {
emissive = new int[tess.fillEmissive.length];
}
PApplet.arrayCopy(tess.fillEmissive, emissive);
return emissive;
}
public float[] fillShininess() {
public float[] fillShininess(float[] shininess) {
updateTesselation();
return tess.fillShininess;
if (shininess == null || shininess.length != tess.fillShininess.length) {
shininess = new float[tess.fillShininess.length];
}
PApplet.arrayCopy(tess.fillShininess, shininess);
return shininess;
}
public short[] fillIndices() {
public int[] fillIndices(int[] indices) {
updateTesselation();
return tess.fillIndices;
if (indices == null || indices.length != tess.fillIndices.length) {
indices = new int[tess.fillIndices.length];
}
PApplet.arrayCopy(tess.fillIndexCount, indices);
return indices;
}
public int firstLineVertex() {
@@ -2104,24 +2152,40 @@ public class PShape3D extends PShape {
return tess.lineIndexCount;
}
public float[] lineVertices() {
public float[] lineVertices(float[] vertices) {
updateTesselation();
return tess.lineVertices;
if (vertices == null || vertices.length != tess.lineVertices.length) {
vertices = new float[tess.lineVertices.length];
}
PApplet.arrayCopy(tess.lineVertices, vertices);
return vertices;
}
public int[] lineColors() {
public int[] lineColors(int[] colors) {
updateTesselation();
return tess.lineColors;
if (colors == null || colors.length != tess.lineColors.length) {
colors = new int[tess.lineColors.length];
}
PApplet.arrayCopy(tess.lineColors, colors);
return colors;
}
public float[] lineAttributes() {
public float[] lineAttributes(float[] attribs) {
updateTesselation();
return tess.lineDirWidths;
if (attribs == null || attribs.length != tess.lineDirWidths.length) {
attribs = new float[tess.lineDirWidths.length];
}
PApplet.arrayCopy(tess.lineDirWidths, attribs);
return attribs;
}
public short[] lineIndices() {
public int[] lineIndices(int[] indices) {
updateTesselation();
return tess.lineIndices;
if (indices == null || indices.length != tess.lineIndices.length) {
indices = new int[tess.lineIndices.length];
}
PApplet.arrayCopy(tess.lineIndices, indices);
return indices;
}
public int firstPointVertex() {
@@ -2154,24 +2218,40 @@ public class PShape3D extends PShape {
return tess.pointIndexCount;
}
public float[] pointVertices() {
public float[] pointVertices(float[] vertices) {
updateTesselation();
return tess.pointVertices;
if (vertices == null || vertices.length != tess.pointVertices.length) {
vertices = new float[tess.pointVertices.length];
}
PApplet.arrayCopy(tess.pointVertices, vertices);
return vertices;
}
public int[] pointColors() {
public int[] pointColors(int[] colors) {
updateTesselation();
return tess.pointColors;
if (colors == null || colors.length != tess.pointColors.length) {
colors = new int[tess.pointColors.length];
}
PApplet.arrayCopy(tess.pointColors, colors);
return colors;
}
public float[] pointAttributes() {
public float[] pointAttributes(float[] attribs) {
updateTesselation();
return tess.pointSizes;
if (attribs == null || attribs.length != tess.pointSizes.length) {
attribs = new float[tess.pointSizes.length];
}
PApplet.arrayCopy(tess.pointSizes, attribs);
return attribs;
}
public short[] pointIndices() {
public int[] pointIndices(int[] indices) {
updateTesselation();
return tess.pointIndices;
if (indices == null || indices.length != tess.pointIndices.length) {
indices = new int[tess.pointIndices.length];
}
PApplet.arrayCopy(tess.pointIndices, indices);
return indices;
}
public FloatBuffer mapFillVertices() {
@@ -2361,7 +2441,7 @@ public class PShape3D extends PShape {
protected void updateTesselation() {
if (!root.tessellated) {
if (!root.tessellated || root.contextIsOutdated()) {
root.tessellate();
root.aggregate();
}
@@ -2375,7 +2455,11 @@ public class PShape3D extends PShape {
child.tessellate();
}
} else {
if (!tessellated && shapeEnded) {
if (shapeEnded) {
if (tessellated) {
tess.clear();
}
tessellator.setInGeometry(in);
tessellator.setTessGeometry(tess);
tessellator.setFill(fill || texture != null);
@@ -2500,9 +2584,14 @@ public class PShape3D extends PShape {
protected void tessellateBox() {
// TODO: move to InGeometry
float w = params[0];
float h = params[1];
float d = params[2];
float w, h, d;
if (params.length == 1) {
w = h = d = params[0];
} else {
w = params[0];
h = params[1];
d = params[2];
}
float x1 = -w/2f; float x2 = w/2f;
float y1 = -h/2f; float y2 = h/2f;
@@ -2645,52 +2734,72 @@ public class PShape3D extends PShape {
// Copying any data remaining in the caches
if (root.fillVerticesCache != null && root.fillVerticesCache.hasData()) {
root.copyFillVertices(root.fillVerticesCache.offset, root.fillVerticesCache.size, root.fillVerticesCache.floatData);
root.fillVerticesCache.reset();
root.fillVerticesCache.clear();
}
if (root.fillColorsCache != null && root.fillColorsCache.hasData()) {
root.copyFillColors(root.fillColorsCache.offset, root.fillColorsCache.size, root.fillColorsCache.intData);
root.fillColorsCache.reset();
root.fillColorsCache.clear();
}
if (root.fillNormalsCache != null && root.fillNormalsCache.hasData()) {
root.copyFillNormals(root.fillNormalsCache.offset, root.fillNormalsCache.size, root.fillNormalsCache.floatData);
root.fillNormalsCache.reset();
root.fillNormalsCache.clear();
}
if (root.fillTexCoordsCache != null && root.fillTexCoordsCache.hasData()) {
root.copyFillTexCoords(root.fillTexCoordsCache.offset, root.fillTexCoordsCache.size, root.fillTexCoordsCache.floatData);
root.fillTexCoordsCache.reset();
root.fillTexCoordsCache.clear();
}
if (root.fillAmbientCache != null && root.fillAmbientCache.hasData()) {
root.copyFillAmbient(root.fillAmbientCache.offset, root.fillAmbientCache.size, root.fillAmbientCache.intData);
root.fillAmbientCache.clear();
}
if (root.fillSpecularCache != null && root.fillSpecularCache.hasData()) {
root.copyFillSpecular(root.fillSpecularCache.offset, root.fillSpecularCache.size, root.fillSpecularCache.intData);
root.fillSpecularCache.clear();
}
if (root.fillEmissiveCache != null && root.fillEmissiveCache.hasData()) {
root.copyFillEmissive(root.fillEmissiveCache.offset, root.fillEmissiveCache.size, root.fillEmissiveCache.intData);
root.fillEmissiveCache.clear();
}
if (root.fillShininessCache != null && root.fillShininessCache.hasData()) {
root.copyFillShininess(root.fillShininessCache.offset, root.fillShininessCache.size, root.fillShininessCache.floatData);
root.fillShininessCache.clear();
}
if (root.lineVerticesCache != null && root.lineVerticesCache.hasData()) {
root.copyLineVertices(root.lineVerticesCache.offset, root.lineVerticesCache.size, root.lineVerticesCache.floatData);
root.lineVerticesCache.reset();
root.lineVerticesCache.clear();
}
if (root.lineColorsCache != null && root.lineColorsCache.hasData()) {
root.copyLineColors(root.lineColorsCache.offset, root.lineColorsCache.size, root.lineColorsCache.intData);
root.lineColorsCache.reset();
root.lineColorsCache.clear();
}
if (root.lineAttributesCache != null && root.lineAttributesCache.hasData()) {
root.copyLineAttributes(root.lineAttributesCache.offset, root.lineAttributesCache.size, root.lineAttributesCache.floatData);
root.lineAttributesCache.reset();
root.lineAttributesCache.clear();
}
if (root.pointVerticesCache != null && root.pointVerticesCache.hasData()) {
root.copyPointVertices(root.pointVerticesCache.offset, root.pointVerticesCache.size, root.pointVerticesCache.floatData);
root.pointVerticesCache.reset();
root.pointVerticesCache.clear();
}
if (root.pointColorsCache != null && root.pointColorsCache.hasData()) {
root.copyPointColors(root.pointColorsCache.offset, root.pointColorsCache.size, root.pointColorsCache.intData);
root.pointColorsCache.reset();
root.pointColorsCache.clear();
}
if (root.pointAttributesCache != null && root.pointAttributesCache.hasData()) {
root.copyPointAttributes(root.pointAttributesCache.offset, root.pointAttributesCache.size, root.pointAttributesCache.floatData);
root.pointAttributesCache.reset();
root.pointAttributesCache.clear();
}
}
}
@@ -2746,7 +2855,7 @@ public class PShape3D extends PShape {
// level of the shape hierarchy.
protected void aggregateImpl() {
if (family == GROUP) {
tess.reset();
tess.clear();
boolean firstGeom = true;
boolean firstStroke = true;
@@ -2804,6 +2913,7 @@ public class PShape3D extends PShape {
}
root.lastLineVertexOffset = tess.setLineVertex(root.lastLineVertexOffset);
root.lastLineIndexOffset = tess.setLineIndex(root.firstLineVertexRel, root.lastLineIndexOffset);
root.firstLineVertexRel += tess.lineVertexCount;
addLineIndexData(root.firstLineVertexAbs, tess.firstLineIndex, tess.lastLineIndex - tess.firstLineIndex + 1);
}
@@ -2814,6 +2924,7 @@ public class PShape3D extends PShape {
}
root.lastPointVertexOffset = tess.setPointVertex(root.lastPointVertexOffset);
root.lastPointIndexOffset = tess.setPointIndex(root.firstPointVertexRel, root.lastPointIndexOffset);
root.firstPointVertexRel += tess.pointVertexCount;
addPointIndexData(root.firstPointVertexAbs, tess.firstPointIndex, tess.lastPointIndex - tess.firstPointIndex + 1);
}
}
@@ -2925,11 +3036,45 @@ public class PShape3D extends PShape {
}
}
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
// The OpenGL resources have been already deleted
// when the context changed. We only need to zero
// them to avoid deleting them again when the GC
// runs the finalizers of the disposed object.
glFillVertexBufferID = 0;
glFillColorBufferID = 0;
glFillNormalBufferID = 0;
glFillTexCoordBufferID = 0;
glFillAmbientBufferID = 0;
glFillSpecularBufferID = 0;
glFillEmissiveBufferID = 0;
glFillShininessBufferID = 0;
glFillIndexBufferID = 0;
glLineVertexBufferID = 0;
glLineColorBufferID = 0;
glLineDirWidthBufferID = 0;
glLineIndexBufferID = 0;
glPointVertexBufferID = 0;
glPointColorBufferID = 0;
glPointSizeBufferID = 0;
glPointIndexBufferID = 0;
}
return outdated;
}
protected void initFillBuffers(int nvert, int nind) {
int sizef = nvert * PGL.SIZEOF_FLOAT;
int sizei = nvert * PGL.SIZEOF_INT;
int sizex = nind * PGL.SIZEOF_INDEX;
context = pgl.getContext();
glFillVertexBufferID = pg.createVertexBufferObject();
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillVertexBufferID);
pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, glMode);
@@ -3010,7 +3155,7 @@ public class PShape3D extends PShape {
modifiedFillVertices = false;
} else if (root.fillVerticesCache != null && root.fillVerticesCache.hasData()) {
root.copyFillVertices(root.fillVerticesCache.offset, root.fillVerticesCache.size, root.fillVerticesCache.floatData);
root.fillVerticesCache.reset();
root.fillVerticesCache.clear();
}
if (modifiedFillColors) {
@@ -3021,7 +3166,7 @@ public class PShape3D extends PShape {
modifiedFillColors = false;
} else if (root.fillColorsCache != null && root.fillColorsCache.hasData()) {
root.copyFillColors(root.fillColorsCache.offset, root.fillColorsCache.size, root.fillColorsCache.intData);
root.fillColorsCache.reset();
root.fillColorsCache.clear();
}
if (modifiedFillNormals) {
@@ -3032,7 +3177,7 @@ public class PShape3D extends PShape {
modifiedFillNormals = false;
} else if (root.fillNormalsCache != null && root.fillNormalsCache.hasData()) {
root.copyFillNormals(root.fillNormalsCache.offset, root.fillNormalsCache.size, root.fillNormalsCache.floatData);
root.fillNormalsCache.reset();
root.fillNormalsCache.clear();
}
if (modifiedFillTexCoords) {
@@ -3043,7 +3188,7 @@ public class PShape3D extends PShape {
modifiedFillTexCoords = false;
} else if (root.fillTexCoordsCache != null && root.fillTexCoordsCache.hasData()) {
root.copyFillTexCoords(root.fillTexCoordsCache.offset, root.fillTexCoordsCache.size, root.fillTexCoordsCache.floatData);
root.fillTexCoordsCache.reset();
root.fillTexCoordsCache.clear();
}
if (modifiedFillAmbient) {
@@ -3053,8 +3198,8 @@ public class PShape3D extends PShape {
root.fillAmbientCache.add(root.fillVertCopyOffset, tess.fillVertexCount, tess.fillAmbient);
modifiedFillAmbient = false;
} else if (root.fillAmbientCache != null && root.fillAmbientCache.hasData()) {
root.copyfillAmbient(root.fillAmbientCache.offset, root.fillAmbientCache.size, root.fillAmbientCache.intData);
root.fillAmbientCache.reset();
root.copyFillAmbient(root.fillAmbientCache.offset, root.fillAmbientCache.size, root.fillAmbientCache.intData);
root.fillAmbientCache.clear();
}
if (modifiedFillSpecular) {
@@ -3064,8 +3209,8 @@ public class PShape3D extends PShape {
root.fillSpecularCache.add(root.fillVertCopyOffset, tess.fillVertexCount, tess.fillSpecular);
modifiedFillSpecular = false;
} else if (root.fillSpecularCache != null && root.fillSpecularCache.hasData()) {
root.copyfillSpecular(root.fillSpecularCache.offset, root.fillSpecularCache.size, root.fillSpecularCache.intData);
root.fillSpecularCache.reset();
root.copyFillSpecular(root.fillSpecularCache.offset, root.fillSpecularCache.size, root.fillSpecularCache.intData);
root.fillSpecularCache.clear();
}
if (modifiedFillEmissive) {
@@ -3075,8 +3220,8 @@ public class PShape3D extends PShape {
root.fillEmissiveCache.add(root.fillVertCopyOffset, tess.fillVertexCount, tess.fillEmissive);
modifiedFillEmissive = false;
} else if (root.fillEmissiveCache != null && root.fillEmissiveCache.hasData()) {
root.copyfillEmissive(root.fillEmissiveCache.offset, root.fillEmissiveCache.size, root.fillEmissiveCache.intData);
root.fillEmissiveCache.reset();
root.copyFillEmissive(root.fillEmissiveCache.offset, root.fillEmissiveCache.size, root.fillEmissiveCache.intData);
root.fillEmissiveCache.clear();
}
if (modifiedFillShininess) {
@@ -3086,8 +3231,8 @@ public class PShape3D extends PShape {
root.fillShininessCache.add(root.fillVertCopyOffset, tess.fillVertexCount, tess.fillShininess);
modifiedFillShininess = false;
} else if (root.fillShininessCache != null && root.fillShininessCache.hasData()) {
root.copyfillShininess(root.fillShininessCache.offset, root.fillShininessCache.size, root.fillShininessCache.floatData);
root.fillShininessCache.reset();
root.copyFillShininess(root.fillShininessCache.offset, root.fillShininessCache.size, root.fillShininessCache.floatData);
root.fillShininessCache.clear();
}
}
@@ -3100,7 +3245,7 @@ public class PShape3D extends PShape {
modifiedLineVertices = false;
} else if (root.lineVerticesCache != null && root.lineVerticesCache.hasData()) {
root.copyLineVertices(root.lineVerticesCache.offset, root.lineVerticesCache.size, root.lineVerticesCache.floatData);
root.lineVerticesCache.reset();
root.lineVerticesCache.clear();
}
if (modifiedLineColors) {
@@ -3111,7 +3256,7 @@ public class PShape3D extends PShape {
modifiedLineColors = false;
} else if (root.lineColorsCache != null && root.lineColorsCache.hasData()) {
root.copyLineColors(root.lineColorsCache.offset, root.lineColorsCache.size, root.lineColorsCache.intData);
root.lineColorsCache.reset();
root.lineColorsCache.clear();
}
if (modifiedLineAttributes) {
@@ -3122,7 +3267,7 @@ public class PShape3D extends PShape {
modifiedLineAttributes = false;
} else if (root.lineAttributesCache != null && root.lineAttributesCache.hasData()) {
root.copyLineAttributes(root.lineAttributesCache.offset, root.lineAttributesCache.size, root.lineAttributesCache.floatData);
root.lineAttributesCache.reset();
root.lineAttributesCache.clear();
}
}
@@ -3135,7 +3280,7 @@ public class PShape3D extends PShape {
modifiedPointVertices = false;
} else if (root.pointVerticesCache != null && root.pointVerticesCache.hasData()) {
root.copyPointVertices(root.pointVerticesCache.offset, root.pointVerticesCache.size, root.pointVerticesCache.floatData);
root.pointVerticesCache.reset();
root.pointVerticesCache.clear();
}
if (modifiedPointColors) {
@@ -3146,7 +3291,7 @@ public class PShape3D extends PShape {
modifiedPointColors = false;
} else if (root.pointColorsCache != null && root.pointColorsCache.hasData()) {
root.copyPointColors(root.pointColorsCache.offset, root.pointColorsCache.size, root.pointColorsCache.intData);
root.pointColorsCache.reset();
root.pointColorsCache.clear();
}
if (modifiedPointAttributes) {
@@ -3157,7 +3302,7 @@ public class PShape3D extends PShape {
modifiedPointAttributes = false;
} else if (root.pointAttributesCache != null && root.pointAttributesCache.hasData()) {
root.copyPointAttributes(root.pointAttributesCache.offset, root.pointAttributesCache.size, root.pointAttributesCache.floatData);
root.pointAttributesCache.reset();
root.pointAttributesCache.clear();
}
}
@@ -3235,28 +3380,28 @@ public class PShape3D extends PShape {
}
protected void copyfillAmbient(int offset, int size, int[] ambient) {
protected void copyFillAmbient(int offset, int size, int[] ambient) {
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillAmbientBufferID);
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(ambient, 0, size));
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
}
protected void copyfillSpecular(int offset, int size, int[] specular) {
protected void copyFillSpecular(int offset, int size, int[] specular) {
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillSpecularBufferID);
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(specular, 0, size));
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
}
protected void copyfillEmissive(int offset, int size, int[] emissive) {
protected void copyFillEmissive(int offset, int size, int[] emissive) {
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillEmissiveBufferID);
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(emissive, 0, size));
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
}
protected void copyfillShininess(int offset, int size, float[] shininess) {
protected void copyFillShininess(int offset, int size, float[] shininess) {
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glFillShininessBufferID);
pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_FLOAT, size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(shininess, 0, size));
pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0);
@@ -3785,7 +3930,7 @@ public class PShape3D extends PShape {
this.size = 0;
}
void reset() {
void clear() {
offset = 0;
size = 0;
}
+15 -8
View File
@@ -97,8 +97,7 @@ public class PTexture implements PConstants {
this.parent = parent;
pg = (PGraphicsAndroid3D)parent.g;
pgl = pg.pgl;
context = pgl.getContext();
pgl = pg.pgl;
glID = 0;
@@ -114,8 +113,7 @@ public class PTexture implements PConstants {
} finally {
super.finalize();
}
}
}
////////////////////////////////////////////////////////////
@@ -771,23 +769,24 @@ public class PTexture implements PConstants {
pgl.enableTexturing(glTarget);
context = pgl.getContext();
glID = pg.createTextureObject();
pgl.glBindTexture(glTarget, glID);
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MIN_FILTER, glMinFilter);
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MAG_FILTER, glMagFilter);
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MAG_FILTER, glMagFilter);
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_WRAP_S, glWrapS);
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_WRAP_T, glWrapT);
pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_WRAP_T, glWrapT);
// First, we use glTexImage2D to set the full size of the texture (glW/glH might be diff
// from w/h in the case that the GPU doesn't support NPOT textures)
pgl.glTexImage2D(glTarget, 0, glFormat, glWidth, glHeight, 0, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, null);
// Makes sure that the texture buffer in video memory doesn't contain any garbage.
pgl.initTexture(glTarget, width, height, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE);
pgl.initTexture(glTarget, width, height, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE);
pgl.glBindTexture(glTarget, 0);
pgl.disableTexturing(glTarget);
pgl.disableTexturing(glTarget);
}
@@ -802,6 +801,14 @@ public class PTexture implements PConstants {
}
protected boolean contextIsOutdated() {
boolean outdated = !pgl.contextIsCurrent(context);
if (outdated) {
glID = 0;
}
return outdated;
}
///////////////////////////////////////////////////////////
// Utilities.
@@ -39,8 +39,6 @@ import java.nio.IntBuffer;
* By Andres Colubri.
*/
// TODO: restart framebuffer when context changes
public class PFramebuffer implements PConstants {
protected PApplet parent;
protected PGraphicsOpenGL pg;
@@ -34,7 +34,6 @@ import java.util.TimerTask;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLContext;
@@ -210,16 +209,16 @@ public class PGL {
public static final int GL_DST_COLOR = GL.GL_DST_COLOR;
public static final int GL_SRC_COLOR = GL.GL_SRC_COLOR;
public static final int GL_FRAMEBUFFER = GL.GL_FRAMEBUFFER;
public static final int GL_COLOR_ATTACHMENT0 = GL.GL_COLOR_ATTACHMENT0;
public static final int GL_FRAMEBUFFER = GL.GL_FRAMEBUFFER;
public static final int GL_COLOR_ATTACHMENT0 = GL.GL_COLOR_ATTACHMENT0;
public static final int GL_COLOR_ATTACHMENT1 = GL2.GL_COLOR_ATTACHMENT1;
public static final int GL_COLOR_ATTACHMENT2 = GL2.GL_COLOR_ATTACHMENT2;
public static final int GL_COLOR_ATTACHMENT3 = GL2.GL_COLOR_ATTACHMENT3;
public static final int GL_RENDERBUFFER = GL.GL_RENDERBUFFER;
public static final int GL_DEPTH_ATTACHMENT = GL.GL_DEPTH_ATTACHMENT;
public static final int GL_STENCIL_ATTACHMENT = GL.GL_STENCIL_ATTACHMENT;
public static final int GL_READ_FRAMEBUFFER = GL2.GL_READ_FRAMEBUFFER;
public static final int GL_DRAW_FRAMEBUFFER = GL2.GL_DRAW_FRAMEBUFFER ;
public static final int GL_COLOR_ATTACHMENT1 = GL2.GL_COLOR_ATTACHMENT1;
public static final int GL_COLOR_ATTACHMENT2 = GL2.GL_COLOR_ATTACHMENT2;
public static final int GL_COLOR_ATTACHMENT3 = GL2.GL_COLOR_ATTACHMENT3;
public static final int GL_READ_FRAMEBUFFER = GL2.GL_READ_FRAMEBUFFER;
public static final int GL_DRAW_FRAMEBUFFER = GL2.GL_DRAW_FRAMEBUFFER;
public static final int GL_VERTEX_SHADER = GL2.GL_VERTEX_SHADER;
public static final int GL_FRAGMENT_SHADER = GL2.GL_FRAGMENT_SHADER;
@@ -1439,8 +1439,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (primarySurface) {
int[] temp = { 0 };
pgl.glGetIntegerv(PGL.GL_SAMPLES, temp, 0);
if (antialias != temp[0]) {
PGraphics.showWarning("Smooth level " + antialias + " not supported. Using " + temp[0] + " instead.");
if (antialias != temp[0] && 1 < temp[0] && 1 < antialias) {
antialias = temp[0];
}
}
@@ -2944,7 +2943,7 @@ public class PGraphicsOpenGL extends PGraphics {
smooth = true;
if (maxSamples < level) {
PGraphics.showWarning("Smooth level not supported by the video card. Using " + maxSamples + " instead.");
PGraphics.showWarning("Smooth level " + level + " is not supported by the hardware. Using " + maxSamples + " instead.");
level = maxSamples;
}