Add m_ to member variables.

This commit is contained in:
2021-07-04 19:42:12 +02:00
parent 482b041059
commit 498de84943
39 changed files with 679 additions and 678 deletions

View File

@@ -12,7 +12,7 @@ add_executable(Fall-Fever
Entity.cpp Entity.cpp
Light.cpp Light.cpp
World.cpp World.cpp
Framebuffer.cpp FrameBuffer.cpp
Widget.cpp Widget.cpp
Screen.cpp Screen.cpp
Menu.cpp Menu.cpp

View File

@@ -6,66 +6,66 @@
Camera::Camera(float fov, float aspectRatio) Camera::Camera(float fov, float aspectRatio)
{ {
this->fov = fov; this->m_fov = fov;
viewMatrix = glm::mat4(1.0f); m_viewMatrix = glm::mat4(1.0f);
updateAspectRatio(aspectRatio); updateAspectRatio(aspectRatio);
updateVPM(); updateVPM();
} }
void Camera::updateVPM() void Camera::updateVPM()
{ {
viewProjectionMatrix = projectionMatrix * viewMatrix; m_viewProjectionMatrix = m_projectionMatrix * m_viewMatrix;
} }
void Camera::updateAspectRatio(float aspectRatio) void Camera::updateAspectRatio(float aspectRatio)
{ {
// projectionMatrix = glm::ortho(-2.0f, 2.0f, -2.0f, 2.0f, -10.f, 100.0f); // m_projectionMatrix = glm::ortho(-2.0f, 2.0f, -2.0f, 2.0f, -10.f, 100.0f);
projectionMatrix = glm::perspective(fov / 2.0f, aspectRatio, 0.1f, 1000.0f); m_projectionMatrix = glm::perspective(m_fov / 2.0f, aspectRatio, 0.1f, 1000.0f);
updateVPM(); updateVPM();
} }
void Camera::translate(glm::vec3 translateVector) void Camera::translate(glm::vec3 translateVector)
{ {
position += translateVector; m_position += translateVector;
viewMatrix = glm::translate(viewMatrix, translateVector * -1.0f); m_viewMatrix = glm::translate(m_viewMatrix, translateVector * -1.0f);
} }
void Camera::lookAtTarget(glm::vec3 target) void Camera::lookAtTarget(glm::vec3 target)
{ {
viewMatrix = glm::lookAt(position, target, upVec); m_viewMatrix = glm::lookAt(m_position, target, m_upVec);
} }
void Camera::lookForward() void Camera::lookForward()
{ {
viewMatrix = glm::lookAt(position, position + frontVec, upVec); m_viewMatrix = glm::lookAt(m_position, m_position + m_frontVec, m_upVec);
} }
void Camera::updatePositionFromKeyboardInput(const CameraActionMap &cameraActionMap, float deltaTime) void Camera::updatePositionFromKeyboardInput(const CameraActionMap &cameraActionMap, float deltaTime)
{ {
glm::vec3 frontVecWithoutY = glm::vec3(frontVec.x, 0.0f, frontVec.z); glm::vec3 frontVecWithoutY = glm::vec3(m_frontVec.x, 0.0f, m_frontVec.z);
glm::vec3 deltaPos = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 deltaPos = glm::vec3(0.0f, 0.0f, 0.0f);
if (cameraActionMap.at(CameraAction::Forward)) { if (cameraActionMap.at(CameraAction::Forward)) {
deltaPos += speed * deltaTime * glm::normalize(frontVecWithoutY); deltaPos += m_speed * deltaTime * glm::normalize(frontVecWithoutY);
} }
if (cameraActionMap.at(CameraAction::Backward)) { if (cameraActionMap.at(CameraAction::Backward)) {
deltaPos -= speed * deltaTime * glm::normalize(frontVecWithoutY); deltaPos -= m_speed * deltaTime * glm::normalize(frontVecWithoutY);
} }
if (cameraActionMap.at(CameraAction::Left)) { if (cameraActionMap.at(CameraAction::Left)) {
deltaPos -= speed * deltaTime * glm::normalize(glm::cross(frontVec, upVec)); deltaPos -= m_speed * deltaTime * glm::normalize(glm::cross(m_frontVec, m_upVec));
} }
if (cameraActionMap.at(CameraAction::Right)) { if (cameraActionMap.at(CameraAction::Right)) {
deltaPos += speed * deltaTime * glm::normalize(glm::cross(frontVec, upVec)); deltaPos += m_speed * deltaTime * glm::normalize(glm::cross(m_frontVec, m_upVec));
} }
if (cameraActionMap.at(CameraAction::Up)) { if (cameraActionMap.at(CameraAction::Up)) {
deltaPos += speed * deltaTime * upVec; deltaPos += m_speed * deltaTime * m_upVec;
} }
if (cameraActionMap.at(CameraAction::Down)) { if (cameraActionMap.at(CameraAction::Down)) {
deltaPos -= speed * deltaTime * upVec; deltaPos -= m_speed * deltaTime * m_upVec;
} }
position += deltaPos; m_position += deltaPos;
} }
void Camera::updateDirectionFromMouseInput(const CameraMouseActionMap &cameraMouseActionMap) void Camera::updateDirectionFromMouseInput(const CameraMouseActionMap &cameraMouseActionMap)
@@ -76,49 +76,49 @@ void Camera::updateDirectionFromMouseInput(const CameraMouseActionMap &cameraMou
return; return;
} }
yaw += cameraMouseActionMap.at(CameraMouseAction::DeltaX); m_yaw += cameraMouseActionMap.at(CameraMouseAction::DeltaX);
pitch += cameraMouseActionMap.at(CameraMouseAction::DeltaY); m_pitch += cameraMouseActionMap.at(CameraMouseAction::DeltaY);
if (pitch > 89.0f) { if (m_pitch > 89.0f) {
pitch = 89.0f; m_pitch = 89.0f;
} }
if (pitch < -89.0f) { if (m_pitch < -89.0f) {
pitch = -89.0f; m_pitch = -89.0f;
} }
glm::vec3 direction; glm::vec3 direction;
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); direction.x = cos(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
direction.y = sin(glm::radians(pitch)); direction.y = sin(glm::radians(m_pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); direction.z = sin(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
frontVec = glm::normalize(direction); m_frontVec = glm::normalize(direction);
} }
void Camera::setPosition(glm::vec3 position) void Camera::setPosition(glm::vec3 position)
{ {
this->position = position; this->m_position = position;
} }
glm::mat4 Camera::getView() glm::mat4 Camera::getView()
{ {
return viewMatrix; return m_viewMatrix;
} }
glm::mat4 Camera::getProj() glm::mat4 Camera::getProj()
{ {
return projectionMatrix; return m_projectionMatrix;
} }
glm::mat4 Camera::getViewProj() glm::mat4 Camera::getViewProj()
{ {
return viewProjectionMatrix; return m_viewProjectionMatrix;
} }
glm::vec3 Camera::getPosition() glm::vec3 Camera::getPosition()
{ {
return position; return m_position;
} }
glm::vec3 Camera::getDirection() glm::vec3 Camera::getDirection()
{ {
return frontVec; return m_frontVec;
} }

View File

@@ -29,18 +29,18 @@ public:
void setPosition(glm::vec3 position); void setPosition(glm::vec3 position);
private: private:
glm::mat4 viewMatrix; glm::mat4 m_viewMatrix;
glm::mat4 projectionMatrix; glm::mat4 m_projectionMatrix;
glm::mat4 viewProjectionMatrix; glm::mat4 m_viewProjectionMatrix;
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 m_position = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 frontVec = glm::vec3(0.0f, 0.0f, -1.0f); glm::vec3 m_frontVec = glm::vec3(0.0f, 0.0f, -1.0f);
glm::vec3 upVec = glm::vec3(0.0f, 1.0f, 0.0f); glm::vec3 m_upVec = glm::vec3(0.0f, 1.0f, 0.0f);
float pitch = 0.0f; float m_pitch = 0.0f;
float yaw = -90.0f; float m_yaw = -90.0f;
float speed = 2.0f; float m_speed = 2.0f;
float fov; float m_fov;
}; };

View File

