示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonPoint"/> class.
 /// </summary>
 /// <param name="gorgon2D">Gorgon interface that owns this renderable.</param>
 /// <param name="name">The name of the point.</param>
 internal GorgonPoint(Gorgon2D gorgon2D, string name)
     : base(name)
 {
     CullingMode   = CullingMode.Back;
     Gorgon2D      = gorgon2D;
     _depthState   = new GorgonRenderable.DepthStencilStates();
     _blendState   = new GorgonRenderable.BlendState();
     _samplerState = new GorgonRenderable.TextureSamplerState();
     _vertices     = new []
     {
         new Gorgon2DVertex
         {
             Position = new Vector4(0, 0, 0, 1.0f)
         },
         new Gorgon2DVertex
         {
             Position = new Vector4(0, 0, 0, 1.0f)
         },
         new Gorgon2DVertex
         {
             Position = new Vector4(0, 0, 0, 1.0f)
         },
         new Gorgon2DVertex
         {
             Position = new Vector4(0, 0, 0, 1.0f)
         }
     };
 }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonDrawing"/> class.
        /// </summary>
        /// <param name="gorgon2D">The gorgon 2D interface that owns this object.</param>
        internal GorgonDrawing(Gorgon2D gorgon2D)
        {
            _depthStencil = new GorgonRenderable.DepthStencilStates();
            _sampler      = new GorgonRenderable.TextureSamplerState();
            _blend        = new GorgonRenderable.BlendState();

            // Default to modulated blending for drawing operations.
            BlendingMode = BlendingMode.Modulate;

            CullingMode = CullingMode.Back;

            _rect = new GorgonRectangle(gorgon2D, "Gorgon2D.Rectangle", false)
            {
                Position = Vector2.Zero,
                Size     = Vector2.Zero
            };
            _point = new GorgonPoint(gorgon2D, "Gorgon2D.Point")
            {
                Position = Vector2.Zero,
                Color    = GorgonColor.White
            };
            _line = new GorgonLine(gorgon2D, "Gorgon2D.Line")
            {
                Color      = GorgonColor.White,
                StartPoint = Vector2.Zero,
                EndPoint   = Vector2.Zero
            };
            _ellipse = new GorgonEllipse(gorgon2D, "Gorgon2D.Ellipse")
            {
                Quality = 64,
                Color   = GorgonColor.White
            };
            _triangle = new GorgonTriangle(gorgon2D,
                                           "Gorgon2D.Triangle")
            {
                IsFilled = false
            };
            _string = gorgon2D.Renderables.CreateText("Gorgon2D.String");
        }
