Exemplo n.º 1
0
        public void Draw(Matrix currentViewMatrix, Matrix currentProjection)
        {
            dsState = new DepthStencilState();
            dsState.DepthBufferWriteEnable = false;
            device.DepthStencilState = dsState;

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

            Matrix wMatrix = Matrix.CreateTranslation(translation) * Matrix.CreateScale(scale); //* Matrix.CreateTranslation(theCamera.CamPos)
            foreach (ModelMesh mesh in model.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(currentViewMatrix);
                    currentEffect.Parameters["xProjection"].SetValue(currentProjection);
                    currentEffect.Parameters["xTexture1"].SetValue(texture);
                    currentEffect.Parameters["xEnableLighting"].SetValue(false);
                }
                mesh.Draw();
            }
            dsState = new DepthStencilState();
            dsState.DepthBufferWriteEnable = true;
            device.DepthStencilState = dsState;
        }
Exemplo n.º 2
0
        public ImperativeRenderer(
            IBatchContainer container,
            DefaultMaterialSet materials,
            int layer = 0, 
            RasterizerState rasterizerState = null,
            DepthStencilState depthStencilState = null,
            BlendState blendState = null,
            SamplerState samplerState = null,
            bool worldSpace = true,
            bool useZBuffer = false,
            bool autoIncrementSortKey = false,
            bool autoIncrementLayer = false
        )
        {
            if (container == null)
                throw new ArgumentNullException("container");
            if (materials == null)
                throw new ArgumentNullException("materials");

            Container = container;
            Materials = materials;
            Layer = layer;
            RasterizerState = rasterizerState;
            DepthStencilState = depthStencilState;
            BlendState = blendState;
            SamplerState = samplerState;
            UseZBuffer = useZBuffer;
            WorldSpace = worldSpace;
            AutoIncrementSortKey = autoIncrementSortKey;
            AutoIncrementLayer = autoIncrementLayer;
            NextSortKey = 0;
            PreviousBatch = null;
        }
Exemplo n.º 3
0
        protected override void LoadContent()
        {
            _adt = new ADT(_path);
            _adt.Read();

            _terrain = new GeometryDrawer();
            _terrain.Initialize(Game, Color.Green, _adt.MapChunks.Select(mc => mc.Vertices),
                                _adt.MapChunks.Select(mc => mc.Triangles));

            var firstVert = _adt.MapChunks[0].Vertices[0];
            meshDisplay.Game.Camera.Camera.Position = new Vector3(firstVert.Y, firstVert.Z, firstVert.X);

            if (_adt.DoodadHandler.Triangles != null)
            {
                _doodads = new GeometryDrawer();
                _doodads.Initialize(Game, Color.Yellow, _adt.DoodadHandler.Vertices, _adt.DoodadHandler.Triangles);
            }

            if (_adt.WorldModelHandler.Triangles != null)
            {
                _wmos = new GeometryDrawer();
                _wmos.Initialize(Game, Color.Red, _adt.WorldModelHandler.Vertices, _adt.WorldModelHandler.Triangles);
            }

            if (_adt.LiquidHandler.Triangles != null)
            {
                _liquid = new GeometryDrawer();
                _liquid.Initialize(Game, Color.Blue, _adt.LiquidHandler.Vertices, _adt.LiquidHandler.Triangles);
            }

            _effect = new BasicEffect(GraphicsDevice);
            _depthState = new DepthStencilState {DepthBufferEnable = true};
        }