@@ -25,28 +25,28 @@
Controller::Controller() Controller::Controller()
{ {
gameWindow = new Window(); m_gameWindow = new Window();
gameEventHandler = new EventHandler(gameWindow->getGLFWwindow()); m_gameEventHandler = new EventHandler(m_gameWindow->getGLFWwindow());
camera = new Camera(90.0f, gameWindow->getWindowAspectRatio()); m_camera = new Camera(90.0f, m_gameWindow->getWindowAspectRatio());
JsonParser shaderParser("data/shaderPrograms.json"); JsonParser shaderParser("data/shaderPrograms.json");
shaderPrograms = shaderParser.getShaderPrograms(); m_shaderPrograms = shaderParser.getShaderPrograms();
pp_framebuffer = new Framebuffer(gameWindow->getWindowWidth(), gameWindow->getWindowHeight(), m_postProcessFrameBuffer = new FrameBuffer(m_gameWindow->getWindowWidth(), m_gameWindow->getWindowHeight(),
getShaderProgramByName("postProcessingProgram")); getShaderProgramByName("postProcessingProgram"));
menu = new Menu(pp_framebuffer, getShaderProgramByName("menuProgram")); m_menu = new Menu(m_postProcessFrameBuffer, getShaderProgramByName("menuProgram"));
// Show loading screen... // Show loading screen...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
menu->showScreenByName("loadingScreen"); m_menu->showScreenByName("loadingScreen");
glfwSwapBuffers(gameWindow->getGLFWwindow()); glfwSwapBuffers(m_gameWindow->getGLFWwindow());
// Show main menu when loading is finished... // Show main menu when loading is finished...
menu->showScreenByName("mainMenuScreen"); m_menu->showScreenByName("mainMenuScreen");
world = new World(shaderPrograms); m_world = new World(m_shaderPrograms);
#ifdef _DEBUG #ifdef _DEBUG
// Setup Dear ImGui context // Setup Dear ImGui context
@@ -55,7 +55,7 @@ Controller::Controller()
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
(void)io; (void)io;
// Setup Platform/Renderer bindings // Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(gameWindow->getGLFWwindow(), true); ImGui_ImplGlfw_InitForOpenGL(m_gameWindow->getGLFWwindow(), true);
ImGui_ImplOpenGL3_Init("#version 150"); ImGui_ImplOpenGL3_Init("#version 150");
// Setup Dear ImGui style // Setup Dear ImGui style
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
@@ -70,32 +70,32 @@ Controller::~Controller()
ImGui::DestroyContext(); ImGui::DestroyContext();
#endif #endif
for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) { for (auto it = m_shaderPrograms.begin(); it != m_shaderPrograms.end(); it++) {
delete *it; delete *it;
} }
delete world; delete m_world;
delete camera; delete m_camera;
delete menu; delete m_menu;
delete pp_framebuffer; delete m_postProcessFrameBuffer;
delete gameEventHandler; delete m_gameEventHandler;
delete gameWindow; delete m_gameWindow;
} }
void Controller::run() void Controller::run()
{ {
updateExposure(getShaderProgramByName("postProcessingProgram")); updateExposure(getShaderProgramByName("postProcessingProgram"));
Entity *lightSource = world->getEntityByName("light"); Entity *lightSource = m_world->getEntityByName("light");
lightSource->setScale(0.1f); lightSource->setScale(0.1f);
lightSource->setRotation(glm::vec3(0.f)); lightSource->setRotation(glm::vec3(0.f));
lightSource->setPosition(glm::vec3(-2.f, 1.5f, 2.f)); lightSource->setPosition(glm::vec3(-2.f, 1.5f, 2.f));
lightSource->setIsLightSource(true); lightSource->setIsLightSource(true);
camera->translate(glm::vec3(0.0f, 1.5f, 5.0f)); m_camera->translate(glm::vec3(0.0f, 1.5f, 5.0f));
// This is the game loop // This is the game loop
while (!glfwWindowShouldClose(gameWindow->getGLFWwindow())) { while (!glfwWindowShouldClose(m_gameWindow->getGLFWwindow())) {
// --- Timing --- // --- Timing ---
limit_framerate(); limit_framerate();
@@ -106,15 +106,15 @@ void Controller::run()
if (rotateLightSource) { if (rotateLightSource) {
float radius = 4.0; float radius = 4.0;
glm::vec3 newPos = glm::vec3(-cos(glfwGetTime() * 0.5), 0.5f, sin(glfwGetTime() * 0.5)) * radius; glm::vec3 newPos = glm::vec3(-cos(glfwGetTime() * 0.5), 0.5f, sin(glfwGetTime() * 0.5)) * radius;
world->getEntityByName("light")->setPosition(newPos); m_world->getEntityByName("light")->setPosition(newPos);
} }
if (rotateEntity) { if (rotateEntity) {
world->getEntityById(0)->rotate(glm::vec3(0.0f, 1.0f, 0.0f), -0.2f * deltaTime); m_world->getEntityById(0)->rotate(glm::vec3(0.0f, 1.0f, 0.0f), -0.2f * m_deltaTime);
} }
static glm::vec3 lightColor = glm::vec3(1.f); static glm::vec3 lightColor = glm::vec3(1.f);
static float intensity = 7.5f; static float intensity = 7.5f;
world->updatePointLight(0, true, world->getEntityByName("light")->getPosition(), lightColor, intensity); m_world->updatePointLight(0, true, m_world->getEntityByName("light")->getPosition(), lightColor, intensity);
world->updateDirectionalLight(true, world->getDirectionalLight()->getDirection(), lightColor); m_world->updateDirectionalLight(true, m_world->getDirectionalLight()->getDirection(), lightColor);
getShaderProgramByName("lightProgram")->bind(); getShaderProgramByName("lightProgram")->bind();
getShaderProgramByName("lightProgram")->setUniform("v_lightColor", lightColor * 100.0f); getShaderProgramByName("lightProgram")->setUniform("v_lightColor", lightColor * 100.0f);
getShaderProgramByName("lightProgram")->unbind(); getShaderProgramByName("lightProgram")->unbind();
@@ -129,55 +129,55 @@ void Controller::run()
getShaderProgramByName("defaultProgram")->unbind(); getShaderProgramByName("defaultProgram")->unbind();
if (drawShadows || firstRun) { if (drawShadows || firstRun) {
firstRun = false; firstRun = false;
world->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"), m_world->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"),
getShaderProgramByName("pointShadowDepthProgram")); getShaderProgramByName("pointShadowDepthProgram"));
} }
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
auto activeScreen = menu->getActiveScreen(); auto activeScreen = m_menu->getActiveScreen();
if (activeScreen) { if (activeScreen) {
activeScreen->draw(); activeScreen->draw();
} else { } else {
pp_framebuffer->bind(); m_postProcessFrameBuffer->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera->lookForward(); m_camera->lookForward();
camera->updateVPM(); m_camera->updateVPM();
world->getSkybox()->draw(camera->getView(), camera->getProj()); m_world->getSkybox()->draw(m_camera->getView(), m_camera->getProj());
world->draw(camera->getViewProj(), camera->getPosition()); m_world->draw(m_camera->getViewProj(), m_camera->getPosition());
pp_framebuffer->unbind(); m_postProcessFrameBuffer->unbind();
pp_framebuffer->render(); m_postProcessFrameBuffer->render();
#ifdef _DEBUG #ifdef _DEBUG
renderImGui(world, &lightColor, &rotateEntity, &rotateLightSource, renderImGui(m_world, &lightColor, &rotateEntity, &rotateLightSource,
getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows); getShaderProgramByName("postProcessingProgram"), &intensity, &drawShadows);
#endif #endif
} }
glfwSwapBuffers(gameWindow->getGLFWwindow()); glfwSwapBuffers(m_gameWindow->getGLFWwindow());
// Update window size // Update window size
if (gameWindow->isWindowResized()) { if (m_gameWindow->isWindowResized()) {
gameWindow->updateWindowDimensions(); m_gameWindow->updateWindowDimensions();
updateWindowDimensions(); updateWindowDimensions();
} }
// --- Check events, handle input --- // --- Check events, handle input ---
gameEventHandler->handleEvents(); m_gameEventHandler->handleEvents();
camera->updatePositionFromKeyboardInput(gameEventHandler->getCameraActionMap(), deltaTime); m_camera->updatePositionFromKeyboardInput(m_gameEventHandler->getCameraActionMap(), m_deltaTime);
if (gameWindow->getMouseIsCatched()) { if (m_gameWindow->getMouseIsCatched()) {
camera->updateDirectionFromMouseInput(gameEventHandler->getCameraMouseActionMap()); m_camera->updateDirectionFromMouseInput(m_gameEventHandler->getCameraMouseActionMap());
} }
menu->writeWindowActions(gameEventHandler->getWindowActionMap()); m_menu->writeWindowActions(m_gameEventHandler->getWindowActionMap());
gameWindow->handleWindowActionMap(gameEventHandler->getWindowActionMap()); m_gameWindow->handleWindowActionMap(m_gameEventHandler->getWindowActionMap());
// Handle widget pressed event only when a screen is currently active // Handle widget pressed event only when a screen is currently active
if (menu->getActiveScreen()) if (m_menu->getActiveScreen())
menu->handleMouseButtonActionMap(gameEventHandler->getMouseButtonActionMap(), gameWindow); m_menu->handleMouseButtonActionMap(m_gameEventHandler->getMouseButtonActionMap(), m_gameWindow);
} }
} }
@@ -188,34 +188,34 @@ void Controller::limit_framerate()
lastTime = glfwGetTime() - startingTime; lastTime = glfwGetTime() - startingTime;
double frameTime = 1 / (double)MAX_FPS; double frameTime = 1 / (double)m_MAX_FPS;
if (frameTime > lastTime) { if (frameTime > lastTime) {
Helper::sleep((frameTime - lastTime) * 1000000); Helper::sleep((frameTime - lastTime) * 1000000);
} }
deltaTime = glfwGetTime() - startingTime; m_deltaTime = glfwGetTime() - startingTime;
startingTime = glfwGetTime(); startingTime = glfwGetTime();
} }
void Controller::updateWindowDimensions() void Controller::updateWindowDimensions()
{ {
camera->updateAspectRatio(gameWindow->getWindowAspectRatio()); m_camera->updateAspectRatio(m_gameWindow->getWindowAspectRatio());
gameEventHandler->setFirstMouseInput(1); m_gameEventHandler->setFirstMouseInput(1);
pp_framebuffer->changeDimensions(gameWindow->getWindowWidth(), gameWindow->getWindowHeight()); m_postProcessFrameBuffer->changeDimensions(m_gameWindow->getWindowWidth(), m_gameWindow->getWindowHeight());
} }
void Controller::updateExposure(ShaderProgram *shaderProgram) void Controller::updateExposure(ShaderProgram *shaderProgram)
{ {
shaderProgram->bind(); shaderProgram->bind();
shaderProgram->setUniform("u_exposure", exposure); shaderProgram->setUniform("u_exposure", m_exposure);
shaderProgram->unbind(); shaderProgram->unbind();
} }
ShaderProgram *Controller::getShaderProgramByName(const std::string &name) ShaderProgram *Controller::getShaderProgramByName(const std::string &name)
{ {
for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) { for (auto it = m_shaderPrograms.begin(); it != m_shaderPrograms.end(); it++) {
if ((*it)->getUniqueName() == name) { if ((*it)->getUniqueName() == name) {
return *it; return *it;
} }
@@ -237,7 +237,7 @@ ShaderProgram *Controller::getShaderProgramByName(std::vector<ShaderProgram *> s
void Controller::setMaxFps(uint16_t fps) void Controller::setMaxFps(uint16_t fps)
{ {
MAX_FPS = fps; m_MAX_FPS = fps;
} }
#ifdef _DEBUG #ifdef _DEBUG
@@ -281,7 +281,7 @@ void Controller::renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEn
lightColor->z = color[2]; lightColor->z = color[2];
ImGui::Text("\nMiscellaneous"); ImGui::Text("\nMiscellaneous");
ImGui::SliderFloat("Exposure", &exposure, 0, 5.0f); ImGui::SliderFloat("Exposure", &m_exposure, 0, 5.0f);
ImGui::Checkbox("Draw Shadows", drawShadows); ImGui::Checkbox("Draw Shadows", drawShadows);
ImGui::Checkbox("Rotate Lightsource", rotateLightSource); ImGui::Checkbox("Rotate Lightsource", rotateLightSource);

View File

@@ -3,7 +3,7 @@
#include "Camera.h" #include "Camera.h"
#include "Entity.h" #include "Entity.h"
#include "EventHandler.h" #include "EventHandler.h"
#include "Framebuffer.h" #include "FrameBuffer.h"
#include "Light.h" #include "Light.h"
#include "Menu.h" #include "Menu.h"
#include "ShaderProgram.h" #include "ShaderProgram.h"
@@ -33,21 +33,20 @@ private:
void renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, void renderImGui(World *world, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource,
ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows); ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows);
private: Window *m_gameWindow;
Window *gameWindow; EventHandler *m_gameEventHandler;
EventHandler *gameEventHandler;
World *world; World *m_world;
Camera *camera; Camera *m_camera;
Menu *menu; Menu *m_menu;
std::vector<ShaderProgram *> shaderPrograms; std::vector<ShaderProgram *> m_shaderPrograms;
Framebuffer *pp_framebuffer; FrameBuffer *m_postProcessFrameBuffer;
uint16_t MAX_FPS = 60; uint16_t m_MAX_FPS = 60;
double deltaTime; double m_deltaTime;
float exposure = 1.0f; float m_exposure = 1.0f;
}; };

View File

@@ -3,43 +3,43 @@
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
uint32_t Entity::id_counter = 0; uint32_t Entity::s_idCounter = 0;
Entity::Entity(std::string name, Model *model, ShaderProgram *shaderProgram) Entity::Entity(const std::string &name, Model *model, ShaderProgram *shaderProgram)
: unique_name(name), model(model), shaderProgram(shaderProgram) : m_uniqueName(name), m_model(model), m_shaderProgram(shaderProgram)
{ {
id = id_counter++; m_id = s_idCounter++;
} }
void Entity::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition) void Entity::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition)
{ {
shaderProgram->bind(); m_shaderProgram->bind();
glm::mat4 modelViewProj = viewProjMatrix * modelMatrix; glm::mat4 modelViewProj = viewProjMatrix * m_modelMatrix;
shaderProgram->setUniform("u_modelViewProjMatrix", modelViewProj); m_shaderProgram->setUniform("u_modelViewProjMatrix", modelViewProj);
shaderProgram->setUniform("u_modelMatrix", modelMatrix); m_shaderProgram->setUniform("u_modelMatrix", m_modelMatrix);
glm::mat3 normalMatrix = glm::mat3(modelMatrix); glm::mat3 normalMatrix = glm::mat3(m_modelMatrix);
normalMatrix = glm::transpose(glm::inverse(normalMatrix)); normalMatrix = glm::transpose(glm::inverse(normalMatrix));
shaderProgram->setUniform("u_normalMatrix", normalMatrix); m_shaderProgram->setUniform("u_normalMatrix", normalMatrix);
shaderProgram->setUniform("u_viewPosition", viewPosition); m_shaderProgram->setUniform("u_viewPosition", viewPosition);
// Draw the model // Draw the model
model->draw(shaderProgram); m_model->draw(m_shaderProgram);
shaderProgram->unbind(); m_shaderProgram->unbind();
} }
void Entity::drawDirectionalShadows(glm::mat4 viewProjMatrix, ShaderProgram *p_shaderProgram) void Entity::drawDirectionalShadows(glm::mat4 viewProjMatrix, ShaderProgram *p_shaderProgram)
{ {
p_shaderProgram->bind(); p_shaderProgram->bind();
glm::mat4 modelViewProj = viewProjMatrix * modelMatrix; glm::mat4 modelViewProj = viewProjMatrix * m_modelMatrix;
p_shaderProgram->setUniform("u_modelViewProjMatrix", modelViewProj); p_shaderProgram->setUniform("u_modelViewProjMatrix", modelViewProj);
// Draw the model // Draw the model
model->drawWithoutTextures(); m_model->drawWithoutTextures();
p_shaderProgram->unbind(); p_shaderProgram->unbind();
} }
@@ -48,48 +48,48 @@ void Entity::drawPointShadows(ShaderProgram *p_shaderProgram)
{ {
p_shaderProgram->bind(); p_shaderProgram->bind();
p_shaderProgram->setUniform("u_modelMatrix", modelMatrix); p_shaderProgram->setUniform("u_modelMatrix", m_modelMatrix);
// Draw the model // Draw the model
model->drawWithoutTextures(); m_model->drawWithoutTextures();
p_shaderProgram->unbind(); p_shaderProgram->unbind();
} }
void Entity::translate(glm::vec3 vector) void Entity::translate(glm::vec3 vector)
{ {
position += vector; m_position += vector;
updateModelMatrix(); updateModelMatrix();
} }
void Entity::rotate(glm::vec3 axis, float radians) void Entity::rotate(glm::vec3 axis, float radians)
{ {
glm::quat rotation = glm::angleAxis(radians, axis); glm::quat rotation = glm::angleAxis(radians, axis);
quaternion = rotation * quaternion; m_quaternion = rotation * m_quaternion;
updateModelMatrix(); updateModelMatrix();
} }
void Entity::setPosition(glm::vec3 position) void Entity::setPosition(glm::vec3 position)
{ {
this->position = position; this->m_position = position;
updateModelMatrix(); updateModelMatrix();
} }
void Entity::setRotation(glm::vec3 eulerAngles) void Entity::setRotation(glm::vec3 eulerAngles)
{ {
quaternion = glm::quat(eulerAngles); m_quaternion = glm::quat(eulerAngles);
updateModelMatrix(); updateModelMatrix();
} }
void Entity::setRotation(glm::vec3 axis, float radians) void Entity::setRotation(glm::vec3 axis, float radians)
{ {
quaternion = glm::angleAxis(radians, axis); m_quaternion = glm::angleAxis(radians, axis);
updateModelMatrix(); updateModelMatrix();
} }
void Entity::setScale(float scaleFactor) void Entity::setScale(float scaleFactor)
{ {
modelScale = scaleFactor; m_modelScale = scaleFactor;
updateModelMatrix(); updateModelMatrix();
} }
@@ -99,55 +99,55 @@ void Entity::updateModelMatrix()
// First scaling, then rotation, then translation // First scaling, then rotation, then translation
// Translate // Translate
glm::mat4 translationMatrix = glm::translate(glm::mat4(1.0f), position); glm::mat4 translationMatrix = glm::translate(glm::mat4(1.0f), m_position);
// Rotate // Rotate
glm::mat4 rotationMatrix = glm::toMat4(quaternion); glm::mat4 rotationMatrix = glm::toMat4(m_quaternion);
// Scale // Scale
glm::mat4 scaleMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(modelScale, modelScale, modelScale)); glm::mat4 scaleMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(m_modelScale, m_modelScale, m_modelScale));
modelMatrix = translationMatrix * rotationMatrix * scaleMatrix; m_modelMatrix = translationMatrix * rotationMatrix * scaleMatrix;
} }
void Entity::setIsLightSource(bool temp) void Entity::setIsLightSource(bool temp)
{ {
isLightSource = temp; m_isLightSource = temp;
} }
void Entity::setId(uint32_t id) void Entity::setId(uint32_t id)
{ {
this->id = id; this->m_id = id;
} }
uint32_t Entity::getId() uint32_t Entity::getId()
{ {
return id; return m_id;
} }
std::string Entity::getUniqueName() std::string Entity::getUniqueName()
{ {
return unique_name; return m_uniqueName;
} }
glm::vec3 Entity::getPosition() glm::vec3 Entity::getPosition()
{ {
return position; return m_position;
} }
glm::mat4 Entity::getModelMatrix() glm::mat4 Entity::getModelMatrix()
{ {
return modelMatrix; return m_modelMatrix;
} }
bool Entity::getIsLightSource() bool Entity::getIsLightSource()
{ {
return isLightSource; return m_isLightSource;
} }
Skybox::Skybox(Model *cubeModel, ShaderProgram *shaderProgram, const char *texturePseudoPath) Skybox::Skybox(Model *cubeModel, ShaderProgram *shaderProgram, const char *texturePseudoPath)
: cubeModel(cubeModel), shaderProgram(shaderProgram), cubeMap(texturePseudoPath), : m_cubeModel(cubeModel), m_shaderProgram(shaderProgram), m_cubeMap(texturePseudoPath),
vertexArray(cubeModel->getMesh(0)->getVertexArray()) m_vertexArray(cubeModel->getMesh(0)->getVertexArray())
{ {
// Empty // Empty
} }
@@ -160,18 +160,18 @@ void Skybox::draw(glm::mat4 viewMatrix, glm::mat4 projectionMatrix)
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
shaderProgram->bind(); m_shaderProgram->bind();
// Delete any translation from the skybox cube // Delete any translation from the skybox cube
glm::mat4 viewProjectionMatrix = projectionMatrix * glm::mat4(glm::mat3(viewMatrix)); glm::mat4 viewProjectionMatrix = projectionMatrix * glm::mat4(glm::mat3(viewMatrix));
shaderProgram->setUniform("u_viewProjectionMatrix", viewProjectionMatrix); m_shaderProgram->setUniform("u_viewProjectionMatrix", viewProjectionMatrix);
cubeMap.bind(shaderProgram); m_cubeMap.bind(m_shaderProgram);
cubeModel->getMesh(0)->drawWithoutTextures(); m_cubeModel->getMesh(0)->drawWithoutTextures();
cubeMap.unbind(); m_cubeMap.unbind();
shaderProgram->unbind(); m_shaderProgram->unbind();
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
// Restore face culling // Restore face culling

View File

@@ -10,7 +10,7 @@
class Entity class Entity
{ {
public: public:
Entity(std::string name, Model *model, ShaderProgram *shaderProgram); Entity(const std::string &name, Model *model, ShaderProgram *shaderProgram);
~Entity() = default; ~Entity() = default;
void draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition); void draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition);
@@ -36,23 +36,22 @@ public:
private: private:
void updateModelMatrix(); void updateModelMatrix();
private: uint32_t m_id;
uint32_t id; static uint32_t s_idCounter;
static uint32_t id_counter; std::string m_uniqueName;
std::string unique_name;
Model *model; Model *m_model;
ShaderProgram *shaderProgram; ShaderProgram *m_shaderProgram;
bool isLightSource = false; bool m_isLightSource = false;
glm::mat4 modelMatrix = glm::mat4(1.0f); glm::mat4 m_modelMatrix = glm::mat4(1.0f);
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 m_position = glm::vec3(0.0f, 0.0f, 0.0f);
glm::quat quaternion; glm::vec3 m_velocity = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 velocity = glm::vec3(0.0f, 0.0f, 0.0f); glm::quat m_quaternion;
float modelScale = 1.0f; float m_modelScale = 1.0f;
}; };
class Skybox class Skybox
@@ -64,10 +63,10 @@ public:
void draw(glm::mat4 viewMatrix, glm::mat4 projectionMatrix); void draw(glm::mat4 viewMatrix, glm::mat4 projectionMatrix);
private: private:
Model *cubeModel; Model *m_cubeModel;
ShaderProgram *shaderProgram; ShaderProgram *m_shaderProgram;
CubeMap cubeMap; CubeMap m_cubeMap;
VertexArray *vertexArray; VertexArray *m_vertexArray;
}; };

View File

@@ -2,29 +2,29 @@
#include <iostream> #include <iostream>
CameraActionMap EventHandler::cameraActionMap = {{CameraAction::Forward, false}, {CameraAction::Backward, false}, CameraActionMap EventHandler::s_cameraActionMap = {{CameraAction::Forward, false}, {CameraAction::Backward, false},
{CameraAction::Up, false}, {CameraAction::Down, false}, {CameraAction::Up, false}, {CameraAction::Down, false},
{CameraAction::Left, false}, {CameraAction::Right, false}}; {CameraAction::Left, false}, {CameraAction::Right, false}};
CameraMouseActionMap EventHandler::cameraMouseActionMap = {{CameraMouseAction::DeltaX, 0.0}, CameraMouseActionMap EventHandler::s_cameraMouseActionMap = {{CameraMouseAction::DeltaX, 0.0},
{CameraMouseAction::DeltaY, 0.0}}; {CameraMouseAction::DeltaY, 0.0}};
WindowActionMap EventHandler::windowActionMap = {{WindowAction::WireFrameToggle, false}, WindowActionMap EventHandler::s_windowActionMap = {{WindowAction::WireFrameToggle, false},
{WindowAction::MouseCatchToggle, false}, {WindowAction::MouseCatchToggle, false},
{WindowAction::WindowShouldClose, false}}; {WindowAction::WindowShouldClose, false}};
MouseButtonActionMap EventHandler::mouseButtonActionMap = {{MouseButtonAction::LeftClicked, false}, MouseButtonActionMap EventHandler::s_mouseButtonActionMap = {{MouseButtonAction::LeftClicked, false},
{MouseButtonAction::RightClicked, false}, {MouseButtonAction::RightClicked, false},
{MouseButtonAction::MiddleClicked, false}}; {MouseButtonAction::MiddleClicked, false}};
bool EventHandler::firstMouseInput = 1; bool EventHandler::s_firstMouseInput = 1;
float EventHandler::mouseSensitivity = 0.15f; float EventHandler::s_mouseSensitivity = 0.15f;
EventHandler::EventHandler(GLFWwindow *p_window) : window(p_window) EventHandler::EventHandler(GLFWwindow *p_window) : m_window(p_window)
{ {
glfwSetKeyCallback(window, key_callback); glfwSetKeyCallback(m_window, key_callback);
glfwSetCursorPosCallback(window, mouse_callback); glfwSetCursorPosCallback(m_window, mouse_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetMouseButtonCallback(m_window, mouse_button_callback);
} }
void EventHandler::handleEvents() void EventHandler::handleEvents()
@@ -35,15 +35,15 @@ void EventHandler::handleEvents()
void EventHandler::clearActionRegisters() void EventHandler::clearActionRegisters()
{ {
for (auto &element : cameraMouseActionMap) { for (auto &element : s_cameraMouseActionMap) {
element.second = 0.0; element.second = 0.0;
} }
for (auto &element : windowActionMap) { for (auto &element : s_windowActionMap) {
element.second = 0.0; element.second = 0.0;
} }
for (auto &element : mouseButtonActionMap) { for (auto &element : s_mouseButtonActionMap) {
element.second = 0.0; element.second = 0.0;
} }
} }
@@ -56,55 +56,55 @@ void EventHandler::key_callback(GLFWwindow *window, int key, int scancode, int a
(void)mods; (void)mods;
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
windowActionMap[WindowAction::WindowShouldClose] = 1; s_windowActionMap[WindowAction::WindowShouldClose] = 1;
} }
if (key == GLFW_KEY_O && action == GLFW_PRESS) { if (key == GLFW_KEY_O && action == GLFW_PRESS) {
windowActionMap[WindowAction::WireFrameToggle] = 1; s_windowActionMap[WindowAction::WireFrameToggle] = 1;
} }
if (key == GLFW_KEY_LEFT_CONTROL && action == GLFW_PRESS) { if (key == GLFW_KEY_LEFT_CONTROL && action == GLFW_PRESS) {
windowActionMap[WindowAction::MouseCatchToggle] = 1; s_windowActionMap[WindowAction::MouseCatchToggle] = 1;
firstMouseInput = 1; s_firstMouseInput = 1;
} }
// Movement press // Movement press
if (key == GLFW_KEY_W && action == GLFW_PRESS) { if (key == GLFW_KEY_W && action == GLFW_PRESS) {
cameraActionMap[CameraAction::Forward] = 1; s_cameraActionMap[CameraAction::Forward] = 1;
} }
if (key == GLFW_KEY_S && action == GLFW_PRESS) { if (key == GLFW_KEY_S && action == GLFW_PRESS) {
cameraActionMap[CameraAction::Backward] = 1; s_cameraActionMap[CameraAction::Backward] = 1;
} }
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) { if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) {
cameraActionMap[CameraAction::Up] = 1; s_cameraActionMap[CameraAction::Up] = 1;
} }
if (key == GLFW_KEY_LEFT_SHIFT && action == GLFW_PRESS) { if (key == GLFW_KEY_LEFT_SHIFT && action == GLFW_PRESS) {
cameraActionMap[CameraAction::Down] = 1; s_cameraActionMap[CameraAction::Down] = 1;
} }
if (key == GLFW_KEY_A && action == GLFW_PRESS) { if (key == GLFW_KEY_A && action == GLFW_PRESS) {
cameraActionMap[CameraAction::Left] = 1; s_cameraActionMap[CameraAction::Left] = 1;
} }
if (key == GLFW_KEY_D && action == GLFW_PRESS) { if (key == GLFW_KEY_D && action == GLFW_PRESS) {
cameraActionMap[CameraAction::Right] = 1; s_cameraActionMap[CameraAction::Right] = 1;
} }
// Movement release // Movement release
if (key == GLFW_KEY_W && action == GLFW_RELEASE) { if (key == GLFW_KEY_W && action == GLFW_RELEASE) {
cameraActionMap[CameraAction::Forward] = 0; s_cameraActionMap[CameraAction::Forward] = 0;
} }
if (key == GLFW_KEY_S && action == GLFW_RELEASE) { if (key == GLFW_KEY_S && action == GLFW_RELEASE) {
cameraActionMap[CameraAction::Backward] = 0; s_cameraActionMap[CameraAction::Backward] = 0;
} }
if (key == GLFW_KEY_SPACE && action == GLFW_RELEASE) { if (key == GLFW_KEY_SPACE && action == GLFW_RELEASE) {
cameraActionMap[CameraAction::Up] = 0; s_cameraActionMap[CameraAction::Up] = 0;
} }
if (key == GLFW_KEY_LEFT_SHIFT && action == GLFW_RELEASE) { if (key == GLFW_KEY_LEFT_SHIFT && action == GLFW_RELEASE) {
cameraActionMap[CameraAction::Down] = 0; s_cameraActionMap[CameraAction::Down] = 0;
} }
if (key == GLFW_KEY_A && action == GLFW_RELEASE) { if (key == GLFW_KEY_A && action == GLFW_RELEASE) {
cameraActionMap[CameraAction::Left] = 0; s_cameraActionMap[CameraAction::Left] = 0;
} }
if (key == GLFW_KEY_D && action == GLFW_RELEASE) { if (key == GLFW_KEY_D && action == GLFW_RELEASE) {
cameraActionMap[CameraAction::Right] = 0; s_cameraActionMap[CameraAction::Right] = 0;
} }
} }
@@ -122,17 +122,17 @@ void EventHandler::mouse_callback(GLFWwindow *window, double xpos, double ypos)
lastCursorPosY = ypos; lastCursorPosY = ypos;
// Check if this is the first VALID mouse event after window being resized // Check if this is the first VALID mouse event after window being resized
if (firstMouseInput && !(deltaCursorPosX == 0 && deltaCursorPosY == 0)) { if (s_firstMouseInput && !(deltaCursorPosX == 0 && deltaCursorPosY == 0)) {
firstMouseInput = 0; s_firstMouseInput = 0;
deltaCursorPosX = 0.0; deltaCursorPosX = 0.0;
deltaCursorPosY = 0.0; deltaCursorPosY = 0.0;
} }
deltaCursorPosX *= mouseSensitivity; deltaCursorPosX *= s_mouseSensitivity;
deltaCursorPosY *= mouseSensitivity; deltaCursorPosY *= s_mouseSensitivity;
cameraMouseActionMap[CameraMouseAction::DeltaX] += deltaCursorPosX; s_cameraMouseActionMap[CameraMouseAction::DeltaX] += deltaCursorPosX;
cameraMouseActionMap[CameraMouseAction::DeltaY] += deltaCursorPosY; s_cameraMouseActionMap[CameraMouseAction::DeltaY] += deltaCursorPosY;
} }
void EventHandler::mouse_button_callback(GLFWwindow *window, int button, int action, int mods) void EventHandler::mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
@@ -141,34 +141,34 @@ void EventHandler::mouse_button_callback(GLFWwindow *window, int button, int act
(void)mods; (void)mods;
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS)
mouseButtonActionMap[MouseButtonAction::LeftClicked] = true; s_mouseButtonActionMap[MouseButtonAction::LeftClicked] = true;
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS)
mouseButtonActionMap[MouseButtonAction::RightClicked] = true; s_mouseButtonActionMap[MouseButtonAction::RightClicked] = true;
if (button == GLFW_MOUSE_BUTTON_MIDDLE && action == GLFW_PRESS) if (button == GLFW_MOUSE_BUTTON_MIDDLE && action == GLFW_PRESS)
mouseButtonActionMap[MouseButtonAction::MiddleClicked] = true; s_mouseButtonActionMap[MouseButtonAction::MiddleClicked] = true;
} }
const CameraActionMap &EventHandler::getCameraActionMap() const const CameraActionMap &EventHandler::getCameraActionMap() const
{ {
return cameraActionMap; return s_cameraActionMap;
} }
WindowActionMap &EventHandler::getWindowActionMap() const WindowActionMap &EventHandler::getWindowActionMap() const
{ {
return windowActionMap; return s_windowActionMap;
} }
const MouseButtonActionMap &EventHandler::getMouseButtonActionMap() const const MouseButtonActionMap &EventHandler::getMouseButtonActionMap() const
{ {
return mouseButtonActionMap; return s_mouseButtonActionMap;
} }
const CameraMouseActionMap &EventHandler::getCameraMouseActionMap() const const CameraMouseActionMap &EventHandler::getCameraMouseActionMap() const
{ {
return cameraMouseActionMap; return s_cameraMouseActionMap;
} }
void EventHandler::setFirstMouseInput(bool val) void EventHandler::setFirstMouseInput(bool val)
{ {
firstMouseInput = val; s_firstMouseInput = val;
} }

View File

@@ -32,14 +32,13 @@ private:
static void mouse_button_callback(GLFWwindow *window, int button, int action, int mods); static void mouse_button_callback(GLFWwindow *window, int button, int action, int mods);
static void mouse_callback(GLFWwindow *window, double xpos, double ypos); static void mouse_callback(GLFWwindow *window, double xpos, double ypos);
private: static CameraActionMap s_cameraActionMap;
static CameraActionMap cameraActionMap; static CameraMouseActionMap s_cameraMouseActionMap;
static CameraMouseActionMap cameraMouseActionMap; static WindowActionMap s_windowActionMap;
static WindowActionMap windowActionMap; static MouseButtonActionMap s_mouseButtonActionMap;
static MouseButtonActionMap mouseButtonActionMap;
GLFWwindow *window; static float s_mouseSensitivity;
static bool s_firstMouseInput;
static float mouseSensitivity; GLFWwindow *m_window;
static bool firstMouseInput;
}; };

View File

@@ -1,45 +1,45 @@
#include "Framebuffer.h" #include "FrameBuffer.h"
#include <cstddef> #include <cstddef>
#include <iostream> #include <iostream>
Framebuffer::Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram) : shaderProgram(shaderProgram) FrameBuffer::FrameBuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram) : m_shaderProgram(shaderProgram)
{ {
glGenFramebuffers(1, &FBO); glGenFramebuffers(1, &m_FBO);
generateTextures(width, height); generateTextures(width, height);
setExposureCorrection(true); setExposureCorrection(true);
} }
Framebuffer::~Framebuffer() FrameBuffer::~FrameBuffer()
{ {
glDeleteFramebuffers(1, &FBO); glDeleteFramebuffers(1, &m_FBO);
glDeleteTextures(1, &colorBuffer); glDeleteTextures(1, &m_colorBuffer);
glDeleteRenderbuffers(1, &depthStencilBuffer); glDeleteRenderbuffers(1, &m_depthStencilBuffer);
} }
void Framebuffer::bind() void FrameBuffer::bind()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, FBO); glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
} }
void Framebuffer::unbind() void FrameBuffer::unbind()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
} }
void Framebuffer::render() void FrameBuffer::render()
{ {
// Disable wireframe mode // Disable wireframe mode
GLint wireframe; GLint wireframe;
glGetIntegerv(GL_POLYGON_MODE, &wireframe); glGetIntegerv(GL_POLYGON_MODE, &wireframe);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
shaderProgram->bind(); m_shaderProgram->bind();
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTextureId()); glBindTexture(GL_TEXTURE_2D, getTextureId());
GLint location = glGetUniformLocation(shaderProgram->getShaderProgramId(), "u_texture"); GLint location = glGetUniformLocation(m_shaderProgram->getShaderProgramId(), "u_texture");
glUniform1i(location, 0); glUniform1i(location, 0);
// A VAO is necessary although no data is stored in it // A VAO is necessary although no data is stored in it
@@ -50,66 +50,66 @@ void Framebuffer::render()
glBindVertexArray(0); glBindVertexArray(0);
glPolygonMode(GL_FRONT_AND_BACK, wireframe); glPolygonMode(GL_FRONT_AND_BACK, wireframe);
shaderProgram->unbind(); m_shaderProgram->unbind();
} }
void Framebuffer::changeDimensions(uint32_t width, uint32_t height) void FrameBuffer::changeDimensions(uint32_t width, uint32_t height)
{ {
// Delete old textures // Delete old textures
glDeleteTextures(1, &colorBuffer); glDeleteTextures(1, &m_colorBuffer);
glDeleteRenderbuffers(1, &depthStencilBuffer); glDeleteRenderbuffers(1, &m_depthStencilBuffer);
generateTextures(width, height); generateTextures(width, height);
} }
void Framebuffer::generateTextures(uint32_t width, uint32_t height) void FrameBuffer::generateTextures(uint32_t width, uint32_t height)
{ {
bind(); bind();
// Create new textures // Create new textures
glGenTextures(1, &colorBuffer); glGenTextures(1, &m_colorBuffer);
glGenRenderbuffers(1, &depthStencilBuffer); glGenRenderbuffers(1, &m_depthStencilBuffer);
glBindTexture(GL_TEXTURE_2D, colorBuffer); glBindTexture(GL_TEXTURE_2D, m_colorBuffer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBuffer, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0);
glBindRenderbuffer(GL_RENDERBUFFER, depthStencilBuffer); glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilBuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "[Error] Framebuffer is not complete!" << std::endl; std::cout << "[Error] FrameBuffer is not complete!" << std::endl;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
unbind(); unbind();
} }
void Framebuffer::setExposureCorrection(bool exposureCorrection) void FrameBuffer::setExposureCorrection(bool exposureCorrection)
{ {
shaderProgram->bind(); m_shaderProgram->bind();
shaderProgram->setUniform("u_exposureCorrection", exposureCorrection); m_shaderProgram->setUniform("u_exposureCorrection", exposureCorrection);
shaderProgram->unbind(); m_shaderProgram->unbind();
} }
GLuint Framebuffer::getTextureId() GLuint FrameBuffer::getTextureId()
{ {
return colorBuffer; return m_colorBuffer;
} }
DepthMap::DepthMap(int TYPE, int RESOLUTION) DepthMap::DepthMap(DepthMapType type, int RESOLUTION)
{ {
glGenFramebuffers(1, &depthMapFBO); glGenFramebuffers(1, &m_depthMapFBO);
bind(); bind();
if (TYPE == DEPTHMAP_NORMAL) { if (type == DepthMapType::Normal) {
glGenTextures(1, &depthMap); glGenTextures(1, &m_depthMap);
glBindTexture(GL_TEXTURE_2D, depthMap); glBindTexture(GL_TEXTURE_2D, m_depthMap);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, RESOLUTION, RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, RESOLUTION, RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
NULL); NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -119,33 +119,33 @@ DepthMap::DepthMap(int TYPE, int RESOLUTION)
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthMap, 0);
glDrawBuffer(GL_NONE); glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE); glReadBuffer(GL_NONE);
} else if (TYPE == DEPTHMAP_CUBEMAP) { } else if (type == DepthMapType::CubeMap) {
cubeMap = new CubeMap(RESOLUTION); m_cubeMap = new CubeMap(RESOLUTION);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, cubeMap->getTextureId(), 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_cubeMap->getTextureId(), 0);
glDrawBuffer(GL_NONE); glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE); glReadBuffer(GL_NONE);
} }
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "[Error] Framebuffer is not complete!" << std::endl; std::cout << "[Error] FrameBuffer is not complete!" << std::endl;
unbind(); unbind();
} }
DepthMap::~DepthMap() DepthMap::~DepthMap()
{ {
if (cubeMap) if (m_cubeMap)
delete cubeMap; delete m_cubeMap;
} }
void DepthMap::bind() void DepthMap::bind()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); glBindFramebuffer(GL_FRAMEBUFFER, m_depthMapFBO);
} }
void DepthMap::unbind() void DepthMap::unbind()
@@ -155,15 +155,15 @@ void DepthMap::unbind()
GLuint DepthMap::getFBO() GLuint DepthMap::getFBO()
{ {
return depthMapFBO; return m_depthMapFBO;
} }
GLuint DepthMap::getDepthMap() GLuint DepthMap::getDepthMap()
{ {
return depthMap; return m_depthMap;
} }
GLuint DepthMap::getCubeMapId() GLuint DepthMap::getCubeMapId()
{ {
return cubeMap->getTextureId(); return m_cubeMap->getTextureId();
} }

View File

@@ -4,11 +4,11 @@
#include "Texture.h" #include "Texture.h"
#include <glad/glad.h> #include <glad/glad.h>
class Framebuffer class FrameBuffer
{ {
public: public:
Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram); FrameBuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram);
~Framebuffer(); ~FrameBuffer();
void bind(); void bind();
void unbind(); void unbind();
@@ -23,26 +23,25 @@ public:
private: private:
void generateTextures(uint32_t width, uint32_t height); void generateTextures(uint32_t width, uint32_t height);
private: GLuint m_FBO;
GLuint FBO; GLuint m_colorBuffer;
GLuint colorBuffer; GLuint m_depthStencilBuffer;
GLuint depthStencilBuffer;
ShaderProgram *shaderProgram; ShaderProgram *m_shaderProgram;
}; };
enum depthMapType enum class DepthMapType
{ {
DEPTHMAP_NORMAL, Normal,
DEPTHMAP_CUBEMAP CubeMap
}; };
// Framebuffer without color buffer. (Shadows) // FrameBuffer without color buffer. (Shadows)
class DepthMap class DepthMap
{ {
public: public:
// Normal depthMap with texture and point depthMap with cubeMap // Normal depthMap with texture and point depthMap with cubeMap
DepthMap(int TYPE, int RESOLUTION); DepthMap(DepthMapType type, int RESOLUTION);
~DepthMap(); ~DepthMap();
void bind(); void bind();
@@ -53,10 +52,10 @@ public:
GLuint getCubeMapId(); GLuint getCubeMapId();
private: private:
GLuint depthMapFBO; GLuint m_depthMapFBO;
// Either a normal depthMap is used (Directional shadows) // Either a normal depthMap is used (Directional shadows)
// or a cubeMap is used (Point shadows) // or a cubeMap is used (Point shadows)
GLuint depthMap; GLuint m_depthMap;
CubeMap *cubeMap; CubeMap *m_cubeMap;
}; };

View File

@@ -75,7 +75,7 @@ void Helper::gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum sev
break; break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
_type = "UDEFINED BEHAVIOR"; _type = "UNDEFINED BEHAVIOR";
break; break;
case GL_DEBUG_TYPE_PORTABILITY: case GL_DEBUG_TYPE_PORTABILITY:
@@ -131,17 +131,17 @@ void Helper::gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum sev
<< std::endl; << std::endl;
} }
Helper::Timer::Timer(const std::string &name) : name(name) Helper::Timer::Timer(const std::string &name) : m_name(name)
{ {
start = std::chrono::high_resolution_clock::now(); m_start = std::chrono::high_resolution_clock::now();
} }
Helper::Timer::~Timer() Helper::Timer::~Timer()
{ {
end = std::chrono::high_resolution_clock::now(); m_end = std::chrono::high_resolution_clock::now();
duration = end - start; m_duration = m_end - m_start;
float ms = duration.count() * 1000.0f; float ms = m_duration.count() * 1000.0f;
std::cout << "Timer " << name << " took " << ms << "ms!" << std::endl; std::cout << "Timer " << m_name << " took " << ms << "ms!" << std::endl;
} }

View File

@@ -18,9 +18,11 @@ public:
~Timer(); ~Timer();
private: private:
std::string name; std::string m_name;
std::chrono::high_resolution_clock::time_point start, end;
std::chrono::duration<float> duration; std::chrono::high_resolution_clock::time_point m_start;
std::chrono::high_resolution_clock::time_point m_end;
std::chrono::duration<float> m_duration;
}; };
} // namespace Helper } // namespace Helper

View File

