|
@@ -5,7 +5,7 @@ import h3d.mat.Data;
|
|
|
class Texture {
|
|
|
|
|
|
static var UID = 0;
|
|
|
-
|
|
|
+
|
|
|
var t : h3d.impl.Driver.Texture;
|
|
|
var mem : h3d.impl.MemoryManager;
|
|
|
#if debug
|
|
@@ -28,7 +28,7 @@ class Texture {
|
|
|
it's been free because of lack of memory.
|
|
|
**/
|
|
|
public var realloc : Void -> Void;
|
|
|
-
|
|
|
+
|
|
|
public function new(w, h, ?flags : Array<TextureFlags>, ?allocPos : h3d.impl.AllocPos ) {
|
|
|
var engine = h3d.Engine.getCurrent();
|
|
|
this.mem = engine.mem;
|
|
@@ -42,8 +42,8 @@ class Texture {
|
|
|
while( tw < w ) tw <<= 1;
|
|
|
while( th < h) th <<= 1;
|
|
|
if( tw != w || th != h )
|
|
|
- this.flags.set(IsRectangle);
|
|
|
-
|
|
|
+ this.flags.set(IsNPOT);
|
|
|
+
|
|
|
// make the texture disposable if we're out of memory
|
|
|
// this can be disabled after allocation by reseting realloc
|
|
|
if( this.flags.has(Target) ) realloc = function() { };
|
|
@@ -59,16 +59,16 @@ class Texture {
|
|
|
#end
|
|
|
alloc();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function alloc() {
|
|
|
if( t == null )
|
|
|
mem.allocTexture(this);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function toString() {
|
|
|
return name+" "+width+"x"+height;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function setName(n) {
|
|
|
name = n;
|
|
|
}
|
|
@@ -84,13 +84,13 @@ class Texture {
|
|
|
bits = (bits & ~(3 << 3)) | (Type.enumIndex(f) << 3);
|
|
|
return filter = f;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function set_wrap(w:Wrap) {
|
|
|
bits |= 0x80000;
|
|
|
bits = (bits & ~(3 << 6)) | (Type.enumIndex(w) << 6);
|
|
|
return wrap = w;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
inline function hasDefaultFlags() {
|
|
|
return bits & 0x80000 == 0;
|
|
|
}
|
|
@@ -98,21 +98,21 @@ class Texture {
|
|
|
public inline function isDisposed() {
|
|
|
return t == null && realloc == null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function resize(width, height) {
|
|
|
dispose();
|
|
|
-
|
|
|
+
|
|
|
var tw = 1, th = 1;
|
|
|
while( tw < width ) tw <<= 1;
|
|
|
while( th < height ) th <<= 1;
|
|
|
if( tw != width || th != height )
|
|
|
- this.flags.set(IsRectangle);
|
|
|
+ this.flags.set(IsNPOT);
|
|
|
else
|
|
|
- this.flags.unset(IsRectangle);
|
|
|
+ this.flags.unset(IsNPOT);
|
|
|
|
|
|
this.width = width;
|
|
|
this.height = height;
|
|
|
-
|
|
|
+
|
|
|
if( !flags.has(NoAlloc) )
|
|
|
alloc();
|
|
|
}
|
|
@@ -131,7 +131,7 @@ class Texture {
|
|
|
uploadPixels(p);
|
|
|
p.dispose();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function uploadBitmap( bmp : hxd.BitmapData, mipLevel = 0, side = 0 ) {
|
|
|
alloc();
|
|
|
mem.driver.uploadTextureBitmap(this, bmp, mipLevel, side);
|
|
@@ -150,19 +150,19 @@ class Texture {
|
|
|
#end
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static function fromBitmap( bmp : hxd.BitmapData, ?allocPos : h3d.impl.AllocPos ) {
|
|
|
var t = new Texture(bmp.width, bmp.height, allocPos);
|
|
|
t.uploadBitmap(bmp);
|
|
|
return t;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static function fromPixels( pixels : hxd.Pixels, ?allocPos : h3d.impl.AllocPos ) {
|
|
|
var t = new Texture(pixels.width, pixels.height, allocPos);
|
|
|
t.uploadPixels(pixels);
|
|
|
return t;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
static var COLOR_CACHE = new Map<Int,h3d.mat.Texture>();
|
|
|
/**
|
|
|
Creates a 1x1 texture using the ARGB color passed as parameter.
|