|
@@ -40,12 +40,23 @@ class TextureCache {
|
|
|
position = 0;
|
|
|
}
|
|
|
|
|
|
- function lookupTarget( name, width, height, format, isCube, isMipmapped ) {
|
|
|
+ function lookupTarget( name, width, height, format, flags : Array<h3d.mat.Data.TextureFlags> ) {
|
|
|
var t = cache[position];
|
|
|
// look for a suitable candidate
|
|
|
for( i in position+1...cache.length ) {
|
|
|
var t2 = cache[i];
|
|
|
- if( t2 != null && !t2.isDisposed() && t2.width == width && t2.height == height && t2.format == format && isCube == t2.flags.has(Cube) ) {
|
|
|
+ if( t2 != null && !t2.isDisposed() && t2.width == width && t2.height == height && t2.format == format ) {
|
|
|
+ if ( flags != null ) {
|
|
|
+ var fitFlags = true;
|
|
|
+ for ( f in flags ) {
|
|
|
+ if ( !t2.flags.has(f) ) {
|
|
|
+ fitFlags = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( !fitFlags )
|
|
|
+ continue;
|
|
|
+ }
|
|
|
// swap
|
|
|
cache[position] = t2;
|
|
|
cache[i] = t;
|
|
@@ -57,9 +68,9 @@ class TextureCache {
|
|
|
t.dispose();
|
|
|
t = null;
|
|
|
}
|
|
|
- var flags : Array<h3d.mat.Data.TextureFlags> = [Target];
|
|
|
- if( isCube ) flags.push(Cube);
|
|
|
- if( isMipmapped ) flags.push(MipMapped);
|
|
|
+ if ( flags == null ) flags = [];
|
|
|
+ if ( !flags.contains(Target) )
|
|
|
+ flags.push(Target);
|
|
|
var newt = new h3d.mat.Texture(width, height, flags, format);
|
|
|
// make the texture disposable if we're out of memory
|
|
|
newt.realloc = function() {};
|
|
@@ -70,11 +81,22 @@ class TextureCache {
|
|
|
return newt;
|
|
|
}
|
|
|
|
|
|
- public function allocTarget( name : String, width : Int, height : Int, defaultDepth=true, ?format:hxd.PixelFormat, isCube = false, isMipmapped = false ) {
|
|
|
+ public function allocTarget( name : String, width : Int, height : Int, defaultDepth=true, ?format:hxd.PixelFormat, flags : Array<h3d.mat.Data.TextureFlags> = null ) {
|
|
|
var t = cache[position];
|
|
|
if( format == null ) format = defaultFormat;
|
|
|
- if( t == null || t.isDisposed() || t.width != width || t.height != height || t.format != format || isCube != t.flags.has(Cube) )
|
|
|
- t = lookupTarget(name,width,height,format,isCube,isMipmapped);
|
|
|
+ var alloc = false;
|
|
|
+ if( t == null || t.isDisposed() || t.width != width || t.height != height || t.format != format )
|
|
|
+ alloc = true;
|
|
|
+ if ( !alloc && flags != null ) {
|
|
|
+ for ( f in flags ) {
|
|
|
+ if ( !t.flags.has(f) ) {
|
|
|
+ alloc = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( alloc )
|
|
|
+ t = lookupTarget(name,width,height,format,flags);
|
|
|
t.depthBuffer = defaultDepth ? defaultDepthBuffer : null;
|
|
|
t.setName(name);
|
|
|
position++;
|