]> git.tdb.fi Git - libs/gl.git/blob - source/vertexbuffer.cpp
Windows compatibility:
[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 #include "arb_vertex_buffer_object.h"
9 #include "extension.h"
10 #include "vertexbuffer.h"
11
12 namespace Msp {
13 namespace GL {
14
15 VertexBuffer::VertexBuffer()
16 {
17         require_extension("GL_ARB_vertex_buffer_object");
18
19         glGenBuffersARB(1, &id);
20 }
21
22 void VertexBuffer::bind() const
23 {
24         glBindBufferARB(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         glBufferDataARB(GL_ARRAY_BUFFER, size, d, GL_STATIC_DRAW);
33 }
34
35 VertexBuffer::~VertexBuffer()
36 {
37         glDeleteBuffersARB(1, &id);
38 }
39
40 void VertexBuffer::unbind()
41 {
42         if(bound)
43         {
44                 glBindBufferARB(GL_ARRAY_BUFFER, 0);
45                 bound=0;
46         }
47 }
48
49 const VertexBuffer *VertexBuffer::bound=0;
50
51 } // namespace GL
52 } // namespace Msp