Selaa lähdekoodia

added h3d.mat.Texture.lodBias support

Nicolas Cannasse 5 vuotta sitten
vanhempi
commit
c94b7b7281
4 muutettua tiedostoa jossa 14 lisäystä ja 6 poistoa
  1. 3 0
      h3d/impl/DirectXDriver.hx
  2. 3 3
      h3d/impl/Driver.hx
  3. 7 3
      h3d/impl/GlDriver.hx
  4. 1 0
      h3d/mat/Texture.hx

+ 3 - 0
h3d/impl/DirectXDriver.hx

@@ -1116,6 +1116,8 @@ class DirectXDriver extends h3d.impl.Driver {
 				}
 				}
 
 
 				var bits = @:privateAccess t.bits;
 				var bits = @:privateAccess t.bits;
+				if( t.lodBias != 0 )
+					bits |= Std.int((t.lodBias + 32)*32) << 10;
 				if( bits != state.samplerBits[i] ) {
 				if( bits != state.samplerBits[i] ) {
 					var ss = samplerStates.get(bits);
 					var ss = samplerStates.get(bits);
 					if( ss == null ) {
 					if( ss == null ) {
@@ -1126,6 +1128,7 @@ class DirectXDriver extends h3d.impl.Driver {
 						// only the first sampler maxLod seems to be taken into account :'(
 						// only the first sampler maxLod seems to be taken into account :'(
 						desc.minLod = 0;
 						desc.minLod = 0;
 						desc.maxLod = 1e30;
 						desc.maxLod = 1e30;
+						desc.mipLodBias = t.lodBias;
 						ss = Driver.createSamplerState(desc);
 						ss = Driver.createSamplerState(desc);
 						samplerStates.set(bits, ss);
 						samplerStates.set(bits, ss);
 					}
 					}

+ 3 - 3
h3d/impl/Driver.hx

@@ -15,19 +15,19 @@ typedef Query = {};
 #elseif js
 #elseif js
 typedef IndexBuffer = { b : js.html.webgl.Buffer, is32 : Bool };
 typedef IndexBuffer = { b : js.html.webgl.Buffer, is32 : Bool };
 typedef VertexBuffer = { b : js.html.webgl.Buffer, stride : Int #if multidriver, driver : Driver #end };
 typedef VertexBuffer = { b : js.html.webgl.Buffer, stride : Int #if multidriver, driver : Driver #end };
-typedef Texture = { t : js.html.webgl.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bind : Int #if multidriver, driver : Driver #end };
+typedef Texture = { t : js.html.webgl.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bias : Float, bind : Int #if multidriver, driver : Driver #end };
 typedef DepthBuffer = { r : js.html.webgl.Renderbuffer #if multidriver, driver : Driver #end };
 typedef DepthBuffer = { r : js.html.webgl.Renderbuffer #if multidriver, driver : Driver #end };
 typedef Query = {};
 typedef Query = {};
 #elseif hlsdl
 #elseif hlsdl
 typedef IndexBuffer = { b : sdl.GL.Buffer, is32 : Bool };
 typedef IndexBuffer = { b : sdl.GL.Buffer, is32 : Bool };
 typedef VertexBuffer = { b : sdl.GL.Buffer, stride : Int };
 typedef VertexBuffer = { b : sdl.GL.Buffer, stride : Int };
-typedef Texture = { t : sdl.GL.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bind : Int };
+typedef Texture = { t : sdl.GL.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bind : Int, bias : Float };
 typedef DepthBuffer = { r : sdl.GL.Renderbuffer };
 typedef DepthBuffer = { r : sdl.GL.Renderbuffer };
 typedef Query = { q : sdl.GL.Query, kind : QueryKind };
 typedef Query = { q : sdl.GL.Query, kind : QueryKind };
 #elseif usegl
 #elseif usegl
 typedef IndexBuffer = { b : haxe.GLTypes.Buffer, is32 : Bool };
 typedef IndexBuffer = { b : haxe.GLTypes.Buffer, is32 : Bool };
 typedef VertexBuffer = { b : haxe.GLTypes.Buffer, stride : Int };
 typedef VertexBuffer = { b : haxe.GLTypes.Buffer, stride : Int };
-typedef Texture = { t : haxe.GLTypes.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bind : Int };
+typedef Texture = { t : haxe.GLTypes.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bind : Int, bias : Float };
 typedef DepthBuffer = { r : haxe.GLTypes.Renderbuffer };
 typedef DepthBuffer = { r : haxe.GLTypes.Renderbuffer };
 typedef Query = { q : haxe.GLTypes.Query, kind : QueryKind };
 typedef Query = { q : haxe.GLTypes.Query, kind : QueryKind };
 #elseif hldx
 #elseif hldx

+ 7 - 3
h3d/impl/GlDriver.hx

@@ -576,6 +576,10 @@ class GlDriver extends Driver {
 					gl.texParameteri(mode, GL.TEXTURE_WRAP_S, w);
 					gl.texParameteri(mode, GL.TEXTURE_WRAP_S, w);
 					gl.texParameteri(mode, GL.TEXTURE_WRAP_T, w);
 					gl.texParameteri(mode, GL.TEXTURE_WRAP_T, w);
 				}
 				}
+				if( t.lodBias != t.t.bias ) {
+					t.t.bias = t.lodBias;
+					gl.texParameterf(pt.mode, GL.TEXTURE_LOD_BIAS, t.lodBias);
+				}
 			}
 			}
 		}
 		}
 	}
 	}
@@ -828,7 +832,7 @@ class GlDriver extends Driver {
 		discardError();
 		discardError();
 		var tt = gl.createTexture();
 		var tt = gl.createTexture();
 		var bind = getBindType(t);
 		var bind = getBindType(t);
-		var tt : Texture = { t : tt, width : t.width, height : t.height, internalFmt : GL.RGBA, pixelFmt : GL.UNSIGNED_BYTE, bits : -1, bind : bind #if multidriver, driver : this #end };
+		var tt : Texture = { t : tt, width : t.width, height : t.height, internalFmt : GL.RGBA, pixelFmt : GL.UNSIGNED_BYTE, bits : -1, bind : bind, bias : 0, #if multidriver, driver : this #end };
 		switch( t.format ) {
 		switch( t.format ) {
 		case RGBA:
 		case RGBA:
 			// default
 			// default
@@ -1486,7 +1490,7 @@ class GlDriver extends Driver {
 			gl.framebufferTextureLayer(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, tex.t.t, mipLevel, layer);
 			gl.framebufferTextureLayer(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, tex.t.t, mipLevel, layer);
 		else
 		else
 			gl.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, tex.flags.has(Cube) ? CUBE_FACES[layer] : GL.TEXTURE_2D, tex.t.t, mipLevel);
 			gl.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, tex.flags.has(Cube) ? CUBE_FACES[layer] : GL.TEXTURE_2D, tex.t.t, mipLevel);
-		
+
 		if( tex.depthBuffer != null ) {
 		if( tex.depthBuffer != null ) {
 			// Depthbuffer and stencilbuffer are combined in one buffer, created with GL.DEPTH_STENCIL
 			// Depthbuffer and stencilbuffer are combined in one buffer, created with GL.DEPTH_STENCIL
 			if(tex.depthBuffer.hasStencil() && tex.depthBuffer.format == Depth24Stencil8) {
 			if(tex.depthBuffer.hasStencil() && tex.depthBuffer.format == Depth24Stencil8) {
@@ -1494,7 +1498,7 @@ class GlDriver extends Driver {
 			} else {
 			} else {
 				gl.framebufferRenderbuffer(GL.FRAMEBUFFER, GL.DEPTH_STENCIL_ATTACHMENT, GL.RENDERBUFFER,null);
 				gl.framebufferRenderbuffer(GL.FRAMEBUFFER, GL.DEPTH_STENCIL_ATTACHMENT, GL.RENDERBUFFER,null);
 				gl.framebufferRenderbuffer(GL.FRAMEBUFFER, GL.DEPTH_ATTACHMENT, GL.RENDERBUFFER, @:privateAccess tex.depthBuffer.b.r);
 				gl.framebufferRenderbuffer(GL.FRAMEBUFFER, GL.DEPTH_ATTACHMENT, GL.RENDERBUFFER, @:privateAccess tex.depthBuffer.b.r);
-				gl.framebufferRenderbuffer(GL.FRAMEBUFFER, GL.STENCIL_ATTACHMENT, GL.RENDERBUFFER,tex.depthBuffer.hasStencil() ? @:privateAccess tex.depthBuffer.b.r : null);						
+				gl.framebufferRenderbuffer(GL.FRAMEBUFFER, GL.STENCIL_ATTACHMENT, GL.RENDERBUFFER,tex.depthBuffer.hasStencil() ? @:privateAccess tex.depthBuffer.b.r : null);
 			}
 			}
 		} else {
 		} else {
 			gl.framebufferRenderbuffer(GL.FRAMEBUFFER, GL.DEPTH_STENCIL_ATTACHMENT, GL.RENDERBUFFER,null);
 			gl.framebufferRenderbuffer(GL.FRAMEBUFFER, GL.DEPTH_STENCIL_ATTACHMENT, GL.RENDERBUFFER,null);

+ 1 - 0
h3d/mat/Texture.hx

@@ -38,6 +38,7 @@ class Texture {
 	public var filter(default,set) : Filter;
 	public var filter(default,set) : Filter;
 	public var wrap(default, set) : Wrap;
 	public var wrap(default, set) : Wrap;
 	public var layerCount(get, never) : Int;
 	public var layerCount(get, never) : Int;
+	public var lodBias : Float = 0.;
 
 
 	/**
 	/**
 		If this callback is set, the texture can be re-allocated when the 3D context has been lost or when
 		If this callback is set, the texture can be re-allocated when the 3D context has been lost or when