Inheritance: GraphicsResource
        public override void Draw(GameTime gameTime)
        {
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            rs.FillMode = FillMode.WireFrame;
            this.device.RasterizerState = rs;

            Viewport viewport = this.device.Viewport;
            this.defaultEfft.World = Matrix.CreateTranslation(new Vector3(-this.witdth/2, -this.heigh/2, -100.0f));
            this.defaultEfft.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                              viewport.AspectRatio,
                                                                              5.0f,
                                                                              200.0f);

            foreach (EffectPass pass in this.defaultEfft.CurrentTechnique.Passes)
            {
                pass.Apply();
                foreach (VertexPositionColor[] row in this.pointMatrics)
                {
                    this.device.DrawUserPrimitives(PrimitiveType.TriangleStrip,
                                                row, 0, row.Length - 2,
                                                VertexPositionColor.VertexDeclaration);
                }

            }
            base.Draw(gameTime);
        }
Example #2
0
        /// <summary>
        /// Begins a new sprite and text batch with the specified render state.
        /// </summary>
        /// <param name="sortMode">The drawing order for sprite and text drawing. <see cref="SpriteSortMode.Deferred"/> by default.</param>
        /// <param name="blendState">State of the blending. Uses <see cref="BlendState.AlphaBlend"/> if null.</param>
        /// <param name="samplerState">State of the sampler. Uses <see cref="SamplerState.LinearClamp"/> if null.</param>
        /// <param name="depthStencilState">State of the depth-stencil buffer. Uses <see cref="DepthStencilState.None"/> if null.</param>
        /// <param name="rasterizerState">State of the rasterization. Uses <see cref="RasterizerState.CullCounterClockwise"/> if null.</param>
        /// <param name="effect">A custom <see cref="Effect"/> to override the default sprite effect. Uses default sprite effect if null.</param>
        /// <param name="transformMatrix">An optional matrix used to transform the sprite geometry. Uses <see cref="Matrix.Identity"/> if null.</param>
        /// <exception cref="InvalidOperationException">Thrown if <see cref="Begin"/> is called next time without previous <see cref="End"/>.</exception>
        /// <remarks>This method uses optional parameters.</remarks>
        /// <remarks>The <see cref="Begin"/> Begin should be called before drawing commands, and you cannot call it again before subsequent <see cref="End"/>.</remarks>
        public void Begin
        (
             SpriteSortMode sortMode = SpriteSortMode.Deferred,
             BlendState blendState = null,
             SamplerState samplerState = null,
             DepthStencilState depthStencilState = null,
             RasterizerState rasterizerState = null,
             Effect effect = null,
             Matrix? transformMatrix = null
        )
        {
            if (_beginCalled)
                throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");

            // defaults
            _sortMode = sortMode;
            _blendState = blendState ?? BlendState.AlphaBlend;
            _samplerState = samplerState ?? SamplerState.LinearClamp;
            _depthStencilState = depthStencilState ?? DepthStencilState.None;
            _rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise;
            _effect = effect;
            _matrix = transformMatrix ?? Matrix.Identity;

            // Setup things now so a user can change them.
            if (sortMode == SpriteSortMode.Immediate)
            {
                Setup();
            }

            _beginCalled = true;
        }
Example #3
0
        public override void Draw(GameTime gameTime)
        {
            var rs = new RasterizerState();
            rs.CullMode = CullMode.CullCounterClockwiseFace;
            GraphicsDevice.RasterizerState = rs;

            Matrix[] modelTransforms = new Matrix[_skyDome.Bones.Count];
            _skyDome.CopyAbsoluteBoneTransformsTo(modelTransforms);

            Matrix wMatrix = Matrix.CreateTranslation(0, -0.3f, 0) * Matrix.CreateScale(100) * Matrix.CreateTranslation(_game.Camera.Position);
            foreach (ModelMesh mesh in _skyDome.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    Matrix worldMatrix = modelTransforms[mesh.ParentBone.Index] * wMatrix;
                    currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
                    currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
                    currentEffect.Parameters["xView"].SetValue(_game.Camera.View);
                    currentEffect.Parameters["xProjection"].SetValue(_game.Camera.Projection);
                    currentEffect.Parameters["xTexture"].SetValue(_cloudMap);
                    currentEffect.Parameters["xEnableLighting"].SetValue(false);
                }
                mesh.Draw();
            }

            rs = new RasterizerState();
            rs.CullMode = CullMode.CullClockwiseFace;
            GraphicsDevice.RasterizerState = rs;

            base.Draw(gameTime);
        }
Example #4
0
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            if (karoGame.KaroGameManager == null ||
                !(karoGame.KaroGameManager.CurrentState is ComputerState))
            {
                // Not loading, stop execution.
                return;
            }

            RasterizerState rs = new RasterizerState();
            rs.DepthBias = -10f;
            RasterizerState rsold = Game.GraphicsDevice.RasterizerState;
            Game.GraphicsDevice.RasterizerState = rs;
            foreach (ModelMesh mesh in _beachBall.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.View = _view;
                    effect.Projection = _projection;
                    effect.World = Matrix.CreateRotationZ(1.5f) *
                        Matrix.CreateRotationX(_rotation) *
                        Matrix.CreateTranslation(_position) *
                        Matrix.CreateTranslation(_offset);
                }
                mesh.Draw();
            }
            Game.GraphicsDevice.RasterizerState = rsold;
        }
 public DefaultLightContext(
     Texture2D deferredColorMap, 
     Texture2D deferredNormalMap,
     Texture2D deferredDepthMap, 
     Texture2D deferredSpecularMap,
     RenderTarget2D diffuseLightRenderTarget,
     RenderTarget2D specularLightRenderTarget,
     BlendState lightBlendState,
     RasterizerState rasterizerStateCullNone,
     RasterizerState rasterizerStateCullClockwiseFace, 
     RasterizerState rasterizerStateCullCounterClockwiseFace, 
     Vector2 halfPixel)
 {
     DeferredColorMap = deferredColorMap;
     DeferredNormalMap = deferredNormalMap;
     DeferredDepthMap = deferredDepthMap;
     DeferredSpecularMap = deferredSpecularMap;
     DiffuseLightRenderTarget = diffuseLightRenderTarget;
     SpecularLightRenderTarget = specularLightRenderTarget;
     LightBlendState = lightBlendState;
     RasterizerStateCullNone = rasterizerStateCullNone;
     RasterizerStateCullClockwiseFace = rasterizerStateCullClockwiseFace;
     RasterizerStateCullCounterClockwiseFace = rasterizerStateCullCounterClockwiseFace;
     HalfPixel = halfPixel;
 }
Example #6
0
        public override void Draw(Camera camera)
        {
            graphicsDevice.SetVertexBuffer(particleVertexBuffer);
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            graphicsDevice.RasterizerState = rs;

            if (endOfLiveParticlesIndex - endOfDeadParticlesIndex > 0)
            {
                for (int i = endOfDeadParticlesIndex; i < endOfLiveParticlesIndex; ++i)
                {
                    particleEffect.Parameters["WorldViewProjection"].SetValue(
                        camera.view * camera.projection);
                    particleEffect.Parameters["particleColor"].SetValue(
                        vertexColorArray[i].ToVector4());

                    foreach (EffectPass pass in particleEffect.CurrentTechnique.Passes)
                    {
                        pass.Apply();

                        graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, verts, i * 4, 2);
                    }
                }
            }
        }
Example #7
0
        protected override void Draw(GameTime gameTime)
        {
            RasterizerState rasterizerState1 = new RasterizerState();
            rasterizerState1.CullMode = CullMode.None;
            rasterizerState1.FillMode = FillMode.WireFrame; // for å se kun streker av trekanten
            //rasterizerState1.FillMode = FillMode.Solid; // for å fylle med hel farge
            device.RasterizerState = rasterizerState1;

            device.Clear(Color.Black);

            // Setter world
            world = Matrix.Identity;
            // Setter world-matrisa på effect-objektet (verteks-shaderen)
            effect.World = world;

            // Starter tegning - må bruke effect-objektet
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                // Angir primitivtype, aktuelle vertekser, en offsetverdi og antall
                // primitiver (her 1 siden verteksene beskriver en trekant)
                device.DrawUserPrimitives(PrimitiveType.TriangleStrip, sider, 0, 8, VertexPositionColor.VertexDeclaration);
                device.DrawUserPrimitives(PrimitiveType.TriangleStrip, topp, 0, 2, VertexPositionColor.VertexDeclaration);
                device.DrawUserPrimitives(PrimitiveType.TriangleStrip, bunn, 0, 2, VertexPositionColor.VertexDeclaration);

            }

            base.Draw(gameTime);
        }
Example #8
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            GraphicsDevice.RasterizerState = rs;

            // camera
            camera = new Camera(this, new Vector3(0, 0, 5));
            Components.Add(camera);

            verts = new[]
                {
                    new VertexPositionColor(new Vector3(0, 1, 0), Color.Blue),
                    new VertexPositionColor(new Vector3(1, -1, 0), Color.Red),
                    new VertexPositionColor(new Vector3(-1, -1, 0), Color.Green)
                };

               vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor),
               verts.Length, BufferUsage.None);

            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionTexture),
                verts.Length, BufferUsage.None);
               vertexBuffer.SetData(verts);

            // effect
            effect = new BasicEffect(GraphicsDevice);
        }
        protected override void Draw(GameTime gameTime)
        {
            float time = (float)gameTime.TotalGameTime.TotalMilliseconds / 100.0f;
            RasterizerState rs = new RasterizerState();
            if (_geometryAndSettings.WireFramesOnly)
            {
                rs.FillMode = FillMode.WireFrame;
            }
            rs.CullMode = CullMode.None; // CullCounterClockwiseFace;

            _geometryAndSettings.device.RasterizerState = rs;

            DrawRefractionMap();
            DrawReflectionMap();

            Color bgColor = new Color(0.94140625f, 0.7421875f, 0.21484375f);

            _geometryAndSettings.device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, bgColor, 1.0f, 0);

            DrawSkyDome(_geometryAndSettings.viewMatrix);

            DrawTerrain(_geometryAndSettings.viewMatrix);

            DrawWater(time / 10);

            base.Draw(gameTime);
        }
Example #10
0
        public void drawBigbuffer(DrawabeElement element, int[] index, Camera came, GraphicsDevice graphicsDevice, bool trans)
        {
            WIREFRAME_RASTERIZER_STATE = new RasterizerState() { CullMode = CullMode.CullClockwiseFace, FillMode = FillMode.Solid };

            graphicsDevice.RasterizerState = WIREFRAME_RASTERIZER_STATE;

            // draw in wireframe

            if (trans)
            {
                graphicsDevice.BlendState = BlendState.AlphaBlend;

            }
            else
            {
                graphicsDevice.BlendState = BlendState.Opaque;
            }

            graphicsDevice.DepthStencilState = DepthStencilState.Default;

            //   effect.DiffuseColor = Color.Red.ToVector3();
            element.effect.View = came.getview();
            element.effect.CurrentTechnique.Passes[0].Apply();
            // vb.GetData<VertexPositionNormalTexture>(vertexData);

            graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, element.vpc, 0, element.vpc.Count() / 3);
            // graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, vertexData.Count(), index, 0, index.Count() / 3);
        }
Example #11
0
        /// <summary>
        /// Inicializa os componentes da camara
        /// </summary>
        /// <param name="graphics">Instância de GraphicsDevice</param>
        public static void Initialize(GraphicsDevice graphics)
        {
            //Posição inicial da camâra
            position = new Vector3(0, 3, 15);
            //Inicializar as matrizes world, view e projection
            World = Matrix.Identity;
            UpdateViewMatrix();
            Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45),
                graphics.Viewport.AspectRatio,
                nearPlane,
                farPlane);

            //Criar e definir o resterizerState a utilizar para desenhar a geometria
            RasterizerState rasterizerState = new RasterizerState();
            //Desenha todas as faces, independentemente da orientação
            rasterizerState.CullMode = CullMode.None;
            //rasterizerState.FillMode = FillMode.WireFrame;
            rasterizerState.MultiSampleAntiAlias = true;
            graphics.RasterizerState = rasterizerState;

            //Coloca o rato no centro do ecrã
            Mouse.SetPosition(graphics.Viewport.Width / 2, graphics.Viewport.Height / 2);

            originalMouseState = Mouse.GetState();
        }
        public override void Draw()
        {
            MilkShake.Graphics.SamplerStates[0] = new SamplerState()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Wrap
            };

            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            rs.FillMode = (KeyboardInput.isKeyDown(Keys.LeftShift)) ? FillMode.WireFrame : FillMode.Solid;
            rs.MultiSampleAntiAlias = true;
            MilkShake.Graphics.RasterizerState = rs;

            _effect.TextureEnabled = true;
            _effect.Texture = _texture.Texture;
            _effect.LightingEnabled = false;
            _effect.VertexColorEnabled = false;

            foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                foreach (VertexPositionTexture[] currentQuad in _renderVerticies.Values)
                {
                    MilkShake.GraphicsManager.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, currentQuad, 0, 2, VertexPositionTexture.VertexDeclaration);
                }
            }

            base.Draw();
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            mDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);

            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            mDevice.RasterizerState = rs;

            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(Matrix.Identity);
            effect.Parameters["xTexture"].SetValue(mTerrain.getTexture());

            effect.CurrentTechnique = effect.Techniques["Textured"];
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                mTerrain.draw(mDevice);
            }

            effect.CurrentTechnique = effect.Techniques["Colored"];
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                mXWing.draw(viewMatrix, projectionMatrix);
                mTable.draw(viewMatrix, projectionMatrix);
                mSkydome.draw(viewMatrix, projectionMatrix);
            }

            base.Draw(gameTime);
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            device.Clear(Color.Black);
            RasterizerState rasterizerState1 = new RasterizerState();
            rasterizerState1.CullMode = CullMode.None;
            rasterizerState1.FillMode = FillMode.WireFrame;
            device.RasterizerState = rasterizerState1;

            //Setter world=I:
            world = Matrix.Identity;
            // Setter world-matrisa på effect-objektet (verteks-shaderen):
            effect.World = world;

            //Starter tegning - må bruke effect-objektet:
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                // Angir primitivtype, aktuelle vertekser, en offsetverdi og antall
                // primitiver (her 1 siden verteksene beskriver en trekant):
                //Trekant fra Trekant1
                device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1, VertexPositionColor.VertexDeclaration);
                //2 enkle linjer
                device.DrawUserPrimitives(PrimitiveType.LineList, linelist, 0, 1);
                device.DrawUserPrimitives(PrimitiveType.LineList, linelist2, 0, 1);
                //3 sammenhengende linjer
                device.DrawUserPrimitives(PrimitiveType.LineStrip, linestrip, 0, 3);
                //Trekant
                device.DrawUserPrimitives(PrimitiveType.TriangleStrip, trianglestrip, 0, 3);
            }

            base.Draw(gameTime);
        }
Example #15
0
        public GdxSpriteBatch(GraphicsDevice graphicsDevice)
        {
            if (graphicsDevice == null)
                throw new ArgumentNullException("graphicsDevice");

            _device = graphicsDevice;

            _spriteEffect = new LocalSpriteEffect(graphicsDevice);
            _matrixTransform = _spriteEffect.Parameters["MatrixTransform"];
            _spritePass = _spriteEffect.CurrentTechnique.Passes[0];

            _transformMatrix = Matrix.Identity;
            //_projectionMatrix = Matrix.CreateOrthographicOffCenter(0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 0, 1);
            _projectionMatrix = XnaExt.Matrix.CreateOrthographic2D(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, -1, 0);

            Color = Color.White;

            CalculateIndexBuffer();

            _rasterizerScissorState = new RasterizerState() {
                CullMode = CullMode.None,
                ScissorTestEnable = true,
            };

            // projection uses CreateOrthographicOffCenter to create 2d projection
            // matrix with 0,0 in the upper left.
            /*_basicEffect.Projection = Matrix.CreateOrthographicOffCenter
                (0, graphicsDevice.Viewport.Width,
                graphicsDevice.Viewport.Height, 0,
                0, 1);
            this._basicEffect.World = Matrix.Identity;
            this._basicEffect.View = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward,
                Vector3.Up);*/
        }
        protected override void LoadContent()
        {
            map = new TiledMap(Content, "Content/HacksoiContent/test.tmx", "HacksoiContent/");

            graphics.PreferredBackBufferWidth = map.Map.Width * map.Map.TileWidth;
            graphics.PreferredBackBufferHeight = map.Map.Height * map.Map.TileHeight;
            graphics.ApplyChanges();
            centerWindow();
            
            cameraPosition = Vector2.Zero;
            screenCenter = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2f, graphics.GraphicsDevice.Viewport.Height / 2f);
            batch = new SpriteBatch(graphics.GraphicsDevice);

            basicEffect = new BasicEffect(graphics.GraphicsDevice);
            basicEffect.Projection = Matrix.CreateOrthographic(graphics.GraphicsDevice.Viewport.Width, -graphics.GraphicsDevice.Viewport.Height, 0.1f, 1000f);
            basicEffect.View = Matrix.Identity;
            basicEffect.World = Matrix.Identity;
            basicEffect.TextureEnabled = true;

            rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;

            font = Content.Load<SpriteFont>("Font");

            LoadWorld();
        }
