mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
Add VertexBuffer::Mapper for RAII vbo mapping
This commit is contained in:
@@ -69,8 +69,9 @@ namespace opengl
|
|||||||
// Fill element buffer.
|
// Fill element buffer.
|
||||||
{
|
{
|
||||||
VertexBuffer::Bind bind(*element_buf);
|
VertexBuffer::Bind bind(*element_buf);
|
||||||
|
VertexBuffer::Mapper mapper(*element_buf, GL_WRITE_ONLY);
|
||||||
|
|
||||||
GLushort *indices = static_cast<GLushort*>(element_buf->map(GL_WRITE_ONLY));
|
GLushort *indices = static_cast<GLushort*>(mapper.get());
|
||||||
|
|
||||||
if (indices)
|
if (indices)
|
||||||
{
|
{
|
||||||
@@ -85,8 +86,6 @@ namespace opengl
|
|||||||
indices[i*6+5] = 3+(i*4);
|
indices[i*6+5] = 3+(i*4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element_buf->unmap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,6 +173,33 @@ namespace opengl
|
|||||||
VertexBuffer &buf;
|
VertexBuffer &buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Mapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Memory-maps a VertexBuffer.
|
||||||
|
*/
|
||||||
|
Mapper(VertexBuffer& buffer, GLenum access)
|
||||||
|
: buf(buffer)
|
||||||
|
{ elems = buf.map(access); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unmaps the buffer
|
||||||
|
*/
|
||||||
|
~Mapper()
|
||||||
|
{ buf.unmap(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get pointer to memory mapped region
|
||||||
|
*/
|
||||||
|
void* get()
|
||||||
|
{ return elems; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
VertexBuffer &buf;
|
||||||
|
void* elems;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// The size of the buffer, in bytes.
|
// The size of the buffer, in bytes.
|
||||||
|
|||||||
Reference in New Issue
Block a user