From c4bb714e548f3f6afc1cd11b33a4d8e2d599023d Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Fri, 9 Sep 2016 21:13:21 +0100 Subject: [PATCH] clang-format files in rwlib/source/gl --- rwlib/source/gl/DrawBuffer.cpp | 48 ++++++------- rwlib/source/gl/DrawBuffer.hpp | 51 ++++++------- rwlib/source/gl/GeometryBuffer.cpp | 30 ++++---- rwlib/source/gl/GeometryBuffer.hpp | 111 +++++++++++++++-------------- rwlib/source/gl/TextureData.hpp | 49 +++++++------ 5 files changed, 143 insertions(+), 146 deletions(-) diff --git a/rwlib/source/gl/DrawBuffer.cpp b/rwlib/source/gl/DrawBuffer.cpp index 7f4f7f03..434cfec9 100644 --- a/rwlib/source/gl/DrawBuffer.cpp +++ b/rwlib/source/gl/DrawBuffer.cpp @@ -4,37 +4,29 @@ /* TODO: Come up with a more elegant solution to "WHICH ARRAY IS IT?" */ std::map semantic_to_attrib_array = { - {ATRS_Position, 0}, - {ATRS_Normal, 1}, - {ATRS_Colour, 2}, - {ATRS_TexCoord, 3} -}; - -DrawBuffer::DrawBuffer() -: vao(0) -{ + {ATRS_Position, 0}, {ATRS_Normal, 1}, {ATRS_Colour, 2}, {ATRS_TexCoord, 3}}; +DrawBuffer::DrawBuffer() : vao(0) { } -DrawBuffer::~DrawBuffer() -{ - if(vao) { - glDeleteVertexArrays(1, &vao); - } +DrawBuffer::~DrawBuffer() { + if (vao) { + glDeleteVertexArrays(1, &vao); + } } -void DrawBuffer::addGeometry(GeometryBuffer* gbuff) -{ - if(vao == 0) { - glGenVertexArrays(1, &vao); - } - - glBindVertexArray(vao); - glBindBuffer(GL_ARRAY_BUFFER, gbuff->getVBOName()); - // Iterate the attributes present in the gbuff - for(const AttributeIndex& at : gbuff->getDataAttributes()) { - GLuint vaoindex = semantic_to_attrib_array[at.sem]; - glEnableVertexAttribArray(vaoindex); - glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride, reinterpret_cast(at.offset)); - } +void DrawBuffer::addGeometry(GeometryBuffer* gbuff) { + if (vao == 0) { + glGenVertexArrays(1, &vao); + } + + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, gbuff->getVBOName()); + // Iterate the attributes present in the gbuff + for (const AttributeIndex& at : gbuff->getDataAttributes()) { + GLuint vaoindex = semantic_to_attrib_array[at.sem]; + glEnableVertexAttribArray(vaoindex); + glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride, + reinterpret_cast(at.offset)); + } } diff --git a/rwlib/source/gl/DrawBuffer.hpp b/rwlib/source/gl/DrawBuffer.hpp index a65cc2c4..e2bccacd 100644 --- a/rwlib/source/gl/DrawBuffer.hpp +++ b/rwlib/source/gl/DrawBuffer.hpp @@ -1,35 +1,38 @@ -#pragma once +#pragma once #ifndef _DRAWBUFFER_HPP_ #define _DRAWBUFFER_HPP_ #include class GeometryBuffer; -/** - * DrawBuffer stores VAO state +/** + * DrawBuffer stores VAO state */ class DrawBuffer { - GLuint vao; - - GLenum facetype; + GLuint vao; + + GLenum facetype; + public: - - DrawBuffer(); - ~DrawBuffer(); - - GLuint getVAOName() const - { return vao; } - - void setFaceType(GLenum ft) - { facetype = ft; } - - GLenum getFaceType() const - { return facetype; } - - /** - * Adds a Geometry Buffer to the Draw Buffer. - */ - void addGeometry(GeometryBuffer* gbuff); + DrawBuffer(); + ~DrawBuffer(); + + GLuint getVAOName() const { + return vao; + } + + void setFaceType(GLenum ft) { + facetype = ft; + } + + GLenum getFaceType() const { + return facetype; + } + + /** + * Adds a Geometry Buffer to the Draw Buffer. + */ + void addGeometry(GeometryBuffer* gbuff); }; -#endif +#endif diff --git a/rwlib/source/gl/GeometryBuffer.cpp b/rwlib/source/gl/GeometryBuffer.cpp index f165b074..a9e0ed64 100644 --- a/rwlib/source/gl/GeometryBuffer.cpp +++ b/rwlib/source/gl/GeometryBuffer.cpp @@ -1,24 +1,20 @@ #include -GeometryBuffer::GeometryBuffer() - : vbo(0), num(0) -{ - +GeometryBuffer::GeometryBuffer() : vbo(0), num(0) { } -GeometryBuffer::~GeometryBuffer() -{ - if(vbo != 0) { - glDeleteBuffers(1, &vbo); - } +GeometryBuffer::~GeometryBuffer() { + if (vbo != 0) { + glDeleteBuffers(1, &vbo); + } } -void GeometryBuffer::uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem) -{ - if(vbo == 0) { - glGenBuffers(1, &vbo); - } - this->num = num; - glBindBuffer(GL_ARRAY_BUFFER, vbo); - glBufferData(GL_ARRAY_BUFFER, size, mem, GL_STATIC_DRAW); +void GeometryBuffer::uploadVertices(GLsizei num, GLsizeiptr size, + const GLvoid* mem) { + if (vbo == 0) { + glGenBuffers(1, &vbo); + } + this->num = num; + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData(GL_ARRAY_BUFFER, size, mem, GL_STATIC_DRAW); } diff --git a/rwlib/source/gl/GeometryBuffer.hpp b/rwlib/source/gl/GeometryBuffer.hpp index 0ced4ae9..da4723f9 100644 --- a/rwlib/source/gl/GeometryBuffer.hpp +++ b/rwlib/source/gl/GeometryBuffer.hpp @@ -8,79 +8,80 @@ * Enum used to determine which shader input an attribute maps to */ enum AttributeSemantic { - ATRS_Position, - ATRS_Normal, - ATRS_Colour, - ATRS_TexCoord + ATRS_Position, + ATRS_Normal, + ATRS_Colour, + ATRS_TexCoord }; /** * Stores Vertex Attribute data */ struct AttributeIndex { - AttributeSemantic sem; - GLsizei size; - GLsizei stride; - GLsizei offset; - GLenum type; + AttributeSemantic sem; + GLsizei size; + GLsizei stride; + GLsizei offset; + GLenum type; - AttributeIndex(AttributeSemantic s, - GLsizei sz, - GLsizei strd, - GLsizei offs, - GLenum type = GL_FLOAT) - : sem(s), size(sz), stride(strd), offset(offs), type(type) - {} + AttributeIndex(AttributeSemantic s, GLsizei sz, GLsizei strd, GLsizei offs, + GLenum type = GL_FLOAT) + : sem(s), size(sz), stride(strd), offset(offs), type(type) { + } }; typedef std::vector AttributeList; -/** +/** * GeometryBuffer stores a set of vertex attribute data */ class GeometryBuffer { - GLuint vbo; - GLsizei num; - - AttributeList attributes; + GLuint vbo; + GLsizei num; + + AttributeList attributes; + public: + GeometryBuffer(); + template + GeometryBuffer(const std::vector& data) : vbo(0), num(0) { + uploadVertices(data); + } - GeometryBuffer(); - template GeometryBuffer(const std::vector& data) - : vbo(0), num(0) - { - uploadVertices(data); - } + ~GeometryBuffer(); - ~GeometryBuffer(); + GLuint getVBOName() const { + return vbo; + } - GLuint getVBOName() const - { return vbo; } - - GLsizei getCount() const - { return num; } - - /** - * Uploads Vertex Buffer data from an STL vector - * - * vertex_attributes() is assumed to exist so that vertex types - * can implicitly declare the strides and offsets for their data. - */ - template void uploadVertices(const std::vector& data) { - uploadVertices(data.size(), data.size()*sizeof(T), data.data()); - // Assume T has a static method for attributes; - attributes = T::vertex_attributes(); - } - - /** - * Uploads raw memory into the buffer. - */ - void uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem); - - const AttributeList& getDataAttributes() const - { return attributes; } - AttributeList& getDataAttributes() - { return attributes; } + GLsizei getCount() const { + return num; + } + + /** + * Uploads Vertex Buffer data from an STL vector + * + * vertex_attributes() is assumed to exist so that vertex types + * can implicitly declare the strides and offsets for their data. + */ + template + void uploadVertices(const std::vector& data) { + uploadVertices(data.size(), data.size() * sizeof(T), data.data()); + // Assume T has a static method for attributes; + attributes = T::vertex_attributes(); + } + + /** + * Uploads raw memory into the buffer. + */ + void uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem); + + const AttributeList& getDataAttributes() const { + return attributes; + } + AttributeList& getDataAttributes() { + return attributes; + } }; #endif diff --git a/rwlib/source/gl/TextureData.hpp b/rwlib/source/gl/TextureData.hpp index d3473963..83f9381b 100644 --- a/rwlib/source/gl/TextureData.hpp +++ b/rwlib/source/gl/TextureData.hpp @@ -7,28 +7,33 @@ /** * Stores a handle and metadata about a loaded texture. */ -class TextureData -{ +class TextureData { public: - - TextureData(GLuint name, const glm::ivec2& dims, bool alpha) - : texName( name ), size( dims ), hasAlpha(alpha) { } - - GLuint getName() const { return texName; } - - const glm::ivec2& getSize() const { return size; } - - bool isTransparent() const { return hasAlpha; } - - typedef std::shared_ptr Handle; - - static Handle create(GLuint name, const glm::ivec2& size, bool transparent) - { - return Handle( new TextureData( name, size, transparent ) ); - } - + TextureData(GLuint name, const glm::ivec2& dims, bool alpha) + : texName(name), size(dims), hasAlpha(alpha) { + } + + GLuint getName() const { + return texName; + } + + const glm::ivec2& getSize() const { + return size; + } + + bool isTransparent() const { + return hasAlpha; + } + + typedef std::shared_ptr Handle; + + static Handle create(GLuint name, const glm::ivec2& size, + bool transparent) { + return Handle(new TextureData(name, size, transparent)); + } + private: - GLuint texName; - glm::ivec2 size; - bool hasAlpha; + GLuint texName; + glm::ivec2 size; + bool hasAlpha; };