using Serilog;

namespace Engine.Graphics;

public abstract class OpenGlObject
{
  public int Handle { get; protected set; } = -1;

  internal abstract void Bind();
  internal abstract void Unbind();

  protected abstract void Destroy();

  ~OpenGlObject()
  {
    if (Handle == -1)
    {
      return;
    }

    Engine.Instance.Renderer.Schedule(() =>
    {
      Destroy();

      Log.Debug("OpenGL object {Handle} destroyed", Handle);

      Handle = -1;
    });
  }
}