using OpenTK.Graphics.OpenGL4; 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) Compile(); return _id; } } /// /// Identifies the object. /// public abstract ObjectLabelIdentifier TypeIdentifier { get; } /// /// The action, that is called, when "ID" tries to compile something. /// protected virtual void 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) => glo.ID; } }