1 #include <msp/gl/extensions/arb_direct_state_access.h>
2 #include <msp/gl/extensions/ext_framebuffer_multisample.h>
3 #include <msp/gl/extensions/ext_framebuffer_object.h>
5 #include "renderbuffer.h"
12 Renderbuffer::Renderbuffer()
14 static Require _req(EXT_framebuffer_object);
16 if(ARB_direct_state_access)
17 glCreateRenderbuffers(1, &id);
19 glGenRenderbuffers(1, &id);
22 Renderbuffer::~Renderbuffer()
24 glDeleteRenderbuffers(1, &id);
27 void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht)
29 require_pixelformat(fmt);
32 if(ARB_direct_state_access)
33 glNamedRenderbufferStorage(id, fmt, width, height);
36 BindRestore _bind(this);
37 glRenderbufferStorage(GL_RENDERBUFFER, fmt, width, height);
41 unsigned Renderbuffer::get_max_samples()
43 static unsigned max_samples = (EXT_framebuffer_multisample ? get_i(GL_MAX_SAMPLES) : 0);
47 void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht)
50 return storage(fmt, wd, ht);
52 static Require _req(EXT_framebuffer_multisample);
53 if(samples>get_max_samples())
54 throw out_of_range("Renderbuffer::storage_multisample");
56 require_pixelformat(fmt);
60 if(ARB_direct_state_access)
61 glNamedRenderbufferStorageMultisample(id, samples, fmt, width, height);
64 BindRestore _bind(this);
65 glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, fmt, width, height);
69 void Renderbuffer::bind() const
72 glBindRenderbuffer(GL_RENDERBUFFER, id);
75 void Renderbuffer::unbind()
78 glBindRenderbuffer(GL_RENDERBUFFER, 0);