Exemplo n.º 4
0
 public IRenderRequest CreateInstancedRequest(IRenderContext renderContext, RasterizerState rasterizerState,
     BlendState blendState, DepthStencilState depthStencilState, IEffect effect, IEffectParameterSet effectParameterSet,
     VertexBuffer meshVertexBuffer, IndexBuffer meshIndexBuffer, PrimitiveType primitiveType,
     Matrix[] instanceWorldTransforms, Action<List<Matrix>, VertexBuffer, IndexBuffer> computeCombinedBuffers)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
        static EffectApplication()
        {
            sDSStateSky = new DepthStencilState();
            sDSStateSky.DepthBufferFunction = CompareFunction.LessEqual;

            sRenderStateBlendStateMap = new Dictionary<RenderStatePresets, BlendState>();
            sRenderStateBlendStateMap.Add(RenderStatePresets.Default, BlendState.Opaque);
            sRenderStateBlendStateMap.Add(RenderStatePresets.AlphaAdd, BlendState.Additive);
            sRenderStateBlendStateMap.Add(RenderStatePresets.AlphaBlend, BlendState.AlphaBlend);
            sRenderStateBlendStateMap.Add(RenderStatePresets.AlphaBlendNPM, BlendState.NonPremultiplied);
            sRenderStateBlendStateMap.Add(RenderStatePresets.Skybox, BlendState.Opaque);

            sRenderStateDepthStencilStateMap = new Dictionary<RenderStatePresets, DepthStencilState>();
            sRenderStateDepthStencilStateMap.Add(RenderStatePresets.Default, DepthStencilState.Default);
            sRenderStateDepthStencilStateMap.Add(RenderStatePresets.AlphaAdd, DepthStencilState.DepthRead);
            sRenderStateDepthStencilStateMap.Add(RenderStatePresets.AlphaBlend, DepthStencilState.DepthRead);
            sRenderStateDepthStencilStateMap.Add(RenderStatePresets.AlphaBlendNPM, DepthStencilState.DepthRead);
            sRenderStateDepthStencilStateMap.Add(RenderStatePresets.Skybox, sDSStateSky);

            sRenderStateRasterizerStateMap = new Dictionary<RenderStatePresets, RasterizerState>();
            sRenderStateRasterizerStateMap.Add(RenderStatePresets.Default, RasterizerState.CullCounterClockwise);
            sRenderStateRasterizerStateMap.Add(RenderStatePresets.AlphaAdd, RasterizerState.CullNone);
            sRenderStateRasterizerStateMap.Add(RenderStatePresets.AlphaBlend, RasterizerState.CullCounterClockwise);
            sRenderStateRasterizerStateMap.Add(RenderStatePresets.AlphaBlendNPM, RasterizerState.CullCounterClockwise);
            sRenderStateRasterizerStateMap.Add(RenderStatePresets.Skybox, RasterizerState.CullNone);

            sRenderStateAlphaPassMap = new Dictionary<RenderStatePresets, bool>();
            sRenderStateAlphaPassMap.Add(RenderStatePresets.Default, false);
            sRenderStateAlphaPassMap.Add(RenderStatePresets.AlphaAdd, true);
            sRenderStateAlphaPassMap.Add(RenderStatePresets.AlphaBlend, true);
            sRenderStateAlphaPassMap.Add(RenderStatePresets.AlphaBlendNPM, true);
            sRenderStateAlphaPassMap.Add(RenderStatePresets.Skybox, false);
        }
Exemplo n.º 6
0
        private void DrawSkybox()
        {
            SamplerState ss = new SamplerState();
              ss.AddressU = TextureAddressMode.Clamp;
              ss.AddressV = TextureAddressMode.Clamp;

              Engine.Video.GraphicsDevice.SamplerStates[0] = ss;

              DepthStencilState dss = new DepthStencilState();
              dss.DepthBufferEnable = false;
              Engine.Video.GraphicsDevice.DepthStencilState = dss;

              Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
              skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);

              int i = 0;
              foreach(ModelMesh mesh in skyboxModel.Meshes) {
            foreach(Effect currentEffect in mesh.Effects) {
              Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index];
              currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
              currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
              currentEffect.Parameters["xView"].SetValue(camera.ViewMatrix);
              currentEffect.Parameters["xProjection"].SetValue(camera.ProjectionMatrix);
              currentEffect.Parameters["xTexture"].SetValue(skyboxTextures[i++]);
            }

            mesh.Draw();
              }

              dss = new DepthStencilState();
              dss.DepthBufferEnable = true;
              Engine.Video.GraphicsDevice.DepthStencilState = dss;
        }