Example #17
0
File: Game1.cs Project: scy7he/Pong
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            collisionSystem = new CollisionSystemPersistentSAP();
            collisionSystem.CollisionDetected += new CollisionDetectedHandler(CollisionDetected);

            world = new World(collisionSystem);

            Random rr = new Random();
            rndColors = new Color[20];
            for (int i = 0; i < 20; i++)
            {
                rndColors[i] = new Color((float)rr.NextDouble(), (float)rr.NextDouble(), (float)rr.NextDouble());
            }

            wireframe = new RasterizerState();
            wireframe.FillMode = FillMode.WireFrame;

            cullMode = new RasterizerState();
            cullMode.CullMode = CullMode.None;

            normal = new RasterizerState();
        }
Example #18
0
        public override void DrawAll(GameTime gameTime)
        {
            device.Clear(Color.DarkSlateBlue);

            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            rs.FillMode = FillMode.Solid;
            device.RasterizerState = rs;

            effect.TextureEnabled = true;

            effect.World = Matrix.Identity;

            effect.View = viewMatrix;
            effect.Projection = projectionMatrix;

            effect.LightingEnabled = true;
            effect.EnableDefaultLighting();

            device.SetVertexBuffer(vertexBuffer);

            UpdateCamera();

            DrawBall();
            DrawStaticWorld();
            DrawSky();

            drawBonuses();
            DrawBallData();

            base.Draw(gameTime);
        }
Example #19
0
        public void Draw(Camera camera)
        {
            //Sets the CullMode to none and blendstate to additive (Explosions have a black background)
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            _device.RasterizerState = rs;
            _device.BlendState = BlendState.Additive;

            foreach (Explosion explosion in _explosionList)
            {
                switch (explosion.ExplosionType)
                {
                    case ExplosionType.Big:
                        _textureQuad.SetTexture(explosion.Index);
                        _textureQuad.Draw(camera, explosion.Position);
                        break;
                    case ExplosionType.Small:
                        _smallTextureQuad.SetTexture(explosion.Index);
                        _smallTextureQuad.Draw(camera, explosion.Position);
                        break;
                }
            }

            //Resets the state of the BlendState and Rasterizer State
            RasterizerState rs2 = new RasterizerState();
            rs2.CullMode = CullMode.CullCounterClockwiseFace;
            _device.RasterizerState = rs2;
            _device.BlendState = BlendState.NonPremultiplied;
        }
Example #20
0
        /// <summary>
        /// Starts the specified batch.
        /// </summary>
        /// <param name="batch">The batch.</param>
        /// <param name="useCamera">if set to <c>true</c> camera matrix will be applied.</param>
        /// <param name="sortMode">The sort mode.</param>
        /// <param name="blendState">State of the blend.</param>
        /// <param name="samplerState">State of the sampler.</param>
        /// <param name="depthStencilState">State of the depth stencil.</param>
        /// <param name="rasterizerState">State of the rasterizer.</param>
        /// <param name="effect">The effect.</param>
        /// <param name="transform">The transformation matrix.</param>
        public static void Start(this SpriteBatch batch,
            bool useCamera = false,
            SpriteSortMode sortMode = SpriteSortMode.Deferred,
            BlendState blendState = null,
            SamplerState samplerState = null,
            DepthStencilState depthStencilState = null,
            RasterizerState rasterizerState = null,
            Effect effect = null,
            Matrix? transform = null)
        {
            Matrix matrix = AlmiranteEngine.IsWinForms ? Matrix.Identity : AlmiranteEngine.Settings.Resolution.Matrix;

            if (useCamera)
            {
                matrix = AlmiranteEngine.Camera.Matrix * matrix;
            }

            if (transform.HasValue)
            {
                matrix = transform.Value * matrix;
            }

            BatchExtensions._sortMode = sortMode;
            BatchExtensions._blendState = blendState;
            BatchExtensions._samplerState = samplerState;
            BatchExtensions._depthStencilState = depthStencilState;
            BatchExtensions._rasterizerState = rasterizerState;
            BatchExtensions._effect = effect;
            BatchExtensions._matrix = matrix;

            batch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, matrix);
        }
Example #21
0
 static HighlightModule()
 {
     var color = Color.Black;
     CubeVerticies = new[]
     {
         new VertexPositionColor(new XVector3(0, 0, 1), color),
         new VertexPositionColor(new XVector3(1, 0, 1), color),
         new VertexPositionColor(new XVector3(1, 1, 1), color),
         new VertexPositionColor(new XVector3(0, 1, 1), color),
         new VertexPositionColor(new XVector3(0, 0, 0), color),
         new VertexPositionColor(new XVector3(1, 0, 0), color),
         new VertexPositionColor(new XVector3(1, 1, 0), color),
         new VertexPositionColor(new XVector3(0, 1, 0), color)
     };
     CubeIndicies = new short[]
     {
         0, 1,   1, 2,   2, 3,   3, 0,
         0, 4,   4, 7,   7, 6,   6, 2,
         1, 5,   5, 4,   3, 7,   6, 5
     };
     DestructionBlendState = new BlendState
     {
         ColorSourceBlend = Blend.DestinationColor,
         ColorDestinationBlend = Blend.SourceColor,
         AlphaSourceBlend = Blend.DestinationAlpha,
         AlphaDestinationBlend = Blend.SourceAlpha
     };
     RasterizerState = new RasterizerState
     {
         DepthBias = -3,
         SlopeScaleDepthBias = -3
     };
 }
