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

Commit

Permalink
add workaround for adreno driver issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hjanetzek committed May 7, 2014
1 parent 62255e7 commit bdc63d8
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 16 deletions.
6 changes: 6 additions & 0 deletions vtm/src/org/oscim/backend/GLAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class GLAdapter {

public static boolean NON_PREMUL_CANVAS;

/**
* Set false as workaround for adreno driver issue:
* https://github.com/opensciencemap/vtm/issues/52
*/
public static boolean VBO_TEXTURE_LAYERS = false;

public static GL20 get() {
if (g == null)
throw new IllegalStateException();
Expand Down
3 changes: 3 additions & 0 deletions vtm/src/org/oscim/layers/marker/MarkerRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Comparator;

import org.oscim.backend.GLAdapter;
import org.oscim.core.MercatorProjection;
import org.oscim.core.Point;
import org.oscim.core.Tile;
Expand Down Expand Up @@ -61,6 +62,8 @@ public String toString() {
}

public MarkerRenderer(MarkerLayer<MarkerItem> markerLayer, MarkerSymbol defaultSymbol) {
layers.useVBO = GLAdapter.VBO_TEXTURE_LAYERS;

mSymbolLayer = new SymbolLayer();
mMarkerLayer = markerLayer;
mDefaultMarker = defaultSymbol;
Expand Down
11 changes: 9 additions & 2 deletions vtm/src/org/oscim/layers/tile/vector/labeling/TextRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
// 5 QuadTree might be handy
//

import org.oscim.backend.GL20;
import org.oscim.backend.GLAdapter;
import org.oscim.layers.tile.vector.labeling.LabelLayer.Worker;
import org.oscim.renderer.ElementRenderer;
import org.oscim.renderer.GLState;
Expand All @@ -47,6 +49,8 @@ class TextRenderer extends ElementRenderer {

public TextRenderer(Worker worker) {
mWorker = worker;

layers.useVBO = GLAdapter.VBO_TEXTURE_LAYERS;
}

long lastDraw = 0;
Expand Down Expand Up @@ -77,14 +81,17 @@ public synchronized void render(GLViewport v) {
GLState.test(false, false);
//Debug.draw(pos, layers);

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

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

setMatrix(v, false);

for (RenderElement l = layers.getTextureLayers(); l != null;)
l = TextureLayer.Renderer.draw(l, v, scale);
l = TextureLayer.Renderer.draw(layers, l, v, scale);
}

}
25 changes: 20 additions & 5 deletions vtm/src/org/oscim/renderer/ElementRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import static org.oscim.renderer.elements.RenderElement.SYMBOL;
import static org.oscim.renderer.elements.RenderElement.TEXLINE;

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

import org.oscim.backend.GL20;
Expand Down Expand Up @@ -80,7 +82,11 @@ public ElementRenderer() {
protected synchronized void render(GLViewport v) {
MapPosition layerPos = mMapPosition;

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

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

Expand Down Expand Up @@ -121,7 +127,7 @@ protected synchronized void render(GLViewport v) {
continue;
}
if (l.type == SYMBOL) {
l = TextureLayer.Renderer.draw(l, v, div);
l = TextureLayer.Renderer.draw(layers, l, v, div);
continue;
}
log.debug("invalid layer {}", l.type);
Expand All @@ -144,7 +150,7 @@ protected synchronized void compile() {
return;
}

if (layers.vbo == null)
if (layers.useVBO && layers.vbo == null)
layers.vbo = BufferObject.get(GL20.GL_ARRAY_BUFFER, newSize);

if (uploadLayers(layers, newSize, true))
Expand All @@ -157,7 +163,15 @@ public static boolean uploadLayers(ElementLayers layers, int newSize,
if (addFill)
newSize += 8;

ShortBuffer sbuf = MapRenderer.getShortBuffer(newSize);
ShortBuffer sbuf;
if (layers.useVBO) {
sbuf = MapRenderer.getShortBuffer(newSize);
} else {
layers.vertexArrayBuffer = ByteBuffer
.allocateDirect(newSize * 2)
.order(ByteOrder.nativeOrder());
sbuf = layers.vertexArrayBuffer.asShortBuffer();
}

if (addFill)
sbuf.put(fillCoords, 0, 8);
Expand All @@ -172,8 +186,9 @@ public static boolean uploadLayers(ElementLayers layers, int newSize,
+ " buffer fill: " + sbuf.remaining());
return false;
}
if (layers.useVBO)
layers.vbo.loadBufferData(sbuf.flip(), newSize * 2);

layers.vbo.loadBufferData(sbuf.flip(), newSize * 2);
return true;
}

Expand Down
7 changes: 7 additions & 0 deletions vtm/src/org/oscim/renderer/elements/ElementLayers.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.oscim.renderer.elements.RenderElement.POLYGON;
import static org.oscim.renderer.elements.RenderElement.TEXLINE;

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

import org.oscim.backend.GL20;
Expand Down Expand Up @@ -72,6 +73,10 @@ public class ElementLayers extends TileData {
* ...
*/
public BufferObject vbo;
public boolean useVBO = true;

/* holds vertex data for rendering when not using VBO */
public ByteBuffer vertexArrayBuffer;

/**
* To not need to switch VertexAttribPointer positions all the time:
Expand Down Expand Up @@ -379,6 +384,8 @@ public void clear() {

if (vbo != null)
vbo = BufferObject.release(vbo);

vertexArrayBuffer = null;
}

@Override
Expand Down
32 changes: 23 additions & 9 deletions vtm/src/org/oscim/renderer/elements/TextureLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,15 @@ static void init() {
pool.init(0);
}

public static RenderElement draw(RenderElement l, GLViewport v, float scale) {
shader.useProgram();
public static RenderElement draw(ElementLayers layers, RenderElement l,
GLViewport v, float scale) {

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

TextureLayer tl = (TextureLayer) l;
shader.useProgram();

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

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

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

GL.glVertexAttribPointer(shader.aTexCoord, 2,
GL20.GL_SHORT,
false, 12, off + 8);
} else {
layers.vertexArrayBuffer.position(off);
GL.glVertexAttribPointer(shader.aPos, 4,
GL20.GL_SHORT, false, 12,
layers.vertexArrayBuffer);
layers.vertexArrayBuffer.position(off + 8);
GL.glVertexAttribPointer(shader.aTexCoord,
2, GL20.GL_SHORT, false, 12,
layers.vertexArrayBuffer);
}
int numVertices = t.vertices - i;
if (numVertices > maxVertices)
numVertices = maxVertices;

GL.glDrawElements(GL20.GL_TRIANGLES, numVertices,
GL20.GL_UNSIGNED_SHORT, 0);

}
}

Expand Down

0 comments on commit bdc63d8

Please sign in to comment.