get() for GL instance and other fixes for gwt compilation
This commit is contained in:
parent
970c0b6f0b
commit
1f8739023c
@ -85,7 +85,7 @@ public interface GL20 {
|
||||
public static final int GL_POLYGON_OFFSET_FILL = 0x8037;
|
||||
public static final int GL_SAMPLE_ALPHA_TO_COVERAGE = 0x809E;
|
||||
public static final int GL_SAMPLE_COVERAGE = 0x80A0;
|
||||
public static final int GL_NO_ERROR = 0;
|
||||
//public static final int GL_NO_ERROR = 0;
|
||||
public static final int GL_INVALID_ENUM = 0x0500;
|
||||
public static final int GL_INVALID_VALUE = 0x0501;
|
||||
public static final int GL_INVALID_OPERATION = 0x0502;
|
||||
|
||||
@ -18,4 +18,8 @@ package org.oscim.backend;
|
||||
|
||||
public class GLAdapter {
|
||||
public static GL20 INSTANCE; //= new AndroidGL20();
|
||||
|
||||
public static GL20 get(){
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ import org.oscim.view.MapViewPosition;
|
||||
|
||||
class TextRenderLayer extends BasicRenderLayer {
|
||||
private final static String TAG = TextRenderLayer.class.getName();
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
private final static float MIN_CAPTION_DIST = 5;
|
||||
private final static float MIN_WAY_DIST = 3;
|
||||
|
||||
@ -77,17 +77,17 @@ public abstract class TileLayer<T extends TileLoader> extends Layer {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
for (T tileWorker : mTileLoader) {
|
||||
tileWorker.pause();
|
||||
tileWorker.interrupt();
|
||||
tileWorker.cleanup();
|
||||
for (T loader : mTileLoader) {
|
||||
loader.pause();
|
||||
loader.interrupt();
|
||||
loader.cleanup();
|
||||
|
||||
try {
|
||||
tileWorker.join(10000);
|
||||
} catch (InterruptedException e) {
|
||||
// restore the interrupted status
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// try {
|
||||
// tileWorker.join(10000);
|
||||
// } catch (InterruptedException e) {
|
||||
// // restore the interrupted status
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
}
|
||||
mTileManager.destroy();
|
||||
}
|
||||
@ -96,7 +96,7 @@ public abstract class TileLayer<T extends TileLoader> extends Layer {
|
||||
for (int i = 0; i < mNumTileLoader; i++) {
|
||||
T m = mTileLoader.get(i);
|
||||
synchronized (m) {
|
||||
m.notify();
|
||||
m.go();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,9 @@ public abstract class TileLoader extends PausableThread {
|
||||
|
||||
protected abstract boolean executeJob(MapTile tile);
|
||||
|
||||
public void go(){
|
||||
notify();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWork() {
|
||||
|
||||
@ -34,15 +34,13 @@ import org.oscim.view.MapView;
|
||||
import org.oscim.view.MapViewPosition;
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
* - prefetching to cache file
|
||||
* - this class should probably not be in 'renderer' -> tilemap?
|
||||
* - make it general for reuse in tile-overlays
|
||||
* @TODO - prefetching to cache file - this class should probably not be in
|
||||
* 'renderer' -> tilemap? - make it general for reuse in tile-overlays
|
||||
*/
|
||||
public class TileManager {
|
||||
private static final int CACHE_TILES_MAX = 250;
|
||||
|
||||
static final String TAG = TileManager.class.getSimpleName();
|
||||
static final String TAG = TileManager.class.getName();
|
||||
private final static int MIN_ZOOMLEVEL = 2;
|
||||
|
||||
private final int mMaxZoom;
|
||||
@ -56,7 +54,6 @@ public class TileManager {
|
||||
private final MapView mMapView;
|
||||
private final MapViewPosition mMapViewPosition;
|
||||
|
||||
|
||||
// cache for all tiles
|
||||
private MapTile[] mTiles;
|
||||
|
||||
@ -80,7 +77,7 @@ public class TileManager {
|
||||
private final Object mTilelock = new Object();
|
||||
|
||||
// need to keep track of TileSets to clear on reset.
|
||||
//private final ArrayList<TileSet> mTileSets = new ArrayList<TileSet>(4);
|
||||
// private final ArrayList<TileSet> mTileSets = new ArrayList<TileSet>(4);
|
||||
|
||||
private TileSet mCurrentTiles;
|
||||
/* package */TileSet mNewTiles;
|
||||
@ -148,42 +145,41 @@ public class TileManager {
|
||||
|
||||
// sync with GLRender thread
|
||||
// ... and labeling thread?
|
||||
GLRenderer.drawlock.lock();
|
||||
synchronized (GLRenderer.drawlock) {
|
||||
|
||||
if (!first) {
|
||||
// pass VBOs and VertexItems back to pools
|
||||
for (int i = 0; i < mTilesSize; i++)
|
||||
clearTile(mTiles[i]);
|
||||
}
|
||||
|
||||
// FIXME any of this still needed?
|
||||
// mInitialized is set when surface changed
|
||||
// and VBOs might be lost
|
||||
// VertexPool.init();
|
||||
// clear cache index
|
||||
// QuadTree.init();
|
||||
|
||||
// clear references to cached MapTiles
|
||||
Arrays.fill(mTiles, null);
|
||||
mTilesSize = 0;
|
||||
mTilesCount = 0;
|
||||
|
||||
// set up TileSet large enough to hold current tiles
|
||||
int num = Math.max(mMapView.getWidth(), mMapView.getHeight());
|
||||
int size = Tile.SIZE >> 1;
|
||||
int numTiles = (num * num) / (size * size) * 4;
|
||||
|
||||
mNewTiles = new TileSet(numTiles);
|
||||
mCurrentTiles = new TileSet(numTiles);
|
||||
Log.d(TAG, "max tiles: " + numTiles);
|
||||
|
||||
if (!first) {
|
||||
// pass VBOs and VertexItems back to pools
|
||||
for (int i = 0; i < mTilesSize; i++)
|
||||
clearTile(mTiles[i]);
|
||||
}
|
||||
|
||||
// FIXME any of this still needed?
|
||||
// mInitialized is set when surface changed
|
||||
// and VBOs might be lost
|
||||
// VertexPool.init();
|
||||
// clear cache index
|
||||
// QuadTree.init();
|
||||
|
||||
// clear references to cached MapTiles
|
||||
Arrays.fill(mTiles, null);
|
||||
mTilesSize = 0;
|
||||
mTilesCount = 0;
|
||||
|
||||
// set up TileSet large enough to hold current tiles
|
||||
int num = Math.max(mMapView.getWidth(), mMapView.getHeight());
|
||||
int size = Tile.SIZE >> 1;
|
||||
int numTiles = (num * num) / (size * size) * 4;
|
||||
|
||||
mNewTiles = new TileSet(numTiles);
|
||||
mCurrentTiles = new TileSet(numTiles);
|
||||
Log.d(TAG, "max tiles: " + numTiles);
|
||||
|
||||
GLRenderer.drawlock.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Update mCurrentTiles TileSet of currently visible tiles.
|
||||
* 2. Add not yet loaded (or loading) tiles to JobQueue.
|
||||
* 3. Manage cache
|
||||
* 1. Update mCurrentTiles TileSet of currently visible tiles. 2. Add not
|
||||
* yet loaded (or loading) tiles to JobQueue. 3. Manage cache
|
||||
*
|
||||
* @param pos
|
||||
* current MapPosition
|
||||
@ -202,9 +198,9 @@ public class TileManager {
|
||||
|
||||
int tileZoom = FastMath.clamp(pos.zoomLevel, MIN_ZOOMLEVEL, mMaxZoom);
|
||||
|
||||
if (mZoomTable != null){
|
||||
if (mZoomTable != null) {
|
||||
int match = 0;
|
||||
for (int z : mZoomTable){
|
||||
for (int z : mZoomTable) {
|
||||
if (z <= tileZoom && z > match)
|
||||
match = z;
|
||||
}
|
||||
@ -260,7 +256,7 @@ public class TileManager {
|
||||
|
||||
mUpdateSerial++;
|
||||
}
|
||||
|
||||
Log.d(TAG, newCnt + " << " + Arrays.deepToString(mCurrentTiles.tiles));
|
||||
// request rendering as tiles changed
|
||||
mMapView.render();
|
||||
}
|
||||
@ -283,7 +279,7 @@ public class TileManager {
|
||||
int remove = mTilesCount - CACHE_TILES_MAX;
|
||||
|
||||
if (remove > CACHE_THRESHOLD ||
|
||||
mTilesForUpload > MAX_TILES_IN_QUEUE)
|
||||
mTilesForUpload > MAX_TILES_IN_QUEUE)
|
||||
|
||||
limitCache(pos, remove);
|
||||
}
|
||||
@ -294,12 +290,12 @@ public class TileManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive a TileSet of current tiles.
|
||||
* Tiles remain locked in cache until the set is unlocked by either passing
|
||||
* it again to this function or to releaseTiles. If passed TileSet is null
|
||||
* it will be allocated.
|
||||
* Retrive a TileSet of current tiles. Tiles remain locked in cache until
|
||||
* the set is unlocked by either passing it again to this function or to
|
||||
* releaseTiles. If passed TileSet is null it will be allocated.
|
||||
*
|
||||
* @param tileSet to be updated
|
||||
* @param tileSet
|
||||
* to be updated
|
||||
* @return true if TileSet has changed
|
||||
*/
|
||||
public boolean getActiveTiles(TileSet tileSet) {
|
||||
@ -342,17 +338,17 @@ public class TileManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param tiles ...
|
||||
// */
|
||||
// public void releaseTiles(TileSet tiles) {
|
||||
// /**
|
||||
// * @param tiles ...
|
||||
// */
|
||||
// public void releaseTiles(TileSet tiles) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
/* package */MapTile addTile(int x, int y, int zoomLevel) {
|
||||
MapTile tile;
|
||||
|
||||
//tile = QuadTree.getTile(x, y, zoomLevel);
|
||||
// tile = QuadTree.getTile(x, y, zoomLevel);
|
||||
tile = mIndex.getTile(x, y, zoomLevel);
|
||||
|
||||
if (tile == null) {
|
||||
@ -383,7 +379,7 @@ public class TileManager {
|
||||
}
|
||||
|
||||
if (zoomLevel > 3) {
|
||||
// prefetch grand parent
|
||||
// prefetch grand parent
|
||||
p = tile.rel.parent.parent.item;
|
||||
add = false;
|
||||
if (p == null) {
|
||||
@ -432,14 +428,14 @@ public class TileManager {
|
||||
|
||||
mIndex.remove(t);
|
||||
|
||||
//QuadTree.remove(t);
|
||||
// QuadTree.remove(t);
|
||||
t.state = STATE_NONE;
|
||||
|
||||
mTilesCount--;
|
||||
}
|
||||
|
||||
private static void updateTileDistances(MapTile[] tiles, int size, MapPosition pos) {
|
||||
// TODO there is probably a better quad-tree distance function
|
||||
// TODO there is probably a better quad-tree distance function
|
||||
|
||||
int zoom = 20;
|
||||
long x = (long) (pos.x * (1 << zoom));
|
||||
@ -509,32 +505,32 @@ public class TileManager {
|
||||
// so end of mTiles is at mTilesCount now
|
||||
size = mTilesSize = mTilesCount;
|
||||
|
||||
//Log.d(TAG, "remove:" + remove + " new:" + newTileCnt);
|
||||
//Log.d(TAG, "cur: " + mapPosition);
|
||||
// Log.d(TAG, "remove:" + remove + " new:" + newTileCnt);
|
||||
// Log.d(TAG, "cur: " + mapPosition);
|
||||
|
||||
for (int i = size - 1; i >= 0 && remove > 0; i--) {
|
||||
MapTile t = tiles[i];
|
||||
if (t.isLocked()) {
|
||||
// dont remove tile used by GLRenderer, or somewhere else
|
||||
Log.d(TAG, "locked " + t
|
||||
+ " " + t.distance
|
||||
+ " " + (t.state == STATE_NEW_DATA)
|
||||
+ " " + (t.state == STATE_LOADING)
|
||||
+ " " + pos.zoomLevel);
|
||||
+ " " + t.distance
|
||||
+ " " + (t.state == STATE_NEW_DATA)
|
||||
+ " " + (t.state == STATE_LOADING)
|
||||
+ " " + pos.zoomLevel);
|
||||
// try again in next run.
|
||||
} else if (t.state == STATE_LOADING) {
|
||||
// NOTE: when set loading to false the tile could be
|
||||
// NOTE: when set loading to false the tile could be
|
||||
// added to load queue again while still processed in
|
||||
// MapTileLoader => need tile.cancel flag.
|
||||
// t.isLoading = false;
|
||||
Log.d(TAG, "cancel loading " + t
|
||||
+ " " + t.distance);
|
||||
+ " " + t.distance);
|
||||
} else {
|
||||
// clear unused tile
|
||||
|
||||
if (t.state == STATE_NEW_DATA) {
|
||||
//Log.d(TAG, "limitCache: clear unused " + t
|
||||
// + " " + t.distance);
|
||||
// Log.d(TAG, "limitCache: clear unused " + t
|
||||
// + " " + t.distance);
|
||||
newTileCnt--;
|
||||
}
|
||||
|
||||
@ -545,7 +541,7 @@ public class TileManager {
|
||||
}
|
||||
|
||||
remove = (newTileCnt - MAX_TILES_IN_QUEUE) + 10;
|
||||
//int r = remove;
|
||||
// int r = remove;
|
||||
for (int i = size - 1; i >= 0 && remove > 0; i--) {
|
||||
MapTile t = tiles[i];
|
||||
if (t != null && t.state == STATE_NEW_DATA) {
|
||||
@ -559,7 +555,8 @@ public class TileManager {
|
||||
}
|
||||
|
||||
mTilesForUpload += newTileCnt;
|
||||
//Log.d(TAG, "cleanup load queue " + tilesForUpload + "/" + r + " - " + remove);
|
||||
// Log.d(TAG, "cleanup load queue " + tilesForUpload + "/" + r +
|
||||
// " - " + remove);
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,7 +573,7 @@ public class TileManager {
|
||||
// - should rather be STATE_FAILED
|
||||
// no one should be able to use this tile now, MapTileLoader passed
|
||||
// it, GL-Thread does nothing until newdata is set.
|
||||
//Log.d(TAG, "passTile: failed loading " + tile);
|
||||
// Log.d(TAG, "passTile: failed loading " + tile);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -17,15 +17,16 @@ package org.oscim.layers.tile;
|
||||
import static org.oscim.layers.tile.MapTile.STATE_NEW_DATA;
|
||||
import static org.oscim.layers.tile.MapTile.STATE_READY;
|
||||
|
||||
import org.oscim.view.MapView;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.BufferObject;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
import org.oscim.renderer.RenderLayer;
|
||||
import org.oscim.utils.ScanBox;
|
||||
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
public class TileRenderLayer extends RenderLayer {
|
||||
private final static String TAG = TileRenderLayer.class.getName();
|
||||
@ -62,13 +63,15 @@ public class TileRenderLayer extends RenderLayer {
|
||||
int tileCnt = mDrawTiles.cnt;
|
||||
MapTile[] tiles = mDrawTiles.tiles;
|
||||
|
||||
if (tilesChanged || positionChanged)
|
||||
if (tilesChanged || positionChanged){
|
||||
updateTileVisibility(m.mapPlane);
|
||||
Log.d(TAG, tileCnt + " >> " + Arrays.deepToString(tiles));
|
||||
|
||||
}
|
||||
tileCnt += mNumTileHolder;
|
||||
|
||||
/* prepare tile for rendering */
|
||||
if (compileTileLayers(tiles, tileCnt) > 0){
|
||||
if (compileTileLayers(tiles, tileCnt) > 0) {
|
||||
mUploadSerial++;
|
||||
BufferObject.checkBufferUsage(false);
|
||||
}
|
||||
@ -89,9 +92,9 @@ public class TileRenderLayer extends RenderLayer {
|
||||
public void clearTiles() {
|
||||
// Clear all references to MapTiles as all current
|
||||
// tiles will also be removed from TileManager.
|
||||
GLRenderer.drawlock.lock();
|
||||
mDrawTiles = new TileSet();
|
||||
GLRenderer.drawlock.unlock();
|
||||
synchronized (GLRenderer.drawlock) {
|
||||
mDrawTiles = new TileSet();
|
||||
}
|
||||
}
|
||||
|
||||
/** compile tile layer data and upload to VBOs */
|
||||
@ -192,8 +195,8 @@ public class TileRenderLayer extends RenderLayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update tileSet with currently visible tiles
|
||||
* get a TileSet of currently visible tiles
|
||||
* Update tileSet with currently visible tiles get a TileSet of currently
|
||||
* visible tiles
|
||||
*/
|
||||
public boolean getVisibleTiles(TileSet tileSet) {
|
||||
if (tileSet == null)
|
||||
@ -205,8 +208,8 @@ public class TileRenderLayer extends RenderLayer {
|
||||
}
|
||||
|
||||
// same tiles as before
|
||||
//if (tileSet.serial == mDrawTiles.serial)
|
||||
//return false;
|
||||
// if (tileSet.serial == mDrawTiles.serial)
|
||||
// return false;
|
||||
|
||||
int prevSerial = tileSet.serial;
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ import org.oscim.utils.quadtree.QuadTree;
|
||||
public class TileRenderer {
|
||||
//private final static String TAG = TileRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
// Counter increases polygon-offset for each tile drawn.
|
||||
private static int mOffsetCnt;
|
||||
@ -153,7 +153,7 @@ public class TileRenderer {
|
||||
|
||||
// simple line shader does not take forward shortening into
|
||||
// account. only used when tilt is 0.
|
||||
int simpleShader = (pos.tilt < 1 ? 1 : 0);
|
||||
int simpleShader = 1; //(pos.tilt < 1 ? 1 : 0);
|
||||
|
||||
boolean clipped = false;
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ import org.oscim.utils.GlUtils;
|
||||
public final class BufferObject {
|
||||
private final static String TAG = BufferObject.class.getName();
|
||||
|
||||
private final static GL20 GL = GLAdapter.INSTANCE;
|
||||
private final static GL20 GL = GLAdapter.get();
|
||||
|
||||
private static final int MB = 1024 * 1024;
|
||||
private static final int LIMIT_BUFFERS = 16 * MB;
|
||||
|
||||
@ -19,7 +19,6 @@ import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
@ -39,7 +38,7 @@ import org.oscim.view.MapViewPosition;
|
||||
public class GLRenderer {
|
||||
private static final String TAG = GLRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static GL20 GL = GLAdapter.get();
|
||||
|
||||
private static final int SHORT_BYTES = 2;
|
||||
private static final int CACHE_TILES_MAX = 250;
|
||||
@ -97,7 +96,7 @@ public class GLRenderer {
|
||||
|
||||
// drawlock to synchronize Main- and GL-Thread
|
||||
// static ReentrantLock tilelock = new ReentrantLock();
|
||||
public static ReentrantLock drawlock = new ReentrantLock();
|
||||
public static Object drawlock = new Object();
|
||||
|
||||
/**
|
||||
* @param mapView
|
||||
@ -252,11 +251,8 @@ public class GLRenderer {
|
||||
|
||||
// prevent main thread recreating all tiles (updateMap)
|
||||
// while rendering is going on.
|
||||
drawlock.lock();
|
||||
try {
|
||||
synchronized(drawlock){
|
||||
draw();
|
||||
} finally {
|
||||
drawlock.unlock();
|
||||
}
|
||||
|
||||
mBufferPool.releaseBuffers();
|
||||
@ -348,7 +344,7 @@ public class GLRenderer {
|
||||
mMatrices.mvp.setScale(0.5f, 0.5f, 1);
|
||||
mMatrices.proj.multiplyLhs(mMatrices.mvp);
|
||||
}
|
||||
|
||||
GL = GLAdapter.get();
|
||||
GL.glViewport(0, 0, width, height);
|
||||
GL.glScissor(0, 0, width, height);
|
||||
GL.glEnable(GL20.GL_SCISSOR_TEST);
|
||||
@ -399,6 +395,9 @@ public class GLRenderer {
|
||||
}
|
||||
|
||||
public void onSurfaceCreated() {
|
||||
|
||||
Log.d(TAG, "surface created");
|
||||
|
||||
// Log.d(TAG, GL.glGetString(GL20.GL_EXTENSIONS));
|
||||
|
||||
// classes that require GL context for initialization
|
||||
|
||||
@ -19,7 +19,7 @@ import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
|
||||
public class GLState {
|
||||
private final static GL20 GL = GLAdapter.INSTANCE;
|
||||
private final static GL20 GL = GLAdapter.get();
|
||||
|
||||
private final static String TAG = GLState.class.getName();
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ import org.oscim.view.MapView;
|
||||
*/
|
||||
public abstract class BasicRenderLayer extends RenderLayer {
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
public final Layers layers;
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ import org.oscim.view.MapView;
|
||||
|
||||
public class CustomRenderLayer extends RenderLayer {
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
private int mProgramObject;
|
||||
private int hVertexPosition;
|
||||
|
||||
@ -39,7 +39,7 @@ import org.oscim.view.MapView;
|
||||
|
||||
public class CustomRenderLayer2 extends RenderLayer {
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
private int mProgramObject;
|
||||
private int hVertexPosition;
|
||||
|
||||
@ -37,7 +37,7 @@ import org.oscim.view.MapView;
|
||||
public class ExtrusionRenderLayer extends RenderLayer {
|
||||
private final static String TAG = ExtrusionRenderLayer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
private final TileRenderLayer mTileLayer;
|
||||
|
||||
@ -421,14 +421,14 @@ public class ExtrusionRenderLayer extends RenderLayer {
|
||||
+ "}}}";
|
||||
|
||||
final static String extrusionFragmentShader = ""
|
||||
//+ "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "varying vec4 color;"
|
||||
+ "void main() {"
|
||||
+ " gl_FragColor = color;"
|
||||
+ "}";
|
||||
|
||||
final static String extrusionFragmentShaderZ = ""
|
||||
// + "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "varying float depth;"
|
||||
+ "void main() {"
|
||||
+ "float d = depth * 0.2;"
|
||||
|
||||
@ -14,9 +14,6 @@
|
||||
*/
|
||||
package org.oscim.renderer.layers;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.oscim.view.MapView;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.backend.canvas.Paint.Cap;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
@ -24,15 +21,13 @@ import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
import org.oscim.renderer.sublayers.LineLayer;
|
||||
import org.oscim.renderer.sublayers.TextItem;
|
||||
import org.oscim.renderer.sublayers.TextLayer;
|
||||
import org.oscim.theme.renderinstruction.Line;
|
||||
import org.oscim.theme.renderinstruction.Text;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
public class GridRenderLayer extends BasicRenderLayer {
|
||||
private final static String TILE_FORMAT = "%d/%d/%d";
|
||||
private final TextLayer mTextLayer;
|
||||
private final Text mText;
|
||||
// private final TextLayer mTextLayer;
|
||||
// private final Text mText;
|
||||
|
||||
private final LineLayer mLineLayer;
|
||||
|
||||
@ -67,44 +62,44 @@ public class GridRenderLayer extends BasicRenderLayer {
|
||||
mLines.addPoint(pos + size * 8, y);
|
||||
}
|
||||
|
||||
mText = Text.createText(22, 0, Color.RED, 0, false);
|
||||
// mText = Text.createText(22, 0, Color.RED, 0, false);
|
||||
|
||||
mTextLayer = layers.addTextLayer(new TextLayer());
|
||||
// mTextLayer = layers.addTextLayer(new TextLayer());
|
||||
mLineLayer = layers.addLineLayer(0,
|
||||
new Line(Color.BLUE, 1.5f, Cap.BUTT));
|
||||
}
|
||||
|
||||
private void addLabels(int x, int y, int z) {
|
||||
int s = Tile.SIZE;
|
||||
|
||||
TextLayer tl = mTextLayer;
|
||||
tl.clear();
|
||||
|
||||
for (int yy = -2; yy < 2; yy++) {
|
||||
for (int xx = -2; xx < 2; xx++) {
|
||||
|
||||
// String label = String.format(
|
||||
// Locale.ROOT, TILE_FORMAT,
|
||||
// Integer.valueOf(x + xx),
|
||||
// Integer.valueOf(y + yy),
|
||||
// Integer.valueOf(z));
|
||||
String label = Integer.valueOf(x + xx) + "/" +
|
||||
Integer.valueOf(y + yy) + "/" +
|
||||
Integer.valueOf(z);
|
||||
|
||||
TextItem ti = TextItem.pool.get();
|
||||
ti.set(s * xx + s / 2, s * yy + s / 2, label, mText);
|
||||
|
||||
tl.addText(ti);
|
||||
}
|
||||
}
|
||||
|
||||
// render TextItems to a bitmap and prepare vertex buffer data.
|
||||
tl.prepare();
|
||||
|
||||
// release TextItems
|
||||
tl.clearLabels();
|
||||
}
|
||||
// private void addLabels(int x, int y, int z) {
|
||||
// int s = Tile.SIZE;
|
||||
//
|
||||
// TextLayer tl = mTextLayer;
|
||||
// tl.clear();
|
||||
//
|
||||
// for (int yy = -2; yy < 2; yy++) {
|
||||
// for (int xx = -2; xx < 2; xx++) {
|
||||
//
|
||||
// // String label = String.format(
|
||||
// // Locale.ROOT, TILE_FORMAT,
|
||||
// // Integer.valueOf(x + xx),
|
||||
// // Integer.valueOf(y + yy),
|
||||
// // Integer.valueOf(z));
|
||||
// String label = Integer.valueOf(x + xx) + "/" +
|
||||
// Integer.valueOf(y + yy) + "/" +
|
||||
// Integer.valueOf(z);
|
||||
//
|
||||
// TextItem ti = TextItem.pool.get();
|
||||
// ti.set(s * xx + s / 2, s * yy + s / 2, label, mText);
|
||||
//
|
||||
// tl.addText(ti);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // render TextItems to a bitmap and prepare vertex buffer data.
|
||||
// tl.prepare();
|
||||
//
|
||||
// // release TextItems
|
||||
// tl.clearLabels();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void update(MapPosition pos, boolean changed, Matrices m) {
|
||||
@ -129,7 +124,7 @@ public class GridRenderLayer extends BasicRenderLayer {
|
||||
layerPos.y = (double) y / z;
|
||||
layerPos.scale = z;
|
||||
|
||||
addLabels(x, y, pos.zoomLevel);
|
||||
// addLabels(x, y, pos.zoomLevel);
|
||||
|
||||
mLineLayer.clear();
|
||||
mLineLayer.addLine(mLines);
|
||||
|
||||
@ -57,7 +57,7 @@ import org.oscim.view.MapViewPosition;
|
||||
|
||||
public class TextRenderLayer extends BasicRenderLayer {
|
||||
private final static String TAG = TextRenderLayer.class.getName();
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
private final static float MIN_CAPTION_DIST = 5;
|
||||
private final static float MIN_WAY_DIST = 3;
|
||||
|
||||
@ -27,7 +27,7 @@ import org.oscim.utils.GlUtils;
|
||||
public final class BitmapRenderer {
|
||||
|
||||
//private final static String TAG = BitmapRenderer.class.getName();
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
public final static boolean debug = true;
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ import org.oscim.utils.LineClipper;
|
||||
public class ExtrusionLayer extends Layer {
|
||||
private final static String TAG = ExtrusionLayer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
private static final float S = GLRenderer.COORD_SCALE;
|
||||
private VertexItem mVertices;
|
||||
|
||||
@ -27,7 +27,7 @@ import org.oscim.utils.GlUtils;
|
||||
public final class LineRenderer {
|
||||
private final static String TAG = LineRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static GL20 GL;
|
||||
|
||||
private static final int LINE_VERTICES_DATA_POS_OFFSET = 0;
|
||||
|
||||
@ -46,6 +46,8 @@ public final class LineRenderer {
|
||||
private static int mTexID;
|
||||
|
||||
static boolean init() {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
lineProgram[0] = GlUtils.createProgram(lineVertexShader,
|
||||
lineFragmentShader);
|
||||
if (lineProgram[0] == 0) {
|
||||
@ -93,11 +95,11 @@ public final class LineRenderer {
|
||||
}
|
||||
|
||||
public static void beginLines() {
|
||||
//GL.glBindTexture(GL20.GL_TEXTURE_2D, mTexID);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, mTexID);
|
||||
}
|
||||
|
||||
public static void endLines() {
|
||||
//GL.glBindTexture(GL20.GL_TEXTURE_2D, 0);
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
public static Layer draw(Layers layers, Layer curLayer, MapPosition pos,
|
||||
@ -249,7 +251,7 @@ public final class LineRenderer {
|
||||
}
|
||||
|
||||
private final static String lineVertexShader = ""
|
||||
//+ "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform mat4 u_mvp;"
|
||||
// factor to increase line width relative to scale
|
||||
+ "uniform float u_width;"
|
||||
@ -268,7 +270,7 @@ public final class LineRenderer {
|
||||
+ "}";
|
||||
|
||||
private final static String lineSimpleFragmentShader = ""
|
||||
//+ "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform sampler2D tex;"
|
||||
+ "uniform float u_wscale;"
|
||||
+ "uniform float u_mode;"
|
||||
@ -283,8 +285,8 @@ public final class LineRenderer {
|
||||
//+ " len = texture2D(tex, v_st).a;"
|
||||
//+ " len = u_mode * length(v_st);"
|
||||
// this avoids branching, need to check performance
|
||||
//+ " float len = max((1.0 - u_mode) * abs(v_st.s), u_mode * texture2D(tex, v_st).a);"
|
||||
+ " float len = max((1.0 - u_mode) * abs(v_st.s), u_mode * length(v_st));"
|
||||
+ " float len = max((1.0 - u_mode) * abs(v_st.s), u_mode * texture2D(tex, v_st).a);"
|
||||
//+ " float len = max((1.0 - u_mode) * abs(v_st.s), u_mode * length(v_st));"
|
||||
// interpolate alpha between: 0.0 < 1.0 - len < u_wscale
|
||||
// where wscale is 'filter width' / 'line width' and 0 <= len <= sqrt(2)
|
||||
//+ " gl_FragColor = u_color * smoothstep(0.0, u_wscale, 1.0 - len);"
|
||||
@ -294,7 +296,7 @@ public final class LineRenderer {
|
||||
|
||||
private final static String lineFragmentShader = ""
|
||||
+ "#extension GL_OES_standard_derivatives : enable\n"
|
||||
//+ "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform sampler2D tex;"
|
||||
+ "uniform float u_mode;"
|
||||
+ "uniform vec4 u_color;"
|
||||
@ -307,8 +309,8 @@ public final class LineRenderer {
|
||||
+ " len = abs(v_st.s);"
|
||||
+ " fuzz = fwidth(v_st.s);"
|
||||
+ " } else {"
|
||||
//+ " len = texture2D(tex, v_st).a;"
|
||||
+ " len = length(v_st);"
|
||||
+ " len = texture2D(tex, v_st).a;"
|
||||
//+ " len = length(v_st);"
|
||||
+ " vec2 st_width = fwidth(v_st);"
|
||||
+ " fuzz = max(st_width.s, st_width.t);"
|
||||
+ " }"
|
||||
|
||||
@ -14,8 +14,7 @@
|
||||
*/
|
||||
package org.oscim.renderer.sublayers;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
@ -30,7 +29,7 @@ import org.oscim.utils.GlUtils;
|
||||
public class LineTexRenderer {
|
||||
private final static String TAG = LineTexRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
// factor to normalize extrusion vector and scale to coord scale
|
||||
private final static float COORD_SCALE_BY_DIR_SCALE =
|
||||
@ -76,18 +75,17 @@ public class LineTexRenderer {
|
||||
int[] vboIds = GlUtils.glGenBuffers(1);
|
||||
mVertexFlipID = vboIds[0];
|
||||
|
||||
// 0, 1, 0, 1, 0, ...
|
||||
byte[] flip = new byte[GLRenderer.maxQuads * 4];
|
||||
// bytes: 0, 1, 0, 1, 0, ...
|
||||
short[] flip = new short[GLRenderer.maxQuads * 2];
|
||||
for (int i = 0; i < flip.length; i++)
|
||||
flip[i] = (byte) (i % 2);
|
||||
flip[i] = 1;
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(flip.length)
|
||||
.order(ByteOrder.nativeOrder());
|
||||
ShortBuffer buf = GLRenderer.getShortBuffer(flip.length);
|
||||
|
||||
buf.put(flip);
|
||||
buf.flip();
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, mVertexFlipID);
|
||||
GL.glBufferData(GL20.GL_ARRAY_BUFFER, flip.length, buf,
|
||||
GL.glBufferData(GL20.GL_ARRAY_BUFFER, flip.length * 2, buf,
|
||||
GL20.GL_STATIC_DRAW);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
@ -230,7 +228,7 @@ public class LineTexRenderer {
|
||||
}
|
||||
|
||||
final static String vertexShader = ""
|
||||
//+ "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform mat4 u_mvp;"
|
||||
+ "uniform vec4 u_color;"
|
||||
+ "uniform float u_pscale;"
|
||||
@ -258,7 +256,7 @@ public class LineTexRenderer {
|
||||
//*
|
||||
final static String fragmentShader = ""
|
||||
+ "#extension GL_OES_standard_derivatives : enable\n"
|
||||
//+ " precision mediump float;"
|
||||
+ " precision mediump float;"
|
||||
+ " uniform vec4 u_color;"
|
||||
+ " uniform vec4 u_bgcolor;"
|
||||
+ " uniform float u_pwidth;"
|
||||
|
||||
@ -20,6 +20,7 @@ import java.nio.FloatBuffer;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
@ -35,7 +36,7 @@ import org.oscim.utils.Matrix4;
|
||||
public final class PolygonRenderer {
|
||||
private static final String TAG = PolygonRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static GL20 GL;
|
||||
|
||||
private static final int POLYGON_VERTICES_DATA_POS_OFFSET = 0;
|
||||
private static final int STENCIL_BITS = 8;
|
||||
@ -63,6 +64,8 @@ public final class PolygonRenderer {
|
||||
private static int mTexGrass;
|
||||
|
||||
static boolean init() {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
for (int i = 0; i < numShaders; i++) {
|
||||
|
||||
// Set up the program for rendering polygons
|
||||
@ -80,7 +83,7 @@ public final class PolygonRenderer {
|
||||
}
|
||||
|
||||
if (polygonProgram[i] == 0) {
|
||||
// Log.e(TAG, "Could not create polygon program.");
|
||||
Log.e(TAG, "Could not create polygon program.");
|
||||
return false;
|
||||
}
|
||||
hPolygonMatrix[i] = GL.glGetUniformLocation(polygonProgram[i], "u_mvp");
|
||||
@ -427,7 +430,7 @@ public final class PolygonRenderer {
|
||||
}
|
||||
|
||||
private final static String polygonVertexShader = ""
|
||||
//+ "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform mat4 u_mvp;"
|
||||
+ "attribute vec4 a_pos;"
|
||||
+ "void main() {"
|
||||
@ -435,14 +438,14 @@ public final class PolygonRenderer {
|
||||
+ "}";
|
||||
|
||||
private final static String polygonFragmentShader = ""
|
||||
//+ "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform vec4 u_color;"
|
||||
+ "void main() {"
|
||||
+ " gl_FragColor = u_color;"
|
||||
+ "}";
|
||||
|
||||
private final static String polygonVertexShaderZ = ""
|
||||
//+ "precision highp float;"
|
||||
+ "precision highp float;"
|
||||
+ "uniform mat4 u_mvp;"
|
||||
+ "attribute vec4 a_pos;"
|
||||
+ "varying float z;"
|
||||
@ -451,7 +454,7 @@ public final class PolygonRenderer {
|
||||
+ " z = gl_Position.z;"
|
||||
+ "}";
|
||||
private final static String polygonFragmentShaderZ = ""
|
||||
//+ "precision highp float;"
|
||||
+ "precision highp float;"
|
||||
+ "uniform vec4 u_color;"
|
||||
+ "varying float z;"
|
||||
+ "void main() {"
|
||||
@ -466,7 +469,7 @@ public final class PolygonRenderer {
|
||||
+ "}";
|
||||
|
||||
private final static String textureVertexShader = ""
|
||||
//+ "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform mat4 u_mvp;"
|
||||
+ "uniform vec2 u_scale;"
|
||||
+ "attribute vec4 a_pos;"
|
||||
@ -479,7 +482,7 @@ public final class PolygonRenderer {
|
||||
+ "}";
|
||||
|
||||
private final static String textureFragmentShader = ""
|
||||
//+ "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform vec4 u_color;"
|
||||
+ "uniform sampler2D tex;"
|
||||
+ "uniform vec2 u_scale;"
|
||||
|
||||
@ -30,7 +30,7 @@ import org.oscim.utils.pool.SyncPool;
|
||||
|
||||
public class TextureItem extends Inlist<TextureItem> {
|
||||
private final static String TAG = TextureItem.class.getName();
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
// texture ID
|
||||
public int id;
|
||||
@ -254,13 +254,14 @@ public class TextureItem extends Inlist<TextureItem> {
|
||||
mBitmaps.clear();
|
||||
mTextures.clear();
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Bitmap bitmap = CanvasAdapter.g.getBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 0);
|
||||
// Bitmap bitmap = Bitmap.createBitmap(
|
||||
// TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
||||
// Bitmap.Config.ARGB_8888);
|
||||
mBitmaps.add(bitmap);
|
||||
}
|
||||
// for (int i = 0; i < 4; i++) {
|
||||
// Bitmap bitmap = CanvasAdapter.g.getBitmap(TEXTURE_WIDTH,
|
||||
// TEXTURE_HEIGHT, 0);
|
||||
// // Bitmap bitmap = Bitmap.createBitmap(
|
||||
// // TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
||||
// // Bitmap.Config.ARGB_8888);
|
||||
// mBitmaps.add(bitmap);
|
||||
// }
|
||||
|
||||
// mBitmapFormat = GLUtils.getInternalFormat(mBitmaps.get(0));
|
||||
// mBitmapType = GLUtils.getType(mBitmaps.get(0));
|
||||
|
||||
@ -27,7 +27,7 @@ import org.oscim.utils.GlUtils;
|
||||
public final class TextureRenderer {
|
||||
//private final static String TAG = TextureRenderer.class.getName();
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
public final static boolean debug = false;
|
||||
|
||||
@ -119,7 +119,7 @@ public final class TextureRenderer {
|
||||
private final static double COORD_DIV = 1.0 / GLRenderer.COORD_SCALE;
|
||||
|
||||
private final static String textVertexShader = ""
|
||||
// + "precision mediump float; "
|
||||
+ "precision mediump float; "
|
||||
+ "attribute vec4 vertex;"
|
||||
+ "attribute vec2 tex_coord;"
|
||||
+ "uniform mat4 u_mv;"
|
||||
@ -143,7 +143,7 @@ public final class TextureRenderer {
|
||||
+ "}";
|
||||
|
||||
private final static String textFragmentShader = ""
|
||||
// + "precision mediump float;"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform sampler2D tex;"
|
||||
+ "varying vec2 tex_c;"
|
||||
+ "void main() {"
|
||||
|
||||
@ -28,13 +28,14 @@ import org.oscim.renderer.GLRenderer;
|
||||
* Utility functions
|
||||
*/
|
||||
public class GlUtils {
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static GL20 GL = GLAdapter.get();
|
||||
|
||||
// public static native void setColor(int location, int color, float alpha);
|
||||
// public static native void setColorBlend(int location, int color1, int
|
||||
// color2, float mix);
|
||||
|
||||
public static void setColor(int location, int color, float alpha) {
|
||||
GL = GLAdapter.get();
|
||||
if (alpha >= 1)
|
||||
alpha = ((color >>> 24) & 0xff) / 255f;
|
||||
else if (alpha < 0)
|
||||
@ -60,7 +61,7 @@ public class GlUtils {
|
||||
public static void setColorBlend(int location, int color1, int color2, float mix) {
|
||||
float a1 = (((color1 >>> 24) & 0xff) / 255f) * (1 - mix);
|
||||
float a2 = (((color2 >>> 24) & 0xff) / 255f) * mix;
|
||||
|
||||
GL = GLAdapter.get();
|
||||
GL.glUniform4f
|
||||
(location,
|
||||
((((color1 >>> 16) & 0xff) / 255f) * a1 + (((color2 >>> 16) & 0xff) / 255f) * a2),
|
||||
@ -72,6 +73,7 @@ public class GlUtils {
|
||||
private static String TAG = "GlUtils";
|
||||
|
||||
public static void setTextureParameter(int min_filter, int mag_filter, int wrap_s, int wrap_t) {
|
||||
GL = GLAdapter.get();
|
||||
GL.glTexParameterf(GL20.GL_TEXTURE_2D,
|
||||
GL20.GL_TEXTURE_MIN_FILTER,
|
||||
min_filter);
|
||||
@ -111,7 +113,7 @@ public class GlUtils {
|
||||
public static int loadTexture(byte[] pixel, int width, int height, int format,
|
||||
int min_filter, int mag_filter, int wrap_s, int wrap_t) {
|
||||
int[] textureIds = GlUtils.glGenTextures(1);
|
||||
|
||||
GL = GLAdapter.get();
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, textureIds[0]);
|
||||
|
||||
setTextureParameter(min_filter, mag_filter, wrap_s, wrap_t);
|
||||
@ -119,15 +121,17 @@ public class GlUtils {
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(width * height).order(ByteOrder.nativeOrder());
|
||||
buf.put(pixel);
|
||||
buf.position(0);
|
||||
|
||||
IntBuffer intBuf = buf.asIntBuffer();
|
||||
GL.glTexImage2D(GL20.GL_TEXTURE_2D, 0, format, width, height, 0, format,
|
||||
GL20.GL_UNSIGNED_BYTE, buf);
|
||||
GL20.GL_UNSIGNED_BYTE, intBuf);
|
||||
|
||||
GL.glBindTexture(GL20.GL_TEXTURE_2D, 0);
|
||||
return textureIds[0];
|
||||
}
|
||||
|
||||
public static int loadStippleTexture(byte[] stipple) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
int sum = 0;
|
||||
for (byte flip : stipple)
|
||||
sum += flip;
|
||||
@ -166,6 +170,7 @@ public class GlUtils {
|
||||
* @return gl identifier
|
||||
*/
|
||||
public static int loadShader(int shaderType, String source) {
|
||||
|
||||
int shader = GL.glCreateShader(shaderType);
|
||||
if (shader != 0) {
|
||||
GL.glShaderSource(shader, source);
|
||||
@ -173,6 +178,7 @@ public class GlUtils {
|
||||
IntBuffer compiled = GLRenderer.getIntBuffer(1);
|
||||
|
||||
GL.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, compiled);
|
||||
compiled.position(0);
|
||||
if (compiled.get() == 0) {
|
||||
Log.e(TAG, "Could not compile shader " + shaderType + ":");
|
||||
Log.e(TAG, GL.glGetShaderInfoLog(shader));
|
||||
@ -191,6 +197,8 @@ public class GlUtils {
|
||||
* @return gl identifier
|
||||
*/
|
||||
public static int createProgram(String vertexSource, String fragmentSource) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
int vertexShader = loadShader(GL20.GL_VERTEX_SHADER, vertexSource);
|
||||
if (vertexShader == 0) {
|
||||
return 0;
|
||||
@ -211,6 +219,7 @@ public class GlUtils {
|
||||
GL.glLinkProgram(program);
|
||||
IntBuffer linkStatus = GLRenderer.getIntBuffer(1);
|
||||
GL.glGetProgramiv(program, GL20.GL_LINK_STATUS, linkStatus);
|
||||
linkStatus.position(0);
|
||||
if (linkStatus.get() != GL20.GL_TRUE) {
|
||||
Log.e(TAG, "Could not link program: ");
|
||||
Log.e(TAG, GL.glGetProgramInfoLog(program));
|
||||
@ -226,17 +235,21 @@ public class GlUtils {
|
||||
* ...
|
||||
*/
|
||||
public static void checkGlError(String op) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
int error;
|
||||
while ((error = GL.glGetError()) != GL20.GL_NO_ERROR) {
|
||||
while ((error = GL.glGetError()) != 0) { //GL20.GL_NO_ERROR) {
|
||||
Log.e(TAG, op + ": glError " + error);
|
||||
// throw new RuntimeException(op + ": glError " + error);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkGlOutOfMemory(String op) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
int error;
|
||||
boolean oom = false;
|
||||
while ((error = GL.glGetError()) != GL20.GL_NO_ERROR) {
|
||||
while ((error = GL.glGetError()) != 0) {// GL20.GL_NO_ERROR) {
|
||||
Log.e(TAG, op + ": glError " + error);
|
||||
// throw new RuntimeException(op + ": glError " + error);
|
||||
if (error == 1285)
|
||||
@ -261,6 +274,8 @@ public class GlUtils {
|
||||
// }
|
||||
|
||||
public static void setColor(int handle, float[] c, float alpha) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
if (alpha >= 1) {
|
||||
GL.glUniform4f(handle, c[0], c[1], c[2], c[3]);
|
||||
} else {
|
||||
@ -318,6 +333,8 @@ public class GlUtils {
|
||||
}
|
||||
|
||||
public static void glUniform4fv(int location, int count, float[] val) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
FloatBuffer buf = GLRenderer.getFloatBuffer(count * 4);
|
||||
buf.put(val);
|
||||
buf.flip();
|
||||
@ -325,6 +342,8 @@ public class GlUtils {
|
||||
}
|
||||
|
||||
public static int[] glGenBuffers(int num) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
IntBuffer buf = GLRenderer.getIntBuffer(num);
|
||||
buf.position(0);
|
||||
buf.limit(num);
|
||||
@ -337,6 +356,8 @@ public class GlUtils {
|
||||
}
|
||||
|
||||
public static void glDeleteBuffers(int num, int[] ids) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
IntBuffer buf = GLRenderer.getIntBuffer(num);
|
||||
buf.put(ids, 0, num);
|
||||
buf.position(0);
|
||||
@ -344,6 +365,8 @@ public class GlUtils {
|
||||
}
|
||||
|
||||
public static int[] glGenTextures(int num) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
IntBuffer buf = GLRenderer.getIntBuffer(num);
|
||||
buf.position(0);
|
||||
buf.limit(num);
|
||||
@ -356,6 +379,8 @@ public class GlUtils {
|
||||
}
|
||||
|
||||
public static void glDeleteTextures(int num, int[] ids) {
|
||||
GL = GLAdapter.get();
|
||||
|
||||
IntBuffer buf = GLRenderer.getIntBuffer(num);
|
||||
buf.put(ids, 0, num);
|
||||
buf.position(0);
|
||||
|
||||
@ -24,7 +24,7 @@ import org.oscim.backend.GLAdapter;
|
||||
|
||||
public class Matrix4 {
|
||||
|
||||
private static final GL20 GL = GLAdapter.INSTANCE;
|
||||
private static final GL20 GL = GLAdapter.get();
|
||||
|
||||
private final static String TAG = Matrix4.class.getName();
|
||||
private final static boolean dbg = false;
|
||||
|
||||
@ -43,6 +43,13 @@ public abstract class PausableThread extends Thread {
|
||||
synchronized (this) {
|
||||
super.interrupt();
|
||||
}
|
||||
|
||||
try {
|
||||
this.join(10000);
|
||||
} catch (InterruptedException e) {
|
||||
// restore the interrupted status
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user