コード例 #1
0
ファイル: Game.cs プロジェクト: TheStolenBattenberg/Psycpros
        //
        // Game Set up area
        //
        protected override void OnLoad(EventArgs e)
        {
            // Output some OpenGL and System info
            Console.WriteLine("Renderer: " + GL.GetString(StringName.Renderer));
            Console.WriteLine("OpGL Version: " + GL.GetString(StringName.Version));
            Console.WriteLine("GLSL Version: " + GL.GetString(StringName.ShadingLanguageVersion));
            Console.WriteLine("");

            //Create new camera
            pCamera = new CCamera(new Vector4(0.0f, 0.0f, Width, Height), Vector3.UnitY);
            pCamera.SetPosition(new Vector3(16.0f, 512.0f, 0.0f));
            pCamera.SetDirection(new Vector3(1.0f, 0.0f, 1.0f));

            //Create Primitives (testing);
            Rectangle2D = new CPrimitiveRectangle(64.0f, 64.0f, new Vector4(1.0f, 0.0f, 0.0f, 1.0f));

            //Load a TIM Texture. This is threaded.
            pTexture = new CTextureTGA("Resource\\Texture\\page5.TGA");

            //Load a map
            pMap = new CMap();
            pMap.LoadTileset(TilesetFormat.TMD, "Resource\\Tileset\\coast.tmd");
            pMap.LoadKF("Resource\\Map\\coast.map");
            pMap.LoadKFItem("Resource\\Map\\coast.idb");
        }
コード例 #2
0
        public void RegFetchTexture2D(CTexture2D tex, FOnGpuFinished cb)
        {
            for (int i = 0; i < WaitGpuFinishResources.Count; i++)
            {
                if (WaitGpuFinishResources[i].Texture2D == tex)
                {
                    return;
                }
            }

            var state = new FetchState();

            state.Texture2D     = tex;
            state.OnGpuFinished = cb;
            state.TickFrame     = 4;
            WaitGpuFinishResources.Add(state);
        }
コード例 #3
0
ファイル: SceneDataSM3.cs プロジェクト: huangdonghai/titan3d
        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);
                }
            }
        }
コード例 #4
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);
        }
コード例 #5
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();
        }