#pragma once

#include <gl/gl.h>

class ScopedGlShader
{
public:
	explicit ScopedGlShader(GLuint shader = 0) : mShader(shader) {}
	~ScopedGlShader() { reset(); }

	ScopedGlShader(const ScopedGlShader&) = delete;
	ScopedGlShader& operator=(const ScopedGlShader&) = delete;

	GLuint get() const { return mShader; }
	GLuint release()
	{
		GLuint shader = mShader;
		mShader = 0;
		return shader;
	}
	void reset(GLuint shader = 0)
	{
		if (mShader != 0)
			glDeleteShader(mShader);
		mShader = shader;
	}

private:
	GLuint mShader;
};

class ScopedGlProgram
{
public:
	explicit ScopedGlProgram(GLuint program = 0) : mProgram(program) {}
	~ScopedGlProgram() { reset(); }

	ScopedGlProgram(const ScopedGlProgram&) = delete;
	ScopedGlProgram& operator=(const ScopedGlProgram&) = delete;

	GLuint get() const { return mProgram; }
	GLuint release()
	{
		GLuint program = mProgram;
		mProgram = 0;
		return program;
	}
	void reset(GLuint program = 0)
	{
		if (mProgram != 0)
			glDeleteProgram(mProgram);
		mProgram = program;
	}

private:
	GLuint mProgram;
};
