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 PixelFormat Renderbuffer::normalize_format(PixelFormat fmt)
29 if(!get_component_size(fmt) && OES_required_internalformat)
30 return get_default_sized_pixelformat(fmt);
35 void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht)
37 fmt = normalize_format(fmt);
38 require_pixelformat(fmt);
41 if(ARB_direct_state_access)
42 glNamedRenderbufferStorage(id, fmt, width, height);
45 BindRestore _bind(this);
46 glRenderbufferStorage(GL_RENDERBUFFER, fmt, width, height);
50 unsigned Renderbuffer::get_max_samples()
52 static unsigned max_samples = (EXT_framebuffer_multisample ? get_i(GL_MAX_SAMPLES) : 0);
56 void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht)
59 return storage(fmt, wd, ht);
61 static Require _req(EXT_framebuffer_multisample);
62 if(samples>get_max_samples())
63 throw out_of_range("Renderbuffer::storage_multisample");
65 fmt = normalize_format(fmt);
66 require_pixelformat(fmt);
70 if(ARB_direct_state_access)
71 glNamedRenderbufferStorageMultisample(id, samples, fmt, width, height);
74 BindRestore _bind(this);
75 glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, fmt, width, height);
79 void Renderbuffer::bind() const
82 glBindRenderbuffer(GL_RENDERBUFFER, id);
85 void Renderbuffer::unbind()
88 glBindRenderbuffer(GL_RENDERBUFFER, 0);