Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public unsafe void UpdateGpuBufferVTF(CRenderContext rc, EngineNS.CCommandList cmd, Graphics.CGfxCamera Camera)
        {
            CTexture2DDesc desc = new CTexture2DDesc();

            desc.Init();

            var spDesc = new CSamplerStateDesc();

            spDesc.SetDefault();
            spDesc.Filter = ESamplerFilter.SPF_MIN_MAG_MIP_POINT;
            mSamplerState = CEngine.Instance.SamplerStateManager.GetSamplerState(rc, spDesc);

            int vertStride = sizeof(Cluster.GpuSceneVertex);
            int size       = mAllVertices.Count * vertStride;
            int side       = (int)Math.Sqrt((float)size) + 1;

            desc.Width     = 512;
            desc.Height    = 512;
            desc.MipLevels = 1;
            desc.Format    = EPixelFormat.PXF_R32G32B32A32_FLOAT;
            mVertexTexture = rc.CreateTexture2D(desc);
            CShaderResourceViewDesc srvDesc = new CShaderResourceViewDesc();

            srvDesc.mFormat    = desc.Format;
            srvDesc.mTexture2D = mVertexTexture.CoreObject;
            mVertexTextureView = rc.CreateShaderResourceView(srvDesc);
            mVertexTextureView.ResourceState.StreamState = EStreamingState.SS_Valid;

            {
                var copyArray = mAllVertices.ToArray();
                fixed(Vector4 *p = &mVertexTexData[0])
                fixed(Cluster.GpuSceneVertex * v = &copyArray[0])
                {
                    CoreSDK.SDK_Memory_Copy(p, v, (uint)size);

                    mVertexTexture.UpdateMipData(cmd, 0, p, 512, 512, 512 * 4 * 4);
                }
            }

            int InstStride = sizeof(GpuMeshInstanceData);

            size                     = mGpuInstanceDatas.Count * InstStride;
            side                     = (int)Math.Sqrt((float)size) + 1;
            desc.Width               = 256;
            desc.Height              = 256;
            desc.MipLevels           = 1;
            desc.Format              = EPixelFormat.PXF_R32G32B32A32_FLOAT;
            mInstanceDataTexture     = rc.CreateTexture2D(desc);
            srvDesc.mFormat          = desc.Format;
            srvDesc.mTexture2D       = mInstanceDataTexture.CoreObject;
            mInstanceDataTextureView = rc.CreateShaderResourceView(srvDesc);
            mInstanceDataTextureView.ResourceState.StreamState = EStreamingState.SS_Valid;

            {
                var copyArray = mGpuInstanceDatas.ToArray();
                fixed(Vector4 *p = &mInstTexData[0])
                fixed(GpuMeshInstanceData * v = &copyArray[0])
                {
                    CoreSDK.SDK_Memory_Copy(p, v, (uint)size);
                    mInstanceDataTexture.UpdateMipData(cmd, 0, p, 256, 256, 256 * 4 * 4);
                }
            }
        }
Exemplo n.º 3
0
        public bool OnResize(CRenderContext RHICtx, CSwapChain swapChain, UInt32 width, UInt32 height)
        {
            if (mViewport == null)
            {
                return(false);
            }

            if (width == 0 || height == 0)
            {
                return(false);
            }

            mViewport.Width  = width;
            mViewport.Height = height;
            SDK_GfxSceneView_ResizeViewport(CoreObject, (UInt32)mViewport.TopLeftX, (UInt32)mViewport.TopLeftY, width, height);

            mFrameBuffer?.Cleanup();
            mFrameBuffer = null;

            CFrameBuffersDesc fbDesc = new CFrameBuffersDesc();

            fbDesc.IsSwapChainBuffer = vBOOL.FromBoolean(false);
            fbDesc.UseDSV            = (mViewInfo.mUseDSV ? vBOOL.FromBoolean(true) : vBOOL.FromBoolean(false));
            mFrameBuffer             = RHICtx.CreateFrameBuffers(fbDesc);
            if (mFrameBuffer == null)
            {
                return(false);
            }

            SDK_GfxSceneView_SetFrameBuffers(CoreObject, FrameBuffer.CoreObject);
            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();

            for (int idx = 0; idx < mRTVArray.Count; idx++)
            {
                mRTVArray[idx]?.Cleanup();
            }
            mRTVArray.Clear();

            mDSV?.Cleanup();
            mDSV = null;

            for (int i = 0; i < mViewInfo.mRTVDescArray.Count; i++)
            {
                var refRTVDesc = mViewInfo.mRTVDescArray[i];
                if (refRTVDesc.mCanBeSampled == true)
                {
                    CTexture2DDesc Tex2dDesc = new CTexture2DDesc();
                    Tex2dDesc.Init();
                    Tex2dDesc.Width     = width;
                    Tex2dDesc.Height    = height;
                    Tex2dDesc.Format    = refRTVDesc.Format;
                    Tex2dDesc.BindFlags = (UInt32)(EBindFlags.BF_SHADER_RES | EBindFlags.BF_RENDER_TARGET);
                    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_RT((UInt32)i, SRV);

                    refRTVDesc.mTexture2D = Tex2d.CoreObject;
                    var RTV = RHICtx.CreateRenderTargetView(refRTVDesc);
                    mRTVArray.Add(RTV);
                    mFrameBuffer.BindRenderTargetView((UInt32)i, RTV);
                }
                else
                {
                    CTexture2DDesc Tex2dDesc = new CTexture2DDesc();
                    Tex2dDesc.Init();
                    Tex2dDesc.Width     = width;
                    Tex2dDesc.Height    = height;
                    Tex2dDesc.Format    = refRTVDesc.Format;
                    Tex2dDesc.BindFlags = (UInt32)(EBindFlags.BF_RENDER_TARGET);
                    var Tex2d = RHICtx.CreateTexture2D(Tex2dDesc);
                    mTex2dArray.Add(Tex2d);

                    CRenderTargetViewDesc rtDesc = new CRenderTargetViewDesc();
                    rtDesc.mTexture2D = Tex2d.CoreObject;
                    var RTV = RHICtx.CreateRenderTargetView(rtDesc);
                    mRTVArray.Add(RTV);
                    mFrameBuffer.BindRenderTargetView((UInt32)i, RTV);
                }
            }

            mViewInfo.mDSVDesc.Width  = width;
            mViewInfo.mDSVDesc.Height = height;
            if (mViewInfo.mUseDSV)
            {
                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;
                    mDSV = RHICtx.CreateDepthStencilView(mViewInfo.mDSVDesc);
                    mFrameBuffer.BindDepthStencilView(mDSV);
                }
                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;
                    mDSV = RHICtx.CreateDepthStencilView(mViewInfo.mDSVDesc);
                    mFrameBuffer.BindDepthStencilView(mDSV);
                }
            }
            else
            {
                mDSV = null;
            }

            return(true);
        }