@@ -14,8 +14,8 @@ JsonParser::JsonParser(const std::string &path)
} }
std::string errs; std::string errs;
rbuilder["collectComments"] = false; m_rbuilder["collectComments"] = false;
bool parsingSuccessful = Json::parseFromStream(rbuilder, file, &root, &errs); bool parsingSuccessful = Json::parseFromStream(m_rbuilder, file, &m_root, &errs);
file.close(); file.close();
if (!parsingSuccessful) { if (!parsingSuccessful) {
std::cout << "Failed to parse file\n" << errs << std::endl; std::cout << "Failed to parse file\n" << errs << std::endl;
@@ -30,7 +30,7 @@ std::vector<Model *> JsonParser::getModels()
{ {
std::vector<Model *> temp_models; std::vector<Model *> temp_models;
const Json::Value modelsJson = root["models"]; const Json::Value modelsJson = m_root["models"];
struct ModelSkeleton struct ModelSkeleton
{ {
@@ -72,7 +72,7 @@ std::vector<Entity *> JsonParser::getEntities(std::vector<Model *> &models, std:
{ {
std::vector<Entity *> temp_entities; std::vector<Entity *> temp_entities;
const Json::Value entitiesJson = root["entities"]; const Json::Value entitiesJson = m_root["entities"];
for (unsigned int index = 0; index < entitiesJson.size(); index++) { for (unsigned int index = 0; index < entitiesJson.size(); index++) {
std::string entity_name = entitiesJson[index]["unique_name"].asString(); std::string entity_name = entitiesJson[index]["unique_name"].asString();
@@ -135,7 +135,7 @@ std::vector<ShaderProgram *> JsonParser::getShaderPrograms()
{ {
std::vector<ShaderProgram *> temp_shaderPrograms; std::vector<ShaderProgram *> temp_shaderPrograms;
const Json::Value shaderProgramsJson = root["shaderPrograms"]; const Json::Value shaderProgramsJson = m_root["shaderPrograms"];
for (unsigned int index = 0; index < shaderProgramsJson.size(); index++) { for (unsigned int index = 0; index < shaderProgramsJson.size(); index++) {
std::string shaderProgram_name = shaderProgramsJson[index]["unique_name"].asString(); std::string shaderProgram_name = shaderProgramsJson[index]["unique_name"].asString();
@@ -166,7 +166,7 @@ std::vector<Light *> JsonParser::getLights(ShaderProgram *shaderProgram)
glm::vec3 light_color = {1.0f, 1.0f, 1.0f}; glm::vec3 light_color = {1.0f, 1.0f, 1.0f};
float light_intensity = 10.0f; float light_intensity = 10.0f;
const Json::Value directionalLightsJson = root["directionalLight"]; const Json::Value directionalLightsJson = m_root["directionalLight"];
const Json::Value directionJson = directionalLightsJson["direction"]; const Json::Value directionJson = directionalLightsJson["direction"];
Json::Value colorJson = directionalLightsJson["color"]; Json::Value colorJson = directionalLightsJson["color"];
@@ -192,7 +192,7 @@ std::vector<Light *> JsonParser::getLights(ShaderProgram *shaderProgram)
temp_lights.push_back(current_directionalLight); temp_lights.push_back(current_directionalLight);
// Pointlights // Pointlights
const Json::Value pointLightsJson = root["pointLights"]; const Json::Value pointLightsJson = m_root["pointLights"];
int index = 0; int index = 0;
for (; index < (int)pointLightsJson.size(); index++) { for (; index < (int)pointLightsJson.size(); index++) {
@@ -235,12 +235,12 @@ std::vector<Light *> JsonParser::getLights(ShaderProgram *shaderProgram)
return temp_lights; return temp_lights;
} }
std::vector<Screen *> JsonParser::getScreens(ShaderProgram *menuProgram, Framebuffer *framebuffer) std::vector<Screen *> JsonParser::getScreens(ShaderProgram *menuProgram, FrameBuffer *framebuffer)
{ {
std::vector<Screen *> temp_screens; std::vector<Screen *> temp_screens;
const Json::Value loadingScreenJson = root["loadingScreen"]; const Json::Value loadingScreenJson = m_root["loadingScreen"];
const Json::Value mainMenuScreenJson = root["mainMenuScreen"]; const Json::Value mainMenuScreenJson = m_root["mainMenuScreen"];
std::string name; std::string name;
Screen *screen; Screen *screen;
@@ -282,7 +282,7 @@ Skybox *JsonParser::getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram)
{ {
Skybox *temp_skybox; Skybox *temp_skybox;
const Json::Value shaderProgramsJson = root["skybox"]; const Json::Value shaderProgramsJson = m_root["skybox"];
std::string skybox_texturePath = shaderProgramsJson["texturePath"].asString(); std::string skybox_texturePath = shaderProgramsJson["texturePath"].asString();
temp_skybox = new Skybox(cubeModel, skyboxProgram, skybox_texturePath.c_str()); temp_skybox = new Skybox(cubeModel, skyboxProgram, skybox_texturePath.c_str());

View File

@@ -19,7 +19,7 @@ public:
std::vector<Model *> getModels(); std::vector<Model *> getModels();
std::vector<Entity *> getEntities(std::vector<Model *> &models, std::vector<ShaderProgram *> shaderPrograms); std::vector<Entity *> getEntities(std::vector<Model *> &models, std::vector<ShaderProgram *> shaderPrograms);
std::vector<Light *> getLights(ShaderProgram *shaderProgram); std::vector<Light *> getLights(ShaderProgram *shaderProgram);
std::vector<Screen *> getScreens(ShaderProgram *menuProgram, Framebuffer *framebuffer); std::vector<Screen *> getScreens(ShaderProgram *menuProgram, FrameBuffer *framebuffer);
Skybox *getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram); Skybox *getSkybox(Model *cubeModel, ShaderProgram *skyboxProgram);
std::vector<ShaderProgram *> getShaderPrograms(); std::vector<ShaderProgram *> getShaderPrograms();
@@ -27,7 +27,6 @@ public:
private: private:
std::vector<Widget *> getWidgetsFromScreen(const Json::Value &screenJson); std::vector<Widget *> getWidgetsFromScreen(const Json::Value &screenJson);
private: Json::Value m_root;
Json::Value root; Json::CharReaderBuilder m_rbuilder;
Json::CharReaderBuilder rbuilder;
}; };

View File

@@ -2,108 +2,108 @@
#include <string> #include <string>
uint32_t Light::id_counter = 0; uint32_t Light::s_idCounter = 0;
// Light // Light
Light::Light(glm::vec3 color, float intensity, ShaderProgram *shaderProgram) Light::Light(glm::vec3 color, float intensity, ShaderProgram *shaderProgram)
: shaderProgram(shaderProgram), intensity(intensity) : m_shaderProgram(shaderProgram), m_intensity(intensity)
{ {
id = id_counter++; m_id = s_idCounter++;
lightColor = color * intensity; m_lightColor = color * intensity;
} }
glm::vec3 Light::getColor() glm::vec3 Light::getColor()
{ {
return lightColor; return m_lightColor;
} }
void Light::setShaderProgram(ShaderProgram *shaderProgram) void Light::setShaderProgram(ShaderProgram *shaderProgram)
{ {
this->shaderProgram = shaderProgram; this->m_shaderProgram = shaderProgram;
update(); update();
} }
void Light::setColor(glm::vec3 color) void Light::setColor(glm::vec3 color)
{ {
lightColor = color * intensity; m_lightColor = color * m_intensity;
update(); update();
} }
void Light::setIntensity(float intensity) void Light::setIntensity(float intensity)
{ {
this->intensity = intensity; this->m_intensity = intensity;
} }
void Light::setActive(bool active) void Light::setActive(bool active)
{ {
isActive = active; m_isActive = active;
update(); update();
} }
// PointLight // PointLight
PointLight::PointLight(glm::vec3 position, glm::vec3 color, float intensity, ShaderProgram *shaderProgram) PointLight::PointLight(glm::vec3 position, glm::vec3 color, float intensity, ShaderProgram *shaderProgram)
: Light(color, intensity, shaderProgram), position(position) : Light(color, intensity, shaderProgram), m_position(position)
{ {
// Empty // Empty
} }
void PointLight::update() void PointLight::update()
{ {
shaderProgram->bind(); m_shaderProgram->bind();
shaderProgram->setUniform((getStructMemberName() + "isActive").c_str(), isActive); m_shaderProgram->setUniform((getStructMemberName() + "isActive").c_str(), m_isActive);
shaderProgram->setUniform((getStructMemberName() + "position").c_str(), position); m_shaderProgram->setUniform((getStructMemberName() + "position").c_str(), m_position);
shaderProgram->setUniform((getStructMemberName() + "color").c_str(), lightColor); m_shaderProgram->setUniform((getStructMemberName() + "color").c_str(), m_lightColor);
shaderProgram->unbind(); m_shaderProgram->unbind();
} }
std::string PointLight::getStructMemberName() std::string PointLight::getStructMemberName()
{ {
// id - 1 because id 0 is always the DirectionalLight! // id - 1 because id 0 is always the DirectionalLight!
std::string temp = "u_pointLight[" + std::to_string(id - 1) + "]."; std::string temp = "u_pointLight[" + std::to_string(m_id - 1) + "].";
return temp; return temp;
} }
glm::vec3 PointLight::getPosition() glm::vec3 PointLight::getPosition()
{ {
return position; return m_position;
} }
void PointLight::setPosition(glm::vec3 position) void PointLight::setPosition(glm::vec3 position)
{ {
this->position = position; this->m_position = position;
update(); update();
} }
// DirectionalLight // DirectionalLight
DirectionalLight::DirectionalLight(glm::vec3 direction, glm::vec3 color, float intensity, ShaderProgram *shaderProgram) DirectionalLight::DirectionalLight(glm::vec3 direction, glm::vec3 color, float intensity, ShaderProgram *shaderProgram)
: Light(color, intensity, shaderProgram), direction(direction) : Light(color, intensity, shaderProgram), m_direction(direction)
{ {
// Empty // Empty
} }
void DirectionalLight::update() void DirectionalLight::update()
{ {
shaderProgram->bind(); m_shaderProgram->bind();
shaderProgram->setUniform("u_directionalLight.isActive", isActive); m_shaderProgram->setUniform("u_directionalLight.isActive", m_isActive);
shaderProgram->setUniform("u_directionalLight.direction", direction); m_shaderProgram->setUniform("u_directionalLight.direction", m_direction);
shaderProgram->setUniform("u_directionalLight.color", lightColor); m_shaderProgram->setUniform("u_directionalLight.color", m_lightColor);
shaderProgram->unbind(); m_shaderProgram->unbind();
} }
void DirectionalLight::setDirection(glm::vec3 direction) void DirectionalLight::setDirection(glm::vec3 direction)
{ {
this->direction = direction; this->m_direction = direction;
update(); update();
} }
glm::vec3 DirectionalLight::getDirection() glm::vec3 DirectionalLight::getDirection()
{ {
return direction; return m_direction;
} }

View File

@@ -24,19 +24,18 @@ public:
protected: protected:
Light(glm::vec3 color, float intensity, ShaderProgram *shaderProgram); Light(glm::vec3 color, float intensity, ShaderProgram *shaderProgram);
protected: ShaderProgram *m_shaderProgram;
ShaderProgram *shaderProgram;
uint32_t id; uint32_t m_id;
static uint32_t id_counter; static uint32_t s_idCounter;
bool isActive; bool m_isActive;
bool shouldCastShadow = true; bool m_shouldCastShadow = true;
float intensity; float m_intensity;
// Color // Color
glm::vec3 lightColor; glm::vec3 m_lightColor;
}; };
class PointLight : public Light class PointLight : public Light
@@ -53,8 +52,7 @@ private:
void update() override; void update() override;
std::string getStructMemberName(); std::string getStructMemberName();
private: glm::vec3 m_position = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
}; };
class DirectionalLight : public Light class DirectionalLight : public Light
@@ -69,6 +67,5 @@ public:
private: private:
void update() override; void update() override;
private: glm::vec3 m_direction;
glm::vec3 direction;
}; };

View File

@@ -5,29 +5,29 @@
#include <iostream> #include <iostream>
Menu::Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram) Menu::Menu(FrameBuffer *p_framebuffer, ShaderProgram *p_shaderProgram)
: framebuffer(p_framebuffer), shaderProgram(p_shaderProgram) : m_frameBuffer(p_framebuffer), m_shaderProgram(p_shaderProgram)
{ {
JsonParser screenParser("data/screens.json"); JsonParser screenParser("data/screens.json");
screens = screenParser.getScreens(shaderProgram, framebuffer); m_screens = screenParser.getScreens(m_shaderProgram, m_frameBuffer);
} }
Menu::~Menu() Menu::~Menu()
{ {
// Iterate over screens delete all items // Iterate over screens delete all items
for (auto it = screens.begin(); it != screens.end(); it++) { for (auto it = m_screens.begin(); it != m_screens.end(); it++) {
delete (*it); delete (*it);
} }
} }
Screen *Menu::getScreenByName(const std::string &name) const Screen *Menu::getScreenByName(const std::string &name) const
{ {
if (m_screen_name_cache.find(name) != m_screen_name_cache.end()) if (m_screenNameCache.find(name) != m_screenNameCache.end())
return m_screen_name_cache[name]; return m_screenNameCache[name];
for (auto it : screens) { for (auto it : m_screens) {
if (it->getUniqueName() == name) { if (it->getUniqueName() == name) {
m_screen_name_cache[name] = it; m_screenNameCache[name] = it;
return it; return it;
} }
} }
@@ -37,7 +37,7 @@ Screen *Menu::getScreenByName(const std::string &name) const
Screen *Menu::getActiveScreen() const Screen *Menu::getActiveScreen() const
{ {
return activeScreen; return m_activeScreen;
} }
void Menu::showScreenByName(const std::string &name) void Menu::showScreenByName(const std::string &name)
@@ -48,25 +48,25 @@ void Menu::showScreenByName(const std::string &name)
return; return;
screen->draw(); screen->draw();
activeScreen = screen; m_activeScreen = screen;
} }
void Menu::resetActiveScreen() void Menu::resetActiveScreen()
{ {
activeScreen = nullptr; m_activeScreen = nullptr;
} }
void Menu::handleMouseButtonActionMap(const MouseButtonActionMap &mouseButtonActionMap, Window *window) void Menu::handleMouseButtonActionMap(const MouseButtonActionMap &mouseButtonActionMap, Window *window)
{ {
if (mouseButtonActionMap.at(MouseButtonAction::LeftClicked)) { if (mouseButtonActionMap.at(MouseButtonAction::LeftClicked)) {
auto widgets = activeScreen->getWidgets(); auto widgets = m_activeScreen->getWidgets();
for (auto it = widgets.begin(); it != widgets.end(); it++) { for (auto it = widgets.begin(); it != widgets.end(); it++) {
if ((*it)->isHovered(window)) { if ((*it)->isHovered(window)) {
// std::cout << (*it)->getUniqueName() << " clicked!" << std::endl; // std::cout << (*it)->getUniqueName() << " clicked!" << std::endl;
if ((*it)->getCallbackId() == 1) if ((*it)->getCallbackId() == 1)
resetActiveScreen(); resetActiveScreen();
if ((*it)->getCallbackId() == 2) if ((*it)->getCallbackId() == 2)
shouldExit = true; m_shouldExit = true;
} }
} }
} }
@@ -74,7 +74,7 @@ void Menu::handleMouseButtonActionMap(const MouseButtonActionMap &mouseButtonAct
void Menu::writeWindowActions(WindowActionMap &windowActionMap) void Menu::writeWindowActions(WindowActionMap &windowActionMap)
{ {
if (shouldExit) if (m_shouldExit)
windowActionMap[WindowAction::WindowShouldClose] = true; windowActionMap[WindowAction::WindowShouldClose] = true;
} }

View File

@@ -3,7 +3,7 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include "Framebuffer.h" #include "FrameBuffer.h"
#include "JsonParser.h" #include "JsonParser.h"
#include "Screen.h" #include "Screen.h"
#include "EventHandler.h" #include "EventHandler.h"
@@ -11,7 +11,7 @@
class Menu class Menu
{ {
public: public:
Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram); Menu(FrameBuffer *p_framebuffer, ShaderProgram *p_shaderProgram);
~Menu(); ~Menu();
Screen *getScreenByName(const std::string &name) const; Screen *getScreenByName(const std::string &name) const;
@@ -28,17 +28,17 @@ public:
void onExitPressed(); void onExitPressed();
private: private:
Framebuffer *framebuffer; FrameBuffer *m_frameBuffer;
ShaderProgram *shaderProgram; ShaderProgram *m_shaderProgram;
bool shouldExit = false; bool m_shouldExit = false;
std::vector<Screen *> screens; std::vector<Screen *> m_screens;
Screen *activeScreen; Screen *m_activeScreen;
/*Screen *loadingScreen; /*Screen *loadingScreen;
Screen *mainMenuScreen; Screen *mainMenuScreen;
Screen *optionMenuScreen; Screen *optionMenuScreen;
Screen *pauseMenuScreen;*/ Screen *pauseMenuScreen;*/
mutable std::unordered_map<std::string, Screen *> m_screen_name_cache; mutable std::unordered_map<std::string, Screen *> m_screenNameCache;
}; };

View File

@@ -1,9 +1,9 @@
#include "Mesh.h" #include "Mesh.h"
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<uint32_t> indices, std::vector<Texture *> textures) Mesh::Mesh(std::vector<Vertex> vertices, std::vector<uint32_t> indices, std::vector<Texture *> textures)
: numElements(indices.size()), textures(textures), : m_numElements(indices.size()), m_textures(textures),
vertexArray(static_cast<void *>(vertices.data()), static_cast<void *>(indices.data()), vertices.size(), m_vertexArray(static_cast<void *>(vertices.data()), static_cast<void *>(indices.data()), vertices.size(),
indices.size()) indices.size())
{} {}
void Mesh::draw(ShaderProgram *shaderProgram) void Mesh::draw(ShaderProgram *shaderProgram)
@@ -11,8 +11,8 @@ void Mesh::draw(ShaderProgram *shaderProgram)
uint8_t typeNumberCount[static_cast<int>(TextureType::TEXTURE_TYPE_NUM_ITEMS)]{0}; uint8_t typeNumberCount[static_cast<int>(TextureType::TEXTURE_TYPE_NUM_ITEMS)]{0};
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
// Bind all textures in order to its texture unit // Bind all textures in order to its texture unit
for (auto it = textures.begin(); it != textures.end(); it++) { for (auto it = m_textures.begin(); it != m_textures.end(); it++) {
const int i = it - textures.begin(); const int i = it - m_textures.begin();
TextureType currentTextureType = (*it)->getTextureType(); TextureType currentTextureType = (*it)->getTextureType();
@@ -22,24 +22,24 @@ void Mesh::draw(ShaderProgram *shaderProgram)
} }
// Draw elements // Draw elements
vertexArray.bind(); m_vertexArray.bind();
glDrawElements(GL_TRIANGLES, numElements, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, m_numElements, GL_UNSIGNED_INT, 0);
vertexArray.unbind(); m_vertexArray.unbind();
// Unbind all textures // Unbind all textures
for (auto it = textures.begin(); it != textures.end(); it++) { for (auto it = m_textures.begin(); it != m_textures.end(); it++) {
(*it)->unbind(); (*it)->unbind();
} }
} }
void Mesh::drawWithoutTextures() void Mesh::drawWithoutTextures()
{ {
vertexArray.bind(); m_vertexArray.bind();
glDrawElements(GL_TRIANGLES, numElements, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, m_numElements, GL_UNSIGNED_INT, 0);
vertexArray.unbind(); m_vertexArray.unbind();
} }
VertexArray *Mesh::getVertexArray() VertexArray *Mesh::getVertexArray()
{ {
return &vertexArray; return &m_vertexArray;
} }

View File

@@ -21,9 +21,8 @@ public:
private: private:
void setupMesh(); void setupMesh();
private: uint32_t m_numElements;
uint32_t numElements; std::vector<Texture *> m_textures;
std::vector<Texture *> textures;
VertexArray vertexArray; VertexArray m_vertexArray;
}; };

View File

@@ -3,46 +3,46 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
uint32_t Model::id_counter = 0; uint32_t Model::s_idCounter = 0;
Model::Model(const std::string &modelName, const std::string &modelPath) : unique_name(modelName) Model::Model(const std::string &modelName, const std::string &modelPath) : m_uniqueName(modelName)
{ {
directory = modelPath.substr(0, modelPath.find_last_of('/')); m_workingPath = modelPath.substr(0, modelPath.find_last_of('/'));
loadModel(modelPath); loadModel(modelPath);
id = id_counter++; m_id = s_idCounter++;
} }
Model::~Model() Model::~Model()
{ {
// Go through all loaded textures and delete them // Go through all loaded textures and delete them
for (auto it = loadedTextures.begin(); it != loadedTextures.end(); it++) { for (auto it = m_loadedTextures.begin(); it != m_loadedTextures.end(); it++) {
delete (*it); delete (*it);
} }
} }
void Model::draw(ShaderProgram *shaderProgram) void Model::draw(ShaderProgram *shaderProgram)
{ {
if (!model_prepared) { if (!m_modelPrepared) {
std::cout << "WARNING: Model not prepared! Unable to draw!" << std::endl; std::cout << "WARNING: Model not prepared! Unable to draw!" << std::endl;
return; return;
} }
// Iterate through every mesh and call the draw function // Iterate through every mesh and call the draw function
for (auto mesh : meshes) { for (auto mesh : m_meshes) {
mesh->draw(shaderProgram); mesh->draw(shaderProgram);
} }
} }
void Model::drawWithoutTextures() void Model::drawWithoutTextures()
{ {
if (!model_prepared) { if (!m_modelPrepared) {
std::cout << "WARNING: Model not prepared! Unable to draw!" << std::endl; std::cout << "WARNING: Model not prepared! Unable to draw!" << std::endl;
return; return;
} }
// Iterate through every mesh and call the draw function // Iterate through every mesh and call the draw function
for (auto mesh : meshes) { for (auto mesh : m_meshes) {
mesh->drawWithoutTextures(); mesh->drawWithoutTextures();
} }
} }
@@ -82,12 +82,12 @@ void Model::loadModel(const std::string &pathToModel)
for (unsigned int i = 0; i < numTextures; i++) { for (unsigned int i = 0; i < numTextures; i++) {
TexturePrototype texture_prototype; TexturePrototype texture_prototype;
std::string texturePath = directory + '/' + textureSources[i].c_str(); std::string texturePath = m_workingPath + '/' + textureSources[i].c_str();
texture_prototype.texturePath = std::move(texturePath); texture_prototype.texturePath = std::move(texturePath);
texture_prototype.textureType = textureTypes[i]; texture_prototype.textureType = textureTypes[i];
modelTexturePrototypes.push_back(texture_prototype); m_modelTexturePrototypes.push_back(texture_prototype);
} }
// When there is no normal map bound, please use fallback texture // When there is no normal map bound, please use fallback texture
@@ -103,7 +103,7 @@ void Model::loadModel(const std::string &pathToModel)
texture_prototype.texturePath = "data/res/models/tex/fallback_normal.png"; texture_prototype.texturePath = "data/res/models/tex/fallback_normal.png";
texture_prototype.textureType = TextureType::Normal; texture_prototype.textureType = TextureType::Normal;
modelTexturePrototypes.push_back(texture_prototype); m_modelTexturePrototypes.push_back(texture_prototype);
} }
// Here starts the first mesh // Here starts the first mesh
@@ -146,7 +146,7 @@ void Model::loadModel(const std::string &pathToModel)
mesh_prototype.textureIds.push_back(numTextures); mesh_prototype.textureIds.push_back(numTextures);
} }
modelMeshPrototypes.push_back(std::move(mesh_prototype)); m_modelMeshPrototypes.push_back(std::move(mesh_prototype));
} }
input.close(); input.close();
@@ -154,32 +154,32 @@ void Model::loadModel(const std::string &pathToModel)
void Model::prepareModel() void Model::prepareModel()
{ {
model_prepared = true; m_modelPrepared = true;
// Create textures on GPU // Create textures on GPU
for (auto &it : modelTexturePrototypes) { for (auto &it : m_modelTexturePrototypes) {
Texture *newTex = new Texture(it.texturePath.c_str(), it.textureType); Texture *newTex = new Texture(it.texturePath.c_str(), it.textureType);
loadedTextures.push_back(newTex); m_loadedTextures.push_back(newTex);
} }
// Create meshes on GPU // Create meshes on GPU
for (const auto &it : modelMeshPrototypes) { for (const auto &it : m_modelMeshPrototypes) {
std::vector<Texture *> meshTextures; std::vector<Texture *> meshTextures;
for (const auto it2 : it.textureIds) { for (const auto it2 : it.textureIds) {
meshTextures.push_back(loadedTextures[it2]); meshTextures.push_back(m_loadedTextures[it2]);
} }
Mesh *currentMesh = new Mesh(std::move(it.meshVertices), std::move(it.meshIndices), meshTextures); Mesh *currentMesh = new Mesh(std::move(it.meshVertices), std::move(it.meshIndices), meshTextures);
meshes.push_back(currentMesh); m_meshes.push_back(currentMesh);
} }
} }
Mesh *Model::getMesh(unsigned int index) Mesh *Model::getMesh(unsigned int index)
{ {
return meshes[index]; return m_meshes[index];
} }
std::string Model::getUniqueName() const std::string &Model::getUniqueName()
{ {
return unique_name; return m_uniqueName;
} }

View File

@@ -30,23 +30,22 @@ public:
void drawWithoutTextures(); void drawWithoutTextures();
Mesh *getMesh(unsigned int index); Mesh *getMesh(unsigned int index);
std::string getUniqueName(); const std::string &getUniqueName();
private: private:
void loadModel(const std::string &pathToModel); void loadModel(const std::string &pathToModel);
private: std::vector<Mesh *> m_meshes;
std::vector<Mesh *> meshes; std::vector<Texture *> m_loadedTextures;
std::vector<Texture *> loadedTextures;
std::vector<TexturePrototype> modelTexturePrototypes; std::vector<TexturePrototype> m_modelTexturePrototypes;
std::vector<MeshPrototype> modelMeshPrototypes; std::vector<MeshPrototype> m_modelMeshPrototypes;
std::string directory; std::string m_workingPath;
bool model_prepared = false; bool m_modelPrepared = false;
static uint32_t id_counter; static uint32_t s_idCounter;
uint32_t id; uint32_t m_id;
std::string unique_name; std::string m_uniqueName;
}; };

View File

