2 #include "arb_vertex_buffer_object.h"
11 const Buffer *Buffer::bound[4] = { 0, 0, 0, 0 };
13 Buffer::Buffer(BufferType t):
18 require_buffer_type(type);
20 glGenBuffersARB(1, &id);
25 glDeleteBuffersARB(1, &id);
28 void Buffer::require_buffer_type(BufferType type)
30 static RequireExtension _req_vbo("GL_ARB_vertex_buffer_object");
31 if(type==PIXEL_PACK_BUFFER || type==PIXEL_UNPACK_BUFFER)
32 static RequireExtension _req_pbo("GL_ARB_pixel_buffer_object");
35 void Buffer::set_usage(BufferUsage u)
40 void Buffer::data(unsigned sz, const void *d)
42 const Buffer *old = current(type);
44 glBufferDataARB(type, sz, d, usage);
49 void Buffer::sub_data(unsigned off, unsigned sz, const void *d)
51 const Buffer *old = current(type);
53 glBufferSubDataARB(type, off, sz, d);
57 void Buffer::bind_to(BufferType t) const
60 require_buffer_type(t);
61 if(set_current(t, this))
62 glBindBufferARB(t, id);
65 void Buffer::unbind_from(BufferType type)
67 if(set_current(type, 0))
68 glBindBufferARB(type, 0);
71 const Buffer *&Buffer::binding(BufferType type)
75 case ARRAY_BUFFER: return bound[0];
76 case ELEMENT_ARRAY_BUFFER: return bound[1];
77 case PIXEL_PACK_BUFFER: return bound[2];
78 case PIXEL_UNPACK_BUFFER: return bound[3];
79 default: throw invalid_argument("Buffer::binding");
83 bool Buffer::set_current(BufferType type, const Buffer *buf)
85 const Buffer *&ptr = binding(type);
93 void Buffer::restore(const Buffer *buf, BufferType type)
95 if(buf!=current(type))