コード例 #1
0
        private async System.Threading.Tasks.Task <bool> TestSnapRender(CRenderContext rc)
        {
            var mCurMesh = await CEngine.Instance.MeshManager.CreateMeshAsync(rc, RName.GetRName("editor/basemesh/box.gms"));

            if (mCurMesh == null)
            {
                return(false);
            }
            mTestSnapshort           = new Editor.GSnapshotCreator();
            mTestSnapshort.SkyName   = EngineNS.RName.GetRName("Mesh/sky.gms");
            mTestSnapshort.FloorName = EngineNS.RName.GetRName(@"editor/floor.gms");
            var eye = new EngineNS.Vector3();

            eye.SetValue(1.6f, 1.5f, -3.6f);
            var at = new EngineNS.Vector3();

            at.SetValue(0.0f, 0.0f, 0.0f);
            var up = new EngineNS.Vector3();

            up.SetValue(0.0f, 1.0f, 0.0f);
            await mTestSnapshort.InitEnviroment();

            mTestSnapshort.Camera.LookAtLH(eye, at, up);

            var actor = EngineNS.GamePlay.Actor.GActor.NewMeshActorDirect(mCurMesh);

            mCurMesh.PreUse(true);//就这个地方用,别的地方别乱用,效率不好
            mTestSnapshort.World.AddActor(actor);
            mTestSnapshort.World.GetScene(RName.GetRName("SnapshorCreator")).AddActor(actor);
            mTestSnapshort.FocusActor = actor;
            actor.Placement.Location  = new Vector3(0, 0, 0);
            OnFetchFinished           = (InSrv) =>
            {
                var blob = new EngineNS.Support.CBlobObject();
                unsafe
                {
                    void *pData;
                    uint  rowPitch;
                    uint  depthPitch;
                    if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch))
                    {
                        InSrv.BuildImageBlob(blob, pData, rowPitch);
                        InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0);
                    }
                }
                bool bSave = false;
                if (bSave)
                {
                    var blbArray = new EngineNS.Support.CBlobObject[] { blob };
                    CShaderResourceView.SaveSnap(@"D:\OpenSource\titan3d\Content\editor\basemesh\box.gms.snap", blbArray);
                }
            };
            mTestSnapshort.mRP_Snapshot.OnAfterTickLogic = (InView, InRc, InCmd, InArg) =>
            {
                CTexture2D ReadableTex = null;
                InCmd.CreateReadableTexture2D(ref ReadableTex, mTestSnapshort.mRP_Snapshot.BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0), mTestSnapshort.mRP_Snapshot.BaseSceneView.FrameBuffer);

                EngineNS.CEngine.Instance.GpuFetchManager.RegFetchTexture2D(ReadableTex, OnFetchFinished);
            };
            return(true);
        }
