move TextureAtlas, etc to 'renderer.atlas'
This commit is contained in:
parent
9e00115b06
commit
8403ab87e0
@ -12,9 +12,10 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* 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/>.
|
* 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 org.oscim.utils.pool.Inlist;
|
||||||
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@ -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 org.oscim.utils.pool.Inlist;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class TextureAtlas extends Inlist<TextureAtlas> {
|
public class TextureAtlas extends Inlist<TextureAtlas> {
|
||||||
|
private final static String TAG = TextureAtlas.class.getName();
|
||||||
|
|
||||||
|
|
||||||
/** Allocated slots */
|
/** Allocated slots */
|
||||||
public Slot mSlots;
|
public Slot mSlots;
|
||||||
@ -83,11 +86,23 @@ public class TextureAtlas extends Inlist<TextureAtlas> {
|
|||||||
/** Allocated surface size */
|
/** Allocated surface size */
|
||||||
int mUsed;
|
int mUsed;
|
||||||
|
|
||||||
/** Texture identity (OpenGL) */
|
|
||||||
int id;
|
|
||||||
|
|
||||||
/** Atlas data */
|
public TextureItem texture;
|
||||||
Bitmap mData;
|
|
||||||
|
/**
|
||||||
|
* 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 static class Slot extends Inlist<Slot> {
|
||||||
public int x, y, w;
|
public int x, y, w;
|
||||||
@ -100,6 +115,13 @@ public class TextureAtlas extends Inlist<TextureAtlas> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Rect extends Inlist<Rect> {
|
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;
|
public int x, y, w, h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,12 +132,31 @@ public class TextureAtlas extends Inlist<TextureAtlas> {
|
|||||||
mSlots = new Slot(1, 1, width - 2);
|
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) {
|
public Rect getRegion(int width, int height) {
|
||||||
int y, bestHeight, bestWidth;
|
int y, bestHeight, bestWidth;
|
||||||
Slot slot, prev;
|
Slot slot, prev;
|
||||||
Rect r = new Rect();
|
Rect r = new Rect(0, 0, width, height);
|
||||||
r.w = width;
|
|
||||||
r.h = height;
|
|
||||||
|
|
||||||
bestHeight = Integer.MAX_VALUE;
|
bestHeight = Integer.MAX_VALUE;
|
||||||
bestWidth = Integer.MAX_VALUE;
|
bestWidth = Integer.MAX_VALUE;
|
||||||
@ -213,4 +254,11 @@ public class TextureAtlas extends Inlist<TextureAtlas> {
|
|||||||
|
|
||||||
return new TextureAtlas(width, height, depth);
|
return new TextureAtlas(width, height, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /// FIXME
|
||||||
|
// @Override
|
||||||
|
// protected void finalize(){
|
||||||
|
// if (texture != null)
|
||||||
|
// TextureItem.releaseTexture(texture);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
28
src/org/oscim/renderer/atlas/TextureRegion.java
Normal file
28
src/org/oscim/renderer/atlas/TextureRegion.java
Normal 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;
|
||||||
|
}
|
||||||
@ -6,13 +6,13 @@ import org.oscim.core.MapPosition;
|
|||||||
import org.oscim.graphics.Color;
|
import org.oscim.graphics.Color;
|
||||||
import org.oscim.graphics.Paint.Cap;
|
import org.oscim.graphics.Paint.Cap;
|
||||||
import org.oscim.renderer.GLRenderer.Matrices;
|
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.layers.BasicRenderLayer;
|
||||||
import org.oscim.renderer.sublayers.LineLayer;
|
import org.oscim.renderer.sublayers.LineLayer;
|
||||||
import org.oscim.renderer.sublayers.TextItem;
|
import org.oscim.renderer.sublayers.TextItem;
|
||||||
import org.oscim.renderer.sublayers.TextLayer;
|
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.Line;
|
||||||
import org.oscim.theme.renderinstruction.Text;
|
import org.oscim.theme.renderinstruction.Text;
|
||||||
import org.oscim.view.MapView;
|
import org.oscim.view.MapView;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user