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);
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;
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;
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);
}
}
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);
}
}
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;
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())
{
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
friend class BufferRange;
private:
- BufferType type;
unsigned id;
unsigned size;
bool allocated;
static const Buffer *bound[5];
public:
- Buffer(BufferType);
+ Buffer();
~Buffer();
private:
/** Returns the OpenGL ID of the buffer. For internal use only. */
unsigned get_id() const { return id; }
- /** Returns the default binding type for the buffer. */
- BufferType get_type() const { return type; }
-
/** Defines the storage size of the buffer. Must be called before data can
be uploaded. Storage cannot be changed once set. */
void storage(unsigned);
DEPRECATED void *map(BufferAccess) { return map(); }
bool unmap();
- /** Binds the buffer in its default slot. */
- void bind() const { bind_to(type); }
-
- /** Binds the buffer in an alternate slot. */
+ /** Binds the buffer. */
void bind_to(BufferType) const;
- /** Unbinds the buffer from its default slot. */
- void unbind() const { unbind_from(type); }
-
static const Buffer *current(BufferType);
static void unbind_from(BufferType);
private: