瀏覽代碼

Adding onTextureBiasChanged to handle gl polygon offset

clementlandrin 10 月之前
父節點
當前提交
17be98fd46
共有 4 個文件被更改,包括 35 次插入6 次删除
  1. 6 0
      h3d/Engine.hx
  2. 3 0
      h3d/impl/Driver.hx
  3. 7 3
      h3d/impl/GlDriver.hx
  4. 19 3
      h3d/mat/Texture.hx

+ 6 - 0
h3d/Engine.hx

@@ -429,6 +429,12 @@ class Engine {
 		return true;
 	}
 
+	public function onTextureBiasChanged(t : h3d.mat.Texture) {
+		if ( !t.isDepth() )
+			throw "Can change texture bias on depth buffer only";
+		driver.onTextureBiasChanged(t);
+	}
+
 	public function dispose() {
 		driver.dispose();
 		window.removeResizeEvent(onWindowResize);

+ 3 - 0
h3d/impl/Driver.hx

@@ -265,6 +265,9 @@ class Driver {
 		throw "Driver does not allow to read vertex bytes";
 	}
 
+	public function onTextureBiasChanged( t : h3d.mat.Texture ) {
+	}
+
 	/**
 		Returns true if we could copy the texture, false otherwise (not supported by driver or mismatch in size/format)
 	**/

+ 7 - 3
h3d/impl/GlDriver.hx

@@ -1835,10 +1835,14 @@ class GlDriver extends Driver {
 		#end
 	}
 
-	function setPolygonOffset( depthTexture : h3d.mat.Texture ) {
-		if ( depthTexture != null && ( depthTexture.depthBias != 0 || depthTexture.slopeScaledBias != 0 ) ) {
+	override function onTextureBiasChanged( t : h3d.mat.Texture ) {
+		setPolygonOffset(t);
+	}
+
+	function setPolygonOffset( depthBuffer : h3d.mat.Texture ) {
+		if ( depthBuffer != null && ( depthBuffer.depthBias != 0 || depthBuffer.slopeScaledBias != 0 ) ) {
 			gl.enable(GL.POLYGON_OFFSET_FILL);
-			gl.polygonOffset(depthTexture.slopeScaledBias, depthTexture.depthBias);
+			gl.polygonOffset(depthBuffer.slopeScaledBias, depthBuffer.depthBias);
 		}
 		else
 			gl.disable(GL.POLYGON_OFFSET_FILL);

+ 19 - 3
h3d/mat/Texture.hx

@@ -40,8 +40,8 @@ class Texture {
 	public var startingMip : Int = 0;
 	public var lodBias : Float = 0.;
 	public var mipLevels(get, never) : Int;
-	public var depthBias : Float = 0.;
-	public var slopeScaledBias : Float = 0.;
+	public var depthBias(default, set) : Float = 0.;
+	public var slopeScaledBias(default, set) : Float = 0.;
 	public var depthClamp : Bool = false;
 	var customMipLevels : Int;
 
@@ -201,6 +201,22 @@ class Texture {
 		name = n;
 	}
 
+	public function set_depthBias(v : Float) {
+		if ( v != depthBias ) {
+			depthBias = v;
+			h3d.Engine.getCurrent().onTextureBiasChanged(this);
+		}
+		return depthBias;
+	}
+
+	public function set_slopeScaledBias(v : Float) {
+		if ( v != slopeScaledBias ) {
+			slopeScaledBias = v;
+			h3d.Engine.getCurrent().onTextureBiasChanged(this);
+		}
+		return slopeScaledBias;
+	}
+
 	function set_mipMap(m:MipMap) {
 		bits = (bits & ~(3 << 0)) | (Type.enumIndex(m) << 0);
 		return mipMap = m;
@@ -331,7 +347,7 @@ class Texture {
 		flags.set(WasCleared);
 		checkMipMapGen(mipLevel, layer);
 	}
-	
+
 	public function dispose() {
 		if( t != null )
 			mem.deleteTexture(this);