IDepthStencilView GetDsv(ref DepthStencilViewDescription viewDesc) { CDepthStencilView view = null; foreach (var v in dsvs) { if (v.DescEquals(ref viewDesc)) { view = v; break; } } if (view == null) { view = new CDepthStencilView(this, GetSurfaceLevel(viewDesc.FirstArraySlice, viewDesc.MipSlice), ref viewDesc); dsvs.Add(view); } return view; }
public bool OnResize(CRenderContext RHICtx, CSwapChain SwapChain, UInt32 width, UInt32 height) { if (mViewport == null || width == 0 || height == 0) { return(false); } mViewport.Width = width; mViewport.Height = height; //frame buffer; mFrameBuffer?.Cleanup(); mFrameBuffer = null; CFrameBuffersDesc FBDesc = new CFrameBuffersDesc(); FBDesc.IsSwapChainBuffer = vBOOL.FromBoolean(mViewInfo.IsSwapChainBuffer); FBDesc.UseDSV = (mViewInfo.UseDepthStencilView ? vBOOL.FromBoolean(true) : vBOOL.FromBoolean(false)); mFrameBuffer = RHICtx.CreateFrameBuffers(FBDesc); if (mFrameBuffer == null) { return(false); } for (int idx = 0; idx < mTex2dArray.Count; idx++) { mTex2dArray[idx]?.Cleanup(); } mTex2dArray.Clear(); for (int idx = 0; idx < mSRVArray.Count; idx++) { mSRVArray[idx]?.Cleanup(); } mSRVArray.Clear(); //render target view; for (int idx = 0; idx < mRTVArray.Count; idx++) { mRTVArray[idx]?.Cleanup(); } mRTVArray.Clear(); mDepthStencilView?.Cleanup(); mDepthStencilView = null; if (mViewInfo.IsSwapChainBuffer == true && SwapChain != null) { for (int idx = 0; idx < mViewInfo.mRTVDescArray.Count; idx++) { var RTVDesc = mViewInfo.mRTVDescArray[idx]; //gles3.1 can not sample swap chain buffer; RTVDesc.mCanBeSampled = vBOOL.FromBoolean(false); RTVDesc.mTexture2D = SwapChain.Texture2D.CoreObject; //this is for editor to use(snapshot needs this); if (CEngine.Instance.Desc.RHIType == ERHIType.RHT_D3D11) { CShaderResourceViewDesc SRVDesc = new CShaderResourceViewDesc(); SRVDesc.Init(); SRVDesc.mTexture2D = SwapChain.Texture2D.CoreObject; var SRV = RHICtx.CreateShaderResourceView(SRVDesc); mSRVArray.Add(SRV); mFrameBuffer.BindSRV_RT((UInt32)idx, SRV); } var RTV = RHICtx.CreateRenderTargetView(RTVDesc); mRTVArray.Add(RTV); mFrameBuffer.BindRenderTargetView((UInt32)idx, RTV); } } else { for (int idx = 0; idx < mViewInfo.mRTVDescArray.Count; idx++) { var refRTVDesc = mViewInfo.mRTVDescArray[idx]; if (refRTVDesc.mCanBeSampled == true) { CTexture2DDesc TexDesc = new CTexture2DDesc(); TexDesc.Init(); TexDesc.Width = width; TexDesc.Height = height; TexDesc.Format = refRTVDesc.Format; TexDesc.BindFlags = (UInt32)(EBindFlags.BF_SHADER_RES | EBindFlags.BF_RENDER_TARGET); var Tex2D = RHICtx.CreateTexture2D(TexDesc); mTex2dArray.Add(Tex2D); CShaderResourceViewDesc SRVDesc = new CShaderResourceViewDesc(); SRVDesc.Init(); SRVDesc.mTexture2D = Tex2D.CoreObject; var SRV = RHICtx.CreateShaderResourceView(SRVDesc); mSRVArray.Add(SRV); mFrameBuffer.BindSRV_RT((UInt32)idx, SRV); refRTVDesc.mTexture2D = Tex2D.CoreObject; var RTV = RHICtx.CreateRenderTargetView(refRTVDesc); mRTVArray.Add(RTV); mFrameBuffer.BindRenderTargetView((UInt32)idx, RTV); } else { CTexture2DDesc TexDesc = new CTexture2DDesc(); TexDesc.Init(); TexDesc.Width = width; TexDesc.Height = height; TexDesc.Format = refRTVDesc.Format; TexDesc.BindFlags = (UInt32)(EBindFlags.BF_RENDER_TARGET); var Tex2D = RHICtx.CreateTexture2D(TexDesc); mTex2dArray.Add(Tex2D); refRTVDesc.mTexture2D = Tex2D.CoreObject; var RTV = RHICtx.CreateRenderTargetView(refRTVDesc); mRTVArray.Add(RTV); mFrameBuffer.BindRenderTargetView((UInt32)idx, RTV); } } } mViewInfo.mDSVDesc.Width = width; mViewInfo.mDSVDesc.Height = height; if (mViewInfo.UseDepthStencilView == true) { if (mViewInfo.mDSVDesc.mCanBeSampled == true) { CTexture2DDesc Tex2dDesc = new CTexture2DDesc(); Tex2dDesc.Init(); Tex2dDesc.Width = width; Tex2dDesc.Height = height; Tex2dDesc.Format = mViewInfo.mDSVDesc.Format; Tex2dDesc.BindFlags = (UInt32)(EBindFlags.BF_SHADER_RES | EBindFlags.BF_DEPTH_STENCIL); var Tex2d = RHICtx.CreateTexture2D(Tex2dDesc); mTex2dArray.Add(Tex2d); CShaderResourceViewDesc SRVDesc = new CShaderResourceViewDesc(); SRVDesc.Init(); SRVDesc.mTexture2D = Tex2d.CoreObject; var SRV = RHICtx.CreateShaderResourceView(SRVDesc); mSRVArray.Add(SRV); mFrameBuffer.BindSRV_DS(SRV); mViewInfo.mDSVDesc.mTexture2D = Tex2d.CoreObject; mDepthStencilView = RHICtx.CreateDepthStencilView(mViewInfo.mDSVDesc); mFrameBuffer.BindDepthStencilView(mDepthStencilView); } else { CTexture2DDesc Tex2dDesc = new CTexture2DDesc(); Tex2dDesc.Init(); Tex2dDesc.Width = width; Tex2dDesc.Height = height; Tex2dDesc.Format = mViewInfo.mDSVDesc.Format; Tex2dDesc.BindFlags = (UInt32)(EBindFlags.BF_SHADER_RES | EBindFlags.BF_DEPTH_STENCIL); var Tex2d = RHICtx.CreateTexture2D(Tex2dDesc); mTex2dArray.Add(Tex2d); mViewInfo.mDSVDesc.mTexture2D = Tex2d.CoreObject; mDepthStencilView = RHICtx.CreateDepthStencilView(mViewInfo.mDSVDesc); mFrameBuffer.BindDepthStencilView(mDepthStencilView); } } else { mDepthStencilView = null; } return(true); }