Example #22
0
        public void Draw()
        {
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            rs.FillMode = FillMode.Solid;
            device.RasterizerState = rs;

            worldMatrix = Matrix.CreateTranslation(-terrainWidth / 2.0f, 0, terrainHeight / 2.0f) * (Matrix.CreateRotationY(angle2));

            effect.CurrentTechnique = effect.Techniques["Colored"];
            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(worldMatrix);
            Vector3 lightDirection = new Vector3(1.0f, -1.0f, -1.0f);
            lightDirection.Normalize();
            effect.Parameters["xLightDirection"].SetValue(lightDirection);
            effect.Parameters["xAmbient"].SetValue(0.1f);
            effect.Parameters["xEnableLighting"].SetValue(true); 

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.Indices = myIndexBuffer;
                device.SetVertexBuffer(myVertexBuffer);
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
            }
        }
Example #23
0
 protected UIStaticInfo()
 {
     scissorDisabledState = new RasterizerState();
     scissorEnabledState = new RasterizerState();
     scissorEnabledState.ScissorTestEnable = true;
     spriteBatch = new SpriteBatch(UIManager.Instance.mainDevice);
 }
Example #24
0
        /// <summary>
        /// Public constructor.
        /// </summary>
        /// <param name="terrainSize">The size of the terrain.</param>
        /// <param name="blockSize">The size of a single block. The terrain size should be dividable by it.</param>
        /// <param name="maxDepth">The maximum division depth for the quad trees.</param>
        /// <param name="name">The name of the entity.</param>
        public Terrain(Vector2 terrainSize, float blockSize, int maxDepth, string name = "Terrain")
            : base(name)
        {
            if (_terrainSize.X % blockSize > 0.0f)
            {
                throw new Exception("The width of the terrain size is not dividable by the block size.");
            }
            if (_terrainSize.Y % blockSize > 0.0f)
            {
                throw new Exception("The height of the terrain size is not dividable by the block size.");
            }

            _terrainSize = terrainSize;
            _blockSize = blockSize;
            _maxDepth = maxDepth;

            DebugEnabled = false;
            _rasterizerState = new RasterizerState
            {
                CullMode = CullMode.CullCounterClockwiseFace,
                FillMode = FillMode.Solid
            };
            _debugRasterizerState = new RasterizerState
            {
                CullMode = CullMode.CullCounterClockwiseFace,
                FillMode = FillMode.WireFrame
            };
        }
Example #25
0
        private void DrawModel(Model m)
        {
            Matrix[] transforms = new Matrix[m.Bones.Count];
            float aspectRatio = Context.Graphics.Device.Viewport.AspectRatio;
            m.CopyAbsoluteBoneTransformsTo(transforms);
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
            Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 2.0f, 10f), Vector3.Zero, Vector3.Up);

            var state = new RasterizerState();
            state.CullMode = CullMode.None;
            Context.Graphics.Device.RasterizerState = state;

            foreach (ModelMesh mesh in m.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.DiffuseColor = new Vector3(1, 1, 1);

                    effect.View = view;
                    effect.Projection = projection;
                    effect.World = Matrix.Identity * transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position) * Matrix.CreateRotationY(MathHelper.ToRadians(angle));
                }

                mesh.Draw();
            }
        }
Example #26
0
        public void DrawBlocks()
        {
            //GraphicsD.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            GraphicsD.RasterizerState = rs;

            effect.CurrentTechnique = effect.Techniques["Textured"];
            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(worldMatrix);

            Vector3 lightDirection = new Vector3(0f, 0f, .35f);
            effect.Parameters["xAmbient"].SetValue(.3f);
            effect.Parameters["xLightDirection"].SetValue(Vector3.Transform(lightDirection, worldMatrix));
            effect.Parameters["xEnableLighting"].SetValue(true);
            effect.Parameters["xTexture"].SetValue(PassedTexture);
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

            GraphicsD.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, BlockLocations.Length * 12, VertexPositionNormalTexture.VertexDeclaration);
            }
            mousestate = Mouse.GetState();
            if (mousestate.RightButton == ButtonState.Pressed)
            {
            }
        }
        /// <summary>
        /// Load content for the screen.
        /// </summary>
        /// <param name="GraphicInfo"></param>
        /// <param name="factory"></param>
        /// <param name="contentManager"></param>
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);
            
            ///Uncoment to add your model
            SimpleModel simpleModel = new SimpleModel(factory, "Model/cenario");
            ///Physic info (position, rotation and scale are set here)
            TriangleMeshObject tmesh = new TriangleMeshObject(simpleModel, Vector3.Zero, Matrix.Identity, Vector3.One, MaterialDescription.DefaultBepuMaterial());
            ///Forward Shader (look at this shader construction for more info)
            ForwardXNABasicShader shader = new ForwardXNABasicShader();
            ///Forward material
            ForwardMaterial fmaterial = new ForwardMaterial(shader);
            ///The object itself
            IObject obj = new IObject(fmaterial, simpleModel, tmesh);
            ///Add to the world
            this.World.AddObject(obj);

            this.RenderTechnic.AddPostEffect(MotionBlurPostEffect);
            this.RenderTechnic.AddPostEffect(BloomPostEffect);

            BloomPostEffect.Enabled = false;
            MotionBlurPostEffect.Enabled = false;

            blurdefault = MotionBlurPostEffect.Amount;

            RotatingCamera cam = new RotatingCamera(this, new Vector3(0,-100,-400));
            
            this.World.CameraManager.AddCamera(cam);

            RasterizerState = new RasterizerState();
            RasterizerState.CullMode = CullMode.None;
        }
Example #28
0
        internal EffectPass(    Effect effect, 
                                string name,
                                Shader vertexShader, 
                                Shader pixelShader, 
                                BlendState blendState, 
                                DepthStencilState depthStencilState, 
                                RasterizerState rasterizerState,
                                EffectAnnotationCollection annotations )
        {
            Debug.Assert(effect != null, "Got a null effect!");
            Debug.Assert(annotations != null, "Got a null annotation collection!");

            _effect = effect;

            Name = name;

            _vertexShader = vertexShader;
            _pixelShader = pixelShader;

            _blendState = blendState;
            _depthStencilState = depthStencilState;
            _rasterizerState = rasterizerState;

            Annotations = annotations;
        }
