diff --git a/src/dawn/display/font/truetype/TrueTypeFaceTexture.hpp b/src/dawn/display/font/truetype/TrueTypeFaceTexture.hpp index dad03b8d..d4a01cc5 100644 --- a/src/dawn/display/font/truetype/TrueTypeFaceTexture.hpp +++ b/src/dawn/display/font/truetype/TrueTypeFaceTexture.hpp @@ -33,6 +33,12 @@ namespace Dawn { uint32_t fontSize; flag_t style; + /** + * Overload for the less than operator. + * + * @param r Right hand side of the operator. + * @return True if the left hand side is less than the right hand side. + */ bool operator < (const struct TrueTypeFaceTextureStyle& r) const { return std::tie(fontSize, style) < std::tie(r.fontSize, r.style); } diff --git a/src/dawn/display/mesh/CapsuleMesh.cpp b/src/dawn/display/mesh/CapsuleMesh.cpp index 7eb4ffcf..94a82968 100644 --- a/src/dawn/display/mesh/CapsuleMesh.cpp +++ b/src/dawn/display/mesh/CapsuleMesh.cpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #include "CapsuleMesh.hpp" +#include "util/mathutils.hpp" using namespace Dawn; diff --git a/src/dawn/display/mesh/CapsuleMesh.hpp b/src/dawn/display/mesh/CapsuleMesh.hpp index 21ae1540..d233a358 100644 --- a/src/dawn/display/mesh/CapsuleMesh.hpp +++ b/src/dawn/display/mesh/CapsuleMesh.hpp @@ -5,11 +5,21 @@ #pragma once #include "display/mesh/Mesh.hpp" -#include "util/mathutils.hpp" namespace Dawn { class CapsuleMesh { protected: + /** + * Calculates a ring of vertices within a capsule. + * + * @param segments Count of segments in the ring. + * @param height Height of the ring. + * @param radius Radius of the ring. + * @param dr The delta radius of the ring. + * @param y The y position of the ring. + * @param dy The delta y position of the ring. + * @param positions The positions vector to push the positions to. + */ static void calculateRing( const int32_t segments, const float_t height, @@ -21,6 +31,13 @@ namespace Dawn { ); public: + /** + * Creates a capsule mesh. + * + * @param mesh Mesh to instanciate. + * @param radius Radius of the capsule. + * @param height Height of the capsule. + */ static void create( Mesh &mesh, const float_t radius, diff --git a/src/dawn/display/mesh/CubeMesh.hpp b/src/dawn/display/mesh/CubeMesh.hpp index 67bbb51a..b76da8f0 100644 --- a/src/dawn/display/mesh/CubeMesh.hpp +++ b/src/dawn/display/mesh/CubeMesh.hpp @@ -12,6 +12,15 @@ namespace Dawn { class CubeMesh { public: + /** + * Buffers cube mesh vertices onto a mesh. + * + * @param mesh Mesh to buffer onto. + * @param pos Position of the cube. + * @param size Size of the cube. + * @param verticeStart Starting vertice index. + * @param indiceStart Starting indice index. + */ static void buffer( Mesh &mesh, const glm::vec3 pos, diff --git a/src/dawn/display/mesh/SphereMesh.cpp b/src/dawn/display/mesh/SphereMesh.cpp index 6212026a..bde648d3 100644 --- a/src/dawn/display/mesh/SphereMesh.cpp +++ b/src/dawn/display/mesh/SphereMesh.cpp @@ -4,14 +4,15 @@ // https://opensource.org/licenses/MIT #include "SphereMesh.hpp" +#include "util/mathutils.hpp" using namespace Dawn; void SphereMesh::createSphere( - Mesh *mesh, - float_t radius, - int32_t slices, - int32_t stacks + Mesh &mesh, + const float_t radius, + const int32_t slices, + const int32_t stacks ) { std::vector positions; @@ -53,7 +54,7 @@ void SphereMesh::createSphere( } } - mesh->createBuffers(positions.size(), indices.size()); - mesh->bufferPositions(0, positions.data(), positions.size()); - mesh->bufferIndices(0, indices.data(), indices.size()); + mesh.createBuffers(positions.size(), indices.size()); + mesh.bufferPositions(0, positions.data(), positions.size()); + mesh.bufferIndices(0, indices.data(), indices.size()); } \ No newline at end of file diff --git a/src/dawn/display/mesh/SphereMesh.hpp b/src/dawn/display/mesh/SphereMesh.hpp index 35c45f95..168e3153 100644 --- a/src/dawn/display/mesh/SphereMesh.hpp +++ b/src/dawn/display/mesh/SphereMesh.hpp @@ -5,16 +5,23 @@ #pragma once #include "display/mesh/Mesh.hpp" -#include "util/mathutils.hpp" namespace Dawn { class SphereMesh { public: + /** + * Creates a sphere mesh. + * + * @param mesh Mesh to instanciate. + * @param radius Radius of the sphere. + * @param slices How many horizontal slices to make. + * @param stacks How many vertical stacks to make. + */ static void createSphere( - Mesh *mesh, - float_t radius, - int32_t slices, - int32_t stacks + Mesh &mesh, + const float_t radius, + const int32_t slices, + const int32_t stacks ); }; } \ No newline at end of file diff --git a/src/dawn/display/mesh/TriangleMesh.cpp b/src/dawn/display/mesh/TriangleMesh.cpp index 4b24130d..a2c90779 100644 --- a/src/dawn/display/mesh/TriangleMesh.cpp +++ b/src/dawn/display/mesh/TriangleMesh.cpp @@ -7,9 +7,7 @@ using namespace Dawn; -void TriangleMesh::createTriangleMesh(Mesh *mesh) { - assertNotNull(mesh, "TriangleMesh::createTriangleMesh: Mesh cannot be null"); - +void TriangleMesh::createTriangleMesh(Mesh &mesh) { glm::vec3 positions[3] = { glm::vec3(-0.5f, -0.5f, 0), glm::vec3(0.5f, -0.5f, 0), @@ -26,8 +24,8 @@ void TriangleMesh::createTriangleMesh(Mesh *mesh) { 0, 1, 2 }; - mesh->createBuffers(3, 3); - mesh->bufferPositions(0, positions, 3); - mesh->bufferCoordinates(0, coordinates, 3); - mesh->bufferIndices(0, indices, 3); + mesh.createBuffers(3, 3); + mesh.bufferPositions(0, positions, 3); + mesh.bufferCoordinates(0, coordinates, 3); + mesh.bufferIndices(0, indices, 3); } \ No newline at end of file diff --git a/src/dawn/display/mesh/TriangleMesh.hpp b/src/dawn/display/mesh/TriangleMesh.hpp index f48544a2..e1bc523a 100644 --- a/src/dawn/display/mesh/TriangleMesh.hpp +++ b/src/dawn/display/mesh/TriangleMesh.hpp @@ -14,6 +14,6 @@ namespace Dawn { * * @param mesh Mesh to initialize as a triangle. */ - static void createTriangleMesh(Mesh *mesh); + static void createTriangleMesh(Mesh &mesh); }; } \ No newline at end of file diff --git a/src/dawn/display/shader/IShader.hpp b/src/dawn/display/shader/IShader.hpp index b13aa34e..59d702e0 100644 --- a/src/dawn/display/shader/IShader.hpp +++ b/src/dawn/display/shader/IShader.hpp @@ -4,8 +4,6 @@ // https://opensource.org/licenses/MIT #pragma once -#include "display/mesh/Mesh.hpp" -#include "display/IRenderManager.hpp" #include "display/Texture.hpp" #include "display/shader/ShaderParameterBuffer.hpp" @@ -33,7 +31,10 @@ namespace Dawn { * @param buffer Buffer to bind. */ template - void setParameterBuffer(shaderbufferslot_t slot, ShaderParameterBuffer *buffer); + void setParameterBuffer( + const shaderbufferslot_t slot, + const ShaderParameterBuffer &buffer + ); /** * Set's a specific shader parameter to a matrix. @@ -41,7 +42,10 @@ namespace Dawn { * @param parameter parameter on the shader to set. * @param matrix Matrix to apply. */ - virtual void setMatrix(T parameter, glm::mat4 matrix) = 0; + virtual void setMatrix( + const T parameter, + const glm::mat4 matrix + ) = 0; /** * Attaches a boolean to a shader. @@ -49,7 +53,10 @@ namespace Dawn { * @param parameter parameter to set. * @param value Value to set. */ - virtual void setBoolean(T parameter, bool_t value) = 0; + virtual void setBoolean( + const T parameter, + const bool_t value + ) = 0; /** * Set a color on to the shader. @@ -57,7 +64,10 @@ namespace Dawn { * @param parameter parameter to set the color to. * @param color Color to set. */ - virtual void setColor(T parameter, struct Color color) = 0; + virtual void setColor( + const T parameter, + const struct Color color + ) = 0; /** * Set a 3D vector on to the shader. @@ -65,7 +75,10 @@ namespace Dawn { * @param parameter parameter to set the vector to. * @param vector Vector to set. */ - virtual void setVector3(T parameter, glm::vec3 vector) = 0; + virtual void setVector3( + const T parameter, + const glm::vec3 vector + ) = 0; /** * Attaches a texture to the currently bound shader. @@ -73,7 +86,10 @@ namespace Dawn { * @param parameter parameter to set the texture on to. * @param texture Texture slot to bind to the parameter. */ - virtual void setTexture(T parameter, textureslot_t texture) = 0; + virtual void setTexture( + const T parameter, + const textureslot_t texture + ) = 0; /** * Sets a floating point value to the shader. @@ -81,6 +97,16 @@ namespace Dawn { * @param parameter Paramater to set the float ont o. * @param Float to bind. */ - virtual void setFloat(T parameter, float_t value) = 0; + virtual void setFloat( + const T parameter, + const float_t value + ) = 0; + + /** + * Destroys/Cleans up the shader. + */ + virtual ~IShader() { + + } }; } \ No newline at end of file diff --git a/src/dawn/display/shader/IShaderParameterBuffer.hpp b/src/dawn/display/shader/IShaderParameterBuffer.hpp index abdf2cb0..e929d7dd 100644 --- a/src/dawn/display/shader/IShaderParameterBuffer.hpp +++ b/src/dawn/display/shader/IShaderParameterBuffer.hpp @@ -20,6 +20,6 @@ namespace Dawn { * * @param location Location to bind this buffer to. */ - virtual void bind(L location) = 0; + virtual void bind(const L location) = 0; }; } \ No newline at end of file diff --git a/src/dawnopengl/display/shader/Shader.cpp b/src/dawnopengl/display/shader/Shader.cpp index 5bcff878..e34dc4c2 100644 --- a/src/dawnopengl/display/shader/Shader.cpp +++ b/src/dawnopengl/display/shader/Shader.cpp @@ -10,8 +10,8 @@ using namespace Dawn; void Shader::compileShader( std::map attributeLocations, - std::string vertexShader, - std::string fragmentShader + const std::string vertexShader, + const std::string fragmentShader ) { GLint isSuccess; int32_t maxLength; @@ -79,54 +79,75 @@ void Shader::compileShader( assertNoGLError(); } -void Shader::bindAttributeLocation(std::string name, int32_t location) { +void Shader::bindAttributeLocation( + const std::string name, + const int32_t location +) { if(this->shaderProgram == -1) throw "Shader has not yet been compiled"; glBindAttribLocation(this->shaderProgram, location, name.c_str()); assertNoGLError(); } -void Shader::setTexture(shaderparameter_t param, textureslot_t slot) { +void Shader::setTexture( + const shaderparameter_t param, + const textureslot_t slot +) { glUniform1i(param, slot); assertNoGLError(); } -shaderparameter_t Shader::getParameterByName(std::string name) { +shaderparameter_t Shader::getParameterByName(const std::string name) { return glGetUniformLocation(this->shaderProgram, name.c_str()); } -shaderbufferlocation_t Shader::getBufferLocationByName(std::string name) { +shaderbufferlocation_t Shader::getBufferLocationByName(const std::string name) { return glGetUniformBlockIndex(this->shaderProgram, name.c_str()); } void Shader::setParameterBuffer( - shaderbufferlocation_t location, - shaderbufferslot_t slot + const shaderbufferlocation_t location, + const shaderbufferslot_t slot ) { glUniformBlockBinding(this->shaderProgram, location, slot); assertNoGLError(); } -void Shader::setMatrix(shaderparameter_t uniform, glm::mat4 matrix) { +void Shader::setMatrix( + const shaderparameter_t uniform, + const glm::mat4 matrix +) { glUniformMatrix4fv(uniform, 1, GL_FALSE, glm::value_ptr(matrix)); assertNoGLError(); } -void Shader::setBoolean(shaderparameter_t uni, bool value) { +void Shader::setBoolean( + const shaderparameter_t uni, + const bool value +) { glUniform1i(uni, value); assertNoGLError(); } -void Shader::setColor(shaderparameter_t uniform, struct Color color) { +void Shader::setColor( + const shaderparameter_t uniform, + const struct Color color +) { glUniform4f(uniform, color.r, color.g, color.b, color.a); assertNoGLError(); } -void Shader::setVector3(shaderparameter_t uniform, glm::vec3 vector) { +void Shader::setVector3( + const shaderparameter_t uniform, + const glm::vec3 vector +) { glUniform3f(uniform, vector.x, vector.y, vector.z); assertNoGLError(); } -void Shader::setFloat(shaderparameter_t param, float_t value) { +void Shader::setFloat( + const shaderparameter_t param, + const float_t value +) { glUniform1f(param, value); assertNoGLError(); } diff --git a/src/dawnopengl/display/shader/Shader.hpp b/src/dawnopengl/display/shader/Shader.hpp index a1d34170..1bafa450 100644 --- a/src/dawnopengl/display/shader/Shader.hpp +++ b/src/dawnopengl/display/shader/Shader.hpp @@ -31,8 +31,8 @@ namespace Dawn { */ void compileShader( std::map attributeLocations, - std::string vertexShader, - std::string fragmentShader + const std::string vertexShader, + const std::string fragmentShader ); /** @@ -43,7 +43,10 @@ namespace Dawn { * @param name Attribute name in the HLSL shader. * @param location Index pointing to which location it is to be bound to. */ - void bindAttributeLocation(std::string name, int32_t location); + void bindAttributeLocation( + const std::string name, + const int32_t location + ); public: /** @@ -52,7 +55,7 @@ namespace Dawn { * @param name Name of the parameter to get. * @return The shader parameter. */ - shaderparameter_t getParameterByName(std::string name); + shaderparameter_t getParameterByName(const std::string name); /** * Locate a shader buffer parameter set by its name. @@ -60,27 +63,49 @@ namespace Dawn { * @param name Name of the buffer to get. * @return The shader buffer. */ - shaderbufferlocation_t getBufferLocationByName(std::string name); + shaderbufferlocation_t getBufferLocationByName(const std::string name); virtual void compile() override = 0; void bind() override; + void setParameterBuffer( - shaderbufferlocation_t location, - shaderbufferslot_t slot + const shaderbufferlocation_t location, + const shaderbufferslot_t slot ); - void setMatrix(shaderparameter_t parameter, glm::mat4 matrix) override; - void setBoolean(shaderparameter_t parameter, bool_t value) override; - void setColor(shaderparameter_t parameter, struct Color color) override; - void setVector3(shaderparameter_t parameter, glm::vec3 vector) override; - void setTexture( - shaderparameter_t parameter, - textureslot_t texture + + void setMatrix( + const shaderparameter_t parameter, + const glm::mat4 matrix + ) override; + + void setBoolean( + const shaderparameter_t parameter, + const bool_t value + ) override; + + void setColor( + const shaderparameter_t parameter, + const struct Color color + ) override; + + void setVector3( + const shaderparameter_t parameter, + const glm::vec3 vector + ) override; + + void setTexture( + const shaderparameter_t parameter, + const textureslot_t texture + ) override; + + void setFloat( + const shaderparameter_t parameter, + const float_t value ) override; - void setFloat(shaderparameter_t parameter, float_t value) override; /** * Destroys and deletes the shader from the GPU. */ - virtual ~Shader(); + ~Shader(); }; } \ No newline at end of file