move TextureAtlas, etc to 'renderer.atlas'

This commit is contained in:
Hannes Janetzek 2013-06-21 09:36:34 +02:00
parent 9e00115b06
commit 8403ab87e0
4 changed files with 92 additions and 15 deletions

View File

@ -12,9 +12,10 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;

View File

@ -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<TextureAtlas> {
private final static String TAG = TextureAtlas.class.getName();
/** Allocated slots */
public Slot mSlots;
@ -83,11 +86,23 @@ public class TextureAtlas extends Inlist<TextureAtlas> {
/** 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<Slot> {
public int x, y, w;
@ -100,6 +115,13 @@ public class TextureAtlas extends Inlist<TextureAtlas> {
}
public static class Rect extends Inlist<Rect> {
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<TextureAtlas> {
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<Object, TextureRegion>();
}
private HashMap<Object, TextureRegion> 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<TextureAtlas> {
return new TextureAtlas(width, height, depth);
}
// /// FIXME
// @Override
// protected void finalize(){
// if (texture != null)
// TextureItem.releaseTexture(texture);
// }
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}

View File

@ -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;