Example #29
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // ����������ڱ�
            // This particular cube model has the surfaces of the cube facing outwards.
            RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState;
            RasterizerState rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;
            graphics.GraphicsDevice.RasterizerState = rasterizerState;

            skybox.Draw(view, projection, cameraPosition);

            graphics.GraphicsDevice.RasterizerState = originalRasterizerState;

            DrawModelWithEffect(model, world, view, projection);

            // RasterizerState ��ֻ������, ���������淽���ı�
            // graphics.GraphicsDevice.RasterizerState.CullMode = CullMode.CullClockwiseFace;
            // skybox.Draw(view, projection, cameraPosition);
            // graphics.GraphicsDevice.RasterizerState.CullMode = CullMode.CullCounterClockwiseFace;
            // DrawModelWithEffect(model, world, view, projection);

            base.Draw(gameTime);
        }
        public override void Draw(GameTime gameTime)
        {
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            device.RasterizerState = rs;

            viewMatrix = Game1.Instance.Camera.getView();
            projectionMatrix = Game1.Instance.Camera.getProjection();

            Matrix worldMatrix = Matrix.Identity;
            effect.CurrentTechnique = effect.Techniques["Colored"];
            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(worldMatrix);
            Vector3 lightDirection = new Vector3(1.0f, -1.0f, -1.0f);
            lightDirection.Normalize();
            effect.Parameters["xLightDirection"].SetValue(lightDirection);
            effect.Parameters["xAmbient"].SetValue(0.1f);
            effect.Parameters["xEnableLighting"].SetValue(true);

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                device.Indices = myIndexBuffer;
                device.SetVertexBuffer(myVertexBuffer);
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
            }

            base.Draw(gameTime);
        }
Example #31
0
        public void Enable()
        {
            var rasterizerState = new X.RasterizerState()
            {
                CullMode             = desc.cullMode,
                FillMode             = desc.fillMode,
                MultiSampleAntiAlias = desc.multisampleEnable
            };

            video.Device.RasterizerState = rasterizerState;
        }
Example #32
0
        public void RenderShadowMaps(Camera camera)
        {
            Microsoft.Xna.Framework.Graphics.RasterizerState originalState    = this.main.GraphicsDevice.RasterizerState;
            Microsoft.Xna.Framework.Graphics.RasterizerState reverseCullState = new Microsoft.Xna.Framework.Graphics.RasterizerState {
                CullMode = Microsoft.Xna.Framework.Graphics.CullMode.CullClockwiseFace
            };

            this.main.GraphicsDevice.RasterizerState = reverseCullState;

            this.shadowMapIndices.Clear();

            if (this.maxShadowedSpotLights > 0)
            {
                // Collect spot lights
                foreach (SpotLight light in SpotLight.All)
                {
                    if (light.Enabled && !light.Suspended && light.Shadowed && light.Attenuation > 0.0f && camera.BoundingFrustum.Intersects(light.BoundingFrustum))
                    {
                        float score = (light.Position.Value - camera.Position.Value).LengthSquared() / light.Attenuation;
                        if (score < LightingManager.lightShadowThreshold)
                        {
                            this.spotLightEntries.Add(new LightEntry <SpotLight> {
                                Light = light, Score = score
                            });
                        }
                    }
                }
                this.spotLightEntries.Sort(this.spotLightComparer);

                // Render spot shadow maps
                for (int i = 0; i < this.spotLightEntries.Count; i++)
                {
                    LightEntry <SpotLight> entry = this.spotLightEntries[i];
                    this.shadowMapIndices[entry.Light] = i;
                    this.RenderSpotShadowMap(entry.Light, i);
                    if (i >= this.maxShadowedSpotLights - 1)
                    {
                        break;
                    }
                }
                this.spotLightEntries.Clear();
            }

            this.main.GraphicsDevice.RasterizerState = originalState;

            // Render global shadow map
            if (this.EnableGlobalShadowMap && this.globalShadowLight != null)
            {
                this.RenderGlobalShadowMap(camera);
            }
        }
Example #33
0
 /// <summary>
 /// Binds the implementation. This is called the first time an unbound state is set to the device or manually by the user in order to
 /// create the underlying state ahead of time (best practice). Once called the state properties are read-only.
 /// </summary>
 public override void BindRasterizerState()
 {
     if (!base.IsBound)
     {
         _rasterizerState                      = new XFG.RasterizerState();
         _rasterizerState.CullMode             = XNAHelper.ToXNACullMode(base.Cull, base.VertexWinding);
         _rasterizerState.DepthBias            = base.DepthBias;
         _rasterizerState.FillMode             = XNAHelper.ToXNAFillMode(base.Fill);
         _rasterizerState.MultiSampleAntiAlias = base.EnableMultiSampleAntiAlias;
         _rasterizerState.ScissorTestEnable    = base.EnableScissorTest;
         _rasterizerState.SlopeScaleDepthBias  = base.SlopeScaledDepthBias;
         base.IsBound = true;
     }
 }
Example #34
0
        private void defualtStates()
        {
            var rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();

            rasterizerState.CullMode             = CullMode.None;
            rasterizerState.FillMode             = FillMode.Solid;
            rasterizerState.MultiSampleAntiAlias = false;
            rasterizerState.ScissorTestEnable    = false;
            Device.RasterizerState = rasterizerState;

            var samplerStates = new Microsoft.Xna.Framework.Graphics.SamplerState();

            samplerStates.Filter    = TextureFilter.Linear;
            Device.SamplerStates[0] = samplerStates;
        }
