#region usings
using System.Diagnostics;
using OpenTK.Graphics.OpenGL4;
#endregion
namespace SM.OGL
{
///
/// Specifies default object behaviour.
///
public abstract class GLObject
{
///
/// Contains the OpenGL ID
///
protected int _id = -1;
///
/// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
///
protected virtual bool AutoCompile { get; } = false;
///
/// Checks if the object was compiled.
///
public bool WasCompiled => _id > 0;
///
/// Returns the id for this object.
/// It will auto compile, if needed and allowed.
///
public virtual int ID
{
get
{
if (AutoCompile && !WasCompiled) PerformCompile();
return _id;
}
}
///
/// Identifies the object.
///
public abstract ObjectLabelIdentifier TypeIdentifier { get; }
[DebuggerStepThrough]
private void PerformCompile()
{
Compile();
}
///
/// The action, that is called, when "ID" tries to compile something.
///
public virtual void Compile()
{
}
///
/// Is triggered, when something want to dispose this object.
///
public virtual void Dispose()
{
}
///
/// Re-compiles the object.
///
public void Recompile()
{
if (!WasCompiled) return;
Dispose();
Compile();
}
///
/// Names the object for debugging.
///
///
public void Name(string name)
{
if (GLSystem.Debugging) GL.ObjectLabel(TypeIdentifier, _id, name.Length, name);
}
///
/// Returns the ID for the object.
///
///
public static implicit operator int(GLObject glo)
{
return glo.ID;
}
}
}