]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/buffer.cpp
Remove the notion of default binding point from Buffer
[libs/gl.git] / source / core / buffer.cpp
index 013a136a560a2a5866ee6bf7c343b0102cf9e246..4750846ab1dceb291a600043977f1c06f868f403 100644 (file)
@@ -18,12 +18,11 @@ namespace GL {
 const Buffer *Buffer::bound[5] = { 0, 0, 0, 0, 0 };
 BufferType buffer_types[] = { ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, UNIFORM_BUFFER };
 
-Buffer::Buffer(BufferType t):
-       type(t),
+Buffer::Buffer():
        size(0),
        allocated(false)
 {
-       require_buffer_type(type);
+       static Require _req(ARB_vertex_buffer_object);
 
        if(ARB_direct_state_access)
                glCreateBuffers(1, &id);
@@ -76,8 +75,8 @@ void Buffer::allocate()
                        glNamedBufferStorage(id, size, 0, flags);
                else
                {
-                       BindRestore _bind(this, type);
-                       glBufferStorage(type, size, 0, flags);
+                       BindRestore _bind(this, ARRAY_BUFFER);
+                       glBufferStorage(ARRAY_BUFFER, size, 0, flags);
                }
 
                allocated = true;
@@ -102,8 +101,8 @@ void Buffer::data(const void *d)
                glNamedBufferData(id, size, d, STATIC_DRAW);
        else
        {
-               BindRestore _bind(this, type);
-               glBufferData(type, size, d, STATIC_DRAW);
+               BindRestore _bind(this, ARRAY_BUFFER);
+               glBufferData(ARRAY_BUFFER, size, d, STATIC_DRAW);
        }
 
        allocated = true;
@@ -130,8 +129,8 @@ void Buffer::sub_data(unsigned off, unsigned sz, const void *d)
                glNamedBufferSubData(id, off, sz, d);
        else
        {
-               BindRestore _bind(this, type);
-               glBufferSubData(type, off, sz, d);
+               BindRestore _bind(this, ARRAY_BUFFER);
+               glBufferSubData(ARRAY_BUFFER, off, sz, d);
        }
 }
 
@@ -155,8 +154,8 @@ void *Buffer::map()
                return glMapNamedBufferRange(id, 0, size, GL_MAP_READ_BIT|GL_MAP_WRITE_BIT);
        else
        {
-               BindRestore _bind(this, type);
-               return glMapBufferRange(type, 0, size, GL_MAP_READ_BIT|GL_MAP_WRITE_BIT);
+               BindRestore _bind(this, ARRAY_BUFFER);
+               return glMapBufferRange(ARRAY_BUFFER, 0, size, GL_MAP_READ_BIT|GL_MAP_WRITE_BIT);
        }
 }
 
@@ -167,8 +166,8 @@ bool Buffer::unmap()
                return glUnmapNamedBuffer(id);
        else if(OES_mapbuffer)
        {
-               BindRestore _bind(this, type);
-               return glUnmapBuffer(type);
+               BindRestore _bind(this, ARRAY_BUFFER);
+               return glUnmapBuffer(ARRAY_BUFFER);
        }
        else
                return true;
@@ -176,8 +175,7 @@ bool Buffer::unmap()
 
 void Buffer::bind_to(BufferType t) const
 {
-       if(t!=type)
-               require_buffer_type(t);
+       require_buffer_type(t);
        if(t==ELEMENT_ARRAY_BUFFER)
                if(const VertexSetup *vs = VertexSetup::current())
                {
@@ -265,8 +263,7 @@ void BufferRange::data(const void *d)
 
 void BufferRange::bind_to(BufferType t, unsigned i)
 {
-       if(t!=buffer.type)
-               Buffer::require_buffer_type(t);
+       Buffer::require_buffer_type(t);
        if(set_current(t, i, this))
        {
                // The buffer gets bound as a side effect