コード例 #2
0
ファイル: CGfxHitProxy.cs プロジェクト: huangdonghai/titan3d
        public void TickLogic()
        {
            if (mUpdateSelf == false || mEnabled == false)
            {
                return;
            }

            var RHICtx = EngineNS.CEngine.Instance.RenderContext;

            if (RHICtx == null || mHitProxyView == null)
            {
                return;
            }
            ScopeTickLogic.Begin();

            //int CurrDPNumber = 0;
            //CEngine.Instance.HitProxyManager.HitProxyIsNewest = false;

            //opaque render pass;
            mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_Opaque, mCamera, mHitProxySE, PrebuildPassIndex.PPI_HitProxy);
            //custom opaque pass;
            mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_CustomOpaque, mCamera, mHitProxySE, PrebuildPassIndex.PPI_HitProxy);
            //custom translucent render pass;
            mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_CustomTranslucent, mCamera, mHitProxySE, PrebuildPassIndex.PPI_HitProxy);
            //translucent render pass;
            mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_Translucent, mCamera, mHitProxySE, PrebuildPassIndex.PPI_HitProxy);
            //gizmos pass;the coordinary should be rendered in this pass;
            mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_Gizmos, mCamera, mHitProxyAxisSE, PrebuildPassIndex.PPI_HitProxy);

            var CmdList = mCLDB_HitProxy[0];

            CmdList.BeginCommand();
            CmdList.BeginRenderPass(mRenderPassDesc_HitProxy, mHitProxyView.FrameBuffer);
            mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_Opaque);
            mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_CustomOpaque);
            mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_CustomTranslucent);
            mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_Translucent);
            mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_Gizmos);
            CmdList.BuildRenderPass();
            CmdList.EndRenderPass();

            CmdList.CreateReadableTexture2D(ref HitProxyTex2D, mHitProxyView.FrameBuffer.GetSRV_RenderTarget(0), mHitProxyView.FrameBuffer);
            EngineNS.CEngine.Instance.GpuFetchManager.RegFetchTexture2D(HitProxyTex2D, (InSrv) =>
            {
                if (mHitProxyCPUTexture == null)
                {
                    mHitProxyCPUTexture = new CBlobObject();
                }
                if (CEngine.Instance.Desc.RHIType == ERHIType.RHT_OGL)
                {
                    var t1 = EngineNS.Support.Time.HighPrecision_GetTickCount();
                    unsafe
                    {
                        void *pData;
                        uint rowPitch;
                        uint depthPitch;
                        if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch))
                        {
                            lock (mHitProxyCPUTexture)
                            {
                                InSrv.BuildImageBlob(mHitProxyCPUTexture, pData, rowPitch);
                            }
                            InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0);
                        }
                        var t2 = EngineNS.Support.Time.HighPrecision_GetTickCount();
                        //System.Diagnostics.Debug.WriteLine($"Fetch hitproxy time : {t2 - t1}");
                    }
                }
                else
                {
                    CEngine.Instance.EventPoster.RunOn(() =>
                    {
                        var t1 = EngineNS.Support.Time.HighPrecision_GetTickCount();
                        unsafe
                        {
                            void *pData;
                            uint rowPitch;
                            uint depthPitch;
                            if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch))
                            {
                                lock (mHitProxyCPUTexture)
                                {
                                    InSrv.BuildImageBlob(mHitProxyCPUTexture, pData, rowPitch);
                                }
                                InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0);
                            }
                            var t2 = EngineNS.Support.Time.HighPrecision_GetTickCount();
                            //System.Diagnostics.Debug.WriteLine($"Fetch hitproxy time : {t2 - t1}");
                        }
                        return(null);
                    }, Thread.Async.EAsyncTarget.AsyncEditor);
                }
            });

            CmdList.EndCommand();

            ScopeTickLogic.End();
        }
