diff --git a/binaries/lib-macos/libgoopylib.dylib b/binaries/lib-macos/libgoopylib.dylib index 90f871d9..aa595dcc 100755 Binary files a/binaries/lib-macos/libgoopylib.dylib and b/binaries/lib-macos/libgoopylib.dylib differ diff --git a/src/core/Buffer.cpp b/src/core/Buffer.cpp index 846e1371..8e07743c 100644 --- a/src/core/Buffer.cpp +++ b/src/core/Buffer.cpp @@ -87,8 +87,9 @@ namespace gp { bind(); - GP_OPENGL("glBufferData(target={0}, size={1}*{2}, data={3}, ...)", GP_BUFFER_TARGET, length, m_Layout.m_Stride, data); - glBufferData(_getBufferTarget(), length * m_Layout.m_Stride, data, _getBufferUsage()); + GP_OPENGL("glBufferData(target={0}, size={1}*{2}, data={3}, ...)", + GP_BUFFER_TARGET, length, m_Layout.getStride(), data); + glBufferData(_getBufferTarget(), length * m_Layout.getStride(), data, _getBufferUsage()); m_Length = length; } @@ -107,8 +108,8 @@ namespace gp { bind(); GP_OPENGL("glBufferSubData(target={0}, offset={1}*{2}, size={3}*{2}, data={4})", - GP_BUFFER_TARGET, offset, m_Layout.m_Stride, length, data); - glBufferSubData(_getBufferTarget(), offset * m_Layout.m_Stride, length * m_Layout.m_Stride, data); + GP_BUFFER_TARGET, offset, m_Layout.getStride(), length, data); + glBufferSubData(_getBufferTarget(), offset * m_Layout.getStride(), length * m_Layout.getStride(), data); } void Buffer::setData(const std::span data) { diff --git a/src/core/BufferLayout.cpp b/src/core/BufferLayout.cpp index 289ad3cc..405a8bed 100644 --- a/src/core/BufferLayout.cpp +++ b/src/core/BufferLayout.cpp @@ -6,7 +6,7 @@ #include namespace gp { - GLenum shaderOpenGLType(ShaderDataType type) { + GLenum shaderOpenGLType(const ShaderDataType type) { switch (type) { case ShaderDataType::Float: case ShaderDataType::Float2: @@ -26,7 +26,7 @@ namespace gp { return GL_BYTE; default: - GP_CORE_ERROR("Unrecognised Shader Type"); + GP_CORE_ERROR("gp::shaderOpenGLType() Unrecognised Shader Type"); return 0; } } @@ -34,7 +34,7 @@ namespace gp { // Buffer Layout Element namespace gp { - int32_t shaderTypeSize(ShaderDataType type) { + int32_t shaderTypeSize(const ShaderDataType type) { switch (type) { case ShaderDataType::Float: return 4; @@ -59,17 +59,24 @@ namespace gp { case ShaderDataType::Bool: return 1; default: - GP_CORE_ERROR("Unrecognised Shader Type"); + GP_CORE_ERROR("gp::shaderTypeSize() Unrecognised Shader Type"); return 0; } } - BufferElement::BufferElement(ShaderDataType type, const char *name, bool normalized) - : m_Name(name), - m_Type(type), - m_Normalized(normalized), - m_Size(shaderTypeSize(type)), - m_Offset(0) { + BufferElement::BufferElement(const ShaderDataType type, const char *name, const bool normalized) + : m_Name(name), + m_Type(type), + m_Size(shaderTypeSize(type)), + m_Normalized(normalized) { + } + + const char *BufferElement::getName() const { + return m_Name; + } + + ShaderDataType BufferElement::getDataType() const { + return m_Type; } int32_t BufferElement::getCount() const { @@ -103,42 +110,46 @@ namespace gp { } } - ShaderDataType BufferElement::getDataType() const { - return m_Type; - } - - bool BufferElement::isNormalised() const { - return m_Normalized; + int32_t BufferElement::getSize() const { + return m_Size; } - size_t BufferElement::getOffset() const { + int32_t BufferElement::getOffset() const { return m_Offset; } - const char *BufferElement::getName() const { - return m_Name; + bool BufferElement::isNormalized() const { + return m_Normalized; } } // Buffer Layout namespace gp { - BufferLayout::BufferLayout(BufferElement *elements, int32_t count) { - GP_CORE_INFO("Initializing BufferLayout"); + BufferLayout::BufferLayout(const BufferElement *elements, const int32_t count) { + GP_CORE_INFO("gp::BufferLayout::BufferLayout({0}, count={1})", reinterpret_cast(elements), count); - const gp::BufferElement *end = &elements[count]; + const BufferElement *end = &elements[count]; - for (gp::BufferElement *element = elements; element != end; element++) { + for (const BufferElement *element = elements; element != end; element++) { m_Elements.push_back(*element); } - calculateOffsetAndStride(); + _calculateOffsetAndStride(); } - BufferLayout::BufferLayout(std::initializer_list elements) - : m_Elements(elements) { - GP_CORE_INFO("Initializing BufferLayout"); + BufferLayout::BufferLayout(const std::initializer_list elements) + : m_Elements{elements} { + GP_CORE_INFO("gp::BufferLayout::BufferLayout(count={0})", elements.size()); + + _calculateOffsetAndStride(); + } + + int32_t BufferLayout::getStride() const { + return m_Stride; + } - calculateOffsetAndStride(); + int32_t BufferLayout::getCount() const { + return m_Count; } std::vector::iterator BufferLayout::begin() { @@ -157,13 +168,13 @@ namespace gp { return m_Elements.end(); } - void BufferLayout::calculateOffsetAndStride() { + void BufferLayout::_calculateOffsetAndStride() { m_Stride = 0; m_Count = 0; for (auto &element: m_Elements) { element.m_Offset = m_Stride; - m_Stride += element.m_Size; + m_Stride += element.getSize(); m_Count += element.getCount(); } } diff --git a/src/core/BufferLayout.h b/src/core/BufferLayout.h index 82e0245b..a665a577 100644 --- a/src/core/BufferLayout.h +++ b/src/core/BufferLayout.h @@ -22,38 +22,40 @@ namespace gp { public: BufferElement(ShaderDataType type, const char *name, bool normalized = false); - [[nodiscard]] int32_t getCount() const; + [[nodiscard]] const char *getName() const; [[nodiscard]] ShaderDataType getDataType() const; - [[nodiscard]] bool isNormalised() const; + [[nodiscard]] int32_t getCount() const; - [[nodiscard]] size_t getOffset() const; + [[nodiscard]] int32_t getSize() const; - [[nodiscard]] const char *getName() const; + [[nodiscard]] int32_t getOffset() const; + + [[nodiscard]] bool isNormalized() const; private: const char *m_Name; ShaderDataType m_Type; - bool m_Normalized; int32_t m_Size = 0; - size_t m_Offset = 0; + int32_t m_Offset = 0; + bool m_Normalized; }; } // Buffer Layout namespace gp { class GPAPI BufferLayout { - friend class VertexArray; - - friend class Buffer; - public: - BufferLayout(BufferElement *elements, int32_t count); + BufferLayout(const BufferElement *elements, int32_t count); BufferLayout(std::initializer_list elements); + int32_t getStride() const; + + int32_t getCount() const; + [[nodiscard]] std::vector::iterator begin(); [[nodiscard]] std::vector::iterator end(); @@ -62,11 +64,12 @@ namespace gp { [[nodiscard]] std::vector::const_iterator end() const; - void calculateOffsetAndStride(); - private: - std::vector m_Elements; int32_t m_Stride = 0; - uint32_t m_Count = 0; + int32_t m_Count = 0; + + std::vector m_Elements; + + void _calculateOffsetAndStride(); }; } diff --git a/src/core/VertexArray.cpp b/src/core/VertexArray.cpp index 70d68ab9..67a578ea 100644 --- a/src/core/VertexArray.cpp +++ b/src/core/VertexArray.cpp @@ -119,12 +119,12 @@ namespace gp { GP_OPENGL( "glVertexAttribPointer({0}, size={1}, type=GL_FLOAT, normalised={2}, stride={3}, offset={4})", - attrIndex, element.getCount(), element.isNormalised(), layout.m_Stride, element.getOffset()); + attrIndex, element.getCount(), element.isNormalised(), layout.getStride(), element.getOffset()); glVertexAttribPointer(attrIndex, element.getCount(), GL_FLOAT, - element.isNormalised() ? GL_TRUE : GL_FALSE, - layout.m_Stride, + element.isNormalized() ? GL_TRUE : GL_FALSE, + layout.getStride(), (const void *) element.getOffset()); attrIndex++; break; @@ -139,11 +139,11 @@ namespace gp { GP_OPENGL( "glVertexAttribIPointer({0}, size={1}, type={2}, stride={3}, offset={4})", - attrIndex, element.getCount(), shaderOpenGLType(type), layout.m_Stride, element.getOffset()); + attrIndex, element.getCount(), shaderOpenGLType(type), layout.getStride(), element.getOffset()); glVertexAttribIPointer(attrIndex, element.getCount(), shaderOpenGLType(type), - layout.m_Stride, + layout.getStride(), (const void *) element.getOffset()); attrIndex++; break; @@ -151,9 +151,9 @@ namespace gp { case ShaderDataType::Mat3: case ShaderDataType::Mat4: { GLenum glType = shaderOpenGLType(type); - bool normalized = element.isNormalised() ? GL_TRUE : GL_FALSE; + bool normalized = element.isNormalized() ? GL_TRUE : GL_FALSE; int32_t count = element.getCount(); - int32_t stride = layout.m_Stride; + int32_t stride = layout.getStride(); for (int32_t i = 0; i < count; i++) { GP_OPENGL("glEnableVertexAttribArray({0})", attrIndex);