Finished documenting code
This commit is contained in:
parent
a9fd6dc729
commit
7b071b2db6
|
@ -4,11 +4,25 @@
|
||||||
|
|
||||||
namespace lol
|
namespace lol
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @brief Represents an EBO and manages its state
|
||||||
|
*/
|
||||||
class ElementBuffer : public Buffer
|
class ElementBuffer : public Buffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ElementBuffer(size_t count, const std::vector<unsigned int>& 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<unsigned int>& 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; }
|
inline size_t GetCount() const { return count; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -4,27 +4,71 @@
|
||||||
|
|
||||||
namespace lol
|
namespace lol
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @brief Stores attribute data for one vertex
|
||||||
|
*
|
||||||
|
*/
|
||||||
struct VertexAttribute
|
struct VertexAttribute
|
||||||
{
|
{
|
||||||
int size;
|
int size; ///< Number of elements in this attribute
|
||||||
Type type;
|
Type type; ///< Type of the attribute
|
||||||
bool normalized;
|
bool normalized; ///< Whether the data is normalized
|
||||||
int offset;
|
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) :
|
VertexAttribute(Type type, unsigned int count, bool normalized) :
|
||||||
type(type), size(count), normalized(normalized), offset(0)
|
type(type), size(count), normalized(normalized), offset(0)
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stored the layout of a VertexBuffer
|
||||||
|
*/
|
||||||
class BufferLayout
|
class BufferLayout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new BufferLayout
|
||||||
|
*
|
||||||
|
* @param attributes A list of vertex attributes making up the layout
|
||||||
|
*/
|
||||||
BufferLayout(const std::initializer_list<VertexAttribute>& attributes);
|
BufferLayout(const std::initializer_list<VertexAttribute>& attributes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the stored layout
|
||||||
|
*
|
||||||
|
* @return A list of VertexAttributes
|
||||||
|
*/
|
||||||
inline const std::vector<VertexAttribute>& GetLayout() const { return layout; }
|
inline const std::vector<VertexAttribute>& 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; }
|
inline int GetStride() const { return stride; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns iterator to beginning of layout list
|
||||||
|
*
|
||||||
|
* @return Iterator to beginning of list
|
||||||
|
*/
|
||||||
std::vector<VertexAttribute>::const_iterator begin() const { return layout.begin(); }
|
std::vector<VertexAttribute>::const_iterator begin() const { return layout.begin(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns iterator to end of layout list
|
||||||
|
*
|
||||||
|
* @return Iterator to end of list
|
||||||
|
*/
|
||||||
std::vector<VertexAttribute>::const_iterator end() const { return layout.end(); }
|
std::vector<VertexAttribute>::const_iterator end() const { return layout.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -32,12 +76,32 @@ namespace lol
|
||||||
int stride;
|
int stride;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Represents a VBO and manages its state
|
||||||
|
*/
|
||||||
class VertexBuffer : public Buffer
|
class VertexBuffer : public Buffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VertexBuffer(size_t size, const std::vector<float>& 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<float>& 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; };
|
inline void SetLayout(const BufferLayout& layout) { this->layout = layout; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the VBOs BufferLayout
|
||||||
|
*
|
||||||
|
* @return The stored BufferLayout
|
||||||
|
*/
|
||||||
inline const BufferLayout& GetLayout() { return layout; }
|
inline const BufferLayout& GetLayout() { return layout; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -3,12 +3,20 @@
|
||||||
namespace lol
|
namespace lol
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Defines a rectangle via a point and its dimensions
|
||||||
|
*
|
||||||
|
*/
|
||||||
struct Rect
|
struct Rect
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
float w, h;
|
float w, h;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Defines a 3D area in space
|
||||||
|
*
|
||||||
|
*/
|
||||||
struct BoundingBox
|
struct BoundingBox
|
||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
|
@ -7,9 +7,20 @@
|
||||||
|
|
||||||
namespace lol
|
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
|
class ObjectNotFoundException : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new ObjectNotFoundException
|
||||||
|
*
|
||||||
|
* @param id ID of the object that was not found
|
||||||
|
*/
|
||||||
ObjectNotFoundException(unsigned int id) :
|
ObjectNotFoundException(unsigned int id) :
|
||||||
std::runtime_error("Failed to Get() object with ID " + std::to_string(id) + " from ObjectManager. It does not exist.")
|
std::runtime_error("Failed to Get() object with ID " + std::to_string(id) + " from ObjectManager. It does not exist.")
|
||||||
{ }
|
{ }
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
namespace lol
|
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
|
* Any object inheriting from this will not be able to be copied anymore
|
||||||
*/
|
*/
|
||||||
class NonCopyable
|
class NonCopyable
|
||||||
|
|
|
@ -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
|
* 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
|
* 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.
|
* objects can then retrieve them if they have the ID.
|
||||||
|
@ -23,8 +25,24 @@ namespace lol
|
||||||
class ObjectManager : public NonCopyable
|
class ObjectManager : public NonCopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new ObjectManager
|
||||||
|
*
|
||||||
|
*/
|
||||||
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<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
std::shared_ptr<T> Create(unsigned int id, Args... args)
|
std::shared_ptr<T> 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);
|
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<void> Get(unsigned int id);
|
std::shared_ptr<void> 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<typename T>
|
template<typename T>
|
||||||
std::shared_ptr<T> Get(unsigned int id)
|
std::shared_ptr<T> Get(unsigned int id)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +85,22 @@ namespace lol
|
||||||
return std::static_pointer_cast<T>(object);
|
return std::static_pointer_cast<T>(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();
|
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();
|
void Clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace lol
|
namespace lol
|
||||||
{
|
{
|
||||||
ElementBuffer::ElementBuffer(size_t count, const std::vector<unsigned int>& elements, Usage usage) :
|
ElementBuffer::ElementBuffer(const std::vector<unsigned int>& elements, Usage usage) :
|
||||||
Buffer(BufferType::ElementArray), count(count)
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,9 +14,9 @@ namespace lol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VertexBuffer::VertexBuffer(size_t size, const std::vector<float>& data, Usage usage) :
|
VertexBuffer::VertexBuffer(const std::vector<float>& data, Usage usage) :
|
||||||
Buffer(BufferType::Array), layout{}
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue