zMol
A viewer for molecular data using OpenGL and ambient occlusion
buffer_object.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_BUFFER_OBJECT_HPP
29 #define ZMOL_BUFFER_OBJECT_HPP
30 
31 #include "opengl3.hpp"
32 #include "noncopyable.hpp"
33 
34 
35 namespace zmol
36 {
37 
38 
51  private noncopyable
52 {
53 public:
60  explicit buffer_object(GLenum const p_target, GLenum const p_usage);
65 
69  inline GLuint get_name() const
70  {
71  return m_name;
72  }
73 
77  inline GLenum get_target() const
78  {
79  return m_target;
80  }
81 
85  inline GLenum get_usage() const
86  {
87  return m_usage;
88  }
89 
93  void bind();
97  void unbind();
98 
106  void upload_data(void const *p_data, unsigned long const p_num_bytes);
114  void resize(unsigned long const p_num_bytes);
115 
119  inline unsigned long get_size() const
120  {
121  return m_size; // also used in buffer_object_mapping in assert() expressions to catch out-of-bound errors
122  }
123 
124 protected:
125  GLuint m_name;
126  GLenum m_target, m_usage;
127  unsigned long m_size;
128 };
129 
130 
148  private noncopyable
149 {
150 public:
156  explicit buffer_object_mapping(buffer_object &p_bufobj, GLenum const p_access);
164  explicit buffer_object_mapping(buffer_object &p_bufobj, GLenum const p_access, GLintptr const p_offset, GLsizeiptr p_length);
169 
173  void* get_mapped_pointer();
177  void const * get_mapped_pointer() const;
178 
185  void flush_subrange(GLintptr const p_offset, GLsizeiptr p_length);
190  void flush_entire_range();
191 
192 private:
193  buffer_object &m_bufobj;
194  GLvoid *m_mapped_pointer;
195  GLintptr m_flush_offset;
196  GLsizeiptr m_flush_length;
197  bool m_explicit_flush;
198 };
199 
200 
201 // glBindBufferBase
202 void bind_to_indexed_target(buffer_object &p_bufobj, GLenum const p_target, GLuint const p_index);
203 // glBindBufferRange
204 void bind_to_indexed_target(buffer_object &p_bufobj, GLenum const p_target, GLuint const p_index, GLintptr const p_offset, GLsizeiptr const p_size);
205 
206 
207 }
208 
209 
210 #endif
211