Exemplo n.º 7
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)
        {
            renderer.matrix = Matrix.CreateTranslation(0, 0, 0);
            GraphicsDevice.Clear(Color.Black);
            Vector3 cameraPosition = new Vector3(0, 0, 2.5f);
            cameraPosition.Y -= .01f;
            if (target == null)
            {
                //Uncomment for depth correction; but blurry pictures
                //target = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight,false,SurfaceFormat.Rgba64,DepthFormat.Depth24);
                target = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);

            } RasterizerState tstate = new RasterizerState();

            tstate.CullMode = CullMode.None;
            DepthStencilState lstate = new DepthStencilState();
            GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
            lstate.DepthBufferEnable = true;
            GraphicsDevice.DepthStencilState = lstate;
            GraphicsDevice.RasterizerState = tstate;

                if (!renderer.NtfyReadyRender(GraphicsDevice))
                {

                    renderer.NtfyReadyRender(GraphicsDevice);
                }

            base.Draw(gameTime);
        }
Exemplo n.º 8
0
        Texture2D[] skyboxTextures; // textures to display around the skybox

        #endregion Fields

        #region Methods

        /// <summary>
        /// Draw the skybox to the screen.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="gameCamera">Used to get the view and projection matrices</param>
        /// <param name="player">The player's position governs where the skybox is drawn</param>
        public void Draw(ref GraphicsDevice device, Camera gameCamera, Player player)
        {
            device.SamplerStates[0] = clampTextureAddressMode;

            DepthStencilState dss = new DepthStencilState();
            dss.DepthBufferEnable = false;
            device.DepthStencilState = dss;

            Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
            skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
            int i = 0;
            foreach (ModelMesh mesh in skyboxModel.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(player.Position);
                    currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
                    currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
                    currentEffect.Parameters["xView"].SetValue(gameCamera.ViewMatrix);
                    currentEffect.Parameters["xProjection"].SetValue(gameCamera.ProjectionMatrix);
                    currentEffect.Parameters["xTexture"].SetValue(skyboxTextures[i++]);
                }
                mesh.Draw();
            }

            dss = new DepthStencilState();
            dss.DepthBufferEnable = true;
            device.DepthStencilState = dss;
        }
Exemplo n.º 9
0
        public override void Draw(GameTime gameTime)
        {
            DepthStencilState s = new DepthStencilState();
            s.DepthBufferWriteEnable = false;
            DepthStencilState bak = device.DepthStencilState;
            device.DepthStencilState = s;
            device.RasterizerState = new RasterizerState() { CullMode = CullMode.None, FillMode = FillMode.Solid };

            Matrix wMatrix = Matrix.CreateScale(scale) * Matrix.CreateTranslation(cameraPosition);
            effect.CurrentTechnique = effect.Techniques["SkyBox"];
            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(wMatrix);
            effect.Parameters["xCamPos"].SetValue(cameraPosition);
            effect.Parameters["xSkyBoxTexture"].SetValue(cloudMap);
            effect.Parameters["xEnableLighting"].SetValue(false);
            effect.Parameters["xClipping"].SetValue(false);
            effect.Parameters["xTexture"].SetValue(Tools.Quick.biomeTextures[1]);

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.SetVertexBuffer(vertexBuffer);
                device.Indices = indexBuffer;
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indexBuffer.IndexCount, 0, indexBuffer.IndexCount / 3);
            }

            device.DepthStencilState = bak;
            base.Draw(gameTime);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 public EffectState(Effect effect, SamplerState sampler, RasterizerState raster, DepthStencilState stencil, bool texture)
 {
     Effect = effect;
     Sampler = sampler;
     Raster = raster;
     TextureOverride = texture;
 }
Exemplo n.º 12
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;
        }
Exemplo n.º 13
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;
        }
Exemplo n.º 14
0
Arquivo: Mask.cs Projeto: hgrandry/Mgx
        public Mask(Sprite spriteMask, Sprite spriteTarget)
        {
            _spriteMask = spriteMask;
            _spriteTarget = spriteTarget;

            Render.Viewport.ResolutionChanged += Setup;
            Setup();

            _maskStencilState = new DepthStencilState
            {
                StencilEnable = true,
                StencilFunction = CompareFunction.Always,
                StencilPass = StencilOperation.Replace,
                ReferenceStencil = 1,
                DepthBufferEnable = false,
            };

            _targetStencilState = new DepthStencilState
            {
                StencilEnable = true,
                StencilFunction = CompareFunction.LessEqual,
                StencilPass = StencilOperation.Replace,
                ReferenceStencil = 1,
                DepthBufferEnable = false,
            };

            Add(new DrawComponent(Draw));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Does the actual drawing of the skybox with our skybox effect.
        /// There is no world matrix, because we're assuming the skybox won't
        /// be moved around.  The size of the skybox can be changed with the size
        /// variable.
        /// </summary>
        /// <param name="view">The view matrix for the effect</param>
        /// <param name="projection">The projection matrix for the effect</param>
        /// <param name="cameraPosition">The position of the camera</param>
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice device = game.GraphicsDevice;
            SamplerState ss = new SamplerState();
            ss.AddressU = TextureAddressMode.Clamp;
            ss.AddressV = TextureAddressMode.Clamp;
            device.SamplerStates[0] = ss;

            DepthStencilState dss = new DepthStencilState();
            dss.DepthBufferEnable = false;
            device.DepthStencilState = dss;

            Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
            skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
            int i = 0;
            foreach (ModelMesh mesh in skyboxModel.Meshes)
            {
                foreach (BasicEffect currentEffect in mesh.Effects)
                {
                    Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(camera.position);

                    currentEffect.World = worldMatrix;
                    currentEffect.View = camera.view;
                    currentEffect.Projection = camera.projection;
                    currentEffect.TextureEnabled=true;
                    currentEffect.Texture = skyboxTextures[i++];

                }
                mesh.Draw();
            }

            dss = new DepthStencilState();
            dss.DepthBufferEnable = true;
            device.DepthStencilState = dss;
        }
Exemplo n.º 16
0
        public override void Draw(GameTime gameTime)
        {
            var strings = new List<String>();
            strings.Add(String.Format("Num blocks / vertices : {0} / {1}", _game.Map.NumBlocks, _game.Map.NumVertices));
            strings.Add(String.Format("Player position : {0}, {1}, {2} ({3}, {4}, {5})",
                _game.Player.MapPosition.X, _game.Player.MapPosition.Y, _game.Player.MapPosition.Z,
                _game.Player.Position.X, _game.Player.Position.Y, _game.Player.Position.Z));
            strings.Add(String.Format("Player block aim : {0}, {1}, {2}", _game.Player.BlockAim.X, _game.Player.BlockAim.Y, _game.Player.BlockAim.Z));

            _game.SpriteBatch.Begin();

            var height = 45;

            foreach(var str in strings)
            {
                _game.SpriteBatch.DrawString(_font, str, new Vector2(20, height), Color.White);

                height += 20;
            }

            _game.SpriteBatch.End();

            base.Draw(gameTime);

            var state = new DepthStencilState();
            state.DepthBufferEnable = true;
            _game.GraphicsDevice.DepthStencilState = state;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            input = new Input();
            GraphicsDevice.BlendState = BlendState.AlphaBlend;
            dpsLockDepthWrite = new DepthStencilState();
            dpsLockDepthWrite.DepthBufferWriteEnable = false;
            DepthStencilState dpsUnLockDepthWrite = new DepthStencilState();
            dpsUnLockDepthWrite.DepthBufferWriteEnable = true;

            //graphics.PreferredBackBufferWidth = 1280;
            //graphics.PreferredBackBufferHeight = 720;
            //b = new Bat(-11f, Vector3.UnitZ, Vector3.Up, 0.9f, 0.9f, 0.9f, Color.Gray, graphics);

            myCamera = new CameraComponent(graphics);

            //model = new GameModel(this, Content, myCamera, Matrix.Identity, e, "box");
            //Components.Add(model);
            float width = 2.0f;
            float height = 1.2f;
            tunnel = new Tunnel(this, graphics, myCamera, Content, 1, 15, Vector3.Zero, Vector3.Backward, Vector3.Up, width, height);

            frontBat = new Bat(-2.0f, Vector3.Backward, Vector3.Up, .2f, .2f, Color.Red, myCamera, graphics, width, height);
            backBat = new Bat(-15.0f, Vector3.Backward, Vector3.Up, .2f, .2f, Color.Green, myCamera, graphics, width, height);
            Components.Add(tunnel);

            base.Initialize();
        }
Exemplo n.º 18
0
 public Score(PuzzleBooble3dGame puzzlegame)
     : base(puzzlegame)
 {
     DepthStateEnabled = new DepthStencilState();
     DepthStateEnabled.DepthBufferEnable = true; /* Enable the depth buffer */
     //depthState.DepthBufferWriteEnable = true; /* When drawing to the screen, write to the depth buffer */
 }
Exemplo n.º 19
0
        public void DrawSkybox(Camera camera, Vector3 shipPosition)
        {
            //A TextureAddressMode.Clamp state removes the seams between the cube.
            SamplerState ss = new SamplerState();
            ss.AddressU = TextureAddressMode.Clamp;
            ss.AddressV = TextureAddressMode.Clamp;
            _device.SamplerStates[0] = ss;

            //Removes the ZBuffer so no size can be set for the skybox.
            DepthStencilState dss = new DepthStencilState();
            dss.DepthBufferEnable = false;
            _device.DepthStencilState = dss;

            Matrix[] transforms = new Matrix[_skyboxModel.Bones.Count]; //Represents the position of each model bone.
            _skyboxModel.CopyAbsoluteBoneTransformsTo(transforms); //Models have a method that populates an array.

            foreach (ModelMesh mesh in _skyboxModel.Meshes)
            {
                //BasicEffect is a simplified version of it's parent class Effect.  Effects allow objects to be placed on screen.
                foreach (BasicEffect basicEffect in mesh.Effects)
                {
                    basicEffect.Projection = camera.Projection;
                    basicEffect.View = camera.View;
                    basicEffect.World =  Matrix.CreateScale(80) * mesh.ParentBone.Transform * Matrix.CreateTranslation(shipPosition); //Positions the mesh in the correct place relavent to the world.

                }
                mesh.Draw();
            }

            //Reenabling the ZBuffer.
            dss = new DepthStencilState();
            dss.DepthBufferEnable = true;
            _device.DepthStencilState = dss;
        }
Exemplo n.º 20
0
        public void DrawClippedSky(GraphicsDevice device, Effect effect, Camera camera)
        {
            DepthStencilState s = new DepthStencilState();
            s.DepthBufferWriteEnable = false;
            DepthStencilState bak = device.DepthStencilState;
            device.DepthStencilState = s;
            device.RasterizerState = new RasterizerState() { CullMode = CullMode.None, FillMode = FillMode.Solid };

            Matrix wMatrix = Matrix.CreateScale(scale) * Matrix.CreateTranslation(camera.position);

            effect.CurrentTechnique = effect.Techniques["SkyBox"];
            effect.Parameters["xView"].SetValue(camera.getview());
            effect.Parameters["xProjection"].SetValue(camera.GetProjection());
            effect.Parameters["xWorld"].SetValue(wMatrix);
            effect.Parameters["xCamPos"].SetValue(camera.position);
            effect.Parameters["xSkyBoxTexture"].SetValue(cloudMap);
            effect.Parameters["xEnableLighting"].SetValue(false);
            //currentEffect.Parameters["xClipping"].SetValue(true);

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.SetVertexBuffer(vertexBuffer);
                device.Indices = indexBuffer;
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indexBuffer.IndexCount, 0, indexBuffer.IndexCount / 3);
            }

            device.DepthStencilState = bak;
        }
Exemplo n.º 21
0
        public void draw(Matrix view, Matrix projection, Vector3 playerPosition)
        {
            SamplerState samplerState = new SamplerState();
            samplerState.AddressU = TextureAddressMode.Clamp;
            samplerState.AddressV = TextureAddressMode.Clamp;
            Game1.getGraphics().GraphicsDevice.SamplerStates[0] = samplerState;

            DepthStencilState dss = new DepthStencilState();
            dss.DepthBufferEnable = false;
            Game1.getGraphics().GraphicsDevice.DepthStencilState = dss;

            Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
            skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
            foreach (ModelMesh mesh in skyboxModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(playerPosition);
                    //effect.CurrentTechnique = effect.Techniques["Textured"];
                    effect.LightingEnabled = true;
                    effect.AmbientLightColor = new Vector3(1f, 1f, 1f);
                    effect.EmissiveColor = new Vector3(0.4f, 0.4f, 0.4f);
                    effect.TextureEnabled = true;
                    effect.Texture = skyboxTextures;
                    effect.World = worldMatrix;
                    effect.View = view;
                    effect.Projection = projection;

                }
                mesh.Draw();
            }
            dss = new DepthStencilState();
            dss.DepthBufferEnable = true;
            Game1.getGraphics().GraphicsDevice.DepthStencilState = dss;
        }
Exemplo n.º 22
0
        internal RenderManager(GraphicsDevice device)
        {
            Skins = new Dictionary<string, Skin>();
            Texts = new Dictionary<string, Text>();

            ApplyStencil = new DepthStencilState {
                StencilEnable = true,
                StencilFunction = CompareFunction.Always,
                StencilPass = StencilOperation.Replace,
                ReferenceStencil = 1,
                DepthBufferEnable = false,
            };

            SampleStencil = new DepthStencilState {
                StencilEnable = true,
                StencilFunction = CompareFunction.Equal,
                StencilPass = StencilOperation.Keep,
                ReferenceStencil = 1,
                DepthBufferEnable = false,
            };

            GraphicsDevice = device;
            RasterizerState = new RasterizerState { ScissorTestEnable = true };
            SpriteBatch = new SpriteBatch(GraphicsDevice);
        }
 public override void Initialize()
 {
    JeuDepthBufferState = new DepthStencilState();
    JeuDepthBufferState.DepthBufferEnable = true;
    JeuRasterizerState = new RasterizerState();
    JeuRasterizerState.CullMode = CullMode.CullCounterClockwiseFace;
    JeuBlendState = BlendState.Opaque;
    base.Initialize();
 }
Exemplo n.º 24
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState)
 {
     _sortMode = sortMode;
     _blendState = (blendState == null) ? BlendState.AlphaBlend : blendState;
     _depthStencilState = DepthStencilState.None;
     _samplerState = SamplerState.LinearClamp;
     _rasterizerState = RasterizerState.CullCounterClockwise;
     _matrix = Matrix.Identity;
 }
Exemplo n.º 25
0
 public void Begin()
 {
     _sortMode = SpriteSortMode.Deferred;
     _blendState = BlendState.AlphaBlend;
     _depthStencilState = DepthStencilState.None;
     _samplerState = SamplerState.LinearClamp;
     _rasterizerState = RasterizerState.CullCounterClockwise;
     _matrix = Matrix.Identity;
 }
Exemplo n.º 26
0
 protected override void Initialize()
 {
     button1 = new MenuButton(new Vector2(100, 600), Content.Load<Texture2D>("jouer2"), Content.Load<Texture2D>("jouer2"), new Rectangle(20, 20, 20, 20));
     base.Initialize();
     this.graphics.PreferredBackBufferWidth = 800;
     this.graphics.PreferredBackBufferHeight = 200;
     DepthStencilState dst = new DepthStencilState();
     this.graphics.GraphicsDevice.DepthStencilState = dst;
 }
Exemplo n.º 27
0
        static RenderTarget()
        {
            _cumulativeSpriteBatch = new SpriteBatch(Gbl.Device);
            _renderTargets = new List<RenderTarget>();

            _universalDepthStencil = new DepthStencilState();
            _universalDepthStencil.DepthBufferEnable = true;
            _universalDepthStencil.DepthBufferWriteEnable = true;
        }
Exemplo n.º 28
0
 public DrawMode(DrawMode copy)
 {
     sortMode          = copy.sortMode;
     blendState        = copy.blendState;
     samplerState      = copy.samplerState;
     depthStencilState = copy.depthStencilState;
     rasterizerState   = copy.rasterizerState;
     effect            = copy.effect;
     transform         = copy.transform;
 }
