Ejemplo n.º 1
0
        private void Attach(FrameBufferDescription description)
        {
            if (!description.HasAttachments)
            {
                throw new ArgumentException("Can't create a framebuffer object without attachments.", "description");
            }

            Description = description;

            if (graphicsDevice.OpenGLCapabilities.DirectStateAccess == DirectStateAccess.None)
            {
                graphicsDevice.BindManager.Fbo = this;

                if (description.ColorAttachmentIDs != null)
                {
                    DrawBuffersEnum[] buffers = new DrawBuffersEnum[description.ColorAttachmentIDs.Length];

                    for (int i = 0; i < description.ColorAttachmentIDs.Length; i++)
                    {
                        GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + i, description.ColorAttachmentIDs[i], 0);
                        buffers[i] = DrawBuffersEnum.ColorAttachment0 + i;
                    }

                    if (description.ColorAttachmentIDs.Length == 0)
                    {
                        GL.DrawBuffer(DrawBufferMode.None);
                    }
                    else
                    {
                        GL.DrawBuffers(buffers.Length, buffers);
                    }
                }
                else
                {
                    GL.DrawBuffer(DrawBufferMode.None);
                }

                if (description.DepthAttachmentID != -1)
                {
                    GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, description.DepthAttachmentID, 0);
                }
            }
            else if (graphicsDevice.OpenGLCapabilities.DirectStateAccess == DirectStateAccess.Extension)
            {
                if (description.ColorAttachmentIDs != null)
                {
                    OpenTK.Graphics.OpenGL.DrawBufferMode[] buffers = new OpenTK.Graphics.OpenGL.DrawBufferMode[description.ColorAttachmentIDs.Length];

                    for (int i = 0; i < description.ColorAttachmentIDs.Length; i++)
                    {
                        Ext.NamedFramebufferTexture(FboID, OpenTK.Graphics.OpenGL.FramebufferAttachment.ColorAttachment0 + i, description.ColorAttachmentIDs[i], 0);
                        buffers[i] = OpenTK.Graphics.OpenGL.DrawBufferMode.ColorAttachment0 + i;
                    }

                    if (description.ColorAttachmentIDs.Length == 0)
                    {
                        Ext.FramebufferDrawBuffer(FboID, OpenTK.Graphics.OpenGL.DrawBufferMode.None);
                    }
                    else
                    {
                        Ext.FramebufferDrawBuffers(FboID, buffers.Length, buffers);
                    }
                }
                else
                {
                    GL.DrawBuffer(DrawBufferMode.None);
                }

                if (description.DepthAttachmentID != -1)
                {
                    Ext.NamedFramebufferTexture(FboID, OpenTK.Graphics.OpenGL.FramebufferAttachment.DepthAttachment, description.DepthAttachmentID, 0);
                }
            }
        }