]> git.tdb.fi Git - libs/gl.git/blob - source/vertexbuffer.cpp
c10dec40cc68cb551d538297f9ec115d5bb5b857
[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 const VertexBuffer *VertexBuffer::bound=0;
41
42 } // namespace GL
43 } // namespace Msp