@@ -1,44 +1,44 @@
#include "Screen.h" #include "Screen.h"
#include "Helper.h" #include "Helper.h"
uint32_t Screen::id_counter = 0; uint32_t Screen::s_idCounter = 0;
Screen::Screen(const std::string &name, std::vector<Widget *> widgets, Framebuffer *framebuffer, Screen::Screen(const std::string &name, std::vector<Widget *> widgets, FrameBuffer *framebuffer,
ShaderProgram *shaderProgram) ShaderProgram *shaderProgram)
: unique_name(name), framebuffer(framebuffer), shaderProgram(shaderProgram), widgets(widgets) : m_uniqueName(name), m_frameBuffer(framebuffer), m_shaderProgram(shaderProgram), m_widgets(widgets)
{ {
id = id_counter++; m_id = s_idCounter++;
} }
Screen::~Screen() Screen::~Screen()
{ {
// Iterate over Widgets and Textures to delete all of them // Iterate over Widgets and Textures to delete all of them
for (auto it = widgets.begin(); it != widgets.end(); it++) { for (auto it = m_widgets.begin(); it != m_widgets.end(); it++) {
delete *it; delete *it;
} }
for (auto it = textures.begin(); it != textures.end(); it++) { for (auto it = m_textures.begin(); it != m_textures.end(); it++) {
delete *it; delete *it;
} }
} }
const std::string &Screen::getUniqueName() const const std::string &Screen::getUniqueName() const
{ {
return unique_name; return m_uniqueName;
} }
std::vector<Widget *> Screen::getWidgets() const std::vector<Widget *> Screen::getWidgets() const
{ {
return widgets; return m_widgets;
} }
Widget *Screen::getWidgetByName(const std::string &name) const Widget *Screen::getWidgetByName(const std::string &name) const
{ {
if (m_widget_name_cache.find(name) != m_widget_name_cache.end()) if (m_widgetNameCache.find(name) != m_widgetNameCache.end())
return m_widget_name_cache[name]; return m_widgetNameCache[name];
for (auto it : widgets) { for (auto it : m_widgets) {
if (it->getUniqueName() == name) { if (it->getUniqueName() == name) {
m_widget_name_cache[name] = it; m_widgetNameCache[name] = it;
return it; return it;
} }
} }
@@ -47,19 +47,19 @@ Widget *Screen::getWidgetByName(const std::string &name) const
void Screen::addWidget(Widget *widget) void Screen::addWidget(Widget *widget)
{ {
widgets.push_back(widget); m_widgets.push_back(widget);
} }
void Screen::draw() const void Screen::draw() const
{ {
framebuffer->setExposureCorrection(false); m_frameBuffer->setExposureCorrection(false);
framebuffer->bind(); m_frameBuffer->bind();
for (auto it = widgets.begin(); it != widgets.end(); it++) { for (auto it = m_widgets.begin(); it != m_widgets.end(); it++) {
(*it)->draw(shaderProgram); (*it)->draw(m_shaderProgram);
} }
framebuffer->unbind(); m_frameBuffer->unbind();
framebuffer->render(); m_frameBuffer->render();
framebuffer->setExposureCorrection(true); m_frameBuffer->setExposureCorrection(true);
} }

View File

@@ -2,7 +2,7 @@
#include <unordered_map> #include <unordered_map>
#include "Framebuffer.h" #include "FrameBuffer.h"
#include "ShaderProgram.h" #include "ShaderProgram.h"
#include "Widget.h" #include "Widget.h"
@@ -11,7 +11,7 @@ class Menu;
class Screen class Screen
{ {
public: public:
Screen(const std::string &name, std::vector<Widget *> widgets, Framebuffer *framebuffer, Screen(const std::string &name, std::vector<Widget *> widgets, FrameBuffer *framebuffer,
ShaderProgram *shaderProgram); ShaderProgram *shaderProgram);
~Screen(); ~Screen();
@@ -23,15 +23,15 @@ public:
Widget *getWidgetByName(const std::string &name) const; Widget *getWidgetByName(const std::string &name) const;
private: private:
uint32_t id; uint32_t m_id;
static uint32_t id_counter; static uint32_t s_idCounter;
std::string unique_name; std::string m_uniqueName;
Framebuffer *framebuffer; FrameBuffer *m_frameBuffer;
ShaderProgram *shaderProgram; ShaderProgram *m_shaderProgram;
std::vector<Texture *> textures; std::vector<Texture *> m_textures;
std::vector<Widget *> widgets; std::vector<Widget *> m_widgets;
mutable std::unordered_map<std::string, Widget *> m_widget_name_cache; mutable std::unordered_map<std::string, Widget *> m_widgetNameCache;
}; };

View File

@@ -8,22 +8,22 @@
ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath, ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath,
const std::string &fragmentShaderPath) const std::string &fragmentShaderPath)
: unique_name(name) : m_uniqueName(name)
{ {
std::string vertexShaderSource = parse(vertexShaderPath.c_str()); std::string vertexShaderSource = parse(vertexShaderPath.c_str());
std::string fragmentShaderSource = parse(fragmentShaderPath.c_str()); std::string fragmentShaderSource = parse(fragmentShaderPath.c_str());
shaderProgramId = glCreateProgram(); m_shaderProgramId = glCreateProgram();
GLuint vs = compile(vertexShaderSource, GL_VERTEX_SHADER); GLuint vs = compile(vertexShaderSource, GL_VERTEX_SHADER);
GLuint fs = compile(fragmentShaderSource, GL_FRAGMENT_SHADER); GLuint fs = compile(fragmentShaderSource, GL_FRAGMENT_SHADER);
glAttachShader(shaderProgramId, vs); glAttachShader(m_shaderProgramId, vs);
glAttachShader(shaderProgramId, fs); glAttachShader(m_shaderProgramId, fs);
glLinkProgram(shaderProgramId); glLinkProgram(m_shaderProgramId);
GLint isLinked = 0; GLint isLinked = 0;
glGetProgramiv(shaderProgramId, GL_LINK_STATUS, &isLinked); glGetProgramiv(m_shaderProgramId, GL_LINK_STATUS, &isLinked);
if (!isLinked) { if (!isLinked) {
std::cout << "Failed to link shaderProgram: " << vertexShaderPath << ", " << fragmentShaderPath << std::endl; std::cout << "Failed to link shaderProgram: " << vertexShaderPath << ", " << fragmentShaderPath << std::endl;
} }
@@ -39,25 +39,25 @@ ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexS
ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath, ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexShaderPath,
const std::string &geometryShaderPath, const std::string &fragmentShaderPath) const std::string &geometryShaderPath, const std::string &fragmentShaderPath)
: unique_name(name) : m_uniqueName(name)
{ {
std::string vertexShaderSource = parse(vertexShaderPath.c_str()); std::string vertexShaderSource = parse(vertexShaderPath.c_str());
std::string geometryShaderSource = parse(geometryShaderPath.c_str()); std::string geometryShaderSource = parse(geometryShaderPath.c_str());
std::string fragmentShaderSource = parse(fragmentShaderPath.c_str()); std::string fragmentShaderSource = parse(fragmentShaderPath.c_str());
shaderProgramId = glCreateProgram(); m_shaderProgramId = glCreateProgram();
GLuint vs = compile(vertexShaderSource, GL_VERTEX_SHADER); GLuint vs = compile(vertexShaderSource, GL_VERTEX_SHADER);
GLuint gs = compile(geometryShaderSource, GL_GEOMETRY_SHADER); GLuint gs = compile(geometryShaderSource, GL_GEOMETRY_SHADER);
GLuint fs = compile(fragmentShaderSource, GL_FRAGMENT_SHADER); GLuint fs = compile(fragmentShaderSource, GL_FRAGMENT_SHADER);
glAttachShader(shaderProgramId, vs); glAttachShader(m_shaderProgramId, vs);
glAttachShader(shaderProgramId, gs); glAttachShader(m_shaderProgramId, gs);
glAttachShader(shaderProgramId, fs); glAttachShader(m_shaderProgramId, fs);
glLinkProgram(shaderProgramId); glLinkProgram(m_shaderProgramId);
GLint isLinked = 0; GLint isLinked = 0;
glGetProgramiv(shaderProgramId, GL_LINK_STATUS, &isLinked); glGetProgramiv(m_shaderProgramId, GL_LINK_STATUS, &isLinked);
if (!isLinked) { if (!isLinked) {
std::cout << "Failed to link shaderProgram: " << vertexShaderPath << ", " << geometryShaderPath << ", " std::cout << "Failed to link shaderProgram: " << vertexShaderPath << ", " << geometryShaderPath << ", "
<< fragmentShaderPath << std::endl; << fragmentShaderPath << std::endl;
@@ -76,12 +76,12 @@ ShaderProgram::ShaderProgram(const std::string &name, const std::string &vertexS
ShaderProgram::~ShaderProgram() ShaderProgram::~ShaderProgram()
{ {
glDeleteProgram(shaderProgramId); glDeleteProgram(m_shaderProgramId);
} }
void ShaderProgram::bind() void ShaderProgram::bind()
{ {
glUseProgram(shaderProgramId); glUseProgram(m_shaderProgramId);
} }
void ShaderProgram::unbind() void ShaderProgram::unbind()
@@ -127,11 +127,11 @@ GLuint ShaderProgram::compile(const std::string &shaderSource, GLenum type)
GLint ShaderProgram::retrieveUniformLocation(const std::string &name) const GLint ShaderProgram::retrieveUniformLocation(const std::string &name) const
{ {
if (uniformLocationCache.find(name) != uniformLocationCache.end()) if (m_uniformLocationCache.find(name) != m_uniformLocationCache.end())
return uniformLocationCache[name]; return m_uniformLocationCache[name];
GLint location = glGetUniformLocation(shaderProgramId, name.c_str()); GLint location = glGetUniformLocation(m_shaderProgramId, name.c_str());
uniformLocationCache[name] = location; m_uniformLocationCache[name] = location;
return location; return location;
} }
@@ -174,10 +174,10 @@ void ShaderProgram::setUniform(const std::string &name, glm::mat4 matrix) const
GLuint ShaderProgram::getShaderProgramId() GLuint ShaderProgram::getShaderProgramId()
{ {
return shaderProgramId; return m_shaderProgramId;
} }
std::string ShaderProgram::getUniqueName() const std::string &ShaderProgram::getUniqueName()
{ {
return unique_name; return m_uniqueName;
} }

View File

@@ -25,16 +25,14 @@ public:
void setUniform(const std::string &name, glm::mat3 matrix) const; void setUniform(const std::string &name, glm::mat3 matrix) const;
void setUniform(const std::string &name, glm::mat4 matrix) const; void setUniform(const std::string &name, glm::mat4 matrix) const;
public:
GLuint getShaderProgramId(); GLuint getShaderProgramId();
std::string getUniqueName(); const std::string &getUniqueName();
private: private:
std::string parse(const std::string &filename); std::string parse(const std::string &filename);
GLuint compile(const std::string &shaderSource, GLenum type); GLuint compile(const std::string &shaderSource, GLenum type);
private: GLuint m_shaderProgramId;
GLuint shaderProgramId; std::string m_uniqueName;
std::string unique_name; mutable std::unordered_map<std::string, GLint> m_uniformLocationCache;
mutable std::unordered_map<std::string, GLint> uniformLocationCache;
}; };

View File

@@ -4,27 +4,27 @@
#include <stb/stb_image.h> #include <stb/stb_image.h>
Texture::Texture(const std::string &texturePath, TextureType textureType) Texture::Texture(const std::string &texturePath, TextureType textureType)
: texturePath(texturePath), textureType(textureType) : m_texturePath(texturePath), m_textureType(textureType)
{ {
stbi_set_flip_vertically_on_load(1); stbi_set_flip_vertically_on_load(1);
auto *textureBuffer = stbi_load(texturePath.c_str(), &textureWidth, &textureHeight, &numComponents, 0); auto *textureBuffer = stbi_load(texturePath.c_str(), &m_textureWidth, &m_textureHeight, &m_numComponents, 0);
GLenum internalFormat; GLenum internalFormat;
GLenum dataFormat; GLenum dataFormat;
if (numComponents == 1) { if (m_numComponents == 1) {
internalFormat = GL_RED; internalFormat = GL_RED;
dataFormat = GL_RED; dataFormat = GL_RED;
} else if (numComponents == 3) { } else if (m_numComponents == 3) {
internalFormat = (textureType == TextureType::Diffuse) ? GL_SRGB8 : GL_RGB8; internalFormat = (textureType == TextureType::Diffuse) ? GL_SRGB8 : GL_RGB8;
dataFormat = GL_RGB; dataFormat = GL_RGB;
} else if (numComponents == 4) { } else if (m_numComponents == 4) {
internalFormat = (textureType == TextureType::Diffuse) ? GL_SRGB8_ALPHA8 : GL_RGBA8; internalFormat = (textureType == TextureType::Diffuse) ? GL_SRGB8_ALPHA8 : GL_RGBA8;
dataFormat = GL_RGBA; dataFormat = GL_RGBA;
} }
// Push texture to grahics card // Push texture to grahics card
glGenTextures(1, &textureId); glGenTextures(1, &m_textureId);
glBindTexture(GL_TEXTURE_2D, textureId); glBindTexture(GL_TEXTURE_2D, m_textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
@@ -38,7 +38,7 @@ Texture::Texture(const std::string &texturePath, TextureType textureType)
return; return;
} }
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, textureWidth, textureHeight, 0, dataFormat, GL_UNSIGNED_BYTE, glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_textureWidth, m_textureHeight, 0, dataFormat, GL_UNSIGNED_BYTE,
textureBuffer); textureBuffer);
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
@@ -48,14 +48,14 @@ Texture::Texture(const std::string &texturePath, TextureType textureType)
Texture::~Texture() Texture::~Texture()
{ {
glDeleteTextures(1, &textureId); glDeleteTextures(1, &m_textureId);
} }
void Texture::bind(uint8_t textureUnit, ShaderProgram *shaderProgram, uint8_t textureTypeNum) void Texture::bind(uint8_t textureUnit, ShaderProgram *shaderProgram, uint8_t textureTypeNum)
{ {
std::string uniformName = "texture_"; std::string uniformName = "texture_";
switch (textureType) { switch (m_textureType) {
case TextureType::Diffuse: case TextureType::Diffuse:
uniformName += "diffuse" + std::to_string(textureTypeNum); uniformName += "diffuse" + std::to_string(textureTypeNum);
@@ -79,7 +79,7 @@ void Texture::bind(uint8_t textureUnit, ShaderProgram *shaderProgram, uint8_t te
shaderProgram->setUniform(uniformName.c_str(), textureUnit); shaderProgram->setUniform(uniformName.c_str(), textureUnit);
glActiveTexture(GL_TEXTURE0 + textureUnit); glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_2D, textureId); glBindTexture(GL_TEXTURE_2D, m_textureId);
} }
void Texture::unbind() void Texture::unbind()
@@ -89,29 +89,29 @@ void Texture::unbind()
TextureType Texture::getTextureType() TextureType Texture::getTextureType()
{ {
return textureType; return m_textureType;
} }
std::string Texture::getPath() std::string Texture::getPath()
{ {
return texturePath; return m_texturePath;
} }
GLuint Texture::getTextureId() GLuint Texture::getTextureId()
{ {
return textureId; return m_textureId;
} }
CubeMap::CubeMap(const char *texturePseudoPath) CubeMap::CubeMap(const char *texturePseudoPath)
{ {
// Reserve space in vector so that elements can be accessed explicitly. // Reserve space in vector so that elements can be accessed explicitly.
texturePaths.resize(CUBEMAP_FACES_NUM_ITEMS); m_texturePaths.resize(CUBEMAP_FACES_NUM_ITEMS);
fillTexturePathVector(texturePseudoPath); fillTexturePathVector(texturePseudoPath);
stbi_set_flip_vertically_on_load(0); stbi_set_flip_vertically_on_load(0);
glGenTextures(1, &textureId); glGenTextures(1, &m_textureId);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureId); glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureId);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -122,7 +122,8 @@ CubeMap::CubeMap(const char *texturePseudoPath)
for (unsigned int i = 0; i < CUBEMAP_FACES_NUM_ITEMS; i++) { for (unsigned int i = 0; i < CUBEMAP_FACES_NUM_ITEMS; i++) {
int32_t numComponents; int32_t numComponents;
auto *textureBuffer = stbi_load(texturePaths[i].c_str(), &textureWidth, &textureHeight, &numComponents, 0); auto *textureBuffer =
stbi_load(m_texturePaths[i].c_str(), &m_textureWidth, &m_textureHeight, &numComponents, 0);
GLenum internalFormat; GLenum internalFormat;
GLenum dataFormat; GLenum dataFormat;
@@ -138,12 +139,12 @@ CubeMap::CubeMap(const char *texturePseudoPath)
} }
if (!textureBuffer) { if (!textureBuffer) {
std::cout << "[Warning] CubeMap Texture " << texturePaths[i].c_str() << " not found!" << std::endl; std::cout << "[Warning] CubeMap Texture " << m_texturePaths[i].c_str() << " not found!" << std::endl;
return; return;
} }
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, textureWidth, textureHeight, 0, dataFormat, glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, m_textureWidth, m_textureHeight, 0,
GL_UNSIGNED_BYTE, textureBuffer); dataFormat, GL_UNSIGNED_BYTE, textureBuffer);
stbi_image_free(textureBuffer); stbi_image_free(textureBuffer);
} }
@@ -151,11 +152,11 @@ CubeMap::CubeMap(const char *texturePseudoPath)
glBindTexture(GL_TEXTURE_CUBE_MAP, 0); glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
} }
CubeMap::CubeMap(int RESOLUTION) : textureWidth(RESOLUTION), textureHeight(RESOLUTION) CubeMap::CubeMap(int RESOLUTION) : m_textureWidth(RESOLUTION), m_textureHeight(RESOLUTION)
{ {
glGenTextures(1, &textureId); glGenTextures(1, &m_textureId);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureId); glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureId);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -174,7 +175,7 @@ CubeMap::CubeMap(int RESOLUTION) : textureWidth(RESOLUTION), textureHeight(RESOL
CubeMap::~CubeMap() CubeMap::~CubeMap()
{ {
glDeleteTextures(1, &textureId); glDeleteTextures(1, &m_textureId);
} }
void CubeMap::bind(ShaderProgram *shaderProgram) void CubeMap::bind(ShaderProgram *shaderProgram)
@@ -183,7 +184,7 @@ void CubeMap::bind(ShaderProgram *shaderProgram)
shaderProgram->setUniform(uniformName.c_str(), 0); shaderProgram->setUniform(uniformName.c_str(), 0);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureId); glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureId);
} }
void CubeMap::unbind() void CubeMap::unbind()
@@ -194,16 +195,16 @@ void CubeMap::unbind()
void CubeMap::fillTexturePathVector(const char *texturePseudoPath) void CubeMap::fillTexturePathVector(const char *texturePseudoPath)
{ {
for (unsigned int i = 0; i < CUBEMAP_FACES_NUM_ITEMS; i++) { for (unsigned int i = 0; i < CUBEMAP_FACES_NUM_ITEMS; i++) {
texturePaths[cm_front] = std::string(texturePseudoPath) + "front.png"; m_texturePaths[cm_front] = std::string(texturePseudoPath) + "front.png";
texturePaths[cm_back] = std::string(texturePseudoPath) + "back.png"; m_texturePaths[cm_back] = std::string(texturePseudoPath) + "back.png";
texturePaths[cm_top] = std::string(texturePseudoPath) + "top.png"; m_texturePaths[cm_top] = std::string(texturePseudoPath) + "top.png";
texturePaths[cm_bottom] = std::string(texturePseudoPath) + "bottom.png"; m_texturePaths[cm_bottom] = std::string(texturePseudoPath) + "bottom.png";
texturePaths[cm_left] = std::string(texturePseudoPath) + "left.png"; m_texturePaths[cm_left] = std::string(texturePseudoPath) + "left.png";
texturePaths[cm_right] = std::string(texturePseudoPath) + "right.png"; m_texturePaths[cm_right] = std::string(texturePseudoPath) + "right.png";
} }
} }
GLuint CubeMap::getTextureId() GLuint CubeMap::getTextureId()
{ {
return textureId; return m_textureId;
} }

View File

@@ -35,15 +35,15 @@ public:
GLuint getTextureId(); GLuint getTextureId();
private: private:
std::string texturePath; std::string m_texturePath;
int32_t textureWidth; int32_t m_textureWidth;
int32_t textureHeight; int32_t m_textureHeight;
int32_t numComponents; int32_t m_numComponents;
GLuint textureId; GLuint m_textureId;
TextureType textureType; TextureType m_textureType;
}; };
class CubeMap class CubeMap
@@ -62,11 +62,10 @@ public:
private: private:
void fillTexturePathVector(const char *texturePseudoPath); void fillTexturePathVector(const char *texturePseudoPath);
private: std::vector<std::string> m_texturePaths;
std::vector<std::string> texturePaths;
GLuint textureId; GLuint m_textureId;
int32_t textureWidth; int32_t m_textureWidth;
int32_t textureHeight; int32_t m_textureHeight;
}; };

View File

@@ -6,15 +6,15 @@
VertexArray::VertexArray(void *vertexData, void *indexData, uint32_t numVertices, uint32_t numIndices) VertexArray::VertexArray(void *vertexData, void *indexData, uint32_t numVertices, uint32_t numIndices)
{ {
glGenVertexArrays(1, &VAO); glGenVertexArrays(1, &m_VAO);
glBindVertexArray(VAO); glBindVertexArray(m_VAO);
glGenBuffers(1, &VBO); glGenBuffers(1, &m_VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO); glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(Vertex), vertexData, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(Vertex), vertexData, GL_STATIC_DRAW);
glGenBuffers(1, &EBO); glGenBuffers(1, &m_EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof(uint32_t), indexData, GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof(uint32_t), indexData, GL_STATIC_DRAW);
// Position // Position
@@ -43,12 +43,12 @@ VertexArray::VertexArray(void *vertexData, void *indexData, uint32_t numVertices
VertexArray::~VertexArray() VertexArray::~VertexArray()
{ {
glDeleteBuffers(1, &VBO); glDeleteBuffers(1, &m_VBO);
} }
void VertexArray::bind() void VertexArray::bind()
{ {
glBindVertexArray(VAO); glBindVertexArray(m_VAO);
} }
void VertexArray::unbind() void VertexArray::unbind()

View File

@@ -16,7 +16,7 @@ public:
static std::vector<Vertex> createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates); static std::vector<Vertex> createVertices(double *vertices, uint32_t numVertices, float *textureCoordinates);
private: private:
GLuint VAO; GLuint m_VAO;
GLuint VBO; GLuint m_VBO;
GLuint EBO; GLuint m_EBO;
}; };

View File

@@ -3,45 +3,53 @@
#include "VertexArray.h" #include "VertexArray.h"
Widget::Widget(std::string &name, Texture *texture, float p_x, float p_y, float p_w, float p_h, uint16_t callbackId) Widget::Widget(std::string &name, Texture *texture, float p_x, float p_y, float p_w, float p_h, uint16_t callbackId)
: x(p_x), y(p_y), w(p_w), h(p_h), unique_name(name), callbackId(callbackId) : m_posX(p_x), m_posY(p_y), m_width(p_w), m_height(p_h), m_uniqueName(name), m_callbackId(callbackId)
{ {
widgetTextures.push_back(texture); m_widgetTextures.push_back(texture);
double widgetVerticesData[12] = { double widgetVerticesData[12] = {
2 * (x + w) - 1.0f, 2 * (y)-1.0f, 0.0f, // Bottom right 2 * (m_posX + m_width) - 1.0f,
2 * (x)-1.0f, 2 * (y + h) - 1.0f, 0.0f, // Top left 2 * (m_posY)-1.0f,
2 * (x)-1.0f, 2 * (y)-1.0f, 0.0f, // Bottom left 0.0f, // Bottom right
2 * (x + w) - 1.0f, 2 * (y + h) - 1.0f, 0.0f // Top right 2 * (m_posX)-1.0f,
2 * (m_posY + m_height) - 1.0f,
0.0f, // Top left
2 * (m_posX)-1.0f,
2 * (m_posY)-1.0f,
0.0f, // Bottom left
2 * (m_posX + m_width) - 1.0f,
2 * (m_posY + m_height) - 1.0f,
0.0f // Top right
}; };
unsigned int widgetIndicesData[6] = {0, 1, 2, 0, 3, 1}; unsigned int widgetIndicesData[6] = {0, 1, 2, 0, 3, 1};
float widgetTextureCoordinates[8] = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f}; float widgetTextureCoordinates[8] = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f};
widgetVertices = VertexArray::createVertices(widgetVerticesData, 12, widgetTextureCoordinates); m_widgetVertices = VertexArray::createVertices(widgetVerticesData, 12, widgetTextureCoordinates);
widgetIndices.assign(widgetIndicesData, widgetIndicesData + 6); m_widgetIndices.assign(widgetIndicesData, widgetIndicesData + 6);
widgetMesh = new Mesh(widgetVertices, widgetIndices, widgetTextures); m_widgetMesh = new Mesh(m_widgetVertices, m_widgetIndices, m_widgetTextures);
} }
Widget::~Widget() Widget::~Widget()
{ {
delete widgetMesh; delete m_widgetMesh;
} }
std::string Widget::getUniqueName() std::string Widget::getUniqueName()
{ {
return unique_name; return m_uniqueName;
} }
uint16_t Widget::getCallbackId() uint16_t Widget::getCallbackId()
{ {
return callbackId; return m_callbackId;
} }
void Widget::draw(ShaderProgram *shaderProgram) void Widget::draw(ShaderProgram *shaderProgram)
{ {
shaderProgram->bind(); shaderProgram->bind();
widgetMesh->draw(shaderProgram); m_widgetMesh->draw(shaderProgram);
shaderProgram->unbind(); shaderProgram->unbind();
} }
@@ -56,7 +64,7 @@ bool Widget::isHovered(Window *window)
double yrel = -ypos / height + 1; double yrel = -ypos / height + 1;
bool isHovered = false; bool isHovered = false;
if (xrel >= x && xrel <= x + w && yrel >= y && yrel <= y + h) if (xrel >= m_posX && xrel <= m_posX + m_width && yrel >= m_posY && yrel <= m_posY + m_height)
isHovered = true; isHovered = true;
return isHovered; return isHovered;

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Framebuffer.h" #include "FrameBuffer.h"
#include "Mesh.h" #include "Mesh.h"
#include "Texture.h" #include "Texture.h"
#include "Window.h" #include "Window.h"
@@ -22,15 +22,15 @@ public:
bool isHovered(Window *window); bool isHovered(Window *window);
private: private:
double x, y, w, h; double m_posX, m_posY, m_width, m_height;
std::string unique_name; std::string m_uniqueName;
uint16_t callbackId; uint16_t m_callbackId;
std::vector<Vertex> widgetVertices; std::vector<Vertex> m_widgetVertices;
std::vector<uint32_t> widgetIndices; std::vector<uint32_t> m_widgetIndices;
std::vector<Texture *> widgetTextures; std::vector<Texture *> m_widgetTextures;
Mesh *widgetMesh; Mesh *m_widgetMesh;
}; };

View File

@@ -13,8 +13,8 @@ Window::Window()
exit(-1); exit(-1);
} }
width = INIT_WINDOW_WIDTH; m_width = INIT_WINDOW_WIDTH;
height = INIT_WINDOW_HEIGHT; m_height = INIT_WINDOW_HEIGHT;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
@@ -28,7 +28,7 @@ Window::Window()
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
#endif #endif
window = glfwCreateWindow(width, height, "OpenGL", NULL, NULL); window = glfwCreateWindow(m_width, m_height, "OpenGL", NULL, NULL);
if (!window) { if (!window) {
std::cout << "Failed to create window" << std::endl; std::cout << "Failed to create window" << std::endl;
} }
@@ -36,8 +36,8 @@ Window::Window()
// Wait for window to maximize (in case) // Wait for window to maximize (in case)
Helper::sleep(1000); Helper::sleep(1000);
glfwGetWindowPos(window, &posX, &posY); glfwGetWindowPos(window, &m_posX, &m_posY);
glfwGetWindowSize(window, &width, &height); glfwGetWindowSize(window, &m_width, &m_height);
// Create OpenGL context // Create OpenGL context
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
@@ -54,7 +54,7 @@ Window::Window()
glDebugMessageCallback(Helper::gl_debug_callback, NULL); glDebugMessageCallback(Helper::gl_debug_callback, NULL);
// Disable mouse cursor // Disable mouse cursor
mouseCatched = false; m_mouseCatched = false;
#endif #endif
// Enable z buffer // Enable z buffer
@@ -71,9 +71,9 @@ Window::Window()
// Disable VSync since my sleep function handles this // Disable VSync since my sleep function handles this
glfwSwapInterval(0); glfwSwapInterval(0);
setCatchedCursor(mouseCatched); setCatchedCursor(m_mouseCatched);
glViewport(0, 0, width, height); glViewport(0, 0, m_width, m_height);
// Tell GLFW which function to call when window is resized // Tell GLFW which function to call when window is resized
// glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
@@ -91,15 +91,15 @@ bool Window::isWindowResized()
glfwGetFramebufferSize(window, &new_width, &new_height); glfwGetFramebufferSize(window, &new_width, &new_height);
glfwGetWindowPos(window, &new_posx, &new_posy); glfwGetWindowPos(window, &new_posx, &new_posy);
return !(new_width == width && new_height == height && new_posx == posX && new_posy == posY); return !(new_width == m_width && new_height == m_height && new_posx == m_posX && new_posy == m_posY);
} }
void Window::updateWindowDimensions() void Window::updateWindowDimensions()
{ {
glfwGetFramebufferSize(window, &width, &height); glfwGetFramebufferSize(window, &m_width, &m_height);
glfwGetWindowPos(window, &posX, &posY); glfwGetWindowPos(window, &m_posX, &m_posY);
glViewport(0, 0, width, height); glViewport(0, 0, m_width, m_height);
} }
void Window::setCatchedCursor(bool value) void Window::setCatchedCursor(bool value)
@@ -115,8 +115,8 @@ void Window::handleWindowActionMap(WindowActionMap &windowActionMap)
{ {
if (windowActionMap.at(WindowAction::WireFrameToggle)) { if (windowActionMap.at(WindowAction::WireFrameToggle)) {
windowActionMap[WindowAction::WireFrameToggle] = false; windowActionMap[WindowAction::WireFrameToggle] = false;
wireFrameMode = !wireFrameMode; m_wireFrameMode = !m_wireFrameMode;
if (wireFrameMode) { if (m_wireFrameMode) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
} else { } else {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
@@ -125,8 +125,8 @@ void Window::handleWindowActionMap(WindowActionMap &windowActionMap)
if (windowActionMap.at(WindowAction::MouseCatchToggle)) { if (windowActionMap.at(WindowAction::MouseCatchToggle)) {
windowActionMap[WindowAction::MouseCatchToggle] = false; windowActionMap[WindowAction::MouseCatchToggle] = false;
mouseCatched = !mouseCatched; m_mouseCatched = !m_mouseCatched;
setCatchedCursor(mouseCatched); setCatchedCursor(m_mouseCatched);
} }
if (windowActionMap.at(WindowAction::WindowShouldClose)) { if (windowActionMap.at(WindowAction::WindowShouldClose)) {
@@ -154,20 +154,20 @@ GLFWwindow *Window::getGLFWwindow()
int Window::getWindowWidth() int Window::getWindowWidth()
{ {
return width; return m_width;
} }
int Window::getWindowHeight() int Window::getWindowHeight()
{ {
return height; return m_height;
} }
float Window::getWindowAspectRatio() float Window::getWindowAspectRatio()
{ {
return (float)width / (float)height; return (float)m_width / (float)m_height;
} }
bool Window::getMouseIsCatched() bool Window::getMouseIsCatched()
{ {
return mouseCatched; return m_mouseCatched;
} }

View File

@@ -27,12 +27,11 @@ private:
static void framebuffer_size_callback(GLFWwindow *window, int width, int height); static void framebuffer_size_callback(GLFWwindow *window, int width, int height);
void setCatchedCursor(bool value); void setCatchedCursor(bool value);
private:
GLFWwindow *window; GLFWwindow *window;
int posX, posY; int m_posX, m_posY;
int width, height; int m_width, m_height;
bool mouseCatched = true; bool m_mouseCatched = true;
bool wireFrameMode = false; bool m_wireFrameMode = false;
}; };

View File

@@ -5,62 +5,62 @@
#include <iostream> #include <iostream>
World::World(std::vector<ShaderProgram *> shaderPrograms) World::World(std::vector<ShaderProgram *> shaderPrograms)
: shaderProgram(Controller::getShaderProgramByName(shaderPrograms, "defaultProgram")), : m_shaderProgram(Controller::getShaderProgramByName(shaderPrograms, "defaultProgram")),
depthMapDirectionalFBO(DEPTHMAP_NORMAL, SHADOW_RES) m_depthMapDirectionalFBO(DepthMapType::Normal, SHADOW_RES)
{ {
// Create 4 depthMaps // Create 4 depthMaps
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
DepthMap *temp_depthMap = new DepthMap(DEPTHMAP_CUBEMAP, SHADOW_RES); DepthMap *temp_depthMap = new DepthMap(DepthMapType::CubeMap, SHADOW_RES);
depthMapPointFBO.push_back(temp_depthMap); m_depthMapPointFBO.push_back(temp_depthMap);
} }
// This will be removed in future when gloss maps are implemented // This will be removed in future when gloss maps are implemented
shaderProgram->bind(); m_shaderProgram->bind();
shaderProgram->setUniform("u_material.shininess", 100.0f); m_shaderProgram->setUniform("u_material.shininess", 100.0f);
shaderProgram->unbind(); m_shaderProgram->unbind();
JsonParser modelParser("data/models.json"); JsonParser modelParser("data/models.json");
models = modelParser.getModels(); m_models = modelParser.getModels();
for (const auto &it : models) { for (const auto &it : m_models) {
it->prepareModel(); it->prepareModel();
} }
entities = modelParser.getEntities(models, shaderPrograms); m_entities = modelParser.getEntities(m_models, shaderPrograms);
skybox = modelParser.getSkybox(getModelByName("cube"), m_skybox = modelParser.getSkybox(getModelByName("cube"),
Controller::getShaderProgramByName(shaderPrograms, "skyboxProgram")); Controller::getShaderProgramByName(shaderPrograms, "skyboxProgram"));
JsonParser lightParser("data/lights.json"); JsonParser lightParser("data/lights.json");
lights = lightParser.getLights(shaderProgram); m_lights = lightParser.getLights(m_shaderProgram);
} }
World::~World() World::~World()
{ {
// Iterate over depthMapPointFBO vector and delete all items // Iterate over depthMapPointFBO vector and delete all items
for (auto it = depthMapPointFBO.begin(); it != depthMapPointFBO.end(); it++) { for (auto it = m_depthMapPointFBO.begin(); it != m_depthMapPointFBO.end(); it++) {
delete (*it); delete (*it);
} }
// Iterate over models and entities and delete all items // Iterate over models and entities and delete all items
for (auto it = models.begin(); it != models.end(); it++) { for (auto it = m_models.begin(); it != m_models.end(); it++) {
delete (*it); delete (*it);
} }
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
delete (*it); delete (*it);
} }
delete skybox; delete m_skybox;
} }
void World::addEntity(Entity *entity) void World::addEntity(Entity *entity)
{ {
entities.push_back(entity); m_entities.push_back(entity);
} }
void World::removeEntityByName(std::string name) void World::removeEntityByName(std::string name)
{ {
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
if ((*it)->getUniqueName() == name) { if ((*it)->getUniqueName() == name) {
entities.erase(it); m_entities.erase(it);
return; return;
} }
} }
@@ -70,8 +70,8 @@ void World::removeEntityByName(std::string name)
void World::clearEntities() void World::clearEntities()
{ {
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
entities.erase(it); m_entities.erase(it);
} }
} }
@@ -95,7 +95,7 @@ void World::updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 c
void World::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition) void World::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition)
{ {
// Draw all entities // Draw all entities
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
(*it)->draw(viewProjMatrix, viewPosition); (*it)->draw(viewProjMatrix, viewPosition);
} }
@@ -113,60 +113,66 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
// Switch face culling (Peter panning) // Switch face culling (Peter panning)
glCullFace(GL_BACK); glCullFace(GL_BACK);
depthMapDirectionalFBO.bind(); m_depthMapDirectionalFBO.bind();
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
// --- Directional shadows --- // --- Directional shadows ---
glm::mat4 directionalLightView = glm::mat4 directionalLightView =
glm::lookAt(-5.0f * glm::vec3(-0.2f, -1.0f, -0.3f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); glm::lookAt(-5.0f * glm::vec3(-0.2f, -1.0f, -0.3f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 directionalLightViewProjectionMatrix = directionalLightProjection * directionalLightView; glm::mat4 directionalLightViewProjectionMatrix = m_directionalLightProjection * directionalLightView;
// Draw scene from light perspective // Draw scene from light perspective
// Draw all entities // Draw all entities
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
(*it)->drawDirectionalShadows(directionalLightViewProjectionMatrix, directionalShaderProgram); (*it)->drawDirectionalShadows(directionalLightViewProjectionMatrix, directionalShaderProgram);
} }
depthMapDirectionalFBO.unbind(); m_depthMapDirectionalFBO.unbind();
shaderProgram->bind(); m_shaderProgram->bind();
// Send lightViewProjMatrix to basic shader // Send lightViewProjMatrix to basic shader
shaderProgram->setUniform("u_directionalLightViewProjMatrix", directionalLightViewProjectionMatrix); m_shaderProgram->setUniform("u_directionalLightViewProjMatrix", directionalLightViewProjectionMatrix);
// Send shadowMap to basic shader // Send shadowMap to basic shader
int textureUnit = static_cast<int>(TextureType::TEXTURE_TYPE_NUM_ITEMS) * 2; int textureUnit = static_cast<int>(TextureType::TEXTURE_TYPE_NUM_ITEMS) * 2;
shaderProgram->setUniform("u_texture_directionalShadowMap", (int)textureUnit); m_shaderProgram->setUniform("u_texture_directionalShadowMap", (int)textureUnit);
glActiveTexture(GL_TEXTURE0 + textureUnit); glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_2D, depthMapDirectionalFBO.getDepthMap()); glBindTexture(GL_TEXTURE_2D, m_depthMapDirectionalFBO.getDepthMap());
shaderProgram->unbind(); m_shaderProgram->unbind();
// --- Point shadows --- // --- Point shadows ---
std::vector<PointLight *> pointLights = getPointLights(); std::vector<PointLight *> pointLights = getPointLights();
// 4 depthMaps for 4 point lights // 4 depthMaps for 4 point lights
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
depthMapPointFBO[i]->bind(); m_depthMapPointFBO[i]->bind();
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
// Create 6 view matrices for every face of the cubeMap // Create 6 view matrices for every face of the cubeMap
std::vector<glm::mat4> viewProjMatrices; std::vector<glm::mat4> viewProjMatrices;
glm::vec3 lightPos = pointLights[i]->getPosition(); glm::vec3 lightPos = pointLights[i]->getPosition();
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(1.0f, 0.0f, 0.0f), viewProjMatrices.push_back(m_pointLightProjection * glm::lookAt(lightPos,
glm::vec3(0.0f, -1.0f, 0.0f))); lightPos + glm::vec3(1.0f, 0.0f, 0.0f),
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)));
glm::vec3(0.0f, -1.0f, 0.0f))); viewProjMatrices.push_back(m_pointLightProjection * glm::lookAt(lightPos,
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 1.0f, 0.0f), lightPos + glm::vec3(-1.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 1.0f))); glm::vec3(0.0f, -1.0f, 0.0f)));
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, -1.0f, 0.0f), viewProjMatrices.push_back(m_pointLightProjection * glm::lookAt(lightPos,
glm::vec3(0.0f, 0.0f, -1.0f))); lightPos + glm::vec3(0.0f, 1.0f, 0.0f),
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, 1.0f)));
glm::vec3(0.0f, -1.0f, 0.0f))); viewProjMatrices.push_back(m_pointLightProjection * glm::lookAt(lightPos,
viewProjMatrices.push_back(pointLightProjection * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, -1.0f), lightPos + glm::vec3(0.0f, -1.0f, 0.0f),
glm::vec3(0.0f, -1.0f, 0.0f))); glm::vec3(0.0f, 0.0f, -1.0f)));
viewProjMatrices.push_back(m_pointLightProjection * glm::lookAt(lightPos,
lightPos + glm::vec3(0.0f, 0.0f, 1.0f),
glm::vec3(0.0f, -1.0f, 0.0f)));
viewProjMatrices.push_back(m_pointLightProjection * glm::lookAt(lightPos,
lightPos + glm::vec3(0.0f, 0.0f, -1.0f),
glm::vec3(0.0f, -1.0f, 0.0f)));
pointShaderProgram->bind(); pointShaderProgram->bind();
@@ -175,27 +181,27 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
viewProjMatrices[i]); viewProjMatrices[i]);
} }
pointShaderProgram->setUniform("pointShadowDepthMapFarPlane", far_plane_point); pointShaderProgram->setUniform("pointShadowDepthMapFarPlane", m_farPlanePoint);
pointShaderProgram->setUniform("v_lightPos", lightPos); pointShaderProgram->setUniform("v_lightPos", lightPos);
// Draw scene from light perspective // Draw scene from light perspective
// Draw all entities // Draw all entities
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
(*it)->drawPointShadows(pointShaderProgram); (*it)->drawPointShadows(pointShaderProgram);
} }
depthMapPointFBO[i]->unbind(); m_depthMapPointFBO[i]->unbind();
shaderProgram->bind(); m_shaderProgram->bind();
shaderProgram->setUniform("pointShadowDepthMapFarPlane", far_plane_point); m_shaderProgram->setUniform("pointShadowDepthMapFarPlane", m_farPlanePoint);
textureUnit = static_cast<int>(TextureType::TEXTURE_TYPE_NUM_ITEMS) * 2 + i + 1; textureUnit = static_cast<int>(TextureType::TEXTURE_TYPE_NUM_ITEMS) * 2 + i + 1;
shaderProgram->setUniform("u_texture_pointShadowMap0", (int)textureUnit); m_shaderProgram->setUniform("u_texture_pointShadowMap0", (int)textureUnit);
glActiveTexture(GL_TEXTURE0 + textureUnit); glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_CUBE_MAP, depthMapPointFBO[i]->getCubeMapId()); glBindTexture(GL_TEXTURE_CUBE_MAP, m_depthMapPointFBO[i]->getCubeMapId());
shaderProgram->unbind(); m_shaderProgram->unbind();
} }
// Reset viewport size // Reset viewport size
@@ -205,7 +211,7 @@ void World::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
Model *World::getModelByName(std::string name) Model *World::getModelByName(std::string name)
{ {
for (auto it = models.begin(); it != models.end(); it++) { for (auto it = m_models.begin(); it != m_models.end(); it++) {
if ((*it)->getUniqueName() == name) { if ((*it)->getUniqueName() == name) {
return *it; return *it;
} }
@@ -216,7 +222,7 @@ Model *World::getModelByName(std::string name)
Entity *World::getEntityByName(std::string name) Entity *World::getEntityByName(std::string name)
{ {
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
if ((*it)->getUniqueName() == name) { if ((*it)->getUniqueName() == name) {
return *it; return *it;
} }
@@ -227,7 +233,7 @@ Entity *World::getEntityByName(std::string name)
Entity *World::getEntityById(uint32_t id) Entity *World::getEntityById(uint32_t id)
{ {
for (auto it = entities.begin(); it != entities.end(); it++) { for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
if ((*it)->getId() == id) { if ((*it)->getId() == id) {
return *it; return *it;
} }
@@ -240,7 +246,7 @@ std::vector<PointLight *> World::getPointLights()
{ {
std::vector<PointLight *> temp_pointLights; std::vector<PointLight *> temp_pointLights;
for (auto it = lights.begin(); it != lights.end(); it++) { for (auto it = m_lights.begin(); it != m_lights.end(); it++) {
PointLight *temp_pointLight = dynamic_cast<PointLight *>(*it); PointLight *temp_pointLight = dynamic_cast<PointLight *>(*it);
if (temp_pointLight) { if (temp_pointLight) {
temp_pointLights.push_back(temp_pointLight); temp_pointLights.push_back(temp_pointLight);
@@ -254,7 +260,7 @@ DirectionalLight *World::getDirectionalLight()
{ {
DirectionalLight *temp_directionalLight = nullptr; DirectionalLight *temp_directionalLight = nullptr;
for (auto it = lights.begin(); it != lights.end(); it++) { for (auto it = m_lights.begin(); it != m_lights.end(); it++) {
temp_directionalLight = dynamic_cast<DirectionalLight *>(*it); temp_directionalLight = dynamic_cast<DirectionalLight *>(*it);
if (temp_directionalLight) if (temp_directionalLight)
break; break;
@@ -265,10 +271,10 @@ DirectionalLight *World::getDirectionalLight()
std::vector<Entity *> World::getEntities() std::vector<Entity *> World::getEntities()
{ {
return entities; return m_entities;
} }
Skybox *World::getSkybox() Skybox *World::getSkybox()
{ {
return skybox; return m_skybox;
} }

View File

@@ -4,7 +4,7 @@
#include "Camera.h" #include "Camera.h"
#include "Entity.h" #include "Entity.h"
#include "Framebuffer.h" #include "FrameBuffer.h"
#include "Light.h" #include "Light.h"
#include "ShaderProgram.h" #include "ShaderProgram.h"
@@ -33,27 +33,27 @@ public:
void calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProgram *pointShaderProgram); void calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProgram *pointShaderProgram);
private: private:
ShaderProgram *shaderProgram; ShaderProgram *m_shaderProgram;
std::vector<Model *> models; std::vector<Model *> m_models;
std::vector<Entity *> entities; std::vector<Entity *> m_entities;
Skybox *skybox; Skybox *m_skybox;
// Lights // Lights
std::vector<Light *> lights; std::vector<Light *> m_lights;
// Shadows // Shadows
const int SHADOW_RES = 4096 / 4; const int SHADOW_RES = 4096 / 4;
DepthMap depthMapDirectionalFBO; DepthMap m_depthMapDirectionalFBO;
std::vector<DepthMap *> depthMapPointFBO; std::vector<DepthMap *> m_depthMapPointFBO;
// Shadow projection matrices // Shadow projection matrices
const float near_plane_directional = 1.0f; const float m_nearPlaneDirectional = 1.0f;
const float far_plane_directional = 15.0f; const float m_farPlaneDirectional = 15.0f;
glm::mat4 directionalLightProjection = glm::mat4 m_directionalLightProjection =
glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane_directional, far_plane_directional); glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, m_nearPlaneDirectional, m_farPlaneDirectional);
const float aspect_ratio_point = 1.0f; const float m_aspectRatioPoint = 1.0f;
const float near_plane_point = 1.0f; const float m_nearPlanePoint = 1.0f;
const float far_plane_point = 25.0f; const float m_farPlanePoint = 25.0f;
glm::mat4 pointLightProjection = glm::mat4 m_pointLightProjection =
glm::perspective(glm::radians(90.0f), aspect_ratio_point, near_plane_point, far_plane_point); glm::perspective(glm::radians(90.0f), m_aspectRatioPoint, m_nearPlanePoint, m_farPlanePoint);
}; };

View File

@@ -60,9 +60,9 @@ int main(int argc, char** argv) {
Model currentModel; Model currentModel;
if(((*it).find('/')) < (*it).length()) { if(((*it).find('/')) < (*it).length()) {
// source includes a / // source includes a /
currentModel.directory = (*it).substr(0, (*it).find_last_of('/')); currentModel.m_workingPath = (*it).substr(0, (*it).find_last_of('/'));
} else { } else {
currentModel.directory = "."; currentModel.m_workingPath = ".";
} }
processNode(scene->mRootNode, scene, &currentModel); processNode(scene->mRootNode, scene, &currentModel);
@@ -96,9 +96,9 @@ int main(int argc, char** argv) {
} }
// Write meshes // Write meshes
uint32_t numMeshes = currentModel.meshes.size(); uint32_t numMeshes = currentModel.m_meshes.size();
output.write((char*) &numMeshes, sizeof(uint32_t)); output.write((char*) &numMeshes, sizeof(uint32_t));
for(auto it1 = currentModel.meshes.begin(); it1 != currentModel.meshes.end(); it1++) { for (auto it1 = currentModel.m_meshes.begin(); it1 != currentModel.m_meshes.end(); it1++) {
uint32_t numVertices = (*it1).vertices.size(); uint32_t numVertices = (*it1).vertices.size();
uint32_t numIndices = (*it1).indices.size(); uint32_t numIndices = (*it1).indices.size();
uint32_t numTextureIds = (*it1).textureIds.size(); uint32_t numTextureIds = (*it1).textureIds.size();
@@ -128,7 +128,7 @@ void processNode(aiNode *node, const aiScene *scene, Model* model) {
// Push the node's meshes into the mesh vector // Push the node's meshes into the mesh vector
for(uint32_t i = 0; i < node->mNumMeshes; i++) { for(uint32_t i = 0; i < node->mNumMeshes; i++) {
aiMesh *mesh = scene->mMeshes[node->mMeshes[i]]; aiMesh *mesh = scene->mMeshes[node->mMeshes[i]];
model->meshes.push_back(processMesh(mesh, scene, model)); model->m_meshes.push_back(processMesh(mesh, scene, model));
} }
// Process child nodes too // Process child nodes too
@@ -228,7 +228,7 @@ std::vector<Texture> loadMaterialTextures(aiMaterial *mat, aiTextureType type, u
aiString filename; aiString filename;
mat->GetTexture(type, i, &filename); mat->GetTexture(type, i, &filename);
std::string currentPath = model->directory + '/' + filename.C_Str(); std::string currentPath = model->m_workingPath + '/' + filename.C_Str();
bool skip = 0; bool skip = 0;
for(uint32_t j = 0; j < model->textures.size(); j++) { for(uint32_t j = 0; j < model->textures.size(); j++) {
@@ -244,12 +244,12 @@ std::vector<Texture> loadMaterialTextures(aiMaterial *mat, aiTextureType type, u
texture.pathToTexture = currentPath; texture.pathToTexture = currentPath;
texture.textureType = textureType; texture.textureType = textureType;
// textureIds start at 0, but vector elements start at 1. // textureIds start at 0, but vector elements start at 1.
texture.textureId = model->textures.size(); texture.m_textureId = model->textures.size();
model->textures.push_back(texture); model->textures.push_back(texture);
// Add newest texture id to mesh // Add newest texture id to mesh
mesh->textureIds.push_back(texture.textureId); mesh->textureIds.push_back(texture.m_textureId);
} }
} }

View File

@@ -7,8 +7,7 @@ struct Texture {
std::string pathToTexture; std::string pathToTexture;
uint32_t textureType; uint32_t textureType;
uint32_t textureId; uint32_t m_textureId;
}; };
struct Mesh { struct Mesh {
@@ -22,7 +21,6 @@ struct Mesh {
struct Model { struct Model {
std::vector<Texture> textures; std::vector<Texture> textures;
std::vector<Mesh> meshes; std::vector<Mesh> m_meshes;
std::string directory; std::string m_workingPath;
}; };