private InvokeOnDisposal establishFrameBufferViewport(Vector2 roundedSize)
        {
            // Disable masking for generating the frame buffer since masking will be re-applied
            // when actually drawing later on anyways. This allows more information to be captured
            // in the frame buffer and helps with cached buffers being re-used.
            Rectangle screenSpaceMaskingRect = new Rectangle((int)Math.Floor(ScreenSpaceDrawRectangle.X), (int)Math.Floor(ScreenSpaceDrawRectangle.Y), (int)roundedSize.X + 1, (int)roundedSize.Y + 1);

            GLWrapper.PushMaskingInfo(new MaskingInfo
            {
                ScreenSpaceAABB = screenSpaceMaskingRect,
                MaskingRect     = ScreenSpaceDrawRectangle,
                ToMaskingSpace  = Matrix3.Identity,
                BlendRange      = 1,
                AlphaExponent   = 1,
            }, true);

            // Match viewport to FrameBuffer such that we don't draw unnecessary pixels.
            GLWrapper.PushViewport(new Rectangle(0, 0, (int)roundedSize.X, (int)roundedSize.Y));

            return(new InvokeOnDisposal(delegate
            {
                GLWrapper.PopViewport();
                GLWrapper.PopMaskingInfo();
            }));
        }
 private void returnViewport()
 {
     GLWrapper.PopScissorOffset();
     GLWrapper.PopViewport();
     GLWrapper.PopScissor();
     GLWrapper.PopMaskingInfo();
 }
        protected override void PostDraw()
        {
            frameBuffer.Unbind();

            GLWrapper.PopOrtho();
            GLWrapper.PopViewport();

            GLWrapper.SetBlend(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);

            Rectangle textureRect = new Rectangle(0, frameBuffer.Texture.Height, frameBuffer.Texture.Width, -frameBuffer.Texture.Height);

            frameBuffer.Texture.Draw(ScreenSpaceDrawQuad, textureRect, DrawInfo.Colour, quadBatch);

            // In the case of nested framebuffer containerse we need to draw to
            // the last framebuffer container immediately, so let's force it
            ActiveBatch.Draw();
        }
 private void returnViewport()
 {
     GLWrapper.PopViewport();
     GLWrapper.PopMaskingInfo();
 }
 protected override void PostDrawMask(FrameBuffer clippingMask)
 {
     GLWrapper.PopViewport();
     clippingMask.Unbind();
 }