]> git.tdb.fi Git - libs/gl.git/blob - source/core/renderbuffer.cpp
Export texture extension modes from Blender
[libs/gl.git] / source / core / 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 void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht)
28 {
29         require_pixelformat(fmt);
30         width = wd;
31         height = ht;
32         if(ARB_direct_state_access)
33                 glNamedRenderbufferStorage(id, fmt, width, height);
34         else
35         {
36                 BindRestore _bind(this);
37                 glRenderbufferStorage(GL_RENDERBUFFER, fmt, width, height);
38         }
39 }
40
41 unsigned Renderbuffer::get_max_samples()
42 {
43         static unsigned max_samples = (EXT_framebuffer_multisample ? get_i(GL_MAX_SAMPLES) : 0);
44         return max_samples;
45 }
46
47 void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht)
48 {
49         if(!samples)
50                 return storage(fmt, wd, ht);
51
52         static Require _req(EXT_framebuffer_multisample);
53         if(samples>get_max_samples())
54                 throw out_of_range("Renderbuffer::storage_multisample");
55
56         require_pixelformat(fmt);
57
58         width = wd;
59         height = ht;
60         if(ARB_direct_state_access)
61                 glNamedRenderbufferStorageMultisample(id, samples, fmt, width, height);
62         else
63         {
64                 BindRestore _bind(this);
65                 glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, fmt, width, height);
66         }
67 }
68
69 void Renderbuffer::bind() const
70 {
71         if(set_current(this))
72                 glBindRenderbuffer(GL_RENDERBUFFER, id);
73 }
74
75 void Renderbuffer::unbind()
76 {
77         if(set_current(0))
78                 glBindRenderbuffer(GL_RENDERBUFFER, 0);
79 }
80
81 } // namespace GL
82 } // namespace Msp