]> git.tdb.fi Git - libs/gl.git/blob - source/renderbuffer.cpp
Automatically determine texture units for effects
[libs/gl.git] / source / renderbuffer.cpp
1 #include <msp/gl/extensions/ext_framebuffer_multisample.h>
2 #include <msp/gl/extensions/ext_framebuffer_object.h>
3 #include "renderbuffer.h"
4
5 namespace Msp {
6 namespace GL {
7
8 Renderbuffer::Renderbuffer()
9 {
10         static Require _req(EXT_framebuffer_object);
11
12         glGenRenderbuffers(1, &id);
13 }
14
15 Renderbuffer::~Renderbuffer()
16 {
17         glDeleteRenderbuffers(1, &id);
18 }
19
20 void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht)
21 {
22         require_pixelformat(fmt);
23         Bind _bind(this, true);
24         width = wd;
25         height = ht;
26         glRenderbufferStorage(GL_RENDERBUFFER, fmt, width, height);
27 }
28
29 void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht)
30 {
31         static Require _req(EXT_framebuffer_multisample);
32         require_pixelformat(fmt);
33
34         Bind _bind(this, true);
35         width = wd;
36         height = ht;
37         glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, fmt, width, height);
38 }
39
40 void Renderbuffer::bind() const
41 {
42         if(set_current(this))
43                 glBindRenderbuffer(GL_RENDERBUFFER, id);
44 }
45
46 void Renderbuffer::unbind()
47 {
48         if(set_current(0))
49                 glBindRenderbuffer(GL_RENDERBUFFER, 0);
50 }
51
52 } // namespace GL
53 } // namespace Msp