コード例 #3
0
        public async System.Threading.Tasks.Task SaveToFile(string strFileName, long duration, int frame = 4)
        {
            mDuration = duration;
            mFrameNum = 1;// frame;
            mRP_Snapshot.OnAfterTickLogic = (InView, InRc, InCmd, InArg) =>
            {
                CTexture2D ReadableTex = null;
                InCmd.CreateReadableTexture2D(ref ReadableTex, mRP_Snapshot.BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0), mRP_Snapshot.BaseSceneView.FrameBuffer);
                EngineNS.CEngine.Instance.GpuFetchManager.RegFetchTexture2D(ReadableTex, (InSrv) =>
                {
                    var blob = new EngineNS.Support.CBlobObject();
                    unsafe
                    {
                        void *pData;
                        uint rowPitch;
                        uint depthPitch;
                        if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch))
                        {
                            InSrv.BuildImageBlob(blob, pData, rowPitch);
                            InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0);
                        }
                    }
                    EngineNS.CEngine.Instance.EventPoster.RunOn(() =>
                    {
                        var blbArray = new EngineNS.Support.CBlobObject[] { blob };
                        CShaderResourceView.SaveSnap(strFileName, blbArray);
                        return(true);
                    }, EngineNS.Thread.Async.EAsyncTarget.AsyncEditor);
                });
            };
            var rp = CEngine.Instance.GetCurrentModule().RenderPolicy as EngineNS.Graphics.RenderPolicy.CGfxRP_EditorMobile;

            if (rp != null)
            {
                lock (rp.mSnapshots)
                {
                    rp.mSnapshots.Add(this);
                }
            }
            //frame = 1;
            //await EngineNS.Thread.AsyncDummyClass.DummyFunc();
            //var rc = CEngine.Instance.RenderContext;

            //foreach (var actor in mWorld.Actors.Values)
            //{
            //    actor.PreUse(true);
            //}

            //CalculateCamera(mCamera, 1.0);

            //EngineNS.CEngine.Instance.TextureManager.PauseKickResource = true;
            //var saveTime = EngineNS.CEngine.Instance.EngineTime;
            //var saveElapse = EngineNS.CEngine.Instance.EngineElapseTime;
            //EngineNS.Support.CBlobObject[] data = new EngineNS.Support.CBlobObject[frame];
            //mRP_Snapshot.OnAfterTickLogic = (InView, InRc, InCmd, InArg) =>
            //{
            //    CTexture2D ReadableTex = null;
            //    InCmd.CreateReadableTexture2D(ref ReadableTex, mRP_Snapshot.BaseSceneView.FrameBuffer.GetSRV_RenderTarget(0), mRP_Snapshot.BaseSceneView.FrameBuffer);
            //    EngineNS.CEngine.Instance.GpuFetchManager.RegFetchTexture2D(ReadableTex, (InSrv) =>
            //    {
            //        //{
            //        //    var blob = new EngineNS.Support.CBlobObject();
            //        //    unsafe
            //        //    {
            //        //        void* pData;
            //        //        uint rowPitch;
            //        //        uint depthPitch;
            //        //        if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch))
            //        //        {
            //        //            InSrv.BuildImageBlob(blob, pData, rowPitch);
            //        //            InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0);
            //        //        }
            //        //    }
            //        //    bool bSave = true;
            //        //    if (bSave)
            //        //    {
            //        //        var blbArray = new EngineNS.Support.CBlobObject[] { blob };
            //        //        CShaderResourceView.SaveSnap(strFileName, blbArray);
            //        //    }
            //        //    return;
            //        //}
            //        if (InArg == null)
            //            InArg = (int)0;
            //        data[(int)InArg] = new EngineNS.Support.CBlobObject();

            //        var t1 = EngineNS.Support.Time.HighPrecision_GetTickCount();
            //        unsafe
            //        {
            //            void* pData;
            //            uint rowPitch;
            //            uint depthPitch;
            //            if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch))
            //            {
            //                InSrv.BuildImageBlob(data[(int)InArg], pData, rowPitch);
            //                InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0);
            //            }
            //        }
            //        var t2 = EngineNS.Support.Time.HighPrecision_GetTickCount();

            //        System.Diagnostics.Debug.WriteLine($"Fetch Snap time : {t2 - t1}");

            //        int finishCount = 0;
            //        foreach (var i in data)
            //        {
            //            if (i != null)
            //                finishCount++;
            //        }
            //        if (finishCount == data.Length)
            //        {
            //            EngineNS.CEngine.Instance.EventPoster.RunOn(() =>
            //            {
            //                CShaderResourceView.SaveSnap(strFileName, data);
            //                //foreach (var i in data)
            //                //{
            //                //    i.Dispose();
            //                //}
            //                //data = null;
            //                //System.GC.Collect();
            //                return true;
            //            }, EngineNS.Thread.Async.EAsyncTarget.AsyncEditor);
            //        }
            //        return;
            //    });
            //};
            //for (int i = 0; i < frame; i++)
            //{
            //    EngineNS.CEngine.Instance._UpdateEngineTime(saveTime + duration * i / frame);
            //    EngineNS.CEngine.Instance.SetPerFrameCBuffer();

            //    TickLogicEvent?.Invoke(this, i);
            //    mRP_Snapshot.TickSync();
            //    mRP_Snapshot.TickRender(null);

            //    TickLogicEvent?.Invoke(this, i);
            //    mRP_Snapshot.TickSync();
            //    mRP_Snapshot.TickRender(null);
            //}
            //EngineNS.CEngine.Instance._ResetTime(saveTime, saveElapse);
            //EngineNS.CEngine.Instance.SetPerFrameCBuffer();
            //EngineNS.CEngine.Instance.TextureManager.PauseKickResource = false;
            //mRP_Snapshot.OnAfterTickLogic = null;

            //FinalCleanup();
        }