Exemplo n.º 29
0
 /// <summary>
 /// Begin the SpriteBatch
 /// </summary>
 /// <param name="SortMode">Self-explanatory.</param>
 /// <param name="BlendState">Self-explanatory.</param>
 /// <param name="SamplerState">Self-explanatory.</param>
 /// <param name="DepthStencilState">Self-explanatory.</param>
 /// <param name="RasterizerState">Self-explanatory.</param>
 /// <param name="Effect">Self-explanatory.</param>
 /// <param name="Matrix">Self-explanatory.</param>
 public void Begin(SpriteSortMode SortMode = SpriteSortMode.Deferred, BlendState BlendState = null,
     SamplerState SamplerState = null, DepthStencilState DepthStencilState = null,
     RasterizerState RasterizerState = null, Effect Effect = null, Matrix? Matrix = null, bool Backup = false)
 {
     if (Begun) End();
     Begun = true;
     if (Backup)
         this.Backup(SortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix);
     SpriteBatch.Begin(SortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix);
 }
Exemplo n.º 30
0
 // ================== CONSTRUCTORS ================== //
 public DrawMode()
 {
     sortMode          = SpriteSortMode.Immediate;
     blendState        = BlendState.NonPremultiplied;
     samplerState      = SamplerState.LinearClamp;
     depthStencilState = DepthStencilState.None;
     rasterizerState   = RasterizerState.CullNone;
     effect            = null;
     transform         = Matrix.Identity;
 }
Exemplo n.º 31
0
        public void Enable()
        {
            var depthStencilState = new X.DepthStencilState()
            {
                DepthBufferEnable      = desc.depthReadEnable,
                DepthBufferWriteEnable = desc.depthWriteEnable,
                DepthBufferFunction    = desc.depthFunc,

                StencilEnable          = desc.stencilEnable,
                StencilFunction        = desc.stencilFunc,
                StencilFail            = desc.stencilFailOp,
                StencilDepthBufferFail = desc.stencilDepthFailOp,
                StencilPass            = desc.stencilPassOp,

                TwoSidedStencilMode                    = false,
                CounterClockwiseStencilFunction        = X.CompareFunction.Never,
                CounterClockwiseStencilFail            = X.StencilOperation.Keep,
                CounterClockwiseStencilDepthBufferFail = X.StencilOperation.Keep,
                CounterClockwiseStencilPass            = X.StencilOperation.Keep
            };

            video.Device.DepthStencilState = depthStencilState;
        }
Exemplo n.º 32
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 BindDepthStencilState()
 {
     if (!base.IsBound)
     {
         _depthStencilState = new XFG.DepthStencilState();
         _depthStencilState.DepthBufferEnable                      = base.DepthEnable;
         _depthStencilState.DepthBufferWriteEnable                 = base.DepthWriteEnable;
         _depthStencilState.StencilEnable                          = base.StencilEnable;
         _depthStencilState.TwoSidedStencilMode                    = base.TwoSidedStencilEnable;
         _depthStencilState.StencilMask                            = base.StencilReadMask;
         _depthStencilState.StencilWriteMask                       = base.StencilWriteMask;
         _depthStencilState.ReferenceStencil                       = base.ReferenceStencil;
         _depthStencilState.CounterClockwiseStencilPass            = XNAHelper.ToXNAStencilOperation(base.CounterClockwiseStencilPass);
         _depthStencilState.CounterClockwiseStencilDepthBufferFail = XNAHelper.ToXNAStencilOperation(base.CounterClockwiseStencilDepthFail);
         _depthStencilState.CounterClockwiseStencilFail            = XNAHelper.ToXNAStencilOperation(base.CounterClockwiseStencilFail);
         _depthStencilState.CounterClockwiseStencilFunction        = XNAHelper.ToXNACompareFunction(base.CounterClockwiseStencilFunction);
         _depthStencilState.DepthBufferFunction                    = XNAHelper.ToXNACompareFunction(base.DepthFunction);
         _depthStencilState.StencilFunction                        = XNAHelper.ToXNACompareFunction(base.StencilFunction);
         _depthStencilState.StencilDepthBufferFail                 = XNAHelper.ToXNAStencilOperation(base.StencilDepthFail);
         _depthStencilState.StencilFail                            = XNAHelper.ToXNAStencilOperation(base.StencilFail);
         _depthStencilState.StencilPass                            = XNAHelper.ToXNAStencilOperation(base.StencilPass);
         base.IsBound = true;
     }
 }
