bump product version to 6.4.0.3
[LibreOffice.git] / vcl / inc / opengl / BufferObject.hxx
blob56f3aa9c20de1a5d01976406d51d239c3f8e93ab
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 */
11 #ifndef INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
12 #define INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
14 namespace vcl
17 template<typename TYPE, GLenum BUFFER_TYPE>
18 class BufferObject
20 private:
21 GLuint mId;
23 public:
24 BufferObject()
25 : mId(0)
27 glGenBuffers(1, &mId);
28 CHECK_GL_ERROR();
31 virtual ~BufferObject()
33 if (mId)
35 glDeleteBuffers(1, &mId);
36 CHECK_GL_ERROR();
37 mId = 0;
41 void bind()
43 if (mId)
45 glBindBuffer(BUFFER_TYPE, mId);
46 CHECK_GL_ERROR();
50 void unbind()
52 if (mId)
54 glBindBuffer(BUFFER_TYPE, 0);
55 CHECK_GL_ERROR();
59 void upload(const std::vector<TYPE>& rData)
61 if (mId)
63 bind();
64 glBufferData(BUFFER_TYPE, sizeof(TYPE) * rData.size(), rData.data(), GL_STATIC_DRAW);
65 CHECK_GL_ERROR();
71 template<typename TYPE>
72 class VertexBufferObject : public BufferObject<TYPE, GL_ARRAY_BUFFER>
76 class IndexBufferObject : public BufferObject<GLuint, GL_ELEMENT_ARRAY_BUFFER>
80 } // end vcl
82 #endif // INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */