X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fbuffer.cpp;h=98625b813bdfd9a626d8be87f52e6a2d7db228d6;hb=86721a55699193e63c76e8a0a7b0ced0416c1cce;hp=56705b8701b88a00b691bf25725d10042554679a;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/core/buffer.cpp b/source/core/buffer.cpp index 56705b87..98625b81 100644 --- a/source/core/buffer.cpp +++ b/source/core/buffer.cpp @@ -18,7 +18,8 @@ BufferType buffer_types[] = { ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUF Buffer::Buffer(BufferType t): type(t), - size(0) + size(0), + allocated(false) { require_buffer_type(type); @@ -53,6 +54,15 @@ void Buffer::storage(unsigned sz) 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) { static const int flags = GL_MAP_READ_BIT|GL_MAP_WRITE_BIT|GL_DYNAMIC_STORAGE_BIT; @@ -63,7 +73,11 @@ void Buffer::storage(unsigned sz) BindRestore _bind(this, type); glBufferStorage(type, size, 0, flags); } + + allocated = true; } + else + data(0); } void Buffer::set_usage(BufferUsage) @@ -85,6 +99,8 @@ void Buffer::data(const void *d) BindRestore _bind(this, type); glBufferData(type, size, d, STATIC_DRAW); } + + allocated = true; } void Buffer::data(unsigned sz, const void *d) @@ -99,6 +115,11 @@ void Buffer::data(unsigned sz, const void *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 @@ -121,6 +142,7 @@ BufferRange *Buffer::create_range(unsigned s, unsigned o) void *Buffer::map() { + allocate(); if(ARB_map_buffer_range) { if(ARB_direct_state_access)