コード例 #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);
        }
コード例 #2
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);
        }