GLS  1.0.0
GL Stuff - A library aimed at reducing the boilerplate OpenGL code you always have to write.
renderbuffer.hpp
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 #include <gls/headercheck.hpp>
8 #include <gls/errorcheck.hpp>
9 #include <gls/objects/object.hpp>
10 #include <cassert>
11 
12 namespace gls {
13 
14 namespace priv {
15  void gen_renderbuffers( GLsizei size, GLuint* name ) { glGenRenderbuffers( size, name ); }
16  void delete_renderbuffers( GLsizei size, const GLuint* name ) { glDeleteRenderbuffers( size, name ); }
17 }
18 
23 class renderbuffer {
24 public:
35  renderbuffer( GLenum internal_format, GLsizei the_width, GLsizei the_height ) :
36  renderbuffer( 0, internal_format, the_width, the_height )
37  {
38  }
39 
51  renderbuffer( GLsizei samples, GLenum internal_format, GLsizei the_width, GLsizei the_height ) :
52  m_width( the_width ),
53  m_height( the_height )
54  {
55  auto max_samples = GLint();
56  auto max_renderbuffer_size = GLint();
57 
58  check_gl_error( glGetIntegerv( GL_MAX_SAMPLES, &max_samples ) );
59  check_gl_error( glGetIntegerv( GL_MAX_RENDERBUFFER_SIZE, &max_renderbuffer_size ) );
60 
61  assert( samples <= static_cast<GLsizei>( max_samples ) );
62  assert( the_width <= static_cast<GLsizei>( max_renderbuffer_size ) );
63  assert( the_height <= static_cast<GLsizei>( max_renderbuffer_size ) );
64 
65  bind();
66  check_gl_error( glRenderbufferStorageMultisample( GL_RENDERBUFFER, samples, internal_format, the_width, the_height ) );
67  unbind();
68  }
69 
76  GLuint name() const {
77  return m_object.name();
78  }
79 
86  GLsizei width() const {
87  return m_width;
88  }
89 
96  GLsizei height() const {
97  return m_width;
98  }
99 
104  void bind() {
105  check_gl_error( glBindRenderbuffer( GL_RENDERBUFFER, m_object.name() ) );
106  }
107 
112  static void unbind() {
113  check_gl_error( glBindRenderbuffer( GL_RENDERBUFFER, 0 ) );
114  }
115 
116 private:
118  GLsizei m_width;
119  GLsizei m_height;
120 };
121 
122 }
123 
void bind()
Bind this renderbuffer.
Definition: renderbuffer.hpp:104
GLsizei height() const
Retrieve the height of the allocated renderbuffer storage.
Definition: renderbuffer.hpp:96
GLsizei width() const
Retrieve the width of the allocated renderbuffer storage.
Definition: renderbuffer.hpp:86
renderbuffer(GLenum internal_format, GLsizei the_width, GLsizei the_height)
Construct a gls::renderbuffer without multi-sampling.
Definition: renderbuffer.hpp:35
renderbuffer(GLsizei samples, GLenum internal_format, GLsizei the_width, GLsizei the_height)
Construct a gls::renderbuffer with multi-sampling.
Definition: renderbuffer.hpp:51
GLuint name() const
Retrieve the OpenGL name of this renderbuffer.
Definition: renderbuffer.hpp:76
Class encapsulating an OpenGL renderbuffer object.
Definition: renderbuffer.hpp:23
static void unbind()
Unbind the currently bound renderbuffer.
Definition: renderbuffer.hpp:112
Definition: buffer.hpp:12