コード例 #1
0
ファイル: Gorgon2D.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to prepare the renderer for 2D rendering.
        /// </summary>
        /// <returns>A state recall object that is used to recall the previous state before this method was called.</returns>
        /// <remarks>This method should be used to initialize a scene for 2D rendering.  When this method is called, it will return an object that contains the current state before this method was called.
        /// Use this state object with the <see cref="End2D"/> method to return the state back to the original settings.
        /// </remarks>
        public Gorgon2DStateRecall Begin2D()
        {
            var currentState = new Gorgon2DStateRecall(this);

            SetDefaultStates();

            return(currentState);
        }
コード例 #2
0
ファイル: Gorgon2D.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to end 2D rendering and restore the state of the graphics interface.
        /// </summary>
        /// <param name="state">[Optional] The state object that contains the states returned by the <see cref="Begin2D"/> method.</param>
        /// <remarks>This method is used to end 2D rendering and restore the state of the graphics API to the state recorded by the <paramref name="state"/> parameter.  If NULL (Nothing in VB.Net)
        /// is passed for the <paramref name="state"/> parameter, then the state will be reset to the state of the graphics interface before this renderer was created.
        /// </remarks>
        public void End2D(Gorgon2DStateRecall state = null)
        {
            _cache.Reset();

            if (state == null)
            {
                if (_initialState == null)
                {
                    return;
                }

                _initialState.Restore(false);
                _initialState = null;

                return;
            }

            // Reset the cache before updating the states.
            state.Restore(false);
        }
コード例 #3
0
ファイル: Gorgon2D.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to set up the renderers initial state.
        /// </summary>
        private void SetDefaultStates()
        {
            // Add shader includes if they're gone.
            if (!Graphics.Shaders.IncludeFiles.Contains("Gorgon2DShaders"))
            {
                Graphics.Shaders.IncludeFiles.Add("Gorgon2DShaders", Encoding.UTF8.GetString(Resources.BasicSprite));
            }

            // Record the initial state before set up.
            if (_initialState == null)
            {
                _initialState = new Gorgon2DStateRecall(this);
            }

            // Reset the cache values.
            _cache.Reset();

            // Set our default shaders.
            VertexShader.Current            = VertexShader.DefaultVertexShader;
            PixelShader.Current             = PixelShader.DefaultPixelShaderDiffuse;
            Graphics.Input.IndexBuffer      = DefaultIndexBuffer;
            Graphics.Input.VertexBuffers[0] = DefaultVertexBufferBinding;
            Graphics.Input.Layout           = DefaultLayout;
            Graphics.Input.PrimitiveType    = PrimitiveType.TriangleList;

            IsMultisamplingEnabled = Graphics.Rasterizer.States.IsMultisamplingEnabled;

            if (PixelShader != null)
            {
                GorgonTextureSamplerStates sampler = GorgonTextureSamplerStates.LinearFilter;
                sampler.TextureFilter = TextureFilter.Point;
                Graphics.Shaders.PixelShader.TextureSamplers[0] = sampler;
                Graphics.Shaders.PixelShader.Resources[0]       = null;
            }

            Graphics.Rasterizer.States                         = GorgonRasterizerStates.CullBackFace;
            Graphics.Output.BlendingState.States               = GorgonBlendStates.DefaultStates;
            Graphics.Output.DepthStencilState.States           = GorgonDepthStencilStates.NoDepthStencil;
            Graphics.Output.DepthStencilState.StencilReference = 0;
            Graphics.Output.SetRenderTarget(_defaultTarget.Target, _defaultTarget.DepthStencil);

            _currentTarget = _defaultTarget;

            UpdateTarget(ref _currentTarget);

            DefaultCamera.Update();

            // Get the current state.
            DefaultState = new Gorgon2DStateRecall(this);

            // By default, turn on multi sampling over a count of 1.
            if (Target.Resource.ResourceType != ResourceType.Texture2D)
            {
                return;
            }

            var target2D = (GorgonRenderTarget2D)Target.Resource;

            if ((!IsMultisamplingEnabled) &&
                ((target2D.Settings.Multisampling.Count > 1) || (target2D.Settings.Multisampling.Quality > 0)) &&
                ((Graphics.VideoDevice.SupportedFeatureLevel == DeviceFeatureLevel.SM4_1) ||
                 (Graphics.VideoDevice.SupportedFeatureLevel == DeviceFeatureLevel.SM5)))
            {
                _multiSampleEnable = true;
            }
        }
コード例 #4
0
ファイル: Gorgon2D.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // Dump any pending rendering.
                _cache.Reset();

                if (_initialState != null)
                {
                    _initialState.Restore(true);
                    _initialState = null;
                }

                TrackedObjects.ReleaseAll();

                if (Effects != null)
                {
                    Effects.FreeEffects();
                    Effects = null;
                }

                if (_currentTarget.SwapChain != null)
                {
                    _currentTarget.SwapChain.AfterSwapChainResized -= target_Resized;
                }

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

                if (VertexShader != null)
                {
                    VertexShader.CleanUp();
                }

                if (PixelShader != null)
                {
                    PixelShader.CleanUp();
                }

                VertexShader = null;
                PixelShader  = null;

                DefaultVertexBufferBinding.VertexBuffer.Dispose();

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

                if ((_systemCreatedTarget) && (_defaultTarget.Target != null))
                {
                    _defaultTarget.Target.Resource.Dispose();
                    _defaultTarget = default(Gorgon2DTarget);
                }

                Graphics.RemoveTrackedObject(this);
            }

            _disposed = true;
        }