API change: RenderLayer

- use setReady(bool) instead of public field
- no more implicit call to compile() when 'newData' is true
  -> call compile() when needed
- make RenderLayer function protected
This commit is contained in:
Hannes Janetzek 2013-09-11 00:31:28 +02:00
parent eb1e8b63c5
commit 0aa7818731
16 changed files with 69 additions and 81 deletions

@ -622,7 +622,7 @@ class TextRenderLayer extends BasicRenderLayer {
layers.textureLayers = mCurLayer.l;
mMapPosition = mCurLayer.pos;
this.newData = true;
compile();
}
//if (!mHolding)

@ -104,7 +104,7 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
if (mItems == null) {
if (layers.textureLayers != null) {
layers.clear();
newData = true;
compile();
}
return;
}
@ -183,7 +183,8 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
}
mSymbolLayer.prepare();
layers.textureLayers = mSymbolLayer;
newData = true;
compile();
}
@Override

@ -127,7 +127,7 @@ public class PathOverlay extends Layer {
if (size == 0) {
if (layers.baseLayers != null) {
layers.clear();
newData = true;
compile();
}
return;
}
@ -224,7 +224,7 @@ public class PathOverlay extends Layer {
// items are placed relative to scale 1
mMapPosition.scale = 1 << z;
newData = true;
compile();
}
private int addPoint(float[] points, int i, int x, int y) {

@ -49,7 +49,7 @@ public class TileRenderLayer extends RenderLayer {
}
@Override
public void update(MapPosition pos, boolean positionChanged, Matrices m) {
protected void update(MapPosition pos, boolean positionChanged, Matrices m) {
if (mAlpha == 0){
mTileManager.releaseTiles(mDrawTiles);
@ -84,12 +84,12 @@ public class TileRenderLayer extends RenderLayer {
}
@Override
public void compile() {
protected void compile() {
}
@Override
public void render(MapPosition pos, Matrices m) {
protected void render(MapPosition pos, Matrices m) {
}

@ -317,21 +317,10 @@ public class GLRenderer {
/* update layers */
RenderLayer[] layers = mMap.getLayers().getRenderLayers();
for (int i = 0, n = layers.length; i < n; i++)
layers[i].update(pos, changed, mMatrices);
/* compile layers */
for (int i = 0, n = layers.length; i < n; i++) {
RenderLayer renderLayer = layers[i];
if (renderLayer.newData) {
renderLayer.compile();
renderLayer.newData = false;
}
}
for (int i = 0, n = layers.length; i < n; i++) {
RenderLayer renderLayer = layers[i];
renderLayer.update(pos, changed, mMatrices);
if (renderLayer.isReady)
renderLayer.render(mMapPosition, mMatrices);
@ -450,6 +439,10 @@ public class GLRenderer {
return mQuadIndicesID;
}
/**
* Get VBO ID for a simple quad. Handy for simple custom RenderLayers
* Vertices: { -1, -1, -1, 1, 1, -1, 1, 1 }
*/
public static int getQuadVertexVBO() {
return mQuadVerticesID;
}

@ -27,11 +27,16 @@ public abstract class RenderLayer {
*/
protected MapPosition mMapPosition;
/** flag to set when data is ready for (re)compilation. */
public boolean newData;
/** flag to set when layer is ready for rendering */
public boolean isReady;
boolean isReady;
/**
* Set 'ready for render' state when layer data is ready for rendering.
* This will
* */
protected void setReady(boolean ready){
isReady = ready;
}
public RenderLayer() {
mMapPosition = new MapPosition();
@ -40,8 +45,7 @@ public abstract class RenderLayer {
/**
* ////////////////////// GLRender Thread ///////////////////////////
* 1. Called first by GLRenderer:
* Update the layer state here. Set 'this.newData = true' when
* 'compile()' should be called before next call to 'render()'
* Update the layer state here.
*
* @param position current MapPosition
* @param changed
@ -49,14 +53,15 @@ public abstract class RenderLayer {
* @param matrices contains the current view- and projection-matrices
* and 'mvp' matrix for temporary use.
*/
public abstract void update(MapPosition position, boolean changed,
protected abstract void update(MapPosition position, boolean changed,
Matrices matrices);
/**
* 2. Compile vertex buffers and upload textures for drawing:
* Set 'this.isReady = true' when things are ready for 'render()'
* 2. Compile vertex buffers and upload textures for drawing.
* Not strictly required but useful when subclassing a RenderLayer.
* Should only be called from update()
*/
public abstract void compile();
protected abstract void compile();
/**
* 3. Draw layer:
@ -66,7 +71,7 @@ public abstract class RenderLayer {
* 'matrices.mvp' is for temporary use to build the model-
* view-projection to set as uniform.
*/
public abstract void render(MapPosition position, Matrices matrices);
protected abstract void render(MapPosition position, Matrices matrices);
/**
* Utility: Set matrices.mvp matrix relative to the difference of current

@ -45,7 +45,7 @@ public abstract class BasicRenderLayer extends RenderLayer {
* Render all 'layers'
*/
@Override
public synchronized void render(MapPosition curPos, Matrices m) {
protected synchronized void render(MapPosition curPos, Matrices m) {
MapPosition pos = mMapPosition;
float div = FastMath.pow(pos.zoomLevel - curPos.zoomLevel);
@ -94,12 +94,12 @@ public abstract class BasicRenderLayer extends RenderLayer {
}
@Override
public void compile() {
protected void compile() {
int newSize = layers.getSize();
if (newSize <= 0) {
BufferObject.release(layers.vbo);
layers.vbo = null;
isReady = false;
setReady(false);
return;
}
@ -107,6 +107,6 @@ public abstract class BasicRenderLayer extends RenderLayer {
layers.vbo = BufferObject.get(GL20.GL_ARRAY_BUFFER, newSize);
if (GLRenderer.uploadLayers(layers, newSize, true))
isReady = true;
setReady(true);
}
}

@ -57,7 +57,7 @@ public class BitmapRenderLayer extends BasicRenderLayer {
}
@Override
public synchronized void update(MapPosition pos, boolean changed, Matrices m) {
protected synchronized void update(MapPosition pos, boolean changed, Matrices m) {
if (!initialized) {
layers.clear();
@ -65,17 +65,17 @@ public class BitmapRenderLayer extends BasicRenderLayer {
l.setBitmap(mBitmap, mWidth, mHeight);
layers.textureLayers = l;
newData = true;
mUpdateBitmap = true;
}
if (mUpdateBitmap) {
newData = true;
mUpdateBitmap = false;
compile();
}
}
@Override
public synchronized void compile() {
protected synchronized void compile() {
if (mBitmap == null)
return;
@ -85,7 +85,7 @@ public class BitmapRenderLayer extends BasicRenderLayer {
}
@Override
public synchronized void render(MapPosition pos, Matrices m) {
protected synchronized void render(MapPosition pos, Matrices m) {
m.useScreenCoordinates(false, 8);
BitmapRenderer.draw(layers.textureLayers, m, 1, 1);
}

@ -60,37 +60,33 @@ public class CustomRenderLayer extends RenderLayer {
// ---------- everything below runs in GLRender Thread ----------
@Override
public void update(MapPosition pos, boolean changed, Matrices matrices) {
protected void update(MapPosition pos, boolean changed, Matrices matrices) {
if (!mInitialized) {
if (!init())
return;
mInitialized = true;
// tell GLRender to call 'compile' when data has changed
newData = true;
// fix current MapPosition
mMapPosition.copy(pos);
compile();
}
}
@Override
public void compile() {
protected void compile() {
// modify mVerticesData and put in FloatBuffer
mVertices.clear();
mVertices.put(mVerticesData);
mVertices.flip();
newData = false;
// tell GLRender to call 'render'
isReady = true;
setReady(true);
}
@Override
public void render(MapPosition pos, Matrices m) {
protected void render(MapPosition pos, Matrices m) {
// Use the program object
GLState.useProgram(mProgramObject);

@ -54,16 +54,14 @@ public class CustomRenderLayer2 extends RenderLayer {
float mCellScale = 60 * GLRenderer.COORD_SCALE;
@Override
public void update(MapPosition pos, boolean changed, Matrices matrices) {
protected void update(MapPosition pos, boolean changed, Matrices matrices) {
if (!mInitialized) {
if (!init())
return;
mInitialized = true;
// tell GLRender to call 'compile' when data has changed
newData = true;
compile();
// fix current MapPosition
//mMapPosition.setPosition(53.1, 8.8);
@ -78,7 +76,7 @@ public class CustomRenderLayer2 extends RenderLayer {
}
@Override
public void compile() {
protected void compile() {
float[] vertices = new float[12];
@ -92,14 +90,12 @@ public class CustomRenderLayer2 extends RenderLayer {
mVBO = BufferObject.get(GL20.GL_ARRAY_BUFFER, 0);
mVBO.loadBufferData(buf, 12 * 4);
newData = false;
// tell GLRender to call 'render'
isReady = true;
setReady(true);
}
@Override
public void render(MapPosition pos, Matrices m) {
protected void render(MapPosition pos, Matrices m) {
// Use the program object
GLState.useProgram(mProgramObject);

@ -88,7 +88,7 @@ public class ExtrusionRenderLayer extends RenderLayer {
}
@Override
public void update(MapPosition pos, boolean changed, Matrices matrices) {
protected void update(MapPosition pos, boolean changed, Matrices matrices) {
mMapPosition.copy(pos);
if (!initialized && !initShader())
@ -98,7 +98,7 @@ public class ExtrusionRenderLayer extends RenderLayer {
return;
if (mAlpha == 0 || pos.zoomLevel < 16) {
isReady = false;
setReady(false);
return;
}
@ -108,8 +108,7 @@ public class ExtrusionRenderLayer extends RenderLayer {
if (mTileSet.cnt == 0) {
mTileLayer.releaseTiles(mTileSet);
isReady = false;
setReady(false);
return;
}
@ -155,14 +154,15 @@ public class ExtrusionRenderLayer extends RenderLayer {
}
mTileCnt = activeTiles;
isReady = activeTiles > 0;
if (!isReady)
if (activeTiles > 0)
setReady(true);
else
mTileLayer.releaseTiles(mTileSet);
}
@Override
public void compile() {
protected void compile() {
}
@ -178,7 +178,7 @@ public class ExtrusionRenderLayer extends RenderLayer {
//private final float[] mVPMatrix = new float[16];
@Override
public void render(MapPosition pos, Matrices m) {
protected void render(MapPosition pos, Matrices m) {
// TODO one could render in one pass to texture and then draw the texture
// with alpha... might be faster and would allow postprocessing outlines.

@ -102,7 +102,7 @@ public class GridRenderLayer extends BasicRenderLayer {
}
@Override
public void update(MapPosition pos, boolean changed, Matrices m) {
protected void update(MapPosition pos, boolean changed, Matrices m) {
// scale coordinates relative to current 'zoom-level' to
// get the position as the nearest tile coordinate
@ -129,7 +129,6 @@ public class GridRenderLayer extends BasicRenderLayer {
mLineLayer.clear();
mLineLayer.addLine(mLines);
// tell GLRender to compile new layer data.
this.newData = true;
compile();
}
}

@ -660,7 +660,7 @@ public class TextRenderLayer extends BasicRenderLayer {
mMapPosition = mTmpPos;
mTmpPos = tmp;
this.newData = true;
compile();
}
// if (!mHolding)

@ -107,18 +107,18 @@ public class AtlasRenderLayer extends BasicRenderLayer {
tl.prepare();
TextItem.pool.releaseAll(tl.labels);
this.newData = true;
}
boolean initial = true;
@Override
public void update(MapPosition pos, boolean changed, Matrices m) {
protected void update(MapPosition pos, boolean changed, Matrices m) {
if (initial) {
mMapPosition.copy(pos);
this.initial = false;
initial = false;
compile();
}
}
}

@ -40,16 +40,14 @@ public class SymbolRenderLayer extends BasicRenderLayer {
}
l.addSymbol(it);
// compile layer on next frame
newData = true;
}
@Override
public void update(MapPosition position, boolean changed, Matrices matrices) {
protected void update(MapPosition position, boolean changed, Matrices matrices) {
if (initialize){
initialize = false;
mMapPosition.copy(position);
compile();
}
}
}

@ -115,7 +115,7 @@ public class TestRenderLayer extends BasicRenderLayer {
}
@Override
public synchronized void update(MapPosition curPos, boolean positionChanged,
protected synchronized void update(MapPosition curPos, boolean positionChanged,
Matrices matrices) {
// keep position constant (or update layer relative to new position)
//mMapPosition.copy(curPos);
@ -129,7 +129,7 @@ public class TestRenderLayer extends BasicRenderLayer {
// pass layers to be uploaded and drawn to GL Thread
// afterwards never modify 'layers' outside of this function!
newData = true;
compile();
}
}