]> git.tdb.fi Git - libs/gl.git/blob - source/vertexbuffer.cpp
d579a373c249da2b39460938fbc8a8ad5b02360a
[libs/gl.git] / source / vertexbuffer.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #define GL_GLEXT_PROTOTYPES
9 #include <GL/gl.h>
10 //XXX gl.h seems to include glext.h, but can I rely on this?
11 //#include <GL/glext.h>
12 #include "vertexbuffer.h"
13
14 namespace Msp {
15 namespace GL {
16
17 VertexBuffer::VertexBuffer()
18 {
19         glGenBuffers(1, &id);
20 }
21
22 void VertexBuffer::bind() const
23 {
24         glBindBuffer(GL_ARRAY_BUFFER, id);
25         bound=this;
26 }
27
28 void VertexBuffer::data(sizei size, void *d)
29 {
30         if(bound!=this) bind();
31
32         glBufferData(GL_ARRAY_BUFFER, size, d, GL_STATIC_DRAW);
33 }
34
35 VertexBuffer::~VertexBuffer()
36 {
37         glDeleteBuffers(1, &id);
38 }
39
40 void VertexBuffer::unbind()
41 {
42         if(bound)
43         {
44                 glBindBuffer(GL_ARRAY_BUFFER, 0);
45                 bound=0;
46         }
47 }
48
49 const VertexBuffer *VertexBuffer::bound=0;
50
51 } // namespace GL
52 } // namespace Msp