share GL reference in RenderElement

This commit is contained in:
Hannes Janetzek 2013-09-25 02:31:27 +02:00
parent 47b8a379a4
commit 39c0fcafea
9 changed files with 37 additions and 32 deletions

View File

@ -27,6 +27,7 @@ import org.oscim.renderer.MapRenderer.Matrices;
* Renderer for a single bitmap, width and height must be power of 2.
*/
public class BitmapLayer extends TextureLayer {
// private final static String TAG = BitmapLayer.class.getName();
private Bitmap mBitmap;
private final boolean mReuseBitmap;
@ -37,7 +38,8 @@ public class BitmapLayer extends TextureLayer {
* it is compiled to texture.
*/
public BitmapLayer(boolean reuseBitmap) {
type = RenderElement.BITMAP;
super(RenderElement.BITMAP);
mReuseBitmap = reuseBitmap;
mVertices = new short[24];
@ -151,7 +153,6 @@ public class BitmapLayer extends TextureLayer {
public static final class Renderer {
//private final static String TAG = BitmapRenderer.class.getName();
private static GL20 GL;
public final static boolean debug = true;
@ -169,9 +170,7 @@ public class BitmapLayer extends TextureLayer {
final static int VERTICES_PER_SPRITE = 4;
final static int SHORTS_PER_VERTICE = 6;
static void init(GL20 gl) {
GL = gl;
static void init() {
mTextureProgram = GLUtils.createProgram(textVertexShader,
textFragmentShader);

View File

@ -25,11 +25,13 @@ public class ElementLayers {
private final static String TAG = ElementLayers.class.getName();
public static void initRenderer(GL20 gl) {
LineLayer.Renderer.init(gl);
LineTexLayer.Renderer.init(gl);
PolygonLayer.Renderer.init(gl);
TextureLayer.Renderer.init(gl);
BitmapLayer.Renderer.init(gl);
RenderElement.GL = gl;
LineLayer.Renderer.init();
LineTexLayer.Renderer.init();
PolygonLayer.Renderer.init();
TextureLayer.Renderer.init();
BitmapLayer.Renderer.init();
TextureItem.init(gl, 0);
}

View File

@ -60,7 +60,7 @@ public class ExtrusionLayer extends RenderElement {
private final float mGroundResolution;
public ExtrusionLayer(int level, float groundResolution) {
this.type = RenderElement.EXTRUSION;
super(RenderElement.EXTRUSION);
this.level = level;
mGroundResolution = groundResolution;

View File

@ -50,8 +50,8 @@ public final class LineLayer extends RenderElement {
public boolean roundCap;
LineLayer(int layer) {
super(RenderElement.LINE);
this.level = layer;
this.type = RenderElement.LINE;
}
public void addOutline(LineLayer link) {
@ -580,8 +580,6 @@ public final class LineLayer extends RenderElement {
public static final class Renderer {
private static GL20 GL;
private static final int LINE_VERTICES_DATA_POS_OFFSET = 0;
// factor to normalize extrusion vector and scale to coord scale
@ -598,8 +596,7 @@ public final class LineLayer extends RenderElement {
private static int[] hLineMode = new int[2];
public static int mTexID;
static boolean init(GL20 gl) {
GL = gl;
static boolean init() {
lineProgram[0] = GLUtils.createProgram(lineVertexShader,
lineFragmentShader);

View File

@ -93,8 +93,9 @@ public final class LineTexLayer extends RenderElement {
private boolean evenSegment;
LineTexLayer(int layer) {
super(RenderElement.TEXLINE);
this.level = layer;
this.type = RenderElement.TEXLINE;
this.evenSegment = true;
}
@ -250,8 +251,6 @@ public final class LineTexLayer extends RenderElement {
public final static class Renderer {
private static GL20 GL;
// factor to normalize extrusion vector and scale to coord scale
private final static float COORD_SCALE_BY_DIR_SCALE =
MapRenderer.COORD_SCALE
@ -273,8 +272,7 @@ public final class LineTexLayer extends RenderElement {
private static int mVertexFlipID;
public static void init(GL20 gl) {
GL = gl;
public static void init() {
shader = GLUtils.createProgram(vertexShader, fragmentShader);
if (shader == 0) {

View File

@ -46,8 +46,9 @@ public final class PolygonLayer extends RenderElement {
public Area area;
PolygonLayer(int layer) {
this.level = layer;
this.type = RenderElement.POLYGON;
super(RenderElement.POLYGON);
level = layer;
curItem = VertexItem.pool.get();
vertexItems = curItem;
}
@ -123,7 +124,7 @@ public final class PolygonLayer extends RenderElement {
public static final class Renderer {
private static GL20 GL;
//private static GL20 GL;
private static final int POLYGON_VERTICES_DATA_POS_OFFSET = 0;
private static final int STENCIL_BITS = 8;
@ -144,8 +145,7 @@ public final class PolygonLayer extends RenderElement {
private static int[] hPolygonColor = new int[numShaders];
private static int[] hPolygonScale = new int[numShaders];
static boolean init(GL20 gl) {
GL = gl;
static boolean init() {
for (int i = 0; i < numShaders; i++) {

View File

@ -16,9 +16,12 @@ package org.oscim.renderer.elements;
import java.nio.ShortBuffer;
import org.oscim.backend.GL20;
import org.oscim.utils.pool.Inlist;
public abstract class RenderElement extends Inlist<RenderElement> {
protected static GL20 GL;
public final static byte LINE = 0;
public final static byte POLYGON = 1;
public final static byte TEXLINE = 2;
@ -26,7 +29,11 @@ public abstract class RenderElement extends Inlist<RenderElement> {
public final static byte BITMAP = 4;
public final static byte EXTRUSION = 5;
public byte type = -1;
protected RenderElement(byte type) {
this.type = type;
}
public final byte type;
// drawing order from bottom to top
int level;

View File

@ -38,7 +38,7 @@ public final class TextLayer extends TextureLayer {
}
public TextLayer() {
type = RenderElement.SYMBOL;
super(RenderElement.SYMBOL);
//mCanvas = Graphics.res.getCanvas();
mCanvas = CanvasAdapter.g.getCanvas();
fixed = true;

View File

@ -25,6 +25,11 @@ import org.oscim.renderer.MapRenderer;
import org.oscim.renderer.MapRenderer.Matrices;
public abstract class TextureLayer extends RenderElement {
protected TextureLayer(byte type) {
super(type);
}
// holds textures and offset in vbo
public TextureItem textures;
@ -87,8 +92,6 @@ public abstract class TextureLayer extends RenderElement {
public static final class Renderer {
//private final static String TAG = TextureRenderer.class.getName();
private static GL20 GL;
public final static boolean debug = false;
private static int mTextureProgram;
@ -104,8 +107,7 @@ public abstract class TextureLayer extends RenderElement {
final static int VERTICES_PER_SPRITE = 4;
final static int SHORTS_PER_VERTICE = 6;
static void init(GL20 gl) {
GL = gl;
static void init() {
mTextureProgram = GLUtils.createProgram(textVertexShader,
textFragmentShader);