refactor: move compileVertexItems() to RenderElement
- rename addPoolItems -> compileVertexItems
This commit is contained in:
parent
9f8a383ce6
commit
59dd9425c8
@ -267,10 +267,28 @@ public class ElementLayers extends TileData {
|
|||||||
|
|
||||||
public void compile(ShortBuffer sbuf, boolean addFill) {
|
public void compile(ShortBuffer sbuf, boolean addFill) {
|
||||||
|
|
||||||
addLayerItems(sbuf, baseLayers, POLYGON, addFill ? 4 : 0);
|
int pos = addFill ? 4 : 0;
|
||||||
|
|
||||||
|
for (RenderElement l = baseLayers; l != null; l = l.next) {
|
||||||
|
if (l.type == POLYGON) {
|
||||||
|
l.compile(sbuf);
|
||||||
|
|
||||||
|
//log.debug("offset {} {}", l.offset, pos);
|
||||||
|
l.offset = pos;
|
||||||
|
pos += l.numVertices;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
offset[LINE] = sbuf.position() * SHORT_BYTES;
|
offset[LINE] = sbuf.position() * SHORT_BYTES;
|
||||||
addLayerItems(sbuf, baseLayers, LINE, 0);
|
pos = 0;
|
||||||
|
for (RenderElement l = baseLayers; l != null; l = l.next) {
|
||||||
|
if (l.type == LINE) {
|
||||||
|
l.compile(sbuf);
|
||||||
|
|
||||||
|
l.offset = pos;
|
||||||
|
pos += l.numVertices;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//offset[TEXLINE] = size * SHORT_BYTES;
|
//offset[TEXLINE] = size * SHORT_BYTES;
|
||||||
|
|
||||||
@ -285,34 +303,6 @@ public class ElementLayers extends TileData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* optimization for Line- and PolygonLayer:
|
|
||||||
* collect all pool items and add back in one go.
|
|
||||||
*/
|
|
||||||
private static int addLayerItems(ShortBuffer sbuf, RenderElement l,
|
|
||||||
int type, int pos) {
|
|
||||||
|
|
||||||
int size = 0;
|
|
||||||
|
|
||||||
for (; l != null; l = l.next) {
|
|
||||||
if (l.type != type)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
size += l.vertexItems.compile(sbuf);
|
|
||||||
|
|
||||||
l.offset = pos;
|
|
||||||
pos += l.numVertices;
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void addPoolItems(RenderElement l, ShortBuffer sbuf) {
|
|
||||||
|
|
||||||
/* keep offset of layer data in vbo */
|
|
||||||
l.offset = sbuf.position() * SHORT_BYTES;
|
|
||||||
l.vertexItems.compile(sbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFrom(ElementLayers layers) {
|
public void setFrom(ElementLayers layers) {
|
||||||
setBaseLayers(layers.baseLayers);
|
setBaseLayers(layers.baseLayers);
|
||||||
setTextureLayers((TextureLayer) layers.textureLayers);
|
setTextureLayers((TextureLayer) layers.textureLayers);
|
||||||
|
@ -224,7 +224,7 @@ public final class LineTexLayer extends RenderElement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void compile(ShortBuffer sbuf) {
|
protected void compile(ShortBuffer sbuf) {
|
||||||
ElementLayers.addPoolItems(this, sbuf);
|
compileVertexItems(sbuf);
|
||||||
/* add additional vertex for interleaving, see TexLineLayer. */
|
/* add additional vertex for interleaving, see TexLineLayer. */
|
||||||
sbuf.position(sbuf.position() + 6);
|
sbuf.position(sbuf.position() + 6);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public class MeshLayer extends RenderElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add vertices to shared VBO */
|
/* add vertices to shared VBO */
|
||||||
ElementLayers.addPoolItems(this, sbuf);
|
ElementLayers.compileVertexItems(this, sbuf);
|
||||||
|
|
||||||
/* add indices to indicesVbo */
|
/* add indices to indicesVbo */
|
||||||
sbuf = MapRenderer.getShortBuffer(numIndices);
|
sbuf = MapRenderer.getShortBuffer(numIndices);
|
||||||
|
@ -55,7 +55,7 @@ public abstract class RenderElement extends Inlist<RenderElement> {
|
|||||||
|
|
||||||
/** compile vertex data to vbo. */
|
/** compile vertex data to vbo. */
|
||||||
protected void compile(ShortBuffer sbuf) {
|
protected void compile(ShortBuffer sbuf) {
|
||||||
|
compileVertexItems(sbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOffset() {
|
public int getOffset() {
|
||||||
@ -76,4 +76,11 @@ public abstract class RenderElement extends Inlist<RenderElement> {
|
|||||||
protected void compile(ShortBuffer vertexBuffer, ShortBuffer indexBuffer) {
|
protected void compile(ShortBuffer vertexBuffer, ShortBuffer indexBuffer) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void compileVertexItems(ShortBuffer sbuf) {
|
||||||
|
/* keep offset of layer data in vbo */
|
||||||
|
offset = sbuf.position() * 2;
|
||||||
|
vertexItems.compile(sbuf);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public abstract class TextureLayer extends RenderElement {
|
|||||||
t.upload();
|
t.upload();
|
||||||
|
|
||||||
/* add vertices to vbo */
|
/* add vertices to vbo */
|
||||||
ElementLayers.addPoolItems(this, sbuf);
|
compileVertexItems(sbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public boolean prepare();
|
abstract public boolean prepare();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user