示例#1
0
        /// <summary>
        /// Binds the framebuffer and all of the renderbuffers.
        /// Clears the buffer bits and sets viewport size.
        /// Perform all rendering after this call.
        /// </summary>
        public void Enable()
        {
            DrawBuffersEnum[] buffers = new DrawBuffersEnum[Attachments.Length];

            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, BufferID);
            for (int i = 0; i < Attachments.Length; i++)
            {
                Gl.BindTexture(TextureTarget.Texture2D, TextureID[i]);
                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[i], TextureID[i], 0);
                buffers[i] = (DrawBuffersEnum)Attachments[i];
            }
            if (Attachments.Length > 1)
            {
                Gl.DrawBuffers(Attachments.Length, buffers);
            }

            Gl.Viewport(0, 0, Size.Width, Size.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        }
示例#2
0
        /// <summary>
        /// Binds the framebuffer and all of the renderbuffers.
        /// Clears the buffer bits and sets viewport size.
        /// Perform all rendering after this call.
        /// </summary>
        /// <param name="clear">True to clear both the color and depth buffer bits of the FBO before enabling.</param>
        public void Enable(bool clear = true)
        {
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, BufferID);
            if (Attachments.Length == 1)
            {
                Gl.BindTexture(TextureTarget.Texture2D, TextureID[0]);
                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[0], TextureID[0], 0);
            }
            else
            {
                DrawBuffersEnum[] buffers = new DrawBuffersEnum[Attachments.Length];

                for (int i = 0; i < Attachments.Length; i++)
                {
                    Gl.BindTexture(TextureTarget.Texture2D, TextureID[i]);
                    Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[i], TextureID[i], 0);
                    buffers[i] = (DrawBuffersEnum)Attachments[i];
                }

                Gl.BindTexture(TextureTarget.Texture2D, DepthID);
                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, DepthID, 0);

                if (Attachments.Length > 1)
                {
                    Gl.DrawBuffers(Attachments.Length, buffers);
                }
            }

            Gl.Viewport(0, 0, Size.Width, Size.Height);

            // configurably clear the buffer and color bits
            if (clear)
            {
                if (Attachments.Length == 1 && Attachments[0] == FramebufferAttachment.DepthAttachment)
                {
                    Gl.Clear(ClearBufferMask.DepthBufferBit);
                }
                else
                {
                    Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Clear surface buffers.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for clearing buffers.
        /// </param>
        /// <param name="bufferMask">
        /// A <see cref="GraphicsBuffersFormat.BufferType"/> indicating which buffers to clear.
        /// </param>
        public void Clear(GraphicsContext ctx, GraphicsBuffersFormat.BufferType bufferMask)
        {
            // Update clear values (only what is necessary)
            if ((bufferMask & GraphicsBuffersFormat.BufferType.Color) != 0)
            {
                Gl.ClearColor(mClearColor.Red, mClearColor.Green, mClearColor.Blue, mClearColor.Alpha);
            }
            if ((bufferMask & GraphicsBuffersFormat.BufferType.Depth) != 0)
            {
                Gl.ClearDepth(mClearDepth);
            }
            if ((bufferMask & GraphicsBuffersFormat.BufferType.Stencil) != 0)
            {
                Gl.ClearStencil(mClearStencil);
            }

            // Clear
            Gl.Clear(GetClearFlags(bufferMask));
        }