From 9d7d344b803c69c7b29323a2d0722e7c30ab8aad Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Thu, 2 Sep 2021 22:30:38 +0200 Subject: [PATCH] - removed commented code from main.cpp that is not useful anymore ~ changed how g_Time is calculated so any shader that uses it should behave properly ~ changed how the uniforms are set to a reinterpret_cast instead of static_cast to perform a direct pointer conversion (safe as we know the types were actually those types) Signed-off-by: Alexis Maiquez --- main.cpp | 80 +------------------ src/WallpaperEngine/Render/Objects/CImage.cpp | 3 - .../Render/Objects/Effects/CPass.cpp | 20 ++--- 3 files changed, 12 insertions(+), 91 deletions(-) diff --git a/main.cpp b/main.cpp index 73968fc..d4b1c66 100644 --- a/main.cpp +++ b/main.cpp @@ -230,8 +230,6 @@ int main (int argc, char* argv[]) auto sceneInformation = project->getWallpaper ()->as (); FloatColor clearColor = sceneInformation->getClearColor (); - glClearColor (clearColor.r, clearColor.g, clearColor.b, clearColor.a); - // enable depth text glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS); @@ -246,7 +244,7 @@ int main (int argc, char* argv[]) while (glfwWindowShouldClose (window) == 0) { // calculate the current time value - g_Time += static_cast (endTime - startTime) / CLOCKS_PER_SEC; + g_Time = (float) glfwGetTime (); // get the start time of the frame startTime = clock (); @@ -255,6 +253,7 @@ int main (int argc, char* argv[]) // ensure we render over the whole screen glViewport (0, 0, 1920, 1080); + glClearColor (clearColor.r, clearColor.g, clearColor.b, clearColor.a); // clear window glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -279,79 +278,4 @@ int main (int argc, char* argv[]) SDL_Quit (); return 0; -/* - try - { - IrrlichtContext = new WallpaperEngine::Irrlicht::CContext (screens, isRootWindow); - IrrlichtContext->initializeContext (); - } - catch (std::runtime_error& ex) - { - std::cerr << ex.what () << std::endl; - - return 1; - } - - path = stringPathFixes (path); - - irr::io::path wallpaper_path = IrrlichtContext->getDevice ()->getFileSystem ()->getAbsolutePath (path.c_str ()); - irr::io::path project_path = wallpaper_path + "project.json"; - - if (mode == RUN_MODE_PACKAGE) - { - irr::io::path scene_path = wallpaper_path + "scene.pkg"; - // add the package file to the lookup list - IrrlichtContext->getDevice ()->getFileSystem ()->addFileArchive (scene_path, true, false); - } - else if (mode == RUN_MODE_DIRECTORY) - { - project_path = wallpaper_path + "project.json"; - // set the working directory to the project folder - IrrlichtContext->getDevice ()->getFileSystem ()->changeWorkingDirectoryTo (wallpaper_path); - } - - WallpaperEngine::Core::CProject* project = WallpaperEngine::Core::CProject::fromFile (project_path); - WallpaperEngine::Render::CWallpaper* wallpaper; - - if (project->getType () == "scene") - { - WallpaperEngine::Core::CScene* scene = project->getWallpaper ()->as (); - wallpaper = new WallpaperEngine::Render::CScene (scene, IrrlichtContext); - IrrlichtContext->getDevice ()->getSceneManager ()->setAmbientLight ( - scene->getAmbientColor ().toSColor () - ); - } - else if (project->getType () == "video") - { - wallpaper = new WallpaperEngine::Render::CVideo ( - project->getWallpaper ()->as (), - IrrlichtContext - ); - } - else - { - throw std::runtime_error ("Unsupported wallpaper type"); - } - - uint32_t minimumTime = 1000 / maximumFPS; - uint32_t startTime = 0; - uint32_t endTime = 0; - - while (IrrlichtContext && IrrlichtContext->getDevice () && IrrlichtContext->getDevice ()->run ()) - { - if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr) - continue; - - startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); - g_Time = startTime / 1000.0f; - - IrrlichtContext->renderFrame (wallpaper); - - endTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); - - IrrlichtContext->getDevice ()->sleep (minimumTime - (endTime - startTime), false); - } - - SDL_Quit (); - return 0;*/ } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 2b40265..5c2a1f1 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -177,9 +177,6 @@ void CImage::render () // now render the last pass (to screen) glBindBuffer (GL_ARRAY_BUFFER, *this->m_material->getImage ()->getVertexBuffer ()); glDrawArrays (GL_TRIANGLES, 0, 6);*/ - - // flush stdout - std::cout << std::flush; } /* diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index 6e30899..3308cbe 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -58,17 +58,17 @@ void CPass::render (GLuint drawTo, GLuint input) if (this->m_pass->getBlendingMode () == "translucent") { glEnable (GL_BLEND); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else if (this->m_pass->getBlendingMode () == "additive") { glEnable (GL_BLEND); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE); + glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE); } else if (this->m_pass->getBlendingMode () == "normal") { glEnable (GL_BLEND); - glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); + glBlendFuncSeparate (GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); } else { @@ -128,25 +128,25 @@ void CPass::render (GLuint drawTo, GLuint input) switch ((*cur)->type) { case Double: - glUniform1d ((*cur)->id, *static_cast ((*cur)->value)); + glUniform1d ((*cur)->id, *reinterpret_cast ((*cur)->value)); break; case Float: - glUniform1f ((*cur)->id, *static_cast ((*cur)->value)); + glUniform1f ((*cur)->id, *reinterpret_cast ((*cur)->value)); break; case Integer: - glUniform1i ((*cur)->id, *static_cast ((*cur)->value)); + glUniform1i ((*cur)->id, *reinterpret_cast ((*cur)->value)); break; case Vector4: - glUniform4fv ((*cur)->id, 1, glm::value_ptr (*static_cast ((*cur)->value))); + glUniform4fv ((*cur)->id, 1, glm::value_ptr (*reinterpret_cast ((*cur)->value))); break; case Vector3: - glUniform3fv ((*cur)->id, 1, glm::value_ptr (*static_cast ((*cur)->value))); + glUniform3fv ((*cur)->id, 1, glm::value_ptr (*reinterpret_cast ((*cur)->value))); break; case Vector2: - glUniform2fv ((*cur)->id, 1, glm::value_ptr (*static_cast ((*cur)->value))); + glUniform2fv ((*cur)->id, 1, glm::value_ptr (*reinterpret_cast ((*cur)->value))); break; case Matrix4: - glUniformMatrix4fv ((*cur)->id, 1, GL_FALSE, glm::value_ptr (*static_cast ((*cur)->value))); + glUniformMatrix4fv ((*cur)->id, 1, GL_FALSE, glm::value_ptr (*reinterpret_cast ((*cur)->value))); break; } }