]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/buffer.cpp
Remove the separate allocation step from textures and buffers
[libs/gl.git] / source / core / buffer.cpp
index 78e85af0456b721a27316d9622849f00a2b37c3e..dcb83a7a5960f1cb48436cb9cff5063327c4d5f2 100644 (file)
@@ -2,13 +2,12 @@
 #include <msp/gl/extensions/arb_buffer_storage.h>
 #include <msp/gl/extensions/arb_direct_state_access.h>
 #include <msp/gl/extensions/arb_map_buffer_range.h>
+#include <msp/gl/extensions/arb_vertex_buffer_object.h>
 #include <msp/gl/extensions/khr_debug.h>
+#include <msp/gl/extensions/oes_mapbuffer.h>
 #include <msp/strings/format.h>
 #include "buffer.h"
-#include "deviceinfo.h"
 #include "error.h"
-#include "misc.h"
-#include "vertexsetup.h"
 
 using namespace std;
 
@@ -18,8 +17,7 @@ namespace GL {
 Buffer *Buffer::scratch_binding = 0;
 
 Buffer::Buffer():
-       size(0),
-       allocated(false)
+       size(0)
 {
        static Require _req(ARB_vertex_buffer_object);
 
@@ -48,14 +46,6 @@ 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)
        {
@@ -67,44 +57,19 @@ void Buffer::allocate()
                        bind_scratch();
                        glBufferStorage(GL_ARRAY_BUFFER, size, 0, flags);
                }
-
-               allocated = true;
        }
-       else
-               data(0);
-}
-
-void Buffer::set_usage(BufferUsage)
-{
-}
-
-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, STATIC_DRAW);
+       else if(ARB_direct_state_access)
+               glNamedBufferData(id, size, 0, GL_STATIC_DRAW);
        else
        {
                bind_scratch();
-               glBufferData(GL_ARRAY_BUFFER, size, d, STATIC_DRAW);
+               glBufferData(GL_ARRAY_BUFFER, size, 0, GL_STATIC_DRAW);
        }
-
-       allocated = true;
 }
 
-void Buffer::data(unsigned sz, const void *d)
+void Buffer::data(const void *d)
 {
-       if(size==0)
-               storage(sz);
-       else if(sz!=size)
-               throw incompatible_data("Buffer::data");
-
-       data(d);
+       return sub_data(0, size, d);
 }
 
 void Buffer::sub_data(unsigned off, unsigned sz, const void *d)
@@ -112,8 +77,6 @@ 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
@@ -133,7 +96,6 @@ void *Buffer::map()
 {
        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