-
-
Save bananu7/389c0db958e3906a40d0 to your computer and use it in GitHub Desktop.
Texture handle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define CREATE_HANDLE(Name, Creator, Deleter, Binder) \ | |
class Name : public boost::noncopyable { \ | |
GLuint id; \ | |
public: \ | |
void init () { \ | |
Creator(1, &id); \ | |
if (!id) \ | |
throw std::runtime_error(std::string("Error creating ") + #Name); \ | |
} \ | |
void bind (GLenum target) { \ | |
Binder(target, id); \ | |
} \ | |
void recreate () { \ | |
Deleter(1, &id); \ | |
Creator(1, &id); \ | |
if (!id) \ | |
throw std::runtime_error(std::string("Error re-creating ") + #Name); \ | |
} \ | |
~Name() { \ | |
if (id && glIsTexture(id)) \ | |
Deleter(1, &id); \ | |
} \ | |
}; | |
CREATE_HANDLE(TextureHandle, glGenTextures, glDeleteTextures, glBindTexture) | |
CREATE_HANDLE(RenderbufferHandle, glGenRenderbuffers, glDeleteRenderbuffers, glBindRenderbuffer) | |
CREATE_HANDLE(VertexBufferHandle, glGenBuffers, glDeleteBuffers, glBindBuffer); | |
#undef CREATE_HANDLE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment