android sync

This commit is contained in:
codeanticode
2012-09-03 01:48:59 +00:00
parent 3fa1dcfc06
commit 45930bda63
7 changed files with 1694 additions and 1661 deletions
@@ -196,7 +196,7 @@ public class FrameBuffer implements PConstants {
public void finish() {
if (noDepth) {
// No need to clear depth buffer because depth testing was disabled.
if (pg.hintEnabled(ENABLE_DEPTH_TEST)) {
if (pg.getHint(ENABLE_DEPTH_TEST)) {
pgl.enable(PGL.DEPTH_TEST);
} else {
pgl.disable(PGL.DEPTH_TEST);
+21 -5
View File
@@ -3,8 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2011 Andres Colubri
Copyright (c) 2010 Ben Fry and Casey Reas
Copyright (c) 2011-12 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -520,10 +519,19 @@ public class PGL {
}
protected int primaryDrawBuffer() {
if (PGraphicsOpenGL.screenFramebuffer.glFbo != 0) {
return GLES20.GL_BACK;
} else {
return GLES20.GL_COLOR_ATTACHMENT0;
}
}
/*
protected boolean primaryIsDoubleBuffered() {
return PGraphicsOpenGL.screenFramebuffer.glFbo != 0;
}
*/
protected boolean primaryIsFboBacked() {
return PGraphicsOpenGL.screenFramebuffer.glFbo != 0;
@@ -569,6 +577,14 @@ public class PGL {
}
protected void bindBackBufferTex() {
}
protected void unbindBackBufferTex() {
}
///////////////////////////////////////////////////////////
// Frame rendering
@@ -576,8 +592,8 @@ public class PGL {
protected void beginOnscreenDraw(boolean clear) {
if (clear && !FORCE_SCREEN_FBO) {
// Simplest scenario: clear mode means we clear both the color and depth buffers.
// No need for saving front color buffer, etc.
// Simplest scenario: clear mode means we clear both the color and depth
// buffers. No need for saving front color buffer, etc.
GLES20.glClearColor(0, 0, 0, 0);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
PGraphicsOpenGL.screenFramebuffer.glFbo = 0;
@@ -66,7 +66,7 @@ public class PGraphics2D extends PGraphicsOpenGL {
@Override
public void hint(int which) {
if (which == ENABLE_STROKE_PERSPECTIVE) {
showWarning("2D lines cannot be perspective-corrected.");
showWarning("Strokes cannot be perspective-corrected in 2D.");
return;
}
super.hint(which);
@@ -47,10 +47,6 @@ public class PGraphicsOpenGL extends PGraphics {
protected WeakHashMap<PFont, FontTexture> fontMap =
new WeakHashMap<PFont, FontTexture>();
/** Additional image parameters not covered by the cache. */
protected WeakHashMap<PImage, Object> paramMap =
new WeakHashMap<PImage, Object>();
// ........................................................
// Basic rendering parameters:
@@ -632,38 +628,6 @@ public class PGraphicsOpenGL extends PGraphics {
}
//////////////////////////////////////////////////////////////
/**
* Store parameters for a renderer that requires extra metadata of
* some kind.
* @param renderer The PGraphics renderer associated to the image
* @param storage The parameters required by the renderer
*/
public void setParams(PImage image, Object params) {
paramMap.put(image, params);
}
/**
* Get the parameters for the specified renderer.
* @param renderer The PGraphics renderer associated to the image
* @return parameters stored for the specified renderer
*/
public Object getParams(PImage image) {
return paramMap.get(image);
}
/**
* Remove information associated with this renderer from the cache, if any.
* @param renderer The PGraphics renderer whose parameters should be removed
*/
public void removeParams(PImage image) {
paramMap.remove(image);
}
//////////////////////////////////////////////////////////////
// RESOURCE HANDLING
@@ -672,6 +636,7 @@ public class PGraphicsOpenGL extends PGraphics {
protected class GLResource {
int id;
int context;
GLResource(int id, int context) {
this.id = id;
this.context = context;
@@ -1589,9 +1554,7 @@ public class PGraphicsOpenGL extends PGraphics {
if (primarySurface) {
pgl.updatePrimary();
if (pgl.primaryIsDoubleBuffered()) {
pgl.drawBuffer(PGL.BACK);
}
pgl.drawBuffer(pgl.primaryDrawBuffer());
} else {
if (!pgl.initialized) {
initOffscreen();
@@ -1677,7 +1640,6 @@ public class PGraphicsOpenGL extends PGraphics {
// The screen texture should be deleted because it
// corresponds to the old window size.
pgPrimary.removeCache(this);
pgPrimary.removeParams(this);
texture = null;
loadTexture();
}
@@ -1709,8 +1671,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
// Because y is flipped, the vertices that should be specified by
// the user in CCW order to define a front-facing facet, end up being
// CW.
// the user in CCW order to define a front-facing facet, end up being CW.
pgl.frontFace(PGL.CW);
pgl.disable(PGL.CULL_FACE);
@@ -1897,35 +1858,32 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.depthMask(true);
}
if (pgl.primaryIsDoubleBuffered()) {
pgl.drawBuffer(PGL.BACK);
}
pgl.drawBuffer(pgl.primaryDrawBuffer());
}
protected void beginPixelsOp(int op) {
if (primarySurface) {
if (pgl.primaryIsDoubleBuffered()) {
// We read or write from the back buffer, where all the
// drawing in the current frame is taking place.
if (pgl.primaryIsFboBacked()) {
if (op == OP_READ) {
pgl.readBuffer(PGL.BACK);
} else {
pgl.drawBuffer(PGL.BACK);
}
offscreenNotCurrent = false;
} else if (pgl.primaryIsFboBacked()) {
if (op == OP_READ) {
// We read from the color FBO, but the multisample FBO is currently bound, so:
// We read from the color FBO, but the multisample FBO is currently
// bound, so:
offscreenNotCurrent = true;
pgl.bindPrimaryColorFBO();
pgl.readBuffer(PGL.COLOR_ATTACHMENT0);
pgl.readBuffer(pgl.primaryDrawBuffer());
} else {
// We write directly to the multisample FBO.
offscreenNotCurrent = false;
pgl.drawBuffer(PGL.COLOR_ATTACHMENT0);
pgl.drawBuffer(pgl.primaryDrawBuffer());
}
} else {
// We read or write from the back buffer, where all the
// drawing in the current frame is taking place.
if (op == OP_READ) {
pgl.readBuffer(pgl.primaryDrawBuffer());
} else {
pgl.drawBuffer(pgl.primaryDrawBuffer());
}
offscreenNotCurrent = false;
}
} else {
@@ -2175,7 +2133,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected boolean hintEnabled(int which) {
protected boolean getHint(int which) {
if (which > 0) {
return hints[which];
} else {
@@ -2225,10 +2183,12 @@ public class PGraphicsOpenGL extends PGraphics {
}
}
protected void endShape(int[] indices) {
endShape(indices, null);
}
protected void endShape(int[] indices, int[] edges) {
if (shape != TRIANGLE && shape != TRIANGLES) {
throw new RuntimeException("Indices and edges can only be set for " +
@@ -5240,6 +5200,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
//////////////////////////////////////////////////////////////
// RENDERER SUPPORT QUERIES
@@ -5253,6 +5214,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
//////////////////////////////////////////////////////////////
// PIMAGE METHODS
@@ -5510,9 +5472,8 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (tex != null) {
texture = tex;
texture.setFlippedY(true);
texture.invertedY(true);
pgPrimary.setCache(this, texture);
pgPrimary.setParams(this, params);
if (!primarySurface && offscreenFramebuffer != null) {
// Attach as the color buffer for this offscreen surface
@@ -5549,9 +5510,8 @@ public class PGraphicsOpenGL extends PGraphics {
Texture.Parameters params = new Texture.Parameters(ARGB,
sampling, mipmap);
texture = new Texture(parent, width, height, params);
texture.setFlippedY(true);
this.setCache(pgPrimary, texture);
this.setParams(pgPrimary, params);
texture.invertedY(true);
pgPrimary.setCache(this, texture);
}
}
@@ -5580,6 +5540,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
//////////////////////////////////////////////////////////////
// IMAGE CONVERSION
@@ -5615,6 +5576,7 @@ public class PGraphicsOpenGL extends PGraphics {
*/
//////////////////////////////////////////////////////////////
// MASK
@@ -5644,6 +5606,7 @@ public class PGraphicsOpenGL extends PGraphics {
}
//////////////////////////////////////////////////////////////
// FILTER
@@ -5689,7 +5652,7 @@ public class PGraphicsOpenGL extends PGraphics {
Texture.Parameters params = new Texture.Parameters(ARGB, Texture.POINT,
false);
textureCopy = new Texture(parent, width, height, params);
textureCopy.setFlippedY(true);
textureCopy.invertedY(true);
imageCopy = wrapTexture(textureCopy);
}
textureCopy.set(texture.glTarget, texture.glName,
@@ -5946,27 +5909,33 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected void bindBackTexture() {
if (primarySurface) {
pgl.bindBackBufferTex();
} else {
}
}
protected void unbindBackTexture() {
if (primarySurface) {
pgl.unbindBackBufferTex();
} else {
}
}
/**
* This utility method creates a texture for the provided image, and adds it
* to the metadata cache of the image.
* @param img the image to have a texture metadata associated to it
*/
protected Texture addTexture(PImage img) {
Texture.Parameters params = (Texture.Parameters)pgPrimary.getParams(img);
if (params == null) {
params = new Texture.Parameters();
if (hints[DISABLE_TEXTURE_MIPMAPS]) {
params.mipmaps = false;
} else {
params.mipmaps = true;
}
params.sampling = textureSampling;
if (params.sampling == Texture.TRILINEAR && !params.mipmaps) {
params.sampling = Texture.BILINEAR;
}
params.wrapU = textureWrap;
params.wrapV = textureWrap;
}
Texture.Parameters params =
new Texture.Parameters(ARGB, textureSampling,
getHint(ENABLE_TEXTURE_MIPMAPS),textureWrap);
return addTexture(img, params);
}
@@ -5981,7 +5950,6 @@ public class PGraphicsOpenGL extends PGraphics {
}
Texture tex = new Texture(img.parent, img.width, img.height, params);
pgPrimary.setCache(img, tex);
pgPrimary.setParams(img, params);
return tex;
}
@@ -6015,7 +5983,6 @@ public class PGraphicsOpenGL extends PGraphics {
img.height = tex.height;
img.format = ARGB;
pgPrimary.setCache(img, tex);
pgPrimary.setParams(img, tex.getParameters());
return img;
}
@@ -6527,6 +6494,8 @@ public class PGraphicsOpenGL extends PGraphics {
protected int projmodelviewMatrixLoc;
protected int modelviewMatrixLoc;
protected int projectionMatrixLoc;
protected int backbufferSamplerLoc;
protected int resolutionLoc;
protected int inVertexLoc;
protected int inColorLoc;
@@ -6555,6 +6524,9 @@ public class PGraphicsOpenGL extends PGraphics {
projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix");
modelviewMatrixLoc = getUniformLoc("modelviewMatrix");
projectionMatrixLoc = getUniformLoc("projectionMatrix");
backbufferSamplerLoc = getUniformLoc("backbufferSampler");
resolutionLoc = getUniformLoc("resolution");
}
@Override
@@ -6595,6 +6567,16 @@ public class PGraphicsOpenGL extends PGraphics {
pgCurrent.updateGLProjection();
setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection);
}
float w = pgCurrent.width;
float h = pgCurrent.height;
setUniformValue(resolutionLoc, w, h);
if (-1 < backbufferSamplerLoc) {
setUniformValue(backbufferSamplerLoc, lastTexUnit);
pgl.activeTexture(PGL.TEXTURE0 + lastTexUnit);
pgCurrent.bindBackTexture();
}
}
@Override
@@ -6602,6 +6584,12 @@ public class PGraphicsOpenGL extends PGraphics {
if (-1 < inVertexLoc) pgl.disableVertexAttribArray(inVertexLoc);
if (-1 < inColorLoc) pgl.disableVertexAttribArray(inColorLoc);
if (-1 < backbufferSamplerLoc) {
pgl.activeTexture(PGL.TEXTURE0 + lastTexUnit);
pgCurrent.unbindBackTexture();
pgl.activeTexture(PGL.TEXTURE0);
}
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
super.unbind();
@@ -6836,20 +6824,20 @@ public class PGraphicsOpenGL extends PGraphics {
float dispu = 0;
float dispv = 0;
if (tex.isFlippedX()) {
if (tex.invertedX()) {
scaleu = -1;
dispu = 1;
}
if (tex.isFlippedY()) {
if (tex.invertedY()) {
scalev = -1;
dispv = 1;
}
scaleu *= tex.maxTexcoordU;
dispu *= tex.maxTexcoordU;
scalev *= tex.maxTexcoordV;
dispv *= tex.maxTexcoordV;
scaleu *= tex.maxTexcoordU();
dispu *= tex.maxTexcoordU();
scalev *= tex.maxTexcoordV();
dispv *= tex.maxTexcoordV();
if (-1 < texcoordMatrixLoc) {
if (tcmat == null) {
@@ -6936,12 +6924,12 @@ public class PGraphicsOpenGL extends PGraphics {
float dispu = 0;
float dispv = 0;
if (tex.isFlippedX()) {
if (tex.invertedX()) {
scaleu = -1;
dispu = 1;
}
if (tex.isFlippedY()) {
if (tex.invertedY()) {
scalev = -1;
dispv = 1;
}
@@ -7078,13 +7066,13 @@ public class PGraphicsOpenGL extends PGraphics {
float h = pgCurrent.viewport[3];
setUniformValue(viewportLoc, x, y, w, h);
if (pgCurrent.hintEnabled(ENABLE_STROKE_PERSPECTIVE)) {
if (pgCurrent.getHint(ENABLE_STROKE_PERSPECTIVE)) {
setUniformValue(perspectiveLoc, 1);
} else {
setUniformValue(perspectiveLoc, 0);
}
if (pgCurrent.hintEnabled(ENABLE_ACCURATE_2D)) {
if (pgCurrent.getHint(ENABLE_ACCURATE_2D)) {
setUniformValue(scaleLoc, 1.0f, 1.0f, 1.0f);
} else {
if (usingOrthoProjection) {
@@ -7199,7 +7187,7 @@ public class PGraphicsOpenGL extends PGraphics {
float h = pgCurrent.viewport[3];
setUniformValue(viewportLoc, x, y, w, h);
if (pgCurrent.hintEnabled(ENABLE_STROKE_PERSPECTIVE)) {
if (pgCurrent.getHint(ENABLE_STROKE_PERSPECTIVE)) {
setUniformValue(perspectiveLoc, 1);
} else {
setUniformValue(perspectiveLoc, 0);
@@ -75,6 +75,7 @@ public class PShader {
protected HashMap<Integer, Texture> textures;
protected int firstTexUnit;
protected int lastTexUnit;
public PShader() {
@@ -473,6 +474,12 @@ public class PShader {
}
protected void setUniformTex(int loc, Texture tex) {
// get unit from last value in bindTextures ...
// pgl.activeTexture(PGL.TEXTURE0 + unit);
tex.bind();
}
/*
// The individual attribute setters are not really needed, read this:
@@ -523,7 +530,7 @@ public class PShader {
protected void consumeUniforms() {
if (uniformValues != null && 0 < uniformValues.size()) {
int texUnit = firstTexUnit;
lastTexUnit = firstTexUnit;
for (Integer loc: uniformValues.keySet()) {
UniformValue val = uniformValues.get(loc);
if (val.type == UniformValue.INT1) {
@@ -586,12 +593,12 @@ public class PShader {
} else if (val.type == UniformValue.SAMPLER2D) {
PImage img = (PImage)val.value;
Texture tex = pgMain.getTexture(img);
pgl.uniform1i(loc, texUnit);
pgl.uniform1i(loc, lastTexUnit);
if (textures == null) {
textures = new HashMap<Integer, Texture>();
}
textures.put(texUnit, tex);
texUnit++;
textures.put(lastTexUnit, tex);
lastTexUnit++;
}
}
uniformValues.clear();
@@ -394,7 +394,7 @@ public class PShapeOpenGL extends PShape {
}
public void updateRoot(PShape root) {
protected void updateRoot(PShape root) {
this.root = (PShapeOpenGL) root;
if (family == GROUP) {
for (int i = 0; i < childCount; i++) {
@@ -546,6 +546,7 @@ public class PShapeOpenGL extends PShape {
}
/*
@Override
public PVector getTop(PVector top) {
if (top == null) {
@@ -568,6 +569,7 @@ public class PShapeOpenGL extends PShape {
getVertexMax(bottom);
return bottom;
}
*/
protected void getVertexMin(PVector min) {
@@ -2880,6 +2882,7 @@ public class PShapeOpenGL extends PShape {
fill, stroke, curveDetail, code);
code = VERTEX;
idx++;
break;
case BREAK:
code = BREAK;
@@ -2931,6 +2934,7 @@ public class PShapeOpenGL extends PShape {
fill, stroke, curveDetail, code);
code = VERTEX;
idx++;
break;
case BREAK:
code = BREAK;
@@ -4118,7 +4122,7 @@ public class PShapeOpenGL extends PShape {
// Or accurate 2D mode is enabled, which forces each
// shape to be rendered separately.
protected boolean fragmentedGroup(PGraphicsOpenGL g) {
return g.hintEnabled(ENABLE_ACCURATE_2D) ||
return g.getHint(ENABLE_ACCURATE_2D) ||
(textures != null && 1 < textures.size()) ||
strokedTexture;
}
@@ -4137,7 +4141,7 @@ public class PShapeOpenGL extends PShape {
@Override
public void post(PGraphics g) {
protected void post(PGraphics g) {
if (g instanceof PGraphicsOpenGL) {
} else {
super.post(g);
File diff suppressed because it is too large Load Diff