diff --git a/src/Buffer.h b/src/Buffer.h index 3d473cba7..fbe036805 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -33,21 +33,38 @@ class Buffer { Buffer& operator=(Buffer&& other) = delete; public: - /** @brief Buffer type */ - enum Type { - /** - * Used for storing vertex attributes. - */ - ArrayBuffer = GL_ARRAY_BUFFER, + /** @brief %Buffer target */ + enum class Target: GLenum { + /** Used for storing vertex attributes. */ + Array = GL_ARRAY_BUFFER, - /** - * Used for storing vertex indices. - */ - ElementArrayBuffer = GL_ELEMENT_ARRAY_BUFFER + /** Source for copies. */ + CopyRead = GL_COPY_READ_BUFFER, + + /** Target for copies. */ + CopyWrite = GL_COPY_WRITE_BUFFER, + + /** Used for storing vertex indices. */ + ElementArray = GL_ELEMENT_ARRAY_BUFFER, + + /** Source for texture update operations. */ + PixelUnpack = GL_PIXEL_UNPACK_BUFFER, + + /** Target for pixel pack operations. */ + PixelPack = GL_PIXEL_PACK_BUFFER, + + /** Source for texel fetches. */ + Texture = GL_TEXTURE_BUFFER, + + /** Target for transform feedback. */ + TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER, + + /** Used for storing uniforms. */ + Uniform = GL_UNIFORM_BUFFER }; /** @brief Buffer usage */ - enum Usage { + enum class Usage: GLenum { /** * Set once by the application and used infrequently for drawing. */ @@ -71,8 +88,8 @@ class Buffer { StaticDraw = GL_STATIC_DRAW, /** - * Set once as output from an OpenGL command and queried many times - * by the application. + * Set once as output from an OpenGL command and queried many + * times by the application. */ StaticRead = GL_STATIC_READ, @@ -103,11 +120,12 @@ class Buffer { /** * @brief Constructor - * @param type Buffer type + * @param defaultTarget Default target (used when calling bind() + * without parameter) * * Generates new OpenGL buffer. */ - inline Buffer(Type type): _type(type) { + inline Buffer(Target defaultTarget): _defaultTarget(defaultTarget) { glGenBuffers(1, &buffer); } @@ -120,28 +138,51 @@ class Buffer { glDeleteBuffers(1, &buffer); } - /** @brief Buffer type */ - inline Type type() const { return _type; } + /** @brief Default bind type */ + inline Target defaultTarget() const { return _defaultTarget; } - /** @brief Bind buffer */ - inline void bind() const { - glBindBuffer(_type, buffer); + /** + * @brief Bind buffer + * + * Binds buffer with default target. + */ + inline void bind() const { bind(_defaultTarget); } + + /** + * @brief Bind buffer + * @param target %Target + */ + inline void bind(Target target) const { + glBindBuffer(static_cast(target), buffer); } /** * @brief Set buffer data * @param size Data size * @param data Pointer to data - * @param usage Buffer usage + * @param usage %Buffer usage + * + * Sets buffer data with default target. */ inline void setData(GLsizeiptr size, const GLvoid* data, Usage usage) { - bind(); - glBufferData(_type, size, data, usage); + setData(_defaultTarget, size, data, usage); + } + + /** + * @brief Set buffer data + * @param target %Target + * @param size Data size + * @param data Pointer to data + * @param usage %Buffer usage + */ + inline void setData(Target target, GLsizeiptr size, const GLvoid* data, Usage usage) { + bind(target); + glBufferData(static_cast(target), size, data, static_cast(usage)); } private: GLuint buffer; - Type _type; + Target _defaultTarget; }; } diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 12615837f..ab1442ac9 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -37,7 +37,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * setIndexCount() and setIndexType() manually for mesh to draw * properly. */ - inline IndexedMesh(): _indexBuffer(Buffer::ElementArrayBuffer), _indexCount(0), _indexType(Type::UnsignedShort) {} + inline IndexedMesh(): _indexBuffer(Buffer::Target::ElementArray), _indexCount(0), _indexType(Type::UnsignedShort) {} /** * @brief Constructor @@ -46,7 +46,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @param indexCount Count of indices * @param indexType Type of indices (indexable, see TypeTraits) */ - inline IndexedMesh(Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType = Type::UnsignedShort): Mesh(primitive, vertexCount), _indexBuffer(Buffer::ElementArrayBuffer), _indexCount(indexCount), _indexType(indexType) {} + inline IndexedMesh(Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType = Type::UnsignedShort): Mesh(primitive, vertexCount), _indexBuffer(Buffer::Target::ElementArray), _indexCount(indexCount), _indexType(indexType) {} /** @brief Index count */ inline GLsizei indexCount() const { return _indexCount; } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 850102e1c..7492b5ba1 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -28,7 +28,7 @@ Mesh::~Mesh() { } Buffer* Mesh::addBuffer(bool interleaved) { - Buffer* buffer = new Buffer(Buffer::ArrayBuffer); + Buffer* buffer = new Buffer(Buffer::Target::Array); _buffers.insert(pair > >( buffer, pair >(interleaved, vector()) diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 1cd0bcc46..989cd6000 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -49,8 +49,8 @@ const GLubyte Cube::_indices[] = { void Cube::build(IndexedMesh* mesh, Buffer* vertexBuffer) { prepareMesh(mesh); - vertexBuffer->setData(sizeof(_vertices), _vertices, Buffer::StaticDraw); - mesh->indexBuffer()->setData(sizeof(_indices), _indices, Buffer::StaticDraw); + vertexBuffer->setData(sizeof(_vertices), _vertices, Buffer::Usage::StaticDraw); + mesh->indexBuffer()->setData(sizeof(_indices), _indices, Buffer::Usage::StaticDraw); } }} diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 92707846f..c4adcfda7 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -54,7 +54,7 @@ template class Icosphere: public AbstractPrimitivebuild(mesh, vertexBuffer, Buffer::StaticDraw, Buffer::StaticDraw); + builder()->build(mesh, vertexBuffer, Buffer::Usage::StaticDraw, Buffer::Usage::StaticDraw); } private: