Esempio n. 1
0
        internal override void Apply()
        {
            // May need to be moved elsewhere within this method
            OnApply();

            GLStateManager.Projection(Projection);
            GLStateManager.WorldView(World, View);

            // this should probably not be here.
            // this should probably be set immediately on assignment.
            GLStateManager.Cull(this.graphicsDevice.RasterizerState.CullMode);

            base.Apply();

            GLStateManager.Textures2D(Texture != null);

            GLStateManager.ColorArray(VertexColorEnabled);
        }
Esempio n. 2
0
 internal virtual void Apply()
 {
     GLStateManager.Cull(graphicsDevice.RasterizerState.CullMode.OpenGL11());
     // TODO: This is prolly not right (DepthBuffer, etc)
     GLStateManager.DepthTest(graphicsDevice.DepthStencilState.DepthBufferEnable);
 }
Esempio n. 3
0
        public void EndGL11()
        {
            // Disable Blending by default = BlendState.Opaque
            GL11.Disable(ALL11.Blend);

            // set the blend mode
            if (_blendState == BlendState.NonPremultiplied)
            {
                GL11.BlendFunc(ALL11.SrcAlpha, ALL11.OneMinusSrcAlpha);
                GL11.Enable(ALL11.Blend);
            }

            if (_blendState == BlendState.AlphaBlend)
            {
                GL11.BlendFunc(ALL11.One, ALL11.OneMinusSrcAlpha);
                GL11.Enable(ALL11.Blend);
            }

            if (_blendState == BlendState.Additive)
            {
                GL11.BlendFunc(ALL11.SrcAlpha, ALL11.One);
                GL11.Enable(ALL11.Blend);
            }

            if (_blendState == BlendState.Multiply)
            {
                GL11.BlendFunc(ALL11.DstColor, ALL11.Zero);
                GL11.Enable(ALL11.Blend);
            }

            if (_blendState == BlendState.Multiplyx2)
            {
                GL11.BlendFunc(ALL11.DstColor, ALL11.SrcColor);
                GL11.Enable(ALL11.Blend);
            }

            // set camera
            GL11.MatrixMode(ALL11.Projection);
            GL11.LoadIdentity();

            GL11.Ortho(0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, -1, 1);

            // Enable Scissor Tests if necessary
            if (this.graphicsDevice.RasterizerState.ScissorTestEnable)
            {
                GL11.Enable(ALL11.ScissorTest);
            }


            GL11.MatrixMode(ALL11.Modelview);

            GL11.Viewport(0, 0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height);

            // Enable Scissor Tests if necessary
            if (this.graphicsDevice.RasterizerState.ScissorTestEnable)
            {
                GL11.Scissor(this.graphicsDevice.ScissorRectangle.X, this.graphicsDevice.ScissorRectangle.Y, this.graphicsDevice.ScissorRectangle.Width, this.graphicsDevice.ScissorRectangle.Height);
            }

            GL11.LoadMatrix(ref _matrix.M11);

            // Initialize OpenGL states (ideally move this to initialize somewhere else)
            GL11.Disable(ALL11.DepthTest);
            GL11.TexEnv(ALL11.TextureEnv, ALL11.TextureEnvMode, (int)ALL11.BlendSrc);
            GL11.Enable(ALL11.Texture2D);
            GL11.EnableClientState(ALL11.VertexArray);
            GL11.EnableClientState(ALL11.ColorArray);
            GL11.EnableClientState(ALL11.TextureCoordArray);

            // No need to cull sprites. they will all be same-facing by construction.
            // Plus, setting frontface to Clockwise is a troll move.
            GLStateManager.Cull(CullMode.None);
            GL11.Color4(1.0f, 1.0f, 1.0f, 1.0f);

            _batcher.DrawBatchGL11(_sortMode, _samplerState);

            if (this.graphicsDevice.RasterizerState.ScissorTestEnable)
            {
                GL11.Disable(ALL11.ScissorTest);
            }
        }
Esempio n. 4
0
        public void End()
        {
            // set up camera
            switch (this.graphicsDevice.PresentationParameters.DisplayOrientation)
            {
            case DisplayOrientation.LandscapeLeft:
            case DisplayOrientation.LandscapeRight:
            case DisplayOrientation.PortraitUpsideDown:
                throw new NotImplementedException();

            default:
                if (this.graphicsDevice.RenderTarget != null)
                {
                    Matrix4.CreateOrthographicOffCenter(0, this.graphicsDevice.RenderTarget.Width, this.graphicsDevice.RenderTarget.Height, 0, -1, 1, out GLStateManager.Projection);
                    break;
                }
                else
                {
                    Matrix4.CreateOrthographicOffCenter(0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, -1, 1, out GLStateManager.Projection);
                    break;
                }
            }

            GL.Viewport(this.graphicsDevice.Viewport.X, this.graphicsDevice.Viewport.Y,
                        this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height);

            // Enable Scissor Tests if necessary
            if (this.graphicsDevice.RenderState.ScissorTestEnable)
            {
                GL.Enable(EnableCap.ScissorTest);
                GL.Scissor(this.graphicsDevice.ScissorRectangle.X, this.graphicsDevice.ScissorRectangle.Y, this.graphicsDevice.ScissorRectangle.Width, this.graphicsDevice.ScissorRectangle.Height);
            }

            GLStateManager.ModelView = _matrix.ToMatrix4();

            // Initialize OpenGL states (ideally move this to initialize somewhere else)
            GLStateManager.DepthTest(false);
            GLStateManager.Textures2D(true);

            // Enable Culling for better performance
            GLStateManager.Cull(FrontFaceDirection.Cw);

            switch (_sortMode)
            {
            case SpriteSortMode.Immediate:
                break;

            default:
                this.graphicsDevice.RenderState.SourceBlend      = _blendState.ColorSourceBlend;
                this.graphicsDevice.RenderState.DestinationBlend = _blendState.ColorDestinationBlend;
                break;
            }

            GLStateManager.BlendFunc((BlendingFactorSrc)this.graphicsDevice.RenderState.SourceBlend, (BlendingFactorDest)this.graphicsDevice.RenderState.DestinationBlend);

            _batcher.DrawBatch(_sortMode);

            // GG EDIT always disable scissor test after drawing a batch
            if (this.graphicsDevice.RenderState.ScissorTestEnable)
            {
                GL.Disable(EnableCap.ScissorTest);
            }
        }