/// <summary>
        /// Bind this GraphicsSurface for drawing.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> to wich associate its rendering result to this GraphicsSurface.
        /// </param>
        public override void BindDraw(GraphicsContext ctx)
        {
            // Bind this framebuffer
            Gl.BindFramebuffer(Gl.DRAW_FRAMEBUFFER, ObjectName);

            List <int> drawBuffers = new List <int>();

            for (uint i = 0; i < GraphicsContext.CurrentCaps.Limits.MaxColorAttachments; i++)
            {
                // Reset dirty binding points
                if ((_ColorBuffers[i] != null) && _ColorBuffers[i].Dirty)
                {
                    // Ensure created buffer
                    _ColorBuffers[i].Create(ctx);
                    // Ensure attached buffer
                    _ColorBuffers[i].Attach(Gl.DRAW_FRAMEBUFFER, Gl.COLOR_ATTACHMENT0 + (int)i);
                    _ColorBuffers[i].Dirty = false;
                }

                // Collect draw buffers
                if (_ColorBuffers[i] != null)
                {
                    drawBuffers.Add(Gl.COLOR_ATTACHMENT0 + (int)i);
                }
            }

            // Validate completeness status
            Validate(ctx);

            // Update draw buffers
            Gl.DrawBuffers(drawBuffers.ToArray());
        }
Exemple #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>
        public void Enable()
        {
            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];
                }
                if (Attachments.Length > 1)
                {
                    Gl.DrawBuffers(Attachments.Length, buffers);
                }
            }

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

            if (Attachments.Length == 1 && Attachments[0] == FramebufferAttachment.DepthAttachment)
            {
                Gl.Clear(ClearBufferMask.DepthBufferBit);
            }
            else
            {
                Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            }
        }