OGLplus (0.52.0) a C++ wrapper for OpenGL

buffer_size.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_BUFFER_SIZE_1310102147_HPP
14 #define OGLPLUS_BUFFER_SIZE_1310102147_HPP
15 
16 #include <vector>
17 #include <array>
18 
19 namespace oglplus {
20 
23 {
24 private:
25  GLsizeiptr _size;
26 public:
28  BufferSize(void)
29  : _size(0)
30  { }
31 
33  BufferSize(GLsizeiptr size)
34  : _size(size)
35  { }
36 
37  template <typename T>
38  BufferSize(unsigned count, const T*)
39  : _size(sizeof(T)*count)
40  { }
41 
42  template <typename T, std::size_t N>
43  BufferSize(const T (&)[N])
44  : _size(sizeof(T)*N)
45  { }
46 
47  template <typename T, std::size_t N>
48  BufferSize(const std::array<T, N>& a)
49  : _size(sizeof(T)*a.size())
50  { }
51 
52  template <typename T>
53  BufferSize(const std::vector<T>& v)
54  : _size(sizeof(T)*v.size())
55  { }
56 
58  GLsizeiptr Get(void) const
59  {
60  return _size;
61  }
62 
64  template <typename T>
65  static BufferSize Of(unsigned count, const T* data = nullptr)
66  {
67  return BufferSize(count, data);
68  }
69 
71  template <typename T>
72  BufferSize Add(unsigned count, const T* = nullptr) const
73  {
74  return BufferSize(_size+sizeof(T)*count);
75  }
76 
77  BufferSize Add(const BufferSize& bs)
78  {
79  return BufferSize(_size+bs._size);
80  }
81 };
82 
83 template <typename Type>
84 class BufferTypedSize
85  : public BufferSize
86 {
87 public:
88  BufferTypedSize(void) { }
89 
90  BufferTypedSize(GLsizeiptr count)
91  : BufferSize(count, (Type*)nullptr)
92  { }
93 };
94 
95 } // namespace oglplus
96 
97 #endif // include guard
This class represents the size of a GPU buffer in bytes.
Definition: buffer_size.hpp:22
BufferSize Add(unsigned count, const T *=nullptr) const
Add the size of count instances of T.
Definition: buffer_size.hpp:72
BufferSize(void)
Construction of zero size.
Definition: buffer_size.hpp:28
BufferSize(GLsizeiptr size)
Construction of the specified size in bytes.
Definition: buffer_size.hpp:33
static BufferSize Of(unsigned count, const T *data=nullptr)
Makes the size of count instances of T.
Definition: buffer_size.hpp:65
GLsizeiptr Get(void) const
Gets the size in bytes.
Definition: buffer_size.hpp:58

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).