refactor: RenderElement:
- remove curItem - rename verticesCnt -> numVertices - add getter/setters
This commit is contained in:
parent
eff5935068
commit
0f02215e63
@ -48,7 +48,7 @@ public class BitmapLayer extends TextureLayer {
|
||||
mVertices = new short[24];
|
||||
|
||||
// used for size calculation of Layers buffer.
|
||||
verticesCnt = 4;
|
||||
numVertices = 4;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +106,7 @@ public class BitmapLayer extends TextureLayer {
|
||||
buf[pos++] = texMax;
|
||||
buf[pos++] = texMax;
|
||||
|
||||
this.offset = sbuf.position() * 2; // bytes
|
||||
setOffset(sbuf.position() * 2);
|
||||
sbuf.put(buf);
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ public class BitmapLayer extends TextureLayer {
|
||||
// draw up to maxVertices in each iteration
|
||||
for (int i = 0; i < t.vertices; i += maxVertices) {
|
||||
// to.offset * (24(shorts) * 2(short-bytes) / 6(indices) == 8)
|
||||
int off = (t.offset + i) * 8 + tl.offset;
|
||||
int off = (t.offset + i) * 8 + tl.getOffset();
|
||||
|
||||
GL.glVertexAttribPointer(hTextureVertex, 4,
|
||||
GL20.GL_SHORT, false, 12, off);
|
||||
|
||||
@ -208,10 +208,10 @@ public class ElementLayers {
|
||||
int size = 0;
|
||||
|
||||
for (RenderElement l = baseLayers; l != null; l = l.next)
|
||||
size += l.verticesCnt * VERTEX_SHORT_CNT[l.type];
|
||||
size += l.numVertices * VERTEX_SHORT_CNT[l.type];
|
||||
|
||||
for (RenderElement l = textureLayers; l != null; l = l.next)
|
||||
size += l.verticesCnt * TEXTURE_VERTEX_SHORTS;
|
||||
size += l.numVertices * TEXTURE_VERTEX_SHORTS;
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -283,16 +283,14 @@ public class ElementLayers {
|
||||
if (last == null)
|
||||
continue;
|
||||
|
||||
l.offset = pos;
|
||||
|
||||
pos += l.verticesCnt;
|
||||
l.setOffset(pos);
|
||||
pos += l.numVertices;
|
||||
|
||||
last.next = items;
|
||||
items = l.vertexItems;
|
||||
last = null;
|
||||
|
||||
l.vertexItems = null;
|
||||
l.curItem = null;
|
||||
}
|
||||
items = VertexItem.pool.releaseAll(items);
|
||||
|
||||
@ -301,7 +299,7 @@ public class ElementLayers {
|
||||
|
||||
static void addPoolItems(RenderElement l, ShortBuffer sbuf) {
|
||||
// offset of layer data in vbo
|
||||
l.offset = sbuf.position() * SHORT_BYTES;
|
||||
l.setOffset(sbuf.position() * SHORT_BYTES);
|
||||
|
||||
for (VertexItem it = l.vertexItems; it != null; it = it.next) {
|
||||
if (it.next == null)
|
||||
@ -318,11 +316,9 @@ public class ElementLayers {
|
||||
|
||||
// clear line and polygon layers directly
|
||||
for (RenderElement l = baseLayers; l != null; l = l.next) {
|
||||
if (l.vertexItems != null) {
|
||||
if (l.vertexItems != null)
|
||||
l.vertexItems = VertexItem.pool.releaseAll(l.vertexItems);
|
||||
l.curItem = null;
|
||||
}
|
||||
l.verticesCnt = 0;
|
||||
l.numVertices = 0;
|
||||
}
|
||||
|
||||
for (RenderElement l = textureLayers; l != null; l = l.next)
|
||||
|
||||
@ -30,6 +30,7 @@ import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.renderer.MapRenderer.Matrices;
|
||||
import org.oscim.theme.styles.Line;
|
||||
import org.oscim.utils.FastMath;
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -95,12 +96,10 @@ public final class LineLayer extends RenderElement {
|
||||
else if (line.cap == Cap.SQUARE)
|
||||
squared = true;
|
||||
|
||||
if (vertexItems == null) {
|
||||
if (vertexItems == null)
|
||||
vertexItems = VertexItem.pool.get();
|
||||
curItem = vertexItems;
|
||||
}
|
||||
|
||||
VertexItem si = curItem;
|
||||
VertexItem si = Inlist.last(vertexItems);
|
||||
short v[] = si.vertices;
|
||||
int opos = si.used;
|
||||
|
||||
@ -155,7 +154,7 @@ public final class LineLayer extends RenderElement {
|
||||
// + 2 for drawing triangle-strip
|
||||
// + 4 for round caps
|
||||
// + 2 for closing polygons
|
||||
verticesCnt += length + (rounded ? 6 : 2) + (closed ? 2 : 0);
|
||||
numVertices += length + (rounded ? 6 : 2) + (closed ? 2 : 0);
|
||||
|
||||
int ipos = pos;
|
||||
|
||||
@ -276,7 +275,7 @@ public final class LineLayer extends RenderElement {
|
||||
}
|
||||
|
||||
if (rounded)
|
||||
verticesCnt -= 2;
|
||||
numVertices -= 2;
|
||||
|
||||
// add first vertex twice
|
||||
ddx = (int) ((ux - tx) * DIR_SCALE);
|
||||
@ -507,7 +506,7 @@ public final class LineLayer extends RenderElement {
|
||||
}
|
||||
|
||||
if (rounded)
|
||||
verticesCnt -= 2;
|
||||
numVertices -= 2;
|
||||
|
||||
ddx = (int) ((ux - vx) * DIR_SCALE);
|
||||
ddy = (int) ((uy - vy) * DIR_SCALE);
|
||||
@ -549,16 +548,13 @@ public final class LineLayer extends RenderElement {
|
||||
}
|
||||
|
||||
si.used = opos;
|
||||
curItem = si;
|
||||
//curItem = si;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if (vertexItems != null) {
|
||||
vertexItems = VertexItem.pool.releaseAll(vertexItems);
|
||||
curItem = null;
|
||||
}
|
||||
verticesCnt = 0;
|
||||
vertexItems = VertexItem.pool.releaseAll(vertexItems);
|
||||
numVertices = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -634,7 +630,8 @@ public final class LineLayer extends RenderElement {
|
||||
|
||||
mTexID = GLUtils.loadTexture(pixel, 128, 128, GL20.GL_ALPHA,
|
||||
GL20.GL_NEAREST, GL20.GL_NEAREST,
|
||||
GL20.GL_MIRRORED_REPEAT, GL20.GL_MIRRORED_REPEAT);
|
||||
GL20.GL_MIRRORED_REPEAT,
|
||||
GL20.GL_MIRRORED_REPEAT);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -714,7 +711,8 @@ public final class LineLayer extends RenderElement {
|
||||
// width stays the same.
|
||||
width = ll.width / (line.fixed ? scale : variableScale);
|
||||
|
||||
GL.glUniform1f(uLineWidth, (float) (width * COORD_SCALE_BY_DIR_SCALE));
|
||||
GL.glUniform1f(uLineWidth,
|
||||
(float) (width * COORD_SCALE_BY_DIR_SCALE));
|
||||
|
||||
// Line-edge fade
|
||||
if (line.blur > 0) {
|
||||
@ -741,7 +739,8 @@ public final class LineLayer extends RenderElement {
|
||||
GL.glUniform1f(uLineMode, capMode);
|
||||
}
|
||||
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, l.offset, l.verticesCnt);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP,
|
||||
l.getOffset(), l.numVertices);
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -754,7 +753,8 @@ public final class LineLayer extends RenderElement {
|
||||
else
|
||||
width = ll.width / scale + o.width / variableScale;
|
||||
|
||||
GL.glUniform1f(uLineWidth, (float) (width * COORD_SCALE_BY_DIR_SCALE));
|
||||
GL.glUniform1f(uLineWidth,
|
||||
(float) (width * COORD_SCALE_BY_DIR_SCALE));
|
||||
|
||||
// Line-edge fade
|
||||
if (line.blur > 0) {
|
||||
@ -775,7 +775,8 @@ public final class LineLayer extends RenderElement {
|
||||
GL.glUniform1f(uLineMode, capMode);
|
||||
}
|
||||
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, o.offset, o.verticesCnt);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP,
|
||||
o.getOffset(), o.numVertices);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -28,6 +28,7 @@ import org.oscim.renderer.GLUtils;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.renderer.MapRenderer.Matrices;
|
||||
import org.oscim.theme.styles.Line;
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -108,22 +109,24 @@ public final class LineTexLayer extends RenderElement {
|
||||
|
||||
public void addLine(float[] points, short[] index) {
|
||||
|
||||
if (vertexItems == null) {
|
||||
vertexItems = VertexItem.pool.get();
|
||||
curItem = vertexItems;
|
||||
VertexItem si = Inlist.last(vertexItems);
|
||||
|
||||
if (si == null) {
|
||||
si = VertexItem.pool.get();
|
||||
vertexItems = si;
|
||||
|
||||
//curItem = vertexItems;
|
||||
// HACK add one vertex offset when compiling
|
||||
// buffer otherwise one cant use the full
|
||||
// VertexItem (see Layers.compile)
|
||||
// add the two 'x' at front and end
|
||||
//verticesCnt = 2;
|
||||
//numVertices = 2;
|
||||
|
||||
// the additional end vertex to make sure
|
||||
// not to read outside allocated memory
|
||||
verticesCnt = 1;
|
||||
numVertices = 1;
|
||||
}
|
||||
|
||||
VertexItem si = curItem;
|
||||
|
||||
short v[] = si.vertices;
|
||||
int opos = si.used;
|
||||
|
||||
@ -218,7 +221,7 @@ public final class LineTexLayer extends RenderElement {
|
||||
even = false;
|
||||
|
||||
// vertex 0 and 2 were added
|
||||
verticesCnt += 3;
|
||||
numVertices += 3;
|
||||
evenQuads++;
|
||||
} else {
|
||||
// go to next block
|
||||
@ -226,7 +229,7 @@ public final class LineTexLayer extends RenderElement {
|
||||
opos += 18;
|
||||
|
||||
// vertex 1 and 3 were added
|
||||
verticesCnt += 1;
|
||||
numVertices += 1;
|
||||
oddQuads++;
|
||||
}
|
||||
}
|
||||
@ -241,7 +244,6 @@ public final class LineTexLayer extends RenderElement {
|
||||
opos += 12;
|
||||
|
||||
si.used = opos;
|
||||
curItem = si;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -367,6 +369,7 @@ public final class LineTexLayer extends RenderElement {
|
||||
for (; l != null && l.type == RenderElement.TEXLINE; l = l.next) {
|
||||
LineTexLayer ll = (LineTexLayer) l;
|
||||
Line line = ll.line;
|
||||
int lOffset = l.getOffset();
|
||||
|
||||
GLUtils.setColor(hTexColor, line.stippleColor, 1);
|
||||
GLUtils.setColor(hBgColor, line.color, 1);
|
||||
@ -393,7 +396,7 @@ public final class LineTexLayer extends RenderElement {
|
||||
numIndices = maxIndices;
|
||||
|
||||
// i / 6 * (24 shorts per block * 2 short bytes)
|
||||
int add = (l.offset + i * 8) + vOffset;
|
||||
int add = (lOffset + i * 8) + vOffset;
|
||||
|
||||
GL.glVertexAttribPointer(hVertexPosition0,
|
||||
4, GL20.GL_SHORT, false, STRIDE,
|
||||
@ -422,7 +425,7 @@ public final class LineTexLayer extends RenderElement {
|
||||
if (numIndices > maxIndices)
|
||||
numIndices = maxIndices;
|
||||
// i / 6 * (24 shorts per block * 2 short bytes)
|
||||
int add = (l.offset + i * 8) + vOffset;
|
||||
int add = (lOffset + i * 8) + vOffset;
|
||||
|
||||
GL.glVertexAttribPointer(hVertexPosition0,
|
||||
4, GL20.GL_SHORT, false, STRIDE,
|
||||
|
||||
@ -60,9 +60,9 @@ public class MeshLayer extends RenderElement {
|
||||
numIndices += Tessellator.tessellate(geom, MapRenderer.COORD_SCALE,
|
||||
Inlist.last(vertexItems),
|
||||
Inlist.last(indiceItems),
|
||||
verticesCnt);
|
||||
numVertices);
|
||||
|
||||
verticesCnt = vertexItems.getSize() / 2;
|
||||
numVertices = vertexItems.getSize() / 2;
|
||||
|
||||
if (numIndices <= 0) {
|
||||
log.debug("empty " + geom.index);
|
||||
@ -144,7 +144,7 @@ public class MeshLayer extends RenderElement {
|
||||
GLUtils.setColor(hColor, ml.area.color, 1);
|
||||
|
||||
GL.glVertexAttribPointer(hVertexPosition, 2, GL20.GL_SHORT,
|
||||
false, 0, ml.offset);
|
||||
false, 0, ml.getOffset());
|
||||
|
||||
GL.glDrawElements(GL20.GL_TRIANGLES, ml.numIndices,
|
||||
GL20.GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
@ -34,6 +34,7 @@ import org.oscim.renderer.MapRenderer.Matrices;
|
||||
import org.oscim.theme.styles.Area;
|
||||
import org.oscim.utils.FastMath;
|
||||
import org.oscim.utils.Interpolation;
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -53,8 +54,7 @@ public final class PolygonLayer extends RenderElement {
|
||||
super(RenderElement.POLYGON);
|
||||
|
||||
level = layer;
|
||||
curItem = VertexItem.pool.get();
|
||||
vertexItems = curItem;
|
||||
vertexItems = VertexItem.pool.get();
|
||||
}
|
||||
|
||||
public void addPolygon(GeometryBuffer geom) {
|
||||
@ -64,7 +64,7 @@ public final class PolygonLayer extends RenderElement {
|
||||
public void addPolygon(float[] points, short[] index) {
|
||||
short center = (short) ((Tile.SIZE >> 1) * S);
|
||||
|
||||
VertexItem si = curItem;
|
||||
VertexItem si = Inlist.last(vertexItems);
|
||||
short[] v = si.vertices;
|
||||
int outPos = si.used;
|
||||
|
||||
@ -79,7 +79,7 @@ public final class PolygonLayer extends RenderElement {
|
||||
continue;
|
||||
}
|
||||
|
||||
verticesCnt += length / 2 + 2;
|
||||
numVertices += length / 2 + 2;
|
||||
|
||||
int inPos = pos;
|
||||
|
||||
@ -115,7 +115,6 @@ public final class PolygonLayer extends RenderElement {
|
||||
}
|
||||
|
||||
si.used = outPos;
|
||||
curItem = si;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -326,7 +325,7 @@ public final class PolygonLayer extends RenderElement {
|
||||
// set stencil mask to draw to
|
||||
GL.glStencilMask(1 << cur++);
|
||||
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_FAN, l.offset, l.verticesCnt);
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_FAN, l.getOffset(), l.numVertices);
|
||||
|
||||
// draw up to 7 layers into stencil buffer
|
||||
if (cur == STENCIL_BITS - 1) {
|
||||
|
||||
@ -26,7 +26,7 @@ public abstract class RenderElement extends Inlist<RenderElement> {
|
||||
|
||||
public final static byte LINE = 0;
|
||||
public final static byte POLYGON = 1;
|
||||
public static final byte MESH = 2;
|
||||
public final static byte MESH = 2;
|
||||
public final static byte TEXLINE = 3;
|
||||
public final static byte SYMBOL = 4;
|
||||
public final static byte BITMAP = 5;
|
||||
@ -38,22 +38,31 @@ public abstract class RenderElement extends Inlist<RenderElement> {
|
||||
|
||||
public final byte type;
|
||||
|
||||
// drawing order from bottom to top
|
||||
/** drawing order from bottom to top */
|
||||
int level;
|
||||
|
||||
// number of vertices for this layer
|
||||
public int verticesCnt;
|
||||
/** number of vertices for this layer */
|
||||
protected int numVertices;
|
||||
|
||||
// in case of line and polygon layer:
|
||||
// - number of VERTICES offset for this layertype in VBO
|
||||
// otherwise:
|
||||
// - offset in byte in VBO
|
||||
public int offset;
|
||||
|
||||
VertexItem vertexItems;
|
||||
protected VertexItem curItem;
|
||||
protected VertexItem vertexItems;
|
||||
|
||||
abstract protected void compile(ShortBuffer sbuf);
|
||||
|
||||
abstract protected void clear();
|
||||
|
||||
/**
|
||||
* for line and polygon layers:
|
||||
* - number of VERTICES mOffset for this layertype in VBO
|
||||
* otherwise:
|
||||
* - offset in byte in VBO
|
||||
*/
|
||||
private int mOffset;
|
||||
|
||||
public int getOffset() {
|
||||
return mOffset;
|
||||
}
|
||||
|
||||
public void setOffset(int offset) {
|
||||
mOffset = offset;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public final class SymbolLayer extends TextureLayer {
|
||||
public void addSymbol(SymbolItem item) {
|
||||
|
||||
// needed to calculate 'sbuf' size for compile
|
||||
verticesCnt += VERTICES_PER_SPRITE;
|
||||
numVertices += VERTICES_PER_SPRITE;
|
||||
|
||||
for (SymbolItem it = symbols; it != null; it = it.next) {
|
||||
if (it.bitmap == item.bitmap) {
|
||||
@ -62,7 +62,7 @@ public final class SymbolLayer extends TextureLayer {
|
||||
@Override
|
||||
protected void compile(ShortBuffer sbuf) {
|
||||
// offset of layer data in vbo
|
||||
this.offset = sbuf.position() * 2; //SHORT_BYTES;
|
||||
setOffset(sbuf.position() * 2); //SHORT_BYTES;
|
||||
|
||||
short numIndices = 0;
|
||||
|
||||
@ -202,7 +202,7 @@ public final class SymbolLayer extends TextureLayer {
|
||||
|
||||
public void clearItems() {
|
||||
symbols = SymbolItem.pool.releaseAll(symbols);
|
||||
//verticesCnt = 0;
|
||||
//numVertices = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -213,7 +213,7 @@ public final class SymbolLayer extends TextureLayer {
|
||||
|
||||
//symbols = SymbolItem.pool.releaseAll(symbols);
|
||||
//vertexItems = VertexItem.pool.releaseAll(vertexItems);
|
||||
//verticesCnt = 0;
|
||||
//numVertices = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -84,7 +84,7 @@ public final class TextLayer extends TextureLayer {
|
||||
int pos = vi.used; // 0
|
||||
short buf[] = vi.vertices;
|
||||
|
||||
verticesCnt = 0;
|
||||
numVertices = 0;
|
||||
|
||||
int advanceY = 0;
|
||||
float x = 0;
|
||||
@ -246,8 +246,8 @@ public final class TextLayer extends TextureLayer {
|
||||
buf[pos++] = v1;
|
||||
|
||||
// six indices to draw the four vertices
|
||||
verticesCnt += 4;
|
||||
numIndices += TextureLayer.INDICES_PER_SPRITE;
|
||||
numVertices += 4;
|
||||
|
||||
if (it.next == null || (it.next.text != it.text)
|
||||
|| (it.next.string != it.string)) {
|
||||
@ -276,7 +276,7 @@ public final class TextLayer extends TextureLayer {
|
||||
clearLabels();
|
||||
//labels = TextItem.pool.releaseAll(labels);
|
||||
//vertexItems = VertexItem.pool.releaseAll(vertexItems);
|
||||
//verticesCnt = 0;
|
||||
//numVertices = 0;
|
||||
}
|
||||
|
||||
public void clearLabels() {
|
||||
|
||||
@ -69,7 +69,7 @@ public abstract class TextureLayer extends RenderElement {
|
||||
textures = textures.dispose();
|
||||
|
||||
vertexItems = VertexItem.pool.releaseAll(vertexItems);
|
||||
verticesCnt = 0;
|
||||
numVertices = 0;
|
||||
}
|
||||
|
||||
static void putSprite(short buf[], int pos,
|
||||
@ -174,7 +174,7 @@ public abstract class TextureLayer extends RenderElement {
|
||||
// draw up to maxVertices in each iteration
|
||||
for (int i = 0; i < t.vertices; i += maxVertices) {
|
||||
// to.offset * (24(shorts) * 2(short-bytes) / 6(indices) == 8)
|
||||
int off = (t.offset + i) * 8 + tl.offset;
|
||||
int off = (t.offset + i) * 8 + tl.getOffset();
|
||||
|
||||
GL.glVertexAttribPointer(hTextureVertex, 4,
|
||||
GL20.GL_SHORT, false, 12, off);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user