#pragma once #include namespace moggle { struct renderbuffer { explicit renderbuffer(bool create_now = false) { if(create_now) create(); } ~renderbuffer() { destroy(); } renderbuffer(renderbuffer const &) = delete; renderbuffer & operator=(renderbuffer const&) = delete; renderbuffer(renderbuffer && r) : id(r.id) { r.id = 0; } renderbuffer & operator=(renderbuffer && r) { std::swap(id, r.id); return *this; } bool created() const { return id; } explicit operator bool() const { return created(); } void create(){ if(!id) gl::generate_renderbuffers(1, &id); } void destroy(){ gl::delete_renderbuffers(1, &id); id = 0; } void bind() { create(); gl::bind_renderbuffer(GL_RENDERBUFFER, id); } GLuint get_id() const { return id; } void storage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height){ bind(); gl::renderbuffer_storage(target, internalformat, width, height); } void storage_multisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height){ bind(); // TODO: wrap this call glRenderbufferStorageMultisample(target, samples, internalformat, width, height); } static renderbuffer create(GLsizei width, GLsizei height, GLsizei samples = 1, GLenum format = GL_RGBA4){ renderbuffer r; if(samples <= 1) r.storage(GL_RENDERBUFFER, format, width, height); else r.storage_multisample(GL_RENDERBUFFER, samples, format, width, height); return r; } private: GLuint id = 0; }; }