Ejemplo n.º 1
0
        public virtual void Draw()
        {
            GL.Viewport(new System.Drawing.Rectangle(0, 0, Resolution.Width, Resolution.Height));

            if (MultisampleLevel > 0)
            {
                FboMs.Bind();
            }
            else
            {
                FrontFbo.Bind();
            }

            // Setup stuff
            GL.DepthMask(true); // enables writing to depth buffer - needed for GL.Clear

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // Draw the scene
            GameObjectPainter.Draw(Renderer, World);

            // Resolve multisampling
            if (MultisampleLevel > 0)
            {
                // We have to blit to another fbo to resolve multisampling before readPixels and postprocessing, unfortunatelly
                FboMs.Bind(FramebufferTarget.ReadFramebuffer);
                FrontFbo.Bind(FramebufferTarget.DrawFramebuffer);
                GL.BlitFramebuffer(
                    0, 0, FboMs.Size.X, FboMs.Size.Y,
                    0, 0, FrontFbo.Size.X, FrontFbo.Size.Y,
                    ClearBufferMask.ColorBufferBit,
                    BlitFramebufferFilter.Linear);
                if (ImagePainter.Settings.CopyDepth || EffectPainter.Settings.EnabledEffects != RenderRequestEffect.None)
                {
                    GL.BlitFramebuffer(
                        0, 0, FboMs.Size.X, FboMs.Size.Y,
                        0, 0, FrontFbo.Size.X, FrontFbo.Size.Y,
                        ClearBufferMask.DepthBufferBit,
                        BlitFramebufferFilter.Nearest);
                }
            }

            // Draw effects after multisampling to save fragment shader calls
            EffectPainter.Draw(Renderer, World);

            // Depth testing is useless for these
            GL.Disable(EnableCap.DepthTest);

            PostprocessPainter.Draw(Renderer, World);
            OverlayPainter.Draw(Renderer, World);

            // Tell OpenGL driver to submit any unissued commands to the GPU
            GL.Flush();
        }