#region usings
using OpenTK;
using OpenTK.Graphics.OpenGL4;
using System;
#endregion
namespace SM.OGL.Texture
{
///
/// Works as a basis for textures.
///
public abstract class TextureBase : GLObject
{
///
protected override bool AutoCompile { get; set; } = true;
///
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Texture;
///
/// Contains the specific information of each pixel.
///
public PixelInformation PixelInformation;
///
/// The target of the texture.
///
public TextureTarget Target { get; set; } = TextureTarget.Texture2D;
///
/// The texture filter.
/// Default:
///
public virtual TextureMinFilter Filter { get; set; } = TextureMinFilter.Linear;
///
/// The wrap mode.
/// Default:
///
public virtual TextureWrapMode WrapMode { get; set; } = TextureWrapMode.Repeat;
///
/// The Width of the texture
///
public virtual int Width { get; protected set; }
///
/// The height of the texture
///
public virtual int Height { get; protected set; }
public Vector2 Size => new Vector2(Width, Height);
public Vector2 TexelSize => new Vector2(1f / Width, 1f / Height);
///
public override void Dispose()
{
GL.DeleteTexture(_id);
base.Dispose();
}
protected void GenerateBaseTexture(Vector2 size)
{
Width = (int)size.X;
Height = (int)size.Y;
GL.BindTexture(TextureTarget.Texture2D, _id);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInformation.InternalFormat,
Width, Height, 0,
PixelInformation.Format, PixelInformation.DataType, IntPtr.Zero);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)Filter);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)Filter);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS,
(int)WrapMode);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT,
(int)WrapMode);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
}
}