فهرست منبع

minor fixes for small/empty textures

Nicolas Cannasse 5 سال پیش
والد
کامیت
254890d38d
4فایلهای تغییر یافته به همراه19 افزوده شده و 5 حذف شده
  1. 8 4
      h3d/impl/DirectXDriver.hx
  2. 4 1
      h3d/impl/GlDriver.hx
  3. 1 0
      h3d/mat/Texture.hx
  4. 6 0
      hxd/Pixels.hx

+ 8 - 4
h3d/impl/DirectXDriver.hx

@@ -529,15 +529,19 @@ class DirectXDriver extends h3d.impl.Driver {
 	}
 	}
 
 
 	function captureTexPixels( pixels: hxd.Pixels, tex:h3d.mat.Texture, layer:Int, mipLevel:Int, x : Int = 0, y : Int = 0)  {
 	function captureTexPixels( pixels: hxd.Pixels, tex:h3d.mat.Texture, layer:Int, mipLevel:Int, x : Int = 0, y : Int = 0)  {
+
+		if( pixels.width == 0 || pixels.height == 0 )
+			return pixels;
+
 		var desc = new Texture2dDesc();
 		var desc = new Texture2dDesc();
 		desc.width = pixels.width;
 		desc.width = pixels.width;
 		desc.height = pixels.height;
 		desc.height = pixels.height;
 		desc.access = CpuRead | CpuWrite;
 		desc.access = CpuRead | CpuWrite;
 		desc.usage = Staging;
 		desc.usage = Staging;
 		desc.format = getTextureFormat(tex);
 		desc.format = getTextureFormat(tex);
-		
+
 		if( hasDeviceError ) throw "Can't capture if device disposed";
 		if( hasDeviceError ) throw "Can't capture if device disposed";
-		
+
 		var tmp = dx.Driver.createTexture2d(desc);
 		var tmp = dx.Driver.createTexture2d(desc);
 		if( tmp == null )
 		if( tmp == null )
 			throw "Capture failed: can't create tmp texture";
 			throw "Capture failed: can't create tmp texture";
@@ -557,9 +561,9 @@ class DirectXDriver extends h3d.impl.Driver {
 		var pitch = 0;
 		var pitch = 0;
 		var bpp = hxd.Pixels.calcStride(1, tex.format);
 		var bpp = hxd.Pixels.calcStride(1, tex.format);
 		var ptr = tmp.map(0, Read, true, pitch);
 		var ptr = tmp.map(0, Read, true, pitch);
-		
+
 		if( hasDeviceError ) throw "Device was disposed during capturePixels";
 		if( hasDeviceError ) throw "Device was disposed during capturePixels";
-		
+
 		if( pitch == desc.width * bpp )
 		if( pitch == desc.width * bpp )
 			@:privateAccess pixels.bytes.b.blit(0, ptr, 0, desc.width * desc.height * bpp);
 			@:privateAccess pixels.bytes.b.blit(0, ptr, 0, desc.width * desc.height * bpp);
 		else {
 		else {

+ 4 - 1
h3d/impl/GlDriver.hx

@@ -1414,6 +1414,9 @@ class GlDriver extends Driver {
 			y = 0;
 			y = 0;
 		}
 		}
 
 
+		if( pixels.width == 0 || pixels.height == 0 )
+			return pixels;
+
 		var old = curTarget;
 		var old = curTarget;
 		var oldCount = numTargets;
 		var oldCount = numTargets;
 		var oldLayer = curTargetLayer;
 		var oldLayer = curTargetLayer;
@@ -1578,7 +1581,7 @@ class GlDriver extends Driver {
 
 
 		case MultipleRenderTargets:
 		case MultipleRenderTargets:
 			mrtExt != null || (mrtExt = gl.getExtension('WEBGL_draw_buffers')) != null;
 			mrtExt != null || (mrtExt = gl.getExtension('WEBGL_draw_buffers')) != null;
-			
+
 		case InstancedRendering:
 		case InstancedRendering:
 			return (glES >= 3) ? true : gl.getExtension("ANGLE_instanced_arrays") != null;
 			return (glES >= 3) ? true : gl.getExtension("ANGLE_instanced_arrays") != null;
 
 

+ 1 - 0
h3d/mat/Texture.hx

@@ -236,6 +236,7 @@ class Texture {
 
 
 	public function clear( color : Int, alpha = 1., ?layer = -1 ) {
 	public function clear( color : Int, alpha = 1., ?layer = -1 ) {
 		alloc();
 		alloc();
+		if( width == 0 || height == 0 ) return;
 		if( #if (usegl || hlsdl || js) true #else flags.has(Target) #end && (width != 1 || height != 1) ) {
 		if( #if (usegl || hlsdl || js) true #else flags.has(Target) #end && (width != 1 || height != 1) ) {
 			var engine = h3d.Engine.getCurrent();
 			var engine = h3d.Engine.getCurrent();
 			color |= Std.int(hxd.Math.clamp(alpha)*255) << 24;
 			color |= Std.int(hxd.Math.clamp(alpha)*255) << 24;

+ 6 - 0
hxd/Pixels.hx

@@ -354,6 +354,12 @@ class Pixels {
 				bytes[p+1] = bytes[p];
 				bytes[p+1] = bytes[p];
 				bytes[p] = a;
 				bytes[p] = a;
 			}
 			}
+		case [RGBA, R8]:
+			var nbytes = haxe.io.Bytes.alloc(width * height);
+			var out : hxd.impl.UncheckedBytes = nbytes;
+			for( i in 0...width*height )
+				out[i] = bytes[i << 2];
+			this.bytes = nbytes;
 
 
 		case [S3TC(a),S3TC(b)] if( a == b ):
 		case [S3TC(a),S3TC(b)] if( a == b ):
 			// nothing
 			// nothing