Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Commit

Permalink
hack: no vbo for texture vertices
Browse files Browse the repository at this point in the history
  • Loading branch information
hjanetzek committed May 7, 2014
1 parent 62255e7 commit b729a52
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// 5 QuadTree might be handy
//

import org.oscim.backend.GL20;
import org.oscim.layers.tile.vector.labeling.LabelLayer.Worker;
import org.oscim.renderer.ElementRenderer;
import org.oscim.renderer.GLState;
Expand Down Expand Up @@ -77,7 +78,10 @@ public synchronized void render(GLViewport v) {
GLState.test(false, false);
//Debug.draw(pos, layers);

layers.vbo.bind();
if (TextureLayer.USE_VBO)
layers.vbo.bind();
else
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);

float scale = (float) (v.pos.scale / mMapPosition.scale);

Expand Down
6 changes: 6 additions & 0 deletions vtm/src/org/oscim/renderer/ElementRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ protected synchronized void render(GLViewport v) {
continue;
}
if (l.type == SYMBOL) {
if (!TextureLayer.USE_VBO)
layers.vbo.unbind();
l = TextureLayer.Renderer.draw(l, v, div);

if (!TextureLayer.USE_VBO)
layers.vbo.bind();

continue;
}
log.debug("invalid layer {}", l.type);
Expand Down
4 changes: 4 additions & 0 deletions vtm/src/org/oscim/renderer/elements/ElementLayers.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,12 @@ public int getSize() {
for (RenderElement l = baseLayers; l != null; l = l.next)
size += l.numVertices * VERTEX_SHORT_CNT[l.type];

/* Still need to get the size otherwise Layer will not be compiled, see
* ElementLayers */
//if (TextureLayer.USE_VBO) {
for (RenderElement l = textureLayers; l != null; l = l.next)
size += l.numVertices * TEXTURE_VERTEX_SHORTS;
//}

return size;
}
Expand Down
72 changes: 58 additions & 14 deletions vtm/src/org/oscim/renderer/elements/TextureLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static org.oscim.renderer.MapRenderer.COORD_SCALE;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;

import org.oscim.backend.GL20;
Expand All @@ -30,9 +32,12 @@
import org.slf4j.LoggerFactory;

public abstract class TextureLayer extends RenderElement {

static final Logger log = LoggerFactory.getLogger(TextureLayer.class);

/* disabling VBO might only work when ElementLayer only contains
* TextureLayers */
public static final boolean USE_VBO = false;

public final static int INDICES_PER_SPRITE = 6;
final static int VERTICES_PER_SPRITE = 4;
final static int SHORTS_PER_VERTICE = 6;
Expand All @@ -56,14 +61,32 @@ protected TextureLayer(int type) {
/** scale mode */
public boolean fixed;

private ByteBuffer mVertexBuffer;

@Override
protected void compile(ShortBuffer sbuf) {

for (TextureItem t = textures; t != null; t = t.next)
t.upload();

/* add vertices to vbo */
ElementLayers.addPoolItems(this, sbuf);
if (USE_VBO) {
/* add vertices to vbo */
ElementLayers.addPoolItems(this, sbuf);
} else if (vertexItems != null) {
/* create vertex buffer */
int s = vertexItems.getSize();
log.debug("load vertex data {}", s);
if (s > 0) {
mVertexBuffer = ByteBuffer
.allocateDirect(s * 2)
.order(ByteOrder.nativeOrder());

ElementLayers.addPoolItems(this, mVertexBuffer.asShortBuffer());

/* advance position in VBO... */
sbuf.position(sbuf.position() + s);
}
}
}

abstract public boolean prepare();
Expand Down Expand Up @@ -151,13 +174,17 @@ static void init() {
}

public static RenderElement draw(RenderElement l, GLViewport v, float scale) {
shader.useProgram();
TextureLayer tl = (TextureLayer) l;

if (!USE_VBO) {
if (tl.mVertexBuffer == null)
return l.next;
}

shader.useProgram();
GLState.test(false, false);
GLState.blend(true);

TextureLayer tl = (TextureLayer) l;

GL.glUniform1f(shader.uScale, tl.fixed ? 1 / scale : 1);

v.proj.setAsUniform(shader.uProj);
Expand All @@ -177,14 +204,31 @@ public static RenderElement draw(RenderElement l, GLViewport v, float scale) {
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;

GL.glVertexAttribPointer(shader.aPos, 4,
GL20.GL_SHORT, false, 12, off);

GL.glVertexAttribPointer(shader.aTexCoord, 2,
GL20.GL_SHORT, false, 12, off + 8);

int off = (t.offset + i) * 8 + (USE_VBO ? tl.offset : 0);

if (USE_VBO) {
GL.glVertexAttribPointer(shader.aPos, 4,
GL20.GL_SHORT, false, 12, off);

GL.glVertexAttribPointer(shader.aTexCoord, 2,
GL20.GL_SHORT, false, 12, off + 8);
} else {

tl.mVertexBuffer.position(off);
GL.glVertexAttribPointer(shader.aPos,
4,
GL20.GL_SHORT,
false,
12,
tl.mVertexBuffer);
tl.mVertexBuffer.position(off + 8);
GL.glVertexAttribPointer(shader.aTexCoord,
2,
GL20.GL_SHORT,
false,
12,
tl.mVertexBuffer);
}
int numVertices = t.vertices - i;
if (numVertices > maxVertices)
numVertices = maxVertices;
Expand Down

0 comments on commit b729a52

Please sign in to comment.