Explorar el Código

Merge depth buffer specific code with generic texture's one.

clementlandrin hace 1 año
padre
commit
c5bdc9a314
Se han modificado 3 ficheros con 9 adiciones y 41 borrados
  1. 1 28
      h3d/impl/MemoryManager.hx
  2. 5 11
      h3d/mat/Texture.hx
  3. 3 2
      hxd/Pixels.hx

+ 1 - 28
h3d/impl/MemoryManager.hx

@@ -10,7 +10,6 @@ class MemoryManager {
 	var driver : Driver;
 	var buffers : Array<Buffer>;
 	var textures : Array<h3d.mat.Texture>;
-	var depths : Array<h3d.mat.Texture>;
 
 	var triIndexes16 : Indexes;
 	var quadIndexes16 : Indexes;
@@ -28,7 +27,6 @@ class MemoryManager {
 	public function init() {
 		textures = new Array();
 		buffers = new Array();
-		depths = new Array();
 		initIndexes();
 	}
 
@@ -184,7 +182,7 @@ class MemoryManager {
 				free = cleanTextures(false);
 				lastAutoDispose = hxd.Timer.frameCount;
 			}
-			t.t = driver.allocTexture(t);
+			t.t = t.isDepth() ? driver.allocDepthBuffer(t) : driver.allocTexture(t);
 			if( t.t != null ) break;
 
 			if( driver.isDisposed() ) return;
@@ -196,29 +194,6 @@ class MemoryManager {
 		texMemory += memSize(t);
 	}
 
-	@:allow(h3d.mat.Texture.alloc)
-	function allocDepth( b : h3d.mat.Texture ) {
-		while( true ) {
-			var free = cleanTextures(false);
-			b.t = driver.allocDepthBuffer(b);
-			if( b.t != null ) break;
-
-			if( driver.isDisposed() ) return;
-			while( cleanTextures(false) ) {} // clean all old textures
-			if( !free && !cleanTextures(true) )
-				throw "Maximum texture memory reached";
-		}
-		depths.push(b);
-		texMemory += b.width * b.height * 4;
-	}
-
-	@:allow(h3d.mat.Texture.dispose)
-	function deleteDepth( b : h3d.mat.Texture ) {
-		if( !depths.remove(b) ) return;
-		driver.disposeDepthBuffer(b);
-		texMemory -= b.width * b.height * 4;
-	}
-
 	// ------------------------------------- DISPOSE ------------------------------------------
 
 	public function onContextLost() {
@@ -237,8 +212,6 @@ class MemoryManager {
 		quadIndexes32 = null;
 		for( t in textures.copy() )
 			t.dispose();
-		for( b in depths.copy() )
-			b.dispose();
 		for( b in buffers.copy() )
 			b.dispose();
 		buffers = [];

+ 5 - 11
h3d/mat/Texture.hx

@@ -114,7 +114,7 @@ class Texture {
 		this.wrap = DEFAULT_WRAP;
 		bits &= 0x7FFF;
 		this.allocPos = hxd.impl.AllocPos.make();
-		if( !this.flags.has(NoAlloc) && (!isDepth() || width > 0) ) alloc();
+		if( !this.flags.has(NoAlloc) && width > 0 ) alloc();
 	}
 
 	function get_layerCount() {
@@ -122,9 +122,7 @@ class Texture {
 	}
 
 	public function alloc() {
-		if ( isDepth() )
-			mem.allocDepth(this);
-		else if( t == null )
+		if ( t == null )
 			mem.allocTexture(this);
 	}
 
@@ -215,7 +213,7 @@ class Texture {
 	}
 
 	public inline function isDisposed() {
-		return isDepth() ? t == null : t == null && realloc == null;
+		return t == null && realloc == null;
 	}
 
 	public function resize(width, height) {
@@ -330,12 +328,8 @@ class Texture {
 	}
 
 	public function dispose() {
-		if( t != null ) {
-			if ( isDepth() )
-				mem.deleteDepth(this);
-			else
-				mem.deleteTexture(this);
-		}
+		if( t != null )
+			mem.deleteTexture(this);
 	}
 
 	/**

+ 3 - 2
hxd/Pixels.hx

@@ -564,8 +564,9 @@ class Pixels {
 			if( n == 1 || n == 4 )
 				return blocks << 1;
 			return blocks << 2;
-		case Depth16, Depth24, Depth24Stencil8, Depth32:
-			throw "Not a pixel format";
+		case Depth16: 2;
+		case Depth24: 3;
+		case Depth24Stencil8, Depth32: 4;
 		}
 	}