Example #35
0
        public void RenderShadowMaps(Camera camera)
        {
            Microsoft.Xna.Framework.Graphics.RasterizerState originalState    = this.main.GraphicsDevice.RasterizerState;
            Microsoft.Xna.Framework.Graphics.RasterizerState reverseCullState = new Microsoft.Xna.Framework.Graphics.RasterizerState {
                CullMode = Microsoft.Xna.Framework.Graphics.CullMode.CullClockwiseFace
            };

            this.main.GraphicsDevice.RasterizerState = reverseCullState;

            this.shadowMapIndices.Clear();

            // Collect spot lights
            List <SpotLight> shadowedSpotLights = new List <SpotLight>();

            foreach (SpotLight light in SpotLight.All)
            {
                if (light.Enabled && !light.Suspended && light.Shadowed && light.Attenuation > 0.0f && camera.BoundingFrustum.Intersects(light.BoundingFrustum))
                {
                    shadowedSpotLights.Add(light);
                }
            }
            shadowedSpotLights = shadowedSpotLights.Select(x => new { Light = x, Score = (x.Position.Value - camera.Position.Value).LengthSquared() / x.Attenuation }).Where(x => x.Score < LightingManager.lightShadowThreshold).OrderBy(x => x.Score).Take(this.maxShadowedSpotLights).Select(x => x.Light).ToList();

            // Render spot shadow maps
            int index = 0;

            foreach (SpotLight light in shadowedSpotLights)
            {
                this.shadowMapIndices[light] = index;
                this.RenderSpotShadowMap(light, index);
                index++;
            }

            this.main.GraphicsDevice.RasterizerState = originalState;

            // Render global shadow map
            if (this.EnableGlobalShadowMap && this.globalShadowLight != null)
            {
                this.RenderGlobalShadowMap(camera);
            }
        }
Example #36
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders)
        {
            Shader vertexShader = (Shader)null;
            Shader pixelShader  = (Shader)null;
            EffectPassCollection effectPassCollection = new EffectPassCollection();
            int num = (int)reader.ReadByte();

            for (int index1 = 0; index1 < num; ++index1)
            {
                string name = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int index2 = (int)reader.ReadByte();
                if (index2 != (int)byte.MaxValue)
                {
                    vertexShader = shaders[index2];
                }
                int index3 = (int)reader.ReadByte();
                if (index3 != (int)byte.MaxValue)
                {
                    pixelShader = shaders[index3];
                }
                BlendState        blendState        = (BlendState)null;
                DepthStencilState depthStencilState = (DepthStencilState)null;
                RasterizerState   rasterizerState   = (RasterizerState)null;
                if (reader.ReadBoolean())
                {
                    blendState = new BlendState()
                    {
                        AlphaBlendFunction    = (BlendFunction)reader.ReadByte(),
                        AlphaDestinationBlend = (Blend)reader.ReadByte(),
                        AlphaSourceBlend      = (Blend)reader.ReadByte(),
                        BlendFactor           = new Color((int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte()),
                        ColorBlendFunction    = (BlendFunction)reader.ReadByte(),
                        ColorDestinationBlend = (Blend)reader.ReadByte(),
                        ColorSourceBlend      = (Blend)reader.ReadByte(),
                        ColorWriteChannels    = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels1   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels2   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels3   = (ColorWriteChannels)reader.ReadByte(),
                        MultiSampleMask       = reader.ReadInt32()
                    }
                }
                ;
                if (reader.ReadBoolean())
                {
                    depthStencilState = new DepthStencilState()
                    {
                        CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFail            = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFunction        = (CompareFunction)reader.ReadByte(),
                        CounterClockwiseStencilPass            = (StencilOperation)reader.ReadByte(),
                        DepthBufferEnable      = reader.ReadBoolean(),
                        DepthBufferFunction    = (CompareFunction)reader.ReadByte(),
                        DepthBufferWriteEnable = reader.ReadBoolean(),
                        ReferenceStencil       = reader.ReadInt32(),
                        StencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        StencilEnable          = reader.ReadBoolean(),
                        StencilFail            = (StencilOperation)reader.ReadByte(),
                        StencilFunction        = (CompareFunction)reader.ReadByte(),
                        StencilMask            = reader.ReadInt32(),
                        StencilPass            = (StencilOperation)reader.ReadByte(),
                        StencilWriteMask       = reader.ReadInt32(),
                        TwoSidedStencilMode    = reader.ReadBoolean()
                    }
                }
                ;
                if (reader.ReadBoolean())
                {
                    rasterizerState = new RasterizerState()
                    {
                        CullMode             = (CullMode)reader.ReadByte(),
                        DepthBias            = reader.ReadSingle(),
                        FillMode             = (FillMode)reader.ReadByte(),
                        MultiSampleAntiAlias = reader.ReadBoolean(),
                        ScissorTestEnable    = reader.ReadBoolean(),
                        SlopeScaleDepthBias  = reader.ReadSingle()
                    }
                }
                ;
                EffectPass pass = new EffectPass(effect, name, vertexShader, pixelShader, blendState, depthStencilState, rasterizerState, annotations);
                effectPassCollection.Add(pass);
            }
            return(effectPassCollection);
        }
        public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState)
        {
            _sortMode = sortMode;

            _blendState        = (blendState == null) ? BlendState.AlphaBlend : blendState;
            _depthStencilState = (depthStencilState == null) ? DepthStencilState.None : depthStencilState;
            _samplerState      = (samplerState == null) ? SamplerState.LinearClamp : samplerState;
            _rasterizerState   = (rasterizerState == null) ? RasterizerState.CullCounterClockwise : rasterizerState;

            _matrix = Matrix.Identity;
        }
