wip: Bucket API
This commit is contained in:
parent
9d86c6306d
commit
b0ee833301
@ -16,9 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.renderer.bucket;
|
package org.oscim.renderer.bucket;
|
||||||
|
|
||||||
|
import static org.oscim.backend.GL20.GL_SHORT;
|
||||||
|
import static org.oscim.backend.GL20.GL_TRIANGLES;
|
||||||
|
import static org.oscim.backend.GL20.GL_UNSIGNED_SHORT;
|
||||||
|
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
|
||||||
import org.oscim.backend.canvas.Bitmap;
|
import org.oscim.backend.canvas.Bitmap;
|
||||||
import org.oscim.renderer.GLShader;
|
import org.oscim.renderer.GLShader;
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
@ -218,17 +221,17 @@ public class BitmapBucket extends TextureBucket {
|
|||||||
int off = (t.offset + i) * 8 + tb.vertexOffset;
|
int off = (t.offset + i) * 8 + tb.vertexOffset;
|
||||||
|
|
||||||
GL.glVertexAttribPointer(s.aPos, 2,
|
GL.glVertexAttribPointer(s.aPos, 2,
|
||||||
GL20.GL_SHORT, false, 12, off);
|
GL_SHORT, false, 12, off);
|
||||||
|
|
||||||
GL.glVertexAttribPointer(s.aTexCoord, 2,
|
GL.glVertexAttribPointer(s.aTexCoord, 2,
|
||||||
GL20.GL_SHORT, false, 12, off + 8);
|
GL_SHORT, false, 12, off + 8);
|
||||||
|
|
||||||
int numIndices = t.indices - i;
|
int numIndices = t.indices - i;
|
||||||
if (numIndices > maxIndices)
|
if (numIndices > maxIndices)
|
||||||
numIndices = maxIndices;
|
numIndices = maxIndices;
|
||||||
|
|
||||||
GL.glDrawElements(GL20.GL_TRIANGLES, numIndices,
|
GL.glDrawElements(GL_TRIANGLES, numIndices,
|
||||||
GL20.GL_UNSIGNED_SHORT, 0);
|
GL_UNSIGNED_SHORT, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class ExtrusionBucket extends RenderBucket {
|
|||||||
* ExtrusionLayer for polygon geometries.
|
* ExtrusionLayer for polygon geometries.
|
||||||
*/
|
*/
|
||||||
public ExtrusionBucket(int level, float groundResolution, float[] colors) {
|
public ExtrusionBucket(int level, float groundResolution, float[] colors) {
|
||||||
super(RenderBucket.EXTRUSION);
|
super(RenderBucket.EXTRUSION, true, false);
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.colors = colors;
|
this.colors = colors;
|
||||||
this.color = 0;
|
this.color = 0;
|
||||||
@ -88,7 +88,7 @@ public class ExtrusionBucket extends RenderBucket {
|
|||||||
* ExtrusionLayer for triangle geometries.
|
* ExtrusionLayer for triangle geometries.
|
||||||
*/
|
*/
|
||||||
public ExtrusionBucket(int level, float groundResolution, int color) {
|
public ExtrusionBucket(int level, float groundResolution, int color) {
|
||||||
super(RenderBucket.EXTRUSION);
|
super(RenderBucket.EXTRUSION, true, false);
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public class HairLineBucket extends RenderBucket {
|
|||||||
public LineStyle line;
|
public LineStyle line;
|
||||||
|
|
||||||
public HairLineBucket(int level) {
|
public HairLineBucket(int level) {
|
||||||
super(RenderBucket.HAIRLINE);
|
super(RenderBucket.HAIRLINE, true, false);
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.renderer.bucket;
|
package org.oscim.renderer.bucket;
|
||||||
|
|
||||||
|
import static org.oscim.backend.GL20.GL_SHORT;
|
||||||
|
import static org.oscim.backend.GL20.GL_TRIANGLE_STRIP;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
import org.oscim.backend.GL20;
|
||||||
import org.oscim.backend.GLAdapter;
|
import org.oscim.backend.GLAdapter;
|
||||||
import org.oscim.backend.canvas.Paint.Cap;
|
import org.oscim.backend.canvas.Paint.Cap;
|
||||||
@ -71,7 +74,7 @@ public final class LineBucket extends RenderBucket {
|
|||||||
private int tmin = Integer.MIN_VALUE, tmax = Integer.MAX_VALUE;
|
private int tmin = Integer.MIN_VALUE, tmax = Integer.MAX_VALUE;
|
||||||
|
|
||||||
public LineBucket(int layer) {
|
public LineBucket(int layer) {
|
||||||
super(RenderBucket.LINE);
|
super(RenderBucket.LINE, false, false);
|
||||||
this.level = layer;
|
this.level = layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,8 +593,8 @@ public final class LineBucket extends RenderBucket {
|
|||||||
int uLineWidth = s.uWidth;
|
int uLineWidth = s.uWidth;
|
||||||
int uLineHeight = s.uHeight;
|
int uLineHeight = s.uHeight;
|
||||||
|
|
||||||
GL.glVertexAttribPointer(s.aPos, 4, GL20.GL_SHORT,
|
GL.glVertexAttribPointer(s.aPos, 4, GL_SHORT, false, 0,
|
||||||
false, 0, buckets.offset[LINE]);
|
buckets.offset[LINE]);
|
||||||
|
|
||||||
v.mvp.setAsUniform(s.uMVP);
|
v.mvp.setAsUniform(s.uMVP);
|
||||||
|
|
||||||
@ -680,7 +683,7 @@ public final class LineBucket extends RenderBucket {
|
|||||||
GL.glUniform1f(uLineMode, capMode);
|
GL.glUniform1f(uLineMode, capMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP,
|
GL.glDrawArrays(GL_TRIANGLE_STRIP,
|
||||||
b.vertexOffset, b.numVertices);
|
b.vertexOffset, b.numVertices);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -727,7 +730,7 @@ public final class LineBucket extends RenderBucket {
|
|||||||
GL.glUniform1f(uLineMode, capMode);
|
GL.glUniform1f(uLineMode, capMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP,
|
GL.glDrawArrays(GL_TRIANGLE_STRIP,
|
||||||
ref.vertexOffset, ref.numVertices);
|
ref.vertexOffset, ref.numVertices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public final class LineTexBucket extends RenderBucket {
|
|||||||
protected boolean mRandomizeOffset = true;
|
protected boolean mRandomizeOffset = true;
|
||||||
|
|
||||||
LineTexBucket(int level) {
|
LineTexBucket(int level) {
|
||||||
super(TEXLINE);
|
super(TEXLINE, false, true);
|
||||||
|
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.evenSegment = true;
|
this.evenSegment = true;
|
||||||
|
@ -49,7 +49,7 @@ public class MeshBucket extends RenderBucket {
|
|||||||
private int numPoints;
|
private int numPoints;
|
||||||
|
|
||||||
public MeshBucket(int level) {
|
public MeshBucket(int level) {
|
||||||
super(RenderBucket.MESH);
|
super(RenderBucket.MESH, true, false);
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public final class PolygonBucket extends RenderBucket {
|
|||||||
public AreaStyle area;
|
public AreaStyle area;
|
||||||
|
|
||||||
PolygonBucket(int layer) {
|
PolygonBucket(int layer) {
|
||||||
super(RenderBucket.POLYGON);
|
super(RenderBucket.POLYGON, true, false);
|
||||||
level = layer;
|
level = layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ public abstract class RenderBucket extends Inlist<RenderBucket> {
|
|||||||
public static final int HAIRLINE = 5;
|
public static final int HAIRLINE = 5;
|
||||||
public static final int SYMBOL = 6;
|
public static final int SYMBOL = 6;
|
||||||
public static final int BITMAP = 7;
|
public static final int BITMAP = 7;
|
||||||
|
public static final int SDF = 8;
|
||||||
|
|
||||||
public final int type;
|
public final int type;
|
||||||
|
|
||||||
@ -43,11 +44,21 @@ public abstract class RenderBucket extends Inlist<RenderBucket> {
|
|||||||
protected int numIndices;
|
protected int numIndices;
|
||||||
|
|
||||||
/** Temporary list of vertex data. */
|
/** Temporary list of vertex data. */
|
||||||
protected final VertexData vertexItems = new VertexData();
|
protected final VertexData vertexItems;
|
||||||
protected final VertexData indiceItems = new VertexData();
|
protected final VertexData indiceItems;
|
||||||
|
|
||||||
protected RenderBucket(int type) {
|
final static VertexData EMPTY = new VertexData();
|
||||||
|
final boolean quads;
|
||||||
|
|
||||||
|
protected RenderBucket(int type, boolean indexed, boolean quads) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
vertexItems = new VertexData();
|
||||||
|
if (indexed)
|
||||||
|
indiceItems = new VertexData();
|
||||||
|
else
|
||||||
|
indiceItems = EMPTY;
|
||||||
|
|
||||||
|
this.quads = quads;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Clear all resources. */
|
/** Clear all resources. */
|
||||||
@ -66,11 +77,6 @@ public abstract class RenderBucket extends Inlist<RenderBucket> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /** Compile vertex data to vbo. */
|
|
||||||
// protected void compile(ShortBuffer sbuf) {
|
|
||||||
// compileVertexItems(sbuf);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For line- and polygon-buckets this is the offset
|
* For line- and polygon-buckets this is the offset
|
||||||
* of VERTICES in its bucket.vbo.
|
* of VERTICES in its bucket.vbo.
|
||||||
@ -98,6 +104,7 @@ public abstract class RenderBucket extends Inlist<RenderBucket> {
|
|||||||
|
|
||||||
protected void compile(ShortBuffer vboData, ShortBuffer iboData) {
|
protected void compile(ShortBuffer vboData, ShortBuffer iboData) {
|
||||||
compileVertexItems(vboData);
|
compileVertexItems(vboData);
|
||||||
|
if (iboData != null)
|
||||||
compileIndiceItems(iboData);
|
compileIndiceItems(iboData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +116,7 @@ public abstract class RenderBucket extends Inlist<RenderBucket> {
|
|||||||
|
|
||||||
protected void compileIndiceItems(ShortBuffer iboData) {
|
protected void compileIndiceItems(ShortBuffer iboData) {
|
||||||
/* keep offset of layer data in vbo */
|
/* keep offset of layer data in vbo */
|
||||||
if (indiceItems.empty())
|
if (indiceItems == null || indiceItems.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
indiceOffset = iboData.position() * 2; // needs byte offset...
|
indiceOffset = iboData.position() * 2; // needs byte offset...
|
||||||
|
@ -16,11 +16,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.renderer.bucket;
|
package org.oscim.renderer.bucket;
|
||||||
|
|
||||||
|
import static org.oscim.backend.GL20.GL_SHORT;
|
||||||
|
import static org.oscim.backend.GL20.GL_TRIANGLES;
|
||||||
|
import static org.oscim.backend.GL20.GL_UNSIGNED_SHORT;
|
||||||
import static org.oscim.renderer.MapRenderer.COORD_SCALE;
|
import static org.oscim.renderer.MapRenderer.COORD_SCALE;
|
||||||
|
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
|
||||||
import org.oscim.renderer.GLShader;
|
import org.oscim.renderer.GLShader;
|
||||||
import org.oscim.renderer.GLState;
|
import org.oscim.renderer.GLState;
|
||||||
import org.oscim.renderer.GLViewport;
|
import org.oscim.renderer.GLViewport;
|
||||||
@ -29,7 +31,7 @@ import org.oscim.renderer.bucket.TextureItem.TexturePool;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public abstract class TextureBucket extends RenderBucket {
|
public class TextureBucket extends RenderBucket {
|
||||||
|
|
||||||
static final Logger log = LoggerFactory.getLogger(TextureBucket.class);
|
static final Logger log = LoggerFactory.getLogger(TextureBucket.class);
|
||||||
|
|
||||||
@ -46,12 +48,12 @@ public abstract class TextureBucket extends RenderBucket {
|
|||||||
TEXTURE_WIDTH,
|
TEXTURE_WIDTH,
|
||||||
TEXTURE_HEIGHT);
|
TEXTURE_HEIGHT);
|
||||||
|
|
||||||
protected TextureBucket(int type) {
|
public TextureBucket(int type) {
|
||||||
super(type);
|
super(type, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** holds textures and offset in vbo */
|
/** holds textures and offset in vbo */
|
||||||
protected TextureItem textures;
|
public TextureItem textures;
|
||||||
|
|
||||||
/** scale mode */
|
/** scale mode */
|
||||||
public boolean fixed;
|
public boolean fixed;
|
||||||
@ -78,6 +80,7 @@ public abstract class TextureBucket extends RenderBucket {
|
|||||||
Shader() {
|
Shader() {
|
||||||
if (!create("texture_layer"))
|
if (!create("texture_layer"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uMV = getUniform("u_mv");
|
uMV = getUniform("u_mv");
|
||||||
uProj = getUniform("u_proj");
|
uProj = getUniform("u_proj");
|
||||||
uScale = getUniform("u_scale");
|
uScale = getUniform("u_scale");
|
||||||
@ -96,9 +99,9 @@ public abstract class TextureBucket extends RenderBucket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Renderer {
|
static Shader shader;
|
||||||
|
|
||||||
private static Shader shader;
|
public static final class Renderer {
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
shader = new Shader();
|
shader = new Shader();
|
||||||
@ -135,21 +138,11 @@ public abstract class TextureBucket extends RenderBucket {
|
|||||||
* / 6(indices) == 8) */
|
* / 6(indices) == 8) */
|
||||||
int off = (t.offset + i) * 8 + tb.vertexOffset;
|
int off = (t.offset + i) * 8 + tb.vertexOffset;
|
||||||
|
|
||||||
GL.glVertexAttribPointer(shader.aPos, 4,
|
|
||||||
GL20.GL_SHORT,
|
|
||||||
false, 12, off);
|
|
||||||
|
|
||||||
GL.glVertexAttribPointer(shader.aTexCoord, 2,
|
|
||||||
GL20.GL_SHORT,
|
|
||||||
false, 12, off + 8);
|
|
||||||
|
|
||||||
int numIndices = t.indices - i;
|
int numIndices = t.indices - i;
|
||||||
if (numIndices > maxIndices)
|
if (numIndices > maxIndices)
|
||||||
numIndices = maxIndices;
|
numIndices = maxIndices;
|
||||||
|
|
||||||
GL.glDrawElements(GL20.GL_TRIANGLES, numIndices,
|
tb.render(off, numIndices);
|
||||||
GL20.GL_UNSIGNED_SHORT, 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,4 +155,15 @@ public abstract class TextureBucket extends RenderBucket {
|
|||||||
public TextureItem getTextures() {
|
public TextureItem getTextures() {
|
||||||
return textures;
|
return textures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void render(int offset, int numIndices) {
|
||||||
|
GL.glVertexAttribPointer(shader.aPos, 4, GL_SHORT,
|
||||||
|
false, 12, offset);
|
||||||
|
|
||||||
|
GL.glVertexAttribPointer(shader.aTexCoord, 2, GL_SHORT,
|
||||||
|
false, 12, offset + 8);
|
||||||
|
|
||||||
|
GL.glDrawElements(GL_TRIANGLES, numIndices,
|
||||||
|
GL_UNSIGNED_SHORT, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user