Пример #1
0
        public void RunMainLoop(Control control)
        {
            using (var loop = new RenderLoop(control))
                while (loop.NextFrame())
                {
                    MainLoop(control.Size);
                }

            // main loop is done; release resources

            arrowDefault.Dispose();
            whiteDefault.Dispose();
            TextureManager.DisposeTextures();

            Cube.Dispose();
            Pyramid.Dispose();
            Cylinder.Dispose();
            Sphere.Dispose();
            Plane.Dispose();

            basicBuffer.Dispose();
            basicShader.Dispose();

            defaultBuffer.Dispose();
            defaultShader.Dispose();

            tintedBuffer.Dispose();
            tintedShader.Dispose();

            foreach (SharpMesh mesh in RenderWareModelFile.completeMeshList)
            {
                if (mesh != null)
                {
                    mesh.Dispose();
                }
            }

            foreach (var bf in completeVertexBufferList)
            {
                if (bf != null)
                {
                    bf.Dispose();
                }
            }

            device.Dispose();
        }
Пример #2
0
        public void RunMainLoop(Panel Panel)
        {
            RenderLoop.Run(Panel, () =>
            {
                //Resizing
                if (device.MustResize)
                {
                    device.Resize();
                    Camera.AspectRatio = (float)Panel.Width / Panel.Height;
                }

                Program.MainForm.KeyboardController();

                sharpFPS.Update();

                device.Clear(backgroundColor);

                if (ArchiveEditorFunctions.allowRender)
                {
                    if (isDrawingUI)
                    {
                        viewProjection = Matrix.OrthoOffCenterRH(0, 640, -480, 0, -Camera.FarPlane, Camera.FarPlane);

                        device.SetFillModeDefault();
                        device.SetCullModeDefault();
                        device.ApplyRasterState();
                        device.SetBlendStateAlphaBlend();
                        device.SetDefaultDepthState();
                        device.UpdateAllStates();

                        foreach (IRenderableAsset a in
                                 (from IRenderableAsset asset in ArchiveEditorFunctions.renderableAssets
                                  where (asset is AssetUI || asset is AssetUIFT) && asset.ShouldDraw(this)
                                  select(IClickableAsset) asset).OrderBy(f => - f.PositionZ))
                        {
                            a.Draw(this);
                        }
                    }
                    else
                    {
                        if (playingFly)
                        {
                            flyToPlay.Play();
                        }

                        Program.MainForm.SetToolStripStatusLabel(Camera.ToString() + " FPS: " + $"{sharpFPS.FPS:0.0000}");

                        Matrix view    = Camera.ViewMatrix;
                        viewProjection = view * Camera.ProjectionMatrix;
                        frustum        = new BoundingFrustum(view * Camera.BiggerFovProjectionMatrix);

                        device.SetFillModeDefault();
                        device.SetCullModeDefault();
                        device.ApplyRasterState();
                        device.SetDefaultDepthState();
                        device.UpdateAllStates();

                        foreach (var a in ArchiveEditorFunctions.renderableJSPs)
                        {
                            if (a.ShouldDraw(this))
                            {
                                a.Draw(this);
                            }
                        }

                        foreach (IRenderableAsset a in ArchiveEditorFunctions.renderableAssets)
                        {
                            if (a.ShouldDraw(this))
                            {
                                renderableAssets.Add(a);
                            }
                            else
                            {
                                renderableAssets.Remove(a);
                            }
                        }

                        //foreach (IRenderableAsset a in renderableAssets.OrderByDescending(a => a.GetDistanceFrom(Camera.Position)))
                        //    a.Draw(this);

                        HashSet <IRenderableAsset> renderableAssetsTrans = new HashSet <IRenderableAsset>();

                        foreach (IRenderableAsset a in renderableAssets)
                        {
                            if (a.SpecialBlendMode)
                            {
                                renderableAssetsTrans.Add(a);
                            }
                            else
                            {
                                a.Draw(this);
                            }
                        }

                        foreach (IRenderableAsset a in renderableAssetsTrans.OrderByDescending(a => a.GetDistanceFrom(Camera.Position)))
                        {
                            a.Draw(this);
                        }
                    }
                }

                device.SetCullModeNone();
                device.ApplyRasterState();
                device.SetBlendStateAlphaBlend();
                device.UpdateAllStates();

                ArchiveEditorFunctions.RenderGizmos(this);

                device.Present();
            });

            //release resources
            whiteDefault.Dispose();
            TextureManager.DisposeTextures();

            Cube.Dispose();
            Pyramid.Dispose();
            Cylinder.Dispose();
            Sphere.Dispose();
            Plane.Dispose();

            basicBuffer.Dispose();
            basicShader.Dispose();

            defaultBuffer.Dispose();
            defaultShader.Dispose();

            tintedBuffer.Dispose();
            tintedShader.Dispose();

            foreach (SharpMesh mesh in RenderWareModelFile.completeMeshList)
            {
                if (mesh != null)
                {
                    mesh.Dispose();
                }
            }

            foreach (var bf in completeVertexBufferList)
            {
                if (bf != null)
                {
                    bf.Dispose();
                }
            }

            device.Dispose();
        }