Example #38
0
        public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix)
        {
            if (_beginCalled)
            {
                throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");
            }

            // defaults
            _sortMode          = sortMode;
            _blendState        = blendState ?? BlendState.AlphaBlend;
            _samplerState      = samplerState ?? SamplerState.LinearClamp;
            _depthStencilState = depthStencilState ?? DepthStencilState.None;
            _rasterizerState   = rasterizerState ?? RasterizerState.CullCounterClockwise;

            _effect = effect;

            _matrix = transformMatrix;

            // Setup things now so a user can chage them.
            if (sortMode == SpriteSortMode.Immediate)
            {
                Setup();
            }

            _beginCalled = true;
        }
        public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix)
        {
            _sortMode = sortMode;

            _blendState        = (blendState == null) ? BlendState.AlphaBlend : blendState;
            _depthStencilState = (depthStencilState == null) ? DepthStencilState.None : depthStencilState;
            _samplerState      = (samplerState == null) ? SamplerState.LinearClamp : samplerState;
            _rasterizerState   = (rasterizerState == null) ? RasterizerState.CullCounterClockwise : rasterizerState;

            _effect = effect;
            _matrix = transformMatrix;
        }
Example #40
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders)
        {
            Shader vertexShader = null;
            Shader pixelShader  = null;

            var collection = new EffectPassCollection();

            var count = (int)reader.ReadByte();

            for (var i = 0; i < count; i++)
            {
                var name        = reader.ReadString();
                var annotations = ReadAnnotations(reader);


                // Assign these to the default shaders at this point? or do that in the effect pass.
                // Get the vertex shader.
                var shaderIndex = (int)reader.ReadByte();
                if (shaderIndex != 255)
                {
                    vertexShader = shaders[shaderIndex];
                }

                // Get the pixel shader.
                shaderIndex = (int)reader.ReadByte();
                if (shaderIndex != 255)
                {
                    pixelShader = shaders[shaderIndex];
                }

                BlendState        blend  = null;
                DepthStencilState depth  = null;
                RasterizerState   raster = null;
                if (reader.ReadBoolean())
                {
                    blend = new BlendState
                    {
                        AlphaBlendFunction    = (BlendFunction)reader.ReadByte(),
                        AlphaDestinationBlend = (Blend)reader.ReadByte(),
                        AlphaSourceBlend      = (Blend)reader.ReadByte(),
                        BlendFactor           = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()),
                        ColorBlendFunction    = (BlendFunction)reader.ReadByte(),
                        ColorDestinationBlend = (Blend)reader.ReadByte(),
                        ColorSourceBlend      = (Blend)reader.ReadByte(),
                        ColorWriteChannels    = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels1   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels2   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels3   = (ColorWriteChannels)reader.ReadByte(),
                        MultiSampleMask       = reader.ReadInt32(),
                    };
                }
                if (reader.ReadBoolean())
                {
                    depth = new DepthStencilState
                    {
                        CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFail            = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFunction        = (CompareFunction)reader.ReadByte(),
                        CounterClockwiseStencilPass            = (StencilOperation)reader.ReadByte(),
                        DepthBufferEnable      = reader.ReadBoolean(),
                        DepthBufferFunction    = (CompareFunction)reader.ReadByte(),
                        DepthBufferWriteEnable = reader.ReadBoolean(),
                        ReferenceStencil       = reader.ReadInt32(),
                        StencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        StencilEnable          = reader.ReadBoolean(),
                        StencilFail            = (StencilOperation)reader.ReadByte(),
                        StencilFunction        = (CompareFunction)reader.ReadByte(),
                        StencilMask            = reader.ReadInt32(),
                        StencilPass            = (StencilOperation)reader.ReadByte(),
                        StencilWriteMask       = reader.ReadInt32(),
                        TwoSidedStencilMode    = reader.ReadBoolean(),
                    };
                }
                if (reader.ReadBoolean())
                {
                    raster = new RasterizerState
                    {
                        CullMode             = (CullMode)reader.ReadByte(),
                        DepthBias            = reader.ReadSingle(),
                        FillMode             = (FillMode)reader.ReadByte(),
                        MultiSampleAntiAlias = reader.ReadBoolean(),
                        ScissorTestEnable    = reader.ReadBoolean(),
                        SlopeScaleDepthBias  = reader.ReadSingle(),
                    };
                }
                var pass = new EffectPass(effect, name, vertexShader, pixelShader, blend, depth, raster, annotations);
                collection.Add(pass);
            }

            return(collection);
        }
        public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix)
        {
            // defaults
            _sortMode          = sortMode;
            _blendState        = blendState ?? BlendState.AlphaBlend;
            _samplerState      = samplerState ?? SamplerState.LinearClamp;
            _depthStencilState = depthStencilState ?? DepthStencilState.None;
            _rasterizerState   = rasterizerState ?? RasterizerState.CullCounterClockwise;

            //if (effect != null)
            _effect = effect;

            _matrix = transformMatrix;
        }
 public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect)
 {
     Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, Matrix.Identity);
 }
Example #43
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState)
 {
     this.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, (Effect)null, Matrix.Identity);
 }
Example #44
0
        public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix)
        {
            // defaults
            _sortMode          = sortMode;
            _blendState        = blendState ?? BlendState.AlphaBlend;
            _samplerState      = samplerState ?? SamplerState.LinearClamp;
            _depthStencilState = depthStencilState ?? DepthStencilState.None;
            _rasterizerState   = rasterizerState ?? RasterizerState.CullCounterClockwise;

            _effect = effect;

            _matrix = transformMatrix;

            // Setup things now so a user can chage them.
            if (sortMode == SpriteSortMode.Immediate)
            {
                Setup();
            }

            _beginCalled = true;
        }
Example #45
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix)
 {
     if (this._beginCalled)
     {
         throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");
     }
     this._sortMode          = sortMode;
     this._blendState        = blendState ?? BlendState.AlphaBlend;
     this._samplerState      = samplerState ?? SamplerState.LinearClamp;
     this._depthStencilState = depthStencilState ?? DepthStencilState.None;
     this._rasterizerState   = rasterizerState ?? RasterizerState.CullCounterClockwise;
     this._effect            = effect;
     this._matrix            = transformMatrix;
     if (sortMode == SpriteSortMode.Immediate)
     {
         this.Setup();
     }
     this._beginCalled = true;
 }