#region usings using System; using OpenTK.Graphics.OpenGL4; using SM.OGL.Texture; #endregion namespace SM.OGL.Framebuffer { /// /// Represents a Framebuffer-Color Attachment. /// Can be use like a texture. /// public class ColorAttachment : TextureBase { /// /// Creates a attachment with a specific id. /// /// public ColorAttachment(int attachmentId) : this(attachmentId, PixelInformation.RGBA_LDR) { } public ColorAttachment(int attachmentID, PixelInformation pixelInformation) { AttachmentID = attachmentID; PixelInformation = pixelInformation; } /// /// The ID the attachment was given. /// public int AttachmentID { get; } /// /// Returns the of this ColorAttachment. /// public FramebufferAttachment FramebufferAttachment => FramebufferAttachment.ColorAttachment0 + AttachmentID; /// /// Returns the of this ColorAttachment. /// public DrawBufferMode DrawBufferMode => DrawBufferMode.ColorAttachment0 + AttachmentID; /// /// Returns the of this ColorAttachment. /// public ReadBufferMode ReadBufferMode => ReadBufferMode.ColorAttachment0 + AttachmentID; /// /// Returns the of this ColorAttachment. /// public DrawBuffersEnum DrawBuffersEnum => DrawBuffersEnum.ColorAttachment0 + AttachmentID; /// /// Generates the attachment. /// /// public void Generate(Framebuffer f) { _id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, _id); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInformation.InternalFormat, (int) f.Size.X, (int) f.Size.Y, 0, PixelInformation.Format, PixelInformation.DataType, IntPtr.Zero); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) TextureParameterName.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) TextureParameterName.ClampToEdge); } } }