|
@@ -76,9 +76,9 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
var hasDeviceError = false;
|
|
|
|
|
|
var defaultTarget : RenderTargetView;
|
|
|
- var defaultDepth : DepthBuffer;
|
|
|
- var defaultDepthInst : h3d.mat.DepthBuffer;
|
|
|
- var extraDepthInst : h3d.mat.DepthBuffer;
|
|
|
+ var defaultDepth : Texture;
|
|
|
+ var defaultDepthInst : h3d.mat.Texture;
|
|
|
+ var extraDepthInst : h3d.mat.Texture;
|
|
|
|
|
|
var viewport : hl.BytesAccess<hl.F32> = new hl.Bytes(4 * VIEWPORTS_ELTS);
|
|
|
var rects : hl.BytesAccess<Int> = new hl.Bytes(4 * RECTS_ELTS);
|
|
@@ -87,7 +87,7 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
var offsets : Array<Int> = [];
|
|
|
var currentShader : CompiledShader;
|
|
|
var currentIndex : IndexBuffer;
|
|
|
- var currentDepth : DepthBuffer;
|
|
|
+ var currentDepth : Texture;
|
|
|
var currentLayout : Layout;
|
|
|
var currentTargets = new hl.NativeArray<RenderTargetView>(16);
|
|
|
var currentTargetResources = new hl.NativeArray<ShaderResourceView>(16);
|
|
@@ -184,7 +184,8 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
shaderVersion = if( version < 10 ) "3_0" else if( version < 11 ) "4_0" else "5_0";
|
|
|
|
|
|
Driver.iaSetPrimitiveTopology(TriangleList);
|
|
|
- defaultDepthInst = new h3d.mat.DepthBuffer(-1, -1);
|
|
|
+ defaultDepthInst = new h3d.mat.Texture(-1, -1, Depth24Stencil8);
|
|
|
+ defaultDepthInst.name = "defaultDepth";
|
|
|
for( i in 0...VIEWPORTS_ELTS )
|
|
|
viewport[i] = 0;
|
|
|
for( i in 0...RECTS_ELTS )
|
|
@@ -207,6 +208,7 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
|
|
|
override function resize(width:Int, height:Int) {
|
|
|
if( defaultDepth != null ) {
|
|
|
+ defaultDepth.depthView.release();
|
|
|
defaultDepth.view.release();
|
|
|
defaultDepth.res.release();
|
|
|
}
|
|
@@ -221,14 +223,29 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
var depthDesc = new Texture2dDesc();
|
|
|
depthDesc.width = width;
|
|
|
depthDesc.height = height;
|
|
|
- depthDesc.format = depthStencilFormat;
|
|
|
- depthDesc.bind = DepthStencil;
|
|
|
+ depthDesc.format = R24G8_TYPELESS;
|
|
|
+ depthDesc.usage = Default;
|
|
|
+ depthDesc.mipLevels = 1;
|
|
|
+ depthDesc.arraySize = 1;
|
|
|
+ depthDesc.sampleCount = 1;
|
|
|
+ depthDesc.sampleQuality = 0;
|
|
|
+ depthDesc.bind = DepthStencil | ShaderResource;
|
|
|
var depth = Driver.createTexture2d(depthDesc);
|
|
|
if( depth == null ) throw "Failed to create depthBuffer";
|
|
|
- var depthView = Driver.createDepthStencilView(depth,depthStencilFormat);
|
|
|
- defaultDepth = { res : depth, view : depthView };
|
|
|
+ var depthView = Driver.createDepthStencilView(depth,D24_UNORM_S8_UINT, false);
|
|
|
+ var readOnlyDepthView = Driver.createDepthStencilView(depth, D24_UNORM_S8_UINT, true);
|
|
|
+
|
|
|
+ var vdesc = new ShaderResourceViewDesc();
|
|
|
+ vdesc.format = R24_UNORM_X8_TYPELESS;
|
|
|
+ vdesc.dimension = Texture2D;
|
|
|
+ vdesc.arraySize = 1;
|
|
|
+ vdesc.start = 0;
|
|
|
+ vdesc.count = -1;
|
|
|
+ var shaderView = Driver.createShaderResourceView(depth, vdesc);
|
|
|
+
|
|
|
+ defaultDepth = { res : depth, view : shaderView, depthView : depthView, rt : null, mips : 0 };
|
|
|
@:privateAccess {
|
|
|
- defaultDepthInst.b = defaultDepth;
|
|
|
+ defaultDepthInst.t = defaultDepth;
|
|
|
defaultDepthInst.width = width;
|
|
|
defaultDepthInst.height = height;
|
|
|
}
|
|
@@ -246,8 +263,8 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
if( extraDepthInst != null ) @:privateAccess {
|
|
|
extraDepthInst.width = width;
|
|
|
extraDepthInst.height = height;
|
|
|
- if( extraDepthInst.b != null ) disposeDepthBuffer(extraDepthInst);
|
|
|
- extraDepthInst.b = allocDepthBuffer(extraDepthInst);
|
|
|
+ if( extraDepthInst.t != null ) disposeDepthBuffer(extraDepthInst);
|
|
|
+ extraDepthInst.t = allocDepthBuffer(extraDepthInst);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -273,7 +290,7 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
Driver.clearColor(currentTargets[i], color.r, color.g, color.b, color.a);
|
|
|
}
|
|
|
if( currentDepth != null && (depth != null || stencil != null) )
|
|
|
- Driver.clearDepthStencilView(currentDepth.view, depth, stencil);
|
|
|
+ Driver.clearDepthStencilView(currentDepth.depthView, depth, stencil);
|
|
|
}
|
|
|
|
|
|
override function getDriverName(details:Bool) {
|
|
@@ -303,12 +320,13 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
|
|
|
}
|
|
|
|
|
|
- override function getDefaultDepthBuffer():h3d.mat.DepthBuffer {
|
|
|
+ override function getDefaultDepthBuffer():h3d.mat.Texture {
|
|
|
if( extraDepthInst == null ) @:privateAccess {
|
|
|
- extraDepthInst = new h3d.mat.DepthBuffer(0, 0);
|
|
|
+ extraDepthInst = new h3d.mat.Texture(0, 0, Depth24Stencil8);
|
|
|
+ extraDepthInst.name = "extraDepth";
|
|
|
extraDepthInst.width = outputWidth;
|
|
|
extraDepthInst.height = outputHeight;
|
|
|
- extraDepthInst.b = allocDepthBuffer(extraDepthInst);
|
|
|
+ extraDepthInst.t = allocDepthBuffer(extraDepthInst);
|
|
|
}
|
|
|
return extraDepthInst;
|
|
|
}
|
|
@@ -327,21 +345,36 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
return { res : res, count : count, bits : bits };
|
|
|
}
|
|
|
|
|
|
- override function allocDepthBuffer( b : h3d.mat.DepthBuffer ) : DepthBuffer {
|
|
|
+ override function allocDepthBuffer( b : h3d.mat.Texture ) : Texture {
|
|
|
var depthDesc = new Texture2dDesc();
|
|
|
depthDesc.width = b.width;
|
|
|
depthDesc.height = b.height;
|
|
|
- depthDesc.format = D24_UNORM_S8_UINT;
|
|
|
- depthDesc.bind = DepthStencil;
|
|
|
+ depthDesc.mipLevels = 1;
|
|
|
+ depthDesc.arraySize = 1;
|
|
|
+ depthDesc.format = R24G8_TYPELESS;
|
|
|
+ depthDesc.sampleCount = 1;
|
|
|
+ depthDesc.sampleQuality = 0;
|
|
|
+ depthDesc.usage = Default;
|
|
|
+ depthDesc.bind = DepthStencil | ShaderResource;
|
|
|
var depth = Driver.createTexture2d(depthDesc);
|
|
|
if( depth == null )
|
|
|
return null;
|
|
|
- return { res : depth, view : Driver.createDepthStencilView(depth,depthDesc.format) };
|
|
|
- }
|
|
|
-
|
|
|
- override function disposeDepthBuffer(b:h3d.mat.DepthBuffer) @:privateAccess {
|
|
|
- var d = b.b;
|
|
|
- b.b = null;
|
|
|
+ var vdesc = new ShaderResourceViewDesc();
|
|
|
+ vdesc.format = R24_UNORM_X8_TYPELESS;
|
|
|
+ vdesc.dimension = Texture2D;
|
|
|
+ vdesc.arraySize = 1;
|
|
|
+ vdesc.start = 0;
|
|
|
+ vdesc.count = -1;
|
|
|
+ var srv = Driver.createShaderResourceView(depth,vdesc);
|
|
|
+ var depthView = Driver.createDepthStencilView(depth,D24_UNORM_S8_UINT, false);
|
|
|
+ var readOnlyDepthView = Driver.createDepthStencilView(depth, D24_UNORM_S8_UINT, true);
|
|
|
+ return { res : depth, view : srv, depthView : depthView, rt : null, mips : 0 };
|
|
|
+ }
|
|
|
+
|
|
|
+ override function disposeDepthBuffer(b:h3d.mat.Texture) @:privateAccess {
|
|
|
+ var d = b.t;
|
|
|
+ b.t = null;
|
|
|
+ d.depthView.release();
|
|
|
d.view.release();
|
|
|
d.res.release();
|
|
|
}
|
|
@@ -924,7 +957,7 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
currentTargets[0] = defaultTarget;
|
|
|
currentTargetResources[0] = null;
|
|
|
targetsCount = 1;
|
|
|
- Driver.omSetRenderTargets(1, currentTargets, currentDepth.view);
|
|
|
+ Driver.omSetRenderTargets(1, currentTargets, currentDepth.depthView);
|
|
|
viewport[2] = outputWidth;
|
|
|
viewport[3] = outputHeight;
|
|
|
viewport[5] = 1.;
|
|
@@ -963,7 +996,7 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
curTexture = textures[0];
|
|
|
if( tex.depthBuffer != null && (tex.depthBuffer.width != tex.width || tex.depthBuffer.height != tex.height) )
|
|
|
throw "Invalid depth buffer size : does not match render target size";
|
|
|
- currentDepth = @:privateAccess (tex.depthBuffer == null ? null : tex.depthBuffer.b);
|
|
|
+ currentDepth = @:privateAccess (tex.depthBuffer == null ? null : tex.depthBuffer.t);
|
|
|
for( i in 0...textures.length ) {
|
|
|
var tex = textures[i];
|
|
|
if( tex.t == null ) {
|
|
@@ -993,7 +1026,7 @@ class DirectXDriver extends h3d.impl.Driver {
|
|
|
Driver.clearColor(rt, 0, 0, 0, 0);
|
|
|
}
|
|
|
}
|
|
|
- Driver.omSetRenderTargets(textures.length, currentTargets, currentDepth == null ? null : currentDepth.view);
|
|
|
+ Driver.omSetRenderTargets(textures.length, currentTargets, currentDepth == null ? null : currentDepth.depthView);
|
|
|
targetsCount = textures.length;
|
|
|
|
|
|
var w = tex.width >> mipLevel; if( w == 0 ) w = 1;
|