zMol
A viewer for molecular data using OpenGL and ambient occlusion
fbo.hpp
1 /****************************************************************************
2 
3 Copyright (c) 2012 Carlos Rafael Giani ( email: dv xxx AT pseudoterminal xxx DOT xxx org , remove the xxx )
4 
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source
22  distribution.
23 
24 ****************************************************************************/
25 
26 
27 
28 #ifndef ZMOL_FBO_HPP
29 #define ZMOL_FBO_HPP
30 
31 #include <algorithm>
32 #include <vector>
33 #include "opengl3.hpp"
34 #include "texture.hpp"
35 #include "noncopyable.hpp"
36 
37 
38 namespace zmol
39 {
40 
41 
48  class fbo:
49  private noncopyable
50 {
51 public:
57  explicit fbo(GLenum const p_target = GL_FRAMEBUFFER);
61  ~fbo();
62 
66  inline GLuint get_name() const
67  {
68  return m_name;
69  }
70 
74  inline GLuint get_target() const
75  {
76  return m_target;
77  }
78 
82  void bind();
86  void unbind();
87 
88 protected:
89  GLuint m_name;
90  GLenum m_target;
91 };
92 
93 
101  private noncopyable
102 {
103 public:
112  explicit renderbuffer(GLenum const p_format, GLsizei const p_width, GLsizei const p_height, GLsizei const p_num_antialiasing_samples);
116  ~renderbuffer();
117 
121  inline GLuint get_name() const
122  {
123  return m_name;
124  }
125 
129  void bind();
133  void unbind();
134 
135 protected:
136  GLuint m_name;
137 
138 };
139 
140 
147 void attach_to(fbo &p_fbo, GLenum const p_attachment, renderbuffer const &p_renderbuf);
154 void attach_to(fbo &p_fbo, GLenum const p_attachment, texture const &p_texture);
161 void detach_from(fbo &p_fbo, GLenum const p_attachment, renderbuffer const &p_renderbuf);
168 void detach_from(fbo &p_fbo, GLenum const p_attachment, texture const &p_texture);
169 
170 
175 void set_draw_buffer(GLenum const p_buffer);
182 void set_draw_buffers(GLsizei const p_num_buffers, GLenum const * p_buffers);
183 
184 
185 namespace detail
186 {
187 
188 
189 template < typename Buffers >
190 struct set_draw_buffers_impl
191 {
192  inline void operator()(Buffers const &p_buffers) const
193  {
194  std::vector < GLenum > buffers_array;
195  std::copy(p_buffers.begin(), p_buffers.end(), std::back_inserter(buffers_array));
196  set_draw_buffers(buffers_array.size(), &buffers_array[0]);
197  }
198 };
199 
200 
201 template < typename T, typename Alloc >
202 struct set_draw_buffers_impl < std::vector < T, Alloc > >
203 {
204  inline void operator()(std::vector < T, Alloc > const &p_buffers) const
205  {
206  set_draw_buffers(p_buffers.size(), &p_buffers[0]);
207  }
208 };
209 
210 
211 }
212 
213 
220 template < typename Buffers >
221 inline void set_draw_buffers(Buffers const &p_buffers)
222 {
223  detail::set_draw_buffers_impl < Buffers > ()(p_buffers);
224 }
225 
226 
227 }
228 
229 
230 #endif
231