Implements abstract Geometry Buffer
Inheritance: IDisposable
Exemplo n.º 1
0
        private void DrawGeometry(GeometryBuffer buffer, PointF position, float depth)
        {
            if (isSpriteRenderInProgress)
            {
                spriteBatch.End();
            }

            FNAGeometryBuffer monoGameBuffer = buffer as FNAGeometryBuffer;
            GraphicsDevice device = GraphicsDevice;

            RasterizerState rasState = device.RasterizerState;
            BlendState blendState = device.BlendState;
            DepthStencilState stencilState = device.DepthStencilState;

            device.BlendState = BlendState.AlphaBlend;
            device.DepthStencilState = DepthStencilState.DepthRead;

            if (isClipped)
            {
                device.RasterizerState = clippingRasterizeState;
            }
            else
            {
                device.RasterizerState = rasterizeStateGeometry;
            }

            basicEffect.World = Matrix.CreateTranslation(position.X, position.Y, depth);
            basicEffect.View = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up);
            basicEffect.Projection = Matrix.CreateOrthographicOffCenter(0, (float)device.Viewport.Width, (float)device.Viewport.Height, 0, 1.0f, 1000.0f);

            device.SetVertexBuffer(monoGameBuffer.VertexBuffer);
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                switch (buffer.PrimitiveType)
                {
                    case GeometryPrimitiveType.TriangleList:
                        device.DrawPrimitives(PrimitiveType.TriangleList, 0, monoGameBuffer.PrimitiveCount);
                        break;
                    case GeometryPrimitiveType.TriangleStrip:
                        device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, monoGameBuffer.PrimitiveCount);
                        break;
                    case GeometryPrimitiveType.LineList:
                        device.DrawPrimitives(PrimitiveType.LineList, 0, monoGameBuffer.PrimitiveCount);
                        break;
                    case GeometryPrimitiveType.LineStrip:
                        device.DrawPrimitives(PrimitiveType.LineStrip, 0, monoGameBuffer.PrimitiveCount);
                        break;
                    default:
                        break;
                }
            }

            device.DepthStencilState = stencilState;
            device.BlendState = blendState;
            device.RasterizerState = rasState;

            if (isSpriteRenderInProgress)
            {
                if (isClipped)
                {
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, clippingRasterizeState, effect: currentActiveEffect);
                }
                else
                {
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, currentActiveEffect);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws the color of the geometry.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="position">The position.</param>
        /// <param name="color">The color.</param>
        /// <param name="opacity">The opacity.</param>
        /// <param name="depth">The depth.</param>
        public override void DrawGeometryColor(GeometryBuffer buffer, PointF position, ColorW color, float opacity, float depth)
        {
            if (basicEffect == null)
            {
                basicEffect = new BasicEffect(GraphicsDevice);
            }

            basicEffect.Alpha = color.A / (float)byte.MaxValue * opacity;
            //color = color * effect.Alpha;
            basicEffect.DiffuseColor = new Vector3(color.R / (float)byte.MaxValue, color.G / (float)byte.MaxValue, color.B / (float)byte.MaxValue);
            basicEffect.TextureEnabled = false;
            basicEffect.VertexColorEnabled = true;

            DrawGeometry(buffer, position, depth);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draws the geometry texture.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="position">The position.</param>
        /// <param name="texture">The texture.</param>
        /// <param name="opacity">The opacity.</param>
        /// <param name="depth">The depth.</param>
        public override void DrawGeometryTexture(GeometryBuffer buffer, PointF position, TextureBase texture, float opacity, float depth)
        {
            if (basicEffect == null)
            {
                basicEffect = new BasicEffect(GraphicsDevice);
            }

            basicEffect.Alpha = opacity;
            basicEffect.DiffuseColor = new Vector3(1, 1, 1);
            basicEffect.Texture = texture.GetNativeTexture() as Texture2D;
            basicEffect.VertexColorEnabled = false;
            basicEffect.TextureEnabled = true;

            DrawGeometry(buffer, position, depth);
        }
Exemplo n.º 4
0
        private void DrawGeometry(GeometryBuffer buffer, PointF position, float depth)
        {
            if (isSpriteRenderInProgress)
            {
                spriteBatch.End();
            }

            Matrix world = Matrix.Translation(position.X, position.Y, 0);

            Matrix worldView;
            Matrix.MultiplyTo(ref world, ref view, out worldView);

            Matrix worldViewProjection;
            UpdateProjection(graphicsContext.CommandList);
            Matrix.MultiplyTo(ref worldView, ref projection, out worldViewProjection);

            XenkoGeometryBuffer paradoxBuffer = buffer as XenkoGeometryBuffer;
            paradoxBuffer.EffectInstance.Parameters.Set(SpriteBaseKeys.MatrixTransform, worldViewProjection);
            paradoxBuffer.EffectInstance.Apply(graphicsContext);

            if (isClipped)
            {
                geometryPipelineState.State.RasterizerState = scissorRasterizerStateDescription;
            }
            else
            {
                geometryPipelineState.State.RasterizerState = geometryRasterizerStateDescription;
            }

            switch (buffer.PrimitiveType)
            {
                case GeometryPrimitiveType.TriangleList:
                    geometryPipelineState.State.PrimitiveType = PrimitiveType.TriangleList;
                    break;
                case GeometryPrimitiveType.TriangleStrip:
                    geometryPipelineState.State.PrimitiveType = PrimitiveType.TriangleStrip;
                    break;
                case GeometryPrimitiveType.LineList:
                    geometryPipelineState.State.PrimitiveType = PrimitiveType.LineList;
                    break;
                case GeometryPrimitiveType.LineStrip:
                    geometryPipelineState.State.PrimitiveType = PrimitiveType.LineStrip;
                    break;
                default:
                    break;
            }

            geometryPipelineState.State.RootSignature = paradoxBuffer.EffectInstance.RootSignature;
            geometryPipelineState.State.EffectBytecode = paradoxBuffer.EffectInstance.Effect.Bytecode;
            geometryPipelineState.State.InputElements = paradoxBuffer.InputElementDescriptions;
            geometryPipelineState.State.Output.CaptureState(graphicsContext.CommandList);
            geometryPipelineState.Update();
            graphicsContext.CommandList.SetPipelineState(geometryPipelineState.CurrentState);

            graphicsContext.CommandList.SetVertexBuffer(0, paradoxBuffer.VertexBufferBinding.Buffer, 0, paradoxBuffer.VertexBufferBinding.Stride);
            graphicsContext.CommandList.Draw(paradoxBuffer.PrimitiveCount);

            if (isSpriteRenderInProgress)
            {
                if (isClipped)
                {
                    spriteBatch.Begin(graphicsContext, SpriteSortMode.Deferred,
                        depthStencilState: DepthStencilStates.None, rasterizerState: scissorRasterizerStateDescription, effect: currentActiveEffect);
                }
                else
                {
                    spriteBatch.Begin(graphicsContext, SpriteSortMode.Deferred, depthStencilState: DepthStencilStates.None, effect: currentActiveEffect);
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Draws the geometry texture.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="position">The position.</param>
 /// <param name="texture">The texture.</param>
 /// <param name="opacity">The opacity.</param>
 /// <param name="depth">The depth.</param>
 public override void DrawGeometryTexture(GeometryBuffer buffer, PointF position, TextureBase texture, float opacity, float depth)
 {
     XenkoGeometryBuffer paradoxBuffer = buffer as XenkoGeometryBuffer;
     Texture2D nativeTexture = texture.GetNativeTexture() as Texture2D;
     paradoxBuffer.EffectInstance.Parameters.Set(SpriteEffectKeys.Color, Color.White * opacity);
     paradoxBuffer.EffectInstance.Parameters.Set(TexturingKeys.Texture0, nativeTexture);
     DrawGeometry(buffer, position, depth);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Draws the color of the geometry.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="position">The position.</param>
        /// <param name="color">The color.</param>
        /// <param name="opacity">The opacity.</param>
        /// <param name="depth">The depth.</param>
        public override void DrawGeometryColor(GeometryBuffer buffer, PointF position, ColorW color, float opacity, float depth)
        {
            XenkoGeometryBuffer xenkoBuffer = buffer as XenkoGeometryBuffer;

            Color4 nativeColor = new Color4(color.PackedValue) * opacity;
            xenkoBuffer.EffectInstance.Parameters.Set(SpriteEffectKeys.Color, nativeColor);
            xenkoBuffer.EffectInstance.Parameters.Set(TexturingKeys.Texture0, GraphicsDevice.GetSharedWhiteTexture());
            DrawGeometry(buffer, position, depth);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Draws the geometry texture.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="position">The position.</param>
 /// <param name="texture">The texture.</param>
 /// <param name="opacity">The opacity.</param>
 /// <param name="depth">The depth.</param>
 public abstract void DrawGeometryTexture(GeometryBuffer buffer, PointF position, TextureBase texture, float opacity, float depth);
Exemplo n.º 8
0
 /// <summary>
 /// Draws the color of the geometry.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="position">The position.</param>
 /// <param name="color">The color.</param>
 /// <param name="opacity">The opacity.</param>
 /// <param name="depth">The depth.</param>
 public abstract void DrawGeometryColor(GeometryBuffer buffer, PointF position, ColorW color, float opacity, float depth);