diff --git a/src/org/oscim/renderer/sublayers/SpriteManager.java b/src/org/oscim/renderer/atlas/SpriteManager.java similarity index 94% rename from src/org/oscim/renderer/sublayers/SpriteManager.java rename to src/org/oscim/renderer/atlas/SpriteManager.java index baa7646b..94723c9d 100644 --- a/src/org/oscim/renderer/sublayers/SpriteManager.java +++ b/src/org/oscim/renderer/atlas/SpriteManager.java @@ -12,9 +12,10 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.sublayers; +package org.oscim.renderer.atlas; -import org.oscim.renderer.sublayers.TextureAtlas.Rect; +import org.oscim.renderer.atlas.TextureAtlas.Rect; +import org.oscim.renderer.sublayers.TextureItem; import org.oscim.utils.pool.Inlist; import android.graphics.Canvas; diff --git a/src/org/oscim/renderer/sublayers/TextureAtlas.java b/src/org/oscim/renderer/atlas/TextureAtlas.java similarity index 82% rename from src/org/oscim/renderer/sublayers/TextureAtlas.java rename to src/org/oscim/renderer/atlas/TextureAtlas.java index a0eea2bd..2ac0567a 100644 --- a/src/org/oscim/renderer/sublayers/TextureAtlas.java +++ b/src/org/oscim/renderer/atlas/TextureAtlas.java @@ -57,15 +57,18 @@ * * ============================================================================ */ -package org.oscim.renderer.sublayers; +package org.oscim.renderer.atlas; +import java.util.HashMap; + +import org.oscim.renderer.sublayers.TextureItem; import org.oscim.utils.pool.Inlist; import android.graphics.Bitmap; +import android.util.Log; public class TextureAtlas extends Inlist { - - + private final static String TAG = TextureAtlas.class.getName(); /** Allocated slots */ public Slot mSlots; @@ -83,11 +86,23 @@ public class TextureAtlas extends Inlist { /** Allocated surface size */ int mUsed; - /** Texture identity (OpenGL) */ - int id; - /** Atlas data */ - Bitmap mData; + public TextureItem texture; + + /** + * only call in GL-Thread + */ + public TextureItem compileTexture() { + if (texture != null) { + if (texture.id < 1) { + TextureItem.uploadTexture(texture); + } + return texture; + } + + Log.wtf(TAG, "Missing atlas texture"); + return null; + } public static class Slot extends Inlist { public int x, y, w; @@ -100,6 +115,13 @@ public class TextureAtlas extends Inlist { } public static class Rect extends Inlist { + public Rect(int x, int y, int w, int h) { + this.x = x; + this.y = y; + this.w = w; + this.h = h; + } + public int x, y, w, h; } @@ -110,12 +132,31 @@ public class TextureAtlas extends Inlist { mSlots = new Slot(1, 1, width - 2); } + public TextureAtlas(Bitmap bitmap) { + mDepth = 0; + texture = new TextureItem(bitmap); + mWidth = texture.width; + mHeight = texture.height; + + mRegions = new HashMap(); + } + + private HashMap mRegions; + + public void addTextureRegion(Object key, Rect r) { + + mRegions.put(key, new TextureRegion(this, r)); + + } + + public TextureRegion getTextureRegion(Object key) { + return mRegions.get(key); + } + public Rect getRegion(int width, int height) { int y, bestHeight, bestWidth; Slot slot, prev; - Rect r = new Rect(); - r.w = width; - r.h = height; + Rect r = new Rect(0, 0, width, height); bestHeight = Integer.MAX_VALUE; bestWidth = Integer.MAX_VALUE; @@ -213,4 +254,11 @@ public class TextureAtlas extends Inlist { return new TextureAtlas(width, height, depth); } + + // /// FIXME + // @Override + // protected void finalize(){ + // if (texture != null) + // TextureItem.releaseTexture(texture); + // } } diff --git a/src/org/oscim/renderer/atlas/TextureRegion.java b/src/org/oscim/renderer/atlas/TextureRegion.java new file mode 100644 index 00000000..80328e67 --- /dev/null +++ b/src/org/oscim/renderer/atlas/TextureRegion.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013 Hannes Janetzek + * + * This program is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package org.oscim.renderer.atlas; + +import org.oscim.renderer.atlas.TextureAtlas.Rect; + +public class TextureRegion { + + public TextureRegion(TextureAtlas textureAtlas, Rect r) { + this.atlas = textureAtlas; + this.rect = r; + } + + public final TextureAtlas atlas; + public final Rect rect; +} diff --git a/src/org/oscim/renderer/layers/test/AtlasRenderLayer.java b/src/org/oscim/renderer/layers/test/AtlasRenderLayer.java index b1894440..acd3faec 100644 --- a/src/org/oscim/renderer/layers/test/AtlasRenderLayer.java +++ b/src/org/oscim/renderer/layers/test/AtlasRenderLayer.java @@ -6,13 +6,13 @@ import org.oscim.core.MapPosition; import org.oscim.graphics.Color; import org.oscim.graphics.Paint.Cap; import org.oscim.renderer.GLRenderer.Matrices; +import org.oscim.renderer.atlas.TextureAtlas; +import org.oscim.renderer.atlas.TextureAtlas.Rect; +import org.oscim.renderer.atlas.TextureAtlas.Slot; import org.oscim.renderer.layers.BasicRenderLayer; import org.oscim.renderer.sublayers.LineLayer; import org.oscim.renderer.sublayers.TextItem; import org.oscim.renderer.sublayers.TextLayer; -import org.oscim.renderer.sublayers.TextureAtlas; -import org.oscim.renderer.sublayers.TextureAtlas.Rect; -import org.oscim.renderer.sublayers.TextureAtlas.Slot; import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.Text; import org.oscim.view.MapView;