Strange attractors with OpenCL
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

58 lines
1.5 KiB

#pragma once
#include <moggle/core/gl.hpp>
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;
};
}