internal FrameBuffer(GraphicsDevice graphicsDevice, FrameBufferDescription description) : base(graphicsDevice, new System.Diagnostics.StackTrace(1)) { FboID = GL.GenFramebuffer(); Attach(description); CheckStatus(); }
//RenderTarget internal FrameBuffer GetFBO(FrameBufferDescription description) { if (!description.HasAttachments) { return(null); } FrameBuffer fbo; if (fboPool.TryGetValue(description, out fbo)) { return(fbo); } GraphicsFactory factory = (GraphicsFactory)Factory; fbo = factory.CreateFrameBuffer(description); fboPool.Add(description, fbo); return(fbo); }
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); } } }
internal FrameBuffer CreateFrameBuffer(FrameBufferDescription description) { return(Register(new FrameBuffer(graphicsDevice, description))); }