need to split pool for ELEMENT_ARRAY and ARRAY_BUFFER
- due to webkit's funky gl implementation one cannot reuse a buffer for another type once its target was set.. ... anyway api is nicer now :)
This commit is contained in:
parent
8845a053fb
commit
50cb603bbf
@ -698,7 +698,7 @@ class TextRenderLayer extends BasicRenderLayer {
|
|||||||
@Override
|
@Override
|
||||||
public synchronized void render(MapPosition pos, Matrices m) {
|
public synchronized void render(MapPosition pos, Matrices m) {
|
||||||
|
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, layers.vbo.id);
|
layers.vbo.bind();
|
||||||
GLState.test(false, false);
|
GLState.test(false, false);
|
||||||
|
|
||||||
float scale = (float) (mMapPosition.scale / pos.scale);
|
float scale = (float) (mMapPosition.scale / pos.scale);
|
||||||
|
|||||||
@ -17,8 +17,7 @@ package org.oscim.layers.tile;
|
|||||||
import static org.oscim.layers.tile.MapTile.STATE_NEW_DATA;
|
import static org.oscim.layers.tile.MapTile.STATE_NEW_DATA;
|
||||||
import static org.oscim.layers.tile.MapTile.STATE_READY;
|
import static org.oscim.layers.tile.MapTile.STATE_READY;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import org.oscim.backend.GL20;
|
||||||
|
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.renderer.BufferObject;
|
import org.oscim.renderer.BufferObject;
|
||||||
@ -65,8 +64,6 @@ public class TileRenderLayer extends RenderLayer {
|
|||||||
|
|
||||||
if (tilesChanged || positionChanged){
|
if (tilesChanged || positionChanged){
|
||||||
updateTileVisibility(m.mapPlane);
|
updateTileVisibility(m.mapPlane);
|
||||||
Log.d(TAG, tileCnt + " >> " + Arrays.deepToString(tiles));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
tileCnt += mNumTileHolder;
|
tileCnt += mNumTileHolder;
|
||||||
|
|
||||||
@ -156,7 +153,7 @@ public class TileRenderLayer extends RenderLayer {
|
|||||||
if (newSize > 0) {
|
if (newSize > 0) {
|
||||||
|
|
||||||
if (tile.layers.vbo == null)
|
if (tile.layers.vbo == null)
|
||||||
tile.layers.vbo = BufferObject.get(newSize);
|
tile.layers.vbo = BufferObject.get(GL20.GL_ARRAY_BUFFER, newSize);
|
||||||
|
|
||||||
if (!GLRenderer.uploadLayers(tile.layers, newSize, true)) {
|
if (!GLRenderer.uploadLayers(tile.layers, newSize, true)) {
|
||||||
Log.d(TAG, "BUG uploadTileData " + tile + " failed!");
|
Log.d(TAG, "BUG uploadTileData " + tile + " failed!");
|
||||||
|
|||||||
@ -130,7 +130,7 @@ public class TileRenderer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
t.layers.vbo.bindArrayBuffer();
|
t.layers.vbo.bind();
|
||||||
|
|
||||||
// place tile relative to map position
|
// place tile relative to map position
|
||||||
int z = tile.zoomLevel;
|
int z = tile.zoomLevel;
|
||||||
|
|||||||
@ -37,44 +37,35 @@ public final class BufferObject {
|
|||||||
|
|
||||||
BufferObject next;
|
BufferObject next;
|
||||||
|
|
||||||
BufferObject(int id) {
|
int target;
|
||||||
|
|
||||||
|
BufferObject(int target, int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bufferType;
|
public void loadBufferData(Buffer buf, int newSize) {
|
||||||
|
|
||||||
public void loadBufferData(Buffer buf, int newSize, int type) {
|
|
||||||
boolean clear = false;
|
boolean clear = false;
|
||||||
|
|
||||||
if (type != bufferType) {
|
|
||||||
if (bufferType != 0)
|
|
||||||
clear = true;
|
|
||||||
bufferType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buf.position() != 0) {
|
if (buf.position() != 0) {
|
||||||
Log.d(TAG, "rewind your buffer: " + buf.position());
|
Log.d(TAG, "rewind your buffer: " + buf.position());
|
||||||
}
|
}
|
||||||
|
|
||||||
GL.glBindBuffer(type, id);
|
GL.glBindBuffer(target, id);
|
||||||
|
|
||||||
// reuse memory allocated for vbo when possible and allocated
|
// reuse memory allocated for vbo when possible and allocated
|
||||||
// memory is less then four times the new data
|
// memory is less then four times the new data
|
||||||
if (!clear && (size > newSize) && (size < newSize * 4)) {
|
if (!clear && (size > newSize) && (size < newSize * 4)) {
|
||||||
GL.glBufferSubData(type, 0, newSize, buf);
|
GL.glBufferSubData(target, 0, newSize, buf);
|
||||||
} else {
|
} else {
|
||||||
mBufferMemoryUsage += newSize - size;
|
mBufferMemoryUsage += newSize - size;
|
||||||
size = newSize;
|
size = newSize;
|
||||||
GL.glBufferData(type, size, buf, GL20.GL_DYNAMIC_DRAW);
|
GL.glBufferData(target, size, buf, GL20.GL_DYNAMIC_DRAW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindArrayBuffer() {
|
public void bind() {
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, id);
|
GL.glBindBuffer(target, id);
|
||||||
}
|
|
||||||
|
|
||||||
public void bindIndexBuffer() {
|
|
||||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------- pool ----------------------------
|
// ---------------------------- pool ----------------------------
|
||||||
@ -95,29 +86,31 @@ public final class BufferObject {
|
|||||||
Log.d(TAG, "now: " + mBufferMemoryUsage / MB + "MB");
|
Log.d(TAG, "now: " + mBufferMemoryUsage / MB + "MB");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BufferObject pool;
|
private static BufferObject pool[] = new BufferObject[2];
|
||||||
static int counter = 0;
|
static int counter[] = new int[2];
|
||||||
|
|
||||||
public static synchronized BufferObject get(int size) {
|
public static synchronized BufferObject get(int target, int size) {
|
||||||
|
|
||||||
if (pool == null) {
|
int t = (target == GL20.GL_ARRAY_BUFFER) ? 0 : 1;
|
||||||
if (counter != 0)
|
|
||||||
|
if (pool[t] == null) {
|
||||||
|
if (counter[t] != 0)
|
||||||
Log.d(TAG, "BUG: missing BufferObjects: " + counter);
|
Log.d(TAG, "BUG: missing BufferObjects: " + counter);
|
||||||
|
|
||||||
createBuffers(10);
|
createBuffers(target, 10);
|
||||||
counter += 10;
|
counter[t] += 10;
|
||||||
}
|
}
|
||||||
counter--;
|
counter[t]--;
|
||||||
|
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
// find an item that has bound more than 'size' bytes.
|
// find an item that has bound more than 'size' bytes.
|
||||||
// this has the advantage that either memory can be reused or
|
// this has the advantage that either memory can be reused or
|
||||||
// a large unused block will be replaced by a smaller one.
|
// a large unused block will be replaced by a smaller one.
|
||||||
BufferObject prev = null;
|
BufferObject prev = null;
|
||||||
for (BufferObject bo = pool; bo != null; bo = bo.next) {
|
for (BufferObject bo = pool[t]; bo != null; bo = bo.next) {
|
||||||
if (bo.size > size) {
|
if (bo.size > size) {
|
||||||
if (prev == null)
|
if (prev == null)
|
||||||
pool = bo.next;
|
pool[t] = bo.next;
|
||||||
else
|
else
|
||||||
prev.next = bo.next;
|
prev.next = bo.next;
|
||||||
|
|
||||||
@ -127,8 +120,9 @@ public final class BufferObject {
|
|||||||
prev = bo;
|
prev = bo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BufferObject bo = pool;
|
|
||||||
pool = pool.next;
|
BufferObject bo = pool[t];
|
||||||
|
pool[t] = pool[t].next;
|
||||||
bo.next = null;
|
bo.next = null;
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
@ -140,30 +134,38 @@ public final class BufferObject {
|
|||||||
// if (counter > 200) {
|
// if (counter > 200) {
|
||||||
// Log.d(TAG, "should clear some buffers " + counter);
|
// Log.d(TAG, "should clear some buffers " + counter);
|
||||||
// }
|
// }
|
||||||
|
int t = (bo.target == GL20.GL_ARRAY_BUFFER) ? 0 : 1;
|
||||||
|
|
||||||
bo.next = pool;
|
bo.next = pool[t];
|
||||||
pool = bo;
|
pool[t] = bo;
|
||||||
counter++;
|
counter[t]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: only call from GL-Thread
|
// Note: only call from GL-Thread
|
||||||
static synchronized int limitUsage(int reduce) {
|
static synchronized int limitUsage(int reduce) {
|
||||||
if (pool == null) {
|
|
||||||
|
int vboIds[] = new int[10];
|
||||||
|
int freed = 0;
|
||||||
|
|
||||||
|
for (int t = 0; t < 2; t++) {
|
||||||
|
|
||||||
|
int removed = 0;
|
||||||
|
BufferObject prev = pool[t];
|
||||||
|
|
||||||
|
if (prev == null) {
|
||||||
Log.d(TAG, "nothing to free");
|
Log.d(TAG, "nothing to free");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int vboIds[] = new int[10];
|
|
||||||
int removed = 0;
|
|
||||||
int freed = 0;
|
|
||||||
BufferObject prev = pool;
|
|
||||||
|
|
||||||
for (BufferObject bo = pool.next; bo != null;) {
|
for (BufferObject bo = pool[t].next; bo != null;) {
|
||||||
if (bo.size > 0) {
|
if (bo.size > 0) {
|
||||||
freed += bo.size;
|
freed += bo.size;
|
||||||
bo.size = 0;
|
bo.size = 0;
|
||||||
|
|
||||||
vboIds[removed++] = bo.id;
|
vboIds[removed++] = bo.id;
|
||||||
prev.next = bo.next;
|
prev.next = bo.next;
|
||||||
bo = bo.next;
|
bo = bo.next;
|
||||||
|
|
||||||
if (removed == 10 || reduce < freed)
|
if (removed == 10 || reduce < freed)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -175,26 +177,32 @@ public final class BufferObject {
|
|||||||
|
|
||||||
if (removed > 0) {
|
if (removed > 0) {
|
||||||
GlUtils.glDeleteBuffers(removed, vboIds);
|
GlUtils.glDeleteBuffers(removed, vboIds);
|
||||||
counter -= removed;
|
counter[t] -= removed;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return freed;
|
return freed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void createBuffers(int num) {
|
static void createBuffers(int target, int num) {
|
||||||
int[] mVboIds = GlUtils.glGenBuffers(num);
|
int[] mVboIds = GlUtils.glGenBuffers(num);
|
||||||
|
|
||||||
|
int t = (target == GL20.GL_ARRAY_BUFFER) ? 0 : 1;
|
||||||
|
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
BufferObject bo = new BufferObject(mVboIds[i]);
|
BufferObject bo = new BufferObject(target, mVboIds[i]);
|
||||||
bo.next = pool;
|
bo.next = pool[t];
|
||||||
pool = bo;
|
pool[t] = bo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static synchronized void init(int num) {
|
static synchronized void init(int num) {
|
||||||
mBufferMemoryUsage = 0;
|
mBufferMemoryUsage = 0;
|
||||||
pool = null;
|
|
||||||
createBuffers(num);
|
// FIXME!!!!! pool = new BufferObject[2];
|
||||||
counter = num;
|
|
||||||
|
createBuffers(GL20.GL_ARRAY_BUFFER, num);
|
||||||
|
counter[0] = num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -137,7 +137,7 @@ public class GLRenderer {
|
|||||||
int tmpBufferSize;
|
int tmpBufferSize;
|
||||||
|
|
||||||
void growBuffer(int size) {
|
void growBuffer(int size) {
|
||||||
Log.d(TAG, "grow buffer " + size);
|
//Log.d(TAG, "grow buffer " + size);
|
||||||
// 32kb min size
|
// 32kb min size
|
||||||
if (size < (1 << 15))
|
if (size < (1 << 15))
|
||||||
size = (1 << 15);
|
size = (1 << 15);
|
||||||
@ -243,7 +243,7 @@ public class GLRenderer {
|
|||||||
}
|
}
|
||||||
newSize *= SHORT_BYTES;
|
newSize *= SHORT_BYTES;
|
||||||
|
|
||||||
layers.vbo.loadBufferData(sbuf, newSize, GL20.GL_ARRAY_BUFFER);
|
layers.vbo.loadBufferData(sbuf, newSize);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
package org.oscim.renderer.layers;
|
package org.oscim.renderer.layers;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.renderer.BufferObject;
|
import org.oscim.renderer.BufferObject;
|
||||||
import org.oscim.renderer.GLRenderer;
|
import org.oscim.renderer.GLRenderer;
|
||||||
@ -37,8 +36,6 @@ import org.oscim.view.MapView;
|
|||||||
*/
|
*/
|
||||||
public abstract class BasicRenderLayer extends RenderLayer {
|
public abstract class BasicRenderLayer extends RenderLayer {
|
||||||
|
|
||||||
private static final GL20 GL = GLAdapter.get();
|
|
||||||
|
|
||||||
public final Layers layers;
|
public final Layers layers;
|
||||||
|
|
||||||
public BasicRenderLayer(MapView mapView) {
|
public BasicRenderLayer(MapView mapView) {
|
||||||
@ -55,7 +52,7 @@ public abstract class BasicRenderLayer extends RenderLayer {
|
|||||||
|
|
||||||
float div = FastMath.pow(pos.zoomLevel - curPos.zoomLevel);
|
float div = FastMath.pow(pos.zoomLevel - curPos.zoomLevel);
|
||||||
|
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, layers.vbo.id);
|
layers.vbo.bind();
|
||||||
GLState.test(false, false);
|
GLState.test(false, false);
|
||||||
GLState.blend(true);
|
GLState.blend(true);
|
||||||
int simple = (curPos.tilt < 1 ? 1 : 0);
|
int simple = (curPos.tilt < 1 ? 1 : 0);
|
||||||
@ -91,10 +88,6 @@ public abstract class BasicRenderLayer extends RenderLayer {
|
|||||||
l = BitmapRenderer.draw(l, 1, m);
|
l = BitmapRenderer.draw(l, 1, m);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case Layer.SYMBOL:
|
|
||||||
// l = BitmapRenderer.draw(l, 1, m);
|
|
||||||
// break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
l = TextureRenderer.draw(l, scale, m);
|
l = TextureRenderer.draw(l, scale, m);
|
||||||
}
|
}
|
||||||
@ -113,7 +106,7 @@ public abstract class BasicRenderLayer extends RenderLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (layers.vbo == null) {
|
if (layers.vbo == null) {
|
||||||
layers.vbo = BufferObject.get(newSize);
|
layers.vbo = BufferObject.get(GL20.GL_ARRAY_BUFFER, newSize);
|
||||||
|
|
||||||
if (layers.vbo == null)
|
if (layers.vbo == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -95,8 +95,8 @@ public class CustomRenderLayer2 extends RenderLayer {
|
|||||||
buf.put(vertices);
|
buf.put(vertices);
|
||||||
buf.flip();
|
buf.flip();
|
||||||
|
|
||||||
mVBO = BufferObject.get(0);
|
mVBO = BufferObject.get(GL20.GL_ARRAY_BUFFER, 0);
|
||||||
mVBO.loadBufferData(buf, 12 * 4, GL20.GL_ARRAY_BUFFER);
|
mVBO.loadBufferData(buf, 12 * 4);
|
||||||
newData = false;
|
newData = false;
|
||||||
|
|
||||||
// tell GLRender to call 'render'
|
// tell GLRender to call 'render'
|
||||||
@ -113,7 +113,7 @@ public class CustomRenderLayer2 extends RenderLayer {
|
|||||||
GLState.test(false, false);
|
GLState.test(false, false);
|
||||||
|
|
||||||
// bind VBO data
|
// bind VBO data
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, mVBO.id);
|
mVBO.bind();
|
||||||
|
|
||||||
// set VBO vertex layout
|
// set VBO vertex layout
|
||||||
GL.glVertexAttribPointer(hVertexPosition, 2, GL20.GL_FLOAT, false, 0, 0);
|
GL.glVertexAttribPointer(hVertexPosition, 2, GL20.GL_FLOAT, false, 0, 0);
|
||||||
|
|||||||
@ -14,10 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.renderer.layers;
|
package org.oscim.renderer.layers;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.nio.ShortBuffer;
|
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
import org.oscim.backend.GLAdapter;
|
||||||
import org.oscim.backend.Log;
|
import org.oscim.backend.Log;
|
||||||
@ -203,8 +199,8 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
|||||||
setMatrix(pos, m, tiles[i], 0);
|
setMatrix(pos, m, tiles[i], 0);
|
||||||
m.mvp.setAsUniform(uExtMatrix);
|
m.mvp.setAsUniform(uExtMatrix);
|
||||||
|
|
||||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, el.vboIndices.id);
|
el.vboIndices.bind();
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, el.vboVertices.id);
|
el.vboVertices.bind();
|
||||||
|
|
||||||
GL.glVertexAttribPointer(uExtVertexPosition, 3,
|
GL.glVertexAttribPointer(uExtVertexPosition, 3,
|
||||||
GL20.GL_SHORT, false, 8, 0);
|
GL20.GL_SHORT, false, 8, 0);
|
||||||
@ -255,8 +251,8 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
|||||||
setMatrix(pos, m, t, d);
|
setMatrix(pos, m, t, d);
|
||||||
m.mvp.setAsUniform(uExtMatrix);
|
m.mvp.setAsUniform(uExtMatrix);
|
||||||
|
|
||||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, el.vboIndices.id);
|
el.vboIndices.bind();
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, el.vboVertices.id);
|
el.vboVertices.bind();
|
||||||
|
|
||||||
GL.glVertexAttribPointer(uExtVertexPosition, 3,
|
GL.glVertexAttribPointer(uExtVertexPosition, 3,
|
||||||
GL20.GL_SHORT, false, 8, 0);
|
GL20.GL_SHORT, false, 8, 0);
|
||||||
@ -281,8 +277,8 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
|||||||
setMatrix(pos, m, t, d);
|
setMatrix(pos, m, t, d);
|
||||||
m.mvp.setAsUniform(uExtMatrix);
|
m.mvp.setAsUniform(uExtMatrix);
|
||||||
|
|
||||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, el.vboIndices.id);
|
el.vboIndices.bind();
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, el.vboVertices.id);
|
el.vboVertices.bind();
|
||||||
|
|
||||||
GL.glVertexAttribPointer(uExtVertexPosition, 3,
|
GL.glVertexAttribPointer(uExtVertexPosition, 3,
|
||||||
GL20.GL_SHORT, false, 8, 0);
|
GL20.GL_SHORT, false, 8, 0);
|
||||||
|
|||||||
@ -28,8 +28,6 @@ package org.oscim.renderer.layers;
|
|||||||
// 5 R-Tree might be handy
|
// 5 R-Tree might be handy
|
||||||
//
|
//
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.backend.canvas.Color;
|
import org.oscim.backend.canvas.Color;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
@ -56,13 +54,13 @@ import org.oscim.view.MapViewPosition;
|
|||||||
|
|
||||||
|
|
||||||
public class TextRenderLayer extends BasicRenderLayer {
|
public class TextRenderLayer extends BasicRenderLayer {
|
||||||
private final static String TAG = TextRenderLayer.class.getName();
|
//private final static String TAG = TextRenderLayer.class.getName();
|
||||||
private static final GL20 GL = GLAdapter.get();
|
//private static final GL20 GL = GLAdapter.get();
|
||||||
|
|
||||||
private final static float MIN_CAPTION_DIST = 5;
|
private final static float MIN_CAPTION_DIST = 5;
|
||||||
private final static float MIN_WAY_DIST = 3;
|
private final static float MIN_WAY_DIST = 3;
|
||||||
|
|
||||||
private final static long MAX_RELABEL_DELAY = 200;
|
//private final static long MAX_RELABEL_DELAY = 200;
|
||||||
|
|
||||||
private final MapViewPosition mMapViewPosition;
|
private final MapViewPosition mMapViewPosition;
|
||||||
private final TileSet mTileSet;
|
private final TileSet mTileSet;
|
||||||
@ -734,7 +732,7 @@ public class TextRenderLayer extends BasicRenderLayer {
|
|||||||
@Override
|
@Override
|
||||||
public synchronized void render(MapPosition pos, Matrices m) {
|
public synchronized void render(MapPosition pos, Matrices m) {
|
||||||
|
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, layers.vbo.id);
|
layers.vbo.bind();
|
||||||
GLState.test(false, false);
|
GLState.test(false, false);
|
||||||
|
|
||||||
float scale = (float) (mMapPosition.scale / pos.scale);
|
float scale = (float) (mMapPosition.scale / pos.scale);
|
||||||
@ -758,7 +756,7 @@ public class TextRenderLayer extends BasicRenderLayer {
|
|||||||
l = TextureRenderer.draw(l, scale, m);
|
l = TextureRenderer.draw(l, scale, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mHolding;
|
//private boolean mHolding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param enable layer updates
|
* @param enable layer updates
|
||||||
|
|||||||
@ -15,130 +15,55 @@
|
|||||||
package org.oscim.renderer.layers.test;
|
package org.oscim.renderer.layers.test;
|
||||||
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.nio.FloatBuffer;
|
|
||||||
|
|
||||||
import org.oscim.view.MapView;
|
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.renderer.GLRenderer.Matrices;
|
import org.oscim.renderer.GLRenderer.Matrices;
|
||||||
import org.oscim.renderer.RenderLayer;
|
import org.oscim.renderer.RenderLayer;
|
||||||
|
import org.oscim.view.MapView;
|
||||||
public class ModelRenderLayer extends RenderLayer{
|
public class ModelRenderLayer extends RenderLayer{
|
||||||
|
|
||||||
public ModelRenderLayer(MapView mapView) {
|
public ModelRenderLayer(MapView mapView) {
|
||||||
super(mapView);
|
super(mapView);
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(MapPosition pos, boolean changed, Matrices m) {
|
public void update(MapPosition pos, boolean changed, Matrices m) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void compile() {
|
public void compile() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(MapPosition pos, Matrices m) {
|
public void render(MapPosition pos, Matrices m) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// based on edu.spsu.logo.SimpleRenderer (c) Jeff Chastine
|
|
||||||
private FloatBuffer vertexBuffer; // A buffer to hold the geometry/vertices
|
|
||||||
private FloatBuffer normalBuffer; // A buffer to hold the normals of each vertex
|
|
||||||
private FloatBuffer texCoordBuffer; // A buffer to hold the texture coordinates for each vertex
|
|
||||||
//private FloatBuffer lightBuffer; // A buffer to hold the position of a light
|
|
||||||
|
|
||||||
private void initShapes() {
|
|
||||||
|
|
||||||
float sin30 = (float)Math.sin(Math.PI/6.0);
|
// private final static String vertexShader = ""
|
||||||
float cos30 = (float)Math.cos(Math.PI/6.0);
|
// + "uniform mat4 uMVPMatrix;"
|
||||||
|
// + "uniform vec4 uLightPos;"
|
||||||
float hexagonCoords[] = {
|
// + "attribute vec4 vPosition;"
|
||||||
0.0f, 0.0f, 0.0f, // Hexagon face of SPSU logo
|
// + "attribute vec4 vNormal;"
|
||||||
cos30, sin30, 0.0f,
|
// + "attribute vec2 aTextureCoord;"
|
||||||
0.0f, 1.0f, 0.0f,
|
// + "varying vec2 vTextureCoord;"
|
||||||
-cos30, sin30, 0.0f,
|
// + "varying vec4 color;"
|
||||||
-cos30, -sin30, 0.0f,
|
// +
|
||||||
0.0f, -1.0f, 0.0f,
|
//
|
||||||
cos30, -sin30, 0.0f,
|
// "void main() {"
|
||||||
cos30, sin30, 0.0f
|
// + " vec3 light = normalize (uLightPos.xyz);"
|
||||||
};
|
// + " vec3 normal = normalize (vNormal.xyz);"
|
||||||
|
// + " vTextureCoord = aTextureCoord;"
|
||||||
float hexagonNormals[] = {
|
// + " color = vec4 (0.6, 0.8, 0.1, 1.0)*max(0.2, dot(normal, light));"
|
||||||
0.0f, 0.0f, 1.0f, // Normals for each vertex
|
// + " gl_Position = uMVPMatrix * vPosition;"
|
||||||
0.0f, 0.0f, 1.0f,
|
// + "}";
|
||||||
0.0f, 0.0f, 1.0f,
|
//
|
||||||
0.0f, 0.0f, 1.0f,
|
// private final static String fragmentShader = ""
|
||||||
0.0f, 0.0f, 1.0f,
|
// + "precision mediump float;"
|
||||||
0.0f, 0.0f, 1.0f,
|
// + "varying vec4 color;"
|
||||||
0.0f, 0.0f, 1.0f,
|
// + "varying vec2 vTextureCoord;"
|
||||||
0.0f, 0.0f, 1.0f
|
// + "uniform sampler2D sTexture;"
|
||||||
};
|
// + "void main() {"
|
||||||
|
// + " gl_FragColor = color + texture2D(sTexture, vTextureCoord);"
|
||||||
float hexagonTexCoords[] = {
|
// + "}";
|
||||||
0.5f, 0.5f, // Texture coordinates for each vertex
|
|
||||||
-cos30/2.0f+0.5f, -sin30/2.0f+0.5f,
|
|
||||||
0.5f, 0.0f,
|
|
||||||
cos30/2.0f+0.5f, -sin30/2.0f+0.5f,
|
|
||||||
cos30/2.0f+0.5f, sin30/2.0f+0.5f,
|
|
||||||
0.5f, 1.0f,
|
|
||||||
-cos30/2.0f+0.5f, sin30/2.0f+0.5f,
|
|
||||||
-cos30/2.0f+0.5f, -sin30/2.0f+0.5f,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Load all of that info into 3 buffers
|
|
||||||
ByteBuffer vbb = ByteBuffer.allocateDirect(hexagonCoords.length*4);
|
|
||||||
vbb.order (ByteOrder.nativeOrder());
|
|
||||||
vertexBuffer = vbb.asFloatBuffer(); // make a buffer from a buffer
|
|
||||||
vertexBuffer.put(hexagonCoords); // add the coords to the float buffer
|
|
||||||
vertexBuffer.position(0); // set the reading pointer back to 0
|
|
||||||
|
|
||||||
ByteBuffer vbb2 = ByteBuffer.allocateDirect(hexagonNormals.length*4);
|
|
||||||
vbb2.order (ByteOrder.nativeOrder());
|
|
||||||
normalBuffer = vbb2.asFloatBuffer(); // make a buffer from a buffer
|
|
||||||
normalBuffer.put(hexagonNormals); // add the coords to the float buffer
|
|
||||||
normalBuffer.position(0); // set the reading pointer back to 0
|
|
||||||
|
|
||||||
ByteBuffer vbb3 = ByteBuffer.allocateDirect(hexagonTexCoords.length*4);
|
|
||||||
vbb3.order (ByteOrder.nativeOrder());
|
|
||||||
texCoordBuffer = vbb3.asFloatBuffer(); // make a buffer from a buffer
|
|
||||||
texCoordBuffer.put(hexagonTexCoords); // add the coords to the float buffer
|
|
||||||
texCoordBuffer.position(0); // set the reading pointer back to 0
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private final static String vertexShader = ""
|
|
||||||
+ "uniform mat4 uMVPMatrix;"
|
|
||||||
+ "uniform vec4 uLightPos;"
|
|
||||||
+ "attribute vec4 vPosition;"
|
|
||||||
+ "attribute vec4 vNormal;"
|
|
||||||
+ "attribute vec2 aTextureCoord;"
|
|
||||||
+ "varying vec2 vTextureCoord;"
|
|
||||||
+ "varying vec4 color;"
|
|
||||||
+
|
|
||||||
|
|
||||||
"void main() {"
|
|
||||||
//" vec4 normal = vNormal*uMVPMatrix;" +
|
|
||||||
+ " vec3 light = normalize (uLightPos.xyz);"
|
|
||||||
+ " vec3 normal = normalize (vNormal.xyz);"
|
|
||||||
+ " vTextureCoord = aTextureCoord;"
|
|
||||||
+ " color = vec4 (0.6, 0.8, 0.1, 1.0)*max(0.2, dot(normal, light));"
|
|
||||||
+ " gl_Position = uMVPMatrix * vPosition;"
|
|
||||||
+ "}";
|
|
||||||
|
|
||||||
private final static String fragmentShader = ""
|
|
||||||
+ "precision mediump float;"
|
|
||||||
+ "varying vec4 color;"
|
|
||||||
+ "varying vec2 vTextureCoord;"
|
|
||||||
+ "uniform sampler2D sTexture;"
|
|
||||||
+ "void main() {"
|
|
||||||
+ " gl_FragColor = color + texture2D(sTexture, vTextureCoord);"
|
|
||||||
+ "}";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -402,8 +402,8 @@ public class ExtrusionLayer extends Layer {
|
|||||||
|
|
||||||
sbuf.flip();
|
sbuf.flip();
|
||||||
int size = mNumIndices * 2;
|
int size = mNumIndices * 2;
|
||||||
vboIndices = BufferObject.get(size);
|
vboIndices = BufferObject.get(GL20.GL_ELEMENT_ARRAY_BUFFER, size);
|
||||||
vboIndices.loadBufferData(sbuf, size, GL20.GL_ELEMENT_ARRAY_BUFFER);
|
vboIndices.loadBufferData(sbuf, size);
|
||||||
|
|
||||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
@ -414,8 +414,8 @@ public class ExtrusionLayer extends Layer {
|
|||||||
|
|
||||||
sbuf.flip();
|
sbuf.flip();
|
||||||
size = mNumVertices * 4 * 2;
|
size = mNumVertices * 4 * 2;
|
||||||
vboVertices = BufferObject.get(size);
|
vboVertices = BufferObject.get(GL20.GL_ARRAY_BUFFER, size);
|
||||||
vboVertices.loadBufferData(sbuf, size, GL20.GL_ARRAY_BUFFER);
|
vboVertices.loadBufferData(sbuf, size);
|
||||||
|
|
||||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
@ -502,7 +502,8 @@ public class ExtrusionLayer extends Layer {
|
|||||||
* @return number of triangles in io buffer
|
* @return number of triangles in io buffer
|
||||||
*/
|
*/
|
||||||
public static native int triangulate(float[] points, int pos, int len, int numRings,
|
public static native int triangulate(float[] points, int pos, int len, int numRings,
|
||||||
ShortBuffer io,
|
ShortBuffer io, int ioffset) /*-{
|
||||||
int ioffset);
|
return 0;
|
||||||
|
}-*/;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user