|
@@ -2,6 +2,12 @@ package hxd.res;
|
|
|
|
|
|
class Image extends Resource {
|
|
|
|
|
|
+ /**
|
|
|
+ Specify if we will automatically convert non-power-of-two textures to power-of-two.
|
|
|
+ **/
|
|
|
+ public static var ALLOW_NPOT = #if flash11_8 true #else false #end;
|
|
|
+ public static var DEFAULT_FILTER : h3d.mat.Data.Filter = Linear;
|
|
|
+
|
|
|
var tex : h3d.mat.Texture;
|
|
|
var inf : { width : Int, height : Int, isPNG : Bool };
|
|
|
|
|
@@ -89,6 +95,8 @@ class Image extends Resource {
|
|
|
// immediately loading the PNG is faster than going through loadBitmap
|
|
|
tex.alloc();
|
|
|
var pixels = getPixels();
|
|
|
+ if( pixels.width != tex.width || pixels.height != tex.height )
|
|
|
+ pixels.makeSquare();
|
|
|
tex.uploadPixels(pixels);
|
|
|
pixels.dispose();
|
|
|
tex.realloc = loadTexture;
|
|
@@ -101,7 +109,13 @@ class Image extends Resource {
|
|
|
// use native decoding
|
|
|
entry.loadBitmap(function(bmp) {
|
|
|
tex.alloc();
|
|
|
- tex.uploadBitmap(bmp);
|
|
|
+ if( bmp.width != tex.width || bmp.height != tex.height ) {
|
|
|
+ var pixels = bmp.getPixels();
|
|
|
+ pixels.makeSquare();
|
|
|
+ tex.uploadPixels(pixels);
|
|
|
+ pixels.dispose();
|
|
|
+ } else
|
|
|
+ tex.uploadBitmap(bmp);
|
|
|
bmp.dispose();
|
|
|
tex.realloc = loadTexture;
|
|
|
});
|
|
@@ -112,7 +126,16 @@ class Image extends Resource {
|
|
|
if( tex != null )
|
|
|
return tex;
|
|
|
getSize();
|
|
|
- tex = new h3d.mat.Texture(inf.width, inf.height, [NoAlloc]);
|
|
|
+ var width = inf.width, height = inf.height;
|
|
|
+ if( !ALLOW_NPOT ) {
|
|
|
+ var tw = 1, th = 1;
|
|
|
+ while( tw < width ) tw <<= 1;
|
|
|
+ while( th < height ) th <<= 1;
|
|
|
+ width = tw;
|
|
|
+ height = th;
|
|
|
+ }
|
|
|
+ tex = new h3d.mat.Texture(width, height, [NoAlloc]);
|
|
|
+ tex.filter = DEFAULT_FILTER;
|
|
|
tex.setName(entry.path);
|
|
|
loadTexture();
|
|
|
return tex;
|