Browse Source

allow setting less mip levels than maximum required for textures

Nicolas Cannasse 4 years ago
parent
commit
fb8a4102ed
3 changed files with 5 additions and 1 deletions
  1. 1 1
      h3d/impl/GlDriver.hx
  2. 3 0
      h3d/mat/Texture.hx
  3. 1 0
      hxd/res/Image.hx

+ 1 - 1
h3d/impl/GlDriver.hx

@@ -957,7 +957,7 @@ class GlDriver extends Driver {
 			return false;
 		}
 
-		#if (hlsdl >= version("1.12.0"))
+		#if (js || (hlsdl >= version("1.12.0")))
 		gl.texParameteri(bind, GL2.TEXTURE_BASE_LEVEL, 0);
 		gl.texParameteri(bind, GL2.TEXTURE_MAX_LEVEL, t.mipLevels-1);
 		#end

+ 3 - 0
h3d/mat/Texture.hx

@@ -40,6 +40,7 @@ class Texture {
 	public var layerCount(get, never) : Int;
 	public var lodBias : Float = 0.;
 	public var mipLevels(get, never) : Int;
+	var customMipLevels : Int;
 
 	/**
 		If this callback is set, the texture can be re-allocated when the 3D context has been lost or when
@@ -71,6 +72,8 @@ class Texture {
 	function get_mipLevels() {
 		if( !flags.has(MipMapped) )
 			return 1;
+		if( customMipLevels > 0 )
+			return customMipLevels;
 		/* atm we don't allow textures with mipmaps < max levels */
 		var lv = 1;
 		var w = width, h = height;

+ 1 - 0
hxd/res/Image.hx

@@ -437,6 +437,7 @@ class Image extends Resource {
 		if( !getFormat().useAsyncDecode && !DEFAULT_ASYNC ) {
 			function load() {
 				// immediately loading the PNG is faster than going through loadBitmap
+				@:privateAccess tex.customMipLevels = inf.mipLevels;
 				tex.alloc();
 				for( layer in 0...tex.layerCount ) {
 					for( mip in 0...inf.mipLevels ) {