示例#3
0
        /// <summary>
        /// Function to determine what state changes are proposed by the current renderable.
        /// </summary>
        /// <param name="renderable">The renderable to test.</param>
        /// <returns>The states that require changes.</returns>
        internal StateChange Compare(IRenderable renderable)
        {
            var result = StateChange.None;

            GorgonRenderable.DepthStencilStates  depthStencil = renderable.DepthStencil;
            GorgonRenderable.BlendState          blending     = renderable.Blending;
            GorgonRenderable.TextureSamplerState sampler      = renderable.TextureSampler;
            GorgonShaderView textureView = null;

            var alphaTest = new Gorgon2DAlphaTest(Gorgon2D.IsAlphaTestEnabled, renderable.AlphaTestValues);

            // Get the current texture view.
            if (renderable.Texture != null)
            {
                textureView = renderable.Texture;
            }

            // Ensure that the stored resource is up to date.  If it's been changed outside of the
            // state management, then we can have issues (text does this).
            if ((textureView != _resource) ||
                (_resource != Gorgon2D.PixelShader.Resources[0]))
            {
                result |= StateChange.Texture;
            }

            if (Gorgon2D.IsBlendingEnabled == _blendStates.RenderTarget0.IsBlendingEnabled)
            {
                // If blending is enabled, then track the blending changes.
                if (Gorgon2D.IsBlendingEnabled)
                {
                    if (!blending.BlendFactor.Equals(ref _blendFactor))
                    {
                        result |= StateChange.BlendFactor;
                    }

                    if ((blending.SourceBlend != _blendStates.RenderTarget0.SourceBlend) ||
                        (blending.DestinationBlend != _blendStates.RenderTarget0.DestinationBlend) ||
                        (blending.AlphaOperation != _blendStates.RenderTarget0.AlphaOperation) ||
                        (blending.BlendOperation != _blendStates.RenderTarget0.BlendingOperation) ||
                        (blending.SourceAlphaBlend != _blendStates.RenderTarget0.SourceAlphaBlend) ||
                        (blending.DestinationAlphaBlend != _blendStates.RenderTarget0.DestinationAlphaBlend) ||
                        (blending.WriteMask != _blendStates.RenderTarget0.WriteMask))
                    {
                        result |= StateChange.BlendState;
                    }
                }
            }
            else
            {
                result |= StateChange.BlendState;
            }

            if ((sampler.TextureFilter != _samplerState.TextureFilter) ||
                (sampler.VerticalWrapping != _samplerState.VerticalAddressing) ||
                (sampler.HorizontalWrapping != _samplerState.HorizontalAddressing) ||
                (!sampler.BorderColor.Equals(ref _samplerState.BorderColor)))
            {
                result |= StateChange.Sampler;
            }

            if (((Gorgon2D.ClipRegion != null) != (_rasterStates.IsScissorTestingEnabled)) ||
                (renderable.DepthStencil.DepthBias != _rasterStates.DepthBias) ||
                (renderable.CullingMode != _rasterStates.CullingMode) ||
                (Gorgon2D.IsMultisamplingEnabled != _rasterStates.IsMultisamplingEnabled))
            {
                result |= StateChange.Raster;
            }

            if (renderable.PrimitiveType != _graphics.Input.PrimitiveType)
            {
                result |= StateChange.PrimitiveType;
            }

            if (renderable.IndexBuffer != _graphics.Input.IndexBuffer)
            {
                result |= StateChange.IndexBuffer;
            }

            if (!renderable.VertexBufferBinding.Equals(ref _vertexBuffer))
            {
                result |= StateChange.VertexBuffer;
            }

            if (!Gorgon2DAlphaTest.Equals(ref _alphaTest, ref alphaTest))
            {
                result |= StateChange.AlphaTest;
            }

            if (depthStencil.StencilReference != _depthStencilReference)
            {
                result |= StateChange.DepthStencilReference;
            }

            if ((Gorgon2D.IsDepthBufferEnabled != _depthStencilState.IsDepthEnabled) ||
                (Gorgon2D.IsStencilEnabled != _depthStencilState.IsStencilEnabled))
            {
                result |= StateChange.DepthStencil;
            }
            else
            {
                if ((Gorgon2D.IsDepthBufferEnabled) &&
                    (depthStencil.IsDepthWriteEnabled != _depthStencilState.IsDepthWriteEnabled) ||
                    (depthStencil.DepthComparison != _depthStencilState.DepthComparison))
                {
                    result |= StateChange.DepthStencil;
                }

                if ((Gorgon2D.IsStencilEnabled) &&
                    ((_depthStencilState.StencilReadMask != depthStencil.StencilReadMask) ||
                     (_depthStencilState.StencilWriteMask != depthStencil.StencilWriteMask) ||
                     (_depthStencilState.StencilFrontFace.ComparisonOperator != depthStencil.FrontFace.ComparisonOperator) ||
                     (_depthStencilState.StencilFrontFace.DepthFailOperation != depthStencil.FrontFace.DepthFailOperation) ||
                     (_depthStencilState.StencilFrontFace.FailOperation != depthStencil.FrontFace.FailOperation) ||
                     (_depthStencilState.StencilFrontFace.PassOperation != depthStencil.FrontFace.PassOperation) ||
                     (_depthStencilState.StencilBackFace.ComparisonOperator != depthStencil.BackFace.ComparisonOperator) ||
                     (_depthStencilState.StencilBackFace.DepthFailOperation != depthStencil.BackFace.DepthFailOperation) ||
                     (_depthStencilState.StencilBackFace.FailOperation != depthStencil.BackFace.FailOperation) ||
                     (_depthStencilState.StencilBackFace.PassOperation != depthStencil.BackFace.PassOperation)))
                {
                    result |= StateChange.DepthStencil;
                }
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// Function to apply any state changes.
        /// </summary>
        /// <param name="renderable">Renderable object to retrieve states from.</param>
        /// <param name="state">States that need updating.</param>
        internal void UpdateState(IRenderable renderable, StateChange state)
        {
            GorgonRenderable.DepthStencilStates  depthStencil = renderable.DepthStencil;
            GorgonRenderable.BlendState          blending     = renderable.Blending;
            GorgonRenderable.TextureSamplerState sampler      = renderable.TextureSampler;

            if ((state & StateChange.Texture) == StateChange.Texture)
            {
                _resource = _graphics.Shaders.PixelShader.Resources[0] = renderable.Texture;

                // If we have a texture change, and we have the default diffuse shader loaded, then switch to the textured shader, otherwise
                // switch to the diffuse shader.
                Gorgon2D.PixelShader.TextureSwitch(renderable.Texture);
            }

            if ((state & StateChange.BlendFactor) == StateChange.BlendFactor)
            {
                _blendFactor = blending.BlendFactor;
                _graphics.Output.BlendingState.BlendFactor = blending.BlendFactor;
            }

            if ((state & StateChange.BlendState) == StateChange.BlendState)
            {
                _blendStates.RenderTarget0.IsBlendingEnabled     = Gorgon2D.IsBlendingEnabled;
                _blendStates.RenderTarget0.AlphaOperation        = blending.AlphaOperation;
                _blendStates.RenderTarget0.BlendingOperation     = blending.BlendOperation;
                _blendStates.RenderTarget0.DestinationAlphaBlend = blending.DestinationAlphaBlend;
                _blendStates.RenderTarget0.DestinationBlend      = blending.DestinationBlend;
                _blendStates.RenderTarget0.SourceAlphaBlend      = blending.SourceAlphaBlend;
                _blendStates.RenderTarget0.SourceBlend           = blending.SourceBlend;
                _blendStates.RenderTarget0.WriteMask             = blending.WriteMask;
                _graphics.Output.BlendingState.States            = _blendStates;
            }

            if ((state & StateChange.Sampler) == StateChange.Sampler)
            {
                _samplerState.HorizontalAddressing = sampler.HorizontalWrapping;
                _samplerState.VerticalAddressing   = sampler.VerticalWrapping;
                _samplerState.BorderColor          = sampler.BorderColor;
                _samplerState.TextureFilter        = sampler.TextureFilter;
                _graphics.Shaders.PixelShader.TextureSamplers[0] = _samplerState;
            }

            if ((state & StateChange.Raster) == StateChange.Raster)
            {
                _rasterStates.IsScissorTestingEnabled = Gorgon2D.ClipRegion != null;
                _rasterStates.CullingMode             = renderable.CullingMode;
                _rasterStates.IsMultisamplingEnabled  = Gorgon2D.IsMultisamplingEnabled;
                _rasterStates.DepthBias     = depthStencil.DepthBias;
                _graphics.Rasterizer.States = _rasterStates;
            }

            if ((state & StateChange.PrimitiveType) == StateChange.PrimitiveType)
            {
                _primitiveType = _graphics.Input.PrimitiveType = renderable.PrimitiveType;
            }

            if ((state & StateChange.IndexBuffer) == StateChange.IndexBuffer)
            {
                _indexBuffer = _graphics.Input.IndexBuffer = renderable.IndexBuffer;
            }

            if ((state & StateChange.VertexBuffer) == StateChange.VertexBuffer)
            {
                _vertexBuffer = _graphics.Input.VertexBuffers[0] = renderable.VertexBufferBinding;
            }

            if ((state & StateChange.AlphaTest) == StateChange.AlphaTest)
            {
                _alphaTest = new Gorgon2DAlphaTest(Gorgon2D.IsAlphaTestEnabled, renderable.AlphaTestValues);
                Gorgon2D.PixelShader.AlphaTestValuesBuffer.Update(ref _alphaTest);
            }

            if ((state & StateChange.DepthStencilReference) == StateChange.DepthStencilReference)
            {
                _depthStencilReference = _graphics.Output.DepthStencilState.StencilReference = depthStencil.StencilReference;
            }

            if ((state & StateChange.DepthStencil) != StateChange.DepthStencil)
            {
                return;
            }

            _depthStencilState.IsDepthEnabled      = Gorgon2D.IsDepthBufferEnabled;
            _depthStencilState.IsDepthWriteEnabled = depthStencil.IsDepthWriteEnabled;
            _depthStencilState.DepthComparison     = depthStencil.DepthComparison;
            _depthStencilState.StencilReadMask     = depthStencil.StencilReadMask;
            _depthStencilState.StencilWriteMask    = depthStencil.StencilWriteMask;
            _depthStencilState.IsStencilEnabled    = Gorgon2D.IsStencilEnabled;
            _depthStencilState.StencilFrontFace.ComparisonOperator = depthStencil.FrontFace.ComparisonOperator;
            _depthStencilState.StencilFrontFace.DepthFailOperation = depthStencil.FrontFace.DepthFailOperation;
            _depthStencilState.StencilFrontFace.FailOperation      = depthStencil.FrontFace.FailOperation;
            _depthStencilState.StencilFrontFace.PassOperation      = depthStencil.FrontFace.PassOperation;
            _depthStencilState.StencilBackFace.ComparisonOperator  = depthStencil.BackFace.ComparisonOperator;
            _depthStencilState.StencilBackFace.DepthFailOperation  = depthStencil.BackFace.DepthFailOperation;
            _depthStencilState.StencilBackFace.FailOperation       = depthStencil.BackFace.FailOperation;
            _depthStencilState.StencilBackFace.PassOperation       = depthStencil.BackFace.PassOperation;
            _graphics.Output.DepthStencilState.States = _depthStencilState;
        }