LibreOffice Module vcl (master)  1
BufferObject.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  */
10 
11 #ifndef INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
12 #define INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
13 
14 namespace vcl
15 {
16 
17 template<typename TYPE, GLenum BUFFER_TYPE>
19 {
20 private:
21  GLuint mId;
22 
23 public:
25  : mId(0)
26  {
27  glGenBuffers(1, &mId);
29  }
30 
31  virtual ~BufferObject()
32  {
33  if (mId)
34  {
35  glDeleteBuffers(1, &mId);
37  mId = 0;
38  }
39  }
40 
41  void bind()
42  {
43  if (mId)
44  {
45  glBindBuffer(BUFFER_TYPE, mId);
47  }
48  }
49 
50  void unbind()
51  {
52  if (mId)
53  {
54  glBindBuffer(BUFFER_TYPE, 0);
56  }
57  }
58 
59  void upload(const std::vector<TYPE>& rData)
60  {
61  if (mId)
62  {
63  bind();
64  glBufferData(BUFFER_TYPE, sizeof(TYPE) * rData.size(), rData.data(), GL_STATIC_DRAW);
66  }
67  }
68 
69 };
70 
71 template<typename TYPE>
72 class VertexBufferObject : public BufferObject<TYPE, GL_ARRAY_BUFFER>
73 {
74 };
75 
76 class IndexBufferObject : public BufferObject<GLuint, GL_ELEMENT_ARRAY_BUFFER>
77 {
78 };
79 
80 } // end vcl
81 
82 #endif // INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
83 
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~BufferObject()
TYPE
void upload(const std::vector< TYPE > &rData)
#define CHECK_GL_ERROR()