nss: upgrade to release 3.73
[LibreOffice.git] / vcl / inc / opengl / BufferObject.hxx
blobe31148b74c6e6eb022fb938277a183d0e7794f7f
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
16 template <typename TYPE, GLenum BUFFER_TYPE> class BufferObject
18 private:
19 GLuint mId;
21 public:
22 BufferObject()
23 : mId(0)
25 glGenBuffers(1, &mId);
26 CHECK_GL_ERROR();
29 virtual ~BufferObject()
31 if (mId)
33 glDeleteBuffers(1, &mId);
34 CHECK_GL_ERROR();
35 mId = 0;
39 void bind()
41 if (mId)
43 glBindBuffer(BUFFER_TYPE, mId);
44 CHECK_GL_ERROR();
48 void unbind()
50 if (mId)
52 glBindBuffer(BUFFER_TYPE, 0);
53 CHECK_GL_ERROR();
57 void upload(const std::vector<TYPE>& rData)
59 if (mId)
61 bind();
62 glBufferData(BUFFER_TYPE, sizeof(TYPE) * rData.size(), rData.data(), GL_STATIC_DRAW);
63 CHECK_GL_ERROR();
68 template <typename TYPE> class VertexBufferObject final : public BufferObject<TYPE, GL_ARRAY_BUFFER>
72 class IndexBufferObject final : public BufferObject<GLuint, GL_ELEMENT_ARRAY_BUFFER>
76 } // end vcl
78 #endif // INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */