Buffer *Buffer::scratch_binding = 0;
Buffer::Buffer():
- size(0),
- allocated(false)
+ size(0)
{
static Require _req(ARB_vertex_buffer_object);
throw invalid_argument("Buffer::storage");
size = sz;
-}
-
-void Buffer::allocate()
-{
- if(size==0)
- throw invalid_operation("Buffer::allocate");
- if(allocated)
- return;
if(ARB_buffer_storage)
{
bind_scratch();
glBufferStorage(GL_ARRAY_BUFFER, size, 0, flags);
}
-
- allocated = true;
}
- else
- data(0);
-}
-
-void Buffer::data(const void *d)
-{
- if(size==0)
- throw invalid_operation("Buffer::data");
-
- if(ARB_buffer_storage)
- return sub_data(0, size, d);
-
- if(ARB_direct_state_access)
- glNamedBufferData(id, size, d, GL_STATIC_DRAW);
+ else if(ARB_direct_state_access)
+ glNamedBufferData(id, size, 0, GL_STATIC_DRAW);
else
{
bind_scratch();
- glBufferData(GL_ARRAY_BUFFER, size, d, GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, size, 0, GL_STATIC_DRAW);
}
+}
- allocated = true;
+void Buffer::data(const void *d)
+{
+ return sub_data(0, size, d);
}
void Buffer::sub_data(unsigned off, unsigned sz, const void *d)
if(size==0)
throw invalid_operation("Buffer::sub_data");
- allocate();
-
if(ARB_direct_state_access)
glNamedBufferSubData(id, off, sz, d);
else
{
static Require _req(ARB_map_buffer_range);
- allocate();
if(ARB_direct_state_access)
return glMapNamedBufferRange(id, 0, size, GL_MAP_READ_BIT|GL_MAP_WRITE_BIT);
else