]> git.tdb.fi Git - libs/gl.git/blob - source/renderbuffer.cpp
Add multiplication operators between Matrix and float
[libs/gl.git] / source / renderbuffer.cpp
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>
4 #include "misc.h"
5 #include "renderbuffer.h"
6
7 using namespace std;
8
9 namespace Msp {
10 namespace GL {
11
12 Renderbuffer::Renderbuffer()
13 {
14         static Require _req(EXT_framebuffer_object);
15
16         if(ARB_direct_state_access)
17                 glCreateRenderbuffers(1, &id);
18         else
19                 glGenRenderbuffers(1, &id);
20 }
21
22 Renderbuffer::~Renderbuffer()
23 {
24         glDeleteRenderbuffers(1, &id);
25 }
26
27 PixelFormat Renderbuffer::normalize_format(PixelFormat fmt)
28 {
29         if(!get_component_size(fmt) && OES_required_internalformat)
30                 return get_default_sized_pixelformat(fmt);
31
32         return fmt;
33 }
34
35 void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht)
36 {
37         fmt = normalize_format(fmt);
38         require_pixelformat(fmt);
39         width = wd;
40         height = ht;
41         if(ARB_direct_state_access)
42                 glNamedRenderbufferStorage(id, fmt, width, height);
43         else
44         {
45                 BindRestore _bind(this);
46                 glRenderbufferStorage(GL_RENDERBUFFER, fmt, width, height);
47         }
48 }
49
50 unsigned Renderbuffer::get_max_samples()
51 {
52         static unsigned max_samples = (EXT_framebuffer_multisample ? get_i(GL_MAX_SAMPLES) : 0);
53         return max_samples;
54 }
55
56 void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht)
57 {
58         if(!samples)
59                 return storage(fmt, wd, ht);
60
61         static Require _req(EXT_framebuffer_multisample);
62         if(samples>get_max_samples())
63                 throw out_of_range("Renderbuffer::storage_multisample");
64
65         fmt = normalize_format(fmt);
66         require_pixelformat(fmt);
67
68         width = wd;
69         height = ht;
70         if(ARB_direct_state_access)
71                 glNamedRenderbufferStorageMultisample(id, samples, fmt, width, height);
72         else
73         {
74                 BindRestore _bind(this);
75                 glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, fmt, width, height);
76         }
77 }
78
79 void Renderbuffer::bind() const
80 {
81         if(set_current(this))
82                 glBindRenderbuffer(GL_RENDERBUFFER, id);
83 }
84
85 void Renderbuffer::unbind()
86 {
87         if(set_current(0))
88                 glBindRenderbuffer(GL_RENDERBUFFER, 0);
89 }
90
91 } // namespace GL
92 } // namespace Msp