Exemplo n.º 33
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;
        }
Exemplo n.º 34
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;

            if (effect != null)
            {
                _effect = effect;
            }

            _matrix = transformMatrix;
        }
Exemplo n.º 35
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect)
 {
     Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, Matrix.Identity);
 }
Exemplo n.º 36
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);
        }
Exemplo n.º 37
0
        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;
        }
Exemplo n.º 38
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;
        }
Exemplo n.º 39
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);
 }
Exemplo n.º 40
0
 static DepthStencilState()
 {
     Default   = new DepthStencilState("DepthStencilState.Default", true, true);
     DepthRead = new DepthStencilState("DepthStencilState.DepthRead", true, false);
     None      = new DepthStencilState("DepthStencilState.None", false, false);
 }
Exemplo n.º 41
0
        public void EndApplyDepthStencil()
        {
            StateHash hash = GetDepthStencilHash(
                DepthBufferEnable,
                DepthBufferWriteEnable,
                DepthBufferFunction,
                StencilEnable,
                StencilFunction,
                StencilPass,
                StencilFail,
                StencilDepthBufferFail,
                TwoSidedStencilMode,
                CCWStencilFunction,
                CCWStencilPass,
                CCWStencilFail,
                CCWStencilDepthBufferFail,
                StencilMask,
                StencilWriteMask,
                ReferenceStencil
                );
            DepthStencilState newDepthStencil;

            if (!depthStencilCache.TryGetValue(hash, out newDepthStencil))
            {
                newDepthStencil = new DepthStencilState();

                newDepthStencil.DepthBufferEnable                      = DepthBufferEnable;
                newDepthStencil.DepthBufferWriteEnable                 = DepthBufferWriteEnable;
                newDepthStencil.DepthBufferFunction                    = DepthBufferFunction;
                newDepthStencil.StencilEnable                          = StencilEnable;
                newDepthStencil.StencilFunction                        = StencilFunction;
                newDepthStencil.StencilPass                            = StencilPass;
                newDepthStencil.StencilFail                            = StencilFail;
                newDepthStencil.StencilDepthBufferFail                 = StencilDepthBufferFail;
                newDepthStencil.TwoSidedStencilMode                    = TwoSidedStencilMode;
                newDepthStencil.CounterClockwiseStencilFunction        = CCWStencilFunction;
                newDepthStencil.CounterClockwiseStencilFail            = CCWStencilFail;
                newDepthStencil.CounterClockwiseStencilPass            = CCWStencilPass;
                newDepthStencil.CounterClockwiseStencilDepthBufferFail = CCWStencilDepthBufferFail;
                newDepthStencil.StencilMask                            = StencilMask;
                newDepthStencil.StencilWriteMask                       = StencilWriteMask;
                newDepthStencil.ReferenceStencil                       = ReferenceStencil;

                depthStencilCache.Add(hash, newDepthStencil);
#if VERBOSE_PIPELINECACHE
                FNALoggerEXT.LogInfo(
                    "New DepthStencilState added to pipeline cache with hash:\n" +
                    hash.ToString()
                    );
                FNALoggerEXT.LogInfo(
                    "Updated size of DepthStencilState cache: " +
                    depthStencilCache.Count
                    );
            }
            else
            {
                FNALoggerEXT.LogInfo(
                    "Retrieved DepthStencilState from pipeline cache with hash:\n" +
                    hash.ToString()
                    );
#endif
            }

            device.DepthStencilState = newDepthStencil;
        }
Exemplo n.º 42
0
        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;
        }
Exemplo n.º 43
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);
        }
Exemplo n.º 44
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;
 }