Loads and loads of small improvements I added while developing on my game
This commit is contained in:
parent
41421b1df9
commit
a7c71e7ea1
107 changed files with 2278 additions and 1023 deletions
|
|
@ -14,20 +14,8 @@ namespace SM.OGL.Framebuffer
|
|||
/// </summary>
|
||||
public class ColorAttachment : TextureBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a attachment with a specific id.
|
||||
/// </summary>
|
||||
/// <param name="attachmentId"></param>
|
||||
public ColorAttachment(int attachmentId) : this(attachmentId, PixelInformation.RGBA_LDR)
|
||||
{ }
|
||||
|
||||
public ColorAttachment(int attachmentID, PixelInformation pixelInformation)
|
||||
{
|
||||
|
||||
AttachmentID = attachmentID;
|
||||
PixelInformation = pixelInformation;
|
||||
}
|
||||
|
||||
private int _multisamples;
|
||||
|
||||
/// <summary>
|
||||
/// The ID the attachment was given.
|
||||
/// </summary>
|
||||
|
|
@ -50,6 +38,22 @@ namespace SM.OGL.Framebuffer
|
|||
/// </summary>
|
||||
public DrawBuffersEnum DrawBuffersEnum => DrawBuffersEnum.ColorAttachment0 + AttachmentID;
|
||||
|
||||
public bool IsMultisampled => _multisamples > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a attachment with a specific id.
|
||||
/// </summary>
|
||||
/// <param name="attachmentId"></param>
|
||||
public ColorAttachment(int attachmentId) : this(attachmentId, PixelInformation.RGBA_LDR)
|
||||
{ }
|
||||
|
||||
public ColorAttachment(int attachmentID, PixelInformation pixelInformation, int multisamples = 0)
|
||||
{
|
||||
AttachmentID = attachmentID;
|
||||
PixelInformation = pixelInformation;
|
||||
_multisamples = multisamples;
|
||||
Target = IsMultisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;
|
||||
}
|
||||
/// <summary>
|
||||
/// Generates the attachment.
|
||||
/// </summary>
|
||||
|
|
@ -57,20 +61,36 @@ namespace SM.OGL.Framebuffer
|
|||
public void Generate(Framebuffer f)
|
||||
{
|
||||
_id = GL.GenTexture();
|
||||
|
||||
if (IsMultisampled) GenerateMultisampledTexture(f);
|
||||
else GenerateTexture(f);
|
||||
}
|
||||
|
||||
private void GenerateTexture(Framebuffer f)
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2D, _id);
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInformation.InternalFormat,
|
||||
(int) f.Size.X, (int) f.Size.Y,
|
||||
(int)f.Size.X, (int)f.Size.Y,
|
||||
0, PixelInformation.Format, PixelInformation.DataType, IntPtr.Zero);
|
||||
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
|
||||
(int) TextureMinFilter.Linear);
|
||||
(int)TextureMinFilter.Linear);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
|
||||
|
||||
(int) TextureMinFilter.Linear);
|
||||
(int)TextureMinFilter.Linear);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS,
|
||||
(int) TextureParameterName.ClampToEdge);
|
||||
(int)TextureParameterName.ClampToEdge);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT,
|
||||
(int) TextureParameterName.ClampToEdge);
|
||||
(int)TextureParameterName.ClampToEdge);
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
}
|
||||
|
||||
private void GenerateMultisampledTexture(Framebuffer f)
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2DMultisample, _id);
|
||||
GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, _multisamples, PixelInformation.InternalFormat, (int)f.Size.X, (int)f.Size.Y, true);
|
||||
GL.BindTexture(TextureTarget.Texture2DMultisample, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue