diff --git a/include/lol/buffers/ElementBuffer.hpp b/include/lol/buffers/ElementBuffer.hpp index 1cb25ab..1a33693 100644 --- a/include/lol/buffers/ElementBuffer.hpp +++ b/include/lol/buffers/ElementBuffer.hpp @@ -4,11 +4,25 @@ namespace lol { + /** + * @brief Represents an EBO and manages its state + */ class ElementBuffer : public Buffer { public: - ElementBuffer(size_t count, const std::vector& elements, Usage usage = Usage::StaticDraw); + /** + * @brief Construct a new ElementBuffer + * + * @param elements Data to put into the buffer + * @param usage Hint OpenGL on how the buffer will be used + */ + ElementBuffer(const std::vector& elements, Usage usage = Usage::StaticDraw); + /** + * @brief Get the number of indices in the buffer + * + * @return Number of indices inside the buffer + */ inline size_t GetCount() const { return count; } private: diff --git a/include/lol/buffers/VertexBuffer.hpp b/include/lol/buffers/VertexBuffer.hpp index 9cd030b..ef87d74 100644 --- a/include/lol/buffers/VertexBuffer.hpp +++ b/include/lol/buffers/VertexBuffer.hpp @@ -4,27 +4,71 @@ namespace lol { + /** + * @brief Stores attribute data for one vertex + * + */ struct VertexAttribute { - int size; - Type type; - bool normalized; - int offset; + int size; ///< Number of elements in this attribute + Type type; ///< Type of the attribute + bool normalized; ///< Whether the data is normalized + int offset; ///< Offset of the attribute into the vertex data + /** + * @brief Construct a new VertexAttribute + * + * @param type Datatype of the attribute + * @param count Number of elements in this attribute + * @param normalized If data is normalized + */ VertexAttribute(Type type, unsigned int count, bool normalized) : type(type), size(count), normalized(normalized), offset(0) { } }; + /** + * @brief Stored the layout of a VertexBuffer + */ class BufferLayout { public: + /** + * @brief Construct a new BufferLayout + * + * @param attributes A list of vertex attributes making up the layout + */ BufferLayout(const std::initializer_list& attributes); + /** + * @brief Returns the stored layout + * + * @return A list of VertexAttributes + */ inline const std::vector& GetLayout() const { return layout; } + + /** + * @brief Get the stride of the layout + * + * The stride is the size of one vertex in the buffer in bytes. + * The more attributes a vertex has, the larger its stride will be + * + * @return Number of bytes per vertex + */ inline int GetStride() const { return stride; } + /** + * @brief Returns iterator to beginning of layout list + * + * @return Iterator to beginning of list + */ std::vector::const_iterator begin() const { return layout.begin(); } + + /** + * @brief Returns iterator to end of layout list + * + * @return Iterator to end of list + */ std::vector::const_iterator end() const { return layout.end(); } private: @@ -32,12 +76,32 @@ namespace lol int stride; }; + /** + * @brief Represents a VBO and manages its state + */ class VertexBuffer : public Buffer { public: - VertexBuffer(size_t size, const std::vector& data, Usage usage = Usage::StaticDraw); + /** + * @brief Construct a new VertexBuffer + * + * @param data Data to put into the buffer + * @param usage Hint OpenGL on how the buffer will be used + */ + VertexBuffer(const std::vector& data, Usage usage = Usage::StaticDraw); + /** + * @brief Set the BufferLayout of this VBO + * + * @param layout The new layout to give to this buffer + */ inline void SetLayout(const BufferLayout& layout) { this->layout = layout; }; + + /** + * @brief Get the VBOs BufferLayout + * + * @return The stored BufferLayout + */ inline const BufferLayout& GetLayout() { return layout; } private: diff --git a/include/lol/util/BoundingBox.hpp b/include/lol/util/BoundingBox.hpp index f822b68..31be2e1 100644 --- a/include/lol/util/BoundingBox.hpp +++ b/include/lol/util/BoundingBox.hpp @@ -3,12 +3,20 @@ namespace lol { + /** + * @brief Defines a rectangle via a point and its dimensions + * + */ struct Rect { - float x, y; + float x, y; float w, h; }; + /** + * @brief Defines a 3D area in space + * + */ struct BoundingBox { float x, y, z; diff --git a/include/lol/util/Exceptions.hpp b/include/lol/util/Exceptions.hpp index 5226682..a313b9c 100644 --- a/include/lol/util/Exceptions.hpp +++ b/include/lol/util/Exceptions.hpp @@ -7,9 +7,20 @@ namespace lol { + /** + * @brief The requested object was not found + * + * Thrown by ObjectManager::Get() if the specified ID isn't associated + * with any objects in the manager + */ class ObjectNotFoundException : public std::runtime_error { public: + /** + * @brief Construct a new ObjectNotFoundException + * + * @param id ID of the object that was not found + */ ObjectNotFoundException(unsigned int id) : std::runtime_error("Failed to Get() object with ID " + std::to_string(id) + " from ObjectManager. It does not exist.") { } diff --git a/include/lol/util/NonCopyable.hpp b/include/lol/util/NonCopyable.hpp index 3c603ce..4b610ee 100644 --- a/include/lol/util/NonCopyable.hpp +++ b/include/lol/util/NonCopyable.hpp @@ -3,7 +3,8 @@ namespace lol { /** - * A object without copy constructors or assignment operators. + * @brief An object without copy constructors or assignment operators. + * * Any object inheriting from this will not be able to be copied anymore */ class NonCopyable diff --git a/include/lol/util/ObjectManager.hpp b/include/lol/util/ObjectManager.hpp index fed00b2..b13e638 100644 --- a/include/lol/util/ObjectManager.hpp +++ b/include/lol/util/ObjectManager.hpp @@ -10,6 +10,8 @@ namespace lol { /** + * @brief Manages objects and cleans them up if they're not needed anymore. + * * Some objects should only exist once but be available to multiple objects (e.g. multiple * models sharing the same VAO and shaders. Any object can register objects here and other * objects can then retrieve them if they have the ID. @@ -23,8 +25,24 @@ namespace lol class ObjectManager : public NonCopyable { public: + /** + * @brief Construct a new ObjectManager + * + */ ObjectManager() {} + /** + * @brief Tell the ObjectManager to create a new object of type T + * + * The object will be constructed by the manager, ObjectManager will + * own it. + * + * @tparam T Type of the object to create + * @tparam Args + * @param id ID to give this object in the manager + * @param args Argumnts to pass to T's constructor + * @return A shared pointer to the newly constructed object + */ template std::shared_ptr Create(unsigned int id, Args... args) { @@ -35,15 +53,30 @@ namespace lol } /** - * Remove object from manager + * @brief Remove object from manager + * + * @param id ID of the object to remove */ void Delete(unsigned int id); /** - * Retrieve object from manager + * @brief Retrieve a generic object from manager + * + * The object returned will essentially be a void*. + * The ObjectManager performs no casting. + * + * @param id ID of the object to retrieve + * @return A void* to a blob of data making up the object */ std::shared_ptr Get(unsigned int id); + /** + * @brief Retriege an object of a specific type from the manager + * + * @tparam T Type of the object + * @param id ID of the object + * @return A pointer to the object + */ template std::shared_ptr Get(unsigned int id) { @@ -52,7 +85,22 @@ namespace lol return std::static_pointer_cast(object); } + /** + * @brief Removes any objects that aren't in use by anyone anymore + * + * Deletes any stored shared_ptr if their use count is equal to 1. + * Note that if you're holding a weak pointer to one of the objects it + * might be deleted at any time + */ void ClearUnused(); + + /** + * @brief Removes all objects from the manager + * + * If an object holds a shared_ptr from the manager then this + * will not break the object. This merely causes the manager + * to "untrack" all objects. + */ void Clear(); private: diff --git a/src/buffers/ElementBuffer.cpp b/src/buffers/ElementBuffer.cpp index 1dbd628..a6a042c 100644 --- a/src/buffers/ElementBuffer.cpp +++ b/src/buffers/ElementBuffer.cpp @@ -2,9 +2,9 @@ namespace lol { - ElementBuffer::ElementBuffer(size_t count, const std::vector& elements, Usage usage) : + ElementBuffer::ElementBuffer(const std::vector& elements, Usage usage) : Buffer(BufferType::ElementArray), count(count) { - glBufferData(NATIVE(type), count * sizeof(unsigned int), elements.data(), NATIVE(usage)); + glBufferData(NATIVE(type), elements.size() * sizeof(unsigned int), elements.data(), NATIVE(usage)); } } \ No newline at end of file diff --git a/src/buffers/VertexBuffer.cpp b/src/buffers/VertexBuffer.cpp index fbce37d..cd55ed2 100644 --- a/src/buffers/VertexBuffer.cpp +++ b/src/buffers/VertexBuffer.cpp @@ -14,9 +14,9 @@ namespace lol } - VertexBuffer::VertexBuffer(size_t size, const std::vector& data, Usage usage) : + VertexBuffer::VertexBuffer(const std::vector& data, Usage usage) : Buffer(BufferType::Array), layout{} { - glBufferData(NATIVE(type), size * sizeof(float), data.data(), NATIVE(usage)); + glBufferData(NATIVE(type), data.size() * sizeof(float), data.data(), NATIVE(usage)); } } \ No newline at end of file