/// <summary> /// Function to save the state information to this object. /// </summary> private void Save() { _targets = _graphics.Output.GetRenderTargets(); _uavs = _graphics.Output.GetUnorderedAccessViews(); _indexBuffer = _graphics.Input.IndexBuffer; _vertexBuffer = _graphics.Input.VertexBuffers[0]; _inputLayout = _graphics.Input.Layout; _primitiveType = _graphics.Input.PrimitiveType; _pixelShader = _graphics.Shaders.PixelShader.Current; _vertexShader = _graphics.Shaders.VertexShader.Current; _blendStates = _graphics.Output.BlendingState.States; _blendFactor = _graphics.Output.BlendingState.BlendFactor; _blendSampleMask = _graphics.Output.BlendingState.BlendSampleMask; _rasterStates = _graphics.Rasterizer.States; _samplerState = _graphics.Shaders.PixelShader.TextureSamplers[0]; _resource = _graphics.Shaders.PixelShader.Resources[0]; _depthStencilState = _graphics.Output.DepthStencilState.States; _depthStencilReference = _graphics.Output.DepthStencilState.StencilReference; _rasterStates.IsScissorTestingEnabled = false; _depthStencil = _graphics.Output.DepthStencilView; _viewports = _graphics.Rasterizer.GetViewports(); _scissorTests = _graphics.Rasterizer.GetScissorRectangles(); _alphaTest = new Gorgon2DAlphaTest(Gorgon2D.IsAlphaTestEnabled, GorgonRangeF.Empty); _vsConstantBuffers = new Dictionary <int, GorgonConstantBuffer>(); _psConstantBuffers = new Dictionary <int, GorgonConstantBuffer>(); // Only store the constant buffers that we were using. // We need to store all the constant buffers because the effects // make use of multiple constant slots. Unlike the resource views, // where we know that we're only using the first item (all bets are // off if a user decides to use another resource view slot), there's no // guarantee that we'll be only using 1 or 2 constant buffer slots. for (int i = 0; i < _graphics.Shaders.VertexShader.ConstantBuffers.Count; i++) { if (_graphics.Shaders.VertexShader.ConstantBuffers[i] != null) { _vsConstantBuffers[i] = _graphics.Shaders.VertexShader.ConstantBuffers[i]; } } for (int i = 0; i < _graphics.Shaders.PixelShader.ConstantBuffers.Count; i++) { if (_graphics.Shaders.PixelShader.ConstantBuffers[i] != null) { _psConstantBuffers[i] = _graphics.Shaders.PixelShader.ConstantBuffers[i]; } } }
/// <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; } }