From bb4fcbc97b72e2a6a50ec154cee84c062d1a0df9 Mon Sep 17 00:00:00 2001 From: Menno Date: Fri, 21 May 2021 15:09:07 +0200 Subject: [PATCH] [EDIT] comments on each function --- src/entities/Camera.h | 6 +++ src/entities/Entity.h | 11 ++++++ src/models/Model.h | 9 +++-- src/renderEngine/Loader.h | 13 +++++-- src/renderEngine/Renderer.h | 12 ++++-- src/renderEngine/obj_loader.h | 4 +- src/shaders/entity_shader.h | 34 +++++++++++++++++ src/shaders/shader_program.h | 72 +++++++++++++++++++++++++++++++---- src/toolbox/toolbox.h | 18 ++++++++- 9 files changed, 160 insertions(+), 19 deletions(-) diff --git a/src/entities/Camera.h b/src/entities/Camera.h index 5fe6313..68dfa5b 100644 --- a/src/entities/Camera.h +++ b/src/entities/Camera.h @@ -12,6 +12,7 @@ namespace entities class Camera { private: + // The movement speed of the camera const float SPEED = 0.52f; glm::vec3 position; @@ -20,6 +21,11 @@ namespace entities public: Camera(const ::glm::vec3& position, const ::glm::vec3& rotation); + /* + * @brief: This funtion moves the camera's position from the inputs of the keyboard + * + * @param window: The OpenGL window + */ void Move(GLFWwindow* window); inline glm::vec3 GetPosition() const{ return position; } diff --git a/src/entities/Entity.h b/src/entities/Entity.h index 089091d..ca09fe0 100644 --- a/src/entities/Entity.h +++ b/src/entities/Entity.h @@ -20,7 +20,18 @@ namespace entities public: Entity(const models::TexturedModel& model, const glm::vec3& position, const glm::vec3& rotation, float scale); + /* + * @brief: This function increases the position of the entity + * + * @param distance: The amount of distance in each axis the entity needs to move + */ void IncreasePosition(const glm::vec3& distance); + + /* + * @brief: This function increases the rotation of the entity + * + * @param rotation: The angle of each axis the entity needs to rotate + */ void IncreaseRotation(const glm::vec3& rotation); inline models::TexturedModel GetModel() const{return model;} diff --git a/src/models/Model.h b/src/models/Model.h index 0388654..b2e6d98 100644 --- a/src/models/Model.h +++ b/src/models/Model.h @@ -5,11 +5,11 @@ namespace models { /* - Structure for storing a vboID and vertex_count. + Structure for storing a vboID and vertex_count (this representa a mesh without a model). - This structure represents a Bare bones Model (A mesh without a texture). - The vao_id, points to an ID stored by openGL and the - vertex_count is how many triangles in the mesh there are. + vao_id = The openGL id of the model + vertex_count = The amount of vertices in the model + model_size = The size on each axis of the model */ struct RawModel { @@ -21,6 +21,7 @@ namespace models /* Structure for storing a texture (texture_id) to apply to a RawModel. + texture_id = The openGL id of the textures shine_damper = A damper for the angle the model needs to be look at to see reflections reflectivity = The amount of light the model reflects */ diff --git a/src/renderEngine/Loader.h b/src/renderEngine/Loader.h index c5fa8e9..2a360f2 100644 --- a/src/renderEngine/Loader.h +++ b/src/renderEngine/Loader.h @@ -9,17 +9,24 @@ namespace render_engine namespace loader { /* - This function generates a model from model data. + @brief: This function generates a model from model data. + + @param position: The positions of each vertex (in order: x, y, z) in the model + @param texture_coords: The texture coordinates of the model + @param normals: The normals of each face of the model + @param indices: A list with a sort of lookup table to the positions parameter */ models::RawModel LoadToVAO(std::vector& positions, std::vector& texture_coords, std::vector& normals, std::vector& indices); /* - Loads a texture from a file into openGL using stb_image.h + @brief: Loads a texture from a file into openGL using stb_image.h + + @param file_name: The filepath to the texture */ GLuint LoadTexture(std::string file_name); /* - Call this function when cleaning up all the meshes (when exiting the program). + @brief: Call this function when cleaning up all the meshes (when exiting the program). */ void CleanUp(); } diff --git a/src/renderEngine/Renderer.h b/src/renderEngine/Renderer.h index d908e4f..2379ebf 100644 --- a/src/renderEngine/Renderer.h +++ b/src/renderEngine/Renderer.h @@ -10,17 +10,23 @@ namespace render_engine const glm::vec3 SKY_COLOR = { 0.3f, 0.4f, 0.6f }; /* - Call this function when starting the program + @brief: Call this function when starting the program + + @param shader: The shader to render the entities with */ void Init(shaders::EntityShader& shader); /* - Call this function before rendering. + @brief: Call this function before rendering. + This function will enable culling and load the projectionMatrix into the shader. */ void Prepare(); /* - Call this function when wanting to Render a mesh to the screen. + @brief: Call this function when wanting to Render a mesh to the screen. + + @param entity: The entity which needs to be rendered + @param shader: The shader the entity needs to be rendered with */ void Render(entities::Entity& entity, shaders::EntityShader& shader); } diff --git a/src/renderEngine/obj_loader.h b/src/renderEngine/obj_loader.h index 59a2a7b..4ee6362 100644 --- a/src/renderEngine/obj_loader.h +++ b/src/renderEngine/obj_loader.h @@ -6,7 +6,9 @@ namespace render_engine { /* - * This function retrieves an .obj file, loads it into the VBO and returns a RawModel + * @brief: This function retrieves an .obj file, loads it into the VBO and returns a RawModel + * + * @param file_name: The path to the .obj file */ models::RawModel LoadObjModel(std::string file_name); } \ No newline at end of file diff --git a/src/shaders/entity_shader.h b/src/shaders/entity_shader.h index f236c83..54d9c2e 100644 --- a/src/shaders/entity_shader.h +++ b/src/shaders/entity_shader.h @@ -26,13 +26,47 @@ namespace shaders public: EntityShader(); + /* + * @brief: A method to load the model matrix into the shader + * + * @param matrix: The model matrix + */ void LoadModelMatrix(const glm::mat4& matrix) const; + + /* + * @brief: A method to load the projection matrix into the shader + * + * @param projection: The projection matrix + */ void LoadProjectionMatrix(const glm::mat4& projection) const; + + /* + * @brief: A method to load the view matrix (camera) into the shader + * + * @param camera: The camera which the scene needs to be rendered from + */ void LoadViewMatrix(entities::Camera& camera) const; + /* + * @brief: A method to load a light into the shader + * + * @param light: The light + */ void LoadLight(entities::Light& light) const; + + /* + * @brief: A method to load the the shine variables from a model into the shader + * + * @param shine_damper: The dampening of the angle from when to render reflectivity on the vertex + * @param reflectivity: The amount the model reflects + */ void LoadShineVariables(float shine_damper, float reflectivity) const; + /* + * @brief: A method to load the sky color into the shader. This color will be used for the fog + * + * @param sky_color: The color of the sky + */ void LoadSkyColor(glm::vec3 sky_color) const; protected: diff --git a/src/shaders/shader_program.h b/src/shaders/shader_program.h index b6a04c3..b3f76d3 100644 --- a/src/shaders/shader_program.h +++ b/src/shaders/shader_program.h @@ -21,29 +21,87 @@ namespace shaders ShaderProgram(std::string& vertex_shader, std::string& fragment_shader); virtual ~ShaderProgram() = default; - // Call this function after making the shaderprogram (sets all the attributes of the shader) + /* + * @brief: Call this function after making the shaderprogram (sets all the attributes of the shader) + */ void Init(); - // Call this function before rendering + + /* + * @brief: Call this function before rendering + */ void Start() const; - // Call this function after rendering + + /* + * @brief: Call this function after rendering + */ void Stop() const; - // Call this function when closing the application + + /* + * @brief: Call this function when closing the application + */ void CleanUp() const; protected: - // Set the inputs of the vertex shader + /* + * @brief: Set the inputs of the vertex shader + */ virtual void SetAttributes() const = 0; + + /* + * @brief: Sets/binds a input variable (in) to a VBO from the model + * + * @param attribute: The id of the VBO + * @param variable_name: The name of the "in" variable in the shader + */ void SetAttribute(const GLuint attribute, const char* variable_name) const; - // Loads value's (uniform variables) into the shader + /* + * @brief: This function loads a float value into a uniform variable into the shader + * + * @param location: The location of the variable in openGL + * @param value: The value which will be loaded into the variable + */ void LoadFloat(GLuint location, GLfloat value) const; + + /* + * @brief: This function loads a vector value into a uniform variable into the shader + * + * @param location: The location of the variable in openGL + * @param vector: The value which will be loaded into the variable + */ void LoadVector(GLuint location, glm::vec3 vector) const; + + /* + * @brief: This function loads a 4x4 matrix value into a uniform variable into the shader + * + * @param location: The location of the variable in openGL + * @param matrix: The value which will be loaded into the variable + */ void LoadMatrix(GLuint location, glm::mat4 matrix) const; - + + /* + * @brief: This function will get all the locations of each uniform variable + */ virtual void GetAllUniformLocations() = 0; + + /* + * @brief: This function will retrieve the location of a uniform variable + * + * @param uniform_name: The name of the uniform variable + * + * @return: The location of the uniform variable + */ GLuint GetUniformLocation(const GLchar* uniform_name) const; private: + /* + * @brief: This function will load a shader into openGL + * + * @param shader_string: The shader as a string (the whole code) + * @param type: The type of the shader (Vertex/Fragment) + * + * @return: The id of the shader given by openGL + */ GLuint LoadShader(const std::string& shader_string, GLuint type) const; }; } \ No newline at end of file diff --git a/src/toolbox/toolbox.h b/src/toolbox/toolbox.h index 5e006eb..7e443f2 100644 --- a/src/toolbox/toolbox.h +++ b/src/toolbox/toolbox.h @@ -7,8 +7,24 @@ namespace toolbox { #define WINDOW_WIDTH 1400.0f #define WINDOW_HEIGT 800.0f - + + /* + * @brief: This function will create a model matrix + * + * @param translation: The position of the model + * @param rotation: The rotation of the model + * @param scale: The scale of the model + * + * @return: The model matrix of the model + */ glm::mat4 CreateModelMatrix(glm::vec3 translation, glm::vec3 rotation, float scale); + /* + * @brief: This function will create a view matrix from the camera's position + * + * @param camera: The camera the view matrix needs to be made from + * + * @return: The view matrix + */ glm::mat4 CreateViewMatrix(entities::Camera& camera); }