コード例 #1
0
        internal static void UnloadContent(bool removeObjects = true)
        {
            MyRender.Log.WriteLine("MyRender.UnloadContent - START");
            MyRender.Log.IncreaseIndent();

            UnloadContent_Video();

            foreach (var ro in m_renderObjects)
            {
                ro.Value.UnloadContent();
            }

            foreach (var renderComponent in m_renderComponents.Reverse())
            {
                renderComponent.Value.UnloadContent();
            }

            for (int i = 0; i < m_renderTargets.GetLength(0); i++)
            {
                DisposeRenderTarget((MyRenderTargets)i);
            }

            DisposeSpotShadowRT();

            if (m_randomTexture != null)
            {
                m_randomTexture.Dispose();
                m_randomTexture = null;
            }

            UnloadEffects();

            Clear();

            if (m_fullscreenQuad != null)
            {
                m_fullscreenQuad.Dispose();
                m_fullscreenQuad = null;
            }

            MyTextureManager.UnloadTexture(BlankTexture);
            MyRenderTexturePool.ReleaseResources();

            if (m_spriteBatch != null)
            {
                m_spriteBatch.Dispose();
                m_spriteBatch = null;
            }

            if (DefaultSurface != null)
            {
                DefaultSurface.Dispose();
                DefaultSurface = null;
            }
            if (DefaultDepth != null)
            {
                DefaultDepth.Dispose();
                DefaultDepth = null;
            }

            try
            {
                if (GraphicsDevice != null)
                {
                    GraphicsDevice.SetStreamSource(0, null, 0, 0);
                    GraphicsDevice.Indices      = null;
                    GraphicsDevice.PixelShader  = null;
                    GraphicsDevice.VertexShader = null;
                    for (int i = 0; i < 16; i++)
                    {
                        GraphicsDevice.SetTexture(i, null);
                    }

                    GraphicsDevice.EvictManagedResources();
                }
                GraphicsDevice = null;
            }
            catch (Exception e)
            {
                //Because of crash on Win8
                Log.WriteLine(e);
            }

            MyRender.Log.DecreaseIndent();
            MyRender.Log.WriteLine("MyRender.UnloadContent - END");
        }
コード例 #2
0
        /// <summary>
        /// Called when graphics resources need to be unloaded. Override this method to unload any game-specific graphics resources.
        /// </summary>
        public override void UnloadContent()
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMinerGame::UnloadContent");
            MyMwcLog.WriteLine("MyMinerGame.UnloadContent() - START");
            MyMwcLog.IncreaseIndent();

            if (m_debugFont != null)
            {
                m_debugFont.Dispose();
                m_debugFont = null;
            }

            if (DefaultSurface != null)
            {
                DefaultSurface.Dispose();
                DefaultSurface = null;
            }
            if (DefaultDepth != null)
            {
                DefaultDepth.Dispose();
                DefaultDepth = null;
            }

            // GUI
            MyGuiManager.UnloadContent();

            MyRender.UnloadContent();

            MyTextureManager.UnloadContent();
            MyModels.UnloadContent();

            // Global content
            //Content.Unload();

            // Render
            MySunGlare.UnloadContent();

            MyDebugDrawCachedLines.UnloadContent();
            MyDebugDraw.UnloadContent();

            //MyRender.UnloadContent(); //it is unloaded in gui gameplay screen

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyMinerGame.UnloadContent() - END");

            GraphicsDevice.SetStreamSource(0, null, 0, 0);
            GraphicsDevice.Indices           = null;
            GraphicsDevice.VertexDeclaration = null;
            GraphicsDevice.PixelShader       = null;
            GraphicsDevice.VertexShader      = null;
            for (int i = 0; i < 16; i++)
            {
                GraphicsDevice.SetTexture(i, null);
            }

            base.UnloadContent();

            GC.Collect();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }