Skip to content

Commit

Permalink
Merge pull request #37 from MGTheTrain/opt/general
Browse files Browse the repository at this point in the history
Streamlined console logs and replace `#define` macros with `enum class`
  • Loading branch information
MGTheTrain authored Feb 8, 2025
2 parents f91c671 + fc42274 commit 74fa47c
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 110 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Streamlined console logging for better clarity
- Replaced `#define` macros in `gltf-scene-importer` with `enum class` for improved type safety and readability

## [0.8.0] - 05-01-2024

### Added
Expand Down
4 changes: 2 additions & 2 deletions apps/opengl-viewer/include/opengl-viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class OpenGlViewer {
/**
* @brief Iterates recursively over all nodes in the scene
*
* This function is responsible for iteraing recursively over all nodes in the
* This method is responsible for iteraing recursively over all nodes in the
*scene
*
* @param node A shared pointer to the node.
Expand All @@ -139,7 +139,7 @@ class OpenGlViewer {
/**
* @brief Renders the mesh using the specified rendering technique.
*
* This function is responsible for rendering the mesh using the current
* This method is responsible for rendering the mesh using the current
* rendering technique and associated settings. It should be called within the
* rendering loop.
*/
Expand Down
38 changes: 11 additions & 27 deletions apps/opengl-viewer/src/opengl-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ Mgtt::Apps::OpenGlViewer::OpenGlViewer() {
Mgtt::Apps::OpenGlViewer::FramebufferSizeCallback);
#ifndef __EMSCRIPTEN__
if (glewInit() != GLEW_OK) {
throw std::runtime_error("GLEW ERROR: Glew could not be initialized");
throw std::runtime_error("Glew could not be initialized");
}
// Compile shaders and link to OpenGl program

std::pair<std::string, std::string> pbrShaderPathes = {
"assets/shader/core/pbr.vert", "assets/shader/core/pbr.frag"};
this->mgttScene.shader.Compile(pbrShaderPathes);
Expand All @@ -80,7 +80,7 @@ Mgtt::Apps::OpenGlViewer::OpenGlViewer() {
this->renderTextureContainer = Mgtt::Rendering::RenderTexturesContainer(
eq2BrdfLutShaderPathes, brdfLutShaderPathes, envMapShaderPathes);
#else
// Compile shaders and link to OpenGl program

std::pair<std::string, std::string> pbrShaderPathes = {
"assets/shader/es/pbr.vert", "assets/shader/es/pbr.frag"};
this->mgttScene.shader.Compile(pbrShaderPathes);
Expand All @@ -95,20 +95,16 @@ Mgtt::Apps::OpenGlViewer::OpenGlViewer() {
#endif
glEnable(GL_DEPTH_TEST);

// scene
this->gltfSceneImporter =
std::make_unique<Mgtt::Rendering::GltfSceneImporter>();
std::string mgttScenePath = "assets/scenes/water-bottle/WaterBottle.gltf";
// std::string mgttScenePath =
// "assets/scenes/glTF-Sample-Models/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf";

this->gltfSceneImporter->Load(this->mgttScene, mgttScenePath);

// equirectangular to env map
std::string hdrTexturePath = "assets/texture/surgery.jpg";
this->textureManager->LoadFromHdr(this->renderTextureContainer,
hdrTexturePath);

// brdf lut
this->textureManager->LoadBrdfLut(this->renderTextureContainer);

glViewport(0, 0, windowWidth, windowHeight);
Expand Down Expand Up @@ -144,7 +140,7 @@ void Mgtt::Apps::OpenGlViewer::Render() {
static_cast<float>(width) / static_cast<float>(height), 0.1f, 1000.0f);
this->glmMatrices->view =
glm::translate(this->glmMatrices->view, this->cameraPosition);
// Model space transformations

this->glmMatrices->model = glm::scale(
glm::mat4(1.0f), glm::vec3(1.0f / this->mgttScene.aabb.scale));
this->glmMatrices->model =
Expand Down Expand Up @@ -203,14 +199,6 @@ void Mgtt::Apps::OpenGlViewer::Render() {
this->TraverseSceneNode(node);
}

//// Check brdf lut
// this->renderTextureContainer.brdfLutShader.Use();

// glBindVertexArray(this->renderTextureContainer.quadVao);
// glDrawArrays(GL_TRIANGLES, 0, 6);
// glBindVertexArray(0);

// Check env map
if (this->showEnvMap) {
glDepthFunc(GL_LEQUAL);
this->renderTextureContainer.envMapShader.Use();
Expand Down Expand Up @@ -239,7 +227,7 @@ void Mgtt::Apps::OpenGlViewer::Render() {
/**
* @brief Iterates recursively over all nodes in the scene
*
* This function is responsible for iteraing recursively over all nodes in the
* This method is responsible for iteraing recursively over all nodes in the
*scene
*
* @param node A shared pointer to the node.
Expand All @@ -255,7 +243,7 @@ void Mgtt::Apps::OpenGlViewer::TraverseSceneNode(
/**
* @brief Renders the mesh using the specified rendering technique.
*
* This function is responsible for rendering the mesh using the current
* This method is responsible for rendering the mesh using the current
* rendering technique and associated settings. It should be called within the
* rendering loop.
*/
Expand All @@ -266,7 +254,6 @@ void Mgtt::Apps::OpenGlViewer::RenderMesh(
glGetUniformLocation(this->mgttScene.shader.GetProgramId(), "matrix"),
1, GL_FALSE, &node->mesh->matrix[0][0]);
for (auto& meshPrimitve : node->mesh->meshPrimitives) {
// base color
if (meshPrimitve.pbrMaterial.baseColorTexture.id > 0) {
this->mgttScene.shader.SetBool("baseColorTextureSet", true);
this->mgttScene.shader.SetInt("baseColorMap", 0);
Expand All @@ -277,7 +264,6 @@ void Mgtt::Apps::OpenGlViewer::RenderMesh(
this->mgttScene.shader.SetBool("baseColorTextureSet", false);
}

// metallic roughness
if (meshPrimitve.pbrMaterial.metallicRoughnessTexture.id > 0) {
this->mgttScene.shader.SetBool("physicalDescriptorTextureSet", true);
this->mgttScene.shader.SetInt("physicalDescriptorMap", 1);
Expand All @@ -288,7 +274,6 @@ void Mgtt::Apps::OpenGlViewer::RenderMesh(
this->mgttScene.shader.SetBool("physicalDescriptorTextureSet", false);
}

// normal
if (meshPrimitve.pbrMaterial.normalTexture.id > 0) {
this->mgttScene.shader.SetBool("normalTextureSet", true);
this->mgttScene.shader.SetInt("normalMap", 2);
Expand All @@ -298,7 +283,6 @@ void Mgtt::Apps::OpenGlViewer::RenderMesh(
this->mgttScene.shader.SetBool("normalTextureSet", false);
}

// emissive
if (meshPrimitve.pbrMaterial.emissiveTexture.id > 0) {
this->mgttScene.shader.SetBool("emissiveTextureSet", true);
this->mgttScene.shader.SetInt("emissiveMap", 3);
Expand All @@ -309,7 +293,6 @@ void Mgtt::Apps::OpenGlViewer::RenderMesh(
this->mgttScene.shader.SetBool("emissiveTextureSet", false);
}

// ambient occlusion
if (meshPrimitve.pbrMaterial.occlusionTexture.id > 0) {
this->mgttScene.shader.SetBool("occlusionTextureSet", true);
this->mgttScene.shader.SetInt("occlusionMap", 4);
Expand Down Expand Up @@ -410,7 +393,6 @@ void Mgtt::Apps::OpenGlViewer::UpdateSettings() {
std::string mgttScenePath = std::string(selectedPath);
this->gltfSceneImporter->Load(this->mgttScene, mgttScenePath);

// Reset attributes
this->scaleIblAmbient = 1.0f;
this->showEnvMap = false;

Expand Down Expand Up @@ -473,8 +455,10 @@ void Mgtt::Apps::OpenGlViewer::ClearImGui() {
Mgtt::Apps::OpenGlViewer openGlViewer;
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
// @ref
// https://stackoverflow.com/questions/55415179/unable-to-pass-a-proper-lambda-to-emscripten-set-main-loop
/**
* @ref
* https://stackoverflow.com/questions/55415179/unable-to-pass-a-proper-lambda-to-emscripten-set-main-loop
*/
void EmscriptenMainLoop() { openGlViewer.Render(); }
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RotatingTexturedCube {
/**
* @brief Process input for the GLFW window.
*
* This function processes input for the specified GLFW window. It can handle
* This method processes input for the specified GLFW window. It can handle
* keyboard and mouse input events and update the application state
* accordingly.
*/
Expand Down
13 changes: 7 additions & 6 deletions apps/rotating-textured-cube/src/rotating-textured-cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Mgtt::Apps::RotatingTexturedCube::RotatingTexturedCube() {
Mgtt::Apps::RotatingTexturedCube::FramebufferSizeCallback);
#ifndef __EMSCRIPTEN__
if (glewInit() != GLEW_OK) {
throw std::runtime_error("GLEW ERROR: Glew could not be initialized");
throw std::runtime_error("Glew could not be initialized");
}
std::string vsPath = "assets/shader/core/coordinate.vert";
std::string fsPath = "assets/shader/core/coordinate.frag";
Expand Down Expand Up @@ -174,8 +174,7 @@ Mgtt::Apps::RotatingTexturedCube::RotatingTexturedCube() {
}
glGenerateMipmap(GL_TEXTURE_2D);
} else {
throw std::runtime_error("TEXTURE ERROR: Failed to load texture " +
texturePath);
throw std::runtime_error("Failed to load texture " + texturePath);
}
if (this->mesh.meshPrimitives[0].pbrMaterial.baseColorTexture.data) {
stbi_image_free(
Expand Down Expand Up @@ -239,7 +238,7 @@ void Mgtt::Apps::RotatingTexturedCube::Render() {
/**
* @brief Process input for the GLFW window.
*
* This function processes input for the specified GLFW window. It can handle
* This method processes input for the specified GLFW window. It can handle
* keyboard and mouse input events and update the application state accordingly.
*
* @param window A pointer to the GLFW window for which input should be
Expand Down Expand Up @@ -273,8 +272,10 @@ void Mgtt::Apps::RotatingTexturedCube::FramebufferSizeCallback(
Mgtt::Apps::RotatingTexturedCube RotatingTexturedCube;
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
// @ref
// https://stackoverflow.com/questions/55415179/unable-to-pass-a-proper-lambda-to-emscripten-set-main-loop
/**
* @ref
* https://stackoverflow.com/questions/55415179/unable-to-pass-a-proper-lambda-to-emscripten-set-main-loop
*/
void EmscriptenMainLoop() { RotatingTexturedCube.Render(); }
#endif

Expand Down
49 changes: 18 additions & 31 deletions modules/rendering/include/gltf-scene-importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,21 @@
#include <string>
#include <vector>

#define GLTF_COMPONENT_TYPE_BYTE (5120)
#define GLTF_COMPONENT_TYPE_UNSIGNED_BYTE (5121)
#define GLTF_COMPONENT_TYPE_SHORT (5122)
#define GLTF_COMPONENT_TYPE_UNSIGNED_SHORT (5123)
#define GLTF_COMPONENT_TYPE_INT (5124)
#define GLTF_COMPONENT_TYPE_UNSIGNED_INT (5125)
#define GLTF_COMPONENT_TYPE_FLOAT (5126)
#define GLTF_COMPONENT_TYPE_DOUBLE (5130)

#define GLTF_PARAMETER_TYPE_BYTE (5120)
#define GLTF_PARAMETER_TYPE_UNSIGNED_BYTE (5121)
#define GLTF_PARAMETER_TYPE_SHORT (5122)
#define GLTF_PARAMETER_TYPE_UNSIGNED_SHORT (5123)
#define GLTF_PARAMETER_TYPE_INT (5124)
#define GLTF_PARAMETER_TYPE_UNSIGNED_INT (5125)
#define GLTF_PARAMETER_TYPE_FLOAT (5126)

#define GLTF_TYPE_VEC2 (2)
#define GLTF_TYPE_VEC3 (3)
#define GLTF_TYPE_VEC4 (4)
#define GLTF_TYPE_MAT2 (32 + 2)
#define GLTF_TYPE_MAT3 (32 + 3)
#define GLTF_TYPE_MAT4 (32 + 4)
#define GLTF_TYPE_SCALAR (64 + 1)
#define GLTF_TYPE_VECTOR (64 + 4)
#define GLTF_TYPE_MATRIX (64 + 16)

namespace Mgtt::Rendering {
/**
* Enum class representing component types used in GLTF (e.g. BYTE,
* UNSIGNED_INT).
*/
enum class GLTFParameterType {
BYTE = 5120,
UNSIGNED_BYTE = 5121,
SHORT = 5122,
UNSIGNED_SHORT = 5123,
INT = 5124,
UNSIGNED_INT = 5125,
FLOAT = 5126
};

/**
* @brief Implementation of the ISceneImporter interface for importing 3D
* scenes.
Expand Down Expand Up @@ -104,7 +91,7 @@ class GltfSceneImporter : public ISceneImporter {
/**
* @brief Extracts the folder path from a given file path.
*
* This function takes a file path as input and extracts the folder path
* This method takes a file path as input and extracts the folder path
* by finding the last occurrence of the directory separator ('/' or '\\').
*
* @param path The full file path from which to extract the folder path.
Expand Down Expand Up @@ -206,7 +193,7 @@ class GltfSceneImporter : public ISceneImporter {
/**
* @brief Calculates the dimensions of the entire scene.
*
* This function calculates the dimensions of the entire scene by utilizing
* This method calculates the dimensions of the entire scene by utilizing
* the CalculateSceneAABB() and CalculateSceneNodeAABBs() methods. It
* traverses the nodes of the scene recursively to determine the overall size
* of the scene. The calculated dimensions typically include the minimum and
Expand All @@ -219,7 +206,7 @@ class GltfSceneImporter : public ISceneImporter {
/**
* @brief Calculates the axis-aligned bounding box (AABB) of the entire scene.
*
* This function calculates the axis-aligned bounding box (AABB) of the entire
* This method calculates the axis-aligned bounding box (AABB) of the entire
* scene. It traverses all nodes in the scene recursively and computes the
* AABB that encapsulates all geometry within the scene. The AABB represents
* the minimum volume box that entirely contains all objects in the scene.
Expand All @@ -234,7 +221,7 @@ class GltfSceneImporter : public ISceneImporter {
* @brief Calculates the axis-aligned bounding boxes (AABBs) for each node in
* the scene.
*
* This function calculates the axis-aligned bounding boxes (AABBs) for each
* This method calculates the axis-aligned bounding boxes (AABBs) for each
* node in the scene. It traverses all nodes recursively and computes the AABB
* for each individual node based on its geometry.
*
Expand Down
4 changes: 2 additions & 2 deletions modules/rendering/include/model/aabb.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ struct AABB {
* @brief CalculateBoundingBox calculates the bounding box of an object
* transformed by the given matrix.
*
* This function takes a 4x4 transformation matrix and calculates the bounding
* This method takes a 4x4 transformation matrix and calculates the bounding
* box of an object after being transformed by the matrix. The resulting
* bounding box can be used for various purposes, such as collision detection
* or rendering optimizations.
*
* @param m A 4x4 transformation matrix representing the object's
* transformation.
*
* @return void This function does not return a value. The bounding box
* @return void This method does not return a value. The bounding box
* information is typically stored or used internally within the calling code.
*
* @note The function assumes that the object's original bounding box is
Expand Down
2 changes: 1 addition & 1 deletion modules/rendering/include/model/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct Node {
* @brief Applies the initial transformation to the specified node and its
* child nodes recursively.
*
* This function applies the initial transformation to the given node and its
* This method applies the initial transformation to the given node and its
* child nodes recursively. It ensures that the transformation is propagated
* down the hierarchy of nodes, allowing for hierarchical transformations in
* the scene graph.
Expand Down
10 changes: 5 additions & 5 deletions modules/rendering/include/texture-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TextureManager {
/**
* @brief Load cube map textures from the given folder path.
*
* This function loads cube map textures and
* This method loads cube map textures and
* associates it with the provided RenderTexturesContainer. It performs
* necessary operations to make the textures available for use in rendering.
*
Expand All @@ -64,7 +64,7 @@ class TextureManager {
/**
* @brief Load an HDR texture from the given file path.
*
* This function loads an HDR texture from the specified file path and
* This method loads an HDR texture from the specified file path and
* associates it with the provided RenderTexturesContainer. It performs
* necessary operations to make the texture available for use in rendering.
*
Expand All @@ -79,7 +79,7 @@ class TextureManager {
* @brief Load the BRDF Lookup Texture into the provided HDR texture
* container.
*
* This function loads the BRDF Lookup Texture into the provided HDR texture
* This method loads the BRDF Lookup Texture into the provided HDR texture
* container. It performs necessary operations to make the BRDF texture
* available for use in rendering.
*
Expand All @@ -91,7 +91,7 @@ class TextureManager {
/**
* @brief Clear the provided render textures container.
*
* This function clears the contents of the provided RenderTexturesContainer,
* This method clears the contents of the provided RenderTexturesContainer,
* releasing any resources associated with the textures.
*
* @param container The RenderTexturesContainer to clear.
Expand Down Expand Up @@ -126,7 +126,7 @@ class TextureManager {
/**
* @brief Generate the irradiance map for the provided HDR texture container.
*
* This function generates the irradiance map for the provided HDR texture
* This method generates the irradiance map for the provided HDR texture
* container. It performs necessary operations to make the irradiance map
* available for use in rendering.
*
Expand Down
Loading

0 comments on commit 74fa47c

Please sign in to comment.